@dxos/react-ui-form 0.7.5-labs.c0e040f → 0.7.5-labs.d199c0f
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 +200 -92
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +224 -116
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +200 -92
- package/dist/lib/node-esm/index.mjs.map +3 -3
- 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 -6
- 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 +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 +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/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.map +1 -1
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/package.json +25 -24
- package/src/components/Form/Defaults.tsx +1 -1
- package/src/components/Form/FormContext.tsx +11 -7
- package/src/components/Form/custom/GeoPointInput.tsx +42 -12
- package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
- package/src/components/Form/factory.tsx +1 -1
- package/src/hooks/useForm.ts +64 -41
- package/src/translations.ts +1 -1
- package/src/util/field.ts +19 -1
- package/src/util/formatting.ts +29 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -72,6 +72,7 @@ var import_invariant = require("@dxos/invariant");
|
|
|
72
72
|
var import_log2 = require("@dxos/log");
|
|
73
73
|
var import_schema2 = require("@dxos/schema");
|
|
74
74
|
var import_react5 = __toESM(require("react"));
|
|
75
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
75
76
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
76
77
|
var import_util = require("@dxos/util");
|
|
77
78
|
var import_react6 = __toESM(require("react"));
|
|
@@ -97,7 +98,7 @@ var import_react_ui_theme6 = require("@dxos/react-ui-theme");
|
|
|
97
98
|
var import_effect3 = require("effect");
|
|
98
99
|
var import_String = require("effect/String");
|
|
99
100
|
var import_react12 = __toESM(require("react"));
|
|
100
|
-
var
|
|
101
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
101
102
|
var import_effect4 = require("@dxos/effect");
|
|
102
103
|
var import_react_ui_theme7 = require("@dxos/react-ui-theme");
|
|
103
104
|
var import_schema3 = require("@dxos/schema");
|
|
@@ -105,21 +106,21 @@ var import_util3 = require("@dxos/util");
|
|
|
105
106
|
var import_effect5 = require("effect");
|
|
106
107
|
var import_String2 = require("effect/String");
|
|
107
108
|
var import_react13 = __toESM(require("react"));
|
|
108
|
-
var
|
|
109
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
109
110
|
var import_effect6 = require("@dxos/effect");
|
|
110
111
|
var import_invariant2 = require("@dxos/invariant");
|
|
111
112
|
var import_react_ui9 = require("@dxos/react-ui");
|
|
112
113
|
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
113
114
|
var import_schema4 = require("@dxos/schema");
|
|
114
|
-
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
115
|
-
var import_react14 = __toESM(require("react"));
|
|
116
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");
|
|
117
118
|
var import_react_ui10 = require("@dxos/react-ui");
|
|
118
119
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
119
120
|
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
120
121
|
var import_schema5 = require("@dxos/schema");
|
|
121
|
-
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
122
122
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
123
|
+
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
123
124
|
var translationKey = "react-ui-form";
|
|
124
125
|
var translations_default = [
|
|
125
126
|
{
|
|
@@ -150,7 +151,7 @@ var translations_default = [
|
|
|
150
151
|
"format hostname": "Hostname",
|
|
151
152
|
"format integer": "Integer",
|
|
152
153
|
"format json": "JSON",
|
|
153
|
-
"format latlng": "
|
|
154
|
+
"format latlng": "Geopoint",
|
|
154
155
|
"format markdown": "Markdown",
|
|
155
156
|
"format percent": "Percent",
|
|
156
157
|
"format ref": "Reference",
|
|
@@ -265,7 +266,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
265
266
|
}, [
|
|
266
267
|
errors
|
|
267
268
|
]);
|
|
268
|
-
const canSave = (0, import_react4.useMemo)(() => !saving && // Check if any error paths that are touched have errors
|
|
269
|
+
const canSave = (0, import_react4.useMemo)(() => !saving && // Check if any error paths that are touched have errors.
|
|
269
270
|
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
270
271
|
touched,
|
|
271
272
|
errors,
|
|
@@ -298,10 +299,12 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
298
299
|
}, [
|
|
299
300
|
errors
|
|
300
301
|
]);
|
|
301
|
-
const getFormValue = (path) => {
|
|
302
|
+
const getFormValue = (0, import_react4.useCallback)((path) => {
|
|
302
303
|
return (0, import_echo_schema3.getValue)(values, (0, import_effect2.createJsonPath)(path));
|
|
303
|
-
}
|
|
304
|
-
|
|
304
|
+
}, [
|
|
305
|
+
values
|
|
306
|
+
]);
|
|
307
|
+
const onValueChange = (0, import_react4.useCallback)((path, type, value) => {
|
|
305
308
|
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
306
309
|
let parsedValue = value;
|
|
307
310
|
try {
|
|
@@ -311,7 +314,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
311
314
|
} catch (err) {
|
|
312
315
|
import_log2.log.catch(err, void 0, {
|
|
313
316
|
F: __dxlog_file,
|
|
314
|
-
L:
|
|
317
|
+
L: 202,
|
|
315
318
|
S: void 0,
|
|
316
319
|
C: (f, a) => f(...a)
|
|
317
320
|
});
|
|
@@ -332,7 +335,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
332
335
|
changed
|
|
333
336
|
});
|
|
334
337
|
}
|
|
335
|
-
}
|
|
338
|
+
}, [
|
|
339
|
+
values,
|
|
340
|
+
onValuesChanged,
|
|
341
|
+
validate,
|
|
342
|
+
onValid,
|
|
343
|
+
changed
|
|
344
|
+
]);
|
|
336
345
|
const onTouched = (0, import_react4.useCallback)((path) => {
|
|
337
346
|
const jsonPath = (0, import_effect2.createJsonPath)(path);
|
|
338
347
|
setTouched((touched2) => ({
|
|
@@ -344,26 +353,39 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
344
353
|
validate,
|
|
345
354
|
values
|
|
346
355
|
]);
|
|
347
|
-
return {
|
|
356
|
+
return (0, import_react4.useMemo)(() => ({
|
|
348
357
|
// State.
|
|
349
358
|
values,
|
|
350
359
|
errors,
|
|
351
360
|
touched,
|
|
352
361
|
changed,
|
|
353
362
|
canSave,
|
|
354
|
-
handleSave,
|
|
355
363
|
formIsValid,
|
|
364
|
+
// Actions.
|
|
365
|
+
handleSave,
|
|
356
366
|
// Field utils.
|
|
357
367
|
getStatus,
|
|
358
368
|
getValue: getFormValue,
|
|
359
369
|
onValueChange,
|
|
360
370
|
onTouched
|
|
361
|
-
}
|
|
371
|
+
}), [
|
|
372
|
+
values,
|
|
373
|
+
errors,
|
|
374
|
+
touched,
|
|
375
|
+
changed,
|
|
376
|
+
canSave,
|
|
377
|
+
formIsValid,
|
|
378
|
+
handleSave,
|
|
379
|
+
getStatus,
|
|
380
|
+
getFormValue,
|
|
381
|
+
onValueChange,
|
|
382
|
+
onTouched
|
|
383
|
+
]);
|
|
362
384
|
};
|
|
363
385
|
var createKeySet = (obj, value) => {
|
|
364
386
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
365
387
|
F: __dxlog_file,
|
|
366
|
-
L:
|
|
388
|
+
L: 264,
|
|
367
389
|
S: void 0,
|
|
368
390
|
A: [
|
|
369
391
|
"obj",
|
|
@@ -395,12 +417,21 @@ var useFormValues = (path = []) => {
|
|
|
395
417
|
};
|
|
396
418
|
var useInputProps = (path = []) => {
|
|
397
419
|
const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
+
]);
|
|
404
435
|
};
|
|
405
436
|
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
406
437
|
const form = useForm(formOptions);
|
|
@@ -455,32 +486,69 @@ var InputHeader = ({ children, error }) => {
|
|
|
455
486
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
456
487
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
457
488
|
const { status, error } = getStatus();
|
|
458
|
-
const
|
|
489
|
+
const geoPoint = (0, import_react5.useMemo)(() => getValue3() ?? [
|
|
490
|
+
0,
|
|
491
|
+
0
|
|
492
|
+
], [
|
|
493
|
+
getValue3
|
|
494
|
+
]);
|
|
495
|
+
const geoLocation = (0, import_react5.useMemo)(() => import_echo_schema4.GeoLocation.fromGeoPoint(geoPoint), [
|
|
496
|
+
geoPoint
|
|
497
|
+
]);
|
|
498
|
+
const [longitudeText, setLongitudeText] = (0, import_react5.useState)(geoLocation.longitude?.toString());
|
|
499
|
+
const [latitudeText, setLatitudeText] = (0, import_react5.useState)(geoLocation.latitude?.toString());
|
|
500
|
+
(0, import_react5.useEffect)(() => {
|
|
501
|
+
const location = import_echo_schema4.GeoLocation.fromGeoPoint(geoPoint);
|
|
502
|
+
setLongitudeText(location.longitude.toString());
|
|
503
|
+
setLatitudeText(location.latitude.toString());
|
|
504
|
+
}, [
|
|
505
|
+
geoPoint
|
|
506
|
+
]);
|
|
507
|
+
const handleCoordinateChange = (0, import_react5.useCallback)((coordinateType, setText) => (event) => {
|
|
508
|
+
const inputText = event.target.value;
|
|
509
|
+
setText(inputText);
|
|
510
|
+
if (inputText !== "" && inputText !== "-") {
|
|
511
|
+
const coord = (0, import_util.safeParseFloat)(inputText);
|
|
512
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
513
|
+
const currentLocation = import_echo_schema4.GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
514
|
+
0,
|
|
515
|
+
0
|
|
516
|
+
]);
|
|
517
|
+
const newLocation = {
|
|
518
|
+
...currentLocation,
|
|
519
|
+
[coordinateType]: coord
|
|
520
|
+
};
|
|
521
|
+
const newValue = import_echo_schema4.GeoLocation.toGeoPoint(newLocation);
|
|
522
|
+
onValueChange(type, newValue);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}, [
|
|
526
|
+
getValue3,
|
|
527
|
+
onValueChange,
|
|
528
|
+
type
|
|
529
|
+
]);
|
|
459
530
|
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Root, {
|
|
460
531
|
validationValence: status
|
|
461
532
|
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
462
533
|
error
|
|
463
534
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
535
|
+
role: "none",
|
|
464
536
|
className: "grid grid-cols-2 gap-2"
|
|
465
537
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
466
|
-
type: "
|
|
538
|
+
type: "text",
|
|
539
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
467
540
|
disabled,
|
|
468
|
-
placeholder: t("placeholder
|
|
469
|
-
value:
|
|
470
|
-
onChange: (
|
|
471
|
-
lat,
|
|
472
|
-
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
473
|
-
]),
|
|
541
|
+
placeholder: t("placeholder latitude"),
|
|
542
|
+
value: latitudeText,
|
|
543
|
+
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
474
544
|
onBlur
|
|
475
545
|
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Input.TextInput, {
|
|
476
|
-
type: "
|
|
546
|
+
type: "text",
|
|
547
|
+
pattern: "^-?[0-9]*\\.?[0-9]*$",
|
|
477
548
|
disabled,
|
|
478
|
-
placeholder: t("placeholder
|
|
479
|
-
value:
|
|
480
|
-
onChange: (
|
|
481
|
-
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
482
|
-
lng
|
|
483
|
-
]),
|
|
549
|
+
placeholder: t("placeholder longitude"),
|
|
550
|
+
value: longitudeText,
|
|
551
|
+
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
484
552
|
onBlur
|
|
485
553
|
})));
|
|
486
554
|
};
|
|
@@ -637,9 +705,9 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
|
|
|
637
705
|
"data-no-submit": true
|
|
638
706
|
}), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Toolbar.Root, {
|
|
639
707
|
classNames: "p-0 m-0 !is-auto"
|
|
640
|
-
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_pickers.
|
|
641
|
-
|
|
642
|
-
|
|
708
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui_pickers.HuePicker, {
|
|
709
|
+
value: item.color,
|
|
710
|
+
onChange: handleColorChange(item.id)
|
|
643
711
|
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.IconButton, {
|
|
644
712
|
icon: "ph--trash--fill",
|
|
645
713
|
iconOnly: true,
|
|
@@ -778,7 +846,7 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
|
|
|
778
846
|
disabled,
|
|
779
847
|
placeholder,
|
|
780
848
|
value: getValue3() ?? "",
|
|
781
|
-
classNames: "min-bs-auto overflow-
|
|
849
|
+
classNames: "min-bs-auto max-h-40 overflow-auto",
|
|
782
850
|
onChange: (event) => onValueChange(type, event.target.value),
|
|
783
851
|
onBlur,
|
|
784
852
|
style: {
|
|
@@ -826,11 +894,11 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
826
894
|
]
|
|
827
895
|
});
|
|
828
896
|
const label = title ?? (0, import_effect5.pipe)(name, import_String2.capitalize);
|
|
829
|
-
const tupleType = (0, import_effect6.findNode)(ast,
|
|
897
|
+
const tupleType = (0, import_effect6.findNode)(ast, import_echo_schema6.AST.isTupleType);
|
|
830
898
|
const elementType = tupleType?.rest[0]?.type;
|
|
831
899
|
const getDefaultObjectValue = (typeNode) => {
|
|
832
900
|
const baseNode = (0, import_effect6.findNode)(typeNode, import_effect6.isDiscriminatedUnion);
|
|
833
|
-
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode,
|
|
901
|
+
const typeLiteral = baseNode ? (0, import_effect6.getDiscriminatedType)(baseNode, {}) : (0, import_effect6.findNode)(typeNode, import_echo_schema6.AST.isTypeLiteral);
|
|
834
902
|
if (!typeLiteral) {
|
|
835
903
|
return {};
|
|
836
904
|
}
|
|
@@ -916,9 +984,9 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
916
984
|
};
|
|
917
985
|
var getInputComponent = (type, format) => {
|
|
918
986
|
switch (format) {
|
|
919
|
-
case
|
|
987
|
+
case import_echo_schema7.FormatEnum.GeoPoint:
|
|
920
988
|
return GeoPointInput;
|
|
921
|
-
case
|
|
989
|
+
case import_echo_schema7.FormatEnum.Markdown:
|
|
922
990
|
return MarkdownInput;
|
|
923
991
|
}
|
|
924
992
|
switch (type) {
|
|
@@ -943,7 +1011,7 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
943
1011
|
]);
|
|
944
1012
|
const FoundComponent = lookupComponent?.({
|
|
945
1013
|
prop: name,
|
|
946
|
-
schema:
|
|
1014
|
+
schema: import_echo_schema5.S.make(ast),
|
|
947
1015
|
inputProps: {
|
|
948
1016
|
type,
|
|
949
1017
|
format,
|
|
@@ -1013,12 +1081,12 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1013
1081
|
}
|
|
1014
1082
|
if (type === "object") {
|
|
1015
1083
|
const baseNode = (0, import_effect4.findNode)(ast, import_effect4.isDiscriminatedUnion);
|
|
1016
|
-
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast,
|
|
1084
|
+
const typeLiteral = baseNode ? (0, import_effect4.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect4.findNode)(ast, import_echo_schema5.AST.isTypeLiteral);
|
|
1017
1085
|
if (typeLiteral) {
|
|
1018
1086
|
return /* @__PURE__ */ import_react12.default.createElement("div", {
|
|
1019
1087
|
role: "none"
|
|
1020
1088
|
}, !inline && /* @__PURE__ */ import_react12.default.createElement("div", null, label), /* @__PURE__ */ import_react12.default.createElement(FormFields, {
|
|
1021
|
-
schema:
|
|
1089
|
+
schema: import_echo_schema5.S.make(typeLiteral),
|
|
1022
1090
|
path,
|
|
1023
1091
|
readonly,
|
|
1024
1092
|
Custom
|
|
@@ -1257,14 +1325,14 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1257
1325
|
});
|
|
1258
1326
|
};
|
|
1259
1327
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1260
|
-
var ViewMetaSchema =
|
|
1261
|
-
name:
|
|
1262
|
-
[
|
|
1328
|
+
var ViewMetaSchema = import_echo_schema8.S.Struct({
|
|
1329
|
+
name: import_echo_schema8.S.String.annotations({
|
|
1330
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "View"
|
|
1263
1331
|
}),
|
|
1264
|
-
typename:
|
|
1265
|
-
[
|
|
1332
|
+
typename: import_echo_schema8.Format.URL.annotations({
|
|
1333
|
+
[import_echo_schema8.AST.TitleAnnotationId]: "Typename"
|
|
1266
1334
|
})
|
|
1267
|
-
}).pipe(
|
|
1335
|
+
}).pipe(import_echo_schema8.S.mutable);
|
|
1268
1336
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1269
1337
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1270
1338
|
const projection = (0, import_react14.useMemo)(() => new import_schema5.ViewProjection(schema, view), [
|
|
@@ -1331,7 +1399,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1331
1399
|
className: (0, import_react_ui_theme9.mx)(import_react_ui_theme9.inputTextLabel)
|
|
1332
1400
|
}, t("fields label"))), /* @__PURE__ */ import_react14.default.createElement(import_react_ui_list2.List.Root, {
|
|
1333
1401
|
items: view.fields,
|
|
1334
|
-
isItem:
|
|
1402
|
+
isItem: import_echo_schema8.S.is(import_schema5.FieldSchema),
|
|
1335
1403
|
getId: (field2) => field2.id,
|
|
1336
1404
|
onMove: handleMove
|
|
1337
1405
|
}, ({ items: fields }) => /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, showHeading && /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
@@ -1374,7 +1442,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1374
1442
|
}
|
|
1375
1443
|
const parseScalar = (type2) => {
|
|
1376
1444
|
switch (type2) {
|
|
1377
|
-
case
|
|
1445
|
+
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1378
1446
|
if (typeof value === "string") {
|
|
1379
1447
|
const lowercaseValue = value.toLowerCase();
|
|
1380
1448
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1385,13 +1453,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1385
1453
|
}
|
|
1386
1454
|
return Boolean(value);
|
|
1387
1455
|
}
|
|
1388
|
-
case
|
|
1456
|
+
case import_echo_schema9.TypeEnum.Number: {
|
|
1389
1457
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1390
1458
|
const num = Number(cleaned);
|
|
1391
1459
|
return Number.isNaN(num) ? null : num;
|
|
1392
1460
|
}
|
|
1393
|
-
case
|
|
1394
|
-
case
|
|
1461
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1462
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1395
1463
|
return String(value);
|
|
1396
1464
|
default: {
|
|
1397
1465
|
return value;
|
|
@@ -1402,25 +1470,45 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1402
1470
|
return parseScalar(type);
|
|
1403
1471
|
}
|
|
1404
1472
|
switch (format) {
|
|
1405
|
-
case
|
|
1406
|
-
return parseScalar(
|
|
1407
|
-
case
|
|
1408
|
-
case
|
|
1409
|
-
case
|
|
1410
|
-
return parseScalar(
|
|
1411
|
-
case
|
|
1412
|
-
case
|
|
1413
|
-
return parseScalar(
|
|
1473
|
+
case import_echo_schema9.FormatEnum.Boolean:
|
|
1474
|
+
return parseScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1475
|
+
case import_echo_schema9.FormatEnum.Number:
|
|
1476
|
+
case import_echo_schema9.FormatEnum.Percent:
|
|
1477
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1478
|
+
return parseScalar(import_echo_schema9.TypeEnum.Number);
|
|
1479
|
+
case import_echo_schema9.FormatEnum.String:
|
|
1480
|
+
case import_echo_schema9.FormatEnum.Markdown: {
|
|
1481
|
+
return parseScalar(import_echo_schema9.TypeEnum.String);
|
|
1414
1482
|
}
|
|
1415
|
-
case
|
|
1416
|
-
throw new Error(`unexpected format: ${
|
|
1417
|
-
case
|
|
1418
|
-
case
|
|
1419
|
-
case
|
|
1420
|
-
case
|
|
1483
|
+
case import_echo_schema9.FormatEnum.Ref:
|
|
1484
|
+
throw new Error(`unexpected format: ${import_echo_schema9.FormatEnum.Ref}`);
|
|
1485
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1486
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1487
|
+
case import_echo_schema9.FormatEnum.Time:
|
|
1488
|
+
case import_echo_schema9.FormatEnum.Timestamp: {
|
|
1421
1489
|
const date = new Date(value);
|
|
1422
1490
|
return isNaN(date.getTime()) ? null : date;
|
|
1423
1491
|
}
|
|
1492
|
+
case import_echo_schema9.FormatEnum.GeoPoint: {
|
|
1493
|
+
if (typeof value === "string") {
|
|
1494
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1495
|
+
const parts = cleaned.split(",");
|
|
1496
|
+
if (parts.length === 2) {
|
|
1497
|
+
const lat = parseFloat(parts[0]);
|
|
1498
|
+
const long = parseFloat(parts[1]);
|
|
1499
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1500
|
+
return import_echo_schema9.GeoLocation.toGeoPoint({
|
|
1501
|
+
latitude: lat,
|
|
1502
|
+
longitude: long
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return [
|
|
1508
|
+
0,
|
|
1509
|
+
0
|
|
1510
|
+
];
|
|
1511
|
+
}
|
|
1424
1512
|
default: {
|
|
1425
1513
|
return value;
|
|
1426
1514
|
}
|
|
@@ -1429,19 +1517,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1429
1517
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1430
1518
|
if (!format) {
|
|
1431
1519
|
switch (type) {
|
|
1432
|
-
case
|
|
1520
|
+
case import_echo_schema9.TypeEnum.Number:
|
|
1433
1521
|
return [
|
|
1434
1522
|
"text-right",
|
|
1435
1523
|
"font-mono"
|
|
1436
1524
|
];
|
|
1437
|
-
case
|
|
1525
|
+
case import_echo_schema9.TypeEnum.Boolean:
|
|
1438
1526
|
return [
|
|
1439
1527
|
"text-right",
|
|
1440
1528
|
"font-mono"
|
|
1441
1529
|
];
|
|
1442
|
-
case
|
|
1530
|
+
case import_echo_schema9.TypeEnum.String:
|
|
1443
1531
|
return void 0;
|
|
1444
|
-
case
|
|
1532
|
+
case import_echo_schema9.TypeEnum.Ref:
|
|
1445
1533
|
return void 0;
|
|
1446
1534
|
default: {
|
|
1447
1535
|
return void 0;
|
|
@@ -1449,20 +1537,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1449
1537
|
}
|
|
1450
1538
|
}
|
|
1451
1539
|
switch (format) {
|
|
1452
|
-
case
|
|
1540
|
+
case import_echo_schema9.FormatEnum.Markdown:
|
|
1453
1541
|
return void 0;
|
|
1454
|
-
case
|
|
1455
|
-
case
|
|
1456
|
-
case
|
|
1457
|
-
case
|
|
1542
|
+
case import_echo_schema9.FormatEnum.Timestamp:
|
|
1543
|
+
case import_echo_schema9.FormatEnum.DateTime:
|
|
1544
|
+
case import_echo_schema9.FormatEnum.Date:
|
|
1545
|
+
case import_echo_schema9.FormatEnum.Time:
|
|
1458
1546
|
return [
|
|
1459
1547
|
"font-mono"
|
|
1460
1548
|
];
|
|
1461
|
-
case
|
|
1549
|
+
case import_echo_schema9.FormatEnum.Currency:
|
|
1462
1550
|
return [
|
|
1463
1551
|
"text-right"
|
|
1464
1552
|
];
|
|
1465
|
-
case
|
|
1553
|
+
case import_echo_schema9.FormatEnum.JSON:
|
|
1466
1554
|
return [
|
|
1467
1555
|
"font-mono"
|
|
1468
1556
|
];
|
|
@@ -1480,12 +1568,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1480
1568
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1481
1569
|
const formatScalar = (type2) => {
|
|
1482
1570
|
switch (type2) {
|
|
1483
|
-
case
|
|
1571
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1484
1572
|
return value.toLocaleString().toUpperCase();
|
|
1485
|
-
case
|
|
1573
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1486
1574
|
return value.toLocaleString(locale);
|
|
1487
|
-
case
|
|
1488
|
-
case
|
|
1575
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1576
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1489
1577
|
return String(value);
|
|
1490
1578
|
default: {
|
|
1491
1579
|
return String(value);
|
|
@@ -1496,20 +1584,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1496
1584
|
return formatScalar(type);
|
|
1497
1585
|
}
|
|
1498
1586
|
switch (format) {
|
|
1499
|
-
case
|
|
1500
|
-
return formatScalar(
|
|
1587
|
+
case import_echo_schema10.FormatEnum.Boolean: {
|
|
1588
|
+
return formatScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1501
1589
|
}
|
|
1502
|
-
case
|
|
1503
|
-
return formatScalar(
|
|
1590
|
+
case import_echo_schema10.FormatEnum.Number: {
|
|
1591
|
+
return formatScalar(import_echo_schema10.TypeEnum.Number);
|
|
1504
1592
|
}
|
|
1505
|
-
case
|
|
1506
|
-
case
|
|
1507
|
-
return formatScalar(
|
|
1593
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1594
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1595
|
+
return formatScalar(import_echo_schema10.TypeEnum.String);
|
|
1508
1596
|
}
|
|
1509
|
-
case
|
|
1597
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1510
1598
|
return `${value * 100}%`;
|
|
1511
1599
|
}
|
|
1512
|
-
case
|
|
1600
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1513
1601
|
return value.toLocaleString(locale, {
|
|
1514
1602
|
style: "currency",
|
|
1515
1603
|
currency: "USD",
|
|
@@ -1517,18 +1605,28 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1517
1605
|
maximumFractionDigits: 2
|
|
1518
1606
|
});
|
|
1519
1607
|
}
|
|
1520
|
-
case
|
|
1521
|
-
case
|
|
1522
|
-
case
|
|
1608
|
+
case import_echo_schema10.FormatEnum.DateTime:
|
|
1609
|
+
case import_echo_schema10.FormatEnum.Date:
|
|
1610
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1523
1611
|
const date = new Date(value);
|
|
1524
|
-
if (format ===
|
|
1612
|
+
if (format === import_echo_schema10.FormatEnum.DateTime) {
|
|
1525
1613
|
return date.toLocaleString(locale);
|
|
1526
|
-
} else if (format ===
|
|
1614
|
+
} else if (format === import_echo_schema10.FormatEnum.Date) {
|
|
1527
1615
|
return date.toLocaleDateString(locale);
|
|
1528
1616
|
} else {
|
|
1529
1617
|
return date.toLocaleTimeString(locale);
|
|
1530
1618
|
}
|
|
1531
1619
|
}
|
|
1620
|
+
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1621
|
+
if (value === null || value === void 0) {
|
|
1622
|
+
return "";
|
|
1623
|
+
}
|
|
1624
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1625
|
+
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1626
|
+
return `${latitude},${longitude}`;
|
|
1627
|
+
}
|
|
1628
|
+
return String(value);
|
|
1629
|
+
}
|
|
1532
1630
|
default: {
|
|
1533
1631
|
if (value === null || value === "undefined") {
|
|
1534
1632
|
return "";
|
|
@@ -1540,10 +1638,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1540
1638
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1541
1639
|
const formatScalar = (type2) => {
|
|
1542
1640
|
switch (type2) {
|
|
1543
|
-
case
|
|
1544
|
-
case
|
|
1545
|
-
case
|
|
1546
|
-
case
|
|
1641
|
+
case import_echo_schema10.TypeEnum.Boolean:
|
|
1642
|
+
case import_echo_schema10.TypeEnum.Number:
|
|
1643
|
+
case import_echo_schema10.TypeEnum.String:
|
|
1644
|
+
case import_echo_schema10.TypeEnum.Ref:
|
|
1547
1645
|
return String(value);
|
|
1548
1646
|
default:
|
|
1549
1647
|
return String(value);
|
|
@@ -1553,30 +1651,40 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1553
1651
|
return formatScalar(type);
|
|
1554
1652
|
}
|
|
1555
1653
|
switch (format) {
|
|
1556
|
-
case
|
|
1557
|
-
case
|
|
1558
|
-
case
|
|
1559
|
-
case
|
|
1654
|
+
case import_echo_schema10.FormatEnum.Boolean:
|
|
1655
|
+
case import_echo_schema10.FormatEnum.Number:
|
|
1656
|
+
case import_echo_schema10.FormatEnum.String:
|
|
1657
|
+
case import_echo_schema10.FormatEnum.Ref: {
|
|
1560
1658
|
return formatScalar(type);
|
|
1561
1659
|
}
|
|
1562
|
-
case
|
|
1660
|
+
case import_echo_schema10.FormatEnum.Percent: {
|
|
1563
1661
|
return String(value * 100);
|
|
1564
1662
|
}
|
|
1565
|
-
case
|
|
1663
|
+
case import_echo_schema10.FormatEnum.Currency: {
|
|
1566
1664
|
return String(value);
|
|
1567
1665
|
}
|
|
1568
|
-
case
|
|
1666
|
+
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1569
1667
|
const date = new Date(value);
|
|
1570
1668
|
return date.toISOString();
|
|
1571
1669
|
}
|
|
1572
|
-
case
|
|
1670
|
+
case import_echo_schema10.FormatEnum.Date: {
|
|
1573
1671
|
const date = new Date(value);
|
|
1574
1672
|
return date.toISOString().split("T")[0];
|
|
1575
1673
|
}
|
|
1576
|
-
case
|
|
1674
|
+
case import_echo_schema10.FormatEnum.Time: {
|
|
1577
1675
|
const date = new Date(value);
|
|
1578
1676
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1579
1677
|
}
|
|
1678
|
+
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1679
|
+
if (value === null || value === void 0) {
|
|
1680
|
+
return "";
|
|
1681
|
+
}
|
|
1682
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1683
|
+
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1684
|
+
return `${latitude},${longitude}`;
|
|
1685
|
+
}
|
|
1686
|
+
return String(value);
|
|
1687
|
+
}
|
|
1580
1688
|
default: {
|
|
1581
1689
|
return String(value);
|
|
1582
1690
|
}
|