@dxos/react-ui-form 0.7.1 → 0.7.2-staging.6d26b2a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/lib/browser/index.mjs +107 -81
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +100 -74
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +107 -81
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/Form/Custom.d.ts +2 -1
  11. package/dist/types/src/components/Form/Custom.d.ts.map +1 -1
  12. package/dist/types/src/components/Form/Defaults.d.ts +11 -4
  13. package/dist/types/src/components/Form/Defaults.d.ts.map +1 -1
  14. package/dist/types/src/components/Form/Form.d.ts +5 -4
  15. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  16. package/dist/types/src/components/Form/Form.stories.d.ts +1 -4
  17. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  18. package/dist/types/src/components/Form/Input.d.ts +3 -8
  19. package/dist/types/src/components/Form/Input.d.ts.map +1 -1
  20. package/dist/types/src/components/Form/factory.d.ts +2 -2
  21. package/dist/types/src/components/Form/factory.d.ts.map +1 -1
  22. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  23. package/dist/types/src/hooks/useForm.d.ts +5 -4
  24. package/dist/types/src/hooks/useForm.d.ts.map +1 -1
  25. package/package.json +22 -24
  26. package/src/components/Form/Custom.tsx +9 -9
  27. package/src/components/Form/Defaults.tsx +10 -5
  28. package/src/components/Form/Form.stories.tsx +2 -2
  29. package/src/components/Form/Form.tsx +43 -19
  30. package/src/components/Form/Input.tsx +3 -7
  31. package/src/components/Form/factory.tsx +4 -4
  32. package/src/components/ViewEditor/ViewEditor.stories.tsx +1 -2
  33. package/src/hooks/useForm.ts +7 -6
@@ -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 import_effect = require("@dxos/effect");
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 LatLngInput = ({ property, type, label, disabled, getStatus, getValue, onValueChange, onBlur }) => {
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("div", {
185
- className: "grid grid-cols-2 gap-2"
186
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
187
- type: "number",
188
- disabled,
189
- placeholder: t("placeholder latitude"),
190
- value: lat,
191
- onChange: (event) => onValueChange(property, type, {
192
- lat: safeParseFloat(event.target.value, 0),
193
- lng
194
- }),
195
- onBlur
196
- }), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.TextInput, {
197
- type: "number",
198
- disabled,
199
- placeholder: t("placeholder longitude"),
200
- value: lng,
201
- onChange: (event) => onValueChange(property, type, {
202
- lat,
203
- lng: safeParseFloat(event.target.value, 0)
204
- }),
205
- onBlur
206
- })));
207
- };
208
- var safeParseFloat = (str, defaultValue) => {
209
- try {
210
- return parseFloat(str);
211
- } catch {
212
- return defaultValue ?? 0;
213
- }
214
- };
215
- var TextInput = ({ property, type, label, disabled, placeholder, getStatus, getValue, onValueChange, onBlur }) => {
216
- const { status, error } = getStatus?.(property);
217
- return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
218
- validationValence: status
219
- }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
220
- error
221
- }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
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__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
194
+ return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
232
195
  validationValence: status
233
- }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
196
+ }, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
234
197
  error
235
- }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.TextInput, {
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__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
209
+ return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
247
210
  validationValence: status
248
- }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
211
+ }, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
249
212
  error
250
- }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Switch, {
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__ */ import_react6.default.createElement(import_react_ui6.Input.Root, {
220
+ return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Input.Root, {
258
221
  validationValence: status
259
- }, /* @__PURE__ */ import_react6.default.createElement(InputHeader, {
222
+ }, /* @__PURE__ */ import_react4.default.createElement(InputHeader, {
260
223
  error
261
- }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Input.Label, null, label)), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Root, {
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__ */ import_react6.default.createElement(import_react_ui6.Select.TriggerButton, {
227
+ }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Select.TriggerButton, {
265
228
  classNames: "is-full",
266
229
  disabled,
267
230
  placeholder
268
- }), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Portal, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.Select.Viewport, null, options?.map(({ value, label: label2 }) => (
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__ */ import_react6.default.createElement(import_react_ui6.Select.Option, {
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 LatLngInput;
281
+ return GeiPointInput;
280
282
  }
281
283
  switch (type) {
282
284
  case "string":
@@ -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: 164,
362
+ L: 165,
361
363
  S: void 0,
362
364
  C: (f, a) => f(...a)
363
365
  });
@@ -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: 215,
417
+ L: 216,
416
418
  S: void 0,
417
419
  A: [
418
420
  "obj",
@@ -448,11 +450,11 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
448
450
  onValid,
449
451
  onSubmit
450
452
  });
451
- const props = (0, import_react3.useMemo)(() => {
452
- const props2 = (0, import_schema2.getSchemaProperties)(schema.ast, values);
453
- const filtered = filter ? filter(props2) : props2;
454
- const findIndex = (props3, prop) => {
455
- const idx = props3.findIndex((p) => p === prop);
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: 93,
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
- }, props.map(({ prop, name, type, format, title, description, examples }) => {
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 InputComponent = Custom?.[key.join(".")] ?? getInputComponent(type, format);
489
+ const label = (0, import_effect.pipe)(title ?? 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, import_effect.findNode)(prop.type, import_effect.isDiscriminatedUnion);
490
- const typeLiteral = baseNode ? (0, import_effect.getDiscriminatedType)(baseNode, values[name]) : (0, import_effect.findNode)(prop.type, import_echo_schema2.AST.isTypeLiteral);
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
- }, title ?? name), /* @__PURE__ */ import_react3.default.createElement(Form, {
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: 132,
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,7 +553,7 @@ var Form = ({ classNames, schema, values: initialValues, path = [], readonly, fi
527
553
  format,
528
554
  property: name,
529
555
  disabled: readonly,
530
- label: title ?? name,
556
+ label,
531
557
  placeholder,
532
558
  ...inputProps
533
559
  }));
@@ -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,