Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

39 рядки
1.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. * @flow strict-local
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type { BlockNodeRecord } from "./BlockNodeRecord";
  13. import type { DraftRange } from "./DraftRange";
  14. const invariant = require("fbjs/lib/invariant");
  15. /**
  16. * Obtain the start and end positions of the range that has the
  17. * specified entity applied to it.
  18. *
  19. * Entity keys are applied only to contiguous stretches of text, so this
  20. * method searches for the first instance of the entity key and returns
  21. * the subsequent range.
  22. */
  23. function getRangesForDraftEntity(block: BlockNodeRecord, key: string): Array<DraftRange> {
  24. const ranges = [];
  25. block.findEntityRanges(c => c.getEntity() === key, (start, end) => {
  26. ranges.push({
  27. start,
  28. end
  29. });
  30. });
  31. invariant(!!ranges.length, 'Entity key not found in this range.');
  32. return ranges;
  33. }
  34. module.exports = getRangesForDraftEntity;