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

DraftOffsetKey.js.flow 1.0 KiB

3 лет назад
123456789101112131415161718192021222324252627282930
  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 { DraftOffsetKeyPath } from "./DraftOffsetKeyPath";
  13. const KEY_DELIMITER = '-';
  14. const DraftOffsetKey = {
  15. encode: function (blockKey: string, decoratorKey: number, leafKey: number): string {
  16. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  17. },
  18. decode: function (offsetKey: string): DraftOffsetKeyPath {
  19. // Extracts the last two parts of offsetKey and captures the rest in blockKeyParts
  20. const [leafKey, decoratorKey, ...blockKeyParts] = offsetKey.split(KEY_DELIMITER).reverse();
  21. return {
  22. // Recomposes the parts of blockKey after reversing them
  23. blockKey: blockKeyParts.reverse().join(KEY_DELIMITER),
  24. decoratorKey: parseInt(decoratorKey, 10),
  25. leafKey: parseInt(leafKey, 10)
  26. };
  27. }
  28. };
  29. module.exports = DraftOffsetKey;