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

39 строки
1.3 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 applyEntityToContentBlock = require("./applyEntityToContentBlock");
  13. var Immutable = require("immutable");
  14. function applyEntityToContentState(contentState, selectionState, entityKey) {
  15. var blockMap = contentState.getBlockMap();
  16. var startKey = selectionState.getStartKey();
  17. var startOffset = selectionState.getStartOffset();
  18. var endKey = selectionState.getEndKey();
  19. var endOffset = selectionState.getEndOffset();
  20. var newBlocks = blockMap.skipUntil(function (_, k) {
  21. return k === startKey;
  22. }).takeUntil(function (_, k) {
  23. return k === endKey;
  24. }).toOrderedMap().merge(Immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  25. var sliceStart = blockKey === startKey ? startOffset : 0;
  26. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  27. return applyEntityToContentBlock(block, sliceStart, sliceEnd, entityKey);
  28. });
  29. return contentState.merge({
  30. blockMap: blockMap.merge(newBlocks),
  31. selectionBefore: selectionState,
  32. selectionAfter: selectionState
  33. });
  34. }
  35. module.exports = applyEntityToContentState;