Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

encodeEntityRanges.js 1.0 KiB

3 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 DraftStringKey = require("./DraftStringKey");
  13. var UnicodeUtils = require("fbjs/lib/UnicodeUtils");
  14. var strlen = UnicodeUtils.strlen;
  15. /**
  16. * Convert to UTF-8 character counts for storage.
  17. */
  18. function encodeEntityRanges(block, storageMap) {
  19. var encoded = [];
  20. block.findEntityRanges(function (character) {
  21. return !!character.getEntity();
  22. }, function (
  23. /*number*/
  24. start,
  25. /*number*/
  26. end) {
  27. var text = block.getText();
  28. var key = block.getEntityAt(start);
  29. encoded.push({
  30. offset: strlen(text.slice(0, start)),
  31. length: strlen(text.slice(start, end)),
  32. // Encode the key as a number for range storage.
  33. key: Number(storageMap[DraftStringKey.stringify(key)])
  34. });
  35. });
  36. return encoded;
  37. }
  38. module.exports = encodeEntityRanges;