@dxos/react-ui-form 0.7.5-main.9cb18ac → 0.7.5-main.9d2a38b
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 +76 -40
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +72 -36
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +76 -40
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +9 -3
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -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/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/src/components/FieldEditor/FieldEditor.tsx +56 -39
- package/src/components/Form/Form.tsx +30 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +25 -4
- package/src/components/ViewEditor/ViewEditor.tsx +9 -4
|
@@ -82,7 +82,7 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
// packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
|
|
85
|
-
import React7, { useCallback as useCallback2, useEffect as useEffect3, useState as useState2 } from "react";
|
|
85
|
+
import React7, { useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo3, useState as useState2 } from "react";
|
|
86
86
|
import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
|
|
87
87
|
import { log as log3 } from "@dxos/log";
|
|
88
88
|
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
@@ -437,7 +437,7 @@ var flatMap = (errors) => {
|
|
|
437
437
|
// packages/ui/react-ui-form/src/components/Form/Form.tsx
|
|
438
438
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
|
|
439
439
|
var padding = "px-2";
|
|
440
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, Custom }) => {
|
|
440
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
441
441
|
const onValid = useMemo2(() => autoSave ? onSave : void 0, [
|
|
442
442
|
autoSave,
|
|
443
443
|
onSave
|
|
@@ -469,7 +469,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
469
469
|
errors
|
|
470
470
|
}, {
|
|
471
471
|
F: __dxlog_file2,
|
|
472
|
-
L:
|
|
472
|
+
L: 106,
|
|
473
473
|
S: void 0,
|
|
474
474
|
C: (f, a) => f(...a)
|
|
475
475
|
});
|
|
@@ -489,6 +489,26 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
489
489
|
];
|
|
490
490
|
const label = title ?? pipe(name, capitalize);
|
|
491
491
|
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
492
|
+
const FoundComponent = lookupComponent?.({
|
|
493
|
+
prop: name,
|
|
494
|
+
schema: S.make(ast),
|
|
495
|
+
inputProps: {
|
|
496
|
+
property: name,
|
|
497
|
+
type,
|
|
498
|
+
format,
|
|
499
|
+
label,
|
|
500
|
+
disabled: readonly,
|
|
501
|
+
placeholder,
|
|
502
|
+
...inputProps
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
if (FoundComponent) {
|
|
506
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
507
|
+
key: name,
|
|
508
|
+
role: "none",
|
|
509
|
+
className: padding
|
|
510
|
+
}, FoundComponent);
|
|
511
|
+
}
|
|
492
512
|
let InputComponent = Custom?.[key.join(".")];
|
|
493
513
|
if (!InputComponent) {
|
|
494
514
|
if (options) {
|
|
@@ -555,7 +575,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
555
575
|
type
|
|
556
576
|
}, {
|
|
557
577
|
F: __dxlog_file2,
|
|
558
|
-
L:
|
|
578
|
+
L: 213,
|
|
559
579
|
S: void 0,
|
|
560
580
|
C: (f, a) => f(...a)
|
|
561
581
|
});
|
|
@@ -756,9 +776,9 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
756
776
|
}, [
|
|
757
777
|
registry
|
|
758
778
|
]);
|
|
759
|
-
const [
|
|
779
|
+
const [referenceSchema, setReferenceSchema] = useState2();
|
|
760
780
|
useEffect3(() => {
|
|
761
|
-
|
|
781
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
762
782
|
}, [
|
|
763
783
|
schemas,
|
|
764
784
|
props?.referenceSchema
|
|
@@ -776,9 +796,15 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
776
796
|
fieldSchema: fieldSchema2
|
|
777
797
|
};
|
|
778
798
|
});
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
799
|
+
setReferenceSchema((prev) => {
|
|
800
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
801
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
802
|
+
if (newSchema) {
|
|
803
|
+
return newSchema;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return prev;
|
|
807
|
+
});
|
|
782
808
|
setProps((props2) => {
|
|
783
809
|
const type = formatToType[_props.format];
|
|
784
810
|
if (props2.type !== type) {
|
|
@@ -825,12 +851,38 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
825
851
|
}, [
|
|
826
852
|
onSave
|
|
827
853
|
]);
|
|
854
|
+
const Custom = useMemo3(() => ({
|
|
855
|
+
["format"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
856
|
+
...props2,
|
|
857
|
+
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
858
|
+
value,
|
|
859
|
+
label: t(`format ${value}`)
|
|
860
|
+
}))
|
|
861
|
+
}),
|
|
862
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
863
|
+
...props2,
|
|
864
|
+
options: schemas.map((schema) => ({
|
|
865
|
+
value: schema.typename
|
|
866
|
+
}))
|
|
867
|
+
}),
|
|
868
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
869
|
+
...props2,
|
|
870
|
+
options: referenceSchema ? getSchemaProperties2(referenceSchema.ast).sort(sortProperties).map((p) => ({
|
|
871
|
+
value: p.name
|
|
872
|
+
})) : []
|
|
873
|
+
})
|
|
874
|
+
}), [
|
|
875
|
+
t,
|
|
876
|
+
schemas,
|
|
877
|
+
referenceSchema
|
|
878
|
+
]);
|
|
879
|
+
const propIsNotType = useCallback2((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
828
880
|
if (!fieldSchema) {
|
|
829
881
|
log3.warn("invalid format", {
|
|
830
882
|
props
|
|
831
883
|
}, {
|
|
832
884
|
F: __dxlog_file3,
|
|
833
|
-
L:
|
|
885
|
+
L: 173,
|
|
834
886
|
S: void 0,
|
|
835
887
|
C: (f, a) => f(...a)
|
|
836
888
|
});
|
|
@@ -841,7 +893,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
841
893
|
autoFocus: true,
|
|
842
894
|
values: props,
|
|
843
895
|
schema: fieldSchema,
|
|
844
|
-
filter:
|
|
896
|
+
filter: propIsNotType,
|
|
845
897
|
sort: [
|
|
846
898
|
"property",
|
|
847
899
|
"format"
|
|
@@ -850,32 +902,12 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
850
902
|
onValidate: handleValidate,
|
|
851
903
|
onSave: handleSave,
|
|
852
904
|
onCancel: handleCancel,
|
|
853
|
-
Custom
|
|
854
|
-
["format"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
855
|
-
...props2,
|
|
856
|
-
options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
|
|
857
|
-
value,
|
|
858
|
-
label: t(`format ${value}`)
|
|
859
|
-
}))
|
|
860
|
-
}),
|
|
861
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
862
|
-
...props2,
|
|
863
|
-
options: schemas.map((schema2) => ({
|
|
864
|
-
value: schema2.typename
|
|
865
|
-
}))
|
|
866
|
-
}),
|
|
867
|
-
["referencePath"]: (props2) => /* @__PURE__ */ React7.createElement(SelectInput, {
|
|
868
|
-
...props2,
|
|
869
|
-
options: schema ? getSchemaProperties2(schema.ast).sort(sortProperties).map((p) => ({
|
|
870
|
-
value: p.name
|
|
871
|
-
})) : []
|
|
872
|
-
})
|
|
873
|
-
}
|
|
905
|
+
Custom
|
|
874
906
|
});
|
|
875
907
|
};
|
|
876
908
|
|
|
877
909
|
// packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
|
|
878
|
-
import React8, { useCallback as useCallback3, useMemo as
|
|
910
|
+
import React8, { useCallback as useCallback3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
879
911
|
import { AST as AST2, Format, S as S2 } from "@dxos/echo-schema";
|
|
880
912
|
import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
881
913
|
import { List } from "@dxos/react-ui-list";
|
|
@@ -891,14 +923,14 @@ var ViewMetaSchema = S2.Struct({
|
|
|
891
923
|
[AST2.TitleAnnotationId]: "Typename"
|
|
892
924
|
})
|
|
893
925
|
}).pipe(S2.mutable);
|
|
894
|
-
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
926
|
+
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
895
927
|
const { t } = useTranslation4(translationKey);
|
|
896
|
-
const projection =
|
|
928
|
+
const projection = useMemo4(() => new ViewProjection(schema, view), [
|
|
897
929
|
schema,
|
|
898
930
|
view
|
|
899
931
|
]);
|
|
900
932
|
const [field, setField] = useState3();
|
|
901
|
-
const viewValues =
|
|
933
|
+
const viewValues = useMemo4(() => {
|
|
902
934
|
return {
|
|
903
935
|
name: view.name,
|
|
904
936
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -910,13 +942,17 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
910
942
|
]);
|
|
911
943
|
const handleViewUpdate = useCallback3(({ name, typename }) => {
|
|
912
944
|
requestAnimationFrame(() => {
|
|
913
|
-
view.name
|
|
914
|
-
|
|
915
|
-
|
|
945
|
+
if (view.name !== name) {
|
|
946
|
+
view.name = name;
|
|
947
|
+
}
|
|
948
|
+
if (view.query.type !== typename) {
|
|
949
|
+
onTypenameChanged(typename);
|
|
950
|
+
}
|
|
916
951
|
});
|
|
917
952
|
}, [
|
|
918
953
|
view,
|
|
919
|
-
schema
|
|
954
|
+
schema,
|
|
955
|
+
onTypenameChanged
|
|
920
956
|
]);
|
|
921
957
|
const handleSelect = useCallback3((field2) => {
|
|
922
958
|
setField((f) => f === field2 ? void 0 : field2);
|