@dxos/react-ui-form 0.8.0 → 0.8.1-main.013e445
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 +571 -507
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +449 -384
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +571 -507
- 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 +2 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +2 -1
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +6 -5
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +2 -2
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +7 -7
- package/dist/types/src/components/Form/FormActions.d.ts +2 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +3 -2
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +1 -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 +2 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +2 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +2 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +1 -2
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts +2 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +3 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +2 -1
- 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 +2 -1
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/package.json +26 -28
- package/src/components/Form/index.ts +1 -3
- package/src/components/ViewEditor/ViewEditor.tsx +71 -2
- package/src/components/deprecated/Form.tsx +2 -2
- package/src/hooks/useForm.ts +12 -2
- package/src/translations.ts +1 -0
- package/src/util/field.ts +1 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(node_exports, {
|
|
|
33
33
|
DeprecatedFormInput: () => DeprecatedFormInput,
|
|
34
34
|
FieldEditor: () => FieldEditor,
|
|
35
35
|
Form: () => Form,
|
|
36
|
+
FormProvider: () => FormProvider,
|
|
36
37
|
GeoPointInput: () => GeoPointInput,
|
|
37
38
|
InputHeader: () => InputHeader,
|
|
38
39
|
MarkdownInput: () => MarkdownInput,
|
|
@@ -50,7 +51,9 @@ __export(node_exports, {
|
|
|
50
51
|
pathNotUniqueError: () => pathNotUniqueError,
|
|
51
52
|
translations: () => translations_default,
|
|
52
53
|
useForm: () => useForm,
|
|
53
|
-
|
|
54
|
+
useFormContext: () => useFormContext,
|
|
55
|
+
useFormValues: () => useFormValues,
|
|
56
|
+
useInputProps: () => useInputProps
|
|
54
57
|
});
|
|
55
58
|
module.exports = __toCommonJS(node_exports);
|
|
56
59
|
var import_react = __toESM(require("react"));
|
|
@@ -62,52 +65,53 @@ var import_log = require("@dxos/log");
|
|
|
62
65
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
63
66
|
var import_schema = require("@dxos/schema");
|
|
64
67
|
var import_react3 = __toESM(require("react"));
|
|
65
|
-
var import_debug = require("@dxos/debug");
|
|
66
68
|
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");
|
|
76
69
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
77
70
|
var import_util = require("@dxos/util");
|
|
78
|
-
var
|
|
71
|
+
var import_react4 = __toESM(require("react"));
|
|
79
72
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
80
73
|
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
81
|
-
var
|
|
74
|
+
var import_react5 = __toESM(require("react"));
|
|
82
75
|
var import_keys = require("@dxos/keys");
|
|
83
76
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
84
77
|
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
85
78
|
var import_react_ui_pickers = require("@dxos/react-ui-pickers");
|
|
86
79
|
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
87
|
-
var
|
|
80
|
+
var import_react6 = __toESM(require("react"));
|
|
88
81
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
89
82
|
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
90
83
|
var import_util2 = require("@dxos/util");
|
|
91
|
-
var
|
|
84
|
+
var import_react7 = __toESM(require("react"));
|
|
92
85
|
var import_react_ui7 = require("@dxos/react-ui");
|
|
93
|
-
var
|
|
86
|
+
var import_react8 = __toESM(require("react"));
|
|
94
87
|
var import_react_ui_theme5 = require("@dxos/react-ui-theme");
|
|
95
|
-
var
|
|
88
|
+
var import_react9 = __toESM(require("react"));
|
|
96
89
|
var import_react_ui8 = require("@dxos/react-ui");
|
|
97
90
|
var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
98
|
-
var
|
|
91
|
+
var import_react10 = __toESM(require("react"));
|
|
92
|
+
var import_debug = require("@dxos/debug");
|
|
93
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
94
|
+
var import_effect = require("@dxos/effect");
|
|
95
|
+
var import_effect2 = require("effect");
|
|
96
|
+
var import_react11 = require("react");
|
|
97
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
98
|
+
var import_effect3 = require("@dxos/effect");
|
|
99
|
+
var import_invariant = require("@dxos/invariant");
|
|
100
|
+
var import_log2 = require("@dxos/log");
|
|
101
|
+
var import_schema2 = require("@dxos/schema");
|
|
102
|
+
var import_effect4 = require("effect");
|
|
99
103
|
var import_String = require("effect/String");
|
|
100
104
|
var import_react12 = __toESM(require("react"));
|
|
101
105
|
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
102
|
-
var
|
|
106
|
+
var import_effect5 = require("@dxos/effect");
|
|
103
107
|
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
104
108
|
var import_schema3 = require("@dxos/schema");
|
|
105
109
|
var import_util3 = require("@dxos/util");
|
|
106
|
-
var
|
|
110
|
+
var import_effect6 = require("effect");
|
|
107
111
|
var import_String2 = require("effect/String");
|
|
108
112
|
var import_react13 = __toESM(require("react"));
|
|
109
113
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
110
|
-
var
|
|
114
|
+
var import_effect7 = require("@dxos/effect");
|
|
111
115
|
var import_invariant2 = require("@dxos/invariant");
|
|
112
116
|
var import_react_ui9 = require("@dxos/react-ui");
|
|
113
117
|
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
@@ -127,6 +131,7 @@ var translations_default = [
|
|
|
127
131
|
"en-US": {
|
|
128
132
|
[translationKey]: {
|
|
129
133
|
"fields label": "Fields",
|
|
134
|
+
"hidden fields label": "Hidden Fields",
|
|
130
135
|
// TODO(burdon): Standardize field/property.
|
|
131
136
|
"button add property": "Add property",
|
|
132
137
|
"field property label": "Property",
|
|
@@ -214,303 +219,48 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
214
219
|
}
|
|
215
220
|
return primary;
|
|
216
221
|
};
|
|
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
|
-
};
|
|
472
222
|
var InputHeader = ({ children, error }) => {
|
|
473
|
-
return /* @__PURE__ */
|
|
223
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
474
224
|
role: "none",
|
|
475
225
|
className: "flex justify-between items-center mb-1"
|
|
476
|
-
}, children, error && /* @__PURE__ */
|
|
226
|
+
}, children, error && /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
477
227
|
asChild: true
|
|
478
|
-
}, /* @__PURE__ */
|
|
228
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Icon, {
|
|
479
229
|
icon: "ph--warning--regular",
|
|
480
230
|
size: 4,
|
|
481
231
|
classNames: import_react_ui_theme2.errorText
|
|
482
|
-
})), /* @__PURE__ */
|
|
232
|
+
})), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
483
233
|
side: "bottom"
|
|
484
|
-
}, /* @__PURE__ */
|
|
234
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
485
235
|
};
|
|
486
236
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
487
237
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
488
238
|
const { status, error } = getStatus();
|
|
489
|
-
const geoPoint = (0,
|
|
239
|
+
const geoPoint = (0, import_react3.useMemo)(() => getValue3() ?? [
|
|
490
240
|
0,
|
|
491
241
|
0
|
|
492
242
|
], [
|
|
493
243
|
getValue3
|
|
494
244
|
]);
|
|
495
|
-
const geoLocation = (0,
|
|
245
|
+
const geoLocation = (0, import_react3.useMemo)(() => import_echo_schema2.GeoLocation.fromGeoPoint(geoPoint), [
|
|
496
246
|
geoPoint
|
|
497
247
|
]);
|
|
498
|
-
const [longitudeText, setLongitudeText] = (0,
|
|
499
|
-
const [latitudeText, setLatitudeText] = (0,
|
|
500
|
-
(0,
|
|
501
|
-
const location =
|
|
248
|
+
const [longitudeText, setLongitudeText] = (0, import_react3.useState)(geoLocation.longitude?.toString());
|
|
249
|
+
const [latitudeText, setLatitudeText] = (0, import_react3.useState)(geoLocation.latitude?.toString());
|
|
250
|
+
(0, import_react3.useEffect)(() => {
|
|
251
|
+
const location = import_echo_schema2.GeoLocation.fromGeoPoint(geoPoint);
|
|
502
252
|
setLongitudeText(location.longitude.toString());
|
|
503
253
|
setLatitudeText(location.latitude.toString());
|
|
504
254
|
}, [
|
|
505
255
|
geoPoint
|
|
506
256
|
]);
|
|
507
|
-
const handleCoordinateChange = (0,
|
|
257
|
+
const handleCoordinateChange = (0, import_react3.useCallback)((coordinateType, setText) => (event) => {
|
|
508
258
|
const inputText = event.target.value;
|
|
509
259
|
setText(inputText);
|
|
510
260
|
if (inputText !== "" && inputText !== "-") {
|
|
511
261
|
const coord = (0, import_util.safeParseFloat)(inputText);
|
|
512
262
|
if (coord !== void 0 && !isNaN(coord)) {
|
|
513
|
-
const currentLocation =
|
|
263
|
+
const currentLocation = import_echo_schema2.GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
514
264
|
0,
|
|
515
265
|
0
|
|
516
266
|
]);
|
|
@@ -518,7 +268,7 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
518
268
|
...currentLocation,
|
|
519
269
|
[coordinateType]: coord
|
|
520
270
|
};
|
|
521
|
-
const newValue =
|
|
271
|
+
const newValue = import_echo_schema2.GeoLocation.toGeoPoint(newLocation);
|
|
522
272
|
onValueChange(type, newValue);
|
|
523
273
|
}
|
|
524
274
|
}
|
|
@@ -527,14 +277,14 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
527
277
|
onValueChange,
|
|
528
278
|
type
|
|
529
279
|
]);
|
|
530
|
-
return /* @__PURE__ */
|
|
280
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Root, {
|
|
531
281
|
validationValence: status
|
|
532
|
-
}, /* @__PURE__ */
|
|
282
|
+
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, {
|
|
533
283
|
error
|
|
534
|
-
}, /* @__PURE__ */
|
|
284
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
535
285
|
role: "none",
|
|
536
286
|
className: "grid grid-cols-2 gap-2"
|
|
537
|
-
}, /* @__PURE__ */
|
|
287
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
538
288
|
type: "text",
|
|
539
289
|
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
540
290
|
disabled,
|
|
@@ -542,7 +292,7 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
542
292
|
value: latitudeText,
|
|
543
293
|
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
544
294
|
onBlur
|
|
545
|
-
}), /* @__PURE__ */
|
|
295
|
+
}), /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
546
296
|
type: "text",
|
|
547
297
|
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
548
298
|
disabled,
|
|
@@ -553,13 +303,13 @@ var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, on
|
|
|
553
303
|
})));
|
|
554
304
|
};
|
|
555
305
|
var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
|
|
556
|
-
const [selected, setSelectedId] = (0,
|
|
557
|
-
const [isNewOption, setIsNewOption] = (0,
|
|
558
|
-
const inputRef = (0,
|
|
306
|
+
const [selected, setSelectedId] = (0, import_react5.useState)(null);
|
|
307
|
+
const [isNewOption, setIsNewOption] = (0, import_react5.useState)(false);
|
|
308
|
+
const inputRef = (0, import_react5.useRef)(null);
|
|
559
309
|
const { t } = (0, import_react_ui5.useTranslation)(translationKey);
|
|
560
310
|
const { status, error } = getStatus();
|
|
561
311
|
const options = getValue3();
|
|
562
|
-
(0,
|
|
312
|
+
(0, import_react5.useEffect)(() => {
|
|
563
313
|
if (options === void 0) {
|
|
564
314
|
onValueChange(type, []);
|
|
565
315
|
}
|
|
@@ -578,7 +328,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
578
328
|
const availableHues = import_react_ui_theme3.hues.filter((hue) => !lastThree.has(hue));
|
|
579
329
|
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? import_react_ui_theme3.hues[Math.floor(Math.random() * import_react_ui_theme3.hues.length)];
|
|
580
330
|
};
|
|
581
|
-
const handleAdd = (0,
|
|
331
|
+
const handleAdd = (0, import_react5.useCallback)(() => {
|
|
582
332
|
const newId = import_keys.PublicKey.random().truncate();
|
|
583
333
|
const newOption = {
|
|
584
334
|
id: newId,
|
|
@@ -596,7 +346,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
596
346
|
type,
|
|
597
347
|
onValueChange
|
|
598
348
|
]);
|
|
599
|
-
const handleDelete = (0,
|
|
349
|
+
const handleDelete = (0, import_react5.useCallback)((id) => {
|
|
600
350
|
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
601
351
|
onValueChange(type, newOptions);
|
|
602
352
|
setSelectedId(null);
|
|
@@ -605,7 +355,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
605
355
|
type,
|
|
606
356
|
onValueChange
|
|
607
357
|
]);
|
|
608
|
-
const handleMove = (0,
|
|
358
|
+
const handleMove = (0, import_react5.useCallback)((from, to) => {
|
|
609
359
|
if (!options) {
|
|
610
360
|
return;
|
|
611
361
|
}
|
|
@@ -620,10 +370,10 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
620
370
|
type,
|
|
621
371
|
onValueChange
|
|
622
372
|
]);
|
|
623
|
-
const handleClick = (0,
|
|
373
|
+
const handleClick = (0, import_react5.useCallback)((id) => {
|
|
624
374
|
setSelectedId((current) => current === id ? null : id);
|
|
625
375
|
}, []);
|
|
626
|
-
const handleTitleChange = (0,
|
|
376
|
+
const handleTitleChange = (0, import_react5.useCallback)((id) => (e) => {
|
|
627
377
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
628
378
|
...o,
|
|
629
379
|
title: e.target.value
|
|
@@ -634,12 +384,12 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
634
384
|
type,
|
|
635
385
|
onValueChange
|
|
636
386
|
]);
|
|
637
|
-
const handleKeyDown = (0,
|
|
387
|
+
const handleKeyDown = (0, import_react5.useCallback)((e) => {
|
|
638
388
|
if (e.key === "Enter") {
|
|
639
389
|
setSelectedId(null);
|
|
640
390
|
}
|
|
641
391
|
}, []);
|
|
642
|
-
const handleColorChange = (0,
|
|
392
|
+
const handleColorChange = (0, import_react5.useCallback)((id) => (hue) => {
|
|
643
393
|
const newOptions = options?.map((o) => o.id === id ? {
|
|
644
394
|
...o,
|
|
645
395
|
color: hue
|
|
@@ -650,7 +400,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
650
400
|
type,
|
|
651
401
|
onValueChange
|
|
652
402
|
]);
|
|
653
|
-
(0,
|
|
403
|
+
(0, import_react5.useEffect)(() => {
|
|
654
404
|
if (selected && isNewOption && inputRef.current) {
|
|
655
405
|
inputRef.current.focus();
|
|
656
406
|
setIsNewOption(false);
|
|
@@ -659,43 +409,43 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
659
409
|
selected,
|
|
660
410
|
isNewOption
|
|
661
411
|
]);
|
|
662
|
-
return /* @__PURE__ */
|
|
412
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Root, {
|
|
663
413
|
validationValence: status
|
|
664
|
-
}, /* @__PURE__ */
|
|
414
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
665
415
|
error
|
|
666
|
-
}, /* @__PURE__ */
|
|
416
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
667
417
|
role: "none"
|
|
668
|
-
}, options && /* @__PURE__ */
|
|
418
|
+
}, options && /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.Root, {
|
|
669
419
|
items: options,
|
|
670
420
|
isItem: (item) => true,
|
|
671
421
|
onMove: handleMove
|
|
672
|
-
}, ({ items }) => /* @__PURE__ */
|
|
422
|
+
}, ({ items }) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
673
423
|
role: "list",
|
|
674
424
|
className: "w-full overflow-auto"
|
|
675
|
-
}, items?.map((item) => /* @__PURE__ */
|
|
425
|
+
}, items?.map((item) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
676
426
|
key: item.id
|
|
677
|
-
}, /* @__PURE__ */
|
|
427
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.Item, {
|
|
678
428
|
role: "button",
|
|
679
429
|
item,
|
|
680
430
|
classNames: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
681
431
|
"aria-expanded": selected === item.id
|
|
682
|
-
}, /* @__PURE__ */
|
|
432
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
683
433
|
className: "flex items-center"
|
|
684
|
-
}, /* @__PURE__ */
|
|
434
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react5.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
685
435
|
onClick: () => handleClick(item.id),
|
|
686
436
|
classNames: "flex-1"
|
|
687
|
-
}, /* @__PURE__ */
|
|
437
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tag, {
|
|
688
438
|
palette: item.color
|
|
689
|
-
}, item.title || "\u200B")), /* @__PURE__ */
|
|
439
|
+
}, item.title || "\u200B")), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
690
440
|
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
691
441
|
onClick: () => handleClick(item.id)
|
|
692
|
-
})), selected === item.id && /* @__PURE__ */
|
|
442
|
+
})), selected === item.id && /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
693
443
|
className: "mis-4 mbs-2 flex flex-col gap-1"
|
|
694
|
-
}, /* @__PURE__ */
|
|
444
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, {
|
|
695
445
|
classNames: "text-xs"
|
|
696
|
-
}, t("select option label")), /* @__PURE__ */
|
|
446
|
+
}, t("select option label")), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
697
447
|
className: "flex flex-row items-center gap-1"
|
|
698
|
-
}, /* @__PURE__ */
|
|
448
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.TextInput, {
|
|
699
449
|
placeholder: t("select option label placeholder"),
|
|
700
450
|
ref: selected === item.id ? inputRef : void 0,
|
|
701
451
|
value: item.title,
|
|
@@ -703,27 +453,27 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
703
453
|
onKeyDown: handleKeyDown,
|
|
704
454
|
classNames: "flex-1",
|
|
705
455
|
"data-no-submit": true
|
|
706
|
-
}), /* @__PURE__ */
|
|
456
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
707
457
|
classNames: "p-0 m-0 !is-auto"
|
|
708
|
-
}, /* @__PURE__ */
|
|
458
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui_pickers.HuePicker, {
|
|
709
459
|
value: item.color,
|
|
710
460
|
onChange: handleColorChange(item.id)
|
|
711
|
-
})), /* @__PURE__ */
|
|
461
|
+
})), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.IconButton, {
|
|
712
462
|
icon: "ph--trash--fill",
|
|
713
463
|
iconOnly: true,
|
|
714
464
|
label: t("select option delete"),
|
|
715
465
|
onClick: () => handleDelete(item.id)
|
|
716
|
-
})))))), /* @__PURE__ */
|
|
466
|
+
})))))), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
717
467
|
role: "listitem"
|
|
718
|
-
}, /* @__PURE__ */
|
|
468
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
719
469
|
role: "button",
|
|
720
470
|
className: (0, import_react_ui_theme3.mx)("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
|
|
721
471
|
onClick: handleAdd
|
|
722
|
-
}, /* @__PURE__ */
|
|
472
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
723
473
|
className: "flex items-center gap-1"
|
|
724
|
-
}, /* @__PURE__ */
|
|
474
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
725
475
|
icon: "ph--plus--regular"
|
|
726
|
-
}), /* @__PURE__ */
|
|
476
|
+
}), /* @__PURE__ */ import_react5.default.createElement("span", {
|
|
727
477
|
className: "text-sm"
|
|
728
478
|
}, t("select option add")))))))));
|
|
729
479
|
};
|
|
@@ -736,13 +486,13 @@ var gridCols = [
|
|
|
736
486
|
var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
737
487
|
const { status, error } = getStatus();
|
|
738
488
|
const values = getValue3() ?? {};
|
|
739
|
-
return /* @__PURE__ */
|
|
489
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
740
490
|
validationValence: status
|
|
741
|
-
}, /* @__PURE__ */
|
|
491
|
+
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
742
492
|
error
|
|
743
|
-
}, /* @__PURE__ */
|
|
493
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
744
494
|
className: (0, import_react_ui_theme4.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
745
|
-
}, binding.map((prop) => /* @__PURE__ */
|
|
495
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
746
496
|
key: prop,
|
|
747
497
|
type: "number",
|
|
748
498
|
disabled,
|
|
@@ -756,92 +506,92 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
|
|
|
756
506
|
};
|
|
757
507
|
var TextInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
758
508
|
const { status, error } = getStatus();
|
|
759
|
-
return /* @__PURE__ */
|
|
509
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
760
510
|
validationValence: status
|
|
761
|
-
}, !inputOnly && /* @__PURE__ */
|
|
511
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
762
512
|
error
|
|
763
|
-
}, /* @__PURE__ */
|
|
513
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
764
514
|
disabled,
|
|
765
515
|
placeholder,
|
|
766
516
|
value: getValue3() ?? "",
|
|
767
517
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
768
518
|
onBlur
|
|
769
|
-
}), inputOnly && /* @__PURE__ */
|
|
519
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
770
520
|
};
|
|
771
521
|
var NumberInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
772
522
|
const { status, error } = getStatus();
|
|
773
|
-
return /* @__PURE__ */
|
|
523
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
774
524
|
validationValence: status
|
|
775
|
-
}, !inputOnly && /* @__PURE__ */
|
|
525
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
776
526
|
error
|
|
777
|
-
}, /* @__PURE__ */
|
|
527
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextInput, {
|
|
778
528
|
type: "number",
|
|
779
529
|
disabled,
|
|
780
530
|
placeholder,
|
|
781
531
|
value: getValue3() ?? 0,
|
|
782
532
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
783
533
|
onBlur
|
|
784
|
-
}), inputOnly && /* @__PURE__ */
|
|
534
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
785
535
|
};
|
|
786
536
|
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
787
537
|
const { status, error } = getStatus();
|
|
788
538
|
const checked = Boolean(getValue3());
|
|
789
|
-
return /* @__PURE__ */
|
|
539
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
790
540
|
validationValence: status
|
|
791
|
-
}, !inputOnly && /* @__PURE__ */
|
|
541
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
792
542
|
error
|
|
793
|
-
}, /* @__PURE__ */
|
|
543
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Switch, {
|
|
794
544
|
checked,
|
|
795
545
|
onCheckedChange: (value) => onValueChange(type, value)
|
|
796
|
-
}), inputOnly && /* @__PURE__ */
|
|
546
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
797
547
|
};
|
|
798
548
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
799
549
|
const { status, error } = getStatus();
|
|
800
|
-
return /* @__PURE__ */
|
|
550
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
801
551
|
validationValence: status
|
|
802
|
-
}, !inputOnly && /* @__PURE__ */
|
|
552
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
803
553
|
error
|
|
804
|
-
}, /* @__PURE__ */
|
|
554
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Root, {
|
|
805
555
|
value: getValue3(),
|
|
806
556
|
onValueChange: (value) => onValueChange(type, value)
|
|
807
|
-
}, /* @__PURE__ */
|
|
557
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.TriggerButton, {
|
|
808
558
|
classNames: "is-full",
|
|
809
559
|
disabled,
|
|
810
560
|
placeholder
|
|
811
|
-
}), /* @__PURE__ */
|
|
561
|
+
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Portal, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Content, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
812
562
|
// NOTE: Numeric values are converted to and from strings.
|
|
813
|
-
/* @__PURE__ */
|
|
563
|
+
/* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Select.Option, {
|
|
814
564
|
key: String(value),
|
|
815
565
|
value: String(value)
|
|
816
566
|
}, label2 ?? String(value))
|
|
817
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
567
|
+
)))))), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.DescriptionAndValidation, null, error));
|
|
818
568
|
};
|
|
819
569
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
820
570
|
const { status, error } = getStatus();
|
|
821
|
-
const textareaRef = (0,
|
|
822
|
-
const adjustHeight = (0,
|
|
571
|
+
const textareaRef = (0, import_react7.useRef)(null);
|
|
572
|
+
const adjustHeight = (0, import_react7.useCallback)(() => {
|
|
823
573
|
const textarea = textareaRef.current;
|
|
824
574
|
if (textarea) {
|
|
825
575
|
textarea.style.blockSize = "auto";
|
|
826
576
|
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
827
577
|
}
|
|
828
578
|
}, []);
|
|
829
|
-
(0,
|
|
579
|
+
(0, import_react7.useEffect)(() => {
|
|
830
580
|
adjustHeight();
|
|
831
581
|
}, [
|
|
832
582
|
adjustHeight
|
|
833
583
|
]);
|
|
834
|
-
(0,
|
|
584
|
+
(0, import_react7.useEffect)(() => {
|
|
835
585
|
adjustHeight();
|
|
836
586
|
}, [
|
|
837
587
|
getValue3(),
|
|
838
588
|
adjustHeight
|
|
839
589
|
]);
|
|
840
|
-
return /* @__PURE__ */
|
|
590
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Root, {
|
|
841
591
|
validationValence: status
|
|
842
|
-
}, !inputOnly && /* @__PURE__ */
|
|
592
|
+
}, !inputOnly && /* @__PURE__ */ import_react7.default.createElement(InputHeader, {
|
|
843
593
|
error
|
|
844
|
-
}, /* @__PURE__ */
|
|
594
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Label, null, label)), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.TextArea, {
|
|
845
595
|
ref: textareaRef,
|
|
846
596
|
disabled,
|
|
847
597
|
placeholder,
|
|
@@ -853,23 +603,286 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
|
|
|
853
603
|
resize: "none"
|
|
854
604
|
},
|
|
855
605
|
spellCheck: false
|
|
856
|
-
}), inputOnly && /* @__PURE__ */
|
|
606
|
+
}), inputOnly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.Input.Validation, null, error));
|
|
607
|
+
};
|
|
608
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
609
|
+
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
610
|
+
(0, import_invariant.invariant)(import_effect2.SchemaAST.isTypeLiteral(schema.ast), void 0, {
|
|
611
|
+
F: __dxlog_file,
|
|
612
|
+
L: 93,
|
|
613
|
+
S: void 0,
|
|
614
|
+
A: [
|
|
615
|
+
"AST.isTypeLiteral(schema.ast)",
|
|
616
|
+
""
|
|
617
|
+
]
|
|
618
|
+
});
|
|
619
|
+
const [values, setValues] = (0, import_react11.useState)(initialValues);
|
|
620
|
+
(0, import_react11.useEffect)(() => {
|
|
621
|
+
setValues(initialValues);
|
|
622
|
+
}, [
|
|
623
|
+
initialValues
|
|
624
|
+
]);
|
|
625
|
+
const [touched, setTouched] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
626
|
+
const [changed, setChanged] = (0, import_react11.useState)(createKeySet(initialValues, false));
|
|
627
|
+
const [errors, setErrors] = (0, import_react11.useState)({});
|
|
628
|
+
const [saving, setSaving] = (0, import_react11.useState)(false);
|
|
629
|
+
const validate = (0, import_react11.useCallback)((values2) => {
|
|
630
|
+
let errors2 = (0, import_schema2.validateSchema)(schema, values2) ?? [];
|
|
631
|
+
if (errors2.length === 0 && onValidate) {
|
|
632
|
+
const validatedValues = values2;
|
|
633
|
+
errors2 = onValidate(validatedValues) ?? [];
|
|
634
|
+
}
|
|
635
|
+
setErrors(flatMap(errors2));
|
|
636
|
+
const valid = errors2.length === 0;
|
|
637
|
+
return valid;
|
|
638
|
+
}, [
|
|
639
|
+
schema,
|
|
640
|
+
onValidate
|
|
641
|
+
]);
|
|
642
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react11.useState)(false);
|
|
643
|
+
(0, import_react11.useEffect)(() => setSchemaDirty(true), [
|
|
644
|
+
schema
|
|
645
|
+
]);
|
|
646
|
+
(0, import_react11.useEffect)(() => {
|
|
647
|
+
if (schemaDirty) {
|
|
648
|
+
validate(values);
|
|
649
|
+
setSchemaDirty(false);
|
|
650
|
+
}
|
|
651
|
+
}, [
|
|
652
|
+
values,
|
|
653
|
+
schemaDirty
|
|
654
|
+
]);
|
|
655
|
+
const formIsValid = (0, import_react11.useMemo)(() => {
|
|
656
|
+
return Object.keys(errors).length === 0;
|
|
657
|
+
}, [
|
|
658
|
+
errors
|
|
659
|
+
]);
|
|
660
|
+
const canSave = (0, import_react11.useMemo)(() => !saving && // Check if any error paths that are touched have errors.
|
|
661
|
+
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
662
|
+
touched,
|
|
663
|
+
errors,
|
|
664
|
+
saving
|
|
665
|
+
]);
|
|
666
|
+
const handleSave = (0, import_react11.useCallback)(async () => {
|
|
667
|
+
if (validate(values)) {
|
|
668
|
+
setSaving(true);
|
|
669
|
+
try {
|
|
670
|
+
await onSave?.(values, {
|
|
671
|
+
changed
|
|
672
|
+
});
|
|
673
|
+
} finally {
|
|
674
|
+
setSaving(false);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}, [
|
|
678
|
+
values,
|
|
679
|
+
validate,
|
|
680
|
+
onSave,
|
|
681
|
+
changed
|
|
682
|
+
]);
|
|
683
|
+
const getStatus = (0, import_react11.useCallback)((path) => {
|
|
684
|
+
const jsonPath = Array.isArray(path) ? (0, import_effect3.createJsonPath)(path) : path;
|
|
685
|
+
const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
|
|
686
|
+
const isTouched = touched[jsonPath];
|
|
687
|
+
if (!isTouched) {
|
|
688
|
+
return {
|
|
689
|
+
status: void 0,
|
|
690
|
+
error: void 0
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
return {
|
|
694
|
+
status: matchingError ? "error" : void 0,
|
|
695
|
+
error: matchingError ? matchingError[1] : void 0
|
|
696
|
+
};
|
|
697
|
+
}, [
|
|
698
|
+
errors,
|
|
699
|
+
touched
|
|
700
|
+
]);
|
|
701
|
+
const getFormValue = (0, import_react11.useCallback)((path) => {
|
|
702
|
+
return (0, import_echo_schema4.getValue)(values, (0, import_effect3.createJsonPath)(path));
|
|
703
|
+
}, [
|
|
704
|
+
values
|
|
705
|
+
]);
|
|
706
|
+
const onValueChange = (0, import_react11.useCallback)((path, type, value) => {
|
|
707
|
+
const jsonPath = (0, import_effect3.createJsonPath)(path);
|
|
708
|
+
let parsedValue = value;
|
|
709
|
+
try {
|
|
710
|
+
if (type === "number") {
|
|
711
|
+
parsedValue = parseFloat(value) || 0;
|
|
712
|
+
}
|
|
713
|
+
} catch (err) {
|
|
714
|
+
import_log2.log.catch(err, void 0, {
|
|
715
|
+
F: __dxlog_file,
|
|
716
|
+
L: 212,
|
|
717
|
+
S: void 0,
|
|
718
|
+
C: (f, a) => f(...a)
|
|
719
|
+
});
|
|
720
|
+
parsedValue = void 0;
|
|
721
|
+
}
|
|
722
|
+
const newValues = {
|
|
723
|
+
...(0, import_echo_schema4.setValue)(values, jsonPath, parsedValue)
|
|
724
|
+
};
|
|
725
|
+
setValues(newValues);
|
|
726
|
+
setChanged((prev) => ({
|
|
727
|
+
...prev,
|
|
728
|
+
[jsonPath]: true
|
|
729
|
+
}));
|
|
730
|
+
onValuesChanged?.(newValues);
|
|
731
|
+
const isValid = validate(newValues);
|
|
732
|
+
if (isValid && onValid) {
|
|
733
|
+
onValid(newValues, {
|
|
734
|
+
changed
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}, [
|
|
738
|
+
values,
|
|
739
|
+
onValuesChanged,
|
|
740
|
+
validate,
|
|
741
|
+
onValid,
|
|
742
|
+
changed
|
|
743
|
+
]);
|
|
744
|
+
const onTouched = (0, import_react11.useCallback)((path) => {
|
|
745
|
+
const jsonPath = (0, import_effect3.createJsonPath)(path);
|
|
746
|
+
setTouched((touched2) => ({
|
|
747
|
+
...touched2,
|
|
748
|
+
[jsonPath]: true
|
|
749
|
+
}));
|
|
750
|
+
validate(values);
|
|
751
|
+
}, [
|
|
752
|
+
validate,
|
|
753
|
+
values
|
|
754
|
+
]);
|
|
755
|
+
return (0, import_react11.useMemo)(() => ({
|
|
756
|
+
// State.
|
|
757
|
+
values,
|
|
758
|
+
errors,
|
|
759
|
+
touched,
|
|
760
|
+
changed,
|
|
761
|
+
canSave,
|
|
762
|
+
formIsValid,
|
|
763
|
+
// Actions.
|
|
764
|
+
handleSave,
|
|
765
|
+
// Field utils.
|
|
766
|
+
getStatus,
|
|
767
|
+
getValue: getFormValue,
|
|
768
|
+
onValueChange,
|
|
769
|
+
onTouched
|
|
770
|
+
}), [
|
|
771
|
+
values,
|
|
772
|
+
errors,
|
|
773
|
+
touched,
|
|
774
|
+
changed,
|
|
775
|
+
canSave,
|
|
776
|
+
formIsValid,
|
|
777
|
+
handleSave,
|
|
778
|
+
getStatus,
|
|
779
|
+
getFormValue,
|
|
780
|
+
onValueChange,
|
|
781
|
+
onTouched
|
|
782
|
+
]);
|
|
783
|
+
};
|
|
784
|
+
var createKeySet = (obj, value) => {
|
|
785
|
+
(0, import_invariant.invariant)(obj, void 0, {
|
|
786
|
+
F: __dxlog_file,
|
|
787
|
+
L: 274,
|
|
788
|
+
S: void 0,
|
|
789
|
+
A: [
|
|
790
|
+
"obj",
|
|
791
|
+
""
|
|
792
|
+
]
|
|
793
|
+
});
|
|
794
|
+
return Object.keys(obj).reduce((acc, key) => ({
|
|
795
|
+
...acc,
|
|
796
|
+
[key]: value
|
|
797
|
+
}), {});
|
|
798
|
+
};
|
|
799
|
+
var flatMap = (errors) => {
|
|
800
|
+
return errors.reduce((result, { path, message }) => {
|
|
801
|
+
const jsonPath = (0, import_effect3.fromEffectValidationPath)(path);
|
|
802
|
+
if (!(jsonPath in result)) {
|
|
803
|
+
result[jsonPath] = message;
|
|
804
|
+
}
|
|
805
|
+
return result;
|
|
806
|
+
}, {});
|
|
807
|
+
};
|
|
808
|
+
var FormContext = /* @__PURE__ */ (0, import_react10.createContext)(void 0);
|
|
809
|
+
var useFormContext = () => {
|
|
810
|
+
return (0, import_react10.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
811
|
+
};
|
|
812
|
+
var useFormValues = (path = []) => {
|
|
813
|
+
const { values: formValues } = useFormContext();
|
|
814
|
+
const jsonPath = (0, import_effect.createJsonPath)(path);
|
|
815
|
+
return (0, import_echo_schema3.getValue)(formValues, jsonPath);
|
|
816
|
+
};
|
|
817
|
+
var useInputProps = (path = []) => {
|
|
818
|
+
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
819
|
+
const stablePath = (0, import_react10.useMemo)(() => path, [
|
|
820
|
+
Array.isArray(path) ? path.join(".") : path
|
|
821
|
+
]);
|
|
822
|
+
return (0, import_react10.useMemo)(() => ({
|
|
823
|
+
getStatus: () => getStatus(stablePath),
|
|
824
|
+
getValue: () => getFormValue(stablePath),
|
|
825
|
+
onValueChange: (type, value) => onValueChange(stablePath, type, value),
|
|
826
|
+
onBlur: () => onTouched(stablePath)
|
|
827
|
+
}), [
|
|
828
|
+
getStatus,
|
|
829
|
+
getFormValue,
|
|
830
|
+
onValueChange,
|
|
831
|
+
onTouched,
|
|
832
|
+
stablePath
|
|
833
|
+
]);
|
|
834
|
+
};
|
|
835
|
+
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
836
|
+
const form = useForm(formOptions);
|
|
837
|
+
(0, import_react10.useEffect)(() => {
|
|
838
|
+
if (!formRef?.current) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const handleKeyDown = (event) => {
|
|
842
|
+
const keyIsEnter = event.key === "Enter";
|
|
843
|
+
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
844
|
+
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
845
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
846
|
+
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
847
|
+
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
848
|
+
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
849
|
+
if (!autoSave && form.canSave) {
|
|
850
|
+
form.handleSave();
|
|
851
|
+
}
|
|
852
|
+
if (autoSave && form.formIsValid) {
|
|
853
|
+
event.target.blur();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
const formElement = formRef.current;
|
|
858
|
+
formElement.addEventListener("keydown", handleKeyDown);
|
|
859
|
+
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
860
|
+
}, [
|
|
861
|
+
formRef,
|
|
862
|
+
form.canSave,
|
|
863
|
+
form.formIsValid,
|
|
864
|
+
form.handleSave,
|
|
865
|
+
autoSave
|
|
866
|
+
]);
|
|
867
|
+
return /* @__PURE__ */ import_react10.default.createElement(FormContext.Provider, {
|
|
868
|
+
value: form
|
|
869
|
+
}, children);
|
|
857
870
|
};
|
|
858
871
|
var FormActions = ({ onCancel, readonly }) => {
|
|
859
872
|
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
860
873
|
const { canSave, handleSave } = useFormContext();
|
|
861
|
-
return /* @__PURE__ */
|
|
874
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
862
875
|
role: "none",
|
|
863
876
|
className: "mt-2 flex justify-center"
|
|
864
|
-
}, /* @__PURE__ */
|
|
877
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
865
878
|
role: "none",
|
|
866
879
|
className: (0, import_react_ui_theme6.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
867
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
880
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
868
881
|
"data-testid": "cancel-button",
|
|
869
882
|
icon: "ph--x--regular",
|
|
870
883
|
label: t("button cancel"),
|
|
871
884
|
onClick: onCancel
|
|
872
|
-
}), handleSave && /* @__PURE__ */
|
|
885
|
+
}), handleSave && /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
873
886
|
type: "submit",
|
|
874
887
|
"data-testid": "save-button",
|
|
875
888
|
disabled: !canSave,
|
|
@@ -893,12 +906,12 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
893
906
|
"`Values at path ${path?.join('.')} must be an array.`"
|
|
894
907
|
]
|
|
895
908
|
});
|
|
896
|
-
const label = title ?? (0,
|
|
897
|
-
const tupleType = (0,
|
|
909
|
+
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
910
|
+
const tupleType = (0, import_effect7.findNode)(ast, import_echo_schema6.AST.isTupleType);
|
|
898
911
|
const elementType = tupleType?.rest[0]?.type;
|
|
899
912
|
const getDefaultObjectValue = (typeNode) => {
|
|
900
|
-
const baseNode = (0,
|
|
901
|
-
const typeLiteral = baseNode ? (0,
|
|
913
|
+
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
914
|
+
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_echo_schema6.AST.isTypeLiteral);
|
|
902
915
|
if (!typeLiteral) {
|
|
903
916
|
return {};
|
|
904
917
|
}
|
|
@@ -911,7 +924,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
911
924
|
if (type === "object" && elementType) {
|
|
912
925
|
return getDefaultObjectValue(elementType);
|
|
913
926
|
} else {
|
|
914
|
-
return
|
|
927
|
+
return import_effect7.SimpleType.getDefaultValue(type);
|
|
915
928
|
}
|
|
916
929
|
}, [
|
|
917
930
|
type,
|
|
@@ -1001,7 +1014,7 @@ var getInputComponent = (type, format) => {
|
|
|
1001
1014
|
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
1002
1015
|
const inputProps = useInputProps(path);
|
|
1003
1016
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1004
|
-
const label = (0, import_react12.useMemo)(() => title ?? (0,
|
|
1017
|
+
const label = (0, import_react12.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1005
1018
|
title,
|
|
1006
1019
|
name
|
|
1007
1020
|
]);
|
|
@@ -1026,7 +1039,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1026
1039
|
role: "none"
|
|
1027
1040
|
}, FoundComponent);
|
|
1028
1041
|
}
|
|
1029
|
-
const jsonPath = (0,
|
|
1042
|
+
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1030
1043
|
const CustomComponent = Custom?.[jsonPath];
|
|
1031
1044
|
if (CustomComponent) {
|
|
1032
1045
|
return /* @__PURE__ */ import_react12.default.createElement(CustomComponent, {
|
|
@@ -1080,8 +1093,8 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1080
1093
|
}));
|
|
1081
1094
|
}
|
|
1082
1095
|
if (type === "object") {
|
|
1083
|
-
const baseNode = (0,
|
|
1084
|
-
const typeLiteral = baseNode ? (0,
|
|
1096
|
+
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1097
|
+
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_echo_schema5.AST.isTypeLiteral);
|
|
1085
1098
|
if (typeLiteral) {
|
|
1086
1099
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
1087
1100
|
role: "none"
|
|
@@ -1125,12 +1138,12 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1125
1138
|
}).filter(import_util3.isNotFalsy));
|
|
1126
1139
|
};
|
|
1127
1140
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1128
|
-
const formRef = (0,
|
|
1129
|
-
const onValid = (0,
|
|
1141
|
+
const formRef = (0, import_react8.useRef)(null);
|
|
1142
|
+
const onValid = (0, import_react8.useMemo)(() => autoSave ? onSave : void 0, [
|
|
1130
1143
|
autoSave,
|
|
1131
1144
|
onSave
|
|
1132
1145
|
]);
|
|
1133
|
-
(0,
|
|
1146
|
+
(0, import_react8.useEffect)(() => {
|
|
1134
1147
|
if (autoFocus && formRef.current) {
|
|
1135
1148
|
const input = formRef.current.querySelector("input");
|
|
1136
1149
|
if (input) {
|
|
@@ -1140,7 +1153,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1140
1153
|
}, [
|
|
1141
1154
|
autoFocus
|
|
1142
1155
|
]);
|
|
1143
|
-
return /* @__PURE__ */
|
|
1156
|
+
return /* @__PURE__ */ import_react8.default.createElement(FormProvider, {
|
|
1144
1157
|
formRef,
|
|
1145
1158
|
schema,
|
|
1146
1159
|
autoSave,
|
|
@@ -1149,12 +1162,12 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1149
1162
|
onValidate,
|
|
1150
1163
|
onValid,
|
|
1151
1164
|
onSave
|
|
1152
|
-
}, /* @__PURE__ */
|
|
1165
|
+
}, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
1153
1166
|
ref: formRef,
|
|
1154
1167
|
role: "none",
|
|
1155
1168
|
className: (0, import_react_ui_theme5.mx)("p-2", classNames),
|
|
1156
1169
|
"data-testid": testId
|
|
1157
|
-
}, /* @__PURE__ */
|
|
1170
|
+
}, /* @__PURE__ */ import_react8.default.createElement(FormFields, {
|
|
1158
1171
|
schema,
|
|
1159
1172
|
path,
|
|
1160
1173
|
readonly,
|
|
@@ -1162,7 +1175,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1162
1175
|
sort,
|
|
1163
1176
|
lookupComponent,
|
|
1164
1177
|
Custom
|
|
1165
|
-
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */
|
|
1178
|
+
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react8.default.createElement(FormActions, {
|
|
1166
1179
|
onCancel,
|
|
1167
1180
|
readonly
|
|
1168
1181
|
})));
|
|
@@ -1373,6 +1386,15 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1373
1386
|
}, [
|
|
1374
1387
|
view
|
|
1375
1388
|
]);
|
|
1389
|
+
const handleDelete = (0, import_react14.useCallback)((fieldId) => {
|
|
1390
|
+
if (fieldId === field?.id) {
|
|
1391
|
+
setField(void 0);
|
|
1392
|
+
}
|
|
1393
|
+
onDelete(fieldId);
|
|
1394
|
+
}, [
|
|
1395
|
+
onDelete,
|
|
1396
|
+
field
|
|
1397
|
+
]);
|
|
1376
1398
|
const handleMove = (0, import_react14.useCallback)((fromIndex, toIndex) => {
|
|
1377
1399
|
const fields = [
|
|
1378
1400
|
...view.fields
|
|
@@ -1384,6 +1406,19 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1384
1406
|
view.fields
|
|
1385
1407
|
]);
|
|
1386
1408
|
const handleClose = (0, import_react14.useCallback)(() => setField(void 0), []);
|
|
1409
|
+
const hiddenProperties = projection.getHiddenProperties();
|
|
1410
|
+
const handleHide = (0, import_react14.useCallback)((fieldId) => {
|
|
1411
|
+
setField(void 0);
|
|
1412
|
+
projection.hideFieldProjection(fieldId);
|
|
1413
|
+
}, [
|
|
1414
|
+
projection
|
|
1415
|
+
]);
|
|
1416
|
+
const handleShow = (0, import_react14.useCallback)((property) => {
|
|
1417
|
+
setField(void 0);
|
|
1418
|
+
projection.showFieldProjection(property);
|
|
1419
|
+
}, [
|
|
1420
|
+
projection
|
|
1421
|
+
]);
|
|
1387
1422
|
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1388
1423
|
role: "none",
|
|
1389
1424
|
className: (0, import_react_ui_theme9.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
@@ -1416,9 +1451,35 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1416
1451
|
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1417
1452
|
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1418
1453
|
onClick: () => handleSelect(field2)
|
|
1419
|
-
}, field2.path), /* @__PURE__ */ import_react14.default.createElement(
|
|
1454
|
+
}, field2.path), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1455
|
+
className: "flex items-center gap-2 -ml-4"
|
|
1456
|
+
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1457
|
+
icon: "ph--eye-slash--regular",
|
|
1458
|
+
disabled: view.fields.length <= 1,
|
|
1459
|
+
onClick: () => handleHide(field2.id)
|
|
1460
|
+
}), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1461
|
+
icon: "ph--trash--regular",
|
|
1420
1462
|
disabled: view.fields.length <= 1,
|
|
1421
|
-
onClick: () =>
|
|
1463
|
+
onClick: () => handleDelete(field2.id)
|
|
1464
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react14.default.createElement("div", null, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1465
|
+
role: "none",
|
|
1466
|
+
className: "p-2"
|
|
1467
|
+
}, /* @__PURE__ */ import_react14.default.createElement("label", {
|
|
1468
|
+
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1469
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1470
|
+
items: hiddenProperties,
|
|
1471
|
+
isItem: (item) => typeof item === "string",
|
|
1472
|
+
getId: (property) => property
|
|
1473
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1474
|
+
role: "list",
|
|
1475
|
+
className: "flex flex-col w-full"
|
|
1476
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Item, {
|
|
1477
|
+
key: property,
|
|
1478
|
+
item: property,
|
|
1479
|
+
classNames: (0, import_react_ui_theme9.mx)(grid, import_react_ui_theme9.ghostHover, "cursor-pointer")
|
|
1480
|
+
}, /* @__PURE__ */ import_react14.default.createElement("div", null), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemTitle, null, property), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1481
|
+
icon: "ph--eye--regular",
|
|
1482
|
+
onClick: () => handleShow(property)
|
|
1422
1483
|
}))))))), field && /* @__PURE__ */ import_react14.default.createElement(FieldEditor, {
|
|
1423
1484
|
key: field.id,
|
|
1424
1485
|
view,
|
|
@@ -1551,6 +1612,7 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1551
1612
|
"text-right"
|
|
1552
1613
|
];
|
|
1553
1614
|
case import_echo_schema9.FormatEnum.JSON:
|
|
1615
|
+
case import_echo_schema9.FormatEnum.DID:
|
|
1554
1616
|
return [
|
|
1555
1617
|
"font-mono"
|
|
1556
1618
|
];
|
|
@@ -1697,6 +1759,7 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1697
1759
|
DeprecatedFormInput,
|
|
1698
1760
|
FieldEditor,
|
|
1699
1761
|
Form,
|
|
1762
|
+
FormProvider,
|
|
1700
1763
|
GeoPointInput,
|
|
1701
1764
|
InputHeader,
|
|
1702
1765
|
MarkdownInput,
|
|
@@ -1714,6 +1777,8 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1714
1777
|
pathNotUniqueError,
|
|
1715
1778
|
translations,
|
|
1716
1779
|
useForm,
|
|
1717
|
-
|
|
1780
|
+
useFormContext,
|
|
1781
|
+
useFormValues,
|
|
1782
|
+
useInputProps
|
|
1718
1783
|
});
|
|
1719
1784
|
//# sourceMappingURL=index.cjs.map
|