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