@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,317 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* Either prop can arrive here as an object (a value known on the server) or
|
|
4
|
+
* not at all (a bound one, which the client script reads live).
|
|
5
|
+
*/
|
|
6
|
+
export const value = $props.value && typeof $props.value === 'object' ? $props.value : null
|
|
7
|
+
export const tinker = $props.tinker && typeof $props.tinker === 'object' ? $props.tinker : null
|
|
8
|
+
export const depth = $num($props.depth, 1)
|
|
9
|
+
export const rowHeight = $num($props.rowHeight) || 22
|
|
10
|
+
export const contextMenu = $bool($props.contextMenu)
|
|
11
|
+
/* A CSS length. `100%` fills a sized parent, which is what a pane wants. */
|
|
12
|
+
export const height = $props.height || '20rem'
|
|
13
|
+
export const label = $props.label || 'Value'
|
|
14
|
+
export const className = $props.className || ''
|
|
15
|
+
export const treeId = $props.id || `json-tree-${$uid}`
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script client>
|
|
19
|
+
/*
|
|
20
|
+
* <JsonTree>: an expandable inspector for a described value.
|
|
21
|
+
*
|
|
22
|
+
* This script is the wiring: props in, events out. Which rows are visible is
|
|
23
|
+
* in ./core, how a tinker result becomes nodes is in ./tinker, and how the
|
|
24
|
+
* rows on screen are drawn is in ./view.
|
|
25
|
+
*/
|
|
26
|
+
import { fromTinkerValue } from './tinker'
|
|
27
|
+
import { JsonTreeView } from './view'
|
|
28
|
+
|
|
29
|
+
const emit = defineEmits(['select', 'toggle', 'copy', 'open', 'load-more', 'context'])
|
|
30
|
+
|
|
31
|
+
function asBoolean(value) {
|
|
32
|
+
if (value == null) return false
|
|
33
|
+
if (typeof value === 'string') return !['false', '0', 'off', 'no'].includes(value.trim().toLowerCase())
|
|
34
|
+
return Boolean(value)
|
|
35
|
+
}
|
|
36
|
+
// A described value is an object or a list of them. As an attribute it is JSON.
|
|
37
|
+
function asDescribed(value) {
|
|
38
|
+
if (value && typeof value === 'object') return value
|
|
39
|
+
if (typeof value === 'string' && (value.charAt(0) === '{' || value.charAt(0) === '[')) {
|
|
40
|
+
try { return JSON.parse(value) }
|
|
41
|
+
catch (e) { return null }
|
|
42
|
+
}
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
function asDepth(value) {
|
|
46
|
+
const number = Number(value)
|
|
47
|
+
return value == null || value === '' || Number.isNaN(number) ? 1 : number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const liveValue = useReactiveProp('value', {{ value }}, { parse: asDescribed })
|
|
51
|
+
const liveTinker = useReactiveProp('tinker', {{ tinker }}, { parse: asDescribed })
|
|
52
|
+
const liveDepth = useReactiveProp('depth', {{ depth }}, { parse: asDepth })
|
|
53
|
+
const liveContextMenu = useReactiveProp('contextMenu', {{ contextMenu }}, { parse: asBoolean })
|
|
54
|
+
// A function can only arrive through a bound attribute, and is read as it is.
|
|
55
|
+
const liveOpenable = useReactiveProp('openable', null, { parse: v => v })
|
|
56
|
+
|
|
57
|
+
// The nodes to show: the described value, or the tinker result adapted.
|
|
58
|
+
function described() {
|
|
59
|
+
const nodes = asDescribed(liveValue())
|
|
60
|
+
if (nodes) return nodes
|
|
61
|
+
const result = asDescribed(liveTinker())
|
|
62
|
+
return result ? fromTinkerValue(result) : null
|
|
63
|
+
}
|
|
64
|
+
function asFunction(value) { return typeof value === 'function' ? value : null }
|
|
65
|
+
|
|
66
|
+
const rootRef = useRef('json-tree')
|
|
67
|
+
let tree = null
|
|
68
|
+
|
|
69
|
+
onMount(() => {
|
|
70
|
+
const root = rootRef()
|
|
71
|
+
if (!root) return
|
|
72
|
+
|
|
73
|
+
tree = new JsonTreeView(root, {
|
|
74
|
+
value: described(),
|
|
75
|
+
depth: asDepth(liveDepth()),
|
|
76
|
+
rowHeight: {{ rowHeight }},
|
|
77
|
+
openable: asFunction(liveOpenable()),
|
|
78
|
+
contextMenu: asBoolean(liveContextMenu()),
|
|
79
|
+
}, {
|
|
80
|
+
onSelect(detail) { emit('select', detail) },
|
|
81
|
+
onToggle(detail) { emit('toggle', detail) },
|
|
82
|
+
onCopy(detail) { emit('copy', detail) },
|
|
83
|
+
onOpen(detail) { emit('open', detail) },
|
|
84
|
+
onLoadMore(detail) { emit('load-more', detail) },
|
|
85
|
+
onContext(detail) { emit('context', detail) },
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
// The first run of each finds what the view was just built with. Setting it
|
|
89
|
+
// again would throw away nothing yet, but would build the rows twice.
|
|
90
|
+
let valueSeen = false
|
|
91
|
+
effect(() => {
|
|
92
|
+
const next = described()
|
|
93
|
+
if (valueSeen) tree.setValue(next)
|
|
94
|
+
valueSeen = true
|
|
95
|
+
})
|
|
96
|
+
let depthSeen = false
|
|
97
|
+
effect(() => {
|
|
98
|
+
const next = asDepth(liveDepth())
|
|
99
|
+
if (depthSeen) tree.setDepth(next)
|
|
100
|
+
depthSeen = true
|
|
101
|
+
})
|
|
102
|
+
effect(() => tree.setOpenable(asFunction(liveOpenable())))
|
|
103
|
+
effect(() => tree.setContextMenu(asBoolean(liveContextMenu())))
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
onDestroy(() => {
|
|
107
|
+
if (tree) tree.destroy()
|
|
108
|
+
tree = null
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
defineExpose({
|
|
112
|
+
expandAll: (id) => { if (tree) tree.expandAll(id) },
|
|
113
|
+
collapseAll: () => { if (tree) tree.collapseAll() },
|
|
114
|
+
expand: id => (tree ? tree.expand(id) : false),
|
|
115
|
+
collapse: id => (tree ? tree.collapse(id) : false),
|
|
116
|
+
reveal: id => (tree ? tree.reveal(id) : false),
|
|
117
|
+
appendChildren: (id, nodes, more) => (tree ? tree.appendChildren(id, nodes, more) : false),
|
|
118
|
+
setValue: (node) => { if (tree) tree.setValue(node) },
|
|
119
|
+
setTinker: (result) => { if (tree) tree.setValue(result ? fromTinkerValue(result) : null) },
|
|
120
|
+
getSelected: () => (tree ? tree.getSelected() : null),
|
|
121
|
+
select: id => (tree ? tree.select(id) : false),
|
|
122
|
+
focus: () => { if (tree) tree.focus() },
|
|
123
|
+
tree: () => tree,
|
|
124
|
+
})
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<div
|
|
128
|
+
ref="json-tree"
|
|
129
|
+
id="{{ treeId }}"
|
|
130
|
+
data-stx-json-tree
|
|
131
|
+
class="stx-jt {{ className }}"
|
|
132
|
+
style="height: {{ height }}"
|
|
133
|
+
>
|
|
134
|
+
{{-- The tree is the thing with focus. Its rows are drawn by the view, and
|
|
135
|
+
the two wrappers between them carry no meaning of their own. --}}
|
|
136
|
+
<div data-jt="scroller" role="tree" tabindex="0" aria-label="{{ label }}" class="stx-jt-scroller">
|
|
137
|
+
<div data-jt="content" role="none" class="stx-jt-content">
|
|
138
|
+
<div data-jt="rows" role="none" class="stx-jt-rows"></div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
<div data-jt="status" role="status" aria-live="polite" class="stx-jt-status"></div>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<style>
|
|
145
|
+
/*
|
|
146
|
+
* Everything the tree is drawn with is a custom property. The surface colours
|
|
147
|
+
* fall back to the library's role tokens and the value colours to the syntax
|
|
148
|
+
* tokens <CodeBlock> and <CodeEditor> use, so a value reads like the code that
|
|
149
|
+
* produced it. Each has a literal behind it, because the stylesheet that
|
|
150
|
+
* defines the syntax tokens ships with those components and may not be here.
|
|
151
|
+
*/
|
|
152
|
+
:where([data-stx-json-tree]) {
|
|
153
|
+
--stx-tree-font: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
|
|
154
|
+
--stx-tree-font-size: 12.5px;
|
|
155
|
+
--stx-tree-row-height: 22px;
|
|
156
|
+
--stx-tree-indent: 14px;
|
|
157
|
+
--stx-tree-bg: var(--stx-panel, #ffffff);
|
|
158
|
+
--stx-tree-fg: var(--stx-fg, #171717);
|
|
159
|
+
--stx-tree-muted: var(--stx-fg-soft, #737373);
|
|
160
|
+
--stx-tree-hover: color-mix(in srgb, var(--stx-fg, #171717) 6%, transparent);
|
|
161
|
+
--stx-tree-active: color-mix(in srgb, var(--stx-accent, #2563eb) 16%, transparent);
|
|
162
|
+
--stx-tree-focus: var(--stx-accent, #2563eb);
|
|
163
|
+
--stx-tree-line: var(--stx-line, #e5e5e5);
|
|
164
|
+
--stx-tree-key: var(--stx-syntax-attribute, #0550ae);
|
|
165
|
+
--stx-tree-string: var(--stx-syntax-string, #0a3069);
|
|
166
|
+
--stx-tree-number: var(--stx-syntax-numeric, #0550ae);
|
|
167
|
+
--stx-tree-keyword: var(--stx-syntax-keyword, #cf222e);
|
|
168
|
+
--stx-tree-type: var(--stx-syntax-type, #953800);
|
|
169
|
+
--stx-tree-function: var(--stx-syntax-function, #8250df);
|
|
170
|
+
--stx-tree-comment: var(--stx-syntax-comment, #6e7781);
|
|
171
|
+
--stx-tree-error: var(--stx-danger, #dc2626);
|
|
172
|
+
position: relative;
|
|
173
|
+
display: flex;
|
|
174
|
+
flex-direction: column;
|
|
175
|
+
min-width: 0;
|
|
176
|
+
background: var(--stx-tree-bg);
|
|
177
|
+
color: var(--stx-tree-fg);
|
|
178
|
+
}
|
|
179
|
+
/* Dark follows the `.dark` class, as the role tokens do: a surface from one
|
|
180
|
+
and text from the other would not be readable. */
|
|
181
|
+
:where(.dark) :where([data-stx-json-tree]) {
|
|
182
|
+
--stx-tree-bg: var(--stx-panel, #262626);
|
|
183
|
+
--stx-tree-fg: var(--stx-fg, #f5f5f5);
|
|
184
|
+
--stx-tree-muted: var(--stx-fg-soft, #a3a3a3);
|
|
185
|
+
--stx-tree-hover: color-mix(in srgb, var(--stx-fg, #f5f5f5) 8%, transparent);
|
|
186
|
+
--stx-tree-line: var(--stx-line, #404040);
|
|
187
|
+
--stx-tree-key: var(--stx-syntax-attribute, #79c0ff);
|
|
188
|
+
--stx-tree-string: var(--stx-syntax-string, #a5d6ff);
|
|
189
|
+
--stx-tree-number: var(--stx-syntax-numeric, #79c0ff);
|
|
190
|
+
--stx-tree-keyword: var(--stx-syntax-keyword, #ff7b72);
|
|
191
|
+
--stx-tree-type: var(--stx-syntax-type, #ffa657);
|
|
192
|
+
--stx-tree-function: var(--stx-syntax-function, #d2a8ff);
|
|
193
|
+
--stx-tree-comment: var(--stx-syntax-comment, #8b949e);
|
|
194
|
+
--stx-tree-error: var(--stx-danger, #f87171);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
[data-stx-json-tree] .stx-jt-scroller {
|
|
198
|
+
position: relative;
|
|
199
|
+
flex: 1 1 auto;
|
|
200
|
+
min-height: 0;
|
|
201
|
+
overflow: auto;
|
|
202
|
+
outline: none;
|
|
203
|
+
font-family: var(--stx-tree-font);
|
|
204
|
+
font-size: var(--stx-tree-font-size);
|
|
205
|
+
line-height: var(--stx-tree-row-height);
|
|
206
|
+
font-variant-ligatures: none;
|
|
207
|
+
}
|
|
208
|
+
[data-stx-json-tree] .stx-jt-scroller:focus-visible {
|
|
209
|
+
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--stx-tree-focus) 55%, transparent);
|
|
210
|
+
}
|
|
211
|
+
[data-stx-json-tree] .stx-jt-content { position: relative; min-width: 100%; }
|
|
212
|
+
[data-stx-json-tree] .stx-jt-rows { position: absolute; top: 0; left: 0; right: 0; }
|
|
213
|
+
|
|
214
|
+
/* Every row is the same height and is placed by a transform, so which rows
|
|
215
|
+
are on screen is arithmetic and moving one costs no layout. */
|
|
216
|
+
[data-stx-json-tree] .stx-jt-row {
|
|
217
|
+
position: absolute;
|
|
218
|
+
top: 0;
|
|
219
|
+
left: 0;
|
|
220
|
+
right: 0;
|
|
221
|
+
box-sizing: border-box;
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
height: var(--stx-tree-row-height);
|
|
225
|
+
padding-left: calc(6px + var(--stx-tree-indent) * var(--stx-tree-depth, 0));
|
|
226
|
+
padding-right: 6px;
|
|
227
|
+
white-space: nowrap;
|
|
228
|
+
cursor: default;
|
|
229
|
+
contain: layout style;
|
|
230
|
+
}
|
|
231
|
+
[data-stx-json-tree] .stx-jt-row:hover { background: var(--stx-tree-hover); }
|
|
232
|
+
[data-stx-json-tree] .stx-jt-row[data-active] { background: var(--stx-tree-active); }
|
|
233
|
+
[data-stx-json-tree] .stx-jt-scroller:focus-visible .stx-jt-row[data-active] {
|
|
234
|
+
box-shadow: inset 2px 0 0 var(--stx-tree-focus);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
[data-stx-json-tree] .stx-jt-twisty {
|
|
238
|
+
flex: 0 0 var(--stx-tree-indent);
|
|
239
|
+
color: var(--stx-tree-muted);
|
|
240
|
+
text-align: center;
|
|
241
|
+
user-select: none;
|
|
242
|
+
-webkit-user-select: none;
|
|
243
|
+
}
|
|
244
|
+
[data-stx-json-tree] .stx-jt-label { flex: 0 0 auto; color: var(--stx-tree-key); }
|
|
245
|
+
[data-stx-json-tree] .stx-jt-separator { flex: 0 0 auto; color: var(--stx-tree-muted); white-space: pre; }
|
|
246
|
+
[data-stx-json-tree] .stx-jt-preview {
|
|
247
|
+
flex: 1 1 auto;
|
|
248
|
+
min-width: 0;
|
|
249
|
+
overflow: hidden;
|
|
250
|
+
text-overflow: ellipsis;
|
|
251
|
+
color: var(--stx-tree-muted);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="string"],
|
|
255
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="regexp"],
|
|
256
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="url"],
|
|
257
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="date"] { color: var(--stx-tree-string); }
|
|
258
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="number"],
|
|
259
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="bigint"],
|
|
260
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="bytes"] { color: var(--stx-tree-number); }
|
|
261
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="boolean"],
|
|
262
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="null"],
|
|
263
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="undefined"] { color: var(--stx-tree-keyword); }
|
|
264
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="function"],
|
|
265
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="symbol"],
|
|
266
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="promise"] { color: var(--stx-tree-function); }
|
|
267
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="model"],
|
|
268
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="html"],
|
|
269
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="relation"] { color: var(--stx-tree-type); }
|
|
270
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="error"] { color: var(--stx-tree-error); }
|
|
271
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="ref"],
|
|
272
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="cut"],
|
|
273
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="more"],
|
|
274
|
+
[data-stx-json-tree] .stx-jt-preview[data-kind="hidden"] { color: var(--stx-tree-comment); font-style: italic; }
|
|
275
|
+
[data-stx-json-tree] .stx-jt-row[data-kind="ref"],
|
|
276
|
+
[data-stx-json-tree] .stx-jt-row[data-kind="more"] { cursor: pointer; }
|
|
277
|
+
|
|
278
|
+
/* The row's buttons: there for a pointer over the row, and for the row the
|
|
279
|
+
cursor is on. The keyboard reaches the same things through the tree's keys. */
|
|
280
|
+
[data-stx-json-tree] .stx-jt-actions {
|
|
281
|
+
flex: 0 0 auto;
|
|
282
|
+
display: none;
|
|
283
|
+
gap: 4px;
|
|
284
|
+
margin-left: 8px;
|
|
285
|
+
}
|
|
286
|
+
[data-stx-json-tree] .stx-jt-row:hover .stx-jt-actions,
|
|
287
|
+
[data-stx-json-tree] .stx-jt-row[data-active] .stx-jt-actions { display: inline-flex; }
|
|
288
|
+
[data-stx-json-tree] .stx-jt-action {
|
|
289
|
+
appearance: none;
|
|
290
|
+
box-sizing: border-box;
|
|
291
|
+
height: calc(var(--stx-tree-row-height) - 4px);
|
|
292
|
+
margin: 0;
|
|
293
|
+
padding: 0 6px;
|
|
294
|
+
border: 1px solid var(--stx-tree-line);
|
|
295
|
+
border-radius: 4px;
|
|
296
|
+
background: var(--stx-tree-bg);
|
|
297
|
+
color: var(--stx-tree-muted);
|
|
298
|
+
font: inherit;
|
|
299
|
+
font-size: 11px;
|
|
300
|
+
line-height: 1;
|
|
301
|
+
cursor: pointer;
|
|
302
|
+
}
|
|
303
|
+
[data-stx-json-tree] .stx-jt-action:hover { color: var(--stx-tree-fg); border-color: var(--stx-tree-focus); }
|
|
304
|
+
[data-stx-json-tree] .stx-jt-action[data-jt-action="open"] { color: var(--stx-tree-focus); }
|
|
305
|
+
|
|
306
|
+
[data-stx-json-tree] .stx-jt-status {
|
|
307
|
+
position: absolute;
|
|
308
|
+
width: 1px;
|
|
309
|
+
height: 1px;
|
|
310
|
+
margin: -1px;
|
|
311
|
+
padding: 0;
|
|
312
|
+
overflow: hidden;
|
|
313
|
+
clip: rect(0, 0, 0, 0);
|
|
314
|
+
white-space: nowrap;
|
|
315
|
+
border: 0;
|
|
316
|
+
}
|
|
317
|
+
</style>
|