@petrarca/sonnet-forms 0.4.1 → 0.5.0

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/index.d.ts CHANGED
@@ -23,6 +23,12 @@ interface FormFieldWrapperProps {
23
23
  * still communicated via the control's own styling (e.g. red border).
24
24
  */
25
25
  compact?: boolean;
26
+ /**
27
+ * Label placement: "top" (default) renders the label above the control;
28
+ * "start" renders the label inline on the reading-start side (RTL-safe: left
29
+ * in LTR, right in RTL). Logical values follow the MUI convention.
30
+ */
31
+ labelPlacement?: "top" | "start";
26
32
  /** Additional class name for the outer wrapper div */
27
33
  className?: string;
28
34
  /** The form control(s) */
@@ -32,7 +38,7 @@ interface FormFieldWrapperProps {
32
38
  * FormFieldWrapper renders label, children (the control), description, and
33
39
  * error in the standard vertical layout used by all form field components.
34
40
  */
35
- declare function FormFieldWrapper({ inputId, label, description, error, required, compact, className, children, }: FormFieldWrapperProps): react_jsx_runtime.JSX.Element;
41
+ declare function FormFieldWrapper({ inputId, label, description, error, required, compact, labelPlacement, className, children, }: FormFieldWrapperProps): react_jsx_runtime.JSX.Element;
36
42
 
37
43
  /**
38
44
  * Shared utility functions for form field components.
@@ -78,6 +84,8 @@ interface FormInputProps extends React__default.ComponentPropsWithoutRef<typeof
78
84
  * still communicated via a red border on the input.
79
85
  */
80
86
  compact?: boolean;
87
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
88
+ labelPlacement?: "top" | "start";
81
89
  }
82
90
  /**
83
91
  * FormInput component with label, description, and error handling
@@ -106,6 +114,8 @@ interface FormTextareaProps extends React__default.ComponentPropsWithoutRef<type
106
114
  required?: boolean;
107
115
  /** Additional class name for the wrapper */
108
116
  wrapperClassName?: string;
117
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
118
+ labelPlacement?: "top" | "start";
109
119
  /** Enable auto-resize behavior (default: false) */
110
120
  autosize?: boolean;
111
121
  /** Minimum number of rows when autosize is enabled (default: 3) */
@@ -163,6 +173,8 @@ interface FormNumberInputProps {
163
173
  id?: string;
164
174
  /** Input name */
165
175
  name?: string;
176
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
177
+ labelPlacement?: "top" | "start";
166
178
  }
167
179
  declare const FormNumberInput: React__default.ForwardRefExoticComponent<FormNumberInputProps & React__default.RefAttributes<HTMLInputElement>>;
168
180
 
@@ -381,6 +393,12 @@ interface ArrayItemTemplateProps {
381
393
  disabled?: boolean;
382
394
  layout: UILayoutConfig;
383
395
  fieldCount: number;
396
+ /**
397
+ * Stable form-internal item id (_fid). Rendered as `data-fid` on the item
398
+ * container so tests can target a specific item across reorders (the
399
+ * positional `index` is not stable).
400
+ */
401
+ fid?: string;
384
402
  onRemove: () => void;
385
403
  onMoveUp?: () => void;
386
404
  onMoveDown?: () => void;
@@ -432,6 +450,8 @@ interface FormSelectProps {
432
450
  * still communicated via a red border on the trigger button.
433
451
  */
434
452
  compact?: boolean;
453
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
454
+ labelPlacement?: "top" | "start";
435
455
  options: SelectOption[];
436
456
  value?: string | null;
437
457
  onChange?: (value: string | null) => void;
@@ -447,6 +467,15 @@ interface FormSelectProps {
447
467
  id?: string;
448
468
  name?: string;
449
469
  autoFocus?: boolean;
470
+ /**
471
+ * Allow creating a new option from the search text. When set, a
472
+ * `+ Create "<text>"` item appears at the bottom of the list whenever the
473
+ * trimmed search matches no existing option label (case-insensitive).
474
+ * Selecting it calls `onCreate(text)`. Requires `onCreate`.
475
+ */
476
+ allowCreate?: boolean;
477
+ /** Called with the trimmed search text when the create item is chosen. */
478
+ onCreate?: (label: string) => void;
450
479
  }
451
480
  declare function FormSelect(props: FormSelectProps): react_jsx_runtime.JSX.Element;
452
481
 
@@ -458,6 +487,8 @@ interface FormMultiSelectProps {
458
487
  error?: string;
459
488
  required?: boolean;
460
489
  wrapperClassName?: string;
490
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
491
+ labelPlacement?: "top" | "start";
461
492
  options: SelectOption[];
462
493
  value?: string[];
463
494
  onChange?: (value: string[]) => void;
@@ -492,6 +523,8 @@ interface FormTagsInputProps {
492
523
  error?: string;
493
524
  required?: boolean;
494
525
  wrapperClassName?: string;
526
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
527
+ labelPlacement?: "top" | "start";
495
528
  id?: string;
496
529
  name?: string;
497
530
  value: string[];
@@ -580,6 +613,8 @@ interface FormQuantityInputProps {
580
613
  autoFocus?: boolean;
581
614
  /** Additional class name for the outer wrapper */
582
615
  wrapperClassName?: string;
616
+ /** Label placement: "vertical" (default, above) or "horizontal" (inline). */
617
+ labelPlacement?: "top" | "start";
583
618
  /** Additional class name for the numeric input */
584
619
  className?: string;
585
620
  id?: string;
@@ -935,6 +970,13 @@ type JsonSchemaFormRendererProps = {
935
970
  readOnly?: boolean;
936
971
  /** Show Save/Cancel action buttons */
937
972
  showActions?: boolean;
973
+ /**
974
+ * Allow Save when the form is pristine (no changes vs the baseline). Set for
975
+ * CREATE forms, where submitting default / empty values is valid -- the
976
+ * "must have changed something" dirty-check is an edit-only concept. Required-
977
+ * field validation still applies. Default false (edit semantics).
978
+ */
979
+ allowPristineSave?: boolean;
938
980
  /** Label for Save button (default: "Save") */
939
981
  saveLabel?: string;
940
982
  /** Label for Cancel button (default: "Cancel") */
@@ -981,6 +1023,12 @@ type JsonSchemaFormRendererProps = {
981
1023
  uiSchema?: {
982
1024
  [fieldName: string]: UISchema;
983
1025
  };
1026
+ /**
1027
+ * Prefix for generated field control ids: `<idPrefix>-<fieldName>` (default
1028
+ * "field"). Set a distinct prefix per form when rendering multiple forms on
1029
+ * one page to avoid duplicate DOM ids.
1030
+ */
1031
+ idPrefix?: string;
984
1032
  };
985
1033
  declare function JsonSchemaFormRenderer(props: JsonSchemaFormRendererProps): React__default.ReactElement;
986
1034
 
@@ -1009,8 +1057,14 @@ interface FormFieldRendererProps {
1009
1057
  registry: WidgetRegistry;
1010
1058
  globalOptions?: UISchemaOptions;
1011
1059
  formData?: Record<string, unknown>;
1060
+ /**
1061
+ * Prefix for generated control ids: `<idPrefix>-<fieldName>` (default
1062
+ * "field"). Set a per-form prefix when rendering multiple forms on one page
1063
+ * to keep ids unique.
1064
+ */
1065
+ idPrefix?: string;
1012
1066
  }
1013
- declare function FormFieldRenderer({ fieldName, property, value, onChange, onBlur, required, disabled, readOnly, schema, uiSchema, registry, globalOptions, formData, }: FormFieldRendererProps): React__default.ReactElement | null;
1067
+ declare function FormFieldRenderer({ fieldName, property, value, onChange, onBlur, required, disabled, readOnly, schema, uiSchema, registry, globalOptions, formData, idPrefix, }: FormFieldRendererProps): React__default.ReactElement | null;
1014
1068
 
1015
1069
  /**
1016
1070
  * useFormEngine - Core form state, schema resolution, and update-mode logic
@@ -1047,6 +1101,13 @@ interface UseFormEngineOptions {
1047
1101
  showActions?: boolean;
1048
1102
  deferChanges?: boolean;
1049
1103
  deferStateUpdates?: boolean;
1104
+ /**
1105
+ * Allow saving when the form is pristine (no changes vs the baseline). Use for
1106
+ * CREATE forms, where submitting default / empty values is valid -- the
1107
+ * "must have changed something" dirty-check is an edit-only concept.
1108
+ * Validation (required fields) still applies. Default false (edit semantics).
1109
+ */
1110
+ allowPristineSave?: boolean;
1050
1111
  }
1051
1112
  interface UseFormEngineResult {
1052
1113
  /** The current working form data (for controlled field values) */
@@ -1067,7 +1128,7 @@ interface UseFormEngineResult {
1067
1128
  handleSave: () => void;
1068
1129
  handleCancel: () => void;
1069
1130
  }
1070
- declare function useFormEngine({ schema, data, uiSchema, onChange, onBlur, onValidationChange, onUpdate, onCancel, readOnly, showActions, deferChanges, deferStateUpdates, }: UseFormEngineOptions): UseFormEngineResult;
1131
+ declare function useFormEngine({ schema, data, uiSchema, onChange, onBlur, onValidationChange, onUpdate, onCancel, readOnly, showActions, deferChanges, deferStateUpdates, allowPristineSave, }: UseFormEngineOptions): UseFormEngineResult;
1071
1132
 
1072
1133
  /**
1073
1134
  * useResolvedSchema - Schema resolution and property ordering