@atolis-hq/corum 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/web/app.jsx +59 -13
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -83,23 +83,63 @@ function NavRail({ activeSection, onSection, debugMode, onDebugMode }) {
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function entryKey(entry) {
|
|
87
|
+
return entry.kind === 'group' ? entry.groupTemplateName : entry.templateName;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds }) {
|
|
87
91
|
const sortedComponents = [...navTree.keys()].sort((a, b) => a.localeCompare(b));
|
|
88
92
|
const [openComponent, setOpenComponent] = useState();
|
|
93
|
+
const [openEntryKeys, setOpenEntryKeys] = useState(new Set());
|
|
89
94
|
const templateMap = new Map(templates.map(template => [template.name, template]));
|
|
90
95
|
|
|
96
|
+
function openComponentWithEntries(component) {
|
|
97
|
+
setOpenComponent(component);
|
|
98
|
+
if (!component) { setOpenEntryKeys(new Set()); return; }
|
|
99
|
+
const entries = navTree.get(component) ?? [];
|
|
100
|
+
setOpenEntryKeys(entries.length === 1 ? new Set([entryKey(entries[0])]) : new Set());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Initialise / recover openComponent when the tree first loads or the open component disappears.
|
|
91
104
|
useEffect(() => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (openComponent !== null && !navTree.has(openComponent)) {
|
|
97
|
-
setOpenComponent(sortedComponents[0] ?? null);
|
|
98
|
-
}
|
|
105
|
+
const autoOpen = sortedComponents.length === 1 ? sortedComponents[0] : null;
|
|
106
|
+
if (openComponent === undefined) { openComponentWithEntries(autoOpen); return; }
|
|
107
|
+
if (openComponent !== null && !navTree.has(openComponent)) { openComponentWithEntries(autoOpen); }
|
|
99
108
|
}, [navTree, openComponent, sortedComponents]);
|
|
100
109
|
|
|
110
|
+
// When navigating directly to a node (e.g. via link), open its component and entry.
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!activeNodeId || !navTree.size) return;
|
|
113
|
+
for (const [component, entries] of navTree.entries()) {
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const eKey = entryKey(entry);
|
|
116
|
+
let found = false;
|
|
117
|
+
if (entry.kind === 'group') {
|
|
118
|
+
found = entry.children.some(child => child.nodes.some(n => n.id === activeNodeId));
|
|
119
|
+
} else {
|
|
120
|
+
found = entry.nodes.some(n => n.id === activeNodeId) ||
|
|
121
|
+
entry.nodes.some(n => (n.navChildren ?? []).some(g => g.nodes.some(c => c.id === activeNodeId)));
|
|
122
|
+
}
|
|
123
|
+
if (found) {
|
|
124
|
+
setOpenComponent(component);
|
|
125
|
+
setOpenEntryKeys(new Set([eKey]));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, [activeNodeId, navTree]);
|
|
131
|
+
|
|
101
132
|
function toggleComponent(component) {
|
|
102
|
-
|
|
133
|
+
if (openComponent === component) { openComponentWithEntries(null); }
|
|
134
|
+
else { openComponentWithEntries(component); }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function toggleEntry(key) {
|
|
138
|
+
setOpenEntryKeys(prev => {
|
|
139
|
+
const next = new Set(prev);
|
|
140
|
+
if (next.has(key)) next.delete(key); else next.add(key);
|
|
141
|
+
return next;
|
|
142
|
+
});
|
|
103
143
|
}
|
|
104
144
|
|
|
105
145
|
if (navTree.size === 0) {
|
|
@@ -118,9 +158,11 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
118
158
|
</div>
|
|
119
159
|
{openComponent === component && entries.map(entry => {
|
|
120
160
|
if (entry.kind === 'group') {
|
|
161
|
+
const gKey = entryKey(entry);
|
|
162
|
+
const gOpen = openEntryKeys.has(gKey);
|
|
121
163
|
return (
|
|
122
164
|
<div key={entry.groupTemplateName}>
|
|
123
|
-
<div className="nav-template-head">
|
|
165
|
+
<div className="nav-template-head" onClick={() => toggleEntry(gKey)} style={{ cursor: 'pointer' }}>
|
|
124
166
|
{entry.icon && (
|
|
125
167
|
<i
|
|
126
168
|
className={`fa-solid fa-${entry.icon}`}
|
|
@@ -128,8 +170,9 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
128
170
|
/>
|
|
129
171
|
)}
|
|
130
172
|
<span>{entry.label}</span>
|
|
173
|
+
<Icon name={gOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
131
174
|
</div>
|
|
132
|
-
{entry.children.map(child => (
|
|
175
|
+
{gOpen && entry.children.map(child => (
|
|
133
176
|
<div key={child.templateName}>
|
|
134
177
|
<div className="nav-subtype-head">
|
|
135
178
|
{child.icon && (
|
|
@@ -167,16 +210,19 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
167
210
|
|
|
168
211
|
const template = templateMap.get(entry.templateName);
|
|
169
212
|
const colour = template?.ui?.colour ?? 'var(--ink-4)';
|
|
213
|
+
const tKey = entryKey(entry);
|
|
214
|
+
const tOpen = openEntryKeys.has(tKey);
|
|
170
215
|
return (
|
|
171
216
|
<div key={entry.templateName}>
|
|
172
|
-
<div className="nav-template-head">
|
|
217
|
+
<div className="nav-template-head" onClick={() => toggleEntry(tKey)} style={{ cursor: 'pointer' }}>
|
|
173
218
|
<i
|
|
174
219
|
className={`fa-solid fa-${template?.ui?.icon ?? 'circle'}`}
|
|
175
220
|
style={{ fontSize: 12, width: 14, textAlign: 'center', flexShrink: 0 }}
|
|
176
221
|
/>
|
|
177
222
|
<span>{templateDisplayName(template)}</span>
|
|
223
|
+
<Icon name={tOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
178
224
|
</div>
|
|
179
|
-
{entry.nodes.map(node => {
|
|
225
|
+
{tOpen && entry.nodes.map(node => {
|
|
180
226
|
const isActive = node.id === activeNodeId;
|
|
181
227
|
return (
|
|
182
228
|
<div key={node.id}>
|
|
@@ -626,7 +672,7 @@ function App() {
|
|
|
626
672
|
|
|
627
673
|
const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
|
|
628
674
|
const activeSection = activeNodeId ? 'components' : (route.pathname.slice(1) || 'dashboard');
|
|
629
|
-
const navTree = buildNavTree(nodes, templates);
|
|
675
|
+
const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
|
|
630
676
|
const showTree = activeSection === 'components' || activeNodeId;
|
|
631
677
|
const activeOverlayRefs = useMemo(() =>
|
|
632
678
|
overlayMode === 'single' ? [] :
|