@streamscloud/kit 0.90.1 → 0.92.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/styles/_semantic.scss +0 -1
- package/dist/ui/_internal/_top-layer.scss +10 -0
- package/dist/ui/_internal/input-emoji-picker/cmp.input-emoji-picker.svelte +1 -1
- package/dist/ui/_internal/top-layer/index.d.ts +1 -0
- package/dist/ui/_internal/top-layer/index.js +6 -0
- package/dist/ui/breadcrumb/cmp.breadcrumb.svelte +4 -11
- package/dist/ui/color-picker/cmp.color-picker.svelte +0 -1
- package/dist/ui/date-picker/cmp.date-picker.svelte +50 -100
- package/dist/ui/date-picker/cmp.date-picker.svelte.d.ts +1 -1
- 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/player/buttons/player-context-menu.svelte +1 -1
- package/dist/ui/popover/cmp.hover-popover.svelte.d.ts +0 -1
- package/dist/ui/popover/cmp.popover.svelte +84 -41
- package/dist/ui/popover/cmp.popover.svelte.d.ts +15 -9
- package/dist/ui/select/cmp.multiselect.svelte.d.ts +1 -1
- package/dist/ui/select/select-listbox.svelte +17 -9
- package/dist/ui/tile-card/cmp.tile-card.svelte +0 -1
- package/dist/ui/toast/cmp.toaster.svelte +0 -4
- package/dist/ui/tooltip/cmp.tooltip.svelte +15 -8
- package/dist/ui/tooltip/cmp.tooltip.svelte.d.ts +0 -1
- package/dist/ui/tree/cmp.tree-node-view.svelte +1 -1
- package/dist/ui/url-input/cmp.url-input.svelte +1 -1
- 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
|
+
}
|
|
@@ -93,7 +93,6 @@
|
|
|
93
93
|
|
|
94
94
|
// Z-scale — relative stacking order for the library's overlay components.
|
|
95
95
|
// 100-unit gaps leave room for consumers to inject custom layers between.
|
|
96
|
-
// Tooltip sits above modals so tooltips work inside dialogs.
|
|
97
96
|
--sc-kit--z-index--popover: 1000;
|
|
98
97
|
--sc-kit--z-index--modal: 1100;
|
|
99
98
|
--sc-kit--z-index--toast: 1200;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Include first: the UA [popover] inset / margin / border / padding / overflow / colors otherwise override the host's box.
|
|
2
|
+
@mixin reset {
|
|
3
|
+
inset: 0 auto auto 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: 0;
|
|
6
|
+
border: 0;
|
|
7
|
+
overflow: visible;
|
|
8
|
+
color: inherit;
|
|
9
|
+
background: transparent;
|
|
10
|
+
}
|
|
@@ -7,7 +7,7 @@ let popover = $state.raw(undefined);
|
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
9
|
<span class="input-emoji-picker input-emoji-picker--{size}">
|
|
10
|
-
<Popover bind:this={popover} position="bottom-end" panel={false} keepOpen fillContainer
|
|
10
|
+
<Popover bind:this={popover} position="bottom-end" panel={false} keepOpen fillContainer>
|
|
11
11
|
{#snippet trigger()}
|
|
12
12
|
<Icon src={IconEmoji} />
|
|
13
13
|
{/snippet}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const showInTopLayer: (element: HTMLElement) => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Call it from the autoUpdate callback too: a keyed {#each} moving an ancestor re-inserts the node, which hides it without a toggle event.
|
|
2
|
+
export const showInTopLayer = (element) => {
|
|
3
|
+
if (element.isConnected && !element.matches(':popover-open')) {
|
|
4
|
+
element.showPopover();
|
|
5
|
+
}
|
|
6
|
+
};
|
|
@@ -6,14 +6,11 @@ let { items, separator = '/', underline = 'hover', overflow = 'wrap', maxItems }
|
|
|
6
6
|
const localization = new BreadcrumbLocalization();
|
|
7
7
|
let canScrollBack = $state(false);
|
|
8
8
|
let canScrollForward = $state(false);
|
|
9
|
-
let menuOpened = $state(false);
|
|
10
9
|
const tailLength = $derived(maxItems === undefined ? 0 : Math.max(2, maxItems) - 1);
|
|
11
10
|
const collapsed = $derived(maxItems !== undefined && items.length > tailLength + 1);
|
|
12
11
|
const hiddenItems = $derived(collapsed ? items.slice(1, items.length - tailLength) : []);
|
|
13
12
|
const shownItems = $derived(collapsed ? [items[0], ...items.slice(items.length - tailLength)] : items);
|
|
14
13
|
const scrolls = $derived(overflow === 'scroll');
|
|
15
|
-
// The "…" Popover renders inside the track; a mask would hide it.
|
|
16
|
-
const masked = $derived(scrolls && !menuOpened);
|
|
17
14
|
const updateScrollState = (node) => {
|
|
18
15
|
canScrollBack = node.scrollLeft > 0;
|
|
19
16
|
canScrollForward = node.scrollLeft < node.scrollWidth - node.clientWidth - 1;
|
|
@@ -61,9 +58,9 @@ const scrollTrack = (node, _items) => {
|
|
|
61
58
|
<div
|
|
62
59
|
class="breadcrumb breadcrumb--underline-{underline}"
|
|
63
60
|
class:breadcrumb--scroll={scrolls}
|
|
64
|
-
class:breadcrumb--mask-back={
|
|
65
|
-
class:breadcrumb--mask-forward={
|
|
66
|
-
class:breadcrumb--mask-both={
|
|
61
|
+
class:breadcrumb--mask-back={scrolls && canScrollBack && !canScrollForward}
|
|
62
|
+
class:breadcrumb--mask-forward={scrolls && canScrollForward && !canScrollBack}
|
|
63
|
+
class:breadcrumb--mask-both={scrolls && canScrollBack && canScrollForward}
|
|
67
64
|
role="navigation"
|
|
68
65
|
aria-label={localization.navLabel}
|
|
69
66
|
use:scrollTrack={shownItems}
|
|
@@ -75,11 +72,7 @@ const scrollTrack = (node, _items) => {
|
|
|
75
72
|
{#if i === 0 && collapsed}
|
|
76
73
|
<span class="breadcrumb__separator" aria-hidden="true">{separator}</span>
|
|
77
74
|
<span class="breadcrumb__more" onwheel={(e) => e.stopPropagation()}>
|
|
78
|
-
<Popover
|
|
79
|
-
position="bottom-start"
|
|
80
|
-
fixedPosition
|
|
81
|
-
aria-label={localization.hiddenLevels}
|
|
82
|
-
on={{ opened: () => (menuOpened = true), closed: () => (menuOpened = false) }}>
|
|
75
|
+
<Popover position="bottom-start" aria-label={localization.hiddenLevels}>
|
|
83
76
|
{#snippet trigger()}
|
|
84
77
|
<span class="breadcrumb__more-trigger">…</span>
|
|
85
78
|
{/snippet}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<script lang="ts">import { claimFormFieldLabel, getFormFieldLabel,
|
|
1
|
+
<script lang="ts">import { claimFormFieldLabel, getFormFieldLabel, resolveAriaLabelledby } from '../_internal/form-field-label-context';
|
|
2
2
|
import { InputClearButton } from '../_internal/input-clear-button';
|
|
3
3
|
import { Icon, IconSlot } from '../icon';
|
|
4
|
+
import { Popover } from '../popover';
|
|
4
5
|
import DatePickerCalendar from './cmp.date-picker-calendar.svelte';
|
|
5
6
|
import { DatePickerLocalization } from './date-picker-localization';
|
|
6
|
-
import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom';
|
|
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();
|
|
@@ -43,8 +43,8 @@ const maxDate = $derived(toDate(max ?? null));
|
|
|
43
43
|
const triggerFmt = $derived(new Intl.DateTimeFormat(resolvedLocale, { dateStyle: 'medium' }));
|
|
44
44
|
const triggerLabel = $derived(selectedDate ? triggerFmt.format(selectedDate) : '');
|
|
45
45
|
let open = $state(false);
|
|
46
|
+
let popover = $state.raw(undefined);
|
|
46
47
|
let triggerEl = $state.raw(undefined);
|
|
47
|
-
let panelEl = $state.raw(undefined);
|
|
48
48
|
const emit = (date) => {
|
|
49
49
|
const iso = date ? date.toISOString() : null;
|
|
50
50
|
if (mode.clearable) {
|
|
@@ -54,12 +54,9 @@ const emit = (date) => {
|
|
|
54
54
|
mode.on?.change?.(iso);
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
const toggleOpen = () => {
|
|
58
|
-
open = !open;
|
|
59
|
-
};
|
|
60
57
|
const handleSelect = (date) => {
|
|
61
58
|
emit(date);
|
|
62
|
-
|
|
59
|
+
popover?.close();
|
|
63
60
|
triggerEl?.focus();
|
|
64
61
|
};
|
|
65
62
|
const handleClearClick = () => {
|
|
@@ -68,58 +65,8 @@ const handleClearClick = () => {
|
|
|
68
65
|
}
|
|
69
66
|
emit(null);
|
|
70
67
|
};
|
|
71
|
-
// Floating UI: position on open, auto-update on scroll/resize, cleanup on close.
|
|
72
|
-
$effect(() => {
|
|
73
|
-
if (!open || !triggerEl || !panelEl) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const trigger = triggerEl;
|
|
77
|
-
const panel = panelEl;
|
|
78
|
-
const update = async () => {
|
|
79
|
-
const result = await computePosition(trigger, panel, {
|
|
80
|
-
placement: 'bottom-start',
|
|
81
|
-
middleware: [offset(4), flip(), shift({ padding: 8 })]
|
|
82
|
-
});
|
|
83
|
-
Object.assign(panel.style, {
|
|
84
|
-
position: 'absolute',
|
|
85
|
-
left: `${result.x}px`,
|
|
86
|
-
top: `${result.y}px`
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
return autoUpdate(trigger, panel, update);
|
|
90
|
-
});
|
|
91
|
-
// Dismiss listeners: only active while open.
|
|
92
|
-
$effect(() => {
|
|
93
|
-
if (!open) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const handleClickOutside = (e) => {
|
|
97
|
-
const target = e.target;
|
|
98
|
-
if (!target) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (triggerEl?.contains(target) || panelEl?.contains(target) || isInsideLabelOf(target, triggerEl)) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
open = false;
|
|
105
|
-
};
|
|
106
|
-
const handleKey = (e) => {
|
|
107
|
-
if (e.key === 'Escape') {
|
|
108
|
-
e.preventDefault();
|
|
109
|
-
open = false;
|
|
110
|
-
triggerEl?.focus();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
114
|
-
document.addEventListener('keydown', handleKey);
|
|
115
|
-
return () => {
|
|
116
|
-
document.removeEventListener('mousedown', handleClickOutside);
|
|
117
|
-
document.removeEventListener('keydown', handleKey);
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
68
|
</script>
|
|
121
69
|
|
|
122
|
-
<!-- svelte-ignore a11y_autofocus -->
|
|
123
70
|
<div
|
|
124
71
|
class="date-picker date-picker--{size}"
|
|
125
72
|
class:date-picker--open={open}
|
|
@@ -128,55 +75,60 @@ $effect(() => {
|
|
|
128
75
|
class:date-picker--readonly={readonly}
|
|
129
76
|
class:date-picker--inert={inert}
|
|
130
77
|
class:date-picker--borderless={borderless}>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{#if mode.clearable && selectedDate && !disabled && !readonly && !inert}
|
|
152
|
-
<InputClearButton size={size} aria-label={localization.clearDate} on={{ clear: handleClearClick }} />
|
|
153
|
-
{:else if !icon}
|
|
154
|
-
<span class="date-picker__icon date-picker__icon--trailing" aria-hidden="true">
|
|
155
|
-
<Icon src={IconCalendar} />
|
|
78
|
+
{#snippet triggerButton()}
|
|
79
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
80
|
+
<button
|
|
81
|
+
bind:this={triggerEl}
|
|
82
|
+
type="button"
|
|
83
|
+
class="date-picker__trigger"
|
|
84
|
+
id={controlId}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
inert={inert}
|
|
87
|
+
autofocus={autofocus}
|
|
88
|
+
aria-haspopup="dialog"
|
|
89
|
+
aria-expanded={open}
|
|
90
|
+
aria-label={ariaLabel ?? name}
|
|
91
|
+
aria-labelledby={resolveAriaLabelledby(formFieldLabel, ariaLabel, ariaLabelledby)}
|
|
92
|
+
aria-describedby={ariaDescribedby}>
|
|
93
|
+
{#if icon}
|
|
94
|
+
<span class="date-picker__icon date-picker__icon--leading" aria-hidden="true"><IconSlot icon={icon} /></span>
|
|
95
|
+
{/if}
|
|
96
|
+
<span class="date-picker__value" class:date-picker__value--placeholder={!selectedDate}>
|
|
97
|
+
{triggerLabel || placeholder}
|
|
156
98
|
</span>
|
|
157
|
-
|
|
158
|
-
|
|
99
|
+
{#if mode.clearable && selectedDate && !disabled && !readonly && !inert}
|
|
100
|
+
<InputClearButton size={size} aria-label={localization.clearDate} on={{ clear: handleClearClick }} />
|
|
101
|
+
{:else if !icon}
|
|
102
|
+
<span class="date-picker__icon date-picker__icon--trailing" aria-hidden="true">
|
|
103
|
+
<Icon src={IconCalendar} />
|
|
104
|
+
</span>
|
|
105
|
+
{/if}
|
|
106
|
+
</button>
|
|
107
|
+
{/snippet}
|
|
108
|
+
<Popover
|
|
109
|
+
bind:this={popover}
|
|
110
|
+
trigger={{ custom: triggerButton }}
|
|
111
|
+
panel={false}
|
|
112
|
+
keepOpen
|
|
113
|
+
disabled={disabled || readonly || inert}
|
|
114
|
+
on={{ opened: () => (open = true), closed: () => (open = false) }}>
|
|
115
|
+
<DatePickerCalendar
|
|
116
|
+
selectedDate={selectedDate}
|
|
117
|
+
minDate={minDate}
|
|
118
|
+
maxDate={maxDate}
|
|
119
|
+
locale={resolvedLocale}
|
|
120
|
+
firstDayOfWeek={resolvedFirstDayOfWeek}
|
|
121
|
+
on={{ select: handleSelect }} />
|
|
122
|
+
</Popover>
|
|
159
123
|
|
|
160
124
|
{#if name}
|
|
161
125
|
<input type="hidden" name={name} value={selectedDate ? selectedDate.toISOString() : ''} aria-required={ariaRequired ? 'true' : undefined} />
|
|
162
126
|
{/if}
|
|
163
|
-
|
|
164
|
-
{#if open}
|
|
165
|
-
<div bind:this={panelEl} class="date-picker__panel">
|
|
166
|
-
<DatePickerCalendar
|
|
167
|
-
selectedDate={selectedDate}
|
|
168
|
-
minDate={minDate}
|
|
169
|
-
maxDate={maxDate}
|
|
170
|
-
locale={resolvedLocale}
|
|
171
|
-
firstDayOfWeek={resolvedFirstDayOfWeek}
|
|
172
|
-
on={{ select: handleSelect }} />
|
|
173
|
-
</div>
|
|
174
|
-
{/if}
|
|
175
127
|
</div>
|
|
176
128
|
|
|
177
129
|
<!--
|
|
178
130
|
@component
|
|
179
|
-
DatePicker — single-day calendar picker
|
|
131
|
+
DatePicker — single-day calendar picker whose calendar opens in a `Popover`. Discriminated by
|
|
180
132
|
`clearable`: `clearable: true` allows clearing to `null` and shows a clear (X) button;
|
|
181
133
|
`clearable: false` requires a value and renders no clear control. Emits ISO 8601 strings via
|
|
182
134
|
`on.change` from local midnight of the picked day.
|
|
@@ -204,6 +156,7 @@ DatePicker — single-day calendar picker built on Floating UI for positioning.
|
|
|
204
156
|
|
|
205
157
|
<style>@charset "UTF-8";
|
|
206
158
|
.date-picker {
|
|
159
|
+
--sc-kit--popover--width: 100%;
|
|
207
160
|
/* TRIGGER — public CSS API resolved with defaults (this block IS the API documentation) */
|
|
208
161
|
--_dp--height: var(--sc-kit--date-picker--height, var(--_dp--size-height, var(--sc-kit--field--height--md)));
|
|
209
162
|
--_dp--padding-inline: var(--sc-kit--date-picker--padding-inline, var(--_dp--size-padding-inline, var(--sc-kit--field--padding-inline--md)));
|
|
@@ -345,7 +298,4 @@ DatePicker — single-day calendar picker built on Floating UI for positioning.
|
|
|
345
298
|
}
|
|
346
299
|
.date-picker__icon--trailing {
|
|
347
300
|
margin-inline-start: var(--_dp--gap);
|
|
348
|
-
}
|
|
349
|
-
.date-picker__panel {
|
|
350
|
-
z-index: var(--sc-kit--z-index--popover);
|
|
351
301
|
}</style>
|