@dxos/react-ui-form 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446

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.
Files changed (97) hide show
  1. package/dist/lib/browser/index.mjs +537 -846
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +506 -807
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +537 -846
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/{ControlSection/ControlSection.d.ts → ControlSection.d.ts} +5 -8
  11. package/dist/types/src/components/ControlSection.d.ts.map +1 -0
  12. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  13. package/dist/types/src/components/Form/ArrayField.d.ts.map +1 -1
  14. package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
  15. package/dist/types/src/components/Form/Form.d.ts +4 -6
  16. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  17. package/dist/types/src/components/Form/Form.stories.d.ts +34 -37
  18. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  19. package/dist/types/src/components/Form/FormActions.d.ts.map +1 -1
  20. package/dist/types/src/components/Form/FormContent.d.ts +11 -14
  21. package/dist/types/src/components/Form/FormContent.d.ts.map +1 -1
  22. package/dist/types/src/components/Form/FormContext.d.ts +2 -2
  23. package/dist/types/src/components/Form/FormContext.d.ts.map +1 -1
  24. package/dist/types/src/components/Form/Input.d.ts.map +1 -1
  25. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -1
  26. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +1 -1
  27. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +1 -1
  28. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -1
  29. package/dist/types/src/components/Form/factory.d.ts +1 -1
  30. package/dist/types/src/components/Form/factory.d.ts.map +1 -1
  31. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  32. package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -1
  33. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
  34. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  35. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  36. package/dist/types/src/components/deprecated/Form.d.ts +2 -2
  37. package/dist/types/src/components/deprecated/Form.d.ts.map +1 -1
  38. package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -1
  39. package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -1
  40. package/dist/types/src/components/index.d.ts.map +1 -1
  41. package/dist/types/src/components/testing.d.ts.map +1 -1
  42. package/dist/types/src/hooks/index.d.ts +0 -2
  43. package/dist/types/src/hooks/index.d.ts.map +1 -1
  44. package/dist/types/src/hooks/useForm.d.ts +2 -2
  45. package/dist/types/src/hooks/useForm.d.ts.map +1 -1
  46. package/dist/types/src/util/field.d.ts.map +1 -1
  47. package/dist/types/src/util/formatting.d.ts.map +1 -1
  48. package/dist/types/src/util/index.d.ts +0 -2
  49. package/dist/types/src/util/index.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +25 -26
  52. package/src/components/{ControlSection/ControlSection.tsx → ControlSection.tsx} +14 -38
  53. package/src/components/FieldEditor/FieldEditor.stories.tsx +1 -1
  54. package/src/components/Form/ArrayField.tsx +17 -13
  55. package/src/components/Form/Defaults.tsx +1 -4
  56. package/src/components/Form/Form.stories.tsx +43 -92
  57. package/src/components/Form/Form.tsx +3 -7
  58. package/src/components/Form/FormContent.tsx +19 -90
  59. package/src/components/Form/FormContext.tsx +3 -13
  60. package/src/components/Form/Input.tsx +9 -3
  61. package/src/components/Form/custom/GeoPointInput.tsx +2 -2
  62. package/src/components/Form/custom/SelectOptionsInput.stories.tsx +5 -6
  63. package/src/components/Form/custom/SelectOptionsInput.tsx +2 -2
  64. package/src/components/Form/factory.tsx +1 -1
  65. package/src/components/Form/index.ts +1 -0
  66. package/src/components/ViewEditor/ViewEditor.stories.tsx +4 -5
  67. package/src/components/ViewEditor/ViewEditor.tsx +20 -23
  68. package/src/components/deprecated/Form.stories.tsx +6 -6
  69. package/src/components/deprecated/Form.tsx +6 -6
  70. package/src/components/deprecated/FormInput.tsx +1 -1
  71. package/src/components/index.ts +0 -1
  72. package/src/hooks/index.ts +1 -3
  73. package/src/hooks/useForm.ts +3 -4
  74. package/src/util/formatting.ts +3 -15
  75. package/src/util/index.ts +1 -3
  76. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
  77. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -8
  78. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
  79. package/dist/types/src/components/ControlSection/index.d.ts +0 -2
  80. package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
  81. package/dist/types/src/components/Form/RefField.d.ts +0 -12
  82. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  83. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
  84. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  85. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  86. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  87. package/dist/types/src/util/refs.d.ts +0 -9
  88. package/dist/types/src/util/refs.d.ts.map +0 -1
  89. package/dist/types/src/util/schema.d.ts +0 -3
  90. package/dist/types/src/util/schema.d.ts.map +0 -1
  91. package/src/components/ControlSection/ControlSection.stories.tsx +0 -29
  92. package/src/components/ControlSection/index.ts +0 -5
  93. package/src/components/Form/RefField.tsx +0 -197
  94. package/src/hooks/useQueryRefOptions.ts +0 -53
  95. package/src/hooks/useRefQueryLookupHandler.ts +0 -41
  96. package/src/util/refs.ts +0 -38
  97. package/src/util/schema.ts +0 -14
@@ -65,7 +65,7 @@ import { mx, textBlockWidth } from "@dxos/react-ui-theme";
65
65
  var DeprecatedFormContainer = ({ children, classNames }) => {
66
66
  return /* @__PURE__ */ React.createElement("div", {
67
67
  role: "none",
68
- className: "container-max-width p-4 justify-center overflow-x-hidden overflow-y-auto"
68
+ className: "w-full p-4 justify-center overflow-x-hidden overflow-y-auto"
69
69
  }, /* @__PURE__ */ React.createElement("div", {
70
70
  role: "form",
71
71
  className: mx("flex flex-col", textBlockWidth, classNames)
@@ -99,23 +99,9 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
99
99
  return primary;
100
100
  };
101
101
 
102
- // packages/ui/react-ui-form/src/components/ControlSection/ControlSection.tsx
102
+ // packages/ui/react-ui-form/src/components/ControlSection.tsx
103
103
  import React2 from "react";
104
- import { Button, Input as Input2, toLocalizedString, useTranslation } from "@dxos/react-ui";
105
- import { mx as mx2 } from "@dxos/react-ui-theme";
106
- var ControlPage = ({ children, classNames, ...props }) => {
107
- return /* @__PURE__ */ React2.createElement("div", {
108
- role: "none",
109
- className: mx2("pli-2", classNames),
110
- ...props
111
- }, children);
112
- };
113
- var ControlSection = ({ title, description, children }) => {
114
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ControlSectionHeading, {
115
- title,
116
- description
117
- }), children);
118
- };
104
+ import { toLocalizedString, useTranslation, Input as Input2 } from "@dxos/react-ui";
119
105
  var ControlSectionHeading = ({ title, description }) => {
120
106
  const { t } = useTranslation(translationKey);
121
107
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", {
@@ -124,18 +110,15 @@ var ControlSectionHeading = ({ title, description }) => {
124
110
  className: "pli-4 mlb-4 container-max-width text-description"
125
111
  }, toLocalizedString(description, t)));
126
112
  };
127
- var ControlGroupButton = ({ classNames, ...props }) => {
128
- return /* @__PURE__ */ React2.createElement(Button, {
129
- ...props,
130
- classNames: [
131
- "md:col-span-2",
132
- classNames
133
- ]
134
- });
113
+ var ControlSection = ({ title, description, children }) => {
114
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ControlSectionHeading, {
115
+ title,
116
+ description
117
+ }), children);
135
118
  };
136
- var ControlGroup = ({ children, classNames }) => /* @__PURE__ */ React2.createElement("div", {
119
+ var ControlGroup = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
137
120
  role: "none",
138
- className: mx2("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4", classNames)
121
+ className: "group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-4"
139
122
  }, children);
140
123
  var ControlFrame = ({ children }) => /* @__PURE__ */ React2.createElement("div", {
141
124
  role: "none",
@@ -181,9 +164,9 @@ var ControlFrameItem = ({ title, description, children }) => {
181
164
  };
182
165
 
183
166
  // packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
184
- import React14, { useCallback as useCallback8, useEffect as useEffect8, useMemo as useMemo7, useState as useState5 } from "react";
185
- import { FormatEnum as FormatEnum5, FormatEnums, formatToType } from "@dxos/echo-schema";
186
- import { log as log3 } from "@dxos/log";
167
+ import React13, { useCallback as useCallback6, useEffect as useEffect7, useMemo as useMemo7, useState as useState4 } from "react";
168
+ import { FormatEnum as FormatEnum2, FormatEnums, formatToType } from "@dxos/echo-schema";
169
+ import { log as log2 } from "@dxos/log";
187
170
  import { useTranslation as useTranslation6 } from "@dxos/react-ui";
188
171
  import { getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
189
172
 
@@ -201,15 +184,15 @@ var InputHeader = ({ children, error }) => {
201
184
  return /* @__PURE__ */ React3.createElement("div", {
202
185
  role: "none",
203
186
  className: "flex justify-between items-center mb-1"
204
- }, children, error && /* @__PURE__ */ React3.createElement(Tooltip.Trigger, {
205
- asChild: true,
206
- content: error,
207
- side: "bottom"
187
+ }, children, error && /* @__PURE__ */ React3.createElement(Tooltip.Root, null, /* @__PURE__ */ React3.createElement(Tooltip.Trigger, {
188
+ asChild: true
208
189
  }, /* @__PURE__ */ React3.createElement(Icon, {
209
190
  icon: "ph--warning--regular",
210
191
  size: 4,
211
192
  classNames: errorText
212
- })));
193
+ })), /* @__PURE__ */ React3.createElement(Tooltip.Content, {
194
+ side: "bottom"
195
+ }, /* @__PURE__ */ React3.createElement(Tooltip.Arrow, null), error)));
213
196
  };
214
197
 
215
198
  // packages/ui/react-ui-form/src/components/Form/custom/GeoPointInput.tsx
@@ -289,7 +272,7 @@ import { PublicKey } from "@dxos/keys";
289
272
  import { Icon as Icon2, IconButton, Input as Input4, Tag, Toolbar, useTranslation as useTranslation3 } from "@dxos/react-ui";
290
273
  import { List } from "@dxos/react-ui-list";
291
274
  import { HuePicker } from "@dxos/react-ui-pickers";
292
- import { hues, mx as mx3 } from "@dxos/react-ui-theme";
275
+ import { hues, mx as mx2 } from "@dxos/react-ui-theme";
293
276
  var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3, onValueChange }) => {
294
277
  const [selected, setSelectedId] = useState2(null);
295
278
  const [isNewOption, setIsNewOption] = useState2(false);
@@ -415,7 +398,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
415
398
  }, /* @__PURE__ */ React5.createElement(List.Item, {
416
399
  role: "button",
417
400
  item,
418
- classNames: mx3("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
401
+ classNames: mx2("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
419
402
  "aria-expanded": selected === item.id
420
403
  }, /* @__PURE__ */ React5.createElement("div", {
421
404
  className: "flex items-center"
@@ -456,7 +439,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
456
439
  role: "listitem"
457
440
  }, /* @__PURE__ */ React5.createElement("div", {
458
441
  role: "button",
459
- className: mx3("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
442
+ className: mx2("p-1 plb-2", "flex flex-col", "cursor-pointer", "hover:bg-hoverOverlay"),
460
443
  onClick: handleAdd
461
444
  }, /* @__PURE__ */ React5.createElement("div", {
462
445
  className: "flex items-center gap-1"
@@ -470,7 +453,7 @@ var SelectOptionInput = ({ type, label, disabled, getStatus, getValue: getValue3
470
453
  // packages/ui/react-ui-form/src/components/Form/custom/TupleInput.tsx
471
454
  import React6 from "react";
472
455
  import { Input as Input5 } from "@dxos/react-ui";
473
- import { mx as mx4 } from "@dxos/react-ui-theme";
456
+ import { mx as mx3 } from "@dxos/react-ui-theme";
474
457
  import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
475
458
  var gridCols = [
476
459
  "grid-cols-1",
@@ -486,7 +469,7 @@ var TupleInput = ({ binding, type, label, disabled, getStatus, getValue: getValu
486
469
  }, /* @__PURE__ */ React6.createElement(InputHeader, {
487
470
  error
488
471
  }, /* @__PURE__ */ React6.createElement(Input5.Label, null, label)), /* @__PURE__ */ React6.createElement("div", {
489
- className: mx4("grid gap-2", gridCols[binding.length - 1])
472
+ className: mx3("grid gap-2", gridCols[binding.length - 1])
490
473
  }, binding.map((prop) => /* @__PURE__ */ React6.createElement(Input5.TextInput, {
491
474
  key: prop,
492
475
  type: "number",
@@ -546,28 +529,23 @@ var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, on
546
529
  };
547
530
  var SelectInput = ({ type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
548
531
  const { status, error } = getStatus();
549
- const value = getValue3();
550
- const handleValueChange = useCallback3((value2) => onValueChange(type, value2), [
551
- type,
552
- onValueChange
553
- ]);
554
532
  return /* @__PURE__ */ React7.createElement(Input6.Root, {
555
533
  validationValence: status
556
534
  }, !inputOnly && /* @__PURE__ */ React7.createElement(InputHeader, {
557
535
  error
558
536
  }, /* @__PURE__ */ React7.createElement(Input6.Label, null, label)), /* @__PURE__ */ React7.createElement(Select.Root, {
559
- value,
560
- onValueChange: handleValueChange
537
+ value: getValue3(),
538
+ onValueChange: (value) => onValueChange(type, value)
561
539
  }, /* @__PURE__ */ React7.createElement(Select.TriggerButton, {
562
540
  classNames: "is-full",
563
541
  disabled,
564
542
  placeholder
565
- }), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value: value2, label: label2 }) => (
543
+ }), /* @__PURE__ */ React7.createElement(Select.Portal, null, /* @__PURE__ */ React7.createElement(Select.Content, null, /* @__PURE__ */ React7.createElement(Select.Viewport, null, options?.map(({ value, label: label2 }) => (
566
544
  // NOTE: Numeric values are converted to and from strings.
567
545
  /* @__PURE__ */ React7.createElement(Select.Option, {
568
- key: String(value2),
569
- value: String(value2)
570
- }, label2 ?? String(value2))
546
+ key: String(value),
547
+ value: String(value)
548
+ }, label2 ?? String(value))
571
549
  )))))), inputOnly && /* @__PURE__ */ React7.createElement(Input6.DescriptionAndValidation, null, error));
572
550
  };
573
551
  var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
@@ -611,22 +589,22 @@ var MarkdownInput = ({ type, label, inputOnly, disabled, placeholder, getStatus,
611
589
  };
612
590
 
613
591
  // packages/ui/react-ui-form/src/components/Form/Form.tsx
614
- import React13, { useEffect as useEffect7, useMemo as useMemo6, useRef as useRef3 } from "react";
615
- import { mx as mx8 } from "@dxos/react-ui-theme";
592
+ import React12, { useEffect as useEffect6, useMemo as useMemo6, useRef as useRef3 } from "react";
593
+ import { mx as mx7 } from "@dxos/react-ui-theme";
616
594
 
617
595
  // packages/ui/react-ui-form/src/components/Form/FormActions.tsx
618
596
  import React9 from "react";
619
597
  import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
620
- import { mx as mx5 } from "@dxos/react-ui-theme";
598
+ import { mx as mx4 } from "@dxos/react-ui-theme";
621
599
 
622
600
  // packages/ui/react-ui-form/src/components/Form/FormContext.tsx
623
- import React8, { createContext, useContext, useEffect as useEffect6, useMemo as useMemo3 } from "react";
601
+ import React8, { createContext, useContext, useEffect as useEffect5, useMemo as useMemo3 } from "react";
624
602
  import { raise } from "@dxos/debug";
625
603
  import { getValue as getValue2 } from "@dxos/echo-schema";
626
604
  import { createJsonPath as createJsonPath2 } from "@dxos/effect";
627
605
 
628
606
  // packages/ui/react-ui-form/src/hooks/useForm.ts
629
- import { SchemaAST } from "effect";
607
+ import { SchemaAST as AST } from "effect";
630
608
  import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
631
609
  import { getValue, setValue } from "@dxos/echo-schema";
632
610
  import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
@@ -635,12 +613,12 @@ import { log } from "@dxos/log";
635
613
  import { validateSchema } from "@dxos/schema";
636
614
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
637
615
  var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
638
- invariant(SchemaAST.isTypeLiteral(schema.ast), void 0, {
616
+ invariant(AST.isTypeLiteral(schema.ast), void 0, {
639
617
  F: __dxlog_file,
640
618
  L: 93,
641
619
  S: void 0,
642
620
  A: [
643
- "SchemaAST.isTypeLiteral(schema.ast)",
621
+ "AST.isTypeLiteral(schema.ast)",
644
622
  ""
645
623
  ]
646
624
  });
@@ -741,7 +719,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
741
719
  } catch (err) {
742
720
  log.catch(err, void 0, {
743
721
  F: __dxlog_file,
744
- L: 213,
722
+ L: 212,
745
723
  S: void 0,
746
724
  C: (f, a) => f(...a)
747
725
  });
@@ -812,7 +790,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
812
790
  var createKeySet = (obj, value) => {
813
791
  invariant(obj, void 0, {
814
792
  F: __dxlog_file,
815
- L: 275,
793
+ L: 274,
816
794
  S: void 0,
817
795
  A: [
818
796
  "obj",
@@ -834,81 +812,6 @@ var flatMap = (errors) => {
834
812
  }, {});
835
813
  };
836
814
 
837
- // packages/ui/react-ui-form/src/hooks/useRefQueryLookupHandler.ts
838
- import { useCallback as useCallback5 } from "react";
839
- import { getDXN } from "@dxos/echo-schema";
840
- import { Filter } from "@dxos/react-client/echo";
841
- import { isNonNullable } from "@dxos/util";
842
- var useRefQueryLookupHandler = ({ space }) => {
843
- const handleRefQueryLookup = useCallback5(async (typeInfo) => {
844
- if (!space) {
845
- return [];
846
- }
847
- const query = space.db.query(Filter.typename(typeInfo.typename));
848
- const { objects } = await query.run();
849
- return objects.map((object) => {
850
- const dxn = getDXN(object);
851
- if (!dxn) {
852
- return void 0;
853
- }
854
- const item = {
855
- dxn,
856
- label: object?.name ?? object?.id ?? ""
857
- };
858
- return item;
859
- }).filter(isNonNullable);
860
- }, [
861
- space
862
- ]);
863
- return handleRefQueryLookup;
864
- };
865
-
866
- // packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts
867
- import { useEffect as useEffect5, useState as useState4 } from "react";
868
- import { log as log2 } from "@dxos/log";
869
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
870
- var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
871
- const [options, setOptions] = useState4([]);
872
- const [loading, setLoading] = useState4(false);
873
- useEffect5(() => {
874
- if (!refTypeInfo || !onQueryRefOptions) {
875
- return;
876
- }
877
- const fetchOptions = async () => {
878
- setLoading(true);
879
- try {
880
- const fetchedOptions = await onQueryRefOptions(refTypeInfo);
881
- setOptions(fetchedOptions.map((option) => {
882
- const dxn = option.dxn.toString();
883
- return {
884
- id: dxn,
885
- label: option.label ?? dxn,
886
- hue: "neutral"
887
- };
888
- }));
889
- } catch (error) {
890
- log2.error("Failed to fetch ref options:", error, {
891
- F: __dxlog_file2,
892
- L: 42,
893
- S: void 0,
894
- C: (f, a) => f(...a)
895
- });
896
- setOptions([]);
897
- } finally {
898
- setLoading(false);
899
- }
900
- };
901
- void fetchOptions();
902
- }, [
903
- refTypeInfo,
904
- onQueryRefOptions
905
- ]);
906
- return {
907
- options,
908
- loading
909
- };
910
- };
911
-
912
815
  // packages/ui/react-ui-form/src/components/Form/FormContext.tsx
913
816
  var FormContext = /* @__PURE__ */ createContext(void 0);
914
817
  var useFormContext = () => {
@@ -939,7 +842,7 @@ var useInputProps = (path = []) => {
939
842
  };
940
843
  var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
941
844
  const form = useForm(formOptions);
942
- useEffect6(() => {
845
+ useEffect5(() => {
943
846
  if (!formRef?.current) {
944
847
  return;
945
848
  }
@@ -947,7 +850,7 @@ var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
947
850
  const keyIsEnter = event.key === "Enter";
948
851
  const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
949
852
  const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
950
- const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
853
+ const inputOptOut = event.target.hasAttribute("data-no-submit");
951
854
  const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
952
855
  const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
953
856
  if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
@@ -983,7 +886,7 @@ var FormActions = ({ onCancel, readonly }) => {
983
886
  className: "mt-2 flex justify-center"
984
887
  }, /* @__PURE__ */ React9.createElement("div", {
985
888
  role: "none",
986
- className: mx5(onCancel && !readonly && "grid grid-cols-2 gap-2")
889
+ className: mx4(onCancel && !readonly && "grid grid-cols-2 gap-2")
987
890
  }, onCancel && !readonly && /* @__PURE__ */ React9.createElement(IconButton2, {
988
891
  "data-testid": "cancel-button",
989
892
  icon: "ph--x--regular",
@@ -1000,588 +903,151 @@ var FormActions = ({ onCancel, readonly }) => {
1000
903
  };
1001
904
 
1002
905
  // packages/ui/react-ui-form/src/components/Form/FormContent.tsx
1003
- import { Schema, SchemaAST as SchemaAST4, pipe as pipe2 } from "effect";
906
+ import { pipe as pipe2 } from "effect";
1004
907
  import { capitalize as capitalize2 } from "effect/String";
1005
- import React12, { useMemo as useMemo5 } from "react";
1006
- import { createJsonPath as createJsonPath3, findNode as findNode3, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
1007
- import { mx as mx7 } from "@dxos/react-ui-theme";
908
+ import React11, { useMemo as useMemo5 } from "react";
909
+ import { AST as AST3, S } from "@dxos/echo-schema";
910
+ import { createJsonPath as createJsonPath3, findNode as findNode2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
911
+ import { mx as mx6 } from "@dxos/react-ui-theme";
1008
912
  import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
1009
913
  import { isNotFalsy } from "@dxos/util";
1010
914
 
1011
915
  // packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
1012
- import { SchemaAST as SchemaAST3, pipe } from "effect";
916
+ import { pipe } from "effect";
1013
917
  import { capitalize } from "effect/String";
1014
- import React10, { useCallback as useCallback6 } from "react";
1015
- import { findNode as findNode2, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
918
+ import React10, { useCallback as useCallback5, useMemo as useMemo4 } from "react";
919
+ import { AST as AST2 } from "@dxos/echo-schema";
920
+ import { findNode, getDiscriminatedType, isDiscriminatedUnion, SimpleType } from "@dxos/effect";
1016
921
  import { invariant as invariant2 } from "@dxos/invariant";
1017
922
  import { IconButton as IconButton3, useTranslation as useTranslation5 } from "@dxos/react-ui";
1018
- import { mx as mx6 } from "@dxos/react-ui-theme";
923
+ import { mx as mx5 } from "@dxos/react-ui-theme";
1019
924
  import { getSchemaProperties } from "@dxos/schema";
1020
-
1021
- // packages/ui/react-ui-form/src/util/field.ts
1022
- import { FormatEnum, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo-schema";
1023
- var parseValue = ({ type, format, value }) => {
1024
- if (value === void 0 || value === null || value === "") {
1025
- return void 0;
1026
- }
1027
- const parseScalar = (type2) => {
1028
- switch (type2) {
1029
- case TypeEnum.Boolean: {
1030
- if (typeof value === "string") {
1031
- const lowercaseValue = value.toLowerCase();
1032
- if (lowercaseValue === "0" || lowercaseValue === "false") {
1033
- return false;
1034
- } else if (lowercaseValue === "1" || lowercaseValue === "true") {
1035
- return true;
1036
- }
1037
- }
1038
- return Boolean(value);
1039
- }
1040
- case TypeEnum.Number: {
1041
- const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
1042
- const num = Number(cleaned);
1043
- return Number.isNaN(num) ? null : num;
1044
- }
1045
- case TypeEnum.String:
1046
- case TypeEnum.Ref:
1047
- return String(value);
1048
- default: {
1049
- return value;
1050
- }
925
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
926
+ var padding = "px-2";
927
+ var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
928
+ const { t } = useTranslation5(translationKey);
929
+ const { ast, name, type, title } = property;
930
+ const values = useFormValues(path ?? []);
931
+ invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
932
+ F: __dxlog_file2,
933
+ L: 37,
934
+ S: void 0,
935
+ A: [
936
+ "Array.isArray(values)",
937
+ "`Values at path ${path?.join('.')} must be an array.`"
938
+ ]
939
+ });
940
+ const label = title ?? pipe(name, capitalize);
941
+ const tupleType = findNode(ast, AST2.isTupleType);
942
+ const elementType = tupleType?.rest[0]?.type;
943
+ const getDefaultObjectValue = (typeNode) => {
944
+ const baseNode = findNode(typeNode, isDiscriminatedUnion);
945
+ const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, AST2.isTypeLiteral);
946
+ if (!typeLiteral) {
947
+ return {};
1051
948
  }
949
+ return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
950
+ prop.name,
951
+ prop.defaultValue
952
+ ]));
1052
953
  };
1053
- if (!format) {
1054
- return parseScalar(type);
1055
- }
1056
- switch (format) {
1057
- case FormatEnum.Boolean:
1058
- return parseScalar(TypeEnum.Boolean);
1059
- case FormatEnum.Number:
1060
- case FormatEnum.Percent:
1061
- case FormatEnum.Currency:
1062
- return parseScalar(TypeEnum.Number);
1063
- case FormatEnum.String:
1064
- case FormatEnum.Markdown: {
1065
- return parseScalar(TypeEnum.String);
1066
- }
1067
- case FormatEnum.Ref:
1068
- throw new Error(`unexpected format: ${FormatEnum.Ref}`);
1069
- case FormatEnum.DateTime:
1070
- case FormatEnum.Date:
1071
- case FormatEnum.Time:
1072
- case FormatEnum.Timestamp: {
1073
- const date = new Date(value);
1074
- return isNaN(date.getTime()) ? null : date;
1075
- }
1076
- case FormatEnum.GeoPoint: {
1077
- if (typeof value === "string") {
1078
- const cleaned = value.replace(/[^0-9.,-]+/g, "");
1079
- const parts = cleaned.split(",");
1080
- if (parts.length === 2) {
1081
- const lat = parseFloat(parts[0]);
1082
- const long = parseFloat(parts[1]);
1083
- if (!isNaN(lat) && !isNaN(long)) {
1084
- return GeoLocation2.toGeoPoint({
1085
- latitude: lat,
1086
- longitude: long
1087
- });
1088
- }
1089
- }
1090
- }
1091
- return [
1092
- 0,
1093
- 0
1094
- ];
1095
- }
1096
- default: {
1097
- return value;
954
+ const newValue = useMemo4(() => {
955
+ if (type === "object" && elementType) {
956
+ return getDefaultObjectValue(elementType);
957
+ } else {
958
+ return SimpleType.getDefaultValue(type);
1098
959
  }
960
+ }, [
961
+ type,
962
+ elementType
963
+ ]);
964
+ const handleAdd = useCallback5(() => {
965
+ inputProps.onValueChange(type, [
966
+ ...values,
967
+ newValue
968
+ ]);
969
+ }, [
970
+ type,
971
+ elementType,
972
+ inputProps,
973
+ newValue,
974
+ values
975
+ ]);
976
+ const handleRemove = useCallback5((index) => {
977
+ const newValues = values.filter((_, i) => i !== index);
978
+ inputProps.onValueChange(type, newValues);
979
+ }, [
980
+ type,
981
+ inputProps,
982
+ values
983
+ ]);
984
+ if (!elementType) {
985
+ return null;
1099
986
  }
987
+ return /* @__PURE__ */ React10.createElement("div", {
988
+ role: "none",
989
+ className: mx5(padding)
990
+ }, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
991
+ role: "none",
992
+ className: "flex flex-col gap-1"
993
+ }, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
994
+ key: index,
995
+ role: "none",
996
+ className: "flex items-center gap-1"
997
+ }, /* @__PURE__ */ React10.createElement("div", {
998
+ role: "none",
999
+ className: "flex-1"
1000
+ }, /* @__PURE__ */ React10.createElement(FormField, {
1001
+ property: {
1002
+ ...property,
1003
+ array: false,
1004
+ ast: elementType
1005
+ },
1006
+ path: [
1007
+ ...path ?? [],
1008
+ index
1009
+ ],
1010
+ readonly,
1011
+ inline: true,
1012
+ Custom,
1013
+ lookupComponent
1014
+ })), /* @__PURE__ */ React10.createElement(IconButton3, {
1015
+ icon: "ph--trash--regular",
1016
+ iconOnly: true,
1017
+ label: t("button remove"),
1018
+ onClick: () => handleRemove(index)
1019
+ })))), /* @__PURE__ */ React10.createElement("div", {
1020
+ role: "none",
1021
+ className: "flex justify-between items-center plb-1"
1022
+ }, /* @__PURE__ */ React10.createElement(IconButton3, {
1023
+ icon: "ph--plus--regular",
1024
+ iconOnly: true,
1025
+ label: t("button add"),
1026
+ onClick: handleAdd
1027
+ })));
1100
1028
  };
1101
- var cellClassesForFieldType = ({ type, format }) => {
1102
- if (!format) {
1103
- switch (type) {
1104
- case TypeEnum.Number:
1105
- return [
1106
- "text-right",
1107
- "font-mono"
1108
- ];
1109
- case TypeEnum.Boolean:
1110
- return [
1111
- "text-right",
1112
- "font-mono"
1113
- ];
1114
- case TypeEnum.String:
1115
- return void 0;
1116
- case TypeEnum.Ref:
1117
- return void 0;
1118
- default: {
1119
- return void 0;
1120
- }
1121
- }
1122
- }
1029
+
1030
+ // packages/ui/react-ui-form/src/components/Form/factory.tsx
1031
+ import { FormatEnum } from "@dxos/echo-schema";
1032
+ var getInputComponent = (type, format) => {
1123
1033
  switch (format) {
1034
+ case FormatEnum.GeoPoint:
1035
+ return GeoPointInput;
1124
1036
  case FormatEnum.Markdown:
1125
- return void 0;
1126
- case FormatEnum.Time:
1127
- case FormatEnum.Timestamp:
1128
- case FormatEnum.DateTime:
1129
- case FormatEnum.Date:
1130
- case FormatEnum.Duration:
1131
- return [
1132
- "font-mono",
1133
- "text-right"
1134
- ];
1135
- case FormatEnum.Currency:
1136
- return [
1137
- "text-right"
1138
- ];
1139
- case FormatEnum.JSON:
1140
- case FormatEnum.DID:
1141
- return [
1142
- "font-mono"
1143
- ];
1144
- default:
1145
- return void 0;
1146
- }
1147
- };
1148
- var pathNotUniqueError = (path) => ({
1149
- path: "path",
1150
- message: `'${path}' is already present`
1151
- });
1152
-
1153
- // packages/ui/react-ui-form/src/util/formatting.ts
1154
- import { format as formatDate } from "date-fns/format";
1155
- import { FormatEnum as FormatEnum2, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
1156
- var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
1157
- const formatScalar = (type2) => {
1158
- switch (type2) {
1159
- case TypeEnum2.Boolean:
1160
- return value.toLocaleString().toUpperCase();
1161
- case TypeEnum2.Number:
1162
- return value.toLocaleString(locale);
1163
- case TypeEnum2.String:
1164
- case TypeEnum2.Ref:
1165
- return String(value);
1166
- default: {
1167
- return String(value);
1168
- }
1169
- }
1170
- };
1171
- if (!format) {
1172
- return formatScalar(type);
1173
- }
1174
- switch (format) {
1175
- case FormatEnum2.Boolean: {
1176
- return formatScalar(TypeEnum2.Boolean);
1177
- }
1178
- case FormatEnum2.Number: {
1179
- return formatScalar(TypeEnum2.Number);
1180
- }
1181
- case FormatEnum2.String:
1182
- case FormatEnum2.Ref: {
1183
- return formatScalar(TypeEnum2.String);
1184
- }
1185
- case FormatEnum2.Percent: {
1186
- return `${value * 100}%`;
1187
- }
1188
- case FormatEnum2.Currency: {
1189
- return value.toLocaleString(locale, {
1190
- style: "currency",
1191
- currency: "USD",
1192
- minimumFractionDigits: 2,
1193
- maximumFractionDigits: 2
1194
- });
1195
- }
1196
- case FormatEnum2.Date: {
1197
- try {
1198
- return formatDate(new Date(value), "yyyy-MM-dd");
1199
- } catch (error) {
1200
- return "Invalid Date";
1201
- }
1202
- }
1203
- case FormatEnum2.Time: {
1204
- try {
1205
- return formatDate(new Date(value), "HH:mm:ss");
1206
- } catch (error) {
1207
- return "Invalid Time";
1208
- }
1209
- }
1210
- case FormatEnum2.DateTime: {
1211
- try {
1212
- return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
1213
- } catch (error) {
1214
- return "Invalid DateTime";
1215
- }
1216
- }
1217
- case FormatEnum2.GeoPoint: {
1218
- if (value === null || value === void 0) {
1219
- return "";
1220
- }
1221
- if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
1222
- const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
1223
- return `${latitude},${longitude}`;
1224
- }
1225
- return String(value);
1226
- }
1227
- default: {
1228
- if (value === null || value === "undefined") {
1229
- return "";
1230
- }
1231
- return String(value);
1232
- }
1233
- }
1234
- };
1235
- var formatForEditing = ({ type, format, value, locale = void 0 }) => {
1236
- const formatScalar = (type2) => {
1237
- switch (type2) {
1238
- case TypeEnum2.Boolean:
1239
- case TypeEnum2.Number:
1240
- case TypeEnum2.String:
1241
- case TypeEnum2.Ref:
1242
- return String(value);
1243
- default:
1244
- return String(value);
1245
- }
1246
- };
1247
- if (!format) {
1248
- return formatScalar(type);
1249
- }
1250
- switch (format) {
1251
- case FormatEnum2.Boolean:
1252
- case FormatEnum2.Number:
1253
- case FormatEnum2.String:
1254
- case FormatEnum2.Ref: {
1255
- return formatScalar(type);
1256
- }
1257
- case FormatEnum2.Percent: {
1258
- return String(value * 100);
1259
- }
1260
- case FormatEnum2.Currency: {
1261
- return String(value);
1262
- }
1263
- case FormatEnum2.DateTime: {
1264
- const date = new Date(value);
1265
- return date.toISOString();
1266
- }
1267
- case FormatEnum2.Date: {
1268
- const date = new Date(value);
1269
- return date.toISOString().split("T")[0];
1270
- }
1271
- case FormatEnum2.Time: {
1272
- const date = new Date(value);
1273
- return date.toISOString().split("T")[1].split(".")[0];
1274
- }
1275
- case FormatEnum2.GeoPoint: {
1276
- if (value === null || value === void 0) {
1277
- return "";
1278
- }
1279
- if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
1280
- const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
1281
- return `${latitude},${longitude}`;
1282
- }
1283
- return String(value);
1284
- }
1285
- default: {
1286
- return String(value);
1287
- }
1288
- }
1289
- };
1290
-
1291
- // packages/ui/react-ui-form/src/util/refs.ts
1292
- import { FormatEnum as FormatEnum3, ReferenceAnnotationId } from "@dxos/echo-schema";
1293
- import { findAnnotation } from "@dxos/effect";
1294
-
1295
- // packages/ui/react-ui-form/src/util/schema.ts
1296
- import { SchemaAST as SchemaAST2 } from "effect";
1297
- import { findNode } from "@dxos/effect";
1298
- var findArrayElementType = (ast) => {
1299
- const tupleType = findNode(ast, SchemaAST2.isTupleType);
1300
- const elementType = tupleType?.rest[0]?.type;
1301
- return elementType;
1302
- };
1303
-
1304
- // packages/ui/react-ui-form/src/util/refs.ts
1305
- var getRefProps = (property) => {
1306
- const { ast, format, array } = property;
1307
- if (format === FormatEnum3.Ref) {
1308
- return {
1309
- ast,
1310
- isArray: false
1311
- };
1312
- }
1313
- if (array) {
1314
- const elementType = findArrayElementType(ast);
1315
- if (elementType) {
1316
- const annotation = findAnnotation(elementType, ReferenceAnnotationId);
1317
- if (annotation) {
1318
- return {
1319
- ast: elementType,
1320
- isArray: true
1321
- };
1322
- }
1323
- }
1324
- }
1325
- return void 0;
1326
- };
1327
-
1328
- // packages/ui/react-ui-form/src/components/Form/ArrayField.tsx
1329
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
1330
- var padding = "px-2";
1331
- var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
1332
- const { t } = useTranslation5(translationKey);
1333
- const { ast, name, type, title } = property;
1334
- const values = useFormValues(path ?? []) ?? [];
1335
- invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
1336
- F: __dxlog_file3,
1337
- L: 39,
1338
- S: void 0,
1339
- A: [
1340
- "Array.isArray(values)",
1341
- "`Values at path ${path?.join('.')} must be an array.`"
1342
- ]
1343
- });
1344
- const label = title ?? pipe(name, capitalize);
1345
- const elementType = findArrayElementType(ast);
1346
- const getDefaultObjectValue = (typeNode) => {
1347
- const baseNode = findNode2(typeNode, isDiscriminatedUnion);
1348
- const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
1349
- if (!typeLiteral) {
1350
- return {};
1351
- }
1352
- return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
1353
- prop.name,
1354
- prop.defaultValue
1355
- ]));
1356
- };
1357
- const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
1358
- const handleAdd = useCallback6(() => {
1359
- inputProps.onValueChange(type, [
1360
- ...values,
1361
- getDefaultValue()
1362
- ]);
1363
- }, [
1364
- type,
1365
- elementType,
1366
- inputProps,
1367
- values
1368
- ]);
1369
- const handleRemove = useCallback6((index) => {
1370
- const newValues = values.filter((_, i) => i !== index);
1371
- inputProps.onValueChange(type, newValues);
1372
- }, [
1373
- type,
1374
- inputProps,
1375
- values
1376
- ]);
1377
- if (!elementType) {
1378
- return null;
1379
- }
1380
- return /* @__PURE__ */ React10.createElement("div", {
1381
- role: "none",
1382
- className: mx6(padding)
1383
- }, /* @__PURE__ */ React10.createElement(InputHeader, null, label), /* @__PURE__ */ React10.createElement("div", {
1384
- role: "none",
1385
- className: "flex flex-col gap-1"
1386
- }, values.map((_value, index) => /* @__PURE__ */ React10.createElement("div", {
1387
- key: index,
1388
- role: "none",
1389
- className: "flex items-center gap-1"
1390
- }, /* @__PURE__ */ React10.createElement("div", {
1391
- role: "none",
1392
- className: "flex-1"
1393
- }, /* @__PURE__ */ React10.createElement(FormField, {
1394
- property: {
1395
- ...property,
1396
- array: false,
1397
- ast: elementType
1398
- },
1399
- path: [
1400
- ...path ?? [],
1401
- index
1402
- ],
1403
- readonly,
1404
- inline: true,
1405
- Custom,
1406
- lookupComponent
1407
- })), /* @__PURE__ */ React10.createElement(IconButton3, {
1408
- icon: "ph--trash--regular",
1409
- iconOnly: true,
1410
- label: t("button remove"),
1411
- onClick: () => handleRemove(index)
1412
- })))), /* @__PURE__ */ React10.createElement("div", {
1413
- role: "none",
1414
- className: "flex justify-between items-center plb-1"
1415
- }, /* @__PURE__ */ React10.createElement(IconButton3, {
1416
- icon: "ph--plus--regular",
1417
- iconOnly: true,
1418
- label: t("button add"),
1419
- onClick: handleAdd
1420
- })));
1421
- };
1422
-
1423
- // packages/ui/react-ui-form/src/components/Form/RefField.tsx
1424
- import React11, { useCallback as useCallback7, useMemo as useMemo4 } from "react";
1425
- import { Expando, getTypeAnnotation, Ref, ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo-schema";
1426
- import { findAnnotation as findAnnotation2 } from "@dxos/effect";
1427
- import { DXN } from "@dxos/keys";
1428
- import { Input as Input7 } from "@dxos/react-ui";
1429
- import { TagPicker } from "@dxos/react-ui-tag-picker";
1430
- import { isNonNullable as isNonNullable2 } from "@dxos/util";
1431
- var RefField = ({ type, label, disabled, placeholder, inputOnly, array, ast, getValue: getValue3, onBlur, onQueryRefOptions, onValueChange, ...restInputProps }) => {
1432
- const refTypeInfo = useMemo4(() => ast ? findAnnotation2(ast, ReferenceAnnotationId2) : void 0, [
1433
- ast
1434
- ]);
1435
- const { options: availableOptions, loading: _loading } = useQueryRefOptions({
1436
- refTypeInfo,
1437
- onQueryRefOptions
1438
- });
1439
- if (refTypeInfo && refTypeInfo?.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
1440
- return /* @__PURE__ */ React11.createElement(RefFieldFallback, {
1441
- type,
1442
- label,
1443
- placeholder,
1444
- disabled,
1445
- inputOnly,
1446
- getValue: getValue3,
1447
- onBlur,
1448
- onValueChange,
1449
- ...restInputProps
1450
- });
1451
- }
1452
- const handleGetValue = useCallback7(() => {
1453
- const formValue = getValue3();
1454
- const unknownToRefOption = (val) => {
1455
- if (Ref.isRef(val)) {
1456
- const dxnString = val.dxn.toString();
1457
- const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
1458
- if (matchingOption) {
1459
- return matchingOption;
1460
- }
1461
- }
1462
- return void 0;
1463
- };
1464
- if (array && Array.isArray(formValue)) {
1465
- return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
1466
- }
1467
- const option = unknownToRefOption(formValue);
1468
- if (option) {
1469
- return [
1470
- option
1471
- ];
1472
- }
1473
- return [];
1474
- }, [
1475
- getValue3,
1476
- availableOptions,
1477
- array
1478
- ]);
1479
- const handleSearch = useCallback7((text, ids) => availableOptions.filter((option) => !ids.includes(option.id)).filter((option) => option.label.toLowerCase().includes(text.toLowerCase())).map((option) => ({
1480
- id: option.id,
1481
- label: option.label,
1482
- hue: option.hue
1483
- })), [
1484
- availableOptions
1485
- ]);
1486
- const handleUpdate = useCallback7((ids) => {
1487
- if (ids.length === 0) {
1488
- onValueChange("object", void 0);
1489
- return;
1490
- }
1491
- const refs = ids.map((id) => {
1492
- const item = availableOptions.find((option) => option.id === id);
1493
- if (item) {
1494
- const dxn = DXN.parse(item.id);
1495
- return Ref.fromDXN(dxn);
1496
- }
1497
- return null;
1498
- }).filter(isNonNullable2);
1499
- if (array) {
1500
- onValueChange("object", refs);
1501
- } else {
1502
- onValueChange("object", refs[0]);
1503
- }
1504
- }, [
1505
- availableOptions,
1506
- array,
1507
- onValueChange
1508
- ]);
1509
- const tagPickerMode = useMemo4(() => array ? "multi-select" : "single-select", [
1510
- array
1511
- ]);
1512
- if (!refTypeInfo) {
1513
- return null;
1514
- }
1515
- const { status, error } = restInputProps.getStatus();
1516
- return /* @__PURE__ */ React11.createElement(Input7.Root, {
1517
- validationValence: status
1518
- }, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
1519
- error
1520
- }, /* @__PURE__ */ React11.createElement(Input7.Label, null, label)), /* @__PURE__ */ React11.createElement("div", {
1521
- "data-no-submit": true
1522
- }, /* @__PURE__ */ React11.createElement(TagPicker, {
1523
- items: handleGetValue(),
1524
- mode: tagPickerMode,
1525
- onBlur: (event) => onBlur(event),
1526
- onUpdate: handleUpdate,
1527
- onSearch: handleSearch,
1528
- classNames: "rounded-sm bg-input p-1.5"
1529
- })), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
1530
- };
1531
- var RefFieldFallback = ({ type, label, disabled, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
1532
- const handleOnValueChange = (_type, dxnString) => {
1533
- const dxn = DXN.tryParse(dxnString);
1534
- if (dxn) {
1535
- onValueChange?.("object", Ref.fromDXN(dxn));
1536
- } else if (dxnString === "") {
1537
- onValueChange?.("object", void 0);
1538
- } else {
1539
- onValueChange?.("string", dxnString);
1540
- }
1541
- };
1542
- const handleGetValue = () => {
1543
- const formValue = getValue3();
1544
- if (typeof formValue === "string") {
1545
- return formValue;
1546
- }
1547
- if (Ref.isRef(formValue)) {
1548
- return formValue.dxn.toString();
1549
- }
1550
- return void 0;
1551
- };
1552
- return /* @__PURE__ */ React11.createElement(TextInput, {
1553
- type,
1554
- label,
1555
- disabled,
1556
- placeholder,
1557
- inputOnly,
1558
- getValue: handleGetValue,
1559
- onValueChange: handleOnValueChange,
1560
- ...restInputProps
1561
- });
1562
- };
1563
-
1564
- // packages/ui/react-ui-form/src/components/Form/factory.tsx
1565
- import { FormatEnum as FormatEnum4 } from "@dxos/echo-schema";
1566
- var getInputComponent = (type, format) => {
1567
- switch (format) {
1568
- case FormatEnum4.GeoPoint:
1569
- return GeoPointInput;
1570
- case FormatEnum4.Markdown:
1571
- return MarkdownInput;
1572
- }
1573
- switch (type) {
1574
- case "string":
1575
- return TextInput;
1576
- case "number":
1577
- return NumberInput;
1578
- case "boolean":
1579
- return BooleanInput;
1037
+ return MarkdownInput;
1038
+ }
1039
+ switch (type) {
1040
+ case "string":
1041
+ return TextInput;
1042
+ case "number":
1043
+ return NumberInput;
1044
+ case "boolean":
1045
+ return BooleanInput;
1580
1046
  }
1581
1047
  };
1582
1048
 
1583
1049
  // packages/ui/react-ui-form/src/components/Form/FormContent.tsx
1584
- var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupComponent, Custom }) => {
1050
+ var FormField = ({ property, path, readonly, inline, lookupComponent, Custom }) => {
1585
1051
  const inputProps = useInputProps(path);
1586
1052
  const { ast, name, type, format, title, description, options, examples, array } = property;
1587
1053
  const label = useMemo5(() => title ?? pipe2(name, capitalize2), [
@@ -1594,7 +1060,7 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
1594
1060
  ]);
1595
1061
  const FoundComponent = lookupComponent?.({
1596
1062
  prop: name,
1597
- schema: Schema.make(ast),
1063
+ schema: S.make(ast),
1598
1064
  inputProps: {
1599
1065
  type,
1600
1066
  format,
@@ -1605,14 +1071,14 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
1605
1071
  }
1606
1072
  });
1607
1073
  if (FoundComponent) {
1608
- return /* @__PURE__ */ React12.createElement("div", {
1074
+ return /* @__PURE__ */ React11.createElement("div", {
1609
1075
  role: "none"
1610
1076
  }, FoundComponent);
1611
1077
  }
1612
1078
  const jsonPath = createJsonPath3(path ?? []);
1613
1079
  const CustomComponent = Custom?.[jsonPath];
1614
1080
  if (CustomComponent) {
1615
- return /* @__PURE__ */ React12.createElement(CustomComponent, {
1081
+ return /* @__PURE__ */ React11.createElement(CustomComponent, {
1616
1082
  type,
1617
1083
  format,
1618
1084
  label,
@@ -1622,23 +1088,8 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
1622
1088
  ...inputProps
1623
1089
  });
1624
1090
  }
1625
- const refProps = getRefProps(property);
1626
- if (refProps) {
1627
- return /* @__PURE__ */ React12.createElement(RefField, {
1628
- ast: refProps.ast,
1629
- array: refProps.isArray,
1630
- type,
1631
- format,
1632
- label,
1633
- placeholder,
1634
- disabled: readonly,
1635
- inputOnly: inline,
1636
- onQueryRefOptions,
1637
- ...inputProps
1638
- });
1639
- }
1640
1091
  if (array) {
1641
- return /* @__PURE__ */ React12.createElement(ArrayField, {
1092
+ return /* @__PURE__ */ React11.createElement(ArrayField, {
1642
1093
  property,
1643
1094
  path,
1644
1095
  inputProps,
@@ -1648,9 +1099,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
1648
1099
  }
1649
1100
  const InputComponent = getInputComponent(type, format);
1650
1101
  if (InputComponent) {
1651
- return /* @__PURE__ */ React12.createElement("div", {
1102
+ return /* @__PURE__ */ React11.createElement("div", {
1652
1103
  role: "none"
1653
- }, /* @__PURE__ */ React12.createElement(InputComponent, {
1104
+ }, /* @__PURE__ */ React11.createElement(InputComponent, {
1654
1105
  type,
1655
1106
  format,
1656
1107
  label,
@@ -1661,9 +1112,9 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
1661
1112
  }));
1662
1113
  }
1663
1114
  if (options) {
1664
- return /* @__PURE__ */ React12.createElement("div", {
1115
+ return /* @__PURE__ */ React11.createElement("div", {
1665
1116
  role: "none"
1666
- }, /* @__PURE__ */ React12.createElement(SelectInput, {
1117
+ }, /* @__PURE__ */ React11.createElement(SelectInput, {
1667
1118
  type,
1668
1119
  format,
1669
1120
  disabled: readonly,
@@ -1678,26 +1129,22 @@ var FormField = ({ property, path, readonly, inline, onQueryRefOptions, lookupCo
1678
1129
  }));
1679
1130
  }
1680
1131
  if (type === "object") {
1681
- const baseNode = findNode3(ast, isDiscriminatedUnion2);
1682
- const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode3(ast, SchemaAST4.isTypeLiteral);
1132
+ const baseNode = findNode2(ast, isDiscriminatedUnion2);
1133
+ const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode2(ast, AST3.isTypeLiteral);
1683
1134
  if (typeLiteral) {
1684
- return /* @__PURE__ */ React12.createElement("div", {
1135
+ return /* @__PURE__ */ React11.createElement("div", {
1685
1136
  role: "none"
1686
- }, !inline && /* @__PURE__ */ React12.createElement("h3", {
1687
- className: "text-lg mbs-2 mbe-1"
1688
- }, label), /* @__PURE__ */ React12.createElement(FormFields, {
1689
- schema: Schema.make(typeLiteral),
1137
+ }, !inline && /* @__PURE__ */ React11.createElement("div", null, label), /* @__PURE__ */ React11.createElement(FormFields, {
1138
+ schema: S.make(typeLiteral),
1690
1139
  path,
1691
1140
  readonly,
1692
- onQueryRefOptions,
1693
- Custom,
1694
- lookupComponent
1141
+ Custom
1695
1142
  }));
1696
1143
  }
1697
1144
  }
1698
1145
  return null;
1699
1146
  };
1700
- var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, lookupComponent, Custom }) => {
1147
+ var FormFields = ({ schema, path, filter, sort, readonly, lookupComponent, Custom }) => {
1701
1148
  const values = useFormValues(path);
1702
1149
  const properties = useMemo5(() => {
1703
1150
  const props = getSchemaProperties2(schema.ast, values);
@@ -1709,11 +1156,11 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
1709
1156
  filter,
1710
1157
  sort
1711
1158
  ]);
1712
- return /* @__PURE__ */ React12.createElement("div", {
1159
+ return /* @__PURE__ */ React11.createElement("div", {
1713
1160
  role: "form",
1714
- className: mx7("flex flex-col w-full gap-2")
1161
+ className: mx6("flex flex-col w-full gap-2")
1715
1162
  }, properties.map((property) => {
1716
- return /* @__PURE__ */ React12.createElement(FormField, {
1163
+ return /* @__PURE__ */ React11.createElement(FormField, {
1717
1164
  key: property.name,
1718
1165
  property,
1719
1166
  path: [
@@ -1721,7 +1168,6 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
1721
1168
  property.name
1722
1169
  ],
1723
1170
  readonly,
1724
- onQueryRefOptions,
1725
1171
  lookupComponent,
1726
1172
  Custom
1727
1173
  });
@@ -1729,13 +1175,13 @@ var FormFields = ({ schema, path, filter, sort, readonly, onQueryRefOptions, loo
1729
1175
  };
1730
1176
 
1731
1177
  // packages/ui/react-ui-form/src/components/Form/Form.tsx
1732
- var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, onQueryRefOptions, lookupComponent, Custom }) => {
1178
+ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
1733
1179
  const formRef = useRef3(null);
1734
1180
  const onValid = useMemo6(() => autoSave ? onSave : void 0, [
1735
1181
  autoSave,
1736
1182
  onSave
1737
1183
  ]);
1738
- useEffect7(() => {
1184
+ useEffect6(() => {
1739
1185
  if (autoFocus && formRef.current) {
1740
1186
  const input = formRef.current.querySelector("input");
1741
1187
  if (input) {
@@ -1745,7 +1191,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
1745
1191
  }, [
1746
1192
  autoFocus
1747
1193
  ]);
1748
- return /* @__PURE__ */ React13.createElement(FormProvider, {
1194
+ return /* @__PURE__ */ React12.createElement(FormProvider, {
1749
1195
  formRef,
1750
1196
  schema,
1751
1197
  autoSave,
@@ -1754,37 +1200,36 @@ var Form = ({ classNames, schema, values: initialValues, path = [], autoFocus, r
1754
1200
  onValidate,
1755
1201
  onValid,
1756
1202
  onSave
1757
- }, /* @__PURE__ */ React13.createElement("div", {
1203
+ }, /* @__PURE__ */ React12.createElement("div", {
1758
1204
  ref: formRef,
1759
1205
  role: "none",
1760
- className: mx8("p-2", classNames),
1206
+ className: mx7("p-2", classNames),
1761
1207
  "data-testid": testId
1762
- }, /* @__PURE__ */ React13.createElement(FormFields, {
1208
+ }, /* @__PURE__ */ React12.createElement(FormFields, {
1763
1209
  schema,
1764
1210
  path,
1765
1211
  readonly,
1766
1212
  filter,
1767
1213
  sort,
1768
- onQueryRefOptions,
1769
1214
  lookupComponent,
1770
1215
  Custom
1771
- }), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React13.createElement(FormActions, {
1216
+ }), (onCancel || onSave) && !autoSave && /* @__PURE__ */ React12.createElement(FormActions, {
1772
1217
  onCancel,
1773
1218
  readonly
1774
1219
  })));
1775
1220
  };
1776
1221
 
1777
1222
  // packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx
1778
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
1223
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
1779
1224
  var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1780
1225
  const { t } = useTranslation6(translationKey);
1781
- const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
1782
- useEffect8(() => setProps(projection.getFieldProjection(field.id).props), [
1226
+ const [props, setProps] = useState4(projection.getFieldProjection(field.id).props);
1227
+ useEffect7(() => setProps(projection.getFieldProjection(field.id).props), [
1783
1228
  field,
1784
1229
  projection
1785
1230
  ]);
1786
- const [schemas, setSchemas] = useState5([]);
1787
- useEffect8(() => {
1231
+ const [schemas, setSchemas] = useState4([]);
1232
+ useEffect7(() => {
1788
1233
  if (!registry) {
1789
1234
  return;
1790
1235
  }
@@ -1802,17 +1247,17 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1802
1247
  }, [
1803
1248
  registry
1804
1249
  ]);
1805
- const [referenceSchema, setReferenceSchema] = useState5();
1806
- useEffect8(() => {
1250
+ const [referenceSchema, setReferenceSchema] = useState4();
1251
+ useEffect7(() => {
1807
1252
  setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
1808
1253
  }, [
1809
1254
  schemas,
1810
1255
  props?.referenceSchema
1811
1256
  ]);
1812
- const [{ fieldSchema }, setFieldSchema] = useState5({
1257
+ const [{ fieldSchema }, setFieldSchema] = useState4({
1813
1258
  fieldSchema: getFormatSchema(props?.format)
1814
1259
  });
1815
- const handleValuesChanged = useCallback8((_props) => {
1260
+ const handleValuesChanged = useCallback6((_props) => {
1816
1261
  setFieldSchema((prev) => {
1817
1262
  const fieldSchema2 = getFormatSchema(_props.format);
1818
1263
  if (prev.fieldSchema === fieldSchema2) {
@@ -1847,7 +1292,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1847
1292
  props.format,
1848
1293
  props.referenceSchema
1849
1294
  ]);
1850
- const handleValidate = useCallback8(({ property }) => {
1295
+ const handleValidate = useCallback6(({ property }) => {
1851
1296
  if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
1852
1297
  return [
1853
1298
  {
@@ -1860,7 +1305,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1860
1305
  view.fields,
1861
1306
  field
1862
1307
  ]);
1863
- const handleSave = useCallback8((props2) => {
1308
+ const handleSave = useCallback6((props2) => {
1864
1309
  projection.setFieldProjection({
1865
1310
  field,
1866
1311
  props: props2
@@ -1871,51 +1316,51 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1871
1316
  field,
1872
1317
  onSave
1873
1318
  ]);
1874
- const handleCancel = useCallback8(() => {
1319
+ const handleCancel = useCallback6(() => {
1875
1320
  requestAnimationFrame(() => onCancel?.());
1876
1321
  onSave();
1877
1322
  }, [
1878
1323
  onSave
1879
1324
  ]);
1880
1325
  const Custom = useMemo7(() => ({
1881
- ["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
1326
+ ["format"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
1882
1327
  ...props2,
1883
- options: FormatEnums.filter((value) => value !== FormatEnum5.None).map((value) => ({
1328
+ options: FormatEnums.filter((value) => value !== FormatEnum2.None).map((value) => ({
1884
1329
  value,
1885
1330
  label: t(`format ${value}`)
1886
1331
  }))
1887
1332
  }),
1888
- ["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
1333
+ ["referenceSchema"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
1889
1334
  ...props2,
1890
1335
  options: schemas.map((schema) => ({
1891
1336
  value: schema.typename
1892
1337
  }))
1893
1338
  }),
1894
- ["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
1339
+ ["referencePath"]: (props2) => /* @__PURE__ */ React13.createElement(SelectInput, {
1895
1340
  ...props2,
1896
1341
  options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
1897
1342
  value: p.name
1898
1343
  })) : []
1899
1344
  }),
1900
- ["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
1345
+ ["options"]: (props2) => /* @__PURE__ */ React13.createElement(SelectOptionInput, props2)
1901
1346
  }), [
1902
1347
  t,
1903
1348
  schemas,
1904
1349
  referenceSchema
1905
1350
  ]);
1906
- const propIsNotType = useCallback8((props2) => props2.filter((p) => p.name !== "type"), []);
1351
+ const propIsNotType = useCallback6((props2) => props2.filter((p) => p.name !== "type"), []);
1907
1352
  if (!fieldSchema) {
1908
- log3.warn("invalid format", {
1353
+ log2.warn("invalid format", {
1909
1354
  props
1910
1355
  }, {
1911
- F: __dxlog_file4,
1356
+ F: __dxlog_file3,
1912
1357
  L: 174,
1913
1358
  S: void 0,
1914
1359
  C: (f, a) => f(...a)
1915
1360
  });
1916
1361
  return null;
1917
1362
  }
1918
- return /* @__PURE__ */ React14.createElement(Form, {
1363
+ return /* @__PURE__ */ React13.createElement(Form, {
1919
1364
  key: field.id,
1920
1365
  autoFocus: true,
1921
1366
  values: props,
@@ -1934,32 +1379,30 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
1934
1379
  };
1935
1380
 
1936
1381
  // packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx
1937
- import { Schema as Schema2, SchemaAST as SchemaAST5 } from "effect";
1938
- import React15, { useCallback as useCallback9, useMemo as useMemo8, useState as useState6 } from "react";
1939
- import { Format, isMutable, toJsonSchema } from "@dxos/echo-schema";
1382
+ import React14, { useCallback as useCallback7, useMemo as useMemo8, useState as useState5 } from "react";
1383
+ import { AST as AST4, Format, S as S2 } from "@dxos/echo-schema";
1940
1384
  import { invariant as invariant3 } from "@dxos/invariant";
1941
1385
  import { IconButton as IconButton4, useTranslation as useTranslation7 } from "@dxos/react-ui";
1942
1386
  import { List as List2 } from "@dxos/react-ui-list";
1943
- import { ghostHover, inputTextLabel, mx as mx9 } from "@dxos/react-ui-theme";
1387
+ import { ghostHover, inputTextLabel, mx as mx8 } from "@dxos/react-ui-theme";
1944
1388
  import { FieldSchema, ViewProjection, VIEW_FIELD_LIMIT } from "@dxos/schema";
1945
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
1389
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
1946
1390
  var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
1947
- var ViewMetaSchema = Schema2.Struct({
1948
- name: Schema2.String.annotations({
1949
- [SchemaAST5.TitleAnnotationId]: "View"
1391
+ var ViewMetaSchema = S2.Struct({
1392
+ name: S2.String.annotations({
1393
+ [AST4.TitleAnnotationId]: "View"
1950
1394
  }),
1951
1395
  typename: Format.URL.annotations({
1952
- [SchemaAST5.TitleAnnotationId]: "Typename"
1396
+ [AST4.TitleAnnotationId]: "Typename"
1953
1397
  })
1954
- }).pipe(Schema2.mutable);
1398
+ }).pipe(S2.mutable);
1955
1399
  var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
1956
1400
  const { t } = useTranslation7(translationKey);
1957
- const projection = useMemo8(() => new ViewProjection(toJsonSchema(schema), view), [
1401
+ const projection = useMemo8(() => new ViewProjection(schema.jsonSchema, view), [
1958
1402
  schema,
1959
1403
  view
1960
1404
  ]);
1961
- const [field, setField] = useState6();
1962
- const immutable = readonly || !isMutable(schema);
1405
+ const [field, setField] = useState5();
1963
1406
  const viewValues = useMemo8(() => {
1964
1407
  return {
1965
1408
  name: view.name,
@@ -1970,16 +1413,16 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1970
1413
  }, [
1971
1414
  view
1972
1415
  ]);
1973
- const handleSelect = useCallback9((field2) => {
1416
+ const handleSelect = useCallback7((field2) => {
1974
1417
  setField((f) => f === field2 ? void 0 : field2);
1975
1418
  }, []);
1976
- const handleAdd = useCallback9(() => {
1977
- invariant3(!immutable, void 0, {
1978
- F: __dxlog_file5,
1979
- L: 78,
1419
+ const handleAdd = useCallback7(() => {
1420
+ invariant3(!schema.readonly, void 0, {
1421
+ F: __dxlog_file4,
1422
+ L: 76,
1980
1423
  S: void 0,
1981
1424
  A: [
1982
- "!immutable",
1425
+ "!schema.readonly",
1983
1426
  ""
1984
1427
  ]
1985
1428
  });
@@ -1989,13 +1432,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
1989
1432
  schema,
1990
1433
  view
1991
1434
  ]);
1992
- const handleUpdate = useCallback9(({ name, typename }) => {
1993
- invariant3(!immutable, void 0, {
1994
- F: __dxlog_file5,
1995
- L: 85,
1435
+ const handleUpdate = useCallback7(({ name, typename }) => {
1436
+ invariant3(!schema.readonly, void 0, {
1437
+ F: __dxlog_file4,
1438
+ L: 83,
1996
1439
  S: void 0,
1997
1440
  A: [
1998
- "!immutable",
1441
+ "!schema.readonly",
1999
1442
  ""
2000
1443
  ]
2001
1444
  });
@@ -2012,13 +1455,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
2012
1455
  view,
2013
1456
  onTypenameChanged
2014
1457
  ]);
2015
- const handleDelete = useCallback9((fieldId) => {
2016
- invariant3(!immutable, void 0, {
2017
- F: __dxlog_file5,
2018
- L: 101,
1458
+ const handleDelete = useCallback7((fieldId) => {
1459
+ invariant3(!schema.readonly, void 0, {
1460
+ F: __dxlog_file4,
1461
+ L: 99,
2019
1462
  S: void 0,
2020
1463
  A: [
2021
- "!immutable",
1464
+ "!schema.readonly",
2022
1465
  ""
2023
1466
  ]
2024
1467
  });
@@ -2031,13 +1474,13 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
2031
1474
  field,
2032
1475
  onDelete
2033
1476
  ]);
2034
- const handleMove = useCallback9((fromIndex, toIndex) => {
2035
- invariant3(!immutable, void 0, {
2036
- F: __dxlog_file5,
2037
- L: 113,
1477
+ const handleMove = useCallback7((fromIndex, toIndex) => {
1478
+ invariant3(!schema.readonly, void 0, {
1479
+ F: __dxlog_file4,
1480
+ L: 111,
2038
1481
  S: void 0,
2039
1482
  A: [
2040
- "!immutable",
1483
+ "!schema.readonly",
2041
1484
  ""
2042
1485
  ]
2043
1486
  });
@@ -2051,111 +1494,363 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
2051
1494
  schema,
2052
1495
  view.fields
2053
1496
  ]);
2054
- const handleClose = useCallback9(() => setField(void 0), []);
1497
+ const handleClose = useCallback7(() => setField(void 0), []);
2055
1498
  const hiddenProperties = projection.getHiddenProperties();
2056
- const handleHide = useCallback9((fieldId) => {
1499
+ const handleHide = useCallback7((fieldId) => {
2057
1500
  setField(void 0);
2058
1501
  projection.hideFieldProjection(fieldId);
2059
1502
  }, [
2060
1503
  projection
2061
1504
  ]);
2062
- const handleShow = useCallback9((property) => {
1505
+ const handleShow = useCallback7((property) => {
2063
1506
  setField(void 0);
2064
1507
  projection.showFieldProjection(property);
2065
1508
  }, [
2066
1509
  projection
2067
1510
  ]);
2068
- return /* @__PURE__ */ React15.createElement("div", {
1511
+ return /* @__PURE__ */ React14.createElement("div", {
2069
1512
  role: "none",
2070
- className: mx9("grid grid-rows-[1fr_1fr] min-bs-0", classNames)
2071
- }, /* @__PURE__ */ React15.createElement(Form, {
1513
+ className: mx8("flex flex-col w-full divide-y divide-separator", classNames)
1514
+ }, /* @__PURE__ */ React14.createElement(Form, {
2072
1515
  autoSave: true,
2073
1516
  schema: ViewMetaSchema,
2074
1517
  values: viewValues,
2075
- onSave: immutable ? void 0 : handleUpdate,
2076
- classNames: "min-bs-0 overflow-y-auto"
2077
- }), /* @__PURE__ */ React15.createElement("div", {
2078
- role: "none",
2079
- className: "border-bs border-separator min-bs-0 overflow-y-auto"
2080
- }, /* @__PURE__ */ React15.createElement("div", {
1518
+ onSave: schema.readonly ? void 0 : handleUpdate
1519
+ }), /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("div", {
2081
1520
  role: "none",
2082
1521
  className: "p-2"
2083
- }, /* @__PURE__ */ React15.createElement("label", {
2084
- className: mx9(inputTextLabel)
2085
- }, t("fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
1522
+ }, /* @__PURE__ */ React14.createElement("label", {
1523
+ className: mx8(inputTextLabel)
1524
+ }, t("fields label"))), /* @__PURE__ */ React14.createElement(List2.Root, {
2086
1525
  items: view.fields,
2087
- isItem: Schema2.is(FieldSchema),
1526
+ isItem: S2.is(FieldSchema),
2088
1527
  getId: (field2) => field2.id,
2089
- onMove: immutable ? void 0 : handleMove
2090
- }, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("div", {
1528
+ onMove: schema.readonly ? void 0 : handleMove
1529
+ }, ({ items: fields }) => /* @__PURE__ */ React14.createElement(React14.Fragment, null, showHeading && /* @__PURE__ */ React14.createElement("div", {
2091
1530
  role: "heading",
2092
1531
  className: grid
2093
- }, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement("div", {
1532
+ }, /* @__PURE__ */ React14.createElement("div", null), /* @__PURE__ */ React14.createElement("div", {
2094
1533
  className: "flex items-center text-sm"
2095
- }, t("field path label"))), /* @__PURE__ */ React15.createElement("div", {
1534
+ }, t("field path label"))), /* @__PURE__ */ React14.createElement("div", {
2096
1535
  role: "list",
2097
1536
  className: "flex flex-col w-full"
2098
- }, fields?.map((field2) => /* @__PURE__ */ React15.createElement(List2.Item, {
1537
+ }, fields?.map((field2) => /* @__PURE__ */ React14.createElement(List2.Item, {
2099
1538
  key: field2.id,
2100
1539
  item: field2,
2101
- classNames: mx9(grid, ghostHover, "cursor-pointer")
2102
- }, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
1540
+ classNames: mx8(grid, ghostHover, "cursor-pointer")
1541
+ }, /* @__PURE__ */ React14.createElement(List2.ItemDragHandle, null), /* @__PURE__ */ React14.createElement(List2.ItemTitle, {
2103
1542
  onClick: () => handleSelect(field2)
2104
- }, field2.path), /* @__PURE__ */ React15.createElement("div", {
1543
+ }, field2.path), /* @__PURE__ */ React14.createElement("div", {
2105
1544
  className: "flex items-center gap-2 -ml-4"
2106
- }, /* @__PURE__ */ React15.createElement(List2.ItemButton, {
1545
+ }, /* @__PURE__ */ React14.createElement(List2.ItemButton, {
2107
1546
  icon: "ph--eye-slash--regular",
2108
1547
  disabled: view.fields.length <= 1,
2109
1548
  onClick: () => handleHide(field2.id)
2110
- }), !immutable && /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
1549
+ }), !schema.readonly && /* @__PURE__ */ React14.createElement(List2.ItemDeleteButton, {
2111
1550
  icon: "ph--trash--regular",
2112
1551
  disabled: view.fields.length <= 1,
2113
1552
  onClick: () => handleDelete(field2.id)
2114
- }))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React15.createElement("div", null, /* @__PURE__ */ React15.createElement("div", {
1553
+ }))))))), hiddenProperties.length > 0 && /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("div", {
2115
1554
  role: "none",
2116
1555
  className: "p-2"
2117
- }, /* @__PURE__ */ React15.createElement("label", {
2118
- className: mx9(inputTextLabel)
2119
- }, t("hidden fields label"))), /* @__PURE__ */ React15.createElement(List2.Root, {
1556
+ }, /* @__PURE__ */ React14.createElement("label", {
1557
+ className: mx8(inputTextLabel)
1558
+ }, t("hidden fields label"))), /* @__PURE__ */ React14.createElement(List2.Root, {
2120
1559
  items: hiddenProperties,
2121
1560
  isItem: (item) => typeof item === "string",
2122
1561
  getId: (property) => property
2123
- }, ({ items: properties }) => /* @__PURE__ */ React15.createElement("div", {
1562
+ }, ({ items: properties }) => /* @__PURE__ */ React14.createElement("div", {
2124
1563
  role: "list",
2125
1564
  className: "flex flex-col w-full"
2126
- }, properties?.map((property) => /* @__PURE__ */ React15.createElement(List2.Item, {
1565
+ }, properties?.map((property) => /* @__PURE__ */ React14.createElement(List2.Item, {
2127
1566
  key: property,
2128
1567
  item: property,
2129
- classNames: mx9(grid, ghostHover, "cursor-pointer")
2130
- }, /* @__PURE__ */ React15.createElement("div", null), /* @__PURE__ */ React15.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
1568
+ classNames: mx8(grid, ghostHover, "cursor-pointer")
1569
+ }, /* @__PURE__ */ React14.createElement("div", null), /* @__PURE__ */ React14.createElement(List2.ItemTitle, null, property), /* @__PURE__ */ React14.createElement(List2.ItemButton, {
2131
1570
  icon: "ph--eye--regular",
2132
1571
  onClick: () => handleShow(property)
2133
- }))))))), field && /* @__PURE__ */ React15.createElement(FieldEditor, {
1572
+ }))))))), field && /* @__PURE__ */ React14.createElement(FieldEditor, {
2134
1573
  key: field.id,
2135
1574
  view,
2136
1575
  projection,
2137
1576
  field,
2138
1577
  registry,
2139
1578
  onSave: handleClose
2140
- }), !readonly && !field && /* @__PURE__ */ React15.createElement("div", {
1579
+ }), !readonly && !field && /* @__PURE__ */ React14.createElement("div", {
2141
1580
  className: "flex p-2 justify-center"
2142
- }, /* @__PURE__ */ React15.createElement(IconButton4, {
1581
+ }, /* @__PURE__ */ React14.createElement(IconButton4, {
2143
1582
  icon: "ph--plus--regular",
2144
1583
  label: t("button add property"),
2145
- onClick: immutable ? void 0 : handleAdd,
1584
+ onClick: schema.readonly ? void 0 : handleAdd,
2146
1585
  // TODO(burdon): Show field limit in ux (not tooltip).
2147
1586
  disabled: view.fields.length >= VIEW_FIELD_LIMIT
2148
1587
  })));
2149
1588
  };
1589
+
1590
+ // packages/ui/react-ui-form/src/util/field.ts
1591
+ import { FormatEnum as FormatEnum3, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo-schema";
1592
+ var parseValue = ({ type, format, value }) => {
1593
+ if (value === void 0 || value === null || value === "") {
1594
+ return void 0;
1595
+ }
1596
+ const parseScalar = (type2) => {
1597
+ switch (type2) {
1598
+ case TypeEnum.Boolean: {
1599
+ if (typeof value === "string") {
1600
+ const lowercaseValue = value.toLowerCase();
1601
+ if (lowercaseValue === "0" || lowercaseValue === "false") {
1602
+ return false;
1603
+ } else if (lowercaseValue === "1" || lowercaseValue === "true") {
1604
+ return true;
1605
+ }
1606
+ }
1607
+ return Boolean(value);
1608
+ }
1609
+ case TypeEnum.Number: {
1610
+ const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
1611
+ const num = Number(cleaned);
1612
+ return Number.isNaN(num) ? null : num;
1613
+ }
1614
+ case TypeEnum.String:
1615
+ case TypeEnum.Ref:
1616
+ return String(value);
1617
+ default: {
1618
+ return value;
1619
+ }
1620
+ }
1621
+ };
1622
+ if (!format) {
1623
+ return parseScalar(type);
1624
+ }
1625
+ switch (format) {
1626
+ case FormatEnum3.Boolean:
1627
+ return parseScalar(TypeEnum.Boolean);
1628
+ case FormatEnum3.Number:
1629
+ case FormatEnum3.Percent:
1630
+ case FormatEnum3.Currency:
1631
+ return parseScalar(TypeEnum.Number);
1632
+ case FormatEnum3.String:
1633
+ case FormatEnum3.Markdown: {
1634
+ return parseScalar(TypeEnum.String);
1635
+ }
1636
+ case FormatEnum3.Ref:
1637
+ throw new Error(`unexpected format: ${FormatEnum3.Ref}`);
1638
+ case FormatEnum3.DateTime:
1639
+ case FormatEnum3.Date:
1640
+ case FormatEnum3.Time:
1641
+ case FormatEnum3.Timestamp: {
1642
+ const date = new Date(value);
1643
+ return isNaN(date.getTime()) ? null : date;
1644
+ }
1645
+ case FormatEnum3.GeoPoint: {
1646
+ if (typeof value === "string") {
1647
+ const cleaned = value.replace(/[^0-9.,-]+/g, "");
1648
+ const parts = cleaned.split(",");
1649
+ if (parts.length === 2) {
1650
+ const lat = parseFloat(parts[0]);
1651
+ const long = parseFloat(parts[1]);
1652
+ if (!isNaN(lat) && !isNaN(long)) {
1653
+ return GeoLocation2.toGeoPoint({
1654
+ latitude: lat,
1655
+ longitude: long
1656
+ });
1657
+ }
1658
+ }
1659
+ }
1660
+ return [
1661
+ 0,
1662
+ 0
1663
+ ];
1664
+ }
1665
+ default: {
1666
+ return value;
1667
+ }
1668
+ }
1669
+ };
1670
+ var cellClassesForFieldType = ({ type, format }) => {
1671
+ if (!format) {
1672
+ switch (type) {
1673
+ case TypeEnum.Number:
1674
+ return [
1675
+ "text-right",
1676
+ "font-mono"
1677
+ ];
1678
+ case TypeEnum.Boolean:
1679
+ return [
1680
+ "text-right",
1681
+ "font-mono"
1682
+ ];
1683
+ case TypeEnum.String:
1684
+ return void 0;
1685
+ case TypeEnum.Ref:
1686
+ return void 0;
1687
+ default: {
1688
+ return void 0;
1689
+ }
1690
+ }
1691
+ }
1692
+ switch (format) {
1693
+ case FormatEnum3.Markdown:
1694
+ return void 0;
1695
+ case FormatEnum3.Time:
1696
+ case FormatEnum3.Timestamp:
1697
+ case FormatEnum3.DateTime:
1698
+ case FormatEnum3.Date:
1699
+ case FormatEnum3.Duration:
1700
+ return [
1701
+ "font-mono",
1702
+ "text-right"
1703
+ ];
1704
+ case FormatEnum3.Currency:
1705
+ return [
1706
+ "text-right"
1707
+ ];
1708
+ case FormatEnum3.JSON:
1709
+ case FormatEnum3.DID:
1710
+ return [
1711
+ "font-mono"
1712
+ ];
1713
+ default:
1714
+ return void 0;
1715
+ }
1716
+ };
1717
+ var pathNotUniqueError = (path) => ({
1718
+ path: "path",
1719
+ message: `'${path}' is already present`
1720
+ });
1721
+
1722
+ // packages/ui/react-ui-form/src/util/formatting.ts
1723
+ import { format as formatDate } from "date-fns/format";
1724
+ import { FormatEnum as FormatEnum4, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
1725
+ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
1726
+ const formatScalar = (type2) => {
1727
+ switch (type2) {
1728
+ case TypeEnum2.Boolean:
1729
+ return value.toLocaleString().toUpperCase();
1730
+ case TypeEnum2.Number:
1731
+ return value.toLocaleString(locale);
1732
+ case TypeEnum2.String:
1733
+ case TypeEnum2.Ref:
1734
+ return String(value);
1735
+ default: {
1736
+ return String(value);
1737
+ }
1738
+ }
1739
+ };
1740
+ if (!format) {
1741
+ return formatScalar(type);
1742
+ }
1743
+ switch (format) {
1744
+ case FormatEnum4.Boolean: {
1745
+ return formatScalar(TypeEnum2.Boolean);
1746
+ }
1747
+ case FormatEnum4.Number: {
1748
+ return formatScalar(TypeEnum2.Number);
1749
+ }
1750
+ case FormatEnum4.String:
1751
+ case FormatEnum4.Ref: {
1752
+ return formatScalar(TypeEnum2.String);
1753
+ }
1754
+ case FormatEnum4.Percent: {
1755
+ return `${value * 100}%`;
1756
+ }
1757
+ case FormatEnum4.Currency: {
1758
+ return value.toLocaleString(locale, {
1759
+ style: "currency",
1760
+ currency: "USD",
1761
+ minimumFractionDigits: 2,
1762
+ maximumFractionDigits: 2
1763
+ });
1764
+ }
1765
+ case FormatEnum4.Date: {
1766
+ return formatDate(new Date(value), "yyyy-MM-dd");
1767
+ }
1768
+ case FormatEnum4.Time: {
1769
+ return formatDate(new Date(value), "HH:mm:ss");
1770
+ }
1771
+ case FormatEnum4.DateTime: {
1772
+ return formatDate(new Date(value), "yyyy-MM-dd HH:mm:ss");
1773
+ }
1774
+ case FormatEnum4.GeoPoint: {
1775
+ if (value === null || value === void 0) {
1776
+ return "";
1777
+ }
1778
+ if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
1779
+ const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
1780
+ return `${latitude},${longitude}`;
1781
+ }
1782
+ return String(value);
1783
+ }
1784
+ default: {
1785
+ if (value === null || value === "undefined") {
1786
+ return "";
1787
+ }
1788
+ return String(value);
1789
+ }
1790
+ }
1791
+ };
1792
+ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
1793
+ const formatScalar = (type2) => {
1794
+ switch (type2) {
1795
+ case TypeEnum2.Boolean:
1796
+ case TypeEnum2.Number:
1797
+ case TypeEnum2.String:
1798
+ case TypeEnum2.Ref:
1799
+ return String(value);
1800
+ default:
1801
+ return String(value);
1802
+ }
1803
+ };
1804
+ if (!format) {
1805
+ return formatScalar(type);
1806
+ }
1807
+ switch (format) {
1808
+ case FormatEnum4.Boolean:
1809
+ case FormatEnum4.Number:
1810
+ case FormatEnum4.String:
1811
+ case FormatEnum4.Ref: {
1812
+ return formatScalar(type);
1813
+ }
1814
+ case FormatEnum4.Percent: {
1815
+ return String(value * 100);
1816
+ }
1817
+ case FormatEnum4.Currency: {
1818
+ return String(value);
1819
+ }
1820
+ case FormatEnum4.DateTime: {
1821
+ const date = new Date(value);
1822
+ return date.toISOString();
1823
+ }
1824
+ case FormatEnum4.Date: {
1825
+ const date = new Date(value);
1826
+ return date.toISOString().split("T")[0];
1827
+ }
1828
+ case FormatEnum4.Time: {
1829
+ const date = new Date(value);
1830
+ return date.toISOString().split("T")[1].split(".")[0];
1831
+ }
1832
+ case FormatEnum4.GeoPoint: {
1833
+ if (value === null || value === void 0) {
1834
+ return "";
1835
+ }
1836
+ if (Array.isArray(value) && value.length >= 2 && value.every(Number.isFinite)) {
1837
+ const { latitude, longitude } = GeoLocation3.fromGeoPoint(value);
1838
+ return `${latitude},${longitude}`;
1839
+ }
1840
+ return String(value);
1841
+ }
1842
+ default: {
1843
+ return String(value);
1844
+ }
1845
+ }
1846
+ };
2150
1847
  export {
2151
1848
  BooleanInput,
2152
1849
  ControlFrame,
2153
1850
  ControlFrameItem,
2154
1851
  ControlGroup,
2155
- ControlGroupButton,
2156
1852
  ControlItem,
2157
1853
  ControlItemInput,
2158
- ControlPage,
2159
1854
  ControlSection,
2160
1855
  ControlSectionHeading,
2161
1856
  DeprecatedFormContainer,
@@ -2174,18 +1869,14 @@ export {
2174
1869
  ViewEditor,
2175
1870
  cellClassesForFieldType,
2176
1871
  controlItemClasses,
2177
- findArrayElementType,
2178
1872
  formatForDisplay,
2179
1873
  formatForEditing,
2180
- getRefProps,
2181
1874
  parseValue,
2182
1875
  pathNotUniqueError,
2183
1876
  translations_default as translations,
2184
1877
  useForm,
2185
1878
  useFormContext,
2186
1879
  useFormValues,
2187
- useInputProps,
2188
- useQueryRefOptions,
2189
- useRefQueryLookupHandler
1880
+ useInputProps
2190
1881
  };
2191
1882
  //# sourceMappingURL=index.mjs.map