Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit 767108d

Browse files
committed
create tree
1 parent a7365fe commit 767108d

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lodash": "^4.17.21",
2525
"lucide-react": "^0.292.0",
2626
"pako": "^2.1.0",
27+
"performant-array-to-tree": "^1.11.0",
2728
"python-struct": "^1.1.3",
2829
"react": "^18.2.0",
2930
"react-dom": "^18.2.0",

pnpm-lock.yaml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/EditorPane.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const EditorPane = () => {
2+
return <></>;
3+
};

src/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './Data';
2+
export * from './EditorPane';
23
export * from './Section';
34
export * from './Status';
45
export * from './editor';

src/utils/createNodeChangTree.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { GUID, NodeChange } from '../kiwi/schema';
1+
import { arrayToTree } from 'performant-array-to-tree';
2+
import { NodeChange } from '../kiwi/schema';
23

34
export const asciiToInt = (ascii: string) => {
45
var sum = 0;
@@ -9,11 +10,19 @@ export const asciiToInt = (ascii: string) => {
910
return sum;
1011
};
1112

12-
type EditorNode = {
13-
parentNodeGUID: GUID;
14-
childrenNodeGUIDs: GUID[];
15-
};
16-
17-
export const createNodeChangTree = (nodeChanges: NodeChange[]) => {
18-
return;
13+
export const createNodeChangeTree = (nodeChanges: NodeChange[]) => {
14+
const nodes = nodeChanges.map((c, i) => {
15+
const id = `${c.guid?.sessionID}-${c.guid?.localID}`;
16+
let parentId = null;
17+
if (c.parentIndex) {
18+
parentId = `${c.parentIndex?.guid?.sessionID}-${c.parentIndex?.guid?.localID}`;
19+
}
20+
return {
21+
id: id,
22+
parentId: parentId,
23+
index: i,
24+
};
25+
});
26+
const tree = arrayToTree(nodes);
27+
return tree;
1928
};

0 commit comments

Comments
 (0)