@dxos/react-ui-form 0.7.5-labs.e27f9b9 → 0.7.5-labs.f400bbc
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 +546 -362
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +589 -401
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +546 -362
- 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 +61 -4
- package/src/components/Form/Form.tsx +9 -5
- package/src/components/Form/FormActions.tsx +1 -1
- package/src/components/Form/FormContent.tsx +10 -13
- 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,269 +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());
|
|
789
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
494
790
|
validationValence: status
|
|
495
|
-
}, !inputOnly && /* @__PURE__ */
|
|
791
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
496
792
|
error
|
|
497
|
-
}, /* @__PURE__ */
|
|
498
|
-
checked
|
|
793
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Switch, {
|
|
794
|
+
checked,
|
|
499
795
|
onCheckedChange: (value) => onValueChange(type, value)
|
|
500
|
-
}), inputOnly && /* @__PURE__ */
|
|
796
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
501
797
|
};
|
|
502
798
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
503
799
|
const { status, error } = getStatus();
|
|
504
|
-
return /* @__PURE__ */
|
|
800
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
505
801
|
validationValence: status
|
|
506
|
-
}, !inputOnly && /* @__PURE__ */
|
|
802
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
507
803
|
error
|
|
508
|
-
}, /* @__PURE__ */
|
|
804
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Root, {
|
|
509
805
|
value: getValue3(),
|
|
510
806
|
onValueChange: (value) => onValueChange(type, value)
|
|
511
|
-
}, /* @__PURE__ */
|
|
807
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
512
808
|
classNames: "is-full",
|
|
513
809
|
disabled,
|
|
514
810
|
placeholder
|
|
515
|
-
}), /* @__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 }) => (
|
|
516
812
|
// NOTE: Numeric values are converted to and from strings.
|
|
517
|
-
/* @__PURE__ */
|
|
813
|
+
/* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Option, {
|
|
518
814
|
key: String(value),
|
|
519
815
|
value: String(value)
|
|
520
816
|
}, label2 ?? String(value))
|
|
521
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
817
|
+
)))))), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
522
818
|
};
|
|
523
|
-
var
|
|
524
|
-
|
|
525
|
-
(0,
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
""
|
|
532
|
-
]
|
|
533
|
-
});
|
|
534
|
-
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
535
|
-
(0, import_react11.useEffect)(() => {
|
|
536
|
-
setValues(initialValues);
|
|
537
|
-
}, [
|
|
538
|
-
initialValues
|
|
539
|
-
]);
|
|
540
|
-
const [touched, setTouched] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
541
|
-
const [changed, setChanged] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
542
|
-
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
543
|
-
const [saving, setSaving] = (0, import_react11.useState)(false);
|
|
544
|
-
const validate = (0, import_react11.useCallback)((values2) => {
|
|
545
|
-
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
546
|
-
if (errors2.length === 0 && onValidate) {
|
|
547
|
-
const validatedValues = values2;
|
|
548
|
-
errors2 = onValidate(validatedValues) ?? [];
|
|
549
|
-
}
|
|
550
|
-
setErrors(flatMap(errors2));
|
|
551
|
-
const valid = errors2.length === 0;
|
|
552
|
-
return valid;
|
|
553
|
-
}, [
|
|
554
|
-
schema,
|
|
555
|
-
onValidate
|
|
556
|
-
]);
|
|
557
|
-
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
558
|
-
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
559
|
-
schema
|
|
560
|
-
]);
|
|
561
|
-
(0, import_react11.useEffect)(() => {
|
|
562
|
-
if (schemaDirty) {
|
|
563
|
-
validate(values);
|
|
564
|
-
setSchemaDirty(false);
|
|
565
|
-
}
|
|
566
|
-
}, [
|
|
567
|
-
values,
|
|
568
|
-
schemaDirty
|
|
569
|
-
]);
|
|
570
|
-
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
571
|
-
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
572
|
-
touched,
|
|
573
|
-
errors,
|
|
574
|
-
saving
|
|
575
|
-
]);
|
|
576
|
-
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
577
|
-
if (validate(values)) {
|
|
578
|
-
setSaving(true);
|
|
579
|
-
try {
|
|
580
|
-
await onSave?.(values, {
|
|
581
|
-
changed
|
|
582
|
-
});
|
|
583
|
-
} finally {
|
|
584
|
-
setSaving(false);
|
|
585
|
-
}
|
|
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`;
|
|
586
827
|
}
|
|
828
|
+
}, []);
|
|
829
|
+
(0, import_react9.useEffect)(() => {
|
|
830
|
+
adjustHeight();
|
|
587
831
|
}, [
|
|
588
|
-
|
|
589
|
-
validate,
|
|
590
|
-
onSave,
|
|
591
|
-
changed
|
|
832
|
+
adjustHeight
|
|
592
833
|
]);
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
596
|
-
return {
|
|
597
|
-
status: matchingError ? "error" : void 0,
|
|
598
|
-
error: matchingError ? matchingError[1] : void 0
|
|
599
|
-
};
|
|
834
|
+
(0, import_react9.useEffect)(() => {
|
|
835
|
+
adjustHeight();
|
|
600
836
|
}, [
|
|
601
|
-
|
|
837
|
+
getValue3(),
|
|
838
|
+
adjustHeight
|
|
602
839
|
]);
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
parsedValue = void 0;
|
|
621
|
-
}
|
|
622
|
-
const newValues = {
|
|
623
|
-
...(0, import_echo_schema3.setValue)(values, jsonPath, parsedValue)
|
|
624
|
-
};
|
|
625
|
-
setValues(newValues);
|
|
626
|
-
setChanged((prev) => ({
|
|
627
|
-
...prev,
|
|
628
|
-
[jsonPath]: true
|
|
629
|
-
}));
|
|
630
|
-
onValuesChanged?.(newValues);
|
|
631
|
-
const isValid = validate(newValues);
|
|
632
|
-
if (isValid && onValid) {
|
|
633
|
-
onValid(newValues, {
|
|
634
|
-
changed
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
639
|
-
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
640
|
-
setTouched((touched2) => ({
|
|
641
|
-
...touched2,
|
|
642
|
-
[jsonPath]: true
|
|
643
|
-
}));
|
|
644
|
-
validate(values);
|
|
645
|
-
}, [
|
|
646
|
-
validate,
|
|
647
|
-
values
|
|
648
|
-
]);
|
|
649
|
-
return {
|
|
650
|
-
// State.
|
|
651
|
-
values,
|
|
652
|
-
errors,
|
|
653
|
-
touched,
|
|
654
|
-
changed,
|
|
655
|
-
canSave,
|
|
656
|
-
handleSave,
|
|
657
|
-
// Field utils.
|
|
658
|
-
getStatus,
|
|
659
|
-
getValue: getFormValue,
|
|
660
|
-
onValueChange,
|
|
661
|
-
onTouched
|
|
662
|
-
};
|
|
663
|
-
};
|
|
664
|
-
var createKeySet = (obj, value) => {
|
|
665
|
-
(0, import_invariant.invariant)(obj, void 0, {
|
|
666
|
-
F: __dxlog_file,
|
|
667
|
-
L: 235,
|
|
668
|
-
S: void 0,
|
|
669
|
-
A: [
|
|
670
|
-
"obj",
|
|
671
|
-
""
|
|
672
|
-
]
|
|
673
|
-
});
|
|
674
|
-
return Object.keys(obj).reduce((acc, key) => ({
|
|
675
|
-
...acc,
|
|
676
|
-
[key]: value
|
|
677
|
-
}), {});
|
|
678
|
-
};
|
|
679
|
-
var flatMap = (errors) => {
|
|
680
|
-
return errors.reduce((result, { path, message }) => {
|
|
681
|
-
const jsonPath = (0, import_effect2.fromEffectValidationPath)(path);
|
|
682
|
-
if (!(jsonPath in result)) {
|
|
683
|
-
result[jsonPath] = message;
|
|
684
|
-
}
|
|
685
|
-
return result;
|
|
686
|
-
}, {});
|
|
687
|
-
};
|
|
688
|
-
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
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);
|
|
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));
|
|
711
857
|
};
|
|
712
858
|
var FormActions = ({ onCancel, readonly }) => {
|
|
713
859
|
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
714
860
|
const { canSave, handleSave } = useFormContext();
|
|
715
|
-
return /* @__PURE__ */
|
|
861
|
+
return /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
716
862
|
role: "none",
|
|
717
|
-
className: "flex justify-center"
|
|
718
|
-
}, /* @__PURE__ */
|
|
863
|
+
className: "mt-2 flex justify-center"
|
|
864
|
+
}, /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
719
865
|
role: "none",
|
|
720
866
|
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
721
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
867
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
722
868
|
"data-testid": "cancel-button",
|
|
723
869
|
icon: "ph--x--regular",
|
|
724
870
|
label: t("button cancel"),
|
|
725
871
|
onClick: onCancel
|
|
726
|
-
}), handleSave && /* @__PURE__ */
|
|
872
|
+
}), handleSave && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
727
873
|
type: "submit",
|
|
728
874
|
"data-testid": "save-button",
|
|
729
875
|
disabled: !canSave,
|
|
@@ -748,11 +894,11 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
748
894
|
]
|
|
749
895
|
});
|
|
750
896
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
751
|
-
const tupleType = (0, import_effect6.findNode)(ast,
|
|
897
|
+
const tupleType = (0, import_effect6.findNode)(ast, import_echo_schema6.AST.isTupleType);
|
|
752
898
|
const elementType = tupleType?.rest[0]?.type;
|
|
753
899
|
const getDefaultObjectValue = (typeNode) => {
|
|
754
900
|
const baseNode = (0, import_effect6.findNode)(typeNode, import_effect6.isDiscriminatedUnion);
|
|
755
|
-
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);
|
|
756
902
|
if (!typeLiteral) {
|
|
757
903
|
return {};
|
|
758
904
|
}
|
|
@@ -838,8 +984,10 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
838
984
|
};
|
|
839
985
|
var getInputComponent = (type, format) => {
|
|
840
986
|
switch (format) {
|
|
841
|
-
case
|
|
987
|
+
case import_echo_schema7.FormatEnum.GeoPoint:
|
|
842
988
|
return GeoPointInput;
|
|
989
|
+
case import_echo_schema7.FormatEnum.Markdown:
|
|
990
|
+
return MarkdownInput;
|
|
843
991
|
}
|
|
844
992
|
switch (type) {
|
|
845
993
|
case "string":
|
|
@@ -863,7 +1011,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
863
1011
|
]);
|
|
864
1012
|
const FoundComponent = lookupComponent?.({
|
|
865
1013
|
prop: name,
|
|
866
|
-
schema:
|
|
1014
|
+
schema: import_echo_schema5.S.make(ast),
|
|
867
1015
|
inputProps: {
|
|
868
1016
|
type,
|
|
869
1017
|
format,
|
|
@@ -881,20 +1029,15 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
881
1029
|
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
882
1030
|
const CustomComponent = Custom?.[jsonPath];
|
|
883
1031
|
if (CustomComponent) {
|
|
884
|
-
return (
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
placeholder,
|
|
894
|
-
disabled: readonly,
|
|
895
|
-
...inputProps
|
|
896
|
-
}))
|
|
897
|
-
);
|
|
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
|
+
});
|
|
898
1041
|
}
|
|
899
1042
|
if (array) {
|
|
900
1043
|
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
@@ -938,12 +1081,12 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
938
1081
|
}
|
|
939
1082
|
if (type === "object") {
|
|
940
1083
|
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,
|
|
1084
|
+
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema5.AST.isTypeLiteral);
|
|
942
1085
|
if (typeLiteral) {
|
|
943
1086
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
944
1087
|
role: "none"
|
|
945
1088
|
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
946
|
-
schema:
|
|
1089
|
+
schema: import_echo_schema5.S.make(typeLiteral),
|
|
947
1090
|
path,
|
|
948
1091
|
readonly,
|
|
949
1092
|
Custom
|
|
@@ -966,7 +1109,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
966
1109
|
]);
|
|
967
1110
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
968
1111
|
role: "form",
|
|
969
|
-
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2
|
|
1112
|
+
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2")
|
|
970
1113
|
}, properties.map((property) => {
|
|
971
1114
|
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
972
1115
|
key: property.name,
|
|
@@ -982,13 +1125,14 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
982
1125
|
}).filter(import_util3.isNotFalsy));
|
|
983
1126
|
};
|
|
984
1127
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
985
|
-
const
|
|
1128
|
+
const formRef = (0, import_react10.useRef)(null);
|
|
1129
|
+
const onValid = (0, import_react10.useMemo)(() => autoSave ? onSave : void 0, [
|
|
986
1130
|
autoSave,
|
|
987
1131
|
onSave
|
|
988
1132
|
]);
|
|
989
|
-
(0,
|
|
990
|
-
if (autoFocus) {
|
|
991
|
-
const input =
|
|
1133
|
+
(0, import_react10.useEffect)(() => {
|
|
1134
|
+
if (autoFocus && formRef.current) {
|
|
1135
|
+
const input = formRef.current.querySelector("input");
|
|
992
1136
|
if (input) {
|
|
993
1137
|
input.focus();
|
|
994
1138
|
}
|
|
@@ -996,18 +1140,21 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
996
1140
|
}, [
|
|
997
1141
|
autoFocus
|
|
998
1142
|
]);
|
|
999
|
-
return /* @__PURE__ */
|
|
1143
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormProvider, {
|
|
1144
|
+
formRef,
|
|
1000
1145
|
schema,
|
|
1146
|
+
autoSave,
|
|
1001
1147
|
initialValues,
|
|
1002
1148
|
onValuesChanged,
|
|
1003
1149
|
onValidate,
|
|
1004
1150
|
onValid,
|
|
1005
1151
|
onSave
|
|
1006
|
-
}, /* @__PURE__ */
|
|
1152
|
+
}, /* @__PURE__ */ import_react10.default.createElement("div", {
|
|
1153
|
+
ref: formRef,
|
|
1007
1154
|
role: "none",
|
|
1008
1155
|
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
1009
1156
|
"data-testid": testId
|
|
1010
|
-
}, /* @__PURE__ */
|
|
1157
|
+
}, /* @__PURE__ */ import_react10.default.createElement(FormFields, {
|
|
1011
1158
|
schema,
|
|
1012
1159
|
path,
|
|
1013
1160
|
readonly,
|
|
@@ -1015,7 +1162,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1015
1162
|
sort,
|
|
1016
1163
|
lookupComponent,
|
|
1017
1164
|
Custom
|
|
1018
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1165
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react10.default.createElement(FormActions, {
|
|
1019
1166
|
onCancel,
|
|
1020
1167
|
readonly
|
|
1021
1168
|
})));
|
|
@@ -1178,14 +1325,14 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1178
1325
|
});
|
|
1179
1326
|
};
|
|
1180
1327
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1181
|
-
var ViewMetaSchema =
|
|
1182
|
-
name:
|
|
1183
|
-
[
|
|
1328
|
+
var ViewMetaSchema = import_echo_schema8.S.Struct({
|
|
1329
|
+
name: import_echo_schema8.S.String.annotations({
|
|
1330
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "View"
|
|
1184
1331
|
}),
|
|
1185
|
-
typename:
|
|
1186
|
-
[
|
|
1332
|
+
typename: import_echo_schema8.Format.URL.annotations({
|
|
1333
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "Typename"
|
|
1187
1334
|
})
|
|
1188
|
-
}).pipe(
|
|
1335
|
+
}).pipe(import_echo_schema8.S.mutable);
|
|
1189
1336
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1190
1337
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1191
1338
|
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
@@ -1241,7 +1388,6 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1241
1388
|
role: "none",
|
|
1242
1389
|
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1243
1390
|
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
1244
|
-
autoFocus: true,
|
|
1245
1391
|
autoSave: true,
|
|
1246
1392
|
schema: ViewMetaSchema,
|
|
1247
1393
|
values: viewValues,
|
|
@@ -1253,7 +1399,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1253
1399
|
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1254
1400
|
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1255
1401
|
items: view.fields,
|
|
1256
|
-
isItem:
|
|
1402
|
+
isItem: import_echo_schema8.S.is(import_schema5.FieldSchema),
|
|
1257
1403
|
getId: (field2) => field2.id,
|
|
1258
1404
|
onMove: handleMove
|
|
1259
1405
|
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
@@ -1296,7 +1442,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1296
1442
|
}
|
|
1297
1443
|
const parseScalar = (type2) => {
|
|
1298
1444
|
switch (type2) {
|
|
1299
|
-
case
|
|
1445
|
+
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1300
1446
|
if (typeof value === "string") {
|
|
1301
1447
|
const lowercaseValue = value.toLowerCase();
|
|
1302
1448
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1307,13 +1453,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1307
1453
|
}
|
|
1308
1454
|
return Boolean(value);
|
|
1309
1455
|
}
|
|
1310
|
-
case
|
|
1456
|
+
case import_echo_schema9.TypeEnum.Number: {
|
|
1311
1457
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1312
1458
|
const num = Number(cleaned);
|
|
1313
1459
|
return Number.isNaN(num) ? null : num;
|
|
1314
1460
|
}
|
|
1315
|
-
case
|
|
1316
|
-
case
|
|
1461
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1462
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1317
1463
|
return String(value);
|
|
1318
1464
|
default: {
|
|
1319
1465
|
return value;
|
|
@@ -1324,25 +1470,45 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1324
1470
|
return parseScalar(type);
|
|
1325
1471
|
}
|
|
1326
1472
|
switch (format) {
|
|
1327
|
-
case
|
|
1328
|
-
return parseScalar(
|
|
1329
|
-
case
|
|
1330
|
-
case
|
|
1331
|
-
case
|
|
1332
|
-
return parseScalar(
|
|
1333
|
-
case
|
|
1334
|
-
case
|
|
1335
|
-
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);
|
|
1336
1482
|
}
|
|
1337
|
-
case
|
|
1338
|
-
throw new Error(`unexpected format: ${
|
|
1339
|
-
case
|
|
1340
|
-
case
|
|
1341
|
-
case
|
|
1342
|
-
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: {
|
|
1343
1489
|
const date = new Date(value);
|
|
1344
1490
|
return isNaN(date.getTime()) ? null : date;
|
|
1345
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
|
+
}
|
|
1346
1512
|
default: {
|
|
1347
1513
|
return value;
|
|
1348
1514
|
}
|
|
@@ -1351,19 +1517,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1351
1517
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1352
1518
|
if (!format) {
|
|
1353
1519
|
switch (type) {
|
|
1354
|
-
case
|
|
1520
|
+
case import_echo_schema9.TypeEnum.Number:
|
|
1355
1521
|
return [
|
|
1356
1522
|
"text-right",
|
|
1357
1523
|
"font-mono"
|
|
1358
1524
|
];
|
|
1359
|
-
case
|
|
1525
|
+
case import_echo_schema9.TypeEnum.Boolean:
|
|
1360
1526
|
return [
|
|
1361
1527
|
"text-right",
|
|
1362
1528
|
"font-mono"
|
|
1363
1529
|
];
|
|
1364
|
-
case
|
|
1530
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1365
1531
|
return void 0;
|
|
1366
|
-
case
|
|
1532
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1367
1533
|
return void 0;
|
|
1368
1534
|
default: {
|
|
1369
1535
|
return void 0;
|
|
@@ -1371,20 +1537,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1371
1537
|
}
|
|
1372
1538
|
}
|
|
1373
1539
|
switch (format) {
|
|
1374
|
-
case
|
|
1540
|
+
case import_echo_schema9.FormatEnum.Markdown:
|
|
1375
1541
|
return void 0;
|
|
1376
|
-
case
|
|
1377
|
-
case
|
|
1378
|
-
case
|
|
1379
|
-
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:
|
|
1380
1546
|
return [
|
|
1381
1547
|
"font-mono"
|
|
1382
1548
|
];
|
|
1383
|
-
case
|
|
1549
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1384
1550
|
return [
|
|
1385
1551
|
"text-right"
|
|
1386
1552
|
];
|
|
1387
|
-
case
|
|
1553
|
+
case import_echo_schema9.FormatEnum.JSON:
|
|
1388
1554
|
return [
|
|
1389
1555
|
"font-mono"
|
|
1390
1556
|
];
|
|
@@ -1402,12 +1568,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1402
1568
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1403
1569
|
const formatScalar = (type2) => {
|
|
1404
1570
|
switch (type2) {
|
|
1405
|
-
case
|
|
1571
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1406
1572
|
return value.toLocaleString().toUpperCase();
|
|
1407
|
-
case
|
|
1573
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1408
1574
|
return value.toLocaleString(locale);
|
|
1409
|
-
case
|
|
1410
|
-
case
|
|
1575
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1576
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1411
1577
|
return String(value);
|
|
1412
1578
|
default: {
|
|
1413
1579
|
return String(value);
|
|
@@ -1418,20 +1584,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1418
1584
|
return formatScalar(type);
|
|
1419
1585
|
}
|
|
1420
1586
|
switch (format) {
|
|
1421
|
-
case
|
|
1422
|
-
return formatScalar(
|
|
1587
|
+
case import_echo_schema10.FormatEnum.Boolean: {
|
|
1588
|
+
return formatScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1423
1589
|
}
|
|
1424
|
-
case
|
|
1425
|
-
return formatScalar(
|
|
1590
|
+
case import_echo_schema10.FormatEnum.Number: {
|
|
1591
|
+
return formatScalar(import_echo_schema10.TypeEnum.Number);
|
|
1426
1592
|
}
|
|
1427
|
-
case
|
|
1428
|
-
case
|
|
1429
|
-
return formatScalar(
|
|
1593
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1594
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1595
|
+
return formatScalar(import_echo_schema10.TypeEnum.String);
|
|
1430
1596
|
}
|
|
1431
|
-
case
|
|
1597
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1432
1598
|
return `${value * 100}%`;
|
|
1433
1599
|
}
|
|
1434
|
-
case
|
|
1600
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1435
1601
|
return value.toLocaleString(locale, {
|
|
1436
1602
|
style: "currency",
|
|
1437
1603
|
currency: "USD",
|
|
@@ -1439,18 +1605,28 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1439
1605
|
maximumFractionDigits: 2
|
|
1440
1606
|
});
|
|
1441
1607
|
}
|
|
1442
|
-
case
|
|
1443
|
-
case
|
|
1444
|
-
case
|
|
1608
|
+
case import_echo_schema10.FormatEnum.DateTime:
|
|
1609
|
+
case import_echo_schema10.FormatEnum.Date:
|
|
1610
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1445
1611
|
const date = new Date(value);
|
|
1446
|
-
if (format ===
|
|
1612
|
+
if (format === import_echo_schema10.FormatEnum.DateTime) {
|
|
1447
1613
|
return date.toLocaleString(locale);
|
|
1448
|
-
} else if (format ===
|
|
1614
|
+
} else if (format === import_echo_schema10.FormatEnum.Date) {
|
|
1449
1615
|
return date.toLocaleDateString(locale);
|
|
1450
1616
|
} else {
|
|
1451
1617
|
return date.toLocaleTimeString(locale);
|
|
1452
1618
|
}
|
|
1453
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
|
+
}
|
|
1454
1630
|
default: {
|
|
1455
1631
|
if (value === null || value === "undefined") {
|
|
1456
1632
|
return "";
|
|
@@ -1462,10 +1638,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1462
1638
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1463
1639
|
const formatScalar = (type2) => {
|
|
1464
1640
|
switch (type2) {
|
|
1465
|
-
case
|
|
1466
|
-
case
|
|
1467
|
-
case
|
|
1468
|
-
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:
|
|
1469
1645
|
return String(value);
|
|
1470
1646
|
default:
|
|
1471
1647
|
return String(value);
|
|
@@ -1475,30 +1651,40 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1475
1651
|
return formatScalar(type);
|
|
1476
1652
|
}
|
|
1477
1653
|
switch (format) {
|
|
1478
|
-
case
|
|
1479
|
-
case
|
|
1480
|
-
case
|
|
1481
|
-
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: {
|
|
1482
1658
|
return formatScalar(type);
|
|
1483
1659
|
}
|
|
1484
|
-
case
|
|
1660
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1485
1661
|
return String(value * 100);
|
|
1486
1662
|
}
|
|
1487
|
-
case
|
|
1663
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1488
1664
|
return String(value);
|
|
1489
1665
|
}
|
|
1490
|
-
case
|
|
1666
|
+
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1491
1667
|
const date = new Date(value);
|
|
1492
1668
|
return date.toISOString();
|
|
1493
1669
|
}
|
|
1494
|
-
case
|
|
1670
|
+
case import_echo_schema10.FormatEnum.Date: {
|
|
1495
1671
|
const date = new Date(value);
|
|
1496
1672
|
return date.toISOString().split("T")[0];
|
|
1497
1673
|
}
|
|
1498
|
-
case
|
|
1674
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1499
1675
|
const date = new Date(value);
|
|
1500
1676
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1501
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
|
+
}
|
|
1502
1688
|
default: {
|
|
1503
1689
|
return String(value);
|
|
1504
1690
|
}
|
|
@@ -1513,6 +1699,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1513
1699
|
Form,
|
|
1514
1700
|
GeoPointInput,
|
|
1515
1701
|
InputHeader,
|
|
1702
|
+
MarkdownInput,
|
|
1516
1703
|
NumberInput,
|
|
1517
1704
|
SelectInput,
|
|
1518
1705
|
SelectOptionInput,
|
|
@@ -1526,6 +1713,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1526
1713
|
parseValue,
|
|
1527
1714
|
pathNotUniqueError,
|
|
1528
1715
|
translations,
|
|
1529
|
-
useForm
|
|
1716
|
+
useForm,
|
|
1717
|
+
useFormValues
|
|
1530
1718
|
});
|
|
1531
1719
|
//# sourceMappingURL=index.cjs.map
|