Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

65 řádky
2.0 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 UserAgent = require("fbjs/lib/UserAgent");
  13. var invariant = require("fbjs/lib/invariant");
  14. var isChrome = UserAgent.isBrowser('Chrome'); // In Chrome, the client rects will include the entire bounds of all nodes that
  15. // begin (have a start tag) within the selection, even if the selection does
  16. // not overlap the entire node. To resolve this, we split the range at each
  17. // start tag and join the client rects together.
  18. // https://code.google.com/p/chromium/issues/detail?id=324437
  19. /* eslint-disable consistent-return */
  20. function getRangeClientRectsChrome(range) {
  21. var tempRange = range.cloneRange();
  22. var clientRects = [];
  23. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  24. // If we've climbed up to the common ancestor, we can now use the
  25. // original start point and stop climbing the tree.
  26. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  27. if (atCommonAncestor) {
  28. tempRange.setStart(range.startContainer, range.startOffset);
  29. } else {
  30. tempRange.setStart(tempRange.endContainer, 0);
  31. }
  32. var rects = Array.from(tempRange.getClientRects());
  33. clientRects.push(rects);
  34. if (atCommonAncestor) {
  35. var _ref;
  36. clientRects.reverse();
  37. return (_ref = []).concat.apply(_ref, clientRects);
  38. }
  39. tempRange.setEndBefore(ancestor);
  40. }
  41. !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant(false) : void 0;
  42. }
  43. /* eslint-enable consistent-return */
  44. /**
  45. * Like range.getClientRects() but normalizes for browser bugs.
  46. */
  47. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  48. return Array.from(range.getClientRects());
  49. };
  50. module.exports = getRangeClientRects;