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


TypeScript draft-js.RichUtils類代碼示例

本文整理匯總了TypeScript中draft-js.RichUtils的典型用法代碼示例。如果您正苦於以下問題:TypeScript RichUtils類的具體用法?TypeScript RichUtils怎麽用?TypeScript RichUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RichUtils類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: toggleStyle

 return function toggleStyle(styleName: string) {
   const {getEditorState, setEditorState} = callbacks;
   const editorState = getEditorState();
   const selection = editorState.getSelection();
   setEditorState(RichUtils.toggleInlineStyle(
     getEditorState(),
     styleName
   ));
 }
開發者ID:react-component,項目名稱:editor-utils,代碼行數:9,代碼來源:getToggleStyleFunc.ts

示例2: resetHighlightForCurrentSelection

export function resetHighlightForCurrentSelection(editorState, style) {
    const type = getHighlightType(style);
    const selection = editorState.getSelection();
    const content = editorState.getCurrentContent();
    const block = content.getBlockForKey(selection.getStartKey());
    const offset = selection.getStartOffset() === block.getLength() - 1 ? 1 : 0;
    const styleBefore = getHighlightStyleAtOffset(editorState, [type], selection, -1);
    const styleAfter = getHighlightStyleAtOffset(editorState, [type], selection, offset, true);

    if (styleBefore !== style && styleAfter !== style) {
        return removeHighlight(editorState, style);
    }

    return RichUtils.toggleInlineStyle(editorState, style);
}
開發者ID:jerome-poisson,項目名稱:superdesk-client-core,代碼行數:15,代碼來源:highlights.ts

示例3:

export const removeLinks = (editorState: EditorState) => {
  return RichUtils.toggleLink(editorState, editorState.getSelection(), null)
}
開發者ID:joeyAghion,項目名稱:positron,代碼行數:3,代碼來源:utils.ts

示例4: addHighlight

export function addHighlight(editorState, type, data, single = false) {
    let nextEditorState = editorState;

    const initialSelection = nextEditorState.getSelection().merge({
        hasFocus: true,
    });

    const highlightsState = getHighlightsState(nextEditorState);

    if (highlightTypeValid(type) !== true) {
        throw new Error('Highlight type invalid');
    }

    if (single && selectionHasType(editorState, type)) {
        return editorState;
    }

    let newIndex = 0;

    if (highlightsState.lastHighlightIds && has(highlightsState.lastHighlightIds, type)) {
        newIndex = highlightsState.lastHighlightIds[type] + 1;
    }
    const styleName = type + '-' + newIndex;

    const newHighlightsState = {
        lastHighlightIds: {
            ...highlightsState.lastHighlightIds,
            [type]: newIndex,
        },
        highlightsStyleMap: {
            ...highlightsState.highlightsStyleMap,
            [styleName]: availableHighlights[type],
        },
        highlightsData: {
            ...highlightsState.highlightsData,
            [styleName]: {
                ...data,
                type,
            },
        },
    };

    nextEditorState = RichUtils.toggleInlineStyle(nextEditorState, styleName);

    // prevent recording the changes to undo stack so user doesn't have to undo twice
    // for the highlight to be completelly(both inline styles and related data) undone
    nextEditorState = EditorState.set(nextEditorState, {allowUndo: false});

    nextEditorState = setHighlightsState(nextEditorState, newHighlightsState);

    // make sure the cursor is at the right position after undo
    // it used to always end up at the position 0 of the first block
    // when undoing after changing block data with `allowUndo` set to false
    nextEditorState = EditorState.push(
        nextEditorState,
        nextEditorState.getCurrentContent().set('selectionBefore', initialSelection),
        'change-block-data',
    );

    // restore focus lost after clicking a toolbar action or entering highlight data OR pushing editorState
    // so the selection is visible after undo
    nextEditorState = EditorState.acceptSelection(
        nextEditorState,
        initialSelection,
    );

    nextEditorState = EditorState.set(nextEditorState, {allowUndo: true});

    return nextEditorState;
}
開發者ID:jerome-poisson,項目名稱:superdesk-client-core,代碼行數:70,代碼來源:highlights.ts


注:本文中的draft-js.RichUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。