@samline/forms 2.7.2 → 2.9.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/CHANGELOG.md +316 -0
- package/README.md +119 -119
- package/dist/browser/global.d.ts +50 -16
- package/dist/browser/global.global.js +12 -6188
- package/dist/browser/global.global.js.map +1 -1
- package/dist/browser/index.cjs +340 -84
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/{chunk-MMHX34WB.js → chunk-6MA5TF6R.js} +341 -85
- package/dist/chunk-6MA5TF6R.js.map +1 -0
- package/dist/index.cjs +340 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{registry-GzopYPCR.d.ts → registry-CPe_lf8-.d.cts} +50 -4
- package/dist/{registry-GzopYPCR.d.cts → registry-CPe_lf8-.d.ts} +50 -4
- package/package.json +39 -8
- package/dist/chunk-MMHX34WB.js.map +0 -1
- package/docs/api/add-cleanup.md +0 -52
- package/docs/api/append.md +0 -96
- package/docs/api/auto-submit.md +0 -91
- package/docs/api/clear-errors.md +0 -69
- package/docs/api/destroy.md +0 -80
- package/docs/api/disable-auto-submit.md +0 -65
- package/docs/api/element.md +0 -78
- package/docs/api/form.md +0 -156
- package/docs/api/format.md +0 -270
- package/docs/api/get-data.md +0 -90
- package/docs/api/get-field.md +0 -87
- package/docs/api/get-state.md +0 -111
- package/docs/api/get-value.md +0 -114
- package/docs/api/index.md +0 -55
- package/docs/api/observe.md +0 -126
- package/docs/api/on-submit.md +0 -94
- package/docs/api/parse-form-data.md +0 -94
- package/docs/api/prefill.md +0 -89
- package/docs/api/regex.md +0 -155
- package/docs/api/reset.md +0 -61
- package/docs/api/revalidate.md +0 -52
- package/docs/api/set-errors.md +0 -97
- package/docs/api/set-value.md +0 -120
- package/docs/api/subscribe.md +0 -107
- package/docs/api/unwatch.md +0 -74
- package/docs/api/validate-field-value.md +0 -144
- package/docs/api/validate-values.md +0 -103
- package/docs/api/validate.md +0 -102
- package/docs/api/watch.md +0 -117
- package/docs/browser.md +0 -156
- package/docs/css-styling.md +0 -191
- package/docs/getting-started.md +0 -222
- package/docs/options.md +0 -326
- package/docs/recipes.md +0 -531
- package/docs/typescript.md +0 -615
- package/docs/vanilla.md +0 -12
- /package/{LICENSE → LICENSE.md} +0 -0
package/dist/browser/global.d.ts
CHANGED
|
@@ -106,7 +106,38 @@ interface AppendContentOptions {
|
|
|
106
106
|
class?: string;
|
|
107
107
|
atStart?: boolean;
|
|
108
108
|
}
|
|
109
|
+
/** One `<option>` written by `setOptions()`. */
|
|
110
|
+
interface SelectOption {
|
|
111
|
+
value: string | number;
|
|
112
|
+
/** Visible text. Defaults to `String(value)`. Written as text, never HTML. */
|
|
113
|
+
label?: string;
|
|
114
|
+
disabled?: boolean;
|
|
115
|
+
/** Selects the option and makes it the default restored by `reset()`. */
|
|
116
|
+
selected?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/** One `<optgroup>` written by `setOptions()`. */
|
|
119
|
+
interface SelectOptionGroup {
|
|
120
|
+
label: string;
|
|
121
|
+
options: Array<string | number | SelectOption>;
|
|
122
|
+
disabled?: boolean;
|
|
123
|
+
}
|
|
124
|
+
/** A plain string or number is shorthand for `{ value, label: String(value) }`. */
|
|
125
|
+
type SelectOptionInput = string | number | SelectOption | SelectOptionGroup;
|
|
126
|
+
interface SetOptionsConfig {
|
|
127
|
+
/**
|
|
128
|
+
* Keep the current selection when its value is still in the new list.
|
|
129
|
+
* Ignored for a select when any new option has `selected: true`.
|
|
130
|
+
* Defaults to `true`.
|
|
131
|
+
*/
|
|
132
|
+
keepValue?: boolean;
|
|
133
|
+
}
|
|
109
134
|
type FormFieldWatcher = (value: FormFieldValue, field: FormFieldElement | FormFieldElement[] | null, form: HTMLFormElement, state: FormStateSnapshot) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Callback for `watch()` / `observe()` with a list of fields. `values` has
|
|
137
|
+
* one entry per watched field. `changed` is the field that triggered the
|
|
138
|
+
* call, or `null` on registration and after `reset()`.
|
|
139
|
+
*/
|
|
140
|
+
type FormFieldsWatcher = (values: FormValues, changed: string | null, form: HTMLFormElement, state: FormStateSnapshot) => void;
|
|
110
141
|
type FormSubmitHandler = (form: HTMLFormElement, data: Record<string, SerializedFormValue>, formData: FormData, state: FormStateSnapshot) => void | Promise<void>;
|
|
111
142
|
type FormCleanup = () => void;
|
|
112
143
|
interface FormController {
|
|
@@ -115,15 +146,30 @@ interface FormController {
|
|
|
115
146
|
readonly options: FormControllerOptions;
|
|
116
147
|
onSubmit: (callback: FormSubmitHandler, preventDefault?: boolean) => FormController;
|
|
117
148
|
addCleanup: (cleanup: FormCleanup) => () => void;
|
|
118
|
-
watch:
|
|
119
|
-
|
|
120
|
-
|
|
149
|
+
watch: {
|
|
150
|
+
(field: string, callback: FormFieldWatcher): FormController;
|
|
151
|
+
(fields: string[], callback: FormFieldsWatcher): FormController;
|
|
152
|
+
};
|
|
153
|
+
observe: {
|
|
154
|
+
(field: string, callback: FormFieldWatcher): () => void;
|
|
155
|
+
(fields: string[], callback: FormFieldsWatcher): () => void;
|
|
156
|
+
};
|
|
157
|
+
unwatch: {
|
|
158
|
+
(field?: string, callback?: FormFieldWatcher): FormController;
|
|
159
|
+
(fields: string[], callback?: FormFieldsWatcher): FormController;
|
|
160
|
+
};
|
|
121
161
|
subscribe: (listener: FormStateListener) => () => void;
|
|
122
162
|
prefill: (fieldName?: string) => FormController;
|
|
123
163
|
append: (options: AppendContentOptions) => HTMLElement | null;
|
|
124
164
|
setErrors: (fields: string[] | FormErrors) => FormController;
|
|
125
165
|
clearErrors: (fields?: string[]) => FormController;
|
|
126
166
|
setValue: (name: string, value: unknown) => FormController;
|
|
167
|
+
/**
|
|
168
|
+
* Replace the `<option>` / `<optgroup>` children of every `<select>`
|
|
169
|
+
* named `name`. Fires the normal change pipeline only when the
|
|
170
|
+
* selected value changes. Chainable.
|
|
171
|
+
*/
|
|
172
|
+
setOptions: (name: string, options: SelectOptionInput[], config?: SetOptionsConfig) => FormController;
|
|
127
173
|
validate: (fields?: string[]) => ValidationResult;
|
|
128
174
|
revalidate: (fields?: string[]) => ValidationResult;
|
|
129
175
|
/**
|
|
@@ -153,22 +199,10 @@ interface NewFormInput {
|
|
|
153
199
|
interface FormsAvailable {
|
|
154
200
|
[id: string]: FormController;
|
|
155
201
|
}
|
|
156
|
-
interface FormsApi {
|
|
157
|
-
form: (target: FormTarget, options?: FormControllerOptions) => FormController;
|
|
158
|
-
newForm: (input: NewFormInput) => FormController | undefined;
|
|
159
|
-
destroyForm: (id: string) => void;
|
|
160
|
-
available: FormsAvailable;
|
|
161
|
-
}
|
|
162
202
|
|
|
163
|
-
declare const Forms: FormsApi;
|
|
164
203
|
declare const form: (target: FormTarget, options?: FormControllerOptions) => FormController;
|
|
165
204
|
declare const newForm: (input: NewFormInput) => FormController | undefined;
|
|
166
205
|
declare const destroyForm: (id: string) => void;
|
|
167
206
|
declare const available: FormsAvailable;
|
|
168
|
-
declare global {
|
|
169
|
-
interface Window {
|
|
170
|
-
Forms: FormsApi;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
207
|
|
|
174
|
-
export { available,
|
|
208
|
+
export { available, destroyForm, form, newForm };
|