@atolis-hq/corum 0.1.24 → 0.1.26

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.
@@ -328,7 +328,6 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
328
328
  if (payloadSchemaName) {
329
329
  const globalId = sharedSchemas.get(payloadSchemaName);
330
330
  if (globalId) {
331
- emitReadsEdge(eventId, globalId, edges);
332
331
  properties.payload = globalId;
333
332
  }
334
333
  else {
@@ -387,12 +386,6 @@ function makeNode(template, component, specPath, id) {
387
386
  properties: {},
388
387
  };
389
388
  }
390
- function emitReadsEdge(from, to, edges) {
391
- const id = `${from}__reads__${to}`;
392
- if (!edges.some(e => e.id === id)) {
393
- edges.push({ id, from, to, type: 'reads', state: 'implemented', stability: 'unstable' });
394
- }
395
- }
396
389
  function refName(ref) {
397
390
  return ref.split('/').pop() ?? ref;
398
391
  }
@@ -407,13 +400,12 @@ function resolveAllOfRef(schema) {
407
400
  return s.allOf[0];
408
401
  return schema;
409
402
  }
410
- function resolveSchemaRef(schemaName, nullable, collection, readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
403
+ function resolveSchemaRef(schemaName, nullable, collection, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
411
404
  const extra = { nullable };
412
405
  if (collection)
413
406
  extra.collection = collection;
414
407
  const globalId = sharedSchemas.get(schemaName);
415
408
  if (globalId) {
416
- emitReadsEdge(readsSource, globalId, edges);
417
409
  return { $ref: globalId, ...extra };
418
410
  }
419
411
  if (localSchemas.has(schemaName))
@@ -482,7 +474,6 @@ function createMapping(mappingName, addlRaw, parentId, rootId, component, packCo
482
474
  return mappingId;
483
475
  }
484
476
  function emitFields(schema, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
485
- const readsSource = rootId ?? parentId;
486
477
  const [component] = parentId.split('.');
487
478
  for (const [fieldName, rawFieldSchema] of Object.entries(schema.properties ?? {})) {
488
479
  const resolvedSchemaId = componentSchemaIdOf(rawFieldSchema);
@@ -495,7 +486,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
495
486
  ? resolvedSchemaId
496
487
  : (isRefSchema(fieldSchema) ? refName(fieldSchema.$ref) : undefined);
497
488
  if (schemaName !== undefined) {
498
- fieldNode.properties = resolveSchemaRef(schemaName, !required, undefined, readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
489
+ fieldNode.properties = resolveSchemaRef(schemaName, !required, undefined, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
499
490
  }
500
491
  else {
501
492
  const fs = fieldSchema;
@@ -514,7 +505,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
514
505
  fieldNode.properties = { type: 'string', nullable, collection: 'array' };
515
506
  }
516
507
  else if (isRefSchema(items)) {
517
- fieldNode.properties = resolveSchemaRef(refName(items.$ref), nullable, 'array', readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
508
+ fieldNode.properties = resolveSchemaRef(refName(items.$ref), nullable, 'array', rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
518
509
  if (!fieldNode.properties.$ref)
519
510
  fieldNode.properties = { type: 'string', nullable, collection: 'array' };
520
511
  }
@@ -37,12 +37,6 @@ export function deriveNodeId(kind, component, name, parentId, section) {
37
37
  export function refName(ref) {
38
38
  return ref.split('/').pop() ?? ref;
39
39
  }
40
- function emitReadsEdge(from, to, edges) {
41
- const id = `${from}__reads__${to}`;
42
- if (!edges.some(e => e.id === id)) {
43
- edges.push({ id, from, to, type: 'reads', state: 'implemented', stability: 'unstable' });
44
- }
45
- }
46
40
  export function mapDocument(document, entry, packConfig, componentNameReplacements = []) {
47
41
  const nodes = [];
48
42
  const edges = [];
@@ -283,8 +277,6 @@ function emitSchemaNode(schema, name, parentId, section, rootId, packConfig, spe
283
277
  const schemaName = refName(schema.$ref);
284
278
  const globalId = sharedSchemas.get(schemaName);
285
279
  if (globalId) {
286
- if (rootId)
287
- emitReadsEdge(rootId, globalId, edges);
288
280
  return globalId;
289
281
  }
290
282
  if (localSchemas.has(schemaName))
@@ -311,13 +303,12 @@ function createInlineSchema(schema, name, parentId, section, rootId, packConfig,
311
303
  emitFields(schema, schemaId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
312
304
  return localRef;
313
305
  }
314
- function resolveFieldRef(schemaName, collection, required, rootId, readsSource, refSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
306
+ function resolveFieldRef(schemaName, collection, required, rootId, refSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
315
307
  const extra = { nullable: !required };
316
308
  if (collection !== 'one')
317
309
  extra.collection = collection;
318
310
  const globalId = sharedSchemas.get(schemaName);
319
311
  if (globalId) {
320
- emitReadsEdge(readsSource, globalId, edges);
321
312
  return { $ref: globalId, ...extra };
322
313
  }
323
314
  if (localSchemas.has(schemaName))
@@ -411,8 +402,6 @@ function createMapping(mappingName, addlRaw, parentId, rootId, packConfig, specP
411
402
  return mappingId;
412
403
  }
413
404
  function emitFields(schema, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
414
- // readsSource: when in endpoint context use rootId, otherwise use the schema itself
415
- const readsSource = rootId ?? parentId;
416
405
  for (const [fieldName, rawFieldSchema] of Object.entries(schema.properties ?? {})) {
417
406
  const fieldSchema = resolveAllOfRef(rawFieldSchema);
418
407
  const fieldId = deriveNodeId('field', undefined, fieldName, parentId, section);
@@ -420,7 +409,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
420
409
  const fieldNode = makeNode(packConfig.constructs.schemaProperty?.template ?? 'Field', component, specPath, fieldId);
421
410
  const required = Array.isArray(schema.required) && schema.required.includes(fieldName);
422
411
  if (isRefSchema(fieldSchema)) {
423
- fieldNode.properties = resolveFieldRef(refName(fieldSchema.$ref), 'one', required, rootId, readsSource, fieldSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
412
+ fieldNode.properties = resolveFieldRef(refName(fieldSchema.$ref), 'one', required, rootId, fieldSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
424
413
  }
425
414
  else {
426
415
  const fs = fieldSchema;
@@ -435,7 +424,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
435
424
  fieldNode.properties = { type: 'string', nullable: !required, collection: 'array' };
436
425
  }
437
426
  else if (isRefSchema(items)) {
438
- fieldNode.properties = resolveFieldRef(refName(items.$ref), 'array', required, rootId, readsSource, items, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
427
+ fieldNode.properties = resolveFieldRef(refName(items.$ref), 'array', required, rootId, items, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
439
428
  }
440
429
  else {
441
430
  const itemType = deriveScalarType(items.type ?? 'string', items.format, packConfig.scalarTypes);
@@ -38,11 +38,64 @@ export function loadClusters(content, templates, diagnostics) {
38
38
  properties: isRecord(record.properties) ? record.properties : {},
39
39
  };
40
40
  addNode(result, root, key, diagnostics);
41
- materialiseChildren(result, root, record, templates, key, diagnostics);
41
+ const rootTemplate = templates.get(root.template);
42
+ if (rootTemplate) {
43
+ for (const target of getNodeRefTargets(root, rootTemplate)) {
44
+ const readsId = `${root.id}__reads__${target}`;
45
+ const existingFrom = result.edgesByFrom.get(root.id) ?? [];
46
+ if (!existingFrom.some(e => e.id === readsId)) {
47
+ addEdge(result, {
48
+ id: readsId, from: root.id, to: target, type: 'reads',
49
+ state: root.state, stability: root.stability, generated: true,
50
+ });
51
+ }
52
+ }
53
+ }
54
+ materialiseChildren(result, root, root, record, templates, key, diagnostics);
42
55
  }
43
56
  return result;
44
57
  }
45
- function materialiseChildren(result, parent, source, templates, filePath, diagnostics) {
58
+ function getPropertySchemasFromTemplate(props) {
59
+ if (Array.isArray(props.allOf)) {
60
+ const merged = {};
61
+ for (const schema of props.allOf) {
62
+ Object.assign(merged, getPropertySchemasFromTemplate(schema));
63
+ }
64
+ return merged;
65
+ }
66
+ if (typeof props.properties === 'object' && props.properties !== null) {
67
+ return props.properties;
68
+ }
69
+ return {};
70
+ }
71
+ function getNodeRefTargets(node, template) {
72
+ if (!template.properties)
73
+ return [];
74
+ const propSchemas = getPropertySchemasFromTemplate(template.properties);
75
+ const targets = [];
76
+ for (const [key, schema] of Object.entries(propSchemas)) {
77
+ const s = schema;
78
+ if (s.format === 'node-ref') {
79
+ const value = node.properties[key];
80
+ if (typeof value === 'string' && !value.startsWith('#/'))
81
+ targets.push(value);
82
+ }
83
+ else if (s.type === 'object' &&
84
+ typeof s.additionalProperties === 'object' &&
85
+ s.additionalProperties !== null &&
86
+ s.additionalProperties.format === 'node-ref') {
87
+ const map = node.properties[key];
88
+ if (typeof map === 'object' && map !== null && !Array.isArray(map)) {
89
+ for (const value of Object.values(map)) {
90
+ if (typeof value === 'string' && !value.startsWith('#/'))
91
+ targets.push(value);
92
+ }
93
+ }
94
+ }
95
+ }
96
+ return targets;
97
+ }
98
+ function materialiseChildren(result, parent, clusterRoot, source, templates, filePath, diagnostics) {
46
99
  const template = templates.get(parent.template);
47
100
  if (!template) {
48
101
  diagnostics.push({ severity: 'error', file: filePath, nodeId: parent.id, message: `unknown template: ${parent.template}` });
@@ -85,7 +138,25 @@ function materialiseChildren(result, parent, source, templates, filePath, diagno
85
138
  stability: child.stability,
86
139
  });
87
140
  }
88
- materialiseChildren(result, child, value, templates, filePath, diagnostics);
141
+ const childTemplate = templates.get(child.template);
142
+ if (childTemplate) {
143
+ for (const target of getNodeRefTargets(child, childTemplate)) {
144
+ const readsId = `${clusterRoot.id}__reads__${target}`;
145
+ const existingFrom = result.edgesByFrom.get(clusterRoot.id) ?? [];
146
+ if (!existingFrom.some(e => e.id === readsId)) {
147
+ addEdge(result, {
148
+ id: readsId,
149
+ from: clusterRoot.id,
150
+ to: target,
151
+ type: 'reads',
152
+ state: clusterRoot.state,
153
+ stability: clusterRoot.stability,
154
+ generated: true,
155
+ });
156
+ }
157
+ }
158
+ }
159
+ materialiseChildren(result, child, clusterRoot, value, templates, filePath, diagnostics);
89
160
  }
90
161
  }
91
162
  }
@@ -13,7 +13,7 @@ export function serializeGraph(graph, options = {}) {
13
13
  map.set(clusterPath(root), stringifyGraphYaml(toClusterDocument(graph, root)));
14
14
  }
15
15
  const explicitEdges = getAllEdges(graph)
16
- .filter(edge => !STRUCTURAL_EDGE_TYPES.has(edge.type))
16
+ .filter(edge => !STRUCTURAL_EDGE_TYPES.has(edge.type) && edge.generated !== true)
17
17
  .sort((a, b) => a.id.localeCompare(b.id));
18
18
  if (explicitEdges.length > 0) {
19
19
  map.set('edges/corum.edges.yaml', stringifyGraphYaml({ edges: explicitEdges.map(toEdgeDocument) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
package/web/app.jsx CHANGED
@@ -13,6 +13,7 @@ const {
13
13
  } = window.CorumPrimitives;
14
14
  const { buildNavTree, buildOverlayIndicatorIds } = window.CorumNav;
15
15
  const { parseRoute, buildRoute } = window.CorumRouter;
16
+ const { SearchModal } = window.CorumSearch;
16
17
 
17
18
  const PANEL_EDGE_TYPES = new Set(['triggers', 'produces', 'calls', 'implements']);
18
19
 
@@ -58,13 +59,31 @@ function summarizeBranchFailure(result) {
58
59
  return result?.error ?? 'Branch failed to load';
59
60
  }
60
61
 
61
- function TopBar() {
62
+ function TopBar({ onSearchOpen }) {
63
+ const inputRef = React.useRef(null);
64
+
65
+ function handleFocus() {
66
+ inputRef.current?.blur();
67
+ onSearchOpen();
68
+ }
69
+
62
70
  return (
63
71
  <div className="topbar">
64
72
  <div className="brand">
65
73
  <BrandMark size={22} color="#fff" />
66
74
  <span>corum</span>
67
75
  </div>
76
+ <div className="topbar-search-wrap">
77
+ <i className="fa-solid fa-magnifying-glass topbar-search-icon" aria-hidden="true" />
78
+ <input
79
+ ref={inputRef}
80
+ className="topbar-search"
81
+ placeholder="Search graph..."
82
+ onFocus={handleFocus}
83
+ readOnly
84
+ />
85
+ <span className="topbar-search-hint">⌘K</span>
86
+ </div>
68
87
  </div>
69
88
  );
70
89
  }
@@ -114,6 +133,7 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
114
133
  const sortedComponents = [...navTree.keys()].sort((a, b) => a.localeCompare(b));
115
134
  const [openComponent, setOpenComponent] = useState();
116
135
  const [openEntryKeys, setOpenEntryKeys] = useState(new Set());
136
+ const [openGroupKeys, setOpenGroupKeys] = useState(new Set());
117
137
  const templateMap = new Map(templates.map(template => [template.name, template]));
118
138
 
119
139
  function openComponentWithEntries(component) {
@@ -152,6 +172,26 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
152
172
  }
153
173
  }, [activeNodeId, navTree]);
154
174
 
175
+ // Auto-expand groups for the active node; collapse all others.
176
+ useEffect(() => {
177
+ if (!activeNodeId || !navTree.size) return;
178
+ for (const entries of navTree.values()) {
179
+ for (const entry of entries) {
180
+ if (entry.kind === 'group') continue;
181
+ for (const node of entry.nodes) {
182
+ const isOwner =
183
+ node.id === activeNodeId ||
184
+ (node.navChildren ?? []).some(g => g.nodes.some(c => c.id === activeNodeId));
185
+ if (isOwner) {
186
+ setOpenGroupKeys(new Set((node.navChildren ?? []).map(g => `${node.id}:${g.label}`)));
187
+ return;
188
+ }
189
+ }
190
+ }
191
+ }
192
+ setOpenGroupKeys(new Set());
193
+ }, [activeNodeId, navTree]);
194
+
155
195
  function toggleComponent(component) {
156
196
  if (openComponent === component) { openComponentWithEntries(null); }
157
197
  else { openComponentWithEntries(component); }
@@ -257,32 +297,47 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
257
297
  >
258
298
  {displayName(node.id)}
259
299
  </div>
260
- {(node.navChildren ?? []).map(group => (
261
- <div className="nav-child-group" key={group.label}>
262
- <div className="nav-child-head">{group.label}</div>
263
- {group.nodes.map(child => {
264
- const childTemplate = templateMap.get(child.template);
265
- const childColour = childTemplate?.ui?.colour ?? colour;
266
- const childIsActive = child.id === activeNodeId;
267
- return (
268
- <div
269
- key={child.id}
270
- className={`nav-node-item nav-node-child${childIsActive ? ' active' : ''}`}
271
- onClick={() => onNode(child.id)}
272
- title={child.id}
273
- style={childIsActive ? { '--nav-node-active-bg': childColour } : undefined}
274
- >
275
- {displayName(child.id)}
276
- {overlayIndicatorIds && overlayIndicatorIds.has(child.id) && (
277
- <span className="signal-dots">
278
- <span className="signal-dot signal-dot-0" />
279
- </span>
280
- )}
281
- </div>
282
- );
283
- })}
284
- </div>
285
- ))}
300
+ {(node.navChildren ?? []).map(group => {
301
+ const groupKey = `${node.id}:${group.label}`;
302
+ const groupOpen = openGroupKeys.has(groupKey);
303
+ return (
304
+ <div className="nav-child-group" key={group.label}>
305
+ <div
306
+ className="nav-child-head"
307
+ style={{ cursor: 'pointer' }}
308
+ onClick={() => setOpenGroupKeys(prev => {
309
+ const next = new Set(prev);
310
+ next.has(groupKey) ? next.delete(groupKey) : next.add(groupKey);
311
+ return next;
312
+ })}
313
+ >
314
+ {group.label}
315
+ <Icon name={groupOpen ? 'chevron-down' : 'chevron-right'} size={10} />
316
+ </div>
317
+ {groupOpen && group.nodes.map(child => {
318
+ const childTemplate = templateMap.get(child.template);
319
+ const childColour = childTemplate?.ui?.colour ?? colour;
320
+ const childIsActive = child.id === activeNodeId;
321
+ return (
322
+ <div
323
+ key={child.id}
324
+ className={`nav-node-item nav-node-child${childIsActive ? ' active' : ''}`}
325
+ onClick={() => onNode(child.id)}
326
+ title={child.id}
327
+ style={childIsActive ? { '--nav-node-active-bg': childColour } : undefined}
328
+ >
329
+ {displayName(child.id)}
330
+ {overlayIndicatorIds && overlayIndicatorIds.has(child.id) && (
331
+ <span className="signal-dots">
332
+ <span className="signal-dot signal-dot-0" />
333
+ </span>
334
+ )}
335
+ </div>
336
+ );
337
+ })}
338
+ </div>
339
+ );
340
+ })}
286
341
  </div>
287
342
  );
288
343
  })}
@@ -694,6 +749,7 @@ function App() {
694
749
  const [debugMode, setDebugMode] = useState(() => {
695
750
  try { return localStorage.getItem('corum:debugMode') === 'true'; } catch { return false; }
696
751
  });
752
+ const [searchOpen, setSearchOpen] = useState(false);
697
753
 
698
754
  function handleDebugMode() {
699
755
  setDebugMode(prev => {
@@ -774,6 +830,17 @@ function App() {
774
830
  return () => window.removeEventListener('hashchange', handler);
775
831
  }, []);
776
832
 
833
+ useEffect(() => {
834
+ function handleKeyDown(e) {
835
+ if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
836
+ e.preventDefault();
837
+ setSearchOpen(true);
838
+ }
839
+ }
840
+ document.addEventListener('keydown', handleKeyDown);
841
+ return () => document.removeEventListener('keydown', handleKeyDown);
842
+ }, []);
843
+
777
844
  const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
778
845
  const activeSection = activeNodeId ? 'components' : (route.pathname.slice(1) || 'dashboard');
779
846
  const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
@@ -836,7 +903,15 @@ function App() {
836
903
 
837
904
  return (
838
905
  <>
839
- <TopBar />
906
+ {searchOpen && (
907
+ <SearchModal
908
+ nodes={nodes}
909
+ templates={templates}
910
+ onNavigate={handleNode}
911
+ onClose={() => setSearchOpen(false)}
912
+ />
913
+ )}
914
+ <TopBar onSearchOpen={() => setSearchOpen(true)} />
840
915
  {gitMode && (
841
916
  <BranchBar
842
917
  branches={branches}
package/web/index.html CHANGED
@@ -23,6 +23,7 @@
23
23
  <script src="nav.js"></script>
24
24
  <script src="router.js"></script>
25
25
  <script type="text/babel" src="primitives.jsx"></script>
26
+ <script type="text/babel" src="search.jsx"></script>
26
27
  <script type="text/babel">
27
28
  fetch('/api/plugins')
28
29
  .then(response => response.ok ? response.json() : [])
package/web/nav.js CHANGED
@@ -46,10 +46,12 @@ function buildNavTree(nodes, templates) {
46
46
  if (nestedNodeIds.has(node.id)) continue;
47
47
  const template = templateMap.get(node.template);
48
48
  const navGroup = template?.ui?.nav?.navGroup;
49
- const navChildren = [...(nestedByParent.get(node.id)?.values() ?? [])].map(group => ({
50
- label: group.label,
51
- nodes: group.nodes.sort((a, b) => a.id.localeCompare(b.id)),
52
- }));
49
+ const navChildren = [...(nestedByParent.get(node.id)?.values() ?? [])]
50
+ .sort((a, b) => a.label.localeCompare(b.label))
51
+ .map(group => ({
52
+ label: group.label,
53
+ nodes: group.nodes.sort((a, b) => a.id.localeCompare(b.id)),
54
+ }));
53
55
  const nodeWithChildren = { ...node, navChildren };
54
56
 
55
57
  if (navGroup) {
@@ -0,0 +1,61 @@
1
+ // Verify fuzzy match algorithm — run with: node web/search-utils.test.js
2
+
3
+ function fuzzyMatch(query, id) {
4
+ if (!query) return { score: 0 };
5
+ const q = query.toLowerCase();
6
+ const s = id.toLowerCase();
7
+ let qi = 0, run = 0, maxRun = 0;
8
+ for (let i = 0; i < s.length; i++) {
9
+ if (qi >= q.length) break;
10
+ if (s[i] === q[qi]) { qi++; run++; if (run > maxRun) maxRun = run; }
11
+ else { run = 0; }
12
+ }
13
+ return qi === q.length ? { score: maxRun } : null;
14
+ }
15
+
16
+ function searchNodes(nodes, templates, query) {
17
+ if (!query || !query.trim()) return [];
18
+ const templateMap = new Map(templates.map(t => [t.name, t]));
19
+ const results = [];
20
+ for (const node of nodes) {
21
+ if (node.parentId) continue;
22
+ const match = fuzzyMatch(query.trim(), node.id);
23
+ if (!match) continue;
24
+ results.push({ node, template: templateMap.get(node.template), score: match.score });
25
+ }
26
+ results.sort((a, b) => b.score - a.score || a.node.id.length - b.node.id.length);
27
+ return results.slice(0, 8);
28
+ }
29
+
30
+ let passed = 0, failed = 0;
31
+ function assert(condition, name) {
32
+ if (condition) { console.log(` ✓ ${name}`); passed++; }
33
+ else { console.error(` ✗ ${name}`); failed++; }
34
+ }
35
+
36
+ // fuzzyMatch
37
+ assert(fuzzyMatch('ord', 'orders.DomainModel.order') !== null, 'matches subsequence');
38
+ assert(fuzzyMatch('xyz', 'orders.DomainModel.order') === null, 'rejects non-match');
39
+ assert(fuzzyMatch('ORD', 'orders.DomainModel.order') !== null, 'case insensitive');
40
+ assert(fuzzyMatch('', 'orders.DomainModel.order') !== null, 'empty query matches');
41
+ assert(fuzzyMatch('order', 'orders.DomainModel.order')?.score >= 5, 'consecutive run scores high');
42
+ assert(fuzzyMatch('o.o', 'orders.DomainModel.order')?.score === 1, 'non-consecutive scores low');
43
+
44
+ // searchNodes
45
+ const nodes = [
46
+ { id: 'orders.DomainModel.order', template: 'DomainModel', component: 'orders' },
47
+ { id: 'orders.RestAPI.OrdersApi', template: 'RestAPI', component: 'orders' },
48
+ { id: 'payments.DomainModel.payment', template: 'DomainModel', component: 'payments' },
49
+ { id: 'orders.DomainModel.order.schemas.OrderSchema', template: 'Schema', component: 'orders', parentId: 'orders.DomainModel.order' },
50
+ ];
51
+ const templates = [{ name: 'DomainModel', ui: { colour: '#f00', displayName: 'Domain Model' } }];
52
+
53
+ const results = searchNodes(nodes, templates, 'order');
54
+ assert(results.length === 2, 'returns matched root nodes only');
55
+ assert(!results.some(r => r.node.parentId), 'excludes child nodes with parentId');
56
+ assert(results[0].node.id === 'orders.DomainModel.order', 'shorter-ID tie-break works');
57
+ assert(searchNodes(nodes, templates, '').length === 0, 'empty query returns nothing');
58
+ assert(searchNodes(nodes, templates, 'zzz').length === 0, 'no-match query returns nothing');
59
+
60
+ console.log(`\n${passed} passed, ${failed} failed`);
61
+ if (failed > 0) process.exit(1);
package/web/search.jsx ADDED
@@ -0,0 +1,111 @@
1
+ /* Search modal: fuzzy match utilities and SearchModal component. */
2
+
3
+ const { useState, useEffect, useRef } = React;
4
+ const { TemplateBadge, Icon } = window.CorumPrimitives;
5
+
6
+ function fuzzyMatch(query, id) {
7
+ if (!query) return { score: 0 };
8
+ const q = query.toLowerCase();
9
+ const s = id.toLowerCase();
10
+ let qi = 0, run = 0, maxRun = 0;
11
+ for (let i = 0; i < s.length; i++) {
12
+ if (qi >= q.length) break;
13
+ if (s[i] === q[qi]) { qi++; run++; if (run > maxRun) maxRun = run; }
14
+ else { run = 0; }
15
+ }
16
+ return qi === q.length ? { score: maxRun } : null;
17
+ }
18
+
19
+ function searchNodes(nodes, templates, query) {
20
+ if (!query || !query.trim()) return [];
21
+ const templateMap = new Map(templates.map(t => [t.name, t]));
22
+ const results = [];
23
+ for (const node of nodes) {
24
+ if (node.parentId) continue;
25
+ const match = fuzzyMatch(query.trim(), node.id);
26
+ if (!match) continue;
27
+ results.push({ node, template: templateMap.get(node.template), score: match.score });
28
+ }
29
+ results.sort((a, b) => b.score - a.score || a.node.id.length - b.node.id.length);
30
+ return results.slice(0, 10);
31
+ }
32
+
33
+ function SearchModal({ nodes, templates, onNavigate, onClose }) {
34
+ const [query, setQuery] = useState('');
35
+ const [selectedIndex, setSelectedIndex] = useState(0);
36
+ const inputRef = useRef(null);
37
+
38
+ const results = searchNodes(nodes, templates, query);
39
+
40
+ useEffect(() => { setSelectedIndex(0); }, [query]);
41
+
42
+ useEffect(() => { inputRef.current?.focus(); }, []);
43
+
44
+ useEffect(() => {
45
+ function handleKey(e) {
46
+ if (e.key === 'Escape') { onClose(); return; }
47
+ if (e.key === 'ArrowDown') {
48
+ e.preventDefault();
49
+ if (results.length > 0) setSelectedIndex(i => (i + 1) % results.length);
50
+ }
51
+ if (e.key === 'ArrowUp') {
52
+ e.preventDefault();
53
+ if (results.length > 0) setSelectedIndex(i => (i - 1 + results.length) % results.length);
54
+ }
55
+ if (e.key === 'Enter' && results[selectedIndex]) {
56
+ onNavigate(results[selectedIndex].node.id);
57
+ onClose();
58
+ }
59
+ }
60
+ document.addEventListener('keydown', handleKey);
61
+ return () => document.removeEventListener('keydown', handleKey);
62
+ }, [results, selectedIndex, onNavigate, onClose]);
63
+
64
+ function handleBackdropClick(e) {
65
+ if (e.target === e.currentTarget) onClose();
66
+ }
67
+
68
+ return (
69
+ <div className="search-backdrop" onClick={handleBackdropClick}>
70
+ <div className="search-modal">
71
+ <div className="search-modal-input-wrap">
72
+ <Icon name="magnifying-glass" size={15} />
73
+ <input
74
+ ref={inputRef}
75
+ className="search-modal-input"
76
+ placeholder="Search graph..."
77
+ value={query}
78
+ onChange={e => setQuery(e.target.value)}
79
+ />
80
+ </div>
81
+ {results.length > 0 && (
82
+ <div className="search-results">
83
+ {results.map((result, index) => {
84
+ const { node, template } = result;
85
+ const name = node.id.split('.').pop();
86
+ const colour = template?.ui?.colour ?? null;
87
+ const tplName = template?.ui?.displayName ?? node.template;
88
+ return (
89
+ <div
90
+ key={node.id}
91
+ className={`search-result-row${index === selectedIndex ? ' selected' : ''}`}
92
+ onClick={() => { onNavigate(node.id); onClose(); }}
93
+ title={node.id}
94
+ >
95
+ <TemplateBadge name={tplName} colour={colour} />
96
+ <span className="search-result-name">{name}</span>
97
+ <span className="search-result-component">{node.component}</span>
98
+ </div>
99
+ );
100
+ })}
101
+ </div>
102
+ )}
103
+ {query.trim() && results.length === 0 && (
104
+ <div className="search-no-results">No results</div>
105
+ )}
106
+ </div>
107
+ </div>
108
+ );
109
+ }
110
+
111
+ window.CorumSearch = { SearchModal };
package/web/style.css CHANGED
@@ -220,6 +220,9 @@ button {
220
220
  }
221
221
 
222
222
  .nav-child-head {
223
+ display: flex;
224
+ align-items: center;
225
+ gap: 6px;
223
226
  padding: 4px 8px 2px 42px;
224
227
  color: var(--ink-4);
225
228
  font-size: 10px;
@@ -838,3 +841,143 @@ button {
838
841
  border-radius: 2px;
839
842
  flex-shrink: 0;
840
843
  }
844
+
845
+ /* ── Search ──────────────────────────────────────── */
846
+
847
+ .topbar-search-wrap {
848
+ margin-left: auto;
849
+ position: relative;
850
+ display: flex;
851
+ align-items: center;
852
+ }
853
+
854
+ .topbar-search-icon {
855
+ position: absolute;
856
+ left: 10px;
857
+ color: rgba(255, 255, 255, 0.65);
858
+ pointer-events: none;
859
+ font-size: 11px;
860
+ }
861
+
862
+ .topbar-search {
863
+ width: 220px;
864
+ padding: 5px 36px 5px 28px;
865
+ background: rgba(255, 255, 255, 0.18);
866
+ border: 1px solid rgba(255, 255, 255, 0.28);
867
+ border-radius: var(--radius);
868
+ color: #fff;
869
+ font: inherit;
870
+ font-size: 12px;
871
+ outline: none;
872
+ cursor: pointer;
873
+ }
874
+
875
+ .topbar-search::placeholder {
876
+ color: rgba(255, 255, 255, 0.6);
877
+ }
878
+
879
+ .topbar-search:hover {
880
+ background: rgba(255, 255, 255, 0.22);
881
+ }
882
+
883
+ .topbar-search-hint {
884
+ position: absolute;
885
+ right: 8px;
886
+ color: rgba(255, 255, 255, 0.5);
887
+ font-size: 11px;
888
+ pointer-events: none;
889
+ user-select: none;
890
+ }
891
+
892
+ .search-backdrop {
893
+ position: fixed;
894
+ inset: 0;
895
+ background: rgba(0, 0, 0, 0.4);
896
+ z-index: 1000;
897
+ animation: search-fade-in 0.12s ease;
898
+ }
899
+
900
+ @keyframes search-fade-in {
901
+ from { opacity: 0; }
902
+ to { opacity: 1; }
903
+ }
904
+
905
+ .search-modal {
906
+ position: absolute;
907
+ top: 15%;
908
+ left: 50%;
909
+ transform: translateX(-50%);
910
+ width: 560px;
911
+ max-width: calc(100vw - 40px);
912
+ background: var(--paper);
913
+ border-radius: 10px;
914
+ box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.1);
915
+ overflow: hidden;
916
+ }
917
+
918
+ .search-modal-input-wrap {
919
+ display: flex;
920
+ align-items: center;
921
+ gap: 10px;
922
+ padding: 14px 16px;
923
+ border-bottom: 1px solid var(--rule);
924
+ color: var(--ink-3);
925
+ }
926
+
927
+ .search-modal-input {
928
+ flex: 1;
929
+ border: none;
930
+ outline: none;
931
+ background: transparent;
932
+ font: inherit;
933
+ font-size: 15px;
934
+ color: var(--ink);
935
+ }
936
+
937
+ .search-modal-input::placeholder {
938
+ color: var(--ink-4);
939
+ }
940
+
941
+ .search-results {
942
+ padding: 4px;
943
+ max-height: 400px;
944
+ overflow-y: auto;
945
+ }
946
+
947
+ .search-result-row {
948
+ display: flex;
949
+ align-items: center;
950
+ gap: 8px;
951
+ padding: 7px 10px;
952
+ border-radius: 6px;
953
+ cursor: pointer;
954
+ }
955
+
956
+ .search-result-row:hover,
957
+ .search-result-row.selected {
958
+ background: var(--paper-2);
959
+ }
960
+
961
+ .search-result-name {
962
+ flex: 1;
963
+ font-size: 13px;
964
+ font-weight: 500;
965
+ color: var(--ink);
966
+ overflow: hidden;
967
+ text-overflow: ellipsis;
968
+ white-space: nowrap;
969
+ }
970
+
971
+ .search-result-component {
972
+ font-size: 11px;
973
+ color: var(--ink-4);
974
+ font-family: "JetBrains Mono", ui-monospace, monospace;
975
+ flex-shrink: 0;
976
+ }
977
+
978
+ .search-no-results {
979
+ padding: 20px 16px;
980
+ color: var(--ink-3);
981
+ font-size: 13px;
982
+ text-align: center;
983
+ }