@atolis-hq/corum 0.1.25 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.25",
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
  }
@@ -730,6 +749,7 @@ function App() {
730
749
  const [debugMode, setDebugMode] = useState(() => {
731
750
  try { return localStorage.getItem('corum:debugMode') === 'true'; } catch { return false; }
732
751
  });
752
+ const [searchOpen, setSearchOpen] = useState(false);
733
753
 
734
754
  function handleDebugMode() {
735
755
  setDebugMode(prev => {
@@ -810,6 +830,17 @@ function App() {
810
830
  return () => window.removeEventListener('hashchange', handler);
811
831
  }, []);
812
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
+
813
844
  const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
814
845
  const activeSection = activeNodeId ? 'components' : (route.pathname.slice(1) || 'dashboard');
815
846
  const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
@@ -872,7 +903,15 @@ function App() {
872
903
 
873
904
  return (
874
905
  <>
875
- <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)} />
876
915
  {gitMode && (
877
916
  <BranchBar
878
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() : [])
@@ -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
@@ -841,3 +841,143 @@ button {
841
841
  border-radius: 2px;
842
842
  flex-shrink: 0;
843
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
+ }