@streamscloud/kit 0.90.0 → 0.91.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/core/validation/form-validation-handler/form-validation-handler.svelte.d.ts +20 -8
- package/dist/core/validation/form-validation-handler/form-validation-handler.svelte.js +80 -63
- package/dist/core/validation/form-validation-handler/index.d.ts +1 -1
- package/dist/core/validation/form-validation-handler/types.d.ts +4 -0
- package/dist/core/validation/form-validation-handler/validation-helper.d.ts +6 -0
- package/dist/core/validation/form-validation-handler/validation-helper.js +27 -0
- package/dist/ui/_internal/form-field-label-context/form-field-label-context.svelte.d.ts +2 -0
- package/dist/ui/_internal/form-field-label-context/form-field-label-context.svelte.js +2 -0
- package/dist/ui/_internal/form-field-label-context/index.d.ts +1 -1
- package/dist/ui/_internal/form-field-label-context/index.js +1 -1
- package/dist/ui/color-picker/cmp.color-picker.svelte +4 -1
- package/dist/ui/date-picker/cmp.date-picker.svelte +6 -3
- package/dist/ui/form-field/cmp.form-field-validatable.svelte +2 -9
- package/dist/ui/form-field/cmp.form-field-validatable.svelte.d.ts +3 -7
- package/dist/ui/popover/cmp.popover.svelte +5 -3
- package/dist/ui/popover/cmp.popover.svelte.d.ts +1 -0
- package/dist/ui/select/cmp.multiselect.svelte.d.ts +1 -1
- package/dist/ui/select/cmp.singleselect-async.svelte +5 -2
- package/dist/ui/select/multiselect-base.svelte +5 -2
- package/dist/ui/select/select-listbox.svelte +3 -2
- package/dist/ui/tree/cmp.tree-node-view.svelte +13 -15
- package/dist/ui/validatable/cmp.validatable.svelte +9 -46
- package/dist/ui/validatable/cmp.validatable.svelte.d.ts +4 -29
- package/dist/ui/validatable/index.d.ts +1 -2
- package/dist/ui/validatable/types.d.ts +12 -0
- package/package.json +1 -1
|
@@ -3,16 +3,22 @@ import type { IFormHandlerValidator } from './types';
|
|
|
3
3
|
type TypeToValidate<T> = {
|
|
4
4
|
[K in keyof T]: T[K];
|
|
5
5
|
};
|
|
6
|
+
export type ValidateFieldOptions = {
|
|
7
|
+
/** Delay before the validator runs; a newer call for the same field restarts it. */
|
|
8
|
+
debounceMs?: number;
|
|
9
|
+
/** Skip the call when the field still holds the value its last validation ran on (or is scheduled to run on). */
|
|
10
|
+
onlyIfChanged?: boolean;
|
|
11
|
+
};
|
|
6
12
|
export declare class FormValidationHandler<T extends TypeToValidate<T> = TypeToValidate<unknown>, TSubmitResult = void> implements IValidator {
|
|
7
13
|
readonly formStringified: Record<string, string>;
|
|
8
14
|
readonly modified: Record<keyof T, boolean>;
|
|
9
|
-
readonly isValid: boolean;
|
|
10
|
-
readonly isModified: boolean;
|
|
11
15
|
private _form;
|
|
12
16
|
private _errors;
|
|
13
17
|
private _touched;
|
|
14
|
-
private
|
|
18
|
+
private _validatingFields;
|
|
19
|
+
private _isFormValidating;
|
|
15
20
|
private _isSubmitting;
|
|
21
|
+
private _checkedValues;
|
|
16
22
|
private _validator;
|
|
17
23
|
private _initialValues;
|
|
18
24
|
private readonly _onSubmit;
|
|
@@ -29,20 +35,25 @@ export declare class FormValidationHandler<T extends TypeToValidate<T> = TypeToV
|
|
|
29
35
|
[P in keyof Partial<T>]: string;
|
|
30
36
|
}>;
|
|
31
37
|
get touched(): Readonly<Record<keyof T, boolean>>;
|
|
38
|
+
get isValid(): boolean;
|
|
39
|
+
get isModified(): boolean;
|
|
32
40
|
get isValidating(): boolean;
|
|
33
41
|
get isSubmitting(): boolean;
|
|
42
|
+
/** True from the moment a field validation is requested (debounce included) until its result is stored. */
|
|
43
|
+
isFieldValidating: (field: keyof T) => boolean;
|
|
34
44
|
updateField: <K extends keyof T>(field: K, value: T[K]) => void;
|
|
35
45
|
updateValidateField: <K extends keyof T>(field: K, value: T[K]) => Promise<void>;
|
|
36
46
|
updateTouched: (field: keyof T, value: boolean) => void;
|
|
37
47
|
updateTouchedForAllFields: (value: boolean) => void;
|
|
38
48
|
/**
|
|
39
49
|
* Sets an error the schema can't produce (a server-side rejection), marking the field touched so it renders.
|
|
40
|
-
*
|
|
50
|
+
* It stays until the field's value changes, the field is validated explicitly, or the whole form is validated.
|
|
41
51
|
*/
|
|
42
52
|
setFieldError: (field: keyof T, message: string) => void;
|
|
43
|
-
/** Batch {@link setFieldError} — skips `undefined` entries
|
|
53
|
+
/** Batch {@link setFieldError} — skips `undefined` entries. */
|
|
44
54
|
setFieldErrors: (errors: Partial<Record<keyof T, string>>) => void;
|
|
45
|
-
|
|
55
|
+
/** Validates one field. A result that a newer validation of the same field has superseded is dropped. */
|
|
56
|
+
validateField: (field: keyof T, options?: ValidateFieldOptions) => Promise<void>;
|
|
46
57
|
updateInitialValues: (newValues: T) => void;
|
|
47
58
|
updateValidator: (validator: IFormHandlerValidator<T>) => void;
|
|
48
59
|
handleReset: () => void;
|
|
@@ -50,7 +61,8 @@ export declare class FormValidationHandler<T extends TypeToValidate<T> = TypeToV
|
|
|
50
61
|
validate: (values?: T) => Promise<boolean>;
|
|
51
62
|
handleSubmit: (event: Event | null) => Promise<void>;
|
|
52
63
|
dispose(): void;
|
|
53
|
-
private
|
|
54
|
-
private
|
|
64
|
+
private _fieldNames;
|
|
65
|
+
private _rememberCheckedValue;
|
|
66
|
+
private _runValidator;
|
|
55
67
|
}
|
|
56
68
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Utils } from '../../utils';
|
|
2
|
+
import { ValidationHelper } from './validation-helper';
|
|
2
3
|
import { dequal as isEqual } from 'dequal/lite';
|
|
3
4
|
const NO_ERROR = '';
|
|
4
5
|
export class FormValidationHandler {
|
|
@@ -6,35 +7,33 @@ export class FormValidationHandler {
|
|
|
6
7
|
if (!this.form) {
|
|
7
8
|
return {};
|
|
8
9
|
}
|
|
9
|
-
return Object.entries(this.form).reduce((acc, [key, value]) => ({ ...acc, [key]:
|
|
10
|
+
return Object.entries(this.form).reduce((acc, [key, value]) => ({ ...acc, [key]: ValidationHelper.stringify(value) }), {});
|
|
10
11
|
});
|
|
11
12
|
modified = $derived.by(() => {
|
|
12
13
|
if (!this.form) {
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
15
|
-
const object =
|
|
16
|
+
const object = ValidationHelper.fillKeys(this.form, false);
|
|
16
17
|
for (const key in this.form) {
|
|
17
18
|
object[key] = !isEqual(this.form[key], this._initialValues[key]);
|
|
18
19
|
}
|
|
19
20
|
return object;
|
|
20
21
|
});
|
|
21
|
-
isValid = $derived(ValidationUtils.getValues(this.errors).every((field) => field === NO_ERROR));
|
|
22
|
-
isModified = $derived.by(() => {
|
|
23
|
-
return ValidationUtils.getValues(this.modified).includes(true);
|
|
24
|
-
});
|
|
25
22
|
_form = $state(null);
|
|
26
23
|
_errors = $state(null);
|
|
27
24
|
_touched = $state(null);
|
|
28
|
-
|
|
25
|
+
_validatingFields = $state({});
|
|
26
|
+
_isFormValidating = $state(false);
|
|
29
27
|
_isSubmitting = $state(false);
|
|
28
|
+
_checkedValues = new Map();
|
|
30
29
|
_validator;
|
|
31
30
|
_initialValues = $state(null);
|
|
32
31
|
_onSubmit;
|
|
33
32
|
_onReset;
|
|
34
33
|
_initials = {
|
|
35
34
|
values: () => Utils.clone(this._initialValues),
|
|
36
|
-
errors: () =>
|
|
37
|
-
touched: () =>
|
|
35
|
+
errors: () => ValidationHelper.fillKeys(this._initialValues, NO_ERROR),
|
|
36
|
+
touched: () => ValidationHelper.fillKeys(this._initialValues, false)
|
|
38
37
|
};
|
|
39
38
|
constructor(context) {
|
|
40
39
|
this._initialValues = context.initialValues || {};
|
|
@@ -54,36 +53,47 @@ export class FormValidationHandler {
|
|
|
54
53
|
get touched() {
|
|
55
54
|
return this._touched;
|
|
56
55
|
}
|
|
56
|
+
get isValid() {
|
|
57
|
+
return Object.values(this._errors).every((error) => !error);
|
|
58
|
+
}
|
|
59
|
+
get isModified() {
|
|
60
|
+
return Object.values(this.modified).includes(true);
|
|
61
|
+
}
|
|
57
62
|
get isValidating() {
|
|
58
|
-
return this.
|
|
63
|
+
return this._isFormValidating || Object.values(this._validatingFields).some(Boolean);
|
|
59
64
|
}
|
|
60
65
|
get isSubmitting() {
|
|
61
66
|
return this._isSubmitting;
|
|
62
67
|
}
|
|
68
|
+
/** True from the moment a field validation is requested (debounce included) until its result is stored. */
|
|
69
|
+
isFieldValidating = (field) => {
|
|
70
|
+
return !!this._validatingFields[field];
|
|
71
|
+
};
|
|
63
72
|
updateField = (field, value) => {
|
|
64
|
-
|
|
73
|
+
this._form[field] = value;
|
|
65
74
|
};
|
|
66
75
|
updateValidateField = async (field, value) => {
|
|
67
76
|
this.updateField(field, value);
|
|
68
|
-
await this.
|
|
77
|
+
await this.validateField(field);
|
|
69
78
|
};
|
|
70
79
|
updateTouched = (field, value) => {
|
|
71
|
-
|
|
80
|
+
this._touched[field] = value;
|
|
72
81
|
};
|
|
73
82
|
updateTouchedForAllFields = (value) => {
|
|
74
|
-
|
|
75
|
-
ValidationUtils.update(this._touched, key, value);
|
|
76
|
-
});
|
|
83
|
+
this._fieldNames().forEach((field) => this.updateTouched(field, value));
|
|
77
84
|
};
|
|
78
85
|
/**
|
|
79
86
|
* Sets an error the schema can't produce (a server-side rejection), marking the field touched so it renders.
|
|
80
|
-
*
|
|
87
|
+
* It stays until the field's value changes, the field is validated explicitly, or the whole form is validated.
|
|
81
88
|
*/
|
|
82
89
|
setFieldError = (field, message) => {
|
|
83
|
-
|
|
90
|
+
if (!this._checkedValues.has(field)) {
|
|
91
|
+
this._rememberCheckedValue(field);
|
|
92
|
+
}
|
|
93
|
+
this._errors[field] = message;
|
|
84
94
|
this.updateTouched(field, true);
|
|
85
95
|
};
|
|
86
|
-
/** Batch {@link setFieldError} — skips `undefined` entries
|
|
96
|
+
/** Batch {@link setFieldError} — skips `undefined` entries. */
|
|
87
97
|
setFieldErrors = (errors) => {
|
|
88
98
|
Object.keys(errors).forEach((field) => {
|
|
89
99
|
const message = errors[field];
|
|
@@ -93,8 +103,19 @@ export class FormValidationHandler {
|
|
|
93
103
|
this.setFieldError(field, message);
|
|
94
104
|
});
|
|
95
105
|
};
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
/** Validates one field. A result that a newer validation of the same field has superseded is dropped. */
|
|
107
|
+
validateField = async (field, options = {}) => {
|
|
108
|
+
const { debounceMs = 0, onlyIfChanged = false } = options;
|
|
109
|
+
const previous = this._checkedValues.get(field);
|
|
110
|
+
if (onlyIfChanged && previous && isEqual(previous.value, $state.snapshot(this._form[field]))) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const checked = this._rememberCheckedValue(field);
|
|
114
|
+
this._validatingFields[field] = true;
|
|
115
|
+
if (debounceMs > 0 && !(await ValidationHelper.waitUnlessCancelled(checked, debounceMs))) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await this._runValidator(field, checked);
|
|
98
119
|
};
|
|
99
120
|
updateInitialValues = (newValues) => {
|
|
100
121
|
this._initialValues = newValues;
|
|
@@ -105,6 +126,9 @@ export class FormValidationHandler {
|
|
|
105
126
|
this.handleReset();
|
|
106
127
|
};
|
|
107
128
|
handleReset = () => {
|
|
129
|
+
this._checkedValues.forEach((checked) => checked.cancel?.());
|
|
130
|
+
this._checkedValues.clear();
|
|
131
|
+
this._validatingFields = {};
|
|
108
132
|
this._form = this._initials.values();
|
|
109
133
|
this._errors = this._initials.errors();
|
|
110
134
|
this._touched = this._initials.touched();
|
|
@@ -132,11 +156,21 @@ export class FormValidationHandler {
|
|
|
132
156
|
validate = async (values) => {
|
|
133
157
|
this.updateTouchedForAllFields(true);
|
|
134
158
|
values = values || this.form;
|
|
135
|
-
this.
|
|
136
|
-
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
159
|
+
const checkedOnSubmit = new Map(this._fieldNames().map((field) => [field, this._rememberCheckedValue(field)]));
|
|
160
|
+
this._validatingFields = {};
|
|
161
|
+
this._isFormValidating = true;
|
|
162
|
+
try {
|
|
163
|
+
const result = await this._validator.validate(values);
|
|
164
|
+
checkedOnSubmit.forEach((checked, field) => {
|
|
165
|
+
if (this._checkedValues.get(field) === checked) {
|
|
166
|
+
this._errors[field] = result.errors[field] ?? NO_ERROR;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return result.isValid;
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
this._isFormValidating = false;
|
|
173
|
+
}
|
|
140
174
|
};
|
|
141
175
|
handleSubmit = async (event) => {
|
|
142
176
|
if (event && event.preventDefault) {
|
|
@@ -160,46 +194,29 @@ export class FormValidationHandler {
|
|
|
160
194
|
this._isSubmitting = false;
|
|
161
195
|
}
|
|
162
196
|
};
|
|
163
|
-
dispose() {
|
|
164
|
-
|
|
197
|
+
dispose() { }
|
|
198
|
+
_fieldNames() {
|
|
199
|
+
return [...new Set([...Object.keys(this._initialValues), ...Object.keys(this._form)])];
|
|
165
200
|
}
|
|
166
|
-
|
|
201
|
+
_rememberCheckedValue(field) {
|
|
202
|
+
this._checkedValues.get(field)?.cancel?.();
|
|
203
|
+
const checked = { value: $state.snapshot(this._form[field]) };
|
|
204
|
+
this._checkedValues.set(field, checked);
|
|
205
|
+
return checked;
|
|
206
|
+
}
|
|
207
|
+
async _runValidator(field, checked) {
|
|
208
|
+
checked.value = $state.snapshot(this._form[field]);
|
|
167
209
|
this.updateTouched(field, true);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
stringify = (value) => {
|
|
174
|
-
if (typeof value !== 'number' && !value) {
|
|
175
|
-
return '';
|
|
176
|
-
}
|
|
177
|
-
if (typeof value === 'string') {
|
|
178
|
-
return value;
|
|
179
|
-
}
|
|
180
|
-
return JSON.stringify(value);
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
class ValidationUtils {
|
|
184
|
-
static update = (object, path, value) => {
|
|
185
|
-
ValidationUtils.set(object, path, value);
|
|
186
|
-
};
|
|
187
|
-
static getValues = (object) => {
|
|
188
|
-
const results = [];
|
|
189
|
-
for (const [, value] of Object.entries(object)) {
|
|
190
|
-
results.push(value);
|
|
210
|
+
try {
|
|
211
|
+
const error = await this._validator.validateAt(this._form, field);
|
|
212
|
+
if (this._checkedValues.get(field) === checked) {
|
|
213
|
+
this._errors[field] = error || NO_ERROR;
|
|
214
|
+
}
|
|
191
215
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
for (const key in object) {
|
|
197
|
-
copy[key] = value;
|
|
216
|
+
finally {
|
|
217
|
+
if (this._checkedValues.get(field) === checked) {
|
|
218
|
+
this._validatingFields[field] = false;
|
|
219
|
+
}
|
|
198
220
|
}
|
|
199
|
-
return copy;
|
|
200
|
-
}
|
|
201
|
-
static set(object, path, value) {
|
|
202
|
-
object[path] = value;
|
|
203
|
-
return object;
|
|
204
221
|
}
|
|
205
222
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FormValidationHandler } from './form-validation-handler.svelte';
|
|
1
|
+
export { FormValidationHandler, type ValidateFieldOptions } from './form-validation-handler.svelte';
|
|
2
2
|
export type { FormValidateResult, IFormHandlerValidator } from './types';
|
|
3
3
|
export { StubFormValidator } from './stub-form-validator';
|
|
4
4
|
export { YupFormValidator } from './yup-form-validator';
|
|
@@ -2,6 +2,10 @@ export type IFormHandlerValidator<T> = {
|
|
|
2
2
|
validate: (obj: T) => Promise<FormValidateResult<Partial<T>>>;
|
|
3
3
|
validateAt: (obj: T, field: keyof T) => Promise<string | null>;
|
|
4
4
|
};
|
|
5
|
+
export type CheckedValue = {
|
|
6
|
+
value: unknown;
|
|
7
|
+
cancel?: () => void;
|
|
8
|
+
};
|
|
5
9
|
export type FormValidateResult<T> = {
|
|
6
10
|
isValid: boolean;
|
|
7
11
|
errors: {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CheckedValue } from './types';
|
|
2
|
+
export declare class ValidationHelper {
|
|
3
|
+
static fillKeys<TObject, TValue>(object: TObject, value: TValue): Record<keyof TObject, TValue>;
|
|
4
|
+
static stringify(value: unknown): string;
|
|
5
|
+
static waitUnlessCancelled(checked: CheckedValue, ms: number): Promise<boolean>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class ValidationHelper {
|
|
2
|
+
static fillKeys(object, value) {
|
|
3
|
+
const copy = {};
|
|
4
|
+
for (const key in object) {
|
|
5
|
+
copy[key] = value;
|
|
6
|
+
}
|
|
7
|
+
return copy;
|
|
8
|
+
}
|
|
9
|
+
static stringify(value) {
|
|
10
|
+
if (typeof value !== 'number' && !value) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
return JSON.stringify(value);
|
|
17
|
+
}
|
|
18
|
+
static waitUnlessCancelled(checked, ms) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const timeout = window.setTimeout(() => resolve(true), ms);
|
|
21
|
+
checked.cancel = () => {
|
|
22
|
+
window.clearTimeout(timeout);
|
|
23
|
+
resolve(false);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -11,5 +11,7 @@ export declare const getFormFieldLabel: () => FormFieldLabelContext | undefined;
|
|
|
11
11
|
export declare const claimFormFieldLabel: (controlId: () => string) => void;
|
|
12
12
|
/** The `aria-labelledby` of a control that is not a text input: the explicit one, else the FormField label's id — unless an explicit `aria-label` names it. */
|
|
13
13
|
export declare const resolveAriaLabelledby: (formFieldLabel: FormFieldLabelContext | undefined, ariaLabel: string | undefined, ariaLabelledby: string | undefined) => string | undefined;
|
|
14
|
+
/** Whether `target` sits in a `<label>` whose `for` control lies inside `controlRoot` — a press there belongs to that control, not outside it. */
|
|
15
|
+
export declare const isInsideLabelOf: (target: Node, controlRoot: HTMLElement | undefined) => boolean;
|
|
14
16
|
/** Below the calling component no control is named by the surrounding FormField label — for a field that renders other fields in its own panel. */
|
|
15
17
|
export declare const stopFormFieldLabelHere: () => void;
|
|
@@ -14,6 +14,8 @@ export const claimFormFieldLabel = (controlId) => {
|
|
|
14
14
|
};
|
|
15
15
|
/** The `aria-labelledby` of a control that is not a text input: the explicit one, else the FormField label's id — unless an explicit `aria-label` names it. */
|
|
16
16
|
export const resolveAriaLabelledby = (formFieldLabel, ariaLabel, ariaLabelledby) => ariaLabelledby ?? (ariaLabel ? undefined : formFieldLabel?.labelId);
|
|
17
|
+
/** Whether `target` sits in a `<label>` whose `for` control lies inside `controlRoot` — a press there belongs to that control, not outside it. */
|
|
18
|
+
export const isInsideLabelOf = (target, controlRoot) => target instanceof Element && !!controlRoot?.contains(target.closest('label')?.control ?? null);
|
|
17
19
|
/** Below the calling component no control is named by the surrounding FormField label — for a field that renders other fields in its own panel. */
|
|
18
20
|
export const stopFormFieldLabelHere = () => {
|
|
19
21
|
setContext(KEY, undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { claimFormFieldLabel, getFormFieldLabel, provideFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere, type FormFieldLabelContext } from './form-field-label-context.svelte';
|
|
1
|
+
export { claimFormFieldLabel, getFormFieldLabel, isInsideLabelOf, provideFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere, type FormFieldLabelContext } from './form-field-label-context.svelte';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { claimFormFieldLabel, getFormFieldLabel, provideFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere } from './form-field-label-context.svelte';
|
|
1
|
+
export { claimFormFieldLabel, getFormFieldLabel, isInsideLabelOf, provideFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere } from './form-field-label-context.svelte';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">import { ColorHelper } from '../../core/utils';
|
|
2
|
-
import { getFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere } from '../_internal/form-field-label-context';
|
|
2
|
+
import { claimFormFieldLabel, getFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere } from '../_internal/form-field-label-context';
|
|
3
3
|
import { Icon } from '../icon';
|
|
4
4
|
import { Input } from '../input';
|
|
5
5
|
import { Popover } from '../popover';
|
|
@@ -11,6 +11,8 @@ import { colord } from 'colord';
|
|
|
11
11
|
import AwesomeColorPicker from 'svelte-awesome-color-picker';
|
|
12
12
|
let { value, variant = 'fill', label, size = 'md', defaultColor, clearable = false, disabled = false, placeholder, on, children, previewIcon, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby } = $props();
|
|
13
13
|
const formFieldLabel = getFormFieldLabel();
|
|
14
|
+
const triggerId = $props.id();
|
|
15
|
+
claimFormFieldLabel(() => triggerId);
|
|
14
16
|
stopFormFieldLabelHere();
|
|
15
17
|
const loc = new ColorPickerLocalization();
|
|
16
18
|
const displayColor = $derived(value || defaultColor || '');
|
|
@@ -54,6 +56,7 @@ const onColorPickerInput = ({ hex }) => {
|
|
|
54
56
|
panel={false}
|
|
55
57
|
fixedPosition
|
|
56
58
|
disabled={disabled}
|
|
59
|
+
id={triggerId}
|
|
57
60
|
aria-label={ariaLabel}
|
|
58
61
|
aria-labelledby={resolveAriaLabelledby(formFieldLabel, ariaLabel, ariaLabelledby)}>
|
|
59
62
|
{#snippet trigger()}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script lang="ts">import { getFormFieldLabel, resolveAriaLabelledby } from '../_internal/form-field-label-context';
|
|
1
|
+
<script lang="ts">import { claimFormFieldLabel, getFormFieldLabel, isInsideLabelOf, resolveAriaLabelledby } from '../_internal/form-field-label-context';
|
|
2
2
|
import { InputClearButton } from '../_internal/input-clear-button';
|
|
3
3
|
import { Icon, IconSlot } from '../icon';
|
|
4
4
|
import DatePickerCalendar from './cmp.date-picker-calendar.svelte';
|
|
@@ -7,6 +7,9 @@ import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/d
|
|
|
7
7
|
import IconCalendar from '@fluentui/svg-icons/icons/calendar_16_regular.svg?raw';
|
|
8
8
|
const { size = 'md', placeholder = '', disabled = false, readonly = false, inert = false, error = false, borderless = false, min, max, locale, name, id = null, autofocus = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'aria-required': ariaRequired, icon, ...mode } = $props();
|
|
9
9
|
const formFieldLabel = getFormFieldLabel();
|
|
10
|
+
const fallbackId = $props.id();
|
|
11
|
+
const controlId = $derived(id ?? fallbackId);
|
|
12
|
+
claimFormFieldLabel(() => controlId);
|
|
10
13
|
const localization = new DatePickerLocalization();
|
|
11
14
|
/** Resolved locale: explicit prop or `'en-US'` default. */
|
|
12
15
|
const resolvedLocale = $derived(locale ?? 'en-US');
|
|
@@ -95,7 +98,7 @@ $effect(() => {
|
|
|
95
98
|
if (!target) {
|
|
96
99
|
return;
|
|
97
100
|
}
|
|
98
|
-
if (triggerEl?.contains(target) || panelEl?.contains(target)) {
|
|
101
|
+
if (triggerEl?.contains(target) || panelEl?.contains(target) || isInsideLabelOf(target, triggerEl)) {
|
|
99
102
|
return;
|
|
100
103
|
}
|
|
101
104
|
open = false;
|
|
@@ -129,7 +132,7 @@ $effect(() => {
|
|
|
129
132
|
bind:this={triggerEl}
|
|
130
133
|
type="button"
|
|
131
134
|
class="date-picker__trigger"
|
|
132
|
-
id={
|
|
135
|
+
id={controlId}
|
|
133
136
|
disabled={disabled}
|
|
134
137
|
inert={inert}
|
|
135
138
|
autofocus={autofocus}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends Record<string, unknown>, K extends keyof T & string">import { Validatable } from '../validatable';
|
|
2
2
|
import { default as FormField } from './cmp.form-field.svelte';
|
|
3
|
-
let { handler, name, label, hint, required = false,
|
|
3
|
+
let { handler, name, label, hint, required = false, debounceMs, disableTouchedTracking, errorPlacement, on, children: field } = $props();
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
|
-
<Validatable
|
|
7
|
-
handler={handler}
|
|
8
|
-
name={name}
|
|
9
|
-
validateOn={validateOn}
|
|
10
|
-
debounceMs={debounceMs}
|
|
11
|
-
disableTouchedTracking={disableTouchedTracking}
|
|
12
|
-
errorPlacement={errorPlacement}
|
|
13
|
-
on={on}>
|
|
6
|
+
<Validatable handler={handler} name={name} debounceMs={debounceMs} disableTouchedTracking={disableTouchedTracking} errorPlacement={errorPlacement} on={on}>
|
|
14
7
|
{#snippet children(binding, validating)}
|
|
15
8
|
<FormField label={label} hint={hint} required={required}>
|
|
16
9
|
{#snippet children(ids)}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { FormValidationHandler } from '../../core/validation';
|
|
2
|
-
import { type ErrorPlacement, type FieldBinding
|
|
2
|
+
import { type ErrorPlacement, type FieldBinding } from '../validatable';
|
|
3
3
|
import { type FormFieldIds } from './cmp.form-field.svelte';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
declare function $$render<T extends Record<string, unknown>, K extends keyof T & string>(): {
|
|
6
6
|
props: {
|
|
7
|
-
/** Form validation handler instance. */
|
|
8
7
|
handler: FormValidationHandler<T>;
|
|
9
|
-
/** Field name in the form handler. */
|
|
10
8
|
name: K;
|
|
11
9
|
/** Label rendered above the input. String renders as text; Snippet allows extra content (e.g. tooltip icon) next to the text. */
|
|
12
10
|
label?: string | Snippet;
|
|
@@ -14,11 +12,9 @@ declare function $$render<T extends Record<string, unknown>, K extends keyof T &
|
|
|
14
12
|
hint?: string | Snippet;
|
|
15
13
|
/** Appends a danger-colored `*` to the label. */
|
|
16
14
|
required?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
validateOn?: ValidateOnEvent[];
|
|
19
|
-
/** Debounce validator calls in ms. Forwarded to `<Validatable>`. @default 0 */
|
|
15
|
+
/** Delay before the validator runs after the value changes. Forwarded to `<Validatable>`. */
|
|
20
16
|
debounceMs?: number;
|
|
21
|
-
/** Show errors before the field has been touched. Forwarded to `<Validatable>`.
|
|
17
|
+
/** Show errors before the field has been touched. Forwarded to `<Validatable>`. */
|
|
22
18
|
disableTouchedTracking?: boolean;
|
|
23
19
|
/** Where the error message sits. Forwarded to `<Validatable>`. @default 'overlay' */
|
|
24
20
|
errorPlacement?: ErrorPlacement;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
<script lang="ts">import {
|
|
1
|
+
<script lang="ts">import { isInsideLabelOf } from '../_internal/form-field-label-context';
|
|
2
|
+
import { Icon } from '../icon';
|
|
2
3
|
import { isIgnored } from './popover-ignore';
|
|
3
4
|
import { validateTrigger } from './validate-trigger';
|
|
4
5
|
import { autoUpdate, computePosition, flip, offset as offsetMiddleware, shift, size } from '@floating-ui/dom';
|
|
5
6
|
import IconChevronDown from '@fluentui/svg-icons/icons/chevron_down_20_regular.svg?raw';
|
|
6
7
|
import { tick } from 'svelte';
|
|
7
|
-
let { position = 'bottom-start', disabled = false, fixedPosition = false, offset = 4, boundaryMargin = 8, backdrop = false, matchWidth = false, panel = true, keepOpen = false, fillContainer = false, tabbable = true, on, children, trigger, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby } = $props();
|
|
8
|
+
let { position = 'bottom-start', disabled = false, fixedPosition = false, offset = 4, boundaryMargin = 8, backdrop = false, matchWidth = false, panel = true, keepOpen = false, fillContainer = false, tabbable = true, on, children, trigger, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby } = $props();
|
|
8
9
|
let opened = $state(false);
|
|
9
10
|
let triggerEl = $state.raw(undefined);
|
|
10
11
|
let contentEl = $state.raw(undefined);
|
|
@@ -106,7 +107,7 @@ $effect(() => {
|
|
|
106
107
|
if (!target) {
|
|
107
108
|
return;
|
|
108
109
|
}
|
|
109
|
-
if (triggerEl?.contains(target) || contentEl?.contains(target)) {
|
|
110
|
+
if (triggerEl?.contains(target) || contentEl?.contains(target) || isInsideLabelOf(target, triggerEl)) {
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
113
|
close();
|
|
@@ -179,6 +180,7 @@ const handleBackdropClick = (e) => {
|
|
|
179
180
|
type="button"
|
|
180
181
|
class="popover__trigger"
|
|
181
182
|
class:popover__trigger--fill={fillContainer}
|
|
183
|
+
id={id}
|
|
182
184
|
disabled={disabled}
|
|
183
185
|
tabindex={tabbable ? undefined : -1}
|
|
184
186
|
aria-label={ariaLabel}
|
|
@@ -29,6 +29,7 @@ type Props = {
|
|
|
29
29
|
children: Snippet;
|
|
30
30
|
/** Content of the trigger `<button>`, so non-interactive only — `Button type="presentational"` for a button look. @default chevron-down icon */
|
|
31
31
|
trigger?: Snippet;
|
|
32
|
+
id?: string;
|
|
32
33
|
'aria-label'?: string;
|
|
33
34
|
'aria-labelledby'?: string;
|
|
34
35
|
};
|
|
@@ -5,7 +5,7 @@ export type MultiselectInstance = {
|
|
|
5
5
|
};
|
|
6
6
|
import { type MultiselectBaseProps, type SelectOption } from './types';
|
|
7
7
|
declare function $$render<T>(): {
|
|
8
|
-
props: Omit<MultiselectBaseProps<T>, "value" | "
|
|
8
|
+
props: Omit<MultiselectBaseProps<T>, "value" | "debounceMs" | "on" | "loadOptions" | "groupHeader" | "selectionMode" | "parentSource"> & {
|
|
9
9
|
/** Flat option list. Fuse filters in-memory on every keystroke — no debounce. */
|
|
10
10
|
options: SelectOption<T>[];
|
|
11
11
|
/** Current selection — array of values. Order is preserved (and editable when `reorderable`). */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>export {};
|
|
2
2
|
</script>
|
|
3
3
|
|
|
4
|
-
<script lang="ts" generics="T">import { getFormFieldLabel, resolveAriaLabelledby } from '../_internal/form-field-label-context';
|
|
4
|
+
<script lang="ts" generics="T">import { claimFormFieldLabel, getFormFieldLabel, resolveAriaLabelledby } from '../_internal/form-field-label-context';
|
|
5
5
|
import { InputClearButton } from '../_internal/input-clear-button';
|
|
6
6
|
import { Spinner } from '../_internal/spinner';
|
|
7
7
|
import { Icon, IconSlot } from '../icon';
|
|
@@ -12,6 +12,9 @@ import { SingleselectLocalization } from './singleselect-localization';
|
|
|
12
12
|
import IconChevronDown from '@fluentui/svg-icons/icons/chevron_down_16_regular.svg?raw';
|
|
13
13
|
const { loadOptions, debounceMs = 400, size = 'md', placeholder = '', disabled = false, readonly = false, inert = false, error = false, borderless = false, searchable = true, groupHeader = 'static', compare = defaultCompare, createOptions, icon, chevronIcon, optionSnippet, selectionSnippet, listbox, id, name, autocomplete = 'off', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'aria-required': ariaRequired, ...mode } = $props();
|
|
14
14
|
const formFieldLabel = getFormFieldLabel();
|
|
15
|
+
const fallbackId = $props.id();
|
|
16
|
+
const controlId = $derived(id ?? fallbackId);
|
|
17
|
+
claimFormFieldLabel(() => controlId);
|
|
15
18
|
const localization = new SingleselectLocalization();
|
|
16
19
|
const selectedOption = $derived(mode.value ?? null);
|
|
17
20
|
const selectionLabel = $derived(selectedOption?.label ?? '');
|
|
@@ -107,7 +110,7 @@ const showClear = $derived(mode.clearable && hasValue && isInteractive && !core.
|
|
|
107
110
|
aria-describedby={ariaDescribedby}
|
|
108
111
|
aria-required={ariaRequired}
|
|
109
112
|
aria-invalid={error ? 'true' : undefined}
|
|
110
|
-
id={
|
|
113
|
+
id={controlId}
|
|
111
114
|
name={name}
|
|
112
115
|
autocomplete={autocomplete}
|
|
113
116
|
placeholder={inputPlaceholder}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>export {};
|
|
2
2
|
</script>
|
|
3
3
|
|
|
4
|
-
<script lang="ts" generics="T">import { getFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere } from '../_internal/form-field-label-context';
|
|
4
|
+
<script lang="ts" generics="T">import { claimFormFieldLabel, getFormFieldLabel, resolveAriaLabelledby, stopFormFieldLabelHere } from '../_internal/form-field-label-context';
|
|
5
5
|
import { Spinner } from '../_internal/spinner';
|
|
6
6
|
import { Button } from '../button';
|
|
7
7
|
import { Icon, IconSlot } from '../icon';
|
|
@@ -16,6 +16,9 @@ import IconChevronDown from '@fluentui/svg-icons/icons/chevron_down_16_regular.s
|
|
|
16
16
|
import { dndzone } from 'svelte-dnd-action';
|
|
17
17
|
const { loadOptions, debounceMs = 400, value, size = 'md', placeholder = '', disabled = false, readonly = false, inert = false, error = false, borderless = false, searchable = true, groupHeader = 'static', compare = defaultCompare, selectionMode = 'children-only', selectedDisplay = 'checkmark', createOptions, chipMode = 'inline', reorderable = false, maxVisible = Infinity, showFullItem = false, chipVariant, showChevron = true, hideSelected = false, icon, chevronIcon, optionSnippet, chipSnippet, selectionSnippet, parentSource, id, name, autocomplete = 'off', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, 'aria-required': ariaRequired, on } = $props();
|
|
18
18
|
const formFieldLabel = getFormFieldLabel();
|
|
19
|
+
const fallbackId = $props.id();
|
|
20
|
+
const controlId = $derived(id ?? fallbackId);
|
|
21
|
+
claimFormFieldLabel(() => controlId);
|
|
19
22
|
stopFormFieldLabelHere();
|
|
20
23
|
const localization = new MultiselectLocalization();
|
|
21
24
|
const isPicked = (v) => value.some((existing) => compare(existing.value, v));
|
|
@@ -232,7 +235,7 @@ const handleDndFinalize = (e) => {
|
|
|
232
235
|
aria-describedby={ariaDescribedby}
|
|
233
236
|
aria-required={ariaRequired}
|
|
234
237
|
aria-invalid={error ? 'true' : undefined}
|
|
235
|
-
id={
|
|
238
|
+
id={controlId}
|
|
236
239
|
name={name}
|
|
237
240
|
autocomplete={autocomplete}
|
|
238
241
|
placeholder={!hasValue && !core.isFiltering ? placeholder : ''}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<script lang="ts" generics="T">import {
|
|
1
|
+
<script lang="ts" generics="T">import { isInsideLabelOf } from '../_internal/form-field-label-context';
|
|
2
|
+
import { Icon } from '../icon';
|
|
2
3
|
import { SelectListboxLocalization } from './select-listbox-localization';
|
|
3
4
|
import { autoUpdate, computePosition, flip, shift, size as floatingSize } from '@floating-ui/dom';
|
|
4
5
|
import IconAdd from '@fluentui/svg-icons/icons/add_16_regular.svg?raw';
|
|
@@ -71,7 +72,7 @@ $effect(() => {
|
|
|
71
72
|
if (!target) {
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
|
-
if (triggerEl?.contains(target) || panelEl?.contains(target)) {
|
|
75
|
+
if (triggerEl?.contains(target) || panelEl?.contains(target) || isInsideLabelOf(target, triggerEl)) {
|
|
75
76
|
return;
|
|
76
77
|
}
|
|
77
78
|
on.dismiss();
|
|
@@ -195,6 +195,7 @@ const handleActionsClosed = () => {
|
|
|
195
195
|
class:tree-node__leaf--draggable={node.drag}
|
|
196
196
|
class:tree-node__leaf--expandable={children.length}
|
|
197
197
|
class:tree-node__leaf--drag-over={dragOver}
|
|
198
|
+
class:tree-node__leaf--with-actions={actionsShown}
|
|
198
199
|
draggable={!!node.drag && !node.renaming}
|
|
199
200
|
ondragstart={handleDragStart}
|
|
200
201
|
ondragend={handleDragEnd}
|
|
@@ -307,7 +308,6 @@ const handleActionsClosed = () => {
|
|
|
307
308
|
--_tree-node--padding-inline: var(--sc-kit--tree-node--padding-inline, 0.5rem);
|
|
308
309
|
--_tree-node--padding-block: var(--sc-kit--tree-node--padding-block, 0.375rem);
|
|
309
310
|
--_tree-node--indent: var(--sc-kit--tree-node--indent, 1rem);
|
|
310
|
-
--_tree-node--action-opacity: 0;
|
|
311
311
|
position: relative;
|
|
312
312
|
width: 100%;
|
|
313
313
|
color: var(--sc-kit--color--text--primary);
|
|
@@ -325,17 +325,25 @@ const handleActionsClosed = () => {
|
|
|
325
325
|
transition: background-color var(--sc-kit--duration--base) var(--sc-kit--ease--default), color var(--sc-kit--duration--base) var(--sc-kit--ease--default);
|
|
326
326
|
}
|
|
327
327
|
.tree-node__leaf:hover {
|
|
328
|
-
--_tree-node--action-opacity: 1;
|
|
329
328
|
color: var(--sc-kit--color--text--primary);
|
|
330
329
|
background: var(--sc-kit--color--bg--hover);
|
|
331
330
|
}
|
|
332
331
|
.tree-node__leaf--active {
|
|
333
|
-
--_tree-node--action-opacity: 1;
|
|
334
332
|
color: var(--sc-kit--color--text--primary);
|
|
335
333
|
background: var(--sc-kit--color--bg--active);
|
|
336
334
|
}
|
|
337
|
-
|
|
338
|
-
--
|
|
335
|
+
@media (any-hover: hover) {
|
|
336
|
+
.tree-node__leaf--with-actions:not(:hover, :has(:global(:focus-visible)), :has(.node-actions--opened)) .node-actions, .tree-node__leaf--with-actions:is(:hover, :has(:global(:focus-visible)), :has(.node-actions--opened)) .tree-node__count {
|
|
337
|
+
position: absolute;
|
|
338
|
+
width: 1px;
|
|
339
|
+
height: 1px;
|
|
340
|
+
margin: -1px;
|
|
341
|
+
padding: 0;
|
|
342
|
+
overflow: hidden;
|
|
343
|
+
clip-path: inset(50%);
|
|
344
|
+
white-space: nowrap;
|
|
345
|
+
border: 0;
|
|
346
|
+
}
|
|
339
347
|
}
|
|
340
348
|
.tree-node__leaf:has(.tree-node__anchor:focus-visible) {
|
|
341
349
|
outline: 2px solid var(--sc-kit--color--border--focus);
|
|
@@ -433,11 +441,6 @@ const handleActionsClosed = () => {
|
|
|
433
441
|
flex-shrink: 0;
|
|
434
442
|
align-items: center;
|
|
435
443
|
margin-left: var(--sc-kit--space--1);
|
|
436
|
-
opacity: var(--_tree-node--action-opacity);
|
|
437
|
-
transition: opacity var(--sc-kit--duration--base) var(--sc-kit--ease--default);
|
|
438
|
-
}
|
|
439
|
-
.node-actions--opened {
|
|
440
|
-
opacity: 1;
|
|
441
444
|
}
|
|
442
445
|
.node-actions__trigger {
|
|
443
446
|
--sc-kit--icon--size: 1rem;
|
|
@@ -452,9 +455,4 @@ const handleActionsClosed = () => {
|
|
|
452
455
|
.node-actions__trigger:hover {
|
|
453
456
|
background: var(--sc-kit--color--bg--active);
|
|
454
457
|
color: var(--sc-kit--color--text--primary);
|
|
455
|
-
}
|
|
456
|
-
@media (any-hover: none) {
|
|
457
|
-
.node-actions {
|
|
458
|
-
opacity: 1;
|
|
459
|
-
}
|
|
460
458
|
}</style>
|
|
@@ -1,33 +1,9 @@
|
|
|
1
|
-
<script lang="ts"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { default as FieldFrame } from './field-frame.svelte';
|
|
6
|
-
let { handler, name, validateOn = ['input', 'change', 'blur'], debounceMs = 0, disableTouchedTracking = false, errorPlacement = 'overlay', on, children } = $props();
|
|
7
|
-
// True between a value change and the next completed validation. Hides the stale error in the
|
|
8
|
-
// UI without mutating handler.errors — the model keeps the last known result, the view just
|
|
9
|
-
// doesn't trust it until the validator has caught up.
|
|
10
|
-
let pendingValidation = $state(false);
|
|
11
|
-
// Monotonic counter: each value change and each validation start bumps it. Completing
|
|
12
|
-
// validation clears `pendingValidation` only when the token still matches the latest bump —
|
|
13
|
-
// this discards results from validations that were superseded by further input.
|
|
14
|
-
let activeToken = 0;
|
|
15
|
-
const runValidate = async () => {
|
|
16
|
-
const myToken = ++activeToken;
|
|
17
|
-
try {
|
|
18
|
-
await handler.validateField(name);
|
|
19
|
-
}
|
|
20
|
-
finally {
|
|
21
|
-
// A rejecting validator would otherwise strand pendingValidation, and the children snippet reads it as a never-ending `validating`.
|
|
22
|
-
if (myToken === activeToken) {
|
|
23
|
-
pendingValidation = false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const validate = $derived(debounceMs > 0 ? Utils.debounce(runValidate, debounceMs) : runValidate);
|
|
28
|
-
const runs = (mode) => validateOn.includes(mode);
|
|
29
|
-
const showErrors = $derived(!pendingValidation && !!handler.errors[name] && (disableTouchedTracking || !!handler.touched[name]));
|
|
1
|
+
<script lang="ts" generics="T extends Record<string, unknown>, K extends keyof T & string">import { default as FieldFrame } from './field-frame.svelte';
|
|
2
|
+
let { handler, name, debounceMs = 0, disableTouchedTracking = false, errorPlacement = 'overlay', on, children } = $props();
|
|
3
|
+
const validating = $derived(handler.isFieldValidating(name));
|
|
4
|
+
const showErrors = $derived(!validating && !!handler.errors[name] && (disableTouchedTracking || !!handler.touched[name]));
|
|
30
5
|
const messageId = $props.id();
|
|
6
|
+
const validate = () => void handler.validateField(name, { debounceMs, onlyIfChanged: true });
|
|
31
7
|
const field = $derived({
|
|
32
8
|
name,
|
|
33
9
|
value: handler.form[name],
|
|
@@ -36,30 +12,17 @@ const field = $derived({
|
|
|
36
12
|
on: {
|
|
37
13
|
input: (v) => {
|
|
38
14
|
handler.updateField(name, v);
|
|
39
|
-
|
|
40
|
-
pendingValidation = true;
|
|
41
|
-
if (runs('input')) {
|
|
42
|
-
validate();
|
|
43
|
-
}
|
|
15
|
+
validate();
|
|
44
16
|
on?.input?.(v);
|
|
45
17
|
},
|
|
46
18
|
change: (v) => {
|
|
47
19
|
handler.updateField(name, v);
|
|
48
|
-
|
|
49
|
-
pendingValidation = true;
|
|
50
|
-
if (runs('change')) {
|
|
51
|
-
validate();
|
|
52
|
-
}
|
|
20
|
+
validate();
|
|
53
21
|
on?.change?.(v);
|
|
54
22
|
},
|
|
55
23
|
blur: () => {
|
|
56
24
|
handler.updateTouched(name, true);
|
|
57
|
-
|
|
58
|
-
validate();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
pendingValidation = false;
|
|
62
|
-
}
|
|
25
|
+
validate();
|
|
63
26
|
on?.blur?.();
|
|
64
27
|
}
|
|
65
28
|
}
|
|
@@ -67,7 +30,7 @@ const field = $derived({
|
|
|
67
30
|
</script>
|
|
68
31
|
|
|
69
32
|
<FieldFrame error={showErrors ? handler.errors[name] : null} errorPlacement={errorPlacement} messageId={messageId}>
|
|
70
|
-
{@render children(field,
|
|
33
|
+
{@render children(field, validating)}
|
|
71
34
|
</FieldFrame>
|
|
72
35
|
|
|
73
36
|
<!--
|
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
export type ValidateOnEvent = 'input' | 'change' | 'blur';
|
|
2
|
-
export type FieldBinding<V> = {
|
|
3
|
-
name: string;
|
|
4
|
-
value: V;
|
|
5
|
-
error: boolean;
|
|
6
|
-
/** Id of the visible error message, set only while the error is shown. */
|
|
7
|
-
'aria-describedby'?: string;
|
|
8
|
-
on: {
|
|
9
|
-
input: (v: V) => void;
|
|
10
|
-
change: (v: V) => void;
|
|
11
|
-
blur: () => void;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
1
|
import type { FormValidationHandler } from '../../core/validation';
|
|
15
|
-
import type { ErrorPlacement } from './types';
|
|
2
|
+
import type { ErrorPlacement, FieldBinding } from './types';
|
|
16
3
|
import type { Snippet } from 'svelte';
|
|
17
4
|
declare function $$render<T extends Record<string, unknown>, K extends keyof T & string>(): {
|
|
18
5
|
props: {
|
|
19
|
-
/** Form validation handler instance. */
|
|
20
6
|
handler: FormValidationHandler<T>;
|
|
21
|
-
/** Field name in the form handler. */
|
|
22
7
|
name: K;
|
|
23
|
-
/**
|
|
24
|
-
* Which events trigger validation. Value is always updated synchronously on `input`/`change`
|
|
25
|
-
* regardless of this option — it only controls when the validator runs.
|
|
26
|
-
* @default ['input', 'change', 'blur']
|
|
27
|
-
*/
|
|
28
|
-
validateOn?: ValidateOnEvent[];
|
|
29
|
-
/**
|
|
30
|
-
* Debounce validator calls in ms. Value update stays sync; only validation is delayed.
|
|
31
|
-
* @default 0
|
|
32
|
-
*/
|
|
8
|
+
/** Delay before the validator runs after the value changes; the value itself updates at once. */
|
|
33
9
|
debounceMs?: number;
|
|
34
|
-
/** Show errors even when the field has not been touched.
|
|
10
|
+
/** Show errors even when the field has not been touched. */
|
|
35
11
|
disableTouchedTracking?: boolean;
|
|
36
12
|
/**
|
|
37
13
|
* Where the error message sits: `'overlay'` covers whatever is below the field, `'reserved'` keeps a
|
|
@@ -51,8 +27,7 @@ declare function $$render<T extends Record<string, unknown>, K extends keyof T &
|
|
|
51
27
|
/**
|
|
52
28
|
* Receives a wired `FieldBinding<T[K]>` to spread into a kit input (`aria-describedby` points at the visible error message; inputs without that
|
|
53
29
|
* prop ignore it; a control whose value prop is not `value`, e.g. `Checkbox`, is wired by hand), plus a `validating` flag — true from the value
|
|
54
|
-
* change until the validator has caught up, debounce window included
|
|
55
|
-
* excludes `input` and `change` the flag stays true for the whole typing session.
|
|
30
|
+
* change until the validator has caught up, debounce window included.
|
|
56
31
|
*/
|
|
57
32
|
children: Snippet<[FieldBinding<T[K]>, boolean]>;
|
|
58
33
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { default as Validatable } from './cmp.validatable.svelte';
|
|
2
|
-
export type { FieldBinding, ValidateOnEvent } from './cmp.validatable.svelte';
|
|
3
2
|
export { default as ValidationError } from './cmp.validation-error.svelte';
|
|
4
|
-
export type { ErrorPlacement } from './types';
|
|
3
|
+
export type { ErrorPlacement, FieldBinding } from './types';
|
|
@@ -5,3 +5,15 @@
|
|
|
5
5
|
* - `'inline'` — in normal flow, only while an error is shown: the field grows on error and shrinks back when it clears.
|
|
6
6
|
*/
|
|
7
7
|
export type ErrorPlacement = 'overlay' | 'reserved' | 'inline';
|
|
8
|
+
export type FieldBinding<V> = {
|
|
9
|
+
name: string;
|
|
10
|
+
value: V;
|
|
11
|
+
error: boolean;
|
|
12
|
+
/** Id of the visible error message, set only while the error is shown. */
|
|
13
|
+
'aria-describedby'?: string;
|
|
14
|
+
on: {
|
|
15
|
+
input: (v: V) => void;
|
|
16
|
+
change: (v: V) => void;
|
|
17
|
+
blur: () => void;
|
|
18
|
+
};
|
|
19
|
+
};
|