@dxos/react-ui-form 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0
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 +731 -573
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +748 -598
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +731 -573
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +4 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +33 -32
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +3 -3
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +7 -18
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +2 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +2 -2
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +23 -0
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +8 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +9 -0
- package/dist/types/src/util/refs.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +3 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -25
- package/src/components/ControlSection/ControlSection.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +10 -16
- package/src/components/Form/Defaults.tsx +4 -1
- package/src/components/Form/Form.stories.tsx +48 -42
- package/src/components/Form/Form.tsx +4 -4
- package/src/components/Form/FormContent.tsx +49 -22
- package/src/components/Form/FormContext.tsx +3 -1
- package/src/components/Form/Input.tsx +3 -9
- package/src/components/Form/RefField.tsx +147 -101
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +6 -5
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/Form/index.ts +0 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +5 -4
- package/src/components/ViewEditor/ViewEditor.tsx +23 -20
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/hooks/index.ts +3 -1
- package/src/hooks/useForm.ts +4 -3
- package/src/hooks/useQueryRefOptions.ts +53 -0
- package/src/hooks/useRefQueryLookupHandler.ts +41 -0
- package/src/util/index.ts +3 -1
- package/src/util/refs.ts +38 -0
- package/src/util/schema.ts +14 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -54,15 +54,19 @@ __export(node_exports, {
|
|
|
54
54
|
ViewEditor: () => ViewEditor,
|
|
55
55
|
cellClassesForFieldType: () => cellClassesForFieldType,
|
|
56
56
|
controlItemClasses: () => controlItemClasses,
|
|
57
|
+
findArrayElementType: () => findArrayElementType,
|
|
57
58
|
formatForDisplay: () => formatForDisplay,
|
|
58
59
|
formatForEditing: () => formatForEditing,
|
|
60
|
+
getRefProps: () => getRefProps,
|
|
59
61
|
parseValue: () => parseValue,
|
|
60
62
|
pathNotUniqueError: () => pathNotUniqueError,
|
|
61
63
|
translations: () => translations_default,
|
|
62
64
|
useForm: () => useForm,
|
|
63
65
|
useFormContext: () => useFormContext,
|
|
64
66
|
useFormValues: () => useFormValues,
|
|
65
|
-
useInputProps: () => useInputProps
|
|
67
|
+
useInputProps: () => useInputProps,
|
|
68
|
+
useQueryRefOptions: () => useQueryRefOptions,
|
|
69
|
+
useRefQueryLookupHandler: () => useRefQueryLookupHandler
|
|
66
70
|
});
|
|
67
71
|
module.exports = __toCommonJS(node_exports);
|
|
68
72
|
var import_react = __toESM(require("react"));
|
|
@@ -111,40 +115,50 @@ var import_effect3 = require("@dxos/effect");
|
|
|
111
115
|
var import_invariant = require("@dxos/invariant");
|
|
112
116
|
var import_log2 = require("@dxos/log");
|
|
113
117
|
var import_schema2 = require("@dxos/schema");
|
|
118
|
+
var import_react13 = require("react");
|
|
119
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
120
|
+
var import_echo = require("@dxos/react-client/echo");
|
|
121
|
+
var import_util3 = require("@dxos/util");
|
|
122
|
+
var import_react14 = require("react");
|
|
123
|
+
var import_log3 = require("@dxos/log");
|
|
114
124
|
var import_effect4 = require("effect");
|
|
115
125
|
var import_String = require("effect/String");
|
|
116
|
-
var
|
|
117
|
-
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
126
|
+
var import_react15 = __toESM(require("react"));
|
|
118
127
|
var import_effect5 = require("@dxos/effect");
|
|
119
128
|
var import_react_ui_theme8 = require("@dxos/react-ui-theme");
|
|
120
129
|
var import_schema3 = require("@dxos/schema");
|
|
121
|
-
var
|
|
130
|
+
var import_util4 = require("@dxos/util");
|
|
122
131
|
var import_effect6 = require("effect");
|
|
123
132
|
var import_String2 = require("effect/String");
|
|
124
|
-
var
|
|
125
|
-
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
133
|
+
var import_react16 = __toESM(require("react"));
|
|
126
134
|
var import_effect7 = require("@dxos/effect");
|
|
127
135
|
var import_invariant2 = require("@dxos/invariant");
|
|
128
136
|
var import_react_ui10 = require("@dxos/react-ui");
|
|
129
137
|
var import_react_ui_theme9 = require("@dxos/react-ui-theme");
|
|
130
138
|
var import_schema4 = require("@dxos/schema");
|
|
131
|
-
var
|
|
139
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
140
|
+
var import_format = require("date-fns/format");
|
|
132
141
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
133
|
-
var import_effect8 = require("@dxos/effect");
|
|
134
|
-
var import_keys2 = require("@dxos/keys");
|
|
135
|
-
var import_live_object = require("@dxos/live-object");
|
|
136
|
-
var import_log3 = require("@dxos/log");
|
|
137
142
|
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
138
|
-
var
|
|
143
|
+
var import_effect8 = require("@dxos/effect");
|
|
144
|
+
var import_effect9 = require("effect");
|
|
145
|
+
var import_effect10 = require("@dxos/effect");
|
|
146
|
+
var import_react17 = __toESM(require("react"));
|
|
139
147
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
140
|
-
var
|
|
148
|
+
var import_effect11 = require("@dxos/effect");
|
|
149
|
+
var import_keys2 = require("@dxos/keys");
|
|
141
150
|
var import_react_ui11 = require("@dxos/react-ui");
|
|
151
|
+
var import_react_ui_tag_picker = require("@dxos/react-ui-tag-picker");
|
|
152
|
+
var import_util5 = require("@dxos/util");
|
|
153
|
+
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
154
|
+
var import_effect12 = require("effect");
|
|
155
|
+
var import_react18 = __toESM(require("react"));
|
|
156
|
+
var import_echo_schema11 = require("@dxos/echo-schema");
|
|
157
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
158
|
+
var import_react_ui12 = require("@dxos/react-ui");
|
|
142
159
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
143
160
|
var import_react_ui_theme10 = require("@dxos/react-ui-theme");
|
|
144
161
|
var import_schema5 = require("@dxos/schema");
|
|
145
|
-
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
146
|
-
var import_format = require("date-fns/format");
|
|
147
|
-
var import_echo_schema11 = require("@dxos/echo-schema");
|
|
148
162
|
var translationKey = "react-ui-form";
|
|
149
163
|
var translations_default = [
|
|
150
164
|
{
|
|
@@ -319,15 +333,15 @@ var InputHeader = ({ children, error }) => {
|
|
|
319
333
|
return /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
320
334
|
role: "none",
|
|
321
335
|
className: "flex justify-between items-center mb-1"
|
|
322
|
-
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.
|
|
323
|
-
asChild: true
|
|
336
|
+
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Trigger, {
|
|
337
|
+
asChild: true,
|
|
338
|
+
content: error,
|
|
339
|
+
side: "bottom"
|
|
324
340
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
325
341
|
icon: "ph--warning--regular",
|
|
326
342
|
size: 4,
|
|
327
343
|
classNames: import_react_ui_theme3.errorText
|
|
328
|
-
}))
|
|
329
|
-
side: "bottom"
|
|
330
|
-
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Arrow, null), error)));
|
|
344
|
+
})));
|
|
331
345
|
};
|
|
332
346
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
333
347
|
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
@@ -644,23 +658,28 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
|
|
|
644
658
|
};
|
|
645
659
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
646
660
|
const { status, error } = getStatus();
|
|
661
|
+
const value = getValue3();
|
|
662
|
+
const handleValueChange = (0, import_react8.useCallback)((value2) => onValueChange(type, value2), [
|
|
663
|
+
type,
|
|
664
|
+
onValueChange
|
|
665
|
+
]);
|
|
647
666
|
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
648
667
|
validationValence: status
|
|
649
668
|
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
650
669
|
error
|
|
651
670
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Root, {
|
|
652
|
-
value
|
|
653
|
-
onValueChange:
|
|
671
|
+
value,
|
|
672
|
+
onValueChange: handleValueChange
|
|
654
673
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.TriggerButton, {
|
|
655
674
|
classNames: "is-full",
|
|
656
675
|
disabled,
|
|
657
676
|
placeholder
|
|
658
|
-
}), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Portal, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Content, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
677
|
+
}), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Portal, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Content, null, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
659
678
|
// NOTE: Numeric values are converted to and from strings.
|
|
660
679
|
/* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Option, {
|
|
661
|
-
key: String(
|
|
662
|
-
value: String(
|
|
663
|
-
}, label2 ?? String(
|
|
680
|
+
key: String(value2),
|
|
681
|
+
value: String(value2)
|
|
682
|
+
}, label2 ?? String(value2))
|
|
664
683
|
)))))), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.DescriptionAndValidation, null, error));
|
|
665
684
|
};
|
|
666
685
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
@@ -709,7 +728,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
709
728
|
L: 93,
|
|
710
729
|
S: void 0,
|
|
711
730
|
A: [
|
|
712
|
-
"
|
|
731
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
713
732
|
""
|
|
714
733
|
]
|
|
715
734
|
});
|
|
@@ -810,7 +829,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
810
829
|
} catch (err) {
|
|
811
830
|
import_log2.log.catch(err, void 0, {
|
|
812
831
|
F: __dxlog_file,
|
|
813
|
-
L:
|
|
832
|
+
L: 213,
|
|
814
833
|
S: void 0,
|
|
815
834
|
C: (f, a) => f(...a)
|
|
816
835
|
});
|
|
@@ -881,7 +900,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
881
900
|
var createKeySet = (obj, value) => {
|
|
882
901
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
883
902
|
F: __dxlog_file,
|
|
884
|
-
L:
|
|
903
|
+
L: 275,
|
|
885
904
|
S: void 0,
|
|
886
905
|
A: [
|
|
887
906
|
"obj",
|
|
@@ -902,6 +921,71 @@ var flatMap = (errors) => {
|
|
|
902
921
|
return result;
|
|
903
922
|
}, {});
|
|
904
923
|
};
|
|
924
|
+
var useRefQueryLookupHandler = ({ space }) => {
|
|
925
|
+
const handleRefQueryLookup = (0, import_react13.useCallback)(async (typeInfo) => {
|
|
926
|
+
if (!space) {
|
|
927
|
+
return [];
|
|
928
|
+
}
|
|
929
|
+
const query = space.db.query(import_echo.Filter.typename(typeInfo.typename));
|
|
930
|
+
const { objects } = await query.run();
|
|
931
|
+
return objects.map((object) => {
|
|
932
|
+
const dxn = (0, import_echo_schema5.getDXN)(object);
|
|
933
|
+
if (!dxn) {
|
|
934
|
+
return void 0;
|
|
935
|
+
}
|
|
936
|
+
const item = {
|
|
937
|
+
dxn,
|
|
938
|
+
label: object?.name ?? object?.id ?? ""
|
|
939
|
+
};
|
|
940
|
+
return item;
|
|
941
|
+
}).filter(import_util3.isNonNullable);
|
|
942
|
+
}, [
|
|
943
|
+
space
|
|
944
|
+
]);
|
|
945
|
+
return handleRefQueryLookup;
|
|
946
|
+
};
|
|
947
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
948
|
+
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
949
|
+
const [options, setOptions] = (0, import_react14.useState)([]);
|
|
950
|
+
const [loading, setLoading] = (0, import_react14.useState)(false);
|
|
951
|
+
(0, import_react14.useEffect)(() => {
|
|
952
|
+
if (!refTypeInfo || !onQueryRefOptions) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const fetchOptions = async () => {
|
|
956
|
+
setLoading(true);
|
|
957
|
+
try {
|
|
958
|
+
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
959
|
+
setOptions(fetchedOptions.map((option) => {
|
|
960
|
+
const dxn = option.dxn.toString();
|
|
961
|
+
return {
|
|
962
|
+
id: dxn,
|
|
963
|
+
label: option.label ?? dxn,
|
|
964
|
+
hue: "neutral"
|
|
965
|
+
};
|
|
966
|
+
}));
|
|
967
|
+
} catch (error) {
|
|
968
|
+
import_log3.log.error("Failed to fetch ref options:", error, {
|
|
969
|
+
F: __dxlog_file2,
|
|
970
|
+
L: 42,
|
|
971
|
+
S: void 0,
|
|
972
|
+
C: (f, a) => f(...a)
|
|
973
|
+
});
|
|
974
|
+
setOptions([]);
|
|
975
|
+
} finally {
|
|
976
|
+
setLoading(false);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
void fetchOptions();
|
|
980
|
+
}, [
|
|
981
|
+
refTypeInfo,
|
|
982
|
+
onQueryRefOptions
|
|
983
|
+
]);
|
|
984
|
+
return {
|
|
985
|
+
options,
|
|
986
|
+
loading
|
|
987
|
+
};
|
|
988
|
+
};
|
|
905
989
|
var FormContext = /* @__PURE__ */ (0, import_react11.createContext)(void 0);
|
|
906
990
|
var useFormContext = () => {
|
|
907
991
|
return (0, import_react11.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
@@ -939,7 +1023,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
939
1023
|
const keyIsEnter = event.key === "Enter";
|
|
940
1024
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
941
1025
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
942
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
1026
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
943
1027
|
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
944
1028
|
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
945
1029
|
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
@@ -988,234 +1072,551 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
988
1072
|
onClick: handleSave
|
|
989
1073
|
})));
|
|
990
1074
|
};
|
|
991
|
-
var
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
995
|
-
const { ast, name, type, title } = property;
|
|
996
|
-
const values = useFormValues(path ?? []) ?? [];
|
|
997
|
-
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
998
|
-
F: __dxlog_file2,
|
|
999
|
-
L: 39,
|
|
1000
|
-
S: void 0,
|
|
1001
|
-
A: [
|
|
1002
|
-
"Array.isArray(values)",
|
|
1003
|
-
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1004
|
-
]
|
|
1005
|
-
});
|
|
1006
|
-
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
1007
|
-
const tupleType = (0, import_effect7.findNode)(ast, import_echo_schema6.AST.isTupleType);
|
|
1008
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
1009
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
1010
|
-
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
1011
|
-
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_echo_schema6.AST.isTypeLiteral);
|
|
1012
|
-
if (!typeLiteral) {
|
|
1013
|
-
return {};
|
|
1014
|
-
}
|
|
1015
|
-
return Object.fromEntries((0, import_schema4.getSchemaProperties)(typeLiteral, {}).map((prop) => [
|
|
1016
|
-
prop.name,
|
|
1017
|
-
prop.defaultValue
|
|
1018
|
-
]));
|
|
1019
|
-
};
|
|
1020
|
-
const newValue = (0, import_react14.useMemo)(() => {
|
|
1021
|
-
if (type === "object" && elementType) {
|
|
1022
|
-
return getDefaultObjectValue(elementType);
|
|
1023
|
-
} else {
|
|
1024
|
-
return import_effect7.SimpleType.getDefaultValue(type);
|
|
1025
|
-
}
|
|
1026
|
-
}, [
|
|
1027
|
-
type,
|
|
1028
|
-
elementType
|
|
1029
|
-
]);
|
|
1030
|
-
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
1031
|
-
inputProps.onValueChange(type, [
|
|
1032
|
-
...values,
|
|
1033
|
-
newValue
|
|
1034
|
-
]);
|
|
1035
|
-
}, [
|
|
1036
|
-
type,
|
|
1037
|
-
elementType,
|
|
1038
|
-
inputProps,
|
|
1039
|
-
newValue,
|
|
1040
|
-
values
|
|
1041
|
-
]);
|
|
1042
|
-
const handleRemove = (0, import_react14.useCallback)((index) => {
|
|
1043
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
1044
|
-
inputProps.onValueChange(type, newValues);
|
|
1045
|
-
}, [
|
|
1046
|
-
type,
|
|
1047
|
-
inputProps,
|
|
1048
|
-
values
|
|
1049
|
-
]);
|
|
1050
|
-
if (!elementType) {
|
|
1051
|
-
return null;
|
|
1052
|
-
}
|
|
1053
|
-
return /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1054
|
-
role: "none",
|
|
1055
|
-
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1056
|
-
}, /* @__PURE__ */ import_react14.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1057
|
-
role: "none",
|
|
1058
|
-
className: "flex flex-col gap-1"
|
|
1059
|
-
}, values.map((_value, index) => /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1060
|
-
key: index,
|
|
1061
|
-
role: "none",
|
|
1062
|
-
className: "flex items-center gap-1"
|
|
1063
|
-
}, /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1064
|
-
role: "none",
|
|
1065
|
-
className: "flex-1"
|
|
1066
|
-
}, /* @__PURE__ */ import_react14.default.createElement(FormField, {
|
|
1067
|
-
property: {
|
|
1068
|
-
...property,
|
|
1069
|
-
array: false,
|
|
1070
|
-
ast: elementType
|
|
1071
|
-
},
|
|
1072
|
-
path: [
|
|
1073
|
-
...path ?? [],
|
|
1074
|
-
index
|
|
1075
|
-
],
|
|
1076
|
-
readonly,
|
|
1077
|
-
inline: true,
|
|
1078
|
-
Custom,
|
|
1079
|
-
lookupComponent
|
|
1080
|
-
})), /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1081
|
-
icon: "ph--trash--regular",
|
|
1082
|
-
iconOnly: true,
|
|
1083
|
-
label: t("button remove"),
|
|
1084
|
-
onClick: () => handleRemove(index)
|
|
1085
|
-
})))), /* @__PURE__ */ import_react14.default.createElement("div", {
|
|
1086
|
-
role: "none",
|
|
1087
|
-
className: "flex justify-between items-center plb-1"
|
|
1088
|
-
}, /* @__PURE__ */ import_react14.default.createElement(import_react_ui10.IconButton, {
|
|
1089
|
-
icon: "ph--plus--regular",
|
|
1090
|
-
iconOnly: true,
|
|
1091
|
-
label: t("button add"),
|
|
1092
|
-
onClick: handleAdd
|
|
1093
|
-
})));
|
|
1094
|
-
};
|
|
1095
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/RefField.tsx";
|
|
1096
|
-
var RefField = ({ ast, type, label, readonly, placeholder, inline, onQueryRefOptions, inputProps }) => {
|
|
1097
|
-
const { getValue: getValue3, onValueChange, ...restInputProps } = inputProps;
|
|
1098
|
-
const refTypeInfo = (0, import_effect8.findAnnotation)(ast, import_echo_schema7.ReferenceAnnotationId);
|
|
1099
|
-
const [refOptions, setRefOptions] = (0, import_react15.useState)([]);
|
|
1100
|
-
const [loading, setLoading] = (0, import_react15.useState)(false);
|
|
1101
|
-
(0, import_react15.useEffect)(() => {
|
|
1102
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
const fetchOptions = async () => {
|
|
1106
|
-
setLoading(true);
|
|
1107
|
-
try {
|
|
1108
|
-
const options = await onQueryRefOptions(refTypeInfo);
|
|
1109
|
-
setRefOptions(options.map((option) => ({
|
|
1110
|
-
label: option.label,
|
|
1111
|
-
value: option.dxn.toString()
|
|
1112
|
-
})));
|
|
1113
|
-
} catch (error) {
|
|
1114
|
-
import_log3.log.error("Failed to fetch ref options:", error, {
|
|
1115
|
-
F: __dxlog_file3,
|
|
1116
|
-
L: 68,
|
|
1117
|
-
S: void 0,
|
|
1118
|
-
C: (f, a) => f(...a)
|
|
1119
|
-
});
|
|
1120
|
-
setRefOptions([]);
|
|
1121
|
-
} finally {
|
|
1122
|
-
setLoading(false);
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
void fetchOptions();
|
|
1126
|
-
}, [
|
|
1127
|
-
refTypeInfo,
|
|
1128
|
-
onQueryRefOptions
|
|
1129
|
-
]);
|
|
1130
|
-
if (!refTypeInfo) {
|
|
1131
|
-
return null;
|
|
1075
|
+
var parseValue = ({ type, format, value }) => {
|
|
1076
|
+
if (value === void 0 || value === null || value === "") {
|
|
1077
|
+
return void 0;
|
|
1132
1078
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1079
|
+
const parseScalar = (type2) => {
|
|
1080
|
+
switch (type2) {
|
|
1081
|
+
case import_echo_schema6.TypeEnum.Boolean: {
|
|
1082
|
+
if (typeof value === "string") {
|
|
1083
|
+
const lowercaseValue = value.toLowerCase();
|
|
1084
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1085
|
+
return false;
|
|
1086
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return Boolean(value);
|
|
1142
1091
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
return formValue;
|
|
1092
|
+
case import_echo_schema6.TypeEnum.Number: {
|
|
1093
|
+
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1094
|
+
const num = Number(cleaned);
|
|
1095
|
+
return Number.isNaN(num) ? null : num;
|
|
1148
1096
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1097
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1098
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1099
|
+
return String(value);
|
|
1100
|
+
default: {
|
|
1101
|
+
return value;
|
|
1151
1102
|
}
|
|
1152
|
-
return void 0;
|
|
1153
|
-
};
|
|
1154
|
-
return /* @__PURE__ */ import_react15.default.createElement(TextInput, {
|
|
1155
|
-
type,
|
|
1156
|
-
label,
|
|
1157
|
-
disabled: readonly,
|
|
1158
|
-
placeholder,
|
|
1159
|
-
inputOnly: inline,
|
|
1160
|
-
getValue: handleGetValue2,
|
|
1161
|
-
onValueChange: handleOnValueChange,
|
|
1162
|
-
...restInputProps
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
const handleGetValue = () => {
|
|
1166
|
-
const formValue = getValue3();
|
|
1167
|
-
if (formValue instanceof import_live_object.RefImpl) {
|
|
1168
|
-
return formValue.dxn.toString();
|
|
1169
1103
|
}
|
|
1170
|
-
return void 0;
|
|
1171
1104
|
};
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
const ref = (0, import_live_object.refFromDXN)(dxn);
|
|
1175
|
-
onValueChange("object", ref);
|
|
1176
|
-
};
|
|
1177
|
-
return /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1178
|
-
type,
|
|
1179
|
-
label,
|
|
1180
|
-
disabled: readonly || loading,
|
|
1181
|
-
placeholder: loading ? "Loading options..." : placeholder,
|
|
1182
|
-
inputOnly: inline,
|
|
1183
|
-
getValue: handleGetValue,
|
|
1184
|
-
onValueChange: handleValueChanged,
|
|
1185
|
-
options: refOptions,
|
|
1186
|
-
...restInputProps
|
|
1187
|
-
});
|
|
1188
|
-
};
|
|
1189
|
-
var getInputComponent = (type, format) => {
|
|
1190
|
-
switch (format) {
|
|
1191
|
-
case import_echo_schema8.FormatEnum.GeoPoint:
|
|
1192
|
-
return GeoPointInput;
|
|
1193
|
-
case import_echo_schema8.FormatEnum.Markdown:
|
|
1194
|
-
return MarkdownInput;
|
|
1105
|
+
if (!format) {
|
|
1106
|
+
return parseScalar(type);
|
|
1195
1107
|
}
|
|
1196
|
-
switch (
|
|
1197
|
-
case
|
|
1198
|
-
return
|
|
1199
|
-
case
|
|
1200
|
-
|
|
1201
|
-
case
|
|
1202
|
-
return
|
|
1108
|
+
switch (format) {
|
|
1109
|
+
case import_echo_schema6.FormatEnum.Boolean:
|
|
1110
|
+
return parseScalar(import_echo_schema6.TypeEnum.Boolean);
|
|
1111
|
+
case import_echo_schema6.FormatEnum.Number:
|
|
1112
|
+
case import_echo_schema6.FormatEnum.Percent:
|
|
1113
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1114
|
+
return parseScalar(import_echo_schema6.TypeEnum.Number);
|
|
1115
|
+
case import_echo_schema6.FormatEnum.String:
|
|
1116
|
+
case import_echo_schema6.FormatEnum.Markdown: {
|
|
1117
|
+
return parseScalar(import_echo_schema6.TypeEnum.String);
|
|
1118
|
+
}
|
|
1119
|
+
case import_echo_schema6.FormatEnum.Ref:
|
|
1120
|
+
throw new Error(`unexpected format: ${import_echo_schema6.FormatEnum.Ref}`);
|
|
1121
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1122
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1123
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1124
|
+
case import_echo_schema6.FormatEnum.Timestamp: {
|
|
1125
|
+
const date = new Date(value);
|
|
1126
|
+
return isNaN(date.getTime()) ? null : date;
|
|
1127
|
+
}
|
|
1128
|
+
case import_echo_schema6.FormatEnum.GeoPoint: {
|
|
1129
|
+
if (typeof value === "string") {
|
|
1130
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1131
|
+
const parts = cleaned.split(",");
|
|
1132
|
+
if (parts.length === 2) {
|
|
1133
|
+
const lat = parseFloat(parts[0]);
|
|
1134
|
+
const long = parseFloat(parts[1]);
|
|
1135
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1136
|
+
return import_echo_schema6.GeoLocation.toGeoPoint({
|
|
1137
|
+
latitude: lat,
|
|
1138
|
+
longitude: long
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return [
|
|
1144
|
+
0,
|
|
1145
|
+
0
|
|
1146
|
+
];
|
|
1147
|
+
}
|
|
1148
|
+
default: {
|
|
1149
|
+
return value;
|
|
1150
|
+
}
|
|
1203
1151
|
}
|
|
1204
1152
|
};
|
|
1205
|
-
var
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1153
|
+
var cellClassesForFieldType = ({ type, format }) => {
|
|
1154
|
+
if (!format) {
|
|
1155
|
+
switch (type) {
|
|
1156
|
+
case import_echo_schema6.TypeEnum.Number:
|
|
1157
|
+
return [
|
|
1158
|
+
"text-right",
|
|
1159
|
+
"font-mono"
|
|
1160
|
+
];
|
|
1161
|
+
case import_echo_schema6.TypeEnum.Boolean:
|
|
1162
|
+
return [
|
|
1163
|
+
"text-right",
|
|
1164
|
+
"font-mono"
|
|
1165
|
+
];
|
|
1166
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1167
|
+
return void 0;
|
|
1168
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1169
|
+
return void 0;
|
|
1170
|
+
default: {
|
|
1171
|
+
return void 0;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
switch (format) {
|
|
1176
|
+
case import_echo_schema6.FormatEnum.Markdown:
|
|
1177
|
+
return void 0;
|
|
1178
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1179
|
+
case import_echo_schema6.FormatEnum.Timestamp:
|
|
1180
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1181
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1182
|
+
case import_echo_schema6.FormatEnum.Duration:
|
|
1183
|
+
return [
|
|
1184
|
+
"font-mono",
|
|
1185
|
+
"text-right"
|
|
1186
|
+
];
|
|
1187
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1188
|
+
return [
|
|
1189
|
+
"text-right"
|
|
1190
|
+
];
|
|
1191
|
+
case import_echo_schema6.FormatEnum.JSON:
|
|
1192
|
+
case import_echo_schema6.FormatEnum.DID:
|
|
1193
|
+
return [
|
|
1194
|
+
"font-mono"
|
|
1195
|
+
];
|
|
1196
|
+
default:
|
|
1197
|
+
return void 0;
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
var pathNotUniqueError = (path) => ({
|
|
1201
|
+
path: "path",
|
|
1202
|
+
message: `'${path}' is already present`
|
|
1203
|
+
});
|
|
1204
|
+
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1205
|
+
const formatScalar = (type2) => {
|
|
1206
|
+
switch (type2) {
|
|
1207
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1208
|
+
return value.toLocaleString().toUpperCase();
|
|
1209
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1210
|
+
return value.toLocaleString(locale);
|
|
1211
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1212
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1213
|
+
return String(value);
|
|
1214
|
+
default: {
|
|
1215
|
+
return String(value);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
if (!format) {
|
|
1220
|
+
return formatScalar(type);
|
|
1221
|
+
}
|
|
1222
|
+
switch (format) {
|
|
1223
|
+
case import_echo_schema7.FormatEnum.Boolean: {
|
|
1224
|
+
return formatScalar(import_echo_schema7.TypeEnum.Boolean);
|
|
1225
|
+
}
|
|
1226
|
+
case import_echo_schema7.FormatEnum.Number: {
|
|
1227
|
+
return formatScalar(import_echo_schema7.TypeEnum.Number);
|
|
1228
|
+
}
|
|
1229
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1230
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1231
|
+
return formatScalar(import_echo_schema7.TypeEnum.String);
|
|
1232
|
+
}
|
|
1233
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1234
|
+
return `${value * 100}%`;
|
|
1235
|
+
}
|
|
1236
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1237
|
+
return value.toLocaleString(locale, {
|
|
1238
|
+
style: "currency",
|
|
1239
|
+
currency: "USD",
|
|
1240
|
+
minimumFractionDigits: 2,
|
|
1241
|
+
maximumFractionDigits: 2
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1245
|
+
try {
|
|
1246
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
return "Invalid Date";
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1252
|
+
try {
|
|
1253
|
+
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1254
|
+
} catch (error) {
|
|
1255
|
+
return "Invalid Time";
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1259
|
+
try {
|
|
1260
|
+
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
return "Invalid DateTime";
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
case import_echo_schema7.FormatEnum.GeoPoint: {
|
|
1266
|
+
if (value === null || value === void 0) {
|
|
1267
|
+
return "";
|
|
1268
|
+
}
|
|
1269
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1270
|
+
const { latitude, longitude } = import_echo_schema7.GeoLocation.fromGeoPoint(value);
|
|
1271
|
+
return `${latitude},${longitude}`;
|
|
1272
|
+
}
|
|
1273
|
+
return String(value);
|
|
1274
|
+
}
|
|
1275
|
+
default: {
|
|
1276
|
+
if (value === null || value === "undefined") {
|
|
1277
|
+
return "";
|
|
1278
|
+
}
|
|
1279
|
+
return String(value);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1284
|
+
const formatScalar = (type2) => {
|
|
1285
|
+
switch (type2) {
|
|
1286
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1287
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1288
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1289
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1290
|
+
return String(value);
|
|
1291
|
+
default:
|
|
1292
|
+
return String(value);
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
if (!format) {
|
|
1296
|
+
return formatScalar(type);
|
|
1297
|
+
}
|
|
1298
|
+
switch (format) {
|
|
1299
|
+
case import_echo_schema7.FormatEnum.Boolean:
|
|
1300
|
+
case import_echo_schema7.FormatEnum.Number:
|
|
1301
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1302
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1303
|
+
return formatScalar(type);
|
|
1304
|
+
}
|
|
1305
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1306
|
+
return String(value * 100);
|
|
1307
|
+
}
|
|
1308
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1309
|
+
return String(value);
|
|
1310
|
+
}
|
|
1311
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1312
|
+
const date = new Date(value);
|
|
1313
|
+
return date.toISOString();
|
|
1314
|
+
}
|
|
1315
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1316
|
+
const date = new Date(value);
|
|
1317
|
+
return date.toISOString().split("T")[0];
|
|
1318
|
+
}
|
|
1319
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1320
|
+
const date = new Date(value);
|
|
1321
|
+
return date.toISOString().split("T")[1].split(".")[0];
|
|
1322
|
+
}
|
|
1323
|
+
case import_echo_schema7.FormatEnum.GeoPoint: {
|
|
1324
|
+
if (value === null || value === void 0) {
|
|
1325
|
+
return "";
|
|
1326
|
+
}
|
|
1327
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1328
|
+
const { latitude, longitude } = import_echo_schema7.GeoLocation.fromGeoPoint(value);
|
|
1329
|
+
return `${latitude},${longitude}`;
|
|
1330
|
+
}
|
|
1331
|
+
return String(value);
|
|
1332
|
+
}
|
|
1333
|
+
default: {
|
|
1334
|
+
return String(value);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
var findArrayElementType = (ast) => {
|
|
1339
|
+
const tupleType = (0, import_effect10.findNode)(ast, import_effect9.SchemaAST.isTupleType);
|
|
1340
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
1341
|
+
return elementType;
|
|
1342
|
+
};
|
|
1343
|
+
var getRefProps = (property) => {
|
|
1344
|
+
const { ast, format, array } = property;
|
|
1345
|
+
if (format === import_echo_schema8.FormatEnum.Ref) {
|
|
1346
|
+
return {
|
|
1347
|
+
ast,
|
|
1348
|
+
isArray: false
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
if (array) {
|
|
1352
|
+
const elementType = findArrayElementType(ast);
|
|
1353
|
+
if (elementType) {
|
|
1354
|
+
const annotation = (0, import_effect8.findAnnotation)(elementType, import_echo_schema8.ReferenceAnnotationId);
|
|
1355
|
+
if (annotation) {
|
|
1356
|
+
return {
|
|
1357
|
+
ast: elementType,
|
|
1358
|
+
isArray: true
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
return void 0;
|
|
1364
|
+
};
|
|
1365
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
1366
|
+
var padding = "px-2";
|
|
1367
|
+
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1368
|
+
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
1369
|
+
const { ast, name, type, title } = property;
|
|
1370
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
1371
|
+
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1372
|
+
F: __dxlog_file3,
|
|
1373
|
+
L: 39,
|
|
1374
|
+
S: void 0,
|
|
1375
|
+
A: [
|
|
1376
|
+
"Array.isArray(values)",
|
|
1377
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1378
|
+
]
|
|
1379
|
+
});
|
|
1380
|
+
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
1381
|
+
const elementType = findArrayElementType(ast);
|
|
1382
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1383
|
+
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
1384
|
+
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_effect6.SchemaAST.isTypeLiteral);
|
|
1385
|
+
if (!typeLiteral) {
|
|
1386
|
+
return {};
|
|
1387
|
+
}
|
|
1388
|
+
return Object.fromEntries((0, import_schema4.getSchemaProperties)(typeLiteral, {}).map((prop) => [
|
|
1389
|
+
prop.name,
|
|
1390
|
+
prop.defaultValue
|
|
1391
|
+
]));
|
|
1392
|
+
};
|
|
1393
|
+
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : import_effect7.SimpleType.getDefaultValue(type);
|
|
1394
|
+
const handleAdd = (0, import_react16.useCallback)(() => {
|
|
1395
|
+
inputProps.onValueChange(type, [
|
|
1396
|
+
...values,
|
|
1397
|
+
getDefaultValue()
|
|
1398
|
+
]);
|
|
1399
|
+
}, [
|
|
1400
|
+
type,
|
|
1401
|
+
elementType,
|
|
1402
|
+
inputProps,
|
|
1403
|
+
values
|
|
1404
|
+
]);
|
|
1405
|
+
const handleRemove = (0, import_react16.useCallback)((index) => {
|
|
1406
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
1407
|
+
inputProps.onValueChange(type, newValues);
|
|
1408
|
+
}, [
|
|
1409
|
+
type,
|
|
1410
|
+
inputProps,
|
|
1411
|
+
values
|
|
1412
|
+
]);
|
|
1413
|
+
if (!elementType) {
|
|
1414
|
+
return null;
|
|
1415
|
+
}
|
|
1416
|
+
return /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1417
|
+
role: "none",
|
|
1418
|
+
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1419
|
+
}, /* @__PURE__ */ import_react16.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1420
|
+
role: "none",
|
|
1421
|
+
className: "flex flex-col gap-1"
|
|
1422
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1423
|
+
key: index,
|
|
1424
|
+
role: "none",
|
|
1425
|
+
className: "flex items-center gap-1"
|
|
1426
|
+
}, /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1427
|
+
role: "none",
|
|
1428
|
+
className: "flex-1"
|
|
1429
|
+
}, /* @__PURE__ */ import_react16.default.createElement(FormField, {
|
|
1430
|
+
property: {
|
|
1431
|
+
...property,
|
|
1432
|
+
array: false,
|
|
1433
|
+
ast: elementType
|
|
1434
|
+
},
|
|
1435
|
+
path: [
|
|
1436
|
+
...path ?? [],
|
|
1437
|
+
index
|
|
1438
|
+
],
|
|
1439
|
+
readonly,
|
|
1440
|
+
inline: true,
|
|
1441
|
+
Custom,
|
|
1442
|
+
lookupComponent
|
|
1443
|
+
})), /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1444
|
+
icon: "ph--trash--regular",
|
|
1445
|
+
iconOnly: true,
|
|
1446
|
+
label: t("button remove"),
|
|
1447
|
+
onClick: () => handleRemove(index)
|
|
1448
|
+
})))), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1449
|
+
role: "none",
|
|
1450
|
+
className: "flex justify-between items-center plb-1"
|
|
1451
|
+
}, /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1452
|
+
icon: "ph--plus--regular",
|
|
1453
|
+
iconOnly: true,
|
|
1454
|
+
label: t("button add"),
|
|
1455
|
+
onClick: handleAdd
|
|
1456
|
+
})));
|
|
1457
|
+
};
|
|
1458
|
+
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1459
|
+
const refTypeInfo = (0, import_react17.useMemo)(() => ast ? (0, import_effect11.findAnnotation)(ast, import_echo_schema9.ReferenceAnnotationId) : void 0, [
|
|
1460
|
+
ast
|
|
1461
|
+
]);
|
|
1462
|
+
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1463
|
+
refTypeInfo,
|
|
1464
|
+
onQueryRefOptions
|
|
1465
|
+
});
|
|
1466
|
+
if (refTypeInfo && refTypeInfo?.typename === (0, import_echo_schema9.getTypeAnnotation)(import_echo_schema9.Expando)?.typename || !onQueryRefOptions) {
|
|
1467
|
+
return /* @__PURE__ */ import_react17.default.createElement(RefFieldFallback, {
|
|
1468
|
+
type,
|
|
1469
|
+
label,
|
|
1470
|
+
placeholder,
|
|
1471
|
+
disabled,
|
|
1472
|
+
inputOnly,
|
|
1473
|
+
getValue: getValue3,
|
|
1474
|
+
onBlur,
|
|
1475
|
+
onValueChange,
|
|
1476
|
+
...restInputProps
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
const handleGetValue = (0, import_react17.useCallback)(() => {
|
|
1480
|
+
const formValue = getValue3();
|
|
1481
|
+
const unknownToRefOption = (val) => {
|
|
1482
|
+
if (import_echo_schema9.Ref.isRef(val)) {
|
|
1483
|
+
const dxnString = val.dxn.toString();
|
|
1484
|
+
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1485
|
+
if (matchingOption) {
|
|
1486
|
+
return matchingOption;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return void 0;
|
|
1490
|
+
};
|
|
1491
|
+
if (array && Array.isArray(formValue)) {
|
|
1492
|
+
return formValue.map(unknownToRefOption).filter(import_util5.isNonNullable) ?? [];
|
|
1493
|
+
}
|
|
1494
|
+
const option = unknownToRefOption(formValue);
|
|
1495
|
+
if (option) {
|
|
1496
|
+
return [
|
|
1497
|
+
option
|
|
1498
|
+
];
|
|
1499
|
+
}
|
|
1500
|
+
return [];
|
|
1501
|
+
}, [
|
|
1502
|
+
getValue3,
|
|
1503
|
+
availableOptions,
|
|
1504
|
+
array
|
|
1505
|
+
]);
|
|
1506
|
+
const handleSearch = (0, import_react17.useCallback)((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1507
|
+
id: option.id,
|
|
1508
|
+
label: option.label,
|
|
1509
|
+
hue: option.hue
|
|
1510
|
+
})), [
|
|
1511
|
+
availableOptions
|
|
1512
|
+
]);
|
|
1513
|
+
const handleUpdate = (0, import_react17.useCallback)((ids) => {
|
|
1514
|
+
if (ids.length === 0) {
|
|
1515
|
+
onValueChange("object", void 0);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
const refs = ids.map((id) => {
|
|
1519
|
+
const item = availableOptions.find((option) => option.id === id);
|
|
1520
|
+
if (item) {
|
|
1521
|
+
const dxn = import_keys2.DXN.parse(item.id);
|
|
1522
|
+
return import_echo_schema9.Ref.fromDXN(dxn);
|
|
1523
|
+
}
|
|
1524
|
+
return null;
|
|
1525
|
+
}).filter(import_util5.isNonNullable);
|
|
1526
|
+
if (array) {
|
|
1527
|
+
onValueChange("object", refs);
|
|
1528
|
+
} else {
|
|
1529
|
+
onValueChange("object", refs[0]);
|
|
1530
|
+
}
|
|
1531
|
+
}, [
|
|
1532
|
+
availableOptions,
|
|
1533
|
+
array,
|
|
1534
|
+
onValueChange
|
|
1535
|
+
]);
|
|
1536
|
+
const tagPickerMode = (0, import_react17.useMemo)(() => array ? "multi-select" : "single-select", [
|
|
1537
|
+
array
|
|
1538
|
+
]);
|
|
1539
|
+
if (!refTypeInfo) {
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
const { status, error } = restInputProps.getStatus();
|
|
1543
|
+
return /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Root, {
|
|
1544
|
+
validationValence: status
|
|
1545
|
+
}, !inputOnly && /* @__PURE__ */ import_react17.default.createElement(InputHeader, {
|
|
1546
|
+
error
|
|
1547
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Label, null, label)), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1548
|
+
"data-no-submit": true
|
|
1549
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui_tag_picker.TagPicker, {
|
|
1550
|
+
items: handleGetValue(),
|
|
1551
|
+
mode: tagPickerMode,
|
|
1552
|
+
onBlur: (event) => onBlur(event),
|
|
1553
|
+
onUpdate: handleUpdate,
|
|
1554
|
+
onSearch: handleSearch,
|
|
1555
|
+
classNames: "rounded-sm bg-input p-1.5"
|
|
1556
|
+
})), inputOnly && /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.DescriptionAndValidation, null, error));
|
|
1557
|
+
};
|
|
1558
|
+
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1559
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1560
|
+
const dxn = import_keys2.DXN.tryParse(dxnString);
|
|
1561
|
+
if (dxn) {
|
|
1562
|
+
onValueChange?.("object", import_echo_schema9.Ref.fromDXN(dxn));
|
|
1563
|
+
} else if (dxnString === "") {
|
|
1564
|
+
onValueChange?.("object", void 0);
|
|
1565
|
+
} else {
|
|
1566
|
+
onValueChange?.("string", dxnString);
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
const handleGetValue = () => {
|
|
1570
|
+
const formValue = getValue3();
|
|
1571
|
+
if (typeof formValue === "string") {
|
|
1572
|
+
return formValue;
|
|
1573
|
+
}
|
|
1574
|
+
if (import_echo_schema9.Ref.isRef(formValue)) {
|
|
1575
|
+
return formValue.dxn.toString();
|
|
1576
|
+
}
|
|
1577
|
+
return void 0;
|
|
1578
|
+
};
|
|
1579
|
+
return /* @__PURE__ */ import_react17.default.createElement(TextInput, {
|
|
1580
|
+
type,
|
|
1581
|
+
label,
|
|
1582
|
+
disabled,
|
|
1583
|
+
placeholder,
|
|
1584
|
+
inputOnly,
|
|
1585
|
+
getValue: handleGetValue,
|
|
1586
|
+
onValueChange: handleOnValueChange,
|
|
1587
|
+
...restInputProps
|
|
1588
|
+
});
|
|
1589
|
+
};
|
|
1590
|
+
var getInputComponent = (type, format) => {
|
|
1591
|
+
switch (format) {
|
|
1592
|
+
case import_echo_schema10.FormatEnum.GeoPoint:
|
|
1593
|
+
return GeoPointInput;
|
|
1594
|
+
case import_echo_schema10.FormatEnum.Markdown:
|
|
1595
|
+
return MarkdownInput;
|
|
1596
|
+
}
|
|
1597
|
+
switch (type) {
|
|
1598
|
+
case "string":
|
|
1599
|
+
return TextInput;
|
|
1600
|
+
case "number":
|
|
1601
|
+
return NumberInput;
|
|
1602
|
+
case "boolean":
|
|
1603
|
+
return BooleanInput;
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1607
|
+
const inputProps = useInputProps(path);
|
|
1608
|
+
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1609
|
+
const label = (0, import_react15.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1610
|
+
title,
|
|
1611
|
+
name
|
|
1612
|
+
]);
|
|
1613
|
+
const placeholder = (0, import_react15.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1614
|
+
examples,
|
|
1615
|
+
description
|
|
1616
|
+
]);
|
|
1617
|
+
const FoundComponent = lookupComponent?.({
|
|
1217
1618
|
prop: name,
|
|
1218
|
-
schema:
|
|
1619
|
+
schema: import_effect4.Schema.make(ast),
|
|
1219
1620
|
inputProps: {
|
|
1220
1621
|
type,
|
|
1221
1622
|
format,
|
|
@@ -1226,14 +1627,14 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1226
1627
|
}
|
|
1227
1628
|
});
|
|
1228
1629
|
if (FoundComponent) {
|
|
1229
|
-
return /* @__PURE__ */
|
|
1630
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1230
1631
|
role: "none"
|
|
1231
1632
|
}, FoundComponent);
|
|
1232
1633
|
}
|
|
1233
1634
|
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1234
1635
|
const CustomComponent = Custom?.[jsonPath];
|
|
1235
1636
|
if (CustomComponent) {
|
|
1236
|
-
return /* @__PURE__ */
|
|
1637
|
+
return /* @__PURE__ */ import_react15.default.createElement(CustomComponent, {
|
|
1237
1638
|
type,
|
|
1238
1639
|
format,
|
|
1239
1640
|
label,
|
|
@@ -1243,8 +1644,23 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1243
1644
|
...inputProps
|
|
1244
1645
|
});
|
|
1245
1646
|
}
|
|
1647
|
+
const refProps = getRefProps(property);
|
|
1648
|
+
if (refProps) {
|
|
1649
|
+
return /* @__PURE__ */ import_react15.default.createElement(RefField, {
|
|
1650
|
+
ast: refProps.ast,
|
|
1651
|
+
array: refProps.isArray,
|
|
1652
|
+
type,
|
|
1653
|
+
format,
|
|
1654
|
+
label,
|
|
1655
|
+
placeholder,
|
|
1656
|
+
disabled: readonly,
|
|
1657
|
+
inputOnly: inline,
|
|
1658
|
+
onQueryRefOptions,
|
|
1659
|
+
...inputProps
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1246
1662
|
if (array) {
|
|
1247
|
-
return /* @__PURE__ */
|
|
1663
|
+
return /* @__PURE__ */ import_react15.default.createElement(ArrayField, {
|
|
1248
1664
|
property,
|
|
1249
1665
|
path,
|
|
1250
1666
|
inputProps,
|
|
@@ -1254,9 +1670,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1254
1670
|
}
|
|
1255
1671
|
const InputComponent = getInputComponent(type, format);
|
|
1256
1672
|
if (InputComponent) {
|
|
1257
|
-
return /* @__PURE__ */
|
|
1673
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1258
1674
|
role: "none"
|
|
1259
|
-
}, /* @__PURE__ */
|
|
1675
|
+
}, /* @__PURE__ */ import_react15.default.createElement(InputComponent, {
|
|
1260
1676
|
type,
|
|
1261
1677
|
format,
|
|
1262
1678
|
label,
|
|
@@ -1267,9 +1683,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1267
1683
|
}));
|
|
1268
1684
|
}
|
|
1269
1685
|
if (options) {
|
|
1270
|
-
return /* @__PURE__ */
|
|
1686
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1271
1687
|
role: "none"
|
|
1272
|
-
}, /* @__PURE__ */
|
|
1688
|
+
}, /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1273
1689
|
type,
|
|
1274
1690
|
format,
|
|
1275
1691
|
disabled: readonly,
|
|
@@ -1283,28 +1699,16 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1283
1699
|
...inputProps
|
|
1284
1700
|
}));
|
|
1285
1701
|
}
|
|
1286
|
-
if (format === "ref") {
|
|
1287
|
-
return /* @__PURE__ */ import_react13.default.createElement(RefField, {
|
|
1288
|
-
ast,
|
|
1289
|
-
type,
|
|
1290
|
-
label,
|
|
1291
|
-
readonly,
|
|
1292
|
-
placeholder,
|
|
1293
|
-
inline,
|
|
1294
|
-
onQueryRefOptions,
|
|
1295
|
-
inputProps
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
1702
|
if (type === "object") {
|
|
1299
1703
|
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1300
|
-
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast,
|
|
1704
|
+
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_effect4.SchemaAST.isTypeLiteral);
|
|
1301
1705
|
if (typeLiteral) {
|
|
1302
|
-
return /* @__PURE__ */
|
|
1706
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1303
1707
|
role: "none"
|
|
1304
|
-
}, !inline && /* @__PURE__ */
|
|
1708
|
+
}, !inline && /* @__PURE__ */ import_react15.default.createElement("h3", {
|
|
1305
1709
|
className: "text-lg mbs-2 mbe-1"
|
|
1306
|
-
}, label), /* @__PURE__ */
|
|
1307
|
-
schema:
|
|
1710
|
+
}, label), /* @__PURE__ */ import_react15.default.createElement(FormFields, {
|
|
1711
|
+
schema: import_effect4.Schema.make(typeLiteral),
|
|
1308
1712
|
path,
|
|
1309
1713
|
readonly,
|
|
1310
1714
|
onQueryRefOptions,
|
|
@@ -1317,7 +1721,7 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1317
1721
|
};
|
|
1318
1722
|
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1319
1723
|
const values = useFormValues(path);
|
|
1320
|
-
const properties = (0,
|
|
1724
|
+
const properties = (0, import_react15.useMemo)(() => {
|
|
1321
1725
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1322
1726
|
const filtered = filter ? filter(props) : props;
|
|
1323
1727
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1327,11 +1731,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1327
1731
|
filter,
|
|
1328
1732
|
sort
|
|
1329
1733
|
]);
|
|
1330
|
-
return /* @__PURE__ */
|
|
1734
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1331
1735
|
role: "form",
|
|
1332
1736
|
className: (0, import_react_ui_theme8.mx)("flex flex-col w-full gap-2")
|
|
1333
1737
|
}, properties.map((property) => {
|
|
1334
|
-
return /* @__PURE__ */
|
|
1738
|
+
return /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1335
1739
|
key: property.name,
|
|
1336
1740
|
property,
|
|
1337
1741
|
path: [
|
|
@@ -1343,7 +1747,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1343
1747
|
lookupComponent,
|
|
1344
1748
|
Custom
|
|
1345
1749
|
});
|
|
1346
|
-
}).filter(
|
|
1750
|
+
}).filter(import_util4.isNotFalsy));
|
|
1347
1751
|
};
|
|
1348
1752
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1349
1753
|
const formRef = (0, import_react9.useRef)(null);
|
|
@@ -1548,22 +1952,23 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1548
1952
|
};
|
|
1549
1953
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1550
1954
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1551
|
-
var ViewMetaSchema =
|
|
1552
|
-
name:
|
|
1553
|
-
[
|
|
1955
|
+
var ViewMetaSchema = import_effect12.Schema.Struct({
|
|
1956
|
+
name: import_effect12.Schema.String.annotations({
|
|
1957
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "View"
|
|
1554
1958
|
}),
|
|
1555
|
-
typename:
|
|
1556
|
-
[
|
|
1959
|
+
typename: import_echo_schema11.Format.URL.annotations({
|
|
1960
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "Typename"
|
|
1557
1961
|
})
|
|
1558
|
-
}).pipe(
|
|
1962
|
+
}).pipe(import_effect12.Schema.mutable);
|
|
1559
1963
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1560
|
-
const { t } = (0,
|
|
1561
|
-
const projection = (0,
|
|
1964
|
+
const { t } = (0, import_react_ui12.useTranslation)(translationKey);
|
|
1965
|
+
const projection = (0, import_react18.useMemo)(() => new import_schema5.ViewProjection((0, import_echo_schema11.toJsonSchema)(schema), view), [
|
|
1562
1966
|
schema,
|
|
1563
1967
|
view
|
|
1564
1968
|
]);
|
|
1565
|
-
const [field, setField] = (0,
|
|
1566
|
-
const
|
|
1969
|
+
const [field, setField] = (0, import_react18.useState)();
|
|
1970
|
+
const immutable = readonly || !(0, import_echo_schema11.isMutable)(schema);
|
|
1971
|
+
const viewValues = (0, import_react18.useMemo)(() => {
|
|
1567
1972
|
return {
|
|
1568
1973
|
name: view.name,
|
|
1569
1974
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1573,16 +1978,16 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1573
1978
|
}, [
|
|
1574
1979
|
view
|
|
1575
1980
|
]);
|
|
1576
|
-
const handleSelect = (0,
|
|
1981
|
+
const handleSelect = (0, import_react18.useCallback)((field2) => {
|
|
1577
1982
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1578
1983
|
}, []);
|
|
1579
|
-
const handleAdd = (0,
|
|
1580
|
-
(0, import_invariant3.invariant)(!
|
|
1984
|
+
const handleAdd = (0, import_react18.useCallback)(() => {
|
|
1985
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
1581
1986
|
F: __dxlog_file5,
|
|
1582
|
-
L:
|
|
1987
|
+
L: 78,
|
|
1583
1988
|
S: void 0,
|
|
1584
1989
|
A: [
|
|
1585
|
-
"!
|
|
1990
|
+
"!immutable",
|
|
1586
1991
|
""
|
|
1587
1992
|
]
|
|
1588
1993
|
});
|
|
@@ -1592,13 +1997,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1592
1997
|
schema,
|
|
1593
1998
|
view
|
|
1594
1999
|
]);
|
|
1595
|
-
const handleUpdate = (0,
|
|
1596
|
-
(0, import_invariant3.invariant)(!
|
|
2000
|
+
const handleUpdate = (0, import_react18.useCallback)(({ name, typename }) => {
|
|
2001
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
1597
2002
|
F: __dxlog_file5,
|
|
1598
|
-
L:
|
|
2003
|
+
L: 85,
|
|
1599
2004
|
S: void 0,
|
|
1600
2005
|
A: [
|
|
1601
|
-
"!
|
|
2006
|
+
"!immutable",
|
|
1602
2007
|
""
|
|
1603
2008
|
]
|
|
1604
2009
|
});
|
|
@@ -1615,13 +2020,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1615
2020
|
view,
|
|
1616
2021
|
onTypenameChanged
|
|
1617
2022
|
]);
|
|
1618
|
-
const handleDelete = (0,
|
|
1619
|
-
(0, import_invariant3.invariant)(!
|
|
2023
|
+
const handleDelete = (0, import_react18.useCallback)((fieldId) => {
|
|
2024
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
1620
2025
|
F: __dxlog_file5,
|
|
1621
|
-
L:
|
|
2026
|
+
L: 101,
|
|
1622
2027
|
S: void 0,
|
|
1623
2028
|
A: [
|
|
1624
|
-
"!
|
|
2029
|
+
"!immutable",
|
|
1625
2030
|
""
|
|
1626
2031
|
]
|
|
1627
2032
|
});
|
|
@@ -1634,13 +2039,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1634
2039
|
field,
|
|
1635
2040
|
onDelete
|
|
1636
2041
|
]);
|
|
1637
|
-
const handleMove = (0,
|
|
1638
|
-
(0, import_invariant3.invariant)(!
|
|
2042
|
+
const handleMove = (0, import_react18.useCallback)((fromIndex, toIndex) => {
|
|
2043
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
1639
2044
|
F: __dxlog_file5,
|
|
1640
|
-
L:
|
|
2045
|
+
L: 113,
|
|
1641
2046
|
S: void 0,
|
|
1642
2047
|
A: [
|
|
1643
|
-
"!
|
|
2048
|
+
"!immutable",
|
|
1644
2049
|
""
|
|
1645
2050
|
]
|
|
1646
2051
|
});
|
|
@@ -1654,361 +2059,102 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1654
2059
|
schema,
|
|
1655
2060
|
view.fields
|
|
1656
2061
|
]);
|
|
1657
|
-
const handleClose = (0,
|
|
2062
|
+
const handleClose = (0, import_react18.useCallback)(() => setField(void 0), []);
|
|
1658
2063
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1659
|
-
const handleHide = (0,
|
|
2064
|
+
const handleHide = (0, import_react18.useCallback)((fieldId) => {
|
|
1660
2065
|
setField(void 0);
|
|
1661
2066
|
projection.hideFieldProjection(fieldId);
|
|
1662
2067
|
}, [
|
|
1663
2068
|
projection
|
|
1664
2069
|
]);
|
|
1665
|
-
const handleShow = (0,
|
|
2070
|
+
const handleShow = (0, import_react18.useCallback)((property) => {
|
|
1666
2071
|
setField(void 0);
|
|
1667
2072
|
projection.showFieldProjection(property);
|
|
1668
2073
|
}, [
|
|
1669
2074
|
projection
|
|
1670
2075
|
]);
|
|
1671
|
-
return /* @__PURE__ */
|
|
2076
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1672
2077
|
role: "none",
|
|
1673
|
-
className: (0, import_react_ui_theme10.mx)("
|
|
1674
|
-
}, /* @__PURE__ */
|
|
2078
|
+
className: (0, import_react_ui_theme10.mx)("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
2079
|
+
}, /* @__PURE__ */ import_react18.default.createElement(Form, {
|
|
1675
2080
|
autoSave: true,
|
|
1676
2081
|
schema: ViewMetaSchema,
|
|
1677
2082
|
values: viewValues,
|
|
1678
|
-
onSave:
|
|
1679
|
-
|
|
2083
|
+
onSave: immutable ? void 0 : handleUpdate,
|
|
2084
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
2085
|
+
}), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
2086
|
+
role: "none",
|
|
2087
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
2088
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1680
2089
|
role: "none",
|
|
1681
2090
|
className: "p-2"
|
|
1682
|
-
}, /* @__PURE__ */
|
|
2091
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1683
2092
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1684
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
2093
|
+
}, t("fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1685
2094
|
items: view.fields,
|
|
1686
|
-
isItem:
|
|
2095
|
+
isItem: import_effect12.Schema.is(import_schema5.FieldSchema),
|
|
1687
2096
|
getId: (field2) => field2.id,
|
|
1688
|
-
onMove:
|
|
1689
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
2097
|
+
onMove: immutable ? void 0 : handleMove
|
|
2098
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, null, showHeading && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1690
2099
|
role: "heading",
|
|
1691
2100
|
className: grid
|
|
1692
|
-
}, /* @__PURE__ */
|
|
2101
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1693
2102
|
className: "flex items-center text-sm"
|
|
1694
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
2103
|
+
}, t("field path label"))), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1695
2104
|
role: "list",
|
|
1696
2105
|
className: "flex flex-col w-full"
|
|
1697
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
2106
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1698
2107
|
key: field2.id,
|
|
1699
2108
|
item: field2,
|
|
1700
2109
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1701
|
-
}, /* @__PURE__ */
|
|
2110
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1702
2111
|
onClick: () => handleSelect(field2)
|
|
1703
|
-
}, field2.path), /* @__PURE__ */
|
|
2112
|
+
}, field2.path), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1704
2113
|
className: "flex items-center gap-2 -ml-4"
|
|
1705
|
-
}, /* @__PURE__ */
|
|
2114
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1706
2115
|
icon: "ph--eye-slash--regular",
|
|
1707
2116
|
disabled: view.fields.length <= 1,
|
|
1708
2117
|
onClick: () => handleHide(field2.id)
|
|
1709
|
-
}), !
|
|
2118
|
+
}), !immutable && /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1710
2119
|
icon: "ph--trash--regular",
|
|
1711
2120
|
disabled: view.fields.length <= 1,
|
|
1712
2121
|
onClick: () => handleDelete(field2.id)
|
|
1713
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
2122
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react18.default.createElement("div", null, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1714
2123
|
role: "none",
|
|
1715
2124
|
className: "p-2"
|
|
1716
|
-
}, /* @__PURE__ */
|
|
2125
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1717
2126
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1718
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
2127
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1719
2128
|
items: hiddenProperties,
|
|
1720
2129
|
isItem: (item) => typeof item === "string",
|
|
1721
2130
|
getId: (property) => property
|
|
1722
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
2131
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1723
2132
|
role: "list",
|
|
1724
2133
|
className: "flex flex-col w-full"
|
|
1725
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
2134
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1726
2135
|
key: property,
|
|
1727
2136
|
item: property,
|
|
1728
2137
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1729
|
-
}, /* @__PURE__ */
|
|
2138
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemTitle, null, property), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1730
2139
|
icon: "ph--eye--regular",
|
|
1731
2140
|
onClick: () => handleShow(property)
|
|
1732
|
-
}))))))), field && /* @__PURE__ */
|
|
2141
|
+
}))))))), field && /* @__PURE__ */ import_react18.default.createElement(FieldEditor, {
|
|
1733
2142
|
key: field.id,
|
|
1734
2143
|
view,
|
|
1735
2144
|
projection,
|
|
1736
2145
|
field,
|
|
1737
2146
|
registry,
|
|
1738
2147
|
onSave: handleClose
|
|
1739
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
2148
|
+
}), !readonly && !field && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1740
2149
|
className: "flex p-2 justify-center"
|
|
1741
|
-
}, /* @__PURE__ */
|
|
2150
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui12.IconButton, {
|
|
1742
2151
|
icon: "ph--plus--regular",
|
|
1743
2152
|
label: t("button add property"),
|
|
1744
|
-
onClick:
|
|
2153
|
+
onClick: immutable ? void 0 : handleAdd,
|
|
1745
2154
|
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
1746
2155
|
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
1747
2156
|
})));
|
|
1748
2157
|
};
|
|
1749
|
-
var parseValue = ({ type, format, value }) => {
|
|
1750
|
-
if (value === void 0 || value === null || value === "") {
|
|
1751
|
-
return void 0;
|
|
1752
|
-
}
|
|
1753
|
-
const parseScalar = (type2) => {
|
|
1754
|
-
switch (type2) {
|
|
1755
|
-
case import_echo_schema10.TypeEnum.Boolean: {
|
|
1756
|
-
if (typeof value === "string") {
|
|
1757
|
-
const lowercaseValue = value.toLowerCase();
|
|
1758
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1759
|
-
return false;
|
|
1760
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1761
|
-
return true;
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
return Boolean(value);
|
|
1765
|
-
}
|
|
1766
|
-
case import_echo_schema10.TypeEnum.Number: {
|
|
1767
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1768
|
-
const num = Number(cleaned);
|
|
1769
|
-
return Number.isNaN(num) ? null : num;
|
|
1770
|
-
}
|
|
1771
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1772
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1773
|
-
return String(value);
|
|
1774
|
-
default: {
|
|
1775
|
-
return value;
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
};
|
|
1779
|
-
if (!format) {
|
|
1780
|
-
return parseScalar(type);
|
|
1781
|
-
}
|
|
1782
|
-
switch (format) {
|
|
1783
|
-
case import_echo_schema10.FormatEnum.Boolean:
|
|
1784
|
-
return parseScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1785
|
-
case import_echo_schema10.FormatEnum.Number:
|
|
1786
|
-
case import_echo_schema10.FormatEnum.Percent:
|
|
1787
|
-
case import_echo_schema10.FormatEnum.Currency:
|
|
1788
|
-
return parseScalar(import_echo_schema10.TypeEnum.Number);
|
|
1789
|
-
case import_echo_schema10.FormatEnum.String:
|
|
1790
|
-
case import_echo_schema10.FormatEnum.Markdown: {
|
|
1791
|
-
return parseScalar(import_echo_schema10.TypeEnum.String);
|
|
1792
|
-
}
|
|
1793
|
-
case import_echo_schema10.FormatEnum.Ref:
|
|
1794
|
-
throw new Error(`unexpected format: ${import_echo_schema10.FormatEnum.Ref}`);
|
|
1795
|
-
case import_echo_schema10.FormatEnum.DateTime:
|
|
1796
|
-
case import_echo_schema10.FormatEnum.Date:
|
|
1797
|
-
case import_echo_schema10.FormatEnum.Time:
|
|
1798
|
-
case import_echo_schema10.FormatEnum.Timestamp: {
|
|
1799
|
-
const date = new Date(value);
|
|
1800
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1801
|
-
}
|
|
1802
|
-
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1803
|
-
if (typeof value === "string") {
|
|
1804
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1805
|
-
const parts = cleaned.split(",");
|
|
1806
|
-
if (parts.length === 2) {
|
|
1807
|
-
const lat = parseFloat(parts[0]);
|
|
1808
|
-
const long = parseFloat(parts[1]);
|
|
1809
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1810
|
-
return import_echo_schema10.GeoLocation.toGeoPoint({
|
|
1811
|
-
latitude: lat,
|
|
1812
|
-
longitude: long
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
return [
|
|
1818
|
-
0,
|
|
1819
|
-
0
|
|
1820
|
-
];
|
|
1821
|
-
}
|
|
1822
|
-
default: {
|
|
1823
|
-
return value;
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
};
|
|
1827
|
-
var cellClassesForFieldType = ({ type, format }) => {
|
|
1828
|
-
if (!format) {
|
|
1829
|
-
switch (type) {
|
|
1830
|
-
case import_echo_schema10.TypeEnum.Number:
|
|
1831
|
-
return [
|
|
1832
|
-
"text-right",
|
|
1833
|
-
"font-mono"
|
|
1834
|
-
];
|
|
1835
|
-
case import_echo_schema10.TypeEnum.Boolean:
|
|
1836
|
-
return [
|
|
1837
|
-
"text-right",
|
|
1838
|
-
"font-mono"
|
|
1839
|
-
];
|
|
1840
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1841
|
-
return void 0;
|
|
1842
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1843
|
-
return void 0;
|
|
1844
|
-
default: {
|
|
1845
|
-
return void 0;
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
switch (format) {
|
|
1850
|
-
case import_echo_schema10.FormatEnum.Markdown:
|
|
1851
|
-
return void 0;
|
|
1852
|
-
case import_echo_schema10.FormatEnum.Time:
|
|
1853
|
-
case import_echo_schema10.FormatEnum.Timestamp:
|
|
1854
|
-
case import_echo_schema10.FormatEnum.DateTime:
|
|
1855
|
-
case import_echo_schema10.FormatEnum.Date:
|
|
1856
|
-
case import_echo_schema10.FormatEnum.Duration:
|
|
1857
|
-
return [
|
|
1858
|
-
"font-mono",
|
|
1859
|
-
"text-right"
|
|
1860
|
-
];
|
|
1861
|
-
case import_echo_schema10.FormatEnum.Currency:
|
|
1862
|
-
return [
|
|
1863
|
-
"text-right"
|
|
1864
|
-
];
|
|
1865
|
-
case import_echo_schema10.FormatEnum.JSON:
|
|
1866
|
-
case import_echo_schema10.FormatEnum.DID:
|
|
1867
|
-
return [
|
|
1868
|
-
"font-mono"
|
|
1869
|
-
];
|
|
1870
|
-
default:
|
|
1871
|
-
return void 0;
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
var pathNotUniqueError = (path) => ({
|
|
1875
|
-
path: "path",
|
|
1876
|
-
message: `'${path}' is already present`
|
|
1877
|
-
});
|
|
1878
|
-
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1879
|
-
const formatScalar = (type2) => {
|
|
1880
|
-
switch (type2) {
|
|
1881
|
-
case import_echo_schema11.TypeEnum.Boolean:
|
|
1882
|
-
return value.toLocaleString().toUpperCase();
|
|
1883
|
-
case import_echo_schema11.TypeEnum.Number:
|
|
1884
|
-
return value.toLocaleString(locale);
|
|
1885
|
-
case import_echo_schema11.TypeEnum.String:
|
|
1886
|
-
case import_echo_schema11.TypeEnum.Ref:
|
|
1887
|
-
return String(value);
|
|
1888
|
-
default: {
|
|
1889
|
-
return String(value);
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
};
|
|
1893
|
-
if (!format) {
|
|
1894
|
-
return formatScalar(type);
|
|
1895
|
-
}
|
|
1896
|
-
switch (format) {
|
|
1897
|
-
case import_echo_schema11.FormatEnum.Boolean: {
|
|
1898
|
-
return formatScalar(import_echo_schema11.TypeEnum.Boolean);
|
|
1899
|
-
}
|
|
1900
|
-
case import_echo_schema11.FormatEnum.Number: {
|
|
1901
|
-
return formatScalar(import_echo_schema11.TypeEnum.Number);
|
|
1902
|
-
}
|
|
1903
|
-
case import_echo_schema11.FormatEnum.String:
|
|
1904
|
-
case import_echo_schema11.FormatEnum.Ref: {
|
|
1905
|
-
return formatScalar(import_echo_schema11.TypeEnum.String);
|
|
1906
|
-
}
|
|
1907
|
-
case import_echo_schema11.FormatEnum.Percent: {
|
|
1908
|
-
return `${value * 100}%`;
|
|
1909
|
-
}
|
|
1910
|
-
case import_echo_schema11.FormatEnum.Currency: {
|
|
1911
|
-
return value.toLocaleString(locale, {
|
|
1912
|
-
style: "currency",
|
|
1913
|
-
currency: "USD",
|
|
1914
|
-
minimumFractionDigits: 2,
|
|
1915
|
-
maximumFractionDigits: 2
|
|
1916
|
-
});
|
|
1917
|
-
}
|
|
1918
|
-
case import_echo_schema11.FormatEnum.Date: {
|
|
1919
|
-
try {
|
|
1920
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1921
|
-
} catch (error) {
|
|
1922
|
-
return "Invalid Date";
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
case import_echo_schema11.FormatEnum.Time: {
|
|
1926
|
-
try {
|
|
1927
|
-
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1928
|
-
} catch (error) {
|
|
1929
|
-
return "Invalid Time";
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
case import_echo_schema11.FormatEnum.DateTime: {
|
|
1933
|
-
try {
|
|
1934
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1935
|
-
} catch (error) {
|
|
1936
|
-
return "Invalid DateTime";
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
case import_echo_schema11.FormatEnum.GeoPoint: {
|
|
1940
|
-
if (value === null || value === void 0) {
|
|
1941
|
-
return "";
|
|
1942
|
-
}
|
|
1943
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1944
|
-
const { latitude, longitude } = import_echo_schema11.GeoLocation.fromGeoPoint(value);
|
|
1945
|
-
return `${latitude},${longitude}`;
|
|
1946
|
-
}
|
|
1947
|
-
return String(value);
|
|
1948
|
-
}
|
|
1949
|
-
default: {
|
|
1950
|
-
if (value === null || value === "undefined") {
|
|
1951
|
-
return "";
|
|
1952
|
-
}
|
|
1953
|
-
return String(value);
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
};
|
|
1957
|
-
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1958
|
-
const formatScalar = (type2) => {
|
|
1959
|
-
switch (type2) {
|
|
1960
|
-
case import_echo_schema11.TypeEnum.Boolean:
|
|
1961
|
-
case import_echo_schema11.TypeEnum.Number:
|
|
1962
|
-
case import_echo_schema11.TypeEnum.String:
|
|
1963
|
-
case import_echo_schema11.TypeEnum.Ref:
|
|
1964
|
-
return String(value);
|
|
1965
|
-
default:
|
|
1966
|
-
return String(value);
|
|
1967
|
-
}
|
|
1968
|
-
};
|
|
1969
|
-
if (!format) {
|
|
1970
|
-
return formatScalar(type);
|
|
1971
|
-
}
|
|
1972
|
-
switch (format) {
|
|
1973
|
-
case import_echo_schema11.FormatEnum.Boolean:
|
|
1974
|
-
case import_echo_schema11.FormatEnum.Number:
|
|
1975
|
-
case import_echo_schema11.FormatEnum.String:
|
|
1976
|
-
case import_echo_schema11.FormatEnum.Ref: {
|
|
1977
|
-
return formatScalar(type);
|
|
1978
|
-
}
|
|
1979
|
-
case import_echo_schema11.FormatEnum.Percent: {
|
|
1980
|
-
return String(value * 100);
|
|
1981
|
-
}
|
|
1982
|
-
case import_echo_schema11.FormatEnum.Currency: {
|
|
1983
|
-
return String(value);
|
|
1984
|
-
}
|
|
1985
|
-
case import_echo_schema11.FormatEnum.DateTime: {
|
|
1986
|
-
const date = new Date(value);
|
|
1987
|
-
return date.toISOString();
|
|
1988
|
-
}
|
|
1989
|
-
case import_echo_schema11.FormatEnum.Date: {
|
|
1990
|
-
const date = new Date(value);
|
|
1991
|
-
return date.toISOString().split("T")[0];
|
|
1992
|
-
}
|
|
1993
|
-
case import_echo_schema11.FormatEnum.Time: {
|
|
1994
|
-
const date = new Date(value);
|
|
1995
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
1996
|
-
}
|
|
1997
|
-
case import_echo_schema11.FormatEnum.GeoPoint: {
|
|
1998
|
-
if (value === null || value === void 0) {
|
|
1999
|
-
return "";
|
|
2000
|
-
}
|
|
2001
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
2002
|
-
const { latitude, longitude } = import_echo_schema11.GeoLocation.fromGeoPoint(value);
|
|
2003
|
-
return `${latitude},${longitude}`;
|
|
2004
|
-
}
|
|
2005
|
-
return String(value);
|
|
2006
|
-
}
|
|
2007
|
-
default: {
|
|
2008
|
-
return String(value);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
};
|
|
2012
2158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2013
2159
|
0 && (module.exports = {
|
|
2014
2160
|
BooleanInput,
|
|
@@ -2037,14 +2183,18 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
2037
2183
|
ViewEditor,
|
|
2038
2184
|
cellClassesForFieldType,
|
|
2039
2185
|
controlItemClasses,
|
|
2186
|
+
findArrayElementType,
|
|
2040
2187
|
formatForDisplay,
|
|
2041
2188
|
formatForEditing,
|
|
2189
|
+
getRefProps,
|
|
2042
2190
|
parseValue,
|
|
2043
2191
|
pathNotUniqueError,
|
|
2044
2192
|
translations,
|
|
2045
2193
|
useForm,
|
|
2046
2194
|
useFormContext,
|
|
2047
2195
|
useFormValues,
|
|
2048
|
-
useInputProps
|
|
2196
|
+
useInputProps,
|
|
2197
|
+
useQueryRefOptions,
|
|
2198
|
+
useRefQueryLookupHandler
|
|
2049
2199
|
});
|
|
2050
2200
|
//# sourceMappingURL=index.cjs.map
|