@dxos/react-ui-form 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +731 -573
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +748 -598
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +731 -573
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +4 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +33 -32
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContent.d.ts +3 -3
- package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/RefField.d.ts +7 -18
- package/dist/types/src/components/Form/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +1 -1
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.d.ts +2 -2
- package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +2 -2
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +23 -0
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +1 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +8 -0
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +9 -0
- package/dist/types/src/util/refs.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +3 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -25
- package/src/components/ControlSection/ControlSection.stories.tsx +1 -1
- package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
- package/src/components/Form/ArrayField.tsx +10 -16
- package/src/components/Form/Defaults.tsx +4 -1
- package/src/components/Form/Form.stories.tsx +48 -42
- package/src/components/Form/Form.tsx +4 -4
- package/src/components/Form/FormContent.tsx +49 -22
- package/src/components/Form/FormContext.tsx +3 -1
- package/src/components/Form/Input.tsx +3 -9
- package/src/components/Form/RefField.tsx +147 -101
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +6 -5
- package/src/components/Form/factory.tsx +1 -1
- package/src/components/Form/index.ts +0 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +5 -4
- package/src/components/ViewEditor/ViewEditor.tsx +23 -20
- package/src/components/deprecated/Form.tsx +6 -6
- package/src/hooks/index.ts +3 -1
- package/src/hooks/useForm.ts +4 -3
- package/src/hooks/useQueryRefOptions.ts +53 -0
- package/src/hooks/useRefQueryLookupHandler.ts +41 -0
- package/src/util/index.ts +3 -1
- package/src/util/refs.ts +38 -0
- package/src/util/schema.ts +14 -0
|
@@ -183,8 +183,8 @@ var ControlFrameItem = ({ title, description, children }) => {
|
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
186
|
-
import React14, { useCallback as
|
|
187
|
-
import { FormatEnum as
|
|
186
|
+
import React14, { useCallback as useCallback8, useEffect as useEffect8, useMemo as useMemo7, useState as useState5 } from "react";
|
|
187
|
+
import { FormatEnum as FormatEnum5, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
188
188
|
import { log as log3 } from "@dxos/log";
|
|
189
189
|
import { useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
190
190
|
import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
|
|
@@ -203,15 +203,15 @@ var InputHeader = ({ children, error }) => {
|
|
|
203
203
|
return /* @__PURE__ */ React3.createElement("div", {
|
|
204
204
|
role: "none",
|
|
205
205
|
className: "flex justify-between items-center mb-1"
|
|
206
|
-
}, children, error && /* @__PURE__ */ React3.createElement(Tooltip.
|
|
207
|
-
asChild: true
|
|
206
|
+
}, children, error && /* @__PURE__ */ React3.createElement(Tooltip.Trigger, {
|
|
207
|
+
asChild: true,
|
|
208
|
+
content: error,
|
|
209
|
+
side: "bottom"
|
|
208
210
|
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
209
211
|
icon: "ph--warning--regular",
|
|
210
212
|
size: 4,
|
|
211
213
|
classNames: errorText
|
|
212
|
-
}))
|
|
213
|
-
side: "bottom"
|
|
214
|
-
}, /* @__PURE__ */ React3.createElement(Tooltip.Arrow, null), error)));
|
|
214
|
+
})));
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
// packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
|
|
@@ -548,23 +548,28 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
|
|
|
548
548
|
};
|
|
549
549
|
var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
550
550
|
const { status, error } = getStatus();
|
|
551
|
+
const value = getValue3();
|
|
552
|
+
const handleValueChange = useCallback3((value2) => onValueChange(type, value2), [
|
|
553
|
+
type,
|
|
554
|
+
onValueChange
|
|
555
|
+
]);
|
|
551
556
|
return /* @__PURE__ */ React7.createElement(Input6.Root, {
|
|
552
557
|
validationValence: status
|
|
553
558
|
}, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
|
|
554
559
|
error
|
|
555
560
|
}, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), /* @__PURE__ */ React7.createElement(Select.Root, {
|
|
556
|
-
value
|
|
557
|
-
onValueChange:
|
|
561
|
+
value,
|
|
562
|
+
onValueChange: handleValueChange
|
|
558
563
|
}, /* @__PURE__ */ React7.createElement(Select.TriggerButton, {
|
|
559
564
|
classNames: "is-full",
|
|
560
565
|
disabled,
|
|
561
566
|
placeholder
|
|
562
|
-
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
567
|
+
}), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
|
|
563
568
|
// NOTE: Numeric values are converted to and from strings.
|
|
564
569
|
/* @__PURE__ */ React7.createElement(Select.Option, {
|
|
565
|
-
key: String(
|
|
566
|
-
value: String(
|
|
567
|
-
}, label2 ?? String(
|
|
570
|
+
key: String(value2),
|
|
571
|
+
value: String(value2)
|
|
572
|
+
}, label2 ?? String(value2))
|
|
568
573
|
)))))), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
|
|
569
574
|
};
|
|
570
575
|
var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
@@ -617,13 +622,13 @@ import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@d
|
|
|
617
622
|
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
618
623
|
|
|
619
624
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
620
|
-
import React8, { createContext, useContext, useEffect as
|
|
625
|
+
import React8, { createContext, useContext, useEffect as useEffect6, useMemo as useMemo3 } from "react";
|
|
621
626
|
import { raise } from "@dxos/debug";
|
|
622
627
|
import { getValue as getValue2 } from "@dxos/echo-schema";
|
|
623
628
|
import { createJsonPath as createJsonPath2 } from "@dxos/effect";
|
|
624
629
|
|
|
625
630
|
// packages/ui/react-ui-form/src/hooks/useForm.ts
|
|
626
|
-
import { SchemaAST
|
|
631
|
+
import { SchemaAST } from "effect";
|
|
627
632
|
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
|
|
628
633
|
import { getValue, setValue } from "@dxos/echo-schema";
|
|
629
634
|
import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
|
|
@@ -632,12 +637,12 @@ import { log } from "@dxos/log";
|
|
|
632
637
|
import { validateSchema } from "@dxos/schema";
|
|
633
638
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
634
639
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
635
|
-
invariant(
|
|
640
|
+
invariant(SchemaAST.isTypeLiteral(schema.ast), void 0, {
|
|
636
641
|
F: __dxlog_file,
|
|
637
642
|
L: 93,
|
|
638
643
|
S: void 0,
|
|
639
644
|
A: [
|
|
640
|
-
"
|
|
645
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
641
646
|
""
|
|
642
647
|
]
|
|
643
648
|
});
|
|
@@ -738,7 +743,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
738
743
|
} catch (err) {
|
|
739
744
|
log.catch(err, void 0, {
|
|
740
745
|
F: __dxlog_file,
|
|
741
|
-
L:
|
|
746
|
+
L: 213,
|
|
742
747
|
S: void 0,
|
|
743
748
|
C: (f, a) => f(...a)
|
|
744
749
|
});
|
|
@@ -809,7 +814,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
809
814
|
var createKeySet = (obj, value) => {
|
|
810
815
|
invariant(obj, void 0, {
|
|
811
816
|
F: __dxlog_file,
|
|
812
|
-
L:
|
|
817
|
+
L: 275,
|
|
813
818
|
S: void 0,
|
|
814
819
|
A: [
|
|
815
820
|
"obj",
|
|
@@ -831,6 +836,81 @@ var flatMap = (errors) => {
|
|
|
831
836
|
}, {});
|
|
832
837
|
};
|
|
833
838
|
|
|
839
|
+
// packages/ui/react-ui-form/src/hooks/useRefQueryLookupHandler.ts
|
|
840
|
+
import { useCallback as useCallback5 } from "react";
|
|
841
|
+
import { getDXN } from "@dxos/echo-schema";
|
|
842
|
+
import { Filter } from "@dxos/react-client/echo";
|
|
843
|
+
import { isNonNullable } from "@dxos/util";
|
|
844
|
+
var useRefQueryLookupHandler = ({ space }) => {
|
|
845
|
+
const handleRefQueryLookup = useCallback5(async (typeInfo) => {
|
|
846
|
+
if (!space) {
|
|
847
|
+
return [];
|
|
848
|
+
}
|
|
849
|
+
const query = space.db.query(Filter.typename(typeInfo.typename));
|
|
850
|
+
const { objects } = await query.run();
|
|
851
|
+
return objects.map((object) => {
|
|
852
|
+
const dxn = getDXN(object);
|
|
853
|
+
if (!dxn) {
|
|
854
|
+
return void 0;
|
|
855
|
+
}
|
|
856
|
+
const item = {
|
|
857
|
+
dxn,
|
|
858
|
+
label: object?.name ?? object?.id ?? ""
|
|
859
|
+
};
|
|
860
|
+
return item;
|
|
861
|
+
}).filter(isNonNullable);
|
|
862
|
+
}, [
|
|
863
|
+
space
|
|
864
|
+
]);
|
|
865
|
+
return handleRefQueryLookup;
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
// packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts
|
|
869
|
+
import { useEffect as useEffect5, useState as useState4 } from "react";
|
|
870
|
+
import { log as log2 } from "@dxos/log";
|
|
871
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
872
|
+
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
873
|
+
const [options, setOptions] = useState4([]);
|
|
874
|
+
const [loading, setLoading] = useState4(false);
|
|
875
|
+
useEffect5(() => {
|
|
876
|
+
if (!refTypeInfo || !onQueryRefOptions) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
const fetchOptions = async () => {
|
|
880
|
+
setLoading(true);
|
|
881
|
+
try {
|
|
882
|
+
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
883
|
+
setOptions(fetchedOptions.map((option) => {
|
|
884
|
+
const dxn = option.dxn.toString();
|
|
885
|
+
return {
|
|
886
|
+
id: dxn,
|
|
887
|
+
label: option.label ?? dxn,
|
|
888
|
+
hue: "neutral"
|
|
889
|
+
};
|
|
890
|
+
}));
|
|
891
|
+
} catch (error) {
|
|
892
|
+
log2.error("Failed to fetch ref options:", error, {
|
|
893
|
+
F: __dxlog_file2,
|
|
894
|
+
L: 42,
|
|
895
|
+
S: void 0,
|
|
896
|
+
C: (f, a) => f(...a)
|
|
897
|
+
});
|
|
898
|
+
setOptions([]);
|
|
899
|
+
} finally {
|
|
900
|
+
setLoading(false);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
void fetchOptions();
|
|
904
|
+
}, [
|
|
905
|
+
refTypeInfo,
|
|
906
|
+
onQueryRefOptions
|
|
907
|
+
]);
|
|
908
|
+
return {
|
|
909
|
+
options,
|
|
910
|
+
loading
|
|
911
|
+
};
|
|
912
|
+
};
|
|
913
|
+
|
|
834
914
|
// packages/ui/react-ui-form/src/components/Form/FormContext.tsx
|
|
835
915
|
var FormContext = /* @__PURE__ */ createContext(void 0);
|
|
836
916
|
var useFormContext = () => {
|
|
@@ -861,7 +941,7 @@ var useInputProps = (path = []) => {
|
|
|
861
941
|
};
|
|
862
942
|
var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
863
943
|
const form = useForm(formOptions);
|
|
864
|
-
|
|
944
|
+
useEffect6(() => {
|
|
865
945
|
if (!formRef?.current) {
|
|
866
946
|
return;
|
|
867
947
|
}
|
|
@@ -869,7 +949,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
|
|
|
869
949
|
const keyIsEnter = event.key === "Enter";
|
|
870
950
|
const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
871
951
|
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
872
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit");
|
|
952
|
+
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
873
953
|
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
874
954
|
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
875
955
|
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
@@ -922,252 +1002,587 @@ var FormActions = ({ onCancel, readonly }) => {
|
|
|
922
1002
|
};
|
|
923
1003
|
|
|
924
1004
|
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
925
|
-
import { pipe as pipe2 } from "effect";
|
|
1005
|
+
import { Schema, SchemaAST as SchemaAST4, pipe as pipe2 } from "effect";
|
|
926
1006
|
import { capitalize as capitalize2 } from "effect/String";
|
|
927
1007
|
import React12, { useMemo as useMemo5 } from "react";
|
|
928
|
-
import {
|
|
929
|
-
import { createJsonPath as createJsonPath3, findNode as findNode2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
1008
|
+
import { createJsonPath as createJsonPath3, findNode as findNode3, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
930
1009
|
import { mx as mx7 } from "@dxos/react-ui-theme";
|
|
931
1010
|
import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
|
|
932
1011
|
import { isNotFalsy } from "@dxos/util";
|
|
933
1012
|
|
|
934
1013
|
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
935
|
-
import { pipe } from "effect";
|
|
1014
|
+
import { SchemaAST as SchemaAST3, pipe } from "effect";
|
|
936
1015
|
import { capitalize } from "effect/String";
|
|
937
|
-
import React10, { useCallback as
|
|
938
|
-
import {
|
|
939
|
-
import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
1016
|
+
import React10, { useCallback as useCallback6 } from "react";
|
|
1017
|
+
import { findNode as findNode2, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
|
|
940
1018
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
941
1019
|
import { IconButton as IconButton3, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
942
1020
|
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
943
1021
|
import { getSchemaProperties } from "@dxos/schema";
|
|
944
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
945
|
-
var padding = "px-2";
|
|
946
|
-
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
947
|
-
const { t } = useTranslation5(translationKey);
|
|
948
|
-
const { ast, name, type, title } = property;
|
|
949
|
-
const values = useFormValues(path ?? []) ?? [];
|
|
950
|
-
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
951
|
-
F: __dxlog_file2,
|
|
952
|
-
L: 39,
|
|
953
|
-
S: void 0,
|
|
954
|
-
A: [
|
|
955
|
-
"Array.isArray(values)",
|
|
956
|
-
"`Values at path ${path?.join('.')} must be an array.`"
|
|
957
|
-
]
|
|
958
|
-
});
|
|
959
|
-
const label = title ?? pipe(name, capitalize);
|
|
960
|
-
const tupleType = findNode(ast, AST2.isTupleType);
|
|
961
|
-
const elementType = tupleType?.rest[0]?.type;
|
|
962
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
963
|
-
const baseNode = findNode(typeNode, isDiscriminatedUnion);
|
|
964
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, AST2.isTypeLiteral);
|
|
965
|
-
if (!typeLiteral) {
|
|
966
|
-
return {};
|
|
967
|
-
}
|
|
968
|
-
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
|
|
969
|
-
prop.name,
|
|
970
|
-
prop.defaultValue
|
|
971
|
-
]));
|
|
972
|
-
};
|
|
973
|
-
const newValue = useMemo4(() => {
|
|
974
|
-
if (type === "object" && elementType) {
|
|
975
|
-
return getDefaultObjectValue(elementType);
|
|
976
|
-
} else {
|
|
977
|
-
return SimpleType.getDefaultValue(type);
|
|
978
|
-
}
|
|
979
|
-
}, [
|
|
980
|
-
type,
|
|
981
|
-
elementType
|
|
982
|
-
]);
|
|
983
|
-
const handleAdd = useCallback5(() => {
|
|
984
|
-
inputProps.onValueChange(type, [
|
|
985
|
-
...values,
|
|
986
|
-
newValue
|
|
987
|
-
]);
|
|
988
|
-
}, [
|
|
989
|
-
type,
|
|
990
|
-
elementType,
|
|
991
|
-
inputProps,
|
|
992
|
-
newValue,
|
|
993
|
-
values
|
|
994
|
-
]);
|
|
995
|
-
const handleRemove = useCallback5((index) => {
|
|
996
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
997
|
-
inputProps.onValueChange(type, newValues);
|
|
998
|
-
}, [
|
|
999
|
-
type,
|
|
1000
|
-
inputProps,
|
|
1001
|
-
values
|
|
1002
|
-
]);
|
|
1003
|
-
if (!elementType) {
|
|
1004
|
-
return null;
|
|
1005
|
-
}
|
|
1006
|
-
return /* @__PURE__ */ React10.createElement("div", {
|
|
1007
|
-
role: "none",
|
|
1008
|
-
className: mx6(padding)
|
|
1009
|
-
}, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
1010
|
-
role: "none",
|
|
1011
|
-
className: "flex flex-col gap-1"
|
|
1012
|
-
}, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
|
|
1013
|
-
key: index,
|
|
1014
|
-
role: "none",
|
|
1015
|
-
className: "flex items-center gap-1"
|
|
1016
|
-
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1017
|
-
role: "none",
|
|
1018
|
-
className: "flex-1"
|
|
1019
|
-
}, /* @__PURE__ */ React10.createElement(FormField, {
|
|
1020
|
-
property: {
|
|
1021
|
-
...property,
|
|
1022
|
-
array: false,
|
|
1023
|
-
ast: elementType
|
|
1024
|
-
},
|
|
1025
|
-
path: [
|
|
1026
|
-
...path ?? [],
|
|
1027
|
-
index
|
|
1028
|
-
],
|
|
1029
|
-
readonly,
|
|
1030
|
-
inline: true,
|
|
1031
|
-
Custom,
|
|
1032
|
-
lookupComponent
|
|
1033
|
-
})), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1034
|
-
icon: "ph--trash--regular",
|
|
1035
|
-
iconOnly: true,
|
|
1036
|
-
label: t("button remove"),
|
|
1037
|
-
onClick: () => handleRemove(index)
|
|
1038
|
-
})))), /* @__PURE__ */ React10.createElement("div", {
|
|
1039
|
-
role: "none",
|
|
1040
|
-
className: "flex justify-between items-center plb-1"
|
|
1041
|
-
}, /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1042
|
-
icon: "ph--plus--regular",
|
|
1043
|
-
iconOnly: true,
|
|
1044
|
-
label: t("button add"),
|
|
1045
|
-
onClick: handleAdd
|
|
1046
|
-
})));
|
|
1047
|
-
};
|
|
1048
1022
|
|
|
1049
|
-
// packages/ui/react-ui-form/src/
|
|
1050
|
-
import
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
import { refFromDXN, RefImpl } from "@dxos/live-object";
|
|
1055
|
-
import { log as log2 } from "@dxos/log";
|
|
1056
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/RefField.tsx";
|
|
1057
|
-
var RefField = ({ ast, type, label, readonly, placeholder, inline, onQueryRefOptions, inputProps }) => {
|
|
1058
|
-
const { getValue: getValue3, onValueChange, ...restInputProps } = inputProps;
|
|
1059
|
-
const refTypeInfo = findAnnotation(ast, ReferenceAnnotationId);
|
|
1060
|
-
const [refOptions, setRefOptions] = useState4([]);
|
|
1061
|
-
const [loading, setLoading] = useState4(false);
|
|
1062
|
-
useEffect6(() => {
|
|
1063
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
const fetchOptions = async () => {
|
|
1067
|
-
setLoading(true);
|
|
1068
|
-
try {
|
|
1069
|
-
const options = await onQueryRefOptions(refTypeInfo);
|
|
1070
|
-
setRefOptions(options.map((option) => ({
|
|
1071
|
-
label: option.label,
|
|
1072
|
-
value: option.dxn.toString()
|
|
1073
|
-
})));
|
|
1074
|
-
} catch (error) {
|
|
1075
|
-
log2.error("Failed to fetch ref options:", error, {
|
|
1076
|
-
F: __dxlog_file3,
|
|
1077
|
-
L: 68,
|
|
1078
|
-
S: void 0,
|
|
1079
|
-
C: (f, a) => f(...a)
|
|
1080
|
-
});
|
|
1081
|
-
setRefOptions([]);
|
|
1082
|
-
} finally {
|
|
1083
|
-
setLoading(false);
|
|
1084
|
-
}
|
|
1085
|
-
};
|
|
1086
|
-
void fetchOptions();
|
|
1087
|
-
}, [
|
|
1088
|
-
refTypeInfo,
|
|
1089
|
-
onQueryRefOptions
|
|
1090
|
-
]);
|
|
1091
|
-
if (!refTypeInfo) {
|
|
1092
|
-
return null;
|
|
1023
|
+
// packages/ui/react-ui-form/src/util/field.ts
|
|
1024
|
+
import { FormatEnum, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo-schema";
|
|
1025
|
+
var parseValue = ({ type, format, value }) => {
|
|
1026
|
+
if (value === void 0 || value === null || value === "") {
|
|
1027
|
+
return void 0;
|
|
1093
1028
|
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1029
|
+
const parseScalar = (type2) => {
|
|
1030
|
+
switch (type2) {
|
|
1031
|
+
case TypeEnum.Boolean: {
|
|
1032
|
+
if (typeof value === "string") {
|
|
1033
|
+
const lowercaseValue = value.toLowerCase();
|
|
1034
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1035
|
+
return false;
|
|
1036
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1037
|
+
return true;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
return Boolean(value);
|
|
1103
1041
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
return formValue;
|
|
1042
|
+
case TypeEnum.Number: {
|
|
1043
|
+
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1044
|
+
const num = Number(cleaned);
|
|
1045
|
+
return Number.isNaN(num) ? null : num;
|
|
1109
1046
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1047
|
+
case TypeEnum.String:
|
|
1048
|
+
case TypeEnum.Ref:
|
|
1049
|
+
return String(value);
|
|
1050
|
+
default: {
|
|
1051
|
+
return value;
|
|
1112
1052
|
}
|
|
1113
|
-
return void 0;
|
|
1114
|
-
};
|
|
1115
|
-
return /* @__PURE__ */ React11.createElement(TextInput, {
|
|
1116
|
-
type,
|
|
1117
|
-
label,
|
|
1118
|
-
disabled: readonly,
|
|
1119
|
-
placeholder,
|
|
1120
|
-
inputOnly: inline,
|
|
1121
|
-
getValue: handleGetValue2,
|
|
1122
|
-
onValueChange: handleOnValueChange,
|
|
1123
|
-
...restInputProps
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
const handleGetValue = () => {
|
|
1127
|
-
const formValue = getValue3();
|
|
1128
|
-
if (formValue instanceof RefImpl) {
|
|
1129
|
-
return formValue.dxn.toString();
|
|
1130
1053
|
}
|
|
1131
|
-
return void 0;
|
|
1132
|
-
};
|
|
1133
|
-
const handleValueChanged = (_type, dxnString) => {
|
|
1134
|
-
const dxn = DXN.parse(dxnString);
|
|
1135
|
-
const ref = refFromDXN(dxn);
|
|
1136
|
-
onValueChange("object", ref);
|
|
1137
1054
|
};
|
|
1138
|
-
|
|
1139
|
-
type
|
|
1140
|
-
label,
|
|
1141
|
-
disabled: readonly || loading,
|
|
1142
|
-
placeholder: loading ? "Loading options..." : placeholder,
|
|
1143
|
-
inputOnly: inline,
|
|
1144
|
-
getValue: handleGetValue,
|
|
1145
|
-
onValueChange: handleValueChanged,
|
|
1146
|
-
options: refOptions,
|
|
1147
|
-
...restInputProps
|
|
1148
|
-
});
|
|
1149
|
-
};
|
|
1150
|
-
|
|
1151
|
-
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
1152
|
-
import { FormatEnum } from "@dxos/echo-schema";
|
|
1153
|
-
var getInputComponent = (type, format) => {
|
|
1154
|
-
switch (format) {
|
|
1155
|
-
case FormatEnum.GeoPoint:
|
|
1156
|
-
return GeoPointInput;
|
|
1157
|
-
case FormatEnum.Markdown:
|
|
1158
|
-
return MarkdownInput;
|
|
1055
|
+
if (!format) {
|
|
1056
|
+
return parseScalar(type);
|
|
1159
1057
|
}
|
|
1160
|
-
switch (
|
|
1161
|
-
case
|
|
1162
|
-
return
|
|
1163
|
-
case
|
|
1164
|
-
|
|
1165
|
-
case
|
|
1166
|
-
return
|
|
1058
|
+
switch (format) {
|
|
1059
|
+
case FormatEnum.Boolean:
|
|
1060
|
+
return parseScalar(TypeEnum.Boolean);
|
|
1061
|
+
case FormatEnum.Number:
|
|
1062
|
+
case FormatEnum.Percent:
|
|
1063
|
+
case FormatEnum.Currency:
|
|
1064
|
+
return parseScalar(TypeEnum.Number);
|
|
1065
|
+
case FormatEnum.String:
|
|
1066
|
+
case FormatEnum.Markdown: {
|
|
1067
|
+
return parseScalar(TypeEnum.String);
|
|
1068
|
+
}
|
|
1069
|
+
case FormatEnum.Ref:
|
|
1070
|
+
throw new Error(`unexpected format: ${FormatEnum.Ref}`);
|
|
1071
|
+
case FormatEnum.DateTime:
|
|
1072
|
+
case FormatEnum.Date:
|
|
1073
|
+
case FormatEnum.Time:
|
|
1074
|
+
case FormatEnum.Timestamp: {
|
|
1075
|
+
const date = new Date(value);
|
|
1076
|
+
return isNaN(date.getTime()) ? null : date;
|
|
1077
|
+
}
|
|
1078
|
+
case FormatEnum.GeoPoint: {
|
|
1079
|
+
if (typeof value === "string") {
|
|
1080
|
+
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1081
|
+
const parts = cleaned.split(",");
|
|
1082
|
+
if (parts.length === 2) {
|
|
1083
|
+
const lat = parseFloat(parts[0]);
|
|
1084
|
+
const long = parseFloat(parts[1]);
|
|
1085
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
1086
|
+
return GeoLocation2.toGeoPoint({
|
|
1087
|
+
latitude: lat,
|
|
1088
|
+
longitude: long
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return [
|
|
1094
|
+
0,
|
|
1095
|
+
0
|
|
1096
|
+
];
|
|
1097
|
+
}
|
|
1098
|
+
default: {
|
|
1099
|
+
return value;
|
|
1100
|
+
}
|
|
1167
1101
|
}
|
|
1168
1102
|
};
|
|
1169
|
-
|
|
1170
|
-
|
|
1103
|
+
var cellClassesForFieldType = ({ type, format }) => {
|
|
1104
|
+
if (!format) {
|
|
1105
|
+
switch (type) {
|
|
1106
|
+
case TypeEnum.Number:
|
|
1107
|
+
return [
|
|
1108
|
+
"text-right",
|
|
1109
|
+
"font-mono"
|
|
1110
|
+
];
|
|
1111
|
+
case TypeEnum.Boolean:
|
|
1112
|
+
return [
|
|
1113
|
+
"text-right",
|
|
1114
|
+
"font-mono"
|
|
1115
|
+
];
|
|
1116
|
+
case TypeEnum.String:
|
|
1117
|
+
return void 0;
|
|
1118
|
+
case TypeEnum.Ref:
|
|
1119
|
+
return void 0;
|
|
1120
|
+
default: {
|
|
1121
|
+
return void 0;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
switch (format) {
|
|
1126
|
+
case FormatEnum.Markdown:
|
|
1127
|
+
return void 0;
|
|
1128
|
+
case FormatEnum.Time:
|
|
1129
|
+
case FormatEnum.Timestamp:
|
|
1130
|
+
case FormatEnum.DateTime:
|
|
1131
|
+
case FormatEnum.Date:
|
|
1132
|
+
case FormatEnum.Duration:
|
|
1133
|
+
return [
|
|
1134
|
+
"font-mono",
|
|
1135
|
+
"text-right"
|
|
1136
|
+
];
|
|
1137
|
+
case FormatEnum.Currency:
|
|
1138
|
+
return [
|
|
1139
|
+
"text-right"
|
|
1140
|
+
];
|
|
1141
|
+
case FormatEnum.JSON:
|
|
1142
|
+
case FormatEnum.DID:
|
|
1143
|
+
return [
|
|
1144
|
+
"font-mono"
|
|
1145
|
+
];
|
|
1146
|
+
default:
|
|
1147
|
+
return void 0;
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
var pathNotUniqueError = (path) => ({
|
|
1151
|
+
path: "path",
|
|
1152
|
+
message: `'${path}' is already present`
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
// packages/ui/react-ui-form/src/util/formatting.ts
|
|
1156
|
+
import { format as formatDate } from "date-fns/format";
|
|
1157
|
+
import { FormatEnum as FormatEnum2, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
|
|
1158
|
+
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1159
|
+
const formatScalar = (type2) => {
|
|
1160
|
+
switch (type2) {
|
|
1161
|
+
case TypeEnum2.Boolean:
|
|
1162
|
+
return value.toLocaleString().toUpperCase();
|
|
1163
|
+
case TypeEnum2.Number:
|
|
1164
|
+
return value.toLocaleString(locale);
|
|
1165
|
+
case TypeEnum2.String:
|
|
1166
|
+
case TypeEnum2.Ref:
|
|
1167
|
+
return String(value);
|
|
1168
|
+
default: {
|
|
1169
|
+
return String(value);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
if (!format) {
|
|
1174
|
+
return formatScalar(type);
|
|
1175
|
+
}
|
|
1176
|
+
switch (format) {
|
|
1177
|
+
case FormatEnum2.Boolean: {
|
|
1178
|
+
return formatScalar(TypeEnum2.Boolean);
|
|
1179
|
+
}
|
|
1180
|
+
case FormatEnum2.Number: {
|
|
1181
|
+
return formatScalar(TypeEnum2.Number);
|
|
1182
|
+
}
|
|
1183
|
+
case FormatEnum2.String:
|
|
1184
|
+
case FormatEnum2.Ref: {
|
|
1185
|
+
return formatScalar(TypeEnum2.String);
|
|
1186
|
+
}
|
|
1187
|
+
case FormatEnum2.Percent: {
|
|
1188
|
+
return `${value * 100}%`;
|
|
1189
|
+
}
|
|
1190
|
+
case FormatEnum2.Currency: {
|
|
1191
|
+
return value.toLocaleString(locale, {
|
|
1192
|
+
style: "currency",
|
|
1193
|
+
currency: "USD",
|
|
1194
|
+
minimumFractionDigits: 2,
|
|
1195
|
+
maximumFractionDigits: 2
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
case FormatEnum2.Date: {
|
|
1199
|
+
try {
|
|
1200
|
+
return formatDate(new Date(value), "yyyy-MM-dd");
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
return "Invalid Date";
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
case FormatEnum2.Time: {
|
|
1206
|
+
try {
|
|
1207
|
+
return formatDate(new Date(value), "HH:mm:ss");
|
|
1208
|
+
} catch (error) {
|
|
1209
|
+
return "Invalid Time";
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
case FormatEnum2.DateTime: {
|
|
1213
|
+
try {
|
|
1214
|
+
return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1215
|
+
} catch (error) {
|
|
1216
|
+
return "Invalid DateTime";
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
case FormatEnum2.GeoPoint: {
|
|
1220
|
+
if (value === null || value === void 0) {
|
|
1221
|
+
return "";
|
|
1222
|
+
}
|
|
1223
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1224
|
+
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1225
|
+
return `${latitude},${longitude}`;
|
|
1226
|
+
}
|
|
1227
|
+
return String(value);
|
|
1228
|
+
}
|
|
1229
|
+
default: {
|
|
1230
|
+
if (value === null || value === "undefined") {
|
|
1231
|
+
return "";
|
|
1232
|
+
}
|
|
1233
|
+
return String(value);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1238
|
+
const formatScalar = (type2) => {
|
|
1239
|
+
switch (type2) {
|
|
1240
|
+
case TypeEnum2.Boolean:
|
|
1241
|
+
case TypeEnum2.Number:
|
|
1242
|
+
case TypeEnum2.String:
|
|
1243
|
+
case TypeEnum2.Ref:
|
|
1244
|
+
return String(value);
|
|
1245
|
+
default:
|
|
1246
|
+
return String(value);
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
if (!format) {
|
|
1250
|
+
return formatScalar(type);
|
|
1251
|
+
}
|
|
1252
|
+
switch (format) {
|
|
1253
|
+
case FormatEnum2.Boolean:
|
|
1254
|
+
case FormatEnum2.Number:
|
|
1255
|
+
case FormatEnum2.String:
|
|
1256
|
+
case FormatEnum2.Ref: {
|
|
1257
|
+
return formatScalar(type);
|
|
1258
|
+
}
|
|
1259
|
+
case FormatEnum2.Percent: {
|
|
1260
|
+
return String(value * 100);
|
|
1261
|
+
}
|
|
1262
|
+
case FormatEnum2.Currency: {
|
|
1263
|
+
return String(value);
|
|
1264
|
+
}
|
|
1265
|
+
case FormatEnum2.DateTime: {
|
|
1266
|
+
const date = new Date(value);
|
|
1267
|
+
return date.toISOString();
|
|
1268
|
+
}
|
|
1269
|
+
case FormatEnum2.Date: {
|
|
1270
|
+
const date = new Date(value);
|
|
1271
|
+
return date.toISOString().split("T")[0];
|
|
1272
|
+
}
|
|
1273
|
+
case FormatEnum2.Time: {
|
|
1274
|
+
const date = new Date(value);
|
|
1275
|
+
return date.toISOString().split("T")[1].split(".")[0];
|
|
1276
|
+
}
|
|
1277
|
+
case FormatEnum2.GeoPoint: {
|
|
1278
|
+
if (value === null || value === void 0) {
|
|
1279
|
+
return "";
|
|
1280
|
+
}
|
|
1281
|
+
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1282
|
+
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1283
|
+
return `${latitude},${longitude}`;
|
|
1284
|
+
}
|
|
1285
|
+
return String(value);
|
|
1286
|
+
}
|
|
1287
|
+
default: {
|
|
1288
|
+
return String(value);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
// packages/ui/react-ui-form/src/util/refs.ts
|
|
1294
|
+
import { FormatEnum as FormatEnum3, ReferenceAnnotationId } from "@dxos/echo-schema";
|
|
1295
|
+
import { findAnnotation } from "@dxos/effect";
|
|
1296
|
+
|
|
1297
|
+
// packages/ui/react-ui-form/src/util/schema.ts
|
|
1298
|
+
import { SchemaAST as SchemaAST2 } from "effect";
|
|
1299
|
+
import { findNode } from "@dxos/effect";
|
|
1300
|
+
var findArrayElementType = (ast) => {
|
|
1301
|
+
const tupleType = findNode(ast, SchemaAST2.isTupleType);
|
|
1302
|
+
const elementType = tupleType?.rest[0]?.type;
|
|
1303
|
+
return elementType;
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
// packages/ui/react-ui-form/src/util/refs.ts
|
|
1307
|
+
var getRefProps = (property) => {
|
|
1308
|
+
const { ast, format, array } = property;
|
|
1309
|
+
if (format === FormatEnum3.Ref) {
|
|
1310
|
+
return {
|
|
1311
|
+
ast,
|
|
1312
|
+
isArray: false
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
if (array) {
|
|
1316
|
+
const elementType = findArrayElementType(ast);
|
|
1317
|
+
if (elementType) {
|
|
1318
|
+
const annotation = findAnnotation(elementType, ReferenceAnnotationId);
|
|
1319
|
+
if (annotation) {
|
|
1320
|
+
return {
|
|
1321
|
+
ast: elementType,
|
|
1322
|
+
isArray: true
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
return void 0;
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
// packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
|
|
1331
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
|
|
1332
|
+
var padding = "px-2";
|
|
1333
|
+
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1334
|
+
const { t } = useTranslation5(translationKey);
|
|
1335
|
+
const { ast, name, type, title } = property;
|
|
1336
|
+
const values = useFormValues(path ?? []) ?? [];
|
|
1337
|
+
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1338
|
+
F: __dxlog_file3,
|
|
1339
|
+
L: 39,
|
|
1340
|
+
S: void 0,
|
|
1341
|
+
A: [
|
|
1342
|
+
"Array.isArray(values)",
|
|
1343
|
+
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1344
|
+
]
|
|
1345
|
+
});
|
|
1346
|
+
const label = title ?? pipe(name, capitalize);
|
|
1347
|
+
const elementType = findArrayElementType(ast);
|
|
1348
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1349
|
+
const baseNode = findNode2(typeNode, isDiscriminatedUnion);
|
|
1350
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
|
|
1351
|
+
if (!typeLiteral) {
|
|
1352
|
+
return {};
|
|
1353
|
+
}
|
|
1354
|
+
return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
|
|
1355
|
+
prop.name,
|
|
1356
|
+
prop.defaultValue
|
|
1357
|
+
]));
|
|
1358
|
+
};
|
|
1359
|
+
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
1360
|
+
const handleAdd = useCallback6(() => {
|
|
1361
|
+
inputProps.onValueChange(type, [
|
|
1362
|
+
...values,
|
|
1363
|
+
getDefaultValue()
|
|
1364
|
+
]);
|
|
1365
|
+
}, [
|
|
1366
|
+
type,
|
|
1367
|
+
elementType,
|
|
1368
|
+
inputProps,
|
|
1369
|
+
values
|
|
1370
|
+
]);
|
|
1371
|
+
const handleRemove = useCallback6((index) => {
|
|
1372
|
+
const newValues = values.filter((_, i) => i !== index);
|
|
1373
|
+
inputProps.onValueChange(type, newValues);
|
|
1374
|
+
}, [
|
|
1375
|
+
type,
|
|
1376
|
+
inputProps,
|
|
1377
|
+
values
|
|
1378
|
+
]);
|
|
1379
|
+
if (!elementType) {
|
|
1380
|
+
return null;
|
|
1381
|
+
}
|
|
1382
|
+
return /* @__PURE__ */ React10.createElement("div", {
|
|
1383
|
+
role: "none",
|
|
1384
|
+
className: mx6(padding)
|
|
1385
|
+
}, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
|
|
1386
|
+
role: "none",
|
|
1387
|
+
className: "flex flex-col gap-1"
|
|
1388
|
+
}, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
|
|
1389
|
+
key: index,
|
|
1390
|
+
role: "none",
|
|
1391
|
+
className: "flex items-center gap-1"
|
|
1392
|
+
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1393
|
+
role: "none",
|
|
1394
|
+
className: "flex-1"
|
|
1395
|
+
}, /* @__PURE__ */ React10.createElement(FormField, {
|
|
1396
|
+
property: {
|
|
1397
|
+
...property,
|
|
1398
|
+
array: false,
|
|
1399
|
+
ast: elementType
|
|
1400
|
+
},
|
|
1401
|
+
path: [
|
|
1402
|
+
...path ?? [],
|
|
1403
|
+
index
|
|
1404
|
+
],
|
|
1405
|
+
readonly,
|
|
1406
|
+
inline: true,
|
|
1407
|
+
Custom,
|
|
1408
|
+
lookupComponent
|
|
1409
|
+
})), /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1410
|
+
icon: "ph--trash--regular",
|
|
1411
|
+
iconOnly: true,
|
|
1412
|
+
label: t("button remove"),
|
|
1413
|
+
onClick: () => handleRemove(index)
|
|
1414
|
+
})))), /* @__PURE__ */ React10.createElement("div", {
|
|
1415
|
+
role: "none",
|
|
1416
|
+
className: "flex justify-between items-center plb-1"
|
|
1417
|
+
}, /* @__PURE__ */ React10.createElement(IconButton3, {
|
|
1418
|
+
icon: "ph--plus--regular",
|
|
1419
|
+
iconOnly: true,
|
|
1420
|
+
label: t("button add"),
|
|
1421
|
+
onClick: handleAdd
|
|
1422
|
+
})));
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
// packages/ui/react-ui-form/src/components/Form/RefField.tsx
|
|
1426
|
+
import React11, { useCallback as useCallback7, useMemo as useMemo4 } from "react";
|
|
1427
|
+
import { Expando, getTypeAnnotation, Ref, ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo-schema";
|
|
1428
|
+
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
1429
|
+
import { DXN } from "@dxos/keys";
|
|
1430
|
+
import { Input as Input7 } from "@dxos/react-ui";
|
|
1431
|
+
import { TagPicker } from "@dxos/react-ui-tag-picker";
|
|
1432
|
+
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1433
|
+
var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
|
|
1434
|
+
const refTypeInfo = useMemo4(() => ast ? findAnnotation2(ast, ReferenceAnnotationId2) : void 0, [
|
|
1435
|
+
ast
|
|
1436
|
+
]);
|
|
1437
|
+
const { options: availableOptions, loading: _loading } = useQueryRefOptions({
|
|
1438
|
+
refTypeInfo,
|
|
1439
|
+
onQueryRefOptions
|
|
1440
|
+
});
|
|
1441
|
+
if (refTypeInfo && refTypeInfo?.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
|
|
1442
|
+
return /* @__PURE__ */ React11.createElement(RefFieldFallback, {
|
|
1443
|
+
type,
|
|
1444
|
+
label,
|
|
1445
|
+
placeholder,
|
|
1446
|
+
disabled,
|
|
1447
|
+
inputOnly,
|
|
1448
|
+
getValue: getValue3,
|
|
1449
|
+
onBlur,
|
|
1450
|
+
onValueChange,
|
|
1451
|
+
...restInputProps
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
const handleGetValue = useCallback7(() => {
|
|
1455
|
+
const formValue = getValue3();
|
|
1456
|
+
const unknownToRefOption = (val) => {
|
|
1457
|
+
if (Ref.isRef(val)) {
|
|
1458
|
+
const dxnString = val.dxn.toString();
|
|
1459
|
+
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1460
|
+
if (matchingOption) {
|
|
1461
|
+
return matchingOption;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
return void 0;
|
|
1465
|
+
};
|
|
1466
|
+
if (array && Array.isArray(formValue)) {
|
|
1467
|
+
return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
|
|
1468
|
+
}
|
|
1469
|
+
const option = unknownToRefOption(formValue);
|
|
1470
|
+
if (option) {
|
|
1471
|
+
return [
|
|
1472
|
+
option
|
|
1473
|
+
];
|
|
1474
|
+
}
|
|
1475
|
+
return [];
|
|
1476
|
+
}, [
|
|
1477
|
+
getValue3,
|
|
1478
|
+
availableOptions,
|
|
1479
|
+
array
|
|
1480
|
+
]);
|
|
1481
|
+
const handleSearch = useCallback7((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
|
|
1482
|
+
id: option.id,
|
|
1483
|
+
label: option.label,
|
|
1484
|
+
hue: option.hue
|
|
1485
|
+
})), [
|
|
1486
|
+
availableOptions
|
|
1487
|
+
]);
|
|
1488
|
+
const handleUpdate = useCallback7((ids) => {
|
|
1489
|
+
if (ids.length === 0) {
|
|
1490
|
+
onValueChange("object", void 0);
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
const refs = ids.map((id) => {
|
|
1494
|
+
const item = availableOptions.find((option) => option.id === id);
|
|
1495
|
+
if (item) {
|
|
1496
|
+
const dxn = DXN.parse(item.id);
|
|
1497
|
+
return Ref.fromDXN(dxn);
|
|
1498
|
+
}
|
|
1499
|
+
return null;
|
|
1500
|
+
}).filter(isNonNullable2);
|
|
1501
|
+
if (array) {
|
|
1502
|
+
onValueChange("object", refs);
|
|
1503
|
+
} else {
|
|
1504
|
+
onValueChange("object", refs[0]);
|
|
1505
|
+
}
|
|
1506
|
+
}, [
|
|
1507
|
+
availableOptions,
|
|
1508
|
+
array,
|
|
1509
|
+
onValueChange
|
|
1510
|
+
]);
|
|
1511
|
+
const tagPickerMode = useMemo4(() => array ? "multi-select" : "single-select", [
|
|
1512
|
+
array
|
|
1513
|
+
]);
|
|
1514
|
+
if (!refTypeInfo) {
|
|
1515
|
+
return null;
|
|
1516
|
+
}
|
|
1517
|
+
const { status, error } = restInputProps.getStatus();
|
|
1518
|
+
return /* @__PURE__ */ React11.createElement(Input7.Root, {
|
|
1519
|
+
validationValence: status
|
|
1520
|
+
}, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
|
|
1521
|
+
error
|
|
1522
|
+
}, /* @__PURE__ */ React11.createElement(Input7.Label, null, label)), /* @__PURE__ */ React11.createElement("div", {
|
|
1523
|
+
"data-no-submit": true
|
|
1524
|
+
}, /* @__PURE__ */ React11.createElement(TagPicker, {
|
|
1525
|
+
items: handleGetValue(),
|
|
1526
|
+
mode: tagPickerMode,
|
|
1527
|
+
onBlur: (event) => onBlur(event),
|
|
1528
|
+
onUpdate: handleUpdate,
|
|
1529
|
+
onSearch: handleSearch,
|
|
1530
|
+
classNames: "rounded-sm bg-input p-1.5"
|
|
1531
|
+
})), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1532
|
+
};
|
|
1533
|
+
var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1534
|
+
const handleOnValueChange = (_type, dxnString) => {
|
|
1535
|
+
const dxn = DXN.tryParse(dxnString);
|
|
1536
|
+
if (dxn) {
|
|
1537
|
+
onValueChange?.("object", Ref.fromDXN(dxn));
|
|
1538
|
+
} else if (dxnString === "") {
|
|
1539
|
+
onValueChange?.("object", void 0);
|
|
1540
|
+
} else {
|
|
1541
|
+
onValueChange?.("string", dxnString);
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
const handleGetValue = () => {
|
|
1545
|
+
const formValue = getValue3();
|
|
1546
|
+
if (typeof formValue === "string") {
|
|
1547
|
+
return formValue;
|
|
1548
|
+
}
|
|
1549
|
+
if (Ref.isRef(formValue)) {
|
|
1550
|
+
return formValue.dxn.toString();
|
|
1551
|
+
}
|
|
1552
|
+
return void 0;
|
|
1553
|
+
};
|
|
1554
|
+
return /* @__PURE__ */ React11.createElement(TextInput, {
|
|
1555
|
+
type,
|
|
1556
|
+
label,
|
|
1557
|
+
disabled,
|
|
1558
|
+
placeholder,
|
|
1559
|
+
inputOnly,
|
|
1560
|
+
getValue: handleGetValue,
|
|
1561
|
+
onValueChange: handleOnValueChange,
|
|
1562
|
+
...restInputProps
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
// packages/ui/react-ui-form/src/components/Form/factory.tsx
|
|
1567
|
+
import { FormatEnum as FormatEnum4 } from "@dxos/echo-schema";
|
|
1568
|
+
var getInputComponent = (type, format) => {
|
|
1569
|
+
switch (format) {
|
|
1570
|
+
case FormatEnum4.GeoPoint:
|
|
1571
|
+
return GeoPointInput;
|
|
1572
|
+
case FormatEnum4.Markdown:
|
|
1573
|
+
return MarkdownInput;
|
|
1574
|
+
}
|
|
1575
|
+
switch (type) {
|
|
1576
|
+
case "string":
|
|
1577
|
+
return TextInput;
|
|
1578
|
+
case "number":
|
|
1579
|
+
return NumberInput;
|
|
1580
|
+
case "boolean":
|
|
1581
|
+
return BooleanInput;
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
// packages/ui/react-ui-form/src/components/Form/FormContent.tsx
|
|
1171
1586
|
var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
|
|
1172
1587
|
const inputProps = useInputProps(path);
|
|
1173
1588
|
const { ast, name, type, format, title, description, options, examples, array } = property;
|
|
@@ -1181,7 +1596,7 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1181
1596
|
]);
|
|
1182
1597
|
const FoundComponent = lookupComponent?.({
|
|
1183
1598
|
prop: name,
|
|
1184
|
-
schema:
|
|
1599
|
+
schema: Schema.make(ast),
|
|
1185
1600
|
inputProps: {
|
|
1186
1601
|
type,
|
|
1187
1602
|
format,
|
|
@@ -1209,6 +1624,21 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1209
1624
|
...inputProps
|
|
1210
1625
|
});
|
|
1211
1626
|
}
|
|
1627
|
+
const refProps = getRefProps(property);
|
|
1628
|
+
if (refProps) {
|
|
1629
|
+
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1630
|
+
ast: refProps.ast,
|
|
1631
|
+
array: refProps.isArray,
|
|
1632
|
+
type,
|
|
1633
|
+
format,
|
|
1634
|
+
label,
|
|
1635
|
+
placeholder,
|
|
1636
|
+
disabled: readonly,
|
|
1637
|
+
inputOnly: inline,
|
|
1638
|
+
onQueryRefOptions,
|
|
1639
|
+
...inputProps
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1212
1642
|
if (array) {
|
|
1213
1643
|
return /* @__PURE__ */ React12.createElement(ArrayField, {
|
|
1214
1644
|
property,
|
|
@@ -1249,28 +1679,16 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
|
|
|
1249
1679
|
...inputProps
|
|
1250
1680
|
}));
|
|
1251
1681
|
}
|
|
1252
|
-
if (format === "ref") {
|
|
1253
|
-
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1254
|
-
ast,
|
|
1255
|
-
type,
|
|
1256
|
-
label,
|
|
1257
|
-
readonly,
|
|
1258
|
-
placeholder,
|
|
1259
|
-
inline,
|
|
1260
|
-
onQueryRefOptions,
|
|
1261
|
-
inputProps
|
|
1262
|
-
});
|
|
1263
|
-
}
|
|
1264
1682
|
if (type === "object") {
|
|
1265
|
-
const baseNode =
|
|
1266
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) :
|
|
1683
|
+
const baseNode = findNode3(ast, isDiscriminatedUnion2);
|
|
1684
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode3(ast, SchemaAST4.isTypeLiteral);
|
|
1267
1685
|
if (typeLiteral) {
|
|
1268
1686
|
return /* @__PURE__ */ React12.createElement("div", {
|
|
1269
1687
|
role: "none"
|
|
1270
1688
|
}, !inline && /* @__PURE__ */ React12.createElement("h3", {
|
|
1271
1689
|
className: "text-lg mbs-2 mbe-1"
|
|
1272
1690
|
}, label), /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1273
|
-
schema:
|
|
1691
|
+
schema: Schema.make(typeLiteral),
|
|
1274
1692
|
path,
|
|
1275
1693
|
readonly,
|
|
1276
1694
|
onQueryRefOptions,
|
|
@@ -1396,7 +1814,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1396
1814
|
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
1397
1815
|
fieldSchema: getFormatSchema(props?.format)
|
|
1398
1816
|
});
|
|
1399
|
-
const handleValuesChanged =
|
|
1817
|
+
const handleValuesChanged = useCallback8((_props) => {
|
|
1400
1818
|
setFieldSchema((prev) => {
|
|
1401
1819
|
const fieldSchema2 = getFormatSchema(_props.format);
|
|
1402
1820
|
if (prev.fieldSchema === fieldSchema2) {
|
|
@@ -1431,7 +1849,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1431
1849
|
props.format,
|
|
1432
1850
|
props.referenceSchema
|
|
1433
1851
|
]);
|
|
1434
|
-
const handleValidate =
|
|
1852
|
+
const handleValidate = useCallback8(({ property }) => {
|
|
1435
1853
|
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
1436
1854
|
return [
|
|
1437
1855
|
{
|
|
@@ -1444,7 +1862,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1444
1862
|
view.fields,
|
|
1445
1863
|
field
|
|
1446
1864
|
]);
|
|
1447
|
-
const handleSave =
|
|
1865
|
+
const handleSave = useCallback8((props2) => {
|
|
1448
1866
|
projection.setFieldProjection({
|
|
1449
1867
|
field,
|
|
1450
1868
|
props: props2
|
|
@@ -1455,7 +1873,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1455
1873
|
field,
|
|
1456
1874
|
onSave
|
|
1457
1875
|
]);
|
|
1458
|
-
const handleCancel =
|
|
1876
|
+
const handleCancel = useCallback8(() => {
|
|
1459
1877
|
requestAnimationFrame(() => onCancel?.());
|
|
1460
1878
|
onSave();
|
|
1461
1879
|
}, [
|
|
@@ -1464,7 +1882,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1464
1882
|
const Custom = useMemo7(() => ({
|
|
1465
1883
|
["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
1466
1884
|
...props2,
|
|
1467
|
-
options: FormatEnums.filter((value) => value !==
|
|
1885
|
+
options: FormatEnums.filter((value) => value !== FormatEnum5.None).map((value) => ({
|
|
1468
1886
|
value,
|
|
1469
1887
|
label: t(`format ${value}`)
|
|
1470
1888
|
}))
|
|
@@ -1487,7 +1905,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1487
1905
|
schemas,
|
|
1488
1906
|
referenceSchema
|
|
1489
1907
|
]);
|
|
1490
|
-
const propIsNotType =
|
|
1908
|
+
const propIsNotType = useCallback8((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
1491
1909
|
if (!fieldSchema) {
|
|
1492
1910
|
log3.warn("invalid format", {
|
|
1493
1911
|
props
|
|
@@ -1518,8 +1936,9 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
1518
1936
|
};
|
|
1519
1937
|
|
|
1520
1938
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
1521
|
-
import
|
|
1522
|
-
import {
|
|
1939
|
+
import { Schema as Schema2, SchemaAST as SchemaAST5 } from "effect";
|
|
1940
|
+
import React15, { useCallback as useCallback9, useMemo as useMemo8, useState as useState6 } from "react";
|
|
1941
|
+
import { Format, isMutable, toJsonSchema } from "@dxos/echo-schema";
|
|
1523
1942
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1524
1943
|
import { IconButton as IconButton4, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1525
1944
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
@@ -1527,21 +1946,22 @@ import { ghostHover, inputTextLabel, mx as mx9 } from "@dxos/react-ui-theme";
|
|
|
1527
1946
|
import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1528
1947
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
1529
1948
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
1530
|
-
var ViewMetaSchema =
|
|
1531
|
-
name:
|
|
1532
|
-
[
|
|
1949
|
+
var ViewMetaSchema = Schema2.Struct({
|
|
1950
|
+
name: Schema2.String.annotations({
|
|
1951
|
+
[SchemaAST5.TitleAnnotationId]: "View"
|
|
1533
1952
|
}),
|
|
1534
1953
|
typename: Format.URL.annotations({
|
|
1535
|
-
[
|
|
1954
|
+
[SchemaAST5.TitleAnnotationId]: "Typename"
|
|
1536
1955
|
})
|
|
1537
|
-
}).pipe(
|
|
1956
|
+
}).pipe(Schema2.mutable);
|
|
1538
1957
|
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
1539
1958
|
const { t } = useTranslation7(translationKey);
|
|
1540
|
-
const projection = useMemo8(() => new ViewProjection(schema
|
|
1959
|
+
const projection = useMemo8(() => new ViewProjection(toJsonSchema(schema), view), [
|
|
1541
1960
|
schema,
|
|
1542
1961
|
view
|
|
1543
1962
|
]);
|
|
1544
1963
|
const [field, setField] = useState6();
|
|
1964
|
+
const immutable = readonly || !isMutable(schema);
|
|
1545
1965
|
const viewValues = useMemo8(() => {
|
|
1546
1966
|
return {
|
|
1547
1967
|
name: view.name,
|
|
@@ -1552,16 +1972,16 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1552
1972
|
}, [
|
|
1553
1973
|
view
|
|
1554
1974
|
]);
|
|
1555
|
-
const handleSelect =
|
|
1975
|
+
const handleSelect = useCallback9((field2) => {
|
|
1556
1976
|
setField((f) => f === field2 ? void 0 : field2);
|
|
1557
1977
|
}, []);
|
|
1558
|
-
const handleAdd =
|
|
1559
|
-
invariant3(!
|
|
1978
|
+
const handleAdd = useCallback9(() => {
|
|
1979
|
+
invariant3(!immutable, void 0, {
|
|
1560
1980
|
F: __dxlog_file5,
|
|
1561
|
-
L:
|
|
1981
|
+
L: 78,
|
|
1562
1982
|
S: void 0,
|
|
1563
1983
|
A: [
|
|
1564
|
-
"!
|
|
1984
|
+
"!immutable",
|
|
1565
1985
|
""
|
|
1566
1986
|
]
|
|
1567
1987
|
});
|
|
@@ -1571,13 +1991,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1571
1991
|
schema,
|
|
1572
1992
|
view
|
|
1573
1993
|
]);
|
|
1574
|
-
const handleUpdate =
|
|
1575
|
-
invariant3(!
|
|
1994
|
+
const handleUpdate = useCallback9(({ name, typename }) => {
|
|
1995
|
+
invariant3(!immutable, void 0, {
|
|
1576
1996
|
F: __dxlog_file5,
|
|
1577
|
-
L:
|
|
1997
|
+
L: 85,
|
|
1578
1998
|
S: void 0,
|
|
1579
1999
|
A: [
|
|
1580
|
-
"!
|
|
2000
|
+
"!immutable",
|
|
1581
2001
|
""
|
|
1582
2002
|
]
|
|
1583
2003
|
});
|
|
@@ -1594,13 +2014,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1594
2014
|
view,
|
|
1595
2015
|
onTypenameChanged
|
|
1596
2016
|
]);
|
|
1597
|
-
const handleDelete =
|
|
1598
|
-
invariant3(!
|
|
2017
|
+
const handleDelete = useCallback9((fieldId) => {
|
|
2018
|
+
invariant3(!immutable, void 0, {
|
|
1599
2019
|
F: __dxlog_file5,
|
|
1600
|
-
L:
|
|
2020
|
+
L: 101,
|
|
1601
2021
|
S: void 0,
|
|
1602
2022
|
A: [
|
|
1603
|
-
"!
|
|
2023
|
+
"!immutable",
|
|
1604
2024
|
""
|
|
1605
2025
|
]
|
|
1606
2026
|
});
|
|
@@ -1613,13 +2033,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1613
2033
|
field,
|
|
1614
2034
|
onDelete
|
|
1615
2035
|
]);
|
|
1616
|
-
const handleMove =
|
|
1617
|
-
invariant3(!
|
|
2036
|
+
const handleMove = useCallback9((fromIndex, toIndex) => {
|
|
2037
|
+
invariant3(!immutable, void 0, {
|
|
1618
2038
|
F: __dxlog_file5,
|
|
1619
|
-
L:
|
|
2039
|
+
L: 113,
|
|
1620
2040
|
S: void 0,
|
|
1621
2041
|
A: [
|
|
1622
|
-
"!
|
|
2042
|
+
"!immutable",
|
|
1623
2043
|
""
|
|
1624
2044
|
]
|
|
1625
2045
|
});
|
|
@@ -1633,15 +2053,15 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1633
2053
|
schema,
|
|
1634
2054
|
view.fields
|
|
1635
2055
|
]);
|
|
1636
|
-
const handleClose =
|
|
2056
|
+
const handleClose = useCallback9(() => setField(void 0), []);
|
|
1637
2057
|
const hiddenProperties = projection.getHiddenProperties();
|
|
1638
|
-
const handleHide =
|
|
2058
|
+
const handleHide = useCallback9((fieldId) => {
|
|
1639
2059
|
setField(void 0);
|
|
1640
2060
|
projection.hideFieldProjection(fieldId);
|
|
1641
2061
|
}, [
|
|
1642
2062
|
projection
|
|
1643
2063
|
]);
|
|
1644
|
-
const handleShow =
|
|
2064
|
+
const handleShow = useCallback9((property) => {
|
|
1645
2065
|
setField(void 0);
|
|
1646
2066
|
projection.showFieldProjection(property);
|
|
1647
2067
|
}, [
|
|
@@ -1649,22 +2069,26 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1649
2069
|
]);
|
|
1650
2070
|
return /* @__PURE__ */ React15.createElement("div", {
|
|
1651
2071
|
role: "none",
|
|
1652
|
-
className: mx9("
|
|
2072
|
+
className: mx9("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
|
|
1653
2073
|
}, /* @__PURE__ */ React15.createElement(Form, {
|
|
1654
2074
|
autoSave: true,
|
|
1655
2075
|
schema: ViewMetaSchema,
|
|
1656
2076
|
values: viewValues,
|
|
1657
|
-
onSave:
|
|
1658
|
-
|
|
2077
|
+
onSave: immutable ? void 0 : handleUpdate,
|
|
2078
|
+
classNames: "min-bs-0 overflow-y-auto"
|
|
2079
|
+
}), /* @__PURE__ */ React15.createElement("div", {
|
|
2080
|
+
role: "none",
|
|
2081
|
+
className: "border-bs border-separator min-bs-0 overflow-y-auto"
|
|
2082
|
+
}, /* @__PURE__ */ React15.createElement("div", {
|
|
1659
2083
|
role: "none",
|
|
1660
2084
|
className: "p-2"
|
|
1661
2085
|
}, /* @__PURE__ */ React15.createElement("label", {
|
|
1662
2086
|
className: mx9(inputTextLabel)
|
|
1663
2087
|
}, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
|
|
1664
2088
|
items: view.fields,
|
|
1665
|
-
isItem:
|
|
2089
|
+
isItem: Schema2.is(FieldSchema),
|
|
1666
2090
|
getId: (field2) => field2.id,
|
|
1667
|
-
onMove:
|
|
2091
|
+
onMove: immutable ? void 0 : handleMove
|
|
1668
2092
|
}, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
|
|
1669
2093
|
role: "heading",
|
|
1670
2094
|
className: grid
|
|
@@ -1685,7 +2109,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1685
2109
|
icon: "ph--eye-slash--regular",
|
|
1686
2110
|
disabled: view.fields.length <= 1,
|
|
1687
2111
|
onClick: () => handleHide(field2.id)
|
|
1688
|
-
}), !
|
|
2112
|
+
}), !immutable && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
1689
2113
|
icon: "ph--trash--regular",
|
|
1690
2114
|
disabled: view.fields.length <= 1,
|
|
1691
2115
|
onClick: () => handleDelete(field2.id)
|
|
@@ -1720,281 +2144,11 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
1720
2144
|
}, /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
1721
2145
|
icon: "ph--plus--regular",
|
|
1722
2146
|
label: t("button add property"),
|
|
1723
|
-
onClick:
|
|
2147
|
+
onClick: immutable ? void 0 : handleAdd,
|
|
1724
2148
|
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
1725
2149
|
disabled: view.fields.length >= VIEW_FIELD_LIMIT
|
|
1726
2150
|
})));
|
|
1727
2151
|
};
|
|
1728
|
-
|
|
1729
|
-
// packages/ui/react-ui-form/src/util/field.ts
|
|
1730
|
-
import { FormatEnum as FormatEnum3, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo-schema";
|
|
1731
|
-
var parseValue = ({ type, format, value }) => {
|
|
1732
|
-
if (value === void 0 || value === null || value === "") {
|
|
1733
|
-
return void 0;
|
|
1734
|
-
}
|
|
1735
|
-
const parseScalar = (type2) => {
|
|
1736
|
-
switch (type2) {
|
|
1737
|
-
case TypeEnum.Boolean: {
|
|
1738
|
-
if (typeof value === "string") {
|
|
1739
|
-
const lowercaseValue = value.toLowerCase();
|
|
1740
|
-
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
1741
|
-
return false;
|
|
1742
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1743
|
-
return true;
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
return Boolean(value);
|
|
1747
|
-
}
|
|
1748
|
-
case TypeEnum.Number: {
|
|
1749
|
-
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1750
|
-
const num = Number(cleaned);
|
|
1751
|
-
return Number.isNaN(num) ? null : num;
|
|
1752
|
-
}
|
|
1753
|
-
case TypeEnum.String:
|
|
1754
|
-
case TypeEnum.Ref:
|
|
1755
|
-
return String(value);
|
|
1756
|
-
default: {
|
|
1757
|
-
return value;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
};
|
|
1761
|
-
if (!format) {
|
|
1762
|
-
return parseScalar(type);
|
|
1763
|
-
}
|
|
1764
|
-
switch (format) {
|
|
1765
|
-
case FormatEnum3.Boolean:
|
|
1766
|
-
return parseScalar(TypeEnum.Boolean);
|
|
1767
|
-
case FormatEnum3.Number:
|
|
1768
|
-
case FormatEnum3.Percent:
|
|
1769
|
-
case FormatEnum3.Currency:
|
|
1770
|
-
return parseScalar(TypeEnum.Number);
|
|
1771
|
-
case FormatEnum3.String:
|
|
1772
|
-
case FormatEnum3.Markdown: {
|
|
1773
|
-
return parseScalar(TypeEnum.String);
|
|
1774
|
-
}
|
|
1775
|
-
case FormatEnum3.Ref:
|
|
1776
|
-
throw new Error(`unexpected format: ${FormatEnum3.Ref}`);
|
|
1777
|
-
case FormatEnum3.DateTime:
|
|
1778
|
-
case FormatEnum3.Date:
|
|
1779
|
-
case FormatEnum3.Time:
|
|
1780
|
-
case FormatEnum3.Timestamp: {
|
|
1781
|
-
const date = new Date(value);
|
|
1782
|
-
return isNaN(date.getTime()) ? null : date;
|
|
1783
|
-
}
|
|
1784
|
-
case FormatEnum3.GeoPoint: {
|
|
1785
|
-
if (typeof value === "string") {
|
|
1786
|
-
const cleaned = value.replace(/[^0-9.,-]+/g, "");
|
|
1787
|
-
const parts = cleaned.split(",");
|
|
1788
|
-
if (parts.length === 2) {
|
|
1789
|
-
const lat = parseFloat(parts[0]);
|
|
1790
|
-
const long = parseFloat(parts[1]);
|
|
1791
|
-
if (!isNaN(lat) && !isNaN(long)) {
|
|
1792
|
-
return GeoLocation2.toGeoPoint({
|
|
1793
|
-
latitude: lat,
|
|
1794
|
-
longitude: long
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
return [
|
|
1800
|
-
0,
|
|
1801
|
-
0
|
|
1802
|
-
];
|
|
1803
|
-
}
|
|
1804
|
-
default: {
|
|
1805
|
-
return value;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
};
|
|
1809
|
-
var cellClassesForFieldType = ({ type, format }) => {
|
|
1810
|
-
if (!format) {
|
|
1811
|
-
switch (type) {
|
|
1812
|
-
case TypeEnum.Number:
|
|
1813
|
-
return [
|
|
1814
|
-
"text-right",
|
|
1815
|
-
"font-mono"
|
|
1816
|
-
];
|
|
1817
|
-
case TypeEnum.Boolean:
|
|
1818
|
-
return [
|
|
1819
|
-
"text-right",
|
|
1820
|
-
"font-mono"
|
|
1821
|
-
];
|
|
1822
|
-
case TypeEnum.String:
|
|
1823
|
-
return void 0;
|
|
1824
|
-
case TypeEnum.Ref:
|
|
1825
|
-
return void 0;
|
|
1826
|
-
default: {
|
|
1827
|
-
return void 0;
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
switch (format) {
|
|
1832
|
-
case FormatEnum3.Markdown:
|
|
1833
|
-
return void 0;
|
|
1834
|
-
case FormatEnum3.Time:
|
|
1835
|
-
case FormatEnum3.Timestamp:
|
|
1836
|
-
case FormatEnum3.DateTime:
|
|
1837
|
-
case FormatEnum3.Date:
|
|
1838
|
-
case FormatEnum3.Duration:
|
|
1839
|
-
return [
|
|
1840
|
-
"font-mono",
|
|
1841
|
-
"text-right"
|
|
1842
|
-
];
|
|
1843
|
-
case FormatEnum3.Currency:
|
|
1844
|
-
return [
|
|
1845
|
-
"text-right"
|
|
1846
|
-
];
|
|
1847
|
-
case FormatEnum3.JSON:
|
|
1848
|
-
case FormatEnum3.DID:
|
|
1849
|
-
return [
|
|
1850
|
-
"font-mono"
|
|
1851
|
-
];
|
|
1852
|
-
default:
|
|
1853
|
-
return void 0;
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
var pathNotUniqueError = (path) => ({
|
|
1857
|
-
path: "path",
|
|
1858
|
-
message: `'${path}' is already present`
|
|
1859
|
-
});
|
|
1860
|
-
|
|
1861
|
-
// packages/ui/react-ui-form/src/util/formatting.ts
|
|
1862
|
-
import { format as formatDate } from "date-fns/format";
|
|
1863
|
-
import { FormatEnum as FormatEnum4, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
|
|
1864
|
-
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1865
|
-
const formatScalar = (type2) => {
|
|
1866
|
-
switch (type2) {
|
|
1867
|
-
case TypeEnum2.Boolean:
|
|
1868
|
-
return value.toLocaleString().toUpperCase();
|
|
1869
|
-
case TypeEnum2.Number:
|
|
1870
|
-
return value.toLocaleString(locale);
|
|
1871
|
-
case TypeEnum2.String:
|
|
1872
|
-
case TypeEnum2.Ref:
|
|
1873
|
-
return String(value);
|
|
1874
|
-
default: {
|
|
1875
|
-
return String(value);
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
};
|
|
1879
|
-
if (!format) {
|
|
1880
|
-
return formatScalar(type);
|
|
1881
|
-
}
|
|
1882
|
-
switch (format) {
|
|
1883
|
-
case FormatEnum4.Boolean: {
|
|
1884
|
-
return formatScalar(TypeEnum2.Boolean);
|
|
1885
|
-
}
|
|
1886
|
-
case FormatEnum4.Number: {
|
|
1887
|
-
return formatScalar(TypeEnum2.Number);
|
|
1888
|
-
}
|
|
1889
|
-
case FormatEnum4.String:
|
|
1890
|
-
case FormatEnum4.Ref: {
|
|
1891
|
-
return formatScalar(TypeEnum2.String);
|
|
1892
|
-
}
|
|
1893
|
-
case FormatEnum4.Percent: {
|
|
1894
|
-
return `${value * 100}%`;
|
|
1895
|
-
}
|
|
1896
|
-
case FormatEnum4.Currency: {
|
|
1897
|
-
return value.toLocaleString(locale, {
|
|
1898
|
-
style: "currency",
|
|
1899
|
-
currency: "USD",
|
|
1900
|
-
minimumFractionDigits: 2,
|
|
1901
|
-
maximumFractionDigits: 2
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
case FormatEnum4.Date: {
|
|
1905
|
-
try {
|
|
1906
|
-
return formatDate(new Date(value), "yyyy-MM-dd");
|
|
1907
|
-
} catch (error) {
|
|
1908
|
-
return "Invalid Date";
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
case FormatEnum4.Time: {
|
|
1912
|
-
try {
|
|
1913
|
-
return formatDate(new Date(value), "HH:mm:ss");
|
|
1914
|
-
} catch (error) {
|
|
1915
|
-
return "Invalid Time";
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
case FormatEnum4.DateTime: {
|
|
1919
|
-
try {
|
|
1920
|
-
return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
|
|
1921
|
-
} catch (error) {
|
|
1922
|
-
return "Invalid DateTime";
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
case FormatEnum4.GeoPoint: {
|
|
1926
|
-
if (value === null || value === void 0) {
|
|
1927
|
-
return "";
|
|
1928
|
-
}
|
|
1929
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1930
|
-
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1931
|
-
return `${latitude},${longitude}`;
|
|
1932
|
-
}
|
|
1933
|
-
return String(value);
|
|
1934
|
-
}
|
|
1935
|
-
default: {
|
|
1936
|
-
if (value === null || value === "undefined") {
|
|
1937
|
-
return "";
|
|
1938
|
-
}
|
|
1939
|
-
return String(value);
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
};
|
|
1943
|
-
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1944
|
-
const formatScalar = (type2) => {
|
|
1945
|
-
switch (type2) {
|
|
1946
|
-
case TypeEnum2.Boolean:
|
|
1947
|
-
case TypeEnum2.Number:
|
|
1948
|
-
case TypeEnum2.String:
|
|
1949
|
-
case TypeEnum2.Ref:
|
|
1950
|
-
return String(value);
|
|
1951
|
-
default:
|
|
1952
|
-
return String(value);
|
|
1953
|
-
}
|
|
1954
|
-
};
|
|
1955
|
-
if (!format) {
|
|
1956
|
-
return formatScalar(type);
|
|
1957
|
-
}
|
|
1958
|
-
switch (format) {
|
|
1959
|
-
case FormatEnum4.Boolean:
|
|
1960
|
-
case FormatEnum4.Number:
|
|
1961
|
-
case FormatEnum4.String:
|
|
1962
|
-
case FormatEnum4.Ref: {
|
|
1963
|
-
return formatScalar(type);
|
|
1964
|
-
}
|
|
1965
|
-
case FormatEnum4.Percent: {
|
|
1966
|
-
return String(value * 100);
|
|
1967
|
-
}
|
|
1968
|
-
case FormatEnum4.Currency: {
|
|
1969
|
-
return String(value);
|
|
1970
|
-
}
|
|
1971
|
-
case FormatEnum4.DateTime: {
|
|
1972
|
-
const date = new Date(value);
|
|
1973
|
-
return date.toISOString();
|
|
1974
|
-
}
|
|
1975
|
-
case FormatEnum4.Date: {
|
|
1976
|
-
const date = new Date(value);
|
|
1977
|
-
return date.toISOString().split("T")[0];
|
|
1978
|
-
}
|
|
1979
|
-
case FormatEnum4.Time: {
|
|
1980
|
-
const date = new Date(value);
|
|
1981
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
1982
|
-
}
|
|
1983
|
-
case FormatEnum4.GeoPoint: {
|
|
1984
|
-
if (value === null || value === void 0) {
|
|
1985
|
-
return "";
|
|
1986
|
-
}
|
|
1987
|
-
if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
|
|
1988
|
-
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
|
|
1989
|
-
return `${latitude},${longitude}`;
|
|
1990
|
-
}
|
|
1991
|
-
return String(value);
|
|
1992
|
-
}
|
|
1993
|
-
default: {
|
|
1994
|
-
return String(value);
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
};
|
|
1998
2152
|
export {
|
|
1999
2153
|
BooleanInput,
|
|
2000
2154
|
ControlFrame,
|
|
@@ -2022,14 +2176,18 @@ export {
|
|
|
2022
2176
|
ViewEditor,
|
|
2023
2177
|
cellClassesForFieldType,
|
|
2024
2178
|
controlItemClasses,
|
|
2179
|
+
findArrayElementType,
|
|
2025
2180
|
formatForDisplay,
|
|
2026
2181
|
formatForEditing,
|
|
2182
|
+
getRefProps,
|
|
2027
2183
|
parseValue,
|
|
2028
2184
|
pathNotUniqueError,
|
|
2029
2185
|
translations_default as translations,
|
|
2030
2186
|
useForm,
|
|
2031
2187
|
useFormContext,
|
|
2032
2188
|
useFormValues,
|
|
2033
|
-
useInputProps
|
|
2189
|
+
useInputProps,
|
|
2190
|
+
useQueryRefOptions,
|
|
2191
|
+
useRefQueryLookupHandler
|
|
2034
2192
|
};
|
|
2035
2193
|
//# sourceMappingURL=index.mjs.map
|