vzcode 2.34.0 → 2.36.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/dist/assets/buildWorker-BZlya278.js +687 -0
- package/dist/assets/index-Cj-ERpBu.css +1 -0
- package/dist/assets/index-DD7vzp4U.js +364 -0
- package/dist/assets/{worker-D8p1JlHW.js → worker-1oQYaz-F.js} +251 -251
- package/dist/assets/worker-BfgPD8zR.js +125 -0
- package/dist/assets/{worker-k7HZ3t-V.js → worker-CoJaqtpi.js} +12 -12
- package/dist/index.html +2 -2
- package/dist/ot.js +180 -2
- package/dist/server/createServer.js +281 -0
- package/dist/server/index.js +6 -269
- package/package.json +14 -3
- package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -14
- package/src/client/VZCodeContext/chatSessionHelpers.ts +17 -0
- package/src/client/VZCodeContext/useAIChatSession.ts +325 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +23 -279
- package/src/client/VZSidebar/AIChatWrapper.tsx +85 -0
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +95 -208
- package/src/client/VZSidebar/VisualEditor/colorUtils.ts +39 -0
- package/src/client/VZSidebar/VisualEditor/status.ts +2 -40
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +10 -1
- package/src/client/VZSidebar/VisualEditor/utils.ts +49 -65
- package/src/client/VZSidebar/index.tsx +2 -2
- package/src/client/definitionJumpListeners.ts +47 -0
- package/src/client/useKeyboardShortcuts.ts +23 -28
- package/src/client/useOpenDirectories.ts +0 -1
- package/src/llm-streaming-server/README.md +5 -3
- package/src/llm-streaming-ui/README.md +44 -42
- package/src/llm-streaming-ui/components/ChatInput.tsx +6 -19
- package/src/llm-streaming-ui/components/DiffView.tsx +6 -24
- package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +1 -1
- package/src/llm-streaming-ui/components/Message.tsx +11 -27
- package/src/llm-streaming-ui/components/MessageList.tsx +15 -29
- package/src/llm-streaming-ui/components/Spinner.scss +37 -0
- package/src/llm-streaming-ui/components/Spinner.tsx +59 -0
- package/src/llm-streaming-ui/components/bootstrap.ts +16 -0
- package/src/llm-streaming-ui/components/icons.tsx +68 -0
- package/src/llm-streaming-ui/components/index.tsx +34 -30
- package/src/llm-streaming-ui/index.ts +13 -0
- package/src/llm-streaming-ui/props.ts +137 -0
- package/src/ot.ts +221 -4
- package/src/server/createServer.ts +413 -0
- package/src/server/index.ts +8 -333
- package/dist/assets/buildWorker-DylWm2VX.js +0 -687
- package/dist/assets/index-Dyt9tpmu.css +0 -1
- package/dist/assets/index-nL6to42p.js +0 -364
- package/dist/assets/worker-b9bkZkXK.js +0 -116
- package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
- package/src/client/AIAssist/generateFilesContext.ts +0 -25
- package/src/client/AIAssist/index.ts +0 -2
- package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
- /package/src/{client → llm-streaming-ui}/hooks/useAutoScroll.ts +0 -0
- /package/src/{client → llm-streaming-ui}/utils/scrollUtils.ts +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useCallback, useContext } from 'react';
|
|
2
|
+
import { getFileId } from '@vizhub/viz-utils';
|
|
3
|
+
import { AIChat } from '../../llm-streaming-ui';
|
|
4
|
+
import { VZCodeContext } from '../VZCodeContext';
|
|
5
|
+
import {
|
|
6
|
+
enableAskMode,
|
|
7
|
+
enableDiffView,
|
|
8
|
+
enableVoiceInput,
|
|
9
|
+
} from '../featureFlags';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Bridges VZCode's context into the standalone `AIChat` component.
|
|
13
|
+
*
|
|
14
|
+
* `AIChat` (from `llm-streaming-ui`) is fully controlled and reads no
|
|
15
|
+
* application state. This wrapper supplies the chat state, callbacks,
|
|
16
|
+
* feature flags, and file-link handling from `VZCodeContext`.
|
|
17
|
+
*/
|
|
18
|
+
export const AIChatWrapper = () => {
|
|
19
|
+
const {
|
|
20
|
+
content,
|
|
21
|
+
aiChatFocused,
|
|
22
|
+
aiChatMode,
|
|
23
|
+
aiChatMessage,
|
|
24
|
+
currentChatId,
|
|
25
|
+
selectedChatId,
|
|
26
|
+
setSelectedChatId,
|
|
27
|
+
aiErrorMessage,
|
|
28
|
+
setAIChatMode,
|
|
29
|
+
getStoredAIPrompt,
|
|
30
|
+
setAIChatMessage,
|
|
31
|
+
handleSendMessage,
|
|
32
|
+
setAIErrorMessage,
|
|
33
|
+
navigateMessageHistoryUp,
|
|
34
|
+
navigateMessageHistoryDown,
|
|
35
|
+
resetMessageHistoryNavigation,
|
|
36
|
+
enableMinimalEditFlow,
|
|
37
|
+
additionalWidgets,
|
|
38
|
+
openTab,
|
|
39
|
+
setIsAIChatOpen,
|
|
40
|
+
} = useContext(VZCodeContext);
|
|
41
|
+
|
|
42
|
+
// Open a file referenced by a link inside a diff.
|
|
43
|
+
const handleOpenFile = useCallback(
|
|
44
|
+
(fileName: string) => {
|
|
45
|
+
if (!content) return;
|
|
46
|
+
const fileId = getFileId(content, fileName);
|
|
47
|
+
if (fileId) {
|
|
48
|
+
openTab({ fileId, isTransient: false });
|
|
49
|
+
setIsAIChatOpen(false);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[content, openTab, setIsAIChatOpen],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<AIChat
|
|
57
|
+
content={content}
|
|
58
|
+
aiChatFocused={aiChatFocused}
|
|
59
|
+
aiChatMode={aiChatMode}
|
|
60
|
+
setAIChatMode={setAIChatMode}
|
|
61
|
+
aiChatMessage={aiChatMessage}
|
|
62
|
+
setAIChatMessage={setAIChatMessage}
|
|
63
|
+
aiErrorMessage={aiErrorMessage}
|
|
64
|
+
setAIErrorMessage={setAIErrorMessage}
|
|
65
|
+
currentChatId={currentChatId}
|
|
66
|
+
selectedChatId={selectedChatId}
|
|
67
|
+
setSelectedChatId={setSelectedChatId}
|
|
68
|
+
handleSendMessage={handleSendMessage}
|
|
69
|
+
navigateMessageHistoryUp={navigateMessageHistoryUp}
|
|
70
|
+
navigateMessageHistoryDown={
|
|
71
|
+
navigateMessageHistoryDown
|
|
72
|
+
}
|
|
73
|
+
resetMessageHistoryNavigation={
|
|
74
|
+
resetMessageHistoryNavigation
|
|
75
|
+
}
|
|
76
|
+
getStoredAIPrompt={getStoredAIPrompt}
|
|
77
|
+
onOpenFile={handleOpenFile}
|
|
78
|
+
additionalWidgets={additionalWidgets}
|
|
79
|
+
enableDiffView={enableDiffView}
|
|
80
|
+
enableAskMode={enableAskMode}
|
|
81
|
+
enableVoiceInput={enableVoiceInput}
|
|
82
|
+
enableMinimalEditFlow={enableMinimalEditFlow}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
@@ -9,7 +9,11 @@ import { VZCodeContext } from '../../VZCodeContext';
|
|
|
9
9
|
import { VizContent, VizFileId } from '@vizhub/viz-types';
|
|
10
10
|
import { VisualEditorConfigEntry } from '../../../types';
|
|
11
11
|
import { EmptyState } from '../EmptyState';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
toHclChannels,
|
|
14
|
+
coerceChannelNumber,
|
|
15
|
+
hclChannelsToHex,
|
|
16
|
+
} from './colorUtils';
|
|
13
17
|
import { CONFIG_FILE_NAME } from './constants';
|
|
14
18
|
import { getVisualEditorEmptyReason } from './status';
|
|
15
19
|
import { updateVisualEditorProperty } from './updateConfig';
|
|
@@ -59,95 +63,61 @@ export const VisualEditor = () => {
|
|
|
59
63
|
}
|
|
60
64
|
}, [configFileId, files]);
|
|
61
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(
|
|
80
|
+
document,
|
|
81
|
+
configFileId,
|
|
82
|
+
property,
|
|
83
|
+
value,
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
[configFileId, submitOperation],
|
|
88
|
+
);
|
|
89
|
+
|
|
62
90
|
const onSliderChange = useCallback(
|
|
63
91
|
(property: string) =>
|
|
64
|
-
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
setLocalValues((prev) => ({
|
|
71
|
-
...prev,
|
|
72
|
-
[property]: newValue,
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
submitOperation((document: VizContent) =>
|
|
76
|
-
updateVisualEditorProperty(
|
|
77
|
-
document,
|
|
78
|
-
configFileId,
|
|
79
|
-
property,
|
|
80
|
-
newValue,
|
|
81
|
-
),
|
|
82
|
-
);
|
|
83
|
-
},
|
|
84
|
-
[configFileId, submitOperation],
|
|
92
|
+
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
93
|
+
setWidgetValue(
|
|
94
|
+
property,
|
|
95
|
+
parseFloat(event.currentTarget.value),
|
|
96
|
+
),
|
|
97
|
+
[setWidgetValue],
|
|
85
98
|
);
|
|
86
99
|
|
|
87
100
|
const onCheckboxChange = useCallback(
|
|
88
101
|
(property: string) =>
|
|
89
|
-
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
[property]: newValue,
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
submitOperation((document: VizContent) =>
|
|
99
|
-
updateVisualEditorProperty(
|
|
100
|
-
document,
|
|
101
|
-
configFileId,
|
|
102
|
-
property,
|
|
103
|
-
newValue,
|
|
104
|
-
),
|
|
105
|
-
);
|
|
106
|
-
},
|
|
107
|
-
[configFileId, submitOperation],
|
|
102
|
+
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
103
|
+
setWidgetValue(
|
|
104
|
+
property,
|
|
105
|
+
event.currentTarget.checked,
|
|
106
|
+
),
|
|
107
|
+
[setWidgetValue],
|
|
108
108
|
);
|
|
109
109
|
|
|
110
110
|
const onTextInputChange = useCallback(
|
|
111
111
|
(property: string) =>
|
|
112
|
-
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// Update local state immediately for responsive UI
|
|
116
|
-
setLocalValues((prev) => ({
|
|
117
|
-
...prev,
|
|
118
|
-
[property]: newValue,
|
|
119
|
-
}));
|
|
120
|
-
|
|
121
|
-
submitOperation((document: VizContent) =>
|
|
122
|
-
updateVisualEditorProperty(
|
|
123
|
-
document,
|
|
124
|
-
configFileId,
|
|
125
|
-
property,
|
|
126
|
-
newValue,
|
|
127
|
-
),
|
|
128
|
-
);
|
|
129
|
-
},
|
|
130
|
-
[configFileId, submitOperation],
|
|
112
|
+
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
113
|
+
setWidgetValue(property, event.currentTarget.value),
|
|
114
|
+
[setWidgetValue],
|
|
131
115
|
);
|
|
132
116
|
|
|
133
117
|
const onDropdownChange = useCallback(
|
|
134
|
-
(property: string,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
...prev,
|
|
138
|
-
[property]: newValue,
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
submitOperation((document: VizContent) =>
|
|
142
|
-
updateVisualEditorProperty(
|
|
143
|
-
document,
|
|
144
|
-
configFileId,
|
|
145
|
-
property,
|
|
146
|
-
newValue,
|
|
147
|
-
),
|
|
148
|
-
);
|
|
149
|
-
},
|
|
150
|
-
[configFileId, submitOperation],
|
|
118
|
+
(property: string, value: string) =>
|
|
119
|
+
setWidgetValue(property, value),
|
|
120
|
+
[setWidgetValue],
|
|
151
121
|
);
|
|
152
122
|
|
|
153
123
|
// Custom dropdown handlers
|
|
@@ -203,74 +173,30 @@ export const VisualEditor = () => {
|
|
|
203
173
|
getNestedProperty<string>(configData, property) ??
|
|
204
174
|
'#000000';
|
|
205
175
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
hclFromRGB.l,
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
// Update the specific LCH component
|
|
226
|
-
const newhcl = [...hclArray];
|
|
227
|
-
if (lchComponent === 'h') newhcl[0] = newValue;
|
|
228
|
-
else if (lchComponent === 'c') newhcl[1] = newValue;
|
|
229
|
-
else if (lchComponent === 'l') newhcl[2] = newValue;
|
|
230
|
-
|
|
231
|
-
// Convert back to hex
|
|
232
|
-
let newHex;
|
|
233
|
-
try {
|
|
234
|
-
const newColor = hcl(
|
|
235
|
-
newhcl[0],
|
|
236
|
-
newhcl[1],
|
|
237
|
-
newhcl[2],
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
if (newColor.displayable()) {
|
|
241
|
-
newHex = newColor.formatHex();
|
|
242
|
-
} else {
|
|
243
|
-
newHex = currentHex;
|
|
244
|
-
}
|
|
245
|
-
} catch {
|
|
246
|
-
// Fallback to current color if conversion fails
|
|
247
|
-
newHex = currentHex;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Update local state for responsive UI
|
|
251
|
-
setLocalValues((prev) => ({
|
|
252
|
-
...prev,
|
|
253
|
-
[property]: newHex,
|
|
254
|
-
[`${property}_h`]: newhcl[0],
|
|
255
|
-
[`${property}_c`]: newhcl[1],
|
|
256
|
-
[`${property}_l`]: newhcl[2],
|
|
257
|
-
}));
|
|
258
|
-
|
|
259
|
-
submitOperation((document: VizContent) =>
|
|
260
|
-
updateVisualEditorProperty(
|
|
261
|
-
document,
|
|
262
|
-
configFileId,
|
|
263
|
-
property,
|
|
264
|
-
newHex,
|
|
265
|
-
),
|
|
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,
|
|
266
192
|
);
|
|
193
|
+
setWidgetValue(property, newHex, {
|
|
194
|
+
[`${property}_h`]: channels.h,
|
|
195
|
+
[`${property}_c`]: channels.c,
|
|
196
|
+
[`${property}_l`]: channels.l,
|
|
197
|
+
});
|
|
267
198
|
},
|
|
268
|
-
[
|
|
269
|
-
configData,
|
|
270
|
-
configFileId,
|
|
271
|
-
submitOperation,
|
|
272
|
-
localValues,
|
|
273
|
-
],
|
|
199
|
+
[configData, setWidgetValue, localValues],
|
|
274
200
|
);
|
|
275
201
|
|
|
276
202
|
const visualEditorWidgets: VisualEditorConfigEntry[] =
|
|
@@ -288,52 +214,19 @@ export const VisualEditor = () => {
|
|
|
288
214
|
[key: string]: number | boolean | string;
|
|
289
215
|
} = {};
|
|
290
216
|
visualEditorWidgets.forEach((widget) => {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
newLocalValues[widget.property] =
|
|
303
|
-
|
|
304
|
-
widget.property,
|
|
305
|
-
);
|
|
306
|
-
} else if (widget.type === 'dropdown') {
|
|
307
|
-
newLocalValues[widget.property] = getNestedProperty(
|
|
308
|
-
configData,
|
|
309
|
-
widget.property,
|
|
310
|
-
);
|
|
311
|
-
} else if (widget.type === 'color') {
|
|
312
|
-
newLocalValues[widget.property] = getNestedProperty(
|
|
313
|
-
configData,
|
|
314
|
-
widget.property,
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
// Convert hex to LCH for internal state
|
|
318
|
-
const hexColor = getNestedProperty<string>(
|
|
319
|
-
configData,
|
|
320
|
-
widget.property,
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
if (hexColor) {
|
|
324
|
-
try {
|
|
325
|
-
const rgbColor = color(hexColor);
|
|
326
|
-
const lch = hcl(rgbColor);
|
|
327
|
-
newLocalValues[`${widget.property}_h`] = lch.h;
|
|
328
|
-
newLocalValues[`${widget.property}_c`] = lch.c;
|
|
329
|
-
newLocalValues[`${widget.property}_l`] = lch.l;
|
|
330
|
-
} catch {
|
|
331
|
-
// Fallback values if conversion fails
|
|
332
|
-
newLocalValues[`${widget.property}_l`] = 0;
|
|
333
|
-
newLocalValues[`${widget.property}_c`] = 0;
|
|
334
|
-
newLocalValues[`${widget.property}_h`] = 0;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
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;
|
|
337
230
|
}
|
|
338
231
|
});
|
|
339
232
|
setLocalValues(newLocalValues);
|
|
@@ -484,25 +377,19 @@ export const VisualEditor = () => {
|
|
|
484
377
|
) ??
|
|
485
378
|
'#000000';
|
|
486
379
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const currentC =
|
|
501
|
-
localValues[`${widgetConfig.property}_c`] ??
|
|
502
|
-
hclColor.c;
|
|
503
|
-
const currentL =
|
|
504
|
-
localValues[`${widgetConfig.property}_l`] ??
|
|
505
|
-
hclColor.l;
|
|
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
|
+
);
|
|
506
393
|
|
|
507
394
|
return (
|
|
508
395
|
<ColorWidget
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { color, hcl } from 'd3-color';
|
|
2
|
+
|
|
3
|
+
export type HclChannels = {
|
|
4
|
+
h: number;
|
|
5
|
+
c: number;
|
|
6
|
+
l: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function toHclChannels(value: string): HclChannels {
|
|
10
|
+
const parsed = color(value);
|
|
11
|
+
const result = parsed ? hcl(parsed) : hcl('black');
|
|
12
|
+
return {
|
|
13
|
+
h: Number.isFinite(result.h) ? result.h : 0,
|
|
14
|
+
c: Number.isFinite(result.c) ? result.c : 0,
|
|
15
|
+
l: Number.isFinite(result.l) ? result.l : 0,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Coerces a widget value to a finite number, falling back when
|
|
21
|
+
* the stored value is not numeric (widget values may be strings or
|
|
22
|
+
* booleans for other widget types).
|
|
23
|
+
*/
|
|
24
|
+
export function coerceChannelNumber(
|
|
25
|
+
value: unknown,
|
|
26
|
+
fallback: number,
|
|
27
|
+
): number {
|
|
28
|
+
return typeof value === 'number' && Number.isFinite(value)
|
|
29
|
+
? value
|
|
30
|
+
: fallback;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function hclChannelsToHex(
|
|
34
|
+
channels: HclChannels,
|
|
35
|
+
fallback: string,
|
|
36
|
+
): string {
|
|
37
|
+
const next = hcl(channels.h, channels.c, channels.l);
|
|
38
|
+
return next.displayable() ? next.formatHex() : fallback;
|
|
39
|
+
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { color } from 'd3-color';
|
|
2
2
|
import type { VisualEditorEmptyReason } from '../../../types';
|
|
3
|
-
|
|
4
|
-
const UNSAFE_PATH_SEGMENTS = new Set([
|
|
5
|
-
'__proto__',
|
|
6
|
-
'constructor',
|
|
7
|
-
'prototype',
|
|
8
|
-
]);
|
|
3
|
+
import { getEditablePropertyValue } from './utils';
|
|
9
4
|
|
|
10
5
|
const isRecord = (
|
|
11
6
|
value: unknown,
|
|
@@ -14,39 +9,6 @@ const isRecord = (
|
|
|
14
9
|
typeof value === 'object' &&
|
|
15
10
|
!Array.isArray(value);
|
|
16
11
|
|
|
17
|
-
/**
|
|
18
|
-
* Resolve only own properties of plain JSON objects, using the same dot-path
|
|
19
|
-
* semantics as setNestedProperty. Missing values, arrays in the path and
|
|
20
|
-
* dangerous keys are not editable targets.
|
|
21
|
-
*/
|
|
22
|
-
function editableValueAt(
|
|
23
|
-
config: Record<string, unknown>,
|
|
24
|
-
path: string,
|
|
25
|
-
): { found: boolean; value: unknown } {
|
|
26
|
-
const segments = path.split('.');
|
|
27
|
-
if (
|
|
28
|
-
segments.some(
|
|
29
|
-
(segment) =>
|
|
30
|
-
!segment || UNSAFE_PATH_SEGMENTS.has(segment),
|
|
31
|
-
)
|
|
32
|
-
) {
|
|
33
|
-
return { found: false, value: undefined };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let value: unknown = config;
|
|
37
|
-
for (const segment of segments) {
|
|
38
|
-
if (
|
|
39
|
-
!isRecord(value) ||
|
|
40
|
-
!Object.prototype.hasOwnProperty.call(value, segment)
|
|
41
|
-
) {
|
|
42
|
-
return { found: false, value: undefined };
|
|
43
|
-
}
|
|
44
|
-
value = value[segment];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { found: true, value };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
12
|
/** Pure classifier shared by the visual editor and host integration tests. */
|
|
51
13
|
export function getVisualEditorEmptyReason(
|
|
52
14
|
configText: string | null,
|
|
@@ -82,7 +44,7 @@ export function getVisualEditorEmptyReason(
|
|
|
82
44
|
return 'invalid-widgets';
|
|
83
45
|
}
|
|
84
46
|
|
|
85
|
-
const { found, value } =
|
|
47
|
+
const { found, value } = getEditablePropertyValue(
|
|
86
48
|
config,
|
|
87
49
|
widget.property,
|
|
88
50
|
);
|
|
@@ -2,7 +2,10 @@ import type {
|
|
|
2
2
|
VizContent,
|
|
3
3
|
VizFileId,
|
|
4
4
|
} from '@vizhub/viz-types';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
setNestedProperty,
|
|
7
|
+
getEditablePropertyValue,
|
|
8
|
+
} from './utils';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Apply a widget edit against the LATEST ShareDB document, not a stale React
|
|
@@ -29,6 +32,12 @@ export function updateVisualEditorProperty(
|
|
|
29
32
|
Array.isArray(currentConfig)
|
|
30
33
|
)
|
|
31
34
|
return document;
|
|
35
|
+
// A widget may become stale after a concurrent config edit. Never recreate
|
|
36
|
+
// a removed property or change the structure of its parent object.
|
|
37
|
+
if (
|
|
38
|
+
!getEditablePropertyValue(currentConfig, property).found
|
|
39
|
+
)
|
|
40
|
+
return document;
|
|
32
41
|
let updated: Record<string, unknown>;
|
|
33
42
|
try {
|
|
34
43
|
updated = setNestedProperty(
|