vzcode 3.2.0 → 3.3.0
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/README.md +185 -40
- package/dist/assets/App-C9mRI7eH.js +387 -0
- package/dist/assets/App-CxiKy3Rs.css +1 -0
- package/dist/assets/bindings_wasm_bg-IWNG_AjZ.wasm +0 -0
- package/dist/assets/buildWorker-N5tFTOqM.js +794 -0
- package/dist/assets/index-COLyIkCc.js +43 -0
- package/dist/assets/index-CZT-v4sH.css +1 -0
- package/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
- package/dist/assets/worker-BpV7Ustv.js +223 -0
- package/dist/assets/worker-CLeezw6h.js +458 -0
- package/dist/assets/worker-DaSIYBQX.js +327 -0
- package/dist/cli.js +170 -99
- package/dist/index.html +3 -2
- package/dist/server/accessControl.js +104 -0
- package/dist/server/computeInitialDocument.js +4 -1
- package/dist/server/createServer.js +356 -104
- package/dist/server/index.js +4 -3
- package/dist/server/workspaceSecurity.js +115 -0
- package/dist/server/workspaceSync.js +141 -0
- package/package.json +74 -72
- package/src/cli.ts +203 -182
- package/src/client/App/index.tsx +2 -0
- package/src/client/App/usePending.ts +3 -1
- package/src/client/RunCodeWidget/index.tsx +1 -0
- package/src/client/VZCodeContext/types.ts +6 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +2 -0
- package/src/client/VZSidebar/AIChatWrapper.tsx +2 -0
- package/src/client/VZSidebar/VisualEditor/CheckboxWidget.tsx +22 -30
- package/src/client/VZSidebar/VisualEditor/ColorWidget.tsx +198 -126
- package/src/client/VZSidebar/VisualEditor/DropdownWidget.tsx +25 -67
- package/src/client/VZSidebar/VisualEditor/PropertySection.tsx +41 -0
- package/src/client/VZSidebar/VisualEditor/SegmentedWidget.tsx +34 -0
- package/src/client/VZSidebar/VisualEditor/SliderWidget.tsx +60 -12
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +31 -393
- package/src/client/VZSidebar/VisualEditor/VisualEditorControls.tsx +478 -0
- package/src/client/VZSidebar/VisualEditor/colorUtils.ts +12 -0
- package/src/client/VZSidebar/VisualEditor/status.ts +47 -0
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +51 -24
- package/src/client/VZSidebar/VisualEditor/utils.ts +1 -1
- package/src/client/VZSidebar/styles.scss +420 -0
- package/src/client/WorkspaceConflictBanner.tsx +120 -0
- package/src/client/index.ts +2 -0
- package/src/client/main.jsx +54 -12
- package/src/llm-streaming-server/README.md +4 -16
- package/src/llm-streaming-ui/README.md +41 -2
- package/src/llm-streaming-ui/components/ChatInput.tsx +65 -13
- package/src/llm-streaming-ui/components/index.tsx +2 -0
- package/src/llm-streaming-ui/hooks/useAutoScroll.ts +1 -1
- package/src/llm-streaming-ui/index.ts +1 -0
- package/src/llm-streaming-ui/props.ts +26 -2
- package/src/server/accessControl.ts +151 -0
- package/src/server/computeInitialDocument.ts +6 -2
- package/src/server/createServer.ts +487 -138
- package/src/server/index.ts +4 -5
- package/src/server/workspaceSecurity.ts +160 -0
- package/src/server/workspaceSync.ts +203 -0
- package/src/types.ts +29 -27
- package/dist/assets/bindings_wasm_bg-9w8E-TmY.wasm +0 -0
- package/dist/assets/buildWorker-BZlya278.js +0 -687
- package/dist/assets/index-B7NRhsN6.js +0 -356
- package/dist/assets/index-D1V1AKed.css +0 -1
- package/dist/assets/worker-1oQYaz-F.js +0 -342
- package/dist/assets/worker-BfgPD8zR.js +0 -125
- package/dist/assets/worker-CoJaqtpi.js +0 -436
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import React, { useRef,
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { renderSliderBackground } from './utils';
|
|
3
|
+
import { normalizeOpaqueColorToHex } from './colorUtils';
|
|
4
|
+
|
|
5
|
+
const PRESETS = [
|
|
6
|
+
'#6366f1',
|
|
7
|
+
'#0891b2',
|
|
8
|
+
'#16a34a',
|
|
9
|
+
'#e11d48',
|
|
10
|
+
'#f59e0b',
|
|
11
|
+
'#111827',
|
|
12
|
+
'#ffffff',
|
|
13
|
+
'#000000',
|
|
14
|
+
];
|
|
3
15
|
|
|
4
16
|
interface ColorWidgetProps {
|
|
5
17
|
property: string;
|
|
@@ -12,6 +24,7 @@ interface ColorWidgetProps {
|
|
|
12
24
|
property: string,
|
|
13
25
|
lchComponent: 'l' | 'c' | 'h',
|
|
14
26
|
) => (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
27
|
+
onHexChange: (property: string, hex: string) => void;
|
|
15
28
|
}
|
|
16
29
|
|
|
17
30
|
export const ColorWidget: React.FC<ColorWidgetProps> = ({
|
|
@@ -22,152 +35,211 @@ export const ColorWidget: React.FC<ColorWidgetProps> = ({
|
|
|
22
35
|
currentC,
|
|
23
36
|
currentL,
|
|
24
37
|
onColorChange,
|
|
38
|
+
onHexChange,
|
|
25
39
|
}) => {
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
const [open, setOpen] = useState(false);
|
|
41
|
+
const [advanced, setAdvanced] = useState(false);
|
|
42
|
+
const [draft, setDraft] = useState(currentHex);
|
|
43
|
+
const root = useRef<HTMLDivElement>(null);
|
|
44
|
+
const canvasRefs = useRef<
|
|
45
|
+
Record<string, HTMLCanvasElement | null>
|
|
46
|
+
>({});
|
|
47
|
+
|
|
48
|
+
const normalizedHex =
|
|
49
|
+
normalizeOpaqueColorToHex(currentHex) ?? '#000000';
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
setDraft(currentHex);
|
|
53
|
+
}, [currentHex]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!open) return;
|
|
56
|
+
const onPointerDown = (event: PointerEvent) => {
|
|
57
|
+
if (!root.current?.contains(event.target as Node))
|
|
58
|
+
setOpen(false);
|
|
59
|
+
};
|
|
60
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
61
|
+
if (event.key === 'Escape') setOpen(false);
|
|
62
|
+
};
|
|
63
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
64
|
+
document.addEventListener('keydown', onKeyDown);
|
|
65
|
+
return () => {
|
|
66
|
+
document.removeEventListener(
|
|
67
|
+
'pointerdown',
|
|
68
|
+
onPointerDown,
|
|
69
|
+
);
|
|
70
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
71
|
+
};
|
|
72
|
+
}, [open]);
|
|
30
73
|
|
|
31
|
-
// Update color slider backgrounds when values change
|
|
32
74
|
useEffect(() => {
|
|
33
|
-
|
|
75
|
+
if (!open || !advanced) return;
|
|
76
|
+
const channels = {
|
|
34
77
|
h: currentH,
|
|
35
78
|
c: currentC,
|
|
36
79
|
l: currentL,
|
|
37
80
|
};
|
|
81
|
+
for (const component of ['h', 'c', 'l'] as const) {
|
|
82
|
+
renderSliderBackground(
|
|
83
|
+
canvasRefs.current[component],
|
|
84
|
+
component,
|
|
85
|
+
channels,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}, [open, advanced, currentH, currentC, currentL]);
|
|
38
89
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
);
|
|
45
|
-
renderSliderBackground(
|
|
46
|
-
canvasRefs.current[`${property}_c_bg`],
|
|
47
|
-
'c',
|
|
48
|
-
values,
|
|
49
|
-
);
|
|
50
|
-
renderSliderBackground(
|
|
51
|
-
canvasRefs.current[`${property}_h_bg`],
|
|
52
|
-
'h',
|
|
53
|
-
values,
|
|
54
|
-
);
|
|
55
|
-
}, [property, currentH, currentC, currentL]);
|
|
90
|
+
const commitDraft = () => {
|
|
91
|
+
const next = normalizeOpaqueColorToHex(draft);
|
|
92
|
+
if (next) onHexChange(property, next);
|
|
93
|
+
else setDraft(currentHex);
|
|
94
|
+
};
|
|
56
95
|
|
|
57
96
|
return (
|
|
58
|
-
<div className="visual-editor-color">
|
|
97
|
+
<div className="visual-editor-color" ref={root}>
|
|
59
98
|
<div className="color-header">
|
|
60
99
|
<label className="color-label">{label}</label>
|
|
61
|
-
<
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
className="color-picker-trigger"
|
|
103
|
+
aria-label={`Choose ${label} color`}
|
|
104
|
+
aria-expanded={open}
|
|
105
|
+
onClick={() => setOpen((value) => !value)}
|
|
106
|
+
>
|
|
107
|
+
<span
|
|
108
|
+
className="color-picker-swatch"
|
|
109
|
+
style={{ backgroundColor: normalizedHex }}
|
|
110
|
+
/>
|
|
111
|
+
<span className="color-picker-hex">
|
|
112
|
+
{normalizedHex.toUpperCase()}
|
|
113
|
+
</span>
|
|
114
|
+
<span aria-hidden="true">▾</span>
|
|
115
|
+
</button>
|
|
62
116
|
</div>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<div className="lch-slider">
|
|
72
|
-
<div className="slider-header">
|
|
73
|
-
<label className="slider-label">
|
|
74
|
-
Lightness
|
|
75
|
-
</label>
|
|
76
|
-
<span className="slider-value">
|
|
77
|
-
{Math.round(currentL)}
|
|
78
|
-
</span>
|
|
79
|
-
</div>
|
|
80
|
-
<div className="slider-container">
|
|
81
|
-
<canvas
|
|
82
|
-
ref={(canvas) => {
|
|
83
|
-
canvasRefs.current[`${property}_l_bg`] =
|
|
84
|
-
canvas;
|
|
85
|
-
}}
|
|
86
|
-
className="slider-bg-canvas"
|
|
87
|
-
width={200}
|
|
88
|
-
/>
|
|
117
|
+
{open && (
|
|
118
|
+
<div
|
|
119
|
+
className="color-picker-popover"
|
|
120
|
+
role="group"
|
|
121
|
+
aria-label={`${label} color picker`}
|
|
122
|
+
>
|
|
123
|
+
<label className="color-picker-field">
|
|
124
|
+
<span>Pick a color</span>
|
|
89
125
|
<input
|
|
90
|
-
type="
|
|
91
|
-
className="
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<div className="slider-bounds">
|
|
100
|
-
<span className="min-value">0</span>
|
|
101
|
-
<span className="max-value">100</span>
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
|
|
105
|
-
{/* Chroma Slider */}
|
|
106
|
-
<div className="lch-slider">
|
|
107
|
-
<div className="slider-header">
|
|
108
|
-
<label className="slider-label">Chroma</label>
|
|
109
|
-
<span className="slider-value">
|
|
110
|
-
{Math.round(currentC)}
|
|
111
|
-
</span>
|
|
112
|
-
</div>
|
|
113
|
-
<div className="slider-container">
|
|
114
|
-
<canvas
|
|
115
|
-
ref={(canvas) => {
|
|
116
|
-
canvasRefs.current[`${property}_c_bg`] =
|
|
117
|
-
canvas;
|
|
118
|
-
}}
|
|
119
|
-
className="slider-bg-canvas"
|
|
120
|
-
width={200}
|
|
126
|
+
type="color"
|
|
127
|
+
className="color-picker-native"
|
|
128
|
+
value={normalizedHex}
|
|
129
|
+
onChange={(event) =>
|
|
130
|
+
onHexChange(
|
|
131
|
+
property,
|
|
132
|
+
event.currentTarget.value,
|
|
133
|
+
)
|
|
134
|
+
}
|
|
121
135
|
/>
|
|
136
|
+
</label>
|
|
137
|
+
<label className="color-picker-field">
|
|
138
|
+
<span>HEX / CSS color</span>
|
|
122
139
|
<input
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{/* Hue Slider */}
|
|
139
|
-
<div className="lch-slider">
|
|
140
|
-
<div className="slider-header">
|
|
141
|
-
<label className="slider-label">Hue</label>
|
|
142
|
-
<span className="slider-value">
|
|
143
|
-
{Math.round(currentH)}°
|
|
144
|
-
</span>
|
|
145
|
-
</div>
|
|
146
|
-
<div className="slider-container">
|
|
147
|
-
<canvas
|
|
148
|
-
ref={(canvas) => {
|
|
149
|
-
canvasRefs.current[`${property}_h_bg`] =
|
|
150
|
-
canvas;
|
|
140
|
+
className="color-picker-hex-input"
|
|
141
|
+
type="text"
|
|
142
|
+
spellCheck={false}
|
|
143
|
+
value={draft}
|
|
144
|
+
onChange={(event) =>
|
|
145
|
+
setDraft(event.currentTarget.value)
|
|
146
|
+
}
|
|
147
|
+
onBlur={commitDraft}
|
|
148
|
+
onKeyDown={(event) => {
|
|
149
|
+
if (event.key === 'Enter') {
|
|
150
|
+
commitDraft();
|
|
151
|
+
event.currentTarget.blur();
|
|
152
|
+
} else if (event.key === 'Escape') {
|
|
153
|
+
setDraft(currentHex);
|
|
154
|
+
}
|
|
151
155
|
}}
|
|
152
|
-
|
|
153
|
-
width={200}
|
|
154
|
-
/>
|
|
155
|
-
<input
|
|
156
|
-
type="range"
|
|
157
|
-
className="slider-input"
|
|
158
|
-
min={0}
|
|
159
|
-
max={360}
|
|
160
|
-
step={1}
|
|
161
|
-
value={currentH}
|
|
162
|
-
onChange={onColorChange(property, 'h')}
|
|
156
|
+
aria-label={`${label} hexadecimal color`}
|
|
163
157
|
/>
|
|
158
|
+
</label>
|
|
159
|
+
<div className="color-picker-preset-label">
|
|
160
|
+
Presets
|
|
164
161
|
</div>
|
|
165
|
-
<div className="
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
<div className="color-picker-presets">
|
|
163
|
+
{PRESETS.map((preset) => (
|
|
164
|
+
<button
|
|
165
|
+
key={preset}
|
|
166
|
+
type="button"
|
|
167
|
+
className="color-picker-preset"
|
|
168
|
+
style={{ backgroundColor: preset }}
|
|
169
|
+
aria-label={`Use color ${preset}`}
|
|
170
|
+
aria-pressed={preset === normalizedHex}
|
|
171
|
+
onClick={() =>
|
|
172
|
+
onHexChange(property, preset)
|
|
173
|
+
}
|
|
174
|
+
/>
|
|
175
|
+
))}
|
|
168
176
|
</div>
|
|
177
|
+
<button
|
|
178
|
+
type="button"
|
|
179
|
+
className="color-picker-advanced-toggle"
|
|
180
|
+
aria-expanded={advanced}
|
|
181
|
+
onClick={() => setAdvanced((value) => !value)}
|
|
182
|
+
>
|
|
183
|
+
Advanced HCL controls {advanced ? '▴' : '▾'}
|
|
184
|
+
</button>
|
|
185
|
+
{advanced && (
|
|
186
|
+
<div className="lch-sliders">
|
|
187
|
+
{(
|
|
188
|
+
[
|
|
189
|
+
['l', 'Lightness', currentL, 100, ''],
|
|
190
|
+
['c', 'Chroma', currentC, 100, ''],
|
|
191
|
+
['h', 'Hue', currentH, 360, '°'],
|
|
192
|
+
] as const
|
|
193
|
+
).map(
|
|
194
|
+
([component, name, value, max, suffix]) => (
|
|
195
|
+
<div
|
|
196
|
+
key={component}
|
|
197
|
+
className="lch-slider"
|
|
198
|
+
>
|
|
199
|
+
<div className="slider-header">
|
|
200
|
+
<label
|
|
201
|
+
className="slider-label"
|
|
202
|
+
htmlFor={`${property}-${component}`}
|
|
203
|
+
>
|
|
204
|
+
{name}
|
|
205
|
+
</label>
|
|
206
|
+
<span className="slider-value">
|
|
207
|
+
{Math.round(value)}
|
|
208
|
+
{suffix}
|
|
209
|
+
</span>
|
|
210
|
+
</div>
|
|
211
|
+
<div className="slider-container">
|
|
212
|
+
<canvas
|
|
213
|
+
ref={(canvas) => {
|
|
214
|
+
canvasRefs.current[component] =
|
|
215
|
+
canvas;
|
|
216
|
+
}}
|
|
217
|
+
className="slider-bg-canvas"
|
|
218
|
+
width={200}
|
|
219
|
+
height={12}
|
|
220
|
+
aria-hidden="true"
|
|
221
|
+
/>
|
|
222
|
+
<input
|
|
223
|
+
id={`${property}-${component}`}
|
|
224
|
+
type="range"
|
|
225
|
+
className="slider-input"
|
|
226
|
+
min={0}
|
|
227
|
+
max={max}
|
|
228
|
+
step={1}
|
|
229
|
+
value={value}
|
|
230
|
+
onChange={onColorChange(
|
|
231
|
+
property,
|
|
232
|
+
component,
|
|
233
|
+
)}
|
|
234
|
+
/>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
),
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
)}
|
|
169
241
|
</div>
|
|
170
|
-
|
|
242
|
+
)}
|
|
171
243
|
</div>
|
|
172
244
|
);
|
|
173
245
|
};
|
|
@@ -5,11 +5,10 @@ interface DropdownWidgetProps {
|
|
|
5
5
|
label: string;
|
|
6
6
|
options: string[];
|
|
7
7
|
currentValue: string;
|
|
8
|
-
|
|
9
|
-
onToggle: () => void;
|
|
10
|
-
onOptionClick: (value: string) => void;
|
|
8
|
+
onChange: (value: string) => void;
|
|
11
9
|
}
|
|
12
10
|
|
|
11
|
+
/** Native select preserves keyboard, touch, type-ahead and screen-reader behavior. */
|
|
13
12
|
export const DropdownWidget: React.FC<
|
|
14
13
|
DropdownWidgetProps
|
|
15
14
|
> = ({
|
|
@@ -17,68 +16,27 @@ export const DropdownWidget: React.FC<
|
|
|
17
16
|
label,
|
|
18
17
|
options,
|
|
19
18
|
currentValue,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<label
|
|
28
|
-
htmlFor={property}
|
|
29
|
-
className="dropdown-label"
|
|
30
|
-
>
|
|
31
|
-
{label}
|
|
32
|
-
</label>
|
|
33
|
-
</div>
|
|
34
|
-
<div className="dropdown-container">
|
|
35
|
-
<button
|
|
36
|
-
type="button"
|
|
37
|
-
className={`dropdown-button ${isOpen ? 'open' : ''}`}
|
|
38
|
-
onClick={onToggle}
|
|
39
|
-
aria-expanded={isOpen}
|
|
40
|
-
aria-haspopup="listbox"
|
|
41
|
-
>
|
|
42
|
-
<span className="dropdown-button-text">
|
|
43
|
-
{currentValue}
|
|
44
|
-
</span>
|
|
45
|
-
<div
|
|
46
|
-
className={`dropdown-arrow ${isOpen ? 'open' : ''}`}
|
|
47
|
-
>
|
|
48
|
-
<svg
|
|
49
|
-
width="12"
|
|
50
|
-
height="8"
|
|
51
|
-
viewBox="0 0 12 8"
|
|
52
|
-
fill="none"
|
|
53
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
54
|
-
>
|
|
55
|
-
<path
|
|
56
|
-
d="M1 1.5L6 6.5L11 1.5"
|
|
57
|
-
stroke="currentColor"
|
|
58
|
-
strokeWidth="2"
|
|
59
|
-
strokeLinecap="round"
|
|
60
|
-
strokeLinejoin="round"
|
|
61
|
-
/>
|
|
62
|
-
</svg>
|
|
63
|
-
</div>
|
|
64
|
-
</button>
|
|
65
|
-
{isOpen && (
|
|
66
|
-
<div className="dropdown-options">
|
|
67
|
-
{options.map((option) => (
|
|
68
|
-
<button
|
|
69
|
-
key={option}
|
|
70
|
-
type="button"
|
|
71
|
-
className={`dropdown-option ${
|
|
72
|
-
option === currentValue ? 'selected' : ''
|
|
73
|
-
}`}
|
|
74
|
-
onClick={() => onOptionClick(option)}
|
|
75
|
-
>
|
|
76
|
-
{option}
|
|
77
|
-
</button>
|
|
78
|
-
))}
|
|
79
|
-
</div>
|
|
80
|
-
)}
|
|
81
|
-
</div>
|
|
19
|
+
onChange,
|
|
20
|
+
}) => (
|
|
21
|
+
<div className="visual-editor-dropdown">
|
|
22
|
+
<div className="dropdown-header">
|
|
23
|
+
<label htmlFor={property} className="dropdown-label">
|
|
24
|
+
{label}
|
|
25
|
+
</label>
|
|
82
26
|
</div>
|
|
83
|
-
|
|
84
|
-
}
|
|
27
|
+
<select
|
|
28
|
+
id={property}
|
|
29
|
+
className="visual-properties-select"
|
|
30
|
+
value={currentValue}
|
|
31
|
+
onChange={(event) =>
|
|
32
|
+
onChange(event.currentTarget.value)
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
{options.map((option) => (
|
|
36
|
+
<option key={option} value={option}>
|
|
37
|
+
{option}
|
|
38
|
+
</option>
|
|
39
|
+
))}
|
|
40
|
+
</select>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useId, useState, type ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export const PropertySection = ({
|
|
4
|
+
title,
|
|
5
|
+
children,
|
|
6
|
+
initiallyOpen = true,
|
|
7
|
+
}: {
|
|
8
|
+
title: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
initiallyOpen?: boolean;
|
|
11
|
+
}) => {
|
|
12
|
+
const [isOpen, setIsOpen] = useState(initiallyOpen);
|
|
13
|
+
const id = useId();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<section className="visual-properties-section">
|
|
17
|
+
<button
|
|
18
|
+
type="button"
|
|
19
|
+
className="visual-properties-section-toggle"
|
|
20
|
+
aria-expanded={isOpen}
|
|
21
|
+
aria-controls={id}
|
|
22
|
+
onClick={() => setIsOpen((open) => !open)}
|
|
23
|
+
>
|
|
24
|
+
<span>{title}</span>
|
|
25
|
+
<span
|
|
26
|
+
aria-hidden="true"
|
|
27
|
+
className={`visual-properties-chevron ${isOpen ? '' : 'collapsed'}`}
|
|
28
|
+
>
|
|
29
|
+
▾
|
|
30
|
+
</span>
|
|
31
|
+
</button>
|
|
32
|
+
<div
|
|
33
|
+
id={id}
|
|
34
|
+
className="visual-properties-section-body"
|
|
35
|
+
hidden={!isOpen}
|
|
36
|
+
>
|
|
37
|
+
{isOpen && children}
|
|
38
|
+
</div>
|
|
39
|
+
</section>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
interface SegmentedWidgetProps {
|
|
4
|
+
label: string;
|
|
5
|
+
options: string[];
|
|
6
|
+
currentValue: string;
|
|
7
|
+
onChange: (value: string) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Small discrete sets are faster to scan as a compact row than a menu. */
|
|
11
|
+
export const SegmentedWidget: React.FC<
|
|
12
|
+
SegmentedWidgetProps
|
|
13
|
+
> = ({ label, options, currentValue, onChange }) => (
|
|
14
|
+
<div className="visual-editor-segmented">
|
|
15
|
+
<div className="segmented-label">{label}</div>
|
|
16
|
+
<div
|
|
17
|
+
className="segmented-options"
|
|
18
|
+
role="group"
|
|
19
|
+
aria-label={label}
|
|
20
|
+
>
|
|
21
|
+
{options.map((option) => (
|
|
22
|
+
<button
|
|
23
|
+
key={option}
|
|
24
|
+
type="button"
|
|
25
|
+
className="segmented-option"
|
|
26
|
+
aria-pressed={currentValue === option}
|
|
27
|
+
onClick={() => onChange(option)}
|
|
28
|
+
>
|
|
29
|
+
{option}
|
|
30
|
+
</button>
|
|
31
|
+
))}
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { calculatePercentage
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { calculatePercentage } from './utils';
|
|
3
3
|
|
|
4
4
|
interface SliderWidgetProps {
|
|
5
5
|
property: string;
|
|
6
6
|
label: string;
|
|
7
7
|
min: number;
|
|
8
8
|
max: number;
|
|
9
|
-
step
|
|
9
|
+
step?: number;
|
|
10
10
|
currentValue: number;
|
|
11
|
+
unit?: string;
|
|
11
12
|
onChange: (
|
|
12
13
|
event: React.ChangeEvent<HTMLInputElement>,
|
|
13
14
|
) => void;
|
|
15
|
+
onNumberChange: (value: number) => void;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export const SliderWidget: React.FC<SliderWidgetProps> = ({
|
|
@@ -18,15 +20,35 @@ export const SliderWidget: React.FC<SliderWidgetProps> = ({
|
|
|
18
20
|
label,
|
|
19
21
|
min,
|
|
20
22
|
max,
|
|
21
|
-
step,
|
|
23
|
+
step = 1,
|
|
22
24
|
currentValue,
|
|
25
|
+
unit,
|
|
23
26
|
onChange,
|
|
27
|
+
onNumberChange,
|
|
24
28
|
}) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const [draft, setDraft] = useState(String(currentValue));
|
|
30
|
+
useEffect(
|
|
31
|
+
() => setDraft(String(currentValue)),
|
|
32
|
+
[currentValue],
|
|
29
33
|
);
|
|
34
|
+
const percent = Math.max(
|
|
35
|
+
0,
|
|
36
|
+
Math.min(
|
|
37
|
+
100,
|
|
38
|
+
calculatePercentage(currentValue, min, max),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const commitNumber = () => {
|
|
43
|
+
const parsed = Number(draft);
|
|
44
|
+
if (draft.trim() === '' || !Number.isFinite(parsed)) {
|
|
45
|
+
setDraft(String(currentValue));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const clamped = Math.max(min, Math.min(max, parsed));
|
|
49
|
+
onNumberChange(clamped);
|
|
50
|
+
setDraft(String(clamped));
|
|
51
|
+
};
|
|
30
52
|
|
|
31
53
|
return (
|
|
32
54
|
<div className="visual-editor-slider">
|
|
@@ -34,14 +56,40 @@ export const SliderWidget: React.FC<SliderWidgetProps> = ({
|
|
|
34
56
|
<label htmlFor={property} className="slider-label">
|
|
35
57
|
{label}
|
|
36
58
|
</label>
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
<div className="slider-number-wrapper">
|
|
60
|
+
<input
|
|
61
|
+
type="number"
|
|
62
|
+
className="slider-number-input"
|
|
63
|
+
aria-label={`${label} value`}
|
|
64
|
+
min={min}
|
|
65
|
+
max={max}
|
|
66
|
+
step={step}
|
|
67
|
+
value={draft}
|
|
68
|
+
onChange={(event) =>
|
|
69
|
+
setDraft(event.currentTarget.value)
|
|
70
|
+
}
|
|
71
|
+
onBlur={commitNumber}
|
|
72
|
+
onKeyDown={(event) => {
|
|
73
|
+
if (event.key === 'Enter') {
|
|
74
|
+
commitNumber();
|
|
75
|
+
event.currentTarget.blur();
|
|
76
|
+
}
|
|
77
|
+
if (event.key === 'Escape')
|
|
78
|
+
setDraft(String(currentValue));
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
{unit && (
|
|
82
|
+
<span className="slider-number-unit">
|
|
83
|
+
{unit}
|
|
84
|
+
</span>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
40
87
|
</div>
|
|
41
88
|
<div className="slider-container">
|
|
42
89
|
<input
|
|
43
90
|
type="range"
|
|
44
91
|
id={property}
|
|
92
|
+
aria-label={label}
|
|
45
93
|
className="slider-input"
|
|
46
94
|
min={min}
|
|
47
95
|
max={max}
|
|
@@ -51,7 +99,7 @@ export const SliderWidget: React.FC<SliderWidgetProps> = ({
|
|
|
51
99
|
/>
|
|
52
100
|
<div
|
|
53
101
|
className="slider-track-fill"
|
|
54
|
-
style={{ width: `${
|
|
102
|
+
style={{ width: `${percent}%` }}
|
|
55
103
|
/>
|
|
56
104
|
</div>
|
|
57
105
|
<div className="slider-bounds">
|