當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript draft-js.Modifier類代碼示例

本文整理匯總了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;未經允許,請勿轉載。