@omnitend/dashboard-for-laravel 0.4.13 → 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.
@@ -1,7 +1,23 @@
1
+ import type { Component } from "vue";
1
2
  /**
2
- * Field types supported by OForm
3
+ * Field types supported by DXForm (and DXField, its per-field renderer).
4
+ *
5
+ * Text-like types render an `<input>`; the remainder render purpose-built
6
+ * controls:
7
+ * - `currency` / `percentage` — numeric input wrapped in an input-group
8
+ * with a symbol affix.
9
+ * - `datetime` — alias for the native `datetime-local` control.
10
+ * - `image` / `file` — file input (`image` additionally shows a preview).
11
+ * - `component` — escape hatch that renders `field.component`.
12
+ * - `repeater` — nested, repeatable sub-form driven by `field.fields`.
3
13
  */
4
- export type FieldType = "text" | "email" | "password" | "number" | "url" | "tel" | "date" | "datetime-local" | "time" | "textarea" | "select" | "checkbox" | "radio";
14
+ export type FieldType = "text" | "email" | "password" | "number" | "url" | "tel" | "date" | "datetime-local" | "datetime" | "time" | "currency" | "percentage" | "textarea" | "select" | "checkbox" | "radio" | "image" | "file" | "component" | "repeater";
15
+ /**
16
+ * A value that may be supplied directly or computed from the live form
17
+ * model. Predicates receive the current model so fields can react to
18
+ * other fields (cross-field reactivity).
19
+ */
20
+ export type MaybeFn<TValue> = TValue | ((model: any) => TValue);
5
21
  /**
6
22
  * Option for select or radio fields
7
23
  */
@@ -11,27 +27,122 @@ export interface FieldOption extends Record<string, unknown> {
11
27
  disabled?: boolean;
12
28
  }
13
29
  /**
14
- * Field definition for OForm
30
+ * Asynchronously resolves the options for a select/radio field from the
31
+ * current model (e.g. fetch a dependent list). Resolved on mount, and
32
+ * again on model change when `reloadOptionsOnChange` is set.
33
+ */
34
+ export type OptionsLoader = (model: any) => Promise<FieldOption[]>;
35
+ /**
36
+ * Field definition shared by every form renderer.
37
+ *
38
+ * DXForm and DXTable's edit modal honour `hint`, `span`, `when`,
39
+ * `readonly`, `disabledWhen`, function-valued `label`/`hint`, async
40
+ * options, the `component` escape hatch and nested `repeater` fields.
15
41
  */
16
42
  export interface FieldDefinition {
17
43
  /** Field key (must match form data key) */
18
44
  key: string;
19
45
  /** Field type */
20
46
  type: FieldType;
21
- /** Field label (optional) */
22
- label?: string;
47
+ /** Field label string or a function of the form model */
48
+ label?: MaybeFn<string>;
23
49
  /** Placeholder text (optional) */
24
50
  placeholder?: string;
25
51
  /** Whether field is required (optional) */
26
52
  required?: boolean;
27
53
  /** Options for select or radio fields */
28
54
  options?: FieldOption[];
55
+ /**
56
+ * Asynchronously load options for select/radio fields. Takes
57
+ * precedence over `options` once resolved.
58
+ */
59
+ optionsLoader?: OptionsLoader;
60
+ /** Re-run `optionsLoader` whenever the form model changes. */
61
+ reloadOptionsOnChange?: boolean;
29
62
  /** Number of rows for textarea (default: 3) */
30
63
  rows?: number;
31
- /** Help text displayed below field */
64
+ /** Step for numeric/currency/percentage inputs */
65
+ step?: number | string;
66
+ /** Min/max for numeric inputs */
67
+ min?: number | string;
68
+ max?: number | string;
69
+ /** Symbol shown for `currency` fields (default: the locale's, "£"). */
70
+ currencySymbol?: string;
71
+ /** `accept` attribute for `image`/`file` inputs (e.g. "image/*"). */
72
+ accept?: string;
73
+ /** Help text displayed below the field (always visible). */
32
74
  help?: string;
75
+ /**
76
+ * Hint text displayed below the field. Unlike `help`, may be a
77
+ * function of the model for dynamic hints.
78
+ */
79
+ hint?: MaybeFn<string>;
33
80
  /** CSS class for the form group */
34
81
  class?: string;
35
82
  /** Additional props to pass to the input component */
36
83
  inputProps?: Record<string, any>;
84
+ /**
85
+ * Render the field full-width with no label wrapper, delegating its
86
+ * content to the `#span(<key>)` slot. Useful for custom blocks.
87
+ */
88
+ span?: boolean;
89
+ /**
90
+ * Component rendered for `type: "component"` fields. Receives
91
+ * `modelValue`, `field`, `model` props and emits `update:modelValue`.
92
+ */
93
+ component?: Component;
94
+ /** Sub-field definitions for `type: "repeater"` fields. */
95
+ fields?: FieldDefinition[];
96
+ /**
97
+ * Default/initial value. Used by `defineForm` to seed form data and by
98
+ * repeaters to seed a freshly-added row's sub-fields. (`defineForm`'s
99
+ * `FormFieldDefinition` re-declares this as required for inference.)
100
+ */
101
+ default?: any;
102
+ /** Label for a repeater's "add row" button (default: "Add"). */
103
+ addLabel?: string;
104
+ /** Minimum / maximum number of repeater rows. */
105
+ minItems?: number;
106
+ maxItems?: number;
107
+ /** Disable the field (static or computed from the model). */
108
+ disabled?: MaybeFn<boolean>;
109
+ /**
110
+ * Disable the field based on the model. Retained for backwards
111
+ * compatibility with DXTable; prefer `disabled` with a function.
112
+ */
113
+ disabledWhen?: (model: any) => boolean;
114
+ /**
115
+ * Render the field read-only (static or computed). For controls
116
+ * without a native readonly state (select/checkbox/radio) this is
117
+ * applied as `disabled`.
118
+ */
119
+ readonly?: MaybeFn<boolean>;
120
+ /**
121
+ * Conditionally show or hide this field. When omitted the field is
122
+ * always visible. Boolean or a function of the form model; evaluated
123
+ * reactively for cross-field conditional fields.
124
+ */
125
+ when?: MaybeFn<boolean>;
126
+ /**
127
+ * Legacy no-argument visibility predicate. Retained for backwards
128
+ * compatibility; prefer `when`. When both are present, a field is
129
+ * visible only if both pass.
130
+ */
131
+ show?: () => boolean;
132
+ }
133
+ /**
134
+ * A tab in a tabbed form. Groups a subset of fields and can be shown
135
+ * conditionally or lazily mounted.
136
+ */
137
+ export interface FormTab {
138
+ /** Unique key for this tab */
139
+ key: string;
140
+ /** Display label (optional, defaults to the key) */
141
+ label?: string;
142
+ /** Field keys (from the form's fields) to render in this tab */
143
+ fieldKeys: string[];
144
+ /** Conditional display — boolean or a function of the form model */
145
+ when?: MaybeFn<boolean>;
146
+ /** Lazily mount tab content until first activated */
147
+ lazy?: boolean;
37
148
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Minimal dot-path get/set helpers used for nested form binding
3
+ * (e.g. repeater rows where a field value lives at `lines.0.price`).
4
+ *
5
+ * Paths are dot-separated; numeric segments index into arrays. Setting
6
+ * creates intermediate objects/arrays as needed so a fresh repeater row
7
+ * can be populated without pre-seeding the whole shape.
8
+ */
9
+ type AnyRecord = Record<string, any>;
10
+ /** Read the value at `path` within `target`, or `undefined` if absent. */
11
+ export declare function getByPath(target: AnyRecord, path: string): any;
12
+ /**
13
+ * Write `value` at `path` within `target`, creating intermediate
14
+ * containers. A numeric next-segment creates an array; otherwise an
15
+ * object. Mutates `target` in place (form.data is reactive).
16
+ */
17
+ export declare function setByPath(target: AnyRecord, path: string, value: any): void;
18
+ export {};