@dxos/react-ui-form 0.8.2-main.5885341 → 0.8.2-main.600d381
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 +720 -557
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +734 -579
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +720 -557
- 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.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 +25 -24
- package/src/components/ControlSection/ControlSection.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +5 -6
- 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 +145 -100
- 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 +4 -3
- package/src/components/ViewEditor/ViewEditor.tsx +9 -8
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/hooks/index.ts +3 -1
- package/src/hooks/useForm.ts +3 -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
|
});
|
|
@@ -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,561 @@ 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: 69,
|
|
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 (import_echo_schema7.Ref.isRef(formValue)) {
|
|
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
|
-
|
|
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 newValue = (0, import_react16.useMemo)(() => {
|
|
1394
|
+
if (type === "object" && elementType) {
|
|
1395
|
+
return getDefaultObjectValue(elementType);
|
|
1396
|
+
} else {
|
|
1397
|
+
return import_effect7.SimpleType.getDefaultValue(type);
|
|
1398
|
+
}
|
|
1399
|
+
}, [
|
|
1400
|
+
type,
|
|
1401
|
+
elementType
|
|
1402
|
+
]);
|
|
1403
|
+
const handleAdd = (0, import_react16.useCallback)(() => {
|
|
1404
|
+
inputProps.onValueChange(type, [
|
|
1405
|
+
...values,
|
|
1406
|
+
newValue
|
|
1407
|
+
]);
|
|
1408
|
+
}, [
|
|
1409
|
+
type,
|
|
1410
|
+
elementType,
|
|
1411
|
+
inputProps,
|
|
1412
|
+
newValue,
|
|
1413
|
+
values
|
|
1414
|
+
]);
|
|
1415
|
+
const handleRemove = (0, import_react16.useCallback)((index) => {
|
|
1416
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
1417
|
+
inputProps.onValueChange(type, newValues);
|
|
1418
|
+
}, [
|
|
1419
|
+
type,
|
|
1420
|
+
inputProps,
|
|
1421
|
+
values
|
|
1422
|
+
]);
|
|
1423
|
+
if (!elementType) {
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
return /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1427
|
+
role: "none",
|
|
1428
|
+
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1429
|
+
}, /* @__PURE__ */ import_react16.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1430
|
+
role: "none",
|
|
1431
|
+
className: "flex flex-col gap-1"
|
|
1432
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1433
|
+
key: index,
|
|
1434
|
+
role: "none",
|
|
1435
|
+
className: "flex items-center gap-1"
|
|
1436
|
+
}, /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1437
|
+
role: "none",
|
|
1438
|
+
className: "flex-1"
|
|
1439
|
+
}, /* @__PURE__ */ import_react16.default.createElement(FormField, {
|
|
1440
|
+
property: {
|
|
1441
|
+
...property,
|
|
1442
|
+
array: false,
|
|
1443
|
+
ast: elementType
|
|
1444
|
+
},
|
|
1445
|
+
path: [
|
|
1446
|
+
...path ?? [],
|
|
1447
|
+
index
|
|
1448
|
+
],
|
|
1449
|
+
readonly,
|
|
1450
|
+
inline: true,
|
|
1451
|
+
Custom,
|
|
1452
|
+
lookupComponent
|
|
1453
|
+
})), /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1454
|
+
icon: "ph--trash--regular",
|
|
1455
|
+
iconOnly: true,
|
|
1456
|
+
label: t("button remove"),
|
|
1457
|
+
onClick: () => handleRemove(index)
|
|
1458
|
+
})))), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1459
|
+
role: "none",
|
|
1460
|
+
className: "flex justify-between items-center plb-1"
|
|
1461
|
+
}, /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1462
|
+
icon: "ph--plus--regular",
|
|
1463
|
+
iconOnly: true,
|
|
1464
|
+
label: t("button add"),
|
|
1465
|
+
onClick: handleAdd
|
|
1466
|
+
})));
|
|
1467
|
+
};
|
|
1468
|
+
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1469
|
+
const refTypeInfo = (0, import_react17.useMemo)(() => ast ? (0, import_effect11.findAnnotation)(ast, import_echo_schema9.ReferenceAnnotationId) : void 0, [
|
|
1470
|
+
ast
|
|
1471
|
+
]);
|
|
1472
|
+
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1473
|
+
refTypeInfo,
|
|
1474
|
+
onQueryRefOptions
|
|
1475
|
+
});
|
|
1476
|
+
if (refTypeInfo && refTypeInfo?.typename === (0, import_echo_schema9.getTypeAnnotation)(import_echo_schema9.Expando)?.typename || !onQueryRefOptions) {
|
|
1477
|
+
return /* @__PURE__ */ import_react17.default.createElement(RefFieldFallback, {
|
|
1478
|
+
type,
|
|
1479
|
+
label,
|
|
1480
|
+
placeholder,
|
|
1481
|
+
disabled,
|
|
1482
|
+
inputOnly,
|
|
1483
|
+
getValue: getValue3,
|
|
1484
|
+
onBlur,
|
|
1485
|
+
onValueChange,
|
|
1486
|
+
...restInputProps
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
const handleGetValue = (0, import_react17.useCallback)(() => {
|
|
1490
|
+
const formValue = getValue3();
|
|
1491
|
+
const unknownToRefOption = (val) => {
|
|
1492
|
+
if (import_echo_schema9.Ref.isRef(val)) {
|
|
1493
|
+
const dxnString = val.dxn.toString();
|
|
1494
|
+
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1495
|
+
if (matchingOption) {
|
|
1496
|
+
return matchingOption;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return void 0;
|
|
1500
|
+
};
|
|
1501
|
+
if (array && Array.isArray(formValue)) {
|
|
1502
|
+
return formValue.map(unknownToRefOption).filter(import_util5.isNonNullable) ?? [];
|
|
1503
|
+
}
|
|
1504
|
+
const option = unknownToRefOption(formValue);
|
|
1505
|
+
if (option) {
|
|
1506
|
+
return [
|
|
1507
|
+
option
|
|
1508
|
+
];
|
|
1509
|
+
}
|
|
1510
|
+
return [];
|
|
1511
|
+
}, [
|
|
1512
|
+
getValue3,
|
|
1513
|
+
availableOptions,
|
|
1514
|
+
array
|
|
1515
|
+
]);
|
|
1516
|
+
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) => ({
|
|
1517
|
+
id: option.id,
|
|
1518
|
+
label: option.label,
|
|
1519
|
+
hue: option.hue
|
|
1520
|
+
})), [
|
|
1521
|
+
availableOptions
|
|
1522
|
+
]);
|
|
1523
|
+
const handleUpdate = (0, import_react17.useCallback)((ids) => {
|
|
1524
|
+
if (ids.length === 0) {
|
|
1525
|
+
onValueChange("object", void 0);
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
const refs = ids.map((id) => {
|
|
1529
|
+
const item = availableOptions.find((option) => option.id === id);
|
|
1530
|
+
if (item) {
|
|
1531
|
+
const dxn = import_keys2.DXN.parse(item.id);
|
|
1532
|
+
return import_echo_schema9.Ref.fromDXN(dxn);
|
|
1533
|
+
}
|
|
1534
|
+
return null;
|
|
1535
|
+
}).filter(import_util5.isNonNullable);
|
|
1536
|
+
if (array) {
|
|
1537
|
+
onValueChange("object", refs);
|
|
1538
|
+
} else {
|
|
1539
|
+
onValueChange("object", refs[0]);
|
|
1540
|
+
}
|
|
1541
|
+
}, [
|
|
1542
|
+
availableOptions,
|
|
1543
|
+
array,
|
|
1544
|
+
onValueChange
|
|
1545
|
+
]);
|
|
1546
|
+
const tagPickerMode = (0, import_react17.useMemo)(() => array ? "multi-select" : "single-select", [
|
|
1547
|
+
array
|
|
1548
|
+
]);
|
|
1549
|
+
if (!refTypeInfo) {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
const { status, error } = restInputProps.getStatus();
|
|
1553
|
+
return /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Root, {
|
|
1554
|
+
validationValence: status
|
|
1555
|
+
}, !inputOnly && /* @__PURE__ */ import_react17.default.createElement(InputHeader, {
|
|
1556
|
+
error
|
|
1557
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.Label, null, label)), /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
1558
|
+
"data-no-submit": true
|
|
1559
|
+
}, /* @__PURE__ */ import_react17.default.createElement(import_react_ui_tag_picker.TagPicker, {
|
|
1560
|
+
items: handleGetValue(),
|
|
1561
|
+
mode: tagPickerMode,
|
|
1562
|
+
onBlur: (event) => onBlur(event),
|
|
1563
|
+
onUpdate: handleUpdate,
|
|
1564
|
+
onSearch: handleSearch,
|
|
1565
|
+
classNames: "rounded-sm bg-input p-1.5"
|
|
1566
|
+
})), inputOnly && /* @__PURE__ */ import_react17.default.createElement(import_react_ui11.Input.DescriptionAndValidation, null, error));
|
|
1567
|
+
};
|
|
1568
|
+
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1569
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1570
|
+
const dxn = import_keys2.DXN.tryParse(dxnString);
|
|
1571
|
+
if (dxn) {
|
|
1572
|
+
onValueChange?.("object", import_echo_schema9.Ref.fromDXN(dxn));
|
|
1573
|
+
} else if (dxnString === "") {
|
|
1574
|
+
onValueChange?.("object", void 0);
|
|
1575
|
+
} else {
|
|
1576
|
+
onValueChange?.("string", dxnString);
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
const handleGetValue = () => {
|
|
1580
|
+
const formValue = getValue3();
|
|
1581
|
+
if (typeof formValue === "string") {
|
|
1582
|
+
return formValue;
|
|
1583
|
+
}
|
|
1584
|
+
if (import_echo_schema9.Ref.isRef(formValue)) {
|
|
1585
|
+
return formValue.dxn.toString();
|
|
1586
|
+
}
|
|
1587
|
+
return void 0;
|
|
1588
|
+
};
|
|
1589
|
+
return /* @__PURE__ */ import_react17.default.createElement(TextInput, {
|
|
1590
|
+
type,
|
|
1591
|
+
label,
|
|
1592
|
+
disabled,
|
|
1593
|
+
placeholder,
|
|
1594
|
+
inputOnly,
|
|
1595
|
+
getValue: handleGetValue,
|
|
1596
|
+
onValueChange: handleOnValueChange,
|
|
1597
|
+
...restInputProps
|
|
1598
|
+
});
|
|
1599
|
+
};
|
|
1600
|
+
var getInputComponent = (type, format) => {
|
|
1601
|
+
switch (format) {
|
|
1602
|
+
case import_echo_schema10.FormatEnum.GeoPoint:
|
|
1603
|
+
return GeoPointInput;
|
|
1604
|
+
case import_echo_schema10.FormatEnum.Markdown:
|
|
1605
|
+
return MarkdownInput;
|
|
1606
|
+
}
|
|
1607
|
+
switch (type) {
|
|
1608
|
+
case "string":
|
|
1609
|
+
return TextInput;
|
|
1610
|
+
case "number":
|
|
1611
|
+
return NumberInput;
|
|
1612
|
+
case "boolean":
|
|
1613
|
+
return BooleanInput;
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1617
|
+
const inputProps = useInputProps(path);
|
|
1618
|
+
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1619
|
+
const label = (0, import_react15.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1620
|
+
title,
|
|
1210
1621
|
name
|
|
1211
1622
|
]);
|
|
1212
|
-
const placeholder = (0,
|
|
1623
|
+
const placeholder = (0, import_react15.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1213
1624
|
examples,
|
|
1214
1625
|
description
|
|
1215
1626
|
]);
|
|
1216
1627
|
const FoundComponent = lookupComponent?.({
|
|
1217
1628
|
prop: name,
|
|
1218
|
-
schema:
|
|
1629
|
+
schema: import_effect4.Schema.make(ast),
|
|
1219
1630
|
inputProps: {
|
|
1220
1631
|
type,
|
|
1221
1632
|
format,
|
|
@@ -1226,14 +1637,14 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1226
1637
|
}
|
|
1227
1638
|
});
|
|
1228
1639
|
if (FoundComponent) {
|
|
1229
|
-
return /* @__PURE__ */
|
|
1640
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1230
1641
|
role: "none"
|
|
1231
1642
|
}, FoundComponent);
|
|
1232
1643
|
}
|
|
1233
1644
|
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1234
1645
|
const CustomComponent = Custom?.[jsonPath];
|
|
1235
1646
|
if (CustomComponent) {
|
|
1236
|
-
return /* @__PURE__ */
|
|
1647
|
+
return /* @__PURE__ */ import_react15.default.createElement(CustomComponent, {
|
|
1237
1648
|
type,
|
|
1238
1649
|
format,
|
|
1239
1650
|
label,
|
|
@@ -1243,8 +1654,23 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1243
1654
|
...inputProps
|
|
1244
1655
|
});
|
|
1245
1656
|
}
|
|
1657
|
+
const refProps = getRefProps(property);
|
|
1658
|
+
if (refProps) {
|
|
1659
|
+
return /* @__PURE__ */ import_react15.default.createElement(RefField, {
|
|
1660
|
+
ast: refProps.ast,
|
|
1661
|
+
array: refProps.isArray,
|
|
1662
|
+
type,
|
|
1663
|
+
format,
|
|
1664
|
+
label,
|
|
1665
|
+
placeholder,
|
|
1666
|
+
disabled: readonly,
|
|
1667
|
+
inputOnly: inline,
|
|
1668
|
+
onQueryRefOptions,
|
|
1669
|
+
...inputProps
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1246
1672
|
if (array) {
|
|
1247
|
-
return /* @__PURE__ */
|
|
1673
|
+
return /* @__PURE__ */ import_react15.default.createElement(ArrayField, {
|
|
1248
1674
|
property,
|
|
1249
1675
|
path,
|
|
1250
1676
|
inputProps,
|
|
@@ -1254,9 +1680,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1254
1680
|
}
|
|
1255
1681
|
const InputComponent = getInputComponent(type, format);
|
|
1256
1682
|
if (InputComponent) {
|
|
1257
|
-
return /* @__PURE__ */
|
|
1683
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1258
1684
|
role: "none"
|
|
1259
|
-
}, /* @__PURE__ */
|
|
1685
|
+
}, /* @__PURE__ */ import_react15.default.createElement(InputComponent, {
|
|
1260
1686
|
type,
|
|
1261
1687
|
format,
|
|
1262
1688
|
label,
|
|
@@ -1267,9 +1693,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1267
1693
|
}));
|
|
1268
1694
|
}
|
|
1269
1695
|
if (options) {
|
|
1270
|
-
return /* @__PURE__ */
|
|
1696
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1271
1697
|
role: "none"
|
|
1272
|
-
}, /* @__PURE__ */
|
|
1698
|
+
}, /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1273
1699
|
type,
|
|
1274
1700
|
format,
|
|
1275
1701
|
disabled: readonly,
|
|
@@ -1283,28 +1709,16 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1283
1709
|
...inputProps
|
|
1284
1710
|
}));
|
|
1285
1711
|
}
|
|
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
1712
|
if (type === "object") {
|
|
1299
1713
|
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,
|
|
1714
|
+
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_effect4.SchemaAST.isTypeLiteral);
|
|
1301
1715
|
if (typeLiteral) {
|
|
1302
|
-
return /* @__PURE__ */
|
|
1716
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1303
1717
|
role: "none"
|
|
1304
|
-
}, !inline && /* @__PURE__ */
|
|
1718
|
+
}, !inline && /* @__PURE__ */ import_react15.default.createElement("h3", {
|
|
1305
1719
|
className: "text-lg mbs-2 mbe-1"
|
|
1306
|
-
}, label), /* @__PURE__ */
|
|
1307
|
-
schema:
|
|
1720
|
+
}, label), /* @__PURE__ */ import_react15.default.createElement(FormFields, {
|
|
1721
|
+
schema: import_effect4.Schema.make(typeLiteral),
|
|
1308
1722
|
path,
|
|
1309
1723
|
readonly,
|
|
1310
1724
|
onQueryRefOptions,
|
|
@@ -1317,7 +1731,7 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1317
1731
|
};
|
|
1318
1732
|
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1319
1733
|
const values = useFormValues(path);
|
|
1320
|
-
const properties = (0,
|
|
1734
|
+
const properties = (0, import_react15.useMemo)(() => {
|
|
1321
1735
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1322
1736
|
const filtered = filter ? filter(props) : props;
|
|
1323
1737
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1327,11 +1741,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1327
1741
|
filter,
|
|
1328
1742
|
sort
|
|
1329
1743
|
]);
|
|
1330
|
-
return /* @__PURE__ */
|
|
1744
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1331
1745
|
role: "form",
|
|
1332
1746
|
className: (0, import_react_ui_theme8.mx)("flex flex-col w-full gap-2")
|
|
1333
1747
|
}, properties.map((property) => {
|
|
1334
|
-
return /* @__PURE__ */
|
|
1748
|
+
return /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1335
1749
|
key: property.name,
|
|
1336
1750
|
property,
|
|
1337
1751
|
path: [
|
|
@@ -1343,7 +1757,7 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
|
|
|
1343
1757
|
lookupComponent,
|
|
1344
1758
|
Custom
|
|
1345
1759
|
});
|
|
1346
|
-
}).filter(
|
|
1760
|
+
}).filter(import_util4.isNotFalsy));
|
|
1347
1761
|
};
|
|
1348
1762
|
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1349
1763
|
const formRef = (0, import_react9.useRef)(null);
|
|
@@ -1548,22 +1962,22 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1548
1962
|
};
|
|
1549
1963
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1550
1964
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1551
|
-
var ViewMetaSchema =
|
|
1552
|
-
name:
|
|
1553
|
-
[
|
|
1965
|
+
var ViewMetaSchema = import_effect12.Schema.Struct({
|
|
1966
|
+
name: import_effect12.Schema.String.annotations({
|
|
1967
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "View"
|
|
1554
1968
|
}),
|
|
1555
|
-
typename:
|
|
1556
|
-
[
|
|
1969
|
+
typename: import_echo_schema11.Format.URL.annotations({
|
|
1970
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "Typename"
|
|
1557
1971
|
})
|
|
1558
|
-
}).pipe(
|
|
1972
|
+
}).pipe(import_effect12.Schema.mutable);
|
|
1559
1973
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1560
|
-
const { t } = (0,
|
|
1561
|
-
const projection = (0,
|
|
1974
|
+
const { t } = (0, import_react_ui12.useTranslation)(translationKey);
|
|
1975
|
+
const projection = (0, import_react18.useMemo)(() => new import_schema5.ViewProjection(schema.jsonSchema, view), [
|
|
1562
1976
|
schema,
|
|
1563
1977
|
view
|
|
1564
1978
|
]);
|
|
1565
|
-
const [field, setField] = (0,
|
|
1566
|
-
const viewValues = (0,
|
|
1979
|
+
const [field, setField] = (0, import_react18.useState)();
|
|
1980
|
+
const viewValues = (0, import_react18.useMemo)(() => {
|
|
1567
1981
|
return {
|
|
1568
1982
|
name: view.name,
|
|
1569
1983
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1573,13 +1987,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1573
1987
|
}, [
|
|
1574
1988
|
view
|
|
1575
1989
|
]);
|
|
1576
|
-
const handleSelect = (0,
|
|
1990
|
+
const handleSelect = (0, import_react18.useCallback)((field2) => {
|
|
1577
1991
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1578
1992
|
}, []);
|
|
1579
|
-
const handleAdd = (0,
|
|
1993
|
+
const handleAdd = (0, import_react18.useCallback)(() => {
|
|
1580
1994
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1581
1995
|
F: __dxlog_file5,
|
|
1582
|
-
L:
|
|
1996
|
+
L: 77,
|
|
1583
1997
|
S: void 0,
|
|
1584
1998
|
A: [
|
|
1585
1999
|
"!schema.readonly",
|
|
@@ -1592,10 +2006,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1592
2006
|
schema,
|
|
1593
2007
|
view
|
|
1594
2008
|
]);
|
|
1595
|
-
const handleUpdate = (0,
|
|
2009
|
+
const handleUpdate = (0, import_react18.useCallback)(({ name, typename }) => {
|
|
1596
2010
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1597
2011
|
F: __dxlog_file5,
|
|
1598
|
-
L:
|
|
2012
|
+
L: 84,
|
|
1599
2013
|
S: void 0,
|
|
1600
2014
|
A: [
|
|
1601
2015
|
"!schema.readonly",
|
|
@@ -1615,10 +2029,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1615
2029
|
view,
|
|
1616
2030
|
onTypenameChanged
|
|
1617
2031
|
]);
|
|
1618
|
-
const handleDelete = (0,
|
|
2032
|
+
const handleDelete = (0, import_react18.useCallback)((fieldId) => {
|
|
1619
2033
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1620
2034
|
F: __dxlog_file5,
|
|
1621
|
-
L:
|
|
2035
|
+
L: 100,
|
|
1622
2036
|
S: void 0,
|
|
1623
2037
|
A: [
|
|
1624
2038
|
"!schema.readonly",
|
|
@@ -1634,10 +2048,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1634
2048
|
field,
|
|
1635
2049
|
onDelete
|
|
1636
2050
|
]);
|
|
1637
|
-
const handleMove = (0,
|
|
2051
|
+
const handleMove = (0, import_react18.useCallback)((fromIndex, toIndex) => {
|
|
1638
2052
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1639
2053
|
F: __dxlog_file5,
|
|
1640
|
-
L:
|
|
2054
|
+
L: 112,
|
|
1641
2055
|
S: void 0,
|
|
1642
2056
|
A: [
|
|
1643
2057
|
"!schema.readonly",
|
|
@@ -1654,95 +2068,95 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1654
2068
|
schema,
|
|
1655
2069
|
view.fields
|
|
1656
2070
|
]);
|
|
1657
|
-
const handleClose = (0,
|
|
2071
|
+
const handleClose = (0, import_react18.useCallback)(() => setField(void 0), []);
|
|
1658
2072
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1659
|
-
const handleHide = (0,
|
|
2073
|
+
const handleHide = (0, import_react18.useCallback)((fieldId) => {
|
|
1660
2074
|
setField(void 0);
|
|
1661
2075
|
projection.hideFieldProjection(fieldId);
|
|
1662
2076
|
}, [
|
|
1663
2077
|
projection
|
|
1664
2078
|
]);
|
|
1665
|
-
const handleShow = (0,
|
|
2079
|
+
const handleShow = (0, import_react18.useCallback)((property) => {
|
|
1666
2080
|
setField(void 0);
|
|
1667
2081
|
projection.showFieldProjection(property);
|
|
1668
2082
|
}, [
|
|
1669
2083
|
projection
|
|
1670
2084
|
]);
|
|
1671
|
-
return /* @__PURE__ */
|
|
2085
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1672
2086
|
role: "none",
|
|
1673
2087
|
className: (0, import_react_ui_theme10.mx)("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1674
|
-
}, /* @__PURE__ */
|
|
2088
|
+
}, /* @__PURE__ */ import_react18.default.createElement(Form, {
|
|
1675
2089
|
autoSave: true,
|
|
1676
2090
|
schema: ViewMetaSchema,
|
|
1677
2091
|
values: viewValues,
|
|
1678
2092
|
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
1679
2093
|
classNames: "min-bs-0 overflow-y-auto"
|
|
1680
|
-
}), /* @__PURE__ */
|
|
2094
|
+
}), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1681
2095
|
role: "none",
|
|
1682
2096
|
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
1683
|
-
}, /* @__PURE__ */
|
|
2097
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1684
2098
|
role: "none",
|
|
1685
2099
|
className: "p-2"
|
|
1686
|
-
}, /* @__PURE__ */
|
|
2100
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1687
2101
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1688
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
2102
|
+
}, t("fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1689
2103
|
items: view.fields,
|
|
1690
|
-
isItem:
|
|
2104
|
+
isItem: import_effect12.Schema.is(import_schema5.FieldSchema),
|
|
1691
2105
|
getId: (field2) => field2.id,
|
|
1692
2106
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1693
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
2107
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, null, showHeading && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1694
2108
|
role: "heading",
|
|
1695
2109
|
className: grid
|
|
1696
|
-
}, /* @__PURE__ */
|
|
2110
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1697
2111
|
className: "flex items-center text-sm"
|
|
1698
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
2112
|
+
}, t("field path label"))), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1699
2113
|
role: "list",
|
|
1700
2114
|
className: "flex flex-col w-full"
|
|
1701
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
2115
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1702
2116
|
key: field2.id,
|
|
1703
2117
|
item: field2,
|
|
1704
2118
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1705
|
-
}, /* @__PURE__ */
|
|
2119
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDragHandle, null), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemTitle, {
|
|
1706
2120
|
onClick: () => handleSelect(field2)
|
|
1707
|
-
}, field2.path), /* @__PURE__ */
|
|
2121
|
+
}, field2.path), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1708
2122
|
className: "flex items-center gap-2 -ml-4"
|
|
1709
|
-
}, /* @__PURE__ */
|
|
2123
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1710
2124
|
icon: "ph--eye-slash--regular",
|
|
1711
2125
|
disabled: view.fields.length <= 1,
|
|
1712
2126
|
onClick: () => handleHide(field2.id)
|
|
1713
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
2127
|
+
}), !schema.readonly && /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1714
2128
|
icon: "ph--trash--regular",
|
|
1715
2129
|
disabled: view.fields.length <= 1,
|
|
1716
2130
|
onClick: () => handleDelete(field2.id)
|
|
1717
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
2131
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react18.default.createElement("div", null, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1718
2132
|
role: "none",
|
|
1719
2133
|
className: "p-2"
|
|
1720
|
-
}, /* @__PURE__ */
|
|
2134
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1721
2135
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1722
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
2136
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1723
2137
|
items: hiddenProperties,
|
|
1724
2138
|
isItem: (item) => typeof item === "string",
|
|
1725
2139
|
getId: (property) => property
|
|
1726
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
2140
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1727
2141
|
role: "list",
|
|
1728
2142
|
className: "flex flex-col w-full"
|
|
1729
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
2143
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1730
2144
|
key: property,
|
|
1731
2145
|
item: property,
|
|
1732
2146
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1733
|
-
}, /* @__PURE__ */
|
|
2147
|
+
}, /* @__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, {
|
|
1734
2148
|
icon: "ph--eye--regular",
|
|
1735
2149
|
onClick: () => handleShow(property)
|
|
1736
|
-
}))))))), field && /* @__PURE__ */
|
|
2150
|
+
}))))))), field && /* @__PURE__ */ import_react18.default.createElement(FieldEditor, {
|
|
1737
2151
|
key: field.id,
|
|
1738
2152
|
view,
|
|
1739
2153
|
projection,
|
|
1740
2154
|
field,
|
|
1741
2155
|
registry,
|
|
1742
2156
|
onSave: handleClose
|
|
1743
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
2157
|
+
}), !readonly && !field && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1744
2158
|
className: "flex p-2 justify-center"
|
|
1745
|
-
}, /* @__PURE__ */
|
|
2159
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui12.IconButton, {
|
|
1746
2160
|
icon: "ph--plus--regular",
|
|
1747
2161
|
label: t("button add property"),
|
|
1748
2162
|
onClick: schema.readonly ? void 0 : handleAdd,
|
|
@@ -1750,269 +2164,6 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1750
2164
|
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
1751
2165
|
})));
|
|
1752
2166
|
};
|
|
1753
|
-
var parseValue = ({ type, format, value }) => {
|
|
1754
|
-
if (value === void 0 || value === null || value === "") {
|
|
1755
|
-
return void 0;
|
|
1756
|
-
}
|
|
1757
|
-
const parseScalar = (type2) => {
|
|
1758
|
-
switch (type2) {
|
|
1759
|
-
case import_echo_schema10.TypeEnum.Boolean: {
|
|
1760
|
-
if (typeof value === "string") {
|
|
1761
|
-
const lowercaseValue = value.toLowerCase();
|
|
1762
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1763
|
-
return false;
|
|
1764
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1765
|
-
return true;
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
return Boolean(value);
|
|
1769
|
-
}
|
|
1770
|
-
case import_echo_schema10.TypeEnum.Number: {
|
|
1771
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1772
|
-
const num = Number(cleaned);
|
|
1773
|
-
return Number.isNaN(num) ? null : num;
|
|
1774
|
-
}
|
|
1775
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1776
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1777
|
-
return String(value);
|
|
1778
|
-
default: {
|
|
1779
|
-
return value;
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
};
|
|
1783
|
-
if (!format) {
|
|
1784
|
-
return parseScalar(type);
|
|
1785
|
-
}
|
|
1786
|
-
switch (format) {
|
|
1787
|
-
case import_echo_schema10.FormatEnum.Boolean:
|
|
1788
|
-
return parseScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1789
|
-
case import_echo_schema10.FormatEnum.Number:
|
|
1790
|
-
case import_echo_schema10.FormatEnum.Percent:
|
|
1791
|
-
case import_echo_schema10.FormatEnum.Currency:
|
|
1792
|
-
return parseScalar(import_echo_schema10.TypeEnum.Number);
|
|
1793
|
-
case import_echo_schema10.FormatEnum.String:
|
|
1794
|
-
case import_echo_schema10.FormatEnum.Markdown: {
|
|
1795
|
-
return parseScalar(import_echo_schema10.TypeEnum.String);
|
|
1796
|
-
}
|
|
1797
|
-
case import_echo_schema10.FormatEnum.Ref:
|
|
1798
|
-
throw new Error(`unexpected format: ${import_echo_schema10.FormatEnum.Ref}`);
|
|
1799
|
-
case import_echo_schema10.FormatEnum.DateTime:
|
|
1800
|
-
case import_echo_schema10.FormatEnum.Date:
|
|
1801
|
-
case import_echo_schema10.FormatEnum.Time:
|
|
1802
|
-
case import_echo_schema10.FormatEnum.Timestamp: {
|
|
1803
|
-
const date = new Date(value);
|
|
1804
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1805
|
-
}
|
|
1806
|
-
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1807
|
-
if (typeof value === "string") {
|
|
1808
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1809
|
-
const parts = cleaned.split(",");
|
|
1810
|
-
if (parts.length === 2) {
|
|
1811
|
-
const lat = parseFloat(parts[0]);
|
|
1812
|
-
const long = parseFloat(parts[1]);
|
|
1813
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1814
|
-
return import_echo_schema10.GeoLocation.toGeoPoint({
|
|
1815
|
-
latitude: lat,
|
|
1816
|
-
longitude: long
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
return [
|
|
1822
|
-
0,
|
|
1823
|
-
0
|
|
1824
|
-
];
|
|
1825
|
-
}
|
|
1826
|
-
default: {
|
|
1827
|
-
return value;
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
|
-
var cellClassesForFieldType = ({ type, format }) => {
|
|
1832
|
-
if (!format) {
|
|
1833
|
-
switch (type) {
|
|
1834
|
-
case import_echo_schema10.TypeEnum.Number:
|
|
1835
|
-
return [
|
|
1836
|
-
"text-right",
|
|
1837
|
-
"font-mono"
|
|
1838
|
-
];
|
|
1839
|
-
case import_echo_schema10.TypeEnum.Boolean:
|
|
1840
|
-
return [
|
|
1841
|
-
"text-right",
|
|
1842
|
-
"font-mono"
|
|
1843
|
-
];
|
|
1844
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1845
|
-
return void 0;
|
|
1846
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1847
|
-
return void 0;
|
|
1848
|
-
default: {
|
|
1849
|
-
return void 0;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
switch (format) {
|
|
1854
|
-
case import_echo_schema10.FormatEnum.Markdown:
|
|
1855
|
-
return void 0;
|
|
1856
|
-
case import_echo_schema10.FormatEnum.Time:
|
|
1857
|
-
case import_echo_schema10.FormatEnum.Timestamp:
|
|
1858
|
-
case import_echo_schema10.FormatEnum.DateTime:
|
|
1859
|
-
case import_echo_schema10.FormatEnum.Date:
|
|
1860
|
-
case import_echo_schema10.FormatEnum.Duration:
|
|
1861
|
-
return [
|
|
1862
|
-
"font-mono",
|
|
1863
|
-
"text-right"
|
|
1864
|
-
];
|
|
1865
|
-
case import_echo_schema10.FormatEnum.Currency:
|
|
1866
|
-
return [
|
|
1867
|
-
"text-right"
|
|
1868
|
-
];
|
|
1869
|
-
case import_echo_schema10.FormatEnum.JSON:
|
|
1870
|
-
case import_echo_schema10.FormatEnum.DID:
|
|
1871
|
-
return [
|
|
1872
|
-
"font-mono"
|
|
1873
|
-
];
|
|
1874
|
-
default:
|
|
1875
|
-
return void 0;
|
|
1876
|
-
}
|
|
1877
|
-
};
|
|
1878
|
-
var pathNotUniqueError = (path) => ({
|
|
1879
|
-
path: "path",
|
|
1880
|
-
message: `'${path}' is already present`
|
|
1881
|
-
});
|
|
1882
|
-
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1883
|
-
const formatScalar = (type2) => {
|
|
1884
|
-
switch (type2) {
|
|
1885
|
-
case import_echo_schema11.TypeEnum.Boolean:
|
|
1886
|
-
return value.toLocaleString().toUpperCase();
|
|
1887
|
-
case import_echo_schema11.TypeEnum.Number:
|
|
1888
|
-
return value.toLocaleString(locale);
|
|
1889
|
-
case import_echo_schema11.TypeEnum.String:
|
|
1890
|
-
case import_echo_schema11.TypeEnum.Ref:
|
|
1891
|
-
return String(value);
|
|
1892
|
-
default: {
|
|
1893
|
-
return String(value);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
};
|
|
1897
|
-
if (!format) {
|
|
1898
|
-
return formatScalar(type);
|
|
1899
|
-
}
|
|
1900
|
-
switch (format) {
|
|
1901
|
-
case import_echo_schema11.FormatEnum.Boolean: {
|
|
1902
|
-
return formatScalar(import_echo_schema11.TypeEnum.Boolean);
|
|
1903
|
-
}
|
|
1904
|
-
case import_echo_schema11.FormatEnum.Number: {
|
|
1905
|
-
return formatScalar(import_echo_schema11.TypeEnum.Number);
|
|
1906
|
-
}
|
|
1907
|
-
case import_echo_schema11.FormatEnum.String:
|
|
1908
|
-
case import_echo_schema11.FormatEnum.Ref: {
|
|
1909
|
-
return formatScalar(import_echo_schema11.TypeEnum.String);
|
|
1910
|
-
}
|
|
1911
|
-
case import_echo_schema11.FormatEnum.Percent: {
|
|
1912
|
-
return `${value * 100}%`;
|
|
1913
|
-
}
|
|
1914
|
-
case import_echo_schema11.FormatEnum.Currency: {
|
|
1915
|
-
return value.toLocaleString(locale, {
|
|
1916
|
-
style: "currency",
|
|
1917
|
-
currency: "USD",
|
|
1918
|
-
minimumFractionDigits: 2,
|
|
1919
|
-
maximumFractionDigits: 2
|
|
1920
|
-
});
|
|
1921
|
-
}
|
|
1922
|
-
case import_echo_schema11.FormatEnum.Date: {
|
|
1923
|
-
try {
|
|
1924
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1925
|
-
} catch (error) {
|
|
1926
|
-
return "Invalid Date";
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
case import_echo_schema11.FormatEnum.Time: {
|
|
1930
|
-
try {
|
|
1931
|
-
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1932
|
-
} catch (error) {
|
|
1933
|
-
return "Invalid Time";
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
case import_echo_schema11.FormatEnum.DateTime: {
|
|
1937
|
-
try {
|
|
1938
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1939
|
-
} catch (error) {
|
|
1940
|
-
return "Invalid DateTime";
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
case import_echo_schema11.FormatEnum.GeoPoint: {
|
|
1944
|
-
if (value === null || value === void 0) {
|
|
1945
|
-
return "";
|
|
1946
|
-
}
|
|
1947
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1948
|
-
const { latitude, longitude } = import_echo_schema11.GeoLocation.fromGeoPoint(value);
|
|
1949
|
-
return `${latitude},${longitude}`;
|
|
1950
|
-
}
|
|
1951
|
-
return String(value);
|
|
1952
|
-
}
|
|
1953
|
-
default: {
|
|
1954
|
-
if (value === null || value === "undefined") {
|
|
1955
|
-
return "";
|
|
1956
|
-
}
|
|
1957
|
-
return String(value);
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
};
|
|
1961
|
-
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1962
|
-
const formatScalar = (type2) => {
|
|
1963
|
-
switch (type2) {
|
|
1964
|
-
case import_echo_schema11.TypeEnum.Boolean:
|
|
1965
|
-
case import_echo_schema11.TypeEnum.Number:
|
|
1966
|
-
case import_echo_schema11.TypeEnum.String:
|
|
1967
|
-
case import_echo_schema11.TypeEnum.Ref:
|
|
1968
|
-
return String(value);
|
|
1969
|
-
default:
|
|
1970
|
-
return String(value);
|
|
1971
|
-
}
|
|
1972
|
-
};
|
|
1973
|
-
if (!format) {
|
|
1974
|
-
return formatScalar(type);
|
|
1975
|
-
}
|
|
1976
|
-
switch (format) {
|
|
1977
|
-
case import_echo_schema11.FormatEnum.Boolean:
|
|
1978
|
-
case import_echo_schema11.FormatEnum.Number:
|
|
1979
|
-
case import_echo_schema11.FormatEnum.String:
|
|
1980
|
-
case import_echo_schema11.FormatEnum.Ref: {
|
|
1981
|
-
return formatScalar(type);
|
|
1982
|
-
}
|
|
1983
|
-
case import_echo_schema11.FormatEnum.Percent: {
|
|
1984
|
-
return String(value * 100);
|
|
1985
|
-
}
|
|
1986
|
-
case import_echo_schema11.FormatEnum.Currency: {
|
|
1987
|
-
return String(value);
|
|
1988
|
-
}
|
|
1989
|
-
case import_echo_schema11.FormatEnum.DateTime: {
|
|
1990
|
-
const date = new Date(value);
|
|
1991
|
-
return date.toISOString();
|
|
1992
|
-
}
|
|
1993
|
-
case import_echo_schema11.FormatEnum.Date: {
|
|
1994
|
-
const date = new Date(value);
|
|
1995
|
-
return date.toISOString().split("T")[0];
|
|
1996
|
-
}
|
|
1997
|
-
case import_echo_schema11.FormatEnum.Time: {
|
|
1998
|
-
const date = new Date(value);
|
|
1999
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
2000
|
-
}
|
|
2001
|
-
case import_echo_schema11.FormatEnum.GeoPoint: {
|
|
2002
|
-
if (value === null || value === void 0) {
|
|
2003
|
-
return "";
|
|
2004
|
-
}
|
|
2005
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
2006
|
-
const { latitude, longitude } = import_echo_schema11.GeoLocation.fromGeoPoint(value);
|
|
2007
|
-
return `${latitude},${longitude}`;
|
|
2008
|
-
}
|
|
2009
|
-
return String(value);
|
|
2010
|
-
}
|
|
2011
|
-
default: {
|
|
2012
|
-
return String(value);
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
};
|
|
2016
2167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2017
2168
|
0 && (module.exports = {
|
|
2018
2169
|
BooleanInput,
|
|
@@ -2041,14 +2192,18 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
2041
2192
|
ViewEditor,
|
|
2042
2193
|
cellClassesForFieldType,
|
|
2043
2194
|
controlItemClasses,
|
|
2195
|
+
findArrayElementType,
|
|
2044
2196
|
formatForDisplay,
|
|
2045
2197
|
formatForEditing,
|
|
2198
|
+
getRefProps,
|
|
2046
2199
|
parseValue,
|
|
2047
2200
|
pathNotUniqueError,
|
|
2048
2201
|
translations,
|
|
2049
2202
|
useForm,
|
|
2050
2203
|
useFormContext,
|
|
2051
2204
|
useFormValues,
|
|
2052
|
-
useInputProps
|
|
2205
|
+
useInputProps,
|
|
2206
|
+
useQueryRefOptions,
|
|
2207
|
+
useRefQueryLookupHandler
|
|
2053
2208
|
});
|
|
2054
2209
|
//# sourceMappingURL=index.cjs.map
|