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

46 строки
1.1 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
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type { BlockNodeRecord } from "./BlockNodeRecord";
  13. import type { EntityRange } from "./EntityRange";
  14. const DraftStringKey = require("./DraftStringKey");
  15. const UnicodeUtils = require("fbjs/lib/UnicodeUtils");
  16. const {
  17. strlen
  18. } = UnicodeUtils;
  19. /**
  20. * Convert to UTF-8 character counts for storage.
  21. */
  22. function encodeEntityRanges(block: BlockNodeRecord, storageMap: Object): Array<EntityRange> {
  23. const encoded = [];
  24. block.findEntityRanges(character => !!character.getEntity(), (
  25. /*number*/
  26. start,
  27. /*number*/
  28. end) => {
  29. const text = block.getText();
  30. const key = block.getEntityAt(start);
  31. encoded.push({
  32. offset: strlen(text.slice(0, start)),
  33. length: strlen(text.slice(start, end)),
  34. // Encode the key as a number for range storage.
  35. key: Number(storageMap[DraftStringKey.stringify(key)])
  36. });
  37. });
  38. return encoded;
  39. }
  40. module.exports = encodeEntityRanges;