@dxos/react-ui-form 0.7.5-main.e9bb01b → 0.7.5-staging.2ff1350
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 +532 -360
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +567 -391
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +532 -360
- 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 +3 -2
- 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 +28 -27
- package/src/components/Form/Defaults.tsx +61 -2
- package/src/components/Form/Form.tsx +17 -2
- package/src/components/Form/FormActions.tsx +1 -1
- package/src/components/Form/FormContent.tsx +10 -13
- package/src/components/Form/FormContext.tsx +48 -4
- 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/components/deprecated/FormInput.tsx +1 -4
- package/src/hooks/useForm.ts +10 -3
- 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
|
{
|
|
@@ -206,66 +209,327 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
206
209
|
}, children))));
|
|
207
210
|
if (secondary) {
|
|
208
211
|
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
209
|
-
role: "none"
|
|
210
|
-
className: "flex flex-col w-full"
|
|
212
|
+
role: "none"
|
|
211
213
|
}, primary, secondary);
|
|
212
214
|
}
|
|
213
215
|
return primary;
|
|
214
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 = (path) => {
|
|
303
|
+
return (0, import_echo_schema3.getValue)(values, (0, import_effect2.createJsonPath)(path));
|
|
304
|
+
};
|
|
305
|
+
const onValueChange = (path, type, value) => {
|
|
306
|
+
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
307
|
+
let parsedValue = value;
|
|
308
|
+
try {
|
|
309
|
+
if (type === "number") {
|
|
310
|
+
parsedValue = parseFloat(value) || 0;
|
|
311
|
+
}
|
|
312
|
+
} catch (err) {
|
|
313
|
+
import_log2.log.catch(err, void 0, {
|
|
314
|
+
F: __dxlog_file,
|
|
315
|
+
L: 198,
|
|
316
|
+
S: void 0,
|
|
317
|
+
C: (f, a) => f(...a)
|
|
318
|
+
});
|
|
319
|
+
parsedValue = void 0;
|
|
320
|
+
}
|
|
321
|
+
const newValues = {
|
|
322
|
+
...(0, import_echo_schema3.setValue)(values, jsonPath, parsedValue)
|
|
323
|
+
};
|
|
324
|
+
setValues(newValues);
|
|
325
|
+
setChanged((prev) => ({
|
|
326
|
+
...prev,
|
|
327
|
+
[jsonPath]: true
|
|
328
|
+
}));
|
|
329
|
+
onValuesChanged?.(newValues);
|
|
330
|
+
const isValid = validate(newValues);
|
|
331
|
+
if (isValid && onValid) {
|
|
332
|
+
onValid(newValues, {
|
|
333
|
+
changed
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const onTouched = (0, import_react4.useCallback)((path) => {
|
|
338
|
+
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
339
|
+
setTouched((touched2) => ({
|
|
340
|
+
...touched2,
|
|
341
|
+
[jsonPath]: true
|
|
342
|
+
}));
|
|
343
|
+
validate(values);
|
|
344
|
+
}, [
|
|
345
|
+
validate,
|
|
346
|
+
values
|
|
347
|
+
]);
|
|
348
|
+
return {
|
|
349
|
+
// State.
|
|
350
|
+
values,
|
|
351
|
+
errors,
|
|
352
|
+
touched,
|
|
353
|
+
changed,
|
|
354
|
+
canSave,
|
|
355
|
+
handleSave,
|
|
356
|
+
formIsValid,
|
|
357
|
+
// Field utils.
|
|
358
|
+
getStatus,
|
|
359
|
+
getValue: getFormValue,
|
|
360
|
+
onValueChange,
|
|
361
|
+
onTouched
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
var createKeySet = (obj, value) => {
|
|
365
|
+
(0, import_invariant.invariant)(obj, void 0, {
|
|
366
|
+
F: __dxlog_file,
|
|
367
|
+
L: 241,
|
|
368
|
+
S: void 0,
|
|
369
|
+
A: [
|
|
370
|
+
"obj",
|
|
371
|
+
""
|
|
372
|
+
]
|
|
373
|
+
});
|
|
374
|
+
return Object.keys(obj).reduce((acc, key) => ({
|
|
375
|
+
...acc,
|
|
376
|
+
[key]: value
|
|
377
|
+
}), {});
|
|
378
|
+
};
|
|
379
|
+
var flatMap = (errors) => {
|
|
380
|
+
return errors.reduce((result, { path, message }) => {
|
|
381
|
+
const jsonPath = (0, import_effect2.fromEffectValidationPath)(path);
|
|
382
|
+
if (!(jsonPath in result)) {
|
|
383
|
+
result[jsonPath] = message;
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
386
|
+
}, {});
|
|
387
|
+
};
|
|
388
|
+
var FormContext = /* @__PURE__ */ (0, import_react3.createContext)(void 0);
|
|
389
|
+
var useFormContext = () => {
|
|
390
|
+
return (0, import_react3.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
391
|
+
};
|
|
392
|
+
var useFormValues = (path = []) => {
|
|
393
|
+
const { values: formValues } = useFormContext();
|
|
394
|
+
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
395
|
+
return (0, import_echo_schema2.getValue)(formValues, jsonPath);
|
|
396
|
+
};
|
|
397
|
+
var useInputProps = (path = []) => {
|
|
398
|
+
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
399
|
+
return {
|
|
400
|
+
getStatus: () => getStatus(path),
|
|
401
|
+
getValue: () => getFormValue(path),
|
|
402
|
+
onValueChange: (type, value) => onValueChange(path, type, value),
|
|
403
|
+
onBlur: () => onTouched(path)
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
407
|
+
const form = useForm(formOptions);
|
|
408
|
+
(0, import_react3.useEffect)(() => {
|
|
409
|
+
if (!formRef?.current) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const handleKeyDown = (event) => {
|
|
413
|
+
const keyIsEnter = event.key === "Enter";
|
|
414
|
+
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
415
|
+
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
416
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
417
|
+
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
418
|
+
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
419
|
+
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
420
|
+
if (!autoSave && form.canSave) {
|
|
421
|
+
form.handleSave();
|
|
422
|
+
}
|
|
423
|
+
if (autoSave && form.formIsValid) {
|
|
424
|
+
event.target.blur();
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const formElement = formRef.current;
|
|
429
|
+
formElement.addEventListener("keydown", handleKeyDown);
|
|
430
|
+
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
431
|
+
}, [
|
|
432
|
+
formRef,
|
|
433
|
+
form.canSave,
|
|
434
|
+
form.formIsValid,
|
|
435
|
+
form.handleSave,
|
|
436
|
+
autoSave
|
|
437
|
+
]);
|
|
438
|
+
return /* @__PURE__ */ import_react3.default.createElement(FormContext.Provider, {
|
|
439
|
+
value: form
|
|
440
|
+
}, children);
|
|
441
|
+
};
|
|
215
442
|
var InputHeader = ({ children, error }) => {
|
|
216
|
-
return /* @__PURE__ */
|
|
443
|
+
return /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
217
444
|
role: "none",
|
|
218
445
|
className: "flex justify-between items-center mb-1"
|
|
219
|
-
}, children, error && /* @__PURE__ */
|
|
446
|
+
}, children, error && /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
220
447
|
asChild: true
|
|
221
|
-
}, /* @__PURE__ */
|
|
448
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Icon, {
|
|
222
449
|
icon: "ph--warning--regular",
|
|
223
450
|
size: 4,
|
|
224
451
|
classNames: import_react_ui_theme2.errorText
|
|
225
|
-
})), /* @__PURE__ */
|
|
452
|
+
})), /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
226
453
|
side: "bottom"
|
|
227
|
-
}, /* @__PURE__ */
|
|
454
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
228
455
|
};
|
|
229
456
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
230
457
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
231
458
|
const { status, error } = getStatus();
|
|
232
|
-
const
|
|
233
|
-
|
|
459
|
+
const geoPoint = (0, import_react5.useMemo)(() => getValue3() ?? [
|
|
460
|
+
0,
|
|
461
|
+
0
|
|
462
|
+
], [
|
|
463
|
+
getValue3
|
|
464
|
+
]);
|
|
465
|
+
const geoLocation = (0, import_react5.useMemo)(() => import_echo_schema4.GeoLocation.fromGeoPoint(geoPoint), [
|
|
466
|
+
geoPoint
|
|
467
|
+
]);
|
|
468
|
+
const [longitudeText, setLongitudeText] = (0, import_react5.useState)(geoLocation.longitude?.toString());
|
|
469
|
+
const [latitudeText, setLatitudeText] = (0, import_react5.useState)(geoLocation.latitude?.toString());
|
|
470
|
+
(0, import_react5.useEffect)(() => {
|
|
471
|
+
const location = import_echo_schema4.GeoLocation.fromGeoPoint(geoPoint);
|
|
472
|
+
setLongitudeText(location.longitude.toString());
|
|
473
|
+
setLatitudeText(location.latitude.toString());
|
|
474
|
+
}, [
|
|
475
|
+
geoPoint
|
|
476
|
+
]);
|
|
477
|
+
const handleCoordinateChange = (0, import_react5.useCallback)((coordinateType, setText) => (event) => {
|
|
478
|
+
const inputText = event.target.value;
|
|
479
|
+
setText(inputText);
|
|
480
|
+
if (inputText !== "" && inputText !== "-") {
|
|
481
|
+
const coord = (0, import_util.safeParseFloat)(inputText);
|
|
482
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
483
|
+
const currentLocation = import_echo_schema4.GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
484
|
+
0,
|
|
485
|
+
0
|
|
486
|
+
]);
|
|
487
|
+
const newLocation = {
|
|
488
|
+
...currentLocation,
|
|
489
|
+
[coordinateType]: coord
|
|
490
|
+
};
|
|
491
|
+
const newValue = import_echo_schema4.GeoLocation.toGeoPoint(newLocation);
|
|
492
|
+
onValueChange(type, newValue);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}, [
|
|
496
|
+
getValue3,
|
|
497
|
+
onValueChange,
|
|
498
|
+
type
|
|
499
|
+
]);
|
|
500
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Root, {
|
|
234
501
|
validationValence: status
|
|
235
|
-
}, /* @__PURE__ */
|
|
502
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
236
503
|
error
|
|
237
|
-
}, /* @__PURE__ */
|
|
504
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
505
|
+
role: "none",
|
|
238
506
|
className: "grid grid-cols-2 gap-2"
|
|
239
|
-
}, /* @__PURE__ */
|
|
240
|
-
type: "
|
|
507
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
508
|
+
type: "text",
|
|
509
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
241
510
|
disabled,
|
|
242
|
-
placeholder: t("placeholder
|
|
243
|
-
value:
|
|
244
|
-
onChange: (
|
|
245
|
-
lat,
|
|
246
|
-
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
247
|
-
]),
|
|
511
|
+
placeholder: t("placeholder latitude"),
|
|
512
|
+
value: latitudeText,
|
|
513
|
+
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
248
514
|
onBlur
|
|
249
|
-
}), /* @__PURE__ */
|
|
250
|
-
type: "
|
|
515
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
516
|
+
type: "text",
|
|
517
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
251
518
|
disabled,
|
|
252
|
-
placeholder: t("placeholder
|
|
253
|
-
value:
|
|
254
|
-
onChange: (
|
|
255
|
-
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
256
|
-
lng
|
|
257
|
-
]),
|
|
519
|
+
placeholder: t("placeholder longitude"),
|
|
520
|
+
value: longitudeText,
|
|
521
|
+
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
258
522
|
onBlur
|
|
259
523
|
})));
|
|
260
524
|
};
|
|
261
525
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
262
|
-
const [selected, setSelectedId] = (0,
|
|
263
|
-
const [isNewOption, setIsNewOption] = (0,
|
|
264
|
-
const inputRef = (0,
|
|
526
|
+
const [selected, setSelectedId] = (0, import_react7.useState)(null);
|
|
527
|
+
const [isNewOption, setIsNewOption] = (0, import_react7.useState)(false);
|
|
528
|
+
const inputRef = (0, import_react7.useRef)(null);
|
|
265
529
|
const { t } = (0, import_react_ui5.useTranslation)(translationKey);
|
|
266
530
|
const { status, error } = getStatus();
|
|
267
531
|
const options = getValue3();
|
|
268
|
-
(0,
|
|
532
|
+
(0, import_react7.useEffect)(() => {
|
|
269
533
|
if (options === void 0) {
|
|
270
534
|
onValueChange(type, []);
|
|
271
535
|
}
|
|
@@ -276,16 +540,15 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
276
540
|
]);
|
|
277
541
|
const randomHue = () => {
|
|
278
542
|
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
279
|
-
const
|
|
280
|
-
const unusedHues = hueKeys.filter((hue) => !usedHues.has(hue));
|
|
543
|
+
const unusedHues = import_react_ui_theme3.hues.filter((hue) => !usedHues.has(hue));
|
|
281
544
|
if (unusedHues.length > 0) {
|
|
282
545
|
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
283
546
|
}
|
|
284
547
|
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
285
|
-
const availableHues =
|
|
286
|
-
return availableHues[Math.floor(Math.random() * availableHues.length)] ??
|
|
548
|
+
const availableHues = import_react_ui_theme3.hues.filter((hue) => !lastThree.has(hue));
|
|
549
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? import_react_ui_theme3.hues[Math.floor(Math.random() * import_react_ui_theme3.hues.length)];
|
|
287
550
|
};
|
|
288
|
-
const handleAdd = (0,
|
|
551
|
+
const handleAdd = (0, import_react7.useCallback)(() => {
|
|
289
552
|
const newId = import_keys.PublicKey.random().truncate();
|
|
290
553
|
const newOption = {
|
|
291
554
|
id: newId,
|
|
@@ -303,7 +566,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
303
566
|
type,
|
|
304
567
|
onValueChange
|
|
305
568
|
]);
|
|
306
|
-
const handleDelete = (0,
|
|
569
|
+
const handleDelete = (0, import_react7.useCallback)((id) => {
|
|
307
570
|
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
308
571
|
onValueChange(type, newOptions);
|
|
309
572
|
setSelectedId(null);
|
|
@@ -312,7 +575,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
312
575
|
type,
|
|
313
576
|
onValueChange
|
|
314
577
|
]);
|
|
315
|
-
const handleMove = (0,
|
|
578
|
+
const handleMove = (0, import_react7.useCallback)((from, to) => {
|
|
316
579
|
if (!options) {
|
|
317
580
|
return;
|
|
318
581
|
}
|
|
@@ -327,10 +590,10 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
327
590
|
type,
|
|
328
591
|
onValueChange
|
|
329
592
|
]);
|
|
330
|
-
const handleClick = (0,
|
|
593
|
+
const handleClick = (0, import_react7.useCallback)((id) => {
|
|
331
594
|
setSelectedId((current) => current === id ? null : id);
|
|
332
595
|
}, []);
|
|
333
|
-
const handleTitleChange = (0,
|
|
596
|
+
const handleTitleChange = (0, import_react7.useCallback)((id) => (e) => {
|
|
334
597
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
335
598
|
...o,
|
|
336
599
|
title: e.target.value
|
|
@@ -341,12 +604,12 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
341
604
|
type,
|
|
342
605
|
onValueChange
|
|
343
606
|
]);
|
|
344
|
-
const handleKeyDown = (0,
|
|
607
|
+
const handleKeyDown = (0, import_react7.useCallback)((e) => {
|
|
345
608
|
if (e.key === "Enter") {
|
|
346
609
|
setSelectedId(null);
|
|
347
610
|
}
|
|
348
611
|
}, []);
|
|
349
|
-
const handleColorChange = (0,
|
|
612
|
+
const handleColorChange = (0, import_react7.useCallback)((id) => (hue) => {
|
|
350
613
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
351
614
|
...o,
|
|
352
615
|
color: hue
|
|
@@ -357,7 +620,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
357
620
|
type,
|
|
358
621
|
onValueChange
|
|
359
622
|
]);
|
|
360
|
-
(0,
|
|
623
|
+
(0, import_react7.useEffect)(() => {
|
|
361
624
|
if (selected && isNewOption && inputRef.current) {
|
|
362
625
|
inputRef.current.focus();
|
|
363
626
|
setIsNewOption(false);
|
|
@@ -366,70 +629,71 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
366
629
|
selected,
|
|
367
630
|
isNewOption
|
|
368
631
|
]);
|
|
369
|
-
return /* @__PURE__ */
|
|
632
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Root, {
|
|
370
633
|
validationValence: status
|
|
371
|
-
}, /* @__PURE__ */
|
|
634
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
372
635
|
error
|
|
373
|
-
}, /* @__PURE__ */
|
|
636
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
374
637
|
role: "none"
|
|
375
|
-
}, options && /* @__PURE__ */
|
|
638
|
+
}, options && /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.Root, {
|
|
376
639
|
items: options,
|
|
377
640
|
isItem: (item) => true,
|
|
378
641
|
onMove: handleMove
|
|
379
|
-
}, ({ items }) => /* @__PURE__ */
|
|
642
|
+
}, ({ items }) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
380
643
|
role: "list",
|
|
381
644
|
className: "w-full overflow-auto"
|
|
382
|
-
}, items?.map((item) => /* @__PURE__ */
|
|
645
|
+
}, items?.map((item) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
383
646
|
key: item.id
|
|
384
|
-
}, /* @__PURE__ */
|
|
647
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.Item, {
|
|
385
648
|
role: "button",
|
|
386
649
|
item,
|
|
387
650
|
classNames: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
388
651
|
"aria-expanded": selected === item.id
|
|
389
|
-
}, /* @__PURE__ */
|
|
652
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
390
653
|
className: "flex items-center"
|
|
391
|
-
}, /* @__PURE__ */
|
|
654
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react7.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
392
655
|
onClick: () => handleClick(item.id),
|
|
393
656
|
classNames: "flex-1"
|
|
394
|
-
}, /* @__PURE__ */
|
|
657
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tag, {
|
|
395
658
|
palette: item.color
|
|
396
|
-
}, item.title || "\u200B")), /* @__PURE__ */
|
|
659
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
397
660
|
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
398
661
|
onClick: () => handleClick(item.id)
|
|
399
|
-
})), selected === item.id && /* @__PURE__ */
|
|
662
|
+
})), selected === item.id && /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
400
663
|
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
401
|
-
}, /* @__PURE__ */
|
|
664
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.Label, {
|
|
402
665
|
classNames: "text-xs"
|
|
403
|
-
}, t("select option label")), /* @__PURE__ */
|
|
666
|
+
}, t("select option label")), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
404
667
|
className: "flex flex-row items-center gap-1"
|
|
405
|
-
}, /* @__PURE__ */
|
|
668
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Input.TextInput, {
|
|
406
669
|
placeholder: t("select option label placeholder"),
|
|
407
670
|
ref: selected === item.id ? inputRef : void 0,
|
|
408
671
|
value: item.title,
|
|
409
672
|
onChange: handleTitleChange(item.id),
|
|
410
673
|
onKeyDown: handleKeyDown,
|
|
411
|
-
classNames: "flex-1"
|
|
412
|
-
|
|
674
|
+
classNames: "flex-1",
|
|
675
|
+
"data-no-submit": true
|
|
676
|
+
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
413
677
|
classNames: "p-0 m-0 !is-auto"
|
|
414
|
-
}, /* @__PURE__ */
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
})), /* @__PURE__ */
|
|
678
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_pickers.HuePicker, {
|
|
679
|
+
value: item.color,
|
|
680
|
+
onChange: handleColorChange(item.id)
|
|
681
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.IconButton, {
|
|
418
682
|
icon: "ph--trash--fill",
|
|
419
683
|
iconOnly: true,
|
|
420
684
|
label: t("select option delete"),
|
|
421
685
|
onClick: () => handleDelete(item.id)
|
|
422
|
-
})))))), /* @__PURE__ */
|
|
686
|
+
})))))), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
423
687
|
role: "listitem"
|
|
424
|
-
}, /* @__PURE__ */
|
|
688
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
425
689
|
role: "button",
|
|
426
690
|
className: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
427
691
|
onClick: handleAdd
|
|
428
|
-
}, /* @__PURE__ */
|
|
692
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
429
693
|
className: "flex items-center gap-1"
|
|
430
|
-
}, /* @__PURE__ */
|
|
694
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
431
695
|
icon: "ph--plus--regular"
|
|
432
|
-
}), /* @__PURE__ */
|
|
696
|
+
}), /* @__PURE__ */ import_react7.default.createElement("span", {
|
|
433
697
|
className: "text-sm"
|
|
434
698
|
}, t("select option add")))))))));
|
|
435
699
|
};
|
|
@@ -442,13 +706,13 @@ var gridCols = [
|
|
|
442
706
|
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
443
707
|
const { status, error } = getStatus();
|
|
444
708
|
const values = getValue3() ?? {};
|
|
445
|
-
return /* @__PURE__ */
|
|
709
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.Root, {
|
|
446
710
|
validationValence: status
|
|
447
|
-
}, /* @__PURE__ */
|
|
711
|
+
}, /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
448
712
|
error
|
|
449
|
-
}, /* @__PURE__ */
|
|
713
|
+
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
450
714
|
className: (0, import_react_ui_theme4.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
451
|
-
}, binding.map((prop) => /* @__PURE__ */
|
|
715
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react8.default.createElement(import_react_ui6.Input.TextInput, {
|
|
452
716
|
key: prop,
|
|
453
717
|
type: "number",
|
|
454
718
|
disabled,
|
|
@@ -462,260 +726,120 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
462
726
|
};
|
|
463
727
|
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
464
728
|
const { status, error } = getStatus();
|
|
465
|
-
return /* @__PURE__ */
|
|
729
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
466
730
|
validationValence: status
|
|
467
|
-
}, !inputOnly && /* @__PURE__ */
|
|
731
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
468
732
|
error
|
|
469
|
-
}, /* @__PURE__ */
|
|
733
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextInput, {
|
|
470
734
|
disabled,
|
|
471
735
|
placeholder,
|
|
472
736
|
value: getValue3() ?? "",
|
|
473
737
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
474
738
|
onBlur
|
|
475
|
-
}), inputOnly && /* @__PURE__ */
|
|
739
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
476
740
|
};
|
|
477
741
|
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
478
742
|
const { status, error } = getStatus();
|
|
479
|
-
return /* @__PURE__ */
|
|
743
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
480
744
|
validationValence: status
|
|
481
|
-
}, !inputOnly && /* @__PURE__ */
|
|
745
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
482
746
|
error
|
|
483
|
-
}, /* @__PURE__ */
|
|
747
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextInput, {
|
|
484
748
|
type: "number",
|
|
485
749
|
disabled,
|
|
486
750
|
placeholder,
|
|
487
751
|
value: getValue3() ?? 0,
|
|
488
752
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
489
753
|
onBlur
|
|
490
|
-
}), inputOnly && /* @__PURE__ */
|
|
754
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
491
755
|
};
|
|
492
756
|
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
493
757
|
const { status, error } = getStatus();
|
|
494
|
-
|
|
758
|
+
const checked = Boolean(getValue3());
|
|
759
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
495
760
|
validationValence: status
|
|
496
|
-
}, !inputOnly && /* @__PURE__ */
|
|
761
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
497
762
|
error
|
|
498
|
-
}, /* @__PURE__ */
|
|
499
|
-
checked
|
|
763
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Switch, {
|
|
764
|
+
checked,
|
|
500
765
|
onCheckedChange: (value) => onValueChange(type, value)
|
|
501
|
-
}), inputOnly && /* @__PURE__ */
|
|
766
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
502
767
|
};
|
|
503
768
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
504
769
|
const { status, error } = getStatus();
|
|
505
|
-
return /* @__PURE__ */
|
|
770
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
506
771
|
validationValence: status
|
|
507
|
-
}, !inputOnly && /* @__PURE__ */
|
|
772
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
508
773
|
error
|
|
509
|
-
}, /* @__PURE__ */
|
|
774
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Root, {
|
|
510
775
|
value: getValue3(),
|
|
511
776
|
onValueChange: (value) => onValueChange(type, value)
|
|
512
|
-
}, /* @__PURE__ */
|
|
777
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
513
778
|
classNames: "is-full",
|
|
514
779
|
disabled,
|
|
515
780
|
placeholder
|
|
516
|
-
}), /* @__PURE__ */
|
|
781
|
+
}), /* @__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
782
|
// NOTE: Numeric values are converted to and from strings.
|
|
518
|
-
/* @__PURE__ */
|
|
783
|
+
/* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Select.Option, {
|
|
519
784
|
key: String(value),
|
|
520
785
|
value: String(value)
|
|
521
786
|
}, label2 ?? String(value))
|
|
522
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
787
|
+
)))))), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
523
788
|
};
|
|
524
|
-
var
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
(0,
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const [touched, setTouched] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
533
|
-
const [changed, setChanged] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
534
|
-
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
535
|
-
const [saving, setSaving] = (0, import_react11.useState)(false);
|
|
536
|
-
const validate = (0, import_react11.useCallback)((values2) => {
|
|
537
|
-
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
538
|
-
if (errors2.length === 0 && onValidate) {
|
|
539
|
-
const validatedValues = values2;
|
|
540
|
-
errors2 = onValidate(validatedValues) ?? [];
|
|
541
|
-
}
|
|
542
|
-
setErrors(flatMap(errors2));
|
|
543
|
-
const valid = errors2.length === 0;
|
|
544
|
-
return valid;
|
|
545
|
-
}, [
|
|
546
|
-
schema,
|
|
547
|
-
onValidate
|
|
548
|
-
]);
|
|
549
|
-
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
550
|
-
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
551
|
-
schema
|
|
552
|
-
]);
|
|
553
|
-
(0, import_react11.useEffect)(() => {
|
|
554
|
-
if (schemaDirty) {
|
|
555
|
-
validate(values);
|
|
556
|
-
setSchemaDirty(false);
|
|
557
|
-
}
|
|
558
|
-
}, [
|
|
559
|
-
values,
|
|
560
|
-
schemaDirty
|
|
561
|
-
]);
|
|
562
|
-
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
563
|
-
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
564
|
-
touched,
|
|
565
|
-
errors,
|
|
566
|
-
saving
|
|
567
|
-
]);
|
|
568
|
-
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
569
|
-
if (validate(values)) {
|
|
570
|
-
setSaving(true);
|
|
571
|
-
try {
|
|
572
|
-
await onSave?.(values, {
|
|
573
|
-
changed
|
|
574
|
-
});
|
|
575
|
-
} finally {
|
|
576
|
-
setSaving(false);
|
|
577
|
-
}
|
|
789
|
+
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
790
|
+
const { status, error } = getStatus();
|
|
791
|
+
const textareaRef = (0, import_react9.useRef)(null);
|
|
792
|
+
const adjustHeight = (0, import_react9.useCallback)(() => {
|
|
793
|
+
const textarea = textareaRef.current;
|
|
794
|
+
if (textarea) {
|
|
795
|
+
textarea.style.blockSize = "auto";
|
|
796
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
578
797
|
}
|
|
798
|
+
}, []);
|
|
799
|
+
(0, import_react9.useEffect)(() => {
|
|
800
|
+
adjustHeight();
|
|
579
801
|
}, [
|
|
580
|
-
|
|
581
|
-
validate,
|
|
582
|
-
onSave,
|
|
583
|
-
changed
|
|
584
|
-
]);
|
|
585
|
-
const getStatus = (0, import_react11.useCallback)((path) => {
|
|
586
|
-
const jsonPath = Array.isArray(path) ? (0, import_effect2.createJsonPath)(path) : path;
|
|
587
|
-
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
588
|
-
return {
|
|
589
|
-
status: matchingError ? "error" : void 0,
|
|
590
|
-
error: matchingError ? matchingError[1] : void 0
|
|
591
|
-
};
|
|
592
|
-
}, [
|
|
593
|
-
errors
|
|
802
|
+
adjustHeight
|
|
594
803
|
]);
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
};
|
|
598
|
-
const onValueChange = (path, type, value) => {
|
|
599
|
-
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
600
|
-
let parsedValue = value;
|
|
601
|
-
try {
|
|
602
|
-
if (type === "number") {
|
|
603
|
-
parsedValue = parseFloat(value) || 0;
|
|
604
|
-
}
|
|
605
|
-
} catch (err) {
|
|
606
|
-
import_log2.log.catch(err, void 0, {
|
|
607
|
-
F: __dxlog_file,
|
|
608
|
-
L: 192,
|
|
609
|
-
S: void 0,
|
|
610
|
-
C: (f, a) => f(...a)
|
|
611
|
-
});
|
|
612
|
-
parsedValue = void 0;
|
|
613
|
-
}
|
|
614
|
-
const newValues = {
|
|
615
|
-
...(0, import_echo_schema3.setValue)(values, jsonPath, parsedValue)
|
|
616
|
-
};
|
|
617
|
-
setValues(newValues);
|
|
618
|
-
setChanged((prev) => ({
|
|
619
|
-
...prev,
|
|
620
|
-
[jsonPath]: true
|
|
621
|
-
}));
|
|
622
|
-
onValuesChanged?.(newValues);
|
|
623
|
-
const isValid = validate(newValues);
|
|
624
|
-
if (isValid && onValid) {
|
|
625
|
-
onValid(newValues, {
|
|
626
|
-
changed
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
631
|
-
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
632
|
-
setTouched((touched2) => ({
|
|
633
|
-
...touched2,
|
|
634
|
-
[jsonPath]: true
|
|
635
|
-
}));
|
|
636
|
-
validate(values);
|
|
804
|
+
(0, import_react9.useEffect)(() => {
|
|
805
|
+
adjustHeight();
|
|
637
806
|
}, [
|
|
638
|
-
|
|
639
|
-
|
|
807
|
+
getValue3(),
|
|
808
|
+
adjustHeight
|
|
640
809
|
]);
|
|
641
|
-
return {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
F: __dxlog_file,
|
|
659
|
-
L: 234,
|
|
660
|
-
S: void 0,
|
|
661
|
-
A: [
|
|
662
|
-
"obj",
|
|
663
|
-
""
|
|
664
|
-
]
|
|
665
|
-
});
|
|
666
|
-
return Object.keys(obj).reduce((acc, key) => ({
|
|
667
|
-
...acc,
|
|
668
|
-
[key]: value
|
|
669
|
-
}), {});
|
|
670
|
-
};
|
|
671
|
-
var flatMap = (errors) => {
|
|
672
|
-
return errors.reduce((result, { path, message }) => {
|
|
673
|
-
const jsonPath = (0, import_effect2.fromEffectValidationPath)(path);
|
|
674
|
-
if (!(jsonPath in result)) {
|
|
675
|
-
result[jsonPath] = message;
|
|
676
|
-
}
|
|
677
|
-
return result;
|
|
678
|
-
}, {});
|
|
679
|
-
};
|
|
680
|
-
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
681
|
-
var useFormContext = () => {
|
|
682
|
-
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
683
|
-
};
|
|
684
|
-
var useFormValues = (path = []) => {
|
|
685
|
-
const { values: formValues } = useFormContext();
|
|
686
|
-
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
687
|
-
return (0, import_echo_schema2.getValue)(formValues, jsonPath);
|
|
688
|
-
};
|
|
689
|
-
var useInputProps = (path = []) => {
|
|
690
|
-
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
691
|
-
return {
|
|
692
|
-
getStatus: () => getStatus(path),
|
|
693
|
-
getValue: () => getFormValue(path),
|
|
694
|
-
onValueChange: (type, value) => onValueChange(path, type, value),
|
|
695
|
-
onBlur: () => onTouched(path)
|
|
696
|
-
};
|
|
697
|
-
};
|
|
698
|
-
var FormProvider = ({ children, ...formOptions }) => {
|
|
699
|
-
const formHandler = useForm(formOptions);
|
|
700
|
-
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
701
|
-
value: formHandler
|
|
702
|
-
}, children);
|
|
810
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Root, {
|
|
811
|
+
validationValence: status
|
|
812
|
+
}, !inputOnly && /* @__PURE__ */ import_react9.default.createElement(InputHeader, {
|
|
813
|
+
error
|
|
814
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.TextArea, {
|
|
815
|
+
ref: textareaRef,
|
|
816
|
+
disabled,
|
|
817
|
+
placeholder,
|
|
818
|
+
value: getValue3() ?? "",
|
|
819
|
+
classNames: "min-bs-auto max-h-40 overflow-auto",
|
|
820
|
+
onChange: (event) => onValueChange(type, event.target.value),
|
|
821
|
+
onBlur,
|
|
822
|
+
style: {
|
|
823
|
+
resize: "none"
|
|
824
|
+
},
|
|
825
|
+
spellCheck: false
|
|
826
|
+
}), inputOnly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
703
827
|
};
|
|
704
828
|
var FormActions = ({ onCancel, readonly }) => {
|
|
705
829
|
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
706
830
|
const { canSave, handleSave } = useFormContext();
|
|
707
|
-
return /* @__PURE__ */
|
|
831
|
+
return /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
708
832
|
role: "none",
|
|
709
|
-
className: "flex justify-center"
|
|
710
|
-
}, /* @__PURE__ */
|
|
833
|
+
className: "mt-2 flex justify-center"
|
|
834
|
+
}, /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
711
835
|
role: "none",
|
|
712
836
|
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
713
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
837
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
714
838
|
"data-testid": "cancel-button",
|
|
715
839
|
icon: "ph--x--regular",
|
|
716
840
|
label: t("button cancel"),
|
|
717
841
|
onClick: onCancel
|
|
718
|
-
}), handleSave && /* @__PURE__ */
|
|
842
|
+
}), handleSave && /* @__PURE__ */ import_react11.default.createElement(import_react_ui8.IconButton, {
|
|
719
843
|
type: "submit",
|
|
720
844
|
"data-testid": "save-button",
|
|
721
845
|
disabled: !canSave,
|
|
@@ -740,11 +864,11 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
740
864
|
]
|
|
741
865
|
});
|
|
742
866
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
743
|
-
const tupleType = (0, import_effect6.findNode)(ast,
|
|
867
|
+
const tupleType = (0, import_effect6.findNode)(ast, import_echo_schema6.AST.isTupleType);
|
|
744
868
|
const elementType = tupleType?.rest[0]?.type;
|
|
745
869
|
const getDefaultObjectValue = (typeNode) => {
|
|
746
870
|
const baseNode = (0, import_effect6.findNode)(typeNode, import_effect6.isDiscriminatedUnion);
|
|
747
|
-
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode,
|
|
871
|
+
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode, import_echo_schema6.AST.isTypeLiteral);
|
|
748
872
|
if (!typeLiteral) {
|
|
749
873
|
return {};
|
|
750
874
|
}
|
|
@@ -830,8 +954,10 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
830
954
|
};
|
|
831
955
|
var getInputComponent = (type, format) => {
|
|
832
956
|
switch (format) {
|
|
833
|
-
case
|
|
957
|
+
case import_echo_schema7.FormatEnum.LatLong:
|
|
834
958
|
return GeoPointInput;
|
|
959
|
+
case import_echo_schema7.FormatEnum.Markdown:
|
|
960
|
+
return MarkdownInput;
|
|
835
961
|
}
|
|
836
962
|
switch (type) {
|
|
837
963
|
case "string":
|
|
@@ -855,7 +981,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
855
981
|
]);
|
|
856
982
|
const FoundComponent = lookupComponent?.({
|
|
857
983
|
prop: name,
|
|
858
|
-
schema:
|
|
984
|
+
schema: import_echo_schema5.S.make(ast),
|
|
859
985
|
inputProps: {
|
|
860
986
|
type,
|
|
861
987
|
format,
|
|
@@ -873,20 +999,15 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
873
999
|
const jsonPath = (0, import_effect4.createJsonPath)(path ?? []);
|
|
874
1000
|
const CustomComponent = Custom?.[jsonPath];
|
|
875
1001
|
if (CustomComponent) {
|
|
876
|
-
return (
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
placeholder,
|
|
886
|
-
disabled: readonly,
|
|
887
|
-
...inputProps
|
|
888
|
-
}))
|
|
889
|
-
);
|
|
1002
|
+
return /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
1003
|
+
type,
|
|
1004
|
+
format,
|
|
1005
|
+
label,
|
|
1006
|
+
inputOnly: inline,
|
|
1007
|
+
placeholder,
|
|
1008
|
+
disabled: readonly,
|
|
1009
|
+
...inputProps
|
|
1010
|
+
});
|
|
890
1011
|
}
|
|
891
1012
|
if (array) {
|
|
892
1013
|
return /* @__PURE__ */ import_react12.default.createElement(ArrayField, {
|
|
@@ -930,12 +1051,12 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
930
1051
|
}
|
|
931
1052
|
if (type === "object") {
|
|
932
1053
|
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
933
|
-
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast,
|
|
1054
|
+
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema5.AST.isTypeLiteral);
|
|
934
1055
|
if (typeLiteral) {
|
|
935
1056
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
936
1057
|
role: "none"
|
|
937
1058
|
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
938
|
-
schema:
|
|
1059
|
+
schema: import_echo_schema5.S.make(typeLiteral),
|
|
939
1060
|
path,
|
|
940
1061
|
readonly,
|
|
941
1062
|
Custom
|
|
@@ -958,7 +1079,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
958
1079
|
]);
|
|
959
1080
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
960
1081
|
role: "form",
|
|
961
|
-
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2
|
|
1082
|
+
className: (0, import_react_ui_theme7.mx)("flex flex-col w-full gap-2")
|
|
962
1083
|
}, properties.map((property) => {
|
|
963
1084
|
return /* @__PURE__ */ import_react12.default.createElement(FormField, {
|
|
964
1085
|
key: property.name,
|
|
@@ -973,23 +1094,37 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
973
1094
|
});
|
|
974
1095
|
}).filter(import_util3.isNotFalsy));
|
|
975
1096
|
};
|
|
976
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
977
|
-
const
|
|
1097
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1098
|
+
const formRef = (0, import_react10.useRef)(null);
|
|
1099
|
+
const onValid = (0, import_react10.useMemo)(() => autoSave ? onSave : void 0, [
|
|
978
1100
|
autoSave,
|
|
979
1101
|
onSave
|
|
980
1102
|
]);
|
|
981
|
-
|
|
1103
|
+
(0, import_react10.useEffect)(() => {
|
|
1104
|
+
if (autoFocus && formRef.current) {
|
|
1105
|
+
const input = formRef.current.querySelector("input");
|
|
1106
|
+
if (input) {
|
|
1107
|
+
input.focus();
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}, [
|
|
1111
|
+
autoFocus
|
|
1112
|
+
]);
|
|
1113
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormProvider, {
|
|
1114
|
+
formRef,
|
|
982
1115
|
schema,
|
|
1116
|
+
autoSave,
|
|
983
1117
|
initialValues,
|
|
984
1118
|
onValuesChanged,
|
|
985
1119
|
onValidate,
|
|
986
1120
|
onValid,
|
|
987
1121
|
onSave
|
|
988
|
-
}, /* @__PURE__ */
|
|
1122
|
+
}, /* @__PURE__ */ import_react10.default.createElement("div", {
|
|
1123
|
+
ref: formRef,
|
|
989
1124
|
role: "none",
|
|
990
1125
|
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
991
1126
|
"data-testid": testId
|
|
992
|
-
}, /* @__PURE__ */
|
|
1127
|
+
}, /* @__PURE__ */ import_react10.default.createElement(FormFields, {
|
|
993
1128
|
schema,
|
|
994
1129
|
path,
|
|
995
1130
|
readonly,
|
|
@@ -997,7 +1132,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
997
1132
|
sort,
|
|
998
1133
|
lookupComponent,
|
|
999
1134
|
Custom
|
|
1000
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1135
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react10.default.createElement(FormActions, {
|
|
1001
1136
|
onCancel,
|
|
1002
1137
|
readonly
|
|
1003
1138
|
})));
|
|
@@ -1160,14 +1295,14 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1160
1295
|
});
|
|
1161
1296
|
};
|
|
1162
1297
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1163
|
-
var ViewMetaSchema =
|
|
1164
|
-
name:
|
|
1165
|
-
[
|
|
1298
|
+
var ViewMetaSchema = import_echo_schema8.S.Struct({
|
|
1299
|
+
name: import_echo_schema8.S.String.annotations({
|
|
1300
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "View"
|
|
1166
1301
|
}),
|
|
1167
|
-
typename:
|
|
1168
|
-
[
|
|
1302
|
+
typename: import_echo_schema8.Format.URL.annotations({
|
|
1303
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "Typename"
|
|
1169
1304
|
})
|
|
1170
|
-
}).pipe(
|
|
1305
|
+
}).pipe(import_echo_schema8.S.mutable);
|
|
1171
1306
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1172
1307
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1173
1308
|
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
@@ -1223,7 +1358,6 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1223
1358
|
role: "none",
|
|
1224
1359
|
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1225
1360
|
}, /* @__PURE__ */ import_react14.default.createElement(Form, {
|
|
1226
|
-
autoFocus: true,
|
|
1227
1361
|
autoSave: true,
|
|
1228
1362
|
schema: ViewMetaSchema,
|
|
1229
1363
|
values: viewValues,
|
|
@@ -1235,7 +1369,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1235
1369
|
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1236
1370
|
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1237
1371
|
items: view.fields,
|
|
1238
|
-
isItem:
|
|
1372
|
+
isItem: import_echo_schema8.S.is(import_schema5.FieldSchema),
|
|
1239
1373
|
getId: (field2) => field2.id,
|
|
1240
1374
|
onMove: handleMove
|
|
1241
1375
|
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
@@ -1278,7 +1412,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1278
1412
|
}
|
|
1279
1413
|
const parseScalar = (type2) => {
|
|
1280
1414
|
switch (type2) {
|
|
1281
|
-
case
|
|
1415
|
+
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1282
1416
|
if (typeof value === "string") {
|
|
1283
1417
|
const lowercaseValue = value.toLowerCase();
|
|
1284
1418
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1289,13 +1423,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1289
1423
|
}
|
|
1290
1424
|
return Boolean(value);
|
|
1291
1425
|
}
|
|
1292
|
-
case
|
|
1426
|
+
case import_echo_schema9.TypeEnum.Number: {
|
|
1293
1427
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1294
1428
|
const num = Number(cleaned);
|
|
1295
1429
|
return Number.isNaN(num) ? null : num;
|
|
1296
1430
|
}
|
|
1297
|
-
case
|
|
1298
|
-
case
|
|
1431
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1432
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1299
1433
|
return String(value);
|
|
1300
1434
|
default: {
|
|
1301
1435
|
return value;
|
|
@@ -1306,25 +1440,45 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1306
1440
|
return parseScalar(type);
|
|
1307
1441
|
}
|
|
1308
1442
|
switch (format) {
|
|
1309
|
-
case
|
|
1310
|
-
return parseScalar(
|
|
1311
|
-
case
|
|
1312
|
-
case
|
|
1313
|
-
case
|
|
1314
|
-
return parseScalar(
|
|
1315
|
-
case
|
|
1316
|
-
case
|
|
1317
|
-
return parseScalar(
|
|
1443
|
+
case import_echo_schema9.FormatEnum.Boolean:
|
|
1444
|
+
return parseScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1445
|
+
case import_echo_schema9.FormatEnum.Number:
|
|
1446
|
+
case import_echo_schema9.FormatEnum.Percent:
|
|
1447
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1448
|
+
return parseScalar(import_echo_schema9.TypeEnum.Number);
|
|
1449
|
+
case import_echo_schema9.FormatEnum.String:
|
|
1450
|
+
case import_echo_schema9.FormatEnum.Markdown: {
|
|
1451
|
+
return parseScalar(import_echo_schema9.TypeEnum.String);
|
|
1318
1452
|
}
|
|
1319
|
-
case
|
|
1320
|
-
throw new Error(`unexpected format: ${
|
|
1321
|
-
case
|
|
1322
|
-
case
|
|
1323
|
-
case
|
|
1324
|
-
case
|
|
1453
|
+
case import_echo_schema9.FormatEnum.Ref:
|
|
1454
|
+
throw new Error(`unexpected format: ${import_echo_schema9.FormatEnum.Ref}`);
|
|
1455
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1456
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1457
|
+
case import_echo_schema9.FormatEnum.Time:
|
|
1458
|
+
case import_echo_schema9.FormatEnum.Timestamp: {
|
|
1325
1459
|
const date = new Date(value);
|
|
1326
1460
|
return isNaN(date.getTime()) ? null : date;
|
|
1327
1461
|
}
|
|
1462
|
+
case import_echo_schema9.FormatEnum.LatLong: {
|
|
1463
|
+
if (typeof value === "string") {
|
|
1464
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1465
|
+
const parts = cleaned.split(",");
|
|
1466
|
+
if (parts.length === 2) {
|
|
1467
|
+
const lat = parseFloat(parts[0]);
|
|
1468
|
+
const long = parseFloat(parts[1]);
|
|
1469
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1470
|
+
return import_echo_schema9.GeoLocation.toGeoPoint({
|
|
1471
|
+
latitude: lat,
|
|
1472
|
+
longitude: long
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
return [
|
|
1478
|
+
0,
|
|
1479
|
+
0
|
|
1480
|
+
];
|
|
1481
|
+
}
|
|
1328
1482
|
default: {
|
|
1329
1483
|
return value;
|
|
1330
1484
|
}
|
|
@@ -1333,19 +1487,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1333
1487
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1334
1488
|
if (!format) {
|
|
1335
1489
|
switch (type) {
|
|
1336
|
-
case
|
|
1490
|
+
case import_echo_schema9.TypeEnum.Number:
|
|
1337
1491
|
return [
|
|
1338
1492
|
"text-right",
|
|
1339
1493
|
"font-mono"
|
|
1340
1494
|
];
|
|
1341
|
-
case
|
|
1495
|
+
case import_echo_schema9.TypeEnum.Boolean:
|
|
1342
1496
|
return [
|
|
1343
1497
|
"text-right",
|
|
1344
1498
|
"font-mono"
|
|
1345
1499
|
];
|
|
1346
|
-
case
|
|
1500
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1347
1501
|
return void 0;
|
|
1348
|
-
case
|
|
1502
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1349
1503
|
return void 0;
|
|
1350
1504
|
default: {
|
|
1351
1505
|
return void 0;
|
|
@@ -1353,20 +1507,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1353
1507
|
}
|
|
1354
1508
|
}
|
|
1355
1509
|
switch (format) {
|
|
1356
|
-
case
|
|
1510
|
+
case import_echo_schema9.FormatEnum.Markdown:
|
|
1357
1511
|
return void 0;
|
|
1358
|
-
case
|
|
1359
|
-
case
|
|
1360
|
-
case
|
|
1361
|
-
case
|
|
1512
|
+
case import_echo_schema9.FormatEnum.Timestamp:
|
|
1513
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1514
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1515
|
+
case import_echo_schema9.FormatEnum.Time:
|
|
1362
1516
|
return [
|
|
1363
1517
|
"font-mono"
|
|
1364
1518
|
];
|
|
1365
|
-
case
|
|
1519
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1366
1520
|
return [
|
|
1367
1521
|
"text-right"
|
|
1368
1522
|
];
|
|
1369
|
-
case
|
|
1523
|
+
case import_echo_schema9.FormatEnum.JSON:
|
|
1370
1524
|
return [
|
|
1371
1525
|
"font-mono"
|
|
1372
1526
|
];
|
|
@@ -1384,12 +1538,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1384
1538
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1385
1539
|
const formatScalar = (type2) => {
|
|
1386
1540
|
switch (type2) {
|
|
1387
|
-
case
|
|
1541
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1388
1542
|
return value.toLocaleString().toUpperCase();
|
|
1389
|
-
case
|
|
1543
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1390
1544
|
return value.toLocaleString(locale);
|
|
1391
|
-
case
|
|
1392
|
-
case
|
|
1545
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1546
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1393
1547
|
return String(value);
|
|
1394
1548
|
default: {
|
|
1395
1549
|
return String(value);
|
|
@@ -1400,20 +1554,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1400
1554
|
return formatScalar(type);
|
|
1401
1555
|
}
|
|
1402
1556
|
switch (format) {
|
|
1403
|
-
case
|
|
1404
|
-
return formatScalar(
|
|
1557
|
+
case import_echo_schema10.FormatEnum.Boolean: {
|
|
1558
|
+
return formatScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1405
1559
|
}
|
|
1406
|
-
case
|
|
1407
|
-
return formatScalar(
|
|
1560
|
+
case import_echo_schema10.FormatEnum.Number: {
|
|
1561
|
+
return formatScalar(import_echo_schema10.TypeEnum.Number);
|
|
1408
1562
|
}
|
|
1409
|
-
case
|
|
1410
|
-
case
|
|
1411
|
-
return formatScalar(
|
|
1563
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1564
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1565
|
+
return formatScalar(import_echo_schema10.TypeEnum.String);
|
|
1412
1566
|
}
|
|
1413
|
-
case
|
|
1567
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1414
1568
|
return `${value * 100}%`;
|
|
1415
1569
|
}
|
|
1416
|
-
case
|
|
1570
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1417
1571
|
return value.toLocaleString(locale, {
|
|
1418
1572
|
style: "currency",
|
|
1419
1573
|
currency: "USD",
|
|
@@ -1421,18 +1575,28 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1421
1575
|
maximumFractionDigits: 2
|
|
1422
1576
|
});
|
|
1423
1577
|
}
|
|
1424
|
-
case
|
|
1425
|
-
case
|
|
1426
|
-
case
|
|
1578
|
+
case import_echo_schema10.FormatEnum.DateTime:
|
|
1579
|
+
case import_echo_schema10.FormatEnum.Date:
|
|
1580
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1427
1581
|
const date = new Date(value);
|
|
1428
|
-
if (format ===
|
|
1582
|
+
if (format === import_echo_schema10.FormatEnum.DateTime) {
|
|
1429
1583
|
return date.toLocaleString(locale);
|
|
1430
|
-
} else if (format ===
|
|
1584
|
+
} else if (format === import_echo_schema10.FormatEnum.Date) {
|
|
1431
1585
|
return date.toLocaleDateString(locale);
|
|
1432
1586
|
} else {
|
|
1433
1587
|
return date.toLocaleTimeString(locale);
|
|
1434
1588
|
}
|
|
1435
1589
|
}
|
|
1590
|
+
case import_echo_schema10.FormatEnum.LatLong: {
|
|
1591
|
+
if (value === null || value === void 0) {
|
|
1592
|
+
return "";
|
|
1593
|
+
}
|
|
1594
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1595
|
+
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1596
|
+
return `${latitude},${longitude}`;
|
|
1597
|
+
}
|
|
1598
|
+
return String(value);
|
|
1599
|
+
}
|
|
1436
1600
|
default: {
|
|
1437
1601
|
if (value === null || value === "undefined") {
|
|
1438
1602
|
return "";
|
|
@@ -1444,10 +1608,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1444
1608
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1445
1609
|
const formatScalar = (type2) => {
|
|
1446
1610
|
switch (type2) {
|
|
1447
|
-
case
|
|
1448
|
-
case
|
|
1449
|
-
case
|
|
1450
|
-
case
|
|
1611
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1612
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1613
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1614
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1451
1615
|
return String(value);
|
|
1452
1616
|
default:
|
|
1453
1617
|
return String(value);
|
|
@@ -1457,30 +1621,40 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1457
1621
|
return formatScalar(type);
|
|
1458
1622
|
}
|
|
1459
1623
|
switch (format) {
|
|
1460
|
-
case
|
|
1461
|
-
case
|
|
1462
|
-
case
|
|
1463
|
-
case
|
|
1624
|
+
case import_echo_schema10.FormatEnum.Boolean:
|
|
1625
|
+
case import_echo_schema10.FormatEnum.Number:
|
|
1626
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1627
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1464
1628
|
return formatScalar(type);
|
|
1465
1629
|
}
|
|
1466
|
-
case
|
|
1630
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1467
1631
|
return String(value * 100);
|
|
1468
1632
|
}
|
|
1469
|
-
case
|
|
1633
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1470
1634
|
return String(value);
|
|
1471
1635
|
}
|
|
1472
|
-
case
|
|
1636
|
+
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1473
1637
|
const date = new Date(value);
|
|
1474
1638
|
return date.toISOString();
|
|
1475
1639
|
}
|
|
1476
|
-
case
|
|
1640
|
+
case import_echo_schema10.FormatEnum.Date: {
|
|
1477
1641
|
const date = new Date(value);
|
|
1478
1642
|
return date.toISOString().split("T")[0];
|
|
1479
1643
|
}
|
|
1480
|
-
case
|
|
1644
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1481
1645
|
const date = new Date(value);
|
|
1482
1646
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1483
1647
|
}
|
|
1648
|
+
case import_echo_schema10.FormatEnum.LatLong: {
|
|
1649
|
+
if (value === null || value === void 0) {
|
|
1650
|
+
return "";
|
|
1651
|
+
}
|
|
1652
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1653
|
+
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1654
|
+
return `${latitude},${longitude}`;
|
|
1655
|
+
}
|
|
1656
|
+
return String(value);
|
|
1657
|
+
}
|
|
1484
1658
|
default: {
|
|
1485
1659
|
return String(value);
|
|
1486
1660
|
}
|
|
@@ -1495,6 +1669,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1495
1669
|
Form,
|
|
1496
1670
|
GeoPointInput,
|
|
1497
1671
|
InputHeader,
|
|
1672
|
+
MarkdownInput,
|
|
1498
1673
|
NumberInput,
|
|
1499
1674
|
SelectInput,
|
|
1500
1675
|
SelectOptionInput,
|
|
@@ -1508,6 +1683,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1508
1683
|
parseValue,
|
|
1509
1684
|
pathNotUniqueError,
|
|
1510
1685
|
translations,
|
|
1511
|
-
useForm
|
|
1686
|
+
useForm,
|
|
1687
|
+
useFormValues
|
|
1512
1688
|
});
|
|
1513
1689
|
//# sourceMappingURL=index.cjs.map
|