Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

54 rindas
1.9 KiB

  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. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. var EditorState = require("./EditorState");
  13. var containsNode = require("fbjs/lib/containsNode");
  14. var getActiveElement = require("fbjs/lib/getActiveElement");
  15. function editOnBlur(editor, e) {
  16. // In a contentEditable element, when you select a range and then click
  17. // another active element, this does trigger a `blur` event but will not
  18. // remove the DOM selection from the contenteditable.
  19. // This is consistent across all browsers, but we prefer that the editor
  20. // behave like a textarea, where a `blur` event clears the DOM selection.
  21. // We therefore force the issue to be certain, checking whether the active
  22. // element is `body` to force it when blurring occurs within the window (as
  23. // opposed to clicking to another tab or window).
  24. var ownerDocument = e.currentTarget.ownerDocument;
  25. if ( // This ESLint rule conflicts with `sketchy-null-bool` flow check
  26. // eslint-disable-next-line no-extra-boolean-cast
  27. !Boolean(editor.props.preserveSelectionOnBlur) && getActiveElement(ownerDocument) === ownerDocument.body) {
  28. var _selection = ownerDocument.defaultView.getSelection();
  29. var editorNode = editor.editor;
  30. if (_selection.rangeCount === 1 && containsNode(editorNode, _selection.anchorNode) && containsNode(editorNode, _selection.focusNode)) {
  31. _selection.removeAllRanges();
  32. }
  33. }
  34. var editorState = editor._latestEditorState;
  35. var currentSelection = editorState.getSelection();
  36. if (!currentSelection.getHasFocus()) {
  37. return;
  38. }
  39. var selection = currentSelection.set('hasFocus', false);
  40. editor.props.onBlur && editor.props.onBlur(e);
  41. editor.update(EditorState.acceptSelection(editorState, selection));
  42. }
  43. module.exports = editOnBlur;