UNPKG

d2-ui

Version:
1,458 lines (1,251 loc) 440 kB
/** * Draft v0.7.0 * * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ var Draft = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule Draft */ 'use strict'; var AtomicBlockUtils = __webpack_require__(57); var BlockMapBuilder = __webpack_require__(14); var CharacterMetadata = __webpack_require__(6); var CompositeDraftDecorator = __webpack_require__(58); var ContentBlock = __webpack_require__(10); var ContentState = __webpack_require__(21); var DefaultDraftBlockRenderMap = __webpack_require__(22); var DefaultDraftInlineStyle = __webpack_require__(34); var DraftEditor = __webpack_require__(60); var DraftEditorBlock = __webpack_require__(35); var DraftModifier = __webpack_require__(4); var DraftEntity = __webpack_require__(9); var DraftEntityInstance = __webpack_require__(36); var EditorState = __webpack_require__(1); var KeyBindingUtil = __webpack_require__(23); var RichTextEditorUtil = __webpack_require__(71); var SelectionState = __webpack_require__(13); var convertFromDraftStateToRaw = __webpack_require__(76); var convertFromHTMLToContentBlocks = __webpack_require__(39); var convertFromRawToDraftState = __webpack_require__(77); var generateRandomKey = __webpack_require__(7); var getDefaultKeyBinding = __webpack_require__(40); var getVisibleSelectionRect = __webpack_require__(100); var DraftPublic = { Editor: DraftEditor, EditorBlock: DraftEditorBlock, EditorState: EditorState, CompositeDecorator: CompositeDraftDecorator, Entity: DraftEntity, EntityInstance: DraftEntityInstance, BlockMapBuilder: BlockMapBuilder, CharacterMetadata: CharacterMetadata, ContentBlock: ContentBlock, ContentState: ContentState, SelectionState: SelectionState, AtomicBlockUtils: AtomicBlockUtils, KeyBindingUtil: KeyBindingUtil, Modifier: DraftModifier, RichUtils: RichTextEditorUtil, DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap, DefaultDraftInlineStyle: DefaultDraftInlineStyle, convertFromHTML: convertFromHTMLToContentBlocks, convertFromRaw: convertFromRawToDraftState, convertToRaw: convertFromDraftStateToRaw, genKey: generateRandomKey, getDefaultKeyBinding: getDefaultKeyBinding, getVisibleSelectionRect: getVisibleSelectionRect }; module.exports = DraftPublic; /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule EditorState * */ 'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var BlockTree = __webpack_require__(33); var ContentState = __webpack_require__(21); var EditorBidiService = __webpack_require__(70); var Immutable = __webpack_require__(2); var SelectionState = __webpack_require__(13); var OrderedSet = Immutable.OrderedSet; var Record = Immutable.Record; var Stack = Immutable.Stack; var defaultRecord = { allowUndo: true, currentContent: null, decorator: null, directionMap: null, forceSelection: false, inCompositionMode: false, inlineStyleOverride: null, lastChangeType: null, nativelyRenderedContent: null, redoStack: Stack(), selection: null, treeMap: null, undoStack: Stack() }; var EditorStateRecord = Record(defaultRecord); var EditorState = (function () { _createClass(EditorState, [{ key: 'toJS', value: function toJS() { return this.getImmutable().toJS(); } }, { key: 'getAllowUndo', value: function getAllowUndo() { return this.getImmutable().get('allowUndo'); } }, { key: 'getCurrentContent', value: function getCurrentContent() { return this.getImmutable().get('currentContent'); } }, { key: 'getUndoStack', value: function getUndoStack() { return this.getImmutable().get('undoStack'); } }, { key: 'getRedoStack', value: function getRedoStack() { return this.getImmutable().get('redoStack'); } }, { key: 'getSelection', value: function getSelection() { return this.getImmutable().get('selection'); } }, { key: 'getDecorator', value: function getDecorator() { return this.getImmutable().get('decorator'); } }, { key: 'isInCompositionMode', value: function isInCompositionMode() { return this.getImmutable().get('inCompositionMode'); } }, { key: 'mustForceSelection', value: function mustForceSelection() { return this.getImmutable().get('forceSelection'); } }, { key: 'getNativelyRenderedContent', value: function getNativelyRenderedContent() { return this.getImmutable().get('nativelyRenderedContent'); } }, { key: 'getLastChangeType', value: function getLastChangeType() { return this.getImmutable().get('lastChangeType'); } /** * While editing, the user may apply inline style commands with a collapsed * cursor, intending to type text that adopts the specified style. In this * case, we track the specified style as an "override" that takes precedence * over the inline style of the text adjacent to the cursor. * * If null, there is no override in place. */ }, { key: 'getInlineStyleOverride', value: function getInlineStyleOverride() { return this.getImmutable().get('inlineStyleOverride'); } }, { key: 'getCurrentInlineStyle', /** * Get the appropriate inline style for the editor state. If an * override is in place, use it. Otherwise, the current style is * based on the location of the selection state. */ value: function getCurrentInlineStyle() { var override = this.getInlineStyleOverride(); if (override != null) { return override; } var content = this.getCurrentContent(); var selection = this.getSelection(); if (selection.isCollapsed()) { return getInlineStyleForCollapsedSelection(content, selection); } return getInlineStyleForNonCollapsedSelection(content, selection); } }, { key: 'getBlockTree', value: function getBlockTree(blockKey) { return this.getImmutable().getIn(['treeMap', blockKey]); } }, { key: 'isSelectionAtStartOfContent', value: function isSelectionAtStartOfContent() { var firstKey = this.getCurrentContent().getBlockMap().first().getKey(); return this.getSelection().hasEdgeWithin(firstKey, 0, 0); } }, { key: 'isSelectionAtEndOfContent', value: function isSelectionAtEndOfContent() { var content = this.getCurrentContent(); var blockMap = content.getBlockMap(); var last = blockMap.last(); var end = last.getLength(); return this.getSelection().hasEdgeWithin(last.getKey(), end, end); } }, { key: 'getDirectionMap', value: function getDirectionMap() { return this.getImmutable().get('directionMap'); } /** * Incorporate native DOM selection changes into the EditorState. This * method can be used when we simply want to accept whatever the DOM * has given us to represent selection, and we do not need to re-render * the editor. * * To forcibly move the DOM selection, see `EditorState.forceSelection`. */ }], [{ key: 'createEmpty', value: function createEmpty(decorator) { return EditorState.createWithContent(ContentState.createFromText(''), decorator); } }, { key: 'createWithContent', value: function createWithContent(contentState, decorator) { var firstKey = contentState.getBlockMap().first().getKey(); return EditorState.create({ currentContent: contentState, undoStack: Stack(), redoStack: Stack(), decorator: decorator || null, selection: SelectionState.createEmpty(firstKey) }); } }, { key: 'create', value: function create(config) { var currentContent = config.currentContent; var decorator = config.decorator; var recordConfig = _extends({}, config, { treeMap: generateNewTreeMap(currentContent, decorator), directionMap: EditorBidiService.getDirectionMap(currentContent) }); return new EditorState(new EditorStateRecord(recordConfig)); } }, { key: 'set', value: function set(editorState, put) { var map = editorState.getImmutable().withMutations(function (state) { var existingDecorator = state.get('decorator'); var decorator = existingDecorator; if (put.decorator === null) { decorator = null; } else if (put.decorator) { decorator = put.decorator; } var newContent = put.currentContent || editorState.getCurrentContent(); if (decorator !== existingDecorator) { var treeMap = state.get('treeMap'); var newTreeMap; if (decorator && existingDecorator) { newTreeMap = regenerateTreeForNewDecorator(newContent.getBlockMap(), treeMap, decorator, existingDecorator); } else { newTreeMap = generateNewTreeMap(newContent, decorator); } state.merge({ decorator: decorator, treeMap: newTreeMap, nativelyRenderedContent: null }); return; } var existingContent = editorState.getCurrentContent(); if (newContent !== existingContent) { state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), decorator)); } state.merge(put); }); return new EditorState(map); } }, { key: 'setInlineStyleOverride', value: function setInlineStyleOverride(editorState, inlineStyleOverride) { return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride }); } }, { key: 'acceptSelection', value: function acceptSelection(editorState, selection) { return updateSelection(editorState, selection, false); } /** * At times, we need to force the DOM selection to be where we * need it to be. This can occur when the anchor or focus nodes * are non-text nodes, for instance. In this case, we want to trigger * a re-render of the editor, which in turn forces selection into * the correct place in the DOM. The `forceSelection` method * accomplishes this. * * This method should be used in cases where you need to explicitly * move the DOM selection from one place to another without a change * in ContentState. */ }, { key: 'forceSelection', value: function forceSelection(editorState, selection) { if (!selection.getHasFocus()) { selection = selection.set('hasFocus', true); } return updateSelection(editorState, selection, true); } /** * Move selection to the end of the editor without forcing focus. */ }, { key: 'moveSelectionToEnd', value: function moveSelectionToEnd(editorState) { var content = editorState.getCurrentContent(); var lastBlock = content.getLastBlock(); var lastKey = lastBlock.getKey(); var length = lastBlock.getLength(); return EditorState.acceptSelection(editorState, new SelectionState({ anchorKey: lastKey, anchorOffset: length, focusKey: lastKey, focusOffset: length, isBackward: false })); } /** * Force focus to the end of the editor. This is useful in scenarios * where we want to programmatically focus the input and it makes sense * to allow the user to continue working seamlessly. */ }, { key: 'moveFocusToEnd', value: function moveFocusToEnd(editorState) { var afterSelectionMove = EditorState.moveSelectionToEnd(editorState); return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection()); } /** * Push the current ContentState onto the undo stack if it should be * considered a boundary state, and set the provided ContentState as the * new current content. */ }, { key: 'push', value: function push(editorState, contentState, changeType) { if (editorState.getCurrentContent() === contentState) { return editorState; } var forceSelection = changeType !== 'insert-characters'; var directionMap = EditorBidiService.getDirectionMap(contentState, editorState.getDirectionMap()); if (!editorState.getAllowUndo()) { return EditorState.set(editorState, { currentContent: contentState, directionMap: directionMap, lastChangeType: changeType, selection: contentState.getSelectionAfter(), forceSelection: forceSelection, inlineStyleOverride: null }); } var selection = editorState.getSelection(); var currentContent = editorState.getCurrentContent(); var undoStack = editorState.getUndoStack(); var newContent = contentState; if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) { undoStack = undoStack.push(currentContent); newContent = newContent.set('selectionBefore', selection); } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') { // Preserve the previous selection. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore()); } var inlineStyleOverride = editorState.getInlineStyleOverride(); // Don't discard inline style overrides on block type or depth changes. if (changeType !== 'adjust-depth' && changeType !== 'change-block-type') { inlineStyleOverride = null; } var editorStateChanges = { currentContent: newContent, directionMap: directionMap, undoStack: undoStack, redoStack: Stack(), lastChangeType: changeType, selection: contentState.getSelectionAfter(), forceSelection: forceSelection, inlineStyleOverride: inlineStyleOverride }; return EditorState.set(editorState, editorStateChanges); } /** * Make the top ContentState in the undo stack the new current content and * push the current content onto the redo stack. */ }, { key: 'undo', value: function undo(editorState) { if (!editorState.getAllowUndo()) { return editorState; } var undoStack = editorState.getUndoStack(); var newCurrentContent = undoStack.peek(); if (!newCurrentContent) { return editorState; } var currentContent = editorState.getCurrentContent(); var directionMap = EditorBidiService.getDirectionMap(newCurrentContent, editorState.getDirectionMap()); return EditorState.set(editorState, { currentContent: newCurrentContent, directionMap: directionMap, undoStack: undoStack.shift(), redoStack: editorState.getRedoStack().push(currentContent), forceSelection: true, inlineStyleOverride: null, lastChangeType: 'undo', nativelyRenderedContent: null, selection: currentContent.getSelectionBefore() }); } /** * Make the top ContentState in the redo stack the new current content and * push the current content onto the undo stack. */ }, { key: 'redo', value: function redo(editorState) { if (!editorState.getAllowUndo()) { return editorState; } var redoStack = editorState.getRedoStack(); var newCurrentContent = redoStack.peek(); if (!newCurrentContent) { return editorState; } var currentContent = editorState.getCurrentContent(); var directionMap = EditorBidiService.getDirectionMap(newCurrentContent, editorState.getDirectionMap()); return EditorState.set(editorState, { currentContent: newCurrentContent, directionMap: directionMap, undoStack: editorState.getUndoStack().push(currentContent), redoStack: redoStack.shift(), forceSelection: true, inlineStyleOverride: null, lastChangeType: 'redo', nativelyRenderedContent: null, selection: newCurrentContent.getSelectionAfter() }); } /** * Not for public consumption. */ }]); function EditorState(immutable) { _classCallCheck(this, EditorState); this._immutable = immutable; } /** * Set the supplied SelectionState as the new current selection, and set * the `force` flag to trigger manual selection placement by the view. */ /** * Not for public consumption. */ _createClass(EditorState, [{ key: 'getImmutable', value: function getImmutable() { return this._immutable; } }]); return EditorState; })(); function updateSelection(editorState, selection, forceSelection) { return EditorState.set(editorState, { selection: selection, forceSelection: forceSelection, nativelyRenderedContent: null, inlineStyleOverride: null }); } /** * Regenerate the entire tree map for a given ContentState and decorator. * Returns an OrderedMap that maps all available ContentBlock objects. */ function generateNewTreeMap(contentState, decorator) { return contentState.getBlockMap().map(function (block) { return BlockTree.generate(block, decorator); }).toOrderedMap(); } /** * Regenerate tree map objects for all ContentBlocks that have changed * between the current editorState and newContent. Returns an OrderedMap * with only changed regenerated tree map objects. */ function regenerateTreeForNewBlocks(editorState, newBlockMap, decorator) { var prevBlockMap = editorState.getCurrentContent().getBlockMap(); var prevTreeMap = editorState.getImmutable().get('treeMap'); return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) { return block !== prevBlockMap.get(key); }).map(function (block) { return BlockTree.generate(block, decorator); })); } /** * Generate tree map objects for a new decorator object, preserving any * decorations that are unchanged from the previous decorator. * * Note that in order for this to perform optimally, decoration Lists for * decorators should be preserved when possible to allow for direct immutable * List comparison. */ function regenerateTreeForNewDecorator(blockMap, previousTreeMap, decorator, existingDecorator) { return previousTreeMap.merge(blockMap.toSeq().filter(function (block) { return decorator.getDecorations(block) !== existingDecorator.getDecorations(block); }).map(function (block) { return BlockTree.generate(block, decorator); })); } /** * Return whether a change should be considered a boundary state, given * the previous change type. Allows us to discard potential boundary states * during standard typing or deletion behavior. */ function mustBecomeBoundary(editorState, changeType) { var lastChangeType = editorState.getLastChangeType(); return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character'; } function getInlineStyleForCollapsedSelection(content, selection) { var startKey = selection.getStartKey(); var startOffset = selection.getStartOffset(); var startBlock = content.getBlockForKey(startKey); // If the cursor is not at the start of the block, look backward to // preserve the style of the preceding character. if (startOffset > 0) { return startBlock.getInlineStyleAt(startOffset - 1); } // The caret is at position zero in this block. If the block has any // text at all, use the style of the first character. if (startBlock.getLength()) { return startBlock.getInlineStyleAt(0); } // Otherwise, look upward in the document to find the closest character. return lookUpwardForInlineStyle(content, startKey); } function getInlineStyleForNonCollapsedSelection(content, selection) { var startKey = selection.getStartKey(); var startOffset = selection.getStartOffset(); var startBlock = content.getBlockForKey(startKey); // If there is a character just inside the selection, use its style. if (startOffset < startBlock.getLength()) { return startBlock.getInlineStyleAt(startOffset); } // Check if the selection at the end of a non-empty block. Use the last // style in the block. if (startOffset > 0) { return startBlock.getInlineStyleAt(startOffset - 1); } // Otherwise, look upward in the document to find the closest character. return lookUpwardForInlineStyle(content, startKey); } function lookUpwardForInlineStyle(content, fromKey) { var previousBlock = content.getBlockBefore(fromKey); var previousLength; while (previousBlock) { previousLength = previousBlock.getLength(); if (previousLength) { return previousBlock.getInlineStyleAt(previousLength - 1); } previousBlock = content.getBlockBefore(previousBlock.getKey()); } return OrderedSet(); } module.exports = EditorState; /***/ }, /* 2 */ /***/ function(module, exports) { module.exports = Immutable; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ 'use strict'; /** * Use invariant() to assert state which your program assumes to be true. * * Provide sprintf-style format (only %s is supported) and arguments * to provide information about what broke and what you were * expecting. * * The invariant message will be stripped in production, but the invariant * will remain to ensure logic does not differ in production. */ function invariant(condition, format, a, b, c, d, e, f) { if (true) { if (format === undefined) { throw new Error('invariant requires an error message argument'); } } if (!condition) { var error; if (format === undefined) { error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); } else { var args = [a, b, c, d, e, f]; var argIndex = 0; error = new Error(format.replace(/%s/g, function () { return args[argIndex++]; })); error.name = 'Invariant Violation'; } error.framesToPop = 1; // we don't care about invariant's own frame throw error; } } module.exports = invariant; /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule DraftModifier * @typechecks * */ /** * `DraftModifier` provides a set of convenience methods that apply * modifications to a `ContentState` object based on a target `SelectionState`. * * Any change to a `ContentState` should be decomposable into a series of * transaction functions that apply the required changes and return output * `ContentState` objects. * * These functions encapsulate some of the most common transaction sequences. */ 'use strict'; var CharacterMetadata = __webpack_require__(6); var ContentStateInlineStyle = __webpack_require__(59); var _require = __webpack_require__(2); var OrderedSet = _require.OrderedSet; var applyEntityToContentState = __webpack_require__(75); var getCharacterRemovalRange = __webpack_require__(96); var getContentStateFragment = __webpack_require__(20); var insertFragmentIntoContentState = __webpack_require__(101); var insertTextIntoContentState = __webpack_require__(102); var invariant = __webpack_require__(3); var removeEntitiesAtEdges = __webpack_require__(51); var removeRangeFromContentState = __webpack_require__(113); var setBlockTypeForContentState = __webpack_require__(114); var splitBlockInContentState = __webpack_require__(116); var DraftModifier = { replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) { var withoutEntities = removeEntitiesAtEdges(contentState, rangeToReplace); var withoutText = removeRangeFromContentState(withoutEntities, rangeToReplace); var character = CharacterMetadata.create({ style: inlineStyle || OrderedSet(), entity: entityKey || null }); return insertTextIntoContentState(withoutText, withoutText.getSelectionAfter(), text, character); }, insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) { !targetRange.isCollapsed() ? true ? invariant(false, 'Target range must be collapsed for `insertText`.') : invariant(false) : undefined; return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey); }, moveText: function moveText(contentState, removalRange, targetRange) { var movedFragment = getContentStateFragment(contentState, removalRange); var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward'); return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment); }, replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) { var withoutEntities = removeEntitiesAtEdges(contentState, targetRange); var withoutText = removeRangeFromContentState(withoutEntities, targetRange); return insertFragmentIntoContentState(withoutText, withoutText.getSelectionAfter(), fragment); }, removeRange: function removeRange(contentState, rangeToRemove, removalDirection) { // Check whether the selection state overlaps with a single entity. // If so, try to remove the appropriate substring of the entity text. if (rangeToRemove.getAnchorKey() === rangeToRemove.getFocusKey()) { var key = rangeToRemove.getAnchorKey(); var startOffset = rangeToRemove.getStartOffset(); var endOffset = rangeToRemove.getEndOffset(); var block = contentState.getBlockForKey(key); var startEntity = block.getEntityAt(startOffset); var endEntity = block.getEntityAt(endOffset - 1); if (startEntity && startEntity === endEntity) { var adjustedRemovalRange = getCharacterRemovalRange(block, rangeToRemove, removalDirection); return removeRangeFromContentState(contentState, adjustedRemovalRange); } } var withoutEntities = removeEntitiesAtEdges(contentState, rangeToRemove); return removeRangeFromContentState(withoutEntities, rangeToRemove); }, splitBlock: function splitBlock(contentState, selectionState) { var withoutEntities = removeEntitiesAtEdges(contentState, selectionState); var withoutText = removeRangeFromContentState(withoutEntities, selectionState); return splitBlockInContentState(withoutText, withoutText.getSelectionAfter()); }, applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) { return ContentStateInlineStyle.add(contentState, selectionState, inlineStyle); }, removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) { return ContentStateInlineStyle.remove(contentState, selectionState, inlineStyle); }, setBlockType: function setBlockType(contentState, selectionState, blockType) { return setBlockTypeForContentState(contentState, selectionState, blockType); }, applyEntity: function applyEntity(contentState, selectionState, entityKey) { var withoutEntities = removeEntitiesAtEdges(contentState, selectionState); return applyEntityToContentState(withoutEntities, selectionState, entityKey); } }; module.exports = DraftModifier; /***/ }, /* 5 */ /***/ function(module, exports) { "use strict"; /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ var nullthrows = function (x) { if (x != null) { return x; } throw new Error("Got unexpected null or undefined"); }; module.exports = nullthrows; /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule CharacterMetadata * @typechecks * */ 'use strict'; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var _require = __webpack_require__(2); var Map = _require.Map; var OrderedSet = _require.OrderedSet; var Record = _require.Record; var EMPTY_SET = OrderedSet(); var defaultRecord = { style: EMPTY_SET, entity: null }; var CharacterMetadataRecord = Record(defaultRecord); var CharacterMetadata = (function (_CharacterMetadataRecord) { _inherits(CharacterMetadata, _CharacterMetadataRecord); function CharacterMetadata() { _classCallCheck(this, CharacterMetadata); _get(Object.getPrototypeOf(CharacterMetadata.prototype), 'constructor', this).apply(this, arguments); } _createClass(CharacterMetadata, [{ key: 'getStyle', value: function getStyle() { return this.get('style'); } }, { key: 'getEntity', value: function getEntity() { return this.get('entity'); } }, { key: 'hasStyle', value: function hasStyle(style) { return this.getStyle().has(style); } }], [{ key: 'applyStyle', value: function applyStyle(record, style) { var withStyle = record.set('style', record.getStyle().add(style)); return CharacterMetadata.create(withStyle); } }, { key: 'removeStyle', value: function removeStyle(record, style) { var withoutStyle = record.set('style', record.getStyle().remove(style)); return CharacterMetadata.create(withoutStyle); } }, { key: 'applyEntity', value: function applyEntity(record, entityKey) { var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey); return CharacterMetadata.create(withEntity); } /** * Use this function instead of the `CharacterMetadata` constructor. * Since most content generally uses only a very small number of * style/entity permutations, we can reuse these objects as often as * possible. */ }, { key: 'create', value: function create(config) { if (!config) { return EMPTY; } // Fill in unspecified properties, if necessary. var configMap = Map({ style: EMPTY_SET, entity: null }).merge(config); var existing = pool.get(configMap); if (existing) { return existing; } var newCharacter = new CharacterMetadata(configMap); pool = pool.set(configMap, newCharacter); return newCharacter; } }]); return CharacterMetadata; })(CharacterMetadataRecord); var EMPTY = new CharacterMetadata(); var pool = Map([[Map(defaultRecord), EMPTY]]); CharacterMetadata.EMPTY = EMPTY; module.exports = CharacterMetadata; /***/ }, /* 7 */ /***/ function(module, exports) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule generateRandomKey * @typechecks * */ 'use strict'; var seenKeys = {}; var MULTIPLIER = Math.pow(2, 24); function generateRandomKey() { var key = undefined; while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) { key = Math.floor(Math.random() * MULTIPLIER).toString(32); } seenKeys[key] = true; return key; } module.exports = generateRandomKey; /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ 'use strict'; var UserAgentData = __webpack_require__(122); var VersionRange = __webpack_require__(123); var mapObject = __webpack_require__(136); var memoizeStringOnly = __webpack_require__(137); /** * Checks to see whether `name` and `version` satisfy `query`. * * @param {string} name Name of the browser, device, engine or platform * @param {?string} version Version of the browser, engine or platform * @param {string} query Query of form "Name [range expression]" * @param {?function} normalizer Optional pre-processor for range expression * @return {boolean} */ function compare(name, version, query, normalizer) { // check for exact match with no version if (name === query) { return true; } // check for non-matching names if (!query.startsWith(name)) { return false; } // full comparison with version var range = query.slice(name.length); if (version) { range = normalizer ? normalizer(range) : range; return VersionRange.contains(range, version); } return false; } /** * Normalizes `version` by stripping any "NT" prefix, but only on the Windows * platform. * * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class. * * @param {string} version * @return {string} */ function normalizePlatformVersion(version) { if (UserAgentData.platformName === 'Windows') { return version.replace(/^\s*NT/, ''); } return version; } /** * Provides client-side access to the authoritative PHP-generated User Agent * information supplied by the server. */ var UserAgent = { /** * Check if the User Agent browser matches `query`. * * `query` should be a string like "Chrome" or "Chrome > 33". * * Valid browser names include: * * - ACCESS NetFront * - AOL * - Amazon Silk * - Android * - BlackBerry * - BlackBerry PlayBook * - Chrome * - Chrome for iOS * - Chrome frame * - Facebook PHP SDK * - Facebook for iOS * - Firefox * - IE * - IE Mobile * - Mobile Safari * - Motorola Internet Browser * - Nokia * - Openwave Mobile Browser * - Opera * - Opera Mini * - Opera Mobile * - Safari * - UIWebView * - Unknown * - webOS * - etc... * * An authoritative list can be found in the PHP `BrowserDetector` class and * related classes in the same file (see calls to `new UserAgentBrowser` here: * https://fburl.com/50728104). * * @note Function results are memoized * * @param {string} query Query of the form "Name [range expression]" * @return {boolean} */ isBrowser: function (query) { return compare(UserAgentData.browserName, UserAgentData.browserFullVersion, query); }, /** * Check if the User Agent browser uses a 32 or 64 bit architecture. * * @note Function results are memoized * * @param {string} query Query of the form "32" or "64". * @return {boolean} */ isBrowserArchitecture: function (query) { return compare(UserAgentData.browserArchitecture, null, query); }, /** * Check if the User Agent device matches `query`. * * `query` should be a string like "iPhone" or "iPad". * * Valid device names include: * * - Kindle * - Kindle Fire * - Unknown * - iPad * - iPhone * - iPod * - etc... * * An authoritative list can be found in the PHP `DeviceDetector` class and * related classes in the same file (see calls to `new UserAgentDevice` here: * https://fburl.com/50728332). * * @note Function results are memoized * * @param {string} query Query of the form "Name" * @return {boolean} */ isDevice: function (query) { return compare(UserAgentData.deviceName, null, query); }, /** * Check if the User Agent rendering engine matches `query`. * * `query` should be a string like "WebKit" or "WebKit >= 537". * * Valid engine names include: * * - Gecko * - Presto * - Trident * - WebKit * - etc... * * An authoritative list can be found in the PHP `RenderingEngineDetector` * class related classes in the same file (see calls to `new * UserAgentRenderingEngine` here: https://fburl.com/50728617). * * @note Function results are memoized * * @param {string} query Query of the form "Name [range expression]" * @return {boolean} */ isEngine: function (query) { return compare(UserAgentData.engineName, UserAgentData.engineVersion, query); }, /** * Check if the User Agent platform matches `query`. * * `query` should be a string like "Windows" or "iOS 5 - 6". * * Valid platform names include: * * - Android * - BlackBerry OS * - Java ME * - Linux * - Mac OS X * - Mac OS X Calendar * - Mac OS X Internet Account * - Symbian * - SymbianOS * - Windows * - Windows Mobile * - Windows Phone * - iOS * - iOS Facebook Integration Account * - iOS Facebook Social Sharing UI * - webOS * - Chrome OS * - etc... * * An authoritative list can be found in the PHP `PlatformDetector` class and * related classes in the same file (see calls to `new UserAgentPlatform` * here: https://fburl.com/50729226). * * @note Function results are memoized * * @param {string} query Query of the form "Name [range expression]" * @return {boolean} */ isPlatform: function (query) { return compare(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion); }, /** * Check if the User Agent platform is a 32 or 64 bit architecture. * * @note Function results are memoized * * @param {string} query Query of the form "32" or "64". * @return {boolean} */ isPlatformArchitecture: function (query) { return compare(UserAgentData.platformArchitecture, null, query); } }; module.exports = mapObject(UserAgent, memoizeStringOnly); /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule DraftEntity * @typechecks * */ 'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var DraftEntityInstance = __webpack_require__(36); var Immutable = __webpack_require__(2); var invariant = __webpack_require__(3); var Map = Immutable.Map; var instances = Map(); var instanceKey = 0; /** * A "document entity" is an object containing metadata associated with a * piece of text in a ContentBlock. * * For example, a `link` entity might include a `uri` property. When a * ContentBlock is rendered in the browser, text that refers to that link * entity may be rendered as an anchor, with the `uri` as the href value. * * In a ContentBlock, every position in the text may correspond to zero * or one entities. This correspondence is tracked using a key string, * generated via DraftEntity.create() and used to obtain entity metadata * via DraftEntity.get(). */ var DraftEntity = { /** * Create a DraftEntityInstance and store it for later retrieval. * * A random key string will be generated and returned. This key may * be used to track the entity's usage in a ContentBlock, and for * retrieving data about the entity at render time. */ create: function create(type, mutability, data) { return DraftEntity.add(new DraftEntityInstance({ type: type, mutability: mutability, data: data || {} })); }, /** * Add an existing DraftEntityInstance to the DraftEntity map. This is * useful when restoring instances from the server. */ add: function add(instance) { var key = '' + ++instanceKey; instances = instances.set(key, instance); return key; }, /** * Retrieve the entity corresponding to the supplied key string. */ get: function get(key) { var instance = instances.get(key); !!!instance ? true ? invariant(false, 'Unknown DraftEntity key.') : invariant(false) : undefined; return instance; }, /** * Entity instances are immutable. If you need to update the data for an * instance, this method will merge your data updates and return a new * instance. */ mergeData: function mergeData(key, toMerge) { var instance = DraftEntity.get(key); var newData = _extends({}, instance.getData(), toMerge); var newInstance = instance.set('data', newData); instances = instances.set(key, newInstance); return newInstance; }, /** * Completely replace the data for a given instance. */ replaceData: function replaceData(key, newData) { var instance = DraftEntity.get(key); var newInstance = instance.set('data', newData); instances = instances.set(key, newInstance); return newInstance; } }; module.exports = DraftEntity; /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ContentBlock * @typechecks * */ 'use strict'; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, no