arch-editor
Version:
Rich text editor with a high degree of customization.
2 lines • 2.64 kB
JavaScript
/*! For license information please see draftUtils.js.LICENSE.txt */
!function(){"use strict";var t={d:function(e,n){for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{clearInlineStyles:function(){return u},createBlockEntity:function(){return o},forceReRender:function(){return y},getBlockTypeFromSelection:function(){return g},getSelectionBlocks:function(){return a},removeBlockEntity:function(){return i},takeSelectionFocus:function(){return l},updateBlockEntityData:function(){return c},validateSelection:function(){return f}});var n=require("draft-js"),r=require("./default");function o(t,e,r,o){var i=t.getCurrentContent().createEntity(e,r,o);return{entityKey:i.getLastCreatedEntityKey(),editorState:n.EditorState.set(t,{currentContent:i})}}function i(t,e){var r=e.getCurrentContent(),o=t.getKey(),i=t.merge({type:"unstyled",text:"",characterList:t.getCharacterList().slice(0,0),data:{}}),c=r.getBlockMap(),u=r.merge({blockMap:c.set(o,i)}),a=n.EditorState.push(e,u,"change-block-type"),l=n.SelectionState.createEmpty(o);return n.EditorState.forceSelection(a,l)}function c(t,e,r){var o=t.getEntityAt(0),i=e.getCurrentContent().mergeEntityData(o,r);return n.EditorState.set(e,{currentContent:i})}function u(t){var e=t.getSelection();if(e.isCollapsed())return t;var r=n.RichUtils.toggleLink(t,e,null),o=r.getCurrentContent(),i=["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE"].reduce((function(t,r){return n.Modifier.removeInlineStyle(t,e,r)}),o);return n.EditorState.push(r,i,"change-inline-style")}function a(t){for(var e=t.getSelection(),n=e.getStartKey(),r=e.getEndKey(),o=!1,i=[],c=t.getCurrentContent().getBlocksAsArray(),u=0;u<c.length;u++){var a=c[u],l=a.getKey();if(l===n&&(o=!0),o&&i.push(a),l===r)break}return i}function l(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=t.getSelection(),o=r.merge({hasFocus:e});return n.EditorState.forceSelection(t,o)}function g(t){var e=t.getSelection().getAnchorKey();return t.getCurrentContent().getBlockForKey(e).getType()}function f(t){return!(a(t).length>1)&&"atomic"!==g(t)}function y(t){var e=t.getCurrentContent(),o=n.EditorState.createWithContent(e,new n.CompositeDecorator(r.defaultStrategy));return n.EditorState.set(o,{selection:t.getSelection(),undoStack:t.getUndoStack(),redoStack:t.getRedoStack(),lastChangeType:t.getLastChangeType()})}module.exports=e}();