Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

getNextDelimiterBlockKey.js.flow 1.4 KiB

3 lat temu
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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
  9. * @emails oncall+draft_js
  10. *
  11. * This is unstable and not part of the public API and should not be used by
  12. * production systems. This file may be update/removed without notice.
  13. */
  14. import type { BlockMap } from "./BlockMap";
  15. import type { BlockNodeRecord } from "./BlockNodeRecord";
  16. const ContentBlockNode = require("./ContentBlockNode");
  17. const getNextDelimiterBlockKey = (block: BlockNodeRecord, blockMap: BlockMap): ?string => {
  18. const isExperimentalTreeBlock = block instanceof ContentBlockNode;
  19. if (!isExperimentalTreeBlock) {
  20. return null;
  21. }
  22. const nextSiblingKey = block.getNextSiblingKey();
  23. if (nextSiblingKey) {
  24. return nextSiblingKey;
  25. }
  26. const parent = block.getParentKey();
  27. if (!parent) {
  28. return null;
  29. }
  30. let nextNonDescendantBlock = blockMap.get(parent);
  31. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  32. const parentKey = nextNonDescendantBlock.getParentKey();
  33. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  34. }
  35. if (!nextNonDescendantBlock) {
  36. return null;
  37. }
  38. return nextNonDescendantBlock.getNextSiblingKey();
  39. };
  40. module.exports = getNextDelimiterBlockKey;