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

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