vzcode 3.1.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.
Files changed (74) hide show
  1. package/README.md +185 -40
  2. package/dist/assets/App-C9mRI7eH.js +387 -0
  3. package/dist/assets/App-CxiKy3Rs.css +1 -0
  4. package/dist/assets/bindings_wasm_bg-IWNG_AjZ.wasm +0 -0
  5. package/dist/assets/buildWorker-N5tFTOqM.js +794 -0
  6. package/dist/assets/index-COLyIkCc.js +43 -0
  7. package/dist/assets/index-CZT-v4sH.css +1 -0
  8. package/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
  9. package/dist/assets/worker-BpV7Ustv.js +223 -0
  10. package/dist/assets/worker-CLeezw6h.js +458 -0
  11. package/dist/assets/worker-DaSIYBQX.js +327 -0
  12. package/dist/cli.js +170 -99
  13. package/dist/index.html +3 -2
  14. package/dist/server/accessControl.js +104 -0
  15. package/dist/server/computeInitialDocument.js +4 -1
  16. package/dist/server/createServer.js +356 -104
  17. package/dist/server/index.js +4 -3
  18. package/dist/server/workspaceSecurity.js +115 -0
  19. package/dist/server/workspaceSync.js +141 -0
  20. package/package.json +74 -72
  21. package/src/cli.ts +203 -182
  22. package/src/client/App/index.tsx +2 -0
  23. package/src/client/App/usePending.ts +3 -1
  24. package/src/client/CodeEditor/style.scss +18 -11
  25. package/src/client/RunCodeWidget/index.tsx +1 -0
  26. package/src/client/TabList/Tab.tsx +13 -5
  27. package/src/client/TabList/style.scss +32 -5
  28. package/src/client/VZCodeContext/types.ts +6 -0
  29. package/src/client/VZCodeContext/useVZCodeState.ts +2 -0
  30. package/src/client/VZResizer/styles.scss +1 -1
  31. package/src/client/VZSidebar/AIChatWrapper.tsx +2 -0
  32. package/src/client/VZSidebar/DeleteConfirmationModal.tsx +1 -1
  33. package/src/client/VZSidebar/Item.tsx +8 -4
  34. package/src/client/VZSidebar/VisualEditor/CheckboxWidget.tsx +22 -30
  35. package/src/client/VZSidebar/VisualEditor/ColorWidget.tsx +198 -126
  36. package/src/client/VZSidebar/VisualEditor/DropdownWidget.tsx +25 -67
  37. package/src/client/VZSidebar/VisualEditor/PropertySection.tsx +41 -0
  38. package/src/client/VZSidebar/VisualEditor/SegmentedWidget.tsx +34 -0
  39. package/src/client/VZSidebar/VisualEditor/SliderWidget.tsx +60 -12
  40. package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +31 -393
  41. package/src/client/VZSidebar/VisualEditor/VisualEditorControls.tsx +478 -0
  42. package/src/client/VZSidebar/VisualEditor/colorUtils.ts +12 -0
  43. package/src/client/VZSidebar/VisualEditor/status.ts +47 -0
  44. package/src/client/VZSidebar/VisualEditor/updateConfig.ts +51 -24
  45. package/src/client/VZSidebar/VisualEditor/utils.ts +1 -1
  46. package/src/client/VZSidebar/index.tsx +55 -23
  47. package/src/client/VZSidebar/styles.scss +426 -6
  48. package/src/client/WorkspaceConflictBanner.tsx +120 -0
  49. package/src/client/index.ts +2 -0
  50. package/src/client/main.jsx +54 -12
  51. package/src/client/ui.scss +156 -4
  52. package/src/client/ui.tsx +1 -1
  53. package/src/llm-streaming-server/README.md +4 -16
  54. package/src/llm-streaming-ui/README.md +41 -2
  55. package/src/llm-streaming-ui/components/ChatInput.tsx +65 -13
  56. package/src/llm-streaming-ui/components/index.tsx +2 -0
  57. package/src/llm-streaming-ui/components/styles.scss +46 -0
  58. package/src/llm-streaming-ui/hooks/useAutoScroll.ts +1 -1
  59. package/src/llm-streaming-ui/index.ts +1 -0
  60. package/src/llm-streaming-ui/props.ts +26 -2
  61. package/src/server/accessControl.ts +151 -0
  62. package/src/server/computeInitialDocument.ts +6 -2
  63. package/src/server/createServer.ts +487 -138
  64. package/src/server/index.ts +4 -5
  65. package/src/server/workspaceSecurity.ts +160 -0
  66. package/src/server/workspaceSync.ts +203 -0
  67. package/src/types.ts +29 -27
  68. package/dist/assets/bindings_wasm_bg-9w8E-TmY.wasm +0 -0
  69. package/dist/assets/buildWorker-BZlya278.js +0 -687
  70. package/dist/assets/index-5qf102c2.css +0 -1
  71. package/dist/assets/index-dSJDl5x9.js +0 -356
  72. package/dist/assets/worker-1oQYaz-F.js +0 -342
  73. package/dist/assets/worker-BfgPD8zR.js +0 -125
  74. package/dist/assets/worker-CoJaqtpi.js +0 -436
@@ -1,16 +1,18 @@
1
- import React from 'react';
2
- import { calculatePercentage, formatValue } from './utils';
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: number;
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 percentage = calculatePercentage(
26
- currentValue,
27
- min,
28
- max,
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
- <span className="slider-value">
38
- {formatValue(currentValue, min, max)}
39
- </span>
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: `${percentage}%` }}
102
+ style={{ width: `${percent}%` }}
55
103
  />
56
104
  </div>
57
105
  <div className="slider-bounds">
@@ -1,28 +1,12 @@
1
- import {
2
- useCallback,
3
- useContext,
4
- useState,
5
- useEffect,
6
- useMemo,
7
- } from 'react';
1
+ /** Live ShareDB adapter around the reusable visual properties controls. */
2
+ import React, { useCallback, useContext } from 'react';
8
3
  import { VZCodeContext } from '../../VZCodeContext';
9
- import { VizContent, VizFileId } from '@vizhub/viz-types';
10
- import { VisualEditorConfigEntry } from '../../../types';
11
- import { EmptyState } from '../EmptyState';
12
- import {
13
- toHclChannels,
14
- coerceChannelNumber,
15
- hclChannelsToHex,
16
- } from './colorUtils';
17
4
  import { CONFIG_FILE_NAME } from './constants';
18
- import { getVisualEditorEmptyReason } from './status';
19
- import { updateVisualEditorProperty } from './updateConfig';
20
- import { SliderWidget } from './SliderWidget';
21
- import { CheckboxWidget } from './CheckboxWidget';
22
- import { TextInputWidget } from './TextInputWidget';
23
- import { DropdownWidget } from './DropdownWidget';
24
- import { ColorWidget } from './ColorWidget';
25
- import { getNestedProperty } from './utils';
5
+ import {
6
+ updateVisualEditorProperties,
7
+ type WidgetValue,
8
+ } from './updateConfig';
9
+ import { VisualEditorControls } from './VisualEditorControls';
26
10
 
27
11
  export const VisualEditor = () => {
28
12
  const {
@@ -30,381 +14,35 @@ export const VisualEditor = () => {
30
14
  submitOperation,
31
15
  renderVisualEditorEmptyState,
32
16
  } = useContext(VZCodeContext);
33
-
34
- // Local state to track widget values during user interaction
35
- const [localValues, setLocalValues] = useState<{
36
- [key: string]: number | boolean | string;
37
- }>({});
38
-
39
- // State to track which dropdown is open
40
- const [openDropdown, setOpenDropdown] = useState<
41
- string | null
42
- >(null);
43
-
44
- let configFileId: VizFileId | null = null;
45
- if (files) {
46
- for (const fileId in files) {
47
- if (files[fileId].name === CONFIG_FILE_NAME) {
48
- configFileId = fileId;
49
- break;
50
- }
51
- }
52
- }
53
-
54
- const configData = useMemo(() => {
55
- if (!files || !configFileId) {
56
- return null;
57
- }
58
- try {
59
- return JSON.parse(files[configFileId].text);
60
- } catch (_error) {
61
- console.error('Error parsing config.json:', _error);
62
- return null;
63
- }
64
- }, [configFileId, files]);
65
-
66
- // All controls share one optimistic state + ShareDB write path.
67
- const setWidgetValue = useCallback(
68
- (
69
- property: string,
70
- value: number | boolean | string,
71
- extraLocalValues: Record<string, number> = {},
72
- ) => {
73
- setLocalValues((prev) => ({
74
- ...prev,
75
- [property]: value,
76
- ...extraLocalValues,
77
- }));
78
- submitOperation((document: VizContent) =>
79
- updateVisualEditorProperty(
17
+ const configId = files
18
+ ? (Object.keys(files).find(
19
+ (id) => files[id].name === CONFIG_FILE_NAME,
20
+ ) ?? null)
21
+ : null;
22
+ const configText =
23
+ configId && files
24
+ ? (files[configId]?.text ?? null)
25
+ : null;
26
+ const onChangeBatch = useCallback(
27
+ (changes: Record<string, WidgetValue>) => {
28
+ submitOperation((document) =>
29
+ updateVisualEditorProperties(
80
30
  document,
81
- configFileId,
82
- property,
83
- value,
84
- ),
85
- );
86
- },
87
- [configFileId, submitOperation],
88
- );
89
-
90
- const onSliderChange = useCallback(
91
- (property: string) =>
92
- (event: React.ChangeEvent<HTMLInputElement>) =>
93
- setWidgetValue(
94
- property,
95
- parseFloat(event.currentTarget.value),
96
- ),
97
- [setWidgetValue],
98
- );
99
-
100
- const onCheckboxChange = useCallback(
101
- (property: string) =>
102
- (event: React.ChangeEvent<HTMLInputElement>) =>
103
- setWidgetValue(
104
- property,
105
- event.currentTarget.checked,
31
+ configId,
32
+ changes,
106
33
  ),
107
- [setWidgetValue],
108
- );
109
-
110
- const onTextInputChange = useCallback(
111
- (property: string) =>
112
- (event: React.ChangeEvent<HTMLInputElement>) =>
113
- setWidgetValue(property, event.currentTarget.value),
114
- [setWidgetValue],
115
- );
116
-
117
- const onDropdownChange = useCallback(
118
- (property: string, value: string) =>
119
- setWidgetValue(property, value),
120
- [setWidgetValue],
121
- );
122
-
123
- // Custom dropdown handlers
124
- const handleDropdownToggle = useCallback(
125
- (property: string) => {
126
- setOpenDropdown((prev) =>
127
- prev === property ? null : property,
128
34
  );
129
35
  },
130
- [],
36
+ [configId, submitOperation],
131
37
  );
132
-
133
- const handleDropdownOptionClick = useCallback(
134
- (property: string, value: string) => {
135
- onDropdownChange(property, value);
136
- setOpenDropdown(null);
137
- },
138
- [onDropdownChange],
139
- );
140
-
141
- // Close dropdown when clicking outside
142
- useEffect(() => {
143
- const handleClickOutside = (event: MouseEvent) => {
144
- if (openDropdown) {
145
- const target = event.target as Element;
146
- if (!target.closest('.visual-editor-dropdown')) {
147
- setOpenDropdown(null);
148
- }
149
- }
150
- };
151
-
152
- document.addEventListener(
153
- 'mousedown',
154
- handleClickOutside,
155
- );
156
- return () => {
157
- document.removeEventListener(
158
- 'mousedown',
159
- handleClickOutside,
160
- );
161
- };
162
- }, [openDropdown]);
163
-
164
- const onColorChange = useCallback(
165
- (property: string, lchComponent: 'l' | 'c' | 'h') =>
166
- (event: React.ChangeEvent<HTMLInputElement>) => {
167
- const newValue = parseFloat(
168
- event.currentTarget.value,
169
- );
170
-
171
- // Get current hex color from config using nested property access
172
- const currentHex =
173
- getNestedProperty<string>(configData, property) ??
174
- '#000000';
175
-
176
- const base = toHclChannels(currentHex);
177
- const channels = {
178
- h:
179
- (localValues[`${property}_h`] as number) ??
180
- base.h,
181
- c:
182
- (localValues[`${property}_c`] as number) ??
183
- base.c,
184
- l:
185
- (localValues[`${property}_l`] as number) ??
186
- base.l,
187
- };
188
- channels[lchComponent] = newValue;
189
- const newHex = hclChannelsToHex(
190
- channels,
191
- currentHex,
192
- );
193
- setWidgetValue(property, newHex, {
194
- [`${property}_h`]: channels.h,
195
- [`${property}_c`]: channels.c,
196
- [`${property}_l`]: channels.l,
197
- });
198
- },
199
- [configData, setWidgetValue, localValues],
200
- );
201
-
202
- const visualEditorWidgets: VisualEditorConfigEntry[] =
203
- useMemo(
204
- () =>
205
- Array.isArray(configData?.visualEditorWidgets)
206
- ? configData.visualEditorWidgets
207
- : [],
208
- [configData],
209
- );
210
-
211
- // Sync local values with config data when it changes (including remote updates)
212
- useEffect(() => {
213
- const newLocalValues: {
214
- [key: string]: number | boolean | string;
215
- } = {};
216
- visualEditorWidgets.forEach((widget) => {
217
- const value = getNestedProperty<
218
- string | number | boolean
219
- >(configData, widget.property);
220
- if (value !== undefined)
221
- newLocalValues[widget.property] = value;
222
- if (
223
- widget.type === 'color' &&
224
- typeof value === 'string'
225
- ) {
226
- const channels = toHclChannels(value);
227
- newLocalValues[`${widget.property}_h`] = channels.h;
228
- newLocalValues[`${widget.property}_c`] = channels.c;
229
- newLocalValues[`${widget.property}_l`] = channels.l;
230
- }
231
- });
232
- setLocalValues(newLocalValues);
233
- }, [configData, visualEditorWidgets]);
234
-
235
- const emptyReason = getVisualEditorEmptyReason(
236
- configFileId === null
237
- ? null
238
- : (files?.[configFileId]?.text ?? null),
239
- );
240
- if (emptyReason) {
241
- const hostUI =
242
- renderVisualEditorEmptyState?.(emptyReason);
243
- if (hostUI != null) return <>{hostUI}</>;
244
- const messages = {
245
- 'missing-config':
246
- 'To begin using the visual editor, create a config.json.',
247
- 'invalid-config':
248
- 'Your config.json file is not valid JSON.',
249
- 'missing-widgets':
250
- 'Add a visualEditorWidgets array to config.json.',
251
- 'invalid-widgets':
252
- 'Your visualEditorWidgets configuration is invalid.',
253
- 'empty-widgets':
254
- 'Add at least one widget to visualEditorWidgets.',
255
- };
256
- return <EmptyState>{messages[emptyReason]}</EmptyState>;
257
- }
258
-
259
38
  return (
260
- <div className="visual-editor">
261
- {visualEditorWidgets.map((widgetConfig, _index) => {
262
- if (widgetConfig.type === 'slider') {
263
- // Use local value if available, otherwise fall back to config value
264
- const currentValue =
265
- (localValues[
266
- widgetConfig.property
267
- ] as number) ??
268
- getNestedProperty<number>(
269
- configData,
270
- widgetConfig.property,
271
- ) ??
272
- widgetConfig.min;
273
-
274
- return (
275
- <SliderWidget
276
- key={widgetConfig.property}
277
- property={widgetConfig.property}
278
- label={widgetConfig.label}
279
- min={widgetConfig.min}
280
- max={widgetConfig.max}
281
- step={widgetConfig.step}
282
- currentValue={currentValue}
283
- onChange={onSliderChange(
284
- widgetConfig.property,
285
- )}
286
- />
287
- );
288
- } else if (widgetConfig.type === 'checkbox') {
289
- // Use local value if available, otherwise fall back to config value
290
- const currentValue =
291
- (localValues[
292
- widgetConfig.property
293
- ] as boolean) ??
294
- getNestedProperty<boolean>(
295
- configData,
296
- widgetConfig.property,
297
- ) ??
298
- false;
299
-
300
- return (
301
- <CheckboxWidget
302
- key={widgetConfig.property}
303
- property={widgetConfig.property}
304
- label={widgetConfig.label}
305
- currentValue={currentValue}
306
- onChange={onCheckboxChange(
307
- widgetConfig.property,
308
- )}
309
- />
310
- );
311
- } else if (widgetConfig.type === 'textInput') {
312
- // Use local value if available, otherwise fall back to config value
313
- const currentValue =
314
- (localValues[
315
- widgetConfig.property
316
- ] as string) ??
317
- getNestedProperty<string>(
318
- configData,
319
- widgetConfig.property,
320
- ) ??
321
- '';
322
-
323
- return (
324
- <TextInputWidget
325
- key={widgetConfig.property}
326
- property={widgetConfig.property}
327
- label={widgetConfig.label}
328
- currentValue={currentValue}
329
- onChange={onTextInputChange(
330
- widgetConfig.property,
331
- )}
332
- />
333
- );
334
- } else if (widgetConfig.type === 'dropdown') {
335
- // Use local value if available, otherwise fall back to config value
336
- const currentValue =
337
- (localValues[
338
- widgetConfig.property
339
- ] as string) ??
340
- getNestedProperty<string>(
341
- configData,
342
- widgetConfig.property,
343
- ) ??
344
- widgetConfig.options?.[0] ??
345
- '';
346
- const isOpen =
347
- openDropdown === widgetConfig.property;
348
-
349
- return (
350
- <DropdownWidget
351
- key={widgetConfig.property}
352
- property={widgetConfig.property}
353
- label={widgetConfig.label}
354
- options={widgetConfig.options}
355
- currentValue={currentValue}
356
- isOpen={isOpen}
357
- onToggle={() =>
358
- handleDropdownToggle(widgetConfig.property)
359
- }
360
- onOptionClick={(value) =>
361
- handleDropdownOptionClick(
362
- widgetConfig.property,
363
- value,
364
- )
365
- }
366
- />
367
- );
368
- } else if (widgetConfig.type === 'color') {
369
- // Use local value if available, otherwise fall back to config value
370
- const currentHex =
371
- (localValues[
372
- widgetConfig.property
373
- ] as string) ??
374
- getNestedProperty<string>(
375
- configData,
376
- widgetConfig.property,
377
- ) ??
378
- '#000000';
379
-
380
- const channels = toHclChannels(currentHex);
381
- const currentH = coerceChannelNumber(
382
- localValues[`${widgetConfig.property}_h`],
383
- channels.h,
384
- );
385
- const currentC = coerceChannelNumber(
386
- localValues[`${widgetConfig.property}_c`],
387
- channels.c,
388
- );
389
- const currentL = coerceChannelNumber(
390
- localValues[`${widgetConfig.property}_l`],
391
- channels.l,
392
- );
393
-
394
- return (
395
- <ColorWidget
396
- key={widgetConfig.property}
397
- property={widgetConfig.property}
398
- label={widgetConfig.label}
399
- currentHex={currentHex}
400
- currentH={currentH}
401
- currentC={currentC}
402
- currentL={currentL}
403
- onColorChange={onColorChange}
404
- />
405
- );
406
- }
407
- })}
408
- </div>
39
+ <VisualEditorControls
40
+ configText={configText}
41
+ renderEmptyState={renderVisualEditorEmptyState}
42
+ onChange={(property, value) =>
43
+ onChangeBatch({ [property]: value })
44
+ }
45
+ onChangeBatch={onChangeBatch}
46
+ />
409
47
  );
410
48
  };