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