@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
package/dist/lib/node/index.cjs
CHANGED
|
@@ -473,7 +473,7 @@ var flatMap = (errors) => {
|
|
|
473
473
|
};
|
|
474
474
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
|
|
475
475
|
var padding = "px-2";
|
|
476
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, Custom }) => {
|
|
476
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
477
477
|
const onValid = (0, import_react7.useMemo)(() => autoSave ? onSave : void 0, [
|
|
478
478
|
autoSave,
|
|
479
479
|
onSave
|
|
@@ -505,7 +505,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
505
505
|
errors
|
|
506
506
|
}, {
|
|
507
507
|
F: __dxlog_file2,
|
|
508
|
-
L:
|
|
508
|
+
L: 106,
|
|
509
509
|
S: void 0,
|
|
510
510
|
C: (f, a) => f(...a)
|
|
511
511
|
});
|
|
@@ -525,6 +525,26 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
525
525
|
];
|
|
526
526
|
const label = title ?? (0, import_effect.pipe)(name, import_String.capitalize);
|
|
527
527
|
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
528
|
+
const FoundComponent = lookupComponent?.({
|
|
529
|
+
prop: name,
|
|
530
|
+
schema: import_echo_schema2.S.make(ast),
|
|
531
|
+
inputProps: {
|
|
532
|
+
property: name,
|
|
533
|
+
type,
|
|
534
|
+
format,
|
|
535
|
+
label,
|
|
536
|
+
disabled: readonly,
|
|
537
|
+
placeholder,
|
|
538
|
+
...inputProps
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
if (FoundComponent) {
|
|
542
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
543
|
+
key: name,
|
|
544
|
+
role: "none",
|
|
545
|
+
className: padding
|
|
546
|
+
}, FoundComponent);
|
|
547
|
+
}
|
|
528
548
|
let InputComponent = Custom?.[key.join(".")];
|
|
529
549
|
if (!InputComponent) {
|
|
530
550
|
if (options) {
|
|
@@ -591,7 +611,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
591
611
|
type
|
|
592
612
|
}, {
|
|
593
613
|
F: __dxlog_file2,
|
|
594
|
-
L:
|
|
614
|
+
L: 213,
|
|
595
615
|
S: void 0,
|
|
596
616
|
C: (f, a) => f(...a)
|
|
597
617
|
});
|
|
@@ -790,9 +810,9 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
790
810
|
}, [
|
|
791
811
|
registry
|
|
792
812
|
]);
|
|
793
|
-
const [
|
|
813
|
+
const [referenceSchema, setReferenceSchema] = (0, import_react2.useState)();
|
|
794
814
|
(0, import_react2.useEffect)(() => {
|
|
795
|
-
|
|
815
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
796
816
|
}, [
|
|
797
817
|
schemas,
|
|
798
818
|
props?.referenceSchema
|
|
@@ -810,9 +830,15 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
810
830
|
fieldSchema: fieldSchema2
|
|
811
831
|
};
|
|
812
832
|
});
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
833
|
+
setReferenceSchema((prev) => {
|
|
834
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
835
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
836
|
+
if (newSchema) {
|
|
837
|
+
return newSchema;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return prev;
|
|
841
|
+
});
|
|
816
842
|
setProps((props2) => {
|
|
817
843
|
const type = import_echo_schema.formatToType[_props.format];
|
|
818
844
|
if (props2.type !== type) {
|
|
@@ -859,12 +885,38 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
859
885
|
}, [
|
|
860
886
|
onSave
|
|
861
887
|
]);
|
|
888
|
+
const Custom = (0, import_react2.useMemo)(() => ({
|
|
889
|
+
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
890
|
+
...props2,
|
|
891
|
+
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
892
|
+
value,
|
|
893
|
+
label: t(`format ${value}`)
|
|
894
|
+
}))
|
|
895
|
+
}),
|
|
896
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
897
|
+
...props2,
|
|
898
|
+
options: schemas.map((schema) => ({
|
|
899
|
+
value: schema.typename
|
|
900
|
+
}))
|
|
901
|
+
}),
|
|
902
|
+
["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
903
|
+
...props2,
|
|
904
|
+
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
905
|
+
value: p.name
|
|
906
|
+
})) : []
|
|
907
|
+
})
|
|
908
|
+
}), [
|
|
909
|
+
t,
|
|
910
|
+
schemas,
|
|
911
|
+
referenceSchema
|
|
912
|
+
]);
|
|
913
|
+
const propIsNotType = (0, import_react2.useCallback)((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
862
914
|
if (!fieldSchema) {
|
|
863
915
|
import_log.log.warn("invalid format", {
|
|
864
916
|
props
|
|
865
917
|
}, {
|
|
866
918
|
F: __dxlog_file3,
|
|
867
|
-
L:
|
|
919
|
+
L: 173,
|
|
868
920
|
S: void 0,
|
|
869
921
|
C: (f, a) => f(...a)
|
|
870
922
|
});
|
|
@@ -875,7 +927,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
875
927
|
autoFocus: true,
|
|
876
928
|
values: props,
|
|
877
929
|
schema: fieldSchema,
|
|
878
|
-
filter:
|
|
930
|
+
filter: propIsNotType,
|
|
879
931
|
sort: [
|
|
880
932
|
"property",
|
|
881
933
|
"format"
|
|
@@ -884,27 +936,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
884
936
|
onValidate: handleValidate,
|
|
885
937
|
onSave: handleSave,
|
|
886
938
|
onCancel: handleCancel,
|
|
887
|
-
Custom
|
|
888
|
-
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
889
|
-
...props2,
|
|
890
|
-
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
891
|
-
value,
|
|
892
|
-
label: t(`format ${value}`)
|
|
893
|
-
}))
|
|
894
|
-
}),
|
|
895
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
896
|
-
...props2,
|
|
897
|
-
options: schemas.map((schema2) => ({
|
|
898
|
-
value: schema2.typename
|
|
899
|
-
}))
|
|
900
|
-
}),
|
|
901
|
-
["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
902
|
-
...props2,
|
|
903
|
-
options: schema ? (0, import_schema.getSchemaProperties)(schema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
904
|
-
value: p.name
|
|
905
|
-
})) : []
|
|
906
|
-
})
|
|
907
|
-
}
|
|
939
|
+
Custom
|
|
908
940
|
});
|
|
909
941
|
};
|
|
910
942
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
@@ -916,7 +948,7 @@ var ViewMetaSchema = import_echo_schema5.S.Struct({
|
|
|
916
948
|
[import_echo_schema5.AST.TitleAnnotationId]: "Typename"
|
|
917
949
|
})
|
|
918
950
|
}).pipe(import_echo_schema5.S.mutable);
|
|
919
|
-
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
951
|
+
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
920
952
|
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
921
953
|
const projection = (0, import_react9.useMemo)(() => new import_schema4.ViewProjection(schema, view), [
|
|
922
954
|
schema,
|
|
@@ -935,13 +967,17 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
935
967
|
]);
|
|
936
968
|
const handleViewUpdate = (0, import_react9.useCallback)(({ name, typename }) => {
|
|
937
969
|
requestAnimationFrame(() => {
|
|
938
|
-
view.name
|
|
939
|
-
|
|
940
|
-
|
|
970
|
+
if (view.name !== name) {
|
|
971
|
+
view.name = name;
|
|
972
|
+
}
|
|
973
|
+
if (view.query.type !== typename) {
|
|
974
|
+
onTypenameChanged(typename);
|
|
975
|
+
}
|
|
941
976
|
});
|
|
942
977
|
}, [
|
|
943
978
|
view,
|
|
944
|
-
schema
|
|
979
|
+
schema,
|
|
980
|
+
onTypenameChanged
|
|
945
981
|
]);
|
|
946
982
|
const handleSelect = (0, import_react9.useCallback)((field2) => {
|
|
947
983
|
setField((f) => f === field2 ? void 0 : field2);
|