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

3 лет назад
123456789101112131415161718192021222324252627282930313233
  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 ContentState from "./ContentState";
  13. import type SelectionState from "./SelectionState";
  14. function adjustBlockDepthForContentState(contentState: ContentState, selectionState: SelectionState, adjustment: number, maxDepth: number): ContentState {
  15. const startKey = selectionState.getStartKey();
  16. const endKey = selectionState.getEndKey();
  17. let blockMap = contentState.getBlockMap();
  18. const blocks = blockMap.toSeq().skipUntil((_, k) => k === startKey).takeUntil((_, k) => k === endKey).concat([[endKey, blockMap.get(endKey)]]).map(block => {
  19. let depth = block.getDepth() + adjustment;
  20. depth = Math.max(0, Math.min(depth, maxDepth));
  21. return block.set('depth', depth);
  22. });
  23. blockMap = blockMap.merge(blocks);
  24. return contentState.merge({
  25. blockMap,
  26. selectionBefore: selectionState,
  27. selectionAfter: selectionState
  28. });
  29. }
  30. module.exports = adjustBlockDepthForContentState;