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

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