@dxos/react-ui-form 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (189) hide show
  1. package/README.md +0 -1
  2. package/dist/lib/browser/index.mjs +2305 -2352
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/node-esm/index.mjs +2305 -2352
  6. package/dist/lib/node-esm/index.mjs.map +4 -4
  7. package/dist/lib/node-esm/meta.json +1 -1
  8. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +8 -7
  9. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  10. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +66 -59
  11. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
  12. package/dist/types/src/components/Form/Form.d.ts +87 -27
  13. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  14. package/dist/types/src/components/Form/Form.stories.d.ts +112 -136
  15. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  16. package/dist/types/src/components/Form/FormField.d.ts +43 -0
  17. package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
  18. package/dist/types/src/components/Form/FormFieldComponent.d.ts +77 -0
  19. package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
  20. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
  21. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
  22. package/dist/types/src/components/Form/FormFieldSet.d.ts +18 -0
  23. package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
  24. package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
  25. package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
  26. package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
  27. package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
  28. package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
  29. package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
  30. package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
  31. package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
  32. package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
  33. package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
  34. package/dist/types/src/components/Form/fields/RefField.d.ts +16 -0
  35. package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
  36. package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
  37. package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
  38. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
  39. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
  40. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +82 -0
  41. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
  42. package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
  43. package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
  44. package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
  45. package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
  46. package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
  47. package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
  48. package/dist/types/src/components/Form/fields/index.d.ts +12 -0
  49. package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
  50. package/dist/types/src/components/Form/index.d.ts +2 -4
  51. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  52. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +23 -10
  53. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
  54. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +62 -58
  55. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
  56. package/dist/types/src/components/Settings/Settings.d.ts +39 -0
  57. package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
  58. package/dist/types/src/components/Settings/Settings.stories.d.ts +81 -0
  59. package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
  60. package/dist/types/src/components/Settings/index.d.ts +2 -0
  61. package/dist/types/src/components/Settings/index.d.ts.map +1 -0
  62. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +11 -13
  63. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  64. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +67 -62
  65. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  66. package/dist/types/src/components/index.d.ts +1 -1
  67. package/dist/types/src/components/index.d.ts.map +1 -1
  68. package/dist/types/src/components/testing.d.ts +0 -2
  69. package/dist/types/src/components/testing.d.ts.map +1 -1
  70. package/dist/types/src/hooks/index.d.ts +2 -3
  71. package/dist/types/src/hooks/index.d.ts.map +1 -1
  72. package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
  73. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
  74. package/dist/types/src/hooks/useKeyHandler.d.ts +7 -0
  75. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
  76. package/dist/types/src/translations.d.ts +63 -59
  77. package/dist/types/src/translations.d.ts.map +1 -1
  78. package/dist/types/src/util/field.d.ts +3 -3
  79. package/dist/types/src/util/field.d.ts.map +1 -1
  80. package/dist/types/src/util/formatting.d.ts +2 -2
  81. package/dist/types/src/util/formatting.d.ts.map +1 -1
  82. package/dist/types/src/util/index.d.ts +1 -1
  83. package/dist/types/src/util/index.d.ts.map +1 -1
  84. package/dist/types/src/util/properties.d.ts +7 -0
  85. package/dist/types/src/util/properties.d.ts.map +1 -0
  86. package/dist/types/src/util/refs.d.ts +2 -2
  87. package/dist/types/src/util/refs.d.ts.map +1 -1
  88. package/dist/types/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +51 -48
  90. package/src/components/FieldEditor/FieldEditor.stories.tsx +43 -25
  91. package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
  92. package/src/components/FieldEditor/FieldEditor.tsx +74 -78
  93. package/src/components/Form/AUDIT.md +17 -0
  94. package/src/components/Form/Form.stories.tsx +148 -250
  95. package/src/components/Form/Form.tsx +324 -110
  96. package/src/components/Form/FormField.tsx +304 -0
  97. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  98. package/src/components/Form/FormFieldComponent.tsx +171 -0
  99. package/src/components/Form/FormFieldSet.tsx +128 -0
  100. package/src/components/Form/README.md +3 -0
  101. package/src/components/Form/fields/ArrayField.tsx +154 -0
  102. package/src/components/Form/fields/BooleanField.tsx +22 -0
  103. package/src/components/Form/fields/GeoPointField.tsx +120 -0
  104. package/src/components/Form/fields/MarkdownField.tsx +78 -0
  105. package/src/components/Form/fields/NumberField.tsx +39 -0
  106. package/src/components/Form/fields/RefField.tsx +198 -0
  107. package/src/components/Form/fields/SelectField.tsx +65 -0
  108. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +19 -17
  109. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +29 -24
  110. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  111. package/src/components/Form/fields/TextField.tsx +38 -0
  112. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +16 -9
  113. package/src/components/Form/fields/index.ts +15 -0
  114. package/src/components/Form/index.ts +3 -4
  115. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +18 -16
  116. package/src/components/ObjectPicker/ObjectPicker.tsx +103 -78
  117. package/src/components/Settings/Settings.stories.tsx +55 -0
  118. package/src/components/Settings/Settings.tsx +129 -0
  119. package/src/components/{ControlSection → Settings}/index.ts +1 -1
  120. package/src/components/ViewEditor/ViewEditor.stories.tsx +47 -45
  121. package/src/components/ViewEditor/ViewEditor.test.tsx +5 -5
  122. package/src/components/ViewEditor/ViewEditor.tsx +297 -210
  123. package/src/components/index.ts +1 -1
  124. package/src/components/testing.tsx +23 -9
  125. package/src/hooks/index.ts +2 -3
  126. package/src/hooks/useFormHandler.ts +380 -0
  127. package/src/hooks/useKeyHandler.tsx +37 -0
  128. package/src/translations.ts +66 -64
  129. package/src/util/field.ts +25 -25
  130. package/src/util/formatting.ts +22 -22
  131. package/src/util/index.ts +1 -1
  132. package/src/util/properties.ts +18 -0
  133. package/src/util/refs.ts +13 -15
  134. package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
  135. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
  136. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -83
  137. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
  138. package/dist/types/src/components/ControlSection/index.d.ts +0 -2
  139. package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
  140. package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
  141. package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
  142. package/dist/types/src/components/Form/Defaults.d.ts +0 -14
  143. package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
  144. package/dist/types/src/components/Form/FormActions.d.ts +0 -9
  145. package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
  146. package/dist/types/src/components/Form/FormContent.d.ts +0 -63
  147. package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
  148. package/dist/types/src/components/Form/FormContext.d.ts +0 -23
  149. package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
  150. package/dist/types/src/components/Form/Input.d.ts +0 -29
  151. package/dist/types/src/components/Form/Input.d.ts.map +0 -1
  152. package/dist/types/src/components/Form/RefField.d.ts +0 -22
  153. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  154. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
  155. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
  156. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
  157. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
  158. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -78
  159. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
  160. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  161. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  162. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  163. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  164. package/dist/types/src/components/Form/factory.d.ts +0 -8
  165. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  166. package/dist/types/src/hooks/useForm.d.ts +0 -67
  167. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  168. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -29
  169. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  170. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  171. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  172. package/dist/types/src/util/schema.d.ts +0 -3
  173. package/dist/types/src/util/schema.d.ts.map +0 -1
  174. package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
  175. package/src/components/ControlSection/ControlSection.tsx +0 -153
  176. package/src/components/Form/ArrayField.tsx +0 -125
  177. package/src/components/Form/Defaults.tsx +0 -205
  178. package/src/components/Form/FormActions.tsx +0 -54
  179. package/src/components/Form/FormContent.tsx +0 -362
  180. package/src/components/Form/FormContext.tsx +0 -110
  181. package/src/components/Form/Input.tsx +0 -54
  182. package/src/components/Form/RefField.tsx +0 -283
  183. package/src/components/Form/custom/GeoPointInput.tsx +0 -80
  184. package/src/components/Form/custom/index.ts +0 -7
  185. package/src/components/Form/factory.tsx +0 -31
  186. package/src/hooks/useForm.ts +0 -296
  187. package/src/hooks/useQueryRefOptions.ts +0 -62
  188. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  189. package/src/util/schema.ts +0 -12
@@ -1,778 +1,443 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/translations.ts
4
- var translationKey = "react-ui-form";
4
+ var translationKey = "@dxos/react-ui-form";
5
5
  var translations = [
6
6
  {
7
7
  "en-US": {
8
8
  [translationKey]: {
9
- "fields label": "Fields",
10
- "hidden fields label": "Hidden Fields",
11
- "empty readonly ref field label": "(none)",
12
- // TODO(burdon): Standardize field/property.
13
- "add property button": "Add property",
14
- "field property label": "Property",
15
- "field property placeholder": "Property name",
16
- "field format label": "Type",
17
- "field path label": "Field path",
18
- "add field": "Add field",
19
- "delete field": "Delete field",
20
- "field limit reached": "Maximum number of fields reached",
21
- "boolean input true value": "Yes",
22
- "boolean input false value": "No",
23
- "show field label": "Show field",
24
- "hide field label": "Hide field",
25
- "delete field label": "Delete field",
26
- "ref field combobox input placeholder": "Search\u2026",
27
- "ref field placeholder_one": "Select\u2026",
28
- "ref field placeholder_other": "Select items\u2026",
29
- // TODO(burdon): Factor out?
30
- "save button": "Save",
31
- // FormatEnum
32
- "format boolean": "Boolean",
33
- "format currency": "Currency",
34
- "format date": "Date",
35
- "format date-time": "DateTime",
36
- "format did": "DID",
37
- "format duration": "Duration",
38
- "format dxn": "DXN",
39
- "format email": "Email",
40
- "format formula": "Formula",
41
- "format hostname": "Hostname",
42
- "format integer": "Integer",
43
- "format json": "JSON",
44
- "format lnglat": "Geopoint",
45
- "format markdown": "Markdown",
46
- "format percent": "Percent",
47
- "format ref": "Reference",
48
- "format regex": "RegExp",
49
- "format string": "String",
50
- "format single-select": "Select",
51
- "format multi-select": "Multi-select",
52
- "format text": "Long text",
53
- "format time": "Time",
54
- "format timestamp": "Timestamp",
55
- "format user": "User",
56
- "format number": "Number",
57
- "format uri": "URI",
58
- "format url": "URL",
59
- "format uuid": "UUID",
60
- // GeoPointInput.
61
- "latitude label": "Latitude",
62
- "longitude label": "Longitude",
63
- // SelectOptionsInput.
64
- "select option label": "Label",
65
- "select option label placeholder": "Option label",
66
- "select option color": "Color",
67
- "select option delete": "Delete",
68
- "select option add": "Add option",
9
+ "fields.label": "Fields",
10
+ "hidden-fields.label": "Hidden Fields",
11
+ "empty-readonly-ref-field.label": "(none)",
12
+ "add-property-button.label": "Add property",
13
+ "field-property.label": "Property",
14
+ "field-property.placeholder": "Property name",
15
+ "field-format.label": "Type",
16
+ "field-path.label": "Field path",
17
+ "add-field.button": "Add field",
18
+ "boolean-input-true.value": "Yes",
19
+ "boolean-input-false.value": "No",
20
+ "show-field.label": "Show field",
21
+ "hide-field.label": "Hide field",
22
+ "delete-field.label": "Delete field",
23
+ "ref-field-combobox-input.placeholder": "Search\u2026",
24
+ "ref-field.placeholder": "Select\u2026",
25
+ "ref-field.placeholder_one": "Select\u2026",
26
+ "ref-field.placeholder_other": "Select items\u2026",
27
+ "create-option.label": "Create",
28
+ "example.placeholder": "Example",
29
+ "latitude.placeholder": "Latitude (e.g., 40.7128)",
30
+ "longitude.placeholder": "Longitude (e.g., -74.0060)",
31
+ "cancel-button.label": "Cancel",
32
+ "save-button.label": "Save",
33
+ // TypeFormat
34
+ "format.boolean.label": "Boolean",
35
+ "format.currency.label": "Currency",
36
+ "format.date.label": "Date",
37
+ "format.date-time.label": "DateTime",
38
+ "format.did.label": "DID",
39
+ "format.duration.label": "Duration",
40
+ "format.dxn.label": "DXN",
41
+ "format.email.label": "Email",
42
+ "format.formula.label": "Formula",
43
+ "format.hostname.label": "Hostname",
44
+ "format.integer.label": "Integer",
45
+ "format.json.label": "JSON",
46
+ "format.lnglat.label": "Geopoint",
47
+ "format.markdown.label": "Markdown",
48
+ "format.percent.label": "Percent",
49
+ "format.ref.label": "Reference",
50
+ "format.regex.label": "RegExp",
51
+ "format.string.label": "String",
52
+ "format.single-select.label": "Select",
53
+ "format.multi-select.label": "Multi-select",
54
+ "format.text.label": "Long text",
55
+ "format.time.label": "Time",
56
+ "format.timestamp.label": "Timestamp",
57
+ "format.user.label": "User",
58
+ "format.number.label": "Number",
59
+ "format.uri.label": "URI",
60
+ "format.url.label": "URL",
61
+ "format.uuid.label": "UUID",
62
+ // GeoPointField.
63
+ "latitude.label": "Latitude",
64
+ "longitude.label": "Longitude",
65
+ // SelectOptionsField.
66
+ "select-option.label": "Label",
67
+ "select-option-label.placeholder": "Option label",
68
+ "select-option-delete.button": "Delete",
69
+ "select-option-add.button": "Add option",
69
70
  // System schema message.
70
- "system schema title": "System record type",
71
- "system schema description": "This is a system record type and cannot be modified, though the view can still be configured."
71
+ "system-schema.title": "System type",
72
+ "system-schema.description": "System type: cannot add or remove fields.",
73
+ "remove.button": "Remove"
72
74
  }
73
75
  }
74
76
  }
75
77
  ];
76
78
 
77
- // src/components/ControlSection/ControlSection.tsx
78
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
79
- import React from "react";
80
- import { Button, Input, toLocalizedString, useTranslation } from "@dxos/react-ui";
81
- import { StackItem } from "@dxos/react-ui-stack";
82
- import { mx } from "@dxos/react-ui-theme";
83
- var ControlPage = ({ children, classNames, ...props }) => {
84
- var _effect = _useSignals();
85
- try {
86
- return /* @__PURE__ */ React.createElement(StackItem.Content, {
87
- scrollable: true,
88
- classNames: "[--control-spacing:var(--dx-trimMd)]"
89
- }, /* @__PURE__ */ React.createElement("div", {
90
- role: "none",
91
- className: mx("pli-cardSpacingInline pbe-trimLg", classNames),
92
- ...props
93
- }, children));
94
- } finally {
95
- _effect.f();
96
- }
97
- };
98
- var ControlSection = ({ title, description, children }) => {
99
- var _effect = _useSignals();
100
- try {
101
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ControlSectionHeading, {
102
- title,
103
- description
104
- }), children);
105
- } finally {
106
- _effect.f();
107
- }
108
- };
109
- var ControlSectionHeading = ({ title, description }) => {
110
- var _effect = _useSignals();
111
- try {
112
- const { t } = useTranslation(translationKey);
113
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h2", {
114
- className: "pli-trimMd container-max-width text-xl mbs-trimLg mbe-trimMd"
115
- }, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
116
- className: "pli-trimMd mlb-trimMd container-max-width text-description"
117
- }, toLocalizedString(description, t)));
118
- } finally {
119
- _effect.f();
120
- }
121
- };
122
- var ControlGroupButton = ({ classNames, ...props }) => {
123
- var _effect = _useSignals();
124
- try {
125
- return /* @__PURE__ */ React.createElement(Button, {
126
- ...props,
127
- classNames: [
128
- "md:col-span-2",
129
- classNames
130
- ]
131
- });
132
- } finally {
133
- _effect.f();
134
- }
135
- };
136
- var ControlGroup = ({ children, classNames }) => {
137
- var _effect = _useSignals();
138
- try {
139
- return /* @__PURE__ */ React.createElement("div", {
140
- role: "none",
141
- className: mx("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd", "[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end", classNames)
142
- }, children);
143
- } finally {
144
- _effect.f();
145
- }
146
- };
147
- var ControlFrame = ({ children }) => {
148
- var _effect = _useSignals();
149
- try {
150
- return /* @__PURE__ */ React.createElement("div", {
151
- role: "none",
152
- className: mx("container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd", "border border-separator rounded-md")
153
- }, children);
154
- } finally {
155
- _effect.f();
156
- }
157
- };
158
- var controlItemClasses = mx([
159
- "container-max-width grid md:col-span-2 grid-cols-subgrid gap-trimSm items-center",
160
- // TODO(burdon): Use grid gap consistently or apply margins consistently?
161
- "mlb-[--control-spacing] *:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd",
162
- "border border-separator rounded-md"
163
- ]);
164
- var controlItemTitleClasses = "mbe-0 text-lg text-baseText font-normal";
165
- var controlItemDescriptionClasses = "mlb-trimSm md:mbe-0 text-base text-description";
166
- var ControlItem = ({ title, description, children }) => {
167
- var _effect = _useSignals();
168
- try {
169
- const { t } = useTranslation(translationKey);
170
- return /* @__PURE__ */ React.createElement("div", {
171
- className: controlItemClasses
172
- }, /* @__PURE__ */ React.createElement("div", {
173
- role: "none"
174
- }, /* @__PURE__ */ React.createElement("h3", {
175
- className: controlItemTitleClasses
176
- }, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
177
- className: controlItemDescriptionClasses
178
- }, toLocalizedString(description, t))), children);
179
- } finally {
180
- _effect.f();
181
- }
182
- };
183
- var ControlItemInput = ({ title, description, children }) => {
184
- var _effect = _useSignals();
185
- try {
186
- const { t } = useTranslation(translationKey);
187
- return /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement("div", {
188
- className: controlItemClasses
189
- }, /* @__PURE__ */ React.createElement("div", {
190
- role: "none"
191
- }, /* @__PURE__ */ React.createElement(Input.Label, {
192
- classNames: controlItemTitleClasses
193
- }, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Description, {
194
- classNames: controlItemDescriptionClasses
195
- }, toLocalizedString(description, t)))), children));
196
- } finally {
197
- _effect.f();
198
- }
199
- };
200
- var ControlFrameItem = ({ title, description, children }) => {
201
- var _effect = _useSignals();
202
- try {
203
- const { t } = useTranslation(translationKey);
204
- return /* @__PURE__ */ React.createElement("div", {
205
- role: "group",
206
- className: "min-is-0"
207
- }, /* @__PURE__ */ React.createElement("h3", {
208
- className: "text-lg mbe-2"
209
- }, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
210
- className: "mlb-trimSm md:mbe-0 text-description"
211
- }, toLocalizedString(description, t)), children);
212
- } finally {
213
- _effect.f();
214
- }
215
- };
216
-
217
79
  // src/components/FieldEditor/FieldEditor.tsx
218
- import { useSignals as _useSignals14 } from "@preact-signals/safe-react/tracking";
219
- import React14, { useCallback as useCallback12, useEffect as useEffect8, useMemo as useMemo7, useState as useState6 } from "react";
220
- import { FormatEnum as FormatEnum5, FormatEnums, formatToType } from "@dxos/echo/internal";
221
- import { log as log3 } from "@dxos/log";
222
- import { useAsyncEffect, useTranslation as useTranslation9 } from "@dxos/react-ui";
223
- import { formatToAdditionalPropertyAttributes, getFormatSchema, getSchemaProperties as getSchemaProperties3, sortProperties } from "@dxos/schema";
224
-
225
- // src/components/Form/custom/GeoPointInput.tsx
226
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
227
- import React3, { useCallback, useEffect, useMemo, useState } from "react";
228
- import { GeoLocation } from "@dxos/echo/internal";
229
- import { Input as Input3, useTranslation as useTranslation2 } from "@dxos/react-ui";
230
- import { safeParseFloat } from "@dxos/util";
80
+ import React17, { useCallback as useCallback14, useEffect as useEffect6, useMemo as useMemo7, useState as useState5 } from "react";
81
+ import { Obj as Obj2 } from "@dxos/echo";
82
+ import { Format as Format4, FormatEnums, formatToType } from "@dxos/echo/internal";
83
+ import { log as log2 } from "@dxos/log";
84
+ import { useAsyncEffect, useTranslation as useTranslation8 } from "@dxos/react-ui";
85
+ import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
231
86
 
232
- // src/components/Form/Input.tsx
233
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
234
- import React2 from "react";
235
- import { Icon, Input as Input2, Tooltip } from "@dxos/react-ui";
236
- import { labelSpacing } from "@dxos/react-ui-stack";
237
- import { errorText, mx as mx2 } from "@dxos/react-ui-theme";
238
- var InputHeader = ({ error, label, readonly }) => {
239
- var _effect = _useSignals2();
240
- try {
241
- const Label = readonly ? "span" : Input2.Label;
242
- const labelProps = readonly ? {} : {
243
- classNames: "!mlb-0"
244
- };
245
- return /* @__PURE__ */ React2.createElement("div", {
246
- role: "none",
247
- className: mx2("flex justify-between items-center", labelSpacing)
248
- }, /* @__PURE__ */ React2.createElement(Label, labelProps, label), error && /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
249
- asChild: true,
250
- content: error,
251
- side: "bottom"
252
- }, /* @__PURE__ */ React2.createElement(Icon, {
253
- icon: "ph--warning--regular",
254
- size: 4,
255
- classNames: errorText
256
- })));
257
- } finally {
258
- _effect.f();
87
+ // src/util/field.ts
88
+ import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
89
+ var parseValue = ({ type, format, value: value3 }) => {
90
+ if (value3 === void 0 || value3 === null || value3 === "") {
91
+ return void 0;
259
92
  }
260
- };
261
-
262
- // src/components/Form/custom/GeoPointInput.tsx
263
- var GeoPointInput = ({ type, label, readonly, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
264
- var _effect = _useSignals3();
265
- try {
266
- const { t } = useTranslation2(translationKey);
267
- const { status, error } = getStatus();
268
- const geoPoint = useMemo(() => getValue3() ?? [
269
- 0,
270
- 0
271
- ], [
272
- getValue3
273
- ]);
274
- const geoLocation = useMemo(() => GeoLocation.fromGeoPoint(geoPoint), [
275
- geoPoint
276
- ]);
277
- const [longitudeText, setLongitudeText] = useState(geoLocation.longitude?.toString());
278
- const [latitudeText, setLatitudeText] = useState(geoLocation.latitude?.toString());
279
- useEffect(() => {
280
- const location = GeoLocation.fromGeoPoint(geoPoint);
281
- setLongitudeText(location.longitude.toString());
282
- setLatitudeText(location.latitude.toString());
283
- }, [
284
- geoPoint
285
- ]);
286
- const handleCoordinateChange = useCallback((coordinateType, setText) => (event) => {
287
- const inputText = event.target.value;
288
- setText(inputText);
289
- if (inputText !== "" && inputText !== "-") {
290
- const coord = safeParseFloat(inputText);
291
- if (coord !== void 0 && !isNaN(coord)) {
292
- const currentLocation = GeoLocation.fromGeoPoint(getValue3() ?? [
293
- 0,
294
- 0
295
- ]);
296
- const newLocation = {
297
- ...currentLocation,
298
- [coordinateType]: coord
299
- };
300
- const newValue = GeoLocation.toGeoPoint(newLocation);
301
- onValueChange(type, newValue);
93
+ const parseScalar = (type2) => {
94
+ switch (type2) {
95
+ case TypeEnum.Boolean: {
96
+ if (typeof value3 === "string") {
97
+ const lowercaseValue = value3.toLowerCase();
98
+ if (lowercaseValue === "0" || lowercaseValue === "false") {
99
+ return false;
100
+ } else if (lowercaseValue === "1" || lowercaseValue === "true") {
101
+ return true;
102
+ }
302
103
  }
104
+ return Boolean(value3);
303
105
  }
304
- }, [
305
- getValue3,
306
- onValueChange,
307
- type
308
- ]);
309
- return /* @__PURE__ */ React3.createElement(Input3.Root, {
310
- validationValence: status
311
- }, /* @__PURE__ */ React3.createElement(InputHeader, {
312
- error,
313
- label
314
- }), /* @__PURE__ */ React3.createElement("div", {
315
- role: "none",
316
- className: "grid grid-cols-2 gap-2"
317
- }, /* @__PURE__ */ React3.createElement("div", {
318
- role: "none"
319
- }, /* @__PURE__ */ React3.createElement(Input3.Label, null, t("latitude label")), /* @__PURE__ */ React3.createElement(Input3.TextInput, {
320
- type: "number",
321
- step: "0.00001",
322
- min: "-90",
323
- max: "90",
324
- disabled: !!readonly,
325
- value: latitudeText,
326
- onChange: handleCoordinateChange("latitude", setLatitudeText),
327
- onBlur
328
- })), /* @__PURE__ */ React3.createElement("div", {
329
- role: "none"
330
- }, /* @__PURE__ */ React3.createElement(Input3.Label, null, t("longitude label")), /* @__PURE__ */ React3.createElement(Input3.TextInput, {
331
- type: "number",
332
- step: "0.00001",
333
- min: "-180",
334
- max: "180",
335
- disabled: !!readonly,
336
- value: longitudeText,
337
- onChange: handleCoordinateChange("longitude", setLongitudeText),
338
- onBlur
339
- }))));
340
- } finally {
341
- _effect.f();
342
- }
343
- };
344
-
345
- // src/components/Form/custom/SelectOptionsInput.tsx
346
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
347
- import React4, { useCallback as useCallback2, useEffect as useEffect2, useRef, useState as useState2 } from "react";
348
- import { PublicKey } from "@dxos/keys";
349
- import { IconButton, Input as Input4, Tag, useTranslation as useTranslation3 } from "@dxos/react-ui";
350
- import { List } from "@dxos/react-ui-list";
351
- import { HuePicker } from "@dxos/react-ui-pickers";
352
- import { hues, subtleHover } from "@dxos/react-ui-theme";
353
- var SelectOptionInput = ({ type, label, readonly, getStatus, getValue: getValue3, onValueChange }) => {
354
- var _effect = _useSignals4();
355
- try {
356
- const [selected, setSelectedId] = useState2(null);
357
- const [isNewOption, setIsNewOption] = useState2(false);
358
- const inputRef = useRef(null);
359
- const { t } = useTranslation3(translationKey);
360
- const { status, error } = getStatus();
361
- const options = getValue3();
362
- useEffect2(() => {
363
- if (options === void 0) {
364
- onValueChange(type, []);
106
+ case TypeEnum.Number: {
107
+ const cleaned = typeof value3 === "string" ? value3.replace(/[^0-9.-]+/g, "") : value3;
108
+ const num = Number(cleaned);
109
+ return Number.isNaN(num) ? null : num;
365
110
  }
366
- }, [
367
- options,
368
- onValueChange,
369
- type
370
- ]);
371
- const randomHue = () => {
372
- const usedHues = new Set(options?.map((option) => option.color) ?? []);
373
- const unusedHues = hues.filter((hue) => !usedHues.has(hue));
374
- if (unusedHues.length > 0) {
375
- return unusedHues[Math.floor(Math.random() * unusedHues.length)];
111
+ case TypeEnum.String:
112
+ case TypeEnum.Ref:
113
+ return String(value3);
114
+ default: {
115
+ return value3;
376
116
  }
377
- const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
378
- const availableHues = hues.filter((hue) => !lastThree.has(hue));
379
- return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
380
- };
381
- const handleAdd = useCallback2(() => {
382
- const newId = PublicKey.random().truncate();
383
- const newOption = {
384
- id: newId,
385
- title: "",
386
- color: randomHue()
387
- };
388
- onValueChange(type, [
389
- ...options ?? [],
390
- newOption
391
- ]);
392
- setSelectedId(newId);
393
- setIsNewOption(true);
394
- }, [
395
- options,
396
- type,
397
- onValueChange
398
- ]);
399
- const handleDelete = useCallback2((id) => {
400
- const newOptions = options?.filter((option) => option.id !== id) ?? [];
401
- onValueChange(type, newOptions);
402
- setSelectedId(null);
403
- }, [
404
- options,
405
- type,
406
- onValueChange
407
- ]);
408
- const handleMove = useCallback2((from, to) => {
409
- if (!options) {
410
- return;
117
+ }
118
+ };
119
+ if (!format) {
120
+ return parseScalar(type);
121
+ }
122
+ switch (format) {
123
+ case Format.TypeFormat.Boolean:
124
+ return parseScalar(TypeEnum.Boolean);
125
+ case Format.TypeFormat.Number:
126
+ case Format.TypeFormat.Percent:
127
+ case Format.TypeFormat.Currency:
128
+ return parseScalar(TypeEnum.Number);
129
+ case Format.TypeFormat.String:
130
+ case Format.TypeFormat.Markdown: {
131
+ return parseScalar(TypeEnum.String);
132
+ }
133
+ case Format.TypeFormat.Ref:
134
+ throw new Error(`unexpected format: ${Format.TypeFormat.Ref}`);
135
+ case Format.TypeFormat.DateTime:
136
+ case Format.TypeFormat.Date:
137
+ case Format.TypeFormat.Time:
138
+ case Format.TypeFormat.Timestamp: {
139
+ const date = new Date(value3);
140
+ return isNaN(date.getTime()) ? null : date;
141
+ }
142
+ case Format.TypeFormat.GeoPoint: {
143
+ if (typeof value3 === "string") {
144
+ const cleaned = value3.replace(/[^0-9.,-]+/g, "");
145
+ const parts = cleaned.split(",");
146
+ if (parts.length === 2) {
147
+ const lat = parseFloat(parts[0]);
148
+ const long = parseFloat(parts[1]);
149
+ if (!isNaN(lat) && !isNaN(long)) {
150
+ return GeoLocation.toGeoPoint({
151
+ latitude: lat,
152
+ longitude: long
153
+ });
154
+ }
155
+ }
411
156
  }
412
- const newOptions = [
413
- ...options
157
+ return [
158
+ 0,
159
+ 0
414
160
  ];
415
- const [removed] = newOptions.splice(from, 1);
416
- newOptions.splice(to, 0, removed);
417
- onValueChange(type, newOptions);
418
- }, [
419
- options,
420
- type,
421
- onValueChange
422
- ]);
423
- const handleClick = useCallback2((id) => {
424
- setSelectedId((current) => current === id ? null : id);
425
- }, []);
426
- const handleTitleChange = useCallback2((id) => (e) => {
427
- const newOptions = options?.map((o) => o.id === id ? {
428
- ...o,
429
- title: e.target.value
430
- } : o);
431
- onValueChange(type, newOptions ?? []);
432
- }, [
433
- options,
434
- type,
435
- onValueChange
436
- ]);
437
- const handleKeyDown = useCallback2((e) => {
438
- if (e.key === "Enter") {
439
- setSelectedId(null);
440
- }
441
- }, []);
442
- const handleColorChange = useCallback2((id) => (hue) => {
443
- const newOptions = options?.map((o) => o.id === id ? {
444
- ...o,
445
- color: hue
446
- } : o);
447
- onValueChange(type, newOptions ?? []);
448
- }, [
449
- options,
450
- type,
451
- onValueChange
452
- ]);
453
- useEffect2(() => {
454
- if (selected && isNewOption && inputRef.current) {
455
- inputRef.current.focus();
456
- setIsNewOption(false);
457
- }
458
- }, [
459
- selected,
460
- isNewOption
461
- ]);
462
- return /* @__PURE__ */ React4.createElement(Input4.Root, {
463
- validationValence: status
464
- }, /* @__PURE__ */ React4.createElement(InputHeader, {
465
- error,
466
- label
467
- }), /* @__PURE__ */ React4.createElement("div", {
468
- role: "none"
469
- }, options && /* @__PURE__ */ React4.createElement(List.Root, {
470
- items: options,
471
- isItem: (item) => true,
472
- onMove: readonly ? void 0 : handleMove,
473
- readonly: !!readonly
474
- }, ({ items }) => /* @__PURE__ */ React4.createElement("div", {
475
- role: "list",
476
- className: "is-full overflow-auto"
477
- }, items?.map((item) => /* @__PURE__ */ React4.createElement("div", {
478
- key: item.id
479
- }, /* @__PURE__ */ React4.createElement(List.Item, {
480
- role: "button",
481
- item,
482
- classNames: [
483
- subtleHover,
484
- "flex flex-col cursor-pointer rounded-sm"
485
- ],
486
- "aria-expanded": selected === item.id
487
- }, /* @__PURE__ */ React4.createElement("div", {
488
- className: "flex items-center"
489
- }, /* @__PURE__ */ React4.createElement(List.ItemDragHandle, {
490
- disabled: !!readonly
491
- }), /* @__PURE__ */ React4.createElement(List.ItemTitle, {
492
- onClick: () => handleClick(item.id),
493
- classNames: "flex-1"
494
- }, /* @__PURE__ */ React4.createElement(Tag, {
495
- palette: item.color
496
- }, item.title || "\u200B")), /* @__PURE__ */ React4.createElement(IconButton, {
497
- iconOnly: true,
498
- variant: "ghost",
499
- label: t(selected === item.id ? "collapse label" : "expand label", {
500
- ns: "os"
501
- }),
502
- icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
503
- onClick: () => handleClick(item.id)
504
- })), selected === item.id && /* @__PURE__ */ React4.createElement("div", {
505
- className: "pli-cardSpacingInline plb-cardSpacingBlock flex flex-col gap-1 density-fine"
506
- }, /* @__PURE__ */ React4.createElement(Input4.Label, {
507
- classNames: "text-xs"
508
- }, t("select option label")), /* @__PURE__ */ React4.createElement("div", {
509
- className: "grid grid-cols-[1fr_min-content_min-content] gap-1"
510
- }, /* @__PURE__ */ React4.createElement(Input4.TextInput, {
511
- disabled: !!readonly,
512
- placeholder: t("select option label placeholder"),
513
- ref: selected === item.id ? inputRef : void 0,
514
- value: item.title,
515
- onChange: handleTitleChange(item.id),
516
- onKeyDown: handleKeyDown,
517
- classNames: "flex-1",
518
- "data-no-submit": true
519
- }), /* @__PURE__ */ React4.createElement(HuePicker, {
520
- disabled: !!readonly,
521
- value: item.color,
522
- onChange: handleColorChange(item.id)
523
- }), /* @__PURE__ */ React4.createElement(IconButton, {
524
- disabled: !!readonly,
525
- icon: "ph--trash--fill",
526
- iconOnly: true,
527
- label: t("select option delete"),
528
- onClick: () => handleDelete(item.id)
529
- })))))), /* @__PURE__ */ React4.createElement(IconButton, {
530
- variant: "ghost",
531
- icon: "ph--plus--regular",
532
- label: t("select option add"),
533
- onClick: handleAdd,
534
- disabled: !!readonly,
535
- classNames: "is-full"
536
- })))));
537
- } finally {
538
- _effect.f();
161
+ }
162
+ default: {
163
+ return value3;
164
+ }
539
165
  }
540
166
  };
541
-
542
- // src/components/Form/custom/TupleInput.tsx
543
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
544
- import React5 from "react";
545
- import { Input as Input5 } from "@dxos/react-ui";
546
- import { mx as mx3 } from "@dxos/react-ui-theme";
547
- import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
548
- var gridCols = [
549
- "grid-cols-1",
550
- "grid-cols-2",
551
- "grid-cols-3",
552
- "grid-cols-4"
553
- ];
554
- var TupleInput = ({ binding, type, label, readonly, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
555
- var _effect = _useSignals5();
556
- try {
557
- const { status, error } = getStatus();
558
- const values = getValue3() ?? {};
559
- return /* @__PURE__ */ React5.createElement(Input5.Root, {
560
- validationValence: status
561
- }, /* @__PURE__ */ React5.createElement(InputHeader, {
562
- error,
563
- label
564
- }), /* @__PURE__ */ React5.createElement("div", {
565
- className: mx3("grid gap-2", gridCols[binding.length - 1])
566
- }, binding.map((prop) => /* @__PURE__ */ React5.createElement(Input5.TextInput, {
567
- key: prop,
568
- type: "number",
569
- disabled: !!readonly,
570
- value: values[prop],
571
- onChange: (event) => onValueChange(type, {
572
- ...values,
573
- [prop]: safeParseFloat2(event.target.value, 0)
574
- }),
575
- onBlur
576
- }))));
577
- } finally {
578
- _effect.f();
167
+ var cellClassesForFieldType = ({ type, format }) => {
168
+ switch (format || type) {
169
+ case Format.TypeFormat.Markdown:
170
+ return void 0;
171
+ case Format.TypeFormat.Time:
172
+ case Format.TypeFormat.Timestamp:
173
+ case Format.TypeFormat.DateTime:
174
+ case Format.TypeFormat.Date:
175
+ case Format.TypeFormat.Duration:
176
+ return [
177
+ "font-mono",
178
+ "text-right"
179
+ ];
180
+ case Format.TypeFormat.Currency:
181
+ return [
182
+ "text-right"
183
+ ];
184
+ case Format.TypeFormat.JSON:
185
+ case Format.TypeFormat.DID:
186
+ return [
187
+ "font-mono"
188
+ ];
189
+ case TypeEnum.Number:
190
+ case TypeEnum.Boolean:
191
+ return [
192
+ "text-right",
193
+ "font-mono"
194
+ ];
195
+ case TypeEnum.String:
196
+ return void 0;
197
+ case TypeEnum.Ref:
198
+ return void 0;
199
+ default:
200
+ return void 0;
579
201
  }
580
202
  };
203
+ var pathNotUniqueError = (path) => ({
204
+ path: "path",
205
+ message: `'${path}' is already present`
206
+ });
581
207
 
582
- // src/components/Form/Defaults.tsx
583
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
584
- import React6, { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef2 } from "react";
585
- import { Input as Input6, Select, useTranslation as useTranslation4 } from "@dxos/react-ui";
586
- var TextInput = ({ type, label, inputOnly, readonly, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
587
- var _effect = _useSignals6();
588
- try {
589
- const { status, error } = getStatus();
590
- return readonly && !getValue3() ? null : readonly === "static" && inputOnly ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.Root, {
591
- validationValence: status
592
- }, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
593
- error,
594
- label
595
- }), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.TextInput, {
596
- disabled: !!readonly,
597
- placeholder,
598
- value: getValue3() ?? "",
599
- onChange: (event) => onValueChange(type, event.target.value),
600
- onBlur
601
- }), inputOnly && /* @__PURE__ */ React6.createElement(Input6.Validation, null, error));
602
- } finally {
603
- _effect.f();
208
+ // src/util/formatting.ts
209
+ import { format as formatDate } from "date-fns/format";
210
+ import { Format as Format2, GeoLocation as GeoLocation2, TypeEnum as TypeEnum2 } from "@dxos/echo/internal";
211
+ var formatForDisplay = ({ type, format, value: value3, locale = void 0 }) => {
212
+ const formatScalar = (type2) => {
213
+ switch (type2) {
214
+ case TypeEnum2.Boolean:
215
+ return value3.toLocaleString().toUpperCase();
216
+ case TypeEnum2.Number:
217
+ return value3.toLocaleString(locale);
218
+ case TypeEnum2.String:
219
+ case TypeEnum2.Ref:
220
+ return String(value3);
221
+ default: {
222
+ return String(value3);
223
+ }
224
+ }
225
+ };
226
+ if (!format) {
227
+ return formatScalar(type);
604
228
  }
605
- };
606
- var NumberInput = ({ type, label, inputOnly, readonly, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
607
- var _effect = _useSignals6();
608
- try {
609
- const { status, error } = getStatus();
610
- return readonly && !getValue3() ? null : readonly === "static" && inputOnly ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.Root, {
611
- validationValence: status
612
- }, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
613
- error,
614
- label
615
- }), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.TextInput, {
616
- type: "number",
617
- disabled: !!readonly,
618
- placeholder,
619
- value: getValue3(),
620
- onChange: (event) => onValueChange(type, event.target.value),
621
- onBlur
622
- }), inputOnly && /* @__PURE__ */ React6.createElement(Input6.DescriptionAndValidation, null, error));
623
- } finally {
624
- _effect.f();
229
+ switch (format) {
230
+ case Format2.TypeFormat.Boolean: {
231
+ return formatScalar(TypeEnum2.Boolean);
232
+ }
233
+ case Format2.TypeFormat.Number: {
234
+ return formatScalar(TypeEnum2.Number);
235
+ }
236
+ case Format2.TypeFormat.String:
237
+ case Format2.TypeFormat.Ref: {
238
+ return formatScalar(TypeEnum2.String);
239
+ }
240
+ case Format2.TypeFormat.Percent: {
241
+ return `${value3 * 100}%`;
242
+ }
243
+ case Format2.TypeFormat.Currency: {
244
+ return value3.toLocaleString(locale, {
245
+ style: "currency",
246
+ currency: "USD",
247
+ minimumFractionDigits: 2,
248
+ maximumFractionDigits: 2
249
+ });
250
+ }
251
+ case Format2.TypeFormat.Date: {
252
+ try {
253
+ return formatDate(new Date(value3), "yyyy-MM-dd");
254
+ } catch (error) {
255
+ return "Invalid Date";
256
+ }
257
+ }
258
+ case Format2.TypeFormat.Time: {
259
+ try {
260
+ return formatDate(new Date(value3), "HH:mm:ss");
261
+ } catch (error) {
262
+ return "Invalid Time";
263
+ }
264
+ }
265
+ case Format2.TypeFormat.DateTime: {
266
+ try {
267
+ return formatDate(new Date(value3), "yyyy-MM-dd HH:mm:ss");
268
+ } catch (error) {
269
+ return "Invalid DateTime";
270
+ }
271
+ }
272
+ case Format2.TypeFormat.GeoPoint: {
273
+ if (value3 === null || value3 === void 0) {
274
+ return "";
275
+ }
276
+ if (Array.isArray(value3) && value3.length >= 2 && value3.every(Number.isFinite)) {
277
+ const { latitude, longitude } = GeoLocation2.fromGeoPoint(value3);
278
+ return `${latitude},${longitude}`;
279
+ }
280
+ return String(value3);
281
+ }
282
+ default: {
283
+ if (value3 === null || value3 === "undefined") {
284
+ return "";
285
+ }
286
+ return String(value3);
287
+ }
625
288
  }
626
289
  };
627
- var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange, readonly }) => {
628
- var _effect = _useSignals6();
629
- try {
630
- const { status, error } = getStatus();
631
- const checked = Boolean(getValue3());
632
- const { t } = useTranslation4(translationKey);
633
- return /* @__PURE__ */ React6.createElement(Input6.Root, {
634
- validationValence: status
635
- }, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
636
- error,
637
- label
638
- }), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, t(checked ? "boolean input true value" : "boolean input false value")) : /* @__PURE__ */ React6.createElement(Input6.Switch, {
639
- disabled: !!readonly,
640
- checked,
641
- onCheckedChange: (value2) => onValueChange(type, value2)
642
- }), inputOnly && /* @__PURE__ */ React6.createElement(Input6.DescriptionAndValidation, null, error));
643
- } finally {
644
- _effect.f();
290
+ var formatForEditing = ({ type, format, value: value3, locale = void 0 }) => {
291
+ const formatScalar = (type2) => {
292
+ switch (type2) {
293
+ case TypeEnum2.Boolean:
294
+ case TypeEnum2.Number:
295
+ case TypeEnum2.String:
296
+ case TypeEnum2.Ref:
297
+ return String(value3);
298
+ default:
299
+ return String(value3);
300
+ }
301
+ };
302
+ if (!format) {
303
+ return formatScalar(type);
645
304
  }
646
- };
647
- var SelectInput = ({ type, label, inputOnly, readonly, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
648
- var _effect = _useSignals6();
649
- try {
650
- const { status, error } = getStatus();
651
- const value2 = getValue3();
652
- const handleValueChange = useCallback3((value3) => onValueChange(type, value3), [
653
- type,
654
- onValueChange
655
- ]);
656
- return readonly && !value2 ? null : /* @__PURE__ */ React6.createElement(Input6.Root, {
657
- validationValence: status
658
- }, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
659
- error,
660
- label
661
- }), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value2)?.label ?? String(value2)) : /* @__PURE__ */ React6.createElement(Select.Root, {
662
- value: value2,
663
- onValueChange: handleValueChange
664
- }, /* @__PURE__ */ React6.createElement(Select.TriggerButton, {
665
- classNames: "is-full",
666
- disabled: !!readonly,
667
- placeholder
668
- }), /* @__PURE__ */ React6.createElement(Select.Portal, null, /* @__PURE__ */ React6.createElement(Select.Content, null, /* @__PURE__ */ React6.createElement(Select.Viewport, null, options?.map(({ value: value3, label: label2 }) => (
669
- // NOTE: Numeric values are converted to and from strings.
670
- /* @__PURE__ */ React6.createElement(Select.Option, {
671
- key: String(value3),
672
- value: String(value3)
673
- }, label2 ?? String(value3))
674
- ))), /* @__PURE__ */ React6.createElement(Select.Arrow, null)))), inputOnly && /* @__PURE__ */ React6.createElement(Input6.DescriptionAndValidation, null, error));
675
- } finally {
676
- _effect.f();
305
+ switch (format) {
306
+ case Format2.TypeFormat.Boolean:
307
+ case Format2.TypeFormat.Number:
308
+ case Format2.TypeFormat.String:
309
+ case Format2.TypeFormat.Ref: {
310
+ return formatScalar(type);
311
+ }
312
+ case Format2.TypeFormat.Percent: {
313
+ return String(value3 * 100);
314
+ }
315
+ case Format2.TypeFormat.Currency: {
316
+ return String(value3);
317
+ }
318
+ case Format2.TypeFormat.DateTime: {
319
+ const date = new Date(value3);
320
+ return date.toISOString();
321
+ }
322
+ case Format2.TypeFormat.Date: {
323
+ const date = new Date(value3);
324
+ return date.toISOString().split("T")[0];
325
+ }
326
+ case Format2.TypeFormat.Time: {
327
+ const date = new Date(value3);
328
+ return date.toISOString().split("T")[1].split(".")[0];
329
+ }
330
+ case Format2.TypeFormat.GeoPoint: {
331
+ if (value3 === null || value3 === void 0) {
332
+ return "";
333
+ }
334
+ if (Array.isArray(value3) && value3.length >= 2 && value3.every(Number.isFinite)) {
335
+ const { latitude, longitude } = GeoLocation2.fromGeoPoint(value3);
336
+ return `${latitude},${longitude}`;
337
+ }
338
+ return String(value3);
339
+ }
340
+ default: {
341
+ return String(value3);
342
+ }
677
343
  }
678
344
  };
679
- var MarkdownInput = ({ type, label, inputOnly, readonly, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
680
- var _effect = _useSignals6();
681
- try {
682
- const { status, error } = getStatus();
683
- const textareaRef = useRef2(null);
684
- const adjustHeight = useCallback3(() => {
685
- const textarea = textareaRef.current;
686
- if (textarea) {
687
- textarea.style.blockSize = "auto";
688
- textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
345
+
346
+ // src/util/properties.ts
347
+ import * as Option from "effect/Option";
348
+ import { Annotation } from "@dxos/echo";
349
+ import { getProperties } from "@dxos/effect";
350
+ var getFormProperties = (ast) => {
351
+ return getProperties(ast).filter((prop) => Annotation.FormInputAnnotation.getFromAst(prop.type).pipe(Option.getOrElse(() => true)));
352
+ };
353
+
354
+ // src/util/refs.ts
355
+ import { Ref } from "@dxos/echo";
356
+ import { ReferenceAnnotationId } from "@dxos/echo/internal";
357
+ import { findAnnotation, getArrayElementType, isArrayType } from "@dxos/effect";
358
+ var getRefProps = (ast) => {
359
+ if (isArrayType(ast)) {
360
+ const elementType = getArrayElementType(ast);
361
+ if (elementType) {
362
+ if (Ref.isRefType(elementType)) {
363
+ const typename = findAnnotation(elementType, ReferenceAnnotationId)?.typename;
364
+ return {
365
+ ast: elementType,
366
+ isArray: true,
367
+ typename
368
+ };
689
369
  }
690
- }, []);
691
- useEffect3(() => {
692
- adjustHeight();
693
- }, [
694
- adjustHeight
695
- ]);
696
- useEffect3(() => {
697
- adjustHeight();
698
- }, [
699
- getValue3(),
700
- adjustHeight
701
- ]);
702
- return /* @__PURE__ */ React6.createElement(Input6.Root, {
703
- validationValence: status
704
- }, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
705
- error,
706
- label
707
- }), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.TextArea, {
708
- ref: textareaRef,
709
- disabled: !!readonly,
710
- placeholder,
711
- value: getValue3() ?? "",
712
- classNames: "min-bs-auto max-bs-40 overflow-auto",
713
- onChange: (event) => onValueChange(type, event.target.value),
714
- onBlur,
715
- style: {
716
- resize: "none"
717
- },
718
- spellCheck: false
719
- }), inputOnly && /* @__PURE__ */ React6.createElement(Input6.Validation, null, error));
720
- } finally {
721
- _effect.f();
370
+ }
722
371
  }
372
+ if (Ref.isRefType(ast)) {
373
+ const typename = findAnnotation(ast, ReferenceAnnotationId)?.typename;
374
+ return {
375
+ ast,
376
+ isArray: false,
377
+ typename
378
+ };
379
+ }
380
+ return void 0;
723
381
  };
724
382
 
725
- // src/components/Form/Form.tsx
726
- import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
727
- import { useFocusFinders } from "@fluentui/react-tabster";
728
- import React13, { useCallback as useCallback11, useEffect as useEffect7, useRef as useRef3 } from "react";
729
- import { cardDialogOverflow, cardSpacing as cardSpacing2 } from "@dxos/react-ui-stack";
730
-
731
- // src/components/Form/FormActions.tsx
732
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
733
- import React8 from "react";
734
- import { IconButton as IconButton2, useTranslation as useTranslation5 } from "@dxos/react-ui";
735
- import { cardSpacing } from "@dxos/react-ui-stack";
736
- import { mx as mx4 } from "@dxos/react-ui-theme";
383
+ // src/components/Form/fields/ArrayField.tsx
384
+ import * as Option3 from "effect/Option";
385
+ import * as SchemaAST3 from "effect/SchemaAST";
386
+ import React5, { useCallback as useCallback3 } from "react";
387
+ import { findNode as findNode2, getArrayElementType as getArrayElementType2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2, isNestedType as isNestedType2 } from "@dxos/effect";
388
+ import { IconButton as IconButton2, useTranslation as useTranslation3 } from "@dxos/react-ui";
737
389
 
738
- // src/components/Form/FormContext.tsx
739
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
740
- import React7, { createContext, useCallback as useCallback7, useContext, useEffect as useEffect6, useMemo as useMemo3 } from "react";
741
- import { raise } from "@dxos/debug";
742
- import { getValue as getValue2 } from "@dxos/echo/internal";
743
- import { createJsonPath as createJsonPath2 } from "@dxos/effect";
390
+ // src/components/Form/Form.tsx
391
+ import { createContext } from "@radix-ui/react-context";
392
+ import * as Schema2 from "effect/Schema";
393
+ import * as SchemaAST2 from "effect/SchemaAST";
394
+ import React4, { useEffect as useEffect2, useMemo as useMemo4, useRef } from "react";
395
+ import { createJsonPath as createJsonPath3, getValue as getValue$2 } from "@dxos/effect";
396
+ import { IconButton, ScrollArea, useMergeRefs, useTranslation as useTranslation2 } from "@dxos/react-ui";
397
+ import { composable, composableProps, mx } from "@dxos/ui-theme";
744
398
 
745
- // src/hooks/useForm.ts
746
- import * as SchemaAST from "effect/SchemaAST";
747
- import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
748
- import { getValue, setValue } from "@dxos/echo/internal";
749
- import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
750
- import { invariant } from "@dxos/invariant";
399
+ // src/hooks/useFormHandler.ts
400
+ import { useControllableState } from "@radix-ui/react-use-controllable-state";
401
+ import { useCallback, useEffect, useMemo, useState } from "react";
402
+ import { createJsonPath, fromEffectValidationPath, getValue as getValue$ } from "@dxos/effect";
751
403
  import { log } from "@dxos/log";
404
+ import { useDefaultValue } from "@dxos/react-ui";
752
405
  import { validateSchema } from "@dxos/schema";
753
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
754
- var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
755
- invariant(SchemaAST.isTypeLiteral(schema.ast), void 0, {
756
- F: __dxlog_file,
757
- L: 96,
758
- S: void 0,
759
- A: [
760
- "SchemaAST.isTypeLiteral(schema.ast)",
761
- ""
762
- ]
406
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useFormHandler.ts";
407
+ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: defaultValuesProp, onValuesChanged, onValidate, onSave, onCancel, ...props }) => {
408
+ const [changed, setChanged] = useState({});
409
+ const [touched, setTouched] = useState({});
410
+ const [errors, setErrors] = useState({});
411
+ const [saving, setSaving] = useState(false);
412
+ const defaultValues = useDefaultValue(defaultValuesProp, () => ({}));
413
+ const [values$, setValues] = useControllableState({
414
+ prop: valuesProp,
415
+ defaultProp: defaultValues,
416
+ onChange: () => {
417
+ if (valuesProp !== void 0) {
418
+ setValues(valuesProp ?? defaultValues);
419
+ setChanged({});
420
+ setTouched({});
421
+ setErrors({});
422
+ setSaving(false);
423
+ }
424
+ }
763
425
  });
764
- const [values, setValues] = useState3(initialValues);
765
- useEffect4(() => {
766
- setValues(initialValues);
767
- }, [
768
- initialValues
769
- ]);
770
- const [touched, setTouched] = useState3(createKeySet(initialValues, false));
771
- const [changed, setChanged] = useState3(createKeySet(initialValues, false));
772
- const [errors, setErrors] = useState3({});
773
- const [saving, setSaving] = useState3(false);
774
- const validate = useCallback4((values2) => {
426
+ const values = values$;
427
+ const validate = useCallback((values2) => {
428
+ if (!schema) {
429
+ return false;
430
+ }
775
431
  let errors2 = validateSchema(schema, values2) ?? [];
432
+ log("validate", {
433
+ values: values2,
434
+ errors: errors2
435
+ }, {
436
+ F: __dxlog_file,
437
+ L: 155,
438
+ S: void 0,
439
+ C: (f, a) => f(...a)
440
+ });
776
441
  if (errors2.length === 0 && onValidate) {
777
442
  const validatedValues = values2;
778
443
  errors2 = onValidate(validatedValues) ?? [];
@@ -784,36 +449,38 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
784
449
  schema,
785
450
  onValidate
786
451
  ]);
787
- const [schemaDirty, setSchemaDirty] = useState3(false);
788
- useEffect4(() => setSchemaDirty(true), [
452
+ const [schemaChanged, setSchemaChanged] = useState(false);
453
+ useEffect(() => setSchemaChanged(true), [
789
454
  schema
790
455
  ]);
791
- useEffect4(() => {
792
- if (schemaDirty) {
456
+ useEffect(() => {
457
+ if (schemaChanged) {
793
458
  validate(values);
794
- setSchemaDirty(false);
459
+ setSchemaChanged(false);
795
460
  }
796
461
  }, [
462
+ validate,
797
463
  values,
798
- schemaDirty
464
+ schemaChanged
799
465
  ]);
800
- const formIsValid = useMemo2(() => {
466
+ const isValid = useMemo(() => {
801
467
  return Object.keys(errors).length === 0;
802
468
  }, [
803
469
  errors
804
470
  ]);
805
- const canSave = useMemo2(() => !saving && // Check if any error paths that are touched have errors.
471
+ const canSave = useMemo(() => !saving && // Check if any error paths that are touched have errors.
806
472
  !Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
807
473
  touched,
808
474
  errors,
809
475
  saving
810
476
  ]);
811
- const handleSave = useCallback4(async () => {
477
+ const handleSave = useCallback(async () => {
812
478
  if (validate(values)) {
813
479
  setSaving(true);
814
480
  try {
815
481
  await onSave?.(values, {
816
- changed
482
+ changed,
483
+ isValid
817
484
  });
818
485
  } finally {
819
486
  setSaving(false);
@@ -823,11 +490,17 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
823
490
  values,
824
491
  validate,
825
492
  onSave,
826
- changed
493
+ changed,
494
+ isValid
495
+ ]);
496
+ const handleCancel = useCallback(() => {
497
+ onCancel?.();
498
+ }, [
499
+ onCancel
827
500
  ]);
828
- const getStatus = useCallback4((path) => {
501
+ const getStatus = useCallback((path) => {
829
502
  const jsonPath = Array.isArray(path) ? createJsonPath(path) : path;
830
- const matchingError = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`));
503
+ const [_, error] = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`)) ?? [];
831
504
  const isTouched = touched[jsonPath];
832
505
  if (!isTouched) {
833
506
  return {
@@ -836,111 +509,138 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
836
509
  };
837
510
  }
838
511
  return {
839
- status: matchingError ? "error" : void 0,
840
- error: matchingError ? matchingError[1] : void 0
512
+ status: error ? "error" : void 0,
513
+ error: error ? error ?? void 0 : void 0
841
514
  };
842
515
  }, [
843
516
  errors,
844
517
  touched
845
518
  ]);
846
- const getFormValue = useCallback4((path) => {
847
- return getValue(values, createJsonPath(path));
519
+ const getValue = useCallback((path) => {
520
+ return getValue$(values, createJsonPath(path));
848
521
  }, [
849
522
  values
850
523
  ]);
851
- const onValueChange = useCallback4((path, type, value2) => {
524
+ const onValueChange = useCallback((path, type, value3) => {
525
+ log("onValueChange", {
526
+ path,
527
+ value: value3
528
+ }, {
529
+ F: __dxlog_file,
530
+ L: 254,
531
+ S: void 0,
532
+ C: (f, a) => f(...a)
533
+ });
852
534
  const jsonPath = createJsonPath(path);
853
- let parsedValue = value2;
535
+ const pathArray = path;
536
+ let parsedValue = value3;
854
537
  try {
855
- if (type === "number") {
856
- parsedValue = parseFloat(value2) || 0;
538
+ if (type._tag === "NumberKeyword") {
539
+ parsedValue = parseFloat(value3) || 0;
857
540
  }
858
541
  } catch (err) {
859
542
  log.catch(err, void 0, {
860
543
  F: __dxlog_file,
861
- L: 217,
544
+ L: 264,
862
545
  S: void 0,
863
546
  C: (f, a) => f(...a)
864
547
  });
865
548
  parsedValue = void 0;
866
549
  }
867
- const newValues = {
868
- ...setValue(values, jsonPath, parsedValue)
869
- };
870
- setValues(newValues);
550
+ const newValues = mergeAtPath(values, pathArray, parsedValue);
871
551
  const newChanged = {
872
- ...changed,
873
552
  [jsonPath]: true
874
553
  };
875
- setChanged(newChanged);
876
- onValuesChanged?.(newValues);
877
- const isValid = validate(newValues);
878
- if (isValid && onValid) {
879
- onValid(newValues, {
880
- changed: newChanged
881
- });
554
+ setChanged((prev) => ({
555
+ ...prev,
556
+ ...newChanged
557
+ }));
558
+ const isValid2 = validate(newValues);
559
+ onValuesChanged?.(newValues, {
560
+ isValid: isValid2,
561
+ changed: newChanged
562
+ });
563
+ if (valuesProp === void 0) {
564
+ setValues(newValues);
882
565
  }
883
566
  }, [
884
567
  values,
885
- onValuesChanged,
886
568
  validate,
887
- onValid,
888
- changed
569
+ onValuesChanged,
570
+ valuesProp
889
571
  ]);
890
- const onTouched = useCallback4((path) => {
572
+ const onBlur = useCallback(async (path) => {
891
573
  const jsonPath = createJsonPath(path);
892
574
  setTouched((touched2) => ({
893
575
  ...touched2,
894
576
  [jsonPath]: true
895
577
  }));
896
- validate(values);
578
+ const isValid2 = validate(values);
579
+ if (Object.keys(changed).length > 0 && isValid2 && autoSave) {
580
+ await onSave?.(values, {
581
+ changed,
582
+ isValid: isValid2
583
+ });
584
+ }
897
585
  }, [
898
586
  validate,
899
- values
587
+ values,
588
+ changed,
589
+ autoSave,
590
+ onSave
900
591
  ]);
901
- return useMemo2(() => ({
592
+ return useMemo(() => ({
902
593
  // State.
594
+ schema,
903
595
  values,
904
596
  errors,
905
597
  touched,
906
598
  changed,
599
+ isValid,
907
600
  canSave,
908
- formIsValid,
601
+ autoSave,
909
602
  // Actions.
910
- handleSave,
603
+ onSave: handleSave,
604
+ onCancel: handleCancel,
911
605
  // Field utils.
912
606
  getStatus,
913
- getValue: getFormValue,
607
+ getValue,
608
+ onBlur,
914
609
  onValueChange,
915
- onTouched
610
+ ...props
916
611
  }), [
612
+ schema,
917
613
  values,
918
614
  errors,
919
615
  touched,
920
616
  changed,
921
617
  canSave,
922
- formIsValid,
923
- handleSave,
618
+ isValid,
924
619
  getStatus,
925
- getFormValue,
620
+ getValue,
621
+ onBlur,
926
622
  onValueChange,
927
- onTouched
623
+ onSave,
624
+ onCancel
928
625
  ]);
929
626
  };
930
- var createKeySet = (obj, value2) => {
931
- invariant(obj, void 0, {
932
- F: __dxlog_file,
933
- L: 280,
934
- S: void 0,
935
- A: [
936
- "obj",
937
- ""
938
- ]
939
- });
940
- return Object.keys(obj).reduce((acc, key) => ({
941
- ...acc,
942
- [key]: value2
943
- }), {});
627
+ var mergeAtPath = (obj, path, value3) => {
628
+ if (path.length === 0) {
629
+ return value3;
630
+ }
631
+ const [head2, ...rest] = path;
632
+ const child = rest.length === 0 ? value3 : mergeAtPath(obj?.[head2], rest, value3);
633
+ if (Array.isArray(obj)) {
634
+ const copy = [
635
+ ...obj
636
+ ];
637
+ copy[head2] = child;
638
+ return copy;
639
+ }
640
+ return {
641
+ ...obj,
642
+ [head2]: child
643
+ };
944
644
  };
945
645
  var flatMap = (errors) => {
946
646
  return errors.reduce((result, { path, message }) => {
@@ -952,1661 +652,1918 @@ var flatMap = (errors) => {
952
652
  }, {});
953
653
  };
954
654
 
955
- // src/hooks/useRefQueryLookupHandler.ts
956
- import { useCallback as useCallback5 } from "react";
957
- import { Obj } from "@dxos/echo";
958
- import { getObjectDXN } from "@dxos/echo/internal";
959
- import { Filter } from "@dxos/react-client/echo";
960
- import { isNonNullable } from "@dxos/util";
961
- var useRefQueryLookupHandler = ({ space }) => {
962
- return useCallback5(async (typeInfo) => {
963
- if (!space) {
964
- return [];
965
- }
966
- const query = space.db.query(Filter.typename(typeInfo.typename));
967
- const { objects } = await query.run();
968
- return objects.map((object) => {
969
- const dxn = getObjectDXN(object);
970
- if (!dxn) {
971
- return void 0;
655
+ // src/hooks/useKeyHandler.tsx
656
+ import { useCallback as useCallback2, useLayoutEffect } from "react";
657
+ import { addEventListener } from "@dxos/async";
658
+ var useKeyHandler = (elRef, form) => {
659
+ const handleKeyDown = useCallback2((event) => {
660
+ switch (event.key) {
661
+ case "Enter": {
662
+ if (event.metaKey && form.canSave) {
663
+ form.onSave();
664
+ }
665
+ break;
972
666
  }
973
- const item = {
974
- dxn,
975
- label: Obj.getLabel(object) ?? object?.id ?? ""
976
- };
977
- return item;
978
- }).filter(isNonNullable);
667
+ }
979
668
  }, [
980
- space
669
+ form.isValid,
670
+ form.canSave,
671
+ form.onSave,
672
+ form.autoSave
981
673
  ]);
982
- };
983
-
984
- // src/hooks/useQueryRefOptions.ts
985
- import { useCallback as useCallback6, useEffect as useEffect5, useState as useState4 } from "react";
986
- import { log as log2 } from "@dxos/log";
987
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
988
- var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
989
- const [options, setOptions] = useState4([]);
990
- const [loading, setLoading] = useState4(false);
991
- const [state, setState] = useState4({});
992
- const update = useCallback6(() => setState({}), []);
993
- useEffect5(() => {
994
- if (!refTypeInfo || !onQueryRefOptions) {
674
+ useLayoutEffect(() => {
675
+ const el = elRef.current;
676
+ if (!el) {
995
677
  return;
996
678
  }
997
- const fetchOptions = async () => {
998
- setLoading(true);
999
- try {
1000
- const fetchedOptions = await onQueryRefOptions(refTypeInfo);
1001
- setOptions(fetchedOptions.map((option) => {
1002
- const dxn = option.dxn.toString();
1003
- return {
1004
- id: dxn,
1005
- label: option.label ?? dxn,
1006
- hue: "neutral"
1007
- };
1008
- }));
1009
- } catch (error) {
1010
- log2.error("Failed to fetch ref options:", error, {
1011
- F: __dxlog_file2,
1012
- L: 51,
1013
- S: void 0,
1014
- C: (f, a) => f(...a)
1015
- });
1016
- setOptions([]);
1017
- } finally {
1018
- setLoading(false);
1019
- }
1020
- };
1021
- void fetchOptions();
679
+ return addEventListener(el, "keydown", handleKeyDown);
1022
680
  }, [
1023
- refTypeInfo,
1024
- onQueryRefOptions,
1025
- state
681
+ elRef,
682
+ handleKeyDown
1026
683
  ]);
1027
- return {
1028
- options,
1029
- update,
1030
- loading
1031
- };
1032
684
  };
1033
685
 
1034
- // src/components/Form/FormContext.tsx
1035
- var FormContext = /* @__PURE__ */ createContext(void 0);
1036
- var useFormContext = () => {
1037
- return useContext(FormContext) ?? raise(new Error("Missing FormContext"));
1038
- };
1039
- var useFormValues = (path = []) => {
1040
- const { values: formValues } = useFormContext();
1041
- const jsonPath = createJsonPath2(path);
1042
- return getValue2(formValues, jsonPath);
1043
- };
1044
- var useInputProps = (path = []) => {
1045
- const { getStatus, getValue: getFormValue, onValueChange, onTouched } = useFormContext();
1046
- const stablePath = useMemo3(() => path, [
1047
- Array.isArray(path) ? path.join(".") : path
1048
- ]);
1049
- return useMemo3(() => ({
1050
- getStatus: () => getStatus(stablePath),
1051
- getValue: () => getFormValue(stablePath),
1052
- onValueChange: (type, value2) => onValueChange(stablePath, type, value2),
1053
- onBlur: () => onTouched(stablePath)
1054
- }), [
1055
- getStatus,
1056
- getFormValue,
1057
- onValueChange,
1058
- onTouched,
1059
- stablePath
1060
- ]);
1061
- };
1062
- var FormProvider = ({ children, formRef, autoSave, ...formOptions }) => {
1063
- var _effect = _useSignals7();
1064
- try {
1065
- const form = useForm(formOptions);
1066
- const handleKeyDown = useCallback7((event) => {
1067
- const keyIsEnter = event.key === "Enter";
1068
- const modifierUsed = event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
1069
- const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
1070
- const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
1071
- const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
1072
- const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
1073
- if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
1074
- if (!autoSave && form.canSave) {
1075
- form.handleSave();
1076
- }
1077
- if (autoSave && form.formIsValid) {
1078
- event.target.blur();
1079
- }
1080
- }
1081
- }, [
1082
- form.canSave,
1083
- form.formIsValid,
1084
- form.handleSave,
1085
- autoSave
1086
- ]);
1087
- useEffect6(() => {
1088
- if (!formRef?.current) {
1089
- return;
1090
- }
1091
- const formElement = formRef.current;
1092
- formElement.addEventListener("keydown", handleKeyDown);
1093
- return () => formElement.removeEventListener("keydown", handleKeyDown);
1094
- }, [
1095
- formRef,
1096
- form.canSave,
1097
- form.formIsValid,
1098
- form.handleSave,
1099
- autoSave
1100
- ]);
1101
- return /* @__PURE__ */ React7.createElement(FormContext.Provider, {
1102
- value: form
1103
- }, children);
1104
- } finally {
1105
- _effect.f();
1106
- }
686
+ // src/components/Form/FormFieldComponent.tsx
687
+ import React, { Component } from "react";
688
+ import { Icon, Input, Tooltip } from "@dxos/react-ui";
689
+ import { inputTextLabel } from "@dxos/ui-theme";
690
+ var FormFieldLabel = ({ label, error, readonly, asChild }) => {
691
+ const Label = readonly || asChild ? "span" : Input.Label;
692
+ return /* @__PURE__ */ React.createElement("div", {
693
+ role: "none",
694
+ className: "flex items-center justify-between"
695
+ }, /* @__PURE__ */ React.createElement(Label, {
696
+ className: inputTextLabel
697
+ }, label), error && /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
698
+ asChild: true,
699
+ content: error,
700
+ side: "bottom"
701
+ }, /* @__PURE__ */ React.createElement(Icon, {
702
+ icon: "ph--warning--regular",
703
+ size: 4,
704
+ classNames: "text-error-text"
705
+ })));
1107
706
  };
1108
-
1109
- // src/components/Form/FormActions.tsx
1110
- var FormActions = ({ readonly, onCancel, outerSpacing = true }) => {
1111
- var _effect = _useSignals8();
1112
- try {
1113
- const { t } = useTranslation5(translationKey);
1114
- const { canSave, handleSave } = useFormContext();
1115
- return /* @__PURE__ */ React8.createElement("div", {
1116
- role: "none",
1117
- className: mx4(outerSpacing === "scroll-fields" ? "pli-cardSpacingInline mbe-cardSpacingBlock" : outerSpacing ? cardSpacing : "mbs-cardSpacingBlock", "flex [&_button]:grow gap-1 first:mbs-0")
1118
- }, onCancel && !readonly && /* @__PURE__ */ React8.createElement(IconButton2, {
1119
- "data-testid": "cancel-button",
1120
- icon: "ph--x--regular",
1121
- label: t("cancel button"),
1122
- onClick: onCancel
1123
- }), handleSave && /* @__PURE__ */ React8.createElement(IconButton2, {
1124
- type: "submit",
1125
- "data-testid": "save-button",
1126
- disabled: !canSave,
1127
- icon: "ph--check--regular",
1128
- label: t("save button"),
1129
- onClick: handleSave
1130
- }));
1131
- } finally {
1132
- _effect.f();
707
+ FormFieldLabel.displayName = "Form.FieldLabel";
708
+ var FormFieldWrapper = (props) => {
709
+ const { children, readonly, layout, label, getStatus, getValue } = props;
710
+ const { status, error } = getStatus();
711
+ const value3 = getValue();
712
+ if (layout === "static" && value3 == null) {
713
+ return null;
1133
714
  }
715
+ const str = String(value3 ?? "");
716
+ return /* @__PURE__ */ React.createElement("div", {
717
+ role: "none",
718
+ className: "contents"
719
+ }, /* @__PURE__ */ React.createElement(Input.Root, {
720
+ validationValence: status
721
+ }, layout !== "inline" && /* @__PURE__ */ React.createElement(FormFieldLabel, {
722
+ error,
723
+ readonly,
724
+ label
725
+ }), layout === "static" ? /* @__PURE__ */ React.createElement("p", null, str) : children ? children({
726
+ value: value3
727
+ }) : null, layout === "full" && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Validation, null, error))));
1134
728
  };
1135
-
1136
- // src/components/Form/FormContent.tsx
1137
- import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
1138
- import * as Function2 from "effect/Function";
1139
- import * as Schema from "effect/Schema";
1140
- import * as SchemaAST4 from "effect/SchemaAST";
1141
- import * as StringEffect from "effect/String";
1142
- import React12, { Component, forwardRef as forwardRef2, useMemo as useMemo6 } from "react";
1143
- import { createJsonPath as createJsonPath3, findNode as findNode3, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
1144
- import { mx as mx6 } from "@dxos/react-ui-theme";
1145
- import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
1146
- import { isTruthy } from "@dxos/util";
1147
-
1148
- // src/util/field.ts
1149
- import { FormatEnum, GeoLocation as GeoLocation2, TypeEnum } from "@dxos/echo/internal";
1150
- var parseValue = ({ type, format, value: value2 }) => {
1151
- if (value2 === void 0 || value2 === null || value2 === "") {
1152
- return void 0;
729
+ var FormFieldErrorBoundary = class extends Component {
730
+ static getDerivedStateFromError(error) {
731
+ return {
732
+ error
733
+ };
1153
734
  }
1154
- const parseScalar = (type2) => {
1155
- switch (type2) {
1156
- case TypeEnum.Boolean: {
1157
- if (typeof value2 === "string") {
1158
- const lowercaseValue = value2.toLowerCase();
1159
- if (lowercaseValue === "0" || lowercaseValue === "false") {
1160
- return false;
1161
- } else if (lowercaseValue === "1" || lowercaseValue === "true") {
1162
- return true;
1163
- }
1164
- }
1165
- return Boolean(value2);
1166
- }
1167
- case TypeEnum.Number: {
1168
- const cleaned = typeof value2 === "string" ? value2.replace(/[^0-9.-]+/g, "") : value2;
1169
- const num = Number(cleaned);
1170
- return Number.isNaN(num) ? null : num;
1171
- }
1172
- case TypeEnum.String:
1173
- case TypeEnum.Ref:
1174
- return String(value2);
1175
- default: {
1176
- return value2;
1177
- }
1178
- }
735
+ state = {
736
+ error: void 0
1179
737
  };
1180
- if (!format) {
1181
- return parseScalar(type);
1182
- }
1183
- switch (format) {
1184
- case FormatEnum.Boolean:
1185
- return parseScalar(TypeEnum.Boolean);
1186
- case FormatEnum.Number:
1187
- case FormatEnum.Percent:
1188
- case FormatEnum.Currency:
1189
- return parseScalar(TypeEnum.Number);
1190
- case FormatEnum.String:
1191
- case FormatEnum.Markdown: {
1192
- return parseScalar(TypeEnum.String);
1193
- }
1194
- case FormatEnum.Ref:
1195
- throw new Error(`unexpected format: ${FormatEnum.Ref}`);
1196
- case FormatEnum.DateTime:
1197
- case FormatEnum.Date:
1198
- case FormatEnum.Time:
1199
- case FormatEnum.Timestamp: {
1200
- const date = new Date(value2);
1201
- return isNaN(date.getTime()) ? null : date;
1202
- }
1203
- case FormatEnum.GeoPoint: {
1204
- if (typeof value2 === "string") {
1205
- const cleaned = value2.replace(/[^0-9.,-]+/g, "");
1206
- const parts = cleaned.split(",");
1207
- if (parts.length === 2) {
1208
- const lat = parseFloat(parts[0]);
1209
- const long = parseFloat(parts[1]);
1210
- if (!isNaN(lat) && !isNaN(long)) {
1211
- return GeoLocation2.toGeoPoint({
1212
- latitude: lat,
1213
- longitude: long
1214
- });
1215
- }
1216
- }
1217
- }
1218
- return [
1219
- 0,
1220
- 0
1221
- ];
738
+ componentDidUpdate(prevProps) {
739
+ if (prevProps.path !== this.props.path) {
740
+ this.resetError();
1222
741
  }
1223
- default: {
1224
- return value2;
742
+ }
743
+ render() {
744
+ if (this.state.error) {
745
+ return /* @__PURE__ */ React.createElement("div", {
746
+ className: "flex gap-2 border border-rose-fill font-mono text-sm"
747
+ }, /* @__PURE__ */ React.createElement("span", {
748
+ className: "bg-rose-fill text-surface-text px-1 font-thin"
749
+ }, "ERROR"), String(this.props.path?.join(".")));
1225
750
  }
751
+ return this.props.children;
1226
752
  }
1227
- };
1228
- var cellClassesForFieldType = ({ type, format }) => {
1229
- switch (format || type) {
1230
- case FormatEnum.Markdown:
1231
- return void 0;
1232
- case FormatEnum.Time:
1233
- case FormatEnum.Timestamp:
1234
- case FormatEnum.DateTime:
1235
- case FormatEnum.Date:
1236
- case FormatEnum.Duration:
1237
- return [
1238
- "font-mono",
1239
- "text-right"
1240
- ];
1241
- case FormatEnum.Currency:
1242
- return [
1243
- "text-right"
1244
- ];
1245
- case FormatEnum.JSON:
1246
- case FormatEnum.DID:
1247
- return [
1248
- "font-mono"
1249
- ];
1250
- case TypeEnum.Number:
1251
- case TypeEnum.Boolean:
1252
- return [
1253
- "text-right",
1254
- "font-mono"
1255
- ];
1256
- case TypeEnum.String:
1257
- return void 0;
1258
- case TypeEnum.Ref:
1259
- return void 0;
1260
- default:
1261
- return void 0;
753
+ resetError() {
754
+ this.setState({
755
+ error: void 0
756
+ });
1262
757
  }
1263
758
  };
1264
- var pathNotUniqueError = (path) => ({
1265
- path: "path",
1266
- message: `'${path}' is already present`
1267
- });
1268
759
 
1269
- // src/util/formatting.ts
1270
- import { format as formatDate } from "date-fns/format";
1271
- import { FormatEnum as FormatEnum2, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo/internal";
1272
- var formatForDisplay = ({ type, format, value: value2, locale = void 0 }) => {
1273
- const formatScalar = (type2) => {
1274
- switch (type2) {
1275
- case TypeEnum2.Boolean:
1276
- return value2.toLocaleString().toUpperCase();
1277
- case TypeEnum2.Number:
1278
- return value2.toLocaleString(locale);
1279
- case TypeEnum2.String:
1280
- case TypeEnum2.Ref:
1281
- return String(value2);
1282
- default: {
1283
- return String(value2);
1284
- }
1285
- }
760
+ // src/components/Form/FormFieldSet.tsx
761
+ import React3, { useMemo as useMemo3 } from "react";
762
+
763
+ // src/components/Form/FormField.tsx
764
+ import * as Match from "effect/Match";
765
+ import * as Option2 from "effect/Option";
766
+ import * as Schema from "effect/Schema";
767
+ import * as SchemaAST from "effect/SchemaAST";
768
+ import * as String2 from "effect/String";
769
+ import React2, { useMemo as useMemo2 } from "react";
770
+ import { Format as Format3 } from "@dxos/echo";
771
+ import { createJsonPath as createJsonPath2, findNode, getAnnotation, getDiscriminatedType, isArrayType as isArrayType2, isDiscriminatedUnion, isLiteralUnion, isNestedType } from "@dxos/effect";
772
+ import { useTranslation } from "@dxos/react-ui";
773
+ var FormField = (props) => {
774
+ const {
775
+ type,
776
+ name,
777
+ path,
778
+ projection,
779
+ fieldMap,
780
+ fieldProvider,
781
+ readonly,
782
+ layout,
783
+ // RefFieldProps
784
+ createTypename,
785
+ createOptionLabel,
786
+ createOptionIcon,
787
+ createInitialValuePath,
788
+ createFieldMap,
789
+ db,
790
+ schemaHook,
791
+ getOptions: getRefOptions,
792
+ onCreate
793
+ } = props;
794
+ const { t } = useTranslation(translationKey);
795
+ const title = getAnnotation(SchemaAST.TitleAnnotationId)(type);
796
+ const description = getAnnotation(SchemaAST.DescriptionAnnotationId)(type);
797
+ const examples = getAnnotation(SchemaAST.ExamplesAnnotationId)(type);
798
+ const label = useMemo2(() => title ?? String2.capitalize(name), [
799
+ title,
800
+ name
801
+ ]);
802
+ const placeholder = useMemo2(() => examples?.length ? `${t("example.placeholder")}: ${examples[0]}` : description ?? label, [
803
+ examples,
804
+ description,
805
+ label
806
+ ]);
807
+ const fieldState = useFormFieldState(FormField.displayName, path);
808
+ const fieldProps = {
809
+ type,
810
+ format: Format3.FormatAnnotation.getFromAst(type).pipe((annotation) => Option2.getOrUndefined(annotation)),
811
+ readonly,
812
+ label,
813
+ placeholder,
814
+ layout,
815
+ ...fieldState
1286
816
  };
1287
- if (!format) {
1288
- return formatScalar(type);
817
+ const jsonPath = createJsonPath2(path ?? []);
818
+ const CustomField = fieldMap?.[jsonPath];
819
+ if (CustomField) {
820
+ return /* @__PURE__ */ React2.createElement(CustomField, fieldProps);
1289
821
  }
1290
- switch (format) {
1291
- case FormatEnum2.Boolean: {
1292
- return formatScalar(TypeEnum2.Boolean);
1293
- }
1294
- case FormatEnum2.Number: {
1295
- return formatScalar(TypeEnum2.Number);
1296
- }
1297
- case FormatEnum2.String:
1298
- case FormatEnum2.Ref: {
1299
- return formatScalar(TypeEnum2.String);
1300
- }
1301
- case FormatEnum2.Percent: {
1302
- return `${value2 * 100}%`;
1303
- }
1304
- case FormatEnum2.Currency: {
1305
- return value2.toLocaleString(locale, {
1306
- style: "currency",
1307
- currency: "USD",
1308
- minimumFractionDigits: 2,
1309
- maximumFractionDigits: 2
822
+ const component = fieldProvider?.({
823
+ schema: Schema.make(type),
824
+ prop: name,
825
+ fieldProps
826
+ });
827
+ if (component) {
828
+ return component;
829
+ }
830
+ if (isArrayType2(type)) {
831
+ return /* @__PURE__ */ React2.createElement(ArrayField, {
832
+ fieldProps: fieldState,
833
+ label,
834
+ ...props
835
+ });
836
+ }
837
+ const Field = getFormField(fieldProps);
838
+ if (Field) {
839
+ return /* @__PURE__ */ React2.createElement(Field, fieldProps);
840
+ }
841
+ const options = getOptions(type);
842
+ if (options) {
843
+ const fieldProjections = projection?.getFieldProjections();
844
+ const fieldProjection = fieldProjections?.find((fp) => fp.field.path === name);
845
+ const selectOptions = fieldProjection?.props.options;
846
+ return /* @__PURE__ */ React2.createElement(SelectField, {
847
+ ...fieldProps,
848
+ options: options.map((option) => {
849
+ const selectOption = selectOptions?.find((so) => so.id === globalThis.String(option));
850
+ return {
851
+ value: option,
852
+ label: selectOption?.title ?? option.toString()
853
+ };
854
+ })
855
+ });
856
+ }
857
+ const refProps = getRefProps(type);
858
+ if (refProps) {
859
+ const isCreateTarget = !createTypename || refProps.typename === createTypename;
860
+ return /* @__PURE__ */ React2.createElement(RefField, {
861
+ ...fieldProps,
862
+ ...refProps,
863
+ createOptionLabel: isCreateTarget ? createOptionLabel : void 0,
864
+ createOptionIcon: isCreateTarget ? createOptionIcon : void 0,
865
+ createInitialValuePath: isCreateTarget ? createInitialValuePath : void 0,
866
+ createFieldMap: isCreateTarget ? createFieldMap : void 0,
867
+ db,
868
+ schemaHook,
869
+ getOptions: getRefOptions,
870
+ onCreate
871
+ });
872
+ }
873
+ if (isNestedType(type)) {
874
+ const baseNode = findNode(type, isDiscriminatedUnion);
875
+ const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST.isTypeLiteral);
876
+ if (typeLiteral) {
877
+ const schema = Schema.make(typeLiteral);
878
+ return /* @__PURE__ */ React2.createElement(FormFieldSet, {
879
+ schema,
880
+ path,
881
+ readonly,
882
+ layout,
883
+ label,
884
+ projection,
885
+ fieldMap,
886
+ fieldProvider,
887
+ createOptionLabel,
888
+ createOptionIcon,
889
+ createInitialValuePath,
890
+ db,
891
+ schemaHook,
892
+ getOptions: getRefOptions,
893
+ onCreate
1310
894
  });
1311
895
  }
1312
- case FormatEnum2.Date: {
1313
- try {
1314
- return formatDate(new Date(value2), "yyyy-MM-dd");
1315
- } catch (error) {
1316
- return "Invalid Date";
1317
- }
1318
- }
1319
- case FormatEnum2.Time: {
1320
- try {
1321
- return formatDate(new Date(value2), "HH:mm:ss");
1322
- } catch (error) {
1323
- return "Invalid Time";
1324
- }
1325
- }
1326
- case FormatEnum2.DateTime: {
1327
- try {
1328
- return formatDate(new Date(value2), "yyyy-MM-dd HH:mm:ss");
1329
- } catch (error) {
1330
- return "Invalid DateTime";
1331
- }
896
+ }
897
+ return null;
898
+ };
899
+ FormField.displayName = "Form.FormField";
900
+ var getFormField = ({ type, format }) => {
901
+ const formatField = Match.value(format).pipe(Match.withReturnType(), Match.when(Format3.TypeFormat.GeoPoint, () => GeoPointField), Match.when(Format3.TypeFormat.Markdown, () => MarkdownField), Match.when(Format3.TypeFormat.Text, () => TextAreaField), Match.orElse(() => void 0));
902
+ if (formatField) {
903
+ return formatField;
904
+ }
905
+ switch (type._tag) {
906
+ // TODO(wittjosiah): Schema.Any is currently used to represent template inputs.
907
+ case "AnyKeyword":
908
+ case "StringKeyword":
909
+ return TextField;
910
+ case "NumberKeyword":
911
+ return NumberField;
912
+ case "BooleanKeyword":
913
+ return BooleanField;
914
+ }
915
+ };
916
+ var getOptions = (ast) => {
917
+ if (isLiteralUnion(ast)) {
918
+ return ast.types.map((type) => type.literal).filter((v) => v !== null);
919
+ }
920
+ return Format3.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option2.getOrUndefined(annotation));
921
+ };
922
+
923
+ // src/components/Form/FormFieldSet.tsx
924
+ var FORM_FIELDSET_NAME = "Form.FieldSet";
925
+ var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection, layout, ...props }) => {
926
+ const values = useFormValues(FORM_FIELDSET_NAME, path);
927
+ const properties = useMemo3(() => {
928
+ if (!schema) {
929
+ return [];
1332
930
  }
1333
- case FormatEnum2.GeoPoint: {
1334
- if (value2 === null || value2 === void 0) {
1335
- return "";
1336
- }
1337
- if (Array.isArray(value2) && value2.length >= 2 && value2.every(Number.isFinite)) {
1338
- const { latitude, longitude } = GeoLocation3.fromGeoPoint(value2);
1339
- return `${latitude},${longitude}`;
931
+ const schemaProps = getFormProperties(schema.ast);
932
+ const filteredProps = exclude ? exclude(schemaProps) : schemaProps;
933
+ if (projection) {
934
+ const fieldProjections = projection.getFieldProjections();
935
+ const hiddenProperties = new Set(projection.getHiddenProperties());
936
+ const visibleProps = filteredProps.filter((prop) => !hiddenProperties.has(prop.name.toString()));
937
+ const orderedProps = [];
938
+ for (const fieldProjection of fieldProjections) {
939
+ const fieldPath = String(fieldProjection.field.path);
940
+ const prop = visibleProps.find((p) => p.name === fieldPath);
941
+ if (prop) {
942
+ orderedProps.push(prop);
943
+ }
1340
944
  }
1341
- return String(value2);
945
+ const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
946
+ const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
947
+ orderedProps.push(...remainingProps);
948
+ return orderedProps;
1342
949
  }
1343
- default: {
1344
- if (value2 === null || value2 === "undefined") {
1345
- return "";
1346
- }
1347
- return String(value2);
950
+ return sort ? [
951
+ ...filteredProps
952
+ ].sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString())) : filteredProps;
953
+ }, [
954
+ schema,
955
+ values,
956
+ exclude,
957
+ sort,
958
+ projection
959
+ ]);
960
+ if ((readonly || layout === "static") && values == null) {
961
+ return null;
962
+ }
963
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, layout !== "inline" && label && /* @__PURE__ */ React3.createElement(FormFieldLabel, {
964
+ label,
965
+ asChild: true
966
+ }), properties.map((property) => {
967
+ const name = property.name.toString();
968
+ return /* @__PURE__ */ React3.createElement(FormFieldErrorBoundary, {
969
+ key: name,
970
+ path: [
971
+ ...path ?? [],
972
+ name
973
+ ]
974
+ }, /* @__PURE__ */ React3.createElement(FormField, {
975
+ type: property.type,
976
+ name,
977
+ path: [
978
+ ...path ?? [],
979
+ name
980
+ ],
981
+ readonly,
982
+ layout,
983
+ projection,
984
+ ...props
985
+ }));
986
+ }));
987
+ };
988
+ FormFieldSet.displayName = FORM_FIELDSET_NAME;
989
+
990
+ // src/components/Form/Form.tsx
991
+ var omitId = (schema) => schema.pipe(Schema2.omit("id"));
992
+ var [FormContextProvider, useFormContext] = createContext("Form");
993
+ var useFormValues = (componentName, path, defaultValue) => {
994
+ const stablePath = useMemo4(() => path ?? [], [
995
+ path ? path.join(".") : void 0
996
+ ]);
997
+ const jsonPath = createJsonPath3(stablePath);
998
+ const { form: { values, onValueChange } } = useFormContext(componentName);
999
+ const value3 = getValue$2(values, jsonPath);
1000
+ const lastAppliedPathRef = useRef(null);
1001
+ useEffect2(() => {
1002
+ if (value3 == null && defaultValue && lastAppliedPathRef.current !== jsonPath) {
1003
+ lastAppliedPathRef.current = jsonPath;
1004
+ onValueChange(stablePath, SchemaAST2.stringKeyword, defaultValue());
1348
1005
  }
1006
+ }, [
1007
+ value3,
1008
+ defaultValue,
1009
+ onValueChange,
1010
+ stablePath,
1011
+ jsonPath
1012
+ ]);
1013
+ return value3;
1014
+ };
1015
+ var useFormFieldState = (componentName, path = []) => {
1016
+ const stablePath = useMemo4(() => path, [
1017
+ Array.isArray(path) ? path.join(".") : path
1018
+ ]);
1019
+ const { form: { getStatus, getValue, onBlur, onValueChange } } = useFormContext(componentName);
1020
+ return useMemo4(() => ({
1021
+ getStatus: () => getStatus(stablePath),
1022
+ getValue: () => getValue(stablePath),
1023
+ onBlur: () => onBlur(stablePath),
1024
+ onValueChange: (ast, value3) => onValueChange(stablePath, ast, value3)
1025
+ }), [
1026
+ getStatus,
1027
+ getValue,
1028
+ onBlur,
1029
+ onValueChange,
1030
+ stablePath
1031
+ ]);
1032
+ };
1033
+ var FormRoot = ({ children, schema, values, onSave, onCancel, ...props }) => {
1034
+ const form = useFormHandler({
1035
+ schema,
1036
+ values,
1037
+ onSave,
1038
+ onCancel,
1039
+ ...props
1040
+ });
1041
+ return /* @__PURE__ */ React4.createElement(FormContextProvider, {
1042
+ form,
1043
+ ...props
1044
+ }, children);
1045
+ };
1046
+ FormRoot.displayName = "Form.Root";
1047
+ var FORM_VIEWPORT_NAME = "Form.Viewport";
1048
+ var FormViewport = composable(({ children, ...props }, forwardedRef) => {
1049
+ return /* @__PURE__ */ React4.createElement(ScrollArea.Root, {
1050
+ ...composableProps(props),
1051
+ orientation: "vertical",
1052
+ centered: true,
1053
+ padding: true,
1054
+ thin: true,
1055
+ ref: forwardedRef
1056
+ }, /* @__PURE__ */ React4.createElement(ScrollArea.Viewport, null, children));
1057
+ });
1058
+ FormViewport.displayName = FORM_VIEWPORT_NAME;
1059
+ var FORM_CONTENT_NAME = "Form.Content";
1060
+ var FormContent = composable(({ children, ...props }, forwardedRef) => {
1061
+ const { form, testId } = useFormContext(FORM_CONTENT_NAME);
1062
+ const localRef = useRef(null);
1063
+ const mergedRef = useMergeRefs([
1064
+ forwardedRef,
1065
+ localRef
1066
+ ]);
1067
+ useKeyHandler(localRef, form);
1068
+ return /* @__PURE__ */ React4.createElement("div", {
1069
+ ...composableProps(props, {
1070
+ role: "form",
1071
+ classNames: "flex flex-col w-full pb-form-gap"
1072
+ }),
1073
+ "data-testid": testId,
1074
+ ref: mergedRef
1075
+ }, children);
1076
+ });
1077
+ FormContent.displayName = FORM_CONTENT_NAME;
1078
+ var FORM_FIELDSET_NAME2 = "Form.FieldSet";
1079
+ var FormFieldSet2 = (props) => {
1080
+ const { form, ...contextProps } = useFormContext(FORM_FIELDSET_NAME2);
1081
+ return /* @__PURE__ */ React4.createElement(FormFieldSet, {
1082
+ schema: form.schema,
1083
+ ...contextProps,
1084
+ ...props
1085
+ });
1086
+ };
1087
+ FormFieldSet2.displayName = FORM_FIELDSET_NAME2;
1088
+ var FORM_ACTIONS_NAME = "Form.Actions";
1089
+ var FormActions = ({ classNames }) => {
1090
+ const { t } = useTranslation2(translationKey);
1091
+ const { form: { canSave, onSave, onCancel }, readonly, layout } = useFormContext(FORM_ACTIONS_NAME);
1092
+ if (readonly || layout === "static") {
1093
+ return null;
1349
1094
  }
1095
+ return /* @__PURE__ */ React4.createElement("div", {
1096
+ role: "none",
1097
+ className: mx("grid grid-flow-col gap-form-gap auto-cols-fr py-form-padding", classNames)
1098
+ }, onCancel && /* @__PURE__ */ React4.createElement(IconButton, {
1099
+ icon: "ph--x--regular",
1100
+ iconEnd: true,
1101
+ label: t("cancel-button.label"),
1102
+ onClick: onCancel,
1103
+ "data-testid": "cancel-button"
1104
+ }), onSave && /* @__PURE__ */ React4.createElement(IconButton, {
1105
+ type: "submit",
1106
+ variant: "primary",
1107
+ disabled: !canSave,
1108
+ icon: "ph--check--regular",
1109
+ iconEnd: true,
1110
+ label: t("save-button.label"),
1111
+ onClick: onSave,
1112
+ "data-testid": "save-button"
1113
+ }));
1350
1114
  };
1351
- var formatForEditing = ({ type, format, value: value2, locale = void 0 }) => {
1352
- const formatScalar = (type2) => {
1353
- switch (type2) {
1354
- case TypeEnum2.Boolean:
1355
- case TypeEnum2.Number:
1356
- case TypeEnum2.String:
1357
- case TypeEnum2.Ref:
1358
- return String(value2);
1359
- default:
1360
- return String(value2);
1115
+ FormActions.displayName = FORM_ACTIONS_NAME;
1116
+ var FORM_SUBMIT_NAME = "Form.Submit";
1117
+ var FormSubmit = ({ classNames, label, icon, disabled }) => {
1118
+ const { t } = useTranslation2(translationKey);
1119
+ const { form: { canSave, onSave }, readonly, layout } = useFormContext(FORM_SUBMIT_NAME);
1120
+ if (readonly || layout === "static") {
1121
+ return null;
1122
+ }
1123
+ return /* @__PURE__ */ React4.createElement("div", {
1124
+ role: "none",
1125
+ className: mx("flex w-full pt-form-padding", classNames)
1126
+ }, /* @__PURE__ */ React4.createElement(IconButton, {
1127
+ classNames: "w-full",
1128
+ type: "submit",
1129
+ variant: "primary",
1130
+ disabled: disabled ?? !canSave,
1131
+ icon: icon ?? "ph--check--regular",
1132
+ label: label ?? t("save-button.label"),
1133
+ onClick: onSave,
1134
+ "data-testid": "save-button"
1135
+ }));
1136
+ };
1137
+ FormSubmit.displayName = FORM_SUBMIT_NAME;
1138
+ var Form = {
1139
+ Root: FormRoot,
1140
+ Viewport: FormViewport,
1141
+ Content: FormContent,
1142
+ FieldSet: FormFieldSet2,
1143
+ Label: FormFieldLabel,
1144
+ Actions: FormActions,
1145
+ Submit: FormSubmit
1146
+ };
1147
+
1148
+ // src/components/Form/fields/ArrayField.tsx
1149
+ var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps, ...props }) => {
1150
+ const { t } = useTranslation3(translationKey);
1151
+ const elementType = getArrayElementType2(type);
1152
+ const { onValueChange } = inputProps;
1153
+ const values = useFormValues(ArrayField.displayName, path, () => []);
1154
+ const getDefaultObjectValue = (typeNode) => {
1155
+ const baseNode = findNode2(typeNode, isDiscriminatedUnion2);
1156
+ const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
1157
+ if (!typeLiteral) {
1158
+ return {};
1361
1159
  }
1160
+ return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
1161
+ const defaultValue = SchemaAST3.getDefaultAnnotation(prop.type).pipe((annotation) => Option3.getOrUndefined(annotation));
1162
+ return [
1163
+ prop.name,
1164
+ defaultValue
1165
+ ];
1166
+ }));
1362
1167
  };
1363
- if (!format) {
1364
- return formatScalar(type);
1168
+ const handleAdd = useCallback3(() => {
1169
+ const defaultValue = isNestedType2(type) && elementType ? getDefaultObjectValue(elementType) : getDefaultValue(elementType);
1170
+ values && onValueChange(type, [
1171
+ ...values,
1172
+ defaultValue
1173
+ ]);
1174
+ }, [
1175
+ onValueChange,
1176
+ type,
1177
+ elementType,
1178
+ values
1179
+ ]);
1180
+ const handleDelete = useCallback3((idx) => {
1181
+ onValueChange(type, values?.filter((_, i) => i !== idx));
1182
+ }, [
1183
+ onValueChange,
1184
+ type,
1185
+ values
1186
+ ]);
1187
+ if (!elementType || (readonly || layout === "static") && values && values.length < 1) {
1188
+ return null;
1365
1189
  }
1366
- switch (format) {
1367
- case FormatEnum2.Boolean:
1368
- case FormatEnum2.Number:
1369
- case FormatEnum2.String:
1370
- case FormatEnum2.Ref: {
1371
- return formatScalar(type);
1372
- }
1373
- case FormatEnum2.Percent: {
1374
- return String(value2 * 100);
1375
- }
1376
- case FormatEnum2.Currency: {
1377
- return String(value2);
1378
- }
1379
- case FormatEnum2.DateTime: {
1380
- const date = new Date(value2);
1381
- return date.toISOString();
1190
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, (layout !== "static" || values && values.length > 0) && /* @__PURE__ */ React5.createElement(FormFieldLabel, {
1191
+ readonly,
1192
+ label,
1193
+ asChild: true
1194
+ }), /* @__PURE__ */ React5.createElement("div", {
1195
+ role: "none",
1196
+ className: "flex flex-col gap-form-gap"
1197
+ }, values?.map((_, index) => {
1198
+ return /* @__PURE__ */ React5.createElement("div", {
1199
+ role: "none",
1200
+ key: index,
1201
+ className: "flex gap-form-gap last:mb-form-gap"
1202
+ }, /* @__PURE__ */ React5.createElement(FormField, {
1203
+ autoFocus: index === values.length - 1,
1204
+ type: elementType,
1205
+ path: [
1206
+ ...path ?? [],
1207
+ index
1208
+ ],
1209
+ readonly: readonly || layout === "static",
1210
+ layout: "inline",
1211
+ ...props
1212
+ }), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement("div", {
1213
+ role: "none",
1214
+ className: "flex flex-col h-full justify-end"
1215
+ }, /* @__PURE__ */ React5.createElement("div", {
1216
+ role: "none",
1217
+ className: "flex items-center h-[2rem]"
1218
+ }, /* @__PURE__ */ React5.createElement(IconButton2, {
1219
+ icon: "ph--x--regular",
1220
+ iconOnly: true,
1221
+ label: t("remove.button"),
1222
+ onClick: () => handleDelete(index),
1223
+ classNames: "self-center"
1224
+ }))));
1225
+ })), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement(IconButton2, {
1226
+ classNames: "flex w-full",
1227
+ icon: "ph--plus--regular",
1228
+ label: t("add-field.button"),
1229
+ onClick: handleAdd
1230
+ }));
1231
+ };
1232
+ ArrayField.displayName = "Form.ArrayField";
1233
+ var getDefaultValue = (ast) => {
1234
+ switch (ast?._tag) {
1235
+ case "StringKeyword": {
1236
+ return "";
1382
1237
  }
1383
- case FormatEnum2.Date: {
1384
- const date = new Date(value2);
1385
- return date.toISOString().split("T")[0];
1238
+ case "NumberKeyword": {
1239
+ return 0;
1386
1240
  }
1387
- case FormatEnum2.Time: {
1388
- const date = new Date(value2);
1389
- return date.toISOString().split("T")[1].split(".")[0];
1241
+ case "BooleanKeyword": {
1242
+ return false;
1390
1243
  }
1391
- case FormatEnum2.GeoPoint: {
1392
- if (value2 === null || value2 === void 0) {
1393
- return "";
1394
- }
1395
- if (Array.isArray(value2) && value2.length >= 2 && value2.every(Number.isFinite)) {
1396
- const { latitude, longitude } = GeoLocation3.fromGeoPoint(value2);
1397
- return `${latitude},${longitude}`;
1398
- }
1399
- return String(value2);
1244
+ case "Suspend": {
1245
+ return getDefaultValue(ast.f());
1400
1246
  }
1401
1247
  default: {
1402
- return String(value2);
1248
+ if (ast && isNestedType2(ast)) {
1249
+ return {};
1250
+ } else {
1251
+ throw new Error(`Unsupported type: ${ast?._tag}`);
1252
+ }
1403
1253
  }
1404
1254
  }
1405
1255
  };
1406
1256
 
1407
- // src/util/refs.ts
1408
- import { FormatEnum as FormatEnum3, ReferenceAnnotationId } from "@dxos/echo/internal";
1409
- import { findAnnotation } from "@dxos/effect";
1410
-
1411
- // src/util/schema.ts
1412
- import * as SchemaAST2 from "effect/SchemaAST";
1413
- import { findNode } from "@dxos/effect";
1414
- var findArrayElementType = (ast) => {
1415
- const tupleType = findNode(ast, SchemaAST2.isTupleType);
1416
- return tupleType?.rest[0]?.type;
1257
+ // src/components/Form/fields/BooleanField.tsx
1258
+ import React6, { useCallback as useCallback4 } from "react";
1259
+ import { Input as Input2 } from "@dxos/react-ui";
1260
+ var BooleanField = ({ type, readonly, onValueChange, ...props }) => {
1261
+ const handleChange = useCallback4((value3) => onValueChange?.(type, value3), [
1262
+ type,
1263
+ onValueChange
1264
+ ]);
1265
+ return /* @__PURE__ */ React6.createElement(FormFieldWrapper, {
1266
+ readonly,
1267
+ ...props
1268
+ }, ({ value: value3 }) => /* @__PURE__ */ React6.createElement(Input2.Switch, {
1269
+ disabled: !!readonly,
1270
+ checked: value3,
1271
+ onCheckedChange: handleChange
1272
+ }));
1417
1273
  };
1418
1274
 
1419
- // src/util/refs.ts
1420
- var getRefProps = (property) => {
1421
- const { ast, format, array } = property;
1422
- if (array) {
1423
- const elementType = findArrayElementType(ast);
1424
- if (elementType) {
1425
- const annotation = findAnnotation(elementType, ReferenceAnnotationId);
1426
- if (annotation) {
1427
- return {
1428
- ast: elementType,
1429
- isArray: true
1275
+ // src/components/Form/fields/GeoPointField.tsx
1276
+ import React7, { useCallback as useCallback5, useEffect as useEffect3, useMemo as useMemo5, useState as useState2 } from "react";
1277
+ import { GeoLocation as GeoLocation3 } from "@dxos/echo/internal";
1278
+ import { Input as Input3, useTranslation as useTranslation4 } from "@dxos/react-ui";
1279
+ import { safeParseFloat } from "@dxos/util";
1280
+ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
1281
+ const { t } = useTranslation4(translationKey);
1282
+ const { status, error } = getStatus();
1283
+ const geoPoint = useMemo5(() => getValue() ?? [
1284
+ 0,
1285
+ 0
1286
+ ], [
1287
+ getValue
1288
+ ]);
1289
+ const value3 = useMemo5(() => GeoLocation3.fromGeoPoint(geoPoint), [
1290
+ geoPoint
1291
+ ]);
1292
+ const [longitudeText, setLongitudeText] = useState2(value3.longitude?.toString());
1293
+ const [latitudeText, setLatitudeText] = useState2(value3.latitude?.toString());
1294
+ useEffect3(() => {
1295
+ const location = GeoLocation3.fromGeoPoint(geoPoint);
1296
+ setLongitudeText(location.longitude?.toString());
1297
+ setLatitudeText(location.latitude?.toString());
1298
+ }, [
1299
+ geoPoint
1300
+ ]);
1301
+ const handleChange = useCallback5((coordinateType, setText) => (event) => {
1302
+ const inputText = event.target.value;
1303
+ setText(inputText);
1304
+ if (inputText !== "" && inputText !== "-") {
1305
+ const coord = safeParseFloat(inputText);
1306
+ if (coord !== void 0 && !isNaN(coord)) {
1307
+ const currentLocation = GeoLocation3.fromGeoPoint(getValue() ?? [
1308
+ 0,
1309
+ 0
1310
+ ]);
1311
+ const newLocation = {
1312
+ ...currentLocation,
1313
+ [coordinateType]: coord
1430
1314
  };
1315
+ const newValue = GeoLocation3.toGeoPoint(newLocation);
1316
+ onValueChange(type, newValue);
1431
1317
  }
1432
1318
  }
1319
+ }, [
1320
+ type,
1321
+ getValue,
1322
+ onValueChange
1323
+ ]);
1324
+ if ((readonly || layout === "static") && !value3?.latitude && !value3?.longitude) {
1325
+ return null;
1433
1326
  }
1434
- if (format === FormatEnum3.Ref) {
1435
- return {
1436
- ast,
1437
- isArray: false
1438
- };
1439
- }
1440
- return void 0;
1327
+ return /* @__PURE__ */ React7.createElement(Input3.Root, {
1328
+ validationValence: status
1329
+ }, layout !== "inline" && /* @__PURE__ */ React7.createElement(FormFieldLabel, {
1330
+ error,
1331
+ readonly,
1332
+ label,
1333
+ asChild: true
1334
+ }), layout === "static" ? /* @__PURE__ */ React7.createElement(LatLng, value3) : /* @__PURE__ */ React7.createElement("div", {
1335
+ role: "none",
1336
+ className: "grid grid-cols-2 gap-form-gap"
1337
+ }, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("latitude.label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
1338
+ type: "number",
1339
+ step: "0.00001",
1340
+ min: "-90",
1341
+ max: "90",
1342
+ disabled: !!readonly,
1343
+ placeholder: t("latitude.placeholder"),
1344
+ value: latitudeText ?? "",
1345
+ onChange: handleChange("latitude", setLatitudeText),
1346
+ onBlur
1347
+ }))), /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("longitude.label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
1348
+ type: "number",
1349
+ step: "0.00001",
1350
+ min: "-180",
1351
+ max: "180",
1352
+ disabled: !!readonly,
1353
+ placeholder: t("longitude.placeholder"),
1354
+ value: longitudeText ?? "",
1355
+ onChange: handleChange("longitude", setLongitudeText),
1356
+ onBlur
1357
+ })))));
1358
+ };
1359
+ var LatLng = ({ latitude = 0, longitude = 0 }) => {
1360
+ const latHem = latitude >= 0 ? "N" : "S";
1361
+ const lngHem = longitude >= 0 ? "E" : "W";
1362
+ return /* @__PURE__ */ React7.createElement("span", {
1363
+ className: "inline-flex items-center gap-form-gap"
1364
+ }, /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(latitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
1365
+ className: "text-subdued"
1366
+ }, "\xB0", latHem)), /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(longitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
1367
+ className: "text-subdued"
1368
+ }, "\xB0", lngHem)));
1441
1369
  };
1442
1370
 
1443
- // src/components/Form/ArrayField.tsx
1444
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1445
- import * as Function from "effect/Function";
1446
- import * as SchemaAST3 from "effect/SchemaAST";
1447
- import * as String2 from "effect/String";
1448
- import React9, { Fragment, useCallback as useCallback8 } from "react";
1449
- import { SimpleType, findNode as findNode2, getDiscriminatedType, isDiscriminatedUnion } from "@dxos/effect";
1450
- import { invariant as invariant2 } from "@dxos/invariant";
1451
- import { IconButton as IconButton3, useTranslation as useTranslation6 } from "@dxos/react-ui";
1452
- import { getSchemaProperties } from "@dxos/schema";
1453
- var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/Form/ArrayField.tsx";
1454
- var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
1455
- var _effect = _useSignals9();
1456
- try {
1457
- const { t } = useTranslation6(translationKey);
1458
- const { ast, name, type, title } = property;
1459
- const values = useFormValues(path ?? []) ?? [];
1460
- invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
1461
- F: __dxlog_file3,
1462
- L: 37,
1463
- S: void 0,
1464
- A: [
1465
- "Array.isArray(values)",
1466
- "`Values at path ${path?.join('.')} must be an array.`"
1467
- ]
1468
- });
1469
- const label = title ?? Function.pipe(name, String2.capitalize);
1470
- const elementType = findArrayElementType(ast);
1471
- const getDefaultObjectValue = (typeNode) => {
1472
- const baseNode = findNode2(typeNode, isDiscriminatedUnion);
1473
- const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
1474
- if (!typeLiteral) {
1475
- return {};
1476
- }
1477
- return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [
1478
- prop.name,
1479
- prop.defaultValue
1480
- ]));
1481
- };
1482
- const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
1483
- const handleAdd = useCallback8(() => {
1484
- inputProps.onValueChange(type, [
1485
- ...values,
1486
- getDefaultValue()
1487
- ]);
1488
- }, [
1489
- type,
1490
- elementType,
1491
- inputProps,
1492
- values
1493
- ]);
1494
- const handleRemove = useCallback8((index) => {
1495
- const newValues = values.filter((_, i) => i !== index);
1496
- inputProps.onValueChange(type, newValues);
1497
- }, [
1498
- type,
1499
- inputProps,
1500
- values
1501
- ]);
1502
- if (!elementType) {
1503
- return null;
1371
+ // src/components/Form/fields/MarkdownField.tsx
1372
+ import React8, { useCallback as useCallback6, useEffect as useEffect4, useRef as useRef2 } from "react";
1373
+ import { Input as Input4 } from "@dxos/react-ui";
1374
+ var MarkdownField = ({ type, readonly, label, placeholder, layout, getStatus, getValue, onValueChange, onBlur }) => {
1375
+ const { status, error } = getStatus();
1376
+ const textareaRef = useRef2(null);
1377
+ const adjustHeight = useCallback6(() => {
1378
+ const textarea = textareaRef.current;
1379
+ if (textarea) {
1380
+ textarea.style.blockSize = "auto";
1381
+ textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
1504
1382
  }
1505
- return readonly && values.length < 1 ? null : /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement(InputHeader, {
1506
- readonly: true,
1507
- label
1508
- }), /* @__PURE__ */ React9.createElement("div", {
1509
- role: "none",
1510
- className: readonly ? "flex flex-wrap gap-1 mlb-1" : values.length > 0 ? "grid gap-1 grid-cols-[1fr_min-content] mlb-1" : "hidden"
1511
- }, values.map((_value, index) => {
1512
- const field = /* @__PURE__ */ React9.createElement(FormField, {
1513
- property: {
1514
- ...property,
1515
- array: false,
1516
- ast: elementType
1517
- },
1518
- path: [
1519
- ...path ?? [],
1520
- index
1521
- ],
1522
- readonly,
1523
- inline: true,
1524
- Custom,
1525
- lookupComponent
1526
- });
1527
- return readonly ? field : /* @__PURE__ */ React9.createElement(Fragment, {
1528
- key: index
1529
- }, /* @__PURE__ */ React9.createElement("div", {
1530
- role: "none"
1531
- }, field), /* @__PURE__ */ React9.createElement(IconButton3, {
1532
- icon: "ph--trash--regular",
1533
- iconOnly: true,
1534
- label: t("button remove"),
1535
- onClick: () => handleRemove(index),
1536
- classNames: "self-center"
1537
- }));
1538
- })), !readonly && /* @__PURE__ */ React9.createElement(IconButton3, {
1539
- classNames: "is-full mlb-cardSpacingBlock flex",
1540
- icon: "ph--plus--regular",
1541
- label: t("add field"),
1542
- onClick: handleAdd
1543
- }));
1544
- } finally {
1545
- _effect.f();
1383
+ }, []);
1384
+ useEffect4(() => {
1385
+ adjustHeight();
1386
+ }, [
1387
+ adjustHeight
1388
+ ]);
1389
+ useEffect4(() => {
1390
+ adjustHeight();
1391
+ }, [
1392
+ getValue(),
1393
+ adjustHeight
1394
+ ]);
1395
+ const handleChange = useCallback6((event) => onValueChange(type, event.target.value), [
1396
+ type,
1397
+ onValueChange
1398
+ ]);
1399
+ const value3 = getValue();
1400
+ if ((readonly || layout === "static") && !value3) {
1401
+ return null;
1546
1402
  }
1403
+ return /* @__PURE__ */ React8.createElement(Input4.Root, {
1404
+ validationValence: status
1405
+ }, layout !== "inline" && /* @__PURE__ */ React8.createElement(FormFieldLabel, {
1406
+ error,
1407
+ readonly,
1408
+ label
1409
+ }), layout === "static" ? /* @__PURE__ */ React8.createElement("p", null, value3) : /* @__PURE__ */ React8.createElement(Input4.TextArea, {
1410
+ ref: textareaRef,
1411
+ disabled: !!readonly,
1412
+ placeholder,
1413
+ value: value3 ?? "",
1414
+ classNames: "min-h-auto max-h-40 overflow-auto",
1415
+ onChange: handleChange,
1416
+ onBlur,
1417
+ style: {
1418
+ resize: "none"
1419
+ },
1420
+ spellCheck: false
1421
+ }), layout === "full" && /* @__PURE__ */ React8.createElement(Input4.Validation, null, error));
1547
1422
  };
1548
1423
 
1549
- // src/components/Form/factory.tsx
1550
- import { FormatEnum as FormatEnum4 } from "@dxos/echo/internal";
1551
- var getInputComponent = (type, format) => {
1552
- switch (format) {
1553
- case FormatEnum4.GeoPoint:
1554
- return GeoPointInput;
1555
- case FormatEnum4.Markdown:
1556
- return MarkdownInput;
1557
- }
1558
- switch (type) {
1559
- case "string":
1560
- return TextInput;
1561
- case "number":
1562
- return NumberInput;
1563
- case "boolean":
1564
- return BooleanInput;
1565
- }
1424
+ // src/components/Form/fields/NumberField.tsx
1425
+ import React9, { useCallback as useCallback7 } from "react";
1426
+ import { Input as Input5 } from "@dxos/react-ui";
1427
+ import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
1428
+ var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
1429
+ const handleChange = useCallback7((event) => onValueChange(type, safeParseFloat2(event.target.value) || 0), [
1430
+ type,
1431
+ onValueChange
1432
+ ]);
1433
+ return /* @__PURE__ */ React9.createElement(FormFieldWrapper, {
1434
+ readonly,
1435
+ ...props
1436
+ }, ({ value: value3 = "" }) => /* @__PURE__ */ React9.createElement(Input5.TextInput, {
1437
+ type: "number",
1438
+ disabled: !!readonly,
1439
+ placeholder,
1440
+ value: value3,
1441
+ onChange: handleChange,
1442
+ onBlur
1443
+ }));
1566
1444
  };
1567
1445
 
1568
- // src/components/Form/RefField.tsx
1569
- import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
1446
+ // src/components/Form/fields/RefField.tsx
1447
+ import React11, { useCallback as useCallback9, useMemo as useMemo6 } from "react";
1570
1448
  import "@dxos/lit-ui/dx-tag-picker.pcss";
1571
- import React11, { useCallback as useCallback10, useMemo as useMemo5 } from "react";
1572
- import { Expando, Ref, ReferenceAnnotationId as ReferenceAnnotationId2, getTypeAnnotation } from "@dxos/echo/internal";
1449
+ import { Entity, Filter, Obj, Ref as Ref2, Type } from "@dxos/echo";
1450
+ import { useQuery, useSchema as useSchema$ } from "@dxos/echo-react";
1451
+ import { ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo/internal";
1573
1452
  import { findAnnotation as findAnnotation2 } from "@dxos/effect";
1574
1453
  import { DXN } from "@dxos/keys";
1575
- import { DxAnchor, DxTagPickerItem } from "@dxos/lit-ui/react";
1576
- import { Button as Button2, Icon as Icon3, Input as Input7, useTranslation as useTranslation8 } from "@dxos/react-ui";
1577
- import { descriptionText, mx as mx5 } from "@dxos/react-ui-theme";
1578
- import { isNonNullable as isNonNullable2 } from "@dxos/util";
1454
+ import { DxAnchor } from "@dxos/lit-ui/react";
1455
+ import { Button, Icon as Icon2, Input as Input6, useTranslation as useTranslation6 } from "@dxos/react-ui";
1456
+ import { ParentLabelAnnotationId } from "@dxos/schema";
1457
+ import { mx as mx2 } from "@dxos/ui-theme";
1579
1458
 
1580
1459
  // src/components/ObjectPicker/ObjectPicker.tsx
1581
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
1582
- import React10, { forwardRef, useCallback as useCallback9, useMemo as useMemo4, useState as useState5 } from "react";
1583
- import { Icon as Icon2, Popover, useTranslation as useTranslation7 } from "@dxos/react-ui";
1584
- import { Combobox } from "@dxos/react-ui-searchlist";
1585
- var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, onSelect, onCreate, ...props }, ref) => {
1586
- var _effect = _useSignals10();
1587
- try {
1588
- const { t } = useTranslation7(translationKey);
1589
- const [searchString, setSearchString] = useState5("");
1590
- const [showForm, setShowForm] = useState5(false);
1591
- const handleFormSave = useCallback9((values) => {
1592
- onCreate?.(values);
1593
- setShowForm(false);
1594
- setSearchString("");
1595
- }, [
1596
- onCreate
1597
- ]);
1598
- const handleFormCancel = useCallback9(() => {
1599
- setShowForm(false);
1600
- setSearchString("");
1601
- }, []);
1602
- const handleClick = useCallback9((event) => {
1603
- if (createSchema && event.target.closest('[data-value="__create__"]')) {
1604
- event.stopPropagation();
1605
- event.preventDefault();
1606
- setShowForm(true);
1607
- }
1608
- }, [
1609
- createSchema
1610
- ]);
1611
- const handleKeyDown = useCallback9((event) => {
1612
- if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
1613
- event.stopPropagation();
1614
- event.preventDefault();
1615
- setShowForm(true);
1616
- }
1617
- }, [
1618
- createSchema
1619
- ]);
1620
- const labelById = useMemo4(() => options.reduce((acc, option) => {
1621
- acc[option.id.toLowerCase()] = option.label.toLowerCase();
1622
- return acc;
1623
- }, {}), [
1624
- options
1625
- ]);
1460
+ import React10, { forwardRef, useCallback as useCallback8, useState as useState3 } from "react";
1461
+ import { Popover, useTranslation as useTranslation5 } from "@dxos/react-ui";
1462
+ import { Combobox, useSearchListInput, useSearchListResults } from "@dxos/react-ui-search";
1463
+ var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap, onSelect, onCreate, ...props }, forwardedRef) => {
1464
+ const { t } = useTranslation5(translationKey);
1465
+ const [showForm, setShowForm] = useState3(false);
1466
+ const [formInitialValue, setFormInitialValue] = useState3("");
1467
+ const { results, handleSearch } = useSearchListResults({
1468
+ items: options
1469
+ });
1470
+ const handleFormSave = useCallback8((values) => {
1471
+ onCreate?.(values);
1472
+ setShowForm(false);
1473
+ setFormInitialValue("");
1474
+ }, [
1475
+ onCreate
1476
+ ]);
1477
+ const handleFormCancel = useCallback8(() => {
1478
+ setShowForm(false);
1479
+ setFormInitialValue("");
1480
+ }, []);
1481
+ const handleKeyDown = useCallback8((event) => {
1482
+ if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
1483
+ event.stopPropagation();
1484
+ event.preventDefault();
1485
+ const input = event.currentTarget.querySelector('input[type="text"]');
1486
+ const currentQuery = input?.value || "";
1487
+ setFormInitialValue(currentQuery);
1488
+ setShowForm(true);
1489
+ }
1490
+ }, [
1491
+ createSchema
1492
+ ]);
1493
+ if (showForm && createSchema) {
1626
1494
  return /* @__PURE__ */ React10.createElement(Combobox.Content, {
1627
1495
  ...props,
1628
- ref,
1629
- filter: (value2, search) => value2 === "__create__" || labelById[value2]?.includes(search.toLowerCase()) ? 1 : 0,
1630
- onClickCapture: handleClick,
1631
- onKeyDownCapture: handleKeyDown
1632
- }, showForm && createSchema ? /* @__PURE__ */ React10.createElement(Popover.Viewport, null, /* @__PURE__ */ React10.createElement(Form, {
1496
+ onSearch: handleSearch,
1497
+ onKeyDownCapture: handleKeyDown,
1498
+ ref: forwardedRef
1499
+ }, /* @__PURE__ */ React10.createElement(Popover.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Root, {
1500
+ testId: "create-referenced-object-form",
1633
1501
  schema: createSchema,
1634
- values: createInitialValuePath ? {
1635
- [createInitialValuePath]: searchString
1502
+ defaultValues: createInitialValuePath ? {
1503
+ [createInitialValuePath]: formInitialValue
1636
1504
  } : {},
1505
+ fieldMap: createFieldMap,
1637
1506
  onSave: handleFormSave,
1638
- onCancel: handleFormCancel,
1639
- testId: "create-referenced-object-form"
1640
- })) : /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(Combobox.Input, {
1641
- placeholder: t("ref field combobox input placeholder"),
1642
- value: searchString,
1643
- onValueChange: setSearchString,
1644
- autoFocus: true
1645
- }), /* @__PURE__ */ React10.createElement(Combobox.List, null, options.map((option) => /* @__PURE__ */ React10.createElement(Combobox.Item, {
1646
- key: option.id,
1647
- value: option.id,
1648
- onSelect: () => onSelect(option.id),
1649
- classNames: "flex items-center gap-2"
1650
- }, /* @__PURE__ */ React10.createElement("span", {
1651
- className: "grow"
1652
- }, option.label), selectedIds?.includes(option.id) && /* @__PURE__ */ React10.createElement(Icon2, {
1653
- icon: "ph--check--regular"
1654
- }))), searchString.length > 0 && createOptionLabel && createOptionIcon && createSchema && onCreate && /* @__PURE__ */ React10.createElement(Combobox.Item, {
1655
- value: "__create__",
1656
- classNames: "flex items-center gap-2"
1657
- }, /* @__PURE__ */ React10.createElement(Icon2, {
1658
- icon: createOptionIcon
1659
- }), t(createOptionLabel[0], {
1660
- ns: createOptionLabel[1].ns,
1661
- text: searchString
1662
- })))), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
1663
- } finally {
1664
- _effect.f();
1507
+ onCancel: handleFormCancel
1508
+ }, /* @__PURE__ */ React10.createElement(Form.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Content, null, /* @__PURE__ */ React10.createElement(Form.FieldSet, null), /* @__PURE__ */ React10.createElement(Form.Actions, null))))), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
1665
1509
  }
1510
+ return /* @__PURE__ */ React10.createElement(Combobox.Content, {
1511
+ ...props,
1512
+ onSearch: handleSearch,
1513
+ onKeyDownCapture: handleKeyDown,
1514
+ ref: forwardedRef
1515
+ }, /* @__PURE__ */ React10.createElement(Combobox.Input, {
1516
+ placeholder: t("ref-field-combobox-input.placeholder"),
1517
+ autoFocus: true
1518
+ }), /* @__PURE__ */ React10.createElement(Combobox.List, null, results.map((option) => /* @__PURE__ */ React10.createElement(Combobox.Item, {
1519
+ key: option.id,
1520
+ value: option.id,
1521
+ label: option.label,
1522
+ checked: selectedIds?.includes(option.id),
1523
+ onSelect: () => onSelect(option.id),
1524
+ classNames: "flex items-center gap-2"
1525
+ })), createSchema && onCreate && /* @__PURE__ */ React10.createElement(CreateItem, {
1526
+ createOptionLabel,
1527
+ createOptionIcon: createOptionIcon ?? "ph--plus--regular",
1528
+ onCreateItemSelect: (query) => {
1529
+ setFormInitialValue(query);
1530
+ setShowForm(true);
1531
+ }
1532
+ })), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
1666
1533
  });
1667
- ObjectPickerContent.displayName = "ObjectPickerContent";
1534
+ var CreateItem = ({ createOptionLabel, createOptionIcon, onCreateItemSelect }) => {
1535
+ const { t } = useTranslation5(translationKey);
1536
+ const { query } = useSearchListInput();
1537
+ const label = createOptionLabel ? t(createOptionLabel[0], {
1538
+ ns: createOptionLabel[1].ns,
1539
+ text: query
1540
+ }) : t("create-option.label");
1541
+ return /* @__PURE__ */ React10.createElement(Combobox.Item, {
1542
+ value: "__create__",
1543
+ label,
1544
+ icon: createOptionIcon,
1545
+ classNames: "flex items-center gap-2",
1546
+ closeOnSelect: false,
1547
+ onSelect: () => {
1548
+ onCreateItemSelect(query);
1549
+ }
1550
+ });
1551
+ };
1552
+ ObjectPickerContent.displayName = "ObjectPicker.Content";
1668
1553
  var ObjectPicker = {
1669
1554
  Root: Combobox.Root,
1555
+ Portal: Combobox.Portal,
1670
1556
  Trigger: Combobox.Trigger,
1671
1557
  VirtualTrigger: Combobox.VirtualTrigger,
1672
1558
  Content: ObjectPickerContent
1673
1559
  };
1674
1560
 
1675
- // src/components/Form/RefField.tsx
1676
- var isRefSnapShot = (val) => {
1561
+ // src/components/Form/fields/RefField.tsx
1562
+ var isRefSnapshot = (val) => {
1677
1563
  return typeof val === "object" && typeof val?.["/"] === "string";
1678
1564
  };
1679
- var RefField = ({ type, label, readonly, placeholder, inputOnly, array, ast, getValue: getValue3, createOptionLabel, createOptionIcon, onBlur, onCreate, createSchema, createInitialValuePath, onQueryRefOptions, onValueChange, ...restInputProps }) => {
1680
- var _effect = _useSignals11();
1681
- try {
1682
- const { t } = useTranslation8(translationKey);
1683
- const refTypeInfo = useMemo5(() => ast ? findAnnotation2(ast, ReferenceAnnotationId2) : void 0, [
1684
- ast
1685
- ]);
1686
- const { options: availableOptions, update: updateOptions, loading: _loading } = useQueryRefOptions({
1687
- refTypeInfo,
1688
- onQueryRefOptions
1565
+ var defaultGetOptions = (results, { parentLabel } = {}) => results.map((result) => {
1566
+ const id = Entity.getDXN(result).toString();
1567
+ const parent = parentLabel ? Obj.getParent(result) : void 0;
1568
+ const label = parent ? Entity.getLabel(parent) : Entity.getLabel(result);
1569
+ return {
1570
+ id,
1571
+ label: label ?? id
1572
+ };
1573
+ });
1574
+ var defaultResultsHook = (db, typename) => useQuery(db, typename ? typename === Type.getTypename(Obj.Unknown) ? Filter.everything() : Filter.typename(typename) : Filter.nothing());
1575
+ var RefField = (props) => {
1576
+ const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap, db, resultsHook: useResults = defaultResultsHook, schemaHook: useSchema = useSchema$, getOptions: getOptions2 = defaultGetOptions, onCreate, onValueChange } = props;
1577
+ const { t } = useTranslation6(translationKey);
1578
+ const { status, error } = getStatus();
1579
+ const typename = useMemo6(() => type ? findAnnotation2(type, ReferenceAnnotationId2)?.typename : void 0, [
1580
+ type
1581
+ ]);
1582
+ const results = useResults(db, typename);
1583
+ const options = useMemo6(() => {
1584
+ const parentLabel = type ? findAnnotation2(type, ParentLabelAnnotationId) === true : false;
1585
+ return getOptions2(results, {
1586
+ parentLabel
1689
1587
  });
1690
- if (refTypeInfo && refTypeInfo?.typename === getTypeAnnotation(Expando)?.typename || !onQueryRefOptions) {
1691
- return /* @__PURE__ */ React11.createElement(RefFieldFallback, {
1692
- type,
1693
- label,
1694
- placeholder,
1695
- readonly,
1696
- inputOnly,
1697
- getValue: getValue3,
1698
- onBlur,
1699
- onValueChange,
1700
- ...restInputProps
1701
- });
1702
- }
1703
- const handleGetValue = useCallback10(() => {
1704
- const formValue = getValue3();
1705
- const unknownToRefOption = (val) => {
1706
- const isRef = Ref.isRef(val);
1707
- if (isRef || isRefSnapShot(val)) {
1708
- const dxnString = isRef ? val.dxn.toString() : val["/"];
1709
- const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
1710
- if (matchingOption) {
1711
- return matchingOption;
1712
- }
1713
- }
1714
- return void 0;
1715
- };
1716
- if (array && Array.isArray(formValue)) {
1717
- return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
1718
- }
1719
- const option = unknownToRefOption(formValue);
1720
- if (option) {
1721
- return [
1722
- option
1723
- ];
1724
- }
1725
- return [];
1726
- }, [
1727
- getValue3,
1728
- availableOptions,
1729
- array
1730
- ]);
1731
- const handleUpdate = useCallback10((ids) => {
1732
- if (ids.length === 0) {
1733
- onValueChange("object", void 0);
1734
- return;
1735
- }
1736
- const refs = ids.map((id) => {
1737
- const item = availableOptions.find((option) => option.id === id);
1738
- if (item) {
1739
- const dxn = DXN.parse(item.id);
1740
- return Ref.fromDXN(dxn);
1741
- }
1742
- return null;
1743
- }).filter(isNonNullable2);
1744
- if (array) {
1745
- onValueChange("object", refs);
1746
- } else {
1747
- onValueChange("object", refs[0]);
1748
- }
1749
- }, [
1750
- availableOptions,
1751
- array,
1752
- onValueChange
1753
- ]);
1754
- const handleCreate = useCallback10((values) => {
1755
- onCreate?.(values);
1756
- updateOptions();
1757
- }, [
1758
- onCreate,
1759
- updateOptions
1760
- ]);
1761
- if (!refTypeInfo) {
1762
- return null;
1763
- }
1764
- const { status, error } = restInputProps.getStatus();
1765
- const items = handleGetValue();
1766
- const selectedIds = useMemo5(() => items.map((i) => i.id), [
1767
- items
1768
- ]);
1769
- const toggleSelect = useCallback10((id) => {
1770
- if (array) {
1771
- const nextIds = selectedIds.includes(id) ? selectedIds.filter((x) => x !== id) : [
1772
- ...selectedIds,
1773
- id
1774
- ];
1775
- handleUpdate(nextIds);
1776
- } else {
1777
- if (selectedIds[0] === id) {
1778
- handleUpdate([]);
1779
- } else {
1780
- handleUpdate([
1781
- id
1782
- ]);
1783
- }
1784
- }
1785
- }, [
1786
- array,
1787
- selectedIds,
1788
- handleUpdate
1789
- ]);
1790
- return readonly && items.length < 1 ? null : /* @__PURE__ */ React11.createElement(Input7.Root, {
1791
- validationValence: status
1792
- }, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
1793
- error,
1794
- label
1795
- }), /* @__PURE__ */ React11.createElement("div", {
1796
- "data-no-submit": true
1797
- }, readonly ? items.length < 1 ? /* @__PURE__ */ React11.createElement("p", {
1798
- className: mx5(descriptionText, "mbe-2")
1799
- }, t("empty readonly ref field label")) : items.map((item) => /* @__PURE__ */ React11.createElement(DxAnchor, {
1800
- key: item.id,
1801
- refid: item.id,
1802
- rootclassname: "mie-1"
1803
- }, item.label)) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Trigger, {
1804
- asChild: true
1805
- }, /* @__PURE__ */ React11.createElement(Button2, {
1806
- variant: "ghost",
1807
- classNames: "is-full text-start gap-2"
1808
- }, /* @__PURE__ */ React11.createElement("div", {
1809
- role: "none",
1810
- className: "grow"
1811
- }, items?.length ? items?.map((item) => /* @__PURE__ */ React11.createElement(DxTagPickerItem, {
1812
- key: item.id,
1813
- itemId: item.id,
1814
- label: item.label,
1815
- ...item.hue ? {
1816
- hue: item.hue
1817
- } : {},
1818
- removeLabel: t("remove item label"),
1819
- onItemClick: (event) => {
1820
- if (event.action === "remove") {
1821
- toggleSelect(item.id);
1588
+ }, [
1589
+ results,
1590
+ getOptions2,
1591
+ type
1592
+ ]);
1593
+ const handleGetValue = useCallback9(() => {
1594
+ const formValue = getValue();
1595
+ const unknownToRefOption = (value3) => {
1596
+ const isRef = Ref2.isRef(value3);
1597
+ if (isRef || isRefSnapshot(value3)) {
1598
+ const dxnString = isRef ? value3.dxn.toString() : value3["/"];
1599
+ const matchingOption = options.find((option) => option.id === dxnString);
1600
+ if (matchingOption) {
1601
+ return matchingOption;
1822
1602
  }
1823
1603
  }
1824
- })) : /* @__PURE__ */ React11.createElement("span", {
1825
- className: "text-description"
1826
- }, placeholder ?? t("ref field placeholder", {
1827
- count: array ? 99 : 1
1828
- }))), /* @__PURE__ */ React11.createElement(Icon3, {
1829
- size: 3,
1830
- icon: "ph--caret-down--bold"
1831
- }))), /* @__PURE__ */ React11.createElement(ObjectPicker.Content, {
1832
- options: availableOptions,
1833
- selectedIds,
1834
- onSelect: toggleSelect,
1835
- createSchema,
1836
- createOptionLabel,
1837
- createOptionIcon,
1838
- createInitialValuePath,
1839
- onCreate: handleCreate
1840
- }))), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
1841
- } finally {
1842
- _effect.f();
1843
- }
1844
- };
1845
- var RefFieldFallback = ({ type, label, readonly, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
1846
- var _effect = _useSignals11();
1847
- try {
1848
- const handleOnValueChange = (_type, dxnString) => {
1849
- const dxn = DXN.tryParse(dxnString);
1850
- if (dxn) {
1851
- onValueChange?.("object", Ref.fromDXN(dxn));
1852
- } else if (dxnString === "") {
1853
- onValueChange?.("object", void 0);
1854
- } else {
1855
- onValueChange?.("string", dxnString);
1856
- }
1857
- };
1858
- const handleGetValue = () => {
1859
- const formValue = getValue3();
1860
- if (typeof formValue === "string") {
1861
- return formValue;
1862
- }
1863
- if (Ref.isRef(formValue)) {
1864
- return formValue.dxn.toString();
1865
- }
1866
1604
  return void 0;
1867
1605
  };
1868
- return /* @__PURE__ */ React11.createElement(TextInput, {
1869
- type,
1870
- label,
1871
- readonly,
1872
- placeholder,
1873
- inputOnly,
1874
- getValue: handleGetValue,
1875
- onValueChange: handleOnValueChange,
1876
- ...restInputProps
1877
- });
1878
- } finally {
1879
- _effect.f();
1880
- }
1881
- };
1882
-
1883
- // src/components/Form/FormContent.tsx
1884
- var FormField = ({ property, path, readonly, inline, projection, onQueryRefOptions, createOptionLabel, createOptionIcon, onCreate, createSchema, createInitialValuePath, lookupComponent, Custom }) => {
1885
- var _effect = _useSignals12();
1886
- try {
1887
- const { ast, name, type, format, title, description, options, examples, array } = property;
1888
- const inputProps = useInputProps(path);
1889
- const label = useMemo6(() => title ?? Function2.pipe(name, StringEffect.capitalize), [
1890
- title,
1891
- name
1892
- ]);
1893
- const placeholder = useMemo6(() => examples?.length ? `Example: "${examples[0]}"` : description, [
1894
- examples,
1895
- description
1896
- ]);
1897
- const FoundComponent = lookupComponent?.({
1898
- prop: name,
1899
- schema: Schema.make(ast),
1900
- inputProps: {
1901
- type,
1902
- format,
1903
- label,
1904
- readonly,
1905
- placeholder,
1906
- ...inputProps
1907
- }
1908
- });
1909
- if (FoundComponent) {
1910
- return FoundComponent;
1911
- }
1912
- const jsonPath = createJsonPath3(path ?? []);
1913
- const CustomComponent = Custom?.[jsonPath];
1914
- if (CustomComponent) {
1915
- return /* @__PURE__ */ React12.createElement(CustomComponent, {
1916
- type,
1917
- format,
1918
- label,
1919
- inputOnly: inline,
1920
- placeholder,
1921
- readonly,
1922
- ...inputProps
1923
- });
1924
- }
1925
- const refProps = getRefProps(property);
1926
- if (refProps) {
1927
- return /* @__PURE__ */ React12.createElement(RefField, {
1928
- ast: refProps.ast,
1929
- array: refProps.isArray,
1930
- type,
1931
- format,
1932
- label,
1933
- placeholder,
1934
- readonly,
1935
- inputOnly: inline,
1936
- onQueryRefOptions,
1937
- createOptionLabel,
1938
- createOptionIcon,
1939
- onCreate,
1940
- createSchema,
1941
- createInitialValuePath,
1942
- ...inputProps
1943
- });
1944
- }
1945
- if (array) {
1946
- return /* @__PURE__ */ React12.createElement(ArrayField, {
1947
- property,
1948
- path,
1949
- inputProps,
1950
- readonly,
1951
- Custom
1952
- });
1953
- }
1954
- const InputComponent = getInputComponent(type, format);
1955
- if (InputComponent) {
1956
- return /* @__PURE__ */ React12.createElement(InputComponent, {
1957
- type,
1958
- format,
1959
- label,
1960
- inputOnly: inline,
1961
- placeholder,
1962
- readonly,
1963
- ...inputProps
1964
- });
1965
- }
1966
- if (options) {
1967
- return /* @__PURE__ */ React12.createElement(SelectInput, {
1968
- type,
1969
- format,
1970
- readonly,
1971
- inputOnly: inline,
1972
- label,
1973
- options: options.map((option) => ({
1974
- value: option,
1975
- label: String(option)
1976
- })),
1977
- placeholder,
1978
- ...inputProps
1979
- });
1980
- }
1981
- if (type === "object") {
1982
- const baseNode = findNode3(ast, isDiscriminatedUnion2);
1983
- const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode3(ast, SchemaAST4.isTypeLiteral);
1984
- if (typeLiteral) {
1985
- return /* @__PURE__ */ React12.createElement(React12.Fragment, null, !inline && /* @__PURE__ */ React12.createElement("h3", {
1986
- className: mx6("text-lg mlb-inputSpacingBlock first:mbs-0")
1987
- }, label), /* @__PURE__ */ React12.createElement(FormFields, {
1988
- schema: Schema.make(typeLiteral),
1989
- path,
1990
- readonly,
1991
- projection,
1992
- onQueryRefOptions,
1993
- createOptionLabel,
1994
- createOptionIcon,
1995
- onCreate,
1996
- Custom,
1997
- lookupComponent
1998
- }));
1999
- }
2000
- }
2001
- return null;
2002
- } finally {
2003
- _effect.f();
2004
- }
2005
- };
2006
- var FormFields = /* @__PURE__ */ forwardRef2(({ classNames, schema, path, filter, sort, projection, readonly, lookupComponent, Custom, onQueryRefOptions, ...props }, forwardRef4) => {
2007
- var _effect = _useSignals12();
2008
- try {
2009
- const values = useFormValues(path);
2010
- const properties = useMemo6(() => {
2011
- const props2 = getSchemaProperties2(schema.ast, values);
2012
- if (projection) {
2013
- const fieldProjections = projection.getFieldProjections();
2014
- const hiddenProperties = new Set(projection.getHiddenProperties());
2015
- const visibleProps = props2.filter((prop) => !hiddenProperties.has(prop.name));
2016
- const orderedProps = [];
2017
- for (const fieldProjection of fieldProjections) {
2018
- const fieldPath = String(fieldProjection.field.path);
2019
- const prop = visibleProps.find((p) => p.name === fieldPath);
2020
- if (prop) {
2021
- orderedProps.push(prop);
2022
- }
2023
- }
2024
- const projectionPaths = new Set(fieldProjections.map((fp) => String(fp.field.path)));
2025
- const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name));
2026
- orderedProps.push(...remainingProps);
2027
- return orderedProps;
2028
- }
2029
- const filtered = filter ? filter(props2) : props2;
2030
- return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
2031
- }, [
2032
- schema,
2033
- values,
2034
- filter,
2035
- sort,
2036
- projection?.fields
2037
- ]);
2038
- return /* @__PURE__ */ React12.createElement("div", {
2039
- role: "form",
2040
- className: mx6("is-full", classNames),
2041
- ref: forwardRef4
2042
- }, properties.map((property) => {
2043
- return /* @__PURE__ */ React12.createElement(ErrorBoundary, {
2044
- key: property.name,
2045
- path: [
2046
- ...path ?? [],
2047
- property.name
2048
- ]
2049
- }, /* @__PURE__ */ React12.createElement(FormField, {
2050
- property,
2051
- path: [
2052
- ...path ?? [],
2053
- property.name
2054
- ],
2055
- readonly,
2056
- projection,
2057
- onQueryRefOptions,
2058
- lookupComponent,
2059
- Custom,
2060
- ...props
2061
- }));
2062
- }).filter(isTruthy));
2063
- } finally {
2064
- _effect.f();
2065
- }
2066
- });
2067
- var ErrorBoundary = class extends Component {
2068
- static getDerivedStateFromError(error) {
2069
- return {
2070
- error
2071
- };
2072
- }
2073
- state = {
2074
- error: void 0
2075
- };
2076
- componentDidUpdate(prevProps) {
2077
- if (prevProps.path !== this.props.path) {
2078
- this.resetError();
1606
+ return unknownToRefOption(formValue);
1607
+ }, [
1608
+ options,
1609
+ getValue
1610
+ ]);
1611
+ const handleUpdate = useCallback9((id) => {
1612
+ const item2 = options.find((option) => option.id === id);
1613
+ const ref = item2 ? Ref2.fromDXN(DXN.parse(item2.id)) : void 0;
1614
+ onValueChange(type, ref);
1615
+ }, [
1616
+ options,
1617
+ type,
1618
+ onValueChange
1619
+ ]);
1620
+ const item = handleGetValue();
1621
+ const selectedIds = useMemo6(() => item ? [
1622
+ item.id
1623
+ ] : [], [
1624
+ item
1625
+ ]);
1626
+ const createSchema = useSchema(db, typename);
1627
+ const handleCreate = useCallback9((values) => {
1628
+ if (createSchema && onCreate) {
1629
+ onCreate(createSchema, values);
2079
1630
  }
2080
- }
2081
- render() {
2082
- if (this.state.error) {
2083
- return /* @__PURE__ */ React12.createElement("div", {
2084
- className: "flex gap-2 border border-roseFill font-mono text-sm"
2085
- }, /* @__PURE__ */ React12.createElement("span", {
2086
- className: "bg-roseFill text-surfaceText pli-1 font-thin"
2087
- }, "ERROR"), String(this.props.path?.join(".")));
1631
+ }, [
1632
+ createSchema,
1633
+ onCreate
1634
+ ]);
1635
+ const handleSelect = useCallback9((id) => {
1636
+ if (item?.id === id) {
1637
+ handleUpdate(void 0);
1638
+ } else {
1639
+ handleUpdate(id);
2088
1640
  }
2089
- return this.props.children;
1641
+ }, [
1642
+ item,
1643
+ handleUpdate
1644
+ ]);
1645
+ if (!typename || (readonly || layout === "static") && !item) {
1646
+ return null;
2090
1647
  }
2091
- resetError() {
2092
- this.setState({
2093
- error: void 0
2094
- });
1648
+ return /* @__PURE__ */ React11.createElement(Input6.Root, {
1649
+ validationValence: status
1650
+ }, layout !== "inline" && /* @__PURE__ */ React11.createElement(FormFieldLabel, {
1651
+ error,
1652
+ readonly,
1653
+ label
1654
+ }), /* @__PURE__ */ React11.createElement("div", null, readonly ? !item ? /* @__PURE__ */ React11.createElement("p", {
1655
+ className: mx2("text-description", "mb-2")
1656
+ }, t("empty-readonly-ref-field.label")) : /* @__PURE__ */ React11.createElement(DxAnchor, {
1657
+ key: item.id,
1658
+ dxn: item.id,
1659
+ rootclassname: "me-1"
1660
+ }, item.label) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Trigger, {
1661
+ asChild: true,
1662
+ classNames: "p-0"
1663
+ }, item ? /* @__PURE__ */ React11.createElement("div", {
1664
+ className: "flex gap-form-gap w-full"
1665
+ }, /* @__PURE__ */ React11.createElement(Input6.Root, {
1666
+ key: item.id
1667
+ }, /* @__PURE__ */ React11.createElement(Input6.TextInput, {
1668
+ value: item.label,
1669
+ readOnly: true,
1670
+ classNames: "w-full"
1671
+ }))) : /* @__PURE__ */ React11.createElement(Button, {
1672
+ classNames: "w-full text-start gap-form-gap"
1673
+ }, /* @__PURE__ */ React11.createElement("div", {
1674
+ role: "none",
1675
+ className: "grow overflow-hidden"
1676
+ }, /* @__PURE__ */ React11.createElement("span", {
1677
+ className: "flex truncate text-description"
1678
+ }, placeholder ?? t("ref-field.placeholder"))), /* @__PURE__ */ React11.createElement(Icon2, {
1679
+ size: 3,
1680
+ icon: "ph--caret-down--bold"
1681
+ }))), /* @__PURE__ */ React11.createElement(ObjectPicker.Portal, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Content, {
1682
+ classNames: "dx-card-popover-width",
1683
+ options,
1684
+ selectedIds,
1685
+ createSchema: createSchema && omitId(createSchema),
1686
+ createOptionLabel,
1687
+ createOptionIcon,
1688
+ createInitialValuePath,
1689
+ createFieldMap,
1690
+ onCreate: handleCreate,
1691
+ onSelect: handleSelect
1692
+ })))), layout === "full" && /* @__PURE__ */ React11.createElement(Input6.DescriptionAndValidation, null, error));
1693
+ };
1694
+
1695
+ // src/components/Form/fields/SelectField.tsx
1696
+ import React12, { useCallback as useCallback10 } from "react";
1697
+ import { Input as Input7, Select } from "@dxos/react-ui";
1698
+ var SelectField = ({ type, readonly, label, layout, placeholder, options, getStatus, getValue, onValueChange }) => {
1699
+ const { status, error } = getStatus();
1700
+ const value3 = getValue();
1701
+ const handleValueChange = useCallback10((value4) => onValueChange(type, value4), [
1702
+ type,
1703
+ onValueChange
1704
+ ]);
1705
+ if ((readonly || layout === "static") && value3 == null) {
1706
+ return null;
2095
1707
  }
1708
+ return /* @__PURE__ */ React12.createElement(Input7.Root, {
1709
+ validationValence: status
1710
+ }, layout !== "inline" && /* @__PURE__ */ React12.createElement(FormFieldLabel, {
1711
+ error,
1712
+ readonly,
1713
+ label
1714
+ }), layout === "static" ? /* @__PURE__ */ React12.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value3)?.label ?? String(value3)) : /* @__PURE__ */ React12.createElement(Select.Root, {
1715
+ value: value3,
1716
+ onValueChange: handleValueChange
1717
+ }, /* @__PURE__ */ React12.createElement(Select.TriggerButton, {
1718
+ classNames: "w-full",
1719
+ disabled: !!readonly,
1720
+ placeholder
1721
+ }), /* @__PURE__ */ React12.createElement(Select.Portal, null, /* @__PURE__ */ React12.createElement(Select.Content, null, /* @__PURE__ */ React12.createElement(Select.Viewport, null, options?.map(({ value: value4, label: label2 }) => (
1722
+ // NOTE: Numeric values are converted to and from strings.
1723
+ /* @__PURE__ */ React12.createElement(Select.Option, {
1724
+ key: String(value4),
1725
+ value: String(value4)
1726
+ }, label2 ?? String(value4))
1727
+ ))), /* @__PURE__ */ React12.createElement(Select.Arrow, null)))), layout === "full" && /* @__PURE__ */ React12.createElement(Input7.DescriptionAndValidation, null, error));
2096
1728
  };
2097
1729
 
2098
- // src/components/Form/Form.tsx
2099
- var Form = ({ classNames, id, testId, values: initialValues, autoFocus, readonly, autoSave, outerSpacing = true, schema, onCancel, onValuesChanged, onValidate, onSave, ...props }) => {
2100
- var _effect = _useSignals13();
2101
- try {
2102
- const formRef = useRef3(null);
2103
- const { findFirstFocusable } = useFocusFinders();
2104
- useEffect7(() => {
2105
- if (autoFocus && formRef.current) {
2106
- const firstFocusable = findFirstFocusable(formRef.current);
2107
- if (firstFocusable) {
2108
- firstFocusable.focus();
2109
- }
2110
- }
2111
- }, [
2112
- autoFocus
2113
- ]);
2114
- const handleValid = useCallback11(async (values, meta) => {
2115
- if (autoSave) {
2116
- await onSave?.(values, meta);
2117
- }
2118
- }, [
2119
- autoSave,
2120
- onSave
1730
+ // src/components/Form/fields/SelectOptionField.tsx
1731
+ import React13, { useCallback as useCallback11, useEffect as useEffect5, useRef as useRef3, useState as useState4 } from "react";
1732
+ import { PublicKey } from "@dxos/keys";
1733
+ import { IconButton as IconButton3, Input as Input8, Tag, useTranslation as useTranslation7 } from "@dxos/react-ui";
1734
+ import { List } from "@dxos/react-ui-list";
1735
+ import { HuePicker } from "@dxos/react-ui-pickers";
1736
+ import { hues, osTranslations, subtleHover } from "@dxos/ui-theme";
1737
+ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueChange }) => {
1738
+ const { t } = useTranslation7(translationKey);
1739
+ const { status, error } = getStatus();
1740
+ const [selected, setSelectedId] = useState4(null);
1741
+ const [isNewOption, setIsNewOption] = useState4(false);
1742
+ const inputRef = useRef3(null);
1743
+ const options = getValue();
1744
+ useEffect5(() => {
1745
+ if (options === void 0) {
1746
+ onValueChange(type, []);
1747
+ }
1748
+ }, [
1749
+ options,
1750
+ type,
1751
+ onValueChange
1752
+ ]);
1753
+ const randomHue = () => {
1754
+ const usedHues = new Set(options?.map((option) => option.color) ?? []);
1755
+ const unusedHues = hues.filter((hue) => !usedHues.has(hue));
1756
+ if (unusedHues.length > 0) {
1757
+ return unusedHues[Math.floor(Math.random() * unusedHues.length)];
1758
+ }
1759
+ const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
1760
+ const availableHues = hues.filter((hue) => !lastThree.has(hue));
1761
+ return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
1762
+ };
1763
+ const handleAdd = useCallback11(() => {
1764
+ const newId = PublicKey.random().truncate();
1765
+ const newOption = {
1766
+ id: newId,
1767
+ title: "",
1768
+ color: randomHue()
1769
+ };
1770
+ onValueChange(type, [
1771
+ ...options ?? [],
1772
+ newOption
2121
1773
  ]);
2122
- return /* @__PURE__ */ React13.createElement(FormProvider, {
2123
- formRef,
2124
- schema,
2125
- autoSave,
2126
- initialValues,
2127
- onValuesChanged,
2128
- onValidate,
2129
- onValid: handleValid,
2130
- onSave
2131
- }, /* @__PURE__ */ React13.createElement("div", {
2132
- role: "none",
2133
- className: "contents",
2134
- ...id && {
2135
- "data-object-id": id
2136
- },
2137
- "data-testid": testId
2138
- }, /* @__PURE__ */ React13.createElement(FormFields, {
2139
- ...props,
2140
- ref: formRef,
2141
- classNames: [
2142
- outerSpacing === "blockStart-0" ? "pli-cardSpacingInline mbe-cardSpacingBlock [&>.mbs-inputSpacingBlock:first-child]:!mbs-0" : outerSpacing === "scroll-fields" ? "pli-cardSpacingInline pbe-cardSpacingBlock" : outerSpacing ? cardSpacing2 : false,
2143
- outerSpacing === "scroll-fields" && cardDialogOverflow,
2144
- classNames
2145
- ],
2146
- readonly,
2147
- schema
2148
- }), (onCancel || onSave) && !autoSave && !readonly && /* @__PURE__ */ React13.createElement(FormActions, {
2149
- readonly,
2150
- onCancel,
2151
- outerSpacing
2152
- })));
2153
- } finally {
2154
- _effect.f();
2155
- }
1774
+ setSelectedId(newId);
1775
+ setIsNewOption(true);
1776
+ }, [
1777
+ options,
1778
+ type,
1779
+ onValueChange
1780
+ ]);
1781
+ const handleDelete = useCallback11((id) => {
1782
+ const newOptions = options?.filter((option) => option.id !== id) ?? [];
1783
+ onValueChange(type, newOptions);
1784
+ setSelectedId(null);
1785
+ }, [
1786
+ options,
1787
+ type,
1788
+ onValueChange
1789
+ ]);
1790
+ const handleMove = useCallback11((from, to) => {
1791
+ if (!options) {
1792
+ return;
1793
+ }
1794
+ const newOptions = [
1795
+ ...options
1796
+ ];
1797
+ const [removed] = newOptions.splice(from, 1);
1798
+ newOptions.splice(to, 0, removed);
1799
+ onValueChange(type, newOptions);
1800
+ }, [
1801
+ options,
1802
+ type,
1803
+ onValueChange
1804
+ ]);
1805
+ const handleClick = useCallback11((id) => {
1806
+ setSelectedId((current) => current === id ? null : id);
1807
+ }, []);
1808
+ const handleTitleChange = useCallback11((id) => (e) => {
1809
+ const newOptions = options?.map((o) => o.id === id ? {
1810
+ ...o,
1811
+ title: e.target.value
1812
+ } : o);
1813
+ onValueChange(type, newOptions ?? []);
1814
+ }, [
1815
+ options,
1816
+ type,
1817
+ onValueChange
1818
+ ]);
1819
+ const handleKeyDown = useCallback11((ev) => {
1820
+ if (ev.key === "Enter") {
1821
+ setSelectedId(null);
1822
+ }
1823
+ }, []);
1824
+ const handleColorChange = useCallback11((id) => (hue) => {
1825
+ const newOptions = options?.map((o) => o.id === id ? {
1826
+ ...o,
1827
+ color: hue
1828
+ } : o);
1829
+ onValueChange(type, newOptions ?? []);
1830
+ }, [
1831
+ options,
1832
+ type,
1833
+ onValueChange
1834
+ ]);
1835
+ useEffect5(() => {
1836
+ if (selected && isNewOption && inputRef.current) {
1837
+ inputRef.current.focus();
1838
+ setIsNewOption(false);
1839
+ }
1840
+ }, [
1841
+ selected,
1842
+ isNewOption
1843
+ ]);
1844
+ return /* @__PURE__ */ React13.createElement(Input8.Root, {
1845
+ validationValence: status
1846
+ }, /* @__PURE__ */ React13.createElement(FormFieldLabel, {
1847
+ error,
1848
+ readonly,
1849
+ label
1850
+ }), /* @__PURE__ */ React13.createElement("div", {
1851
+ role: "none"
1852
+ }, options && /* @__PURE__ */ React13.createElement(List.Root, {
1853
+ items: options,
1854
+ isItem: (_item) => true,
1855
+ onMove: readonly ? void 0 : handleMove,
1856
+ readonly: !!readonly
1857
+ }, ({ items }) => /* @__PURE__ */ React13.createElement("div", {
1858
+ role: "list",
1859
+ className: "w-full overflow-auto"
1860
+ }, items?.map((item) => /* @__PURE__ */ React13.createElement("div", {
1861
+ key: item.id
1862
+ }, /* @__PURE__ */ React13.createElement(List.Item, {
1863
+ role: "button",
1864
+ item,
1865
+ classNames: [
1866
+ subtleHover,
1867
+ "flex flex-col cursor-pointer rounded-xs"
1868
+ ],
1869
+ "aria-expanded": selected === item.id
1870
+ }, /* @__PURE__ */ React13.createElement("div", {
1871
+ className: "flex items-center"
1872
+ }, /* @__PURE__ */ React13.createElement(List.ItemDragHandle, {
1873
+ disabled: !!readonly
1874
+ }), /* @__PURE__ */ React13.createElement(List.ItemTitle, {
1875
+ onClick: () => handleClick(item.id),
1876
+ classNames: "flex-1"
1877
+ }, /* @__PURE__ */ React13.createElement(Tag, {
1878
+ palette: item.color
1879
+ }, item.title || "\u200B")), /* @__PURE__ */ React13.createElement(IconButton3, {
1880
+ iconOnly: true,
1881
+ variant: "ghost",
1882
+ label: t(selected === item.id ? "collapse label" : "expand label", {
1883
+ ns: osTranslations
1884
+ }),
1885
+ icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
1886
+ onClick: () => handleClick(item.id)
1887
+ })), selected === item.id && /* @__PURE__ */ React13.createElement("div", {
1888
+ className: "flex flex-col p-form-padding gap-form-gap dx-density-fine"
1889
+ }, /* @__PURE__ */ React13.createElement(Input8.Label, {
1890
+ classNames: "text-xs"
1891
+ }, t("select-option.label")), /* @__PURE__ */ React13.createElement("div", {
1892
+ className: "grid grid-cols-[1fr_min-content_min-content] gap-form-gap"
1893
+ }, /* @__PURE__ */ React13.createElement(Input8.TextInput, {
1894
+ disabled: !!readonly,
1895
+ placeholder: t("select-option-label.placeholder"),
1896
+ ref: selected === item.id ? inputRef : void 0,
1897
+ value: item.title,
1898
+ onChange: handleTitleChange(item.id),
1899
+ onKeyDown: handleKeyDown,
1900
+ classNames: "flex-1"
1901
+ }), /* @__PURE__ */ React13.createElement(HuePicker, {
1902
+ disabled: !!readonly,
1903
+ value: item.color,
1904
+ onChange: handleColorChange(item.id)
1905
+ }), /* @__PURE__ */ React13.createElement(IconButton3, {
1906
+ disabled: !!readonly,
1907
+ icon: "ph--trash--fill",
1908
+ iconOnly: true,
1909
+ label: t("select-option-delete.button"),
1910
+ onClick: () => handleDelete(item.id)
1911
+ })))))), /* @__PURE__ */ React13.createElement(IconButton3, {
1912
+ variant: "ghost",
1913
+ icon: "ph--plus--regular",
1914
+ label: t("select-option-add.button"),
1915
+ onClick: handleAdd,
1916
+ disabled: !!readonly,
1917
+ classNames: "w-full"
1918
+ })))));
1919
+ };
1920
+
1921
+ // src/components/Form/fields/TextField.tsx
1922
+ import React14, { useCallback as useCallback12 } from "react";
1923
+ import { Input as Input9 } from "@dxos/react-ui";
1924
+ var TextField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
1925
+ const handleChange = useCallback12((event) => onValueChange(type, event.target.value), [
1926
+ type,
1927
+ onValueChange
1928
+ ]);
1929
+ return /* @__PURE__ */ React14.createElement(FormFieldWrapper, {
1930
+ readonly,
1931
+ ...props
1932
+ }, ({ value: value3 = "" }) => /* @__PURE__ */ React14.createElement(Input9.TextInput, {
1933
+ noAutoFill: true,
1934
+ disabled: !!readonly,
1935
+ placeholder,
1936
+ value: value3,
1937
+ onChange: handleChange,
1938
+ onBlur
1939
+ }));
1940
+ };
1941
+
1942
+ // src/components/Form/fields/TextAreaField.tsx
1943
+ import React15, { useCallback as useCallback13 } from "react";
1944
+ import { Input as Input10 } from "@dxos/react-ui";
1945
+ var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
1946
+ const handleChange = useCallback13((event) => onValueChange(type, event.target.value), [
1947
+ type,
1948
+ onValueChange
1949
+ ]);
1950
+ return /* @__PURE__ */ React15.createElement(FormFieldWrapper, {
1951
+ readonly,
1952
+ ...props
1953
+ }, ({ value: value3 = "" }) => /* @__PURE__ */ React15.createElement(Input10.TextArea, {
1954
+ rows: 3,
1955
+ disabled: !!readonly,
1956
+ placeholder,
1957
+ value: value3,
1958
+ onChange: handleChange,
1959
+ onBlur
1960
+ }));
1961
+ };
1962
+
1963
+ // src/components/Form/fields/TupleField.tsx
1964
+ import React16 from "react";
1965
+ import { Input as Input11 } from "@dxos/react-ui";
1966
+ import { mx as mx3 } from "@dxos/ui-theme";
1967
+ import { safeParseFloat as safeParseFloat3 } from "@dxos/util";
1968
+ var gridCols = [
1969
+ "grid-cols-1",
1970
+ "grid-cols-2",
1971
+ "grid-cols-3",
1972
+ "grid-cols-4"
1973
+ ];
1974
+ var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValueChange, onBlur }) => {
1975
+ const { status, error } = getStatus();
1976
+ const values = getValue() ?? {};
1977
+ return /* @__PURE__ */ React16.createElement(Input11.Root, {
1978
+ validationValence: status
1979
+ }, /* @__PURE__ */ React16.createElement(FormFieldLabel, {
1980
+ error,
1981
+ readonly,
1982
+ label
1983
+ }), /* @__PURE__ */ React16.createElement("div", {
1984
+ className: mx3("grid gap-form-gap", gridCols[binding.length - 1])
1985
+ }, binding.map((prop) => /* @__PURE__ */ React16.createElement(Input11.TextInput, {
1986
+ key: prop,
1987
+ type: "number",
1988
+ disabled: !!readonly,
1989
+ value: values[prop],
1990
+ onChange: (event) => {
1991
+ onValueChange(type, {
1992
+ ...values,
1993
+ [prop]: safeParseFloat3(event.target.value, 0)
1994
+ });
1995
+ },
1996
+ onBlur
1997
+ }))));
2156
1998
  };
2157
1999
 
2158
2000
  // src/components/FieldEditor/FieldEditor.tsx
2159
- var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
2160
- var FieldEditor = ({ readonly, projection, field, registry, onSave, onCancel, outerSpacing }) => {
2161
- var _effect = _useSignals14();
2162
- try {
2163
- const { t } = useTranslation9(translationKey);
2164
- const [props, setProps] = useState6(projection.getFieldProjection(field.id).props);
2165
- useEffect8(() => setProps(projection.getFieldProjection(field.id).props), [
2166
- field,
2167
- projection
2168
- ]);
2169
- const [schemas, setSchemas] = useState6([]);
2170
- useAsyncEffect(async () => {
2171
- if (!registry) {
2172
- return;
2001
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
2002
+ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }) => {
2003
+ const { t } = useTranslation8(translationKey);
2004
+ const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
2005
+ useEffect6(() => setProps(projection.getFieldProjection(field.id).props), [
2006
+ field,
2007
+ projection
2008
+ ]);
2009
+ const [schemas, setSchemas] = useState5([]);
2010
+ useAsyncEffect(async () => {
2011
+ if (!registry) {
2012
+ return;
2013
+ }
2014
+ const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
2015
+ fire: true
2016
+ });
2017
+ const schemas2 = await registry.query().run();
2018
+ setSchemas(schemas2);
2019
+ return () => subscription?.();
2020
+ }, [
2021
+ registry
2022
+ ]);
2023
+ const [referenceSchema, setReferenceSchema] = useState5();
2024
+ useEffect6(() => {
2025
+ setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
2026
+ }, [
2027
+ schemas,
2028
+ props?.referenceSchema
2029
+ ]);
2030
+ const [{ fieldSchema }, setFieldSchema] = useState5({
2031
+ fieldSchema: getFormatSchema(props?.format)
2032
+ });
2033
+ const fieldMap = useMemo7(() => ({
2034
+ ["format"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
2035
+ ...props2,
2036
+ options: FormatEnums.filter((value3) => value3 !== Format4.TypeFormat.None).map((value3) => ({
2037
+ value: value3,
2038
+ label: t(`format.${value3}.label`)
2039
+ }))
2040
+ }),
2041
+ ["referenceSchema"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
2042
+ ...props2,
2043
+ options: schemas.map((schema) => ({
2044
+ value: schema.typename
2045
+ }))
2046
+ }),
2047
+ ["referencePath"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
2048
+ ...props2,
2049
+ options: referenceSchema ? getFormProperties(referenceSchema.ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
2050
+ value: p.name.toString()
2051
+ })) : []
2052
+ }),
2053
+ ["options"]: (props2) => /* @__PURE__ */ React17.createElement(SelectOptionField, props2)
2054
+ }), [
2055
+ t,
2056
+ schemas,
2057
+ referenceSchema
2058
+ ]);
2059
+ const propIsNotType = useCallback14((props2) => props2.filter((prop) => prop.name !== "type"), []);
2060
+ const handleValuesChanged = useCallback14((_props) => {
2061
+ setFieldSchema((prev) => {
2062
+ const fieldSchema2 = getFormatSchema(_props.format);
2063
+ if (prev.fieldSchema === fieldSchema2) {
2064
+ return prev;
2173
2065
  }
2174
- const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
2175
- fire: true
2176
- });
2177
- const schemas2 = await registry.query().run();
2178
- setSchemas(schemas2);
2179
- return () => subscription?.();
2180
- }, [
2181
- registry
2182
- ]);
2183
- const [referenceSchema, setReferenceSchema] = useState6();
2184
- useEffect8(() => {
2185
- setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
2186
- }, [
2187
- schemas,
2188
- props?.referenceSchema
2189
- ]);
2190
- const [{ fieldSchema }, setFieldSchema] = useState6({
2191
- fieldSchema: getFormatSchema(props?.format)
2066
+ return {
2067
+ fieldSchema: fieldSchema2
2068
+ };
2192
2069
  });
2193
- const handleValuesChanged = useCallback12((_props) => {
2194
- setFieldSchema((prev) => {
2195
- const fieldSchema2 = getFormatSchema(_props.format);
2196
- if (prev.fieldSchema === fieldSchema2) {
2197
- return prev;
2070
+ setReferenceSchema((prev) => {
2071
+ if (_props.referenceSchema !== prev?.typename) {
2072
+ const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
2073
+ if (newSchema) {
2074
+ return newSchema;
2198
2075
  }
2076
+ }
2077
+ return prev;
2078
+ });
2079
+ setProps((props2) => {
2080
+ const type = formatToType[_props.format];
2081
+ const additionalProps = formatToAdditionalPropertyAttributes[_props.format];
2082
+ if (props2.type !== type) {
2199
2083
  return {
2200
- fieldSchema: fieldSchema2
2084
+ ...props2,
2085
+ ..._props,
2086
+ ...additionalProps,
2087
+ type
2201
2088
  };
2202
- });
2203
- setReferenceSchema((prev) => {
2204
- if (_props.referenceSchema !== prev?.typename) {
2205
- const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
2206
- if (newSchema) {
2207
- return newSchema;
2208
- }
2209
- }
2210
- return prev;
2211
- });
2212
- setProps((props2) => {
2213
- const type = formatToType[_props.format];
2214
- const additionalProps = formatToAdditionalPropertyAttributes[_props.format];
2215
- if (props2.type !== type) {
2216
- return {
2217
- ...props2,
2218
- ..._props,
2219
- ...additionalProps,
2220
- type
2221
- };
2089
+ }
2090
+ return _props;
2091
+ });
2092
+ }, [
2093
+ schemas,
2094
+ props.format,
2095
+ props.referenceSchema
2096
+ ]);
2097
+ const handleValidate = useCallback14(({ property }) => {
2098
+ if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
2099
+ return [
2100
+ {
2101
+ path: "property",
2102
+ message: `property is not unique: '${property}'`
2222
2103
  }
2223
- return _props;
2104
+ ];
2105
+ }
2106
+ }, [
2107
+ projection.getFields(),
2108
+ field
2109
+ ]);
2110
+ const handleSave = useCallback14((props2) => {
2111
+ if (view) {
2112
+ Obj2.change(view, () => {
2113
+ projection.setFieldProjection({
2114
+ field,
2115
+ props: props2
2116
+ });
2224
2117
  });
2225
- }, [
2226
- schemas,
2227
- props.format,
2228
- props.referenceSchema
2229
- ]);
2230
- const handleValidate = useCallback12(({ property }) => {
2231
- if (property && projection.fields.find((f) => f.path === property && f.path !== field.path)) {
2232
- return [
2233
- {
2234
- path: "property",
2235
- message: `property is not unique: '${property}'`
2236
- }
2237
- ];
2238
- }
2239
- }, [
2240
- projection.fields,
2241
- field
2242
- ]);
2243
- const handleSave = useCallback12((props2) => {
2118
+ } else {
2244
2119
  projection.setFieldProjection({
2245
2120
  field,
2246
2121
  props: props2
2247
2122
  });
2248
- onSave();
2249
- }, [
2250
- projection,
2251
- field,
2252
- onSave
2253
- ]);
2254
- const handleCancel = useCallback12(() => {
2255
- requestAnimationFrame(() => onCancel?.());
2256
- onSave();
2257
- }, [
2258
- onSave
2259
- ]);
2260
- const custom = useMemo7(() => ({
2261
- ["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
2262
- ...props2,
2263
- options: FormatEnums.filter((value2) => value2 !== FormatEnum5.None).map((value2) => ({
2264
- value: value2,
2265
- label: t(`format ${value2}`)
2266
- }))
2267
- }),
2268
- ["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
2269
- ...props2,
2270
- options: schemas.map((schema) => ({
2271
- value: schema.typename
2272
- }))
2273
- }),
2274
- ["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
2275
- ...props2,
2276
- options: referenceSchema ? getSchemaProperties3(referenceSchema.ast).sort(sortProperties).map((p) => ({
2277
- value: p.name
2278
- })) : []
2279
- }),
2280
- ["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
2281
- }), [
2282
- t,
2283
- schemas,
2284
- referenceSchema
2285
- ]);
2286
- const propIsNotType = useCallback12((props2) => props2.filter((p) => p.name !== "type"), []);
2287
- if (!fieldSchema) {
2288
- log3.warn("invalid format", {
2289
- props
2290
- }, {
2291
- F: __dxlog_file4,
2292
- L: 180,
2293
- S: void 0,
2294
- C: (f, a) => f(...a)
2295
- });
2296
- return null;
2297
2123
  }
2298
- return /* @__PURE__ */ React14.createElement(Form, {
2299
- key: field.id,
2300
- autoFocus: true,
2301
- readonly,
2302
- values: props,
2303
- schema: fieldSchema,
2304
- filter: propIsNotType,
2305
- sort: [
2306
- "property",
2307
- "format"
2308
- ],
2309
- onValuesChanged: handleValuesChanged,
2310
- onValidate: handleValidate,
2311
- onSave: handleSave,
2312
- onCancel: handleCancel,
2313
- Custom: custom,
2314
- outerSpacing
2124
+ onSave();
2125
+ }, [
2126
+ projection,
2127
+ field,
2128
+ view,
2129
+ onSave
2130
+ ]);
2131
+ const handleCancel = useCallback14(() => {
2132
+ onSave();
2133
+ requestAnimationFrame(() => onCancel?.());
2134
+ }, [
2135
+ onSave
2136
+ ]);
2137
+ if (!fieldSchema) {
2138
+ log2.warn("invalid format", {
2139
+ props
2140
+ }, {
2141
+ F: __dxlog_file2,
2142
+ L: 172,
2143
+ S: void 0,
2144
+ C: (f, a) => f(...a)
2315
2145
  });
2316
- } finally {
2317
- _effect.f();
2146
+ return null;
2318
2147
  }
2148
+ return /* @__PURE__ */ React17.createElement(Form.Root, {
2149
+ key: field.id,
2150
+ fieldMap,
2151
+ autoFocus: true,
2152
+ readonly,
2153
+ schema: fieldSchema,
2154
+ values: props,
2155
+ exclude: propIsNotType,
2156
+ sort: [
2157
+ "property",
2158
+ "format"
2159
+ ],
2160
+ onValuesChanged: handleValuesChanged,
2161
+ onValidate: handleValidate,
2162
+ onSave: handleSave,
2163
+ onCancel: handleCancel
2164
+ }, /* @__PURE__ */ React17.createElement(Form.Content, null, /* @__PURE__ */ React17.createElement(Form.FieldSet, null), /* @__PURE__ */ React17.createElement(Form.Actions, null)));
2165
+ };
2166
+
2167
+ // src/components/Settings/Settings.tsx
2168
+ import React18 from "react";
2169
+ import { Input as Input12, ScrollArea as ScrollArea2, toLocalizedString, useTranslation as useTranslation9 } from "@dxos/react-ui";
2170
+ import { composable as composable2, composableProps as composableProps2, mx as mx4 } from "@dxos/ui-theme";
2171
+ var SETTINGS_ROOT_NAME = "Settings.Root";
2172
+ var SETTINGS_VIEWPORT_NAME = "Settings.Viewport";
2173
+ var SETTINGS_SECTION_NAME = "Settings.Section";
2174
+ var SETTINGS_PANEL_NAME = "Settings.Panel";
2175
+ var SETTINGS_ITEM_NAME = "Settings.Item";
2176
+ var SettingsRoot = ({ children, classNames }) => {
2177
+ return /* @__PURE__ */ React18.createElement("div", {
2178
+ className: mx4("flex flex-col gap-2", classNames)
2179
+ }, children);
2180
+ };
2181
+ SettingsRoot.displayName = SETTINGS_ROOT_NAME;
2182
+ var SettingsViewport = composable2(({ children, ...props }, forwardedRef) => {
2183
+ return /* @__PURE__ */ React18.createElement(ScrollArea2.Root, {
2184
+ ...composableProps2(props),
2185
+ orientation: "vertical",
2186
+ centered: true,
2187
+ thin: true,
2188
+ ref: forwardedRef
2189
+ }, /* @__PURE__ */ React18.createElement(ScrollArea2.Viewport, {
2190
+ classNames: "px-4 pointer-coarse:px-2"
2191
+ }, /* @__PURE__ */ React18.createElement("div", {
2192
+ role: "none",
2193
+ className: "dx-document flex flex-col gap-2 py-4"
2194
+ }, children)));
2195
+ });
2196
+ SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
2197
+ var SettingsSection = ({ title, description, children }) => {
2198
+ const { t } = useTranslation9(translationKey);
2199
+ return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("h2", {
2200
+ className: "px-trim-md mt-trim-md text-xl"
2201
+ }, toLocalizedString(title, t)), description && /* @__PURE__ */ React18.createElement("p", {
2202
+ className: "px-trim-md text-description"
2203
+ }, toLocalizedString(description, t)), /* @__PURE__ */ React18.createElement("div", {
2204
+ className: "w-full pt-trim-md space-y-trim-md"
2205
+ }, children));
2206
+ };
2207
+ SettingsSection.displayName = SETTINGS_SECTION_NAME;
2208
+ var SettingsPanel = ({ classNames, children }) => {
2209
+ return /* @__PURE__ */ React18.createElement("div", {
2210
+ role: "none",
2211
+ className: mx4("flex flex-col gap-3 p-trim-md border border-separator rounded-sm", classNames)
2212
+ }, children);
2213
+ };
2214
+ SettingsPanel.displayName = SETTINGS_PANEL_NAME;
2215
+ var SettingsItem = ({ title, description = "", children }) => {
2216
+ const { t } = useTranslation9(translationKey);
2217
+ return /* @__PURE__ */ React18.createElement(Input12.Root, null, /* @__PURE__ */ React18.createElement(SettingsPanel, {
2218
+ classNames: "grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0"
2219
+ }, /* @__PURE__ */ React18.createElement(Input12.Label, {
2220
+ classNames: "pb-trim-md text-base-surface-text text-lg md:col-span-2"
2221
+ }, toLocalizedString(title, t)), /* @__PURE__ */ React18.createElement(Input12.DescriptionAndValidation, null, /* @__PURE__ */ React18.createElement(Input12.Description, {
2222
+ classNames: "text-base text-description"
2223
+ }, toLocalizedString(description, t))), /* @__PURE__ */ React18.createElement("div", {
2224
+ role: "none",
2225
+ className: "text-end py-1"
2226
+ }, children)));
2227
+ };
2228
+ SettingsItem.displayName = SETTINGS_ITEM_NAME;
2229
+ var Settings = {
2230
+ Root: SettingsRoot,
2231
+ Viewport: SettingsViewport,
2232
+ Section: SettingsSection,
2233
+ Panel: SettingsPanel,
2234
+ Item: SettingsItem
2319
2235
  };
2320
2236
 
2321
2237
  // src/components/ViewEditor/ViewEditor.tsx
2322
- import { useSignals as _useSignals15 } from "@preact-signals/safe-react/tracking";
2238
+ import { RegistryContext } from "@effect-atom/atom-react";
2323
2239
  import * as Array2 from "effect/Array";
2324
- import * as Match from "effect/Match";
2325
- import * as Option from "effect/Option";
2326
- import * as Schema2 from "effect/Schema";
2327
- import React15, { forwardRef as forwardRef3, useCallback as useCallback13, useImperativeHandle, useMemo as useMemo8, useState as useState7 } from "react";
2328
- import { QueryAST } from "@dxos/echo";
2329
- import { EchoSchema, Format, isMutable, toJsonSchema } from "@dxos/echo/internal";
2330
- import { Filter as Filter2, Query } from "@dxos/echo-db";
2331
- import { invariant as invariant3 } from "@dxos/invariant";
2332
- import { Callout, IconButton as IconButton4, Input as Input8, useTranslation as useTranslation10 } from "@dxos/react-ui";
2240
+ import * as Match2 from "effect/Match";
2241
+ import * as Option4 from "effect/Option";
2242
+ import * as Schema3 from "effect/Schema";
2243
+ import React19, { forwardRef as forwardRef2, useCallback as useCallback15, useContext, useImperativeHandle, useMemo as useMemo8, useState as useState6 } from "react";
2244
+ import { Entity as Entity2, Feed, Filter as Filter2, Format as Format5, Obj as Obj3, Query, QueryAST, Ref as Ref3 } from "@dxos/echo";
2245
+ import { View } from "@dxos/echo";
2246
+ import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
2247
+ import { invariant } from "@dxos/invariant";
2248
+ import { useObject, useQuery as useQuery2 } from "@dxos/react-client/echo";
2249
+ import { IconButton as IconButton4, Input as Input13, Message, useTranslation as useTranslation10 } from "@dxos/react-ui";
2333
2250
  import { QueryForm } from "@dxos/react-ui-components";
2334
2251
  import { List as List2 } from "@dxos/react-ui-list";
2335
- import { cardSpacing as cardSpacing3 } from "@dxos/react-ui-stack";
2336
- import { inputTextLabel, mx as mx7, subtleHover as subtleHover2 } from "@dxos/react-ui-theme";
2337
- import { FieldSchema, ProjectionModel, VIEW_FIELD_LIMIT, getTypenameFromQuery } from "@dxos/schema";
2338
- var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
2339
- var listGrid = "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]";
2340
- var listItemGrid = "grid grid-cols-subgrid col-span-5";
2341
- var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode = "schema", registry, readonly, showHeading = false, types, tags, onQueryChanged, onDelete, outerSpacing = true }, forwardedRef) => {
2342
- var _effect = _useSignals15();
2343
- try {
2344
- const schemaReadonly = !isMutable(schema);
2345
- const { t } = useTranslation10(translationKey);
2346
- const projectionModel = useMemo8(() => {
2347
- const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
2348
- return new ProjectionModel(jsonSchema, view.projection);
2349
- }, [
2350
- schema,
2351
- JSON.stringify(view.projection)
2352
- ]);
2353
- useImperativeHandle(forwardedRef, () => projectionModel, [
2354
- projectionModel
2355
- ]);
2356
- const [expandedField, setExpandedField] = useState7();
2357
- const queueTarget = Match.value(view.query.ast).pipe(Match.when({
2358
- type: "options"
2359
- }, ({ options }) => {
2360
- return Option.fromNullable(options.queues).pipe(Option.flatMap((queues) => Array2.head(queues)), Option.getOrUndefined);
2361
- }), Match.orElse(() => void 0));
2362
- const viewSchema = useMemo8(() => {
2363
- const base = Schema2.Struct({
2364
- query: mode === "schema" ? Format.URL.annotations({
2365
- title: "Record type"
2366
- }) : QueryAST.Query.annotations({
2367
- title: "Query"
2368
- })
2369
- });
2370
- if (mode === "query" || mode === "named-query") {
2371
- const name = Schema2.Struct({
2372
- name: Schema2.optional(Schema2.String.annotations({
2373
- title: "Name"
2374
- }))
2375
- });
2376
- return Schema2.Struct({
2377
- ...mode === "named-query" ? {
2378
- ...name.fields,
2379
- ...base.fields
2380
- } : base.fields,
2381
- target: Schema2.optional(Schema2.String.annotations({
2382
- title: "Target Queue"
2383
- }))
2384
- }).pipe(Schema2.mutable);
2385
- }
2386
- return base.pipe(Schema2.mutable);
2387
- }, [
2388
- mode
2389
- ]);
2390
- const viewValues = useMemo8(() => ({
2391
- name: view.name,
2392
- query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
2393
- target: queueTarget
2394
- }), [
2395
- view.name,
2396
- mode,
2397
- view.query.ast,
2398
- queueTarget
2399
- ]);
2400
- const handleToggleField = useCallback13((field) => {
2401
- setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
2402
- }, [
2403
- readonly
2404
- ]);
2405
- const handleAdd = useCallback13(() => {
2406
- invariant3(!readonly, void 0, {
2407
- F: __dxlog_file5,
2408
- L: 134,
2409
- S: void 0,
2410
- A: [
2411
- "!readonly",
2412
- ""
2413
- ]
2414
- });
2415
- const field = projectionModel.createFieldProjection();
2416
- setExpandedField(field.id);
2417
- }, [
2418
- schema,
2419
- projectionModel,
2420
- readonly
2421
- ]);
2422
- const handleUpdate = useCallback13((values) => {
2423
- invariant3(!readonly, void 0, {
2424
- F: __dxlog_file5,
2425
- L: 141,
2426
- S: void 0,
2427
- A: [
2428
- "!readonly",
2429
- ""
2430
- ]
2431
- });
2432
- requestAnimationFrame(() => {
2433
- if ("name" in values && view.name !== values.name) {
2434
- view.name = values.name;
2435
- return;
2436
- }
2437
- const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : values.query;
2438
- onQueryChanged?.(query, values.target);
2439
- });
2440
- }, [
2441
- onQueryChanged,
2442
- readonly,
2252
+ import { ParentLabelAnnotation, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
2253
+ import { mx as mx5, osTranslations as osTranslations2, subtleHover as subtleHover2 } from "@dxos/ui-theme";
2254
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
2255
+ var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode = "schema", registry, db, readonly, showHeading = false, types, tags, onQueryChanged, onDelete }, forwardedRef) => {
2256
+ const atomRegistry = useContext(RegistryContext);
2257
+ const schemaReadonly = !isMutable(schema);
2258
+ const { t } = useTranslation10(translationKey);
2259
+ const projectionModel = useMemo8(() => {
2260
+ const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
2261
+ const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
2262
+ const model = new ProjectionModel({
2263
+ registry: atomRegistry,
2443
2264
  view,
2444
- queueTarget,
2445
- mode
2446
- ]);
2447
- const handleDelete = useCallback13((fieldId) => {
2448
- invariant3(!readonly, void 0, {
2449
- F: __dxlog_file5,
2450
- L: 157,
2451
- S: void 0,
2452
- A: [
2453
- "!readonly",
2454
- ""
2455
- ]
2456
- });
2457
- if (fieldId === expandedField) {
2458
- setExpandedField(void 0);
2265
+ baseSchema: jsonSchema,
2266
+ change
2267
+ });
2268
+ return model;
2269
+ }, [
2270
+ atomRegistry,
2271
+ schema,
2272
+ view
2273
+ ]);
2274
+ useImperativeHandle(forwardedRef, () => projectionModel, [
2275
+ projectionModel
2276
+ ]);
2277
+ const queueTarget = Match2.value(view.query.ast).pipe(Match2.when({
2278
+ type: "from"
2279
+ }, ({ from }) => {
2280
+ if (from._tag !== "scope") {
2281
+ return void 0;
2282
+ }
2283
+ return Option4.fromNullable(from.scope.queues).pipe(Option4.flatMap((queues) => Array2.head(queues)), Option4.map(String), Option4.getOrUndefined);
2284
+ }), Match2.orElse(() => void 0));
2285
+ const feeds = useQuery2(db, Filter2.type(Feed.Feed));
2286
+ const targetRef = useMemo8(() => {
2287
+ if (!queueTarget) {
2288
+ return void 0;
2289
+ }
2290
+ const feed = feeds.find((feed2) => Feed.getQueueDxn(feed2)?.toString() === queueTarget);
2291
+ return feed ? Ref3.fromDXN(Entity2.getDXN(feed)) : void 0;
2292
+ }, [
2293
+ queueTarget,
2294
+ feeds
2295
+ ]);
2296
+ const viewSchema = useMemo8(() => {
2297
+ const base = Schema3.Struct({
2298
+ query: mode === "schema" ? Format5.URL.annotations({
2299
+ title: "Record type"
2300
+ }) : QueryAST.Query.annotations({
2301
+ title: "Query"
2302
+ })
2303
+ });
2304
+ if (mode === "tag") {
2305
+ return Schema3.Struct({
2306
+ ...base.fields,
2307
+ // TODO(wittjosiah): Replace Type.Feed with Dataset.Dataset when Ref.Ref supports unions.
2308
+ target: Ref3.Ref(Feed.Feed).pipe(Schema3.annotations({
2309
+ title: "Target Feed"
2310
+ }), ParentLabelAnnotation.set(true), Schema3.optional)
2311
+ }).pipe(Schema3.mutable);
2312
+ }
2313
+ return base.pipe(Schema3.mutable);
2314
+ }, [
2315
+ mode
2316
+ ]);
2317
+ const viewValues = useMemo8(() => ({
2318
+ query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
2319
+ target: targetRef
2320
+ }), [
2321
+ mode,
2322
+ view.query.ast,
2323
+ targetRef
2324
+ ]);
2325
+ const fieldMap = useMemo8(() => mode === "tag" ? customFields({
2326
+ types,
2327
+ tags
2328
+ }) : void 0, [
2329
+ mode,
2330
+ types,
2331
+ tags
2332
+ ]);
2333
+ const handleUpdate = useCallback15((values) => {
2334
+ const targetValue = values.target;
2335
+ let queueDxn;
2336
+ if (Ref3.isRef(targetValue)) {
2337
+ const feedDxn = targetValue.dxn.toString();
2338
+ const feed = feeds.find((feed2) => Obj3.getDXN(feed2).toString() === feedDxn);
2339
+ if (feed) {
2340
+ queueDxn = Feed.getQueueDxn(feed)?.toString();
2459
2341
  }
2460
- onDelete?.(fieldId);
2461
- }, [
2462
- expandedField,
2463
- onDelete,
2464
- readonly
2465
- ]);
2466
- const handleMove = useCallback13((fromIndex, toIndex) => {
2467
- invariant3(!readonly, void 0, {
2468
- F: __dxlog_file5,
2469
- L: 169,
2470
- S: void 0,
2471
- A: [
2472
- "!readonly",
2473
- ""
2474
- ]
2475
- });
2342
+ }
2343
+ const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : JSON.parse(JSON.stringify(values.query));
2344
+ onQueryChanged?.(query, queueDxn);
2345
+ }, [
2346
+ onQueryChanged,
2347
+ mode,
2348
+ feeds
2349
+ ]);
2350
+ const handleDelete = useCallback15((fieldId) => {
2351
+ invariant(!readonly, void 0, {
2352
+ F: __dxlog_file3,
2353
+ L: 185,
2354
+ S: void 0,
2355
+ A: [
2356
+ "!readonly",
2357
+ ""
2358
+ ]
2359
+ });
2360
+ onDelete?.(fieldId);
2361
+ }, [
2362
+ onDelete,
2363
+ readonly
2364
+ ]);
2365
+ return /* @__PURE__ */ React19.createElement("div", {
2366
+ role: "none",
2367
+ className: mx5(classNames)
2368
+ }, schemaReadonly && !readonly && /* @__PURE__ */ React19.createElement(Message.Root, {
2369
+ valence: "info",
2370
+ classNames: "my-form-padding"
2371
+ }, /* @__PURE__ */ React19.createElement(Message.Title, null, t("system-schema.description"))), /* @__PURE__ */ React19.createElement(Form.Root, {
2372
+ schema: viewSchema,
2373
+ values: viewValues,
2374
+ fieldMap,
2375
+ db,
2376
+ onValuesChanged: handleUpdate
2377
+ }, /* @__PURE__ */ React19.createElement(Form.FieldSet, null), /* @__PURE__ */ React19.createElement(FormFieldLabel, {
2378
+ label: t("fields.label"),
2379
+ asChild: true
2380
+ }), /* @__PURE__ */ React19.createElement(FieldList, {
2381
+ schema,
2382
+ view,
2383
+ registry,
2384
+ readonly,
2385
+ showHeading,
2386
+ onDelete: handleDelete
2387
+ })));
2388
+ });
2389
+ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDelete }) => {
2390
+ const atomRegistry = useContext(RegistryContext);
2391
+ const schemaReadonly = !isMutable(schema);
2392
+ const { t } = useTranslation10(translationKey);
2393
+ const [viewSnapshot] = useObject(view);
2394
+ const projectionModel = useMemo8(() => {
2395
+ const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
2396
+ const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
2397
+ const model = new ProjectionModel({
2398
+ registry: atomRegistry,
2399
+ view,
2400
+ baseSchema: jsonSchema,
2401
+ change
2402
+ });
2403
+ return model;
2404
+ }, [
2405
+ atomRegistry,
2406
+ schema,
2407
+ view
2408
+ ]);
2409
+ const [expandedField, setExpandedField] = useState6();
2410
+ const handleAdd = useCallback15(() => {
2411
+ invariant(!readonly, void 0, {
2412
+ F: __dxlog_file3,
2413
+ L: 250,
2414
+ S: void 0,
2415
+ A: [
2416
+ "!readonly",
2417
+ ""
2418
+ ]
2419
+ });
2420
+ const field = projectionModel.createFieldProjection();
2421
+ setExpandedField(field.id);
2422
+ }, [
2423
+ projectionModel,
2424
+ readonly
2425
+ ]);
2426
+ const handleToggleField = useCallback15((field) => {
2427
+ setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
2428
+ }, [
2429
+ readonly
2430
+ ]);
2431
+ const handleDelete = useCallback15((fieldId) => {
2432
+ invariant(!readonly, void 0, {
2433
+ F: __dxlog_file3,
2434
+ L: 264,
2435
+ S: void 0,
2436
+ A: [
2437
+ "!readonly",
2438
+ ""
2439
+ ]
2440
+ });
2441
+ if (fieldId === expandedField) {
2442
+ setExpandedField(void 0);
2443
+ }
2444
+ onDelete?.(fieldId);
2445
+ }, [
2446
+ expandedField,
2447
+ onDelete,
2448
+ readonly
2449
+ ]);
2450
+ const handleMove = useCallback15((fromIndex, toIndex) => {
2451
+ invariant(!readonly, void 0, {
2452
+ F: __dxlog_file3,
2453
+ L: 276,
2454
+ S: void 0,
2455
+ A: [
2456
+ "!readonly",
2457
+ ""
2458
+ ]
2459
+ });
2460
+ Obj3.change(view, (obj) => {
2476
2461
  const fields = [
2477
- ...view.projection.fields
2462
+ ...obj.projection.fields
2478
2463
  ];
2479
2464
  const [moved] = fields.splice(fromIndex, 1);
2480
2465
  fields.splice(toIndex, 0, moved);
2481
- view.projection.fields = fields;
2482
- }, [
2483
- view.projection.fields,
2484
- readonly
2485
- ]);
2486
- const handleClose = useCallback13(() => setExpandedField(void 0), []);
2487
- const handleHide = useCallback13((fieldId) => {
2488
- setExpandedField(void 0);
2489
- projectionModel.hideFieldProjection(fieldId);
2490
- }, [
2491
- projectionModel
2492
- ]);
2493
- const handleShow = useCallback13((property) => {
2494
- setExpandedField(void 0);
2495
- projectionModel.showFieldProjection(property);
2496
- }, [
2497
- projectionModel
2498
- ]);
2499
- const custom = useMemo8(() => mode === "query" ? customFields({
2500
- types,
2501
- tags
2502
- }) : void 0, [
2503
- types,
2504
- tags,
2505
- mode
2506
- ]);
2507
- return /* @__PURE__ */ React15.createElement("div", {
2508
- role: "none",
2509
- className: mx7(classNames)
2510
- }, schemaReadonly && mode === "schema" && /* @__PURE__ */ React15.createElement(Callout.Root, {
2511
- valence: "info",
2512
- classNames: [
2513
- "mlb-cardSpacingBlock",
2514
- outerSpacing && "mli-cardSpacingInline"
2515
- ]
2516
- }, /* @__PURE__ */ React15.createElement(Callout.Title, null, t("system schema description"))), /* @__PURE__ */ React15.createElement(Form, {
2517
- autoSave: true,
2518
- schema: viewSchema,
2519
- values: viewValues,
2520
- readonly: readonly ? "disabled-input" : false,
2521
- onSave: handleUpdate,
2522
- outerSpacing,
2523
- Custom: custom
2524
- }), /* @__PURE__ */ React15.createElement("div", {
2466
+ obj.projection.fields = fields;
2467
+ });
2468
+ }, [
2469
+ view,
2470
+ readonly
2471
+ ]);
2472
+ const handleClose = useCallback15(() => setExpandedField(void 0), []);
2473
+ const handleHide = useCallback15((fieldId) => {
2474
+ setExpandedField(void 0);
2475
+ projectionModel.hideFieldProjection(fieldId);
2476
+ }, [
2477
+ projectionModel
2478
+ ]);
2479
+ const handleShow = useCallback15((property) => {
2480
+ setExpandedField(void 0);
2481
+ projectionModel.showFieldProjection(property);
2482
+ }, [
2483
+ projectionModel
2484
+ ]);
2485
+ if (!viewSnapshot) {
2486
+ return null;
2487
+ }
2488
+ return /* @__PURE__ */ React19.createElement(List2.Root, {
2489
+ items: viewSnapshot.projection.fields,
2490
+ isItem: Schema3.is(View.FieldSchema),
2491
+ getId: (field) => field.id,
2492
+ onMove: readonly ? void 0 : handleMove,
2493
+ readonly
2494
+ }, ({ items: fields }) => /* @__PURE__ */ React19.createElement(React19.Fragment, null, showHeading && /* @__PURE__ */ React19.createElement("h3", {
2495
+ className: "text-sm"
2496
+ }, t("field-path.label")), /* @__PURE__ */ React19.createElement("div", {
2497
+ role: "list",
2498
+ className: "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]"
2499
+ }, fields?.map((field) => {
2500
+ const hidden = field.visible === false;
2501
+ return /* @__PURE__ */ React19.createElement(List2.Item, {
2502
+ key: field.id,
2503
+ item: field,
2504
+ classNames: "grid grid-cols-subgrid col-span-5",
2505
+ "aria-expanded": expandedField === field.id
2506
+ }, /* @__PURE__ */ React19.createElement("div", {
2525
2507
  role: "none",
2526
- className: outerSpacing ? cardSpacing3 : "mlb-cardSpacingBlock"
2527
- }, /* @__PURE__ */ React15.createElement("h2", {
2528
- className: mx7(inputTextLabel)
2529
- }, t("fields label")), /* @__PURE__ */ React15.createElement(List2.Root, {
2530
- items: view.projection.fields,
2531
- isItem: Schema2.is(FieldSchema),
2532
- getId: (field) => field.id,
2533
- onMove: readonly ? void 0 : handleMove,
2534
- readonly
2535
- }, ({ items: fields }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, showHeading && /* @__PURE__ */ React15.createElement("h3", {
2536
- className: "text-sm"
2537
- }, t("field path label")), /* @__PURE__ */ React15.createElement("div", {
2538
- role: "list",
2539
- className: listGrid
2540
- }, fields?.map((field) => {
2541
- const hidden = field.visible === false;
2542
- return /* @__PURE__ */ React15.createElement(List2.Item, {
2543
- key: field.id,
2544
- item: field,
2545
- classNames: listItemGrid,
2546
- "aria-expanded": expandedField === field.id
2547
- }, /* @__PURE__ */ React15.createElement("div", {
2548
- role: "none",
2549
- className: mx7(subtleHover2, listItemGrid, "rounded-sm cursor-pointer min-bs-10")
2550
- }, /* @__PURE__ */ React15.createElement(List2.ItemDragHandle, {
2551
- disabled: readonly
2552
- }), /* @__PURE__ */ React15.createElement(List2.ItemTitle, {
2553
- classNames: hidden && "text-subdued",
2554
- onClick: () => handleToggleField(field)
2555
- }, field.path), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
2556
- label: t(hidden ? "show field label" : "hide field label"),
2557
- "data-testid": hidden ? "show-field-button" : "hide-field-button",
2558
- icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
2559
- autoHide: false,
2560
- disabled: readonly || !hidden && projectionModel.fields.length <= 1,
2561
- onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
2562
- }), mode === "schema" && /* @__PURE__ */ React15.createElement(React15.Fragment, null, /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
2563
- label: t("delete field label"),
2564
- autoHide: false,
2565
- disabled: readonly || schemaReadonly || view.projection.fields.length <= 1,
2566
- onClick: () => handleDelete(field.id),
2567
- "data-testid": "field.delete"
2568
- }), /* @__PURE__ */ React15.createElement(IconButton4, {
2569
- iconOnly: true,
2570
- variant: "ghost",
2571
- label: t("toggle expand label", {
2572
- ns: "os"
2573
- }),
2574
- icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
2575
- onClick: () => handleToggleField(field)
2576
- }))), expandedField === field.id && mode === "schema" && /* @__PURE__ */ React15.createElement("div", {
2577
- role: "none",
2578
- className: "col-span-5 mbs-1 mbe-1 border border-separator rounded-md"
2579
- }, /* @__PURE__ */ React15.createElement(FieldEditor, {
2580
- readonly: readonly || schemaReadonly ? "disabled-input" : false,
2581
- projection: projectionModel,
2582
- field,
2583
- registry,
2584
- onSave: handleClose
2585
- })));
2586
- }))))), !readonly && !expandedField && mode === "schema" && /* @__PURE__ */ React15.createElement("div", {
2508
+ className: mx5(subtleHover2, "grid grid-cols-subgrid col-span-5", "rounded-xs cursor-pointer min-h-10")
2509
+ }, /* @__PURE__ */ React19.createElement(List2.ItemDragHandle, {
2510
+ disabled: readonly || schemaReadonly
2511
+ }), /* @__PURE__ */ React19.createElement(List2.ItemTitle, {
2512
+ classNames: hidden && "text-subdued",
2513
+ onClick: () => handleToggleField(field)
2514
+ }, field.path), /* @__PURE__ */ React19.createElement(List2.ItemIconButton, {
2515
+ label: t(hidden ? "show field label" : "hide field label"),
2516
+ "data-testid": hidden ? "show-field-button" : "hide-field-button",
2517
+ icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
2518
+ autoHide: false,
2519
+ disabled: readonly || !hidden && projectionModel.getFields().length <= 1,
2520
+ onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
2521
+ }), !readonly && /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(List2.ItemDeleteButton, {
2522
+ label: t("delete-field.label"),
2523
+ autoHide: false,
2524
+ disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
2525
+ onClick: () => handleDelete(field.id),
2526
+ "data-testid": "field.delete"
2527
+ }), /* @__PURE__ */ React19.createElement(List2.ItemIconButton, {
2528
+ iconOnly: true,
2529
+ variant: "ghost",
2530
+ label: t("toggle-expand.label", {
2531
+ ns: osTranslations2
2532
+ }),
2533
+ icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
2534
+ onClick: () => handleToggleField(field),
2535
+ "data-testid": "field.toggle"
2536
+ }))), expandedField === field.id && !readonly && /* @__PURE__ */ React19.createElement("div", {
2587
2537
  role: "none",
2588
- className: outerSpacing ? cardSpacing3 : "mlb-cardSpacingBlock"
2589
- }, /* @__PURE__ */ React15.createElement(IconButton4, {
2590
- icon: "ph--plus--regular",
2591
- label: t("add property button"),
2592
- onClick: readonly ? void 0 : handleAdd,
2593
- // TODO(burdon): Show field limit in ux (not tooltip).
2594
- disabled: view.projection.fields.length >= VIEW_FIELD_LIMIT,
2595
- classNames: "is-full"
2538
+ className: "col-span-5 mt-1 mb-1 border border-separator rounded-md"
2539
+ }, /* @__PURE__ */ React19.createElement(FieldEditor, {
2540
+ readonly: readonly || schemaReadonly,
2541
+ registry,
2542
+ projection: projectionModel,
2543
+ field,
2544
+ onSave: handleClose
2596
2545
  })));
2597
- } finally {
2598
- _effect.f();
2599
- }
2600
- });
2546
+ })), !readonly && !expandedField && /* @__PURE__ */ React19.createElement("div", {
2547
+ role: "none",
2548
+ className: "my-form-padding"
2549
+ }, /* @__PURE__ */ React19.createElement(IconButton4, {
2550
+ icon: "ph--plus--regular",
2551
+ label: t("add-property-button.label"),
2552
+ onClick: handleAdd,
2553
+ disabled: viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT,
2554
+ classNames: "w-full"
2555
+ }))));
2556
+ };
2601
2557
  var customFields = ({ types, tags }) => ({
2602
- query: (props) => {
2603
- const handleChange = useCallback13((query) => props.onValueChange("object", query.ast), [
2604
- props.onValueChange
2558
+ query: ({ type, readonly, label, getValue, onValueChange }) => {
2559
+ const handleChange = useCallback15((query) => onValueChange(type, query.ast), [
2560
+ onValueChange
2605
2561
  ]);
2606
- return /* @__PURE__ */ React15.createElement(Input8.Root, null, /* @__PURE__ */ React15.createElement(InputHeader, {
2607
- label: props.label
2608
- }), /* @__PURE__ */ React15.createElement(QueryForm, {
2609
- initialQuery: props.getValue(),
2562
+ return /* @__PURE__ */ React19.createElement(Input13.Root, null, /* @__PURE__ */ React19.createElement(FormFieldLabel, {
2563
+ readonly,
2564
+ label
2565
+ }), /* @__PURE__ */ React19.createElement(QueryForm, {
2566
+ initialQuery: getValue(),
2610
2567
  types,
2611
2568
  tags,
2612
2569
  onChange: handleChange
@@ -2614,43 +2571,39 @@ var customFields = ({ types, tags }) => ({
2614
2571
  }
2615
2572
  });
2616
2573
  export {
2617
- BooleanInput,
2618
- ControlFrame,
2619
- ControlFrameItem,
2620
- ControlGroup,
2621
- ControlGroupButton,
2622
- ControlItem,
2623
- ControlItemInput,
2624
- ControlPage,
2625
- ControlSection,
2626
- ControlSectionHeading,
2574
+ ArrayField,
2575
+ BooleanField,
2627
2576
  FieldEditor,
2628
2577
  Form,
2629
- FormProvider,
2630
- GeoPointInput,
2631
- InputHeader,
2632
- MarkdownInput,
2633
- NumberInput,
2578
+ FormFieldErrorBoundary,
2579
+ FormFieldLabel,
2580
+ FormFieldWrapper,
2581
+ GeoPointField,
2582
+ MarkdownField,
2583
+ NumberField,
2634
2584
  ObjectPicker,
2635
- SelectInput,
2636
- SelectOptionInput,
2637
- TextInput,
2638
- TupleInput,
2585
+ RefField,
2586
+ SelectField,
2587
+ SelectOptionField,
2588
+ Settings,
2589
+ TextAreaField,
2590
+ TextField,
2591
+ TupleField,
2639
2592
  ViewEditor,
2640
2593
  cellClassesForFieldType,
2641
- controlItemClasses,
2642
- findArrayElementType,
2643
2594
  formatForDisplay,
2644
2595
  formatForEditing,
2596
+ getDefaultValue,
2597
+ getFormProperties,
2645
2598
  getRefProps,
2599
+ omitId,
2646
2600
  parseValue,
2647
2601
  pathNotUniqueError,
2648
2602
  translations,
2649
- useForm,
2650
2603
  useFormContext,
2604
+ useFormFieldState,
2605
+ useFormHandler,
2651
2606
  useFormValues,
2652
- useInputProps,
2653
- useQueryRefOptions,
2654
- useRefQueryLookupHandler
2607
+ useKeyHandler
2655
2608
  };
2656
2609
  //# sourceMappingURL=index.mjs.map