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

33 строки
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. *
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. var KEY_DELIMITER = '-';
  13. var DraftOffsetKey = {
  14. encode: function encode(blockKey, decoratorKey, leafKey) {
  15. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  16. },
  17. decode: function decode(offsetKey) {
  18. // Extracts the last two parts of offsetKey and captures the rest in blockKeyParts
  19. var _offsetKey$split$reve = offsetKey.split(KEY_DELIMITER).reverse(),
  20. leafKey = _offsetKey$split$reve[0],
  21. decoratorKey = _offsetKey$split$reve[1],
  22. blockKeyParts = _offsetKey$split$reve.slice(2);
  23. return {
  24. // Recomposes the parts of blockKey after reversing them
  25. blockKey: blockKeyParts.reverse().join(KEY_DELIMITER),
  26. decoratorKey: parseInt(decoratorKey, 10),
  27. leafKey: parseInt(leafKey, 10)
  28. };
  29. }
  30. };
  31. module.exports = DraftOffsetKey;