MCPcopy
hub / github.com/udecode/plate / buildToggleIndex

Function buildToggleIndex

packages/toggle/src/react/toggleIndexAtom.ts:21–47  ·  view source on GitHub ↗
(elements: any[])

Source from the content-addressed store, hash-verified

19
20// Returns, for each child, the enclosing toggle ids
21export const buildToggleIndex = (elements: any[]): Map<string, string[]> => {
22 const result = new Map<string, string[]>();
23 let currentEnclosingToggles: [string, number][] = []; // [toggleId, indent][]
24 elements.forEach((element: any) => {
25 const elementIndent = (element[KEYS.indent] as number) || 0;
26 // For some reason, indent lists have a min indent of 1, even though they are not indented
27 const elementIndentWithListCorrection =
28 element[ListPluginKey] && element[KEYS.indent]
29 ? elementIndent - 1
30 : elementIndent;
31
32 const enclosingToggles = currentEnclosingToggles.filter(
33 ([_, indent]) => indent < elementIndentWithListCorrection
34 );
35 currentEnclosingToggles = enclosingToggles;
36 result.set(
37 element.id as string,
38 enclosingToggles.map(([toggleId]) => toggleId)
39 );
40
41 if (element.type === KEYS.toggle) {
42 currentEnclosingToggles.push([element.id as string, elementIndent]);
43 }
44 });
45
46 return result;
47};
48
49export const editorAtom = plateStore.atom.trackedEditor as Atom<{
50 editor: { children: TIndentElement[] };

Callers 3

toggleIndexAtom.tsFile · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…