@dxos/react-ui-form 0.7.1-staging.599df14

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 (93) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +4 -0
  3. package/dist/lib/browser/index.mjs +1008 -0
  4. package/dist/lib/browser/index.mjs.map +7 -0
  5. package/dist/lib/browser/meta.json +1 -0
  6. package/dist/lib/node/index.cjs +1028 -0
  7. package/dist/lib/node/index.cjs.map +7 -0
  8. package/dist/lib/node/meta.json +1 -0
  9. package/dist/lib/node-esm/index.mjs +1010 -0
  10. package/dist/lib/node-esm/index.mjs.map +7 -0
  11. package/dist/lib/node-esm/meta.json +1 -0
  12. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +16 -0
  13. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -0
  14. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +9 -0
  15. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -0
  16. package/dist/types/src/components/FieldEditor/index.d.ts +2 -0
  17. package/dist/types/src/components/FieldEditor/index.d.ts.map +1 -0
  18. package/dist/types/src/components/Form/Custom.d.ts +4 -0
  19. package/dist/types/src/components/Form/Custom.d.ts.map +1 -0
  20. package/dist/types/src/components/Form/Defaults.d.ts +7 -0
  21. package/dist/types/src/components/Form/Defaults.d.ts.map +1 -0
  22. package/dist/types/src/components/Form/Form.d.ts +26 -0
  23. package/dist/types/src/components/Form/Form.d.ts.map +1 -0
  24. package/dist/types/src/components/Form/Form.stories.d.ts +38 -0
  25. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -0
  26. package/dist/types/src/components/Form/Input.d.ts +29 -0
  27. package/dist/types/src/components/Form/Input.d.ts.map +1 -0
  28. package/dist/types/src/components/Form/factory.d.ts +8 -0
  29. package/dist/types/src/components/Form/factory.d.ts.map +1 -0
  30. package/dist/types/src/components/Form/index.d.ts +5 -0
  31. package/dist/types/src/components/Form/index.d.ts.map +1 -0
  32. package/dist/types/src/components/ViewEditor/Test.stories.d.ts +10 -0
  33. package/dist/types/src/components/ViewEditor/Test.stories.d.ts.map +1 -0
  34. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +18 -0
  35. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -0
  36. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +8 -0
  37. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -0
  38. package/dist/types/src/components/ViewEditor/index.d.ts +2 -0
  39. package/dist/types/src/components/ViewEditor/index.d.ts.map +1 -0
  40. package/dist/types/src/components/deprecated/Form.d.ts +15 -0
  41. package/dist/types/src/components/deprecated/Form.d.ts.map +1 -0
  42. package/dist/types/src/components/deprecated/Form.stories.d.ts +13 -0
  43. package/dist/types/src/components/deprecated/Form.stories.d.ts.map +1 -0
  44. package/dist/types/src/components/deprecated/FormInput.d.ts +11 -0
  45. package/dist/types/src/components/deprecated/FormInput.d.ts.map +1 -0
  46. package/dist/types/src/components/deprecated/index.d.ts +2 -0
  47. package/dist/types/src/components/deprecated/index.d.ts.map +1 -0
  48. package/dist/types/src/components/index.d.ts +5 -0
  49. package/dist/types/src/components/index.d.ts.map +1 -0
  50. package/dist/types/src/components/testing.d.ts +7 -0
  51. package/dist/types/src/components/testing.d.ts.map +1 -0
  52. package/dist/types/src/hooks/index.d.ts +2 -0
  53. package/dist/types/src/hooks/index.d.ts.map +1 -0
  54. package/dist/types/src/hooks/useForm.d.ts +58 -0
  55. package/dist/types/src/hooks/useForm.d.ts.map +1 -0
  56. package/dist/types/src/index.d.ts +6 -0
  57. package/dist/types/src/index.d.ts.map +1 -0
  58. package/dist/types/src/translations.d.ts +46 -0
  59. package/dist/types/src/translations.d.ts.map +1 -0
  60. package/dist/types/src/util/field.d.ts +22 -0
  61. package/dist/types/src/util/field.d.ts.map +1 -0
  62. package/dist/types/src/util/formatting.d.ts +15 -0
  63. package/dist/types/src/util/formatting.d.ts.map +1 -0
  64. package/dist/types/src/util/index.d.ts +3 -0
  65. package/dist/types/src/util/index.d.ts.map +1 -0
  66. package/package.json +76 -0
  67. package/src/components/FieldEditor/FieldEditor.stories.tsx +56 -0
  68. package/src/components/FieldEditor/FieldEditor.tsx +167 -0
  69. package/src/components/FieldEditor/index.ts +5 -0
  70. package/src/components/Form/Custom.tsx +65 -0
  71. package/src/components/Form/Defaults.tsx +130 -0
  72. package/src/components/Form/Form.stories.tsx +137 -0
  73. package/src/components/Form/Form.tsx +176 -0
  74. package/src/components/Form/Input.tsx +56 -0
  75. package/src/components/Form/factory.tsx +32 -0
  76. package/src/components/Form/index.ts +8 -0
  77. package/src/components/ViewEditor/Test.stories.tsx +45 -0
  78. package/src/components/ViewEditor/ViewEditor.stories.tsx +73 -0
  79. package/src/components/ViewEditor/ViewEditor.tsx +158 -0
  80. package/src/components/ViewEditor/index.ts +5 -0
  81. package/src/components/deprecated/Form.stories.tsx +62 -0
  82. package/src/components/deprecated/Form.tsx +119 -0
  83. package/src/components/deprecated/FormInput.tsx +58 -0
  84. package/src/components/deprecated/index.ts +5 -0
  85. package/src/components/index.ts +9 -0
  86. package/src/components/testing.tsx +24 -0
  87. package/src/hooks/index.ts +5 -0
  88. package/src/hooks/useForm.ts +229 -0
  89. package/src/index.ts +11 -0
  90. package/src/translations.ts +59 -0
  91. package/src/util/field.ts +137 -0
  92. package/src/util/formatting.ts +132 -0
  93. package/src/util/index.ts +6 -0
@@ -0,0 +1,1028 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var node_exports = {};
30
+ __export(node_exports, {
31
+ BooleanInput: () => BooleanInput,
32
+ DeprecatedFormInput: () => DeprecatedFormInput,
33
+ FieldEditor: () => FieldEditor,
34
+ Form: () => Form,
35
+ InputHeader: () => InputHeader,
36
+ LatLngInput: () => LatLngInput,
37
+ NumberInput: () => NumberInput,
38
+ SelectInput: () => SelectInput,
39
+ TextInput: () => TextInput,
40
+ ViewEditor: () => ViewEditor,
41
+ cellClassesForFieldType: () => cellClassesForFieldType,
42
+ cellClassesForRowSelection: () => cellClassesForRowSelection,
43
+ formatForDisplay: () => formatForDisplay,
44
+ formatForEditing: () => formatForEditing,
45
+ parseValue: () => parseValue,
46
+ pathNotUniqueError: () => pathNotUniqueError,
47
+ translations: () => translations_default,
48
+ useForm: () => useForm
49
+ });
50
+ module.exports = __toCommonJS(node_exports);
51
+ var import_react = __toESM(require("react"));
52
+ var import_react_ui = require("@dxos/react-ui");
53
+ var import_react2 = __toESM(require("react"));
54
+ var import_echo_schema = require("@dxos/echo-schema");
55
+ var import_log = require("@dxos/log");
56
+ var import_react_ui2 = require("@dxos/react-ui");
57
+ var import_schema = require("@dxos/schema");
58
+ var import_react3 = __toESM(require("react"));
59
+ var import_echo_schema2 = require("@dxos/echo-schema");
60
+ var import_effect = require("@dxos/effect");
61
+ var import_log2 = require("@dxos/log");
62
+ var import_react_ui3 = require("@dxos/react-ui");
63
+ var import_react_ui_theme = require("@dxos/react-ui-theme");
64
+ var import_schema2 = require("@dxos/schema");
65
+ var import_util = require("@dxos/util");
66
+ var import_echo_schema3 = require("@dxos/echo-schema");
67
+ var import_react4 = __toESM(require("react"));
68
+ var import_react_ui4 = require("@dxos/react-ui");
69
+ var import_react5 = __toESM(require("react"));
70
+ var import_react_ui5 = require("@dxos/react-ui");
71
+ var import_react_ui_theme2 = require("@dxos/react-ui-theme");
72
+ var import_react6 = __toESM(require("react"));
73
+ var import_react_ui6 = require("@dxos/react-ui");
74
+ var import_react7 = require("react");
75
+ var import_invariant = require("@dxos/invariant");
76
+ var import_log3 = require("@dxos/log");
77
+ var import_schema3 = require("@dxos/schema");
78
+ var import_react8 = __toESM(require("react"));
79
+ var import_echo_schema4 = require("@dxos/echo-schema");
80
+ var import_react_ui7 = require("@dxos/react-ui");
81
+ var import_react_ui_list = require("@dxos/react-ui-list");
82
+ var import_react_ui_theme3 = require("@dxos/react-ui-theme");
83
+ var import_schema4 = require("@dxos/schema");
84
+ var import_util2 = require("@dxos/util");
85
+ var import_echo_schema5 = require("@dxos/echo-schema");
86
+ var import_echo_schema6 = require("@dxos/echo-schema");
87
+ var translationKey = "react-ui-form";
88
+ var translations_default = [
89
+ {
90
+ "en-US": {
91
+ [translationKey]: {
92
+ "fields label": "Fields",
93
+ // TODO(burdon): Standardize field/property.
94
+ "button add property": "Add property",
95
+ "field property label": "Property",
96
+ "field property placeholder": "Property name",
97
+ "field format label": "Type",
98
+ "field path label": "Field path",
99
+ "add field": "Add field",
100
+ "delete field": "Delete field",
101
+ "field limit reached": "Maximum number of fields reached",
102
+ // TODO(burdon): Factor out?
103
+ "button cancel": "Cancel",
104
+ "button save": "Save",
105
+ // FormatEnum
106
+ "format boolean": "Boolean",
107
+ "format currency": "Currency",
108
+ "format date": "Date",
109
+ "format date-time": "DateTime",
110
+ "format did": "DID",
111
+ "format duration": "Duration",
112
+ "format email": "Email",
113
+ "format formula": "Formula",
114
+ "format hostname": "Hostname",
115
+ "format integer": "Integer",
116
+ "format json": "JSON",
117
+ "format latlng": "LatLng",
118
+ "format markdown": "Markdown",
119
+ "format percent": "Percent",
120
+ "format ref": "Reference",
121
+ "format regex": "RegExp",
122
+ "format string": "String",
123
+ "format text": "Long text",
124
+ "format time": "Time",
125
+ "format timestamp": "Timestamp",
126
+ "format user": "User",
127
+ "format number": "Number",
128
+ "format uri": "URI",
129
+ "format uuid": "UUID",
130
+ // Placeholders
131
+ "placeholder latitude": "Latitude",
132
+ "placeholder longitude": "Longitude"
133
+ }
134
+ }
135
+ }
136
+ ];
137
+ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
138
+ const primary = /* @__PURE__ */ import_react.default.createElement("div", {
139
+ role: "none",
140
+ className: "flex w-full gap-4 py-1"
141
+ }, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Root, null, /* @__PURE__ */ import_react.default.createElement("div", {
142
+ role: "none",
143
+ className: "flex flex-col w-full"
144
+ }, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Label, {
145
+ classNames: "flex min-h-[40px] items-center"
146
+ }, label), description && /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.DescriptionAndValidation, {
147
+ classNames: "mbs-0.5"
148
+ }, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Description, null, description))), /* @__PURE__ */ import_react.default.createElement("div", {
149
+ role: "none"
150
+ }, /* @__PURE__ */ import_react.default.createElement("div", {
151
+ role: "none",
152
+ className: "flex min-h-[40px] items-center"
153
+ }, children))));
154
+ if (secondary) {
155
+ return /* @__PURE__ */ import_react.default.createElement("div", {
156
+ role: "none",
157
+ className: "flex flex-col w-full"
158
+ }, primary, secondary);
159
+ }
160
+ return primary;
161
+ };
162
+ var InputHeader = ({ children, error }) => {
163
+ return /* @__PURE__ */ import_react5.default.createElement("div", {
164
+ role: "none",
165
+ className: "flex justify-between items-center mb-1"
166
+ }, children, error && /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Root, null, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Trigger, {
167
+ asChild: true
168
+ }, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Icon, {
169
+ icon: "ph--warning--regular",
170
+ size: 4,
171
+ classNames: import_react_ui_theme2.errorText
172
+ })), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Content, {
173
+ side: "bottom"
174
+ }, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Arrow, null), error)));
175
+ };
176
+ var LatLngInput = ({ property, type, label, disabled, getStatus, getValue, onValueChange, onBlur }) => {
177
+ const { t } = (0, import_react_ui4.useTranslation)(translationKey);
178
+ const { status, error } = getStatus?.(property);
179
+ const { lat = 0, lng = 0 } = getValue(property) ?? {};
180
+ return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
181
+ validationValence: status
182
+ }, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
183
+ error
184
+ }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement("div", {
185
+ className: "grid grid-cols-2 gap-2"
186
+ }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
187
+ type: "number",
188
+ disabled,
189
+ placeholder: t("placeholder latitude"),
190
+ value: lat,
191
+ onChange: (event) => onValueChange(property, type, {
192
+ lat: safeParseFloat(event.target.value, 0),
193
+ lng
194
+ }),
195
+ onBlur
196
+ }), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
197
+ type: "number",
198
+ disabled,
199
+ placeholder: t("placeholder longitude"),
200
+ value: lng,
201
+ onChange: (event) => onValueChange(property, type, {
202
+ lat,
203
+ lng: safeParseFloat(event.target.value, 0)
204
+ }),
205
+ onBlur
206
+ })));
207
+ };
208
+ var safeParseFloat = (str, defaultValue) => {
209
+ try {
210
+ return parseFloat(str);
211
+ } catch {
212
+ return defaultValue ?? 0;
213
+ }
214
+ };
215
+ var TextInput = ({ property, type, label, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
216
+ const { status, error } = getStatus?.(property);
217
+ return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
218
+ validationValence: status
219
+ }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
220
+ error
221
+ }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
222
+ disabled,
223
+ placeholder,
224
+ value: getValue(property) ?? "",
225
+ onChange: (event) => onValueChange(property, type, event.target.value),
226
+ onBlur
227
+ }));
228
+ };
229
+ var NumberInput = ({ property, type, label, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
230
+ const { status, error } = getStatus?.(property);
231
+ return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
232
+ validationValence: status
233
+ }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
234
+ error
235
+ }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
236
+ type: "number",
237
+ disabled,
238
+ placeholder,
239
+ value: getValue(property) ?? 0,
240
+ onChange: (event) => onValueChange(property, type, event.target.value),
241
+ onBlur
242
+ }));
243
+ };
244
+ var BooleanInput = ({ property, type, label, getStatus, getValue, onValueChange }) => {
245
+ const { status, error } = getStatus?.(property);
246
+ return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
247
+ validationValence: status
248
+ }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
249
+ error
250
+ }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Switch, {
251
+ checked: getValue(property),
252
+ onCheckedChange: (value) => onValueChange(property, type, value)
253
+ }));
254
+ };
255
+ var SelectInput = ({ property, type, label, disabled, placeholder, options, getStatus, getValue, onValueChange }) => {
256
+ const { status, error } = getStatus?.(property);
257
+ return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
258
+ validationValence: status
259
+ }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
260
+ error
261
+ }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Root, {
262
+ value: getValue(property),
263
+ onValueChange: (value) => onValueChange(property, type, value)
264
+ }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.TriggerButton, {
265
+ classNames: "is-full",
266
+ disabled,
267
+ placeholder
268
+ }), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Portal, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
269
+ // NOTE: Numeric values are converted to and from strings.
270
+ /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Option, {
271
+ key: String(value),
272
+ value: String(value)
273
+ }, label2 ?? String(value))
274
+ )))))));
275
+ };
276
+ var getInputComponent = (type, format) => {
277
+ switch (format) {
278
+ case import_echo_schema3.FormatEnum.LatLng:
279
+ return LatLngInput;
280
+ }
281
+ switch (type) {
282
+ case "string":
283
+ return TextInput;
284
+ case "number":
285
+ return NumberInput;
286
+ case "boolean":
287
+ return BooleanInput;
288
+ }
289
+ };
290
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
291
+ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSubmit }) => {
292
+ const [values, setValues] = (0, import_react7.useState)(initialValues);
293
+ (0, import_react7.useEffect)(() => {
294
+ setValues(initialValues);
295
+ }, [
296
+ initialValues
297
+ ]);
298
+ const [touched, setTouched] = (0, import_react7.useState)(createKeySet(initialValues, false));
299
+ const [changed, setChanged] = (0, import_react7.useState)(createKeySet(initialValues, false));
300
+ const [errors, setErrors] = (0, import_react7.useState)({});
301
+ const validate = (0, import_react7.useCallback)((values2) => {
302
+ let errors2 = (0, import_schema3.validateSchema)(schema, values2) ?? [];
303
+ if (errors2.length === 0 && onValidate) {
304
+ errors2 = onValidate(values2) ?? [];
305
+ }
306
+ setErrors(flatMap(errors2));
307
+ return errors2.length === 0;
308
+ }, [
309
+ schema,
310
+ onValidate
311
+ ]);
312
+ const [schemaDirty, setSchemaDirty] = (0, import_react7.useState)(false);
313
+ (0, import_react7.useEffect)(() => setSchemaDirty(true), [
314
+ schema
315
+ ]);
316
+ (0, import_react7.useEffect)(() => {
317
+ if (schemaDirty) {
318
+ validate(values);
319
+ setSchemaDirty(false);
320
+ }
321
+ }, [
322
+ values,
323
+ schemaDirty
324
+ ]);
325
+ const canSubmit = (0, import_react7.useMemo)(() => Object.keys(values).every((property) => touched[property] === false || !errors[property]), [
326
+ values,
327
+ touched,
328
+ errors
329
+ ]);
330
+ const handleSubmit = (0, import_react7.useCallback)(() => {
331
+ if (validate(values)) {
332
+ onSubmit?.(values, {
333
+ changed
334
+ });
335
+ }
336
+ }, [
337
+ values,
338
+ validate,
339
+ onSubmit
340
+ ]);
341
+ const getStatus = (0, import_react7.useCallback)((property) => ({
342
+ status: errors[property] ? "error" : void 0,
343
+ error: errors[property] ? errors[property] : void 0
344
+ }), [
345
+ touched,
346
+ errors
347
+ ]);
348
+ const getValue = (property) => {
349
+ return values[property];
350
+ };
351
+ const onValueChange = (property, type, value) => {
352
+ let parsedValue = value;
353
+ try {
354
+ if (type === "number") {
355
+ parsedValue = parseFloat(value) || 0;
356
+ }
357
+ } catch (err) {
358
+ import_log3.log.catch(err, void 0, {
359
+ F: __dxlog_file,
360
+ L: 164,
361
+ S: void 0,
362
+ C: (f, a) => f(...a)
363
+ });
364
+ parsedValue = void 0;
365
+ }
366
+ const newValues = {
367
+ ...values,
368
+ [property]: parsedValue
369
+ };
370
+ setValues(newValues);
371
+ setChanged((prev) => ({
372
+ ...prev,
373
+ [property]: true
374
+ }));
375
+ onValuesChanged?.(newValues);
376
+ const isValid = validate(newValues);
377
+ if (isValid && onValid) {
378
+ onValid(newValues, {
379
+ changed
380
+ });
381
+ }
382
+ };
383
+ const onBlur = (0, import_react7.useCallback)((event) => {
384
+ const { name } = event.target;
385
+ setTouched((touched2) => ({
386
+ ...touched2,
387
+ [name]: true
388
+ }));
389
+ if (event.relatedTarget?.getAttribute("type") === "submit") {
390
+ setTouched(createKeySet(values, true));
391
+ }
392
+ validate(values);
393
+ }, [
394
+ validate,
395
+ values
396
+ ]);
397
+ return {
398
+ // State.
399
+ values,
400
+ errors,
401
+ touched,
402
+ changed,
403
+ canSubmit,
404
+ handleSubmit,
405
+ // Field utils.
406
+ getStatus,
407
+ getValue,
408
+ onValueChange,
409
+ onBlur
410
+ };
411
+ };
412
+ var createKeySet = (obj, value) => {
413
+ (0, import_invariant.invariant)(obj, void 0, {
414
+ F: __dxlog_file,
415
+ L: 215,
416
+ S: void 0,
417
+ A: [
418
+ "obj",
419
+ ""
420
+ ]
421
+ });
422
+ return Object.keys(obj).reduce((acc, key) => ({
423
+ ...acc,
424
+ [key]: value
425
+ }), {});
426
+ };
427
+ var flatMap = (errors) => {
428
+ return errors.reduce((result, { path, message }) => {
429
+ if (!(path in result)) {
430
+ result[path] = message;
431
+ }
432
+ return result;
433
+ }, {});
434
+ };
435
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
436
+ var padding = "px-2";
437
+ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, onValuesChanged, onValidate, onSubmit, onCancel, Custom }) => {
438
+ const { t } = (0, import_react_ui3.useTranslation)(translationKey);
439
+ const onValid = (0, import_react3.useMemo)(() => autoSave ? onSubmit : void 0, [
440
+ autoSave,
441
+ onSubmit
442
+ ]);
443
+ const { canSubmit, values, errors, handleSubmit, ...inputProps } = useForm({
444
+ schema,
445
+ initialValues,
446
+ onValuesChanged,
447
+ onValidate,
448
+ onValid,
449
+ onSubmit
450
+ });
451
+ const props = (0, import_react3.useMemo)(() => {
452
+ const props2 = (0, import_schema2.getSchemaProperties)(schema.ast, values);
453
+ const filtered = filter ? filter(props2) : props2;
454
+ const findIndex = (props3, prop) => {
455
+ const idx = props3.findIndex((p) => p === prop);
456
+ return idx === -1 ? Infinity : idx;
457
+ };
458
+ return sort ? filtered.sort(({ name: a }, { name: b }) => findIndex(sort, a) - findIndex(sort, b)) : filtered;
459
+ }, [
460
+ schema,
461
+ filter,
462
+ values
463
+ ]);
464
+ (0, import_react3.useEffect)(() => {
465
+ if (errors && Object.keys(errors).length) {
466
+ import_log2.log.warn("validation", {
467
+ errors
468
+ }, {
469
+ F: __dxlog_file2,
470
+ L: 93,
471
+ S: void 0,
472
+ C: (f, a) => f(...a)
473
+ });
474
+ }
475
+ }, [
476
+ errors
477
+ ]);
478
+ return /* @__PURE__ */ import_react3.default.createElement("div", {
479
+ role: "form",
480
+ className: (0, import_react_ui_theme.mx)("flex flex-col w-full gap-2 py-2", classNames)
481
+ }, props.map(({ prop, name, type, format, title, description, examples }) => {
482
+ const key = [
483
+ ...path,
484
+ name
485
+ ];
486
+ const InputComponent = Custom?.[key.join(".")] ?? getInputComponent(type, format);
487
+ if (!InputComponent) {
488
+ if (type === "object") {
489
+ const baseNode = (0, import_effect.findNode)(prop.type, import_effect.isDiscriminatedUnion);
490
+ const typeLiteral = baseNode ? (0, import_effect.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect.findNode)(prop.type, import_echo_schema2.AST.isTypeLiteral);
491
+ if (typeLiteral) {
492
+ const schema2 = import_echo_schema2.S.make(typeLiteral);
493
+ return /* @__PURE__ */ import_react3.default.createElement("div", {
494
+ key: name,
495
+ role: "none"
496
+ }, /* @__PURE__ */ import_react3.default.createElement("div", {
497
+ className: padding
498
+ }, title ?? name), /* @__PURE__ */ import_react3.default.createElement(Form, {
499
+ schema: schema2,
500
+ path: key,
501
+ values: values[name] ?? {},
502
+ onValuesChanged: (childValues) => {
503
+ inputProps.onValueChange(name, "object", childValues);
504
+ },
505
+ Custom
506
+ }));
507
+ }
508
+ }
509
+ (0, import_log2.log)("no renderer for property", {
510
+ name,
511
+ type
512
+ }, {
513
+ F: __dxlog_file2,
514
+ L: 132,
515
+ S: void 0,
516
+ C: (f, a) => f(...a)
517
+ });
518
+ return null;
519
+ }
520
+ const placeholder = examples?.length ? `Example: ${examples[0]}` : description;
521
+ return /* @__PURE__ */ import_react3.default.createElement("div", {
522
+ key: name,
523
+ role: "none",
524
+ className: padding
525
+ }, /* @__PURE__ */ import_react3.default.createElement(InputComponent, {
526
+ type,
527
+ format,
528
+ property: name,
529
+ disabled: readonly,
530
+ label: title ?? name,
531
+ placeholder,
532
+ ...inputProps
533
+ }));
534
+ }).filter(import_util.isNotFalsy), (onCancel || onSubmit) && !autoSave && /* @__PURE__ */ import_react3.default.createElement("div", {
535
+ role: "none",
536
+ className: "flex justify-center"
537
+ }, /* @__PURE__ */ import_react3.default.createElement("div", {
538
+ role: "none",
539
+ className: (0, import_react_ui_theme.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
540
+ }, onCancel && !readonly && /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.IconButton, {
541
+ icon: "ph--x--regular",
542
+ label: t("button cancel"),
543
+ onClick: onCancel
544
+ }), onSubmit && /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.IconButton, {
545
+ type: "submit",
546
+ disabled: !canSubmit,
547
+ icon: "ph--check--regular",
548
+ label: t("button save"),
549
+ onClick: handleSubmit
550
+ }))));
551
+ };
552
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
553
+ var FieldEditor = ({ view, projection, field, registry, onClose, onCancel }) => {
554
+ const { t } = (0, import_react_ui2.useTranslation)(translationKey);
555
+ const [props, setProps] = (0, import_react2.useState)(projection.getFieldProjection(field.id).props);
556
+ (0, import_react2.useEffect)(() => setProps(projection.getFieldProjection(field.id).props), [
557
+ field,
558
+ projection
559
+ ]);
560
+ const [schemas, setSchemas] = (0, import_react2.useState)([]);
561
+ (0, import_react2.useEffect)(() => {
562
+ if (!registry) {
563
+ return;
564
+ }
565
+ const subscription = registry.subscribe(setSchemas);
566
+ const t2 = setTimeout(async () => {
567
+ const schemas2 = await registry.query();
568
+ setSchemas(schemas2);
569
+ });
570
+ return () => {
571
+ clearTimeout(t2);
572
+ subscription?.();
573
+ };
574
+ }, [
575
+ registry
576
+ ]);
577
+ const [schema, setSchema] = (0, import_react2.useState)();
578
+ (0, import_react2.useEffect)(() => {
579
+ setSchema(schemas.find((schema2) => schema2.typename === props?.referenceSchema));
580
+ }, [
581
+ schemas,
582
+ props?.referenceSchema
583
+ ]);
584
+ const [{ fieldSchema }, setFieldSchema] = (0, import_react2.useState)({
585
+ fieldSchema: (0, import_schema.getFormatSchema)(props?.format)
586
+ });
587
+ const handleValuesChanged = (0, import_react2.useCallback)((_props) => {
588
+ if (_props.format !== props.format) {
589
+ setFieldSchema({
590
+ fieldSchema: (0, import_schema.getFormatSchema)(_props.format)
591
+ });
592
+ }
593
+ if (_props.referenceSchema !== props.referenceSchema) {
594
+ setSchema(schemas.find((schema2) => schema2.typename === _props.referenceSchema));
595
+ }
596
+ setProps((props2) => {
597
+ const type = import_echo_schema.formatToType[_props.format];
598
+ if (props2.type !== type) {
599
+ return {
600
+ ...props2,
601
+ ..._props,
602
+ type
603
+ };
604
+ }
605
+ return props2;
606
+ });
607
+ }, [
608
+ schemas,
609
+ props
610
+ ]);
611
+ const handleValidate = (0, import_react2.useCallback)(({ property }) => {
612
+ if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
613
+ return [
614
+ {
615
+ path: "property",
616
+ message: `property is not unique: '${property}'`
617
+ }
618
+ ];
619
+ }
620
+ }, [
621
+ view.fields,
622
+ field
623
+ ]);
624
+ const handleSubmit = (0, import_react2.useCallback)((props2) => {
625
+ projection.setFieldProjection({
626
+ field,
627
+ props: props2
628
+ });
629
+ onClose();
630
+ }, [
631
+ projection,
632
+ field,
633
+ onClose
634
+ ]);
635
+ const handleCancel = (0, import_react2.useCallback)(() => {
636
+ requestAnimationFrame(() => onCancel?.());
637
+ onClose();
638
+ }, [
639
+ onClose
640
+ ]);
641
+ if (!fieldSchema) {
642
+ import_log.log.warn("invalid format", {
643
+ props
644
+ }, {
645
+ F: __dxlog_file3,
646
+ L: 118,
647
+ S: void 0,
648
+ C: (f, a) => f(...a)
649
+ });
650
+ return null;
651
+ }
652
+ return /* @__PURE__ */ import_react2.default.createElement(Form, {
653
+ key: field.id,
654
+ autoFocus: true,
655
+ values: props,
656
+ schema: fieldSchema,
657
+ filter: (props2) => props2.filter((p) => p.name !== "type"),
658
+ sort: [
659
+ "property",
660
+ "format"
661
+ ],
662
+ onValuesChanged: handleValuesChanged,
663
+ onValidate: handleValidate,
664
+ onSubmit: handleSubmit,
665
+ onCancel: handleCancel,
666
+ Custom: {
667
+ ["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
668
+ ...props2,
669
+ options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
670
+ value,
671
+ label: t(`format ${value}`)
672
+ }))
673
+ }),
674
+ ["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
675
+ ...props2,
676
+ options: schemas.map((schema2) => ({
677
+ value: schema2.typename
678
+ }))
679
+ }),
680
+ ["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
681
+ ...props2,
682
+ options: schema ? (0, import_schema.getSchemaProperties)(schema.schema.ast).sort(import_schema.sortProperties).map((p) => ({
683
+ value: p.name
684
+ })) : []
685
+ })
686
+ }
687
+ });
688
+ };
689
+ var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
690
+ var ViewMetaSchema = import_echo_schema4.S.Struct({
691
+ name: import_echo_schema4.S.String.annotations({
692
+ [import_echo_schema4.AST.TitleAnnotationId]: "View"
693
+ }),
694
+ type: import_echo_schema4.Format.DXN.annotations({
695
+ [import_echo_schema4.AST.TitleAnnotationId]: "Typename"
696
+ })
697
+ }).pipe(import_echo_schema4.S.mutable);
698
+ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onDelete }) => {
699
+ const { t } = (0, import_react_ui7.useTranslation)(translationKey);
700
+ const projection = (0, import_react8.useMemo)(() => new import_schema4.ViewProjection(schema, view), [
701
+ schema,
702
+ view
703
+ ]);
704
+ const [field, setField] = (0, import_react8.useState)();
705
+ const viewValues = (0, import_react8.useMemo)(() => {
706
+ return {
707
+ name: view.name,
708
+ // TODO(burdon): Need to warn user of possible consequences of editing.
709
+ // TODO(burdon): Settings should have domain name owned by user.
710
+ type: view.query.type
711
+ };
712
+ }, [
713
+ view
714
+ ]);
715
+ const handleViewUpdate = (0, import_react8.useCallback)(({ name, type }) => {
716
+ requestAnimationFrame(() => {
717
+ view.name = name;
718
+ view.query.type = type;
719
+ schema.updateTypename(type);
720
+ });
721
+ }, [
722
+ view,
723
+ schema
724
+ ]);
725
+ const handleSelect = (0, import_react8.useCallback)((field2) => {
726
+ setField((f) => f === field2 ? void 0 : field2);
727
+ }, []);
728
+ const handleAdd = (0, import_react8.useCallback)(() => {
729
+ const field2 = projection.createFieldProjection();
730
+ setField(field2);
731
+ }, [
732
+ view
733
+ ]);
734
+ const handleMove = (0, import_react8.useCallback)((fromIndex, toIndex) => {
735
+ (0, import_util2.arrayMove)(view.fields, fromIndex, toIndex);
736
+ }, [
737
+ view.fields
738
+ ]);
739
+ const handleClose = (0, import_react8.useCallback)(() => setField(void 0), []);
740
+ return /* @__PURE__ */ import_react8.default.createElement("div", {
741
+ role: "none",
742
+ className: (0, import_react_ui_theme3.mx)("flex flex-col w-full divide-y divide-separator", classNames)
743
+ }, /* @__PURE__ */ import_react8.default.createElement(Form, {
744
+ autoFocus: true,
745
+ autoSave: true,
746
+ schema: ViewMetaSchema,
747
+ values: viewValues,
748
+ onSubmit: handleViewUpdate
749
+ }), /* @__PURE__ */ import_react8.default.createElement("div", null, /* @__PURE__ */ import_react8.default.createElement("div", {
750
+ role: "none",
751
+ className: "p-2"
752
+ }, /* @__PURE__ */ import_react8.default.createElement("label", {
753
+ className: (0, import_react_ui_theme3.mx)(import_react_ui_theme3.inputTextLabel)
754
+ }, t("fields label"))), /* @__PURE__ */ import_react8.default.createElement(import_react_ui_list.List.Root, {
755
+ items: view.fields,
756
+ isItem: import_echo_schema4.S.is(import_schema4.FieldSchema),
757
+ getId: (field2) => field2.id,
758
+ onMove: handleMove
759
+ }, ({ items: fields }) => /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, showHeading && /* @__PURE__ */ import_react8.default.createElement("div", {
760
+ role: "heading",
761
+ className: grid
762
+ }, /* @__PURE__ */ import_react8.default.createElement("div", null), /* @__PURE__ */ import_react8.default.createElement("div", {
763
+ className: "flex items-center text-sm"
764
+ }, t("field path label"))), /* @__PURE__ */ import_react8.default.createElement("div", {
765
+ role: "list",
766
+ className: "flex flex-col w-full"
767
+ }, fields?.map((field2) => /* @__PURE__ */ import_react8.default.createElement(import_react_ui_list.List.Item, {
768
+ key: field2.id,
769
+ item: field2,
770
+ classNames: (0, import_react_ui_theme3.mx)(grid, import_react_ui_theme3.ghostHover, "cursor-pointer")
771
+ }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react8.default.createElement(import_react_ui_list.List.ItemTitle, {
772
+ onClick: () => handleSelect(field2)
773
+ }, field2.path), /* @__PURE__ */ import_react8.default.createElement(import_react_ui_list.List.ItemDeleteButton, {
774
+ disabled: view.fields.length <= 1,
775
+ onClick: () => onDelete(field2.id)
776
+ }))))))), field && /* @__PURE__ */ import_react8.default.createElement(FieldEditor, {
777
+ key: field.id,
778
+ view,
779
+ projection,
780
+ field,
781
+ registry,
782
+ onClose: handleClose
783
+ }), !readonly && !field && /* @__PURE__ */ import_react8.default.createElement("div", {
784
+ className: "flex p-2 justify-center"
785
+ }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui7.IconButton, {
786
+ icon: "ph--plus--regular",
787
+ label: t("button add property"),
788
+ onClick: handleAdd,
789
+ // TODO(burdon): Show field limit in ux (not tooltip).
790
+ disabled: view.fields.length >= import_schema4.VIEW_FIELD_LIMIT
791
+ })));
792
+ };
793
+ var parseValue = ({ type, format, value }) => {
794
+ if (value === void 0 || value === null || value === "") {
795
+ return void 0;
796
+ }
797
+ const parseScalar = (type2) => {
798
+ switch (type2) {
799
+ case import_echo_schema5.TypeEnum.Boolean: {
800
+ if (typeof value === "string") {
801
+ const lowercaseValue = value.toLowerCase();
802
+ if (lowercaseValue === "0" || lowercaseValue === "false") {
803
+ return false;
804
+ } else if (lowercaseValue === "1" || lowercaseValue === "true") {
805
+ return true;
806
+ }
807
+ }
808
+ return Boolean(value);
809
+ }
810
+ case import_echo_schema5.TypeEnum.Number: {
811
+ const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
812
+ const num = Number(cleaned);
813
+ return Number.isNaN(num) ? null : num;
814
+ }
815
+ case import_echo_schema5.TypeEnum.String:
816
+ case import_echo_schema5.TypeEnum.Ref:
817
+ return String(value);
818
+ default: {
819
+ return value;
820
+ }
821
+ }
822
+ };
823
+ if (!format) {
824
+ return parseScalar(type);
825
+ }
826
+ switch (format) {
827
+ case import_echo_schema5.FormatEnum.Boolean:
828
+ return parseScalar(import_echo_schema5.TypeEnum.Boolean);
829
+ case import_echo_schema5.FormatEnum.Number:
830
+ case import_echo_schema5.FormatEnum.Percent:
831
+ case import_echo_schema5.FormatEnum.Currency:
832
+ return parseScalar(import_echo_schema5.TypeEnum.Number);
833
+ case import_echo_schema5.FormatEnum.String:
834
+ case import_echo_schema5.FormatEnum.Markdown: {
835
+ return parseScalar(import_echo_schema5.TypeEnum.String);
836
+ }
837
+ case import_echo_schema5.FormatEnum.Ref:
838
+ throw new Error(`unexpected format: ${import_echo_schema5.FormatEnum.Ref}`);
839
+ case import_echo_schema5.FormatEnum.DateTime:
840
+ case import_echo_schema5.FormatEnum.Date:
841
+ case import_echo_schema5.FormatEnum.Time:
842
+ case import_echo_schema5.FormatEnum.Timestamp: {
843
+ const date = new Date(value);
844
+ return isNaN(date.getTime()) ? null : date;
845
+ }
846
+ default: {
847
+ return value;
848
+ }
849
+ }
850
+ };
851
+ var cellClassesForFieldType = ({ type, format }) => {
852
+ if (!format) {
853
+ switch (type) {
854
+ case import_echo_schema5.TypeEnum.Number:
855
+ return [
856
+ "text-right",
857
+ "font-mono"
858
+ ];
859
+ case import_echo_schema5.TypeEnum.Boolean:
860
+ return [
861
+ "text-right",
862
+ "font-mono"
863
+ ];
864
+ case import_echo_schema5.TypeEnum.String:
865
+ return void 0;
866
+ case import_echo_schema5.TypeEnum.Ref:
867
+ return void 0;
868
+ default: {
869
+ return void 0;
870
+ }
871
+ }
872
+ }
873
+ switch (format) {
874
+ case import_echo_schema5.FormatEnum.Markdown:
875
+ return void 0;
876
+ case import_echo_schema5.FormatEnum.Timestamp:
877
+ case import_echo_schema5.FormatEnum.DateTime:
878
+ case import_echo_schema5.FormatEnum.Date:
879
+ case import_echo_schema5.FormatEnum.Time:
880
+ return [
881
+ "font-mono"
882
+ ];
883
+ case import_echo_schema5.FormatEnum.Currency:
884
+ return [
885
+ "text-right"
886
+ ];
887
+ case import_echo_schema5.FormatEnum.JSON:
888
+ return [
889
+ "font-mono"
890
+ ];
891
+ default:
892
+ return void 0;
893
+ }
894
+ };
895
+ var cellClassesForRowSelection = (selected) => selected ? [
896
+ "!bg-gridCellSelected"
897
+ ] : void 0;
898
+ var pathNotUniqueError = (path) => ({
899
+ path: "path",
900
+ message: `'${path}' is already present`
901
+ });
902
+ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
903
+ const formatScalar = (type2) => {
904
+ switch (type2) {
905
+ case import_echo_schema6.TypeEnum.Boolean:
906
+ return value.toLocaleString().toUpperCase();
907
+ case import_echo_schema6.TypeEnum.Number:
908
+ return value.toLocaleString(locale);
909
+ case import_echo_schema6.TypeEnum.String:
910
+ case import_echo_schema6.TypeEnum.Ref:
911
+ return String(value);
912
+ default: {
913
+ return String(value);
914
+ }
915
+ }
916
+ };
917
+ if (!format) {
918
+ return formatScalar(type);
919
+ }
920
+ switch (format) {
921
+ case import_echo_schema6.FormatEnum.Boolean: {
922
+ return formatScalar(import_echo_schema6.TypeEnum.Boolean);
923
+ }
924
+ case import_echo_schema6.FormatEnum.Number: {
925
+ return formatScalar(import_echo_schema6.TypeEnum.Number);
926
+ }
927
+ case import_echo_schema6.FormatEnum.String:
928
+ case import_echo_schema6.FormatEnum.Ref: {
929
+ return formatScalar(import_echo_schema6.TypeEnum.String);
930
+ }
931
+ case import_echo_schema6.FormatEnum.Percent: {
932
+ return `${value * 100}%`;
933
+ }
934
+ case import_echo_schema6.FormatEnum.Currency: {
935
+ return value.toLocaleString(locale, {
936
+ style: "currency",
937
+ currency: "USD",
938
+ minimumFractionDigits: 2,
939
+ maximumFractionDigits: 2
940
+ });
941
+ }
942
+ case import_echo_schema6.FormatEnum.DateTime:
943
+ case import_echo_schema6.FormatEnum.Date:
944
+ case import_echo_schema6.FormatEnum.Time: {
945
+ const date = new Date(value);
946
+ if (format === import_echo_schema6.FormatEnum.DateTime) {
947
+ return date.toLocaleString(locale);
948
+ } else if (format === import_echo_schema6.FormatEnum.Date) {
949
+ return date.toLocaleDateString(locale);
950
+ } else {
951
+ return date.toLocaleTimeString(locale);
952
+ }
953
+ }
954
+ default: {
955
+ if (value === null || value === "undefined") {
956
+ return "";
957
+ }
958
+ return String(value);
959
+ }
960
+ }
961
+ };
962
+ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
963
+ const formatScalar = (type2) => {
964
+ switch (type2) {
965
+ case import_echo_schema6.TypeEnum.Boolean:
966
+ case import_echo_schema6.TypeEnum.Number:
967
+ case import_echo_schema6.TypeEnum.String:
968
+ case import_echo_schema6.TypeEnum.Ref:
969
+ return String(value);
970
+ default:
971
+ return String(value);
972
+ }
973
+ };
974
+ if (!format) {
975
+ return formatScalar(type);
976
+ }
977
+ switch (format) {
978
+ case import_echo_schema6.FormatEnum.Boolean:
979
+ case import_echo_schema6.FormatEnum.Number:
980
+ case import_echo_schema6.FormatEnum.String:
981
+ case import_echo_schema6.FormatEnum.Ref: {
982
+ return formatScalar(type);
983
+ }
984
+ case import_echo_schema6.FormatEnum.Percent: {
985
+ return String(value * 100);
986
+ }
987
+ case import_echo_schema6.FormatEnum.Currency: {
988
+ return String(value);
989
+ }
990
+ case import_echo_schema6.FormatEnum.DateTime: {
991
+ const date = new Date(value);
992
+ return date.toISOString();
993
+ }
994
+ case import_echo_schema6.FormatEnum.Date: {
995
+ const date = new Date(value);
996
+ return date.toISOString().split("T")[0];
997
+ }
998
+ case import_echo_schema6.FormatEnum.Time: {
999
+ const date = new Date(value);
1000
+ return date.toISOString().split("T")[1].split(".")[0];
1001
+ }
1002
+ default: {
1003
+ return String(value);
1004
+ }
1005
+ }
1006
+ };
1007
+ // Annotate the CommonJS export names for ESM import in node:
1008
+ 0 && (module.exports = {
1009
+ BooleanInput,
1010
+ DeprecatedFormInput,
1011
+ FieldEditor,
1012
+ Form,
1013
+ InputHeader,
1014
+ LatLngInput,
1015
+ NumberInput,
1016
+ SelectInput,
1017
+ TextInput,
1018
+ ViewEditor,
1019
+ cellClassesForFieldType,
1020
+ cellClassesForRowSelection,
1021
+ formatForDisplay,
1022
+ formatForEditing,
1023
+ parseValue,
1024
+ pathNotUniqueError,
1025
+ translations,
1026
+ useForm
1027
+ });
1028
+ //# sourceMappingURL=index.cjs.map