@vitavision/forms 0.8.3 → 0.8.5

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/README.md CHANGED
@@ -31,6 +31,24 @@ helpers for building your own: `defaultValueForSchema`, `resolveSchema`, `shapeO
31
31
  <SchemaValueForm schema={schema} value={config} onValueChange={setConfig} ui={ui} columns={1} />
32
32
  ```
33
33
 
34
+ **Against a baseline**: `baseline` is a value to compare with (the defaults, a previous run).
35
+ - A field that differs gets a rule in the gutter and a note under the control: "changed", what it was, and a Reset
36
+ that writes the baseline's value back through `onValueChange`.
37
+ - A struct, a variant or a tuple row says how many leaves under it changed, with one Reset for the block.
38
+ - A key missing on one side differs from a key present on the other; arrays of equal length compare by index, others as a whole.
39
+ - `diffPaths(value, baseline)` is the same comparison as a list of dot paths.
40
+
41
+ **Messages**: `messages` attaches text to fields by dot path (`solver.max_iters`, `cameras.0.id`), for validation
42
+ that comes from elsewhere, such as a backend.
43
+ - A bare string, or `{ severity: "error", text }`, is announced as an alert and marks the control invalid.
44
+ - `{ severity: "warning", text }` is shown under the field without blocking.
45
+ - The path `""` is the form as a whole, shown above it.
46
+ - A path that no visible field has shows nowhere; list those yourself.
47
+
48
+ ```tsx
49
+ <SchemaValueForm schema={schema} value={config} onValueChange={setConfig} baseline={defaults} messages={{ "solver.max_iters": "Must be at most 1000" }} />
50
+ ```
51
+
34
52
  ## License
35
53
 
36
54
  Licensed under either of
package/dist/index.d.ts CHANGED
@@ -271,6 +271,13 @@ export declare function resolveRef(ref: string, root: JsonSchema): JsonSchema |
271
271
  export declare function resolveSchema<T extends JsonSchema>(node: T, root?: JsonSchema): ResolvedSchema<T>;
272
272
  //#endregion
273
273
  //#region src/api/uiSchema.d.ts
274
+ /**
275
+ * Where a field's label goes. `top` stacks the label over the control. `side` is the
276
+ * property-sheet row: the label in a fixed column on the left, the control on the right,
277
+ * about 32 px tall, with the description behind the hint icon. Objects, unions, tuples and
278
+ * lists keep their label above and span the full width either way.
279
+ */
280
+ type LabelPlacement = "top" | "side";
274
281
  /** A titled set of fields, rendered together. */
275
282
  interface UiGroup {
276
283
  /** Stable id, used for keys and test hooks. */
@@ -287,6 +294,16 @@ interface UiGroup {
287
294
  collapsible?: boolean | undefined;
288
295
  /** Whether a collapsible group starts open. Defaults to closed. */
289
296
  defaultOpen?: boolean | undefined;
297
+ /**
298
+ * Lay the group's fields out on one row, each with its label above its control, instead
299
+ * of the form's grid: for a few small numbers that read as one setting (rows × columns ×
300
+ * square size; iterations and tolerances). Give each field a short `label` in `fields`
301
+ * of the `UiSchema`. A row has no room for descriptions or range notes, so they are
302
+ * dropped, and a field that is not a leaf (an object, a list) should stay out of it.
303
+ */
304
+ inline?: boolean | undefined;
305
+ /** This group's label placement, over the form's. */
306
+ labelPlacement?: LabelPlacement | undefined;
290
307
  /** A line of explanation under the heading. */
291
308
  hint?: ReactNode;
292
309
  }
@@ -318,6 +335,17 @@ interface FieldUi {
318
335
  * `{ brown_conrady5: "Brown-Conrady" }`.
319
336
  */
320
337
  enumLabels?: Record<string, string> | undefined;
338
+ /**
339
+ * For an object (or a union's variant): the order of its fields, by key. Keys not listed
340
+ * follow in schema order, and keys that do not exist are ignored. Use it where the
341
+ * schema's own order is not the one to read in (a schema whose keys arrive sorted).
342
+ */
343
+ order?: string[] | undefined;
344
+ /**
345
+ * For an object: lay its fields out on one row with their labels above, like a group's
346
+ * `inline`. The object keeps its frame and label.
347
+ */
348
+ inline?: boolean | undefined;
321
349
  /** Columns the field takes in the grid. Containers and lists default to the full row. */
322
350
  span?: 1 | 2 | undefined;
323
351
  /**
@@ -361,6 +389,23 @@ interface UiSchema {
361
389
  groups?: UiGroup[] | undefined;
362
390
  /** Per-field presentation, by dot path. */
363
391
  fields?: Record<string, FieldUi> | undefined;
392
+ /**
393
+ * The order of the root object's ungrouped fields, by key. Keys not listed follow in
394
+ * schema order. (Fields inside a group follow the group's `fields`; a nested object's
395
+ * order is `FieldUi.order`.)
396
+ */
397
+ order?: string[] | undefined;
398
+ /**
399
+ * Where labels go, for the whole form: `top` (the default) or `side`. A group can
400
+ * override it, and so can the form's prop, which wins over this.
401
+ */
402
+ labelPlacement?: LabelPlacement | undefined;
403
+ /**
404
+ * Where descriptions go for every field the app did not say otherwise about (see
405
+ * `FieldUi.descriptionAs`). Defaults to `hint`, the same in both placements: a long
406
+ * description is a tooltip, never a line in the form.
407
+ */
408
+ descriptionAs?: "hint" | "inline" | "none" | undefined;
364
409
  }
365
410
  /** What `renderField` is given for a field. */
366
411
  interface RenderFieldContext {
@@ -381,7 +426,18 @@ interface RenderFieldContext {
381
426
  */
382
427
  type RenderField = (context: RenderFieldContext) => ReactNode;
383
428
  //#endregion
429
+ //#region src/components/valueForm/context.d.ts
430
+ /** A message the app attaches to a field, such as a backend's verdict on a value. */
431
+ interface FieldMessage {
432
+ /** `error` is announced as an alert and marks the control invalid; `warning` is shown without blocking. */
433
+ severity: "error" | "warning";
434
+ /** What to tell the person. */
435
+ text: string;
436
+ }
437
+ //#endregion
384
438
  //#region src/components/SchemaValueForm.d.ts
439
+ /** Messages from the app, by dot path (`""` is the form as a whole). A bare string is an error. */
440
+ type FieldMessages = Readonly<Record<string, FieldMessage | string>>;
385
441
  /** Props of `SchemaValueForm`. */
386
442
  interface SchemaValueFormProps {
387
443
  /**
@@ -403,8 +459,34 @@ interface SchemaValueFormProps {
403
459
  onValueChange?: ((next: unknown) => void) | undefined;
404
460
  /** Layout the schema cannot carry: groups, labels, units, widgets. */
405
461
  ui?: UiSchema | undefined;
462
+ /**
463
+ * The value to compare with, such as the defaults or a previous run. A field whose value
464
+ * differs from it is marked "changed" (a rule in the gutter and a note under the control
465
+ * saying what it was), with a Reset that writes the baseline's value back through
466
+ * `onValueChange`; a struct, a variant or a tuple shows how many leaves under it changed
467
+ * and one Reset for them all. A key missing on one side differs from a key present on the
468
+ * other; arrays of equal length compare by index, others as a whole. Without it, nothing is marked.
469
+ */
470
+ baseline?: unknown;
471
+ /**
472
+ * Messages to show on fields, by dot path (`solver.max_iters`, `cameras.0.id`, the paths
473
+ * `getAtPath` reads), for validation that comes from elsewhere, such as a backend. An `error`
474
+ * (or a bare string) is announced as an alert and marks the control invalid; a `warning`
475
+ * is shown under it without blocking. A path of `""` shows above the form. A path that no
476
+ * visible field has shows nowhere: list those yourself.
477
+ */
478
+ messages?: FieldMessages | undefined;
406
479
  /** `2` (the default) puts fields side by side from `sm:` up; `1` is one column, for a narrow rail. */
407
480
  columns?: 1 | 2 | undefined;
481
+ /**
482
+ * Where labels go: `top` (the default) stacks each label over its control; `side` is the
483
+ * property-sheet row, the label in a fixed column on the left (truncated, the full text
484
+ * in its `title`) and the control on the right, about 32 px tall, with the description
485
+ * behind the hint icon. Containers, unions, tuples and lists keep their label above
486
+ * either way. Wins over `ui.labelPlacement`; a group's own `labelPlacement` wins over
487
+ * both for its fields. Works with both `columns`.
488
+ */
489
+ labelPlacement?: LabelPlacement | undefined;
408
490
  /** Blocks every control. The value is still shown. */
409
491
  disabled?: boolean | undefined;
410
492
  /**
@@ -436,7 +518,7 @@ interface SchemaValueFormProps {
436
518
  * The root is a `div` carrying `data-columns` and, while disabled, `data-disabled`. Wraps itself in a
437
519
  * `TooltipProvider`, so it needs none above it.
438
520
  */
439
- export declare function SchemaValueForm({ schema, value, defaultValue, onValueChange, ui, columns, disabled, renderField, className, ref }: SchemaValueFormProps): import("react").JSX.Element;
521
+ export declare function SchemaValueForm({ schema, value, defaultValue, onValueChange, baseline, messages, ui, columns, labelPlacement, disabled, renderField, className, ref }: SchemaValueFormProps): import("react").JSX.Element;
440
522
  //#endregion
441
523
  //#region src/api/firstParagraph.d.ts
442
524
  /**
@@ -600,6 +682,27 @@ export declare function fieldAt(schema: JsonSchema, path: string, root?: JsonSch
600
682
  */
601
683
  export declare function fieldsAt(schema: JsonSchema, path: string, root?: JsonSchema, value?: unknown): FieldInfo[];
602
684
  //#endregion
685
+ //#region src/api/valueDiff.d.ts
686
+ /**
687
+ * Where one JSON value differs from another, by dot path: what a form marks as "changed from
688
+ * the baseline".
689
+ *
690
+ * Paths are the ones `getAtPath` reads. A value and its baseline are compared structurally:
691
+ * objects by key (a key missing on one side differs from a key present on the other, even
692
+ * if the present value is `null`), arrays by index when they have the same length, and by
693
+ * the array as a whole when they do not (its elements have no shared identity to match).
694
+ */
695
+ /**
696
+ * The paths at which `current` differs from `baseline`, deepest first-found, in key order.
697
+ *
698
+ * @param current - The value.
699
+ * @param baseline - What it is compared with.
700
+ * @param path - The path of both, for a recursive call; `""` is the root.
701
+ * @returns Each differing path once; `[""]` when the roots are different kinds of value.
702
+ * Empty when the values are equal.
703
+ */
704
+ export declare function diffPaths(current: unknown, baseline: unknown, path?: string): string[];
705
+ //#endregion
603
706
  //#region src/api/valuePath.d.ts
604
707
  /**
605
708
  * Read the value at a path.
@@ -624,5 +727,5 @@ export declare function getAtPath(value: unknown, path: string): unknown;
624
727
  */
625
728
  export declare function setAtPath(value: unknown, path: string, next: unknown): unknown;
626
729
  //#endregion
627
- export type { ChoiceOption, EnumOption, EnumValue, ExternalVariant, FieldInfo, FieldKind, FieldSpec, FieldUi, FieldWidget, JsonSchema, OptionsSchema, RawValues, RenderField, RenderFieldContext, ResolvedSchema, SchemaNode, SchemaShape, SchemaValueFormProps, TaggedVariant, UiGroup, UiSchema };
730
+ export type { ChoiceOption, EnumOption, EnumValue, ExternalVariant, FieldInfo, FieldKind, FieldMessage, FieldMessages, FieldSpec, FieldUi, FieldWidget, JsonSchema, LabelPlacement, OptionsSchema, RawValues, RenderField, RenderFieldContext, ResolvedSchema, SchemaNode, SchemaShape, SchemaValueFormProps, TaggedVariant, UiGroup, UiSchema };
628
731
  //# sourceMappingURL=index.d.ts.map