@dxos/react-ui-form 0.7.5-labs.e27f9b9 → 0.7.5-main.2567c87
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 +467 -726
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +506 -750
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +467 -726
- 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 +6 -5
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +21 -12
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +1 -2
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +6 -5
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +2 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +2 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/index.d.ts +0 -1
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +2 -2
- package/dist/types/src/components/Form/factory.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 +0 -5
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +11 -10
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +0 -6
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +27 -28
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.tsx +6 -7
- package/src/components/Form/Defaults.tsx +33 -20
- package/src/components/Form/Form.stories.tsx +5 -15
- package/src/components/Form/Form.tsx +355 -46
- package/src/components/Form/Input.tsx +6 -5
- package/src/components/Form/custom/GeoPointInput.tsx +15 -6
- package/src/components/Form/custom/TupleInput.tsx +9 -5
- package/src/components/Form/custom/index.ts +0 -1
- package/src/components/Form/factory.tsx +5 -2
- package/src/components/ViewEditor/ViewEditor.tsx +2 -5
- package/src/components/deprecated/FormInput.tsx +7 -20
- package/src/hooks/useForm.ts +49 -57
- package/src/translations.ts +0 -8
- package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
- package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormActions.d.ts +0 -7
- package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContent.d.ts +0 -26
- package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContext.d.ts +0 -20
- package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -7
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
- package/src/components/Form/ArrayField.tsx +0 -111
- package/src/components/Form/FormActions.tsx +0 -41
- package/src/components/Form/FormContent.tsx +0 -173
- package/src/components/Form/FormContext.tsx +0 -48
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +0 -58
- package/src/components/Form/custom/SelectOptionsInput.tsx +0 -192
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,15 +29,14 @@ 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,
|
|
33
32
|
DeprecatedFormInput: () => DeprecatedFormInput,
|
|
34
33
|
FieldEditor: () => FieldEditor,
|
|
35
34
|
Form: () => Form,
|
|
35
|
+
FormActions: () => FormActions,
|
|
36
36
|
GeoPointInput: () => GeoPointInput,
|
|
37
37
|
InputHeader: () => InputHeader,
|
|
38
38
|
NumberInput: () => NumberInput,
|
|
39
39
|
SelectInput: () => SelectInput,
|
|
40
|
-
SelectOptionInput: () => SelectOptionInput,
|
|
41
40
|
TextInput: () => TextInput,
|
|
42
41
|
TupleInput: () => TupleInput,
|
|
43
42
|
ViewEditor: () => ViewEditor,
|
|
@@ -53,7 +52,6 @@ __export(node_exports, {
|
|
|
53
52
|
module.exports = __toCommonJS(node_exports);
|
|
54
53
|
var import_react = __toESM(require("react"));
|
|
55
54
|
var import_react_ui = require("@dxos/react-ui");
|
|
56
|
-
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
57
55
|
var import_react2 = __toESM(require("react"));
|
|
58
56
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
59
57
|
var import_log = require("@dxos/log");
|
|
@@ -64,60 +62,38 @@ var import_react_ui3 = require("@dxos/react-ui");
|
|
|
64
62
|
var import_util = require("@dxos/util");
|
|
65
63
|
var import_react4 = __toESM(require("react"));
|
|
66
64
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
67
|
-
var
|
|
65
|
+
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
68
66
|
var import_react5 = __toESM(require("react"));
|
|
69
|
-
var import_keys = require("@dxos/keys");
|
|
70
67
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
68
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
69
|
+
var import_util2 = require("@dxos/util");
|
|
74
70
|
var import_react6 = __toESM(require("react"));
|
|
75
71
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
76
|
-
var
|
|
77
|
-
var
|
|
72
|
+
var import_effect = require("effect");
|
|
73
|
+
var import_String = require("effect/String");
|
|
78
74
|
var import_react7 = __toESM(require("react"));
|
|
79
|
-
var import_react_ui7 = require("@dxos/react-ui");
|
|
80
|
-
var import_react8 = __toESM(require("react"));
|
|
81
|
-
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
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"));
|
|
86
|
-
var import_debug = require("@dxos/debug");
|
|
87
75
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
88
|
-
var import_effect = require("@dxos/effect");
|
|
89
|
-
var import_react11 = require("react");
|
|
90
|
-
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
91
76
|
var import_effect2 = require("@dxos/effect");
|
|
92
|
-
var import_invariant = require("@dxos/invariant");
|
|
93
77
|
var import_log2 = require("@dxos/log");
|
|
78
|
+
var import_react_ui7 = require("@dxos/react-ui");
|
|
79
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
94
80
|
var import_schema2 = require("@dxos/schema");
|
|
95
|
-
var
|
|
96
|
-
var
|
|
97
|
-
var
|
|
81
|
+
var import_util3 = require("@dxos/util");
|
|
82
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
83
|
+
var import_react8 = require("react");
|
|
98
84
|
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
99
|
-
var
|
|
100
|
-
var
|
|
85
|
+
var import_invariant = require("@dxos/invariant");
|
|
86
|
+
var import_log3 = require("@dxos/log");
|
|
101
87
|
var import_schema3 = require("@dxos/schema");
|
|
102
|
-
var
|
|
103
|
-
var import_effect5 = require("effect");
|
|
104
|
-
var import_String2 = require("effect/String");
|
|
105
|
-
var import_react13 = __toESM(require("react"));
|
|
88
|
+
var import_react9 = __toESM(require("react"));
|
|
106
89
|
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
var
|
|
110
|
-
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
90
|
+
var import_react_ui8 = require("@dxos/react-ui");
|
|
91
|
+
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
92
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
111
93
|
var import_schema4 = require("@dxos/schema");
|
|
94
|
+
var import_util4 = require("@dxos/util");
|
|
112
95
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
113
|
-
var import_react14 = __toESM(require("react"));
|
|
114
96
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
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");
|
|
118
|
-
var import_schema5 = require("@dxos/schema");
|
|
119
|
-
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
120
|
-
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
121
97
|
var translationKey = "react-ui-form";
|
|
122
98
|
var translations_default = [
|
|
123
99
|
{
|
|
@@ -154,7 +130,6 @@ var translations_default = [
|
|
|
154
130
|
"format ref": "Reference",
|
|
155
131
|
"format regex": "RegExp",
|
|
156
132
|
"format string": "String",
|
|
157
|
-
"format single-select": "Select",
|
|
158
133
|
"format text": "Long text",
|
|
159
134
|
"format time": "Time",
|
|
160
135
|
"format timestamp": "Timestamp",
|
|
@@ -164,26 +139,11 @@ var translations_default = [
|
|
|
164
139
|
"format uuid": "UUID",
|
|
165
140
|
// Placeholders
|
|
166
141
|
"placeholder latitude": "Latitude",
|
|
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"
|
|
142
|
+
"placeholder longitude": "Longitude"
|
|
174
143
|
}
|
|
175
144
|
}
|
|
176
145
|
}
|
|
177
146
|
];
|
|
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
|
-
};
|
|
187
147
|
var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
188
148
|
const primary = /* @__PURE__ */ import_react.default.createElement("div", {
|
|
189
149
|
role: "none",
|
|
@@ -192,21 +152,19 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
192
152
|
role: "none",
|
|
193
153
|
className: "flex flex-col w-full"
|
|
194
154
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Label, {
|
|
195
|
-
classNames: "flex min-
|
|
196
|
-
style: {
|
|
197
|
-
fontSize: "unset"
|
|
198
|
-
}
|
|
155
|
+
classNames: "flex min-h-[40px] items-center"
|
|
199
156
|
}, label), description && /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.DescriptionAndValidation, {
|
|
200
157
|
classNames: "mbs-0.5"
|
|
201
158
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Description, null, description))), /* @__PURE__ */ import_react.default.createElement("div", {
|
|
202
159
|
role: "none"
|
|
203
160
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
204
161
|
role: "none",
|
|
205
|
-
className: "flex min-
|
|
162
|
+
className: "flex min-h-[40px] items-center"
|
|
206
163
|
}, children))));
|
|
207
164
|
if (secondary) {
|
|
208
165
|
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
209
|
-
role: "none"
|
|
166
|
+
role: "none",
|
|
167
|
+
className: "flex flex-col w-full"
|
|
210
168
|
}, primary, secondary);
|
|
211
169
|
}
|
|
212
170
|
return primary;
|
|
@@ -220,15 +178,15 @@ var InputHeader = ({ children, error }) => {
|
|
|
220
178
|
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Icon, {
|
|
221
179
|
icon: "ph--warning--regular",
|
|
222
180
|
size: 4,
|
|
223
|
-
classNames:
|
|
181
|
+
classNames: import_react_ui_theme.errorText
|
|
224
182
|
})), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
225
183
|
side: "bottom"
|
|
226
184
|
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
227
185
|
};
|
|
228
|
-
var GeoPointInput = ({ type, label, disabled, getStatus, getValue:
|
|
186
|
+
var GeoPointInput = ({ property, type, label, disabled, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
229
187
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
230
|
-
const { status, error } = getStatus();
|
|
231
|
-
const [lng = 0, lat = 0] =
|
|
188
|
+
const { status, error } = getStatus?.(property);
|
|
189
|
+
const [lng = 0, lat = 0] = getValue2(property) ?? [];
|
|
232
190
|
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Root, {
|
|
233
191
|
validationValence: status
|
|
234
192
|
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, {
|
|
@@ -240,7 +198,7 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
240
198
|
disabled,
|
|
241
199
|
placeholder: t("placeholder longitude"),
|
|
242
200
|
value: lng,
|
|
243
|
-
onChange: (event) => onValueChange(type, [
|
|
201
|
+
onChange: (event) => onValueChange(property, type, [
|
|
244
202
|
lat,
|
|
245
203
|
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
246
204
|
]),
|
|
@@ -250,299 +208,129 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
250
208
|
disabled,
|
|
251
209
|
placeholder: t("placeholder latitude"),
|
|
252
210
|
value: lat,
|
|
253
|
-
onChange: (event) => onValueChange(type, [
|
|
211
|
+
onChange: (event) => onValueChange(property, type, [
|
|
254
212
|
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
255
213
|
lng
|
|
256
214
|
]),
|
|
257
215
|
onBlur
|
|
258
216
|
})));
|
|
259
217
|
};
|
|
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
|
-
};
|
|
435
218
|
var gridCols = [
|
|
436
219
|
"grid-cols-1",
|
|
437
220
|
"grid-cols-2",
|
|
438
221
|
"grid-cols-3",
|
|
439
222
|
"grid-cols-4"
|
|
440
223
|
];
|
|
441
|
-
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue:
|
|
442
|
-
const { status, error } = getStatus();
|
|
443
|
-
const values =
|
|
444
|
-
return /* @__PURE__ */
|
|
224
|
+
var TupleInput = ({ binding, property, type, label, disabled, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
225
|
+
const { status, error } = getStatus?.(property);
|
|
226
|
+
const values = getValue2(property) ?? {};
|
|
227
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Root, {
|
|
445
228
|
validationValence: status
|
|
446
|
-
}, /* @__PURE__ */
|
|
229
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
447
230
|
error
|
|
448
|
-
}, /* @__PURE__ */
|
|
449
|
-
className: (0,
|
|
450
|
-
}, binding.map((prop) => /* @__PURE__ */
|
|
231
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
232
|
+
className: (0, import_react_ui_theme2.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
233
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.TextInput, {
|
|
451
234
|
key: prop,
|
|
452
235
|
type: "number",
|
|
453
236
|
disabled,
|
|
454
237
|
value: values[prop],
|
|
455
|
-
onChange: (event) => onValueChange(type, {
|
|
238
|
+
onChange: (event) => onValueChange(property, type, {
|
|
456
239
|
...values,
|
|
457
240
|
[prop]: (0, import_util2.safeParseFloat)(event.target.value, 0)
|
|
458
241
|
}),
|
|
459
242
|
onBlur
|
|
460
243
|
}))));
|
|
461
244
|
};
|
|
462
|
-
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue:
|
|
463
|
-
const { status, error } = getStatus();
|
|
464
|
-
return /* @__PURE__ */
|
|
245
|
+
var TextInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
246
|
+
const { status, error } = getStatus?.(property);
|
|
247
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
465
248
|
validationValence: status
|
|
466
|
-
}, !inputOnly && /* @__PURE__ */
|
|
249
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
467
250
|
error
|
|
468
|
-
}, /* @__PURE__ */
|
|
251
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
469
252
|
disabled,
|
|
470
253
|
placeholder,
|
|
471
|
-
value:
|
|
472
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
254
|
+
value: getValue2(property) ?? "",
|
|
255
|
+
onChange: (event) => onValueChange(property, type, event.target.value),
|
|
473
256
|
onBlur
|
|
474
|
-
}), inputOnly && /* @__PURE__ */
|
|
257
|
+
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Validation, null, error));
|
|
475
258
|
};
|
|
476
|
-
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue:
|
|
477
|
-
const { status, error } = getStatus();
|
|
478
|
-
return /* @__PURE__ */
|
|
259
|
+
var NumberInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
260
|
+
const { status, error } = getStatus?.(property);
|
|
261
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
479
262
|
validationValence: status
|
|
480
|
-
}, !inputOnly && /* @__PURE__ */
|
|
263
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
481
264
|
error
|
|
482
|
-
}, /* @__PURE__ */
|
|
265
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
483
266
|
type: "number",
|
|
484
267
|
disabled,
|
|
485
268
|
placeholder,
|
|
486
|
-
value:
|
|
487
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
269
|
+
value: getValue2(property) ?? 0,
|
|
270
|
+
onChange: (event) => onValueChange(property, type, event.target.value),
|
|
488
271
|
onBlur
|
|
489
|
-
}), inputOnly && /* @__PURE__ */
|
|
272
|
+
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
490
273
|
};
|
|
491
|
-
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue:
|
|
492
|
-
const { status, error } = getStatus();
|
|
493
|
-
return /* @__PURE__ */
|
|
274
|
+
var BooleanInput = ({ property, type, label, inputOnly, getStatus, getValue: getValue2, onValueChange }) => {
|
|
275
|
+
const { status, error } = getStatus?.(property);
|
|
276
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
494
277
|
validationValence: status
|
|
495
|
-
}, !inputOnly && /* @__PURE__ */
|
|
278
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
496
279
|
error
|
|
497
|
-
}, /* @__PURE__ */
|
|
498
|
-
checked:
|
|
499
|
-
onCheckedChange: (value) => onValueChange(type, value)
|
|
500
|
-
}), inputOnly && /* @__PURE__ */
|
|
280
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Switch, {
|
|
281
|
+
checked: getValue2(property),
|
|
282
|
+
onCheckedChange: (value) => onValueChange(property, type, value)
|
|
283
|
+
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
501
284
|
};
|
|
502
|
-
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue:
|
|
503
|
-
const { status, error } = getStatus();
|
|
504
|
-
return /* @__PURE__ */
|
|
285
|
+
var SelectInput = ({ property, type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue2, onValueChange }) => {
|
|
286
|
+
const { status, error } = getStatus?.(property);
|
|
287
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
505
288
|
validationValence: status
|
|
506
|
-
}, !inputOnly && /* @__PURE__ */
|
|
289
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
507
290
|
error
|
|
508
|
-
}, /* @__PURE__ */
|
|
509
|
-
value:
|
|
510
|
-
onValueChange: (value) => onValueChange(type, value)
|
|
511
|
-
}, /* @__PURE__ */
|
|
291
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Root, {
|
|
292
|
+
value: getValue2(property),
|
|
293
|
+
onValueChange: (value) => onValueChange(property, type, value)
|
|
294
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.TriggerButton, {
|
|
512
295
|
classNames: "is-full",
|
|
513
296
|
disabled,
|
|
514
297
|
placeholder
|
|
515
|
-
}), /* @__PURE__ */
|
|
298
|
+
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Portal, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
516
299
|
// NOTE: Numeric values are converted to and from strings.
|
|
517
|
-
/* @__PURE__ */
|
|
300
|
+
/* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Option, {
|
|
518
301
|
key: String(value),
|
|
519
302
|
value: String(value)
|
|
520
303
|
}, label2 ?? String(value))
|
|
521
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
304
|
+
)))))), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
305
|
+
};
|
|
306
|
+
var getInputComponent = (type, format) => {
|
|
307
|
+
switch (format) {
|
|
308
|
+
case import_echo_schema3.FormatEnum.LatLng:
|
|
309
|
+
return GeoPointInput;
|
|
310
|
+
}
|
|
311
|
+
switch (type) {
|
|
312
|
+
case "string":
|
|
313
|
+
return TextInput;
|
|
314
|
+
case "number":
|
|
315
|
+
return NumberInput;
|
|
316
|
+
case "boolean":
|
|
317
|
+
return BooleanInput;
|
|
318
|
+
}
|
|
522
319
|
};
|
|
523
320
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
524
321
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
525
|
-
(0,
|
|
526
|
-
|
|
527
|
-
L: 91,
|
|
528
|
-
S: void 0,
|
|
529
|
-
A: [
|
|
530
|
-
"AST.isTypeLiteral(schema.ast)",
|
|
531
|
-
""
|
|
532
|
-
]
|
|
533
|
-
});
|
|
534
|
-
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
535
|
-
(0, import_react11.useEffect)(() => {
|
|
322
|
+
const [values, setValues] = (0, import_react8.useState)(initialValues);
|
|
323
|
+
(0, import_react8.useEffect)(() => {
|
|
536
324
|
setValues(initialValues);
|
|
537
325
|
}, [
|
|
538
326
|
initialValues
|
|
539
327
|
]);
|
|
540
|
-
const [touched, setTouched] = (0,
|
|
541
|
-
const [changed, setChanged] = (0,
|
|
542
|
-
const [errors, setErrors] = (0,
|
|
543
|
-
const [saving, setSaving] = (0,
|
|
544
|
-
const validate = (0,
|
|
545
|
-
let errors2 = (0,
|
|
328
|
+
const [touched, setTouched] = (0, import_react8.useState)(createKeySet(initialValues, false));
|
|
329
|
+
const [changed, setChanged] = (0, import_react8.useState)(createKeySet(initialValues, false));
|
|
330
|
+
const [errors, setErrors] = (0, import_react8.useState)({});
|
|
331
|
+
const [saving, setSaving] = (0, import_react8.useState)(false);
|
|
332
|
+
const validate = (0, import_react8.useCallback)((values2) => {
|
|
333
|
+
let errors2 = (0, import_schema3.validateSchema)(schema, values2) ?? [];
|
|
546
334
|
if (errors2.length === 0 && onValidate) {
|
|
547
335
|
const validatedValues = values2;
|
|
548
336
|
errors2 = onValidate(validatedValues) ?? [];
|
|
@@ -554,11 +342,11 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
554
342
|
schema,
|
|
555
343
|
onValidate
|
|
556
344
|
]);
|
|
557
|
-
const [schemaDirty, setSchemaDirty] = (0,
|
|
558
|
-
(0,
|
|
345
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react8.useState)(false);
|
|
346
|
+
(0, import_react8.useEffect)(() => setSchemaDirty(true), [
|
|
559
347
|
schema
|
|
560
348
|
]);
|
|
561
|
-
(0,
|
|
349
|
+
(0, import_react8.useEffect)(() => {
|
|
562
350
|
if (schemaDirty) {
|
|
563
351
|
validate(values);
|
|
564
352
|
setSchemaDirty(false);
|
|
@@ -567,13 +355,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
567
355
|
values,
|
|
568
356
|
schemaDirty
|
|
569
357
|
]);
|
|
570
|
-
const canSave = (0,
|
|
571
|
-
|
|
358
|
+
const canSave = (0, import_react8.useMemo)(() => !saving && Object.keys(values).every((property) => touched[property] === false || !errors[property]), [
|
|
359
|
+
values,
|
|
572
360
|
touched,
|
|
573
361
|
errors,
|
|
574
362
|
saving
|
|
575
363
|
]);
|
|
576
|
-
const handleSave = (0,
|
|
364
|
+
const handleSave = (0, import_react8.useCallback)(async () => {
|
|
577
365
|
if (validate(values)) {
|
|
578
366
|
setSaving(true);
|
|
579
367
|
try {
|
|
@@ -590,42 +378,38 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
590
378
|
onSave,
|
|
591
379
|
changed
|
|
592
380
|
]);
|
|
593
|
-
const getStatus = (0,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
error: matchingError ? matchingError[1] : void 0
|
|
599
|
-
};
|
|
600
|
-
}, [
|
|
381
|
+
const getStatus = (0, import_react8.useCallback)((property) => ({
|
|
382
|
+
status: errors[property] ? "error" : void 0,
|
|
383
|
+
error: errors[property] ? errors[property] : void 0
|
|
384
|
+
}), [
|
|
385
|
+
touched,
|
|
601
386
|
errors
|
|
602
387
|
]);
|
|
603
|
-
const getFormValue = (
|
|
604
|
-
return (0,
|
|
388
|
+
const getFormValue = (property) => {
|
|
389
|
+
return (0, import_echo_schema4.getValue)(values, property);
|
|
605
390
|
};
|
|
606
|
-
const onValueChange = (
|
|
607
|
-
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
391
|
+
const onValueChange = (property, type, value) => {
|
|
608
392
|
let parsedValue = value;
|
|
609
393
|
try {
|
|
610
394
|
if (type === "number") {
|
|
611
395
|
parsedValue = parseFloat(value) || 0;
|
|
612
396
|
}
|
|
613
397
|
} catch (err) {
|
|
614
|
-
|
|
398
|
+
import_log3.log.catch(err, void 0, {
|
|
615
399
|
F: __dxlog_file,
|
|
616
|
-
L:
|
|
400
|
+
L: 178,
|
|
617
401
|
S: void 0,
|
|
618
402
|
C: (f, a) => f(...a)
|
|
619
403
|
});
|
|
620
404
|
parsedValue = void 0;
|
|
621
405
|
}
|
|
622
406
|
const newValues = {
|
|
623
|
-
...(0,
|
|
407
|
+
...(0, import_echo_schema4.setValue)(values, property, parsedValue)
|
|
624
408
|
};
|
|
625
409
|
setValues(newValues);
|
|
626
410
|
setChanged((prev) => ({
|
|
627
411
|
...prev,
|
|
628
|
-
[
|
|
412
|
+
[property]: true
|
|
629
413
|
}));
|
|
630
414
|
onValuesChanged?.(newValues);
|
|
631
415
|
const isValid = validate(newValues);
|
|
@@ -635,12 +419,15 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
635
419
|
});
|
|
636
420
|
}
|
|
637
421
|
};
|
|
638
|
-
const
|
|
639
|
-
const
|
|
422
|
+
const onBlur = (0, import_react8.useCallback)((event) => {
|
|
423
|
+
const { name } = event.target;
|
|
640
424
|
setTouched((touched2) => ({
|
|
641
425
|
...touched2,
|
|
642
|
-
[
|
|
426
|
+
[name]: true
|
|
643
427
|
}));
|
|
428
|
+
if (event.relatedTarget?.getAttribute("type") === "submit") {
|
|
429
|
+
setTouched(createKeySet(values, true));
|
|
430
|
+
}
|
|
644
431
|
validate(values);
|
|
645
432
|
}, [
|
|
646
433
|
validate,
|
|
@@ -658,13 +445,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
658
445
|
getStatus,
|
|
659
446
|
getValue: getFormValue,
|
|
660
447
|
onValueChange,
|
|
661
|
-
|
|
448
|
+
onBlur
|
|
662
449
|
};
|
|
663
450
|
};
|
|
664
451
|
var createKeySet = (obj, value) => {
|
|
665
452
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
666
453
|
F: __dxlog_file,
|
|
667
|
-
L:
|
|
454
|
+
L: 229,
|
|
668
455
|
S: void 0,
|
|
669
456
|
A: [
|
|
670
457
|
"obj",
|
|
@@ -678,346 +465,322 @@ var createKeySet = (obj, value) => {
|
|
|
678
465
|
};
|
|
679
466
|
var flatMap = (errors) => {
|
|
680
467
|
return errors.reduce((result, { path, message }) => {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
result[jsonPath] = message;
|
|
468
|
+
if (!(path in result)) {
|
|
469
|
+
result[path] = message;
|
|
684
470
|
}
|
|
685
471
|
return result;
|
|
686
472
|
}, {});
|
|
687
473
|
};
|
|
688
|
-
var
|
|
689
|
-
var useFormContext = () => {
|
|
690
|
-
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
691
|
-
};
|
|
692
|
-
var useFormValues = (path = []) => {
|
|
693
|
-
const { values: formValues } = useFormContext();
|
|
694
|
-
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
695
|
-
return (0, import_echo_schema2.getValue)(formValues, jsonPath);
|
|
696
|
-
};
|
|
697
|
-
var useInputProps = (path = []) => {
|
|
698
|
-
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
699
|
-
return {
|
|
700
|
-
getStatus: () => getStatus(path),
|
|
701
|
-
getValue: () => getFormValue(path),
|
|
702
|
-
onValueChange: (type, value) => onValueChange(path, type, value),
|
|
703
|
-
onBlur: () => onTouched(path)
|
|
704
|
-
};
|
|
705
|
-
};
|
|
706
|
-
var FormProvider = ({ children, ...formOptions }) => {
|
|
707
|
-
const formHandler = useForm(formOptions);
|
|
708
|
-
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
709
|
-
value: formHandler
|
|
710
|
-
}, children);
|
|
711
|
-
};
|
|
712
|
-
var FormActions = ({ onCancel, readonly }) => {
|
|
713
|
-
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
714
|
-
const { canSave, handleSave } = useFormContext();
|
|
715
|
-
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
716
|
-
role: "none",
|
|
717
|
-
className: "flex justify-center"
|
|
718
|
-
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
719
|
-
role: "none",
|
|
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, {
|
|
722
|
-
"data-testid": "cancel-button",
|
|
723
|
-
icon: "ph--x--regular",
|
|
724
|
-
label: t("button cancel"),
|
|
725
|
-
onClick: onCancel
|
|
726
|
-
}), handleSave && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
727
|
-
type: "submit",
|
|
728
|
-
"data-testid": "save-button",
|
|
729
|
-
disabled: !canSave,
|
|
730
|
-
icon: "ph--check--regular",
|
|
731
|
-
label: t("button save"),
|
|
732
|
-
onClick: handleSave
|
|
733
|
-
})));
|
|
734
|
-
};
|
|
735
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
474
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
|
|
736
475
|
var padding = "px-2";
|
|
737
|
-
var
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
742
|
-
F: __dxlog_file2,
|
|
743
|
-
L: 37,
|
|
744
|
-
S: void 0,
|
|
745
|
-
A: [
|
|
746
|
-
"Array.isArray(values)",
|
|
747
|
-
"`Values at path ${path?.join('.')} must be an array.`"
|
|
748
|
-
]
|
|
749
|
-
});
|
|
750
|
-
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
751
|
-
const tupleType = (0, import_effect6.findNode)(ast, import_echo_schema5.AST.isTupleType);
|
|
752
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
753
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
754
|
-
const baseNode = (0, import_effect6.findNode)(typeNode, import_effect6.isDiscriminatedUnion);
|
|
755
|
-
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode, import_echo_schema5.AST.isTypeLiteral);
|
|
756
|
-
if (!typeLiteral) {
|
|
757
|
-
return {};
|
|
758
|
-
}
|
|
759
|
-
return Object.fromEntries((0, import_schema4.getSchemaProperties)(typeLiteral, {}).map((prop) => [
|
|
760
|
-
prop.name,
|
|
761
|
-
prop.defaultValue
|
|
762
|
-
]));
|
|
763
|
-
};
|
|
764
|
-
const newValue = (0, import_react13.useMemo)(() => {
|
|
765
|
-
if (type === "object" && elementType) {
|
|
766
|
-
return getDefaultObjectValue(elementType);
|
|
767
|
-
} else {
|
|
768
|
-
return import_effect6.SimpleType.getDefaultValue(type);
|
|
769
|
-
}
|
|
770
|
-
}, [
|
|
771
|
-
type,
|
|
772
|
-
elementType
|
|
476
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
477
|
+
const onValid = (0, import_react7.useMemo)(() => autoSave ? onSave : void 0, [
|
|
478
|
+
autoSave,
|
|
479
|
+
onSave
|
|
773
480
|
]);
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
481
|
+
const { canSave, values, errors, handleSave, ...inputProps } = useForm({
|
|
482
|
+
schema,
|
|
483
|
+
initialValues,
|
|
484
|
+
onValuesChanged,
|
|
485
|
+
onValidate,
|
|
486
|
+
onValid,
|
|
487
|
+
onSave
|
|
488
|
+
});
|
|
489
|
+
const properties = (0, import_react7.useMemo)(() => {
|
|
490
|
+
const props = (0, import_schema2.getSchemaProperties)(schema.ast, values);
|
|
491
|
+
const filtered = filter ? filter(props) : props;
|
|
492
|
+
const findIndex = (props2, prop) => {
|
|
493
|
+
const idx = props2.findIndex((p) => p === prop);
|
|
494
|
+
return idx === -1 ? Infinity : idx;
|
|
495
|
+
};
|
|
496
|
+
return sort ? filtered.sort(({ name: a }, { name: b }) => findIndex(sort, a) - findIndex(sort, b)) : filtered;
|
|
779
497
|
}, [
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
inputProps,
|
|
783
|
-
newValue,
|
|
498
|
+
schema,
|
|
499
|
+
filter,
|
|
784
500
|
values
|
|
785
501
|
]);
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
502
|
+
(0, import_react7.useEffect)(() => {
|
|
503
|
+
if (errors && Object.keys(errors).length) {
|
|
504
|
+
import_log2.log.warn("validation", {
|
|
505
|
+
errors
|
|
506
|
+
}, {
|
|
507
|
+
F: __dxlog_file2,
|
|
508
|
+
L: 106,
|
|
509
|
+
S: void 0,
|
|
510
|
+
C: (f, a) => f(...a)
|
|
511
|
+
});
|
|
512
|
+
}
|
|
789
513
|
}, [
|
|
790
|
-
|
|
791
|
-
inputProps,
|
|
792
|
-
values
|
|
514
|
+
errors
|
|
793
515
|
]);
|
|
794
|
-
|
|
516
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
517
|
+
role: "form",
|
|
518
|
+
className: (0, import_react_ui_theme3.mx)("flex flex-col w-full gap-2 py-2", classNames),
|
|
519
|
+
"data-testid": testId
|
|
520
|
+
}, properties.map((property) => {
|
|
521
|
+
const { ast, name, type, format, title, description, examples, options, array } = property;
|
|
522
|
+
const key = [
|
|
523
|
+
...path,
|
|
524
|
+
name
|
|
525
|
+
];
|
|
526
|
+
const label = title ?? (0, import_effect.pipe)(name, import_String.capitalize);
|
|
527
|
+
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
528
|
+
const FoundComponent = lookupComponent?.({
|
|
529
|
+
prop: name,
|
|
530
|
+
schema: import_echo_schema2.S.make(ast),
|
|
531
|
+
inputProps: {
|
|
532
|
+
property: name,
|
|
533
|
+
type,
|
|
534
|
+
format,
|
|
535
|
+
label,
|
|
536
|
+
disabled: readonly,
|
|
537
|
+
placeholder,
|
|
538
|
+
...inputProps
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
if (FoundComponent) {
|
|
542
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
543
|
+
key: name,
|
|
544
|
+
role: "none",
|
|
545
|
+
className: padding
|
|
546
|
+
}, FoundComponent);
|
|
547
|
+
}
|
|
548
|
+
let InputComponent = Custom?.[key.join(".")];
|
|
549
|
+
if (!InputComponent) {
|
|
550
|
+
if (options) {
|
|
551
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
552
|
+
key: name,
|
|
553
|
+
role: "none",
|
|
554
|
+
className: padding
|
|
555
|
+
}, /* @__PURE__ */ import_react7.default.createElement(SelectInput, {
|
|
556
|
+
type,
|
|
557
|
+
format,
|
|
558
|
+
property: name,
|
|
559
|
+
disabled: readonly,
|
|
560
|
+
label,
|
|
561
|
+
options: options.map((option) => ({
|
|
562
|
+
value: option,
|
|
563
|
+
label: String(option)
|
|
564
|
+
})),
|
|
565
|
+
placeholder,
|
|
566
|
+
...inputProps
|
|
567
|
+
}));
|
|
568
|
+
}
|
|
569
|
+
InputComponent = getInputComponent(type, format);
|
|
570
|
+
if (array) {
|
|
571
|
+
return /* @__PURE__ */ import_react7.default.createElement(ArrayField, {
|
|
572
|
+
key: name,
|
|
573
|
+
name,
|
|
574
|
+
type,
|
|
575
|
+
array: true,
|
|
576
|
+
label,
|
|
577
|
+
ast,
|
|
578
|
+
values,
|
|
579
|
+
format,
|
|
580
|
+
readonly,
|
|
581
|
+
placeholder,
|
|
582
|
+
inputProps,
|
|
583
|
+
Custom
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (!InputComponent) {
|
|
588
|
+
if (type === "object") {
|
|
589
|
+
const baseNode = (0, import_effect2.findNode)(ast, import_effect2.isDiscriminatedUnion);
|
|
590
|
+
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(ast, import_echo_schema2.AST.isTypeLiteral);
|
|
591
|
+
if (typeLiteral) {
|
|
592
|
+
const schema2 = import_echo_schema2.S.make(typeLiteral);
|
|
593
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
594
|
+
key: name,
|
|
595
|
+
role: "none"
|
|
596
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
597
|
+
className: padding
|
|
598
|
+
}, label), /* @__PURE__ */ import_react7.default.createElement(Form, {
|
|
599
|
+
schema: schema2,
|
|
600
|
+
path: key,
|
|
601
|
+
values: values[name] ?? {},
|
|
602
|
+
onValuesChanged: (childValues) => {
|
|
603
|
+
inputProps.onValueChange(name, "object", childValues);
|
|
604
|
+
},
|
|
605
|
+
Custom
|
|
606
|
+
}));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
(0, import_log2.log)("no renderer for property", {
|
|
610
|
+
name,
|
|
611
|
+
type
|
|
612
|
+
}, {
|
|
613
|
+
F: __dxlog_file2,
|
|
614
|
+
L: 213,
|
|
615
|
+
S: void 0,
|
|
616
|
+
C: (f, a) => f(...a)
|
|
617
|
+
});
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
620
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
621
|
+
key: name,
|
|
622
|
+
role: "none",
|
|
623
|
+
className: padding
|
|
624
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputComponent, {
|
|
625
|
+
type,
|
|
626
|
+
format,
|
|
627
|
+
property: name,
|
|
628
|
+
disabled: readonly,
|
|
629
|
+
label,
|
|
630
|
+
placeholder,
|
|
631
|
+
...inputProps
|
|
632
|
+
}));
|
|
633
|
+
}).filter(import_util3.isNotFalsy), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react7.default.createElement(FormActions, {
|
|
634
|
+
onCancel,
|
|
635
|
+
onSubmit: handleSave,
|
|
636
|
+
canSubmit: canSave,
|
|
637
|
+
readonly
|
|
638
|
+
}));
|
|
639
|
+
};
|
|
640
|
+
var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholder, inputProps, Custom }) => {
|
|
641
|
+
const { t } = (0, import_react_ui7.useTranslation)(translationKey);
|
|
642
|
+
const arrayValues = values[name] ?? [];
|
|
643
|
+
const key = [
|
|
644
|
+
name
|
|
645
|
+
];
|
|
646
|
+
const tupleType = (0, import_effect2.findNode)(ast, import_echo_schema2.AST.isTupleType);
|
|
647
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
648
|
+
if (type === "object" && elementType) {
|
|
649
|
+
const baseNode = (0, import_effect2.findNode)(elementType, import_effect2.isDiscriminatedUnion);
|
|
650
|
+
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(elementType, import_echo_schema2.AST.isTypeLiteral);
|
|
651
|
+
if (typeLiteral) {
|
|
652
|
+
const schema = import_echo_schema2.S.make(typeLiteral);
|
|
653
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
654
|
+
key: name,
|
|
655
|
+
role: "none",
|
|
656
|
+
className: (0, import_react_ui_theme3.mx)(padding)
|
|
657
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
658
|
+
role: "none",
|
|
659
|
+
className: "flex flex-col gap-1"
|
|
660
|
+
}, arrayValues.map((value, index) => {
|
|
661
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
662
|
+
key: index,
|
|
663
|
+
role: "none",
|
|
664
|
+
className: "flex items-center gap-1"
|
|
665
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
666
|
+
role: "none",
|
|
667
|
+
className: "flex-1"
|
|
668
|
+
}, /* @__PURE__ */ import_react7.default.createElement(Form, {
|
|
669
|
+
schema,
|
|
670
|
+
path: [
|
|
671
|
+
...key,
|
|
672
|
+
`[${index}]`
|
|
673
|
+
],
|
|
674
|
+
values: value,
|
|
675
|
+
onValuesChanged: (childValues) => {
|
|
676
|
+
const newValues = [
|
|
677
|
+
...arrayValues
|
|
678
|
+
];
|
|
679
|
+
newValues[index] = childValues;
|
|
680
|
+
inputProps.onValueChange(name, "object", newValues);
|
|
681
|
+
},
|
|
682
|
+
Custom
|
|
683
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
684
|
+
icon: "ph--trash--regular",
|
|
685
|
+
iconOnly: true,
|
|
686
|
+
label: t("button remove"),
|
|
687
|
+
onClick: () => {
|
|
688
|
+
const newValues = arrayValues.filter((_, i) => i !== index);
|
|
689
|
+
inputProps.onValueChange(name, type, newValues);
|
|
690
|
+
}
|
|
691
|
+
}));
|
|
692
|
+
})), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
693
|
+
role: "none",
|
|
694
|
+
className: "flex justify-between items-center plb-1"
|
|
695
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
696
|
+
icon: "ph--plus--regular",
|
|
697
|
+
iconOnly: true,
|
|
698
|
+
label: t("button add"),
|
|
699
|
+
onClick: () => {
|
|
700
|
+
const newValues = [
|
|
701
|
+
...arrayValues,
|
|
702
|
+
{}
|
|
703
|
+
];
|
|
704
|
+
inputProps.onValueChange(name, type, newValues);
|
|
705
|
+
}
|
|
706
|
+
})));
|
|
707
|
+
}
|
|
708
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
709
|
+
key: name,
|
|
710
|
+
role: "none"
|
|
711
|
+
}, "Nested form not supported in arrays, yet.");
|
|
712
|
+
}
|
|
713
|
+
const InputComponent = getInputComponent(type, format);
|
|
714
|
+
if (!InputComponent) {
|
|
795
715
|
return null;
|
|
796
716
|
}
|
|
797
|
-
return /* @__PURE__ */
|
|
717
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
798
718
|
role: "none",
|
|
799
|
-
|
|
800
|
-
|
|
719
|
+
key: "meta-input",
|
|
720
|
+
className: (0, import_react_ui_theme3.mx)(padding)
|
|
721
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
801
722
|
role: "none",
|
|
802
723
|
className: "flex flex-col gap-1"
|
|
803
|
-
},
|
|
724
|
+
}, arrayValues.map((_, index) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
804
725
|
key: index,
|
|
805
726
|
role: "none",
|
|
806
|
-
className: "flex items-
|
|
807
|
-
}, /* @__PURE__ */
|
|
727
|
+
className: "flex items-start gap-1"
|
|
728
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
808
729
|
role: "none",
|
|
809
730
|
className: "flex-1"
|
|
810
|
-
}, /* @__PURE__ */
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
readonly,
|
|
821
|
-
inline: true,
|
|
822
|
-
Custom,
|
|
823
|
-
lookupComponent
|
|
824
|
-
})), /* @__PURE__ */ import_react13.default.createElement(import_react_ui9.IconButton, {
|
|
731
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputComponent, {
|
|
732
|
+
type,
|
|
733
|
+
format,
|
|
734
|
+
label,
|
|
735
|
+
inputOnly: true,
|
|
736
|
+
property: `${name}[${index}]`,
|
|
737
|
+
disabled: readonly,
|
|
738
|
+
placeholder,
|
|
739
|
+
...inputProps
|
|
740
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
825
741
|
icon: "ph--trash--regular",
|
|
826
742
|
iconOnly: true,
|
|
827
743
|
label: t("button remove"),
|
|
828
|
-
onClick: () =>
|
|
829
|
-
|
|
744
|
+
onClick: () => {
|
|
745
|
+
const newValues = arrayValues.filter((_2, i) => i !== index);
|
|
746
|
+
inputProps.onValueChange(name, type, newValues);
|
|
747
|
+
}
|
|
748
|
+
})))), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
830
749
|
role: "none",
|
|
831
750
|
className: "flex justify-between items-center plb-1"
|
|
832
|
-
}, /* @__PURE__ */
|
|
751
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
833
752
|
icon: "ph--plus--regular",
|
|
834
753
|
iconOnly: true,
|
|
835
754
|
label: t("button add"),
|
|
836
|
-
onClick:
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
return GeoPointInput;
|
|
843
|
-
}
|
|
844
|
-
switch (type) {
|
|
845
|
-
case "string":
|
|
846
|
-
return TextInput;
|
|
847
|
-
case "number":
|
|
848
|
-
return NumberInput;
|
|
849
|
-
case "boolean":
|
|
850
|
-
return BooleanInput;
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
854
|
-
const inputProps = useInputProps(path);
|
|
855
|
-
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
856
|
-
const label = (0, import_react12.useMemo)(() => title ?? (0, import_effect3.pipe)(name, import_String.capitalize), [
|
|
857
|
-
title,
|
|
858
|
-
name
|
|
859
|
-
]);
|
|
860
|
-
const placeholder = (0, import_react12.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
861
|
-
examples,
|
|
862
|
-
description
|
|
863
|
-
]);
|
|
864
|
-
const FoundComponent = lookupComponent?.({
|
|
865
|
-
prop: name,
|
|
866
|
-
schema: import_echo_schema4.S.make(ast),
|
|
867
|
-
inputProps: {
|
|
868
|
-
type,
|
|
869
|
-
format,
|
|
870
|
-
label,
|
|
871
|
-
disabled: readonly,
|
|
872
|
-
placeholder,
|
|
873
|
-
...inputProps
|
|
874
|
-
}
|
|
875
|
-
});
|
|
876
|
-
if (FoundComponent) {
|
|
877
|
-
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
878
|
-
role: "none"
|
|
879
|
-
}, FoundComponent);
|
|
880
|
-
}
|
|
881
|
-
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
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);
|
|
909
|
-
if (InputComponent) {
|
|
910
|
-
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
911
|
-
role: "none"
|
|
912
|
-
}, /* @__PURE__ */ import_react12.default.createElement(InputComponent, {
|
|
913
|
-
type,
|
|
914
|
-
format,
|
|
915
|
-
label,
|
|
916
|
-
inputOnly: inline,
|
|
917
|
-
placeholder,
|
|
918
|
-
disabled: readonly,
|
|
919
|
-
...inputProps
|
|
920
|
-
}));
|
|
921
|
-
}
|
|
922
|
-
if (options) {
|
|
923
|
-
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
924
|
-
role: "none"
|
|
925
|
-
}, /* @__PURE__ */ import_react12.default.createElement(SelectInput, {
|
|
926
|
-
type,
|
|
927
|
-
format,
|
|
928
|
-
disabled: readonly,
|
|
929
|
-
inputOnly: inline,
|
|
930
|
-
label,
|
|
931
|
-
options: options.map((option) => ({
|
|
932
|
-
value: option,
|
|
933
|
-
label: String(option)
|
|
934
|
-
})),
|
|
935
|
-
placeholder,
|
|
936
|
-
...inputProps
|
|
937
|
-
}));
|
|
938
|
-
}
|
|
939
|
-
if (type === "object") {
|
|
940
|
-
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
941
|
-
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema4.AST.isTypeLiteral);
|
|
942
|
-
if (typeLiteral) {
|
|
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, {
|
|
946
|
-
schema: import_echo_schema4.S.make(typeLiteral),
|
|
947
|
-
path,
|
|
948
|
-
readonly,
|
|
949
|
-
Custom
|
|
950
|
-
}));
|
|
755
|
+
onClick: () => {
|
|
756
|
+
const newValues = [
|
|
757
|
+
...arrayValues,
|
|
758
|
+
import_effect2.SimpleType.getDefaultValue(type)
|
|
759
|
+
];
|
|
760
|
+
inputProps.onValueChange(name, type, newValues);
|
|
951
761
|
}
|
|
952
|
-
}
|
|
953
|
-
return null;
|
|
954
|
-
};
|
|
955
|
-
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
956
|
-
const values = useFormValues(path);
|
|
957
|
-
const properties = (0, import_react12.useMemo)(() => {
|
|
958
|
-
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
959
|
-
const filtered = filter ? filter(props) : props;
|
|
960
|
-
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
961
|
-
}, [
|
|
962
|
-
schema,
|
|
963
|
-
values,
|
|
964
|
-
filter,
|
|
965
|
-
sort
|
|
966
|
-
]);
|
|
967
|
-
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
968
|
-
role: "form",
|
|
969
|
-
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2 py-2")
|
|
970
|
-
}, properties.map((property) => {
|
|
971
|
-
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
972
|
-
key: property.name,
|
|
973
|
-
property,
|
|
974
|
-
path: [
|
|
975
|
-
...path ?? [],
|
|
976
|
-
property.name
|
|
977
|
-
],
|
|
978
|
-
readonly,
|
|
979
|
-
lookupComponent,
|
|
980
|
-
Custom
|
|
981
|
-
});
|
|
982
|
-
}).filter(import_util3.isNotFalsy));
|
|
762
|
+
})));
|
|
983
763
|
};
|
|
984
|
-
var
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
onSave
|
|
988
|
-
]);
|
|
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, {
|
|
1000
|
-
schema,
|
|
1001
|
-
initialValues,
|
|
1002
|
-
onValuesChanged,
|
|
1003
|
-
onValidate,
|
|
1004
|
-
onValid,
|
|
1005
|
-
onSave
|
|
1006
|
-
}, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
764
|
+
var FormActions = ({ onCancel, onSubmit, canSubmit, readonly }) => {
|
|
765
|
+
const { t } = (0, import_react_ui7.useTranslation)(translationKey);
|
|
766
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
1007
767
|
role: "none",
|
|
1008
|
-
className:
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
768
|
+
className: "flex justify-center"
|
|
769
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
770
|
+
role: "none",
|
|
771
|
+
className: (0, import_react_ui_theme3.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
772
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
773
|
+
"data-testid": "cancel-button",
|
|
774
|
+
icon: "ph--x--regular",
|
|
775
|
+
label: t("button cancel"),
|
|
776
|
+
onClick: onCancel
|
|
777
|
+
}), onSubmit && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
778
|
+
type: "submit",
|
|
779
|
+
"data-testid": "save-button",
|
|
780
|
+
disabled: !canSubmit,
|
|
781
|
+
icon: "ph--check--regular",
|
|
782
|
+
label: t("button save"),
|
|
783
|
+
onClick: onSubmit
|
|
1021
784
|
})));
|
|
1022
785
|
};
|
|
1023
786
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
@@ -1085,7 +848,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1085
848
|
type
|
|
1086
849
|
};
|
|
1087
850
|
}
|
|
1088
|
-
return
|
|
851
|
+
return props2;
|
|
1089
852
|
});
|
|
1090
853
|
}, [
|
|
1091
854
|
schemas,
|
|
@@ -1141,8 +904,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1141
904
|
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
1142
905
|
value: p.name
|
|
1143
906
|
})) : []
|
|
1144
|
-
})
|
|
1145
|
-
["options"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectOptionInput, props2)
|
|
907
|
+
})
|
|
1146
908
|
}), [
|
|
1147
909
|
t,
|
|
1148
910
|
schemas,
|
|
@@ -1154,7 +916,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1154
916
|
props
|
|
1155
917
|
}, {
|
|
1156
918
|
F: __dxlog_file3,
|
|
1157
|
-
L:
|
|
919
|
+
L: 173,
|
|
1158
920
|
S: void 0,
|
|
1159
921
|
C: (f, a) => f(...a)
|
|
1160
922
|
});
|
|
@@ -1178,22 +940,22 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1178
940
|
});
|
|
1179
941
|
};
|
|
1180
942
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1181
|
-
var ViewMetaSchema =
|
|
1182
|
-
name:
|
|
1183
|
-
[
|
|
943
|
+
var ViewMetaSchema = import_echo_schema5.S.Struct({
|
|
944
|
+
name: import_echo_schema5.S.String.annotations({
|
|
945
|
+
[import_echo_schema5.AST.TitleAnnotationId]: "View"
|
|
1184
946
|
}),
|
|
1185
|
-
typename:
|
|
1186
|
-
[
|
|
947
|
+
typename: import_echo_schema5.Format.DXN.annotations({
|
|
948
|
+
[import_echo_schema5.AST.TitleAnnotationId]: "Typename"
|
|
1187
949
|
})
|
|
1188
|
-
}).pipe(
|
|
950
|
+
}).pipe(import_echo_schema5.S.mutable);
|
|
1189
951
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1190
|
-
const { t } = (0,
|
|
1191
|
-
const projection = (0,
|
|
952
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
953
|
+
const projection = (0, import_react9.useMemo)(() => new import_schema4.ViewProjection(schema, view), [
|
|
1192
954
|
schema,
|
|
1193
955
|
view
|
|
1194
956
|
]);
|
|
1195
|
-
const [field, setField] = (0,
|
|
1196
|
-
const viewValues = (0,
|
|
957
|
+
const [field, setField] = (0, import_react9.useState)();
|
|
958
|
+
const viewValues = (0, import_react9.useMemo)(() => {
|
|
1197
959
|
return {
|
|
1198
960
|
name: view.name,
|
|
1199
961
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1203,7 +965,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1203
965
|
}, [
|
|
1204
966
|
view
|
|
1205
967
|
]);
|
|
1206
|
-
const handleViewUpdate = (0,
|
|
968
|
+
const handleViewUpdate = (0, import_react9.useCallback)(({ name, typename }) => {
|
|
1207
969
|
requestAnimationFrame(() => {
|
|
1208
970
|
if (view.name !== name) {
|
|
1209
971
|
view.name = name;
|
|
@@ -1217,77 +979,72 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1217
979
|
schema,
|
|
1218
980
|
onTypenameChanged
|
|
1219
981
|
]);
|
|
1220
|
-
const handleSelect = (0,
|
|
982
|
+
const handleSelect = (0, import_react9.useCallback)((field2) => {
|
|
1221
983
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1222
984
|
}, []);
|
|
1223
|
-
const handleAdd = (0,
|
|
985
|
+
const handleAdd = (0, import_react9.useCallback)(() => {
|
|
1224
986
|
const field2 = projection.createFieldProjection();
|
|
1225
987
|
setField(field2);
|
|
1226
988
|
}, [
|
|
1227
989
|
view
|
|
1228
990
|
]);
|
|
1229
|
-
const handleMove = (0,
|
|
1230
|
-
|
|
1231
|
-
...view.fields
|
|
1232
|
-
];
|
|
1233
|
-
const [moved] = fields.splice(fromIndex, 1);
|
|
1234
|
-
fields.splice(toIndex, 0, moved);
|
|
1235
|
-
view.fields = fields;
|
|
991
|
+
const handleMove = (0, import_react9.useCallback)((fromIndex, toIndex) => {
|
|
992
|
+
(0, import_util4.arrayMove)(view.fields, fromIndex, toIndex);
|
|
1236
993
|
}, [
|
|
1237
994
|
view.fields
|
|
1238
995
|
]);
|
|
1239
|
-
const handleClose = (0,
|
|
1240
|
-
return /* @__PURE__ */
|
|
996
|
+
const handleClose = (0, import_react9.useCallback)(() => setField(void 0), []);
|
|
997
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1241
998
|
role: "none",
|
|
1242
|
-
className: (0,
|
|
1243
|
-
}, /* @__PURE__ */
|
|
999
|
+
className: (0, import_react_ui_theme4.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1000
|
+
}, /* @__PURE__ */ import_react9.default.createElement(Form, {
|
|
1244
1001
|
autoFocus: true,
|
|
1245
1002
|
autoSave: true,
|
|
1246
1003
|
schema: ViewMetaSchema,
|
|
1247
1004
|
values: viewValues,
|
|
1248
1005
|
onSave: handleViewUpdate
|
|
1249
|
-
}), /* @__PURE__ */
|
|
1006
|
+
}), /* @__PURE__ */ import_react9.default.createElement("div", null, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1250
1007
|
role: "none",
|
|
1251
1008
|
className: "p-2"
|
|
1252
|
-
}, /* @__PURE__ */
|
|
1253
|
-
className: (0,
|
|
1254
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1009
|
+
}, /* @__PURE__ */ import_react9.default.createElement("label", {
|
|
1010
|
+
className: (0, import_react_ui_theme4.mx)(import_react_ui_theme4.inputTextLabel)
|
|
1011
|
+
}, t("fields label"))), /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.Root, {
|
|
1255
1012
|
items: view.fields,
|
|
1256
|
-
isItem:
|
|
1013
|
+
isItem: import_echo_schema5.S.is(import_schema4.FieldSchema),
|
|
1257
1014
|
getId: (field2) => field2.id,
|
|
1258
1015
|
onMove: handleMove
|
|
1259
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1016
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, showHeading && /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1260
1017
|
role: "heading",
|
|
1261
1018
|
className: grid
|
|
1262
|
-
}, /* @__PURE__ */
|
|
1019
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", null), /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1263
1020
|
className: "flex items-center text-sm"
|
|
1264
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1021
|
+
}, t("field path label"))), /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1265
1022
|
role: "list",
|
|
1266
1023
|
className: "flex flex-col w-full"
|
|
1267
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1024
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.Item, {
|
|
1268
1025
|
key: field2.id,
|
|
1269
1026
|
item: field2,
|
|
1270
|
-
classNames: (0,
|
|
1271
|
-
}, /* @__PURE__ */
|
|
1027
|
+
classNames: (0, import_react_ui_theme4.mx)(grid, import_react_ui_theme4.ghostHover, "cursor-pointer")
|
|
1028
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
1272
1029
|
onClick: () => handleSelect(field2)
|
|
1273
|
-
}, field2.path), /* @__PURE__ */
|
|
1030
|
+
}, field2.path), /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.ItemDeleteButton, {
|
|
1274
1031
|
disabled: view.fields.length <= 1,
|
|
1275
1032
|
onClick: () => onDelete(field2.id)
|
|
1276
|
-
}))))))), field && /* @__PURE__ */
|
|
1033
|
+
}))))))), field && /* @__PURE__ */ import_react9.default.createElement(FieldEditor, {
|
|
1277
1034
|
key: field.id,
|
|
1278
1035
|
view,
|
|
1279
1036
|
projection,
|
|
1280
1037
|
field,
|
|
1281
1038
|
registry,
|
|
1282
1039
|
onSave: handleClose
|
|
1283
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1040
|
+
}), !readonly && !field && /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1284
1041
|
className: "flex p-2 justify-center"
|
|
1285
|
-
}, /* @__PURE__ */
|
|
1042
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
1286
1043
|
icon: "ph--plus--regular",
|
|
1287
1044
|
label: t("button add property"),
|
|
1288
1045
|
onClick: handleAdd,
|
|
1289
1046
|
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
1290
|
-
disabled: view.fields.length >=
|
|
1047
|
+
disabled: view.fields.length >= import_schema4.VIEW_FIELD_LIMIT
|
|
1291
1048
|
})));
|
|
1292
1049
|
};
|
|
1293
1050
|
var parseValue = ({ type, format, value }) => {
|
|
@@ -1296,7 +1053,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1296
1053
|
}
|
|
1297
1054
|
const parseScalar = (type2) => {
|
|
1298
1055
|
switch (type2) {
|
|
1299
|
-
case
|
|
1056
|
+
case import_echo_schema6.TypeEnum.Boolean: {
|
|
1300
1057
|
if (typeof value === "string") {
|
|
1301
1058
|
const lowercaseValue = value.toLowerCase();
|
|
1302
1059
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1307,13 +1064,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1307
1064
|
}
|
|
1308
1065
|
return Boolean(value);
|
|
1309
1066
|
}
|
|
1310
|
-
case
|
|
1067
|
+
case import_echo_schema6.TypeEnum.Number: {
|
|
1311
1068
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1312
1069
|
const num = Number(cleaned);
|
|
1313
1070
|
return Number.isNaN(num) ? null : num;
|
|
1314
1071
|
}
|
|
1315
|
-
case
|
|
1316
|
-
case
|
|
1072
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1073
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1317
1074
|
return String(value);
|
|
1318
1075
|
default: {
|
|
1319
1076
|
return value;
|
|
@@ -1324,22 +1081,22 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1324
1081
|
return parseScalar(type);
|
|
1325
1082
|
}
|
|
1326
1083
|
switch (format) {
|
|
1327
|
-
case
|
|
1328
|
-
return parseScalar(
|
|
1329
|
-
case
|
|
1330
|
-
case
|
|
1331
|
-
case
|
|
1332
|
-
return parseScalar(
|
|
1333
|
-
case
|
|
1334
|
-
case
|
|
1335
|
-
return parseScalar(
|
|
1084
|
+
case import_echo_schema6.FormatEnum.Boolean:
|
|
1085
|
+
return parseScalar(import_echo_schema6.TypeEnum.Boolean);
|
|
1086
|
+
case import_echo_schema6.FormatEnum.Number:
|
|
1087
|
+
case import_echo_schema6.FormatEnum.Percent:
|
|
1088
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1089
|
+
return parseScalar(import_echo_schema6.TypeEnum.Number);
|
|
1090
|
+
case import_echo_schema6.FormatEnum.String:
|
|
1091
|
+
case import_echo_schema6.FormatEnum.Markdown: {
|
|
1092
|
+
return parseScalar(import_echo_schema6.TypeEnum.String);
|
|
1336
1093
|
}
|
|
1337
|
-
case
|
|
1338
|
-
throw new Error(`unexpected format: ${
|
|
1339
|
-
case
|
|
1340
|
-
case
|
|
1341
|
-
case
|
|
1342
|
-
case
|
|
1094
|
+
case import_echo_schema6.FormatEnum.Ref:
|
|
1095
|
+
throw new Error(`unexpected format: ${import_echo_schema6.FormatEnum.Ref}`);
|
|
1096
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1097
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1098
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1099
|
+
case import_echo_schema6.FormatEnum.Timestamp: {
|
|
1343
1100
|
const date = new Date(value);
|
|
1344
1101
|
return isNaN(date.getTime()) ? null : date;
|
|
1345
1102
|
}
|
|
@@ -1351,19 +1108,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1351
1108
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1352
1109
|
if (!format) {
|
|
1353
1110
|
switch (type) {
|
|
1354
|
-
case
|
|
1111
|
+
case import_echo_schema6.TypeEnum.Number:
|
|
1355
1112
|
return [
|
|
1356
1113
|
"text-right",
|
|
1357
1114
|
"font-mono"
|
|
1358
1115
|
];
|
|
1359
|
-
case
|
|
1116
|
+
case import_echo_schema6.TypeEnum.Boolean:
|
|
1360
1117
|
return [
|
|
1361
1118
|
"text-right",
|
|
1362
1119
|
"font-mono"
|
|
1363
1120
|
];
|
|
1364
|
-
case
|
|
1121
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1365
1122
|
return void 0;
|
|
1366
|
-
case
|
|
1123
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1367
1124
|
return void 0;
|
|
1368
1125
|
default: {
|
|
1369
1126
|
return void 0;
|
|
@@ -1371,20 +1128,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1371
1128
|
}
|
|
1372
1129
|
}
|
|
1373
1130
|
switch (format) {
|
|
1374
|
-
case
|
|
1131
|
+
case import_echo_schema6.FormatEnum.Markdown:
|
|
1375
1132
|
return void 0;
|
|
1376
|
-
case
|
|
1377
|
-
case
|
|
1378
|
-
case
|
|
1379
|
-
case
|
|
1133
|
+
case import_echo_schema6.FormatEnum.Timestamp:
|
|
1134
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1135
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1136
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1380
1137
|
return [
|
|
1381
1138
|
"font-mono"
|
|
1382
1139
|
];
|
|
1383
|
-
case
|
|
1140
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1384
1141
|
return [
|
|
1385
1142
|
"text-right"
|
|
1386
1143
|
];
|
|
1387
|
-
case
|
|
1144
|
+
case import_echo_schema6.FormatEnum.JSON:
|
|
1388
1145
|
return [
|
|
1389
1146
|
"font-mono"
|
|
1390
1147
|
];
|
|
@@ -1402,12 +1159,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1402
1159
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1403
1160
|
const formatScalar = (type2) => {
|
|
1404
1161
|
switch (type2) {
|
|
1405
|
-
case
|
|
1162
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1406
1163
|
return value.toLocaleString().toUpperCase();
|
|
1407
|
-
case
|
|
1164
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1408
1165
|
return value.toLocaleString(locale);
|
|
1409
|
-
case
|
|
1410
|
-
case
|
|
1166
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1167
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1411
1168
|
return String(value);
|
|
1412
1169
|
default: {
|
|
1413
1170
|
return String(value);
|
|
@@ -1418,20 +1175,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1418
1175
|
return formatScalar(type);
|
|
1419
1176
|
}
|
|
1420
1177
|
switch (format) {
|
|
1421
|
-
case
|
|
1422
|
-
return formatScalar(
|
|
1178
|
+
case import_echo_schema7.FormatEnum.Boolean: {
|
|
1179
|
+
return formatScalar(import_echo_schema7.TypeEnum.Boolean);
|
|
1423
1180
|
}
|
|
1424
|
-
case
|
|
1425
|
-
return formatScalar(
|
|
1181
|
+
case import_echo_schema7.FormatEnum.Number: {
|
|
1182
|
+
return formatScalar(import_echo_schema7.TypeEnum.Number);
|
|
1426
1183
|
}
|
|
1427
|
-
case
|
|
1428
|
-
case
|
|
1429
|
-
return formatScalar(
|
|
1184
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1185
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1186
|
+
return formatScalar(import_echo_schema7.TypeEnum.String);
|
|
1430
1187
|
}
|
|
1431
|
-
case
|
|
1188
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1432
1189
|
return `${value * 100}%`;
|
|
1433
1190
|
}
|
|
1434
|
-
case
|
|
1191
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1435
1192
|
return value.toLocaleString(locale, {
|
|
1436
1193
|
style: "currency",
|
|
1437
1194
|
currency: "USD",
|
|
@@ -1439,13 +1196,13 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1439
1196
|
maximumFractionDigits: 2
|
|
1440
1197
|
});
|
|
1441
1198
|
}
|
|
1442
|
-
case
|
|
1443
|
-
case
|
|
1444
|
-
case
|
|
1199
|
+
case import_echo_schema7.FormatEnum.DateTime:
|
|
1200
|
+
case import_echo_schema7.FormatEnum.Date:
|
|
1201
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1445
1202
|
const date = new Date(value);
|
|
1446
|
-
if (format ===
|
|
1203
|
+
if (format === import_echo_schema7.FormatEnum.DateTime) {
|
|
1447
1204
|
return date.toLocaleString(locale);
|
|
1448
|
-
} else if (format ===
|
|
1205
|
+
} else if (format === import_echo_schema7.FormatEnum.Date) {
|
|
1449
1206
|
return date.toLocaleDateString(locale);
|
|
1450
1207
|
} else {
|
|
1451
1208
|
return date.toLocaleTimeString(locale);
|
|
@@ -1462,10 +1219,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1462
1219
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1463
1220
|
const formatScalar = (type2) => {
|
|
1464
1221
|
switch (type2) {
|
|
1465
|
-
case
|
|
1466
|
-
case
|
|
1467
|
-
case
|
|
1468
|
-
case
|
|
1222
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1223
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1224
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1225
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1469
1226
|
return String(value);
|
|
1470
1227
|
default:
|
|
1471
1228
|
return String(value);
|
|
@@ -1475,27 +1232,27 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1475
1232
|
return formatScalar(type);
|
|
1476
1233
|
}
|
|
1477
1234
|
switch (format) {
|
|
1478
|
-
case
|
|
1479
|
-
case
|
|
1480
|
-
case
|
|
1481
|
-
case
|
|
1235
|
+
case import_echo_schema7.FormatEnum.Boolean:
|
|
1236
|
+
case import_echo_schema7.FormatEnum.Number:
|
|
1237
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1238
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1482
1239
|
return formatScalar(type);
|
|
1483
1240
|
}
|
|
1484
|
-
case
|
|
1241
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1485
1242
|
return String(value * 100);
|
|
1486
1243
|
}
|
|
1487
|
-
case
|
|
1244
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1488
1245
|
return String(value);
|
|
1489
1246
|
}
|
|
1490
|
-
case
|
|
1247
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1491
1248
|
const date = new Date(value);
|
|
1492
1249
|
return date.toISOString();
|
|
1493
1250
|
}
|
|
1494
|
-
case
|
|
1251
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1495
1252
|
const date = new Date(value);
|
|
1496
1253
|
return date.toISOString().split("T")[0];
|
|
1497
1254
|
}
|
|
1498
|
-
case
|
|
1255
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1499
1256
|
const date = new Date(value);
|
|
1500
1257
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1501
1258
|
}
|
|
@@ -1507,15 +1264,14 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1507
1264
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1508
1265
|
0 && (module.exports = {
|
|
1509
1266
|
BooleanInput,
|
|
1510
|
-
DeprecatedFormContainer,
|
|
1511
1267
|
DeprecatedFormInput,
|
|
1512
1268
|
FieldEditor,
|
|
1513
1269
|
Form,
|
|
1270
|
+
FormActions,
|
|
1514
1271
|
GeoPointInput,
|
|
1515
1272
|
InputHeader,
|
|
1516
1273
|
NumberInput,
|
|
1517
1274
|
SelectInput,
|
|
1518
|
-
SelectOptionInput,
|
|
1519
1275
|
TextInput,
|
|
1520
1276
|
TupleInput,
|
|
1521
1277
|
ViewEditor,
|