@workbench-kit/shell-react 0.0.2-prototype.0.2.6 → 0.0.2-prototype.0.2.8
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 +41 -0
- package/package.json +9 -9
- package/src/{chat-ai-mock-proposals.ts → chat/ai-mock-proposals.ts} +39 -39
- package/src/{chat-command-input.ts → chat/command-input.ts} +52 -52
- package/src/{chat-command-policy.ts → chat/command-policy.ts} +54 -54
- package/src/{chat-command-surface.tsx → chat/command-surface.tsx} +155 -155
- package/src/{use-workbench-chat-command-proposals.ts → chat/use-chat-command-proposals.ts} +194 -194
- package/src/{chat-view-data.ts → chat/view-data.ts} +20 -20
- package/src/{chat-view.tsx → chat/view.tsx} +220 -220
- package/src/{command-inspector-surface.tsx → commands/inspector-surface.tsx} +46 -46
- package/src/{use-workbench-command-descriptors.ts → commands/use-command-descriptors.ts} +41 -41
- package/src/{use-context-key-revision.ts → commands/use-context-key-revision.ts} +18 -18
- package/src/{commands-view-data.ts → commands/view-data.ts} +17 -17
- package/src/{commands-view.tsx → commands/view.tsx} +43 -43
- package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -124
- package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -17
- package/src/devtools/index.ts +11 -11
- package/src/devtools/use-workbench-devtools-snapshot.ts +84 -84
- package/src/devtools/workbench-devtools-snapshot.ts +140 -140
- package/src/devtools/workbench-devtools.css +82 -82
- package/src/{editor-area-dnd.ts → editor/area-dnd.ts} +69 -69
- package/src/{editor-area-model.ts → editor/area-model.ts} +71 -71
- package/src/{editor-area.css → editor/area.css} +454 -454
- package/src/{editor-area.tsx → editor/area.tsx} +676 -676
- package/src/{editor-host-surface.tsx → editor/host-surface.tsx} +631 -634
- package/src/{editor-pane-visibility.ts → editor/pane-visibility.ts} +130 -130
- package/src/{editor-resource.ts → editor/resource.ts} +36 -36
- package/src/{editor-state-storage.ts → editor/state-storage.ts} +182 -193
- package/src/{editor-tab-context-menu.ts → editor/tab-context-menu.ts} +118 -118
- package/src/{use-editor.ts → editor/use-editor.ts} +114 -107
- package/src/{editor-view-providers.tsx → editor/view-providers.tsx} +552 -552
- package/src/{editor-workspace-file-availability.ts → editor/workspace-file-availability.ts} +15 -15
- package/src/{editor-workspace-reconcile.tsx → editor/workspace-reconcile.tsx} +31 -28
- package/src/{explorer-context-menu.ts → explorer/context-menu.ts} +114 -114
- package/src/{createCommandWorkspaceExplorerPort.ts → explorer/create-command-workspace-explorer-port.ts} +86 -86
- package/src/{explorer-reveal.ts → explorer/reveal.ts} +112 -112
- package/src/{search-view-data.ts → explorer/search-view-data.ts} +15 -15
- package/src/{search-view.tsx → explorer/search-view.tsx} +65 -62
- package/src/{use-active-workspace-path.ts → explorer/use-active-workspace-path.ts} +15 -15
- package/src/{explorer-view-data.ts → explorer/view-data.ts} +58 -58
- package/src/{explorer-view.tsx → explorer/view.tsx} +227 -224
- package/src/{extension-context-menu.ts → extensions/context-menu.ts} +52 -52
- package/src/{extension-management-model.ts → extensions/management-model.ts} +313 -313
- package/src/{use-extension-management.ts → extensions/use-extension-management.ts} +241 -193
- package/src/{extensions-view-data.ts → extensions/view-data.ts} +19 -19
- package/src/{extensions-view.tsx → extensions/view.tsx} +63 -38
- package/src/{field-remap-demo.tsx → field-remap/demo.tsx} +18 -18
- package/src/{field-remap-editor-surface.tsx → field-remap/editor-surface.tsx} +36 -36
- package/src/{field-remap-flow-adapter.ts → field-remap/flow-adapter.ts} +240 -240
- package/src/{field-remap-flow.tsx → field-remap/flow.tsx} +369 -369
- package/src/{field-remap-graph.tsx → field-remap/graph.tsx} +559 -559
- package/src/field-remap/jsonata-transform.ts +166 -0
- package/src/{field-remap-panel.tsx → field-remap/panel.tsx} +193 -175
- package/src/{field-remap-samples.ts → field-remap/samples.ts} +352 -352
- package/src/{table-mapping-adapter.ts → field-remap/table-mapping-adapter.ts} +59 -59
- package/src/{field-remap-tree.tsx → field-remap/tree.tsx} +404 -404
- package/src/{field-remap-view-data.ts → field-remap/view-data.ts} +16 -16
- package/src/{field-remap-view.css → field-remap/view.css} +676 -676
- package/src/{field-remap-view.tsx → field-remap/view.tsx} +86 -86
- package/src/index.ts +212 -199
- package/src/{json-form-source-patch.ts → jdw/json-form-source-patch.ts} +323 -323
- package/src/{jdw-lab-view-data.ts → jdw/lab-view-data.ts} +25 -25
- package/src/{jdw-lab-view.css → jdw/lab-view.css} +21 -21
- package/src/{jdw-lab-view.tsx → jdw/lab-view.tsx} +79 -79
- package/src/{jdw-widget-form-view.tsx → jdw/widget-form-view.tsx} +68 -65
- package/src/{jdw-widget-preview-view.tsx → jdw/widget-preview-view.tsx} +54 -51
- package/src/{keybinding-overrides-storage.ts → management/keybinding-overrides-storage.ts} +49 -57
- package/src/{keybinding-management-settings.tsx → management/keybinding-settings.tsx} +16 -16
- package/src/{management-palette-commands.ts → management/palette-commands.ts} +38 -38
- package/src/{preference-settings-storage.ts → management/preference-settings-storage.ts} +50 -58
- package/src/{management-settings-ids.ts → management/settings-ids.ts} +12 -12
- package/src/{management-settings.tsx → management/settings.tsx} +96 -75
- package/src/{use-command-management.ts → management/use-command-management.ts} +191 -191
- package/src/{use-keybinding-management.ts → management/use-keybinding-management.ts} +130 -130
- package/src/{shell-model.tsx → shell/model.tsx} +149 -149
- package/src/{provider.tsx → shell/provider.tsx} +603 -573
- package/src/{shell-secondary-actions.tsx → shell/secondary-actions.tsx} +59 -59
- package/src/{shell-settings-constants.ts → shell/settings-constants.ts} +9 -9
- package/src/{shell-settings.tsx → shell/settings.tsx} +599 -599
- package/src/{shell.tsx → shell/shell.tsx} +680 -649
- package/src/{shell-titlebar-layout-controls.tsx → shell/titlebar-layout-controls.tsx} +4 -4
- package/src/{shell-view-host.tsx → shell/view-host.tsx} +212 -199
- package/src/{workbench-appearance-storage.ts → workbench/appearance-storage.ts} +107 -115
- package/src/{workbench-command-host.tsx → workbench/command-host.tsx} +243 -243
- package/src/{workbench-command-palette.ts → workbench/command-palette.ts} +208 -208
- package/src/{workbench-keybinding-bridge.ts → workbench/keybinding-bridge.ts} +54 -54
- package/src/{workbench-layout-storage.ts → workbench/layout-storage.ts} +134 -145
- package/src/{workbench-profile-modal.tsx → workbench/profile-modal.tsx} +118 -118
- package/src/{workbench-shell-command-registration.ts → workbench/shell-command-registration.ts} +58 -58
- package/src/{workbench-startup-gate.tsx → workbench/startup-gate.tsx} +136 -136
- package/src/{workbench-status-sections.ts → workbench/status-sections.ts} +43 -43
- package/src/{use-persisted-workbench-appearance.ts → workbench/use-persisted-appearance.ts} +33 -33
- package/src/{workbench-user-commands.ts → workbench/user-commands.ts} +46 -46
- package/src/{workspace-view-state.ts → workbench/workspace-view-state.ts} +35 -35
- package/src/jsonata-transform.ts +0 -36
|
@@ -1,323 +1,323 @@
|
|
|
1
|
-
export type JsonFormPath = readonly (string | number)[];
|
|
2
|
-
|
|
3
|
-
export interface JsonTextRange {
|
|
4
|
-
readonly end: number;
|
|
5
|
-
readonly start: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function replaceJsonValueAtPath(
|
|
9
|
-
source: string,
|
|
10
|
-
path: JsonFormPath,
|
|
11
|
-
nextValue: unknown,
|
|
12
|
-
): string {
|
|
13
|
-
if (path.length === 0) {
|
|
14
|
-
return JSON.stringify(nextValue);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const range = findJsonValueRangeAtPath(source, path);
|
|
18
|
-
if (!range) {
|
|
19
|
-
return fallbackSerializeJsonPathEdit(source, path, nextValue);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return `${source.slice(0, range.start)}${JSON.stringify(nextValue)}${source.slice(range.end)}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function fallbackSerializeJsonPathEdit(
|
|
26
|
-
source: string,
|
|
27
|
-
path: JsonFormPath,
|
|
28
|
-
nextValue: unknown,
|
|
29
|
-
): string {
|
|
30
|
-
const parsed: unknown = JSON.parse(source);
|
|
31
|
-
const nextRecord = updateJsonPathValue(parsed, path, nextValue);
|
|
32
|
-
return JSON.stringify(nextRecord, null, detectJsonIndent(source));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function detectJsonIndent(source: string): number {
|
|
36
|
-
return /\n[ \t]+"/.test(source) ? 2 : 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function updateJsonPathValue(value: unknown, path: JsonFormPath, nextValue: unknown): unknown {
|
|
40
|
-
if (path.length === 0) {
|
|
41
|
-
return nextValue;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const [head, ...tail] = path;
|
|
45
|
-
|
|
46
|
-
if (Array.isArray(value) && typeof head === 'number') {
|
|
47
|
-
const nextArray = [...value];
|
|
48
|
-
nextArray[head] = updateJsonPathValue(nextArray[head], tail, nextValue);
|
|
49
|
-
return nextArray;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (isJsonRecord(value) && typeof head === 'string') {
|
|
53
|
-
return {
|
|
54
|
-
...value,
|
|
55
|
-
[head]: updateJsonPathValue(value[head], tail, nextValue),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function isJsonRecord(value: unknown): value is Record<string, unknown> {
|
|
63
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function findJsonValueRangeAtPath(source: string, path: JsonFormPath): JsonTextRange | null {
|
|
67
|
-
const start = skipWhitespace(source, 0);
|
|
68
|
-
if (start >= source.length) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return locateJsonValueRange(source, start, path, 0);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function locateJsonValueRange(
|
|
76
|
-
source: string,
|
|
77
|
-
index: number,
|
|
78
|
-
path: JsonFormPath,
|
|
79
|
-
pathIndex: number,
|
|
80
|
-
): JsonTextRange | null {
|
|
81
|
-
index = skipWhitespace(source, index);
|
|
82
|
-
|
|
83
|
-
if (pathIndex >= path.length) {
|
|
84
|
-
const end = scanJsonValueEnd(source, index);
|
|
85
|
-
return end < 0 ? null : { start: index, end };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const segment = path[pathIndex];
|
|
89
|
-
if (typeof segment === 'number') {
|
|
90
|
-
if (source[index] !== '[') {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return locateJsonValueInArray(source, index + 1, path, pathIndex, segment);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (typeof segment === 'string') {
|
|
98
|
-
if (source[index] !== '{') {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return locateJsonValueInObject(source, index + 1, path, pathIndex, segment);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function locateJsonValueInObject(
|
|
109
|
-
source: string,
|
|
110
|
-
index: number,
|
|
111
|
-
path: JsonFormPath,
|
|
112
|
-
pathIndex: number,
|
|
113
|
-
key: string,
|
|
114
|
-
): JsonTextRange | null {
|
|
115
|
-
let cursor = skipWhitespace(source, index);
|
|
116
|
-
|
|
117
|
-
while (cursor < source.length && source[cursor] !== '}') {
|
|
118
|
-
const keyRange = scanJsonStringToken(source, cursor);
|
|
119
|
-
if (!keyRange) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const parsedKey = JSON.parse(source.slice(keyRange.start, keyRange.end)) as string;
|
|
124
|
-
cursor = skipWhitespace(source, keyRange.end);
|
|
125
|
-
|
|
126
|
-
if (source[cursor] !== ':') {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
cursor = skipWhitespace(source, cursor + 1);
|
|
131
|
-
|
|
132
|
-
if (parsedKey === key) {
|
|
133
|
-
return locateJsonValueRange(source, cursor, path, pathIndex + 1);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const valueEnd = scanJsonValueEnd(source, cursor);
|
|
137
|
-
if (valueEnd < 0) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
cursor = skipWhitespace(source, valueEnd);
|
|
142
|
-
if (source[cursor] === ',') {
|
|
143
|
-
cursor = skipWhitespace(source, cursor + 1);
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (source[cursor] === '}') {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function locateJsonValueInArray(
|
|
158
|
-
source: string,
|
|
159
|
-
index: number,
|
|
160
|
-
path: JsonFormPath,
|
|
161
|
-
pathIndex: number,
|
|
162
|
-
targetIndex: number,
|
|
163
|
-
): JsonTextRange | null {
|
|
164
|
-
let cursor = skipWhitespace(source, index);
|
|
165
|
-
let currentIndex = 0;
|
|
166
|
-
|
|
167
|
-
while (cursor < source.length && source[cursor] !== ']') {
|
|
168
|
-
if (currentIndex === targetIndex) {
|
|
169
|
-
return locateJsonValueRange(source, cursor, path, pathIndex + 1);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const valueEnd = scanJsonValueEnd(source, cursor);
|
|
173
|
-
if (valueEnd < 0) {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
currentIndex += 1;
|
|
178
|
-
cursor = skipWhitespace(source, valueEnd);
|
|
179
|
-
|
|
180
|
-
if (source[cursor] === ',') {
|
|
181
|
-
cursor = skipWhitespace(source, cursor + 1);
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (source[cursor] === ']') {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function scanJsonValueEnd(source: string, index: number): number {
|
|
196
|
-
index = skipWhitespace(source, index);
|
|
197
|
-
if (index >= source.length) {
|
|
198
|
-
return -1;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const char = source[index];
|
|
202
|
-
|
|
203
|
-
if (char === '"') {
|
|
204
|
-
const stringToken = scanJsonStringToken(source, index);
|
|
205
|
-
return stringToken?.end ?? -1;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (char === '{') {
|
|
209
|
-
return scanJsonContainerEnd(source, index, '{', '}');
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (char === '[') {
|
|
213
|
-
return scanJsonContainerEnd(source, index, '[', ']');
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (source.startsWith('true', index)) {
|
|
217
|
-
return index + 4;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (source.startsWith('false', index)) {
|
|
221
|
-
return index + 5;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (source.startsWith('null', index)) {
|
|
225
|
-
return index + 4;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
let cursor = index;
|
|
229
|
-
while (cursor < source.length && !',]} \t\r\n'.includes(source[cursor] ?? '')) {
|
|
230
|
-
cursor += 1;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return cursor > index ? cursor : -1;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function scanJsonContainerEnd(
|
|
237
|
-
source: string,
|
|
238
|
-
index: number,
|
|
239
|
-
openChar: '{' | '[',
|
|
240
|
-
closeChar: '}' | ']',
|
|
241
|
-
): number {
|
|
242
|
-
let depth = 0;
|
|
243
|
-
let cursor = index;
|
|
244
|
-
let inString = false;
|
|
245
|
-
let escaped = false;
|
|
246
|
-
|
|
247
|
-
while (cursor < source.length) {
|
|
248
|
-
const char = source[cursor];
|
|
249
|
-
|
|
250
|
-
if (inString) {
|
|
251
|
-
if (escaped) {
|
|
252
|
-
escaped = false;
|
|
253
|
-
} else if (char === '\\') {
|
|
254
|
-
escaped = true;
|
|
255
|
-
} else if (char === '"') {
|
|
256
|
-
inString = false;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
cursor += 1;
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (char === '"') {
|
|
264
|
-
inString = true;
|
|
265
|
-
cursor += 1;
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (char === openChar) {
|
|
270
|
-
depth += 1;
|
|
271
|
-
} else if (char === closeChar) {
|
|
272
|
-
depth -= 1;
|
|
273
|
-
if (depth === 0) {
|
|
274
|
-
return cursor + 1;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
cursor += 1;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return -1;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function scanJsonStringToken(source: string, index: number): JsonTextRange | null {
|
|
285
|
-
if (source[index] !== '"') {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
let cursor = index + 1;
|
|
290
|
-
let escaped = false;
|
|
291
|
-
|
|
292
|
-
while (cursor < source.length) {
|
|
293
|
-
const char = source[cursor];
|
|
294
|
-
|
|
295
|
-
if (escaped) {
|
|
296
|
-
escaped = false;
|
|
297
|
-
cursor += 1;
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (char === '\\') {
|
|
302
|
-
escaped = true;
|
|
303
|
-
cursor += 1;
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (char === '"') {
|
|
308
|
-
return { start: index, end: cursor + 1 };
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
cursor += 1;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function skipWhitespace(source: string, index: number): number {
|
|
318
|
-
while (index < source.length && /\s/.test(source[index] ?? '')) {
|
|
319
|
-
index += 1;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return index;
|
|
323
|
-
}
|
|
1
|
+
export type JsonFormPath = readonly (string | number)[];
|
|
2
|
+
|
|
3
|
+
export interface JsonTextRange {
|
|
4
|
+
readonly end: number;
|
|
5
|
+
readonly start: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function replaceJsonValueAtPath(
|
|
9
|
+
source: string,
|
|
10
|
+
path: JsonFormPath,
|
|
11
|
+
nextValue: unknown,
|
|
12
|
+
): string {
|
|
13
|
+
if (path.length === 0) {
|
|
14
|
+
return JSON.stringify(nextValue);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const range = findJsonValueRangeAtPath(source, path);
|
|
18
|
+
if (!range) {
|
|
19
|
+
return fallbackSerializeJsonPathEdit(source, path, nextValue);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return `${source.slice(0, range.start)}${JSON.stringify(nextValue)}${source.slice(range.end)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function fallbackSerializeJsonPathEdit(
|
|
26
|
+
source: string,
|
|
27
|
+
path: JsonFormPath,
|
|
28
|
+
nextValue: unknown,
|
|
29
|
+
): string {
|
|
30
|
+
const parsed: unknown = JSON.parse(source);
|
|
31
|
+
const nextRecord = updateJsonPathValue(parsed, path, nextValue);
|
|
32
|
+
return JSON.stringify(nextRecord, null, detectJsonIndent(source));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function detectJsonIndent(source: string): number {
|
|
36
|
+
return /\n[ \t]+"/.test(source) ? 2 : 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function updateJsonPathValue(value: unknown, path: JsonFormPath, nextValue: unknown): unknown {
|
|
40
|
+
if (path.length === 0) {
|
|
41
|
+
return nextValue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const [head, ...tail] = path;
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(value) && typeof head === 'number') {
|
|
47
|
+
const nextArray = [...value];
|
|
48
|
+
nextArray[head] = updateJsonPathValue(nextArray[head], tail, nextValue);
|
|
49
|
+
return nextArray;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isJsonRecord(value) && typeof head === 'string') {
|
|
53
|
+
return {
|
|
54
|
+
...value,
|
|
55
|
+
[head]: updateJsonPathValue(value[head], tail, nextValue),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isJsonRecord(value: unknown): value is Record<string, unknown> {
|
|
63
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function findJsonValueRangeAtPath(source: string, path: JsonFormPath): JsonTextRange | null {
|
|
67
|
+
const start = skipWhitespace(source, 0);
|
|
68
|
+
if (start >= source.length) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return locateJsonValueRange(source, start, path, 0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function locateJsonValueRange(
|
|
76
|
+
source: string,
|
|
77
|
+
index: number,
|
|
78
|
+
path: JsonFormPath,
|
|
79
|
+
pathIndex: number,
|
|
80
|
+
): JsonTextRange | null {
|
|
81
|
+
index = skipWhitespace(source, index);
|
|
82
|
+
|
|
83
|
+
if (pathIndex >= path.length) {
|
|
84
|
+
const end = scanJsonValueEnd(source, index);
|
|
85
|
+
return end < 0 ? null : { start: index, end };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const segment = path[pathIndex];
|
|
89
|
+
if (typeof segment === 'number') {
|
|
90
|
+
if (source[index] !== '[') {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return locateJsonValueInArray(source, index + 1, path, pathIndex, segment);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (typeof segment === 'string') {
|
|
98
|
+
if (source[index] !== '{') {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return locateJsonValueInObject(source, index + 1, path, pathIndex, segment);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function locateJsonValueInObject(
|
|
109
|
+
source: string,
|
|
110
|
+
index: number,
|
|
111
|
+
path: JsonFormPath,
|
|
112
|
+
pathIndex: number,
|
|
113
|
+
key: string,
|
|
114
|
+
): JsonTextRange | null {
|
|
115
|
+
let cursor = skipWhitespace(source, index);
|
|
116
|
+
|
|
117
|
+
while (cursor < source.length && source[cursor] !== '}') {
|
|
118
|
+
const keyRange = scanJsonStringToken(source, cursor);
|
|
119
|
+
if (!keyRange) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const parsedKey = JSON.parse(source.slice(keyRange.start, keyRange.end)) as string;
|
|
124
|
+
cursor = skipWhitespace(source, keyRange.end);
|
|
125
|
+
|
|
126
|
+
if (source[cursor] !== ':') {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
cursor = skipWhitespace(source, cursor + 1);
|
|
131
|
+
|
|
132
|
+
if (parsedKey === key) {
|
|
133
|
+
return locateJsonValueRange(source, cursor, path, pathIndex + 1);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const valueEnd = scanJsonValueEnd(source, cursor);
|
|
137
|
+
if (valueEnd < 0) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
cursor = skipWhitespace(source, valueEnd);
|
|
142
|
+
if (source[cursor] === ',') {
|
|
143
|
+
cursor = skipWhitespace(source, cursor + 1);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (source[cursor] === '}') {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function locateJsonValueInArray(
|
|
158
|
+
source: string,
|
|
159
|
+
index: number,
|
|
160
|
+
path: JsonFormPath,
|
|
161
|
+
pathIndex: number,
|
|
162
|
+
targetIndex: number,
|
|
163
|
+
): JsonTextRange | null {
|
|
164
|
+
let cursor = skipWhitespace(source, index);
|
|
165
|
+
let currentIndex = 0;
|
|
166
|
+
|
|
167
|
+
while (cursor < source.length && source[cursor] !== ']') {
|
|
168
|
+
if (currentIndex === targetIndex) {
|
|
169
|
+
return locateJsonValueRange(source, cursor, path, pathIndex + 1);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const valueEnd = scanJsonValueEnd(source, cursor);
|
|
173
|
+
if (valueEnd < 0) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
currentIndex += 1;
|
|
178
|
+
cursor = skipWhitespace(source, valueEnd);
|
|
179
|
+
|
|
180
|
+
if (source[cursor] === ',') {
|
|
181
|
+
cursor = skipWhitespace(source, cursor + 1);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (source[cursor] === ']') {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function scanJsonValueEnd(source: string, index: number): number {
|
|
196
|
+
index = skipWhitespace(source, index);
|
|
197
|
+
if (index >= source.length) {
|
|
198
|
+
return -1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const char = source[index];
|
|
202
|
+
|
|
203
|
+
if (char === '"') {
|
|
204
|
+
const stringToken = scanJsonStringToken(source, index);
|
|
205
|
+
return stringToken?.end ?? -1;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (char === '{') {
|
|
209
|
+
return scanJsonContainerEnd(source, index, '{', '}');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (char === '[') {
|
|
213
|
+
return scanJsonContainerEnd(source, index, '[', ']');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (source.startsWith('true', index)) {
|
|
217
|
+
return index + 4;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (source.startsWith('false', index)) {
|
|
221
|
+
return index + 5;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (source.startsWith('null', index)) {
|
|
225
|
+
return index + 4;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let cursor = index;
|
|
229
|
+
while (cursor < source.length && !',]} \t\r\n'.includes(source[cursor] ?? '')) {
|
|
230
|
+
cursor += 1;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return cursor > index ? cursor : -1;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function scanJsonContainerEnd(
|
|
237
|
+
source: string,
|
|
238
|
+
index: number,
|
|
239
|
+
openChar: '{' | '[',
|
|
240
|
+
closeChar: '}' | ']',
|
|
241
|
+
): number {
|
|
242
|
+
let depth = 0;
|
|
243
|
+
let cursor = index;
|
|
244
|
+
let inString = false;
|
|
245
|
+
let escaped = false;
|
|
246
|
+
|
|
247
|
+
while (cursor < source.length) {
|
|
248
|
+
const char = source[cursor];
|
|
249
|
+
|
|
250
|
+
if (inString) {
|
|
251
|
+
if (escaped) {
|
|
252
|
+
escaped = false;
|
|
253
|
+
} else if (char === '\\') {
|
|
254
|
+
escaped = true;
|
|
255
|
+
} else if (char === '"') {
|
|
256
|
+
inString = false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
cursor += 1;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (char === '"') {
|
|
264
|
+
inString = true;
|
|
265
|
+
cursor += 1;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (char === openChar) {
|
|
270
|
+
depth += 1;
|
|
271
|
+
} else if (char === closeChar) {
|
|
272
|
+
depth -= 1;
|
|
273
|
+
if (depth === 0) {
|
|
274
|
+
return cursor + 1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
cursor += 1;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return -1;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function scanJsonStringToken(source: string, index: number): JsonTextRange | null {
|
|
285
|
+
if (source[index] !== '"') {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
let cursor = index + 1;
|
|
290
|
+
let escaped = false;
|
|
291
|
+
|
|
292
|
+
while (cursor < source.length) {
|
|
293
|
+
const char = source[cursor];
|
|
294
|
+
|
|
295
|
+
if (escaped) {
|
|
296
|
+
escaped = false;
|
|
297
|
+
cursor += 1;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (char === '\\') {
|
|
302
|
+
escaped = true;
|
|
303
|
+
cursor += 1;
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (char === '"') {
|
|
308
|
+
return { start: index, end: cursor + 1 };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
cursor += 1;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function skipWhitespace(source: string, index: number): number {
|
|
318
|
+
while (index < source.length && /\s/.test(source[index] ?? '')) {
|
|
319
|
+
index += 1;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return index;
|
|
323
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export const SAMPLE_JDW_LAB_VIEW_RENDER_KIND = 'workbench-kit.samples.jdw.view' as const;
|
|
2
|
-
|
|
3
|
-
export interface SampleJdwLabViewRenderData {
|
|
4
|
-
readonly kind: typeof SAMPLE_JDW_LAB_VIEW_RENDER_KIND;
|
|
5
|
-
readonly templateJdwPath: string;
|
|
6
|
-
readonly widgetTreePath: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function isSampleJdwLabViewRenderData(value: unknown): value is SampleJdwLabViewRenderData {
|
|
10
|
-
if (typeof value !== 'object' || value === null) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const candidate = value as {
|
|
15
|
-
kind?: unknown;
|
|
16
|
-
templateJdwPath?: unknown;
|
|
17
|
-
widgetTreePath?: unknown;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
candidate.kind === SAMPLE_JDW_LAB_VIEW_RENDER_KIND &&
|
|
22
|
-
typeof candidate.templateJdwPath === 'string' &&
|
|
23
|
-
typeof candidate.widgetTreePath === 'string'
|
|
24
|
-
);
|
|
25
|
-
}
|
|
1
|
+
export const SAMPLE_JDW_LAB_VIEW_RENDER_KIND = 'workbench-kit.samples.jdw.view' as const;
|
|
2
|
+
|
|
3
|
+
export interface SampleJdwLabViewRenderData {
|
|
4
|
+
readonly kind: typeof SAMPLE_JDW_LAB_VIEW_RENDER_KIND;
|
|
5
|
+
readonly templateJdwPath: string;
|
|
6
|
+
readonly widgetTreePath: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isSampleJdwLabViewRenderData(value: unknown): value is SampleJdwLabViewRenderData {
|
|
10
|
+
if (typeof value !== 'object' || value === null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const candidate = value as {
|
|
15
|
+
kind?: unknown;
|
|
16
|
+
templateJdwPath?: unknown;
|
|
17
|
+
widgetTreePath?: unknown;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
candidate.kind === SAMPLE_JDW_LAB_VIEW_RENDER_KIND &&
|
|
22
|
+
typeof candidate.templateJdwPath === 'string' &&
|
|
23
|
+
typeof candidate.widgetTreePath === 'string'
|
|
24
|
+
);
|
|
25
|
+
}
|