@dxos/react-ui-form 0.7.5-labs.5f04cf6 → 0.7.5-labs.8a82073
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 +403 -160
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +390 -147
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +403 -160
- 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/Defaults.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/Defaults.tsx +2 -1
- package/src/components/Form/Form.tsx +16 -2
- package/src/components/Form/FormActions.tsx +1 -1
- package/src/components/Form/FormContent.tsx +27 -9
- 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,65 @@ 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
|
-
|
|
493
|
+
const checked = Boolean(getValue3());
|
|
494
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
293
495
|
validationValence: status
|
|
294
|
-
}, !inputOnly && /* @__PURE__ */
|
|
496
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
295
497
|
error
|
|
296
|
-
}, /* @__PURE__ */
|
|
297
|
-
checked
|
|
498
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Switch, {
|
|
499
|
+
checked,
|
|
298
500
|
onCheckedChange: (value) => onValueChange(type, value)
|
|
299
|
-
}), inputOnly && /* @__PURE__ */
|
|
501
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
300
502
|
};
|
|
301
503
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
302
504
|
const { status, error } = getStatus();
|
|
303
|
-
return /* @__PURE__ */
|
|
505
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
304
506
|
validationValence: status
|
|
305
|
-
}, !inputOnly && /* @__PURE__ */
|
|
507
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
306
508
|
error
|
|
307
|
-
}, /* @__PURE__ */
|
|
509
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Root, {
|
|
308
510
|
value: getValue3(),
|
|
309
511
|
onValueChange: (value) => onValueChange(type, value)
|
|
310
|
-
}, /* @__PURE__ */
|
|
512
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
311
513
|
classNames: "is-full",
|
|
312
514
|
disabled,
|
|
313
515
|
placeholder
|
|
314
|
-
}), /* @__PURE__ */
|
|
516
|
+
}), /* @__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
517
|
// NOTE: Numeric values are converted to and from strings.
|
|
316
|
-
/* @__PURE__ */
|
|
518
|
+
/* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Option, {
|
|
317
519
|
key: String(value),
|
|
318
520
|
value: String(value)
|
|
319
521
|
}, label2 ?? String(value))
|
|
320
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
522
|
+
)))))), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
321
523
|
};
|
|
322
524
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
323
525
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
@@ -330,17 +532,17 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
330
532
|
""
|
|
331
533
|
]
|
|
332
534
|
});
|
|
333
|
-
const [values, setValues] = (0,
|
|
334
|
-
(0,
|
|
535
|
+
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
536
|
+
(0, import_react11.useEffect)(() => {
|
|
335
537
|
setValues(initialValues);
|
|
336
538
|
}, [
|
|
337
539
|
initialValues
|
|
338
540
|
]);
|
|
339
|
-
const [touched, setTouched] = (0,
|
|
340
|
-
const [changed, setChanged] = (0,
|
|
341
|
-
const [errors, setErrors] = (0,
|
|
342
|
-
const [saving, setSaving] = (0,
|
|
343
|
-
const validate = (0,
|
|
541
|
+
const [touched, setTouched] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
542
|
+
const [changed, setChanged] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
543
|
+
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
544
|
+
const [saving, setSaving] = (0, import_react11.useState)(false);
|
|
545
|
+
const validate = (0, import_react11.useCallback)((values2) => {
|
|
344
546
|
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
345
547
|
if (errors2.length === 0 && onValidate) {
|
|
346
548
|
const validatedValues = values2;
|
|
@@ -353,11 +555,11 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
353
555
|
schema,
|
|
354
556
|
onValidate
|
|
355
557
|
]);
|
|
356
|
-
const [schemaDirty, setSchemaDirty] = (0,
|
|
357
|
-
(0,
|
|
558
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
559
|
+
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
358
560
|
schema
|
|
359
561
|
]);
|
|
360
|
-
(0,
|
|
562
|
+
(0, import_react11.useEffect)(() => {
|
|
361
563
|
if (schemaDirty) {
|
|
362
564
|
validate(values);
|
|
363
565
|
setSchemaDirty(false);
|
|
@@ -366,13 +568,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
366
568
|
values,
|
|
367
569
|
schemaDirty
|
|
368
570
|
]);
|
|
369
|
-
const canSave = (0,
|
|
571
|
+
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
370
572
|
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
371
573
|
touched,
|
|
372
574
|
errors,
|
|
373
575
|
saving
|
|
374
576
|
]);
|
|
375
|
-
const handleSave = (0,
|
|
577
|
+
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
376
578
|
if (validate(values)) {
|
|
377
579
|
setSaving(true);
|
|
378
580
|
try {
|
|
@@ -389,7 +591,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
389
591
|
onSave,
|
|
390
592
|
changed
|
|
391
593
|
]);
|
|
392
|
-
const getStatus = (0,
|
|
594
|
+
const getStatus = (0, import_react11.useCallback)((path) => {
|
|
393
595
|
const jsonPath = Array.isArray(path) ? (0, import_effect2.createJsonPath)(path) : path;
|
|
394
596
|
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
395
597
|
return {
|
|
@@ -412,7 +614,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
412
614
|
} catch (err) {
|
|
413
615
|
import_log2.log.catch(err, void 0, {
|
|
414
616
|
F: __dxlog_file,
|
|
415
|
-
L:
|
|
617
|
+
L: 193,
|
|
416
618
|
S: void 0,
|
|
417
619
|
C: (f, a) => f(...a)
|
|
418
620
|
});
|
|
@@ -434,7 +636,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
434
636
|
});
|
|
435
637
|
}
|
|
436
638
|
};
|
|
437
|
-
const onTouched = (0,
|
|
639
|
+
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
438
640
|
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
439
641
|
setTouched((touched2) => ({
|
|
440
642
|
...touched2,
|
|
@@ -463,7 +665,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
463
665
|
var createKeySet = (obj, value) => {
|
|
464
666
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
465
667
|
F: __dxlog_file,
|
|
466
|
-
L:
|
|
668
|
+
L: 235,
|
|
467
669
|
S: void 0,
|
|
468
670
|
A: [
|
|
469
671
|
"obj",
|
|
@@ -484,9 +686,9 @@ var flatMap = (errors) => {
|
|
|
484
686
|
return result;
|
|
485
687
|
}, {});
|
|
486
688
|
};
|
|
487
|
-
var FormContext = /* @__PURE__ */ (0,
|
|
689
|
+
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
488
690
|
var useFormContext = () => {
|
|
489
|
-
return (0,
|
|
691
|
+
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
490
692
|
};
|
|
491
693
|
var useFormValues = (path = []) => {
|
|
492
694
|
const { values: formValues } = useFormContext();
|
|
@@ -504,25 +706,25 @@ var useInputProps = (path = []) => {
|
|
|
504
706
|
};
|
|
505
707
|
var FormProvider = ({ children, ...formOptions }) => {
|
|
506
708
|
const formHandler = useForm(formOptions);
|
|
507
|
-
return /* @__PURE__ */
|
|
709
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
508
710
|
value: formHandler
|
|
509
711
|
}, children);
|
|
510
712
|
};
|
|
511
713
|
var FormActions = ({ onCancel, readonly }) => {
|
|
512
|
-
const { t } = (0,
|
|
714
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
513
715
|
const { canSave, handleSave } = useFormContext();
|
|
514
|
-
return /* @__PURE__ */
|
|
716
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
515
717
|
role: "none",
|
|
516
|
-
className: "flex justify-center"
|
|
517
|
-
}, /* @__PURE__ */
|
|
718
|
+
className: "mt-2 flex justify-center"
|
|
719
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
518
720
|
role: "none",
|
|
519
|
-
className: (0,
|
|
520
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
721
|
+
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
722
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
521
723
|
"data-testid": "cancel-button",
|
|
522
724
|
icon: "ph--x--regular",
|
|
523
725
|
label: t("button cancel"),
|
|
524
726
|
onClick: onCancel
|
|
525
|
-
}), handleSave && /* @__PURE__ */
|
|
727
|
+
}), handleSave && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
526
728
|
type: "submit",
|
|
527
729
|
"data-testid": "save-button",
|
|
528
730
|
disabled: !canSave,
|
|
@@ -534,16 +736,16 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
534
736
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
535
737
|
var padding = "px-2";
|
|
536
738
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
537
|
-
const { t } = (0,
|
|
739
|
+
const { t } = (0, import_react_ui9.useTranslation)(translationKey);
|
|
538
740
|
const { ast, name, type, title } = property;
|
|
539
741
|
const values = useFormValues(path ?? []);
|
|
540
|
-
(0, import_invariant2.invariant)(Array.isArray(values),
|
|
742
|
+
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
541
743
|
F: __dxlog_file2,
|
|
542
744
|
L: 37,
|
|
543
745
|
S: void 0,
|
|
544
746
|
A: [
|
|
545
747
|
"Array.isArray(values)",
|
|
546
|
-
""
|
|
748
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
547
749
|
]
|
|
548
750
|
});
|
|
549
751
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
@@ -560,7 +762,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
560
762
|
prop.defaultValue
|
|
561
763
|
]));
|
|
562
764
|
};
|
|
563
|
-
const newValue = (0,
|
|
765
|
+
const newValue = (0, import_react13.useMemo)(() => {
|
|
564
766
|
if (type === "object" && elementType) {
|
|
565
767
|
return getDefaultObjectValue(elementType);
|
|
566
768
|
} else {
|
|
@@ -570,7 +772,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
570
772
|
type,
|
|
571
773
|
elementType
|
|
572
774
|
]);
|
|
573
|
-
const handleAdd = (0,
|
|
775
|
+
const handleAdd = (0, import_react13.useCallback)(() => {
|
|
574
776
|
inputProps.onValueChange(type, [
|
|
575
777
|
...values,
|
|
576
778
|
newValue
|
|
@@ -582,7 +784,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
582
784
|
newValue,
|
|
583
785
|
values
|
|
584
786
|
]);
|
|
585
|
-
const handleRemove = (0,
|
|
787
|
+
const handleRemove = (0, import_react13.useCallback)((index) => {
|
|
586
788
|
const newValues = values.filter((_, i) => i !== index);
|
|
587
789
|
inputProps.onValueChange(type, newValues);
|
|
588
790
|
}, [
|
|
@@ -593,20 +795,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
593
795
|
if (!elementType) {
|
|
594
796
|
return null;
|
|
595
797
|
}
|
|
596
|
-
return /* @__PURE__ */
|
|
798
|
+
return /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
597
799
|
role: "none",
|
|
598
|
-
className: (0,
|
|
599
|
-
}, /* @__PURE__ */
|
|
800
|
+
className: (0, import_react_ui_theme8.mx)(padding)
|
|
801
|
+
}, /* @__PURE__ */ import_react13.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
600
802
|
role: "none",
|
|
601
803
|
className: "flex flex-col gap-1"
|
|
602
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
804
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
603
805
|
key: index,
|
|
604
806
|
role: "none",
|
|
605
807
|
className: "flex items-center gap-1"
|
|
606
|
-
}, /* @__PURE__ */
|
|
808
|
+
}, /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
607
809
|
role: "none",
|
|
608
810
|
className: "flex-1"
|
|
609
|
-
}, /* @__PURE__ */
|
|
811
|
+
}, /* @__PURE__ */ import_react13.default.createElement(FormField, {
|
|
610
812
|
property: {
|
|
611
813
|
...property,
|
|
612
814
|
array: false,
|
|
@@ -620,15 +822,15 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
620
822
|
inline: true,
|
|
621
823
|
Custom,
|
|
622
824
|
lookupComponent
|
|
623
|
-
})), /* @__PURE__ */
|
|
825
|
+
})), /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
624
826
|
icon: "ph--trash--regular",
|
|
625
827
|
iconOnly: true,
|
|
626
828
|
label: t("button remove"),
|
|
627
829
|
onClick: () => handleRemove(index)
|
|
628
|
-
})))), /* @__PURE__ */
|
|
830
|
+
})))), /* @__PURE__ */ import_react13.default.createElement("div", {
|
|
629
831
|
role: "none",
|
|
630
832
|
className: "flex justify-between items-center plb-1"
|
|
631
|
-
}, /* @__PURE__ */
|
|
833
|
+
}, /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
632
834
|
icon: "ph--plus--regular",
|
|
633
835
|
iconOnly: true,
|
|
634
836
|
label: t("button add"),
|
|
@@ -652,23 +854,14 @@ var getInputComponent = (type, format) => {
|
|
|
652
854
|
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
653
855
|
const inputProps = useInputProps(path);
|
|
654
856
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
655
|
-
const label = (0,
|
|
857
|
+
const label = (0, import_react12.useMemo)(() => title ?? (0, import_effect3.pipe)(name, import_String.capitalize), [
|
|
656
858
|
title,
|
|
657
859
|
name
|
|
658
860
|
]);
|
|
659
|
-
const placeholder = (0,
|
|
861
|
+
const placeholder = (0, import_react12.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
660
862
|
examples,
|
|
661
863
|
description
|
|
662
864
|
]);
|
|
663
|
-
if (array) {
|
|
664
|
-
return /* @__PURE__ */ import_react11.default.createElement(ArrayField, {
|
|
665
|
-
property,
|
|
666
|
-
path,
|
|
667
|
-
inputProps,
|
|
668
|
-
readonly,
|
|
669
|
-
Custom
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
865
|
const FoundComponent = lookupComponent?.({
|
|
673
866
|
prop: name,
|
|
674
867
|
schema: import_echo_schema4.S.make(ast),
|
|
@@ -682,12 +875,42 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
682
875
|
}
|
|
683
876
|
});
|
|
684
877
|
if (FoundComponent) {
|
|
685
|
-
return /* @__PURE__ */
|
|
878
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
879
|
+
role: "none"
|
|
880
|
+
}, FoundComponent);
|
|
686
881
|
}
|
|
687
882
|
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
688
|
-
const
|
|
883
|
+
const CustomComponent = Custom?.[jsonPath];
|
|
884
|
+
if (CustomComponent) {
|
|
885
|
+
return (
|
|
886
|
+
// TODO(ZaymonFC): We should try to remove this div wrapper.
|
|
887
|
+
/* @__PURE__ */ import_react12.default.createElement("div", {
|
|
888
|
+
role: "none"
|
|
889
|
+
}, /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
890
|
+
type,
|
|
891
|
+
format,
|
|
892
|
+
label,
|
|
893
|
+
inputOnly: inline,
|
|
894
|
+
placeholder,
|
|
895
|
+
disabled: readonly,
|
|
896
|
+
...inputProps
|
|
897
|
+
}))
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
if (array) {
|
|
901
|
+
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
902
|
+
property,
|
|
903
|
+
path,
|
|
904
|
+
inputProps,
|
|
905
|
+
readonly,
|
|
906
|
+
Custom
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
const InputComponent = getInputComponent(type, format);
|
|
689
910
|
if (InputComponent) {
|
|
690
|
-
return /* @__PURE__ */
|
|
911
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
912
|
+
role: "none"
|
|
913
|
+
}, /* @__PURE__ */ import_react12.default.createElement(InputComponent, {
|
|
691
914
|
type,
|
|
692
915
|
format,
|
|
693
916
|
label,
|
|
@@ -698,9 +921,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
698
921
|
}));
|
|
699
922
|
}
|
|
700
923
|
if (options) {
|
|
701
|
-
return /* @__PURE__ */
|
|
924
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
702
925
|
role: "none"
|
|
703
|
-
}, /* @__PURE__ */
|
|
926
|
+
}, /* @__PURE__ */ import_react12.default.createElement(SelectInput, {
|
|
704
927
|
type,
|
|
705
928
|
format,
|
|
706
929
|
disabled: readonly,
|
|
@@ -718,7 +941,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
718
941
|
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
719
942
|
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema4.AST.isTypeLiteral);
|
|
720
943
|
if (typeLiteral) {
|
|
721
|
-
return /* @__PURE__ */
|
|
944
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
945
|
+
role: "none"
|
|
946
|
+
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
722
947
|
schema: import_echo_schema4.S.make(typeLiteral),
|
|
723
948
|
path,
|
|
724
949
|
readonly,
|
|
@@ -730,7 +955,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
730
955
|
};
|
|
731
956
|
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
732
957
|
const values = useFormValues(path);
|
|
733
|
-
const properties = (0,
|
|
958
|
+
const properties = (0, import_react12.useMemo)(() => {
|
|
734
959
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
735
960
|
const filtered = filter ? filter(props) : props;
|
|
736
961
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -740,11 +965,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
740
965
|
filter,
|
|
741
966
|
sort
|
|
742
967
|
]);
|
|
743
|
-
return /* @__PURE__ */
|
|
968
|
+
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
744
969
|
role: "form",
|
|
745
|
-
className: (0,
|
|
970
|
+
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2")
|
|
746
971
|
}, properties.map((property) => {
|
|
747
|
-
return /* @__PURE__ */
|
|
972
|
+
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
748
973
|
key: property.name,
|
|
749
974
|
property,
|
|
750
975
|
path: [
|
|
@@ -757,23 +982,33 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
757
982
|
});
|
|
758
983
|
}).filter(import_util3.isNotFalsy));
|
|
759
984
|
};
|
|
760
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
761
|
-
const onValid = (0,
|
|
985
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
986
|
+
const onValid = (0, import_react8.useMemo)(() => autoSave ? onSave : void 0, [
|
|
762
987
|
autoSave,
|
|
763
988
|
onSave
|
|
764
989
|
]);
|
|
765
|
-
|
|
990
|
+
(0, import_react8.useEffect)(() => {
|
|
991
|
+
if (autoFocus) {
|
|
992
|
+
const input = document.querySelector("input");
|
|
993
|
+
if (input) {
|
|
994
|
+
input.focus();
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}, [
|
|
998
|
+
autoFocus
|
|
999
|
+
]);
|
|
1000
|
+
return /* @__PURE__ */ import_react8.default.createElement(FormProvider, {
|
|
766
1001
|
schema,
|
|
767
1002
|
initialValues,
|
|
768
1003
|
onValuesChanged,
|
|
769
1004
|
onValidate,
|
|
770
1005
|
onValid,
|
|
771
1006
|
onSave
|
|
772
|
-
}, /* @__PURE__ */
|
|
1007
|
+
}, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
773
1008
|
role: "none",
|
|
774
|
-
className: (0,
|
|
1009
|
+
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
775
1010
|
"data-testid": testId
|
|
776
|
-
}, /* @__PURE__ */
|
|
1011
|
+
}, /* @__PURE__ */ import_react8.default.createElement(FormFields, {
|
|
777
1012
|
schema,
|
|
778
1013
|
path,
|
|
779
1014
|
readonly,
|
|
@@ -781,7 +1016,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
781
1016
|
sort,
|
|
782
1017
|
lookupComponent,
|
|
783
1018
|
Custom
|
|
784
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1019
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react8.default.createElement(FormActions, {
|
|
785
1020
|
onCancel,
|
|
786
1021
|
readonly
|
|
787
1022
|
})));
|
|
@@ -851,7 +1086,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
851
1086
|
type
|
|
852
1087
|
};
|
|
853
1088
|
}
|
|
854
|
-
return
|
|
1089
|
+
return _props;
|
|
855
1090
|
});
|
|
856
1091
|
}, [
|
|
857
1092
|
schemas,
|
|
@@ -907,7 +1142,8 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
907
1142
|
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
908
1143
|
value: p.name
|
|
909
1144
|
})) : []
|
|
910
|
-
})
|
|
1145
|
+
}),
|
|
1146
|
+
["options"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectOptionInput, props2)
|
|
911
1147
|
}), [
|
|
912
1148
|
t,
|
|
913
1149
|
schemas,
|
|
@@ -919,7 +1155,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
919
1155
|
props
|
|
920
1156
|
}, {
|
|
921
1157
|
F: __dxlog_file3,
|
|
922
|
-
L:
|
|
1158
|
+
L: 174,
|
|
923
1159
|
S: void 0,
|
|
924
1160
|
C: (f, a) => f(...a)
|
|
925
1161
|
});
|
|
@@ -952,13 +1188,13 @@ var ViewMetaSchema = import_echo_schema7.S.Struct({
|
|
|
952
1188
|
})
|
|
953
1189
|
}).pipe(import_echo_schema7.S.mutable);
|
|
954
1190
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
955
|
-
const { t } = (0,
|
|
956
|
-
const projection = (0,
|
|
1191
|
+
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1192
|
+
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
957
1193
|
schema,
|
|
958
1194
|
view
|
|
959
1195
|
]);
|
|
960
|
-
const [field, setField] = (0,
|
|
961
|
-
const viewValues = (0,
|
|
1196
|
+
const [field, setField] = (0, import_react14.useState)();
|
|
1197
|
+
const viewValues = (0, import_react14.useMemo)(() => {
|
|
962
1198
|
return {
|
|
963
1199
|
name: view.name,
|
|
964
1200
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -968,7 +1204,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
968
1204
|
}, [
|
|
969
1205
|
view
|
|
970
1206
|
]);
|
|
971
|
-
const handleViewUpdate = (0,
|
|
1207
|
+
const handleViewUpdate = (0, import_react14.useCallback)(({ name, typename }) => {
|
|
972
1208
|
requestAnimationFrame(() => {
|
|
973
1209
|
if (view.name !== name) {
|
|
974
1210
|
view.name = name;
|
|
@@ -982,67 +1218,72 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
982
1218
|
schema,
|
|
983
1219
|
onTypenameChanged
|
|
984
1220
|
]);
|
|
985
|
-
const handleSelect = (0,
|
|
1221
|
+
const handleSelect = (0, import_react14.useCallback)((field2) => {
|
|
986
1222
|
setField((f) => f === field2 ? void 0 : field2);
|
|
987
1223
|
}, []);
|
|
988
|
-
const handleAdd = (0,
|
|
1224
|
+
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
989
1225
|
const field2 = projection.createFieldProjection();
|
|
990
1226
|
setField(field2);
|
|
991
1227
|
}, [
|
|
992
1228
|
view
|
|
993
1229
|
]);
|
|
994
|
-
const handleMove = (0,
|
|
995
|
-
|
|
1230
|
+
const handleMove = (0, import_react14.useCallback)((fromIndex, toIndex) => {
|
|
1231
|
+
const fields = [
|
|
1232
|
+
...view.fields
|
|
1233
|
+
];
|
|
1234
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
1235
|
+
fields.splice(toIndex, 0, moved);
|
|
1236
|
+
view.fields = fields;
|
|
996
1237
|
}, [
|
|
997
1238
|
view.fields
|
|
998
1239
|
]);
|
|
999
|
-
const handleClose = (0,
|
|
1000
|
-
return /* @__PURE__ */
|
|
1240
|
+
const handleClose = (0, import_react14.useCallback)(() => setField(void 0), []);
|
|
1241
|
+
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1001
1242
|
role: "none",
|
|
1002
|
-
className: (0,
|
|
1003
|
-
}, /* @__PURE__ */
|
|
1243
|
+
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1244
|
+
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
1004
1245
|
autoFocus: true,
|
|
1005
1246
|
autoSave: true,
|
|
1006
1247
|
schema: ViewMetaSchema,
|
|
1007
1248
|
values: viewValues,
|
|
1008
1249
|
onSave: handleViewUpdate
|
|
1009
|
-
}), /* @__PURE__ */
|
|
1250
|
+
}), /* @__PURE__ */ import_react14.default.createElement("div", null, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1010
1251
|
role: "none",
|
|
1011
1252
|
className: "p-2"
|
|
1012
|
-
}, /* @__PURE__ */
|
|
1013
|
-
className: (0,
|
|
1014
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1253
|
+
}, /* @__PURE__ */ import_react14.default.createElement("label", {
|
|
1254
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1255
|
+
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1015
1256
|
items: view.fields,
|
|
1016
1257
|
isItem: import_echo_schema7.S.is(import_schema5.FieldSchema),
|
|
1017
1258
|
getId: (field2) => field2.id,
|
|
1018
1259
|
onMove: handleMove
|
|
1019
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1260
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1020
1261
|
role: "heading",
|
|
1021
1262
|
className: grid
|
|
1022
|
-
}, /* @__PURE__ */
|
|
1263
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", null), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1023
1264
|
className: "flex items-center text-sm"
|
|
1024
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1265
|
+
}, t("field path label"))), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1025
1266
|
role: "list",
|
|
1026
1267
|
className: "flex flex-col w-full"
|
|
1027
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1268
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Item, {
|
|
1028
1269
|
key: field2.id,
|
|
1029
1270
|
item: field2,
|
|
1030
|
-
classNames: (0,
|
|
1031
|
-
}, /* @__PURE__ */
|
|
1271
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1272
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1032
1273
|
onClick: () => handleSelect(field2)
|
|
1033
|
-
}, field2.path), /* @__PURE__ */
|
|
1274
|
+
}, field2.path), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1034
1275
|
disabled: view.fields.length <= 1,
|
|
1035
1276
|
onClick: () => onDelete(field2.id)
|
|
1036
|
-
}))))))), field && /* @__PURE__ */
|
|
1277
|
+
}))))))), field && /* @__PURE__ */ import_react14.default.createElement(FieldEditor, {
|
|
1037
1278
|
key: field.id,
|
|
1038
1279
|
view,
|
|
1039
1280
|
projection,
|
|
1040
1281
|
field,
|
|
1041
1282
|
registry,
|
|
1042
1283
|
onSave: handleClose
|
|
1043
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1284
|
+
}), !readonly && !field && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1044
1285
|
className: "flex p-2 justify-center"
|
|
1045
|
-
}, /* @__PURE__ */
|
|
1286
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1046
1287
|
icon: "ph--plus--regular",
|
|
1047
1288
|
label: t("button add property"),
|
|
1048
1289
|
onClick: handleAdd,
|
|
@@ -1267,6 +1508,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1267
1508
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1268
1509
|
0 && (module.exports = {
|
|
1269
1510
|
BooleanInput,
|
|
1511
|
+
DeprecatedFormContainer,
|
|
1270
1512
|
DeprecatedFormInput,
|
|
1271
1513
|
FieldEditor,
|
|
1272
1514
|
Form,
|
|
@@ -1274,6 +1516,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1274
1516
|
InputHeader,
|
|
1275
1517
|
NumberInput,
|
|
1276
1518
|
SelectInput,
|
|
1519
|
+
SelectOptionInput,
|
|
1277
1520
|
TextInput,
|
|
1278
1521
|
TupleInput,
|
|
1279
1522
|
ViewEditor,
|