@powerduck/schema-designer 0.1.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 (102) hide show
  1. package/README.md +217 -0
  2. package/dist/InlineSchemaEditor-BssSx3SI.d.ts +6 -0
  3. package/dist/InlineSchemaEditor-Bua-lDhE.d.cts +6 -0
  4. package/dist/chunk-2XUQB6BQ.js +1896 -0
  5. package/dist/chunk-4H3LXOL4.cjs +1900 -0
  6. package/dist/chunk-7LG4MVMD.cjs +2 -0
  7. package/dist/chunk-BXFABOMJ.js +1475 -0
  8. package/dist/chunk-FTALJIVZ.js +1 -0
  9. package/dist/chunk-GTZH37JS.cjs +1120 -0
  10. package/dist/chunk-GWHDTTQK.js +1437 -0
  11. package/dist/chunk-GXXD6ITE.cjs +1477 -0
  12. package/dist/chunk-HI5FBHCO.js +1057 -0
  13. package/dist/chunk-KX3LFFOV.js +88 -0
  14. package/dist/chunk-MADPN2PJ.js +185 -0
  15. package/dist/chunk-NOUORNCI.cjs +1452 -0
  16. package/dist/chunk-O6PTRJQ5.js +1195 -0
  17. package/dist/chunk-OBHJC3I2.cjs +2 -0
  18. package/dist/chunk-OOSNM45O.cjs +264 -0
  19. package/dist/chunk-P5B3HSPY.js +244 -0
  20. package/dist/chunk-PBE36BVA.js +1 -0
  21. package/dist/chunk-PVEYKCM6.js +1 -0
  22. package/dist/chunk-QZADGAP3.cjs +1218 -0
  23. package/dist/chunk-S7GNTGEE.js +1 -0
  24. package/dist/chunk-SMBDRWV2.cjs +2 -0
  25. package/dist/chunk-THYDOHOP.cjs +2 -0
  26. package/dist/chunk-WRHWOMZQ.cjs +190 -0
  27. package/dist/chunk-YNKP5JJA.cjs +32 -0
  28. package/dist/chunk-YWDKCX6N.cjs +91 -0
  29. package/dist/chunk-ZHNYNFGL.js +28 -0
  30. package/dist/compat/inline.cjs +137 -0
  31. package/dist/compat/inline.css +275 -0
  32. package/dist/compat/inline.d.cts +6 -0
  33. package/dist/compat/inline.d.ts +6 -0
  34. package/dist/compat/inline.js +4 -0
  35. package/dist/compat/parameters.cjs +90 -0
  36. package/dist/compat/parameters.css +997 -0
  37. package/dist/compat/parameters.d.cts +70 -0
  38. package/dist/compat/parameters.d.ts +70 -0
  39. package/dist/compat/parameters.js +9 -0
  40. package/dist/compat/tree.cjs +142 -0
  41. package/dist/compat/tree.css +1069 -0
  42. package/dist/compat/tree.d.cts +4 -0
  43. package/dist/compat/tree.d.ts +4 -0
  44. package/dist/compat/tree.js +5 -0
  45. package/dist/compat/variable-editor.cjs +82 -0
  46. package/dist/compat/variable-editor.d.cts +68 -0
  47. package/dist/compat/variable-editor.d.ts +68 -0
  48. package/dist/compat/variable-editor.js +1 -0
  49. package/dist/core/index.cjs +197 -0
  50. package/dist/core/index.d.cts +21 -0
  51. package/dist/core/index.d.ts +21 -0
  52. package/dist/core/index.js +4 -0
  53. package/dist/index.cjs +35 -0
  54. package/dist/index.css +1791 -0
  55. package/dist/index.d.cts +9 -0
  56. package/dist/index.d.ts +9 -0
  57. package/dist/index.js +10 -0
  58. package/dist/parameterValue-2pL9n-3q.d.ts +8 -0
  59. package/dist/parameterValue-Cky9Lnd3.d.cts +8 -0
  60. package/dist/react/index.cjs +35 -0
  61. package/dist/react/index.css +1791 -0
  62. package/dist/react/index.d.cts +9 -0
  63. package/dist/react/index.d.ts +9 -0
  64. package/dist/react/index.js +10 -0
  65. package/dist/react/inlineSchemaEditor/index.cjs +97 -0
  66. package/dist/react/inlineSchemaEditor/index.css +275 -0
  67. package/dist/react/inlineSchemaEditor/index.d.cts +6 -0
  68. package/dist/react/inlineSchemaEditor/index.d.ts +6 -0
  69. package/dist/react/inlineSchemaEditor/index.js +4 -0
  70. package/dist/react/parametersTable/index.cjs +22 -0
  71. package/dist/react/parametersTable/index.css +997 -0
  72. package/dist/react/parametersTable/index.d.cts +7 -0
  73. package/dist/react/parametersTable/index.d.ts +7 -0
  74. package/dist/react/parametersTable/index.js +9 -0
  75. package/dist/react/parametersTable/libs/generateValue.cjs +558 -0
  76. package/dist/react/parametersTable/libs/generateValue.d.cts +17 -0
  77. package/dist/react/parametersTable/libs/generateValue.d.ts +17 -0
  78. package/dist/react/parametersTable/libs/generateValue.js +551 -0
  79. package/dist/react/schemaTreeEditor/index.cjs +18 -0
  80. package/dist/react/schemaTreeEditor/index.css +1069 -0
  81. package/dist/react/schemaTreeEditor/index.d.cts +7 -0
  82. package/dist/react/schemaTreeEditor/index.d.ts +7 -0
  83. package/dist/react/schemaTreeEditor/index.js +5 -0
  84. package/dist/react/variableTextEditor/index.cjs +11 -0
  85. package/dist/react/variableTextEditor/index.css +306 -0
  86. package/dist/react/variableTextEditor/index.d.cts +6 -0
  87. package/dist/react/variableTextEditor/index.d.ts +6 -0
  88. package/dist/react/variableTextEditor/index.js +2 -0
  89. package/dist/schema-CKAPsYeW.d.cts +41 -0
  90. package/dist/schema-o7OJRaJ8.d.ts +41 -0
  91. package/dist/styles.css +1791 -0
  92. package/dist/tree-D06Xa6_N.d.ts +95 -0
  93. package/dist/tree-Dq1Rk-CF.d.cts +95 -0
  94. package/dist/types-B27Dw9do.d.cts +163 -0
  95. package/dist/types-B27Dw9do.d.ts +163 -0
  96. package/dist/types-Bk9rzr6l.d.cts +48 -0
  97. package/dist/types-D2jEaM9Z.d.cts +145 -0
  98. package/dist/types-D2jEaM9Z.d.ts +145 -0
  99. package/dist/types-xAihO_KW.d.ts +48 -0
  100. package/dist/variableTextEditor.types-ClzvARvK.d.cts +49 -0
  101. package/dist/variableTextEditor.types-ClzvARvK.d.ts +49 -0
  102. package/package.json +130 -0
@@ -0,0 +1,1437 @@
1
+ import { SettingsPanel, InlineSchemaEditor_default, InlineSchemaEditor } from './chunk-2XUQB6BQ.js';
2
+ import { VariableTextEditor } from './chunk-BXFABOMJ.js';
3
+ import { parameterKey, parameterValueText } from './chunk-ZHNYNFGL.js';
4
+ import { resolveParameterValue, resolveParameterType } from './chunk-MADPN2PJ.js';
5
+ import { createSchemaForType } from './chunk-HI5FBHCO.js';
6
+ import { nanoid } from 'nanoid';
7
+ import { VscSettingsCompact } from 'react-icons/vsc';
8
+ import { Box, createListCollection, Text, Table, Flex, Checkbox, Span, Select, Portal, ActionBar, Button, Popover, Tabs, Stack, Field, NativeSelect, Switch, Input } from '@chakra-ui/react';
9
+ import { jsx, jsxs } from 'react/jsx-runtime';
10
+ import { memo, useState, useRef, useEffect, useMemo, useLayoutEffect, useCallback } from 'react';
11
+ import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
12
+ import { LuGripVertical, LuRefreshCw } from 'react-icons/lu';
13
+ import { AiOutlineDelete } from 'react-icons/ai';
14
+
15
+ // src/react/parametersTable/libs/columns.ts
16
+ var DEFAULT_COLUMNS = [
17
+ { id: "name", label: "Name", defaultWidth: 180, minWidth: 160 },
18
+ { id: "value", label: "Value", defaultWidth: 220, minWidth: 120 },
19
+ { id: "type", label: "Type", defaultWidth: 140, minWidth: 120 },
20
+ {
21
+ id: "required",
22
+ label: "Required",
23
+ defaultWidth: 100,
24
+ minWidth: 100,
25
+ maxWidth: 140
26
+ },
27
+ { id: "description", label: "Description", defaultWidth: 360, minWidth: 180 }
28
+ ];
29
+ function getVisibleColumns(args) {
30
+ const { showRequired, showType, showDescription } = args;
31
+ return DEFAULT_COLUMNS.filter((c) => {
32
+ if (c.id === "required" && !showRequired) return false;
33
+ if (c.id === "type" && !showType) return false;
34
+ if (c.id === "description" && !showDescription) return false;
35
+ return true;
36
+ });
37
+ }
38
+ function getRightNeighborId(visibleColumns, columnId) {
39
+ const idx = visibleColumns.findIndex((c) => c.id === columnId);
40
+ if (idx < 0) return null;
41
+ return visibleColumns[idx + 1]?.id ?? null;
42
+ }
43
+ function clamp(value, min, max) {
44
+ return Math.max(min, Math.min(max, value));
45
+ }
46
+ function buildColumnDefsById(columns) {
47
+ return columns.reduce(
48
+ (acc, c) => {
49
+ acc[c.id] = c;
50
+ return acc;
51
+ },
52
+ {}
53
+ );
54
+ }
55
+ function fitColumnWidths(previous, columns, available) {
56
+ if (!columns.length || !Number.isFinite(available) || available <= 0)
57
+ return previous;
58
+ const minimum = columns.reduce((sum, column) => sum + column.minWidth, 0);
59
+ const maximum = columns.reduce(
60
+ (sum, column) => sum + (column.maxWidth ?? Infinity),
61
+ 0
62
+ );
63
+ const target = Math.max(minimum, Math.min(maximum, available));
64
+ const currentTotal = columns.reduce(
65
+ (sum, column) => sum + previous[column.id],
66
+ 0
67
+ );
68
+ const valid = columns.every(
69
+ (column) => Number.isFinite(previous[column.id]) && previous[column.id] >= column.minWidth && previous[column.id] <= (column.maxWidth ?? Infinity)
70
+ );
71
+ if (valid && Math.abs(currentTotal - target) < 0.01) return previous;
72
+ const weights = columns.map(
73
+ (column) => Math.max(
74
+ 1,
75
+ Number.isFinite(previous[column.id]) ? previous[column.id] : column.defaultWidth
76
+ )
77
+ );
78
+ const widthAt = (index, scale) => Math.max(
79
+ columns[index].minWidth,
80
+ Math.min(columns[index].maxWidth ?? Infinity, weights[index] * scale)
81
+ );
82
+ let low = 0;
83
+ let high = Math.max(1, target / Math.min(...weights));
84
+ for (let iteration = 0; iteration < 40; iteration += 1) {
85
+ const middle = (low + high) / 2;
86
+ const total = columns.reduce(
87
+ (sum, _, index) => sum + widthAt(index, middle),
88
+ 0
89
+ );
90
+ if (total < target) low = middle;
91
+ else high = middle;
92
+ }
93
+ const next = { ...previous };
94
+ columns.forEach((column, index) => {
95
+ next[column.id] = widthAt(index, (low + high) / 2);
96
+ });
97
+ return columns.every(
98
+ (column) => Math.abs(previous[column.id] - next[column.id]) < 0.01
99
+ ) ? previous : next;
100
+ }
101
+
102
+ // src/react/parametersTable/libs/splitterResize.ts
103
+ var EPSILON = 1e-3;
104
+ function finiteOr(value, fallback) {
105
+ return Number.isFinite(value) ? value : fallback;
106
+ }
107
+ function normalizeBounds(min, max) {
108
+ const safeMin = Math.max(0, finiteOr(min, 0));
109
+ const safeMax = Number.isFinite(max) ? Math.max(safeMin, max) : Number.POSITIVE_INFINITY;
110
+ return [safeMin, safeMax];
111
+ }
112
+ function clamp2(value, min, max) {
113
+ if (!Number.isFinite(value)) {
114
+ return min;
115
+ }
116
+ if (value < min) {
117
+ return min;
118
+ }
119
+ if (value > max) {
120
+ return max;
121
+ }
122
+ return value;
123
+ }
124
+ function applyAdjacentSplitterResize({
125
+ session,
126
+ clientX,
127
+ widths
128
+ }) {
129
+ if (!Number.isFinite(clientX)) {
130
+ return widths;
131
+ }
132
+ const { leftId, rightId, startClientX } = session;
133
+ if (!Number.isFinite(startClientX)) {
134
+ return widths;
135
+ }
136
+ const startLeftWidth = Math.max(
137
+ 0,
138
+ finiteOr(session.startLeftWidth, widths[leftId] ?? 0)
139
+ );
140
+ const startRightWidth = Math.max(
141
+ 0,
142
+ finiteOr(session.startRightWidth, widths[rightId] ?? 0)
143
+ );
144
+ const totalWidth = startLeftWidth + startRightWidth;
145
+ if (!Number.isFinite(totalWidth) || totalWidth <= 0) {
146
+ return widths;
147
+ }
148
+ const [leftMin, leftMax] = normalizeBounds(
149
+ session.leftMinWidth,
150
+ session.leftMaxWidth
151
+ );
152
+ const [rightMin, rightMax] = normalizeBounds(
153
+ session.rightMinWidth,
154
+ session.rightMaxWidth
155
+ );
156
+ const feasibleLeftMin = Math.max(
157
+ leftMin,
158
+ Number.isFinite(rightMax) ? totalWidth - rightMax : 0
159
+ );
160
+ const feasibleLeftMax = Math.min(leftMax, totalWidth - rightMin);
161
+ if (feasibleLeftMin > feasibleLeftMax + EPSILON) {
162
+ return widths;
163
+ }
164
+ const delta = clientX - startClientX;
165
+ const requestedLeft = startLeftWidth + delta;
166
+ const nextLeft = clamp2(requestedLeft, feasibleLeftMin, feasibleLeftMax);
167
+ const nextRight = totalWidth - nextLeft;
168
+ if (nextLeft < leftMin - EPSILON || nextLeft > leftMax + EPSILON || nextRight < rightMin - EPSILON || nextRight > rightMax + EPSILON) {
169
+ return widths;
170
+ }
171
+ const currentLeft = widths[leftId];
172
+ const currentRight = widths[rightId];
173
+ if (Number.isFinite(currentLeft) && Number.isFinite(currentRight) && Math.abs(currentLeft - nextLeft) < EPSILON && Math.abs(currentRight - nextRight) < EPSILON) {
174
+ return widths;
175
+ }
176
+ return {
177
+ ...widths,
178
+ [leftId]: nextLeft,
179
+ [rightId]: nextRight
180
+ };
181
+ }
182
+
183
+ // src/react/parametersTable/libs/reorder.ts
184
+ function reorder(list, startIndex, endIndex) {
185
+ if (!Number.isInteger(startIndex) || !Number.isInteger(endIndex) || startIndex < 0 || endIndex < 0 || startIndex >= list.length || endIndex >= list.length || startIndex === endIndex)
186
+ return list;
187
+ const result = [...list];
188
+ const [removed] = result.splice(startIndex, 1);
189
+ result.splice(endIndex, 0, removed);
190
+ return result;
191
+ }
192
+ function createRows(parameters) {
193
+ return parameters.map((parameter) => ({
194
+ id: nanoid(),
195
+ parameter
196
+ }));
197
+ }
198
+ function getDisplayValue(row, document) {
199
+ const resolved = resolveParameterValue(row.parameter, document);
200
+ if (Object.prototype.hasOwnProperty.call(row, "generatedValue")) {
201
+ return { value: row.generatedValue, source: "generated" };
202
+ }
203
+ return resolved;
204
+ }
205
+ function areParametersEqual(a, b) {
206
+ if (Object.is(a, b)) {
207
+ return true;
208
+ }
209
+ try {
210
+ return JSON.stringify(a) === JSON.stringify(b);
211
+ } catch {
212
+ return false;
213
+ }
214
+ }
215
+ function areParameterArraysEqual(a, b) {
216
+ if (a === b) {
217
+ return true;
218
+ }
219
+ if (a.length !== b.length) {
220
+ return false;
221
+ }
222
+ for (let i = 0; i < a.length; i += 1) {
223
+ if (!areParametersEqual(a[i], b[i])) {
224
+ return false;
225
+ }
226
+ }
227
+ return true;
228
+ }
229
+ function reconcileRows(previous, parameters) {
230
+ if (parameters.length === previous.length && parameters.every(
231
+ (parameter, index) => parameter === previous[index].parameter
232
+ ))
233
+ return previous;
234
+ if (parameters.length === 0) {
235
+ return [];
236
+ }
237
+ const previousByKey = /* @__PURE__ */ new Map();
238
+ for (const row of previous) {
239
+ const name = String(row.parameter.name ?? "");
240
+ const location = String(
241
+ row.parameter.in ?? ""
242
+ );
243
+ const key = `${location}\0${name}`;
244
+ const bucket = previousByKey.get(key);
245
+ if (bucket) {
246
+ bucket.push(row);
247
+ } else {
248
+ previousByKey.set(key, [row]);
249
+ }
250
+ }
251
+ const used = /* @__PURE__ */ new Set();
252
+ return parameters.map((parameter) => {
253
+ const name = String(parameter.name ?? "");
254
+ const location = String(
255
+ parameter.in ?? ""
256
+ );
257
+ const key = `${location}\0${name}`;
258
+ const bucket = previousByKey.get(key);
259
+ if (bucket) {
260
+ while (bucket.length > 0) {
261
+ const candidate = bucket.shift();
262
+ if (candidate && !used.has(candidate.id)) {
263
+ used.add(candidate.id);
264
+ return candidate.parameter === parameter ? candidate : { ...candidate, parameter };
265
+ }
266
+ }
267
+ }
268
+ return {
269
+ id: nanoid(),
270
+ parameter
271
+ };
272
+ });
273
+ }
274
+ function ParameterSettings({
275
+ parameter,
276
+ document,
277
+ disabled,
278
+ onChange
279
+ }) {
280
+ const patch = (value) => {
281
+ if (!disabled) onChange({ ...parameter, ...value });
282
+ };
283
+ return /* @__PURE__ */ jsxs(
284
+ Popover.Root,
285
+ {
286
+ lazyMount: true,
287
+ unmountOnExit: true,
288
+ positioning: {
289
+ placement: "bottom-start",
290
+ strategy: "fixed",
291
+ overflowPadding: 12
292
+ },
293
+ children: [
294
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
295
+ Button,
296
+ {
297
+ width: "24px",
298
+ minWidth: "24px",
299
+ height: "24px",
300
+ padding: "0",
301
+ size: "xs",
302
+ variant: "ghost",
303
+ "aria-label": `Configure ${parameter.name}`,
304
+ title: `Configure ${parameter.name}`,
305
+ children: /* @__PURE__ */ jsx(VscSettingsCompact, { size: 16 })
306
+ }
307
+ ) }),
308
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, { children: /* @__PURE__ */ jsx(SettingsPanel, { title: parameter.name || "Parameter", children: /* @__PURE__ */ jsx("div", { className: InlineSchemaEditor_default.root, children: /* @__PURE__ */ jsxs(
309
+ Tabs.Root,
310
+ {
311
+ variant: "plain",
312
+ defaultValue: "schema",
313
+ lazyMount: true,
314
+ unmountOnExit: true,
315
+ children: [
316
+ /* @__PURE__ */ jsxs(Tabs.List, { children: [
317
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "schema", children: "Schema" }),
318
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "parameter", children: "Parameter" })
319
+ ] }),
320
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "parameter", pt: "2", children: /* @__PURE__ */ jsxs(Stack, { gap: "2", children: [
321
+ /* @__PURE__ */ jsxs(Field.Root, { children: [
322
+ /* @__PURE__ */ jsx(Field.Label, { children: "Location" }),
323
+ /* @__PURE__ */ jsx(NativeSelect.Root, { disabled, children: /* @__PURE__ */ jsx(
324
+ NativeSelect.Field,
325
+ {
326
+ value: parameter.in,
327
+ onChange: (event) => {
328
+ const location = event.target.value;
329
+ patch({
330
+ in: location,
331
+ required: location === "path" ? true : parameter.required
332
+ });
333
+ },
334
+ children: [
335
+ "query",
336
+ "header",
337
+ "path",
338
+ "cookie",
339
+ "querystring"
340
+ ].map((value) => /* @__PURE__ */ jsx("option", { children: value }, value))
341
+ }
342
+ ) })
343
+ ] }),
344
+ /* @__PURE__ */ jsxs(
345
+ Switch.Root,
346
+ {
347
+ checked: parameter.in === "path" || !!parameter.required,
348
+ disabled: disabled || parameter.in === "path",
349
+ onCheckedChange: (event) => patch({ required: event.checked }),
350
+ children: [
351
+ /* @__PURE__ */ jsx(Switch.HiddenInput, {}),
352
+ /* @__PURE__ */ jsx(Switch.Control, {}),
353
+ /* @__PURE__ */ jsx(Switch.Label, { children: "Required" })
354
+ ]
355
+ }
356
+ ),
357
+ /* @__PURE__ */ jsxs(Field.Root, { children: [
358
+ /* @__PURE__ */ jsx(Field.Label, { children: "Description" }),
359
+ /* @__PURE__ */ jsx(
360
+ Input,
361
+ {
362
+ value: parameter.description ?? "",
363
+ disabled,
364
+ onChange: (event) => patch({ description: event.target.value })
365
+ }
366
+ )
367
+ ] }),
368
+ /* @__PURE__ */ jsxs("details", { className: InlineSchemaEditor_default.reference, children: [
369
+ /* @__PURE__ */ jsx("summary", { children: "Serialization" }),
370
+ /* @__PURE__ */ jsxs(Stack, { gap: "2", pt: "2", children: [
371
+ /* @__PURE__ */ jsxs(Field.Root, { children: [
372
+ /* @__PURE__ */ jsx(Field.Label, { children: "Serialization style" }),
373
+ /* @__PURE__ */ jsx(
374
+ Input,
375
+ {
376
+ value: parameter.style ?? "",
377
+ disabled,
378
+ placeholder: "Default for location",
379
+ onChange: (event) => patch({ style: event.target.value || void 0 })
380
+ }
381
+ )
382
+ ] }),
383
+ /* @__PURE__ */ jsxs(
384
+ Switch.Root,
385
+ {
386
+ checked: !!parameter.explode,
387
+ disabled,
388
+ onCheckedChange: (event) => patch({ explode: event.checked }),
389
+ children: [
390
+ /* @__PURE__ */ jsx(Switch.HiddenInput, {}),
391
+ /* @__PURE__ */ jsx(Switch.Control, {}),
392
+ /* @__PURE__ */ jsx(Switch.Label, { children: "Explode" })
393
+ ]
394
+ }
395
+ ),
396
+ /* @__PURE__ */ jsxs(
397
+ Switch.Root,
398
+ {
399
+ checked: !!parameter.allowReserved,
400
+ disabled,
401
+ onCheckedChange: (event) => patch({ allowReserved: event.checked }),
402
+ children: [
403
+ /* @__PURE__ */ jsx(Switch.HiddenInput, {}),
404
+ /* @__PURE__ */ jsx(Switch.Control, {}),
405
+ /* @__PURE__ */ jsx(Switch.Label, { children: "Allow reserved characters" })
406
+ ]
407
+ }
408
+ )
409
+ ] })
410
+ ] })
411
+ ] }) }),
412
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "schema", pt: "2", children: parameter.content ? /* @__PURE__ */ jsx("p", { children: "This parameter uses content. Its media type schema is preserved." }) : /* @__PURE__ */ jsx(
413
+ InlineSchemaEditor,
414
+ {
415
+ schema: parameter.schema ?? {},
416
+ fullSchema: document,
417
+ nested: true,
418
+ disabled,
419
+ onChange: (value) => patch({ schema: value })
420
+ }
421
+ ) })
422
+ ]
423
+ }
424
+ ) }) }) }) })
425
+ ]
426
+ }
427
+ );
428
+ }
429
+
430
+ // src/react/parametersTable/ParametersTable.module.css
431
+ var ParametersTable_default = {
432
+ root: "ParametersTable_root",
433
+ tableViewport: "ParametersTable_tableViewport",
434
+ tableContainer: "ParametersTable_tableContainer",
435
+ table: "ParametersTable_table",
436
+ colCheckbox: "ParametersTable_colCheckbox",
437
+ colData: "ParametersTable_colData",
438
+ headerCell: "ParametersTable_headerCell",
439
+ checkboxCell: "ParametersTable_checkboxCell",
440
+ headerContent: "ParametersTable_headerContent",
441
+ headerLabel: "ParametersTable_headerLabel",
442
+ resizeHandle: "ParametersTable_resizeHandle",
443
+ variableTextEditor: "ParametersTable_variableTextEditor",
444
+ row: "ParametersTable_row",
445
+ cell: "ParametersTable_cell",
446
+ nameCell: "ParametersTable_nameCell",
447
+ checkboxCellGroup: "ParametersTable_checkboxCellGroup",
448
+ checkboxRoot: "ParametersTable_checkboxRoot",
449
+ dragHandleWrap: "ParametersTable_dragHandleWrap",
450
+ dragHandle: "ParametersTable_dragHandle",
451
+ description: "ParametersTable_description",
452
+ required: "ParametersTable_required",
453
+ optional: "ParametersTable_optional",
454
+ empty: "ParametersTable_empty",
455
+ actionBarContent: "ParametersTable_actionBarContent",
456
+ actionBarLeft: "ParametersTable_actionBarLeft",
457
+ actionBarTrigger: "ParametersTable_actionBarTrigger",
458
+ actionBarDivider: "ParametersTable_actionBarDivider",
459
+ actionButton: "ParametersTable_actionButton",
460
+ actionButtonAccent: "ParametersTable_actionButtonAccent",
461
+ actionIcon: "ParametersTable_actionIcon"
462
+ };
463
+ var EMPTY_VARIABLES = Object.freeze([]);
464
+ var CHECKBOX_COLUMN_WIDTH = 48;
465
+ var RowDragHandle = memo(function RowDragHandle2() {
466
+ return /* @__PURE__ */ jsx(
467
+ Box,
468
+ {
469
+ className: ParametersTable_default.dragHandle,
470
+ "aria-label": "Drag to reorder",
471
+ role: "button",
472
+ children: /* @__PURE__ */ jsx(LuGripVertical, { size: 14 })
473
+ }
474
+ );
475
+ });
476
+ var ParameterTable = memo(function ParameterTable2(props) {
477
+ const {
478
+ parameters,
479
+ onChange,
480
+ onSelectionChange,
481
+ onRowReorder,
482
+ generateValue,
483
+ faker,
484
+ emptyState,
485
+ showRequired = false,
486
+ showType = false,
487
+ showDescription = false,
488
+ stickyHeader = true,
489
+ height = "100%",
490
+ className
491
+ } = props;
492
+ const readOnly = props.readOnly === true;
493
+ const requestMode = props.mode === "request";
494
+ const [generationError, setGenerationError] = useState(null);
495
+ const generationRef = useRef(null);
496
+ const rowsRef = useRef([]);
497
+ useEffect(() => () => generationRef.current?.abort(), []);
498
+ const [rows, setRows] = useState(
499
+ () => createRows(parameters)
500
+ );
501
+ rowsRef.current = rows;
502
+ const hasRows = rows.length > 0;
503
+ useEffect(() => {
504
+ generationRef.current?.abort();
505
+ }, [readOnly, requestMode, props.document]);
506
+ const [selectedIds, setSelectedIds] = useState(() => /* @__PURE__ */ new Set());
507
+ const lastEmittedParametersRef = useRef(
508
+ null
509
+ );
510
+ const visibleColumns = useMemo(
511
+ () => getVisibleColumns({
512
+ showRequired,
513
+ showType,
514
+ showDescription
515
+ }),
516
+ [showRequired, showType, showDescription]
517
+ );
518
+ const columnDefsById = useMemo(
519
+ () => buildColumnDefsById(DEFAULT_COLUMNS),
520
+ []
521
+ );
522
+ const [columnWidths, setColumnWidths] = useState(
523
+ () => {
524
+ const initial = {};
525
+ for (const column of DEFAULT_COLUMNS) {
526
+ initial[column.id] = column.defaultWidth;
527
+ }
528
+ return initial;
529
+ }
530
+ );
531
+ const widthsByLayoutRef = useRef(/* @__PURE__ */ new Map());
532
+ const activeLayoutRef = useRef(null);
533
+ const currentWidthsRef = useRef(columnWidths);
534
+ currentWidthsRef.current = columnWidths;
535
+ const viewportRef = useRef(null);
536
+ const tableRef = useRef(null);
537
+ const resizeHandleRefs = useRef(/* @__PURE__ */ new Map());
538
+ useEffect(() => {
539
+ const lastEmitted = lastEmittedParametersRef.current;
540
+ if (lastEmitted && areParameterArraysEqual(parameters, lastEmitted)) {
541
+ lastEmittedParametersRef.current = null;
542
+ return;
543
+ }
544
+ setRows((previous) => reconcileRows(previous, parameters));
545
+ setSelectedIds(/* @__PURE__ */ new Set());
546
+ }, [parameters]);
547
+ useEffect(() => {
548
+ onSelectionChange?.([...selectedIds]);
549
+ }, [onSelectionChange, selectedIds]);
550
+ useLayoutEffect(() => {
551
+ const viewport = viewportRef.current;
552
+ if (!viewport) return;
553
+ const layoutKey = visibleColumns.map((column) => column.id).join(",");
554
+ if (activeLayoutRef.current !== null) {
555
+ widthsByLayoutRef.current.set(
556
+ activeLayoutRef.current,
557
+ currentWidthsRef.current
558
+ );
559
+ }
560
+ activeLayoutRef.current = layoutKey;
561
+ const restored = widthsByLayoutRef.current.get(layoutKey) ?? Object.fromEntries(
562
+ DEFAULT_COLUMNS.map((column) => [column.id, column.defaultWidth])
563
+ );
564
+ let firstMeasurement = true;
565
+ let lastWidth = -1;
566
+ let disposed = false;
567
+ const synchronize = () => {
568
+ if (disposed) return;
569
+ const width = viewport.clientWidth;
570
+ if (!Number.isFinite(width) || width <= 0 || width === lastWidth) return;
571
+ lastWidth = width;
572
+ const baseline = firstMeasurement ? restored : void 0;
573
+ firstMeasurement = false;
574
+ setColumnWidths(
575
+ (previous) => fitColumnWidths(
576
+ baseline ?? previous,
577
+ visibleColumns,
578
+ width - CHECKBOX_COLUMN_WIDTH
579
+ )
580
+ );
581
+ };
582
+ synchronize();
583
+ if (typeof ResizeObserver === "undefined") {
584
+ window.addEventListener("resize", synchronize);
585
+ return () => {
586
+ disposed = true;
587
+ window.removeEventListener("resize", synchronize);
588
+ };
589
+ }
590
+ const observer = new ResizeObserver(synchronize);
591
+ observer.observe(viewport);
592
+ return () => {
593
+ disposed = true;
594
+ observer.disconnect();
595
+ };
596
+ }, [visibleColumns, hasRows]);
597
+ const [localValues, setLocalValues] = useState({});
598
+ const effectiveValues = props.values ?? localValues;
599
+ const controlledValuesRef = useRef(props.values !== void 0);
600
+ controlledValuesRef.current = props.values !== void 0;
601
+ const valuesRef = useRef(effectiveValues);
602
+ valuesRef.current = effectiveValues;
603
+ const onValuesChangeRef = useRef(props.onValuesChange);
604
+ onValuesChangeRef.current = props.onValuesChange;
605
+ const writeValues = (nextRows, changedIds) => {
606
+ const next = { ...valuesRef.current };
607
+ for (const row of nextRows) {
608
+ if (!changedIds.has(row.id)) continue;
609
+ if (Object.prototype.hasOwnProperty.call(row, "generatedValue")) {
610
+ const key = parameterKey(row.parameter);
611
+ next[key] = {
612
+ enabled: next[key]?.enabled ?? true,
613
+ value: row.generatedValue
614
+ };
615
+ }
616
+ }
617
+ if (!controlledValuesRef.current) valuesRef.current = next;
618
+ setLocalValues(next);
619
+ onValuesChangeRef.current?.(next);
620
+ };
621
+ const editValue = (rowId, value) => {
622
+ if (readOnly) return;
623
+ const next = rowsRef.current.map(
624
+ (row) => row.id === rowId ? { ...row, generatedValue: value } : row
625
+ );
626
+ rowsRef.current = next;
627
+ setRows(next);
628
+ writeValues(next, /* @__PURE__ */ new Set([rowId]));
629
+ };
630
+ const allSelected = rows.length > 0 && rows.every((row) => selectedIds.has(row.id));
631
+ const someSelected = rows.some((row) => selectedIds.has(row.id)) && !allSelected;
632
+ const handleSelectAll = useCallback(
633
+ (checked) => {
634
+ if (!checked) {
635
+ setSelectedIds(/* @__PURE__ */ new Set());
636
+ return;
637
+ }
638
+ setSelectedIds(new Set(rows.map((row) => row.id)));
639
+ },
640
+ [rows]
641
+ );
642
+ const handleSelectRow = useCallback((rowId, checked) => {
643
+ setSelectedIds((previous) => {
644
+ const next = new Set(previous);
645
+ if (checked) {
646
+ next.add(rowId);
647
+ } else {
648
+ next.delete(rowId);
649
+ }
650
+ return next;
651
+ });
652
+ }, []);
653
+ const commitRows = useCallback(
654
+ (nextRows) => {
655
+ if (readOnly || requestMode) return;
656
+ rowsRef.current = nextRows;
657
+ setRows(nextRows);
658
+ const nextParameters = nextRows.map((row) => row.parameter);
659
+ lastEmittedParametersRef.current = nextParameters;
660
+ onChange?.(nextParameters);
661
+ },
662
+ [onChange, readOnly, requestMode]
663
+ );
664
+ const commitReorder = useCallback(
665
+ (nextRows) => {
666
+ if (readOnly || requestMode) return;
667
+ rowsRef.current = nextRows;
668
+ setRows(nextRows);
669
+ const nextParameters = nextRows.map((row) => row.parameter);
670
+ lastEmittedParametersRef.current = nextParameters;
671
+ onChange?.(nextParameters);
672
+ onRowReorder?.(nextParameters);
673
+ },
674
+ [onChange, onRowReorder, readOnly, requestMode]
675
+ );
676
+ const typeOptions = useMemo(
677
+ () => createListCollection({
678
+ items: [
679
+ {
680
+ label: "string",
681
+ value: "string"
682
+ },
683
+ {
684
+ label: "integer",
685
+ value: "integer"
686
+ },
687
+ ...["number", "boolean", "array", "object", "null"].map((value) => ({
688
+ label: value,
689
+ value
690
+ }))
691
+ ]
692
+ }),
693
+ []
694
+ );
695
+ const handleGenerate = useCallback(async () => {
696
+ if (readOnly) return;
697
+ setGenerationError(null);
698
+ generationRef.current?.abort();
699
+ const controller = new AbortController();
700
+ generationRef.current = controller;
701
+ const snapshot = rowsRef.current;
702
+ const valuesSnapshot = valuesRef.current;
703
+ const generated = /* @__PURE__ */ new Map();
704
+ await Promise.all(
705
+ snapshot.map(async (row, rowIndex) => {
706
+ if (!selectedIds.has(row.id) || !controlledValuesRef.current && Object.prototype.hasOwnProperty.call(row, "generatedValue"))
707
+ return;
708
+ const key = parameterKey(row.parameter);
709
+ if (valuesSnapshot?.[key] || resolveParameterValue(row.parameter, props.document).source !== "missing")
710
+ return;
711
+ try {
712
+ const context = {
713
+ parameter: row.parameter,
714
+ rowIndex,
715
+ signal: controller.signal,
716
+ document: props.document
717
+ };
718
+ const value = generateValue ? await generateValue(context) : faker ? await faker.generate(context) : await import('./react/parametersTable/libs/generateValue.js').then(
719
+ (module) => module.generateParameterValue(context)
720
+ );
721
+ generated.set(row.id, { ...row, generatedValue: value });
722
+ } catch (error) {
723
+ if (!controller.signal.aborted) {
724
+ setGenerationError(
725
+ error instanceof Error ? error.message : "Value generation failed."
726
+ );
727
+ try {
728
+ props.onError?.(error);
729
+ } catch {
730
+ }
731
+ }
732
+ }
733
+ })
734
+ );
735
+ if (controller.signal.aborted) return;
736
+ const originals = new Map(snapshot.map((row) => [row.id, row]));
737
+ const next = rowsRef.current.map((row) => {
738
+ const key = parameterKey(row.parameter);
739
+ return row === originals.get(row.id) && valuesRef.current?.[key] === valuesSnapshot?.[key] ? generated.get(row.id) ?? row : row;
740
+ });
741
+ const changedIds = new Set(
742
+ next.filter((row, index) => row !== rowsRef.current[index]).map((row) => row.id)
743
+ );
744
+ if (!changedIds.size) return;
745
+ rowsRef.current = next;
746
+ setRows(next);
747
+ writeValues(next, changedIds);
748
+ }, [
749
+ faker,
750
+ generateValue,
751
+ selectedIds,
752
+ readOnly,
753
+ props.onError,
754
+ props.document
755
+ ]);
756
+ const onDragEnd = useCallback(
757
+ (result) => {
758
+ const { destination, source } = result;
759
+ if (!destination) {
760
+ return;
761
+ }
762
+ if (destination.droppableId !== source.droppableId) {
763
+ return;
764
+ }
765
+ if (destination.index === source.index) {
766
+ return;
767
+ }
768
+ const next = reorder(rows, source.index, destination.index);
769
+ commitReorder(next);
770
+ },
771
+ [commitReorder, rows]
772
+ );
773
+ const resizeSessionRef = useRef(null);
774
+ const resizeRafRef = useRef(null);
775
+ const pendingResizeSnapshotRef = useRef(null);
776
+ const resizingColumnRef = useRef(null);
777
+ const getActualColumnWidth = useCallback(
778
+ (columnId) => {
779
+ const header = tableRef.current?.querySelector(
780
+ `th[data-column="${columnId}"]`
781
+ );
782
+ if (!header) {
783
+ return null;
784
+ }
785
+ const width = header.getBoundingClientRect().width;
786
+ if (!Number.isFinite(width) || width <= 0) {
787
+ return null;
788
+ }
789
+ return width;
790
+ },
791
+ []
792
+ );
793
+ const cleanupResize = useCallback(() => {
794
+ resizingColumnRef.current = null;
795
+ pendingResizeSnapshotRef.current = null;
796
+ resizeSessionRef.current = null;
797
+ if (resizeRafRef.current !== null) {
798
+ window.cancelAnimationFrame(resizeRafRef.current);
799
+ resizeRafRef.current = null;
800
+ }
801
+ const handles = resizeHandleRefs.current;
802
+ for (const handle of handles.values()) {
803
+ handle.removeAttribute("data-resizing");
804
+ }
805
+ }, []);
806
+ const onResizeMoveWindow = useCallback((event) => {
807
+ const session = resizeSessionRef.current;
808
+ if (!session) {
809
+ return;
810
+ }
811
+ if (session.pointerId !== event.pointerId) {
812
+ return;
813
+ }
814
+ pendingResizeSnapshotRef.current = {
815
+ clientX: event.clientX,
816
+ pointerId: event.pointerId
817
+ };
818
+ if (resizeRafRef.current !== null) {
819
+ return;
820
+ }
821
+ resizeRafRef.current = window.requestAnimationFrame(() => {
822
+ resizeRafRef.current = null;
823
+ const activeSession = resizeSessionRef.current;
824
+ const snapshot = pendingResizeSnapshotRef.current;
825
+ if (!activeSession || !snapshot) {
826
+ return;
827
+ }
828
+ if (snapshot.pointerId !== activeSession.pointerId) {
829
+ return;
830
+ }
831
+ const clientX = snapshot.clientX;
832
+ setColumnWidths(
833
+ (previous) => applyAdjacentSplitterResize({
834
+ session: activeSession,
835
+ clientX,
836
+ widths: previous
837
+ })
838
+ );
839
+ });
840
+ }, []);
841
+ const onResizeEndWindow = useCallback(
842
+ (event) => {
843
+ const session = resizeSessionRef.current;
844
+ if (!session) {
845
+ return;
846
+ }
847
+ if (session.pointerId !== event.pointerId) {
848
+ return;
849
+ }
850
+ if (event.type === "pointerup")
851
+ setColumnWidths(
852
+ (widths) => applyAdjacentSplitterResize({
853
+ session,
854
+ clientX: event.clientX,
855
+ widths
856
+ })
857
+ );
858
+ cleanupResize();
859
+ window.removeEventListener("pointermove", onResizeMoveWindow);
860
+ window.removeEventListener("pointerup", onResizeEndWindow);
861
+ window.removeEventListener("pointercancel", onResizeEndWindow);
862
+ },
863
+ [cleanupResize, onResizeMoveWindow]
864
+ );
865
+ useEffect(() => {
866
+ return () => {
867
+ cleanupResize();
868
+ window.removeEventListener("pointermove", onResizeMoveWindow);
869
+ window.removeEventListener("pointerup", onResizeEndWindow);
870
+ window.removeEventListener("pointercancel", onResizeEndWindow);
871
+ };
872
+ }, [cleanupResize, onResizeEndWindow, onResizeMoveWindow]);
873
+ const onResizeStart = useCallback(
874
+ (event, leftColumn) => {
875
+ if (event.pointerType === "mouse" && event.button !== 0) {
876
+ return;
877
+ }
878
+ event.preventDefault();
879
+ event.stopPropagation();
880
+ const rightId = getRightNeighborId(visibleColumns, leftColumn.id);
881
+ if (!rightId) {
882
+ return;
883
+ }
884
+ const leftDefinition = columnDefsById[leftColumn.id];
885
+ const rightDefinition = columnDefsById[rightId];
886
+ if (!leftDefinition || !rightDefinition) {
887
+ return;
888
+ }
889
+ const actualLeftWidth = getActualColumnWidth(leftColumn.id);
890
+ const actualRightWidth = getActualColumnWidth(rightId);
891
+ if (actualLeftWidth === null || actualRightWidth === null) {
892
+ return;
893
+ }
894
+ if (actualLeftWidth < leftDefinition.minWidth || actualRightWidth < rightDefinition.minWidth) {
895
+ return;
896
+ }
897
+ const session = {
898
+ leftId: leftColumn.id,
899
+ rightId,
900
+ pointerId: event.pointerId,
901
+ startClientX: event.clientX,
902
+ startLeftWidth: actualLeftWidth,
903
+ startRightWidth: actualRightWidth,
904
+ leftMinWidth: leftDefinition.minWidth,
905
+ leftMaxWidth: leftDefinition.maxWidth ?? Number.POSITIVE_INFINITY,
906
+ rightMinWidth: rightDefinition.minWidth,
907
+ rightMaxWidth: rightDefinition.maxWidth ?? Number.POSITIVE_INFINITY
908
+ };
909
+ resizeSessionRef.current = session;
910
+ pendingResizeSnapshotRef.current = {
911
+ clientX: event.clientX,
912
+ pointerId: event.pointerId
913
+ };
914
+ resizingColumnRef.current = leftColumn.id;
915
+ const leftHandle = resizeHandleRefs.current.get(leftColumn.id);
916
+ leftHandle?.setAttribute("data-resizing", "true");
917
+ window.addEventListener("pointermove", onResizeMoveWindow, {
918
+ passive: true
919
+ });
920
+ window.addEventListener("pointerup", onResizeEndWindow, {
921
+ passive: true
922
+ });
923
+ window.addEventListener("pointercancel", onResizeEndWindow, {
924
+ passive: true
925
+ });
926
+ },
927
+ [
928
+ columnDefsById,
929
+ getActualColumnWidth,
930
+ onResizeEndWindow,
931
+ onResizeMoveWindow,
932
+ visibleColumns
933
+ ]
934
+ );
935
+ const handleInputChange = useCallback(
936
+ (rowId, updater) => {
937
+ const currentRows = rowsRef.current;
938
+ const nextRows = currentRows.map(
939
+ (row) => row.id === rowId ? {
940
+ ...row,
941
+ parameter: updater(row.parameter)
942
+ } : row
943
+ );
944
+ commitRows(nextRows);
945
+ },
946
+ [commitRows, rows]
947
+ );
948
+ const handleDeleteSelected = useCallback(() => {
949
+ if (selectedIds.size === 0) {
950
+ return;
951
+ }
952
+ const nextRows = rows.filter((row) => !selectedIds.has(row.id));
953
+ setSelectedIds(/* @__PURE__ */ new Set());
954
+ commitRows(nextRows);
955
+ }, [commitRows, rows, selectedIds]);
956
+ const setResizeHandleRef = useCallback(
957
+ (columnId, node) => {
958
+ if (node) {
959
+ resizeHandleRefs.current.set(columnId, node);
960
+ } else {
961
+ resizeHandleRefs.current.delete(columnId);
962
+ }
963
+ },
964
+ []
965
+ );
966
+ if (rows.length === 0) {
967
+ return /* @__PURE__ */ jsxs(
968
+ Box,
969
+ {
970
+ className: `${ParametersTable_default.root} ${className ?? ""}`,
971
+ "data-sticky-header": stickyHeader,
972
+ style: { height },
973
+ children: [
974
+ generationError && /* @__PURE__ */ jsx(Text, { role: "alert", fontSize: "sm", p: "2", color: "var(--color-danger)", children: generationError }),
975
+ /* @__PURE__ */ jsx(Box, { className: ParametersTable_default.toolbar, children: /* @__PURE__ */ jsx(Box, { className: ParametersTable_default.toolbarLeft, children: /* @__PURE__ */ jsx(Text, { className: ParametersTable_default.toolbarTitle, children: "Parameters" }) }) }),
976
+ /* @__PURE__ */ jsx(Box, { className: ParametersTable_default.empty, children: emptyState ?? /* @__PURE__ */ jsx(Text, { children: "No parameters defined." }) })
977
+ ]
978
+ }
979
+ );
980
+ }
981
+ return /* @__PURE__ */ jsxs(
982
+ Box,
983
+ {
984
+ className: `${ParametersTable_default.root} ${className ?? ""}`,
985
+ "data-sticky-header": stickyHeader,
986
+ style: { height },
987
+ children: [
988
+ generationError && /* @__PURE__ */ jsx(Text, { role: "alert", fontSize: "sm", p: "2", color: "var(--color-danger)", children: generationError }),
989
+ /* @__PURE__ */ jsxs(Box, { ref: viewportRef, className: ParametersTable_default.tableViewport, children: [
990
+ /* @__PURE__ */ jsx(DragDropContext, { onDragEnd, children: /* @__PURE__ */ jsx(Droppable, { droppableId: "parameters", direction: "vertical", children: (provided) => /* @__PURE__ */ jsx(
991
+ Box,
992
+ {
993
+ ref: provided.innerRef,
994
+ ...provided.droppableProps,
995
+ className: ParametersTable_default.tableContainer,
996
+ children: /* @__PURE__ */ jsxs(
997
+ Table.Root,
998
+ {
999
+ ref: tableRef,
1000
+ className: ParametersTable_default.table,
1001
+ stickyHeader: stickyHeader ? true : void 0,
1002
+ interactive: true,
1003
+ size: "sm",
1004
+ children: [
1005
+ /* @__PURE__ */ jsxs("colgroup", { children: [
1006
+ /* @__PURE__ */ jsx("col", { className: ParametersTable_default.colCheckbox }),
1007
+ visibleColumns.map((column) => /* @__PURE__ */ jsx(
1008
+ "col",
1009
+ {
1010
+ className: ParametersTable_default.colData,
1011
+ style: {
1012
+ width: columnWidths[column.id]
1013
+ }
1014
+ },
1015
+ column.id
1016
+ ))
1017
+ ] }),
1018
+ /* @__PURE__ */ jsx(Table.Header, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
1019
+ /* @__PURE__ */ jsx(
1020
+ Table.ColumnHeader,
1021
+ {
1022
+ className: `${ParametersTable_default.headerCell} ${ParametersTable_default.checkboxCell}`,
1023
+ children: /* @__PURE__ */ jsx(Flex, { className: ParametersTable_default.checkboxCellGroup, children: /* @__PURE__ */ jsxs(
1024
+ Checkbox.Root,
1025
+ {
1026
+ checked: allSelected ? true : someSelected ? "indeterminate" : false,
1027
+ onCheckedChange: (details) => handleSelectAll(details.checked === true),
1028
+ size: "sm",
1029
+ "aria-label": "Select all parameters",
1030
+ className: ParametersTable_default.checkboxRoot,
1031
+ children: [
1032
+ /* @__PURE__ */ jsx(Checkbox.HiddenInput, {}),
1033
+ /* @__PURE__ */ jsx(Checkbox.Control, {})
1034
+ ]
1035
+ }
1036
+ ) })
1037
+ }
1038
+ ),
1039
+ visibleColumns.map((column) => /* @__PURE__ */ jsx(
1040
+ Table.ColumnHeader,
1041
+ {
1042
+ "data-column": column.id,
1043
+ "data-sticky": column.id === "name" ? "end" : void 0,
1044
+ className: ParametersTable_default.headerCell,
1045
+ children: /* @__PURE__ */ jsxs(Box, { className: ParametersTable_default.headerContent, children: [
1046
+ /* @__PURE__ */ jsx(Span, { className: ParametersTable_default.headerLabel, children: column.label }),
1047
+ getRightNeighborId(visibleColumns, column.id) && /* @__PURE__ */ jsx(
1048
+ Span,
1049
+ {
1050
+ tabIndex: 0,
1051
+ "aria-valuenow": Math.round(
1052
+ columnWidths[column.id]
1053
+ ),
1054
+ "aria-valuemin": column.minWidth,
1055
+ onKeyDown: (event) => {
1056
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
1057
+ return;
1058
+ event.preventDefault();
1059
+ const rightId = getRightNeighborId(
1060
+ visibleColumns,
1061
+ column.id
1062
+ );
1063
+ if (!rightId) return;
1064
+ const right = columnDefsById[rightId];
1065
+ setColumnWidths(
1066
+ (widths) => applyAdjacentSplitterResize({
1067
+ widths,
1068
+ clientX: (event.key === "ArrowRight" ? 1 : -1) * (event.shiftKey ? 32 : 8),
1069
+ session: {
1070
+ leftId: column.id,
1071
+ rightId,
1072
+ startClientX: 0,
1073
+ startLeftWidth: widths[column.id],
1074
+ startRightWidth: widths[rightId],
1075
+ leftMinWidth: column.minWidth,
1076
+ leftMaxWidth: column.maxWidth ?? Infinity,
1077
+ rightMinWidth: right.minWidth,
1078
+ rightMaxWidth: right.maxWidth ?? Infinity
1079
+ }
1080
+ })
1081
+ );
1082
+ },
1083
+ ref: (node) => setResizeHandleRef(column.id, node),
1084
+ className: ParametersTable_default.resizeHandle,
1085
+ role: "separator",
1086
+ "aria-orientation": "vertical",
1087
+ "aria-label": `Resize ${column.label} column`,
1088
+ onPointerDown: (event) => onResizeStart(event, column)
1089
+ }
1090
+ )
1091
+ ] })
1092
+ },
1093
+ column.id
1094
+ ))
1095
+ ] }) }),
1096
+ /* @__PURE__ */ jsxs(Table.Body, { children: [
1097
+ rows.map((row, index) => {
1098
+ const parameter = row.parameter;
1099
+ const displayValue = props.values !== void 0 ? resolveParameterValue(parameter, props.document) : getDisplayValue(row, props.document);
1100
+ const type = resolveParameterType(
1101
+ parameter,
1102
+ props.document
1103
+ );
1104
+ const selected = selectedIds.has(row.id);
1105
+ return /* @__PURE__ */ jsx(
1106
+ Draggable,
1107
+ {
1108
+ draggableId: row.id,
1109
+ index,
1110
+ isDragDisabled: readOnly || requestMode,
1111
+ children: (dragProvided, snapshot) => /* @__PURE__ */ jsxs(
1112
+ Table.Row,
1113
+ {
1114
+ ref: dragProvided.innerRef,
1115
+ className: ParametersTable_default.row,
1116
+ "data-selected": selected,
1117
+ "data-dragging": snapshot.isDragging ? "true" : "false",
1118
+ ...dragProvided.draggableProps,
1119
+ children: [
1120
+ /* @__PURE__ */ jsx(
1121
+ Table.Cell,
1122
+ {
1123
+ className: `${ParametersTable_default.cell} ${ParametersTable_default.checkboxCell}`,
1124
+ children: /* @__PURE__ */ jsxs(Flex, { className: ParametersTable_default.checkboxCellGroup, children: [
1125
+ /* @__PURE__ */ jsx(
1126
+ Box,
1127
+ {
1128
+ ...dragProvided.dragHandleProps,
1129
+ className: ParametersTable_default.dragHandleWrap,
1130
+ display: readOnly || requestMode ? "none" : void 0,
1131
+ "aria-label": `Drag ${parameter.name ?? ""}`,
1132
+ children: /* @__PURE__ */ jsx(RowDragHandle, {})
1133
+ }
1134
+ ),
1135
+ /* @__PURE__ */ jsxs(
1136
+ Checkbox.Root,
1137
+ {
1138
+ size: "sm",
1139
+ checked: selected,
1140
+ onCheckedChange: (details) => handleSelectRow(
1141
+ row.id,
1142
+ details.checked === true
1143
+ ),
1144
+ "aria-label": `Select ${parameter.name ?? "parameter"}`,
1145
+ className: ParametersTable_default.checkboxRoot,
1146
+ children: [
1147
+ /* @__PURE__ */ jsx(Checkbox.HiddenInput, {}),
1148
+ /* @__PURE__ */ jsx(Checkbox.Control, {})
1149
+ ]
1150
+ }
1151
+ )
1152
+ ] })
1153
+ }
1154
+ ),
1155
+ visibleColumns.map((column) => {
1156
+ switch (column.id) {
1157
+ case "name":
1158
+ return /* @__PURE__ */ jsx(
1159
+ Table.Cell,
1160
+ {
1161
+ className: `${ParametersTable_default.cell} ${ParametersTable_default.nameCell}`,
1162
+ children: /* @__PURE__ */ jsxs(
1163
+ Box,
1164
+ {
1165
+ className: ParametersTable_default.variableTextEditor,
1166
+ children: [
1167
+ /* @__PURE__ */ jsx(
1168
+ VariableTextEditor,
1169
+ {
1170
+ autoFocus: false,
1171
+ ariaLabel: `Name for ${parameter.name}`,
1172
+ readOnly: readOnly || requestMode,
1173
+ value: String(parameter.name ?? ""),
1174
+ onSubmit: () => {
1175
+ },
1176
+ placeholder: "Name",
1177
+ variables: EMPTY_VARIABLES,
1178
+ allowLineBreaks: false,
1179
+ submitOnEnter: true,
1180
+ expansionMode: "overlay",
1181
+ minHeight: 28,
1182
+ safePadding: 4,
1183
+ maxFocusedHeight: 360,
1184
+ onChange: (name) => {
1185
+ handleInputChange(
1186
+ row.id,
1187
+ (p) => ({
1188
+ ...p,
1189
+ name
1190
+ })
1191
+ );
1192
+ }
1193
+ }
1194
+ ),
1195
+ /* @__PURE__ */ jsx(
1196
+ ParameterSettings,
1197
+ {
1198
+ parameter,
1199
+ document: props.document,
1200
+ disabled: readOnly || requestMode,
1201
+ onChange: (next) => handleInputChange(
1202
+ row.id,
1203
+ () => next
1204
+ )
1205
+ }
1206
+ )
1207
+ ]
1208
+ }
1209
+ )
1210
+ },
1211
+ column.id
1212
+ );
1213
+ case "value":
1214
+ return /* @__PURE__ */ jsx(
1215
+ Table.Cell,
1216
+ {
1217
+ className: ParametersTable_default.cell,
1218
+ children: /* @__PURE__ */ jsxs(
1219
+ Box,
1220
+ {
1221
+ className: ParametersTable_default.variableTextEditor,
1222
+ children: [
1223
+ requestMode && /* @__PURE__ */ jsxs(
1224
+ Checkbox.Root,
1225
+ {
1226
+ className: ParametersTable_default.checkboxRoot,
1227
+ size: "sm",
1228
+ disabled: readOnly || parameter.in === "path",
1229
+ checked: parameter.in === "path" || (effectiveValues[parameterKey(parameter)]?.enabled ?? true),
1230
+ "aria-label": `Include ${parameter.name}`,
1231
+ onCheckedChange: (event) => {
1232
+ const key = parameterKey(parameter);
1233
+ const next = {
1234
+ ...valuesRef.current,
1235
+ [key]: {
1236
+ value: valuesRef.current?.[key] ? valuesRef.current[key].value : displayValue.value,
1237
+ enabled: event.checked === true
1238
+ }
1239
+ };
1240
+ setLocalValues(next);
1241
+ onValuesChangeRef.current?.(
1242
+ next
1243
+ );
1244
+ },
1245
+ children: [
1246
+ /* @__PURE__ */ jsx(Checkbox.HiddenInput, {}),
1247
+ /* @__PURE__ */ jsx(Checkbox.Control, { children: /* @__PURE__ */ jsx(Checkbox.Indicator, {}) })
1248
+ ]
1249
+ }
1250
+ ),
1251
+ /* @__PURE__ */ jsx(
1252
+ VariableTextEditor,
1253
+ {
1254
+ autoFocus: false,
1255
+ ariaLabel: `Value for ${parameter.name}`,
1256
+ readOnly,
1257
+ value: parameterValueText(
1258
+ Object.hasOwn(
1259
+ effectiveValues,
1260
+ parameterKey(parameter)
1261
+ ) ? effectiveValues[parameterKey(parameter)].value : displayValue.value
1262
+ ),
1263
+ onSubmit: () => {
1264
+ },
1265
+ placeholder: "Value",
1266
+ variables: EMPTY_VARIABLES,
1267
+ allowLineBreaks: true,
1268
+ expansionMode: "overlay",
1269
+ minHeight: 28,
1270
+ safePadding: 4,
1271
+ maxFocusedHeight: 360,
1272
+ onChange: (value) => {
1273
+ editValue(row.id, value);
1274
+ }
1275
+ }
1276
+ )
1277
+ ]
1278
+ }
1279
+ )
1280
+ },
1281
+ column.id
1282
+ );
1283
+ case "type":
1284
+ return /* @__PURE__ */ jsx(
1285
+ Table.Cell,
1286
+ {
1287
+ className: ParametersTable_default.cell,
1288
+ children: requestMode || readOnly || parameter.content ? /* @__PURE__ */ jsx(Span, { className: ParametersTable_default.description, children: type }) : /* @__PURE__ */ jsxs(
1289
+ Select.Root,
1290
+ {
1291
+ disabled: readOnly || requestMode,
1292
+ collection: typeOptions,
1293
+ size: "xs",
1294
+ value: [type.split(" (")[0]],
1295
+ onValueChange: (event) => {
1296
+ const newType = event.value[0];
1297
+ if (!newType) {
1298
+ return;
1299
+ }
1300
+ handleInputChange(
1301
+ row.id,
1302
+ (p) => ({
1303
+ ...p,
1304
+ schema: createSchemaForType(
1305
+ newType,
1306
+ typeof p.schema === "object" ? p.schema : void 0
1307
+ )
1308
+ })
1309
+ );
1310
+ },
1311
+ children: [
1312
+ /* @__PURE__ */ jsx(Select.HiddenSelect, {}),
1313
+ /* @__PURE__ */ jsxs(Select.Control, { children: [
1314
+ /* @__PURE__ */ jsx(
1315
+ Select.Trigger,
1316
+ {
1317
+ "aria-label": `Type for ${parameter.name}`,
1318
+ children: /* @__PURE__ */ jsx(
1319
+ Select.ValueText,
1320
+ {
1321
+ placeholder: type === "unknown" ? "Select type" : type
1322
+ }
1323
+ )
1324
+ }
1325
+ ),
1326
+ /* @__PURE__ */ jsx(Select.IndicatorGroup, { children: /* @__PURE__ */ jsx(Select.Indicator, {}) })
1327
+ ] }),
1328
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, { children: /* @__PURE__ */ jsx(Select.Content, { className: "pdDesignerSelectMenu", children: typeOptions.items.map(
1329
+ (item) => /* @__PURE__ */ jsxs(
1330
+ Select.Item,
1331
+ {
1332
+ item,
1333
+ children: [
1334
+ item.label,
1335
+ /* @__PURE__ */ jsx(Select.ItemIndicator, {})
1336
+ ]
1337
+ },
1338
+ item.value
1339
+ )
1340
+ ) }) }) })
1341
+ ]
1342
+ }
1343
+ )
1344
+ },
1345
+ column.id
1346
+ );
1347
+ case "required":
1348
+ return /* @__PURE__ */ jsx(
1349
+ Table.Cell,
1350
+ {
1351
+ className: ParametersTable_default.cell,
1352
+ children: /* @__PURE__ */ jsx(
1353
+ Span,
1354
+ {
1355
+ className: parameter.in === "path" || parameter.required ? ParametersTable_default.required : ParametersTable_default.optional,
1356
+ children: parameter.in === "path" || parameter.required ? "Required" : "Optional"
1357
+ }
1358
+ )
1359
+ },
1360
+ column.id
1361
+ );
1362
+ case "description":
1363
+ return /* @__PURE__ */ jsx(
1364
+ Table.Cell,
1365
+ {
1366
+ className: ParametersTable_default.cell,
1367
+ children: /* @__PURE__ */ jsx(Span, { className: ParametersTable_default.description, children: parameter.description ?? "\u2014" })
1368
+ },
1369
+ column.id
1370
+ );
1371
+ default:
1372
+ return null;
1373
+ }
1374
+ })
1375
+ ]
1376
+ }
1377
+ )
1378
+ },
1379
+ row.id
1380
+ );
1381
+ }),
1382
+ provided.placeholder
1383
+ ] })
1384
+ ]
1385
+ }
1386
+ )
1387
+ }
1388
+ ) }) }),
1389
+ /* @__PURE__ */ jsx(ActionBar.Root, { open: selectedIds.size > 0, children: /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(ActionBar.Positioner, { children: /* @__PURE__ */ jsxs(ActionBar.Content, { className: ParametersTable_default.actionBarContent, children: [
1390
+ /* @__PURE__ */ jsx(Box, { className: ParametersTable_default.actionBarLeft, children: /* @__PURE__ */ jsxs(
1391
+ ActionBar.SelectionTrigger,
1392
+ {
1393
+ className: ParametersTable_default.actionBarTrigger,
1394
+ children: [
1395
+ selectedIds.size,
1396
+ " selected"
1397
+ ]
1398
+ }
1399
+ ) }),
1400
+ /* @__PURE__ */ jsx(Span, { className: ParametersTable_default.actionBarDivider }),
1401
+ /* @__PURE__ */ jsxs(
1402
+ Button,
1403
+ {
1404
+ variant: "ghost",
1405
+ size: "xs",
1406
+ className: ParametersTable_default.actionButton,
1407
+ disabled: readOnly || requestMode,
1408
+ onClick: handleDeleteSelected,
1409
+ children: [
1410
+ /* @__PURE__ */ jsx(AiOutlineDelete, { className: ParametersTable_default.actionIcon }),
1411
+ "Delete"
1412
+ ]
1413
+ }
1414
+ ),
1415
+ /* @__PURE__ */ jsx(Span, { className: ParametersTable_default.actionBarDivider }),
1416
+ /* @__PURE__ */ jsxs(
1417
+ Button,
1418
+ {
1419
+ variant: "ghost",
1420
+ size: "xs",
1421
+ className: `${ParametersTable_default.actionButton} ${ParametersTable_default.actionButtonAccent}`,
1422
+ disabled: readOnly,
1423
+ onClick: handleGenerate,
1424
+ children: [
1425
+ /* @__PURE__ */ jsx(LuRefreshCw, { className: ParametersTable_default.actionIcon }),
1426
+ "Generate values"
1427
+ ]
1428
+ }
1429
+ )
1430
+ ] }) }) }) })
1431
+ ] })
1432
+ ]
1433
+ }
1434
+ );
1435
+ });
1436
+
1437
+ export { DEFAULT_COLUMNS, ParameterTable, applyAdjacentSplitterResize, areParameterArraysEqual, areParametersEqual, buildColumnDefsById, clamp, createRows, fitColumnWidths, getDisplayValue, getRightNeighborId, getVisibleColumns, reconcileRows, reorder };