@stacksjs/components 0.2.855 → 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.
- package/dist/ContextMenu-43g3w5tp.stx +188 -0
- package/dist/DataGrid-7rt7v865.stx +376 -0
- package/dist/GraphView-0t3t9mec.stx +320 -0
- package/dist/JsonTree-satc4010.stx +317 -0
- package/dist/PreviewFrame-erbgvzj8.stx +257 -0
- package/dist/SplitPane-7sqfdwqa.stx +159 -0
- package/dist/component-api/component-api.js +36 -0
- package/dist/context-menu/context-menu.js +575 -0
- package/dist/data-grid/data-grid.js +1244 -0
- package/dist/graph-view/graph-view.js +1408 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +22 -20
- package/dist/json-tree/json-tree.js +1121 -0
- package/dist/preview-frame/preview-frame.js +356 -0
- package/dist/split-pane/split-pane.js +364 -0
- package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
- package/dist/ui/context-menu/context-menu.d.ts +8 -0
- package/dist/ui/context-menu/core.d.ts +74 -0
- package/dist/ui/context-menu/index.d.ts +11 -0
- package/dist/ui/context-menu/view.d.ts +36 -0
- package/dist/ui/data-grid/DataGrid.d.ts +30 -0
- package/dist/ui/data-grid/core.d.ts +141 -0
- package/dist/ui/data-grid/data-grid.d.ts +9 -0
- package/dist/ui/data-grid/index.d.ts +20 -0
- package/dist/ui/data-grid/view.d.ts +56 -0
- package/dist/ui/graph-view/GraphView.d.ts +21 -0
- package/dist/ui/graph-view/core/edges.d.ts +34 -0
- package/dist/ui/graph-view/core/force.d.ts +10 -0
- package/dist/ui/graph-view/core/graph.d.ts +83 -0
- package/dist/ui/graph-view/core/index.d.ts +5 -0
- package/dist/ui/graph-view/core/layered.d.ts +24 -0
- package/dist/ui/graph-view/core/viewport.d.ts +34 -0
- package/dist/ui/graph-view/graph-view.d.ts +9 -0
- package/dist/ui/graph-view/index.d.ts +21 -0
- package/dist/ui/graph-view/view.d.ts +51 -0
- package/dist/ui/json-tree/JsonTree.d.ts +18 -0
- package/dist/ui/json-tree/core.d.ts +108 -0
- package/dist/ui/json-tree/index.d.ts +18 -0
- package/dist/ui/json-tree/json-tree.d.ts +10 -0
- package/dist/ui/json-tree/tinker.d.ts +84 -0
- package/dist/ui/json-tree/view.d.ts +59 -0
- package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
- package/dist/ui/preview-frame/core.d.ts +81 -0
- package/dist/ui/preview-frame/index.d.ts +19 -0
- package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
- package/dist/ui/preview-frame/view.d.ts +37 -0
- package/dist/ui/split-pane/SplitPane.d.ts +18 -0
- package/dist/ui/split-pane/core.d.ts +58 -0
- package/dist/ui/split-pane/index.d.ts +15 -0
- package/dist/ui/split-pane/split-pane.d.ts +8 -0
- package/dist/ui/split-pane/view.d.ts +27 -0
- package/dist/ui/virtual-table/index.d.ts +6 -0
- package/dist/utils/component-api.d.ts +4 -0
- package/package.json +38 -3
- package/src/index.ts +8 -0
- package/src/ui/code-editor/README.md +2 -1
- package/src/ui/context-menu/ContextMenu.stx +188 -0
- package/src/ui/context-menu/README.md +117 -0
- package/src/ui/context-menu/context-menu.ts +8 -0
- package/src/ui/context-menu/core.ts +250 -0
- package/src/ui/context-menu/index.ts +16 -0
- package/src/ui/context-menu/view.ts +540 -0
- package/src/ui/data-grid/DataGrid.stx +376 -0
- package/src/ui/data-grid/README.md +204 -0
- package/src/ui/data-grid/core.ts +813 -0
- package/src/ui/data-grid/data-grid.ts +9 -0
- package/src/ui/data-grid/index.ts +34 -0
- package/src/ui/data-grid/view.ts +806 -0
- package/src/ui/graph-view/GraphView.stx +320 -0
- package/src/ui/graph-view/README.md +210 -0
- package/src/ui/graph-view/core/edges.ts +180 -0
- package/src/ui/graph-view/core/force.ts +237 -0
- package/src/ui/graph-view/core/graph.ts +277 -0
- package/src/ui/graph-view/core/index.ts +5 -0
- package/src/ui/graph-view/core/layered.ts +256 -0
- package/src/ui/graph-view/core/viewport.ts +141 -0
- package/src/ui/graph-view/graph-view.ts +9 -0
- package/src/ui/graph-view/index.ts +35 -0
- package/src/ui/graph-view/view.ts +809 -0
- package/src/ui/json-tree/JsonTree.stx +317 -0
- package/src/ui/json-tree/README.md +193 -0
- package/src/ui/json-tree/core.ts +588 -0
- package/src/ui/json-tree/index.ts +28 -0
- package/src/ui/json-tree/json-tree.ts +10 -0
- package/src/ui/json-tree/tinker.ts +349 -0
- package/src/ui/json-tree/view.ts +665 -0
- package/src/ui/preview-frame/PreviewFrame.stx +257 -0
- package/src/ui/preview-frame/README.md +107 -0
- package/src/ui/preview-frame/core.ts +195 -0
- package/src/ui/preview-frame/index.ts +31 -0
- package/src/ui/preview-frame/preview-frame.ts +8 -0
- package/src/ui/preview-frame/view.ts +336 -0
- package/src/ui/split-pane/README.md +87 -0
- package/src/ui/split-pane/SplitPane.stx +159 -0
- package/src/ui/split-pane/core.ts +200 -0
- package/src/ui/split-pane/index.ts +24 -0
- package/src/ui/split-pane/split-pane.ts +8 -0
- package/src/ui/split-pane/view.ts +305 -0
- package/src/ui/virtual-table/index.ts +6 -0
- package/src/utils/component-api.ts +72 -0
|
@@ -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()">−</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>
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# GraphView
|
|
2
|
+
|
|
3
|
+
Nodes and edges, laid out automatically, in an SVG that can be panned, zoomed,
|
|
4
|
+
walked with the arrow keys and grown one node at a time. No third-party graph
|
|
5
|
+
or layout library underneath; both layouts are in `core/`.
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script client>
|
|
9
|
+
const nodes = [
|
|
10
|
+
{ id: 'User', label: 'User', kind: 'model', detail: 'users', expandable: true },
|
|
11
|
+
{ id: 'Post', label: 'Post', kind: 'model' },
|
|
12
|
+
{ id: 'Team', label: 'Team', kind: 'model' },
|
|
13
|
+
]
|
|
14
|
+
const edges = [
|
|
15
|
+
{ source: 'User', target: 'Post', label: 'hasMany' },
|
|
16
|
+
{ source: 'User', target: 'Team', label: 'belongsTo' },
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
function expand(detail) {
|
|
20
|
+
// detail.node is the node to load more around. Answer with addNeighbours.
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<GraphView label="Model relations" height="24rem" :nodes="nodes" :edges="edges" @expand="expand($event)" />
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
A component's event hands its payload to the handler as `$event`, so `expand`
|
|
28
|
+
above receives the detail object itself.
|
|
29
|
+
|
|
30
|
+
It is made for two pictures:
|
|
31
|
+
|
|
32
|
+
- **A model relation graph.** A node per model, an edge per relation, the
|
|
33
|
+
relation kind (`hasMany`, `belongsTo`) as the edge label. The layered layout
|
|
34
|
+
reads left to right from the model you started at.
|
|
35
|
+
- **An object graph.** A node per object, an edge per property that holds
|
|
36
|
+
another object, the property name as the label. Cycles are fine: an edge that
|
|
37
|
+
closes one is drawn against the flow, and an object that holds itself gets a
|
|
38
|
+
loop.
|
|
39
|
+
|
|
40
|
+
## How it works
|
|
41
|
+
|
|
42
|
+
Three layers of code, each usable without the ones above it:
|
|
43
|
+
|
|
44
|
+
| File | What it is |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `core/` | The model (`GraphModel`), the layered and force layouts, edge geometry and the viewport arithmetic. No DOM and no stx, so it runs anywhere. |
|
|
47
|
+
| `view.ts` | `GraphCanvas`: the SVG, the pointer, wheel and key handling, selection and the status line. |
|
|
48
|
+
| `GraphView.stx` | The template, the toolbar, the styles, and the props and events. |
|
|
49
|
+
|
|
50
|
+
`@stacksjs/components/graph-view` exports the first two for a host that mounts
|
|
51
|
+
a graph itself or wants a layout on its own.
|
|
52
|
+
|
|
53
|
+
A node's size comes from the length of its label, not from measuring text, so a
|
|
54
|
+
layout never touches the DOM. One SVG group carries the pan and zoom, so moving
|
|
55
|
+
the view writes one attribute however many nodes there are.
|
|
56
|
+
|
|
57
|
+
## Nodes and edges
|
|
58
|
+
|
|
59
|
+
| Node field | |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `id` | Required, unique. |
|
|
62
|
+
| `label` | What is written in the node. The id when left out. Cut with an ellipsis past about 28 characters; the full text is the tooltip. |
|
|
63
|
+
| `detail` | A second, quieter line. |
|
|
64
|
+
| `kind` | A free word, put on the node as `data-kind` for a stylesheet to colour by. |
|
|
65
|
+
| `expandable` | `true` draws a `+` mark. `false` means there is nothing more to load: the node is opened instead of expanded. |
|
|
66
|
+
| `data` | Anything; it comes back with the node in every event. |
|
|
67
|
+
|
|
68
|
+
| Edge field | |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `source`, `target` | Node ids. An edge whose ends are not both in the graph is ignored. |
|
|
71
|
+
| `label` | Drawn at the middle of the edge. |
|
|
72
|
+
| `directed` | Default `true`. `false` draws no arrowhead. |
|
|
73
|
+
| `id` | Left out, it is `source->target` plus `:label`. Two edges with the same id are one edge. |
|
|
74
|
+
|
|
75
|
+
Several edges between the same two nodes are drawn beside each other.
|
|
76
|
+
|
|
77
|
+
## Props
|
|
78
|
+
|
|
79
|
+
| Prop | Default | |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `nodes`, `edges` | `[]` | Bound with `:nodes` and `:edges`. A new array replaces the graph and fits it. |
|
|
82
|
+
| `layout` | `'layered'` | `layered` points every edge one way. `force` lets nodes push apart and edges pull together. |
|
|
83
|
+
| `direction` | `'LR'` | The flow of the layered layout: `LR` or `TB`. |
|
|
84
|
+
| `selected` | | The id of the selected node. |
|
|
85
|
+
| `height` | `'24rem'` | Any CSS length. `100%` fills a sized parent. |
|
|
86
|
+
| `minZoom`, `maxZoom` | `0.1`, `4` | |
|
|
87
|
+
| `toolbar` | `true` | The zoom, fit and layout buttons. |
|
|
88
|
+
| `contextMenu` | `false` | Keep the browser's own menu away on a right click, for a host that shows its own from `@context`. |
|
|
89
|
+
| `animate` | `true` | Nodes glide to a new layout. Always off under `prefers-reduced-motion`. |
|
|
90
|
+
| `label` | `'Graph'` | The accessible name. |
|
|
91
|
+
| `id`, `className` | | |
|
|
92
|
+
|
|
93
|
+
## Events
|
|
94
|
+
|
|
95
|
+
| Event | Payload |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `@select` | `{ node, neighbours }`. `node` is null when the selection is cleared. |
|
|
98
|
+
| `@expand` | `{ node }`. A double click, or Enter or Space on the selected node. Answer with `addNeighbours`. |
|
|
99
|
+
| `@open` | `{ node }`. The same gestures on a node with `expandable: false`, or with Cmd/Ctrl held, or the `o` key. |
|
|
100
|
+
| `@move` | `{ node, x, y }`. A node was dragged; the position is in graph units. |
|
|
101
|
+
| `@viewport` | `{ x, y, k }`. A point on screen is the graph point times `k`, plus `x` and `y`. |
|
|
102
|
+
| `@context` | `{ node, x, y }`. A right click; `node` is null on the background, `x` and `y` are client coordinates. |
|
|
103
|
+
| `@layout` | `{ layout }` |
|
|
104
|
+
|
|
105
|
+
## Methods
|
|
106
|
+
|
|
107
|
+
From `componentApi(target)` (`@stacksjs/components/component-api`), where
|
|
108
|
+
`target` is the component's element, its id or a selector: `setGraph(nodes, edges)`,
|
|
109
|
+
`addNeighbours(id, nodes, edges)`, `updateNode(id, patch)`, `select(id)`,
|
|
110
|
+
`focusNode(id)`, `fit()`, `zoomIn()`, `zoomOut()`, `setLayout(name)`,
|
|
111
|
+
`getViewport()`, `graph()` for the model and `canvas()` for the view itself.
|
|
112
|
+
|
|
113
|
+
`addNeighbours` is the answer to `@expand`. It adds what is new and ignores
|
|
114
|
+
what the graph already has, so the reply can name nodes that are already drawn.
|
|
115
|
+
The new nodes start on the node they came from and move out to their places.
|
|
116
|
+
It returns the ids it actually added. Follow it with
|
|
117
|
+
`updateNode(id, { expandable: false })` to take the `+` off.
|
|
118
|
+
|
|
119
|
+
## Keys
|
|
120
|
+
|
|
121
|
+
With the graph focused. It is one stop in the tab order.
|
|
122
|
+
|
|
123
|
+
| Key | |
|
|
124
|
+
|---|---|
|
|
125
|
+
| Arrow keys | Select the nearest node in that direction. A node straight ahead beats a closer one off to the side. With nothing selected, the node nearest the middle. |
|
|
126
|
+
| Enter, Space | Expand the selected node. |
|
|
127
|
+
| `o`, or Cmd/Ctrl+Enter | Open it. |
|
|
128
|
+
| `+`, `-` | Zoom in and out. |
|
|
129
|
+
| `0` | Fit the whole graph. |
|
|
130
|
+
| `f` | Centre the selected node. |
|
|
131
|
+
| Escape | Clear the selection. |
|
|
132
|
+
|
|
133
|
+
## Pointer
|
|
134
|
+
|
|
135
|
+
| Gesture | |
|
|
136
|
+
|---|---|
|
|
137
|
+
| Drag the background | Pan. |
|
|
138
|
+
| Drag a node | Move it. In the force layout it then stays where it was put. |
|
|
139
|
+
| Scroll | Pan. |
|
|
140
|
+
| Pinch, or scroll with Ctrl or Cmd | Zoom about the pointer. |
|
|
141
|
+
| Click | Select. On the background, clear the selection. |
|
|
142
|
+
| Double click | Expand. |
|
|
143
|
+
|
|
144
|
+
## Accessibility
|
|
145
|
+
|
|
146
|
+
The graph is a `role="application"` region described as a graph, with the
|
|
147
|
+
label you give it. The selected node is its `aria-activedescendant`, each node
|
|
148
|
+
is named with its label and how many connections it has, and a polite live
|
|
149
|
+
region says where the selection landed and what it connects to: "User, 2
|
|
150
|
+
connections: Post, Team". The toolbar is a real toolbar of real buttons, and
|
|
151
|
+
the layout switch reports which layout is pressed.
|
|
152
|
+
|
|
153
|
+
## The layouts
|
|
154
|
+
|
|
155
|
+
**Layered.** Cycles are broken by turning round the edges a depth-first walk
|
|
156
|
+
finds pointing back at its own path. Each node goes one layer past its deepest
|
|
157
|
+
predecessor. Each layer is reordered by where its neighbours sit, a few times
|
|
158
|
+
each way, keeping the order with the fewest crossings. Unconnected parts are
|
|
159
|
+
stacked beside each other. Nothing is random: the same graph comes out the same.
|
|
160
|
+
|
|
161
|
+
**Force.** Every node pushes every other and every edge pulls its ends
|
|
162
|
+
together, with a temperature that cools. Starting positions come from a seeded
|
|
163
|
+
source, so it is deterministic too. An expansion starts warm: the nodes that
|
|
164
|
+
already have a place keep it while the new ones find theirs, and are then moved
|
|
165
|
+
only as far as it takes to stop two boxes overlapping.
|
|
166
|
+
|
|
167
|
+
## Theming
|
|
168
|
+
|
|
169
|
+
Everything is a CSS custom property that falls back to one of the library's
|
|
170
|
+
role tokens, so an app that has themed its roles already has a matching graph,
|
|
171
|
+
in light and dark.
|
|
172
|
+
|
|
173
|
+
- `--stx-graph-bg`, `--stx-graph-fg`, `--stx-graph-muted`, `--stx-graph-line`
|
|
174
|
+
- `--stx-graph-node-bg`, `--stx-graph-node-line`, `--stx-graph-edge`
|
|
175
|
+
- `--stx-graph-accent` for the selection, `--stx-graph-dim` for how far the
|
|
176
|
+
rest steps back
|
|
177
|
+
- `--stx-graph-font`, `--stx-graph-font-size`
|
|
178
|
+
|
|
179
|
+
Colour a kind of node from your own stylesheet:
|
|
180
|
+
|
|
181
|
+
```css
|
|
182
|
+
[data-stx-graph-view] .stx-gv-node[data-kind="model"] rect { fill: var(--stx-accent-soft); }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Measured
|
|
186
|
+
|
|
187
|
+
Headless WebKit, 200 nodes and 300 edges, with a forced layout read after each
|
|
188
|
+
step. WebKit's clock is a millisecond coarse.
|
|
189
|
+
|
|
190
|
+
| | |
|
|
191
|
+
|---|---|
|
|
192
|
+
| Layered layout | 1 to 2 ms |
|
|
193
|
+
| Force layout, from cold | about 40 ms |
|
|
194
|
+
| First render, layout included | 7 ms |
|
|
195
|
+
| A pan step | 1.1 ms mean, 2 ms at the 95th percentile |
|
|
196
|
+
| A zoom step | 1.4 ms mean, 2 ms at the 95th percentile |
|
|
197
|
+
| Expanding a node by ten | 6 ms layered, 11 ms force |
|
|
198
|
+
|
|
199
|
+
## Limits of this version
|
|
200
|
+
|
|
201
|
+
- **Every node is in the DOM.** Nothing is culled when it is off screen. That
|
|
202
|
+
is right for hundreds of nodes; thousands want a canvas.
|
|
203
|
+
- **The force layout compares every pair of nodes.** About 40 ms at 200 nodes,
|
|
204
|
+
and it grows with the square of the count.
|
|
205
|
+
- **Edges in the layered layout are single curves.** An edge that spans several
|
|
206
|
+
layers can pass behind a node in between; there are no routing points.
|
|
207
|
+
- **Label width is estimated.** A character is taken to be 7 pixels wide, so a
|
|
208
|
+
label in a script with much wider characters can touch the edge of its node.
|
|
209
|
+
- **No touch pinch.** One finger pans and drags; a trackpad pinch zooms, two
|
|
210
|
+
fingers on a touch screen do not.
|