@dxos/react-ui-form 0.8.2-main.12df754 → 0.8.2-main.30e4dbb
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 +823 -524
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +661 -372
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +823 -524
- 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.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 +8 -7
- 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 +4 -3
- package/src/components/ViewEditor/ViewEditor.tsx +12 -10
- 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/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
|
});
|
|
@@ -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,7 +1390,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1011
1390
|
prop.defaultValue
|
|
1012
1391
|
]));
|
|
1013
1392
|
};
|
|
1014
|
-
const newValue = (0,
|
|
1393
|
+
const newValue = (0, import_react16.useMemo)(() => {
|
|
1015
1394
|
if (type === "object" && elementType) {
|
|
1016
1395
|
return getDefaultObjectValue(elementType);
|
|
1017
1396
|
} else {
|
|
@@ -1021,7 +1400,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1021
1400
|
type,
|
|
1022
1401
|
elementType
|
|
1023
1402
|
]);
|
|
1024
|
-
const handleAdd = (0,
|
|
1403
|
+
const handleAdd = (0, import_react16.useCallback)(() => {
|
|
1025
1404
|
inputProps.onValueChange(type, [
|
|
1026
1405
|
...values,
|
|
1027
1406
|
newValue
|
|
@@ -1033,7 +1412,7 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1033
1412
|
newValue,
|
|
1034
1413
|
values
|
|
1035
1414
|
]);
|
|
1036
|
-
const handleRemove = (0,
|
|
1415
|
+
const handleRemove = (0, import_react16.useCallback)((index) => {
|
|
1037
1416
|
const newValues = values.filter((_, i) => i !== index);
|
|
1038
1417
|
inputProps.onValueChange(type, newValues);
|
|
1039
1418
|
}, [
|
|
@@ -1044,20 +1423,20 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1044
1423
|
if (!elementType) {
|
|
1045
1424
|
return null;
|
|
1046
1425
|
}
|
|
1047
|
-
return /* @__PURE__ */
|
|
1426
|
+
return /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1048
1427
|
role: "none",
|
|
1049
1428
|
className: (0, import_react_ui_theme9.mx)(padding)
|
|
1050
|
-
}, /* @__PURE__ */
|
|
1429
|
+
}, /* @__PURE__ */ import_react16.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1051
1430
|
role: "none",
|
|
1052
1431
|
className: "flex flex-col gap-1"
|
|
1053
|
-
}, values.map((_value, index) => /* @__PURE__ */
|
|
1432
|
+
}, values.map((_value, index) => /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1054
1433
|
key: index,
|
|
1055
1434
|
role: "none",
|
|
1056
1435
|
className: "flex items-center gap-1"
|
|
1057
|
-
}, /* @__PURE__ */
|
|
1436
|
+
}, /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1058
1437
|
role: "none",
|
|
1059
1438
|
className: "flex-1"
|
|
1060
|
-
}, /* @__PURE__ */
|
|
1439
|
+
}, /* @__PURE__ */ import_react16.default.createElement(FormField, {
|
|
1061
1440
|
property: {
|
|
1062
1441
|
...property,
|
|
1063
1442
|
array: false,
|
|
@@ -1071,26 +1450,158 @@ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponen
|
|
|
1071
1450
|
inline: true,
|
|
1072
1451
|
Custom,
|
|
1073
1452
|
lookupComponent
|
|
1074
|
-
})), /* @__PURE__ */
|
|
1453
|
+
})), /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1075
1454
|
icon: "ph--trash--regular",
|
|
1076
1455
|
iconOnly: true,
|
|
1077
1456
|
label: t("button remove"),
|
|
1078
1457
|
onClick: () => handleRemove(index)
|
|
1079
|
-
})))), /* @__PURE__ */
|
|
1458
|
+
})))), /* @__PURE__ */ import_react16.default.createElement("div", {
|
|
1080
1459
|
role: "none",
|
|
1081
1460
|
className: "flex justify-between items-center plb-1"
|
|
1082
|
-
}, /* @__PURE__ */
|
|
1461
|
+
}, /* @__PURE__ */ import_react16.default.createElement(import_react_ui10.IconButton, {
|
|
1083
1462
|
icon: "ph--plus--regular",
|
|
1084
1463
|
iconOnly: true,
|
|
1085
1464
|
label: t("button add"),
|
|
1086
1465
|
onClick: handleAdd
|
|
1087
1466
|
})));
|
|
1088
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
|
+
};
|
|
1089
1600
|
var getInputComponent = (type, format) => {
|
|
1090
1601
|
switch (format) {
|
|
1091
|
-
case
|
|
1602
|
+
case import_echo_schema10.FormatEnum.GeoPoint:
|
|
1092
1603
|
return GeoPointInput;
|
|
1093
|
-
case
|
|
1604
|
+
case import_echo_schema10.FormatEnum.Markdown:
|
|
1094
1605
|
return MarkdownInput;
|
|
1095
1606
|
}
|
|
1096
1607
|
switch (type) {
|
|
@@ -1102,20 +1613,20 @@ var getInputComponent = (type, format) => {
|
|
|
1102
1613
|
return BooleanInput;
|
|
1103
1614
|
}
|
|
1104
1615
|
};
|
|
1105
|
-
var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
|
|
1616
|
+
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1106
1617
|
const inputProps = useInputProps(path);
|
|
1107
1618
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
1108
|
-
const label = (0,
|
|
1619
|
+
const label = (0, import_react15.useMemo)(() => title ?? (0, import_effect4.pipe)(name, import_String.capitalize), [
|
|
1109
1620
|
title,
|
|
1110
1621
|
name
|
|
1111
1622
|
]);
|
|
1112
|
-
const placeholder = (0,
|
|
1623
|
+
const placeholder = (0, import_react15.useMemo)(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1113
1624
|
examples,
|
|
1114
1625
|
description
|
|
1115
1626
|
]);
|
|
1116
1627
|
const FoundComponent = lookupComponent?.({
|
|
1117
1628
|
prop: name,
|
|
1118
|
-
schema:
|
|
1629
|
+
schema: import_effect4.Schema.make(ast),
|
|
1119
1630
|
inputProps: {
|
|
1120
1631
|
type,
|
|
1121
1632
|
format,
|
|
@@ -1126,14 +1637,14 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1126
1637
|
}
|
|
1127
1638
|
});
|
|
1128
1639
|
if (FoundComponent) {
|
|
1129
|
-
return /* @__PURE__ */
|
|
1640
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1130
1641
|
role: "none"
|
|
1131
1642
|
}, FoundComponent);
|
|
1132
1643
|
}
|
|
1133
1644
|
const jsonPath = (0, import_effect5.createJsonPath)(path ?? []);
|
|
1134
1645
|
const CustomComponent = Custom?.[jsonPath];
|
|
1135
1646
|
if (CustomComponent) {
|
|
1136
|
-
return /* @__PURE__ */
|
|
1647
|
+
return /* @__PURE__ */ import_react15.default.createElement(CustomComponent, {
|
|
1137
1648
|
type,
|
|
1138
1649
|
format,
|
|
1139
1650
|
label,
|
|
@@ -1143,8 +1654,23 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1143
1654
|
...inputProps
|
|
1144
1655
|
});
|
|
1145
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
|
+
}
|
|
1146
1672
|
if (array) {
|
|
1147
|
-
return /* @__PURE__ */
|
|
1673
|
+
return /* @__PURE__ */ import_react15.default.createElement(ArrayField, {
|
|
1148
1674
|
property,
|
|
1149
1675
|
path,
|
|
1150
1676
|
inputProps,
|
|
@@ -1154,9 +1680,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1154
1680
|
}
|
|
1155
1681
|
const InputComponent = getInputComponent(type, format);
|
|
1156
1682
|
if (InputComponent) {
|
|
1157
|
-
return /* @__PURE__ */
|
|
1683
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1158
1684
|
role: "none"
|
|
1159
|
-
}, /* @__PURE__ */
|
|
1685
|
+
}, /* @__PURE__ */ import_react15.default.createElement(InputComponent, {
|
|
1160
1686
|
type,
|
|
1161
1687
|
format,
|
|
1162
1688
|
label,
|
|
@@ -1167,9 +1693,9 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1167
1693
|
}));
|
|
1168
1694
|
}
|
|
1169
1695
|
if (options) {
|
|
1170
|
-
return /* @__PURE__ */
|
|
1696
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1171
1697
|
role: "none"
|
|
1172
|
-
}, /* @__PURE__ */
|
|
1698
|
+
}, /* @__PURE__ */ import_react15.default.createElement(SelectInput, {
|
|
1173
1699
|
type,
|
|
1174
1700
|
format,
|
|
1175
1701
|
disabled: readonly,
|
|
@@ -1185,23 +1711,27 @@ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom })
|
|
|
1185
1711
|
}
|
|
1186
1712
|
if (type === "object") {
|
|
1187
1713
|
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,
|
|
1714
|
+
const typeLiteral = baseNode ? (0, import_effect5.getDiscriminatedType)(baseNode, inputProps.getValue()) : (0, import_effect5.findNode)(ast, import_effect4.SchemaAST.isTypeLiteral);
|
|
1189
1715
|
if (typeLiteral) {
|
|
1190
|
-
return /* @__PURE__ */
|
|
1716
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1191
1717
|
role: "none"
|
|
1192
|
-
}, !inline && /* @__PURE__ */
|
|
1193
|
-
|
|
1718
|
+
}, !inline && /* @__PURE__ */ import_react15.default.createElement("h3", {
|
|
1719
|
+
className: "text-lg mbs-2 mbe-1"
|
|
1720
|
+
}, label), /* @__PURE__ */ import_react15.default.createElement(FormFields, {
|
|
1721
|
+
schema: import_effect4.Schema.make(typeLiteral),
|
|
1194
1722
|
path,
|
|
1195
1723
|
readonly,
|
|
1196
|
-
|
|
1724
|
+
onQueryRefOptions,
|
|
1725
|
+
Custom,
|
|
1726
|
+
lookupComponent
|
|
1197
1727
|
}));
|
|
1198
1728
|
}
|
|
1199
1729
|
}
|
|
1200
1730
|
return null;
|
|
1201
1731
|
};
|
|
1202
|
-
var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
|
|
1732
|
+
var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1203
1733
|
const values = useFormValues(path);
|
|
1204
|
-
const properties = (0,
|
|
1734
|
+
const properties = (0, import_react15.useMemo)(() => {
|
|
1205
1735
|
const props = (0, import_schema3.getSchemaProperties)(schema.ast, values);
|
|
1206
1736
|
const filtered = filter ? filter(props) : props;
|
|
1207
1737
|
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
@@ -1211,11 +1741,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1211
1741
|
filter,
|
|
1212
1742
|
sort
|
|
1213
1743
|
]);
|
|
1214
|
-
return /* @__PURE__ */
|
|
1744
|
+
return /* @__PURE__ */ import_react15.default.createElement("div", {
|
|
1215
1745
|
role: "form",
|
|
1216
1746
|
className: (0, import_react_ui_theme8.mx)("flex flex-col w-full gap-2")
|
|
1217
1747
|
}, properties.map((property) => {
|
|
1218
|
-
return /* @__PURE__ */
|
|
1748
|
+
return /* @__PURE__ */ import_react15.default.createElement(FormField, {
|
|
1219
1749
|
key: property.name,
|
|
1220
1750
|
property,
|
|
1221
1751
|
path: [
|
|
@@ -1223,12 +1753,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custo
|
|
|
1223
1753
|
property.name
|
|
1224
1754
|
],
|
|
1225
1755
|
readonly,
|
|
1756
|
+
onQueryRefOptions,
|
|
1226
1757
|
lookupComponent,
|
|
1227
1758
|
Custom
|
|
1228
1759
|
});
|
|
1229
|
-
}).filter(
|
|
1760
|
+
}).filter(import_util4.isNotFalsy));
|
|
1230
1761
|
};
|
|
1231
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
1762
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1232
1763
|
const formRef = (0, import_react9.useRef)(null);
|
|
1233
1764
|
const onValid = (0, import_react9.useMemo)(() => autoSave ? onSave : void 0, [
|
|
1234
1765
|
autoSave,
|
|
@@ -1264,6 +1795,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1264
1795
|
readonly,
|
|
1265
1796
|
filter,
|
|
1266
1797
|
sort,
|
|
1798
|
+
onQueryRefOptions,
|
|
1267
1799
|
lookupComponent,
|
|
1268
1800
|
Custom
|
|
1269
1801
|
}), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react9.default.createElement(FormActions, {
|
|
@@ -1271,7 +1803,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
|
|
|
1271
1803
|
readonly
|
|
1272
1804
|
})));
|
|
1273
1805
|
};
|
|
1274
|
-
var
|
|
1806
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1275
1807
|
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
1276
1808
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
1277
1809
|
const [props, setProps] = (0, import_react3.useState)(projection.getFieldProjection(field.id).props);
|
|
@@ -1404,7 +1936,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1404
1936
|
import_log.log.warn("invalid format", {
|
|
1405
1937
|
props
|
|
1406
1938
|
}, {
|
|
1407
|
-
F:
|
|
1939
|
+
F: __dxlog_file4,
|
|
1408
1940
|
L: 174,
|
|
1409
1941
|
S: void 0,
|
|
1410
1942
|
C: (f, a) => f(...a)
|
|
@@ -1428,24 +1960,24 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1428
1960
|
Custom
|
|
1429
1961
|
});
|
|
1430
1962
|
};
|
|
1431
|
-
var
|
|
1963
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1432
1964
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1433
|
-
var ViewMetaSchema =
|
|
1434
|
-
name:
|
|
1435
|
-
[
|
|
1965
|
+
var ViewMetaSchema = import_effect12.Schema.Struct({
|
|
1966
|
+
name: import_effect12.Schema.String.annotations({
|
|
1967
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "View"
|
|
1436
1968
|
}),
|
|
1437
|
-
typename:
|
|
1438
|
-
[
|
|
1969
|
+
typename: import_echo_schema11.Format.URL.annotations({
|
|
1970
|
+
[import_effect12.SchemaAST.TitleAnnotationId]: "Typename"
|
|
1439
1971
|
})
|
|
1440
|
-
}).pipe(
|
|
1972
|
+
}).pipe(import_effect12.Schema.mutable);
|
|
1441
1973
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1442
|
-
const { t } = (0,
|
|
1443
|
-
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), [
|
|
1444
1976
|
schema,
|
|
1445
1977
|
view
|
|
1446
1978
|
]);
|
|
1447
|
-
const [field, setField] = (0,
|
|
1448
|
-
const viewValues = (0,
|
|
1979
|
+
const [field, setField] = (0, import_react18.useState)();
|
|
1980
|
+
const viewValues = (0, import_react18.useMemo)(() => {
|
|
1449
1981
|
return {
|
|
1450
1982
|
name: view.name,
|
|
1451
1983
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -1455,13 +1987,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1455
1987
|
}, [
|
|
1456
1988
|
view
|
|
1457
1989
|
]);
|
|
1458
|
-
const handleSelect = (0,
|
|
1990
|
+
const handleSelect = (0, import_react18.useCallback)((field2) => {
|
|
1459
1991
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1460
1992
|
}, []);
|
|
1461
|
-
const handleAdd = (0,
|
|
1993
|
+
const handleAdd = (0, import_react18.useCallback)(() => {
|
|
1462
1994
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1463
|
-
F:
|
|
1464
|
-
L:
|
|
1995
|
+
F: __dxlog_file5,
|
|
1996
|
+
L: 77,
|
|
1465
1997
|
S: void 0,
|
|
1466
1998
|
A: [
|
|
1467
1999
|
"!schema.readonly",
|
|
@@ -1474,10 +2006,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1474
2006
|
schema,
|
|
1475
2007
|
view
|
|
1476
2008
|
]);
|
|
1477
|
-
const handleUpdate = (0,
|
|
2009
|
+
const handleUpdate = (0, import_react18.useCallback)(({ name, typename }) => {
|
|
1478
2010
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1479
|
-
F:
|
|
1480
|
-
L:
|
|
2011
|
+
F: __dxlog_file5,
|
|
2012
|
+
L: 84,
|
|
1481
2013
|
S: void 0,
|
|
1482
2014
|
A: [
|
|
1483
2015
|
"!schema.readonly",
|
|
@@ -1497,10 +2029,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1497
2029
|
view,
|
|
1498
2030
|
onTypenameChanged
|
|
1499
2031
|
]);
|
|
1500
|
-
const handleDelete = (0,
|
|
2032
|
+
const handleDelete = (0, import_react18.useCallback)((fieldId) => {
|
|
1501
2033
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1502
|
-
F:
|
|
1503
|
-
L:
|
|
2034
|
+
F: __dxlog_file5,
|
|
2035
|
+
L: 100,
|
|
1504
2036
|
S: void 0,
|
|
1505
2037
|
A: [
|
|
1506
2038
|
"!schema.readonly",
|
|
@@ -1516,10 +2048,10 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1516
2048
|
field,
|
|
1517
2049
|
onDelete
|
|
1518
2050
|
]);
|
|
1519
|
-
const handleMove = (0,
|
|
2051
|
+
const handleMove = (0, import_react18.useCallback)((fromIndex, toIndex) => {
|
|
1520
2052
|
(0, import_invariant3.invariant)(!schema.readonly, void 0, {
|
|
1521
|
-
F:
|
|
1522
|
-
L:
|
|
2053
|
+
F: __dxlog_file5,
|
|
2054
|
+
L: 112,
|
|
1523
2055
|
S: void 0,
|
|
1524
2056
|
A: [
|
|
1525
2057
|
"!schema.readonly",
|
|
@@ -1536,91 +2068,95 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1536
2068
|
schema,
|
|
1537
2069
|
view.fields
|
|
1538
2070
|
]);
|
|
1539
|
-
const handleClose = (0,
|
|
2071
|
+
const handleClose = (0, import_react18.useCallback)(() => setField(void 0), []);
|
|
1540
2072
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1541
|
-
const handleHide = (0,
|
|
2073
|
+
const handleHide = (0, import_react18.useCallback)((fieldId) => {
|
|
1542
2074
|
setField(void 0);
|
|
1543
2075
|
projection.hideFieldProjection(fieldId);
|
|
1544
2076
|
}, [
|
|
1545
2077
|
projection
|
|
1546
2078
|
]);
|
|
1547
|
-
const handleShow = (0,
|
|
2079
|
+
const handleShow = (0, import_react18.useCallback)((property) => {
|
|
1548
2080
|
setField(void 0);
|
|
1549
2081
|
projection.showFieldProjection(property);
|
|
1550
2082
|
}, [
|
|
1551
2083
|
projection
|
|
1552
2084
|
]);
|
|
1553
|
-
return /* @__PURE__ */
|
|
2085
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1554
2086
|
role: "none",
|
|
1555
|
-
className: (0, import_react_ui_theme10.mx)("
|
|
1556
|
-
}, /* @__PURE__ */
|
|
2087
|
+
className: (0, import_react_ui_theme10.mx)("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
2088
|
+
}, /* @__PURE__ */ import_react18.default.createElement(Form, {
|
|
1557
2089
|
autoSave: true,
|
|
1558
2090
|
schema: ViewMetaSchema,
|
|
1559
2091
|
values: viewValues,
|
|
1560
|
-
onSave: schema.readonly ? void 0 : handleUpdate
|
|
1561
|
-
|
|
2092
|
+
onSave: schema.readonly ? void 0 : handleUpdate,
|
|
2093
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
2094
|
+
}), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
2095
|
+
role: "none",
|
|
2096
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
2097
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1562
2098
|
role: "none",
|
|
1563
2099
|
className: "p-2"
|
|
1564
|
-
}, /* @__PURE__ */
|
|
2100
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1565
2101
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1566
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
2102
|
+
}, t("fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1567
2103
|
items: view.fields,
|
|
1568
|
-
isItem:
|
|
2104
|
+
isItem: import_effect12.Schema.is(import_schema5.FieldSchema),
|
|
1569
2105
|
getId: (field2) => field2.id,
|
|
1570
2106
|
onMove: schema.readonly ? void 0 : handleMove
|
|
1571
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
2107
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, null, showHeading && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1572
2108
|
role: "heading",
|
|
1573
2109
|
className: grid
|
|
1574
|
-
}, /* @__PURE__ */
|
|
2110
|
+
}, /* @__PURE__ */ import_react18.default.createElement("div", null), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1575
2111
|
className: "flex items-center text-sm"
|
|
1576
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
2112
|
+
}, t("field path label"))), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1577
2113
|
role: "list",
|
|
1578
2114
|
className: "flex flex-col w-full"
|
|
1579
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
2115
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1580
2116
|
key: field2.id,
|
|
1581
2117
|
item: field2,
|
|
1582
2118
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1583
|
-
}, /* @__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, {
|
|
1584
2120
|
onClick: () => handleSelect(field2)
|
|
1585
|
-
}, field2.path), /* @__PURE__ */
|
|
2121
|
+
}, field2.path), /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1586
2122
|
className: "flex items-center gap-2 -ml-4"
|
|
1587
|
-
}, /* @__PURE__ */
|
|
2123
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemButton, {
|
|
1588
2124
|
icon: "ph--eye-slash--regular",
|
|
1589
2125
|
disabled: view.fields.length <= 1,
|
|
1590
2126
|
onClick: () => handleHide(field2.id)
|
|
1591
|
-
}), !schema.readonly && /* @__PURE__ */
|
|
2127
|
+
}), !schema.readonly && /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.ItemDeleteButton, {
|
|
1592
2128
|
icon: "ph--trash--regular",
|
|
1593
2129
|
disabled: view.fields.length <= 1,
|
|
1594
2130
|
onClick: () => handleDelete(field2.id)
|
|
1595
|
-
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */
|
|
2131
|
+
}))))))), hiddenProperties.length > 0 && /* @__PURE__ */ import_react18.default.createElement("div", null, /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1596
2132
|
role: "none",
|
|
1597
2133
|
className: "p-2"
|
|
1598
|
-
}, /* @__PURE__ */
|
|
2134
|
+
}, /* @__PURE__ */ import_react18.default.createElement("label", {
|
|
1599
2135
|
className: (0, import_react_ui_theme10.mx)(import_react_ui_theme10.inputTextLabel)
|
|
1600
|
-
}, t("hidden fields label"))), /* @__PURE__ */
|
|
2136
|
+
}, t("hidden fields label"))), /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Root, {
|
|
1601
2137
|
items: hiddenProperties,
|
|
1602
2138
|
isItem: (item) => typeof item === "string",
|
|
1603
2139
|
getId: (property) => property
|
|
1604
|
-
}, ({ items: properties }) => /* @__PURE__ */
|
|
2140
|
+
}, ({ items: properties }) => /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1605
2141
|
role: "list",
|
|
1606
2142
|
className: "flex flex-col w-full"
|
|
1607
|
-
}, properties?.map((property) => /* @__PURE__ */
|
|
2143
|
+
}, properties?.map((property) => /* @__PURE__ */ import_react18.default.createElement(import_react_ui_list2.List.Item, {
|
|
1608
2144
|
key: property,
|
|
1609
2145
|
item: property,
|
|
1610
2146
|
classNames: (0, import_react_ui_theme10.mx)(grid, import_react_ui_theme10.ghostHover, "cursor-pointer")
|
|
1611
|
-
}, /* @__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, {
|
|
1612
2148
|
icon: "ph--eye--regular",
|
|
1613
2149
|
onClick: () => handleShow(property)
|
|
1614
|
-
}))))))), field && /* @__PURE__ */
|
|
2150
|
+
}))))))), field && /* @__PURE__ */ import_react18.default.createElement(FieldEditor, {
|
|
1615
2151
|
key: field.id,
|
|
1616
2152
|
view,
|
|
1617
2153
|
projection,
|
|
1618
2154
|
field,
|
|
1619
2155
|
registry,
|
|
1620
2156
|
onSave: handleClose
|
|
1621
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
2157
|
+
}), !readonly && !field && /* @__PURE__ */ import_react18.default.createElement("div", {
|
|
1622
2158
|
className: "flex p-2 justify-center"
|
|
1623
|
-
}, /* @__PURE__ */
|
|
2159
|
+
}, /* @__PURE__ */ import_react18.default.createElement(import_react_ui12.IconButton, {
|
|
1624
2160
|
icon: "ph--plus--regular",
|
|
1625
2161
|
label: t("button add property"),
|
|
1626
2162
|
onClick: schema.readonly ? void 0 : handleAdd,
|
|
@@ -1628,257 +2164,6 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1628
2164
|
disabled: view.fields.length >= import_schema5.VIEW_FIELD_LIMIT
|
|
1629
2165
|
})));
|
|
1630
2166
|
};
|
|
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
2167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1883
2168
|
0 && (module.exports = {
|
|
1884
2169
|
BooleanInput,
|
|
@@ -1907,14 +2192,18 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1907
2192
|
ViewEditor,
|
|
1908
2193
|
cellClassesForFieldType,
|
|
1909
2194
|
controlItemClasses,
|
|
2195
|
+
findArrayElementType,
|
|
1910
2196
|
formatForDisplay,
|
|
1911
2197
|
formatForEditing,
|
|
2198
|
+
getRefProps,
|
|
1912
2199
|
parseValue,
|
|
1913
2200
|
pathNotUniqueError,
|
|
1914
2201
|
translations,
|
|
1915
2202
|
useForm,
|
|
1916
2203
|
useFormContext,
|
|
1917
2204
|
useFormValues,
|
|
1918
|
-
useInputProps
|
|
2205
|
+
useInputProps,
|
|
2206
|
+
useQueryRefOptions,
|
|
2207
|
+
useRefQueryLookupHandler
|
|
1919
2208
|
});
|
|
1920
2209
|
//# sourceMappingURL=index.cjs.map
|