a11y-elements 0.2.0 → 0.3.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/README.md +259 -16
- package/dist/a11y.css +200 -0
- package/dist/browser/components/anchor/define.js +13 -1
- package/dist/browser/components/anchor/define.js.map +1 -1
- package/dist/browser/components/avatar/define.js +13 -1
- package/dist/browser/components/avatar/define.js.map +1 -1
- package/dist/browser/components/checkbox/define.js +13 -1
- package/dist/browser/components/checkbox/define.js.map +1 -1
- package/dist/browser/components/checkbox-group/define.js +394 -0
- package/dist/browser/components/checkbox-group/define.js.map +1 -0
- package/dist/browser/components/file-input/define.js +1069 -0
- package/dist/browser/components/file-input/define.js.map +1 -0
- package/dist/browser/components/focusable/define.js +13 -1
- package/dist/browser/components/focusable/define.js.map +1 -1
- package/dist/browser/components/input/define.js +34 -6
- package/dist/browser/components/input/define.js.map +1 -1
- package/dist/browser/components/label/define.js +13 -1
- package/dist/browser/components/label/define.js.map +1 -1
- package/dist/browser/components/picture/define.js +171 -3
- package/dist/browser/components/picture/define.js.map +1 -1
- package/dist/browser/components/progress/define.js +13 -1
- package/dist/browser/components/progress/define.js.map +1 -1
- package/dist/browser/components/radio-group/define.js +15 -1
- package/dist/browser/components/radio-group/define.js.map +1 -1
- package/dist/browser/components/select/define.js +13 -1
- package/dist/browser/components/select/define.js.map +1 -1
- package/dist/browser/components/skeleton/define.js +13 -1
- package/dist/browser/components/skeleton/define.js.map +1 -1
- package/dist/browser/components/spinner/define.js +13 -1
- package/dist/browser/components/spinner/define.js.map +1 -1
- package/dist/browser/components/switch/define.js +13 -1
- package/dist/browser/components/switch/define.js.map +1 -1
- package/dist/browser/components/textarea/define.js +34 -6
- package/dist/browser/components/textarea/define.js.map +1 -1
- package/dist/browser/components/visually-hidden/define.js +13 -1
- package/dist/browser/components/visually-hidden/define.js.map +1 -1
- package/dist/browser/overlays/blocking-loader/define.js +13 -1
- package/dist/browser/overlays/blocking-loader/define.js.map +1 -1
- package/dist/browser/overlays/context-menu/define.js +19 -3
- package/dist/browser/overlays/context-menu/define.js.map +1 -1
- package/dist/browser/overlays/drawer/define.js +18 -2
- package/dist/browser/overlays/drawer/define.js.map +1 -1
- package/dist/browser/overlays/dropdown/define.js +19 -3
- package/dist/browser/overlays/dropdown/define.js.map +1 -1
- package/dist/browser/overlays/emergency-dialog/define.js +18 -2
- package/dist/browser/overlays/emergency-dialog/define.js.map +1 -1
- package/dist/browser/overlays/modal/define.js +18 -2
- package/dist/browser/overlays/modal/define.js.map +1 -1
- package/dist/browser/overlays/notification-banner/define.js +13 -1
- package/dist/browser/overlays/notification-banner/define.js.map +1 -1
- package/dist/browser/overlays/popover/define.js +18 -2
- package/dist/browser/overlays/popover/define.js.map +1 -1
- package/dist/browser/overlays/snackbar/define.js +13 -1
- package/dist/browser/overlays/snackbar/define.js.map +1 -1
- package/dist/browser/overlays/tooltip/define.js +18 -2
- package/dist/browser/overlays/tooltip/define.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.element.d.ts +51 -0
- package/dist/components/checkbox-group/checkbox-group.element.js +189 -0
- package/dist/components/checkbox-group/checkbox-group.element.js.map +1 -0
- package/dist/components/checkbox-group/define.d.ts +8 -0
- package/dist/components/checkbox-group/define.js +8 -0
- package/dist/components/checkbox-group/define.js.map +1 -0
- package/dist/components/file-input/define.d.ts +9 -0
- package/dist/components/file-input/define.js +9 -0
- package/dist/components/file-input/define.js.map +1 -0
- package/dist/components/file-input/file-input.element.d.ts +95 -0
- package/dist/components/file-input/file-input.element.js +471 -0
- package/dist/components/file-input/file-input.element.js.map +1 -0
- package/dist/components/label/label.element.d.ts +1 -1
- package/dist/components/label/label.element.js +1 -1
- package/dist/components/picture/define.d.ts +1 -0
- package/dist/components/picture/define.js.map +1 -1
- package/dist/components/picture/picture.element.d.ts +72 -6
- package/dist/components/picture/picture.element.js +201 -9
- package/dist/components/picture/picture.element.js.map +1 -1
- package/dist/components/radio-group/radio-group.element.js +4 -0
- package/dist/components/radio-group/radio-group.element.js.map +1 -1
- package/dist/core/a11y-field-element.d.ts +17 -7
- package/dist/core/a11y-field-element.js +25 -5
- package/dist/core/a11y-field-element.js.map +1 -1
- package/dist/core/focus-trap.d.ts +8 -0
- package/dist/core/focus-trap.js +13 -1
- package/dist/core/focus-trap.js.map +1 -1
- package/dist/core/strings.d.ts +24 -0
- package/dist/core/strings.js +12 -0
- package/dist/core/strings.js.map +1 -1
- package/dist/overlays/core/a11y-menu-overlay-element.js +2 -2
- package/dist/overlays/core/a11y-menu-overlay-element.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox-group.element.js","sourceRoot":"","sources":["../../../src/components/checkbox-group/checkbox-group.element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,MAAM,sBAAsB,GAAG,uCAAuC,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1D,MAAM,KAAK,kBAAkB;QAC3B,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAChF,CAAC;IAKD,kGAAkG;IAC1F,aAAa,GAAG,KAAK,CAAC;IAE9B,QAAQ;QACN,OAAO,IAAI,CAAC,QAAQ,EAAE;aACnB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;aAChC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,mFAAmF;IACnF,QAAQ,CAAC,MAAgB;QACvB,KAAK,MAAM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,CAAC;YACT,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC7B,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CheckboxGroupElement } from './checkbox-group.element.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
'a11y-checkbox-group': CheckboxGroupElement;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export { CheckboxGroupElement };
|
|
8
|
+
export { resetStrings, setStrings } from '../../core/strings.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CheckboxGroupElement } from './checkbox-group.element.js';
|
|
2
|
+
if (!customElements.get('a11y-checkbox-group')) {
|
|
3
|
+
customElements.define('a11y-checkbox-group', CheckboxGroupElement);
|
|
4
|
+
}
|
|
5
|
+
export { CheckboxGroupElement };
|
|
6
|
+
// Re-exported so zero-build `<script type="module">` users can reach them too.
|
|
7
|
+
export { resetStrings, setStrings } from '../../core/strings.js';
|
|
8
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/components/checkbox-group/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC;IAC/C,cAAc,CAAC,MAAM,CAAC,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;AACrE,CAAC;AAQD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,+EAA+E;AAC/E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FileInputElement } from './file-input.element.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
'a11y-file-input': FileInputElement;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export { FileInputElement };
|
|
8
|
+
export { bindField } from '../../core/field.js';
|
|
9
|
+
export { resetStrings, setStrings } from '../../core/strings.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FileInputElement } from './file-input.element.js';
|
|
2
|
+
if (!customElements.get('a11y-file-input')) {
|
|
3
|
+
customElements.define('a11y-file-input', FileInputElement);
|
|
4
|
+
}
|
|
5
|
+
export { FileInputElement };
|
|
6
|
+
// Re-exported so zero-build `<script type="module">` users can reach them too.
|
|
7
|
+
export { bindField } from '../../core/field.js';
|
|
8
|
+
export { resetStrings, setStrings } from '../../core/strings.js';
|
|
9
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/components/file-input/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAC3C,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AAC7D,CAAC;AAQD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAC5B,+EAA+E;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { A11yFieldElement } from '../../core/a11y-field-element.js';
|
|
2
|
+
import type { FieldControl } from '../../core/field.js';
|
|
3
|
+
/**
|
|
4
|
+
* A file picker built from a real `<input type="file">`, with the same
|
|
5
|
+
* optional parts as `<a11y-input>` (`<a11y-label>`, `<a11y-hint>`,
|
|
6
|
+
* `<a11y-error>`). Files can be browsed for or dragged onto the element.
|
|
7
|
+
*
|
|
8
|
+
* ```html
|
|
9
|
+
* <a11y-file-input max-size="5MB" max-files="3" previews>
|
|
10
|
+
* <a11y-label>Attachments</a11y-label>
|
|
11
|
+
* <input type="file" name="attachments" multiple accept=".pdf,image/*" required>
|
|
12
|
+
* <a11y-hint>PDF or images, up to 5 MB each.</a11y-hint>
|
|
13
|
+
* <a11y-error></a11y-error>
|
|
14
|
+
* </a11y-file-input>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* The native input stays the focusable control: it's only visually hidden,
|
|
18
|
+
* so it keeps its role, `required`, validity and the field's ARIA. It's
|
|
19
|
+
* joined by generated markup:
|
|
20
|
+
*
|
|
21
|
+
* - a drop zone holding a `<label for>` styled as a "Browse files" button,
|
|
22
|
+
* which opens the picker natively and adds its text to the input's
|
|
23
|
+
* accessible name (so voice control users can say it);
|
|
24
|
+
* - the list of selected files, each with a "Remove" button named after
|
|
25
|
+
* its file;
|
|
26
|
+
* - a list of the files that weren't added, and why;
|
|
27
|
+
* - a polite status region announcing what was added, removed or rejected.
|
|
28
|
+
*
|
|
29
|
+
* Dragging is only a shortcut: everything works from the keyboard. With
|
|
30
|
+
* `multiple`, browsing or dropping again adds to the selection instead of
|
|
31
|
+
* replacing it. Files that fail `accept`, `max-size` or `max-files` are never
|
|
32
|
+
* added (the browser doesn't check `accept` on drop), so those rules can't
|
|
33
|
+
* make the field invalid; `required` and `validators` still can.
|
|
34
|
+
*
|
|
35
|
+
* The selection is written back to `input.files`, so the input submits it
|
|
36
|
+
* with the form like any file input.
|
|
37
|
+
*/
|
|
38
|
+
export declare class FileInputElement extends A11yFieldElement<File[]> {
|
|
39
|
+
static get observedAttributes(): string[];
|
|
40
|
+
protected readonly controlSelector = "input[type=\"file\"]";
|
|
41
|
+
private _files;
|
|
42
|
+
/** The control `_files` was last read from — a new one brings its own files. */
|
|
43
|
+
private _filesControl;
|
|
44
|
+
private _previewUrls;
|
|
45
|
+
/** Set while this element fires `input`/`change` itself, so it doesn't take them for a new pick. */
|
|
46
|
+
private _committing;
|
|
47
|
+
/** `dragenter`s minus `dragleave`s, since both fire again for every child crossed. */
|
|
48
|
+
private _dragDepth;
|
|
49
|
+
/** Key for the host's own listeners in `wireOnce()`, which the field base already uses for the host. */
|
|
50
|
+
private readonly _hostKey;
|
|
51
|
+
/** Adds files as a drop would: checked against the rules, announced, and followed by `input`/`change` events. */
|
|
52
|
+
addFiles(files: Iterable<File>): void;
|
|
53
|
+
/** Removes a file, by reference or index. Silent, like `setValue()`: no events, no announcement. */
|
|
54
|
+
removeFile(file: File | number): void;
|
|
55
|
+
/** Removes every file. Silent, like `setValue()`. */
|
|
56
|
+
clear(): void;
|
|
57
|
+
formResetCallback(): void;
|
|
58
|
+
protected readValue(): File[];
|
|
59
|
+
/** Replaces the selection. Files the rules rule out are dropped, silently. */
|
|
60
|
+
protected writeValue(control: FieldControl, files: File[]): void;
|
|
61
|
+
protected onDisconnect(): void;
|
|
62
|
+
protected onStringsChange(): void;
|
|
63
|
+
protected _sync(): void;
|
|
64
|
+
private _fileControl;
|
|
65
|
+
private _generated;
|
|
66
|
+
private _removeButtons;
|
|
67
|
+
/** Builds the drop zone (right after the input) and the lists and status (last), moving them only when misplaced. */
|
|
68
|
+
private _syncUi;
|
|
69
|
+
/** A pick from the browser's dialog: merge it into the selection before anyone else reads the input. */
|
|
70
|
+
private _onNativePick;
|
|
71
|
+
private _onDrag;
|
|
72
|
+
private _onClick;
|
|
73
|
+
/** Adds files the user picked or dropped, then lists, announces and (for drops) fires `input`/`change`. */
|
|
74
|
+
private _addFromUser;
|
|
75
|
+
/**
|
|
76
|
+
* Checks `incoming` against `accept`, `max-size` and `max-files`. With
|
|
77
|
+
* `multiple`, new files join `current` (skipping ones already there);
|
|
78
|
+
* without, the first acceptable one replaces it — and if none is, `current`
|
|
79
|
+
* stays.
|
|
80
|
+
*/
|
|
81
|
+
private _intake;
|
|
82
|
+
private _afterSilentChange;
|
|
83
|
+
/** Writes the selection to `input.files`, so the form submits it and `required` sees it. */
|
|
84
|
+
private _commit;
|
|
85
|
+
private _dispatch;
|
|
86
|
+
private _renderList;
|
|
87
|
+
private _renderRejected;
|
|
88
|
+
private _announce;
|
|
89
|
+
private _setDragover;
|
|
90
|
+
private _lang;
|
|
91
|
+
}
|
|
92
|
+
/** `5MB`, `500 KB`, `1.5gb` or plain bytes (binary units) → bytes; anything else → no limit. */
|
|
93
|
+
export declare function parseSize(value: string | null): number | null;
|
|
94
|
+
/** A size in the largest fitting unit, localized with `Intl` (`1.5 MB`, `1,5 Mo`, …). */
|
|
95
|
+
export declare function formatSize(bytes: number, lang?: string): string;
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { A11yFieldElement } from '../../core/a11y-field-element.js';
|
|
2
|
+
import { syncAttr, syncText } from '../../core/dom-sync.js';
|
|
3
|
+
import { nextId } from '../../core/ids.js';
|
|
4
|
+
import { formatString, getString } from '../../core/strings.js';
|
|
5
|
+
/** Marks the markup this element builds, so the field never takes it for a consumer part. */
|
|
6
|
+
const GENERATED = 'data-a11y-generated';
|
|
7
|
+
const SIZE_UNITS = ['byte', 'kilobyte', 'megabyte', 'gigabyte'];
|
|
8
|
+
const SIZE_FACTORS = { b: 1, kb: 1024, mb: 1024 ** 2, gb: 1024 ** 3 };
|
|
9
|
+
/**
|
|
10
|
+
* A file picker built from a real `<input type="file">`, with the same
|
|
11
|
+
* optional parts as `<a11y-input>` (`<a11y-label>`, `<a11y-hint>`,
|
|
12
|
+
* `<a11y-error>`). Files can be browsed for or dragged onto the element.
|
|
13
|
+
*
|
|
14
|
+
* ```html
|
|
15
|
+
* <a11y-file-input max-size="5MB" max-files="3" previews>
|
|
16
|
+
* <a11y-label>Attachments</a11y-label>
|
|
17
|
+
* <input type="file" name="attachments" multiple accept=".pdf,image/*" required>
|
|
18
|
+
* <a11y-hint>PDF or images, up to 5 MB each.</a11y-hint>
|
|
19
|
+
* <a11y-error></a11y-error>
|
|
20
|
+
* </a11y-file-input>
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The native input stays the focusable control: it's only visually hidden,
|
|
24
|
+
* so it keeps its role, `required`, validity and the field's ARIA. It's
|
|
25
|
+
* joined by generated markup:
|
|
26
|
+
*
|
|
27
|
+
* - a drop zone holding a `<label for>` styled as a "Browse files" button,
|
|
28
|
+
* which opens the picker natively and adds its text to the input's
|
|
29
|
+
* accessible name (so voice control users can say it);
|
|
30
|
+
* - the list of selected files, each with a "Remove" button named after
|
|
31
|
+
* its file;
|
|
32
|
+
* - a list of the files that weren't added, and why;
|
|
33
|
+
* - a polite status region announcing what was added, removed or rejected.
|
|
34
|
+
*
|
|
35
|
+
* Dragging is only a shortcut: everything works from the keyboard. With
|
|
36
|
+
* `multiple`, browsing or dropping again adds to the selection instead of
|
|
37
|
+
* replacing it. Files that fail `accept`, `max-size` or `max-files` are never
|
|
38
|
+
* added (the browser doesn't check `accept` on drop), so those rules can't
|
|
39
|
+
* make the field invalid; `required` and `validators` still can.
|
|
40
|
+
*
|
|
41
|
+
* The selection is written back to `input.files`, so the input submits it
|
|
42
|
+
* with the form like any file input.
|
|
43
|
+
*/
|
|
44
|
+
export class FileInputElement extends A11yFieldElement {
|
|
45
|
+
static get observedAttributes() {
|
|
46
|
+
return [...super.observedAttributes, 'max-size', 'max-files', 'previews', 'browse-label', 'drop-label'];
|
|
47
|
+
}
|
|
48
|
+
controlSelector = 'input[type="file"]';
|
|
49
|
+
_files = [];
|
|
50
|
+
/** The control `_files` was last read from — a new one brings its own files. */
|
|
51
|
+
_filesControl = null;
|
|
52
|
+
_previewUrls = new Map();
|
|
53
|
+
/** Set while this element fires `input`/`change` itself, so it doesn't take them for a new pick. */
|
|
54
|
+
_committing = false;
|
|
55
|
+
/** `dragenter`s minus `dragleave`s, since both fire again for every child crossed. */
|
|
56
|
+
_dragDepth = 0;
|
|
57
|
+
/** Key for the host's own listeners in `wireOnce()`, which the field base already uses for the host. */
|
|
58
|
+
_hostKey = document.createComment('');
|
|
59
|
+
/** Adds files as a drop would: checked against the rules, announced, and followed by `input`/`change` events. */
|
|
60
|
+
addFiles(files) {
|
|
61
|
+
const control = this._fileControl();
|
|
62
|
+
if (control)
|
|
63
|
+
this._addFromUser(control, [...files], true);
|
|
64
|
+
}
|
|
65
|
+
/** Removes a file, by reference or index. Silent, like `setValue()`: no events, no announcement. */
|
|
66
|
+
removeFile(file) {
|
|
67
|
+
const index = typeof file === 'number' ? file : this._files.indexOf(file);
|
|
68
|
+
const control = this._fileControl();
|
|
69
|
+
if (!control || index < 0 || index >= this._files.length)
|
|
70
|
+
return;
|
|
71
|
+
this._files.splice(index, 1);
|
|
72
|
+
this._afterSilentChange(control);
|
|
73
|
+
}
|
|
74
|
+
/** Removes every file. Silent, like `setValue()`. */
|
|
75
|
+
clear() {
|
|
76
|
+
const control = this._fileControl();
|
|
77
|
+
if (!control)
|
|
78
|
+
return;
|
|
79
|
+
this._files = [];
|
|
80
|
+
this._afterSilentChange(control);
|
|
81
|
+
}
|
|
82
|
+
formResetCallback() {
|
|
83
|
+
super.formResetCallback();
|
|
84
|
+
// The form empties `input.files` itself; only this element's copy is left.
|
|
85
|
+
this._files = [];
|
|
86
|
+
this._renderList();
|
|
87
|
+
this._renderRejected([]);
|
|
88
|
+
const status = this._generated('status');
|
|
89
|
+
if (status)
|
|
90
|
+
syncText(status, '');
|
|
91
|
+
}
|
|
92
|
+
readValue() {
|
|
93
|
+
return [...this._files];
|
|
94
|
+
}
|
|
95
|
+
/** Replaces the selection. Files the rules rule out are dropped, silently. */
|
|
96
|
+
writeValue(control, files) {
|
|
97
|
+
this._files = this._intake(control, files, []).files;
|
|
98
|
+
this._commit(control);
|
|
99
|
+
this._renderList();
|
|
100
|
+
this._renderRejected([]);
|
|
101
|
+
}
|
|
102
|
+
onDisconnect() {
|
|
103
|
+
this._setDragover(false);
|
|
104
|
+
for (const url of this._previewUrls.values())
|
|
105
|
+
URL.revokeObjectURL(url);
|
|
106
|
+
this._previewUrls.clear();
|
|
107
|
+
// Previews are rebuilt on reconnect.
|
|
108
|
+
this._filesControl = null;
|
|
109
|
+
}
|
|
110
|
+
onStringsChange() {
|
|
111
|
+
this._sync(); // relabels the drop zone and re-links the field
|
|
112
|
+
this._renderList();
|
|
113
|
+
}
|
|
114
|
+
_sync() {
|
|
115
|
+
const control = this._fileControl();
|
|
116
|
+
if (control) {
|
|
117
|
+
this._syncUi(control);
|
|
118
|
+
if (this._filesControl !== control) {
|
|
119
|
+
this._filesControl = control;
|
|
120
|
+
this._files = [...(control.files ?? [])];
|
|
121
|
+
this._renderList();
|
|
122
|
+
}
|
|
123
|
+
const list = this._generated('list');
|
|
124
|
+
if (list && this.boolAttr('previews') !== list.hasAttribute('data-previews'))
|
|
125
|
+
this._renderList();
|
|
126
|
+
const disabled = control.matches(':disabled');
|
|
127
|
+
for (const button of this._removeButtons())
|
|
128
|
+
syncAttr(button, 'disabled', disabled ? '' : null);
|
|
129
|
+
}
|
|
130
|
+
this.wireOnce(this._hostKey, () => {
|
|
131
|
+
// Capture: runs before the field base's `onChange`/`onInput`, which then see the merged selection.
|
|
132
|
+
this.listen(this, 'input', (event) => this._onNativePick(event), true);
|
|
133
|
+
this.listen(this, 'change', (event) => this._onNativePick(event), true);
|
|
134
|
+
this.listen(this, 'dragenter', (event) => this._onDrag(event));
|
|
135
|
+
this.listen(this, 'dragover', (event) => this._onDrag(event));
|
|
136
|
+
this.listen(this, 'dragleave', (event) => this._onDrag(event));
|
|
137
|
+
this.listen(this, 'drop', (event) => this._onDrag(event));
|
|
138
|
+
this.listen(this, 'click', (event) => this._onClick(event));
|
|
139
|
+
});
|
|
140
|
+
super._sync();
|
|
141
|
+
}
|
|
142
|
+
_fileControl() {
|
|
143
|
+
return this._control();
|
|
144
|
+
}
|
|
145
|
+
_generated(name) {
|
|
146
|
+
return this.querySelector(`:scope > .a11y-file-input__${name}`);
|
|
147
|
+
}
|
|
148
|
+
_removeButtons() {
|
|
149
|
+
const list = this._generated('list');
|
|
150
|
+
return list ? [...list.querySelectorAll('.a11y-file-input__remove')] : [];
|
|
151
|
+
}
|
|
152
|
+
/** Builds the drop zone (right after the input) and the lists and status (last), moving them only when misplaced. */
|
|
153
|
+
_syncUi(control) {
|
|
154
|
+
if (!control.id)
|
|
155
|
+
control.id = nextId('a11y-field');
|
|
156
|
+
let dropzone = this._generated('dropzone');
|
|
157
|
+
if (!dropzone) {
|
|
158
|
+
dropzone = document.createElement('div');
|
|
159
|
+
dropzone.className = 'a11y-file-input__dropzone';
|
|
160
|
+
dropzone.setAttribute(GENERATED, '');
|
|
161
|
+
const button = document.createElement('label');
|
|
162
|
+
button.className = 'a11y-file-input__button';
|
|
163
|
+
const prompt = document.createElement('span');
|
|
164
|
+
prompt.className = 'a11y-file-input__prompt';
|
|
165
|
+
// A pointer-only instruction: keyboard and screen reader users browse instead.
|
|
166
|
+
prompt.setAttribute('aria-hidden', 'true');
|
|
167
|
+
dropzone.append(button, prompt);
|
|
168
|
+
}
|
|
169
|
+
if (control.nextElementSibling !== dropzone)
|
|
170
|
+
control.after(dropzone);
|
|
171
|
+
const button = dropzone.querySelector('.a11y-file-input__button');
|
|
172
|
+
syncAttr(button, 'for', control.id);
|
|
173
|
+
syncText(button, this.stringAttr('browse-label', getString('browseFiles')));
|
|
174
|
+
syncText(dropzone.querySelector('.a11y-file-input__prompt'), this.stringAttr('drop-label', getString('dropFiles')));
|
|
175
|
+
// After the consumer's parts, so the rejections sit right below the error.
|
|
176
|
+
const tail = ['rejected', 'list', 'status'].map((name) => {
|
|
177
|
+
const existing = this._generated(name);
|
|
178
|
+
if (existing)
|
|
179
|
+
return existing;
|
|
180
|
+
const el = document.createElement(name === 'status' ? 'div' : 'ul');
|
|
181
|
+
el.className = `a11y-file-input__${name}`;
|
|
182
|
+
el.setAttribute(GENERATED, '');
|
|
183
|
+
if (name === 'status')
|
|
184
|
+
el.setAttribute('role', 'status');
|
|
185
|
+
else
|
|
186
|
+
el.hidden = true;
|
|
187
|
+
return el;
|
|
188
|
+
});
|
|
189
|
+
const children = [...this.children];
|
|
190
|
+
if (tail.some((el, i) => children[children.length - tail.length + i] !== el))
|
|
191
|
+
this.append(...tail);
|
|
192
|
+
syncAttr(tail[1], 'aria-label', getString('selectedFiles'));
|
|
193
|
+
}
|
|
194
|
+
/** A pick from the browser's dialog: merge it into the selection before anyone else reads the input. */
|
|
195
|
+
_onNativePick(event) {
|
|
196
|
+
const control = this._fileControl();
|
|
197
|
+
if (this._committing || !control || event.target !== control)
|
|
198
|
+
return;
|
|
199
|
+
const picked = [...(control.files ?? [])];
|
|
200
|
+
// `input` and `change` both fire for one pick: the second finds it already merged.
|
|
201
|
+
if (sameFiles(picked, this._files))
|
|
202
|
+
return;
|
|
203
|
+
this._addFromUser(control, picked, false);
|
|
204
|
+
}
|
|
205
|
+
_onDrag(event) {
|
|
206
|
+
if (![...(event.dataTransfer?.types ?? [])].includes('Files'))
|
|
207
|
+
return;
|
|
208
|
+
const control = this._fileControl();
|
|
209
|
+
const enabled = !!control && !control.matches(':disabled');
|
|
210
|
+
switch (event.type) {
|
|
211
|
+
case 'dragenter':
|
|
212
|
+
if (!enabled)
|
|
213
|
+
return;
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
this._dragDepth++;
|
|
216
|
+
this._setDragover(true);
|
|
217
|
+
break;
|
|
218
|
+
case 'dragover':
|
|
219
|
+
if (!enabled)
|
|
220
|
+
return;
|
|
221
|
+
event.preventDefault(); // allows the drop
|
|
222
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
223
|
+
break;
|
|
224
|
+
case 'dragleave':
|
|
225
|
+
this._dragDepth = Math.max(0, this._dragDepth - 1);
|
|
226
|
+
if (this._dragDepth === 0)
|
|
227
|
+
this._setDragover(false);
|
|
228
|
+
break;
|
|
229
|
+
case 'drop':
|
|
230
|
+
event.preventDefault(); // never let the browser open the file instead
|
|
231
|
+
this._dragDepth = 0;
|
|
232
|
+
this._setDragover(false);
|
|
233
|
+
if (enabled)
|
|
234
|
+
this._addFromUser(control, [...(event.dataTransfer?.files ?? [])], true);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
_onClick(event) {
|
|
239
|
+
const button = event.target.closest?.('.a11y-file-input__remove');
|
|
240
|
+
const control = this._fileControl();
|
|
241
|
+
if (!button || !control || !this._generated('list')?.contains(button))
|
|
242
|
+
return;
|
|
243
|
+
const index = this._removeButtons().indexOf(button);
|
|
244
|
+
const [removed] = this._files.splice(index, 1);
|
|
245
|
+
if (!removed)
|
|
246
|
+
return;
|
|
247
|
+
this._commit(control);
|
|
248
|
+
this._renderList();
|
|
249
|
+
this._renderRejected([]);
|
|
250
|
+
this._announce([formatString(getString('fileRemoved'), { name: removed.name })]);
|
|
251
|
+
this._dispatch(control);
|
|
252
|
+
this.binding?.show();
|
|
253
|
+
// Never drop focus to <body>: the next file, else the previous one, else the input.
|
|
254
|
+
const buttons = this._removeButtons();
|
|
255
|
+
(buttons[index] ?? buttons[index - 1] ?? control).focus();
|
|
256
|
+
}
|
|
257
|
+
/** Adds files the user picked or dropped, then lists, announces and (for drops) fires `input`/`change`. */
|
|
258
|
+
_addFromUser(control, incoming, dispatch) {
|
|
259
|
+
const { files, added, rejected } = this._intake(control, incoming, this._files);
|
|
260
|
+
this._files = files;
|
|
261
|
+
this._commit(control);
|
|
262
|
+
this._renderList();
|
|
263
|
+
this._renderRejected(rejected);
|
|
264
|
+
const messages = [];
|
|
265
|
+
if (added.length === 1)
|
|
266
|
+
messages.push(formatString(getString('fileAdded'), { name: added[0].name }));
|
|
267
|
+
else if (added.length > 1)
|
|
268
|
+
messages.push(formatString(getString('filesAdded'), { count: String(added.length) }));
|
|
269
|
+
this._announce([...messages, ...rejected]);
|
|
270
|
+
if (dispatch) {
|
|
271
|
+
this._dispatch(control);
|
|
272
|
+
this.binding?.show();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Checks `incoming` against `accept`, `max-size` and `max-files`. With
|
|
277
|
+
* `multiple`, new files join `current` (skipping ones already there);
|
|
278
|
+
* without, the first acceptable one replaces it — and if none is, `current`
|
|
279
|
+
* stays.
|
|
280
|
+
*/
|
|
281
|
+
_intake(control, incoming, current) {
|
|
282
|
+
const multiple = control.multiple;
|
|
283
|
+
const maxFiles = multiple ? this.numberAttr('max-files', Infinity) : 1;
|
|
284
|
+
const maxSize = parseSize(this.getAttribute('max-size'));
|
|
285
|
+
const values = {
|
|
286
|
+
max: String(maxFiles),
|
|
287
|
+
maxSize: maxSize == null ? '' : formatSize(maxSize, this._lang()),
|
|
288
|
+
};
|
|
289
|
+
const files = multiple ? [...current] : [];
|
|
290
|
+
const added = [];
|
|
291
|
+
const rejected = [];
|
|
292
|
+
const reject = (key, attribute, file) => rejected.push(formatString(this.stringAttr(attribute, getString(key)), { ...values, name: file.name }));
|
|
293
|
+
for (const file of incoming) {
|
|
294
|
+
if (files.some((kept) => sameFile(kept, file)))
|
|
295
|
+
continue;
|
|
296
|
+
if (!matchesAccept(file, control.accept))
|
|
297
|
+
reject('fileTypeRejected', 'type-rejected-message', file);
|
|
298
|
+
else if (maxSize != null && file.size > maxSize)
|
|
299
|
+
reject('fileSizeRejected', 'size-rejected-message', file);
|
|
300
|
+
else if (files.length >= maxFiles)
|
|
301
|
+
reject('fileCountRejected', 'count-rejected-message', file);
|
|
302
|
+
else {
|
|
303
|
+
files.push(file);
|
|
304
|
+
added.push(file);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return { files: multiple || added.length ? files : [...current], added, rejected };
|
|
308
|
+
}
|
|
309
|
+
_afterSilentChange(control) {
|
|
310
|
+
this._commit(control);
|
|
311
|
+
this._renderList();
|
|
312
|
+
this._renderRejected([]);
|
|
313
|
+
this.binding?.validate();
|
|
314
|
+
}
|
|
315
|
+
/** Writes the selection to `input.files`, so the form submits it and `required` sees it. */
|
|
316
|
+
_commit(control) {
|
|
317
|
+
if (typeof DataTransfer === 'undefined')
|
|
318
|
+
return;
|
|
319
|
+
const transfer = new DataTransfer();
|
|
320
|
+
for (const file of this._files)
|
|
321
|
+
transfer.items.add(file);
|
|
322
|
+
control.files = transfer.files;
|
|
323
|
+
}
|
|
324
|
+
_dispatch(control) {
|
|
325
|
+
this._committing = true;
|
|
326
|
+
try {
|
|
327
|
+
control.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
328
|
+
control.dispatchEvent(new Event('change', { bubbles: true }));
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
this._committing = false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
_renderList() {
|
|
335
|
+
const list = this._generated('list');
|
|
336
|
+
if (!list)
|
|
337
|
+
return;
|
|
338
|
+
const previews = this.boolAttr('previews');
|
|
339
|
+
const disabled = !!this._fileControl()?.matches(':disabled');
|
|
340
|
+
const lang = this._lang();
|
|
341
|
+
for (const [file, url] of this._previewUrls) {
|
|
342
|
+
if (previews && this._files.includes(file))
|
|
343
|
+
continue;
|
|
344
|
+
URL.revokeObjectURL(url);
|
|
345
|
+
this._previewUrls.delete(file);
|
|
346
|
+
}
|
|
347
|
+
list.replaceChildren(...this._files.map((file) => {
|
|
348
|
+
const item = document.createElement('li');
|
|
349
|
+
item.className = 'a11y-file-input__item';
|
|
350
|
+
if (previews && file.type.startsWith('image/')) {
|
|
351
|
+
let url = this._previewUrls.get(file);
|
|
352
|
+
if (!url) {
|
|
353
|
+
url = URL.createObjectURL(file);
|
|
354
|
+
this._previewUrls.set(file, url);
|
|
355
|
+
}
|
|
356
|
+
const img = document.createElement('img');
|
|
357
|
+
img.className = 'a11y-file-input__preview';
|
|
358
|
+
img.alt = ''; // the name next to it already says what it is
|
|
359
|
+
img.src = url;
|
|
360
|
+
item.append(img);
|
|
361
|
+
}
|
|
362
|
+
const name = document.createElement('span');
|
|
363
|
+
name.className = 'a11y-file-input__name';
|
|
364
|
+
name.textContent = file.name;
|
|
365
|
+
const size = document.createElement('span');
|
|
366
|
+
size.className = 'a11y-file-input__size';
|
|
367
|
+
size.textContent = formatSize(file.size, lang);
|
|
368
|
+
const remove = document.createElement('button');
|
|
369
|
+
remove.type = 'button';
|
|
370
|
+
remove.className = 'a11y-file-input__remove';
|
|
371
|
+
remove.textContent = getString('remove');
|
|
372
|
+
// Starts with the visible text, so voice control's "click Remove" still matches.
|
|
373
|
+
remove.setAttribute('aria-label', formatString(getString('removeFile'), { name: file.name }));
|
|
374
|
+
remove.disabled = disabled;
|
|
375
|
+
item.append(name, size, remove);
|
|
376
|
+
return item;
|
|
377
|
+
}));
|
|
378
|
+
syncAttr(list, 'data-previews', previews ? '' : null);
|
|
379
|
+
syncAttr(list, 'hidden', this._files.length ? null : '');
|
|
380
|
+
}
|
|
381
|
+
_renderRejected(messages) {
|
|
382
|
+
const list = this._generated('rejected');
|
|
383
|
+
if (!list)
|
|
384
|
+
return;
|
|
385
|
+
if (messages.length || list.childElementCount) {
|
|
386
|
+
list.replaceChildren(...messages.map((message) => {
|
|
387
|
+
const item = document.createElement('li');
|
|
388
|
+
item.textContent = message;
|
|
389
|
+
return item;
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
syncAttr(list, 'hidden', messages.length ? null : '');
|
|
393
|
+
}
|
|
394
|
+
_announce(messages) {
|
|
395
|
+
const status = this._generated('status');
|
|
396
|
+
if (status && messages.length)
|
|
397
|
+
status.textContent = messages.join('. ');
|
|
398
|
+
}
|
|
399
|
+
_setDragover(on) {
|
|
400
|
+
const dropzone = this._generated('dropzone');
|
|
401
|
+
if (dropzone)
|
|
402
|
+
syncAttr(dropzone, 'data-dragover', on ? '' : null);
|
|
403
|
+
if (!on)
|
|
404
|
+
this._dragDepth = 0;
|
|
405
|
+
try {
|
|
406
|
+
if (on)
|
|
407
|
+
this.internals.states?.add('dragover');
|
|
408
|
+
else
|
|
409
|
+
this.internals.states?.delete('dragover');
|
|
410
|
+
}
|
|
411
|
+
catch {
|
|
412
|
+
// Older Chromium only accepted `--dashed` state names.
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
_lang() {
|
|
416
|
+
return this.closest('[lang]')?.getAttribute('lang') || undefined;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function sameFile(a, b) {
|
|
420
|
+
return a === b || (a.name === b.name && a.size === b.size && a.lastModified === b.lastModified && a.type === b.type);
|
|
421
|
+
}
|
|
422
|
+
function sameFiles(a, b) {
|
|
423
|
+
return a.length === b.length && a.every((file, i) => sameFile(file, b[i]));
|
|
424
|
+
}
|
|
425
|
+
/** The `accept` attribute's rules: `.ext`, `type/*` or an exact MIME type. Empty accepts everything. */
|
|
426
|
+
function matchesAccept(file, accept) {
|
|
427
|
+
const rules = accept
|
|
428
|
+
.split(',')
|
|
429
|
+
.map((rule) => rule.trim().toLowerCase())
|
|
430
|
+
.filter(Boolean);
|
|
431
|
+
if (!rules.length)
|
|
432
|
+
return true;
|
|
433
|
+
const name = file.name.toLowerCase();
|
|
434
|
+
const type = file.type.toLowerCase();
|
|
435
|
+
return rules.some((rule) => {
|
|
436
|
+
if (rule.startsWith('.'))
|
|
437
|
+
return name.endsWith(rule);
|
|
438
|
+
if (rule.endsWith('/*'))
|
|
439
|
+
return type.startsWith(rule.slice(0, -1));
|
|
440
|
+
return type === rule;
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/** `5MB`, `500 KB`, `1.5gb` or plain bytes (binary units) → bytes; anything else → no limit. */
|
|
444
|
+
export function parseSize(value) {
|
|
445
|
+
const match = value?.trim().match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?$/i);
|
|
446
|
+
if (!match)
|
|
447
|
+
return null;
|
|
448
|
+
return Math.round(Number(match[1]) * SIZE_FACTORS[(match[2] ?? 'b').toLowerCase()]);
|
|
449
|
+
}
|
|
450
|
+
/** A size in the largest fitting unit, localized with `Intl` (`1.5 MB`, `1,5 Mo`, …). */
|
|
451
|
+
export function formatSize(bytes, lang) {
|
|
452
|
+
let value = bytes;
|
|
453
|
+
let unit = 0;
|
|
454
|
+
while (value >= 1024 && unit < SIZE_UNITS.length - 1) {
|
|
455
|
+
value /= 1024;
|
|
456
|
+
unit++;
|
|
457
|
+
}
|
|
458
|
+
const options = {
|
|
459
|
+
style: 'unit',
|
|
460
|
+
unit: SIZE_UNITS[unit],
|
|
461
|
+
unitDisplay: unit === 0 ? 'long' : 'short', // "3 bytes", but "1.5 MB"
|
|
462
|
+
maximumFractionDigits: unit === 0 ? 0 : 1,
|
|
463
|
+
};
|
|
464
|
+
try {
|
|
465
|
+
return new Intl.NumberFormat(lang, options).format(value);
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
return new Intl.NumberFormat(undefined, options).format(value); // an invalid `lang`
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
//# sourceMappingURL=file-input.element.js.map
|