@dxos/react-ui-form 0.7.1 → 0.7.2-main.f1adc9f
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 +137 -111
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +130 -104
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +137 -111
- 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/Custom.d.ts +2 -1
- package/dist/types/src/components/Form/Custom.d.ts.map +1 -1
- package/dist/types/src/components/Form/Defaults.d.ts +11 -4
- package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +6 -5
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +1 -4
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Input.d.ts +3 -8
- package/dist/types/src/components/Form/Input.d.ts.map +1 -1
- package/dist/types/src/components/Form/factory.d.ts +2 -2
- package/dist/types/src/components/Form/factory.d.ts.map +1 -1
- 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 +8 -7
- package/dist/types/src/hooks/useForm.d.ts.map +1 -1
- package/package.json +22 -24
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.tsx +8 -8
- package/src/components/Form/Custom.tsx +9 -9
- package/src/components/Form/Defaults.tsx +10 -5
- package/src/components/Form/Form.stories.tsx +6 -6
- package/src/components/Form/Form.tsx +52 -28
- package/src/components/Form/Input.tsx +3 -7
- package/src/components/Form/factory.tsx +4 -4
- package/src/components/ViewEditor/ViewEditor.stories.tsx +1 -2
- package/src/components/ViewEditor/ViewEditor.tsx +8 -7
- package/src/hooks/useForm.ts +18 -17
package/dist/lib/node/index.cjs
CHANGED
|
@@ -32,8 +32,8 @@ __export(node_exports, {
|
|
|
32
32
|
DeprecatedFormInput: () => DeprecatedFormInput,
|
|
33
33
|
FieldEditor: () => FieldEditor,
|
|
34
34
|
Form: () => Form,
|
|
35
|
+
GeiPointInput: () => GeiPointInput,
|
|
35
36
|
InputHeader: () => InputHeader,
|
|
36
|
-
LatLngInput: () => LatLngInput,
|
|
37
37
|
NumberInput: () => NumberInput,
|
|
38
38
|
SelectInput: () => SelectInput,
|
|
39
39
|
TextInput: () => TextInput,
|
|
@@ -55,20 +55,22 @@ var import_echo_schema = require("@dxos/echo-schema");
|
|
|
55
55
|
var import_log = require("@dxos/log");
|
|
56
56
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
57
57
|
var import_schema = require("@dxos/schema");
|
|
58
|
+
var import_effect = require("effect");
|
|
59
|
+
var import_String = require("effect/String");
|
|
58
60
|
var import_react3 = __toESM(require("react"));
|
|
59
61
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
60
|
-
var
|
|
62
|
+
var import_effect2 = require("@dxos/effect");
|
|
61
63
|
var import_log2 = require("@dxos/log");
|
|
62
64
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
63
65
|
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
64
66
|
var import_schema2 = require("@dxos/schema");
|
|
65
67
|
var import_util = require("@dxos/util");
|
|
66
|
-
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
67
68
|
var import_react4 = __toESM(require("react"));
|
|
68
69
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
69
70
|
var import_react5 = __toESM(require("react"));
|
|
70
71
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
71
72
|
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
73
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
72
74
|
var import_react6 = __toESM(require("react"));
|
|
73
75
|
var import_react_ui6 = require("@dxos/react-ui");
|
|
74
76
|
var import_react7 = require("react");
|
|
@@ -173,52 +175,13 @@ var InputHeader = ({ children, error }) => {
|
|
|
173
175
|
side: "bottom"
|
|
174
176
|
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Tooltip.Arrow, null), error)));
|
|
175
177
|
};
|
|
176
|
-
var
|
|
177
|
-
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
178
|
+
var TextInput = ({ property, type, label, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
|
|
178
179
|
const { status, error } = getStatus?.(property);
|
|
179
|
-
const { lat = 0, lng = 0 } = getValue(property) ?? {};
|
|
180
180
|
return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
|
|
181
181
|
validationValence: status
|
|
182
182
|
}, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
|
|
183
183
|
error
|
|
184
|
-
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement(
|
|
185
|
-
className: "grid grid-cols-2 gap-2"
|
|
186
|
-
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
|
|
187
|
-
type: "number",
|
|
188
|
-
disabled,
|
|
189
|
-
placeholder: t("placeholder latitude"),
|
|
190
|
-
value: lat,
|
|
191
|
-
onChange: (event) => onValueChange(property, type, {
|
|
192
|
-
lat: safeParseFloat(event.target.value, 0),
|
|
193
|
-
lng
|
|
194
|
-
}),
|
|
195
|
-
onBlur
|
|
196
|
-
}), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
|
|
197
|
-
type: "number",
|
|
198
|
-
disabled,
|
|
199
|
-
placeholder: t("placeholder longitude"),
|
|
200
|
-
value: lng,
|
|
201
|
-
onChange: (event) => onValueChange(property, type, {
|
|
202
|
-
lat,
|
|
203
|
-
lng: safeParseFloat(event.target.value, 0)
|
|
204
|
-
}),
|
|
205
|
-
onBlur
|
|
206
|
-
})));
|
|
207
|
-
};
|
|
208
|
-
var safeParseFloat = (str, defaultValue) => {
|
|
209
|
-
try {
|
|
210
|
-
return parseFloat(str);
|
|
211
|
-
} catch {
|
|
212
|
-
return defaultValue ?? 0;
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
var TextInput = ({ property, type, label, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
|
|
216
|
-
const { status, error } = getStatus?.(property);
|
|
217
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
218
|
-
validationValence: status
|
|
219
|
-
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
220
|
-
error
|
|
221
|
-
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
184
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
|
|
222
185
|
disabled,
|
|
223
186
|
placeholder,
|
|
224
187
|
value: getValue(property) ?? "",
|
|
@@ -228,11 +191,11 @@ var TextInput = ({ property, type, label, disabled, placeholder, getStatus, getV
|
|
|
228
191
|
};
|
|
229
192
|
var NumberInput = ({ property, type, label, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
|
|
230
193
|
const { status, error } = getStatus?.(property);
|
|
231
|
-
return /* @__PURE__ */
|
|
194
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
|
|
232
195
|
validationValence: status
|
|
233
|
-
}, /* @__PURE__ */
|
|
196
|
+
}, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
|
|
234
197
|
error
|
|
235
|
-
}, /* @__PURE__ */
|
|
198
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
|
|
236
199
|
type: "number",
|
|
237
200
|
disabled,
|
|
238
201
|
placeholder,
|
|
@@ -243,40 +206,79 @@ var NumberInput = ({ property, type, label, disabled, placeholder, getStatus, ge
|
|
|
243
206
|
};
|
|
244
207
|
var BooleanInput = ({ property, type, label, getStatus, getValue, onValueChange }) => {
|
|
245
208
|
const { status, error } = getStatus?.(property);
|
|
246
|
-
return /* @__PURE__ */
|
|
209
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
|
|
247
210
|
validationValence: status
|
|
248
|
-
}, /* @__PURE__ */
|
|
211
|
+
}, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
|
|
249
212
|
error
|
|
250
|
-
}, /* @__PURE__ */
|
|
213
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Switch, {
|
|
251
214
|
checked: getValue(property),
|
|
252
215
|
onCheckedChange: (value) => onValueChange(property, type, value)
|
|
253
216
|
}));
|
|
254
217
|
};
|
|
255
218
|
var SelectInput = ({ property, type, label, disabled, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
256
219
|
const { status, error } = getStatus?.(property);
|
|
257
|
-
return /* @__PURE__ */
|
|
220
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
|
|
258
221
|
validationValence: status
|
|
259
|
-
}, /* @__PURE__ */
|
|
222
|
+
}, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
|
|
260
223
|
error
|
|
261
|
-
}, /* @__PURE__ */
|
|
224
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Label, null, label)), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.Root, {
|
|
262
225
|
value: getValue(property),
|
|
263
226
|
onValueChange: (value) => onValueChange(property, type, value)
|
|
264
|
-
}, /* @__PURE__ */
|
|
227
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.TriggerButton, {
|
|
265
228
|
classNames: "is-full",
|
|
266
229
|
disabled,
|
|
267
230
|
placeholder
|
|
268
|
-
}), /* @__PURE__ */
|
|
231
|
+
}), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.Portal, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.Content, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
|
|
269
232
|
// NOTE: Numeric values are converted to and from strings.
|
|
270
|
-
/* @__PURE__ */
|
|
233
|
+
/* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.Option, {
|
|
271
234
|
key: String(value),
|
|
272
235
|
value: String(value)
|
|
273
236
|
}, label2 ?? String(value))
|
|
274
237
|
)))))));
|
|
275
238
|
};
|
|
239
|
+
var GeiPointInput = ({ property, type, label, disabled, getStatus, getValue, onValueChange, onBlur }) => {
|
|
240
|
+
const { t } = (0, import_react_ui6.useTranslation)(translationKey);
|
|
241
|
+
const { status, error } = getStatus?.(property);
|
|
242
|
+
const [lng = 0, lat = 0] = getValue(property) ?? [];
|
|
243
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
|
|
244
|
+
validationValence: status
|
|
245
|
+
}, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
|
|
246
|
+
error
|
|
247
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement("div", {
|
|
248
|
+
className: "grid grid-cols-2 gap-2"
|
|
249
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
250
|
+
type: "number",
|
|
251
|
+
disabled,
|
|
252
|
+
placeholder: t("placeholder longitude"),
|
|
253
|
+
value: lng,
|
|
254
|
+
onChange: (event) => onValueChange(property, type, [
|
|
255
|
+
lat,
|
|
256
|
+
safeParseFloat(event.target.value, 0)
|
|
257
|
+
]),
|
|
258
|
+
onBlur
|
|
259
|
+
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
|
|
260
|
+
type: "number",
|
|
261
|
+
disabled,
|
|
262
|
+
placeholder: t("placeholder latitude"),
|
|
263
|
+
value: lat,
|
|
264
|
+
onChange: (event) => onValueChange(property, type, [
|
|
265
|
+
safeParseFloat(event.target.value, 0),
|
|
266
|
+
lng
|
|
267
|
+
]),
|
|
268
|
+
onBlur
|
|
269
|
+
})));
|
|
270
|
+
};
|
|
271
|
+
var safeParseFloat = (str, defaultValue) => {
|
|
272
|
+
try {
|
|
273
|
+
return parseFloat(str);
|
|
274
|
+
} catch {
|
|
275
|
+
return defaultValue ?? 0;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
276
278
|
var getInputComponent = (type, format) => {
|
|
277
279
|
switch (format) {
|
|
278
280
|
case import_echo_schema3.FormatEnum.LatLng:
|
|
279
|
-
return
|
|
281
|
+
return GeiPointInput;
|
|
280
282
|
}
|
|
281
283
|
switch (type) {
|
|
282
284
|
case "string":
|
|
@@ -288,7 +290,7 @@ var getInputComponent = (type, format) => {
|
|
|
288
290
|
}
|
|
289
291
|
};
|
|
290
292
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
291
|
-
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid,
|
|
293
|
+
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
292
294
|
const [values, setValues] = (0, import_react7.useState)(initialValues);
|
|
293
295
|
(0, import_react7.useEffect)(() => {
|
|
294
296
|
setValues(initialValues);
|
|
@@ -322,21 +324,21 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
322
324
|
values,
|
|
323
325
|
schemaDirty
|
|
324
326
|
]);
|
|
325
|
-
const
|
|
327
|
+
const canSave = (0, import_react7.useMemo)(() => Object.keys(values).every((property) => touched[property] === false || !errors[property]), [
|
|
326
328
|
values,
|
|
327
329
|
touched,
|
|
328
330
|
errors
|
|
329
331
|
]);
|
|
330
|
-
const
|
|
332
|
+
const handleSave = (0, import_react7.useCallback)(() => {
|
|
331
333
|
if (validate(values)) {
|
|
332
|
-
|
|
334
|
+
onSave?.(values, {
|
|
333
335
|
changed
|
|
334
336
|
});
|
|
335
337
|
}
|
|
336
338
|
}, [
|
|
337
339
|
values,
|
|
338
340
|
validate,
|
|
339
|
-
|
|
341
|
+
onSave
|
|
340
342
|
]);
|
|
341
343
|
const getStatus = (0, import_react7.useCallback)((property) => ({
|
|
342
344
|
status: errors[property] ? "error" : void 0,
|
|
@@ -357,7 +359,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
357
359
|
} catch (err) {
|
|
358
360
|
import_log3.log.catch(err, void 0, {
|
|
359
361
|
F: __dxlog_file,
|
|
360
|
-
L:
|
|
362
|
+
L: 165,
|
|
361
363
|
S: void 0,
|
|
362
364
|
C: (f, a) => f(...a)
|
|
363
365
|
});
|
|
@@ -400,8 +402,8 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
400
402
|
errors,
|
|
401
403
|
touched,
|
|
402
404
|
changed,
|
|
403
|
-
|
|
404
|
-
|
|
405
|
+
canSave,
|
|
406
|
+
handleSave,
|
|
405
407
|
// Field utils.
|
|
406
408
|
getStatus,
|
|
407
409
|
getValue,
|
|
@@ -412,7 +414,7 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
412
414
|
var createKeySet = (obj, value) => {
|
|
413
415
|
(0, import_invariant.invariant)(obj, void 0, {
|
|
414
416
|
F: __dxlog_file,
|
|
415
|
-
L:
|
|
417
|
+
L: 216,
|
|
416
418
|
S: void 0,
|
|
417
419
|
A: [
|
|
418
420
|
"obj",
|
|
@@ -434,25 +436,25 @@ var flatMap = (errors) => {
|
|
|
434
436
|
};
|
|
435
437
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/Form/Form.tsx";
|
|
436
438
|
var padding = "px-2";
|
|
437
|
-
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, onValuesChanged, onValidate,
|
|
439
|
+
var Form = ({ classNames, schema, values: initialValues, path = [], readonly, filter, sort, autoSave, onValuesChanged, onValidate, onSave, onCancel, Custom }) => {
|
|
438
440
|
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
439
|
-
const onValid = (0, import_react3.useMemo)(() => autoSave ?
|
|
441
|
+
const onValid = (0, import_react3.useMemo)(() => autoSave ? onSave : void 0, [
|
|
440
442
|
autoSave,
|
|
441
|
-
|
|
443
|
+
onSave
|
|
442
444
|
]);
|
|
443
|
-
const {
|
|
445
|
+
const { canSave, values, errors, handleSave, ...inputProps } = useForm({
|
|
444
446
|
schema,
|
|
445
447
|
initialValues,
|
|
446
448
|
onValuesChanged,
|
|
447
449
|
onValidate,
|
|
448
450
|
onValid,
|
|
449
|
-
|
|
451
|
+
onSave
|
|
450
452
|
});
|
|
451
|
-
const
|
|
452
|
-
const
|
|
453
|
-
const filtered = filter ? filter(
|
|
454
|
-
const findIndex = (
|
|
455
|
-
const idx =
|
|
453
|
+
const properties = (0, import_react3.useMemo)(() => {
|
|
454
|
+
const props = (0, import_schema2.getSchemaProperties)(schema.ast, values);
|
|
455
|
+
const filtered = filter ? filter(props) : props;
|
|
456
|
+
const findIndex = (props2, prop) => {
|
|
457
|
+
const idx = props2.findIndex((p) => p === prop);
|
|
456
458
|
return idx === -1 ? Infinity : idx;
|
|
457
459
|
};
|
|
458
460
|
return sort ? filtered.sort(({ name: a }, { name: b }) => findIndex(sort, a) - findIndex(sort, b)) : filtered;
|
|
@@ -467,7 +469,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
467
469
|
errors
|
|
468
470
|
}, {
|
|
469
471
|
F: __dxlog_file2,
|
|
470
|
-
L:
|
|
472
|
+
L: 96,
|
|
471
473
|
S: void 0,
|
|
472
474
|
C: (f, a) => f(...a)
|
|
473
475
|
});
|
|
@@ -478,16 +480,41 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
478
480
|
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
479
481
|
role: "form",
|
|
480
482
|
className: (0, import_react_ui_theme.mx)("flex flex-col w-full gap-2 py-2", classNames)
|
|
481
|
-
},
|
|
483
|
+
}, properties.map((property) => {
|
|
484
|
+
const { ast, name, type, format, title, description, examples, options } = property;
|
|
482
485
|
const key = [
|
|
483
486
|
...path,
|
|
484
487
|
name
|
|
485
488
|
];
|
|
486
|
-
const
|
|
489
|
+
const label = title ?? (0, import_effect.pipe)(name, import_String.capitalize);
|
|
490
|
+
const placeholder = examples?.length ? `Example: "${examples[0]}"` : description;
|
|
491
|
+
let InputComponent = Custom?.[key.join(".")];
|
|
492
|
+
if (!InputComponent) {
|
|
493
|
+
if (options) {
|
|
494
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
495
|
+
key: name,
|
|
496
|
+
role: "none",
|
|
497
|
+
className: padding
|
|
498
|
+
}, /* @__PURE__ */ import_react3.default.createElement(SelectInput, {
|
|
499
|
+
type,
|
|
500
|
+
format,
|
|
501
|
+
property: name,
|
|
502
|
+
disabled: readonly,
|
|
503
|
+
label,
|
|
504
|
+
options: options.map((option) => ({
|
|
505
|
+
value: option,
|
|
506
|
+
label: String(option)
|
|
507
|
+
})),
|
|
508
|
+
placeholder,
|
|
509
|
+
...inputProps
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
InputComponent = getInputComponent(type, format);
|
|
513
|
+
}
|
|
487
514
|
if (!InputComponent) {
|
|
488
515
|
if (type === "object") {
|
|
489
|
-
const baseNode = (0,
|
|
490
|
-
const typeLiteral = baseNode ? (0,
|
|
516
|
+
const baseNode = (0, import_effect2.findNode)(ast, import_effect2.isDiscriminatedUnion);
|
|
517
|
+
const typeLiteral = baseNode ? (0, import_effect2.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect2.findNode)(ast, import_echo_schema2.AST.isTypeLiteral);
|
|
491
518
|
if (typeLiteral) {
|
|
492
519
|
const schema2 = import_echo_schema2.S.make(typeLiteral);
|
|
493
520
|
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
@@ -495,7 +522,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
495
522
|
role: "none"
|
|
496
523
|
}, /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
497
524
|
className: padding
|
|
498
|
-
},
|
|
525
|
+
}, label), /* @__PURE__ */ import_react3.default.createElement(Form, {
|
|
499
526
|
schema: schema2,
|
|
500
527
|
path: key,
|
|
501
528
|
values: values[name] ?? {},
|
|
@@ -511,13 +538,12 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
511
538
|
type
|
|
512
539
|
}, {
|
|
513
540
|
F: __dxlog_file2,
|
|
514
|
-
L:
|
|
541
|
+
L: 160,
|
|
515
542
|
S: void 0,
|
|
516
543
|
C: (f, a) => f(...a)
|
|
517
544
|
});
|
|
518
545
|
return null;
|
|
519
546
|
}
|
|
520
|
-
const placeholder = examples?.length ? `Example: ${examples[0]}` : description;
|
|
521
547
|
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
522
548
|
key: name,
|
|
523
549
|
role: "none",
|
|
@@ -527,11 +553,11 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
527
553
|
format,
|
|
528
554
|
property: name,
|
|
529
555
|
disabled: readonly,
|
|
530
|
-
label
|
|
556
|
+
label,
|
|
531
557
|
placeholder,
|
|
532
558
|
...inputProps
|
|
533
559
|
}));
|
|
534
|
-
}).filter(import_util.isNotFalsy), (onCancel ||
|
|
560
|
+
}).filter(import_util.isNotFalsy), (onCancel || onSave) && !autoSave && /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
535
561
|
role: "none",
|
|
536
562
|
className: "flex justify-center"
|
|
537
563
|
}, /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
@@ -541,16 +567,16 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
|
|
|
541
567
|
icon: "ph--x--regular",
|
|
542
568
|
label: t("button cancel"),
|
|
543
569
|
onClick: onCancel
|
|
544
|
-
}),
|
|
570
|
+
}), onSave && /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.IconButton, {
|
|
545
571
|
type: "submit",
|
|
546
|
-
disabled: !
|
|
572
|
+
disabled: !canSave,
|
|
547
573
|
icon: "ph--check--regular",
|
|
548
574
|
label: t("button save"),
|
|
549
|
-
onClick:
|
|
575
|
+
onClick: handleSave
|
|
550
576
|
}))));
|
|
551
577
|
};
|
|
552
578
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
553
|
-
var FieldEditor = ({ view, projection, field, registry,
|
|
579
|
+
var FieldEditor = ({ view, projection, field, registry, onSave, onCancel }) => {
|
|
554
580
|
const { t } = (0, import_react_ui2.useTranslation)(translationKey);
|
|
555
581
|
const [props, setProps] = (0, import_react2.useState)(projection.getFieldProjection(field.id).props);
|
|
556
582
|
(0, import_react2.useEffect)(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
@@ -621,22 +647,22 @@ var FieldEditor = ({ view, projection, field, registry, onClose, onCancel }) =>
|
|
|
621
647
|
view.fields,
|
|
622
648
|
field
|
|
623
649
|
]);
|
|
624
|
-
const
|
|
650
|
+
const handleSave = (0, import_react2.useCallback)((props2) => {
|
|
625
651
|
projection.setFieldProjection({
|
|
626
652
|
field,
|
|
627
653
|
props: props2
|
|
628
654
|
});
|
|
629
|
-
|
|
655
|
+
onSave();
|
|
630
656
|
}, [
|
|
631
657
|
projection,
|
|
632
658
|
field,
|
|
633
|
-
|
|
659
|
+
onSave
|
|
634
660
|
]);
|
|
635
661
|
const handleCancel = (0, import_react2.useCallback)(() => {
|
|
636
662
|
requestAnimationFrame(() => onCancel?.());
|
|
637
|
-
|
|
663
|
+
onSave();
|
|
638
664
|
}, [
|
|
639
|
-
|
|
665
|
+
onSave
|
|
640
666
|
]);
|
|
641
667
|
if (!fieldSchema) {
|
|
642
668
|
import_log.log.warn("invalid format", {
|
|
@@ -661,7 +687,7 @@ var FieldEditor = ({ view, projection, field, registry, onClose, onCancel }) =>
|
|
|
661
687
|
],
|
|
662
688
|
onValuesChanged: handleValuesChanged,
|
|
663
689
|
onValidate: handleValidate,
|
|
664
|
-
|
|
690
|
+
onSave: handleSave,
|
|
665
691
|
onCancel: handleCancel,
|
|
666
692
|
Custom: {
|
|
667
693
|
["format"]: (props2) => /* @__PURE__ */ import_react2.default.createElement(SelectInput, {
|
|
@@ -691,7 +717,7 @@ var ViewMetaSchema = import_echo_schema4.S.Struct({
|
|
|
691
717
|
name: import_echo_schema4.S.String.annotations({
|
|
692
718
|
[import_echo_schema4.AST.TitleAnnotationId]: "View"
|
|
693
719
|
}),
|
|
694
|
-
|
|
720
|
+
typename: import_echo_schema4.Format.DXN.annotations({
|
|
695
721
|
[import_echo_schema4.AST.TitleAnnotationId]: "Typename"
|
|
696
722
|
})
|
|
697
723
|
}).pipe(import_echo_schema4.S.mutable);
|
|
@@ -707,16 +733,16 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
707
733
|
name: view.name,
|
|
708
734
|
// TODO(burdon): Need to warn user of possible consequences of editing.
|
|
709
735
|
// TODO(burdon): Settings should have domain name owned by user.
|
|
710
|
-
|
|
736
|
+
typename: view.query.typename
|
|
711
737
|
};
|
|
712
738
|
}, [
|
|
713
739
|
view
|
|
714
740
|
]);
|
|
715
|
-
const handleViewUpdate = (0, import_react8.useCallback)(({ name,
|
|
741
|
+
const handleViewUpdate = (0, import_react8.useCallback)(({ name, typename }) => {
|
|
716
742
|
requestAnimationFrame(() => {
|
|
717
743
|
view.name = name;
|
|
718
|
-
view.query.
|
|
719
|
-
schema.updateTypename(
|
|
744
|
+
view.query.typename = typename;
|
|
745
|
+
schema.updateTypename(typename);
|
|
720
746
|
});
|
|
721
747
|
}, [
|
|
722
748
|
view,
|
|
@@ -745,7 +771,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
745
771
|
autoSave: true,
|
|
746
772
|
schema: ViewMetaSchema,
|
|
747
773
|
values: viewValues,
|
|
748
|
-
|
|
774
|
+
onSave: handleViewUpdate
|
|
749
775
|
}), /* @__PURE__ */ import_react8.default.createElement("div", null, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
750
776
|
role: "none",
|
|
751
777
|
className: "p-2"
|
|
@@ -779,7 +805,7 @@ var ViewEditor = ({ classNames, schema, view, registry, readonly, showHeading =
|
|
|
779
805
|
projection,
|
|
780
806
|
field,
|
|
781
807
|
registry,
|
|
782
|
-
|
|
808
|
+
onSave: handleClose
|
|
783
809
|
}), !readonly && !field && /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
784
810
|
className: "flex p-2 justify-center"
|
|
785
811
|
}, /* @__PURE__ */ import_react8.default.createElement(import_react_ui7.IconButton, {
|
|
@@ -1010,8 +1036,8 @@ var formatForEditing = ({ type, format, value, locale = void 0 }) => {
|
|
|
1010
1036
|
DeprecatedFormInput,
|
|
1011
1037
|
FieldEditor,
|
|
1012
1038
|
Form,
|
|
1039
|
+
GeiPointInput,
|
|
1013
1040
|
InputHeader,
|
|
1014
|
-
LatLngInput,
|
|
1015
1041
|
NumberInput,
|
|
1016
1042
|
SelectInput,
|
|
1017
1043
|
TextInput,
|