Skip to content

Commit 4433a0c

Browse files
committed
restore collapse status
1 parent db0d5e0 commit 4433a0c

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

assets/js/hooks2/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "./tree";
55

66
import { toggleCollapse } from "./node";
7+
import { restoreCollapsedStatus } from "./store";
78

89
import { DomContainer } from "./types";
910

@@ -15,6 +16,7 @@ export const Hooks = {
1516
container.addEventListener("toggle_collapse", toggleCollapse);
1617

1718
moveHtmlChildNodesToDataPosition(container);
19+
restoreCollapsedStatus(container);
1820
setCursorToEndOfFirstChildNode(container);
1921
},
2022
//updated() {},

assets/js/hooks2/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function getDomNodeById(uuid: UUID | undefined) {
3535
return document.getElementById(`nodes-form-${uuid}`) as DomNode | null;
3636
}
3737

38-
function getDataNodeFromDomNode(node: DomNode): DataNode {
38+
export function getDataNodeFromDomNode(node: DomNode): DataNode {
3939
const uuid = getUUID(node);
4040
const parent_id = getAttribute(node, "parent");
4141
const prev_id = getAttribute(node, "prev");

assets/js/hooks2/store.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { UUID } from "./types";
1+
import { getDataNodeFromDomNode } from "./node";
2+
import { DomContainer, DomNode, UUID } from "./types";
3+
4+
export function restoreCollapsedStatus(container: DomContainer) {
5+
const status = loadCollapsedStatus(container.id);
6+
7+
container.querySelectorAll(".node").forEach((node) => {
8+
const { uuid } = getDataNodeFromDomNode(node as DomNode);
9+
status[uuid] && node.classList.add("collapsed");
10+
});
11+
}
212

313
export function saveCollapseStatus(id: string, uuid: UUID, collapsed: boolean) {
414
const status = loadCollapsedStatus(id);

assets/js/hooks2/tree/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ export function moveHtmlChildNodesToDataPosition(container: DomContainer) {
88
moveDomNodeToDataPosition(node as DomNode);
99
});
1010
}
11-

0 commit comments

Comments
 (0)