UNPKG

react-chart-editor

Version:

plotly.js chart editor react component UI

2 lines 5.46 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.cursorHasLink=cursorHasLink;exports.getEntityByKey=getEntityByKey;exports.getEntityKeyAt=getEntityKeyAt;exports.handleKeyCommand=handleKeyCommand;exports.insertSoftNewline=insertSoftNewline;exports.toggleInlineStyle=toggleInlineStyle;exports.toggleLink=toggleLink;exports.toggleMutuallyExclusiveStyles=toggleMutuallyExclusiveStyles;var _draftJs=require("draft-js");var _DraftModifier=require("draft-js/lib/DraftModifier");var _configuration=require("./configuration");(function(){var enterModule=typeof reactHotLoaderGlobal!=="undefined"?reactHotLoaderGlobal.enterModule:undefined;enterModule&&enterModule(module)})();var __signature__=typeof reactHotLoaderGlobal!=="undefined"?reactHotLoaderGlobal.default.signature:function(a){return a};function selectionHasLink(editorState,selection){if(selection.isCollapsed()){return false}return cursorHasLink(editorState,selection)}function cursorHasLink(editorState,selection){var entity=getEntityByKey(getEntityKeyAt(editorState,selection));return Boolean(entity&&entity.get("type")===_configuration.LINK)}function getEntityByKey(entityKey){if(!entityKey){return null}return _draftJs.Entity.get(entityKey)}function getEntityKeyAt(editorState,selection){if(!selection){return null}var blockStartKey=selection.getStartKey();var selectionOffset=selection.getStartOffset();var contentState=editorState.getCurrentContent();var block=contentState.getBlockForKey(blockStartKey);return block.getEntityAt(selectionOffset)}function handleKeyCommand(editorState,command){switch(command){case"split-block":return insertSoftNewline(editorState);case"bold":return toggleInlineStyle(editorState,_configuration.BOLD);case"italic":return toggleInlineStyle(editorState,_configuration.ITALIC);default:return false}}function insertSoftNewline(editorState){var newEditorState=editorState;var currentStyleSet=newEditorState.getCurrentInlineStyle();newEditorState=currentStyleSet.reduce(function(reducedEditorState,style){return _draftJs.RichUtils.toggleInlineStyle(reducedEditorState,style)},newEditorState);var selectionState=newEditorState.getSelection();var selectionStart=selectionState.getStartOffset();var selectionEnd=selectionState.getEndOffset();if(selectionEnd-selectionStart!==0){var contentState=(0,_DraftModifier.removeRange)(newEditorState.getCurrentContent(),selectionState,"back");newEditorState=_draftJs.EditorState.push(newEditorState,contentState,"backspace-character")}return _draftJs.RichUtils.insertSoftNewline(newEditorState)}function toggleInlineStyle(editorState,inlineStyle){if(inlineStyle===_configuration.LINK){return toggleLink(editorState)}var updatedEditorState=toggleMutuallyExclusiveStyles(editorState,inlineStyle);return _draftJs.RichUtils.toggleInlineStyle(updatedEditorState,inlineStyle)}function toggleLink(editorState){var selection=editorState.getSelection();if(selectionHasLink(editorState,selection)){return _draftJs.RichUtils.toggleLink(editorState,selection,null)}var entityKey=_draftJs.Entity.create(_configuration.LINK,"MUTABLE",{url:""});return _draftJs.RichUtils.toggleLink(editorState,selection,entityKey)}function toggleMutuallyExclusiveStyles(editorState,inlineStyle){var currentStyleSet=editorState.getCurrentInlineStyle();if(inlineStyle===_configuration.SUBSCRIPT&&currentStyleSet.includes(_configuration.SUPERSCRIPT)){return _draftJs.RichUtils.toggleInlineStyle(editorState,_configuration.SUPERSCRIPT)}if(inlineStyle===_configuration.SUPERSCRIPT&&currentStyleSet.includes(_configuration.SUBSCRIPT)){return _draftJs.RichUtils.toggleInlineStyle(editorState,_configuration.SUBSCRIPT)}return editorState};(function(){var reactHotLoader=typeof reactHotLoaderGlobal!=="undefined"?reactHotLoaderGlobal.default:undefined;if(!reactHotLoader){return}reactHotLoader.register(selectionHasLink,"selectionHasLink","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(cursorHasLink,"cursorHasLink","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(getEntityByKey,"getEntityByKey","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(getEntityKeyAt,"getEntityKeyAt","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(handleKeyCommand,"handleKeyCommand","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(insertSoftNewline,"insertSoftNewline","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(toggleInlineStyle,"toggleInlineStyle","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(toggleLink,"toggleLink","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js");reactHotLoader.register(toggleMutuallyExclusiveStyles,"toggleMutuallyExclusiveStyles","/Users/dima/plotly/react-chart-editor/src/components/widgets/text_editors/RichText/DraftCommands.js")})();;(function(){var leaveModule=typeof reactHotLoaderGlobal!=="undefined"?reactHotLoaderGlobal.leaveModule:undefined;leaveModule&&leaveModule(module)})(); //# sourceMappingURL=DraftCommands.js.map