@dxos/react-ui-form 0.8.2-main.f081794 → 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 +827 -537
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +675 -395
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +827 -537
- 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 +6 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +37 -34
- 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 +14 -11
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts +2 -2
- 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 +12 -0
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -0
- 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 +13 -17
- package/src/components/Form/Defaults.tsx +4 -1
- package/src/components/Form/Form.stories.tsx +92 -43
- package/src/components/Form/Form.tsx +7 -3
- package/src/components/Form/FormContent.tsx +90 -19
- package/src/components/Form/FormContext.tsx +13 -3
- package/src/components/Form/Input.tsx +3 -9
- package/src/components/Form/RefField.tsx +197 -0
- package/src/components/Form/custom/GeoPointInput.tsx +2 -2
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +6 -5
- package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
- 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/formatting.ts +15 -3
- 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,34 +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");
|
|
139
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
140
|
+
var import_format = require("date-fns/format");
|
|
131
141
|
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
132
|
-
var import_react15 = __toESM(require("react"));
|
|
133
142
|
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
134
|
-
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"));
|
|
147
|
+
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
148
|
+
var import_effect11 = require("@dxos/effect");
|
|
149
|
+
var import_keys2 = require("@dxos/keys");
|
|
135
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");
|
|
136
159
|
var import_react_ui_list2 = require("@dxos/react-ui-list");
|
|
137
160
|
var import_react_ui_theme10 = require("@dxos/react-ui-theme");
|
|
138
161
|
var import_schema5 = require("@dxos/schema");
|
|
139
|
-
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
140
|
-
var import_format = require("date-fns/format");
|
|
141
|
-
var import_echo_schema10 = require("@dxos/echo-schema");
|
|
142
162
|
var translationKey = "react-ui-form";
|
|
143
163
|
var translations_default = [
|
|
144
164
|
{
|
|
@@ -313,15 +333,15 @@ var InputHeader = ({ children, error }) => {
|
|
|
313
333
|
return /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
314
334
|
role: "none",
|
|
315
335
|
className: "flex justify-between items-center mb-1"
|
|
316
|
-
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.
|
|
317
|
-
asChild: true
|
|
336
|
+
}, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Trigger, {
|
|
337
|
+
asChild: true,
|
|
338
|
+
content: error,
|
|
339
|
+
side: "bottom"
|
|
318
340
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
|
|
319
341
|
icon: "ph--warning--regular",
|
|
320
342
|
size: 4,
|
|
321
343
|
classNames: import_react_ui_theme3.errorText
|
|
322
|
-
}))
|
|
323
|
-
side: "bottom"
|
|
324
|
-
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Arrow, null), error)));
|
|
344
|
+
})));
|
|
325
345
|
};
|
|
326
346
|
var GeoPointInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
327
347
|
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
@@ -638,23 +658,28 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
|
|
|
638
658
|
};
|
|
639
659
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
640
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
|
+
]);
|
|
641
666
|
return /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Root, {
|
|
642
667
|
validationValence: status
|
|
643
668
|
}, !inputOnly && /* @__PURE__ */ import_react8.default.createElement(InputHeader, {
|
|
644
669
|
error
|
|
645
670
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.Label, null, label)), /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Root, {
|
|
646
|
-
value
|
|
647
|
-
onValueChange:
|
|
671
|
+
value,
|
|
672
|
+
onValueChange: handleValueChange
|
|
648
673
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.TriggerButton, {
|
|
649
674
|
classNames: "is-full",
|
|
650
675
|
disabled,
|
|
651
676
|
placeholder
|
|
652
|
-
}), /* @__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 }) => (
|
|
653
678
|
// NOTE: Numeric values are converted to and from strings.
|
|
654
679
|
/* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Select.Option, {
|
|
655
|
-
key: String(
|
|
656
|
-
value: String(
|
|
657
|
-
}, label2 ?? String(
|
|
680
|
+
key: String(value2),
|
|
681
|
+
value: String(value2)
|
|
682
|
+
}, label2 ?? String(value2))
|
|
658
683
|
)))))), inputOnly && /* @__PURE__ */ import_react8.default.createElement(import_react_ui8.Input.DescriptionAndValidation, null, error));
|
|
659
684
|
};
|
|
660
685
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
@@ -703,7 +728,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
703
728
|
L: 93,
|
|
704
729
|
S: void 0,
|
|
705
730
|
A: [
|
|
706
|
-
"
|
|
731
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
707
732
|
""
|
|
708
733
|
]
|
|
709
734
|
});
|
|
@@ -804,7 +829,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
804
829
|
} catch (err) {
|
|
805
830
|
import_log2.log.catch(err, void 0, {
|
|
806
831
|
F: __dxlog_file,
|
|
807
|
-
L:
|
|
832
|
+
L: 213,
|
|
808
833
|
S: void 0,
|
|
809
834
|
C: (f, a) => f(...a)
|
|
810
835
|
});
|
|
@@ -875,7 +900,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
875
900
|
var createKeySet = (obj, value) => {
|
|
876
901
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
877
902
|
F: __dxlog_file,
|
|
878
|
-
L:
|
|
903
|
+
L: 275,
|
|
879
904
|
S: void 0,
|
|
880
905
|
A: [
|
|
881
906
|
"obj",
|
|
@@ -896,6 +921,71 @@ var flatMap = (errors) => {
|
|
|
896
921
|
return result;
|
|
897
922
|
}, {});
|
|
898
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
|
+
};
|
|
899
989
|
var FormContext = /* @__PURE__ */ (0, import_react11.createContext)(void 0);
|
|
900
990
|
var useFormContext = () => {
|
|
901
991
|
return (0, import_react11.useContext)(FormContext) ?? (0, import_debug.raise)(new Error("Missing FormContext"));
|
|
@@ -933,7 +1023,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
933
1023
|
const keyIsEnter = event.key === "Enter";
|
|
934
1024
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
935
1025
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
936
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
1026
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
937
1027
|
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
938
1028
|
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
939
1029
|
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
@@ -982,15 +1072,305 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
982
1072
|
onClick: handleSave
|
|
983
1073
|
})));
|
|
984
1074
|
};
|
|
985
|
-
var
|
|
1075
|
+
var parseValue = ({ type, format, value }) => {
|
|
1076
|
+
if (value === void 0 || value === null || value === "") {
|
|
1077
|
+
return void 0;
|
|
1078
|
+
}
|
|
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);
|
|
1091
|
+
}
|
|
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;
|
|
1096
|
+
}
|
|
1097
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1098
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1099
|
+
return String(value);
|
|
1100
|
+
default: {
|
|
1101
|
+
return value;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
if (!format) {
|
|
1106
|
+
return parseScalar(type);
|
|
1107
|
+
}
|
|
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
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
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";
|
|
986
1366
|
var padding = "px-2";
|
|
987
1367
|
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
988
1368
|
const { t } = (0, import_react_ui10.useTranslation)(translationKey);
|
|
989
1369
|
const { ast, name, type, title } = property;
|
|
990
|
-
const values = useFormValues(path ?? []);
|
|
1370
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
991
1371
|
(0, import_invariant2.invariant)(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
992
|
-
F:
|
|
993
|
-
L:
|
|
1372
|
+
F: __dxlog_file3,
|
|
1373
|
+
L: 39,
|
|
994
1374
|
S: void 0,
|
|
995
1375
|
A: [
|
|
996
1376
|
"Array.isArray(values)",
|
|
@@ -998,11 +1378,10 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
998
1378
|
]
|
|
999
1379
|
});
|
|
1000
1380
|
const label = title ?? (0, import_effect6.pipe)(name, import_String2.capitalize);
|
|
1001
|
-
const
|
|
1002
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
1381
|
+
const elementType = findArrayElementType(ast);
|
|
1003
1382
|
const getDefaultObjectValue = (typeNode) => {
|
|
1004
1383
|
const baseNode = (0, import_effect7.findNode)(typeNode, import_effect7.isDiscriminatedUnion);
|
|
1005
|
-
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode,
|
|
1384
|
+
const typeLiteral = baseNode ? (0, import_effect7.getDiscriminatedType)(baseNode, {}) : (0, import_effect7.findNode)(typeNode, import_effect6.SchemaAST.isTypeLiteral);
|
|
1006
1385
|
if (!typeLiteral) {
|
|
1007
1386
|
return {};
|
|
1008
1387
|
}
|
|
@@ -1011,29 +1390,19 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1011
1390
|
prop.defaultValue
|
|
1012
1391
|
]));
|
|
1013
1392
|
};
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
return getDefaultObjectValue(elementType);
|
|
1017
|
-
} else {
|
|
1018
|
-
return import_effect7.SimpleType.getDefaultValue(type);
|
|
1019
|
-
}
|
|
1020
|
-
}, [
|
|
1021
|
-
type,
|
|
1022
|
-
elementType
|
|
1023
|
-
]);
|
|
1024
|
-
const handleAdd = (0, import_react14.useCallback)(() => {
|
|
1393
|
+
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : import_effect7.SimpleType.getDefaultValue(type);
|
|
1394
|
+
const handleAdd = (0, import_react16.useCallback)(() => {
|
|
1025
1395
|
inputProps.onValueChange(type, [
|
|
1026
1396
|
...values,
|
|
1027
|
-
|
|
1397
|
+
getDefaultValue()
|
|
1028
1398
|
]);
|
|
1029
1399
|
}, [
|
|
1030
1400
|
type,
|
|
1031
1401
|
elementType,
|
|
1032
1402
|
inputProps,
|
|
1033
|
-
newValue,
|
|
1034
1403
|
values
|
|
1035
1404
|
]);
|
|
1036
|
-
const handleRemove = (0,
|
|
1405
|
+
const handleRemove = (0, import_react16.useCallback)((index) => {
|
|
1037
1406
|
const newValues = values.filter((_, i) => i !== index);
|
|
1038
1407
|
inputProps.onValueChange(type, newValues);
|
|
1039
1408
|
}, [
|
|
@@ -1044,20 +1413,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1044
1413
|
if (!elementType) {
|
|
1045
1414
|
return null;
|
|
1046
1415
|
}
|
|
1047
|
-
return /* @__PURE__ */
|
|
1416
|
+
return /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1048
1417
|
role: "none",
|
|
1049
1418
|
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1050
|
-
}, /* @__PURE__ */
|
|
1419
|
+
}, /* @__PURE__ */ import_react16.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1051
1420
|
role: "none",
|
|
1052
1421
|
className: "flex flex-col gap-1"
|
|
1053
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
1422
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1054
1423
|
key: index,
|
|
1055
1424
|
role: "none",
|
|
1056
1425
|
className: "flex items-center gap-1"
|
|
1057
|
-
}, /* @__PURE__ */
|
|
1426
|
+
}, /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1058
1427
|
role: "none",
|
|
1059
1428
|
className: "flex-1"
|
|
1060
|
-
}, /* @__PURE__ */
|
|
1429
|
+
}, /* @__PURE__ */ import_react16.default.createElement(FormField, {
|
|
1061
1430
|
property: {
|
|
1062
1431
|
...property,
|
|
1063
1432
|
array: false,
|
|
@@ -1071,26 +1440,158 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1071
1440
|
inline: true,
|
|
1072
1441
|
Custom,
|
|
1073
1442
|
lookupComponent
|
|
1074
|
-
})), /* @__PURE__ */
|
|
1443
|
+
})), /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1075
1444
|
icon: "ph--trash--regular",
|
|
1076
1445
|
iconOnly: true,
|
|
1077
1446
|
label: t("button remove"),
|
|
1078
1447
|
onClick: () => handleRemove(index)
|
|
1079
|
-
})))), /* @__PURE__ */
|
|
1448
|
+
})))), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1080
1449
|
role: "none",
|
|
1081
1450
|
className: "flex justify-between items-center plb-1"
|
|
1082
|
-
}, /* @__PURE__ */
|
|
1451
|
+
}, /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1083
1452
|
icon: "ph--plus--regular",
|
|
1084
1453
|
iconOnly: true,
|
|
1085
1454
|
label: t("button add"),
|
|
1086
1455
|
onClick: handleAdd
|
|
1087
1456
|
})));
|
|
1088
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
|
+
};
|
|
1089
1590
|
var getInputComponent = (type, format) => {
|
|
1090
1591
|
switch (format) {
|
|
1091
|
-
case
|
|
1592
|
+
case import_echo_schema10.FormatEnum.GeoPoint:
|
|
1092
1593
|
return GeoPointInput;
|
|
1093
|
-
case
|
|
1594
|
+
case import_echo_schema10.FormatEnum.Markdown:
|
|
1094
1595
|
return MarkdownInput;
|
|
1095
1596
|
}
|
|
1096
1597
|
switch (type) {
|
|
@@ -1102,20 +1603,20 @@ var getInputComponent = (type, format) => {
|
|
|
1102
1603
|
return BooleanInput;
|
|
1103
1604
|
}
|
|
1104
1605
|
};
|
|
1105
|
-
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
1606
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1106
1607
|
const inputProps = useInputProps(path);
|
|
1107
1608
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1108
|
-
const label = (0,
|
|
1609
|
+
const label = (0, import_react15.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1109
1610
|
title,
|
|
1110
1611
|
name
|
|
1111
1612
|
]);
|
|
1112
|
-
const placeholder = (0,
|
|
1613
|
+
const placeholder = (0, import_react15.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1113
1614
|
examples,
|
|
1114
1615
|
description
|
|
1115
1616
|
]);
|
|
1116
1617
|
const FoundComponent = lookupComponent?.({
|
|
1117
1618
|
prop: name,
|
|
1118
|
-
schema:
|
|
1619
|
+
schema: import_effect4.Schema.make(ast),
|
|
1119
1620
|
inputProps: {
|
|
1120
1621
|
type,
|
|
1121
1622
|
format,
|
|
@@ -1126,14 +1627,14 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1126
1627
|
}
|
|
1127
1628
|
});
|
|
1128
1629
|
if (FoundComponent) {
|
|
1129
|
-
return /* @__PURE__ */
|
|
1630
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1130
1631
|
role: "none"
|
|
1131
1632
|
}, FoundComponent);
|
|
1132
1633
|
}
|
|
1133
1634
|
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1134
1635
|
const CustomComponent = Custom?.[jsonPath];
|
|
1135
1636
|
if (CustomComponent) {
|
|
1136
|
-
return /* @__PURE__ */
|
|
1637
|
+
return /* @__PURE__ */ import_react15.default.createElement(CustomComponent, {
|
|
1137
1638
|
type,
|
|
1138
1639
|
format,
|
|
1139
1640
|
label,
|
|
@@ -1143,8 +1644,23 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1143
1644
|
...inputProps
|
|
1144
1645
|
});
|
|
1145
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
|
+
}
|
|
1146
1662
|
if (array) {
|
|
1147
|
-
return /* @__PURE__ */
|
|
1663
|
+
return /* @__PURE__ */ import_react15.default.createElement(ArrayField, {
|
|
1148
1664
|
property,
|
|
1149
1665
|
path,
|
|
1150
1666
|
inputProps,
|
|
@@ -1154,9 +1670,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1154
1670
|
}
|
|
1155
1671
|
const InputComponent = getInputComponent(type, format);
|
|
1156
1672
|
if (InputComponent) {
|
|
1157
|
-
return /* @__PURE__ */
|
|
1673
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1158
1674
|
role: "none"
|
|
1159
|
-
}, /* @__PURE__ */
|
|
1675
|
+
}, /* @__PURE__ */ import_react15.default.createElement(InputComponent, {
|
|
1160
1676
|
type,
|
|
1161
1677
|
format,
|
|
1162
1678
|
label,
|
|
@@ -1167,9 +1683,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1167
1683
|
}));
|
|
1168
1684
|
}
|
|
1169
1685
|
if (options) {
|
|
1170
|
-
return /* @__PURE__ */
|
|
1686
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1171
1687
|
role: "none"
|
|
1172
|
-
}, /* @__PURE__ */
|
|
1688
|
+
}, /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1173
1689
|
type,
|
|
1174
1690
|
format,
|
|
1175
1691
|
disabled: readonly,
|
|
@@ -1185,23 +1701,27 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1185
1701
|
}
|
|
1186
1702
|
if (type === "object") {
|
|
1187
1703
|
const baseNode = (0, import_effect5.findNode)(ast, import_effect5.isDiscriminatedUnion);
|
|
1188
|
-
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);
|
|
1189
1705
|
if (typeLiteral) {
|
|
1190
|
-
return /* @__PURE__ */
|
|
1706
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1191
1707
|
role: "none"
|
|
1192
|
-
}, !inline && /* @__PURE__ */
|
|
1193
|
-
|
|
1708
|
+
}, !inline && /* @__PURE__ */ import_react15.default.createElement("h3", {
|
|
1709
|
+
className: "text-lg mbs-2 mbe-1"
|
|
1710
|
+
}, label), /* @__PURE__ */ import_react15.default.createElement(FormFields, {
|
|
1711
|
+
schema: import_effect4.Schema.make(typeLiteral),
|
|
1194
1712
|
path,
|
|
1195
1713
|
readonly,
|
|
1196
|
-
|
|
1714
|
+
onQueryRefOptions,
|
|
1715
|
+
Custom,
|
|
1716
|
+
lookupComponent
|
|
1197
1717
|
}));
|
|
1198
1718
|
}
|
|
1199
1719
|
}
|
|
1200
1720
|
return null;
|
|
1201
1721
|
};
|
|
1202
|
-
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1722
|
+
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1203
1723
|
const values = useFormValues(path);
|
|
1204
|
-
const properties = (0,
|
|
1724
|
+
const properties = (0, import_react15.useMemo)(() => {
|
|
1205
1725
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1206
1726
|
const filtered = filter ? filter(props) : props;
|
|
1207
1727
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1211,11 +1731,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1211
1731
|
filter,
|
|
1212
1732
|
sort
|
|
1213
1733
|
]);
|
|
1214
|
-
return /* @__PURE__ */
|
|
1734
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1215
1735
|
role: "form",
|
|
1216
1736
|
className: (0, import_react_ui_theme8.mx)("flex flex-col w-full gap-2")
|
|
1217
1737
|
}, properties.map((property) => {
|
|
1218
|
-
return /* @__PURE__ */
|
|
1738
|
+
return /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1219
1739
|
key: property.name,
|
|
1220
1740
|
property,
|
|
1221
1741
|
path: [
|
|
@@ -1223,12 +1743,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1223
1743
|
property.name
|
|
1224
1744
|
],
|
|
1225
1745
|
readonly,
|
|
1746
|
+
onQueryRefOptions,
|
|
1226
1747
|
lookupComponent,
|
|
1227
1748
|
Custom
|
|
1228
1749
|
});
|
|
1229
|
-
}).filter(
|
|
1750
|
+
}).filter(import_util4.isNotFalsy));
|
|
1230
1751
|
};
|
|
1231
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1752
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1232
1753
|
const formRef = (0, import_react9.useRef)(null);
|
|
1233
1754
|
const onValid = (0, import_react9.useMemo)(() => autoSave ? onSave : void 0, [
|
|
1234
1755
|
autoSave,
|
|
@@ -1264,6 +1785,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1264
1785
|
readonly,
|
|
1265
1786
|
filter,
|
|
1266
1787
|
sort,
|
|
1788
|
+
onQueryRefOptions,
|
|
1267
1789
|
lookupComponent,
|
|
1268
1790
|
Custom
|
|
1269
1791
|
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react9.default.createElement(FormActions, {
|
|
@@ -1271,7 +1793,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1271
1793
|
readonly
|
|
1272
1794
|
})));
|
|
1273
1795
|
};
|
|
1274
|
-
var
|
|
1796
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1275
1797
|
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1276
1798
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
1277
1799
|
const [props, setProps] = (0, import_react3.useState)(projection.getFieldProjection(field.id).props);
|
|
@@ -1404,7 +1926,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1404
1926
|
import_log.log.warn("invalid format", {
|
|
1405
1927
|
props
|
|
1406
1928
|
}, {
|
|
1407
|
-
F:
|
|
1929
|
+
F: __dxlog_file4,
|
|
1408
1930
|
L: 174,
|
|
1409
1931
|
S: void 0,
|
|
1410
1932
|
C: (f, a) => f(...a)
|
|
@@ -1428,24 +1950,25 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1428
1950
|
Custom
|
|
1429
1951
|
});
|
|
1430
1952
|
};
|
|
1431
|
-
var
|
|
1953
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1432
1954
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1433
|
-
var ViewMetaSchema =
|
|
1434
|
-
name:
|
|
1435
|
-
[
|
|
1955
|
+
var ViewMetaSchema = import_effect12.Schema.Struct({
|
|
1956
|
+
name: import_effect12.Schema.String.annotations({
|
|
1957
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "View"
|
|
1436
1958
|
}),
|
|
1437
|
-
typename:
|
|
1438
|
-
[
|
|
1959
|
+
typename: import_echo_schema11.Format.URL.annotations({
|
|
1960
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "Typename"
|
|
1439
1961
|
})
|
|
1440
|
-
}).pipe(
|
|
1962
|
+
}).pipe(import_effect12.Schema.mutable);
|
|
1441
1963
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1442
|
-
const { t } = (0,
|
|
1443
|
-
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), [
|
|
1444
1966
|
schema,
|
|
1445
1967
|
view
|
|
1446
1968
|
]);
|
|
1447
|
-
const [field, setField] = (0,
|
|
1448
|
-
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)(() => {
|
|
1449
1972
|
return {
|
|
1450
1973
|
name: view.name,
|
|
1451
1974
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1455,16 +1978,16 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1455
1978
|
}, [
|
|
1456
1979
|
view
|
|
1457
1980
|
]);
|
|
1458
|
-
const handleSelect = (0,
|
|
1981
|
+
const handleSelect = (0, import_react18.useCallback)((field2) => {
|
|
1459
1982
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1460
1983
|
}, []);
|
|
1461
|
-
const handleAdd = (0,
|
|
1462
|
-
(0, import_invariant3.invariant)(!
|
|
1463
|
-
F:
|
|
1464
|
-
L:
|
|
1984
|
+
const handleAdd = (0, import_react18.useCallback)(() => {
|
|
1985
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
1986
|
+
F: __dxlog_file5,
|
|
1987
|
+
L: 78,
|
|
1465
1988
|
S: void 0,
|
|
1466
1989
|
A: [
|
|
1467
|
-
"!
|
|
1990
|
+
"!immutable",
|
|
1468
1991
|
""
|
|
1469
1992
|
]
|
|
1470
1993
|
});
|
|
@@ -1474,13 +1997,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1474
1997
|
schema,
|
|
1475
1998
|
view
|
|
1476
1999
|
]);
|
|
1477
|
-
const handleUpdate = (0,
|
|
1478
|
-
(0, import_invariant3.invariant)(!
|
|
1479
|
-
F:
|
|
1480
|
-
L:
|
|
2000
|
+
const handleUpdate = (0, import_react18.useCallback)(({ name, typename }) => {
|
|
2001
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2002
|
+
F: __dxlog_file5,
|
|
2003
|
+
L: 85,
|
|
1481
2004
|
S: void 0,
|
|
1482
2005
|
A: [
|
|
1483
|
-
"!
|
|
2006
|
+
"!immutable",
|
|
1484
2007
|
""
|
|
1485
2008
|
]
|
|
1486
2009
|
});
|
|
@@ -1497,13 +2020,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1497
2020
|
view,
|
|
1498
2021
|
onTypenameChanged
|
|
1499
2022
|
]);
|
|
1500
|
-
const handleDelete = (0,
|
|
1501
|
-
(0, import_invariant3.invariant)(!
|
|
1502
|
-
F:
|
|
1503
|
-
L:
|
|
2023
|
+
const handleDelete = (0, import_react18.useCallback)((fieldId) => {
|
|
2024
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2025
|
+
F: __dxlog_file5,
|
|
2026
|
+
L: 101,
|
|
1504
2027
|
S: void 0,
|
|
1505
2028
|
A: [
|
|
1506
|
-
"!
|
|
2029
|
+
"!immutable",
|
|
1507
2030
|
""
|
|
1508
2031
|
]
|
|
1509
2032
|
});
|
|
@@ -1516,13 +2039,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1516
2039
|
field,
|
|
1517
2040
|
onDelete
|
|
1518
2041
|
]);
|
|
1519
|
-
const handleMove = (0,
|
|
1520
|
-
(0, import_invariant3.invariant)(!
|
|
1521
|
-
F:
|
|
1522
|
-
L:
|
|
2042
|
+
const handleMove = (0, import_react18.useCallback)((fromIndex, toIndex) => {
|
|
2043
|
+
(0, import_invariant3.invariant)(!immutable, void 0, {
|
|
2044
|
+
F: __dxlog_file5,
|
|
2045
|
+
L: 113,
|
|
1523
2046
|
S: void 0,
|
|
1524
2047
|
A: [
|
|
1525
|
-
"!
|
|
2048
|
+
"!immutable",
|
|
1526
2049
|
""
|
|
1527
2050
|
]
|
|
1528
2051
|
});
|
|
@@ -1536,349 +2059,102 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1536
2059
|
schema,
|
|
1537
2060
|
view.fields
|
|
1538
2061
|
]);
|
|
1539
|
-
const handleClose = (0,
|
|
2062
|
+
const handleClose = (0, import_react18.useCallback)(() => setField(void 0), []);
|
|
1540
2063
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1541
|
-
const handleHide = (0,
|
|
2064
|
+
const handleHide = (0, import_react18.useCallback)((fieldId) => {
|
|
1542
2065
|
setField(void 0);
|
|
1543
2066
|
projection.hideFieldProjection(fieldId);
|
|
1544
2067
|
}, [
|
|
1545
2068
|
projection
|
|
1546
2069
|
]);
|
|
1547
|
-
const handleShow = (0,
|
|
2070
|
+
const handleShow = (0, import_react18.useCallback)((property) => {
|
|
1548
2071
|
setField(void 0);
|
|
1549
2072
|
projection.showFieldProjection(property);
|
|
1550
2073
|
}, [
|
|
1551
2074
|
projection
|
|
1552
2075
|
]);
|
|
1553
|
-
return /* @__PURE__ */
|
|
2076
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1554
2077
|
role: "none",
|
|
1555
|
-
className: (0, import_react_ui_theme10.mx)("
|
|
1556
|
-
}, /* @__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, {
|
|
1557
2080
|
autoSave: true,
|
|
1558
2081
|
schema: ViewMetaSchema,
|
|
1559
2082
|
values: viewValues,
|
|
1560
|
-
onSave:
|
|
1561
|
-
|
|
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", {
|
|
1562
2089
|
role: "none",
|
|
1563
2090
|
className: "p-2"
|
|
1564
|
-
}, /* @__PURE__ */
|
|
2091
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1565
2092
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1566
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
2093
|
+
}, t("fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1567
2094
|
items: view.fields,
|
|
1568
|
-
isItem:
|
|
2095
|
+
isItem: import_effect12.Schema.is(import_schema5.FieldSchema),
|
|
1569
2096
|
getId: (field2) => field2.id,
|
|
1570
|
-
onMove:
|
|
1571
|
-
}, ({ 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", {
|
|
1572
2099
|
role: "heading",
|
|
1573
2100
|
className: grid
|
|
1574
|
-
}, /* @__PURE__ */
|
|
2101
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1575
2102
|
className: "flex items-center text-sm"
|
|
1576
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
2103
|
+
}, t("field path label"))), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1577
2104
|
role: "list",
|
|
1578
2105
|
className: "flex flex-col w-full"
|
|
1579
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
2106
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1580
2107
|
key: field2.id,
|
|
1581
2108
|
item: field2,
|
|
1582
2109
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1583
|
-
}, /* @__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, {
|
|
1584
2111
|
onClick: () => handleSelect(field2)
|
|
1585
|
-
}, field2.path), /* @__PURE__ */
|
|
2112
|
+
}, field2.path), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1586
2113
|
className: "flex items-center gap-2 -ml-4"
|
|
1587
|
-
}, /* @__PURE__ */
|
|
2114
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1588
2115
|
icon: "ph--eye-slash--regular",
|
|
1589
2116
|
disabled: view.fields.length <= 1,
|
|
1590
2117
|
onClick: () => handleHide(field2.id)
|
|
1591
|
-
}), !
|
|
2118
|
+
}), !immutable && /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1592
2119
|
icon: "ph--trash--regular",
|
|
1593
2120
|
disabled: view.fields.length <= 1,
|
|
1594
2121
|
onClick: () => handleDelete(field2.id)
|
|
1595
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
2122
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react18.default.createElement("div", null, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1596
2123
|
role: "none",
|
|
1597
2124
|
className: "p-2"
|
|
1598
|
-
}, /* @__PURE__ */
|
|
2125
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1599
2126
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1600
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
2127
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1601
2128
|
items: hiddenProperties,
|
|
1602
2129
|
isItem: (item) => typeof item === "string",
|
|
1603
2130
|
getId: (property) => property
|
|
1604
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
2131
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1605
2132
|
role: "list",
|
|
1606
2133
|
className: "flex flex-col w-full"
|
|
1607
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
2134
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1608
2135
|
key: property,
|
|
1609
2136
|
item: property,
|
|
1610
2137
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1611
|
-
}, /* @__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, {
|
|
1612
2139
|
icon: "ph--eye--regular",
|
|
1613
2140
|
onClick: () => handleShow(property)
|
|
1614
|
-
}))))))), field && /* @__PURE__ */
|
|
2141
|
+
}))))))), field && /* @__PURE__ */ import_react18.default.createElement(FieldEditor, {
|
|
1615
2142
|
key: field.id,
|
|
1616
2143
|
view,
|
|
1617
2144
|
projection,
|
|
1618
2145
|
field,
|
|
1619
2146
|
registry,
|
|
1620
2147
|
onSave: handleClose
|
|
1621
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
2148
|
+
}), !readonly && !field && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1622
2149
|
className: "flex p-2 justify-center"
|
|
1623
|
-
}, /* @__PURE__ */
|
|
2150
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui12.IconButton, {
|
|
1624
2151
|
icon: "ph--plus--regular",
|
|
1625
2152
|
label: t("button add property"),
|
|
1626
|
-
onClick:
|
|
2153
|
+
onClick: immutable ? void 0 : handleAdd,
|
|
1627
2154
|
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
1628
2155
|
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
1629
2156
|
})));
|
|
1630
2157
|
};
|
|
1631
|
-
var parseValue = ({ type, format, value }) => {
|
|
1632
|
-
if (value === void 0 || value === null || value === "") {
|
|
1633
|
-
return void 0;
|
|
1634
|
-
}
|
|
1635
|
-
const parseScalar = (type2) => {
|
|
1636
|
-
switch (type2) {
|
|
1637
|
-
case import_echo_schema9.TypeEnum.Boolean: {
|
|
1638
|
-
if (typeof value === "string") {
|
|
1639
|
-
const lowercaseValue = value.toLowerCase();
|
|
1640
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1641
|
-
return false;
|
|
1642
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1643
|
-
return true;
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
return Boolean(value);
|
|
1647
|
-
}
|
|
1648
|
-
case import_echo_schema9.TypeEnum.Number: {
|
|
1649
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1650
|
-
const num = Number(cleaned);
|
|
1651
|
-
return Number.isNaN(num) ? null : num;
|
|
1652
|
-
}
|
|
1653
|
-
case import_echo_schema9.TypeEnum.String:
|
|
1654
|
-
case import_echo_schema9.TypeEnum.Ref:
|
|
1655
|
-
return String(value);
|
|
1656
|
-
default: {
|
|
1657
|
-
return value;
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
};
|
|
1661
|
-
if (!format) {
|
|
1662
|
-
return parseScalar(type);
|
|
1663
|
-
}
|
|
1664
|
-
switch (format) {
|
|
1665
|
-
case import_echo_schema9.FormatEnum.Boolean:
|
|
1666
|
-
return parseScalar(import_echo_schema9.TypeEnum.Boolean);
|
|
1667
|
-
case import_echo_schema9.FormatEnum.Number:
|
|
1668
|
-
case import_echo_schema9.FormatEnum.Percent:
|
|
1669
|
-
case import_echo_schema9.FormatEnum.Currency:
|
|
1670
|
-
return parseScalar(import_echo_schema9.TypeEnum.Number);
|
|
1671
|
-
case import_echo_schema9.FormatEnum.String:
|
|
1672
|
-
case import_echo_schema9.FormatEnum.Markdown: {
|
|
1673
|
-
return parseScalar(import_echo_schema9.TypeEnum.String);
|
|
1674
|
-
}
|
|
1675
|
-
case import_echo_schema9.FormatEnum.Ref:
|
|
1676
|
-
throw new Error(`unexpected format: ${import_echo_schema9.FormatEnum.Ref}`);
|
|
1677
|
-
case import_echo_schema9.FormatEnum.DateTime:
|
|
1678
|
-
case import_echo_schema9.FormatEnum.Date:
|
|
1679
|
-
case import_echo_schema9.FormatEnum.Time:
|
|
1680
|
-
case import_echo_schema9.FormatEnum.Timestamp: {
|
|
1681
|
-
const date = new Date(value);
|
|
1682
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1683
|
-
}
|
|
1684
|
-
case import_echo_schema9.FormatEnum.GeoPoint: {
|
|
1685
|
-
if (typeof value === "string") {
|
|
1686
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1687
|
-
const parts = cleaned.split(",");
|
|
1688
|
-
if (parts.length === 2) {
|
|
1689
|
-
const lat = parseFloat(parts[0]);
|
|
1690
|
-
const long = parseFloat(parts[1]);
|
|
1691
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1692
|
-
return import_echo_schema9.GeoLocation.toGeoPoint({
|
|
1693
|
-
latitude: lat,
|
|
1694
|
-
longitude: long
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
return [
|
|
1700
|
-
0,
|
|
1701
|
-
0
|
|
1702
|
-
];
|
|
1703
|
-
}
|
|
1704
|
-
default: {
|
|
1705
|
-
return value;
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
};
|
|
1709
|
-
var cellClassesForFieldType = ({ type, format }) => {
|
|
1710
|
-
if (!format) {
|
|
1711
|
-
switch (type) {
|
|
1712
|
-
case import_echo_schema9.TypeEnum.Number:
|
|
1713
|
-
return [
|
|
1714
|
-
"text-right",
|
|
1715
|
-
"font-mono"
|
|
1716
|
-
];
|
|
1717
|
-
case import_echo_schema9.TypeEnum.Boolean:
|
|
1718
|
-
return [
|
|
1719
|
-
"text-right",
|
|
1720
|
-
"font-mono"
|
|
1721
|
-
];
|
|
1722
|
-
case import_echo_schema9.TypeEnum.String:
|
|
1723
|
-
return void 0;
|
|
1724
|
-
case import_echo_schema9.TypeEnum.Ref:
|
|
1725
|
-
return void 0;
|
|
1726
|
-
default: {
|
|
1727
|
-
return void 0;
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
switch (format) {
|
|
1732
|
-
case import_echo_schema9.FormatEnum.Markdown:
|
|
1733
|
-
return void 0;
|
|
1734
|
-
case import_echo_schema9.FormatEnum.Time:
|
|
1735
|
-
case import_echo_schema9.FormatEnum.Timestamp:
|
|
1736
|
-
case import_echo_schema9.FormatEnum.DateTime:
|
|
1737
|
-
case import_echo_schema9.FormatEnum.Date:
|
|
1738
|
-
case import_echo_schema9.FormatEnum.Duration:
|
|
1739
|
-
return [
|
|
1740
|
-
"font-mono",
|
|
1741
|
-
"text-right"
|
|
1742
|
-
];
|
|
1743
|
-
case import_echo_schema9.FormatEnum.Currency:
|
|
1744
|
-
return [
|
|
1745
|
-
"text-right"
|
|
1746
|
-
];
|
|
1747
|
-
case import_echo_schema9.FormatEnum.JSON:
|
|
1748
|
-
case import_echo_schema9.FormatEnum.DID:
|
|
1749
|
-
return [
|
|
1750
|
-
"font-mono"
|
|
1751
|
-
];
|
|
1752
|
-
default:
|
|
1753
|
-
return void 0;
|
|
1754
|
-
}
|
|
1755
|
-
};
|
|
1756
|
-
var pathNotUniqueError = (path) => ({
|
|
1757
|
-
path: "path",
|
|
1758
|
-
message: `'${path}' is already present`
|
|
1759
|
-
});
|
|
1760
|
-
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1761
|
-
const formatScalar = (type2) => {
|
|
1762
|
-
switch (type2) {
|
|
1763
|
-
case import_echo_schema10.TypeEnum.Boolean:
|
|
1764
|
-
return value.toLocaleString().toUpperCase();
|
|
1765
|
-
case import_echo_schema10.TypeEnum.Number:
|
|
1766
|
-
return value.toLocaleString(locale);
|
|
1767
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1768
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1769
|
-
return String(value);
|
|
1770
|
-
default: {
|
|
1771
|
-
return String(value);
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
};
|
|
1775
|
-
if (!format) {
|
|
1776
|
-
return formatScalar(type);
|
|
1777
|
-
}
|
|
1778
|
-
switch (format) {
|
|
1779
|
-
case import_echo_schema10.FormatEnum.Boolean: {
|
|
1780
|
-
return formatScalar(import_echo_schema10.TypeEnum.Boolean);
|
|
1781
|
-
}
|
|
1782
|
-
case import_echo_schema10.FormatEnum.Number: {
|
|
1783
|
-
return formatScalar(import_echo_schema10.TypeEnum.Number);
|
|
1784
|
-
}
|
|
1785
|
-
case import_echo_schema10.FormatEnum.String:
|
|
1786
|
-
case import_echo_schema10.FormatEnum.Ref: {
|
|
1787
|
-
return formatScalar(import_echo_schema10.TypeEnum.String);
|
|
1788
|
-
}
|
|
1789
|
-
case import_echo_schema10.FormatEnum.Percent: {
|
|
1790
|
-
return `${value * 100}%`;
|
|
1791
|
-
}
|
|
1792
|
-
case import_echo_schema10.FormatEnum.Currency: {
|
|
1793
|
-
return value.toLocaleString(locale, {
|
|
1794
|
-
style: "currency",
|
|
1795
|
-
currency: "USD",
|
|
1796
|
-
minimumFractionDigits: 2,
|
|
1797
|
-
maximumFractionDigits: 2
|
|
1798
|
-
});
|
|
1799
|
-
}
|
|
1800
|
-
case import_echo_schema10.FormatEnum.Date: {
|
|
1801
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd");
|
|
1802
|
-
}
|
|
1803
|
-
case import_echo_schema10.FormatEnum.Time: {
|
|
1804
|
-
return (0, import_format.format)(new Date(value), "HH:mm:ss");
|
|
1805
|
-
}
|
|
1806
|
-
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1807
|
-
return (0, import_format.format)(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1808
|
-
}
|
|
1809
|
-
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1810
|
-
if (value === null || value === void 0) {
|
|
1811
|
-
return "";
|
|
1812
|
-
}
|
|
1813
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1814
|
-
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1815
|
-
return `${latitude},${longitude}`;
|
|
1816
|
-
}
|
|
1817
|
-
return String(value);
|
|
1818
|
-
}
|
|
1819
|
-
default: {
|
|
1820
|
-
if (value === null || value === "undefined") {
|
|
1821
|
-
return "";
|
|
1822
|
-
}
|
|
1823
|
-
return String(value);
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
};
|
|
1827
|
-
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1828
|
-
const formatScalar = (type2) => {
|
|
1829
|
-
switch (type2) {
|
|
1830
|
-
case import_echo_schema10.TypeEnum.Boolean:
|
|
1831
|
-
case import_echo_schema10.TypeEnum.Number:
|
|
1832
|
-
case import_echo_schema10.TypeEnum.String:
|
|
1833
|
-
case import_echo_schema10.TypeEnum.Ref:
|
|
1834
|
-
return String(value);
|
|
1835
|
-
default:
|
|
1836
|
-
return String(value);
|
|
1837
|
-
}
|
|
1838
|
-
};
|
|
1839
|
-
if (!format) {
|
|
1840
|
-
return formatScalar(type);
|
|
1841
|
-
}
|
|
1842
|
-
switch (format) {
|
|
1843
|
-
case import_echo_schema10.FormatEnum.Boolean:
|
|
1844
|
-
case import_echo_schema10.FormatEnum.Number:
|
|
1845
|
-
case import_echo_schema10.FormatEnum.String:
|
|
1846
|
-
case import_echo_schema10.FormatEnum.Ref: {
|
|
1847
|
-
return formatScalar(type);
|
|
1848
|
-
}
|
|
1849
|
-
case import_echo_schema10.FormatEnum.Percent: {
|
|
1850
|
-
return String(value * 100);
|
|
1851
|
-
}
|
|
1852
|
-
case import_echo_schema10.FormatEnum.Currency: {
|
|
1853
|
-
return String(value);
|
|
1854
|
-
}
|
|
1855
|
-
case import_echo_schema10.FormatEnum.DateTime: {
|
|
1856
|
-
const date = new Date(value);
|
|
1857
|
-
return date.toISOString();
|
|
1858
|
-
}
|
|
1859
|
-
case import_echo_schema10.FormatEnum.Date: {
|
|
1860
|
-
const date = new Date(value);
|
|
1861
|
-
return date.toISOString().split("T")[0];
|
|
1862
|
-
}
|
|
1863
|
-
case import_echo_schema10.FormatEnum.Time: {
|
|
1864
|
-
const date = new Date(value);
|
|
1865
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
1866
|
-
}
|
|
1867
|
-
case import_echo_schema10.FormatEnum.GeoPoint: {
|
|
1868
|
-
if (value === null || value === void 0) {
|
|
1869
|
-
return "";
|
|
1870
|
-
}
|
|
1871
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1872
|
-
const { latitude, longitude } = import_echo_schema10.GeoLocation.fromGeoPoint(value);
|
|
1873
|
-
return `${latitude},${longitude}`;
|
|
1874
|
-
}
|
|
1875
|
-
return String(value);
|
|
1876
|
-
}
|
|
1877
|
-
default: {
|
|
1878
|
-
return String(value);
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
};
|
|
1882
2158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1883
2159
|
0 && (module.exports = {
|
|
1884
2160
|
BooleanInput,
|
|
@@ -1907,14 +2183,18 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1907
2183
|
ViewEditor,
|
|
1908
2184
|
cellClassesForFieldType,
|
|
1909
2185
|
controlItemClasses,
|
|
2186
|
+
findArrayElementType,
|
|
1910
2187
|
formatForDisplay,
|
|
1911
2188
|
formatForEditing,
|
|
2189
|
+
getRefProps,
|
|
1912
2190
|
parseValue,
|
|
1913
2191
|
pathNotUniqueError,
|
|
1914
2192
|
translations,
|
|
1915
2193
|
useForm,
|
|
1916
2194
|
useFormContext,
|
|
1917
2195
|
useFormValues,
|
|
1918
|
-
useInputProps
|
|
2196
|
+
useInputProps,
|
|
2197
|
+
useQueryRefOptions,
|
|
2198
|
+
useRefQueryLookupHandler
|
|
1919
2199
|
});
|
|
1920
2200
|
//# sourceMappingURL=index.cjs.map
|