@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,257 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
export const html = typeof $props.html === 'string' ? $props.html : ''
|
|
3
|
+
export const viewport = ['phone', 'tablet', 'desktop'].includes($props.viewport) ? $props.viewport : 'fill'
|
|
4
|
+
export const frameWidth = $num($props.frameWidth, 0)
|
|
5
|
+
export const frameHeight = $num($props.frameHeight, 0)
|
|
6
|
+
export const landscape = $bool($props.landscape)
|
|
7
|
+
export const scheme = ['light', 'dark'].includes($props.scheme) ? $props.scheme : 'auto'
|
|
8
|
+
/*
|
|
9
|
+
* Off unless asked for. A page's scripts never share the host's origin either
|
|
10
|
+
* way; this decides whether they run at all.
|
|
11
|
+
*/
|
|
12
|
+
export const scripts = $bool($props.scripts)
|
|
13
|
+
export const forms = $bool($props.forms)
|
|
14
|
+
export const toolbar = $bool($props.toolbar, true)
|
|
15
|
+
export const title = $props.title || 'Preview'
|
|
16
|
+
/* A CSS length for the whole component, toolbar included. */
|
|
17
|
+
export const height = $props.height || '24rem'
|
|
18
|
+
export const className = $props.className || ''
|
|
19
|
+
export const previewId = $props.id || `preview-frame-${$uid}`
|
|
20
|
+
export const viewports = [
|
|
21
|
+
{ name: 'fill', label: 'Fill' },
|
|
22
|
+
{ name: 'phone', label: 'Phone' },
|
|
23
|
+
{ name: 'tablet', label: 'Tablet' },
|
|
24
|
+
{ name: 'desktop', label: 'Desktop' },
|
|
25
|
+
]
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<script client>
|
|
29
|
+
/*
|
|
30
|
+
* <PreviewFrame>: an HTML string shown as a page, in a frame that cannot
|
|
31
|
+
* reach the page around it.
|
|
32
|
+
*
|
|
33
|
+
* What goes into the frame and what it is allowed is in ./core; the frame
|
|
34
|
+
* itself, its size and its toolbar are in ./view. This is the wiring.
|
|
35
|
+
*/
|
|
36
|
+
import { PreviewFrameView } from './view'
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits(['load', 'reload', 'viewport', 'scheme'])
|
|
39
|
+
|
|
40
|
+
function asBoolean(value) {
|
|
41
|
+
if (value == null) return false
|
|
42
|
+
if (typeof value === 'string') return !['false', '0', 'off', 'no'].includes(value.trim().toLowerCase())
|
|
43
|
+
return Boolean(value)
|
|
44
|
+
}
|
|
45
|
+
function asText(value) { return value == null ? '' : String(value) }
|
|
46
|
+
function asSize(value) {
|
|
47
|
+
const size = Number(value)
|
|
48
|
+
return Number.isFinite(size) && size > 0 ? size : null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const liveHtml = useReactiveProp('html', {{ html }}, { parse: asText })
|
|
52
|
+
const liveViewport = useReactiveProp('viewport', {{ viewport }}, { parse: asText })
|
|
53
|
+
const liveScheme = useReactiveProp('scheme', {{ scheme }}, { parse: asText })
|
|
54
|
+
const liveLandscape = useReactiveProp('landscape', {{ landscape }}, { parse: asBoolean })
|
|
55
|
+
const liveScripts = useReactiveProp('scripts', {{ scripts }}, { parse: asBoolean })
|
|
56
|
+
const liveFrameWidth = useReactiveProp('frameWidth', {{ frameWidth }}, { parse: asSize })
|
|
57
|
+
const liveFrameHeight = useReactiveProp('frameHeight', {{ frameHeight }}, { parse: asSize })
|
|
58
|
+
|
|
59
|
+
const rootRef = useRef('preview-frame')
|
|
60
|
+
let preview = null
|
|
61
|
+
|
|
62
|
+
onMount(() => {
|
|
63
|
+
const root = rootRef()
|
|
64
|
+
if (!root) return
|
|
65
|
+
|
|
66
|
+
preview = new PreviewFrameView(root, {
|
|
67
|
+
html: asText(liveHtml()),
|
|
68
|
+
viewport: asText(liveViewport()),
|
|
69
|
+
frameWidth: asSize(liveFrameWidth()),
|
|
70
|
+
frameHeight: asSize(liveFrameHeight()),
|
|
71
|
+
landscape: asBoolean(liveLandscape()),
|
|
72
|
+
scheme: asText(liveScheme()),
|
|
73
|
+
scripts: asBoolean(liveScripts()),
|
|
74
|
+
forms: {{ forms }},
|
|
75
|
+
title: {{ title }},
|
|
76
|
+
}, {
|
|
77
|
+
onLoad(detail) { emit('load', detail) },
|
|
78
|
+
onReload(detail) { emit('reload', detail) },
|
|
79
|
+
onViewport(detail) { emit('viewport', detail) },
|
|
80
|
+
onScheme(detail) { emit('scheme', detail) },
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
effect(() => preview.setHtml(asText(liveHtml())))
|
|
84
|
+
effect(() => preview.setScheme(asText(liveScheme())))
|
|
85
|
+
effect(() => preview.setPermissions({ scripts: asBoolean(liveScripts()) }))
|
|
86
|
+
// What the toolbar chose stays chosen until the parent says something new.
|
|
87
|
+
let viewportSeen = false
|
|
88
|
+
effect(() => {
|
|
89
|
+
const name = asText(liveViewport())
|
|
90
|
+
const options = { landscape: asBoolean(liveLandscape()), width: asSize(liveFrameWidth()), height: asSize(liveFrameHeight()) }
|
|
91
|
+
if (viewportSeen) preview.setViewport(name, options)
|
|
92
|
+
viewportSeen = true
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
onDestroy(() => {
|
|
97
|
+
if (preview) preview.destroy()
|
|
98
|
+
preview = null
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
defineExpose({
|
|
102
|
+
reload: () => { if (preview) preview.reload() },
|
|
103
|
+
setHtml: (next) => { if (preview) preview.setHtml(asText(next)) },
|
|
104
|
+
setViewport: (name, options) => { if (preview) preview.setViewport(asText(name), options || {}) },
|
|
105
|
+
setScheme: (next) => { if (preview) preview.setScheme(asText(next)) },
|
|
106
|
+
getState: () => (preview ? preview.getState() : null),
|
|
107
|
+
})
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<div
|
|
111
|
+
ref="preview-frame"
|
|
112
|
+
id="{{ previewId }}"
|
|
113
|
+
data-stx-preview-frame
|
|
114
|
+
data-viewport="{{ viewport }}"
|
|
115
|
+
class="stx-preview {{ className }}"
|
|
116
|
+
style="height: {{ height }}"
|
|
117
|
+
>
|
|
118
|
+
@if(toolbar)
|
|
119
|
+
<div data-pf="toolbar" role="toolbar" aria-label="{{ title }} controls" class="stx-preview-toolbar">
|
|
120
|
+
<div role="radiogroup" aria-label="Viewport" class="stx-preview-group">
|
|
121
|
+
@foreach(option in viewports)
|
|
122
|
+
<button
|
|
123
|
+
type="button"
|
|
124
|
+
role="radio"
|
|
125
|
+
data-pf-viewport="{{ option.name }}"
|
|
126
|
+
aria-checked="{{ option.name === viewport ? 'true' : 'false' }}"
|
|
127
|
+
tabindex="{{ option.name === viewport ? '0' : '-1' }}"
|
|
128
|
+
class="stx-preview-button"
|
|
129
|
+
>{{ option.label }}</button>
|
|
130
|
+
@endforeach
|
|
131
|
+
</div>
|
|
132
|
+
<button type="button" data-pf-action="rotate" aria-pressed="false" class="stx-preview-button">Rotate</button>
|
|
133
|
+
{{-- Not a live region: it changes on every drag of a pane, and reading
|
|
134
|
+
each size out would bury everything else. --}}
|
|
135
|
+
<span data-pf="size" class="stx-preview-size"></span>
|
|
136
|
+
<span class="stx-preview-spacer"></span>
|
|
137
|
+
<button type="button" data-pf-action="scheme" aria-pressed="false" aria-label="Dark colour scheme" class="stx-preview-button">
|
|
138
|
+
<span data-pf="scheme-text">Light</span>
|
|
139
|
+
</button>
|
|
140
|
+
<button type="button" data-pf-action="reload" class="stx-preview-button">Reload</button>
|
|
141
|
+
</div>
|
|
142
|
+
@endif
|
|
143
|
+
|
|
144
|
+
<div data-pf="stage" class="stx-preview-stage">
|
|
145
|
+
<div data-pf="device" class="stx-preview-device"></div>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<style>
|
|
150
|
+
/*
|
|
151
|
+
* The stage is the neutral ground a device sits on. The frame's own
|
|
152
|
+
* background is the page's business: the frame is drawn in the scheme the
|
|
153
|
+
* page was given, so an unstyled page is white or near-black as it would be
|
|
154
|
+
* in a browser.
|
|
155
|
+
*/
|
|
156
|
+
:where([data-stx-preview-frame]) {
|
|
157
|
+
--stx-preview-bg: var(--stx-panel, #ffffff);
|
|
158
|
+
--stx-preview-fg: var(--stx-fg, #171717);
|
|
159
|
+
--stx-preview-fg-soft: var(--stx-fg-soft, #737373);
|
|
160
|
+
--stx-preview-stage: var(--stx-surface-sunken, #e5e5e5);
|
|
161
|
+
--stx-preview-line: var(--stx-line, #e5e5e5);
|
|
162
|
+
--stx-preview-active: var(--stx-accent, #2563eb);
|
|
163
|
+
--stx-preview-font-size: 12px;
|
|
164
|
+
--stx-preview-radius: 8px;
|
|
165
|
+
display: flex;
|
|
166
|
+
flex-direction: column;
|
|
167
|
+
box-sizing: border-box;
|
|
168
|
+
overflow: hidden;
|
|
169
|
+
border: 1px solid var(--stx-preview-line);
|
|
170
|
+
border-radius: var(--stx-preview-radius);
|
|
171
|
+
background: var(--stx-preview-bg);
|
|
172
|
+
color: var(--stx-preview-fg);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/*
|
|
176
|
+
* The layout is written out here rather than left to utility classes: a
|
|
177
|
+
* device that is the wrong size is a wrong preview, so it must not depend on
|
|
178
|
+
* what the app's stylesheet happens to generate.
|
|
179
|
+
*/
|
|
180
|
+
[data-stx-preview-frame] :is(.stx-preview-toolbar) {
|
|
181
|
+
display: flex;
|
|
182
|
+
flex: none;
|
|
183
|
+
align-items: center;
|
|
184
|
+
gap: 8px;
|
|
185
|
+
padding: 4px 8px;
|
|
186
|
+
border-bottom: 1px solid var(--stx-preview-line);
|
|
187
|
+
font-size: var(--stx-preview-font-size);
|
|
188
|
+
line-height: 1.5;
|
|
189
|
+
/* One line always: a toolbar that wraps changes the size of the stage under it. */
|
|
190
|
+
white-space: nowrap;
|
|
191
|
+
overflow: hidden;
|
|
192
|
+
}
|
|
193
|
+
[data-stx-preview-frame] :is(.stx-preview-spacer) { flex: 1 1 0; }
|
|
194
|
+
[data-stx-preview-frame] :is(.stx-preview-group) {
|
|
195
|
+
display: flex;
|
|
196
|
+
flex: none;
|
|
197
|
+
border: 1px solid var(--stx-preview-line);
|
|
198
|
+
border-radius: 6px;
|
|
199
|
+
overflow: hidden;
|
|
200
|
+
}
|
|
201
|
+
[data-stx-preview-frame] :is(.stx-preview-button) {
|
|
202
|
+
padding: 2px 8px;
|
|
203
|
+
flex: none;
|
|
204
|
+
border: 0;
|
|
205
|
+
border-radius: 5px;
|
|
206
|
+
background: transparent;
|
|
207
|
+
color: inherit;
|
|
208
|
+
font: inherit;
|
|
209
|
+
cursor: pointer;
|
|
210
|
+
}
|
|
211
|
+
[data-stx-preview-frame] :is(.stx-preview-group) > :is(.stx-preview-button) { border-radius: 0; }
|
|
212
|
+
[data-stx-preview-frame] :is(.stx-preview-button):hover { background: color-mix(in srgb, var(--stx-preview-fg) 8%, transparent); }
|
|
213
|
+
[data-stx-preview-frame] :is(.stx-preview-button):is([aria-checked="true"], [aria-pressed="true"]) {
|
|
214
|
+
background: color-mix(in srgb, var(--stx-preview-active) 16%, transparent);
|
|
215
|
+
color: var(--stx-preview-active);
|
|
216
|
+
}
|
|
217
|
+
[data-stx-preview-frame] :is(.stx-preview-button):focus-visible {
|
|
218
|
+
outline: 2px solid var(--stx-preview-active);
|
|
219
|
+
outline-offset: -2px;
|
|
220
|
+
}
|
|
221
|
+
[data-stx-preview-frame] :is(.stx-preview-button):disabled { opacity: 0.45; cursor: default; background: transparent; }
|
|
222
|
+
[data-stx-preview-frame] :is(.stx-preview-size) { overflow: hidden; text-overflow: ellipsis; color: var(--stx-preview-fg-soft); font-variant-numeric: tabular-nums; }
|
|
223
|
+
|
|
224
|
+
[data-stx-preview-frame] :is(.stx-preview-stage) {
|
|
225
|
+
position: relative;
|
|
226
|
+
flex: 1 1 0;
|
|
227
|
+
min-height: 0;
|
|
228
|
+
overflow: hidden;
|
|
229
|
+
display: flex;
|
|
230
|
+
align-items: center;
|
|
231
|
+
justify-content: center;
|
|
232
|
+
background: var(--stx-preview-stage);
|
|
233
|
+
}
|
|
234
|
+
[data-stx-preview-frame] :is(.stx-preview-device) {
|
|
235
|
+
position: relative;
|
|
236
|
+
flex: none;
|
|
237
|
+
overflow: hidden;
|
|
238
|
+
border-radius: 6px;
|
|
239
|
+
box-shadow: 0 0 0 1px var(--stx-preview-line), 0 8px 24px rgb(0 0 0 / 0.12);
|
|
240
|
+
}
|
|
241
|
+
[data-stx-preview-frame] :is(.stx-preview-frame) {
|
|
242
|
+
display: block;
|
|
243
|
+
border: 0;
|
|
244
|
+
transform-origin: 0 0;
|
|
245
|
+
/* Never see-through, so the stage does not show under a page with no background. */
|
|
246
|
+
background: Canvas;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* Filling: no device, the page has the whole stage. */
|
|
250
|
+
[data-stx-preview-frame][data-viewport="fill"] :is(.stx-preview-device) {
|
|
251
|
+
width: 100%;
|
|
252
|
+
height: 100%;
|
|
253
|
+
border-radius: 0;
|
|
254
|
+
box-shadow: none;
|
|
255
|
+
}
|
|
256
|
+
[data-stx-preview-frame][data-viewport="fill"] :is(.stx-preview-frame) { width: 100%; height: 100%; }
|
|
257
|
+
</style>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
export const direction = $props.direction === 'vertical' ? 'vertical' : 'horizontal'
|
|
3
|
+
/*
|
|
4
|
+
* Shares, one per pane: `[30, 70]`, `[1, 2, 1]`, or the text `30,70`. Left
|
|
5
|
+
* out, each pane's own `data-size` is used, and equal shares after that.
|
|
6
|
+
*/
|
|
7
|
+
export const sizes = Array.isArray($props.sizes)
|
|
8
|
+
? $props.sizes
|
|
9
|
+
: (typeof $props.sizes === 'string' && $props.sizes.trim() !== '' ? $props.sizes : null)
|
|
10
|
+
export const minSize = $num($props.minSize, 48)
|
|
11
|
+
export const step = $num($props.step, 16)
|
|
12
|
+
export const storageKey = $props.storageKey || ''
|
|
13
|
+
export const label = $props.label || 'Resize panes'
|
|
14
|
+
/* A CSS length. A split fills the box it is given, so the box needs a height. */
|
|
15
|
+
export const height = $props.height || '100%'
|
|
16
|
+
export const className = $props.className || ''
|
|
17
|
+
export const splitId = $props.id || `split-pane-${$uid}`
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script client>
|
|
21
|
+
/*
|
|
22
|
+
* <SplitPane>: panes side by side, or stacked, with a separator to drag
|
|
23
|
+
* between each pair. The children of the tag are the panes.
|
|
24
|
+
*
|
|
25
|
+
* The arithmetic is in ./core and the DOM in ./view; this is the wiring.
|
|
26
|
+
*/
|
|
27
|
+
import { parseSizes } from './core'
|
|
28
|
+
import { SplitPaneView } from './view'
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits(['resize', 'resize-end'])
|
|
31
|
+
|
|
32
|
+
const asDirection = value => (value === 'vertical' ? 'vertical' : 'horizontal')
|
|
33
|
+
const liveDirection = useReactiveProp('direction', {{ direction }}, { parse: asDirection })
|
|
34
|
+
const liveSizes = useReactiveProp('sizes', {{ sizes }}, { parse: parseSizes })
|
|
35
|
+
|
|
36
|
+
const rootRef = useRef('split-pane')
|
|
37
|
+
let split = null
|
|
38
|
+
|
|
39
|
+
onMount(() => {
|
|
40
|
+
const root = rootRef()
|
|
41
|
+
if (!root) return
|
|
42
|
+
|
|
43
|
+
split = new SplitPaneView(root, {
|
|
44
|
+
direction: asDirection(liveDirection()),
|
|
45
|
+
sizes: parseSizes(liveSizes()),
|
|
46
|
+
minSize: {{ minSize }},
|
|
47
|
+
step: {{ step }},
|
|
48
|
+
storageKey: {{ storageKey }},
|
|
49
|
+
label: {{ label }},
|
|
50
|
+
}, {
|
|
51
|
+
onResize(detail) { emit('resize', detail) },
|
|
52
|
+
onResizeEnd(detail) { emit('resize-end', detail) },
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// The first run of each finds the layout the view was just built with, and
|
|
56
|
+
// must leave a stored layout alone; only a later change is a new instruction.
|
|
57
|
+
let sizesSeen = false
|
|
58
|
+
effect(() => {
|
|
59
|
+
const next = parseSizes(liveSizes())
|
|
60
|
+
if (sizesSeen && next) split.setSizes(next)
|
|
61
|
+
sizesSeen = true
|
|
62
|
+
})
|
|
63
|
+
effect(() => split.setDirection(asDirection(liveDirection())))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
onDestroy(() => {
|
|
67
|
+
if (split) split.destroy()
|
|
68
|
+
split = null
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
defineExpose({
|
|
72
|
+
getSizes: () => (split ? split.getSizes() : []),
|
|
73
|
+
setSizes: (next) => { if (split) split.setSizes(parseSizes(next)) },
|
|
74
|
+
reset: () => { if (split) split.reset() },
|
|
75
|
+
})
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<div
|
|
79
|
+
ref="split-pane"
|
|
80
|
+
id="{{ splitId }}"
|
|
81
|
+
data-stx-split-pane
|
|
82
|
+
data-direction="{{ direction }}"
|
|
83
|
+
class="stx-split {{ className }}"
|
|
84
|
+
style="height: {{ height }}"
|
|
85
|
+
>
|
|
86
|
+
<slot />
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<style>
|
|
90
|
+
/*
|
|
91
|
+
* A separator is drawn as a hairline and grabbed by a wider strip around it,
|
|
92
|
+
* so it does not have to be thick to be easy to hit. Every colour falls back
|
|
93
|
+
* to a role token.
|
|
94
|
+
*/
|
|
95
|
+
:where([data-stx-split-pane]) {
|
|
96
|
+
--stx-split-line: var(--stx-line, #e5e5e5);
|
|
97
|
+
--stx-split-line-active: var(--stx-accent, #2563eb);
|
|
98
|
+
--stx-split-line-size: 1px;
|
|
99
|
+
--stx-split-grab: 9px;
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: row;
|
|
102
|
+
width: 100%;
|
|
103
|
+
min-width: 0;
|
|
104
|
+
min-height: 0;
|
|
105
|
+
}
|
|
106
|
+
:where([data-stx-split-pane][data-direction="vertical"]) { flex-direction: column; }
|
|
107
|
+
|
|
108
|
+
:where([data-stx-split-pane]) > :where([data-split-pane]) {
|
|
109
|
+
min-width: 0;
|
|
110
|
+
min-height: 0;
|
|
111
|
+
overflow: auto;
|
|
112
|
+
}
|
|
113
|
+
/* Before the view has run, the panes still share the space rather than stack. */
|
|
114
|
+
:where([data-stx-split-pane]:not([data-split-ready])) > * { flex: 1 1 0px; min-width: 0; min-height: 0; }
|
|
115
|
+
|
|
116
|
+
[data-stx-split-pane] > .stx-split-separator {
|
|
117
|
+
position: relative;
|
|
118
|
+
flex: 0 0 var(--stx-split-line-size);
|
|
119
|
+
background: var(--stx-split-line);
|
|
120
|
+
cursor: col-resize;
|
|
121
|
+
touch-action: none;
|
|
122
|
+
outline: none;
|
|
123
|
+
transition: background-color 120ms ease;
|
|
124
|
+
}
|
|
125
|
+
[data-stx-split-pane][data-direction="vertical"] > .stx-split-separator { cursor: row-resize; }
|
|
126
|
+
|
|
127
|
+
[data-stx-split-pane] > .stx-split-separator::after {
|
|
128
|
+
content: '';
|
|
129
|
+
position: absolute;
|
|
130
|
+
z-index: 1;
|
|
131
|
+
top: 0;
|
|
132
|
+
bottom: 0;
|
|
133
|
+
left: calc((var(--stx-split-grab) - var(--stx-split-line-size)) / -2);
|
|
134
|
+
width: var(--stx-split-grab);
|
|
135
|
+
}
|
|
136
|
+
[data-stx-split-pane][data-direction="vertical"] > .stx-split-separator::after {
|
|
137
|
+
left: 0;
|
|
138
|
+
right: 0;
|
|
139
|
+
top: calc((var(--stx-split-grab) - var(--stx-split-line-size)) / -2);
|
|
140
|
+
bottom: auto;
|
|
141
|
+
width: auto;
|
|
142
|
+
height: var(--stx-split-grab);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
[data-stx-split-pane] > .stx-split-separator:is(:hover, [data-active]) { background: var(--stx-split-line-active); }
|
|
146
|
+
[data-stx-split-pane] > .stx-split-separator:focus-visible {
|
|
147
|
+
background: var(--stx-split-line-active);
|
|
148
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--stx-split-line-active) 40%, transparent);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* A drag must not select the text it passes over, or lose the pointer to a frame. */
|
|
152
|
+
[data-stx-split-pane][data-dragging] { user-select: none; -webkit-user-select: none; cursor: col-resize; }
|
|
153
|
+
[data-stx-split-pane][data-dragging][data-direction="vertical"] { cursor: row-resize; }
|
|
154
|
+
[data-stx-split-pane][data-dragging] iframe { pointer-events: none; }
|
|
155
|
+
|
|
156
|
+
@media (prefers-reduced-motion: reduce) {
|
|
157
|
+
[data-stx-split-pane] > .stx-split-separator { transition: none; }
|
|
158
|
+
}
|
|
159
|
+
</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/utils/component-api.ts
|
|
2
|
+
var SCOPE = "[data-stx-scope]";
|
|
3
|
+
function find(target) {
|
|
4
|
+
if (!target)
|
|
5
|
+
return null;
|
|
6
|
+
if (typeof target !== "string")
|
|
7
|
+
return target;
|
|
8
|
+
if (typeof document === "undefined")
|
|
9
|
+
return null;
|
|
10
|
+
const byId = /^[\w-]+$/.test(target) ? document.getElementById(target) : null;
|
|
11
|
+
if (byId)
|
|
12
|
+
return byId;
|
|
13
|
+
try {
|
|
14
|
+
return document.querySelector(target);
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function componentApi(target) {
|
|
20
|
+
const element = find(target);
|
|
21
|
+
if (!element || typeof element.closest !== "function")
|
|
22
|
+
return null;
|
|
23
|
+
if (element.__stx_exposed)
|
|
24
|
+
return element.__stx_exposed;
|
|
25
|
+
const around = element.closest(SCOPE);
|
|
26
|
+
if (around?.__stx_exposed)
|
|
27
|
+
return around.__stx_exposed;
|
|
28
|
+
for (const inside of Array.from(element.querySelectorAll(SCOPE))) {
|
|
29
|
+
if (inside.__stx_exposed)
|
|
30
|
+
return inside.__stx_exposed;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
componentApi
|
|
36
|
+
};
|