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

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { DraftInlineStyle } from "./DraftInlineStyle";
  13. import type { InlineStyleRange } from "./InlineStyleRange";
  14. const UnicodeUtils = require("fbjs/lib/UnicodeUtils");
  15. const {
  16. OrderedSet
  17. } = require("immutable");
  18. const {
  19. substr
  20. } = UnicodeUtils;
  21. const EMPTY_SET = OrderedSet();
  22. /**
  23. * Convert to native JavaScript string lengths to determine ranges.
  24. */
  25. function decodeInlineStyleRanges(text: string, ranges?: Array<InlineStyleRange>): Array<DraftInlineStyle> {
  26. const styles = Array(text.length).fill(EMPTY_SET);
  27. if (ranges) {
  28. ranges.forEach(range => {
  29. let cursor = substr(text, 0, range.offset).length;
  30. const end = cursor + substr(text, range.offset, range.length).length;
  31. while (cursor < end) {
  32. styles[cursor] = styles[cursor].add(range.style);
  33. cursor++;
  34. }
  35. });
  36. }
  37. return styles;
  38. }
  39. module.exports = decodeInlineStyleRanges;