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

3 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940
  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. * @flow
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. /**
  13. * Get offset key from a node or it's child nodes. Return the first offset key
  14. * found on the DOM tree of given node.
  15. */
  16. const isElement = require("./isElement");
  17. function getSelectionOffsetKeyForNode(node: Node): ?string {
  18. if (isElement(node)) {
  19. const castedNode: Element = (node: any);
  20. const offsetKey = castedNode.getAttribute('data-offset-key');
  21. if (offsetKey) {
  22. return offsetKey;
  23. }
  24. for (let ii = 0; ii < castedNode.childNodes.length; ii++) {
  25. const childOffsetKey = getSelectionOffsetKeyForNode(castedNode.childNodes[ii]);
  26. if (childOffsetKey) {
  27. return childOffsetKey;
  28. }
  29. }
  30. }
  31. return null;
  32. }
  33. module.exports = getSelectionOffsetKeyForNode;