• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript draft-js.Modifier类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中draft-js.Modifier的典型用法代码示例。如果您正苦于以下问题:TypeScript Modifier类的具体用法?TypeScript Modifier怎么用?TypeScript Modifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Modifier类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: toggleBlockStyle

  return function toggleBlockStyle(styleName: string) {
    const { getEditorState, setEditorState } = callbacks;
    const editorState = getEditorState();
    const currentBlock = getSelectedBlock(editorState);
    const blockTypedContent = Modifier.setBlockType(
      editorState.getCurrentContent(),
      editorState.getSelection(),
      styleName
    );

    setEditorState(
      EditorState.push(editorState, blockTypedContent, 'apply-block-type')
    );

  }
开发者ID:react-component,项目名称:editor-utils,代码行数:15,代码来源:getToggleBlockStyleFunc.ts


示例2: modifyInlineStyle

export function modifyInlineStyle(
  editor: EditorState, selection: SelectionState, {apply, remove}: {apply?: string, remove?: string}
) {
  let content = editor.getCurrentContent()
  if (remove) {
    content = Modifier.removeInlineStyle(content, selection, remove)
  }
  if (apply) {
    content = Modifier.applyInlineStyle(content, selection, apply)
  }

  return EditorState.push(editor, content, 'change-inline-style')
}
开发者ID:Pajn,项目名称:meltdown,代码行数:13,代码来源:editor-syntax-highlighting.ts


示例3:

export const removeBlocks = (editorState: EditorState) => {
  return Modifier.setBlockType(
    editorState.getCurrentContent(),
    editorState.getSelection(),
    "unstyled"
  )
}
开发者ID:joeyAghion,项目名称:positron,代码行数:7,代码来源:utils.ts


示例4: onSelect

    onSelect(query: string, text: string) {
        const selection = this.core.getSelection();
        const offset = selection.getAnchorOffset() - 1;
        const content = this.core.getCurrentContent();
        const block_text = content.getBlockForKey(selection.getAnchorKey()).getText();
        const idx = block_text.lastIndexOf(query, offset);

        if (idx === -1 || (idx + query.length < offset)) {
            log.error('Invalid selection:', selection);
            return this;
        }

        const next_selection = selection.merge({
            anchorOffset: idx,
            focusOffset: idx + query.length,
        }) as SelectionState;
        const next_content = Modifier.replaceText(content, next_selection, text);
        const next_editor = EditorState.forceSelection(
            EditorState.push(
                this.core,
                next_content,
                'insert-characters'
            ),
            next_content.getSelectionAfter()
        );

        return new TweetEditorState(
            next_editor,
            this.is_open,
            this.keymaps,
            this.in_reply_to_status
        );
    }
开发者ID:DevenLu,项目名称:YourFukurou,代码行数:33,代码来源:tweet_editor.ts


示例5: walkChildren

  walkChildren(node, child => {
    let end = start + getLength(child)
    const selection = SelectionState.createEmpty(blockKey).merge({
      anchorOffset: start,
      focusKey: blockKey,
      focusOffset: end,
    })

    if (child.type === 'Emph') {
      updatedContent = Modifier.applyInlineStyle(updatedContent, selection, 'ITALIC')
    } else if (child.type === 'Strong') {
      updatedContent = Modifier.applyInlineStyle(updatedContent, selection, 'BOLD')
    } else if (child.type === 'Code') {
      updatedContent = Modifier.applyInlineStyle(updatedContent, selection, 'CODE')
    }

    start = end + 1
  })
开发者ID:Pajn,项目名称:meltdown,代码行数:18,代码来源:editor-syntax-highlighting.ts


示例6: handlePastedText

export default function handlePastedText(text: string, html?: string):DraftHandleValue {
  if (html) {
    const fragment = customHTML2Content(html);
    const withImage = Modifier.replaceWithFragment(
      imageBlock,
      insertionTarget,
      fragment
    );
  }
  return 'not-handled';
}
开发者ID:react-component,项目名称:editor-core,代码行数:11,代码来源:handlePastedText.ts


示例7:

export const insertPastedState = (
  pastedState: EditorState,
  editorState: EditorState
) => {
  const blockMap = pastedState.getCurrentContent().getBlockMap()

  // Merge blockMap from pasted text into existing content
  const modifiedContent = Modifier.replaceWithFragment(
    editorState.getCurrentContent(),
    editorState.getSelection(),
    blockMap
  )
  // Create a new editorState from merged content
  return EditorState.push(editorState, modifiedContent, "insert-fragment")
}
开发者ID:artsy,项目名称:positron,代码行数:15,代码来源:shared.ts


示例8: insertContentInState

function insertContentInState(
    editorState: EditorState,
    pastedContent: ContentState,
    onChange: (e: EditorState) => void,
    editorFormat: Array<string>): DraftHandleValue {
    let _pastedContent = pastedContent;
    const blockMap = _pastedContent.getBlockMap();
    const hasAtomicBlocks = blockMap.some((block) => block.getType() === 'atomic');
    const acceptedInlineStyles =
        Object.keys(inlineStyles)
            .filter((style) => editorFormat.includes(style))
            .map((style) => inlineStyles[style]);

    let contentState = editorState.getCurrentContent();
    let selection = editorState.getSelection();
    let blocks = [];

    if (hasAtomicBlocks) {
        contentState = Modifier.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
        selection = contentState.getSelectionAfter();
    }

    _pastedContent = sanitizeContent(EditorState.createWithContent(_pastedContent), acceptedInlineStyles)
        .getCurrentContent();

    blockMap.forEach((block) => {
        if (!hasAtomicBlocks || block.getType() !== 'atomic') {
            return blocks.push(block);
        }

        const entityKey = block.getEntityAt(0);
        const entity = _pastedContent.getEntity(entityKey);

        contentState = contentState.addEntity(entity);

        blocks = blocks.concat(
            atomicBlock(block.getData(), contentState.getLastCreatedEntityKey()),
        );
    });

    if (hasAtomicBlocks) {
        contentState = Modifier.setBlockType(contentState, selection, 'atomic');

        blocks = blocks.concat(emptyBlock()); // add empty block to ensure writting afterwards
    }

    const newBlockMap = OrderedMap<string, ContentBlock>(blocks.map((b) => ([b.getKey(), b])));

    let nextEditorState = EditorState.push(
        editorState,
        Modifier.replaceWithFragment(contentState, selection, newBlockMap),
        'insert-fragment',
    );

    const selectionAfterInsert = nextEditorState.getSelection();
    const customData = getAllCustomDataFromEditor(editorState);

    // for the first block recover the initial block data because on replaceWithFragment the block data is
    // replaced with the data from pasted fragment
    nextEditorState = setAllCustomDataForEditor(nextEditorState, customData);

    // reset undo stack
    nextEditorState = EditorState.push(
        editorState,
        nextEditorState.getCurrentContent(),
        'insert-fragment',
    );

    nextEditorState = EditorState.forceSelection(nextEditorState, selectionAfterInsert);

    onChange(nextEditorState);

    return 'handled';
}
开发者ID:jerome-poisson,项目名称:superdesk-client-core,代码行数:74,代码来源:handlePastedText.ts



注:本文中的draft-js.Modifier类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript draft-js.RichUtils类代码示例发布时间:2022-05-25
下一篇:
TypeScript draft-js.EditorState类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap