@dxos/react-ui-form 0.7.5-labs.8a82073 → 0.7.5-labs.a8b535d
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 +542 -359
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +585 -398
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +542 -359
- 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 +1 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +1 -2
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +5 -5
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +2 -2
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts +1 -2
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +2 -3
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +4 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +2 -2
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +1 -2
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +1 -2
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +1 -2
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +2 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts +1 -2
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +1 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +1 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +1 -2
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +2 -2
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +1 -0
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/package.json +25 -24
- package/src/components/Form/Defaults.tsx +59 -3
- package/src/components/Form/Form.tsx +8 -5
- package/src/components/Form/FormContent.tsx +9 -12
- package/src/components/Form/FormContext.tsx +58 -10
- package/src/components/Form/custom/GeoPointInput.tsx +42 -12
- package/src/components/Form/custom/SelectOptionsInput.tsx +7 -9
- package/src/components/Form/factory.tsx +4 -2
- package/src/components/Form/index.ts +3 -0
- package/src/components/ViewEditor/ViewEditor.tsx +2 -2
- package/src/hooks/useForm.ts +69 -40
- package/src/translations.ts +1 -1
- package/src/util/field.ts +19 -1
- package/src/util/formatting.ts +29 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(node_exports, {
|
|
|
35
35
|
Form: () => Form,
|
|
36
36
|
GeoPointInput: () => GeoPointInput,
|
|
37
37
|
InputHeader: () => InputHeader,
|
|
38
|
+
MarkdownInput: () => MarkdownInput,
|
|
38
39
|
NumberInput: () => NumberInput,
|
|
39
40
|
SelectInput: () => SelectInput,
|
|
40
41
|
SelectOptionInput: () => SelectOptionInput,
|
|
@@ -48,7 +49,8 @@ __export(node_exports, {
|
|
|
48
49
|
parseValue: () => parseValue,
|
|
49
50
|
pathNotUniqueError: () => pathNotUniqueError,
|
|
50
51
|
translations: () => translations_default,
|
|
51
|
-
useForm: () => useForm
|
|
52
|
+
useForm: () => useForm,
|
|
53
|
+
useFormValues: () => useFormValues
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(node_exports);
|
|
54
56
|
var import_react = __toESM(require("react"));
|
|
@@ -60,42 +62,43 @@ var import_log = require("@dxos/log");
|
|
|
60
62
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
61
63
|
var import_schema = require("@dxos/schema");
|
|
62
64
|
var import_react3 = __toESM(require("react"));
|
|
65
|
+
var import_debug = require("@dxos/debug");
|
|
66
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
67
|
+
var import_effect = require("@dxos/effect");
|
|
68
|
+
var import_react4 = require("react");
|
|
69
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
70
|
+
var import_effect2 = require("@dxos/effect");
|
|
71
|
+
var import_invariant = require("@dxos/invariant");
|
|
72
|
+
var import_log2 = require("@dxos/log");
|
|
73
|
+
var import_schema2 = require("@dxos/schema");
|
|
74
|
+
var import_react5 = __toESM(require("react"));
|
|
75
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
63
76
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
64
77
|
var import_util = require("@dxos/util");
|
|
65
|
-
var
|
|
78
|
+
var import_react6 = __toESM(require("react"));
|
|
66
79
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
67
80
|
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
68
|
-
var
|
|
81
|
+
var import_react7 = __toESM(require("react"));
|
|
69
82
|
var import_keys = require("@dxos/keys");
|
|
70
83
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
71
84
|
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
72
85
|
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
73
86
|
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
74
|
-
var
|
|
87
|
+
var import_react8 = __toESM(require("react"));
|
|
75
88
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
76
89
|
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
77
90
|
var import_util2 = require("@dxos/util");
|
|
78
|
-
var
|
|
91
|
+
var import_react9 = __toESM(require("react"));
|
|
79
92
|
var import_react_ui7 = require("@dxos/react-ui");
|
|
80
|
-
var
|
|
93
|
+
var import_react10 = __toESM(require("react"));
|
|
81
94
|
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
82
|
-
var
|
|
95
|
+
var import_react11 = __toESM(require("react"));
|
|
83
96
|
var import_react_ui8 = require("@dxos/react-ui");
|
|
84
97
|
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
|
-
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
|
-
var import_effect2 = require("@dxos/effect");
|
|
92
|
-
var import_invariant = require("@dxos/invariant");
|
|
93
|
-
var import_log2 = require("@dxos/log");
|
|
94
|
-
var import_schema2 = require("@dxos/schema");
|
|
95
98
|
var import_effect3 = require("effect");
|
|
96
99
|
var import_String = require("effect/String");
|
|
97
100
|
var import_react12 = __toESM(require("react"));
|
|
98
|
-
var
|
|
101
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
99
102
|
var import_effect4 = require("@dxos/effect");
|
|
100
103
|
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
101
104
|
var import_schema3 = require("@dxos/schema");
|
|
@@ -103,21 +106,21 @@ var import_util3 = require("@dxos/util");
|
|
|
103
106
|
var import_effect5 = require("effect");
|
|
104
107
|
var import_String2 = require("effect/String");
|
|
105
108
|
var import_react13 = __toESM(require("react"));
|
|
106
|
-
var
|
|
109
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
107
110
|
var import_effect6 = require("@dxos/effect");
|
|
108
111
|
var import_invariant2 = require("@dxos/invariant");
|
|
109
112
|
var import_react_ui9 = require("@dxos/react-ui");
|
|
110
113
|
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
111
114
|
var import_schema4 = require("@dxos/schema");
|
|
112
|
-
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
113
|
-
var import_react14 = __toESM(require("react"));
|
|
114
115
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
116
|
+
var import_react14 = __toESM(require("react"));
|
|
117
|
+
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
115
118
|
var import_react_ui10 = require("@dxos/react-ui");
|
|
116
119
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
117
120
|
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
118
121
|
var import_schema5 = require("@dxos/schema");
|
|
119
|
-
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
120
122
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
123
|
+
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
121
124
|
var translationKey = "react-ui-form";
|
|
122
125
|
var translations_default = [
|
|
123
126
|
{
|
|
@@ -148,7 +151,7 @@ var translations_default = [
|
|
|
148
151
|
"format hostname": "Hostname",
|
|
149
152
|
"format integer": "Integer",
|
|
150
153
|
"format json": "JSON",
|
|
151
|
-
"format latlng": "
|
|
154
|
+
"format latlng": "Geopoint",
|
|
152
155
|
"format markdown": "Markdown",
|
|
153
156
|
"format percent": "Percent",
|
|
154
157
|
"format ref": "Reference",
|
|
@@ -211,60 +214,352 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
211
214
|
}
|
|
212
215
|
return primary;
|
|
213
216
|
};
|
|
217
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
218
|
+
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
219
|
+
(0, import_invariant.invariant)(import_effect2.AST.isTypeLiteral(schema.ast), void 0, {
|
|
220
|
+
F: __dxlog_file,
|
|
221
|
+
L: 92,
|
|
222
|
+
S: void 0,
|
|
223
|
+
A: [
|
|
224
|
+
"AST.isTypeLiteral(schema.ast)",
|
|
225
|
+
""
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
const [values, setValues] = (0, import_react4.useState)(initialValues);
|
|
229
|
+
(0, import_react4.useEffect)(() => {
|
|
230
|
+
setValues(initialValues);
|
|
231
|
+
}, [
|
|
232
|
+
initialValues
|
|
233
|
+
]);
|
|
234
|
+
const [touched, setTouched] = (0, import_react4.useState)(createKeySet(initialValues, false));
|
|
235
|
+
const [changed, setChanged] = (0, import_react4.useState)(createKeySet(initialValues, false));
|
|
236
|
+
const [errors, setErrors] = (0, import_react4.useState)({});
|
|
237
|
+
const [saving, setSaving] = (0, import_react4.useState)(false);
|
|
238
|
+
const validate = (0, import_react4.useCallback)((values2) => {
|
|
239
|
+
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
240
|
+
if (errors2.length === 0 && onValidate) {
|
|
241
|
+
const validatedValues = values2;
|
|
242
|
+
errors2 = onValidate(validatedValues) ?? [];
|
|
243
|
+
}
|
|
244
|
+
setErrors(flatMap(errors2));
|
|
245
|
+
const valid = errors2.length === 0;
|
|
246
|
+
return valid;
|
|
247
|
+
}, [
|
|
248
|
+
schema,
|
|
249
|
+
onValidate
|
|
250
|
+
]);
|
|
251
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react4.useState)(false);
|
|
252
|
+
(0, import_react4.useEffect)(() => setSchemaDirty(true), [
|
|
253
|
+
schema
|
|
254
|
+
]);
|
|
255
|
+
(0, import_react4.useEffect)(() => {
|
|
256
|
+
if (schemaDirty) {
|
|
257
|
+
validate(values);
|
|
258
|
+
setSchemaDirty(false);
|
|
259
|
+
}
|
|
260
|
+
}, [
|
|
261
|
+
values,
|
|
262
|
+
schemaDirty
|
|
263
|
+
]);
|
|
264
|
+
const formIsValid = (0, import_react4.useMemo)(() => {
|
|
265
|
+
return Object.keys(errors).length === 0;
|
|
266
|
+
}, [
|
|
267
|
+
errors
|
|
268
|
+
]);
|
|
269
|
+
const canSave = (0, import_react4.useMemo)(() => !saving && // Check if any error paths that are touched have errors.
|
|
270
|
+
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
271
|
+
touched,
|
|
272
|
+
errors,
|
|
273
|
+
saving
|
|
274
|
+
]);
|
|
275
|
+
const handleSave = (0, import_react4.useCallback)(async () => {
|
|
276
|
+
if (validate(values)) {
|
|
277
|
+
setSaving(true);
|
|
278
|
+
try {
|
|
279
|
+
await onSave?.(values, {
|
|
280
|
+
changed
|
|
281
|
+
});
|
|
282
|
+
} finally {
|
|
283
|
+
setSaving(false);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}, [
|
|
287
|
+
values,
|
|
288
|
+
validate,
|
|
289
|
+
onSave,
|
|
290
|
+
changed
|
|
291
|
+
]);
|
|
292
|
+
const getStatus = (0, import_react4.useCallback)((path) => {
|
|
293
|
+
const jsonPath = Array.isArray(path) ? (0, import_effect2.createJsonPath)(path) : path;
|
|
294
|
+
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
295
|
+
return {
|
|
296
|
+
status: matchingError ? "error" : void 0,
|
|
297
|
+
error: matchingError ? matchingError[1] : void 0
|
|
298
|
+
};
|
|
299
|
+
}, [
|
|
300
|
+
errors
|
|
301
|
+
]);
|
|
302
|
+
const getFormValue = (0, import_react4.useCallback)((path) => {
|
|
303
|
+
return (0, import_echo_schema3.getValue)(values, (0, import_effect2.createJsonPath)(path));
|
|
304
|
+
}, [
|
|
305
|
+
values
|
|
306
|
+
]);
|
|
307
|
+
const onValueChange = (0, import_react4.useCallback)((path, type, value) => {
|
|
308
|
+
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
309
|
+
let parsedValue = value;
|
|
310
|
+
try {
|
|
311
|
+
if (type === "number") {
|
|
312
|
+
parsedValue = parseFloat(value) || 0;
|
|
313
|
+
}
|
|
314
|
+
} catch (err) {
|
|
315
|
+
import_log2.log.catch(err, void 0, {
|
|
316
|
+
F: __dxlog_file,
|
|
317
|
+
L: 202,
|
|
318
|
+
S: void 0,
|
|
319
|
+
C: (f, a) => f(...a)
|
|
320
|
+
});
|
|
321
|
+
parsedValue = void 0;
|
|
322
|
+
}
|
|
323
|
+
const newValues = {
|
|
324
|
+
...(0, import_echo_schema3.setValue)(values, jsonPath, parsedValue)
|
|
325
|
+
};
|
|
326
|
+
setValues(newValues);
|
|
327
|
+
setChanged((prev) => ({
|
|
328
|
+
...prev,
|
|
329
|
+
[jsonPath]: true
|
|
330
|
+
}));
|
|
331
|
+
onValuesChanged?.(newValues);
|
|
332
|
+
const isValid = validate(newValues);
|
|
333
|
+
if (isValid && onValid) {
|
|
334
|
+
onValid(newValues, {
|
|
335
|
+
changed
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}, [
|
|
339
|
+
values,
|
|
340
|
+
onValuesChanged,
|
|
341
|
+
validate,
|
|
342
|
+
onValid,
|
|
343
|
+
changed
|
|
344
|
+
]);
|
|
345
|
+
const onTouched = (0, import_react4.useCallback)((path) => {
|
|
346
|
+
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
347
|
+
setTouched((touched2) => ({
|
|
348
|
+
...touched2,
|
|
349
|
+
[jsonPath]: true
|
|
350
|
+
}));
|
|
351
|
+
validate(values);
|
|
352
|
+
}, [
|
|
353
|
+
validate,
|
|
354
|
+
values
|
|
355
|
+
]);
|
|
356
|
+
return (0, import_react4.useMemo)(() => ({
|
|
357
|
+
// State.
|
|
358
|
+
values,
|
|
359
|
+
errors,
|
|
360
|
+
touched,
|
|
361
|
+
changed,
|
|
362
|
+
canSave,
|
|
363
|
+
formIsValid,
|
|
364
|
+
// Actions.
|
|
365
|
+
handleSave,
|
|
366
|
+
// Field utils.
|
|
367
|
+
getStatus,
|
|
368
|
+
getValue: getFormValue,
|
|
369
|
+
onValueChange,
|
|
370
|
+
onTouched
|
|
371
|
+
}), [
|
|
372
|
+
values,
|
|
373
|
+
errors,
|
|
374
|
+
touched,
|
|
375
|
+
changed,
|
|
376
|
+
canSave,
|
|
377
|
+
formIsValid,
|
|
378
|
+
handleSave,
|
|
379
|
+
getStatus,
|
|
380
|
+
getFormValue,
|
|
381
|
+
onValueChange,
|
|
382
|
+
onTouched
|
|
383
|
+
]);
|
|
384
|
+
};
|
|
385
|
+
var createKeySet = (obj, value) => {
|
|
386
|
+
(0, import_invariant.invariant)(obj, void 0, {
|
|
387
|
+
F: __dxlog_file,
|
|
388
|
+
L: 264,
|
|
389
|
+
S: void 0,
|
|
390
|
+
A: [
|
|
391
|
+
"obj",
|
|
392
|
+
""
|
|
393
|
+
]
|
|
394
|
+
});
|
|
395
|
+
return Object.keys(obj).reduce((acc, key) => ({
|
|
396
|
+
...acc,
|
|
397
|
+
[key]: value
|
|
398
|
+
}), {});
|
|
399
|
+
};
|
|
400
|
+
var flatMap = (errors) => {
|
|
401
|
+
return errors.reduce((result, { path, message }) => {
|
|
402
|
+
const jsonPath = (0, import_effect2.fromEffectValidationPath)(path);
|
|
403
|
+
if (!(jsonPath in result)) {
|
|
404
|
+
result[jsonPath] = message;
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
}, {});
|
|
408
|
+
};
|
|
409
|
+
var FormContext = /* @__PURE__ */ (0, import_react3.createContext)(void 0);
|
|
410
|
+
var useFormContext = () => {
|
|
411
|
+
return (0, import_react3.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
412
|
+
};
|
|
413
|
+
var useFormValues = (path = []) => {
|
|
414
|
+
const { values: formValues } = useFormContext();
|
|
415
|
+
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
416
|
+
return (0, import_echo_schema2.getValue)(formValues, jsonPath);
|
|
417
|
+
};
|
|
418
|
+
var useInputProps = (path = []) => {
|
|
419
|
+
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
420
|
+
const stablePath = (0, import_react3.useMemo)(() => path, [
|
|
421
|
+
Array.isArray(path) ? path.join(".") : path
|
|
422
|
+
]);
|
|
423
|
+
return (0, import_react3.useMemo)(() => ({
|
|
424
|
+
getStatus: () => getStatus(stablePath),
|
|
425
|
+
getValue: () => getFormValue(stablePath),
|
|
426
|
+
onValueChange: (type, value) => onValueChange(stablePath, type, value),
|
|
427
|
+
onBlur: () => onTouched(stablePath)
|
|
428
|
+
}), [
|
|
429
|
+
getStatus,
|
|
430
|
+
getFormValue,
|
|
431
|
+
onValueChange,
|
|
432
|
+
onTouched,
|
|
433
|
+
stablePath
|
|
434
|
+
]);
|
|
435
|
+
};
|
|
436
|
+
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
437
|
+
const form = useForm(formOptions);
|
|
438
|
+
(0, import_react3.useEffect)(() => {
|
|
439
|
+
if (!formRef?.current) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const handleKeyDown = (event) => {
|
|
443
|
+
const keyIsEnter = event.key === "Enter";
|
|
444
|
+
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
445
|
+
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
446
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
447
|
+
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
448
|
+
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
449
|
+
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
450
|
+
if (!autoSave && form.canSave) {
|
|
451
|
+
form.handleSave();
|
|
452
|
+
}
|
|
453
|
+
if (autoSave && form.formIsValid) {
|
|
454
|
+
event.target.blur();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
const formElement = formRef.current;
|
|
459
|
+
formElement.addEventListener("keydown", handleKeyDown);
|
|
460
|
+
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
461
|
+
}, [
|
|
462
|
+
formRef,
|
|
463
|
+
form.canSave,
|
|
464
|
+
form.formIsValid,
|
|
465
|
+
form.handleSave,
|
|
466
|
+
autoSave
|
|
467
|
+
]);
|
|
468
|
+
return /* @__PURE__ */ import_react3.default.createElement(FormContext.Provider, {
|
|
469
|
+
value: form
|
|
470
|
+
}, children);
|
|
471
|
+
};
|
|
214
472
|
var InputHeader = ({ children, error }) => {
|
|
215
|
-
return /* @__PURE__ */
|
|
473
|
+
return /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
216
474
|
role: "none",
|
|
217
475
|
className: "flex justify-between items-center mb-1"
|
|
218
|
-
}, children, error && /* @__PURE__ */
|
|
476
|
+
}, children, error && /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
219
477
|
asChild: true
|
|
220
|
-
}, /* @__PURE__ */
|
|
478
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Icon, {
|
|
221
479
|
icon: "ph--warning--regular",
|
|
222
480
|
size: 4,
|
|
223
481
|
classNames: import_react_ui_theme2.errorText
|
|
224
|
-
})), /* @__PURE__ */
|
|
482
|
+
})), /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
225
483
|
side: "bottom"
|
|
226
|
-
}, /* @__PURE__ */
|
|
484
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
227
485
|
};
|
|
228
486
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
229
487
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
230
488
|
const { status, error } = getStatus();
|
|
231
|
-
const
|
|
232
|
-
|
|
489
|
+
const geoPoint = (0, import_react5.useMemo)(() => getValue3() ?? [
|
|
490
|
+
0,
|
|
491
|
+
0
|
|
492
|
+
], [
|
|
493
|
+
getValue3
|
|
494
|
+
]);
|
|
495
|
+
const geoLocation = (0, import_react5.useMemo)(() => import_echo_schema4.GeoLocation.fromGeoPoint(geoPoint), [
|
|
496
|
+
geoPoint
|
|
497
|
+
]);
|
|
498
|
+
const [longitudeText, setLongitudeText] = (0, import_react5.useState)(geoLocation.longitude?.toString());
|
|
499
|
+
const [latitudeText, setLatitudeText] = (0, import_react5.useState)(geoLocation.latitude?.toString());
|
|
500
|
+
(0, import_react5.useEffect)(() => {
|
|
501
|
+
const location = import_echo_schema4.GeoLocation.fromGeoPoint(geoPoint);
|
|
502
|
+
setLongitudeText(location.longitude.toString());
|
|
503
|
+
setLatitudeText(location.latitude.toString());
|
|
504
|
+
}, [
|
|
505
|
+
geoPoint
|
|
506
|
+
]);
|
|
507
|
+
const handleCoordinateChange = (0, import_react5.useCallback)((coordinateType, setText) => (event) => {
|
|
508
|
+
const inputText = event.target.value;
|
|
509
|
+
setText(inputText);
|
|
510
|
+
if (inputText !== "" && inputText !== "-") {
|
|
511
|
+
const coord = (0, import_util.safeParseFloat)(inputText);
|
|
512
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
513
|
+
const currentLocation = import_echo_schema4.GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
514
|
+
0,
|
|
515
|
+
0
|
|
516
|
+
]);
|
|
517
|
+
const newLocation = {
|
|
518
|
+
...currentLocation,
|
|
519
|
+
[coordinateType]: coord
|
|
520
|
+
};
|
|
521
|
+
const newValue = import_echo_schema4.GeoLocation.toGeoPoint(newLocation);
|
|
522
|
+
onValueChange(type, newValue);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}, [
|
|
526
|
+
getValue3,
|
|
527
|
+
onValueChange,
|
|
528
|
+
type
|
|
529
|
+
]);
|
|
530
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Root, {
|
|
233
531
|
validationValence: status
|
|
234
|
-
}, /* @__PURE__ */
|
|
532
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
235
533
|
error
|
|
236
|
-
}, /* @__PURE__ */
|
|
534
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
535
|
+
role: "none",
|
|
237
536
|
className: "grid grid-cols-2 gap-2"
|
|
238
|
-
}, /* @__PURE__ */
|
|
239
|
-
type: "
|
|
537
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
538
|
+
type: "text",
|
|
539
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
240
540
|
disabled,
|
|
241
|
-
placeholder: t("placeholder
|
|
242
|
-
value:
|
|
243
|
-
onChange: (
|
|
244
|
-
lat,
|
|
245
|
-
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
246
|
-
]),
|
|
541
|
+
placeholder: t("placeholder latitude"),
|
|
542
|
+
value: latitudeText,
|
|
543
|
+
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
247
544
|
onBlur
|
|
248
|
-
}), /* @__PURE__ */
|
|
249
|
-
type: "
|
|
545
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
546
|
+
type: "text",
|
|
547
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
250
548
|
disabled,
|
|
251
|
-
placeholder: t("placeholder
|
|
252
|
-
value:
|
|
253
|
-
onChange: (
|
|
254
|
-
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
255
|
-
lng
|
|
256
|
-
]),
|
|
549
|
+
placeholder: t("placeholder longitude"),
|
|
550
|
+
value: longitudeText,
|
|
551
|
+
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
257
552
|
onBlur
|
|
258
553
|
})));
|
|
259
554
|
};
|
|
260
555
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
261
|
-
const [selected, setSelectedId] = (0,
|
|
262
|
-
const [isNewOption, setIsNewOption] = (0,
|
|
263
|
-
const inputRef = (0,
|
|
556
|
+
const [selected, setSelectedId] = (0, import_react7.useState)(null);
|
|
557
|
+
const [isNewOption, setIsNewOption] = (0, import_react7.useState)(false);
|
|
558
|
+
const inputRef = (0, import_react7.useRef)(null);
|
|
264
559
|
const { t } = (0, import_react_ui5.useTranslation)(translationKey);
|
|
265
560
|
const { status, error } = getStatus();
|
|
266
561
|
const options = getValue3();
|
|
267
|
-
(0,
|
|
562
|
+
(0, import_react7.useEffect)(() => {
|
|
268
563
|
if (options === void 0) {
|
|
269
564
|
onValueChange(type, []);
|
|
270
565
|
}
|
|
@@ -275,16 +570,15 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
275
570
|
]);
|
|
276
571
|
const randomHue = () => {
|
|
277
572
|
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
278
|
-
const
|
|
279
|
-
const unusedHues = hueKeys.filter((hue) => !usedHues.has(hue));
|
|
573
|
+
const unusedHues = import_react_ui_theme3.hues.filter((hue) => !usedHues.has(hue));
|
|
280
574
|
if (unusedHues.length > 0) {
|
|
281
575
|
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
282
576
|
}
|
|
283
577
|
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
284
|
-
const availableHues =
|
|
285
|
-
return availableHues[Math.floor(Math.random() * availableHues.length)] ??
|
|
578
|
+
const availableHues = import_react_ui_theme3.hues.filter((hue) => !lastThree.has(hue));
|
|
579
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? import_react_ui_theme3.hues[Math.floor(Math.random() * import_react_ui_theme3.hues.length)];
|
|
286
580
|
};
|
|
287
|
-
const handleAdd = (0,
|
|
581
|
+
const handleAdd = (0, import_react7.useCallback)(() => {
|
|
288
582
|
const newId = import_keys.PublicKey.random().truncate();
|
|
289
583
|
const newOption = {
|
|
290
584
|
id: newId,
|
|
@@ -302,7 +596,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
302
596
|
type,
|
|
303
597
|
onValueChange
|
|
304
598
|
]);
|
|
305
|
-
const handleDelete = (0,
|
|
599
|
+
const handleDelete = (0, import_react7.useCallback)((id) => {
|
|
306
600
|
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
307
601
|
onValueChange(type, newOptions);
|
|
308
602
|
setSelectedId(null);
|
|
@@ -311,7 +605,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
311
605
|
type,
|
|
312
606
|
onValueChange
|
|
313
607
|
]);
|
|
314
|
-
const handleMove = (0,
|
|
608
|
+
const handleMove = (0, import_react7.useCallback)((from, to) => {
|
|
315
609
|
if (!options) {
|
|
316
610
|
return;
|
|
317
611
|
}
|
|
@@ -326,10 +620,10 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
326
620
|
type,
|
|
327
621
|
onValueChange
|
|
328
622
|
]);
|
|
329
|
-
const handleClick = (0,
|
|
623
|
+
const handleClick = (0, import_react7.useCallback)((id) => {
|
|
330
624
|
setSelectedId((current) => current === id ? null : id);
|
|
331
625
|
}, []);
|
|
332
|
-
const handleTitleChange = (0,
|
|
626
|
+
const handleTitleChange = (0, import_react7.useCallback)((id) => (e) => {
|
|
333
627
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
334
628
|
...o,
|
|
335
629
|
title: e.target.value
|
|
@@ -340,12 +634,12 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
340
634
|
type,
|
|
341
635
|
onValueChange
|
|
342
636
|
]);
|
|
343
|
-
const handleKeyDown = (0,
|
|
637
|
+
const handleKeyDown = (0, import_react7.useCallback)((e) => {
|
|
344
638
|
if (e.key === "Enter") {
|
|
345
639
|
setSelectedId(null);
|
|
346
640
|
}
|
|
347
641
|
}, []);
|
|
348
|
-
const handleColorChange = (0,
|
|
642
|
+
const handleColorChange = (0, import_react7.useCallback)((id) => (hue) => {
|
|
349
643
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
350
644
|
...o,
|
|
351
645
|
color: hue
|
|
@@ -356,7 +650,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
356
650
|
type,
|
|
357
651
|
onValueChange
|
|
358
652
|
]);
|
|
359
|
-
(0,
|
|
653
|
+
(0, import_react7.useEffect)(() => {
|
|
360
654
|
if (selected && isNewOption && inputRef.current) {
|
|
361
655
|
inputRef.current.focus();
|
|
362
656
|
setIsNewOption(false);
|
|
@@ -365,70 +659,71 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
365
659
|
selected,
|
|
366
660
|
isNewOption
|
|
367
661
|
]);
|
|
368
|
-
return /* @__PURE__ */
|
|
662
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Root, {
|
|
369
663
|
validationValence: status
|
|
370
|
-
}, /* @__PURE__ */
|
|
664
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
371
665
|
error
|
|
372
|
-
}, /* @__PURE__ */
|
|
666
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
373
667
|
role: "none"
|
|
374
|
-
}, options && /* @__PURE__ */
|
|
668
|
+
}, options && /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.Root, {
|
|
375
669
|
items: options,
|
|
376
670
|
isItem: (item) => true,
|
|
377
671
|
onMove: handleMove
|
|
378
|
-
}, ({ items }) => /* @__PURE__ */
|
|
672
|
+
}, ({ items }) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
379
673
|
role: "list",
|
|
380
674
|
className: "w-full overflow-auto"
|
|
381
|
-
}, items?.map((item) => /* @__PURE__ */
|
|
675
|
+
}, items?.map((item) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
382
676
|
key: item.id
|
|
383
|
-
}, /* @__PURE__ */
|
|
677
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.Item, {
|
|
384
678
|
role: "button",
|
|
385
679
|
item,
|
|
386
680
|
classNames: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
387
681
|
"aria-expanded": selected === item.id
|
|
388
|
-
}, /* @__PURE__ */
|
|
682
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
389
683
|
className: "flex items-center"
|
|
390
|
-
}, /* @__PURE__ */
|
|
684
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
391
685
|
onClick: () => handleClick(item.id),
|
|
392
686
|
classNames: "flex-1"
|
|
393
|
-
}, /* @__PURE__ */
|
|
687
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tag, {
|
|
394
688
|
palette: item.color
|
|
395
|
-
}, item.title || "\u200B")), /* @__PURE__ */
|
|
689
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
396
690
|
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
397
691
|
onClick: () => handleClick(item.id)
|
|
398
|
-
})), selected === item.id && /* @__PURE__ */
|
|
692
|
+
})), selected === item.id && /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
399
693
|
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
400
|
-
}, /* @__PURE__ */
|
|
694
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Label, {
|
|
401
695
|
classNames: "text-xs"
|
|
402
|
-
}, t("select option label")), /* @__PURE__ */
|
|
696
|
+
}, t("select option label")), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
403
697
|
className: "flex flex-row items-center gap-1"
|
|
404
|
-
}, /* @__PURE__ */
|
|
698
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.TextInput, {
|
|
405
699
|
placeholder: t("select option label placeholder"),
|
|
406
700
|
ref: selected === item.id ? inputRef : void 0,
|
|
407
701
|
value: item.title,
|
|
408
702
|
onChange: handleTitleChange(item.id),
|
|
409
703
|
onKeyDown: handleKeyDown,
|
|
410
|
-
classNames: "flex-1"
|
|
411
|
-
|
|
704
|
+
classNames: "flex-1",
|
|
705
|
+
"data-no-submit": true
|
|
706
|
+
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
412
707
|
classNames: "p-0 m-0 !is-auto"
|
|
413
|
-
}, /* @__PURE__ */
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
})), /* @__PURE__ */
|
|
708
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_pickers.HuePicker, {
|
|
709
|
+
value: item.color,
|
|
710
|
+
onChange: handleColorChange(item.id)
|
|
711
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.IconButton, {
|
|
417
712
|
icon: "ph--trash--fill",
|
|
418
713
|
iconOnly: true,
|
|
419
714
|
label: t("select option delete"),
|
|
420
715
|
onClick: () => handleDelete(item.id)
|
|
421
|
-
})))))), /* @__PURE__ */
|
|
716
|
+
})))))), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
422
717
|
role: "listitem"
|
|
423
|
-
}, /* @__PURE__ */
|
|
718
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
424
719
|
role: "button",
|
|
425
720
|
className: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
426
721
|
onClick: handleAdd
|
|
427
|
-
}, /* @__PURE__ */
|
|
722
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
428
723
|
className: "flex items-center gap-1"
|
|
429
|
-
}, /* @__PURE__ */
|
|
724
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
430
725
|
icon: "ph--plus--regular"
|
|
431
|
-
}), /* @__PURE__ */
|
|
726
|
+
}), /* @__PURE__ */ import_react7.default.createElement("span", {
|
|
432
727
|
className: "text-sm"
|
|
433
728
|
}, t("select option add")))))))));
|
|
434
729
|
};
|
|
@@ -441,13 +736,13 @@ var gridCols = [
|
|
|
441
736
|
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
442
737
|
const { status, error } = getStatus();
|
|
443
738
|
const values = getValue3() ?? {};
|
|
444
|
-
return /* @__PURE__ */
|
|
739
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.Root, {
|
|
445
740
|
validationValence: status
|
|
446
|
-
}, /* @__PURE__ */
|
|
741
|
+
}, /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
447
742
|
error
|
|
448
|
-
}, /* @__PURE__ */
|
|
743
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
449
744
|
className: (0, import_react_ui_theme4.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
450
|
-
}, binding.map((prop) => /* @__PURE__ */
|
|
745
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.TextInput, {
|
|
451
746
|
key: prop,
|
|
452
747
|
type: "number",
|
|
453
748
|
disabled,
|
|
@@ -461,270 +756,120 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
461
756
|
};
|
|
462
757
|
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
463
758
|
const { status, error } = getStatus();
|
|
464
|
-
return /* @__PURE__ */
|
|
759
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
465
760
|
validationValence: status
|
|
466
|
-
}, !inputOnly && /* @__PURE__ */
|
|
761
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
467
762
|
error
|
|
468
|
-
}, /* @__PURE__ */
|
|
763
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextInput, {
|
|
469
764
|
disabled,
|
|
470
765
|
placeholder,
|
|
471
766
|
value: getValue3() ?? "",
|
|
472
767
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
473
768
|
onBlur
|
|
474
|
-
}), inputOnly && /* @__PURE__ */
|
|
769
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
475
770
|
};
|
|
476
771
|
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
477
772
|
const { status, error } = getStatus();
|
|
478
|
-
return /* @__PURE__ */
|
|
773
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
479
774
|
validationValence: status
|
|
480
|
-
}, !inputOnly && /* @__PURE__ */
|
|
775
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
481
776
|
error
|
|
482
|
-
}, /* @__PURE__ */
|
|
777
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextInput, {
|
|
483
778
|
type: "number",
|
|
484
779
|
disabled,
|
|
485
780
|
placeholder,
|
|
486
781
|
value: getValue3() ?? 0,
|
|
487
782
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
488
783
|
onBlur
|
|
489
|
-
}), inputOnly && /* @__PURE__ */
|
|
784
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
490
785
|
};
|
|
491
786
|
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
492
787
|
const { status, error } = getStatus();
|
|
493
788
|
const checked = Boolean(getValue3());
|
|
494
|
-
return /* @__PURE__ */
|
|
789
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
495
790
|
validationValence: status
|
|
496
|
-
}, !inputOnly && /* @__PURE__ */
|
|
791
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
497
792
|
error
|
|
498
|
-
}, /* @__PURE__ */
|
|
793
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Switch, {
|
|
499
794
|
checked,
|
|
500
795
|
onCheckedChange: (value) => onValueChange(type, value)
|
|
501
|
-
}), inputOnly && /* @__PURE__ */
|
|
796
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
502
797
|
};
|
|
503
798
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
504
799
|
const { status, error } = getStatus();
|
|
505
|
-
return /* @__PURE__ */
|
|
800
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
506
801
|
validationValence: status
|
|
507
|
-
}, !inputOnly && /* @__PURE__ */
|
|
802
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
508
803
|
error
|
|
509
|
-
}, /* @__PURE__ */
|
|
804
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Root, {
|
|
510
805
|
value: getValue3(),
|
|
511
806
|
onValueChange: (value) => onValueChange(type, value)
|
|
512
|
-
}, /* @__PURE__ */
|
|
807
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
513
808
|
classNames: "is-full",
|
|
514
809
|
disabled,
|
|
515
810
|
placeholder
|
|
516
|
-
}), /* @__PURE__ */
|
|
811
|
+
}), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Portal, null, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Content, null, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
517
812
|
// NOTE: Numeric values are converted to and from strings.
|
|
518
|
-
/* @__PURE__ */
|
|
813
|
+
/* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Option, {
|
|
519
814
|
key: String(value),
|
|
520
815
|
value: String(value)
|
|
521
816
|
}, label2 ?? String(value))
|
|
522
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
817
|
+
)))))), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
523
818
|
};
|
|
524
|
-
var
|
|
525
|
-
|
|
526
|
-
(0,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
""
|
|
533
|
-
]
|
|
534
|
-
});
|
|
535
|
-
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
536
|
-
(0, import_react11.useEffect)(() => {
|
|
537
|
-
setValues(initialValues);
|
|
538
|
-
}, [
|
|
539
|
-
initialValues
|
|
540
|
-
]);
|
|
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) => {
|
|
546
|
-
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
547
|
-
if (errors2.length === 0 && onValidate) {
|
|
548
|
-
const validatedValues = values2;
|
|
549
|
-
errors2 = onValidate(validatedValues) ?? [];
|
|
550
|
-
}
|
|
551
|
-
setErrors(flatMap(errors2));
|
|
552
|
-
const valid = errors2.length === 0;
|
|
553
|
-
return valid;
|
|
554
|
-
}, [
|
|
555
|
-
schema,
|
|
556
|
-
onValidate
|
|
557
|
-
]);
|
|
558
|
-
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
559
|
-
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
560
|
-
schema
|
|
561
|
-
]);
|
|
562
|
-
(0, import_react11.useEffect)(() => {
|
|
563
|
-
if (schemaDirty) {
|
|
564
|
-
validate(values);
|
|
565
|
-
setSchemaDirty(false);
|
|
566
|
-
}
|
|
567
|
-
}, [
|
|
568
|
-
values,
|
|
569
|
-
schemaDirty
|
|
570
|
-
]);
|
|
571
|
-
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
572
|
-
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
573
|
-
touched,
|
|
574
|
-
errors,
|
|
575
|
-
saving
|
|
576
|
-
]);
|
|
577
|
-
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
578
|
-
if (validate(values)) {
|
|
579
|
-
setSaving(true);
|
|
580
|
-
try {
|
|
581
|
-
await onSave?.(values, {
|
|
582
|
-
changed
|
|
583
|
-
});
|
|
584
|
-
} finally {
|
|
585
|
-
setSaving(false);
|
|
586
|
-
}
|
|
819
|
+
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
820
|
+
const { status, error } = getStatus();
|
|
821
|
+
const textareaRef = (0, import_react9.useRef)(null);
|
|
822
|
+
const adjustHeight = (0, import_react9.useCallback)(() => {
|
|
823
|
+
const textarea = textareaRef.current;
|
|
824
|
+
if (textarea) {
|
|
825
|
+
textarea.style.blockSize = "auto";
|
|
826
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
587
827
|
}
|
|
828
|
+
}, []);
|
|
829
|
+
(0, import_react9.useEffect)(() => {
|
|
830
|
+
adjustHeight();
|
|
588
831
|
}, [
|
|
589
|
-
|
|
590
|
-
validate,
|
|
591
|
-
onSave,
|
|
592
|
-
changed
|
|
832
|
+
adjustHeight
|
|
593
833
|
]);
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
597
|
-
return {
|
|
598
|
-
status: matchingError ? "error" : void 0,
|
|
599
|
-
error: matchingError ? matchingError[1] : void 0
|
|
600
|
-
};
|
|
834
|
+
(0, import_react9.useEffect)(() => {
|
|
835
|
+
adjustHeight();
|
|
601
836
|
}, [
|
|
602
|
-
|
|
837
|
+
getValue3(),
|
|
838
|
+
adjustHeight
|
|
603
839
|
]);
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
parsedValue = void 0;
|
|
622
|
-
}
|
|
623
|
-
const newValues = {
|
|
624
|
-
...(0, import_echo_schema3.setValue)(values, jsonPath, parsedValue)
|
|
625
|
-
};
|
|
626
|
-
setValues(newValues);
|
|
627
|
-
setChanged((prev) => ({
|
|
628
|
-
...prev,
|
|
629
|
-
[jsonPath]: true
|
|
630
|
-
}));
|
|
631
|
-
onValuesChanged?.(newValues);
|
|
632
|
-
const isValid = validate(newValues);
|
|
633
|
-
if (isValid && onValid) {
|
|
634
|
-
onValid(newValues, {
|
|
635
|
-
changed
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
640
|
-
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
641
|
-
setTouched((touched2) => ({
|
|
642
|
-
...touched2,
|
|
643
|
-
[jsonPath]: true
|
|
644
|
-
}));
|
|
645
|
-
validate(values);
|
|
646
|
-
}, [
|
|
647
|
-
validate,
|
|
648
|
-
values
|
|
649
|
-
]);
|
|
650
|
-
return {
|
|
651
|
-
// State.
|
|
652
|
-
values,
|
|
653
|
-
errors,
|
|
654
|
-
touched,
|
|
655
|
-
changed,
|
|
656
|
-
canSave,
|
|
657
|
-
handleSave,
|
|
658
|
-
// Field utils.
|
|
659
|
-
getStatus,
|
|
660
|
-
getValue: getFormValue,
|
|
661
|
-
onValueChange,
|
|
662
|
-
onTouched
|
|
663
|
-
};
|
|
664
|
-
};
|
|
665
|
-
var createKeySet = (obj, value) => {
|
|
666
|
-
(0, import_invariant.invariant)(obj, void 0, {
|
|
667
|
-
F: __dxlog_file,
|
|
668
|
-
L: 235,
|
|
669
|
-
S: void 0,
|
|
670
|
-
A: [
|
|
671
|
-
"obj",
|
|
672
|
-
""
|
|
673
|
-
]
|
|
674
|
-
});
|
|
675
|
-
return Object.keys(obj).reduce((acc, key) => ({
|
|
676
|
-
...acc,
|
|
677
|
-
[key]: value
|
|
678
|
-
}), {});
|
|
679
|
-
};
|
|
680
|
-
var flatMap = (errors) => {
|
|
681
|
-
return errors.reduce((result, { path, message }) => {
|
|
682
|
-
const jsonPath = (0, import_effect2.fromEffectValidationPath)(path);
|
|
683
|
-
if (!(jsonPath in result)) {
|
|
684
|
-
result[jsonPath] = message;
|
|
685
|
-
}
|
|
686
|
-
return result;
|
|
687
|
-
}, {});
|
|
688
|
-
};
|
|
689
|
-
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
690
|
-
var useFormContext = () => {
|
|
691
|
-
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
692
|
-
};
|
|
693
|
-
var useFormValues = (path = []) => {
|
|
694
|
-
const { values: formValues } = useFormContext();
|
|
695
|
-
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
696
|
-
return (0, import_echo_schema2.getValue)(formValues, jsonPath);
|
|
697
|
-
};
|
|
698
|
-
var useInputProps = (path = []) => {
|
|
699
|
-
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
700
|
-
return {
|
|
701
|
-
getStatus: () => getStatus(path),
|
|
702
|
-
getValue: () => getFormValue(path),
|
|
703
|
-
onValueChange: (type, value) => onValueChange(path, type, value),
|
|
704
|
-
onBlur: () => onTouched(path)
|
|
705
|
-
};
|
|
706
|
-
};
|
|
707
|
-
var FormProvider = ({ children, ...formOptions }) => {
|
|
708
|
-
const formHandler = useForm(formOptions);
|
|
709
|
-
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
710
|
-
value: formHandler
|
|
711
|
-
}, children);
|
|
840
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
841
|
+
validationValence: status
|
|
842
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
843
|
+
error
|
|
844
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextArea, {
|
|
845
|
+
ref: textareaRef,
|
|
846
|
+
disabled,
|
|
847
|
+
placeholder,
|
|
848
|
+
value: getValue3() ?? "",
|
|
849
|
+
classNames: "min-bs-auto max-h-40 overflow-auto",
|
|
850
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
851
|
+
onBlur,
|
|
852
|
+
style: {
|
|
853
|
+
resize: "none"
|
|
854
|
+
},
|
|
855
|
+
spellCheck: false
|
|
856
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
712
857
|
};
|
|
713
858
|
var FormActions = ({ onCancel, readonly }) => {
|
|
714
859
|
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
715
860
|
const { canSave, handleSave } = useFormContext();
|
|
716
|
-
return /* @__PURE__ */
|
|
861
|
+
return /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
717
862
|
role: "none",
|
|
718
863
|
className: "mt-2 flex justify-center"
|
|
719
|
-
}, /* @__PURE__ */
|
|
864
|
+
}, /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
720
865
|
role: "none",
|
|
721
866
|
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
722
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
867
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
723
868
|
"data-testid": "cancel-button",
|
|
724
869
|
icon: "ph--x--regular",
|
|
725
870
|
label: t("button cancel"),
|
|
726
871
|
onClick: onCancel
|
|
727
|
-
}), handleSave && /* @__PURE__ */
|
|
872
|
+
}), handleSave && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
728
873
|
type: "submit",
|
|
729
874
|
"data-testid": "save-button",
|
|
730
875
|
disabled: !canSave,
|
|
@@ -749,11 +894,11 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
749
894
|
]
|
|
750
895
|
});
|
|
751
896
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
752
|
-
const tupleType = (0, import_effect6.findNode)(ast,
|
|
897
|
+
const tupleType = (0, import_effect6.findNode)(ast, import_echo_schema6.AST.isTupleType);
|
|
753
898
|
const elementType = tupleType?.rest[0]?.type;
|
|
754
899
|
const getDefaultObjectValue = (typeNode) => {
|
|
755
900
|
const baseNode = (0, import_effect6.findNode)(typeNode, import_effect6.isDiscriminatedUnion);
|
|
756
|
-
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode,
|
|
901
|
+
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode, import_echo_schema6.AST.isTypeLiteral);
|
|
757
902
|
if (!typeLiteral) {
|
|
758
903
|
return {};
|
|
759
904
|
}
|
|
@@ -839,8 +984,10 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
839
984
|
};
|
|
840
985
|
var getInputComponent = (type, format) => {
|
|
841
986
|
switch (format) {
|
|
842
|
-
case
|
|
987
|
+
case import_echo_schema7.FormatEnum.GeoPoint:
|
|
843
988
|
return GeoPointInput;
|
|
989
|
+
case import_echo_schema7.FormatEnum.Markdown:
|
|
990
|
+
return MarkdownInput;
|
|
844
991
|
}
|
|
845
992
|
switch (type) {
|
|
846
993
|
case "string":
|
|
@@ -864,7 +1011,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
864
1011
|
]);
|
|
865
1012
|
const FoundComponent = lookupComponent?.({
|
|
866
1013
|
prop: name,
|
|
867
|
-
schema:
|
|
1014
|
+
schema: import_echo_schema5.S.make(ast),
|
|
868
1015
|
inputProps: {
|
|
869
1016
|
type,
|
|
870
1017
|
format,
|
|
@@ -882,20 +1029,15 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
882
1029
|
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
883
1030
|
const CustomComponent = Custom?.[jsonPath];
|
|
884
1031
|
if (CustomComponent) {
|
|
885
|
-
return (
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
placeholder,
|
|
895
|
-
disabled: readonly,
|
|
896
|
-
...inputProps
|
|
897
|
-
}))
|
|
898
|
-
);
|
|
1032
|
+
return /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
1033
|
+
type,
|
|
1034
|
+
format,
|
|
1035
|
+
label,
|
|
1036
|
+
inputOnly: inline,
|
|
1037
|
+
placeholder,
|
|
1038
|
+
disabled: readonly,
|
|
1039
|
+
...inputProps
|
|
1040
|
+
});
|
|
899
1041
|
}
|
|
900
1042
|
if (array) {
|
|
901
1043
|
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
@@ -939,12 +1081,12 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
939
1081
|
}
|
|
940
1082
|
if (type === "object") {
|
|
941
1083
|
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
942
|
-
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast,
|
|
1084
|
+
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema5.AST.isTypeLiteral);
|
|
943
1085
|
if (typeLiteral) {
|
|
944
1086
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
945
1087
|
role: "none"
|
|
946
1088
|
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
947
|
-
schema:
|
|
1089
|
+
schema: import_echo_schema5.S.make(typeLiteral),
|
|
948
1090
|
path,
|
|
949
1091
|
readonly,
|
|
950
1092
|
Custom
|
|
@@ -983,13 +1125,14 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
983
1125
|
}).filter(import_util3.isNotFalsy));
|
|
984
1126
|
};
|
|
985
1127
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
986
|
-
const
|
|
1128
|
+
const formRef = (0, import_react10.useRef)(null);
|
|
1129
|
+
const onValid = (0, import_react10.useMemo)(() => autoSave ? onSave : void 0, [
|
|
987
1130
|
autoSave,
|
|
988
1131
|
onSave
|
|
989
1132
|
]);
|
|
990
|
-
(0,
|
|
991
|
-
if (autoFocus) {
|
|
992
|
-
const input =
|
|
1133
|
+
(0, import_react10.useEffect)(() => {
|
|
1134
|
+
if (autoFocus && formRef.current) {
|
|
1135
|
+
const input = formRef.current.querySelector("input");
|
|
993
1136
|
if (input) {
|
|
994
1137
|
input.focus();
|
|
995
1138
|
}
|
|
@@ -997,18 +1140,21 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
997
1140
|
}, [
|
|
998
1141
|
autoFocus
|
|
999
1142
|
]);
|
|
1000
|
-
return /* @__PURE__ */
|
|
1143
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormProvider, {
|
|
1144
|
+
formRef,
|
|
1001
1145
|
schema,
|
|
1146
|
+
autoSave,
|
|
1002
1147
|
initialValues,
|
|
1003
1148
|
onValuesChanged,
|
|
1004
1149
|
onValidate,
|
|
1005
1150
|
onValid,
|
|
1006
1151
|
onSave
|
|
1007
|
-
}, /* @__PURE__ */
|
|
1152
|
+
}, /* @__PURE__ */ import_react10.default.createElement("div", {
|
|
1153
|
+
ref: formRef,
|
|
1008
1154
|
role: "none",
|
|
1009
1155
|
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
1010
1156
|
"data-testid": testId
|
|
1011
|
-
}, /* @__PURE__ */
|
|
1157
|
+
}, /* @__PURE__ */ import_react10.default.createElement(FormFields, {
|
|
1012
1158
|
schema,
|
|
1013
1159
|
path,
|
|
1014
1160
|
readonly,
|
|
@@ -1016,7 +1162,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1016
1162
|
sort,
|
|
1017
1163
|
lookupComponent,
|
|
1018
1164
|
Custom
|
|
1019
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1165
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react10.default.createElement(FormActions, {
|
|
1020
1166
|
onCancel,
|
|
1021
1167
|
readonly
|
|
1022
1168
|
})));
|
|
@@ -1179,14 +1325,14 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1179
1325
|
});
|
|
1180
1326
|
};
|
|
1181
1327
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1182
|
-
var ViewMetaSchema =
|
|
1183
|
-
name:
|
|
1184
|
-
[
|
|
1328
|
+
var ViewMetaSchema = import_echo_schema8.S.Struct({
|
|
1329
|
+
name: import_echo_schema8.S.String.annotations({
|
|
1330
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "View"
|
|
1185
1331
|
}),
|
|
1186
|
-
typename:
|
|
1187
|
-
[
|
|
1332
|
+
typename: import_echo_schema8.Format.URL.annotations({
|
|
1333
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "Typename"
|
|
1188
1334
|
})
|
|
1189
|
-
}).pipe(
|
|
1335
|
+
}).pipe(import_echo_schema8.S.mutable);
|
|
1190
1336
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1191
1337
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1192
1338
|
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
@@ -1242,7 +1388,6 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1242
1388
|
role: "none",
|
|
1243
1389
|
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1244
1390
|
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
1245
|
-
autoFocus: true,
|
|
1246
1391
|
autoSave: true,
|
|
1247
1392
|
schema: ViewMetaSchema,
|
|
1248
1393
|
values: viewValues,
|
|
@@ -1254,7 +1399,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1254
1399
|
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1255
1400
|
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1256
1401
|
items: view.fields,
|
|
1257
|
-
isItem:
|
|
1402
|
+
isItem: import_echo_schema8.S.is(import_schema5.FieldSchema),
|
|
1258
1403
|
getId: (field2) => field2.id,
|
|
1259
1404
|
onMove: handleMove
|
|
1260
1405
|
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
@@ -1297,7 +1442,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1297
1442
|
}
|
|
1298
1443
|
const parseScalar = (type2) => {
|
|
1299
1444
|
switch (type2) {
|
|
1300
|
-
case
|
|
1445
|
+
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1301
1446
|
if (typeof value === "string") {
|
|
1302
1447
|
const lowercaseValue = value.toLowerCase();
|
|
1303
1448
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1308,13 +1453,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1308
1453
|
}
|
|
1309
1454
|
return Boolean(value);
|
|
1310
1455
|
}
|
|
1311
|
-
case
|
|
1456
|
+
case import_echo_schema9.TypeEnum.Number: {
|
|
1312
1457
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1313
1458
|
const num = Number(cleaned);
|
|
1314
1459
|
return Number.isNaN(num) ? null : num;
|
|
1315
1460
|
}
|
|
1316
|
-
case
|
|
1317
|
-
case
|
|
1461
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1462
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1318
1463
|
return String(value);
|
|
1319
1464
|
default: {
|
|
1320
1465
|
return value;
|
|
@@ -1325,25 +1470,45 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1325
1470
|
return parseScalar(type);
|
|
1326
1471
|
}
|
|
1327
1472
|
switch (format) {
|
|
1328
|
-
case
|
|
1329
|
-
return parseScalar(
|
|
1330
|
-
case
|
|
1331
|
-
case
|
|
1332
|
-
case
|
|
1333
|
-
return parseScalar(
|
|
1334
|
-
case
|
|
1335
|
-
case
|
|
1336
|
-
return parseScalar(
|
|
1473
|
+
case import_echo_schema9.FormatEnum.Boolean:
|
|
1474
|
+
return parseScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1475
|
+
case import_echo_schema9.FormatEnum.Number:
|
|
1476
|
+
case import_echo_schema9.FormatEnum.Percent:
|
|
1477
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1478
|
+
return parseScalar(import_echo_schema9.TypeEnum.Number);
|
|
1479
|
+
case import_echo_schema9.FormatEnum.String:
|
|
1480
|
+
case import_echo_schema9.FormatEnum.Markdown: {
|
|
1481
|
+
return parseScalar(import_echo_schema9.TypeEnum.String);
|
|
1337
1482
|
}
|
|
1338
|
-
case
|
|
1339
|
-
throw new Error(`unexpected format: ${
|
|
1340
|
-
case
|
|
1341
|
-
case
|
|
1342
|
-
case
|
|
1343
|
-
case
|
|
1483
|
+
case import_echo_schema9.FormatEnum.Ref:
|
|
1484
|
+
throw new Error(`unexpected format: ${import_echo_schema9.FormatEnum.Ref}`);
|
|
1485
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1486
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1487
|
+
case import_echo_schema9.FormatEnum.Time:
|
|
1488
|
+
case import_echo_schema9.FormatEnum.Timestamp: {
|
|
1344
1489
|
const date = new Date(value);
|
|
1345
1490
|
return isNaN(date.getTime()) ? null : date;
|
|
1346
1491
|
}
|
|
1492
|
+
case import_echo_schema9.FormatEnum.GeoPoint: {
|
|
1493
|
+
if (typeof value === "string") {
|
|
1494
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1495
|
+
const parts = cleaned.split(",");
|
|
1496
|
+
if (parts.length === 2) {
|
|
1497
|
+
const lat = parseFloat(parts[0]);
|
|
1498
|
+
const long = parseFloat(parts[1]);
|
|
1499
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1500
|
+
return import_echo_schema9.GeoLocation.toGeoPoint({
|
|
1501
|
+
latitude: lat,
|
|
1502
|
+
longitude: long
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return [
|
|
1508
|
+
0,
|
|
1509
|
+
0
|
|
1510
|
+
];
|
|
1511
|
+
}
|
|
1347
1512
|
default: {
|
|
1348
1513
|
return value;
|
|
1349
1514
|
}
|
|
@@ -1352,19 +1517,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1352
1517
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1353
1518
|
if (!format) {
|
|
1354
1519
|
switch (type) {
|
|
1355
|
-
case
|
|
1520
|
+
case import_echo_schema9.TypeEnum.Number:
|
|
1356
1521
|
return [
|
|
1357
1522
|
"text-right",
|
|
1358
1523
|
"font-mono"
|
|
1359
1524
|
];
|
|
1360
|
-
case
|
|
1525
|
+
case import_echo_schema9.TypeEnum.Boolean:
|
|
1361
1526
|
return [
|
|
1362
1527
|
"text-right",
|
|
1363
1528
|
"font-mono"
|
|
1364
1529
|
];
|
|
1365
|
-
case
|
|
1530
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1366
1531
|
return void 0;
|
|
1367
|
-
case
|
|
1532
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1368
1533
|
return void 0;
|
|
1369
1534
|
default: {
|
|
1370
1535
|
return void 0;
|
|
@@ -1372,20 +1537,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1372
1537
|
}
|
|
1373
1538
|
}
|
|
1374
1539
|
switch (format) {
|
|
1375
|
-
case
|
|
1540
|
+
case import_echo_schema9.FormatEnum.Markdown:
|
|
1376
1541
|
return void 0;
|
|
1377
|
-
case
|
|
1378
|
-
case
|
|
1379
|
-
case
|
|
1380
|
-
case
|
|
1542
|
+
case import_echo_schema9.FormatEnum.Timestamp:
|
|
1543
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1544
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1545
|
+
case import_echo_schema9.FormatEnum.Time:
|
|
1381
1546
|
return [
|
|
1382
1547
|
"font-mono"
|
|
1383
1548
|
];
|
|
1384
|
-
case
|
|
1549
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1385
1550
|
return [
|
|
1386
1551
|
"text-right"
|
|
1387
1552
|
];
|
|
1388
|
-
case
|
|
1553
|
+
case import_echo_schema9.FormatEnum.JSON:
|
|
1389
1554
|
return [
|
|
1390
1555
|
"font-mono"
|
|
1391
1556
|
];
|
|
@@ -1403,12 +1568,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1403
1568
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1404
1569
|
const formatScalar = (type2) => {
|
|
1405
1570
|
switch (type2) {
|
|
1406
|
-
case
|
|
1571
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1407
1572
|
return value.toLocaleString().toUpperCase();
|
|
1408
|
-
case
|
|
1573
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1409
1574
|
return value.toLocaleString(locale);
|
|
1410
|
-
case
|
|
1411
|
-
case
|
|
1575
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1576
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1412
1577
|
return String(value);
|
|
1413
1578
|
default: {
|
|
1414
1579
|
return String(value);
|
|
@@ -1419,20 +1584,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1419
1584
|
return formatScalar(type);
|
|
1420
1585
|
}
|
|
1421
1586
|
switch (format) {
|
|
1422
|
-
case
|
|
1423
|
-
return formatScalar(
|
|
1587
|
+
case import_echo_schema10.FormatEnum.Boolean: {
|
|
1588
|
+
return formatScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1424
1589
|
}
|
|
1425
|
-
case
|
|
1426
|
-
return formatScalar(
|
|
1590
|
+
case import_echo_schema10.FormatEnum.Number: {
|
|
1591
|
+
return formatScalar(import_echo_schema10.TypeEnum.Number);
|
|
1427
1592
|
}
|
|
1428
|
-
case
|
|
1429
|
-
case
|
|
1430
|
-
return formatScalar(
|
|
1593
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1594
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1595
|
+
return formatScalar(import_echo_schema10.TypeEnum.String);
|
|
1431
1596
|
}
|
|
1432
|
-
case
|
|
1597
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1433
1598
|
return `${value * 100}%`;
|
|
1434
1599
|
}
|
|
1435
|
-
case
|
|
1600
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1436
1601
|
return value.toLocaleString(locale, {
|
|
1437
1602
|
style: "currency",
|
|
1438
1603
|
currency: "USD",
|
|
@@ -1440,18 +1605,28 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1440
1605
|
maximumFractionDigits: 2
|
|
1441
1606
|
});
|
|
1442
1607
|
}
|
|
1443
|
-
case
|
|
1444
|
-
case
|
|
1445
|
-
case
|
|
1608
|
+
case import_echo_schema10.FormatEnum.DateTime:
|
|
1609
|
+
case import_echo_schema10.FormatEnum.Date:
|
|
1610
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1446
1611
|
const date = new Date(value);
|
|
1447
|
-
if (format ===
|
|
1612
|
+
if (format === import_echo_schema10.FormatEnum.DateTime) {
|
|
1448
1613
|
return date.toLocaleString(locale);
|
|
1449
|
-
} else if (format ===
|
|
1614
|
+
} else if (format === import_echo_schema10.FormatEnum.Date) {
|
|
1450
1615
|
return date.toLocaleDateString(locale);
|
|
1451
1616
|
} else {
|
|
1452
1617
|
return date.toLocaleTimeString(locale);
|
|
1453
1618
|
}
|
|
1454
1619
|
}
|
|
1620
|
+
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1621
|
+
if (value === null || value === void 0) {
|
|
1622
|
+
return "";
|
|
1623
|
+
}
|
|
1624
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1625
|
+
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1626
|
+
return `${latitude},${longitude}`;
|
|
1627
|
+
}
|
|
1628
|
+
return String(value);
|
|
1629
|
+
}
|
|
1455
1630
|
default: {
|
|
1456
1631
|
if (value === null || value === "undefined") {
|
|
1457
1632
|
return "";
|
|
@@ -1463,10 +1638,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1463
1638
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1464
1639
|
const formatScalar = (type2) => {
|
|
1465
1640
|
switch (type2) {
|
|
1466
|
-
case
|
|
1467
|
-
case
|
|
1468
|
-
case
|
|
1469
|
-
case
|
|
1641
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1642
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1643
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1644
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1470
1645
|
return String(value);
|
|
1471
1646
|
default:
|
|
1472
1647
|
return String(value);
|
|
@@ -1476,30 +1651,40 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1476
1651
|
return formatScalar(type);
|
|
1477
1652
|
}
|
|
1478
1653
|
switch (format) {
|
|
1479
|
-
case
|
|
1480
|
-
case
|
|
1481
|
-
case
|
|
1482
|
-
case
|
|
1654
|
+
case import_echo_schema10.FormatEnum.Boolean:
|
|
1655
|
+
case import_echo_schema10.FormatEnum.Number:
|
|
1656
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1657
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1483
1658
|
return formatScalar(type);
|
|
1484
1659
|
}
|
|
1485
|
-
case
|
|
1660
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1486
1661
|
return String(value * 100);
|
|
1487
1662
|
}
|
|
1488
|
-
case
|
|
1663
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1489
1664
|
return String(value);
|
|
1490
1665
|
}
|
|
1491
|
-
case
|
|
1666
|
+
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1492
1667
|
const date = new Date(value);
|
|
1493
1668
|
return date.toISOString();
|
|
1494
1669
|
}
|
|
1495
|
-
case
|
|
1670
|
+
case import_echo_schema10.FormatEnum.Date: {
|
|
1496
1671
|
const date = new Date(value);
|
|
1497
1672
|
return date.toISOString().split("T")[0];
|
|
1498
1673
|
}
|
|
1499
|
-
case
|
|
1674
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1500
1675
|
const date = new Date(value);
|
|
1501
1676
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1502
1677
|
}
|
|
1678
|
+
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1679
|
+
if (value === null || value === void 0) {
|
|
1680
|
+
return "";
|
|
1681
|
+
}
|
|
1682
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1683
|
+
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1684
|
+
return `${latitude},${longitude}`;
|
|
1685
|
+
}
|
|
1686
|
+
return String(value);
|
|
1687
|
+
}
|
|
1503
1688
|
default: {
|
|
1504
1689
|
return String(value);
|
|
1505
1690
|
}
|
|
@@ -1514,6 +1699,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1514
1699
|
Form,
|
|
1515
1700
|
GeoPointInput,
|
|
1516
1701
|
InputHeader,
|
|
1702
|
+
MarkdownInput,
|
|
1517
1703
|
NumberInput,
|
|
1518
1704
|
SelectInput,
|
|
1519
1705
|
SelectOptionInput,
|
|
@@ -1527,6 +1713,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1527
1713
|
parseValue,
|
|
1528
1714
|
pathNotUniqueError,
|
|
1529
1715
|
translations,
|
|
1530
|
-
useForm
|
|
1716
|
+
useForm,
|
|
1717
|
+
useFormValues
|
|
1531
1718
|
});
|
|
1532
1719
|
//# sourceMappingURL=index.cjs.map
|