@dxos/react-ui-form 0.7.4 → 0.7.5-feature-compute.4d9d99a
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.
- package/dist/lib/browser/index.mjs +292 -221
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +380 -308
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +292 -221
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +10 -4
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +5 -0
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +3 -3
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/{Custom.d.ts → custom/GeoPointInput.d.ts} +3 -3
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +7 -0
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +1 -0
- package/dist/types/src/components/Form/custom/index.d.ts +3 -0
- package/dist/types/src/components/Form/custom/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +2 -2
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +6 -5
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/useForm.d.ts +10 -11
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +26 -26
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.tsx +75 -50
- package/src/components/Form/Defaults.tsx +2 -0
- package/src/components/Form/Form.stories.tsx +33 -1
- package/src/components/Form/Form.tsx +33 -5
- package/src/components/Form/Input.tsx +3 -3
- package/src/components/Form/{Custom.tsx → custom/GeoPointInput.tsx} +4 -16
- package/src/components/Form/custom/TupleInput.tsx +53 -0
- package/src/components/Form/custom/index.ts +6 -0
- package/src/components/Form/factory.tsx +2 -2
- package/src/components/Form/index.ts +3 -2
- package/src/components/ViewEditor/ViewEditor.stories.tsx +30 -8
- package/src/components/ViewEditor/ViewEditor.tsx +13 -8
- package/src/hooks/useForm.ts +35 -54
- package/dist/types/src/components/Form/Custom.d.ts.map +0 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -33,11 +33,12 @@ __export(node_exports, {
|
|
|
33
33
|
FieldEditor: () => FieldEditor,
|
|
34
34
|
Form: () => Form,
|
|
35
35
|
FormActions: () => FormActions,
|
|
36
|
-
|
|
36
|
+
GeoPointInput: () => GeoPointInput,
|
|
37
37
|
InputHeader: () => InputHeader,
|
|
38
38
|
NumberInput: () => NumberInput,
|
|
39
39
|
SelectInput: () => SelectInput,
|
|
40
40
|
TextInput: () => TextInput,
|
|
41
|
+
TupleInput: () => TupleInput,
|
|
41
42
|
ViewEditor: () => ViewEditor,
|
|
42
43
|
cellClassesForFieldType: () => cellClassesForFieldType,
|
|
43
44
|
cellClassesForRowSelection: () => cellClassesForRowSelection,
|
|
@@ -56,37 +57,44 @@ var import_echo_schema = require("@dxos/echo-schema");
|
|
|
56
57
|
var import_log = require("@dxos/log");
|
|
57
58
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
58
59
|
var import_schema = require("@dxos/schema");
|
|
59
|
-
var import_effect = require("effect");
|
|
60
|
-
var import_String = require("effect/String");
|
|
61
60
|
var import_react3 = __toESM(require("react"));
|
|
62
|
-
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
63
|
-
var import_effect2 = require("@dxos/effect");
|
|
64
|
-
var import_log2 = require("@dxos/log");
|
|
65
61
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
66
|
-
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
67
|
-
var import_schema2 = require("@dxos/schema");
|
|
68
62
|
var import_util = require("@dxos/util");
|
|
69
63
|
var import_react4 = __toESM(require("react"));
|
|
70
64
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
65
|
+
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
71
66
|
var import_react5 = __toESM(require("react"));
|
|
72
67
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
73
68
|
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
74
|
-
var
|
|
69
|
+
var import_util2 = require("@dxos/util");
|
|
75
70
|
var import_react6 = __toESM(require("react"));
|
|
76
71
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
77
|
-
var
|
|
72
|
+
var import_effect = require("effect");
|
|
73
|
+
var import_String = require("effect/String");
|
|
74
|
+
var import_react7 = __toESM(require("react"));
|
|
75
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
76
|
+
var import_effect2 = require("@dxos/effect");
|
|
77
|
+
var import_log2 = require("@dxos/log");
|
|
78
|
+
var import_react_ui7 = require("@dxos/react-ui");
|
|
79
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
80
|
+
var import_schema2 = require("@dxos/schema");
|
|
81
|
+
var import_util3 = require("@dxos/util");
|
|
82
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
83
|
+
var import_react8 = require("react");
|
|
84
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
85
|
+
var import_effect3 = require("@dxos/effect");
|
|
78
86
|
var import_invariant = require("@dxos/invariant");
|
|
79
87
|
var import_log3 = require("@dxos/log");
|
|
80
88
|
var import_schema3 = require("@dxos/schema");
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
var
|
|
89
|
+
var import_react9 = __toESM(require("react"));
|
|
90
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
91
|
+
var import_react_ui8 = require("@dxos/react-ui");
|
|
84
92
|
var import_react_ui_list = require("@dxos/react-ui-list");
|
|
85
|
-
var
|
|
93
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
86
94
|
var import_schema4 = require("@dxos/schema");
|
|
87
|
-
var
|
|
88
|
-
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
95
|
+
var import_util4 = require("@dxos/util");
|
|
89
96
|
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
97
|
+
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
90
98
|
var translationKey = "react-ui-form";
|
|
91
99
|
var translations_default = [
|
|
92
100
|
{
|
|
@@ -163,123 +171,143 @@ var DeprecatedFormInput = ({ label, description, secondary, children }) => {
|
|
|
163
171
|
return primary;
|
|
164
172
|
};
|
|
165
173
|
var InputHeader = ({ children, error }) => {
|
|
166
|
-
return /* @__PURE__ */
|
|
174
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
167
175
|
role: "none",
|
|
168
176
|
className: "flex justify-between items-center mb-1"
|
|
169
|
-
}, children, error && /* @__PURE__ */
|
|
177
|
+
}, children, error && /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Root, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Trigger, {
|
|
170
178
|
asChild: true
|
|
171
|
-
}, /* @__PURE__ */
|
|
179
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Icon, {
|
|
172
180
|
icon: "ph--warning--regular",
|
|
173
181
|
size: 4,
|
|
174
|
-
classNames:
|
|
175
|
-
})), /* @__PURE__ */
|
|
182
|
+
classNames: import_react_ui_theme.errorText
|
|
183
|
+
})), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Content, {
|
|
176
184
|
side: "bottom"
|
|
177
|
-
}, /* @__PURE__ */
|
|
185
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Tooltip.Arrow, null), error)));
|
|
186
|
+
};
|
|
187
|
+
var GeoPointInput = ({ property, type, label, disabled, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
188
|
+
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
189
|
+
const { status, error } = getStatus?.(property);
|
|
190
|
+
const [lng = 0, lat = 0] = getValue2(property) ?? [];
|
|
191
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Root, {
|
|
192
|
+
validationValence: status
|
|
193
|
+
}, /* @__PURE__ */ import_react3.default.createElement(InputHeader, {
|
|
194
|
+
error
|
|
195
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.Label, null, label)), /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
196
|
+
className: "grid grid-cols-2 gap-2"
|
|
197
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
198
|
+
type: "number",
|
|
199
|
+
disabled,
|
|
200
|
+
placeholder: t("placeholder longitude"),
|
|
201
|
+
value: lng,
|
|
202
|
+
onChange: (event) => onValueChange(property, type, [
|
|
203
|
+
lat,
|
|
204
|
+
(0, import_util.safeParseFloat)(event.target.value, 0)
|
|
205
|
+
]),
|
|
206
|
+
onBlur
|
|
207
|
+
}), /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.Input.TextInput, {
|
|
208
|
+
type: "number",
|
|
209
|
+
disabled,
|
|
210
|
+
placeholder: t("placeholder latitude"),
|
|
211
|
+
value: lat,
|
|
212
|
+
onChange: (event) => onValueChange(property, type, [
|
|
213
|
+
(0, import_util.safeParseFloat)(event.target.value, 0),
|
|
214
|
+
lng
|
|
215
|
+
]),
|
|
216
|
+
onBlur
|
|
217
|
+
})));
|
|
178
218
|
};
|
|
179
|
-
var
|
|
219
|
+
var gridCols = [
|
|
220
|
+
"grid-cols-1",
|
|
221
|
+
"grid-cols-2",
|
|
222
|
+
"grid-cols-3",
|
|
223
|
+
"grid-cols-4"
|
|
224
|
+
];
|
|
225
|
+
var TupleInput = ({ binding, property, type, label, disabled, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
226
|
+
const { status, error } = getStatus?.(property);
|
|
227
|
+
const values = getValue2(property) ?? {};
|
|
228
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Root, {
|
|
229
|
+
validationValence: status
|
|
230
|
+
}, /* @__PURE__ */ import_react5.default.createElement(InputHeader, {
|
|
231
|
+
error
|
|
232
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.Label, null, label)), /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
233
|
+
className: (0, import_react_ui_theme2.mx)("grid gap-2", gridCols[binding.length - 1])
|
|
234
|
+
}, binding.map((prop) => /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Input.TextInput, {
|
|
235
|
+
key: prop,
|
|
236
|
+
type: "number",
|
|
237
|
+
disabled,
|
|
238
|
+
value: values[prop],
|
|
239
|
+
onChange: (event) => onValueChange(property, type, {
|
|
240
|
+
...values,
|
|
241
|
+
[prop]: (0, import_util2.safeParseFloat)(event.target.value, 0)
|
|
242
|
+
}),
|
|
243
|
+
onBlur
|
|
244
|
+
}))));
|
|
245
|
+
};
|
|
246
|
+
var TextInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
180
247
|
const { status, error } = getStatus?.(property);
|
|
181
|
-
return /* @__PURE__ */
|
|
248
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
182
249
|
validationValence: status
|
|
183
|
-
}, !inputOnly && /* @__PURE__ */
|
|
250
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
184
251
|
error
|
|
185
|
-
}, /* @__PURE__ */
|
|
252
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
186
253
|
disabled,
|
|
187
254
|
placeholder,
|
|
188
|
-
value:
|
|
255
|
+
value: getValue2(property) ?? "",
|
|
189
256
|
onChange: (event) => onValueChange(property, type, event.target.value),
|
|
190
257
|
onBlur
|
|
191
|
-
}), inputOnly && /* @__PURE__ */
|
|
258
|
+
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Validation, null, error));
|
|
192
259
|
};
|
|
193
|
-
var NumberInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
|
|
260
|
+
var NumberInput = ({ property, type, label, inputOnly, disabled, placeholder, getStatus, getValue: getValue2, onValueChange, onBlur }) => {
|
|
194
261
|
const { status, error } = getStatus?.(property);
|
|
195
|
-
return /* @__PURE__ */
|
|
262
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
196
263
|
validationValence: status
|
|
197
|
-
}, !inputOnly && /* @__PURE__ */
|
|
264
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
198
265
|
error
|
|
199
|
-
}, /* @__PURE__ */
|
|
266
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
200
267
|
type: "number",
|
|
201
268
|
disabled,
|
|
202
269
|
placeholder,
|
|
203
|
-
value:
|
|
270
|
+
value: getValue2(property) ?? 0,
|
|
204
271
|
onChange: (event) => onValueChange(property, type, event.target.value),
|
|
205
272
|
onBlur
|
|
206
|
-
}), inputOnly && /* @__PURE__ */
|
|
273
|
+
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
207
274
|
};
|
|
208
|
-
var BooleanInput = ({ property, type, label, inputOnly, getStatus, getValue, onValueChange }) => {
|
|
275
|
+
var BooleanInput = ({ property, type, label, inputOnly, getStatus, getValue: getValue2, onValueChange }) => {
|
|
209
276
|
const { status, error } = getStatus?.(property);
|
|
210
|
-
return /* @__PURE__ */
|
|
277
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
211
278
|
validationValence: status
|
|
212
|
-
}, !inputOnly && /* @__PURE__ */
|
|
279
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
213
280
|
error
|
|
214
|
-
}, /* @__PURE__ */
|
|
215
|
-
checked:
|
|
281
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Switch, {
|
|
282
|
+
checked: getValue2(property),
|
|
216
283
|
onCheckedChange: (value) => onValueChange(property, type, value)
|
|
217
|
-
}), inputOnly && /* @__PURE__ */
|
|
284
|
+
}), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
218
285
|
};
|
|
219
|
-
var SelectInput = ({ property, type, label, inputOnly, disabled, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
286
|
+
var SelectInput = ({ property, type, label, inputOnly, disabled, placeholder, options, getStatus, getValue: getValue2, onValueChange }) => {
|
|
220
287
|
const { status, error } = getStatus?.(property);
|
|
221
|
-
return /* @__PURE__ */
|
|
288
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
222
289
|
validationValence: status
|
|
223
|
-
}, !inputOnly && /* @__PURE__ */
|
|
290
|
+
}, !inputOnly && /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
224
291
|
error
|
|
225
|
-
}, /* @__PURE__ */
|
|
226
|
-
value:
|
|
292
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Root, {
|
|
293
|
+
value: getValue2(property),
|
|
227
294
|
onValueChange: (value) => onValueChange(property, type, value)
|
|
228
|
-
}, /* @__PURE__ */
|
|
295
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.TriggerButton, {
|
|
229
296
|
classNames: "is-full",
|
|
230
297
|
disabled,
|
|
231
298
|
placeholder
|
|
232
|
-
}), /* @__PURE__ */
|
|
299
|
+
}), /* @__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 }) => (
|
|
233
300
|
// NOTE: Numeric values are converted to and from strings.
|
|
234
|
-
/* @__PURE__ */
|
|
301
|
+
/* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Option, {
|
|
235
302
|
key: String(value),
|
|
236
303
|
value: String(value)
|
|
237
304
|
}, label2 ?? String(value))
|
|
238
|
-
)))))), inputOnly && /* @__PURE__ */
|
|
239
|
-
};
|
|
240
|
-
var GeiPointInput = ({ property, type, label, disabled, getStatus, getValue, onValueChange, onBlur }) => {
|
|
241
|
-
const { t } = (0, import_react_ui6.useTranslation)(translationKey);
|
|
242
|
-
const { status, error } = getStatus?.(property);
|
|
243
|
-
const [lng = 0, lat = 0] = getValue(property) ?? [];
|
|
244
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
245
|
-
validationValence: status
|
|
246
|
-
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
247
|
-
error
|
|
248
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
249
|
-
className: "grid grid-cols-2 gap-2"
|
|
250
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
251
|
-
type: "number",
|
|
252
|
-
disabled,
|
|
253
|
-
placeholder: t("placeholder longitude"),
|
|
254
|
-
value: lng,
|
|
255
|
-
onChange: (event) => onValueChange(property, type, [
|
|
256
|
-
lat,
|
|
257
|
-
safeParseFloat(event.target.value, 0)
|
|
258
|
-
]),
|
|
259
|
-
onBlur
|
|
260
|
-
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
261
|
-
type: "number",
|
|
262
|
-
disabled,
|
|
263
|
-
placeholder: t("placeholder latitude"),
|
|
264
|
-
value: lat,
|
|
265
|
-
onChange: (event) => onValueChange(property, type, [
|
|
266
|
-
safeParseFloat(event.target.value, 0),
|
|
267
|
-
lng
|
|
268
|
-
]),
|
|
269
|
-
onBlur
|
|
270
|
-
})));
|
|
271
|
-
};
|
|
272
|
-
var safeParseFloat = (str, defaultValue) => {
|
|
273
|
-
try {
|
|
274
|
-
return parseFloat(str);
|
|
275
|
-
} catch {
|
|
276
|
-
return defaultValue ?? 0;
|
|
277
|
-
}
|
|
305
|
+
)))))), inputOnly && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.DescriptionAndValidation, null, error));
|
|
278
306
|
};
|
|
279
307
|
var getInputComponent = (type, format) => {
|
|
280
308
|
switch (format) {
|
|
281
309
|
case import_echo_schema3.FormatEnum.LatLng:
|
|
282
|
-
return
|
|
310
|
+
return GeoPointInput;
|
|
283
311
|
}
|
|
284
312
|
switch (type) {
|
|
285
313
|
case "string":
|
|
@@ -292,32 +320,43 @@ var getInputComponent = (type, format) => {
|
|
|
292
320
|
};
|
|
293
321
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
294
322
|
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
295
|
-
|
|
296
|
-
|
|
323
|
+
(0, import_invariant.invariant)(import_effect3.AST.isTypeLiteral(schema.ast), void 0, {
|
|
324
|
+
F: __dxlog_file,
|
|
325
|
+
L: 91,
|
|
326
|
+
S: void 0,
|
|
327
|
+
A: [
|
|
328
|
+
"AST.isTypeLiteral(schema.ast)",
|
|
329
|
+
""
|
|
330
|
+
]
|
|
331
|
+
});
|
|
332
|
+
const [values, setValues] = (0, import_react8.useState)(initialValues);
|
|
333
|
+
(0, import_react8.useEffect)(() => {
|
|
297
334
|
setValues(initialValues);
|
|
298
335
|
}, [
|
|
299
336
|
initialValues
|
|
300
337
|
]);
|
|
301
|
-
const [touched, setTouched] = (0,
|
|
302
|
-
const [changed, setChanged] = (0,
|
|
303
|
-
const [errors, setErrors] = (0,
|
|
304
|
-
const [saving, setSaving] = (0,
|
|
305
|
-
const validate = (0,
|
|
338
|
+
const [touched, setTouched] = (0, import_react8.useState)(createKeySet(initialValues, false));
|
|
339
|
+
const [changed, setChanged] = (0, import_react8.useState)(createKeySet(initialValues, false));
|
|
340
|
+
const [errors, setErrors] = (0, import_react8.useState)({});
|
|
341
|
+
const [saving, setSaving] = (0, import_react8.useState)(false);
|
|
342
|
+
const validate = (0, import_react8.useCallback)((values2) => {
|
|
306
343
|
let errors2 = (0, import_schema3.validateSchema)(schema, values2) ?? [];
|
|
307
344
|
if (errors2.length === 0 && onValidate) {
|
|
308
|
-
|
|
345
|
+
const validatedValues = values2;
|
|
346
|
+
errors2 = onValidate(validatedValues) ?? [];
|
|
309
347
|
}
|
|
310
348
|
setErrors(flatMap(errors2));
|
|
311
|
-
|
|
349
|
+
const valid = errors2.length === 0;
|
|
350
|
+
return valid;
|
|
312
351
|
}, [
|
|
313
352
|
schema,
|
|
314
353
|
onValidate
|
|
315
354
|
]);
|
|
316
|
-
const [schemaDirty, setSchemaDirty] = (0,
|
|
317
|
-
(0,
|
|
355
|
+
const [schemaDirty, setSchemaDirty] = (0, import_react8.useState)(false);
|
|
356
|
+
(0, import_react8.useEffect)(() => setSchemaDirty(true), [
|
|
318
357
|
schema
|
|
319
358
|
]);
|
|
320
|
-
(0,
|
|
359
|
+
(0, import_react8.useEffect)(() => {
|
|
321
360
|
if (schemaDirty) {
|
|
322
361
|
validate(values);
|
|
323
362
|
setSchemaDirty(false);
|
|
@@ -326,13 +365,13 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
326
365
|
values,
|
|
327
366
|
schemaDirty
|
|
328
367
|
]);
|
|
329
|
-
const canSave = (0,
|
|
368
|
+
const canSave = (0, import_react8.useMemo)(() => !saving && Object.keys(values).every((property) => touched[property] === false || !errors[property]), [
|
|
330
369
|
values,
|
|
331
370
|
touched,
|
|
332
371
|
errors,
|
|
333
372
|
saving
|
|
334
373
|
]);
|
|
335
|
-
const handleSave = (0,
|
|
374
|
+
const handleSave = (0, import_react8.useCallback)(async () => {
|
|
336
375
|
if (validate(values)) {
|
|
337
376
|
setSaving(true);
|
|
338
377
|
try {
|
|
@@ -346,17 +385,18 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
346
385
|
}, [
|
|
347
386
|
values,
|
|
348
387
|
validate,
|
|
349
|
-
onSave
|
|
388
|
+
onSave,
|
|
389
|
+
changed
|
|
350
390
|
]);
|
|
351
|
-
const getStatus = (0,
|
|
391
|
+
const getStatus = (0, import_react8.useCallback)((property) => ({
|
|
352
392
|
status: errors[property] ? "error" : void 0,
|
|
353
393
|
error: errors[property] ? errors[property] : void 0
|
|
354
394
|
}), [
|
|
355
395
|
touched,
|
|
356
396
|
errors
|
|
357
397
|
]);
|
|
358
|
-
const
|
|
359
|
-
return
|
|
398
|
+
const getFormValue = (property) => {
|
|
399
|
+
return (0, import_echo_schema4.getValue)(values, property);
|
|
360
400
|
};
|
|
361
401
|
const onValueChange = (property, type, value) => {
|
|
362
402
|
let parsedValue = value;
|
|
@@ -367,13 +407,15 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
367
407
|
} catch (err) {
|
|
368
408
|
import_log3.log.catch(err, void 0, {
|
|
369
409
|
F: __dxlog_file,
|
|
370
|
-
L:
|
|
410
|
+
L: 179,
|
|
371
411
|
S: void 0,
|
|
372
412
|
C: (f, a) => f(...a)
|
|
373
413
|
});
|
|
374
414
|
parsedValue = void 0;
|
|
375
415
|
}
|
|
376
|
-
const newValues =
|
|
416
|
+
const newValues = {
|
|
417
|
+
...(0, import_echo_schema4.setValue)(values, property, parsedValue)
|
|
418
|
+
};
|
|
377
419
|
setValues(newValues);
|
|
378
420
|
setChanged((prev) => ({
|
|
379
421
|
...prev,
|
|
@@ -387,7 +429,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
387
429
|
});
|
|
388
430
|
}
|
|
389
431
|
};
|
|
390
|
-
const onBlur = (0,
|
|
432
|
+
const onBlur = (0, import_react8.useCallback)((event) => {
|
|
391
433
|
const { name } = event.target;
|
|
392
434
|
setTouched((touched2) => ({
|
|
393
435
|
...touched2,
|
|
@@ -411,7 +453,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
411
453
|
handleSave,
|
|
412
454
|
// Field utils.
|
|
413
455
|
getStatus,
|
|
414
|
-
getValue,
|
|
456
|
+
getValue: getFormValue,
|
|
415
457
|
onValueChange,
|
|
416
458
|
onBlur
|
|
417
459
|
};
|
|
@@ -419,7 +461,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
419
461
|
var createKeySet = (obj, value) => {
|
|
420
462
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
421
463
|
F: __dxlog_file,
|
|
422
|
-
L:
|
|
464
|
+
L: 230,
|
|
423
465
|
S: void 0,
|
|
424
466
|
A: [
|
|
425
467
|
"obj",
|
|
@@ -439,24 +481,10 @@ var flatMap = (errors) => {
|
|
|
439
481
|
return result;
|
|
440
482
|
}, {});
|
|
441
483
|
};
|
|
442
|
-
var getByPath = (obj, path) => {
|
|
443
|
-
const [key, index] = path.split(".");
|
|
444
|
-
return index === void 0 ? obj[key] : obj[key][parseInt(index)];
|
|
445
|
-
};
|
|
446
|
-
var setByPath = (obj, path, value) => {
|
|
447
|
-
const [key, index] = path.split(".");
|
|
448
|
-
const newValue = index === void 0 ? value : [
|
|
449
|
-
...obj[key]
|
|
450
|
-
].map((v, i) => i === parseInt(index) ? value : v);
|
|
451
|
-
return {
|
|
452
|
-
...obj,
|
|
453
|
-
[key]: newValue
|
|
454
|
-
};
|
|
455
|
-
};
|
|
456
484
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
|
|
457
485
|
var padding = "px-2";
|
|
458
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, Custom }) => {
|
|
459
|
-
const onValid = (0,
|
|
486
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, testId, onValuesChanged, onValidate, onSave, onCancel, lookupComponent, Custom }) => {
|
|
487
|
+
const onValid = (0, import_react7.useMemo)(() => autoSave ? onSave : void 0, [
|
|
460
488
|
autoSave,
|
|
461
489
|
onSave
|
|
462
490
|
]);
|
|
@@ -468,7 +496,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
468
496
|
onValid,
|
|
469
497
|
onSave
|
|
470
498
|
});
|
|
471
|
-
const properties = (0,
|
|
499
|
+
const properties = (0, import_react7.useMemo)(() => {
|
|
472
500
|
const props = (0, import_schema2.getSchemaProperties)(schema.ast, values);
|
|
473
501
|
const filtered = filter ? filter(props) : props;
|
|
474
502
|
const findIndex = (props2, prop) => {
|
|
@@ -481,13 +509,13 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
481
509
|
filter,
|
|
482
510
|
values
|
|
483
511
|
]);
|
|
484
|
-
(0,
|
|
512
|
+
(0, import_react7.useEffect)(() => {
|
|
485
513
|
if (errors && Object.keys(errors).length) {
|
|
486
514
|
import_log2.log.warn("validation", {
|
|
487
515
|
errors
|
|
488
516
|
}, {
|
|
489
517
|
F: __dxlog_file2,
|
|
490
|
-
L:
|
|
518
|
+
L: 106,
|
|
491
519
|
S: void 0,
|
|
492
520
|
C: (f, a) => f(...a)
|
|
493
521
|
});
|
|
@@ -495,9 +523,9 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
495
523
|
}, [
|
|
496
524
|
errors
|
|
497
525
|
]);
|
|
498
|
-
return /* @__PURE__ */
|
|
526
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
499
527
|
role: "form",
|
|
500
|
-
className: (0,
|
|
528
|
+
className: (0, import_react_ui_theme3.mx)("flex flex-col w-full gap-2 py-2", classNames),
|
|
501
529
|
"data-testid": testId
|
|
502
530
|
}, properties.map((property) => {
|
|
503
531
|
const { ast, name, type, format, title, description, examples, options, array } = property;
|
|
@@ -507,14 +535,34 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
507
535
|
];
|
|
508
536
|
const label = title ?? (0, import_effect.pipe)(name, import_String.capitalize);
|
|
509
537
|
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
538
|
+
const FoundComponent = lookupComponent?.({
|
|
539
|
+
prop: name,
|
|
540
|
+
schema: import_echo_schema2.S.make(ast),
|
|
541
|
+
inputProps: {
|
|
542
|
+
property: name,
|
|
543
|
+
type,
|
|
544
|
+
format,
|
|
545
|
+
label,
|
|
546
|
+
disabled: readonly,
|
|
547
|
+
placeholder,
|
|
548
|
+
...inputProps
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
if (FoundComponent) {
|
|
552
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
553
|
+
key: name,
|
|
554
|
+
role: "none",
|
|
555
|
+
className: padding
|
|
556
|
+
}, FoundComponent);
|
|
557
|
+
}
|
|
510
558
|
let InputComponent = Custom?.[key.join(".")];
|
|
511
559
|
if (!InputComponent) {
|
|
512
560
|
if (options) {
|
|
513
|
-
return /* @__PURE__ */
|
|
561
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
514
562
|
key: name,
|
|
515
563
|
role: "none",
|
|
516
564
|
className: padding
|
|
517
|
-
}, /* @__PURE__ */
|
|
565
|
+
}, /* @__PURE__ */ import_react7.default.createElement(SelectInput, {
|
|
518
566
|
type,
|
|
519
567
|
format,
|
|
520
568
|
property: name,
|
|
@@ -530,7 +578,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
530
578
|
}
|
|
531
579
|
InputComponent = getInputComponent(type, format);
|
|
532
580
|
if (array) {
|
|
533
|
-
return /* @__PURE__ */
|
|
581
|
+
return /* @__PURE__ */ import_react7.default.createElement(ArrayField, {
|
|
534
582
|
key: name,
|
|
535
583
|
name,
|
|
536
584
|
type,
|
|
@@ -552,12 +600,12 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
552
600
|
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(ast, import_echo_schema2.AST.isTypeLiteral);
|
|
553
601
|
if (typeLiteral) {
|
|
554
602
|
const schema2 = import_echo_schema2.S.make(typeLiteral);
|
|
555
|
-
return /* @__PURE__ */
|
|
603
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
556
604
|
key: name,
|
|
557
605
|
role: "none"
|
|
558
|
-
}, /* @__PURE__ */
|
|
606
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
559
607
|
className: padding
|
|
560
|
-
}, label), /* @__PURE__ */
|
|
608
|
+
}, label), /* @__PURE__ */ import_react7.default.createElement(Form, {
|
|
561
609
|
schema: schema2,
|
|
562
610
|
path: key,
|
|
563
611
|
values: values[name] ?? {},
|
|
@@ -573,17 +621,17 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
573
621
|
type
|
|
574
622
|
}, {
|
|
575
623
|
F: __dxlog_file2,
|
|
576
|
-
L:
|
|
624
|
+
L: 213,
|
|
577
625
|
S: void 0,
|
|
578
626
|
C: (f, a) => f(...a)
|
|
579
627
|
});
|
|
580
628
|
return null;
|
|
581
629
|
}
|
|
582
|
-
return /* @__PURE__ */
|
|
630
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
583
631
|
key: name,
|
|
584
632
|
role: "none",
|
|
585
633
|
className: padding
|
|
586
|
-
}, /* @__PURE__ */
|
|
634
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputComponent, {
|
|
587
635
|
type,
|
|
588
636
|
format,
|
|
589
637
|
property: name,
|
|
@@ -592,7 +640,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
592
640
|
placeholder,
|
|
593
641
|
...inputProps
|
|
594
642
|
}));
|
|
595
|
-
}).filter(
|
|
643
|
+
}).filter(import_util3.isNotFalsy), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react7.default.createElement(FormActions, {
|
|
596
644
|
onCancel,
|
|
597
645
|
onSubmit: handleSave,
|
|
598
646
|
canSubmit: canSave,
|
|
@@ -600,7 +648,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
600
648
|
}));
|
|
601
649
|
};
|
|
602
650
|
var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholder, inputProps, Custom }) => {
|
|
603
|
-
const { t } = (0,
|
|
651
|
+
const { t } = (0, import_react_ui7.useTranslation)(translationKey);
|
|
604
652
|
const arrayValues = values[name] ?? [];
|
|
605
653
|
const key = [
|
|
606
654
|
name
|
|
@@ -612,26 +660,26 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
612
660
|
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(elementType, import_echo_schema2.AST.isTypeLiteral);
|
|
613
661
|
if (typeLiteral) {
|
|
614
662
|
const schema = import_echo_schema2.S.make(typeLiteral);
|
|
615
|
-
return /* @__PURE__ */
|
|
663
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
616
664
|
key: name,
|
|
617
665
|
role: "none",
|
|
618
|
-
className: (0,
|
|
619
|
-
}, /* @__PURE__ */
|
|
666
|
+
className: (0, import_react_ui_theme3.mx)(padding)
|
|
667
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
620
668
|
role: "none",
|
|
621
669
|
className: "flex flex-col gap-1"
|
|
622
670
|
}, arrayValues.map((value, index) => {
|
|
623
|
-
return /* @__PURE__ */
|
|
671
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
624
672
|
key: index,
|
|
625
673
|
role: "none",
|
|
626
674
|
className: "flex items-center gap-1"
|
|
627
|
-
}, /* @__PURE__ */
|
|
675
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
628
676
|
role: "none",
|
|
629
677
|
className: "flex-1"
|
|
630
|
-
}, /* @__PURE__ */
|
|
678
|
+
}, /* @__PURE__ */ import_react7.default.createElement(Form, {
|
|
631
679
|
schema,
|
|
632
680
|
path: [
|
|
633
681
|
...key,
|
|
634
|
-
index
|
|
682
|
+
`[${index}]`
|
|
635
683
|
],
|
|
636
684
|
values: value,
|
|
637
685
|
onValuesChanged: (childValues) => {
|
|
@@ -642,7 +690,7 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
642
690
|
inputProps.onValueChange(name, "object", newValues);
|
|
643
691
|
},
|
|
644
692
|
Custom
|
|
645
|
-
})), /* @__PURE__ */
|
|
693
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
646
694
|
icon: "ph--trash--regular",
|
|
647
695
|
iconOnly: true,
|
|
648
696
|
label: t("button remove"),
|
|
@@ -651,10 +699,10 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
651
699
|
inputProps.onValueChange(name, type, newValues);
|
|
652
700
|
}
|
|
653
701
|
}));
|
|
654
|
-
})), /* @__PURE__ */
|
|
702
|
+
})), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
655
703
|
role: "none",
|
|
656
704
|
className: "flex justify-between items-center plb-1"
|
|
657
|
-
}, /* @__PURE__ */
|
|
705
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
658
706
|
icon: "ph--plus--regular",
|
|
659
707
|
iconOnly: true,
|
|
660
708
|
label: t("button add"),
|
|
@@ -667,7 +715,7 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
667
715
|
}
|
|
668
716
|
})));
|
|
669
717
|
}
|
|
670
|
-
return /* @__PURE__ */
|
|
718
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
671
719
|
key: name,
|
|
672
720
|
role: "none"
|
|
673
721
|
}, "Nested form not supported in arrays, yet.");
|
|
@@ -676,30 +724,30 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
676
724
|
if (!InputComponent) {
|
|
677
725
|
return null;
|
|
678
726
|
}
|
|
679
|
-
return /* @__PURE__ */
|
|
727
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
680
728
|
role: "none",
|
|
681
729
|
key: "meta-input",
|
|
682
|
-
className: (0,
|
|
683
|
-
}, /* @__PURE__ */
|
|
730
|
+
className: (0, import_react_ui_theme3.mx)(padding)
|
|
731
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputHeader, null, label), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
684
732
|
role: "none",
|
|
685
733
|
className: "flex flex-col gap-1"
|
|
686
|
-
}, arrayValues.map((_, index) => /* @__PURE__ */
|
|
734
|
+
}, arrayValues.map((_, index) => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
687
735
|
key: index,
|
|
688
736
|
role: "none",
|
|
689
737
|
className: "flex items-start gap-1"
|
|
690
|
-
}, /* @__PURE__ */
|
|
738
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
691
739
|
role: "none",
|
|
692
740
|
className: "flex-1"
|
|
693
|
-
}, /* @__PURE__ */
|
|
741
|
+
}, /* @__PURE__ */ import_react7.default.createElement(InputComponent, {
|
|
694
742
|
type,
|
|
695
743
|
format,
|
|
696
744
|
label,
|
|
697
745
|
inputOnly: true,
|
|
698
|
-
property: `${name}
|
|
746
|
+
property: `${name}[${index}]`,
|
|
699
747
|
disabled: readonly,
|
|
700
748
|
placeholder,
|
|
701
749
|
...inputProps
|
|
702
|
-
})), /* @__PURE__ */
|
|
750
|
+
})), /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
703
751
|
icon: "ph--trash--regular",
|
|
704
752
|
iconOnly: true,
|
|
705
753
|
label: t("button remove"),
|
|
@@ -707,10 +755,10 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
707
755
|
const newValues = arrayValues.filter((_2, i) => i !== index);
|
|
708
756
|
inputProps.onValueChange(name, type, newValues);
|
|
709
757
|
}
|
|
710
|
-
})))), /* @__PURE__ */
|
|
758
|
+
})))), /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
711
759
|
role: "none",
|
|
712
760
|
className: "flex justify-between items-center plb-1"
|
|
713
|
-
}, /* @__PURE__ */
|
|
761
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
714
762
|
icon: "ph--plus--regular",
|
|
715
763
|
iconOnly: true,
|
|
716
764
|
label: t("button add"),
|
|
@@ -724,19 +772,19 @@ var ArrayField = ({ name, type, label, ast, values, format, readonly, placeholde
|
|
|
724
772
|
})));
|
|
725
773
|
};
|
|
726
774
|
var FormActions = ({ onCancel, onSubmit, canSubmit, readonly }) => {
|
|
727
|
-
const { t } = (0,
|
|
728
|
-
return /* @__PURE__ */
|
|
775
|
+
const { t } = (0, import_react_ui7.useTranslation)(translationKey);
|
|
776
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
729
777
|
role: "none",
|
|
730
778
|
className: "flex justify-center"
|
|
731
|
-
}, /* @__PURE__ */
|
|
779
|
+
}, /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
732
780
|
role: "none",
|
|
733
|
-
className: (0,
|
|
734
|
-
}, onCancel && !readonly && /* @__PURE__ */
|
|
781
|
+
className: (0, import_react_ui_theme3.mx)(onCancel && !readonly && "grid grid-cols-2 gap-2")
|
|
782
|
+
}, onCancel && !readonly && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
735
783
|
"data-testid": "cancel-button",
|
|
736
784
|
icon: "ph--x--regular",
|
|
737
785
|
label: t("button cancel"),
|
|
738
786
|
onClick: onCancel
|
|
739
|
-
}), onSubmit && /* @__PURE__ */
|
|
787
|
+
}), onSubmit && /* @__PURE__ */ import_react7.default.createElement(import_react_ui7.IconButton, {
|
|
740
788
|
type: "submit",
|
|
741
789
|
"data-testid": "save-button",
|
|
742
790
|
disabled: !canSubmit,
|
|
@@ -758,9 +806,11 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
758
806
|
if (!registry) {
|
|
759
807
|
return;
|
|
760
808
|
}
|
|
761
|
-
const subscription = registry.subscribe(setSchemas)
|
|
809
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
810
|
+
fire: true
|
|
811
|
+
});
|
|
762
812
|
const t2 = setTimeout(async () => {
|
|
763
|
-
const schemas2 = await registry.query();
|
|
813
|
+
const schemas2 = await registry.query().run();
|
|
764
814
|
setSchemas(schemas2);
|
|
765
815
|
});
|
|
766
816
|
return () => {
|
|
@@ -770,9 +820,9 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
770
820
|
}, [
|
|
771
821
|
registry
|
|
772
822
|
]);
|
|
773
|
-
const [
|
|
823
|
+
const [referenceSchema, setReferenceSchema] = (0, import_react2.useState)();
|
|
774
824
|
(0, import_react2.useEffect)(() => {
|
|
775
|
-
|
|
825
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
776
826
|
}, [
|
|
777
827
|
schemas,
|
|
778
828
|
props?.referenceSchema
|
|
@@ -781,14 +831,24 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
781
831
|
fieldSchema: (0, import_schema.getFormatSchema)(props?.format)
|
|
782
832
|
});
|
|
783
833
|
const handleValuesChanged = (0, import_react2.useCallback)((_props) => {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
834
|
+
setFieldSchema((prev) => {
|
|
835
|
+
const fieldSchema2 = (0, import_schema.getFormatSchema)(_props.format);
|
|
836
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
837
|
+
return prev;
|
|
838
|
+
}
|
|
839
|
+
return {
|
|
840
|
+
fieldSchema: fieldSchema2
|
|
841
|
+
};
|
|
842
|
+
});
|
|
843
|
+
setReferenceSchema((prev) => {
|
|
844
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
845
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
846
|
+
if (newSchema) {
|
|
847
|
+
return newSchema;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return prev;
|
|
851
|
+
});
|
|
792
852
|
setProps((props2) => {
|
|
793
853
|
const type = import_echo_schema.formatToType[_props.format];
|
|
794
854
|
if (props2.type !== type) {
|
|
@@ -802,7 +862,8 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
802
862
|
});
|
|
803
863
|
}, [
|
|
804
864
|
schemas,
|
|
805
|
-
props
|
|
865
|
+
props.format,
|
|
866
|
+
props.referenceSchema
|
|
806
867
|
]);
|
|
807
868
|
const handleValidate = (0, import_react2.useCallback)(({ property }) => {
|
|
808
869
|
if (property && view.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
@@ -834,12 +895,38 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
834
895
|
}, [
|
|
835
896
|
onSave
|
|
836
897
|
]);
|
|
898
|
+
const Custom = (0, import_react2.useMemo)(() => ({
|
|
899
|
+
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
900
|
+
...props2,
|
|
901
|
+
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
902
|
+
value,
|
|
903
|
+
label: t(`format ${value}`)
|
|
904
|
+
}))
|
|
905
|
+
}),
|
|
906
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
907
|
+
...props2,
|
|
908
|
+
options: schemas.map((schema) => ({
|
|
909
|
+
value: schema.typename
|
|
910
|
+
}))
|
|
911
|
+
}),
|
|
912
|
+
["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
913
|
+
...props2,
|
|
914
|
+
options: referenceSchema ? (0, import_schema.getSchemaProperties)(referenceSchema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
915
|
+
value: p.name
|
|
916
|
+
})) : []
|
|
917
|
+
})
|
|
918
|
+
}), [
|
|
919
|
+
t,
|
|
920
|
+
schemas,
|
|
921
|
+
referenceSchema
|
|
922
|
+
]);
|
|
923
|
+
const propIsNotType = (0, import_react2.useCallback)((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
837
924
|
if (!fieldSchema) {
|
|
838
925
|
import_log.log.warn("invalid format", {
|
|
839
926
|
props
|
|
840
927
|
}, {
|
|
841
928
|
F: __dxlog_file3,
|
|
842
|
-
L:
|
|
929
|
+
L: 173,
|
|
843
930
|
S: void 0,
|
|
844
931
|
C: (f, a) => f(...a)
|
|
845
932
|
});
|
|
@@ -850,7 +937,7 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
850
937
|
autoFocus: true,
|
|
851
938
|
values: props,
|
|
852
939
|
schema: fieldSchema,
|
|
853
|
-
filter:
|
|
940
|
+
filter: propIsNotType,
|
|
854
941
|
sort: [
|
|
855
942
|
"property",
|
|
856
943
|
"format"
|
|
@@ -859,46 +946,26 @@ var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
|
859
946
|
onValidate: handleValidate,
|
|
860
947
|
onSave: handleSave,
|
|
861
948
|
onCancel: handleCancel,
|
|
862
|
-
Custom
|
|
863
|
-
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
864
|
-
...props2,
|
|
865
|
-
options: import_echo_schema.FormatEnums.filter((value) => value !== import_echo_schema.FormatEnum.None).map((value) => ({
|
|
866
|
-
value,
|
|
867
|
-
label: t(`format ${value}`)
|
|
868
|
-
}))
|
|
869
|
-
}),
|
|
870
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
871
|
-
...props2,
|
|
872
|
-
options: schemas.map((schema2) => ({
|
|
873
|
-
value: schema2.typename
|
|
874
|
-
}))
|
|
875
|
-
}),
|
|
876
|
-
["referencePath"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
877
|
-
...props2,
|
|
878
|
-
options: schema ? (0, import_schema.getSchemaProperties)(schema.schema.ast).sort(import_schema.sortProperties).map((p) => ({
|
|
879
|
-
value: p.name
|
|
880
|
-
})) : []
|
|
881
|
-
})
|
|
882
|
-
}
|
|
949
|
+
Custom
|
|
883
950
|
});
|
|
884
951
|
};
|
|
885
952
|
var grid = "grid grid-cols-[32px_1fr_32px] min-bs-[2.5rem]";
|
|
886
|
-
var ViewMetaSchema =
|
|
887
|
-
name:
|
|
888
|
-
[
|
|
953
|
+
var ViewMetaSchema = import_echo_schema5.S.Struct({
|
|
954
|
+
name: import_echo_schema5.S.String.annotations({
|
|
955
|
+
[import_echo_schema5.AST.TitleAnnotationId]: "View"
|
|
889
956
|
}),
|
|
890
|
-
typename:
|
|
891
|
-
[
|
|
957
|
+
typename: import_echo_schema5.Format.DXN.annotations({
|
|
958
|
+
[import_echo_schema5.AST.TitleAnnotationId]: "Typename"
|
|
892
959
|
})
|
|
893
|
-
}).pipe(
|
|
894
|
-
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
895
|
-
const { t } = (0,
|
|
896
|
-
const projection = (0,
|
|
960
|
+
}).pipe(import_echo_schema5.S.mutable);
|
|
961
|
+
var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading = false, onTypenameChanged, onDelete }) => {
|
|
962
|
+
const { t } = (0, import_react_ui8.useTranslation)(translationKey);
|
|
963
|
+
const projection = (0, import_react9.useMemo)(() => new import_schema4.ViewProjection(schema, view), [
|
|
897
964
|
schema,
|
|
898
965
|
view
|
|
899
966
|
]);
|
|
900
|
-
const [field, setField] = (0,
|
|
901
|
-
const viewValues = (0,
|
|
967
|
+
const [field, setField] = (0, import_react9.useState)();
|
|
968
|
+
const viewValues = (0, import_react9.useMemo)(() => {
|
|
902
969
|
return {
|
|
903
970
|
name: view.name,
|
|
904
971
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
@@ -908,77 +975,81 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
908
975
|
}, [
|
|
909
976
|
view
|
|
910
977
|
]);
|
|
911
|
-
const handleViewUpdate = (0,
|
|
978
|
+
const handleViewUpdate = (0, import_react9.useCallback)(({ name, typename }) => {
|
|
912
979
|
requestAnimationFrame(() => {
|
|
913
|
-
view.name
|
|
914
|
-
|
|
915
|
-
|
|
980
|
+
if (view.name !== name) {
|
|
981
|
+
view.name = name;
|
|
982
|
+
}
|
|
983
|
+
if (view.query.type !== typename) {
|
|
984
|
+
onTypenameChanged(typename);
|
|
985
|
+
}
|
|
916
986
|
});
|
|
917
987
|
}, [
|
|
918
988
|
view,
|
|
919
|
-
schema
|
|
989
|
+
schema,
|
|
990
|
+
onTypenameChanged
|
|
920
991
|
]);
|
|
921
|
-
const handleSelect = (0,
|
|
992
|
+
const handleSelect = (0, import_react9.useCallback)((field2) => {
|
|
922
993
|
setField((f) => f === field2 ? void 0 : field2);
|
|
923
994
|
}, []);
|
|
924
|
-
const handleAdd = (0,
|
|
995
|
+
const handleAdd = (0, import_react9.useCallback)(() => {
|
|
925
996
|
const field2 = projection.createFieldProjection();
|
|
926
997
|
setField(field2);
|
|
927
998
|
}, [
|
|
928
999
|
view
|
|
929
1000
|
]);
|
|
930
|
-
const handleMove = (0,
|
|
931
|
-
(0,
|
|
1001
|
+
const handleMove = (0, import_react9.useCallback)((fromIndex, toIndex) => {
|
|
1002
|
+
(0, import_util4.arrayMove)(view.fields, fromIndex, toIndex);
|
|
932
1003
|
}, [
|
|
933
1004
|
view.fields
|
|
934
1005
|
]);
|
|
935
|
-
const handleClose = (0,
|
|
936
|
-
return /* @__PURE__ */
|
|
1006
|
+
const handleClose = (0, import_react9.useCallback)(() => setField(void 0), []);
|
|
1007
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
937
1008
|
role: "none",
|
|
938
|
-
className: (0,
|
|
939
|
-
}, /* @__PURE__ */
|
|
1009
|
+
className: (0, import_react_ui_theme4.mx)("flex flex-col w-full divide-y divide-separator", classNames)
|
|
1010
|
+
}, /* @__PURE__ */ import_react9.default.createElement(Form, {
|
|
940
1011
|
autoFocus: true,
|
|
941
1012
|
autoSave: true,
|
|
942
1013
|
schema: ViewMetaSchema,
|
|
943
1014
|
values: viewValues,
|
|
944
1015
|
onSave: handleViewUpdate
|
|
945
|
-
}), /* @__PURE__ */
|
|
1016
|
+
}), /* @__PURE__ */ import_react9.default.createElement("div", null, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
946
1017
|
role: "none",
|
|
947
1018
|
className: "p-2"
|
|
948
|
-
}, /* @__PURE__ */
|
|
949
|
-
className: (0,
|
|
950
|
-
}, t("fields label"))), /* @__PURE__ */
|
|
1019
|
+
}, /* @__PURE__ */ import_react9.default.createElement("label", {
|
|
1020
|
+
className: (0, import_react_ui_theme4.mx)(import_react_ui_theme4.inputTextLabel)
|
|
1021
|
+
}, t("fields label"))), /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.Root, {
|
|
951
1022
|
items: view.fields,
|
|
952
|
-
isItem:
|
|
1023
|
+
isItem: import_echo_schema5.S.is(import_schema4.FieldSchema),
|
|
953
1024
|
getId: (field2) => field2.id,
|
|
954
1025
|
onMove: handleMove
|
|
955
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
1026
|
+
}, ({ items: fields }) => /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, showHeading && /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
956
1027
|
role: "heading",
|
|
957
1028
|
className: grid
|
|
958
|
-
}, /* @__PURE__ */
|
|
1029
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", null), /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
959
1030
|
className: "flex items-center text-sm"
|
|
960
|
-
}, t("field path label"))), /* @__PURE__ */
|
|
1031
|
+
}, t("field path label"))), /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
961
1032
|
role: "list",
|
|
962
1033
|
className: "flex flex-col w-full"
|
|
963
|
-
}, fields?.map((field2) => /* @__PURE__ */
|
|
1034
|
+
}, fields?.map((field2) => /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.Item, {
|
|
964
1035
|
key: field2.id,
|
|
965
1036
|
item: field2,
|
|
966
|
-
classNames: (0,
|
|
967
|
-
}, /* @__PURE__ */
|
|
1037
|
+
classNames: (0, import_react_ui_theme4.mx)(grid, import_react_ui_theme4.ghostHover, "cursor-pointer")
|
|
1038
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.ItemDragHandle, null), /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.ItemTitle, {
|
|
968
1039
|
onClick: () => handleSelect(field2)
|
|
969
|
-
}, field2.path), /* @__PURE__ */
|
|
1040
|
+
}, field2.path), /* @__PURE__ */ import_react9.default.createElement(import_react_ui_list.List.ItemDeleteButton, {
|
|
970
1041
|
disabled: view.fields.length <= 1,
|
|
971
1042
|
onClick: () => onDelete(field2.id)
|
|
972
|
-
}))))))), field && /* @__PURE__ */
|
|
1043
|
+
}))))))), field && /* @__PURE__ */ import_react9.default.createElement(FieldEditor, {
|
|
973
1044
|
key: field.id,
|
|
974
1045
|
view,
|
|
975
1046
|
projection,
|
|
976
1047
|
field,
|
|
977
1048
|
registry,
|
|
978
1049
|
onSave: handleClose
|
|
979
|
-
}), !readonly && !field && /* @__PURE__ */
|
|
1050
|
+
}), !readonly && !field && /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
980
1051
|
className: "flex p-2 justify-center"
|
|
981
|
-
}, /* @__PURE__ */
|
|
1052
|
+
}, /* @__PURE__ */ import_react9.default.createElement(import_react_ui8.IconButton, {
|
|
982
1053
|
icon: "ph--plus--regular",
|
|
983
1054
|
label: t("button add property"),
|
|
984
1055
|
onClick: handleAdd,
|
|
@@ -992,7 +1063,7 @@ var parseValue = ({ type, format, value }) => {
|
|
|
992
1063
|
}
|
|
993
1064
|
const parseScalar = (type2) => {
|
|
994
1065
|
switch (type2) {
|
|
995
|
-
case
|
|
1066
|
+
case import_echo_schema6.TypeEnum.Boolean: {
|
|
996
1067
|
if (typeof value === "string") {
|
|
997
1068
|
const lowercaseValue = value.toLowerCase();
|
|
998
1069
|
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
@@ -1003,13 +1074,13 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1003
1074
|
}
|
|
1004
1075
|
return Boolean(value);
|
|
1005
1076
|
}
|
|
1006
|
-
case
|
|
1077
|
+
case import_echo_schema6.TypeEnum.Number: {
|
|
1007
1078
|
const cleaned = typeof value === "string" ? value.replace(/[^0-9.-]+/g, "") : value;
|
|
1008
1079
|
const num = Number(cleaned);
|
|
1009
1080
|
return Number.isNaN(num) ? null : num;
|
|
1010
1081
|
}
|
|
1011
|
-
case
|
|
1012
|
-
case
|
|
1082
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1083
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1013
1084
|
return String(value);
|
|
1014
1085
|
default: {
|
|
1015
1086
|
return value;
|
|
@@ -1020,22 +1091,22 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1020
1091
|
return parseScalar(type);
|
|
1021
1092
|
}
|
|
1022
1093
|
switch (format) {
|
|
1023
|
-
case
|
|
1024
|
-
return parseScalar(
|
|
1025
|
-
case
|
|
1026
|
-
case
|
|
1027
|
-
case
|
|
1028
|
-
return parseScalar(
|
|
1029
|
-
case
|
|
1030
|
-
case
|
|
1031
|
-
return parseScalar(
|
|
1094
|
+
case import_echo_schema6.FormatEnum.Boolean:
|
|
1095
|
+
return parseScalar(import_echo_schema6.TypeEnum.Boolean);
|
|
1096
|
+
case import_echo_schema6.FormatEnum.Number:
|
|
1097
|
+
case import_echo_schema6.FormatEnum.Percent:
|
|
1098
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1099
|
+
return parseScalar(import_echo_schema6.TypeEnum.Number);
|
|
1100
|
+
case import_echo_schema6.FormatEnum.String:
|
|
1101
|
+
case import_echo_schema6.FormatEnum.Markdown: {
|
|
1102
|
+
return parseScalar(import_echo_schema6.TypeEnum.String);
|
|
1032
1103
|
}
|
|
1033
|
-
case
|
|
1034
|
-
throw new Error(`unexpected format: ${
|
|
1035
|
-
case
|
|
1036
|
-
case
|
|
1037
|
-
case
|
|
1038
|
-
case
|
|
1104
|
+
case import_echo_schema6.FormatEnum.Ref:
|
|
1105
|
+
throw new Error(`unexpected format: ${import_echo_schema6.FormatEnum.Ref}`);
|
|
1106
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1107
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1108
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1109
|
+
case import_echo_schema6.FormatEnum.Timestamp: {
|
|
1039
1110
|
const date = new Date(value);
|
|
1040
1111
|
return isNaN(date.getTime()) ? null : date;
|
|
1041
1112
|
}
|
|
@@ -1047,19 +1118,19 @@ var parseValue = ({ type, format, value }) => {
|
|
|
1047
1118
|
var cellClassesForFieldType = ({ type, format }) => {
|
|
1048
1119
|
if (!format) {
|
|
1049
1120
|
switch (type) {
|
|
1050
|
-
case
|
|
1121
|
+
case import_echo_schema6.TypeEnum.Number:
|
|
1051
1122
|
return [
|
|
1052
1123
|
"text-right",
|
|
1053
1124
|
"font-mono"
|
|
1054
1125
|
];
|
|
1055
|
-
case
|
|
1126
|
+
case import_echo_schema6.TypeEnum.Boolean:
|
|
1056
1127
|
return [
|
|
1057
1128
|
"text-right",
|
|
1058
1129
|
"font-mono"
|
|
1059
1130
|
];
|
|
1060
|
-
case
|
|
1131
|
+
case import_echo_schema6.TypeEnum.String:
|
|
1061
1132
|
return void 0;
|
|
1062
|
-
case
|
|
1133
|
+
case import_echo_schema6.TypeEnum.Ref:
|
|
1063
1134
|
return void 0;
|
|
1064
1135
|
default: {
|
|
1065
1136
|
return void 0;
|
|
@@ -1067,20 +1138,20 @@ var cellClassesForFieldType = ({ type, format }) => {
|
|
|
1067
1138
|
}
|
|
1068
1139
|
}
|
|
1069
1140
|
switch (format) {
|
|
1070
|
-
case
|
|
1141
|
+
case import_echo_schema6.FormatEnum.Markdown:
|
|
1071
1142
|
return void 0;
|
|
1072
|
-
case
|
|
1073
|
-
case
|
|
1074
|
-
case
|
|
1075
|
-
case
|
|
1143
|
+
case import_echo_schema6.FormatEnum.Timestamp:
|
|
1144
|
+
case import_echo_schema6.FormatEnum.DateTime:
|
|
1145
|
+
case import_echo_schema6.FormatEnum.Date:
|
|
1146
|
+
case import_echo_schema6.FormatEnum.Time:
|
|
1076
1147
|
return [
|
|
1077
1148
|
"font-mono"
|
|
1078
1149
|
];
|
|
1079
|
-
case
|
|
1150
|
+
case import_echo_schema6.FormatEnum.Currency:
|
|
1080
1151
|
return [
|
|
1081
1152
|
"text-right"
|
|
1082
1153
|
];
|
|
1083
|
-
case
|
|
1154
|
+
case import_echo_schema6.FormatEnum.JSON:
|
|
1084
1155
|
return [
|
|
1085
1156
|
"font-mono"
|
|
1086
1157
|
];
|
|
@@ -1098,12 +1169,12 @@ var pathNotUniqueError = (path) => ({
|
|
|
1098
1169
|
var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
1099
1170
|
const formatScalar = (type2) => {
|
|
1100
1171
|
switch (type2) {
|
|
1101
|
-
case
|
|
1172
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1102
1173
|
return value.toLocaleString().toUpperCase();
|
|
1103
|
-
case
|
|
1174
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1104
1175
|
return value.toLocaleString(locale);
|
|
1105
|
-
case
|
|
1106
|
-
case
|
|
1176
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1177
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1107
1178
|
return String(value);
|
|
1108
1179
|
default: {
|
|
1109
1180
|
return String(value);
|
|
@@ -1114,20 +1185,20 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1114
1185
|
return formatScalar(type);
|
|
1115
1186
|
}
|
|
1116
1187
|
switch (format) {
|
|
1117
|
-
case
|
|
1118
|
-
return formatScalar(
|
|
1188
|
+
case import_echo_schema7.FormatEnum.Boolean: {
|
|
1189
|
+
return formatScalar(import_echo_schema7.TypeEnum.Boolean);
|
|
1119
1190
|
}
|
|
1120
|
-
case
|
|
1121
|
-
return formatScalar(
|
|
1191
|
+
case import_echo_schema7.FormatEnum.Number: {
|
|
1192
|
+
return formatScalar(import_echo_schema7.TypeEnum.Number);
|
|
1122
1193
|
}
|
|
1123
|
-
case
|
|
1124
|
-
case
|
|
1125
|
-
return formatScalar(
|
|
1194
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1195
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1196
|
+
return formatScalar(import_echo_schema7.TypeEnum.String);
|
|
1126
1197
|
}
|
|
1127
|
-
case
|
|
1198
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1128
1199
|
return `${value * 100}%`;
|
|
1129
1200
|
}
|
|
1130
|
-
case
|
|
1201
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1131
1202
|
return value.toLocaleString(locale, {
|
|
1132
1203
|
style: "currency",
|
|
1133
1204
|
currency: "USD",
|
|
@@ -1135,13 +1206,13 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1135
1206
|
maximumFractionDigits: 2
|
|
1136
1207
|
});
|
|
1137
1208
|
}
|
|
1138
|
-
case
|
|
1139
|
-
case
|
|
1140
|
-
case
|
|
1209
|
+
case import_echo_schema7.FormatEnum.DateTime:
|
|
1210
|
+
case import_echo_schema7.FormatEnum.Date:
|
|
1211
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1141
1212
|
const date = new Date(value);
|
|
1142
|
-
if (format ===
|
|
1213
|
+
if (format === import_echo_schema7.FormatEnum.DateTime) {
|
|
1143
1214
|
return date.toLocaleString(locale);
|
|
1144
|
-
} else if (format ===
|
|
1215
|
+
} else if (format === import_echo_schema7.FormatEnum.Date) {
|
|
1145
1216
|
return date.toLocaleDateString(locale);
|
|
1146
1217
|
} else {
|
|
1147
1218
|
return date.toLocaleTimeString(locale);
|
|
@@ -1158,10 +1229,10 @@ var formatForDisplay = ({ type, format, value, locale = void 0 }) => {
|
|
|
1158
1229
|
var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
1159
1230
|
const formatScalar = (type2) => {
|
|
1160
1231
|
switch (type2) {
|
|
1161
|
-
case
|
|
1162
|
-
case
|
|
1163
|
-
case
|
|
1164
|
-
case
|
|
1232
|
+
case import_echo_schema7.TypeEnum.Boolean:
|
|
1233
|
+
case import_echo_schema7.TypeEnum.Number:
|
|
1234
|
+
case import_echo_schema7.TypeEnum.String:
|
|
1235
|
+
case import_echo_schema7.TypeEnum.Ref:
|
|
1165
1236
|
return String(value);
|
|
1166
1237
|
default:
|
|
1167
1238
|
return String(value);
|
|
@@ -1171,27 +1242,27 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1171
1242
|
return formatScalar(type);
|
|
1172
1243
|
}
|
|
1173
1244
|
switch (format) {
|
|
1174
|
-
case
|
|
1175
|
-
case
|
|
1176
|
-
case
|
|
1177
|
-
case
|
|
1245
|
+
case import_echo_schema7.FormatEnum.Boolean:
|
|
1246
|
+
case import_echo_schema7.FormatEnum.Number:
|
|
1247
|
+
case import_echo_schema7.FormatEnum.String:
|
|
1248
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1178
1249
|
return formatScalar(type);
|
|
1179
1250
|
}
|
|
1180
|
-
case
|
|
1251
|
+
case import_echo_schema7.FormatEnum.Percent: {
|
|
1181
1252
|
return String(value * 100);
|
|
1182
1253
|
}
|
|
1183
|
-
case
|
|
1254
|
+
case import_echo_schema7.FormatEnum.Currency: {
|
|
1184
1255
|
return String(value);
|
|
1185
1256
|
}
|
|
1186
|
-
case
|
|
1257
|
+
case import_echo_schema7.FormatEnum.DateTime: {
|
|
1187
1258
|
const date = new Date(value);
|
|
1188
1259
|
return date.toISOString();
|
|
1189
1260
|
}
|
|
1190
|
-
case
|
|
1261
|
+
case import_echo_schema7.FormatEnum.Date: {
|
|
1191
1262
|
const date = new Date(value);
|
|
1192
1263
|
return date.toISOString().split("T")[0];
|
|
1193
1264
|
}
|
|
1194
|
-
case
|
|
1265
|
+
case import_echo_schema7.FormatEnum.Time: {
|
|
1195
1266
|
const date = new Date(value);
|
|
1196
1267
|
return date.toISOString().split("T")[1].split(".")[0];
|
|
1197
1268
|
}
|
|
@@ -1207,11 +1278,12 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1207
1278
|
FieldEditor,
|
|
1208
1279
|
Form,
|
|
1209
1280
|
FormActions,
|
|
1210
|
-
|
|
1281
|
+
GeoPointInput,
|
|
1211
1282
|
InputHeader,
|
|
1212
1283
|
NumberInput,
|
|
1213
1284
|
SelectInput,
|
|
1214
1285
|
TextInput,
|
|
1286
|
+
TupleInput,
|
|
1215
1287
|
ViewEditor,
|
|
1216
1288
|
cellClassesForFieldType,
|
|
1217
1289
|
cellClassesForRowSelection,
|