@dxos/react-ui-form 0.7.5-labs.5f04cf6 → 0.7.5-labs.e27f9b9
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/lib/browser/index.mjs +400 -158
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +387 -145
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +400 -158
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +3 -2
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +4 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +7 -0
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +5 -0
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -24
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.tsx +3 -2
- package/src/components/Form/ArrayField.tsx +1 -1
- package/src/components/Form/Form.tsx +15 -2
- package/src/components/Form/FormContent.tsx +26 -8
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +58 -0
- package/src/components/Form/custom/SelectOptionsInput.tsx +192 -0
- package/src/components/Form/custom/index.ts +1 -0
- package/src/components/ViewEditor/ViewEditor.tsx +5 -2
- package/src/components/deprecated/FormInput.tsx +20 -7
- package/src/hooks/useForm.ts +0 -1
- package/src/translations.ts +8 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
BooleanInput: () => BooleanInput,
|
|
32
|
+
DeprecatedFormContainer: () => DeprecatedFormContainer,
|
|
32
33
|
DeprecatedFormInput: () => DeprecatedFormInput,
|
|
33
34
|
FieldEditor: () => FieldEditor,
|
|
34
35
|
Form: () => Form,
|
|
@@ -36,6 +37,7 @@ __export(node_exports, {
|
|
|
36
37
|
InputHeader: () => InputHeader,
|
|
37
38
|
NumberInput: () => NumberInput,
|
|
38
39
|
SelectInput: () => SelectInput,
|
|
40
|
+
SelectOptionInput: () => SelectOptionInput,
|
|
39
41
|
TextInput: () => TextInput,
|
|
40
42
|
TupleInput: () => TupleInput,
|
|
41
43
|
ViewEditor: () => ViewEditor,
|
|
@@ -51,6 +53,7 @@ __export(node_exports, {
|
|
|
51
53
|
module.exports = __toCommonJS(node_exports);
|
|
52
54
|
var import_react = __toESM(require("react"));
|
|
53
55
|
var import_react_ui = require("@dxos/react-ui");
|
|
56
|
+
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
54
57
|
var import_react2 = __toESM(require("react"));
|
|
55
58
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
56
59
|
var import_log = require("@dxos/log");
|
|
@@ -61,23 +64,29 @@ var import_react_ui3 = require("@dxos/react-ui");
|
|
|
61
64
|
var import_util = require("@dxos/util");
|
|
62
65
|
var import_react4 = __toESM(require("react"));
|
|
63
66
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
64
|
-
var
|
|
67
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
65
68
|
var import_react5 = __toESM(require("react"));
|
|
69
|
+
var import_keys = require("@dxos/keys");
|
|
66
70
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
67
|
-
var
|
|
68
|
-
var
|
|
71
|
+
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
72
|
+
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
73
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
69
74
|
var import_react6 = __toESM(require("react"));
|
|
70
75
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
76
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
77
|
+
var import_util2 = require("@dxos/util");
|
|
71
78
|
var import_react7 = __toESM(require("react"));
|
|
72
|
-
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
73
|
-
var import_react8 = __toESM(require("react"));
|
|
74
79
|
var import_react_ui7 = require("@dxos/react-ui");
|
|
75
|
-
var
|
|
80
|
+
var import_react8 = __toESM(require("react"));
|
|
81
|
+
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
76
82
|
var import_react9 = __toESM(require("react"));
|
|
83
|
+
var import_react_ui8 = require("@dxos/react-ui");
|
|
84
|
+
var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
85
|
+
var import_react10 = __toESM(require("react"));
|
|
77
86
|
var import_debug = require("@dxos/debug");
|
|
78
87
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
79
88
|
var import_effect = require("@dxos/effect");
|
|
80
|
-
var
|
|
89
|
+
var import_react11 = require("react");
|
|
81
90
|
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
82
91
|
var import_effect2 = require("@dxos/effect");
|
|
83
92
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -85,29 +94,28 @@ var import_log2 = require("@dxos/log");
|
|
|
85
94
|
var import_schema2 = require("@dxos/schema");
|
|
86
95
|
var import_effect3 = require("effect");
|
|
87
96
|
var import_String = require("effect/String");
|
|
88
|
-
var
|
|
97
|
+
var import_react12 = __toESM(require("react"));
|
|
89
98
|
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
90
99
|
var import_effect4 = require("@dxos/effect");
|
|
91
|
-
var
|
|
100
|
+
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
92
101
|
var import_schema3 = require("@dxos/schema");
|
|
93
102
|
var import_util3 = require("@dxos/util");
|
|
94
103
|
var import_effect5 = require("effect");
|
|
95
104
|
var import_String2 = require("effect/String");
|
|
96
|
-
var
|
|
105
|
+
var import_react13 = __toESM(require("react"));
|
|
97
106
|
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
98
107
|
var import_effect6 = require("@dxos/effect");
|
|
99
108
|
var import_invariant2 = require("@dxos/invariant");
|
|
100
|
-
var
|
|
101
|
-
var
|
|
109
|
+
var import_react_ui9 = require("@dxos/react-ui");
|
|
110
|
+
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
102
111
|
var import_schema4 = require("@dxos/schema");
|
|
103
112
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
104
|
-
var
|
|
113
|
+
var import_react14 = __toESM(require("react"));
|
|
105
114
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
106
|
-
var
|
|
107
|
-
var
|
|
108
|
-
var
|
|
115
|
+
var import_react_ui10 = require("@dxos/react-ui");
|
|
116
|
+
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
117
|
+
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
109
118
|
var import_schema5 = require("@dxos/schema");
|
|
110
|
-
var import_util4 = require("@dxos/util");
|
|
111
119
|
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
112
120
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
113
121
|
var translationKey = "react-ui-form";
|
|
@@ -146,6 +154,7 @@ var translations_default = [
|
|
|
146
154
|
"format ref": "Reference",
|
|
147
155
|
"format regex": "RegExp",
|
|
148
156
|
"format string": "String",
|
|
157
|
+
"format single-select": "Select",
|
|
149
158
|
"format text": "Long text",
|
|
150
159
|
"format time": "Time",
|
|
151
160
|
"format timestamp": "Timestamp",
|
|
@@ -155,11 +164,26 @@ var translations_default = [
|
|
|
155
164
|
"format uuid": "UUID",
|
|
156
165
|
// Placeholders
|
|
157
166
|
"placeholder latitude": "Latitude",
|
|
158
|
-
"placeholder longitude": "Longitude"
|
|
167
|
+
"placeholder longitude": "Longitude",
|
|
168
|
+
// SelectOptionsInput
|
|
169
|
+
"select option label": "Label",
|
|
170
|
+
"select option label placeholder": "Option label",
|
|
171
|
+
"select option color": "Color",
|
|
172
|
+
"select option delete": "Delete",
|
|
173
|
+
"select option add": "Add option"
|
|
159
174
|
}
|
|
160
175
|
}
|
|
161
176
|
}
|
|
162
177
|
];
|
|
178
|
+
var DeprecatedFormContainer = ({ children, classNames }) => {
|
|
179
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
180
|
+
role: "none",
|
|
181
|
+
className: "w-full p-4 justify-center overflow-x-hidden overflow-y-auto"
|
|
182
|
+
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
183
|
+
role: "form",
|
|
184
|
+
className: (0, import_react_ui_theme.mx)("flex flex-col", import_react_ui_theme.textBlockWidth, classNames)
|
|
185
|
+
}, children));
|
|
186
|
+
};
|
|
163
187
|
var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
164
188
|
const primary = /* @__PURE__ */ import_react.default.createElement("div", {
|
|
165
189
|
role: "none",
|
|
@@ -168,19 +192,21 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
168
192
|
role: "none",
|
|
169
193
|
className: "flex flex-col w-full"
|
|
170
194
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Label, {
|
|
171
|
-
classNames: "flex min-
|
|
195
|
+
classNames: "flex min-bs-[--rail-action] items-center",
|
|
196
|
+
style: {
|
|
197
|
+
fontSize: "unset"
|
|
198
|
+
}
|
|
172
199
|
}, label), description && /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.DescriptionAndValidation, {
|
|
173
200
|
classNames: "mbs-0.5"
|
|
174
201
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Description, null, description))), /* @__PURE__ */ import_react.default.createElement("div", {
|
|
175
202
|
role: "none"
|
|
176
203
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
177
204
|
role: "none",
|
|
178
|
-
className: "flex min-
|
|
205
|
+
className: "flex min-bs-[--rail-action] items-center"
|
|
179
206
|
}, children))));
|
|
180
207
|
if (secondary) {
|
|
181
208
|
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
182
|
-
role: "none"
|
|
183
|
-
className: "flex flex-col w-full"
|
|
209
|
+
role: "none"
|
|
184
210
|
}, primary, secondary);
|
|
185
211
|
}
|
|
186
212
|
return primary;
|
|
@@ -194,7 +220,7 @@ var InputHeader = ({ children, error }) => {
|
|
|
194
220
|
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Icon, {
|
|
195
221
|
icon: "ph--warning--regular",
|
|
196
222
|
size: 4,
|
|
197
|
-
classNames:
|
|
223
|
+
classNames: import_react_ui_theme2.errorText
|
|
198
224
|
})), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
199
225
|
side: "bottom"
|
|
200
226
|
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
@@ -231,6 +257,181 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
231
257
|
onBlur
|
|
232
258
|
})));
|
|
233
259
|
};
|
|
260
|
+
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
261
|
+
const [selected, setSelectedId] = (0, import_react5.useState)(null);
|
|
262
|
+
const [isNewOption, setIsNewOption] = (0, import_react5.useState)(false);
|
|
263
|
+
const inputRef = (0, import_react5.useRef)(null);
|
|
264
|
+
const { t } = (0, import_react_ui5.useTranslation)(translationKey);
|
|
265
|
+
const { status, error } = getStatus();
|
|
266
|
+
const options = getValue3();
|
|
267
|
+
(0, import_react5.useEffect)(() => {
|
|
268
|
+
if (options === void 0) {
|
|
269
|
+
onValueChange(type, []);
|
|
270
|
+
}
|
|
271
|
+
}, [
|
|
272
|
+
options,
|
|
273
|
+
onValueChange,
|
|
274
|
+
type
|
|
275
|
+
]);
|
|
276
|
+
const randomHue = () => {
|
|
277
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
278
|
+
const hueKeys = Object.keys(import_react_ui_theme3.hueTokenThemes);
|
|
279
|
+
const unusedHues = hueKeys.filter((hue) => !usedHues.has(hue));
|
|
280
|
+
if (unusedHues.length > 0) {
|
|
281
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
282
|
+
}
|
|
283
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
284
|
+
const availableHues = hueKeys.filter((hue) => !lastThree.has(hue));
|
|
285
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hueKeys[Math.floor(Math.random() * hueKeys.length)];
|
|
286
|
+
};
|
|
287
|
+
const handleAdd = (0, import_react5.useCallback)(() => {
|
|
288
|
+
const newId = import_keys.PublicKey.random().truncate();
|
|
289
|
+
const newOption = {
|
|
290
|
+
id: newId,
|
|
291
|
+
title: "",
|
|
292
|
+
color: randomHue()
|
|
293
|
+
};
|
|
294
|
+
onValueChange(type, [
|
|
295
|
+
...options ?? [],
|
|
296
|
+
newOption
|
|
297
|
+
]);
|
|
298
|
+
setSelectedId(newId);
|
|
299
|
+
setIsNewOption(true);
|
|
300
|
+
}, [
|
|
301
|
+
options,
|
|
302
|
+
type,
|
|
303
|
+
onValueChange
|
|
304
|
+
]);
|
|
305
|
+
const handleDelete = (0, import_react5.useCallback)((id) => {
|
|
306
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
307
|
+
onValueChange(type, newOptions);
|
|
308
|
+
setSelectedId(null);
|
|
309
|
+
}, [
|
|
310
|
+
options,
|
|
311
|
+
type,
|
|
312
|
+
onValueChange
|
|
313
|
+
]);
|
|
314
|
+
const handleMove = (0, import_react5.useCallback)((from, to) => {
|
|
315
|
+
if (!options) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const newOptions = [
|
|
319
|
+
...options
|
|
320
|
+
];
|
|
321
|
+
const [removed] = newOptions.splice(from, 1);
|
|
322
|
+
newOptions.splice(to, 0, removed);
|
|
323
|
+
onValueChange(type, newOptions);
|
|
324
|
+
}, [
|
|
325
|
+
options,
|
|
326
|
+
type,
|
|
327
|
+
onValueChange
|
|
328
|
+
]);
|
|
329
|
+
const handleClick = (0, import_react5.useCallback)((id) => {
|
|
330
|
+
setSelectedId((current) => current === id ? null : id);
|
|
331
|
+
}, []);
|
|
332
|
+
const handleTitleChange = (0, import_react5.useCallback)((id) => (e) => {
|
|
333
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
334
|
+
...o,
|
|
335
|
+
title: e.target.value
|
|
336
|
+
} : o);
|
|
337
|
+
onValueChange(type, newOptions ?? []);
|
|
338
|
+
}, [
|
|
339
|
+
options,
|
|
340
|
+
type,
|
|
341
|
+
onValueChange
|
|
342
|
+
]);
|
|
343
|
+
const handleKeyDown = (0, import_react5.useCallback)((e) => {
|
|
344
|
+
if (e.key === "Enter") {
|
|
345
|
+
setSelectedId(null);
|
|
346
|
+
}
|
|
347
|
+
}, []);
|
|
348
|
+
const handleColorChange = (0, import_react5.useCallback)((id) => (hue) => {
|
|
349
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
350
|
+
...o,
|
|
351
|
+
color: hue
|
|
352
|
+
} : o);
|
|
353
|
+
onValueChange(type, newOptions ?? []);
|
|
354
|
+
}, [
|
|
355
|
+
options,
|
|
356
|
+
type,
|
|
357
|
+
onValueChange
|
|
358
|
+
]);
|
|
359
|
+
(0, import_react5.useEffect)(() => {
|
|
360
|
+
if (selected && isNewOption && inputRef.current) {
|
|
361
|
+
inputRef.current.focus();
|
|
362
|
+
setIsNewOption(false);
|
|
363
|
+
}
|
|
364
|
+
}, [
|
|
365
|
+
selected,
|
|
366
|
+
isNewOption
|
|
367
|
+
]);
|
|
368
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Root, {
|
|
369
|
+
validationValence: status
|
|
370
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
371
|
+
error
|
|
372
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
373
|
+
role: "none"
|
|
374
|
+
}, options && /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.Root, {
|
|
375
|
+
items: options,
|
|
376
|
+
isItem: (item) => true,
|
|
377
|
+
onMove: handleMove
|
|
378
|
+
}, ({ items }) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
379
|
+
role: "list",
|
|
380
|
+
className: "w-full overflow-auto"
|
|
381
|
+
}, items?.map((item) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
382
|
+
key: item.id
|
|
383
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.Item, {
|
|
384
|
+
role: "button",
|
|
385
|
+
item,
|
|
386
|
+
classNames: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
387
|
+
"aria-expanded": selected === item.id
|
|
388
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
389
|
+
className: "flex items-center"
|
|
390
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
391
|
+
onClick: () => handleClick(item.id),
|
|
392
|
+
classNames: "flex-1"
|
|
393
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tag, {
|
|
394
|
+
palette: item.color
|
|
395
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
396
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
397
|
+
onClick: () => handleClick(item.id)
|
|
398
|
+
})), selected === item.id && /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
399
|
+
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
400
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, {
|
|
401
|
+
classNames: "text-xs"
|
|
402
|
+
}, t("select option label")), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
403
|
+
className: "flex flex-row items-center gap-1"
|
|
404
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.TextInput, {
|
|
405
|
+
placeholder: t("select option label placeholder"),
|
|
406
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
407
|
+
value: item.title,
|
|
408
|
+
onChange: handleTitleChange(item.id),
|
|
409
|
+
onKeyDown: handleKeyDown,
|
|
410
|
+
classNames: "flex-1"
|
|
411
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
412
|
+
classNames: "p-0 m-0 !is-auto"
|
|
413
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_pickers.HuePickerToolbarButton, {
|
|
414
|
+
hue: item.color,
|
|
415
|
+
onChangeHue: handleColorChange(item.id)
|
|
416
|
+
})), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.IconButton, {
|
|
417
|
+
icon: "ph--trash--fill",
|
|
418
|
+
iconOnly: true,
|
|
419
|
+
label: t("select option delete"),
|
|
420
|
+
onClick: () => handleDelete(item.id)
|
|
421
|
+
})))))), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
422
|
+
role: "listitem"
|
|
423
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
424
|
+
role: "button",
|
|
425
|
+
className: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
426
|
+
onClick: handleAdd
|
|
427
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
428
|
+
className: "flex items-center gap-1"
|
|
429
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
430
|
+
icon: "ph--plus--regular"
|
|
431
|
+
}), /* @__PURE__ */ import_react5.default.createElement("span", {
|
|
432
|
+
className: "text-sm"
|
|
433
|
+
}, t("select option add")))))))));
|
|
434
|
+
};
|
|
234
435
|
var gridCols = [
|
|
235
436
|
"grid-cols-1",
|
|
236
437
|
"grid-cols-2",
|
|
@@ -240,13 +441,13 @@ var gridCols = [
|
|
|
240
441
|
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
241
442
|
const { status, error } = getStatus();
|
|
242
443
|
const values = getValue3() ?? {};
|
|
243
|
-
return /* @__PURE__ */
|
|
444
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
244
445
|
validationValence: status
|
|
245
|
-
}, /* @__PURE__ */
|
|
446
|
+
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
246
447
|
error
|
|
247
|
-
}, /* @__PURE__ */
|
|
248
|
-
className: (0,
|
|
249
|
-
}, binding.map((prop) => /* @__PURE__ */
|
|
448
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
449
|
+
className: (0, import_react_ui_theme4.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
450
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
250
451
|
key: prop,
|
|
251
452
|
type: "number",
|
|
252
453
|
disabled,
|
|
@@ -260,64 +461,64 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
260
461
|
};
|
|
261
462
|
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
262
463
|
const { status, error } = getStatus();
|
|
263
|
-
return /* @__PURE__ */
|
|
464
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
264
465
|
validationValence: status
|
|
265
|
-
}, !inputOnly && /* @__PURE__ */
|
|
466
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
266
467
|
error
|
|
267
|
-
}, /* @__PURE__ */
|
|
468
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
268
469
|
disabled,
|
|
269
470
|
placeholder,
|
|
270
471
|
value: getValue3() ?? "",
|
|
271
472
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
272
473
|
onBlur
|
|
273
|
-
}), inputOnly && /* @__PURE__ */
|
|
474
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
274
475
|
};
|
|
275
476
|
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
276
477
|
const { status, error } = getStatus();
|
|
277
|
-
return /* @__PURE__ */
|
|
478
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
278
479
|
validationValence: status
|
|
279
|
-
}, !inputOnly && /* @__PURE__ */
|
|
480
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
280
481
|
error
|
|
281
|
-
}, /* @__PURE__ */
|
|
482
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
282
483
|
type: "number",
|
|
283
484
|
disabled,
|
|
284
485
|
placeholder,
|
|
285
486
|
value: getValue3() ?? 0,
|
|
286
487
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
287
488
|
onBlur
|
|
288
|
-
}), inputOnly && /* @__PURE__ */
|
|
489
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
289
490
|
};
|
|
290
491
|
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
291
492
|
const { status, error } = getStatus();
|
|
292
|
-
return /* @__PURE__ */
|
|
493
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
293
494
|
validationValence: status
|
|
294
|
-
}, !inputOnly && /* @__PURE__ */
|
|
495
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
295
496
|
error
|
|
296
|
-
}, /* @__PURE__ */
|
|
497
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Switch, {
|
|
297
498
|
checked: getValue3(),
|
|
298
499
|
onCheckedChange: (value) => onValueChange(type, value)
|
|
299
|
-
}), inputOnly && /* @__PURE__ */
|
|
500
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
300
501
|
};
|
|
301
502
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
302
503
|
const { status, error } = getStatus();
|
|
303
|
-
return /* @__PURE__ */
|
|
504
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
304
505
|
validationValence: status
|
|
305
|
-
}, !inputOnly && /* @__PURE__ */
|
|
506
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
306
507
|
error
|
|
307
|
-
}, /* @__PURE__ */
|
|
508
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Root, {
|
|
308
509
|
value: getValue3(),
|
|
309
510
|
onValueChange: (value) => onValueChange(type, value)
|
|
310
|
-
}, /* @__PURE__ */
|
|
511
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
311
512
|
classNames: "is-full",
|
|
312
513
|
disabled,
|
|
313
514
|
placeholder
|
|
314
|
-
}), /* @__PURE__ */
|
|
515
|
+
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Portal, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Content, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
315
516
|
// NOTE: Numeric values are converted to and from strings.
|
|
316
|
-
/* @__PURE__ */
|
|
517
|
+
/* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Option, {
|
|
317
518
|
key: String(value),
|
|
318
519
|
value: String(value)
|
|
319
520
|
}, label2 ?? String(value))
|
|
320
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
521
|
+
)))))), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
321
522
|
};
|
|
322
523
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
323
524
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
@@ -330,17 +531,17 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
330
531
|
""
|
|
331
532
|
]
|
|
332
533
|
});
|
|
333
|
-
const [values, setValues] = (0,
|
|
334
|
-
(0,
|
|
534
|
+
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
535
|
+
(0, import_react11.useEffect)(() => {
|
|
335
536
|
setValues(initialValues);
|
|
336
537
|
}, [
|
|
337
538
|
initialValues
|
|
338
539
|
]);
|
|
339
|
-
const [touched, setTouched] = (0,
|
|
340
|
-
const [changed, setChanged] = (0,
|
|
341
|
-
const [errors, setErrors] = (0,
|
|
342
|
-
const [saving, setSaving] = (0,
|
|
343
|
-
const validate = (0,
|
|
540
|
+
const [touched, setTouched] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
541
|
+
const [changed, setChanged] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
542
|
+
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
543
|
+
const [saving, setSaving] = (0, import_react11.useState)(false);
|
|
544
|
+
const validate = (0, import_react11.useCallback)((values2) => {
|
|
344
545
|
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
345
546
|
if (errors2.length === 0 && onValidate) {
|
|
346
547
|
const validatedValues = values2;
|
|
@@ -353,11 +554,11 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
353
554
|
schema,
|
|
354
555
|
onValidate
|
|
355
556
|
]);
|
|
356
|
-
const [schemaDirty, setSchemaDirty] = (0,
|
|
357
|
-
(0,
|
|
557
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
558
|
+
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
358
559
|
schema
|
|
359
560
|
]);
|
|
360
|
-
(0,
|
|
561
|
+
(0, import_react11.useEffect)(() => {
|
|
361
562
|
if (schemaDirty) {
|
|
362
563
|
validate(values);
|
|
363
564
|
setSchemaDirty(false);
|
|
@@ -366,13 +567,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
366
567
|
values,
|
|
367
568
|
schemaDirty
|
|
368
569
|
]);
|
|
369
|
-
const canSave = (0,
|
|
570
|
+
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
370
571
|
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
371
572
|
touched,
|
|
372
573
|
errors,
|
|
373
574
|
saving
|
|
374
575
|
]);
|
|
375
|
-
const handleSave = (0,
|
|
576
|
+
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
376
577
|
if (validate(values)) {
|
|
377
578
|
setSaving(true);
|
|
378
579
|
try {
|
|
@@ -389,7 +590,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
389
590
|
onSave,
|
|
390
591
|
changed
|
|
391
592
|
]);
|
|
392
|
-
const getStatus = (0,
|
|
593
|
+
const getStatus = (0, import_react11.useCallback)((path) => {
|
|
393
594
|
const jsonPath = Array.isArray(path) ? (0, import_effect2.createJsonPath)(path) : path;
|
|
394
595
|
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
395
596
|
return {
|
|
@@ -412,7 +613,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
412
613
|
} catch (err) {
|
|
413
614
|
import_log2.log.catch(err, void 0, {
|
|
414
615
|
F: __dxlog_file,
|
|
415
|
-
L:
|
|
616
|
+
L: 193,
|
|
416
617
|
S: void 0,
|
|
417
618
|
C: (f, a) => f(...a)
|
|
418
619
|
});
|
|
@@ -434,7 +635,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
434
635
|
});
|
|
435
636
|
}
|
|
436
637
|
};
|
|
437
|
-
const onTouched = (0,
|
|
638
|
+
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
438
639
|
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
439
640
|
setTouched((touched2) => ({
|
|
440
641
|
...touched2,
|
|
@@ -463,7 +664,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
463
664
|
var createKeySet = (obj, value) => {
|
|
464
665
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
465
666
|
F: __dxlog_file,
|
|
466
|
-
L:
|
|
667
|
+
L: 235,
|
|
467
668
|
S: void 0,
|
|
468
669
|
A: [
|
|
469
670
|
"obj",
|
|
@@ -484,9 +685,9 @@ var flatMap = (errors) => {
|
|
|
484
685
|
return result;
|
|
485
686
|
}, {});
|
|
486
687
|
};
|
|
487
|
-
var FormContext = /* @__PURE__ */ (0,
|
|
688
|
+
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
488
689
|
var useFormContext = () => {
|
|
489
|
-
return (0,
|
|
690
|
+
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
490
691
|
};
|
|
491
692
|
var useFormValues = (path = []) => {
|
|
492
693
|
const { values: formValues } = useFormContext();
|
|
@@ -504,25 +705,25 @@ var useInputProps = (path = []) => {
|
|
|
504
705
|
};
|
|
505
706
|
var FormProvider = ({ children, ...formOptions }) => {
|
|
506
707
|
const formHandler = useForm(formOptions);
|
|
507
|
-
return /* @__PURE__ */
|
|
708
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
508
709
|
value: formHandler
|
|
509
710
|
}, children);
|
|
510
711
|
};
|
|
511
712
|
var FormActions = ({ onCancel, readonly }) => {
|
|
512
|
-
const { t } = (0,
|
|
713
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
513
714
|
const { canSave, handleSave } = useFormContext();
|
|
514
|
-
return /* @__PURE__ */
|
|
715
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
515
716
|
role: "none",
|
|
516
717
|
className: "flex justify-center"
|
|
517
|
-
}, /* @__PURE__ */
|
|
718
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
518
719
|
role: "none",
|
|
519
|
-
className: (0,
|
|
520
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
720
|
+
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
721
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
521
722
|
"data-testid": "cancel-button",
|
|
522
723
|
icon: "ph--x--regular",
|
|
523
724
|
label: t("button cancel"),
|
|
524
725
|
onClick: onCancel
|
|
525
|
-
}), handleSave && /* @__PURE__ */
|
|
726
|
+
}), handleSave && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
526
727
|
type: "submit",
|
|
527
728
|
"data-testid": "save-button",
|
|
528
729
|
disabled: !canSave,
|
|
@@ -534,16 +735,16 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
534
735
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
535
736
|
var padding = "px-2";
|
|
536
737
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
537
|
-
const { t } = (0,
|
|
738
|
+
const { t } = (0, import_react_ui9.useTranslation)(translationKey);
|
|
538
739
|
const { ast, name, type, title } = property;
|
|
539
740
|
const values = useFormValues(path ?? []);
|
|
540
|
-
(0, import_invariant2.invariant)(Array.isArray(values),
|
|
741
|
+
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
541
742
|
F: __dxlog_file2,
|
|
542
743
|
L: 37,
|
|
543
744
|
S: void 0,
|
|
544
745
|
A: [
|
|
545
746
|
"Array.isArray(values)",
|
|
546
|
-
""
|
|
747
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
547
748
|
]
|
|
548
749
|
});
|
|
549
750
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
@@ -560,7 +761,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
560
761
|
prop.defaultValue
|
|
561
762
|
]));
|
|
562
763
|
};
|
|
563
|
-
const newValue = (0,
|
|
764
|
+
const newValue = (0, import_react13.useMemo)(() => {
|
|
564
765
|
if (type === "object" && elementType) {
|
|
565
766
|
return getDefaultObjectValue(elementType);
|
|
566
767
|
} else {
|
|
@@ -570,7 +771,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
570
771
|
type,
|
|
571
772
|
elementType
|
|
572
773
|
]);
|
|
573
|
-
const handleAdd = (0,
|
|
774
|
+
const handleAdd = (0, import_react13.useCallback)(() => {
|
|
574
775
|
inputProps.onValueChange(type, [
|
|
575
776
|
...values,
|
|
576
777
|
newValue
|
|
@@ -582,7 +783,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
582
783
|
newValue,
|
|
583
784
|
values
|
|
584
785
|
]);
|
|
585
|
-
const handleRemove = (0,
|
|
786
|
+
const handleRemove = (0, import_react13.useCallback)((index) => {
|
|
586
787
|
const newValues = values.filter((_, i) => i !== index);
|
|
587
788
|
inputProps.onValueChange(type, newValues);
|
|
588
789
|
}, [
|
|
@@ -593,20 +794,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
593
794
|
if (!elementType) {
|
|
594
795
|
return null;
|
|
595
796
|
}
|
|
596
|
-
return /* @__PURE__ */
|
|
797
|
+
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
597
798
|
role: "none",
|
|
598
|
-
className: (0,
|
|
599
|
-
}, /* @__PURE__ */
|
|
799
|
+
className: (0, import_react_ui_theme8.mx)(padding)
|
|
800
|
+
}, /* @__PURE__ */ import_react13.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
600
801
|
role: "none",
|
|
601
802
|
className: "flex flex-col gap-1"
|
|
602
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
803
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
603
804
|
key: index,
|
|
604
805
|
role: "none",
|
|
605
806
|
className: "flex items-center gap-1"
|
|
606
|
-
}, /* @__PURE__ */
|
|
807
|
+
}, /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
607
808
|
role: "none",
|
|
608
809
|
className: "flex-1"
|
|
609
|
-
}, /* @__PURE__ */
|
|
810
|
+
}, /* @__PURE__ */ import_react13.default.createElement(FormField, {
|
|
610
811
|
property: {
|
|
611
812
|
...property,
|
|
612
813
|
array: false,
|
|
@@ -620,15 +821,15 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
620
821
|
inline: true,
|
|
621
822
|
Custom,
|
|
622
823
|
lookupComponent
|
|
623
|
-
})), /* @__PURE__ */
|
|
824
|
+
})), /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
624
825
|
icon: "ph--trash--regular",
|
|
625
826
|
iconOnly: true,
|
|
626
827
|
label: t("button remove"),
|
|
627
828
|
onClick: () => handleRemove(index)
|
|
628
|
-
})))), /* @__PURE__ */
|
|
829
|
+
})))), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
629
830
|
role: "none",
|
|
630
831
|
className: "flex justify-between items-center plb-1"
|
|
631
|
-
}, /* @__PURE__ */
|
|
832
|
+
}, /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
632
833
|
icon: "ph--plus--regular",
|
|
633
834
|
iconOnly: true,
|
|
634
835
|
label: t("button add"),
|
|
@@ -652,23 +853,14 @@ var getInputComponent = (type, format) => {
|
|
|
652
853
|
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
653
854
|
const inputProps = useInputProps(path);
|
|
654
855
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
655
|
-
const label = (0,
|
|
856
|
+
const label = (0, import_react12.useMemo)(() => title ?? (0, import_effect3.pipe)(name, import_String.capitalize), [
|
|
656
857
|
title,
|
|
657
858
|
name
|
|
658
859
|
]);
|
|
659
|
-
const placeholder = (0,
|
|
860
|
+
const placeholder = (0, import_react12.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
660
861
|
examples,
|
|
661
862
|
description
|
|
662
863
|
]);
|
|
663
|
-
if (array) {
|
|
664
|
-
return /* @__PURE__ */ import_react11.default.createElement(ArrayField, {
|
|
665
|
-
property,
|
|
666
|
-
path,
|
|
667
|
-
inputProps,
|
|
668
|
-
readonly,
|
|
669
|
-
Custom
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
864
|
const FoundComponent = lookupComponent?.({
|
|
673
865
|
prop: name,
|
|
674
866
|
schema: import_echo_schema4.S.make(ast),
|
|
@@ -682,12 +874,42 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
682
874
|
}
|
|
683
875
|
});
|
|
684
876
|
if (FoundComponent) {
|
|
685
|
-
return /* @__PURE__ */
|
|
877
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
878
|
+
role: "none"
|
|
879
|
+
}, FoundComponent);
|
|
686
880
|
}
|
|
687
881
|
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
688
|
-
const
|
|
882
|
+
const CustomComponent = Custom?.[jsonPath];
|
|
883
|
+
if (CustomComponent) {
|
|
884
|
+
return (
|
|
885
|
+
// TODO(ZaymonFC): We should try to remove this div wrapper.
|
|
886
|
+
/* @__PURE__ */ import_react12.default.createElement("div", {
|
|
887
|
+
role: "none"
|
|
888
|
+
}, /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
889
|
+
type,
|
|
890
|
+
format,
|
|
891
|
+
label,
|
|
892
|
+
inputOnly: inline,
|
|
893
|
+
placeholder,
|
|
894
|
+
disabled: readonly,
|
|
895
|
+
...inputProps
|
|
896
|
+
}))
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
if (array) {
|
|
900
|
+
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
901
|
+
property,
|
|
902
|
+
path,
|
|
903
|
+
inputProps,
|
|
904
|
+
readonly,
|
|
905
|
+
Custom
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
const InputComponent = getInputComponent(type, format);
|
|
689
909
|
if (InputComponent) {
|
|
690
|
-
return /* @__PURE__ */
|
|
910
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
911
|
+
role: "none"
|
|
912
|
+
}, /* @__PURE__ */ import_react12.default.createElement(InputComponent, {
|
|
691
913
|
type,
|
|
692
914
|
format,
|
|
693
915
|
label,
|
|
@@ -698,9 +920,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
698
920
|
}));
|
|
699
921
|
}
|
|
700
922
|
if (options) {
|
|
701
|
-
return /* @__PURE__ */
|
|
923
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
702
924
|
role: "none"
|
|
703
|
-
}, /* @__PURE__ */
|
|
925
|
+
}, /* @__PURE__ */ import_react12.default.createElement(SelectInput, {
|
|
704
926
|
type,
|
|
705
927
|
format,
|
|
706
928
|
disabled: readonly,
|
|
@@ -718,7 +940,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
718
940
|
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
719
941
|
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema4.AST.isTypeLiteral);
|
|
720
942
|
if (typeLiteral) {
|
|
721
|
-
return /* @__PURE__ */
|
|
943
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
944
|
+
role: "none"
|
|
945
|
+
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
722
946
|
schema: import_echo_schema4.S.make(typeLiteral),
|
|
723
947
|
path,
|
|
724
948
|
readonly,
|
|
@@ -730,7 +954,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
730
954
|
};
|
|
731
955
|
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
732
956
|
const values = useFormValues(path);
|
|
733
|
-
const properties = (0,
|
|
957
|
+
const properties = (0, import_react12.useMemo)(() => {
|
|
734
958
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
735
959
|
const filtered = filter ? filter(props) : props;
|
|
736
960
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -740,11 +964,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
740
964
|
filter,
|
|
741
965
|
sort
|
|
742
966
|
]);
|
|
743
|
-
return /* @__PURE__ */
|
|
967
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
744
968
|
role: "form",
|
|
745
|
-
className: (0,
|
|
969
|
+
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2 py-2")
|
|
746
970
|
}, properties.map((property) => {
|
|
747
|
-
return /* @__PURE__ */
|
|
971
|
+
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
748
972
|
key: property.name,
|
|
749
973
|
property,
|
|
750
974
|
path: [
|
|
@@ -757,23 +981,33 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
757
981
|
});
|
|
758
982
|
}).filter(import_util3.isNotFalsy));
|
|
759
983
|
};
|
|
760
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
761
|
-
const onValid = (0,
|
|
984
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
985
|
+
const onValid = (0, import_react8.useMemo)(() => autoSave ? onSave : void 0, [
|
|
762
986
|
autoSave,
|
|
763
987
|
onSave
|
|
764
988
|
]);
|
|
765
|
-
|
|
989
|
+
(0, import_react8.useEffect)(() => {
|
|
990
|
+
if (autoFocus) {
|
|
991
|
+
const input = document.querySelector("input");
|
|
992
|
+
if (input) {
|
|
993
|
+
input.focus();
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}, [
|
|
997
|
+
autoFocus
|
|
998
|
+
]);
|
|
999
|
+
return /* @__PURE__ */ import_react8.default.createElement(FormProvider, {
|
|
766
1000
|
schema,
|
|
767
1001
|
initialValues,
|
|
768
1002
|
onValuesChanged,
|
|
769
1003
|
onValidate,
|
|
770
1004
|
onValid,
|
|
771
1005
|
onSave
|
|
772
|
-
}, /* @__PURE__ */
|
|
1006
|
+
}, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
773
1007
|
role: "none",
|
|
774
|
-
className: (0,
|
|
1008
|
+
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
775
1009
|
"data-testid": testId
|
|
776
|
-
}, /* @__PURE__ */
|
|
1010
|
+
}, /* @__PURE__ */ import_react8.default.createElement(FormFields, {
|
|
777
1011
|
schema,
|
|
778
1012
|
path,
|
|
779
1013
|
readonly,
|
|
@@ -781,7 +1015,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
781
1015
|
sort,
|
|
782
1016
|
lookupComponent,
|
|
783
1017
|
Custom
|
|
784
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1018
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react8.default.createElement(FormActions, {
|
|
785
1019
|
onCancel,
|
|
786
1020
|
readonly
|
|
787
1021
|
})));
|
|
@@ -851,7 +1085,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
851
1085
|
type
|
|
852
1086
|
};
|
|
853
1087
|
}
|
|
854
|
-
return
|
|
1088
|
+
return _props;
|
|
855
1089
|
});
|
|
856
1090
|
}, [
|
|
857
1091
|
schemas,
|
|
@@ -907,7 +1141,8 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
907
1141
|
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
908
1142
|
value: p.name
|
|
909
1143
|
})) : []
|
|
910
|
-
})
|
|
1144
|
+
}),
|
|
1145
|
+
["options"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectOptionInput, props2)
|
|
911
1146
|
}), [
|
|
912
1147
|
t,
|
|
913
1148
|
schemas,
|
|
@@ -919,7 +1154,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
919
1154
|
props
|
|
920
1155
|
}, {
|
|
921
1156
|
F: __dxlog_file3,
|
|
922
|
-
L:
|
|
1157
|
+
L: 174,
|
|
923
1158
|
S: void 0,
|
|
924
1159
|
C: (f, a) => f(...a)
|
|
925
1160
|
});
|
|
@@ -952,13 +1187,13 @@ var ViewMetaSchema = import_echo_schema7.S.Struct({
|
|
|
952
1187
|
})
|
|
953
1188
|
}).pipe(import_echo_schema7.S.mutable);
|
|
954
1189
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
955
|
-
const { t } = (0,
|
|
956
|
-
const projection = (0,
|
|
1190
|
+
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1191
|
+
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
957
1192
|
schema,
|
|
958
1193
|
view
|
|
959
1194
|
]);
|
|
960
|
-
const [field, setField] = (0,
|
|
961
|
-
const viewValues = (0,
|
|
1195
|
+
const [field, setField] = (0, import_react14.useState)();
|
|
1196
|
+
const viewValues = (0, import_react14.useMemo)(() => {
|
|
962
1197
|
return {
|
|
963
1198
|
name: view.name,
|
|
964
1199
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -968,7 +1203,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
968
1203
|
}, [
|
|
969
1204
|
view
|
|
970
1205
|
]);
|
|
971
|
-
const handleViewUpdate = (0,
|
|
1206
|
+
const handleViewUpdate = (0, import_react14.useCallback)(({ name, typename }) => {
|
|
972
1207
|
requestAnimationFrame(() => {
|
|
973
1208
|
if (view.name !== name) {
|
|
974
1209
|
view.name = name;
|
|
@@ -982,67 +1217,72 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
982
1217
|
schema,
|
|
983
1218
|
onTypenameChanged
|
|
984
1219
|
]);
|
|
985
|
-
const handleSelect = (0,
|
|
1220
|
+
const handleSelect = (0, import_react14.useCallback)((field2) => {
|
|
986
1221
|
setField((f) => f === field2 ? void 0 : field2);
|
|
987
1222
|
}, []);
|
|
988
|
-
const handleAdd = (0,
|
|
1223
|
+
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
989
1224
|
const field2 = projection.createFieldProjection();
|
|
990
1225
|
setField(field2);
|
|
991
1226
|
}, [
|
|
992
1227
|
view
|
|
993
1228
|
]);
|
|
994
|
-
const handleMove = (0,
|
|
995
|
-
|
|
1229
|
+
const handleMove = (0, import_react14.useCallback)((fromIndex, toIndex) => {
|
|
1230
|
+
const fields = [
|
|
1231
|
+
...view.fields
|
|
1232
|
+
];
|
|
1233
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
1234
|
+
fields.splice(toIndex, 0, moved);
|
|
1235
|
+
view.fields = fields;
|
|
996
1236
|
}, [
|
|
997
1237
|
view.fields
|
|
998
1238
|
]);
|
|
999
|
-
const handleClose = (0,
|
|
1000
|
-
return /* @__PURE__ */
|
|
1239
|
+
const handleClose = (0, import_react14.useCallback)(() => setField(void 0), []);
|
|
1240
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1001
1241
|
role: "none",
|
|
1002
|
-
className: (0,
|
|
1003
|
-
}, /* @__PURE__ */
|
|
1242
|
+
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1243
|
+
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
1004
1244
|
autoFocus: true,
|
|
1005
1245
|
autoSave: true,
|
|
1006
1246
|
schema: ViewMetaSchema,
|
|
1007
1247
|
values: viewValues,
|
|
1008
1248
|
onSave: handleViewUpdate
|
|
1009
|
-
}), /* @__PURE__ */
|
|
1249
|
+
}), /* @__PURE__ */ import_react14.default.createElement("div", null, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1010
1250
|
role: "none",
|
|
1011
1251
|
className: "p-2"
|
|
1012
|
-
}, /* @__PURE__ */
|
|
1013
|
-
className: (0,
|
|
1014
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1252
|
+
}, /* @__PURE__ */ import_react14.default.createElement("label", {
|
|
1253
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1254
|
+
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1015
1255
|
items: view.fields,
|
|
1016
1256
|
isItem: import_echo_schema7.S.is(import_schema5.FieldSchema),
|
|
1017
1257
|
getId: (field2) => field2.id,
|
|
1018
1258
|
onMove: handleMove
|
|
1019
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1259
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1020
1260
|
role: "heading",
|
|
1021
1261
|
className: grid
|
|
1022
|
-
}, /* @__PURE__ */
|
|
1262
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", null), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1023
1263
|
className: "flex items-center text-sm"
|
|
1024
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1264
|
+
}, t("field path label"))), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1025
1265
|
role: "list",
|
|
1026
1266
|
className: "flex flex-col w-full"
|
|
1027
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1267
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Item, {
|
|
1028
1268
|
key: field2.id,
|
|
1029
1269
|
item: field2,
|
|
1030
|
-
classNames: (0,
|
|
1031
|
-
}, /* @__PURE__ */
|
|
1270
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1271
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1032
1272
|
onClick: () => handleSelect(field2)
|
|
1033
|
-
}, field2.path), /* @__PURE__ */
|
|
1273
|
+
}, field2.path), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1034
1274
|
disabled: view.fields.length <= 1,
|
|
1035
1275
|
onClick: () => onDelete(field2.id)
|
|
1036
|
-
}))))))), field && /* @__PURE__ */
|
|
1276
|
+
}))))))), field && /* @__PURE__ */ import_react14.default.createElement(FieldEditor, {
|
|
1037
1277
|
key: field.id,
|
|
1038
1278
|
view,
|
|
1039
1279
|
projection,
|
|
1040
1280
|
field,
|
|
1041
1281
|
registry,
|
|
1042
1282
|
onSave: handleClose
|
|
1043
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1283
|
+
}), !readonly && !field && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1044
1284
|
className: "flex p-2 justify-center"
|
|
1045
|
-
}, /* @__PURE__ */
|
|
1285
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1046
1286
|
icon: "ph--plus--regular",
|
|
1047
1287
|
label: t("button add property"),
|
|
1048
1288
|
onClick: handleAdd,
|
|
@@ -1267,6 +1507,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1267
1507
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1268
1508
|
0 && (module.exports = {
|
|
1269
1509
|
BooleanInput,
|
|
1510
|
+
DeprecatedFormContainer,
|
|
1270
1511
|
DeprecatedFormInput,
|
|
1271
1512
|
FieldEditor,
|
|
1272
1513
|
Form,
|
|
@@ -1274,6 +1515,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1274
1515
|
InputHeader,
|
|
1275
1516
|
NumberInput,
|
|
1276
1517
|
SelectInput,
|
|
1518
|
+
SelectOptionInput,
|
|
1277
1519
|
TextInput,
|
|
1278
1520
|
TupleInput,
|
|
1279
1521
|
ViewEditor,
|