@stacksjs/components 0.2.854 → 0.2.857

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.
Files changed (139) hide show
  1. package/dist/CodeEditor-jg4w7e15.stx +497 -0
  2. package/dist/ContextMenu-43g3w5tp.stx +188 -0
  3. package/dist/DataGrid-7rt7v865.stx +376 -0
  4. package/dist/GraphView-0t3t9mec.stx +320 -0
  5. package/dist/JsonTree-satc4010.stx +317 -0
  6. package/dist/PreviewFrame-erbgvzj8.stx +257 -0
  7. package/dist/SplitPane-7sqfdwqa.stx +159 -0
  8. package/dist/code-editor/editor.js +2166 -0
  9. package/dist/component-api/component-api.js +36 -0
  10. package/dist/components/CodeBlock.d.ts +12 -5
  11. package/dist/context-menu/context-menu.js +575 -0
  12. package/dist/data-grid/data-grid.js +1244 -0
  13. package/dist/graph-view/graph-view.js +1408 -0
  14. package/dist/index.d.ts +10 -0
  15. package/dist/index.js +34 -15
  16. package/dist/json-tree/json-tree.js +1121 -0
  17. package/dist/preview-frame/preview-frame.js +356 -0
  18. package/dist/split-pane/split-pane.js +364 -0
  19. package/dist/ui/code-editor/CodeEditor.d.ts +46 -0
  20. package/dist/ui/code-editor/controller.d.ts +103 -0
  21. package/dist/ui/code-editor/core/commands.d.ts +55 -0
  22. package/dist/ui/code-editor/core/completion.d.ts +40 -0
  23. package/dist/ui/code-editor/core/editor.d.ts +69 -0
  24. package/dist/ui/code-editor/core/highlight.d.ts +61 -0
  25. package/dist/ui/code-editor/core/history.d.ts +27 -0
  26. package/dist/ui/code-editor/core/index.d.ts +13 -0
  27. package/dist/ui/code-editor/core/keymap.d.ts +38 -0
  28. package/dist/ui/code-editor/core/selection.d.ts +30 -0
  29. package/dist/ui/code-editor/core/text.d.ts +64 -0
  30. package/dist/ui/code-editor/editor.d.ts +15 -0
  31. package/dist/ui/code-editor/index.d.ts +29 -0
  32. package/dist/ui/code-editor/tokenizer.d.ts +18 -0
  33. package/dist/ui/code-editor/view.d.ts +59 -0
  34. package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
  35. package/dist/ui/context-menu/context-menu.d.ts +8 -0
  36. package/dist/ui/context-menu/core.d.ts +74 -0
  37. package/dist/ui/context-menu/index.d.ts +11 -0
  38. package/dist/ui/context-menu/view.d.ts +36 -0
  39. package/dist/ui/data-grid/DataGrid.d.ts +30 -0
  40. package/dist/ui/data-grid/core.d.ts +141 -0
  41. package/dist/ui/data-grid/data-grid.d.ts +9 -0
  42. package/dist/ui/data-grid/index.d.ts +20 -0
  43. package/dist/ui/data-grid/view.d.ts +56 -0
  44. package/dist/ui/graph-view/GraphView.d.ts +21 -0
  45. package/dist/ui/graph-view/core/edges.d.ts +34 -0
  46. package/dist/ui/graph-view/core/force.d.ts +10 -0
  47. package/dist/ui/graph-view/core/graph.d.ts +83 -0
  48. package/dist/ui/graph-view/core/index.d.ts +5 -0
  49. package/dist/ui/graph-view/core/layered.d.ts +24 -0
  50. package/dist/ui/graph-view/core/viewport.d.ts +34 -0
  51. package/dist/ui/graph-view/graph-view.d.ts +9 -0
  52. package/dist/ui/graph-view/index.d.ts +21 -0
  53. package/dist/ui/graph-view/view.d.ts +51 -0
  54. package/dist/ui/json-tree/JsonTree.d.ts +18 -0
  55. package/dist/ui/json-tree/core.d.ts +108 -0
  56. package/dist/ui/json-tree/index.d.ts +18 -0
  57. package/dist/ui/json-tree/json-tree.d.ts +10 -0
  58. package/dist/ui/json-tree/tinker.d.ts +84 -0
  59. package/dist/ui/json-tree/view.d.ts +59 -0
  60. package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
  61. package/dist/ui/preview-frame/core.d.ts +81 -0
  62. package/dist/ui/preview-frame/index.d.ts +19 -0
  63. package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
  64. package/dist/ui/preview-frame/view.d.ts +37 -0
  65. package/dist/ui/split-pane/SplitPane.d.ts +18 -0
  66. package/dist/ui/split-pane/core.d.ts +58 -0
  67. package/dist/ui/split-pane/index.d.ts +15 -0
  68. package/dist/ui/split-pane/split-pane.d.ts +8 -0
  69. package/dist/ui/split-pane/view.d.ts +27 -0
  70. package/dist/ui/virtual-table/index.d.ts +6 -0
  71. package/dist/utils/component-api.d.ts +4 -0
  72. package/dist/utils/highlighter.d.ts +19 -1
  73. package/dist/utils/highlighter.js +24 -7
  74. package/dist/utils/syntax-theme.d.ts +44 -0
  75. package/package.json +44 -4
  76. package/src/components/CodeBlock.stx +195 -17
  77. package/src/index.ts +10 -0
  78. package/src/ui/code-editor/CodeEditor.stx +497 -0
  79. package/src/ui/code-editor/README.md +135 -0
  80. package/src/ui/code-editor/controller.ts +517 -0
  81. package/src/ui/code-editor/core/commands.ts +381 -0
  82. package/src/ui/code-editor/core/completion.ts +212 -0
  83. package/src/ui/code-editor/core/editor.ts +319 -0
  84. package/src/ui/code-editor/core/highlight.ts +203 -0
  85. package/src/ui/code-editor/core/history.ts +190 -0
  86. package/src/ui/code-editor/core/index.ts +14 -0
  87. package/src/ui/code-editor/core/keymap.ts +125 -0
  88. package/src/ui/code-editor/core/selection.ts +104 -0
  89. package/src/ui/code-editor/core/text.ts +252 -0
  90. package/src/ui/code-editor/editor.ts +16 -0
  91. package/src/ui/code-editor/index.ts +46 -0
  92. package/src/ui/code-editor/tokenizer.ts +74 -0
  93. package/src/ui/code-editor/view.ts +1066 -0
  94. package/src/ui/context-menu/ContextMenu.stx +188 -0
  95. package/src/ui/context-menu/README.md +117 -0
  96. package/src/ui/context-menu/context-menu.ts +8 -0
  97. package/src/ui/context-menu/core.ts +250 -0
  98. package/src/ui/context-menu/index.ts +16 -0
  99. package/src/ui/context-menu/view.ts +540 -0
  100. package/src/ui/data-grid/DataGrid.stx +376 -0
  101. package/src/ui/data-grid/README.md +204 -0
  102. package/src/ui/data-grid/core.ts +813 -0
  103. package/src/ui/data-grid/data-grid.ts +9 -0
  104. package/src/ui/data-grid/index.ts +34 -0
  105. package/src/ui/data-grid/view.ts +806 -0
  106. package/src/ui/graph-view/GraphView.stx +320 -0
  107. package/src/ui/graph-view/README.md +210 -0
  108. package/src/ui/graph-view/core/edges.ts +180 -0
  109. package/src/ui/graph-view/core/force.ts +237 -0
  110. package/src/ui/graph-view/core/graph.ts +277 -0
  111. package/src/ui/graph-view/core/index.ts +5 -0
  112. package/src/ui/graph-view/core/layered.ts +256 -0
  113. package/src/ui/graph-view/core/viewport.ts +141 -0
  114. package/src/ui/graph-view/graph-view.ts +9 -0
  115. package/src/ui/graph-view/index.ts +35 -0
  116. package/src/ui/graph-view/view.ts +809 -0
  117. package/src/ui/json-tree/JsonTree.stx +317 -0
  118. package/src/ui/json-tree/README.md +193 -0
  119. package/src/ui/json-tree/core.ts +588 -0
  120. package/src/ui/json-tree/index.ts +28 -0
  121. package/src/ui/json-tree/json-tree.ts +10 -0
  122. package/src/ui/json-tree/tinker.ts +349 -0
  123. package/src/ui/json-tree/view.ts +665 -0
  124. package/src/ui/preview-frame/PreviewFrame.stx +257 -0
  125. package/src/ui/preview-frame/README.md +107 -0
  126. package/src/ui/preview-frame/core.ts +195 -0
  127. package/src/ui/preview-frame/index.ts +31 -0
  128. package/src/ui/preview-frame/preview-frame.ts +8 -0
  129. package/src/ui/preview-frame/view.ts +336 -0
  130. package/src/ui/split-pane/README.md +87 -0
  131. package/src/ui/split-pane/SplitPane.stx +159 -0
  132. package/src/ui/split-pane/core.ts +200 -0
  133. package/src/ui/split-pane/index.ts +24 -0
  134. package/src/ui/split-pane/split-pane.ts +8 -0
  135. package/src/ui/split-pane/view.ts +305 -0
  136. package/src/ui/virtual-table/index.ts +6 -0
  137. package/src/utils/component-api.ts +72 -0
  138. package/src/utils/highlighter.ts +121 -218
  139. package/src/utils/syntax-theme.ts +144 -0
@@ -0,0 +1,376 @@
1
+ <script server>
2
+ /*
3
+ * Rows written into the page as a plain prop. A bound one (`:rows="rows()"`)
4
+ * is read live by the client script; this is what it starts from.
5
+ */
6
+ export const rows = Array.isArray($props.rows) ? $props.rows : []
7
+ export const columns = Array.isArray($props.columns) ? $props.columns : []
8
+ export const rowHeight = $num($props.rowHeight) || 28
9
+ export const headerHeight = $num($props.headerHeight) || 32
10
+ /* A CSS length. `100%` fills a sized parent, which is what a pane wants. */
11
+ export const height = $props.height || '24rem'
12
+ export const filterable = $bool($props.filterable, true)
13
+ export const exportable = $bool($props.exportable, true)
14
+ export const selectable = $bool($props.selectable, true)
15
+ export const contextMenu = $bool($props.contextMenu)
16
+ export const filter = typeof $props.filter === 'string' ? $props.filter : ''
17
+ export const label = $props.label || 'Data'
18
+ export const fileName = $props.fileName || 'data'
19
+ export const className = $props.className || ''
20
+ /*
21
+ * Ids unique to this instance: the grid, its filter and its status line all
22
+ * have to be findable when two grids share a page.
23
+ */
24
+ export const gridId = $props.id || `data-grid-${$uid}`
25
+ export const filterId = `${gridId}-filter`
26
+ export const statusId = `${gridId}-status`
27
+ export const hasToolbar = filterable || exportable
28
+ </script>
29
+
30
+ <script client>
31
+ /*
32
+ * <DataGrid>: rows and columns, sorted, filtered, selected and exported.
33
+ *
34
+ * This script is the wiring: props in, events out. What a sort or a filter
35
+ * does is in ./core, and what is drawn is in ./view.
36
+ */
37
+ import { DataGridView } from './view'
38
+
39
+ const emit = defineEmits(['sort', 'filter', 'select', 'cell', 'activate', 'copy', 'export', 'context'])
40
+
41
+ function asList(value) {
42
+ if (Array.isArray(value)) return value
43
+ if (typeof value === 'string' && value.charAt(0) === '[') {
44
+ try { return JSON.parse(value) }
45
+ catch (e) { return [] }
46
+ }
47
+ return []
48
+ }
49
+ function asText(value) { return value == null ? '' : String(value) }
50
+
51
+ const liveRows = useReactiveProp('rows', {{ rows }}, { parse: asList })
52
+ const liveColumns = useReactiveProp('columns', {{ columns }}, { parse: asList })
53
+ const liveFilter = useReactiveProp('filter', {{ filter }}, { parse: asText })
54
+ const liveFileName = useReactiveProp('fileName', {{ fileName }}, { parse: asText })
55
+
56
+ const rootRef = useRef('data-grid')
57
+ let grid = null
58
+
59
+ onMount(() => {
60
+ const root = rootRef()
61
+ if (!root) return
62
+
63
+ const firstColumns = asList(liveColumns())
64
+ grid = new DataGridView(root, {
65
+ rows: asList(liveRows()),
66
+ columns: firstColumns.length ? firstColumns : null,
67
+ rowHeight: {{ rowHeight }},
68
+ headerHeight: {{ headerHeight }},
69
+ selectable: {{ selectable }},
70
+ contextMenu: {{ contextMenu }},
71
+ filter: asText(liveFilter()),
72
+ fileName: asText(liveFileName()),
73
+ }, {
74
+ onSort(sort) { emit('sort', sort) },
75
+ onFilter(detail) { emit('filter', detail) },
76
+ onSelect(detail) { emit('select', detail) },
77
+ onCell(detail) { emit('cell', detail) },
78
+ onActivate(detail) { emit('activate', detail) },
79
+ onCopy(detail) { emit('copy', detail) },
80
+ onExport(detail) { emit('export', detail) },
81
+ onContext(detail) { emit('context', detail) },
82
+ })
83
+
84
+ // The first run of each finds what the view was just built with. Only a
85
+ // later change is news, and rows handed over with setRows() must not be
86
+ // replaced by a prop that has not changed.
87
+ let rowsSeen = false
88
+ effect(() => {
89
+ const next = asList(liveRows())
90
+ if (rowsSeen) grid.setRows(next)
91
+ rowsSeen = true
92
+ })
93
+ let columnsSeen = false
94
+ effect(() => {
95
+ const next = asList(liveColumns())
96
+ if (columnsSeen) grid.setColumns(next.length ? next : null)
97
+ columnsSeen = true
98
+ })
99
+ let filterSeen = false
100
+ effect(() => {
101
+ const next = asText(liveFilter())
102
+ if (filterSeen) grid.setFilter(next)
103
+ filterSeen = true
104
+ })
105
+ effect(() => grid.setFileName(asText(liveFileName())))
106
+ })
107
+
108
+ onDestroy(() => {
109
+ if (grid) grid.destroy()
110
+ grid = null
111
+ })
112
+
113
+ defineExpose({
114
+ setRows: (next) => { if (grid) grid.setRows(asList(next)) },
115
+ setColumns: (next) => { if (grid) grid.setColumns(Array.isArray(next) && next.length ? next : null) },
116
+ getView: () => (grid ? grid.getView() : []),
117
+ getSelection: () => (grid ? grid.getSelection() : { rows: [], indices: [] }),
118
+ clearSelection: () => { if (grid) grid.clearSelection() },
119
+ setFilter: (text) => { if (grid) grid.setFilter(asText(text)) },
120
+ setSort: (sort) => { if (grid) grid.setSort(asList(sort)) },
121
+ exportCsv: () => (grid ? grid.exportCsv() : ''),
122
+ exportJson: () => (grid ? grid.exportJson() : '[]'),
123
+ download: format => (grid ? grid.download(format === 'json' ? 'json' : 'csv') : ''),
124
+ scrollToRow: (index) => { if (grid) grid.scrollToRow(index) },
125
+ focus: () => { if (grid) grid.focus() },
126
+ grid: () => grid,
127
+ })
128
+ </script>
129
+
130
+ <div
131
+ ref="data-grid"
132
+ data-stx-data-grid
133
+ class="stx-dg {{ className }}"
134
+ style="height: {{ height }}"
135
+ @if(selectable)data-selectable@endif
136
+ >
137
+ @if(hasToolbar)
138
+ <div data-dg="toolbar" class="stx-dg-toolbar">
139
+ @if(filterable)
140
+ <label for="{{ filterId }}" class="sr-only">Filter {{ label }}</label>
141
+ <input
142
+ data-dg="filter"
143
+ id="{{ filterId }}"
144
+ type="search"
145
+ class="stx-dg-filter"
146
+ placeholder="Filter rows"
147
+ autocomplete="off"
148
+ spellcheck="false"
149
+ aria-controls="{{ gridId }}"
150
+ value="{{ filter }}"
151
+ >
152
+ @endif
153
+ <span data-dg="status" id="{{ statusId }}" role="status" aria-live="polite" class="stx-dg-status"></span>
154
+ @if(exportable)
155
+ <button type="button" data-dg="export-csv" class="stx-dg-button" aria-label="Export {{ label }} as CSV">CSV</button>
156
+ <button type="button" data-dg="export-json" class="stx-dg-button" aria-label="Export {{ label }} as JSON">JSON</button>
157
+ @endif
158
+ </div>
159
+ @else
160
+ <span data-dg="status" id="{{ statusId }}" role="status" aria-live="polite" class="sr-only"></span>
161
+ @endif
162
+
163
+ {{-- The one scroll container, and the grid itself: focus stays here and the
164
+ active cell is named, since the cells under it come and go. --}}
165
+ <div
166
+ data-dg="scroller"
167
+ id="{{ gridId }}"
168
+ role="grid"
169
+ tabindex="0"
170
+ aria-label="{{ label }}"
171
+ aria-describedby="{{ statusId }}"
172
+ @if(selectable)aria-multiselectable="true"@endif
173
+ class="stx-dg-scroller"
174
+ >
175
+ <div data-dg="content" role="presentation" class="stx-dg-content">
176
+ <div data-dg="header" role="row" aria-rowindex="1" class="stx-dg-header"></div>
177
+ <div data-dg="body" role="rowgroup" class="stx-dg-body"></div>
178
+ </div>
179
+ </div>
180
+ </div>
181
+
182
+ <style>
183
+ /*
184
+ * Everything the grid is drawn with is a custom property, each falling back to
185
+ * one of the library's role tokens, so an app that has themed its roles has a
186
+ * matching grid, in light and in dark.
187
+ *
188
+ * The row and header heights are set by the view, in pixels: the arithmetic
189
+ * that decides which rows exist depends on every row being exactly that tall.
190
+ */
191
+ :where([data-stx-data-grid]) {
192
+ --stx-grid-font: inherit;
193
+ --stx-grid-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
194
+ --stx-grid-font-size: 13px;
195
+ --stx-grid-row-height: 28px;
196
+ --stx-grid-header-height: 32px;
197
+ --stx-grid-cell-padding: 12px;
198
+ --stx-grid-bg: var(--stx-panel, #ffffff);
199
+ --stx-grid-fg: var(--stx-fg, #171717);
200
+ --stx-grid-header-bg: var(--stx-surface, #fafafa);
201
+ --stx-grid-header-fg: var(--stx-fg-muted, #525252);
202
+ --stx-grid-line: var(--stx-line, #e5e5e5);
203
+ --stx-grid-empty-fg: var(--stx-fg-subtle, #a3a3a3);
204
+ --stx-grid-hover: color-mix(in srgb, var(--stx-fg, #171717) 4%, transparent);
205
+ --stx-grid-selected: color-mix(in srgb, var(--stx-accent, #2563eb) 14%, transparent);
206
+ --stx-grid-accent: var(--stx-accent, #2563eb);
207
+ --stx-grid-number: var(--stx-grid-fg);
208
+ --stx-grid-boolean: var(--stx-info, #0891b2);
209
+ display: flex;
210
+ flex-direction: column;
211
+ min-width: 0;
212
+ min-height: 0;
213
+ overflow: hidden;
214
+ border: 1px solid var(--stx-grid-line);
215
+ border-radius: var(--stx-radius-panel, 8px);
216
+ background: var(--stx-grid-bg);
217
+ color: var(--stx-grid-fg);
218
+ font-family: var(--stx-grid-font);
219
+ font-size: var(--stx-grid-font-size);
220
+ }
221
+
222
+ [data-stx-data-grid] .stx-dg-toolbar {
223
+ display: flex;
224
+ flex: 0 0 auto;
225
+ align-items: center;
226
+ gap: 8px;
227
+ padding: 6px 8px;
228
+ border-bottom: 1px solid var(--stx-grid-line);
229
+ background: var(--stx-grid-header-bg);
230
+ }
231
+ [data-stx-data-grid] .stx-dg-filter {
232
+ flex: 0 1 16rem;
233
+ min-width: 6rem;
234
+ height: 26px;
235
+ padding: 0 8px;
236
+ border: 1px solid var(--stx-grid-line);
237
+ border-radius: var(--stx-radius-control, 6px);
238
+ background: var(--stx-field, var(--stx-grid-bg));
239
+ color: inherit;
240
+ font: inherit;
241
+ }
242
+ [data-stx-data-grid] .stx-dg-filter:focus-visible,
243
+ [data-stx-data-grid] .stx-dg-button:focus-visible {
244
+ outline: 2px solid var(--stx-grid-accent);
245
+ outline-offset: 1px;
246
+ }
247
+ [data-stx-data-grid] .stx-dg-status {
248
+ flex: 1 1 auto;
249
+ min-width: 0;
250
+ overflow: hidden;
251
+ color: var(--stx-grid-header-fg);
252
+ font-variant-numeric: tabular-nums;
253
+ text-overflow: ellipsis;
254
+ white-space: nowrap;
255
+ }
256
+ [data-stx-data-grid] .stx-dg-button {
257
+ flex: 0 0 auto;
258
+ height: 26px;
259
+ padding: 0 10px;
260
+ border: 1px solid var(--stx-grid-line);
261
+ border-radius: var(--stx-radius-control, 6px);
262
+ background: var(--stx-grid-bg);
263
+ color: inherit;
264
+ font: inherit;
265
+ font-size: 12px;
266
+ cursor: pointer;
267
+ }
268
+ [data-stx-data-grid] .stx-dg-button:hover { background: var(--stx-grid-hover); }
269
+
270
+ [data-stx-data-grid] .stx-dg-scroller {
271
+ position: relative;
272
+ flex: 1 1 auto;
273
+ min-height: 0;
274
+ overflow: auto;
275
+ outline: none;
276
+ /* The scroller is its own layer, so a scroll repaints nothing outside it. */
277
+ contain: strict;
278
+ }
279
+ [data-stx-data-grid] .stx-dg-scroller:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--stx-grid-accent) 55%, transparent); }
280
+ [data-stx-data-grid] .stx-dg-content { position: relative; min-width: 100%; }
281
+
282
+ [data-stx-data-grid] .stx-dg-header {
283
+ position: sticky;
284
+ top: 0;
285
+ z-index: 2;
286
+ min-width: 100%;
287
+ height: var(--stx-grid-header-height);
288
+ border-bottom: 1px solid var(--stx-grid-line);
289
+ background: var(--stx-grid-header-bg);
290
+ color: var(--stx-grid-header-fg);
291
+ box-sizing: border-box;
292
+ }
293
+ [data-stx-data-grid] .stx-dg-head {
294
+ position: absolute;
295
+ top: 0;
296
+ display: flex;
297
+ align-items: center;
298
+ gap: 4px;
299
+ height: 100%;
300
+ padding: 0 var(--stx-grid-cell-padding);
301
+ box-sizing: border-box;
302
+ border-right: 1px solid var(--stx-grid-line);
303
+ font-weight: 600;
304
+ white-space: nowrap;
305
+ user-select: none;
306
+ -webkit-user-select: none;
307
+ }
308
+ [data-stx-data-grid] .stx-dg-head[data-sortable] { cursor: pointer; }
309
+ [data-stx-data-grid] .stx-dg-head[data-align="right"] { flex-direction: row-reverse; }
310
+ [data-stx-data-grid] .stx-dg-head[data-align="center"] { justify-content: center; }
311
+ [data-stx-data-grid] .stx-dg-head-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
312
+ [data-stx-data-grid] .stx-dg-sort { flex: 0 0 auto; color: var(--stx-grid-accent); font-size: 9px; font-variant-numeric: tabular-nums; }
313
+ [data-stx-data-grid] .stx-dg-resize {
314
+ position: absolute;
315
+ top: 0;
316
+ right: -4px;
317
+ z-index: 1;
318
+ width: 9px;
319
+ height: 100%;
320
+ cursor: col-resize;
321
+ touch-action: none;
322
+ }
323
+ [data-stx-data-grid] .stx-dg-resize:hover,
324
+ [data-stx-data-grid][data-resizing] .stx-dg-resize:hover { background: linear-gradient(to right, transparent 3px, var(--stx-grid-accent) 3px, var(--stx-grid-accent) 5px, transparent 5px); }
325
+ [data-stx-data-grid][data-resizing] { cursor: col-resize; user-select: none; -webkit-user-select: none; }
326
+
327
+ [data-stx-data-grid] .stx-dg-body { position: relative; min-width: 100%; }
328
+ [data-stx-data-grid] .stx-dg-row {
329
+ position: absolute;
330
+ top: 0;
331
+ left: 0;
332
+ right: 0;
333
+ height: var(--stx-grid-row-height);
334
+ border-bottom: 1px solid var(--stx-grid-line);
335
+ box-sizing: border-box;
336
+ contain: layout style;
337
+ }
338
+ [data-stx-data-grid] .stx-dg-row:hover { background: var(--stx-grid-hover); }
339
+ [data-stx-data-grid] .stx-dg-row[aria-selected="true"] { background: var(--stx-grid-selected); }
340
+
341
+ [data-stx-data-grid] .stx-dg-cell {
342
+ position: absolute;
343
+ top: 0;
344
+ height: 100%;
345
+ padding: 0 var(--stx-grid-cell-padding);
346
+ box-sizing: border-box;
347
+ overflow: hidden;
348
+ line-height: calc(var(--stx-grid-row-height) - 1px);
349
+ text-overflow: ellipsis;
350
+ white-space: pre;
351
+ cursor: default;
352
+ }
353
+ [data-stx-data-grid] .stx-dg-cell[data-align="right"] { text-align: right; }
354
+ [data-stx-data-grid] .stx-dg-cell[data-align="center"] { text-align: center; }
355
+ /* Figures in one column line up digit under digit. */
356
+ [data-stx-data-grid] .stx-dg-cell[data-type="number"] { color: var(--stx-grid-number); font-variant-numeric: tabular-nums; }
357
+ [data-stx-data-grid] .stx-dg-cell[data-type="date"] { font-variant-numeric: tabular-nums; }
358
+ [data-stx-data-grid] .stx-dg-cell[data-type="boolean"] { color: var(--stx-grid-boolean); }
359
+ [data-stx-data-grid] .stx-dg-cell[data-type="json"] { font-family: var(--stx-grid-mono); font-size: 12px; }
360
+ [data-stx-data-grid] .stx-dg-cell[data-empty] { color: var(--stx-grid-empty-fg); font-style: italic; }
361
+
362
+ /* The active cell is only marked while the grid has the keyboard. */
363
+ [data-stx-data-grid] .stx-dg-scroller:focus :is(.stx-dg-cell, .stx-dg-head)[data-active] {
364
+ outline: 2px solid var(--stx-grid-accent);
365
+ outline-offset: -2px;
366
+ }
367
+
368
+ [data-stx-data-grid][data-empty] .stx-dg-body::after {
369
+ content: 'No rows';
370
+ position: sticky;
371
+ left: 0;
372
+ display: block;
373
+ padding: 16px var(--stx-grid-cell-padding);
374
+ color: var(--stx-grid-empty-fg);
375
+ }
376
+ </style>
@@ -0,0 +1,320 @@
1
+ <script server>
2
+ export const nodes = Array.isArray($props.nodes) ? $props.nodes : []
3
+ export const edges = Array.isArray($props.edges) ? $props.edges : []
4
+ export const layout = $props.layout === 'force' ? 'force' : 'layered'
5
+ export const direction = $props.direction === 'TB' ? 'TB' : 'LR'
6
+ export const selected = $props.selected == null ? '' : String($props.selected)
7
+ /* A CSS length. `100%` fills a sized parent, which is what a pane wants. */
8
+ export const height = $props.height || '24rem'
9
+ export const minZoom = $num($props.minZoom, 0.1)
10
+ export const maxZoom = $num($props.maxZoom, 4)
11
+ export const toolbar = $bool($props.toolbar, true)
12
+ export const contextMenu = $bool($props.contextMenu)
13
+ /* Nodes glide to a new layout. Off, they are simply there. */
14
+ export const animate = $bool($props.animate, true)
15
+ export const label = $props.label || 'Graph'
16
+ export const className = $props.className || ''
17
+ export const graphId = $props.id || `graph-view-${$uid}`
18
+ export const statusId = `${graphId}-status`
19
+ </script>
20
+
21
+ <script client>
22
+ /*
23
+ * <GraphView>: nodes and edges, laid out, that can be panned, zoomed, walked
24
+ * with the arrow keys and grown a node at a time.
25
+ *
26
+ * The layouts and the geometry are in ./core and the SVG in ./view; this is
27
+ * the wiring: props in, events out, and the toolbar.
28
+ */
29
+ import { GraphCanvas } from './view'
30
+
31
+ const emit = defineEmits(['select', 'expand', 'open', 'move', 'viewport', 'context', 'layout'])
32
+
33
+ function asList(value) {
34
+ if (Array.isArray(value)) return value
35
+ if (typeof value === 'string' && value.charAt(0) === '[') {
36
+ try { return JSON.parse(value) }
37
+ catch (e) { return [] }
38
+ }
39
+ return []
40
+ }
41
+ const asLayout = value => (value === 'force' ? 'force' : 'layered')
42
+ const asDirection = value => (value === 'TB' ? 'TB' : 'LR')
43
+ const asId = value => (value == null ? '' : String(value))
44
+
45
+ const liveNodes = useReactiveProp('nodes', {{ nodes }}, { parse: asList })
46
+ const liveEdges = useReactiveProp('edges', {{ edges }}, { parse: asList })
47
+ const liveLayout = useReactiveProp('layout', {{ layout }}, { parse: asLayout })
48
+ const liveDirection = useReactiveProp('direction', {{ direction }}, { parse: asDirection })
49
+ const liveSelected = useReactiveProp('selected', {{ selected }}, { parse: asId })
50
+
51
+ // What the layout switch shows as pressed. It follows the prop and the buttons.
52
+ const layoutName = state({{ layout }})
53
+ const zoomText = state('100%')
54
+
55
+ const rootRef = useRef('graph-view')
56
+ let canvas = null
57
+
58
+ onMount(() => {
59
+ const root = rootRef()
60
+ if (!root) return
61
+
62
+ canvas = new GraphCanvas(root, {
63
+ nodes: asList(liveNodes()),
64
+ edges: asList(liveEdges()),
65
+ layout: asLayout(liveLayout()),
66
+ direction: asDirection(liveDirection()),
67
+ selected: asId(liveSelected()) || null,
68
+ minZoom: {{ minZoom }},
69
+ maxZoom: {{ maxZoom }},
70
+ contextMenu: {{ contextMenu }},
71
+ animate: {{ animate }},
72
+ label: {{ label }},
73
+ }, {
74
+ onSelect(detail) { emit('select', detail) },
75
+ onExpand(detail) { emit('expand', detail) },
76
+ onOpen(detail) { emit('open', detail) },
77
+ onMove(detail) { emit('move', detail) },
78
+ onViewport(detail) {
79
+ zoomText.set(Math.round(detail.k * 100) + '%')
80
+ emit('viewport', detail)
81
+ },
82
+ onContext(detail) { emit('context', detail) },
83
+ onLayout(detail) {
84
+ layoutName.set(detail.layout)
85
+ emit('layout', detail)
86
+ },
87
+ })
88
+ zoomText.set(Math.round(canvas.getViewport().k * 100) + '%')
89
+
90
+ // The first run of the graph effect finds what the canvas was built with.
91
+ let graphSeen = false
92
+ effect(() => {
93
+ const nextNodes = asList(liveNodes())
94
+ const nextEdges = asList(liveEdges())
95
+ if (graphSeen) canvas.setGraph(nextNodes, nextEdges)
96
+ graphSeen = true
97
+ })
98
+ effect(() => canvas.setLayout(asLayout(liveLayout())))
99
+ effect(() => canvas.setDirection(asDirection(liveDirection())))
100
+ effect(() => {
101
+ const id = asId(liveSelected())
102
+ if (id) canvas.select(id, { silent: true })
103
+ })
104
+ })
105
+
106
+ onDestroy(() => {
107
+ if (canvas) canvas.destroy()
108
+ canvas = null
109
+ })
110
+
111
+ function zoomIn() { if (canvas) canvas.zoomIn() }
112
+ function zoomOut() { if (canvas) canvas.zoomOut() }
113
+ function fitAll() { if (canvas) canvas.fit() }
114
+ function chooseLayout(name) { if (canvas) canvas.setLayout(name) }
115
+
116
+ defineExpose({
117
+ setGraph: (nextNodes, nextEdges) => { if (canvas) canvas.setGraph(asList(nextNodes), asList(nextEdges)) },
118
+ addNeighbours: (id, moreNodes, moreEdges) => (canvas ? canvas.addNeighbours(asId(id), asList(moreNodes), asList(moreEdges)) : { nodes: [], edges: [] }),
119
+ updateNode: (id, patch) => { if (canvas) canvas.updateNode(asId(id), patch || {}) },
120
+ select: (id) => { if (canvas) canvas.select(id == null ? null : asId(id)) },
121
+ focusNode: (id) => { if (canvas) canvas.focusNode(asId(id)) },
122
+ fit: fitAll,
123
+ zoomIn,
124
+ zoomOut,
125
+ setLayout: chooseLayout,
126
+ getViewport: () => (canvas ? canvas.getViewport() : { x: 0, y: 0, k: 1 }),
127
+ graph: () => (canvas ? canvas.graph() : null),
128
+ canvas: () => canvas,
129
+ })
130
+ </script>
131
+
132
+ <div
133
+ ref="graph-view"
134
+ id="{{ graphId }}"
135
+ data-stx-graph-view
136
+ class="stx-gv {{ className }}"
137
+ style="height: {{ height }}"
138
+ >
139
+ @if(toolbar)
140
+ <div role="toolbar" aria-label="{{ label }} controls" class="stx-gv-toolbar">
141
+ <button type="button" class="stx-gv-button" aria-label="Zoom out" title="Zoom out" @click="zoomOut()">&minus;</button>
142
+ <span class="stx-gv-zoom" aria-hidden="true" x-text="zoomText()">100%</span>
143
+ <button type="button" class="stx-gv-button" aria-label="Zoom in" title="Zoom in" @click="zoomIn()">+</button>
144
+ <button type="button" class="stx-gv-button" @click="fitAll()">Fit</button>
145
+ <span class="stx-gv-divider" aria-hidden="true"></span>
146
+ <button type="button" class="stx-gv-button" data-gv-layout="layered" :aria-pressed="layoutName() === 'layered' ? 'true' : 'false'" @click="chooseLayout('layered')">Layered</button>
147
+ <button type="button" class="stx-gv-button" data-gv-layout="force" :aria-pressed="layoutName() === 'force' ? 'true' : 'false'" @click="chooseLayout('force')">Force</button>
148
+ </div>
149
+ @endif
150
+
151
+ {{-- The graph itself. One stop in the tab order; the arrow keys walk the
152
+ nodes from there, and the status line below says where they landed. --}}
153
+ <div
154
+ data-gv="surface"
155
+ class="stx-gv-surface"
156
+ tabindex="0"
157
+ role="application"
158
+ aria-roledescription="graph"
159
+ aria-label="{{ label }}"
160
+ aria-describedby="{{ statusId }}"
161
+ ></div>
162
+
163
+ <div data-gv="status" id="{{ statusId }}" role="status" aria-live="polite" class="stx-gv-status"></div>
164
+ </div>
165
+
166
+ <style>
167
+ /*
168
+ * Everything the graph is drawn with is a custom property that falls back to
169
+ * one of the library's role tokens, so a themed app has a matching graph.
170
+ */
171
+ :where([data-stx-graph-view]) {
172
+ --stx-graph-bg: var(--stx-panel, #ffffff);
173
+ --stx-graph-fg: var(--stx-fg, #171717);
174
+ --stx-graph-muted: var(--stx-fg-soft, #737373);
175
+ --stx-graph-line: var(--stx-line, #e5e5e5);
176
+ --stx-graph-node-bg: var(--stx-surface, #fafafa);
177
+ --stx-graph-node-line: var(--stx-line-strong, #a3a3a3);
178
+ --stx-graph-edge: var(--stx-fg-subtle, #a3a3a3);
179
+ --stx-graph-accent: var(--stx-accent, #2563eb);
180
+ --stx-graph-font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
181
+ --stx-graph-font-size: 12px;
182
+ --stx-graph-dim: 0.22;
183
+ position: relative;
184
+ display: flex;
185
+ flex-direction: column;
186
+ min-width: 0;
187
+ min-height: 0;
188
+ overflow: hidden;
189
+ border: 1px solid var(--stx-graph-line);
190
+ border-radius: var(--stx-radius-panel, 8px);
191
+ background: var(--stx-graph-bg);
192
+ color: var(--stx-graph-fg);
193
+ font-family: var(--stx-graph-font);
194
+ font-size: var(--stx-graph-font-size);
195
+ }
196
+
197
+ [data-stx-graph-view] .stx-gv-toolbar {
198
+ display: flex;
199
+ flex: 0 0 auto;
200
+ align-items: center;
201
+ gap: 4px;
202
+ padding: 4px 6px;
203
+ border-bottom: 1px solid var(--stx-graph-line);
204
+ }
205
+ [data-stx-graph-view] .stx-gv-button {
206
+ min-width: 26px;
207
+ height: 24px;
208
+ padding: 0 8px;
209
+ border: 1px solid transparent;
210
+ border-radius: 5px;
211
+ background: transparent;
212
+ color: inherit;
213
+ font: inherit;
214
+ line-height: 1;
215
+ cursor: pointer;
216
+ }
217
+ [data-stx-graph-view] .stx-gv-button:hover { background: color-mix(in srgb, var(--stx-graph-fg) 8%, transparent); }
218
+ [data-stx-graph-view] .stx-gv-button[aria-pressed="true"] {
219
+ border-color: var(--stx-graph-line);
220
+ background: color-mix(in srgb, var(--stx-graph-accent) 14%, transparent);
221
+ }
222
+ [data-stx-graph-view] .stx-gv-button:focus-visible {
223
+ outline: 2px solid var(--stx-graph-accent);
224
+ outline-offset: 1px;
225
+ }
226
+ [data-stx-graph-view] .stx-gv-zoom {
227
+ min-width: 4ch;
228
+ color: var(--stx-graph-muted);
229
+ text-align: center;
230
+ font-variant-numeric: tabular-nums;
231
+ }
232
+ [data-stx-graph-view] .stx-gv-divider {
233
+ width: 1px;
234
+ height: 16px;
235
+ margin: 0 4px;
236
+ background: var(--stx-graph-line);
237
+ }
238
+
239
+ [data-stx-graph-view] .stx-gv-surface {
240
+ position: relative;
241
+ flex: 1 1 0px;
242
+ min-height: 0;
243
+ overflow: hidden;
244
+ outline: none;
245
+ cursor: grab;
246
+ touch-action: none;
247
+ user-select: none;
248
+ -webkit-user-select: none;
249
+ }
250
+ [data-stx-graph-view] .stx-gv-surface:focus-visible { box-shadow: inset 0 0 0 2px var(--stx-graph-accent); }
251
+ [data-stx-graph-view][data-dragging] .stx-gv-surface { cursor: grabbing; }
252
+
253
+ [data-stx-graph-view] .stx-gv-svg {
254
+ display: block;
255
+ width: 100%;
256
+ height: 100%;
257
+ }
258
+
259
+ [data-stx-graph-view] .stx-gv-node { cursor: pointer; transition: opacity 120ms ease; }
260
+ [data-stx-graph-view] .stx-gv-node rect {
261
+ fill: var(--stx-graph-node-bg);
262
+ stroke: var(--stx-graph-node-line);
263
+ stroke-width: 1;
264
+ }
265
+ [data-stx-graph-view] .stx-gv-node text {
266
+ fill: var(--stx-graph-fg);
267
+ font-family: var(--stx-graph-font);
268
+ font-size: var(--stx-graph-font-size);
269
+ pointer-events: none;
270
+ }
271
+ [data-stx-graph-view] .stx-gv-node .stx-gv-node-detail { fill: var(--stx-graph-muted); font-size: 10px; }
272
+ [data-stx-graph-view] .stx-gv-node .stx-gv-node-mark { fill: var(--stx-graph-muted); font-weight: 600; }
273
+ [data-stx-graph-view] .stx-gv-node:hover rect { stroke: var(--stx-graph-accent); }
274
+ [data-stx-graph-view] .stx-gv-node[data-selected] rect {
275
+ fill: color-mix(in srgb, var(--stx-graph-accent) 14%, var(--stx-graph-node-bg));
276
+ stroke: var(--stx-graph-accent);
277
+ stroke-width: 2;
278
+ }
279
+ [data-stx-graph-view] .stx-gv-node[data-neighbour] rect { stroke: var(--stx-graph-accent); }
280
+
281
+ [data-stx-graph-view] .stx-gv-edge { transition: opacity 120ms ease; }
282
+ [data-stx-graph-view] .stx-gv-edge path {
283
+ stroke: var(--stx-graph-edge);
284
+ stroke-width: 1.25;
285
+ }
286
+ [data-stx-graph-view] .stx-gv-edge[data-active] path { stroke: var(--stx-graph-accent); stroke-width: 1.75; }
287
+ [data-stx-graph-view] .stx-gv-arrow path { fill: var(--stx-graph-edge); }
288
+ [data-stx-graph-view] .stx-gv-arrow-active path { fill: var(--stx-graph-accent); }
289
+
290
+ [data-stx-graph-view] .stx-gv-edge-label { pointer-events: none; transition: opacity 120ms ease; }
291
+ [data-stx-graph-view] .stx-gv-edge-label rect { fill: var(--stx-graph-bg); }
292
+ [data-stx-graph-view] .stx-gv-edge-label text {
293
+ fill: var(--stx-graph-muted);
294
+ font-family: var(--stx-graph-font);
295
+ font-size: 10px;
296
+ }
297
+ [data-stx-graph-view] .stx-gv-edge-label[data-active] text { fill: var(--stx-graph-accent); }
298
+
299
+ /* With a node selected, what it does not touch steps back. */
300
+ [data-stx-graph-view][data-has-selection] .stx-gv-node:not([data-selected], [data-neighbour]),
301
+ [data-stx-graph-view][data-has-selection] .stx-gv-edge:not([data-active]),
302
+ [data-stx-graph-view][data-has-selection] .stx-gv-edge-label:not([data-active]) { opacity: var(--stx-graph-dim); }
303
+
304
+ /* Read aloud, never seen. */
305
+ [data-stx-graph-view] .stx-gv-status {
306
+ position: absolute;
307
+ width: 1px;
308
+ height: 1px;
309
+ margin: -1px;
310
+ padding: 0;
311
+ overflow: hidden;
312
+ clip: rect(0, 0, 0, 0);
313
+ white-space: nowrap;
314
+ border: 0;
315
+ }
316
+
317
+ @media (prefers-reduced-motion: reduce) {
318
+ [data-stx-graph-view] :is(.stx-gv-node, .stx-gv-edge, .stx-gv-edge-label) { transition: none; }
319
+ }
320
+ </style>