MCPcopy Index your code
hub / github.com/triggerdotdev/jsonhero-web / JsonColumnViewProvider

Function JsonColumnViewProvider

app/hooks/useJsonColumnView.tsx:32–173  ·  view source on GitHub ↗
({ children }: { children: ReactNode })

Source from the content-addressed store, hash-verified

30);
31
32export function JsonColumnViewProvider({ children }: { children: ReactNode }) {
33 const [json] = useJson();
34 const { doc, path: initialNodeId } = useJsonDoc();
35
36 const rootNode = React.useMemo(() => {
37 return generateColumnViewNode(json);
38 }, [json]);
39
40 const jsonReducer = React.useCallback(
41 (
42 state: ColumnViewState,
43 action: ColumnViewAction,
44 changes: ColumnViewState
45 ): ColumnViewState => {
46 if (action.type === "MOVE_UP" || action.type == "MOVE_DOWN") {
47 const { selectedNodeId } = state;
48 const { highlightedNodeId } = changes;
49
50 invariant(selectedNodeId, "expected selectedNodeId");
51 invariant(highlightedNodeId, "expected highlightedNodeId");
52
53 const calculatedPath = calculateStablePath(
54 selectedNodeId,
55 highlightedNodeId,
56 json
57 );
58
59 return {
60 ...changes,
61 selectedNodeId: calculatedPath,
62 };
63 }
64
65 if (
66 action.type === "MOVE_TO_PARENT" &&
67 action.source &&
68 action.source.altKey
69 ) {
70 const { selectedNodeId } = state;
71
72 return {
73 ...changes,
74 selectedNodeId,
75 };
76 }
77
78 if (action.type === "MOVE_TO_CHILDREN") {
79 const { selectedNodeId, highlightedNodeId } = state;
80
81 invariant(selectedNodeId, "expected selectedNodeId");
82 invariant(highlightedNodeId, "expected highlightedNodeId");
83
84 // If the previous highlightedNodeId is an ancestor of the previous selectedNodeId
85 if (isAncestorOf(highlightedNodeId, selectedNodeId)) {
86 // Get the next child of the highlightedNodeId in the path of selectedNodeId
87 // And make the highlightedNodeId that next child
88 // And keep the selectedNodeId unchanged
89 const highlightedPath = new JSONHeroPath(highlightedNodeId);

Callers

nothing calls this directly

Calls 7

useJsonFunction · 0.90
useJsonDocFunction · 0.90
generateColumnViewNodeFunction · 0.90
calculateStablePathFunction · 0.90
firstChildToDescendantFunction · 0.90
useColumnViewFunction · 0.90
isAncestorOfFunction · 0.85

Tested by

no test coverage detected