Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. *
  9. * @preventMunge
  10. * @emails oncall+draft_js
  11. */
  12. 'use strict';
  13. var _assign = require("object-assign");
  14. function _extends() { _extends = _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; }; return _extends.apply(this, arguments); }
  15. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  16. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  18. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  19. var DefaultDraftBlockRenderMap = require("./DefaultDraftBlockRenderMap");
  20. var DefaultDraftInlineStyle = require("./DefaultDraftInlineStyle");
  21. var DraftEditorCompositionHandler = require("./DraftEditorCompositionHandler");
  22. var DraftEditorContents = require("./DraftEditorContents.react");
  23. var DraftEditorDragHandler = require("./DraftEditorDragHandler");
  24. var DraftEditorEditHandler = require("./DraftEditorEditHandler");
  25. var flushControlled = require("./DraftEditorFlushControlled");
  26. var DraftEditorPlaceholder = require("./DraftEditorPlaceholder.react");
  27. var DraftEffects = require("./DraftEffects");
  28. var EditorState = require("./EditorState");
  29. var React = require("react");
  30. var Scroll = require("fbjs/lib/Scroll");
  31. var Style = require("fbjs/lib/Style");
  32. var UserAgent = require("fbjs/lib/UserAgent");
  33. var cx = require("fbjs/lib/cx");
  34. var generateRandomKey = require("./generateRandomKey");
  35. var getDefaultKeyBinding = require("./getDefaultKeyBinding");
  36. var getScrollPosition = require("fbjs/lib/getScrollPosition");
  37. var gkx = require("./gkx");
  38. var invariant = require("fbjs/lib/invariant");
  39. var isHTMLElement = require("./isHTMLElement");
  40. var nullthrows = require("fbjs/lib/nullthrows");
  41. var isIE = UserAgent.isBrowser('IE'); // IE does not support the `input` event on contentEditable, so we can't
  42. // observe spellcheck behavior.
  43. var allowSpellCheck = !isIE; // Define a set of handler objects to correspond to each possible `mode`
  44. // of editor behavior.
  45. var handlerMap = {
  46. edit: DraftEditorEditHandler,
  47. composite: DraftEditorCompositionHandler,
  48. drag: DraftEditorDragHandler,
  49. cut: null,
  50. render: null
  51. };
  52. var didInitODS = false;
  53. var UpdateDraftEditorFlags =
  54. /*#__PURE__*/
  55. function (_React$Component) {
  56. _inheritsLoose(UpdateDraftEditorFlags, _React$Component);
  57. function UpdateDraftEditorFlags() {
  58. return _React$Component.apply(this, arguments) || this;
  59. }
  60. var _proto = UpdateDraftEditorFlags.prototype;
  61. _proto.render = function render() {
  62. return null;
  63. };
  64. _proto.componentDidMount = function componentDidMount() {
  65. this._update();
  66. };
  67. _proto.componentDidUpdate = function componentDidUpdate() {
  68. this._update();
  69. };
  70. _proto._update = function _update() {
  71. var editor = this.props.editor;
  72. /**
  73. * Sometimes a render triggers a 'focus' or other event, and that will
  74. * schedule a second render pass.
  75. * In order to make sure the second render pass gets the latest editor
  76. * state, we update it here.
  77. * Example:
  78. * render #1
  79. * +
  80. * |
  81. * | cWU -> Nothing ... latestEditorState = STALE_STATE :(
  82. * |
  83. * | render -> this.props.editorState = FRESH_STATE
  84. * | + *and* set latestEditorState = FRESH_STATE
  85. * |
  86. * | |
  87. * | +--> triggers 'focus' event, calling 'handleFocus' with latestEditorState
  88. * | +
  89. * | |
  90. * +>cdU -> latestEditorState = FRESH_STATE | the 'handleFocus' call schedules render #2
  91. * | with latestEditorState, which is FRESH_STATE
  92. * |
  93. * render #2 <--------------------------------------+
  94. * +
  95. * |
  96. * | cwU -> nothing updates
  97. * |
  98. * | render -> this.props.editorState = FRESH_STATE which was passed in above
  99. * |
  100. * +>cdU fires and resets latestEditorState = FRESH_STATE
  101. * ---
  102. * Note that if we don't set latestEditorState in 'render' in the above
  103. * diagram, then STALE_STATE gets passed to render #2.
  104. */
  105. editor._latestEditorState = this.props.editorState;
  106. /**
  107. * The reason we set this 'blockSelectEvents' flag is that IE will fire a
  108. * 'selectionChange' event when we programmatically change the selection,
  109. * meaning it would trigger a new select event while we are in the middle
  110. * of updating.
  111. * We found that the 'selection.addRange' was what triggered the stray
  112. * selectionchange event in IE.
  113. * To be clear - we have not been able to reproduce specific bugs related
  114. * to this stray selection event, but have recorded logs that some
  115. * conditions do cause it to get bumped into during editOnSelect.
  116. */
  117. editor._blockSelectEvents = true;
  118. };
  119. return UpdateDraftEditorFlags;
  120. }(React.Component);
  121. /**
  122. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  123. * div, and provides a wide variety of useful function props for managing the
  124. * state of the editor. See `DraftEditorProps` for details.
  125. */
  126. var DraftEditor =
  127. /*#__PURE__*/
  128. function (_React$Component2) {
  129. _inheritsLoose(DraftEditor, _React$Component2);
  130. /**
  131. * Define proxies that can route events to the current handler.
  132. */
  133. function DraftEditor(props) {
  134. var _this;
  135. _this = _React$Component2.call(this, props) || this;
  136. _defineProperty(_assertThisInitialized(_this), "_blockSelectEvents", void 0);
  137. _defineProperty(_assertThisInitialized(_this), "_clipboard", void 0);
  138. _defineProperty(_assertThisInitialized(_this), "_handler", void 0);
  139. _defineProperty(_assertThisInitialized(_this), "_dragCount", void 0);
  140. _defineProperty(_assertThisInitialized(_this), "_internalDrag", void 0);
  141. _defineProperty(_assertThisInitialized(_this), "_editorKey", void 0);
  142. _defineProperty(_assertThisInitialized(_this), "_placeholderAccessibilityID", void 0);
  143. _defineProperty(_assertThisInitialized(_this), "_latestEditorState", void 0);
  144. _defineProperty(_assertThisInitialized(_this), "_latestCommittedEditorState", void 0);
  145. _defineProperty(_assertThisInitialized(_this), "_pendingStateFromBeforeInput", void 0);
  146. _defineProperty(_assertThisInitialized(_this), "_onBeforeInput", void 0);
  147. _defineProperty(_assertThisInitialized(_this), "_onBlur", void 0);
  148. _defineProperty(_assertThisInitialized(_this), "_onCharacterData", void 0);
  149. _defineProperty(_assertThisInitialized(_this), "_onCompositionEnd", void 0);
  150. _defineProperty(_assertThisInitialized(_this), "_onCompositionStart", void 0);
  151. _defineProperty(_assertThisInitialized(_this), "_onCopy", void 0);
  152. _defineProperty(_assertThisInitialized(_this), "_onCut", void 0);
  153. _defineProperty(_assertThisInitialized(_this), "_onDragEnd", void 0);
  154. _defineProperty(_assertThisInitialized(_this), "_onDragOver", void 0);
  155. _defineProperty(_assertThisInitialized(_this), "_onDragStart", void 0);
  156. _defineProperty(_assertThisInitialized(_this), "_onDrop", void 0);
  157. _defineProperty(_assertThisInitialized(_this), "_onInput", void 0);
  158. _defineProperty(_assertThisInitialized(_this), "_onFocus", void 0);
  159. _defineProperty(_assertThisInitialized(_this), "_onKeyDown", void 0);
  160. _defineProperty(_assertThisInitialized(_this), "_onKeyPress", void 0);
  161. _defineProperty(_assertThisInitialized(_this), "_onKeyUp", void 0);
  162. _defineProperty(_assertThisInitialized(_this), "_onMouseDown", void 0);
  163. _defineProperty(_assertThisInitialized(_this), "_onMouseUp", void 0);
  164. _defineProperty(_assertThisInitialized(_this), "_onPaste", void 0);
  165. _defineProperty(_assertThisInitialized(_this), "_onSelect", void 0);
  166. _defineProperty(_assertThisInitialized(_this), "editor", void 0);
  167. _defineProperty(_assertThisInitialized(_this), "editorContainer", void 0);
  168. _defineProperty(_assertThisInitialized(_this), "focus", void 0);
  169. _defineProperty(_assertThisInitialized(_this), "blur", void 0);
  170. _defineProperty(_assertThisInitialized(_this), "setMode", void 0);
  171. _defineProperty(_assertThisInitialized(_this), "exitCurrentMode", void 0);
  172. _defineProperty(_assertThisInitialized(_this), "restoreEditorDOM", void 0);
  173. _defineProperty(_assertThisInitialized(_this), "setClipboard", void 0);
  174. _defineProperty(_assertThisInitialized(_this), "getClipboard", void 0);
  175. _defineProperty(_assertThisInitialized(_this), "getEditorKey", void 0);
  176. _defineProperty(_assertThisInitialized(_this), "update", void 0);
  177. _defineProperty(_assertThisInitialized(_this), "onDragEnter", void 0);
  178. _defineProperty(_assertThisInitialized(_this), "onDragLeave", void 0);
  179. _defineProperty(_assertThisInitialized(_this), "_handleEditorContainerRef", function (node) {
  180. _this.editorContainer = node; // Instead of having a direct ref on the child, we'll grab it here.
  181. // This is safe as long as the rendered structure is static (which it is).
  182. // This lets the child support ref={props.editorRef} without merging refs.
  183. _this.editor = node !== null ? node.firstChild : null;
  184. });
  185. _defineProperty(_assertThisInitialized(_this), "focus", function (scrollPosition) {
  186. var editorState = _this.props.editorState;
  187. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  188. var editorNode = _this.editor;
  189. if (!editorNode) {
  190. // once in a while people call 'focus' in a setTimeout, and the node has
  191. // been deleted, so it can be null in that case.
  192. return;
  193. }
  194. var scrollParent = Style.getScrollParent(editorNode);
  195. var _ref = scrollPosition || getScrollPosition(scrollParent),
  196. x = _ref.x,
  197. y = _ref.y;
  198. !isHTMLElement(editorNode) ? process.env.NODE_ENV !== "production" ? invariant(false, 'editorNode is not an HTMLElement') : invariant(false) : void 0;
  199. editorNode.focus(); // Restore scroll position
  200. if (scrollParent === window) {
  201. window.scrollTo(x, y);
  202. } else {
  203. Scroll.setTop(scrollParent, y);
  204. } // On Chrome and Safari, calling focus on contenteditable focuses the
  205. // cursor at the first character. This is something you don't expect when
  206. // you're clicking on an input element but not directly on a character.
  207. // Put the cursor back where it was before the blur.
  208. if (!alreadyHasFocus) {
  209. _this.update(EditorState.forceSelection(editorState, editorState.getSelection()));
  210. }
  211. });
  212. _defineProperty(_assertThisInitialized(_this), "blur", function () {
  213. var editorNode = _this.editor;
  214. if (!editorNode) {
  215. return;
  216. }
  217. !isHTMLElement(editorNode) ? process.env.NODE_ENV !== "production" ? invariant(false, 'editorNode is not an HTMLElement') : invariant(false) : void 0;
  218. editorNode.blur();
  219. });
  220. _defineProperty(_assertThisInitialized(_this), "setMode", function (mode) {
  221. var _this$props = _this.props,
  222. onPaste = _this$props.onPaste,
  223. onCut = _this$props.onCut,
  224. onCopy = _this$props.onCopy;
  225. var editHandler = _objectSpread({}, handlerMap.edit);
  226. if (onPaste) {
  227. /* $FlowFixMe(>=0.117.0 site=www) This comment suppresses an error found
  228. * when Flow v0.117 was deployed. To see the error delete this comment
  229. * and run Flow. */
  230. editHandler.onPaste = onPaste;
  231. }
  232. if (onCut) {
  233. editHandler.onCut = onCut;
  234. }
  235. if (onCopy) {
  236. editHandler.onCopy = onCopy;
  237. }
  238. var handler = _objectSpread({}, handlerMap, {
  239. edit: editHandler
  240. });
  241. _this._handler = handler[mode];
  242. });
  243. _defineProperty(_assertThisInitialized(_this), "exitCurrentMode", function () {
  244. _this.setMode('edit');
  245. });
  246. _defineProperty(_assertThisInitialized(_this), "restoreEditorDOM", function (scrollPosition) {
  247. _this.setState({
  248. contentsKey: _this.state.contentsKey + 1
  249. }, function () {
  250. _this.focus(scrollPosition);
  251. });
  252. });
  253. _defineProperty(_assertThisInitialized(_this), "setClipboard", function (clipboard) {
  254. _this._clipboard = clipboard;
  255. });
  256. _defineProperty(_assertThisInitialized(_this), "getClipboard", function () {
  257. return _this._clipboard;
  258. });
  259. _defineProperty(_assertThisInitialized(_this), "update", function (editorState) {
  260. _this._latestEditorState = editorState;
  261. _this.props.onChange(editorState);
  262. });
  263. _defineProperty(_assertThisInitialized(_this), "onDragEnter", function () {
  264. _this._dragCount++;
  265. });
  266. _defineProperty(_assertThisInitialized(_this), "onDragLeave", function () {
  267. _this._dragCount--;
  268. if (_this._dragCount === 0) {
  269. _this.exitCurrentMode();
  270. }
  271. });
  272. _this._blockSelectEvents = false;
  273. _this._clipboard = null;
  274. _this._handler = null;
  275. _this._dragCount = 0;
  276. _this._editorKey = props.editorKey || generateRandomKey();
  277. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  278. _this._latestEditorState = props.editorState;
  279. _this._latestCommittedEditorState = props.editorState;
  280. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  281. _this._onBlur = _this._buildHandler('onBlur');
  282. _this._onCharacterData = _this._buildHandler('onCharacterData');
  283. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  284. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  285. _this._onCopy = _this._buildHandler('onCopy');
  286. _this._onCut = _this._buildHandler('onCut');
  287. _this._onDragEnd = _this._buildHandler('onDragEnd');
  288. _this._onDragOver = _this._buildHandler('onDragOver');
  289. _this._onDragStart = _this._buildHandler('onDragStart');
  290. _this._onDrop = _this._buildHandler('onDrop');
  291. _this._onInput = _this._buildHandler('onInput');
  292. _this._onFocus = _this._buildHandler('onFocus');
  293. _this._onKeyDown = _this._buildHandler('onKeyDown');
  294. _this._onKeyPress = _this._buildHandler('onKeyPress');
  295. _this._onKeyUp = _this._buildHandler('onKeyUp');
  296. _this._onMouseDown = _this._buildHandler('onMouseDown');
  297. _this._onMouseUp = _this._buildHandler('onMouseUp');
  298. _this._onPaste = _this._buildHandler('onPaste');
  299. _this._onSelect = _this._buildHandler('onSelect');
  300. _this.getEditorKey = function () {
  301. return _this._editorKey;
  302. };
  303. if (process.env.NODE_ENV !== "production") {
  304. ['onDownArrow', 'onEscape', 'onLeftArrow', 'onRightArrow', 'onTab', 'onUpArrow'].forEach(function (propName) {
  305. if (props.hasOwnProperty(propName)) {
  306. // eslint-disable-next-line no-console
  307. console.warn("Supplying an `".concat(propName, "` prop to `DraftEditor` has ") + 'been deprecated. If your handler needs access to the keyboard ' + 'event, supply a custom `keyBindingFn` prop that falls back to ' + 'the default one (eg. https://is.gd/wHKQ3W).');
  308. }
  309. });
  310. } // See `restoreEditorDOM()`.
  311. _this.state = {
  312. contentsKey: 0
  313. };
  314. return _this;
  315. }
  316. /**
  317. * Build a method that will pass the event to the specified handler method.
  318. * This allows us to look up the correct handler function for the current
  319. * editor mode, if any has been specified.
  320. */
  321. var _proto2 = DraftEditor.prototype;
  322. _proto2._buildHandler = function _buildHandler(eventName) {
  323. var _this2 = this;
  324. // Wrap event handlers in `flushControlled`. In sync mode, this is
  325. // effectively a no-op. In async mode, this ensures all updates scheduled
  326. // inside the handler are flushed before React yields to the browser.
  327. return function (e) {
  328. if (!_this2.props.readOnly) {
  329. var method = _this2._handler && _this2._handler[eventName];
  330. if (method) {
  331. if (flushControlled) {
  332. flushControlled(function () {
  333. return method(_this2, e);
  334. });
  335. } else {
  336. method(_this2, e);
  337. }
  338. }
  339. }
  340. };
  341. };
  342. _proto2._showPlaceholder = function _showPlaceholder() {
  343. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  344. };
  345. _proto2._renderPlaceholder = function _renderPlaceholder() {
  346. if (this._showPlaceholder()) {
  347. var placeHolderProps = {
  348. text: nullthrows(this.props.placeholder),
  349. editorState: this.props.editorState,
  350. textAlignment: this.props.textAlignment,
  351. accessibilityID: this._placeholderAccessibilityID
  352. };
  353. /* $FlowFixMe(>=0.112.0 site=www,mobile) This comment suppresses an error
  354. * found when Flow v0.112 was deployed. To see the error delete this
  355. * comment and run Flow. */
  356. return React.createElement(DraftEditorPlaceholder, placeHolderProps);
  357. }
  358. return null;
  359. };
  360. _proto2.render = function render() {
  361. var _this$props2 = this.props,
  362. blockRenderMap = _this$props2.blockRenderMap,
  363. blockRendererFn = _this$props2.blockRendererFn,
  364. blockStyleFn = _this$props2.blockStyleFn,
  365. customStyleFn = _this$props2.customStyleFn,
  366. customStyleMap = _this$props2.customStyleMap,
  367. editorState = _this$props2.editorState,
  368. preventScroll = _this$props2.preventScroll,
  369. readOnly = _this$props2.readOnly,
  370. textAlignment = _this$props2.textAlignment,
  371. textDirectionality = _this$props2.textDirectionality;
  372. var rootClass = cx({
  373. 'DraftEditor/root': true,
  374. 'DraftEditor/alignLeft': textAlignment === 'left',
  375. 'DraftEditor/alignRight': textAlignment === 'right',
  376. 'DraftEditor/alignCenter': textAlignment === 'center'
  377. });
  378. var contentStyle = {
  379. outline: 'none',
  380. // fix parent-draggable Safari bug. #1326
  381. userSelect: 'text',
  382. WebkitUserSelect: 'text',
  383. whiteSpace: 'pre-wrap',
  384. wordWrap: 'break-word'
  385. }; // The aria-expanded and aria-haspopup properties should only be rendered
  386. // for a combobox.
  387. /* $FlowFixMe(>=0.68.0 site=www,mobile) This comment suppresses an error
  388. * found when Flow v0.68 was deployed. To see the error delete this comment
  389. * and run Flow. */
  390. var ariaRole = this.props.role || 'textbox';
  391. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  392. var editorContentsProps = {
  393. blockRenderMap: blockRenderMap,
  394. blockRendererFn: blockRendererFn,
  395. blockStyleFn: blockStyleFn,
  396. customStyleMap: _objectSpread({}, DefaultDraftInlineStyle, customStyleMap),
  397. customStyleFn: customStyleFn,
  398. editorKey: this._editorKey,
  399. editorState: editorState,
  400. preventScroll: preventScroll,
  401. textDirectionality: textDirectionality
  402. };
  403. return React.createElement("div", {
  404. className: rootClass
  405. }, this._renderPlaceholder(), React.createElement("div", {
  406. className: cx('DraftEditor/editorContainer'),
  407. ref: this._handleEditorContainerRef
  408. }, React.createElement("div", {
  409. "aria-activedescendant": readOnly ? null : this.props.ariaActiveDescendantID,
  410. "aria-autocomplete": readOnly ? null : this.props.ariaAutoComplete,
  411. "aria-controls": readOnly ? null : this.props.ariaControls,
  412. "aria-describedby": this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  413. "aria-expanded": readOnly ? null : ariaExpanded,
  414. "aria-label": this.props.ariaLabel,
  415. "aria-labelledby": this.props.ariaLabelledBy,
  416. "aria-multiline": this.props.ariaMultiline,
  417. "aria-owns": readOnly ? null : this.props.ariaOwneeID,
  418. autoCapitalize: this.props.autoCapitalize,
  419. autoComplete: this.props.autoComplete,
  420. autoCorrect: this.props.autoCorrect,
  421. className: cx({
  422. // Chrome's built-in translation feature mutates the DOM in ways
  423. // that Draft doesn't expect (ex: adding <font> tags inside
  424. // DraftEditorLeaf spans) and causes problems. We add notranslate
  425. // here which makes its autotranslation skip over this subtree.
  426. notranslate: !readOnly,
  427. 'public/DraftEditor/content': true
  428. }),
  429. contentEditable: !readOnly,
  430. "data-testid": this.props.webDriverTestID,
  431. onBeforeInput: this._onBeforeInput,
  432. onBlur: this._onBlur,
  433. onCompositionEnd: this._onCompositionEnd,
  434. onCompositionStart: this._onCompositionStart,
  435. onCopy: this._onCopy,
  436. onCut: this._onCut,
  437. onDragEnd: this._onDragEnd,
  438. onDragEnter: this.onDragEnter,
  439. onDragLeave: this.onDragLeave,
  440. onDragOver: this._onDragOver,
  441. onDragStart: this._onDragStart,
  442. onDrop: this._onDrop,
  443. onFocus: this._onFocus,
  444. onInput: this._onInput,
  445. onKeyDown: this._onKeyDown,
  446. onKeyPress: this._onKeyPress,
  447. onKeyUp: this._onKeyUp,
  448. onMouseUp: this._onMouseUp,
  449. onPaste: this._onPaste,
  450. onSelect: this._onSelect,
  451. ref: this.props.editorRef,
  452. role: readOnly ? null : ariaRole,
  453. spellCheck: allowSpellCheck && this.props.spellCheck,
  454. style: contentStyle,
  455. suppressContentEditableWarning: true,
  456. tabIndex: this.props.tabIndex
  457. }, React.createElement(UpdateDraftEditorFlags, {
  458. editor: this,
  459. editorState: editorState
  460. }), React.createElement(DraftEditorContents, _extends({}, editorContentsProps, {
  461. key: 'contents' + this.state.contentsKey
  462. })))));
  463. };
  464. _proto2.componentDidMount = function componentDidMount() {
  465. this._blockSelectEvents = false;
  466. if (!didInitODS && gkx('draft_ods_enabled')) {
  467. didInitODS = true;
  468. DraftEffects.initODS();
  469. }
  470. this.setMode('edit');
  471. /**
  472. * IE has a hardcoded "feature" that attempts to convert link text into
  473. * anchors in contentEditable DOM. This breaks the editor's expectations of
  474. * the DOM, and control is lost. Disable it to make IE behave.
  475. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  476. * ie9-beta-minor-change-list.aspx
  477. */
  478. if (isIE) {
  479. // editor can be null after mounting
  480. // https://stackoverflow.com/questions/44074747/componentdidmount-called-before-ref-callback
  481. if (!this.editor) {
  482. global.execCommand('AutoUrlDetect', false, false);
  483. } else {
  484. this.editor.ownerDocument.execCommand('AutoUrlDetect', false, false);
  485. }
  486. }
  487. };
  488. _proto2.componentDidUpdate = function componentDidUpdate() {
  489. this._blockSelectEvents = false;
  490. this._latestEditorState = this.props.editorState;
  491. this._latestCommittedEditorState = this.props.editorState;
  492. }
  493. /**
  494. * Used via `this.focus()`.
  495. *
  496. * Force focus back onto the editor node.
  497. *
  498. * We attempt to preserve scroll position when focusing. You can also pass
  499. * a specified scroll position (for cases like `cut` behavior where it should
  500. * be restored to a known position).
  501. */
  502. ;
  503. return DraftEditor;
  504. }(React.Component);
  505. _defineProperty(DraftEditor, "defaultProps", {
  506. blockRenderMap: DefaultDraftBlockRenderMap,
  507. blockRendererFn: function blockRendererFn() {
  508. return null;
  509. },
  510. blockStyleFn: function blockStyleFn() {
  511. return '';
  512. },
  513. keyBindingFn: getDefaultKeyBinding,
  514. readOnly: false,
  515. spellCheck: false,
  516. stripPastedStyles: false
  517. });
  518. module.exports = DraftEditor;