ember-aria-voyager 0.2.4 → 1.0.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 +203 -3
- package/dist/aria-tablist-Bpm0pW99.d.cts +198 -0
- package/dist/aria-tablist-ZH-aeJQW.d.mts +198 -0
- package/dist/index.cjs +422 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +410 -0
- package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
- package/dist/template-registry.cjs +0 -0
- package/dist/template-registry.d.cts +11 -0
- package/dist/template-registry.d.mts +12 -0
- package/dist/template-registry.mjs +1 -0
- package/dist/test-support/index.cjs +527 -0
- package/dist/test-support/index.d.cts +36 -0
- package/dist/test-support/index.d.mts +36 -0
- package/dist/test-support/index.mjs +512 -0
- package/package.json +86 -71
- package/declarations/index.d.ts +0 -12
- package/declarations/index.d.ts.map +0 -1
- package/declarations/modifiers/-emitter.d.ts +0 -28
- package/declarations/modifiers/-emitter.d.ts.map +0 -1
- package/declarations/modifiers/aria-listbox.d.ts +0 -25
- package/declarations/modifiers/aria-listbox.d.ts.map +0 -1
- package/declarations/modifiers/aria-menu.d.ts +0 -23
- package/declarations/modifiers/aria-menu.d.ts.map +0 -1
- package/declarations/modifiers/aria-tablist.d.ts +0 -28
- package/declarations/modifiers/aria-tablist.d.ts.map +0 -1
- package/declarations/template-registry.d.ts +0 -9
- package/declarations/template-registry.d.ts.map +0 -1
- package/declarations/test-support/-private/-get-description.d.ts +0 -11
- package/declarations/test-support/-private/-get-description.d.ts.map +0 -1
- package/declarations/test-support/-private/-get-element.d.ts +0 -11
- package/declarations/test-support/-private/-get-element.d.ts.map +0 -1
- package/declarations/test-support/-private/-get-elements.d.ts +0 -5
- package/declarations/test-support/-private/-get-elements.d.ts.map +0 -1
- package/declarations/test-support/-private/-target.d.ts +0 -9
- package/declarations/test-support/-private/-target.d.ts.map +0 -1
- package/declarations/test-support/-private/composite.d.ts +0 -2
- package/declarations/test-support/-private/composite.d.ts.map +0 -1
- package/declarations/test-support/-private/list.d.ts +0 -36
- package/declarations/test-support/-private/list.d.ts.map +0 -1
- package/declarations/test-support/-private/selection.d.ts +0 -18
- package/declarations/test-support/-private/selection.d.ts.map +0 -1
- package/declarations/test-support/index.d.ts +0 -4
- package/declarations/test-support/index.d.ts.map +0 -1
- package/declarations/test-support/listbox.d.ts +0 -13
- package/declarations/test-support/listbox.d.ts.map +0 -1
- package/declarations/test-support/menu.d.ts +0 -9
- package/declarations/test-support/menu.d.ts.map +0 -1
- package/declarations/test-support/tablist.d.ts +0 -13
- package/declarations/test-support/tablist.d.ts.map +0 -1
- package/dist/-emitter-CQPiyyOK.js +0 -47
- package/dist/-emitter-CQPiyyOK.js.map +0 -1
- package/dist/_app_/modifiers/aria-listbox.js +0 -1
- package/dist/_app_/modifiers/aria-menu.js +0 -1
- package/dist/_app_/modifiers/aria-tablist.js +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/modifiers/aria-listbox.js +0 -61
- package/dist/modifiers/aria-listbox.js.map +0 -1
- package/dist/modifiers/aria-menu.js +0 -42
- package/dist/modifiers/aria-menu.js.map +0 -1
- package/dist/modifiers/aria-tablist.js +0 -65
- package/dist/modifiers/aria-tablist.js.map +0 -1
- package/dist/template-registry.js +0 -2
- package/dist/template-registry.js.map +0 -1
- package/dist/test-support/index.js +0 -810
- package/dist/test-support/index.js.map +0 -1
- /package/{addon-main.js → addon-main.cjs} +0 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ember-aria-voyager
|
|
2
2
|
|
|
3
|
-
[](https://qlty.sh/gh/hokulea/projects/aria-voyager)
|
|
4
|
+
[](https://qlty.sh/gh/hokulea/projects/aria-voyager)
|
|
5
5
|
|
|
6
6
|
_Canoe vessel that navigates your aria._
|
|
7
7
|
|
|
@@ -26,6 +26,57 @@ pnpm add ember-aria-voyager
|
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
|
+
### `{{ariaGroup}}`
|
|
30
|
+
|
|
31
|
+
Basic example:
|
|
32
|
+
|
|
33
|
+
```glimmer-ts
|
|
34
|
+
import { ariaGroup } from 'ember-aria-voyager';
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<div role="group" {{ariaGroup}}>
|
|
38
|
+
<button type="button">Cut</button>
|
|
39
|
+
<button type="button">Copy</button>
|
|
40
|
+
<button type="button">Paste</button>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Here are the options, you can pass to `{{ariaGroup}}`
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
interface GroupSignature<T> {
|
|
49
|
+
Element: HTMLElement;
|
|
50
|
+
Args: {
|
|
51
|
+
Positional: [];
|
|
52
|
+
Named: {
|
|
53
|
+
items?: T[];
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Full example with reactive items:
|
|
61
|
+
|
|
62
|
+
```glimmer-ts
|
|
63
|
+
import { ariaGroup } from 'ember-aria-voyager';
|
|
64
|
+
import { tracked } from '@glimmer/tracking';
|
|
65
|
+
|
|
66
|
+
const context = new class {
|
|
67
|
+
@tracked items = ['Cut', 'Copy', 'Paste'];
|
|
68
|
+
@tracked disabled = false;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
<template>
|
|
72
|
+
<div role="group" {{ariaGroup items=context.items disabled=context.disabled}}>
|
|
73
|
+
{{#each context.items as |item|}}
|
|
74
|
+
<button type="button">{{item}}</button>
|
|
75
|
+
{{/each}}
|
|
76
|
+
</div>
|
|
77
|
+
</template>
|
|
78
|
+
```
|
|
79
|
+
|
|
29
80
|
### `{{ariaListbox}}`
|
|
30
81
|
|
|
31
82
|
Basic example:
|
|
@@ -118,9 +169,11 @@ import { ariaMenu } from 'ember-aria-voyager';
|
|
|
118
169
|
Here are the options, you can pass to `{{ariaMenu}}`
|
|
119
170
|
|
|
120
171
|
```ts
|
|
121
|
-
interface
|
|
172
|
+
interface MenuOptions<T> {
|
|
122
173
|
items?: T[];
|
|
123
174
|
disabled?: boolean;
|
|
175
|
+
select?: (selection: HTMLElement[]) => void;
|
|
176
|
+
check?: (selection: HTMLElement[]) => void;
|
|
124
177
|
}
|
|
125
178
|
```
|
|
126
179
|
|
|
@@ -154,6 +207,86 @@ const items = [
|
|
|
154
207
|
</template>
|
|
155
208
|
```
|
|
156
209
|
|
|
210
|
+
#### `menuitemcheckbox`
|
|
211
|
+
|
|
212
|
+
Menu supports checking items.
|
|
213
|
+
|
|
214
|
+
```glimmer-js
|
|
215
|
+
import { ariaMenu } from 'ember-aria-voyager';
|
|
216
|
+
|
|
217
|
+
function check(selection: HTMLElement[]) {
|
|
218
|
+
console.log('checked items:', selection);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
<template>
|
|
222
|
+
<div role="menu" {{ariaMenu check=check}}>
|
|
223
|
+
<span role="menuitemcheckbox">Bold</span>
|
|
224
|
+
<span role="menuitemcheckbox">Italic</span>
|
|
225
|
+
<span role="menuitemcheckbox">Underline</span>
|
|
226
|
+
<span role="menuitemcheckbox">Strikethrough</span>
|
|
227
|
+
</div>
|
|
228
|
+
</template>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### `menuitemradio`
|
|
232
|
+
|
|
233
|
+
Menu supports radio selection.
|
|
234
|
+
The `role="menu"` itself acts as group within one of all radio items is checked.
|
|
235
|
+
|
|
236
|
+
Here is a minimal example:
|
|
237
|
+
|
|
238
|
+
```glimmer-js
|
|
239
|
+
import { ariaMenu } from 'ember-aria-voyager';
|
|
240
|
+
|
|
241
|
+
function select(selection: HTMLElement[]) {
|
|
242
|
+
console.log('selected items:', selection);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
<template>
|
|
246
|
+
<div role="menu" {{ariaMenu select=select}}>
|
|
247
|
+
<span role="menuitemradio">Left</span>
|
|
248
|
+
<span role="menuitemradio">Center</span>
|
|
249
|
+
<span role="menuitemradio">Right</span>
|
|
250
|
+
<span role="menuitemradio">Justified</span>
|
|
251
|
+
</div>
|
|
252
|
+
</template>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Though menus do support multiple groups of radio selection.
|
|
256
|
+
This is supported as well.
|
|
257
|
+
Here are all combinations:
|
|
258
|
+
|
|
259
|
+
```glimmer-js
|
|
260
|
+
import { ariaMenu } from 'ember-aria-voyager';
|
|
261
|
+
|
|
262
|
+
function select(selection: HTMLElement) {
|
|
263
|
+
console.log('selected items across all groups:', selection);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
<template>
|
|
267
|
+
<div role="menu" {{ariaMenu select=select}}>
|
|
268
|
+
<span role="menuitemradio">A</span>
|
|
269
|
+
<div role="group">
|
|
270
|
+
<span role="menuitemradio">B</span>
|
|
271
|
+
<span role="menuitemradio">C</span>
|
|
272
|
+
</div>
|
|
273
|
+
<span role="menuitemradio">D</span>
|
|
274
|
+
<div role="presentation">
|
|
275
|
+
<span role="menuitemradio">E</span>
|
|
276
|
+
<hr>
|
|
277
|
+
<span role="menuitemradio">F</span>
|
|
278
|
+
</div>
|
|
279
|
+
<span role="menuitemradio">G</span>
|
|
280
|
+
<span role="separator"></span>
|
|
281
|
+
<span role="menuitemradio">H</span>
|
|
282
|
+
</div>
|
|
283
|
+
</template>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
- B+C are one group
|
|
287
|
+
- All others are in their own respective group
|
|
288
|
+
- `select()` will return the selection across all groups
|
|
289
|
+
|
|
157
290
|
### `{{ariaTablist}}`
|
|
158
291
|
|
|
159
292
|
Basic example:
|
|
@@ -198,3 +331,70 @@ interface TablistSignature<T> {
|
|
|
198
331
|
```
|
|
199
332
|
|
|
200
333
|
When passing `items` the `select()` and `selection` can work off of your passed items, anyway will fall back to the HTMLElement
|
|
334
|
+
|
|
335
|
+
### `{{ariaRadioGroup}}`
|
|
336
|
+
|
|
337
|
+
Basic example:
|
|
338
|
+
|
|
339
|
+
```glimmer-ts
|
|
340
|
+
import { ariaRadioGroup } from 'ember-aria-voyager';
|
|
341
|
+
|
|
342
|
+
<template>
|
|
343
|
+
<div role="radiogroup" {{ariaRadioGroup}}>
|
|
344
|
+
<button type="button" role="radio" aria-checked="false">Top</button>
|
|
345
|
+
<button type="button" role="radio" aria-checked="false">Bottom</button>
|
|
346
|
+
<button type="button" role="radio" aria-checked="false">Left</button>
|
|
347
|
+
</div>
|
|
348
|
+
</template>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Here are the options, you can pass to `{{ariaRadioGroup}}`
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
interface RadioGroupSignature<T> {
|
|
355
|
+
Element: HTMLElement;
|
|
356
|
+
Args: {
|
|
357
|
+
Positional: [];
|
|
358
|
+
Named: {
|
|
359
|
+
items?: T[];
|
|
360
|
+
select?: (selection: HTMLElement) => void;
|
|
361
|
+
disabled?: boolean;
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Full example with selection callback:
|
|
368
|
+
|
|
369
|
+
```glimmer-ts
|
|
370
|
+
import { ariaRadioGroup } from 'ember-aria-voyager';
|
|
371
|
+
import { tracked } from '@glimmer/tracking';
|
|
372
|
+
|
|
373
|
+
const context = new class {
|
|
374
|
+
@tracked selected?: HTMLElement;
|
|
375
|
+
|
|
376
|
+
select = (item: HTMLElement) => {
|
|
377
|
+
this.selected = item;
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
<template>
|
|
382
|
+
<div role="radiogroup" {{ariaRadioGroup select=context.select}}>
|
|
383
|
+
<button type="button" role="radio" aria-checked="false">Top</button>
|
|
384
|
+
<button type="button" role="radio" aria-checked="false">Bottom</button>
|
|
385
|
+
<button type="button" role="radio" aria-checked="false">Left</button>
|
|
386
|
+
</div>
|
|
387
|
+
</template>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Use in Classic Apps
|
|
391
|
+
|
|
392
|
+
`ember-aria-voyager` is primed to be used with polaris edition of ember using
|
|
393
|
+
imports. Classic v1 addons and v2 addons with compat automatically provide
|
|
394
|
+
re-exports, which this addon does not. Re-export it manually. Here is an example
|
|
395
|
+
for `ariaListbox`:
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
// app/modifiers/aria-listbox.js
|
|
399
|
+
export { ariaListbox as default } from 'ember-aria-voyager';
|
|
400
|
+
```
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import Modifier, { ArgsFor, NamedArgs, PositionalArgs } from "ember-modifier";
|
|
2
|
+
import Owner from "@ember/owner";
|
|
3
|
+
import { Orientation, TablistBehavior } from "aria-voyager";
|
|
4
|
+
|
|
5
|
+
//#region src/modifiers/aria-group.d.ts
|
|
6
|
+
interface GroupSignature<T> {
|
|
7
|
+
Element: HTMLElement;
|
|
8
|
+
Args: {
|
|
9
|
+
Positional: [];
|
|
10
|
+
Named: {
|
|
11
|
+
items?: T[];
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare class GroupModifier<T> extends Modifier<GroupSignature<T>> {
|
|
17
|
+
private group?;
|
|
18
|
+
private updater;
|
|
19
|
+
private emitter;
|
|
20
|
+
private prevItems?;
|
|
21
|
+
private prevDisabled?;
|
|
22
|
+
constructor(owner: Owner, args: ArgsFor<GroupSignature<T>>);
|
|
23
|
+
modify(element: Element, _: PositionalArgs<GroupSignature<T>>, options: NamedArgs<GroupSignature<T>>): void;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/simplify.d.ts
|
|
27
|
+
/**
|
|
28
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
29
|
+
|
|
30
|
+
@example
|
|
31
|
+
```
|
|
32
|
+
import type {Simplify} from 'type-fest';
|
|
33
|
+
|
|
34
|
+
type PositionProps = {
|
|
35
|
+
top: number;
|
|
36
|
+
left: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type SizeProps = {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
45
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
49
|
+
|
|
50
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
51
|
+
|
|
52
|
+
@example
|
|
53
|
+
```
|
|
54
|
+
import type {Simplify} from 'type-fest';
|
|
55
|
+
|
|
56
|
+
interface SomeInterface {
|
|
57
|
+
foo: number;
|
|
58
|
+
bar?: string;
|
|
59
|
+
baz: number | undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type SomeType = {
|
|
63
|
+
foo: number;
|
|
64
|
+
bar?: string;
|
|
65
|
+
baz: number | undefined;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
69
|
+
const someType: SomeType = literal;
|
|
70
|
+
const someInterface: SomeInterface = literal;
|
|
71
|
+
|
|
72
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
73
|
+
|
|
74
|
+
fn(literal); // Good: literal object type is sealed
|
|
75
|
+
fn(someType); // Good: type is sealed
|
|
76
|
+
// @ts-expect-error
|
|
77
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
78
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
82
|
+
@see {@link SimplifyDeep}
|
|
83
|
+
@category Object
|
|
84
|
+
*/
|
|
85
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/modifiers/-emitter.d.ts
|
|
88
|
+
type Items<T> = {
|
|
89
|
+
items: T[];
|
|
90
|
+
};
|
|
91
|
+
type ActivateHandler<T> = {
|
|
92
|
+
activateItem?: (item: T) => void;
|
|
93
|
+
};
|
|
94
|
+
type CheckHandler<T> = {
|
|
95
|
+
check?: (selection: T[]) => void;
|
|
96
|
+
};
|
|
97
|
+
type SingleSelectionHandler<T> = {
|
|
98
|
+
multi?: false;
|
|
99
|
+
selection?: T;
|
|
100
|
+
select?: (selection: T) => void;
|
|
101
|
+
};
|
|
102
|
+
type MultiSelectionHandler<T> = {
|
|
103
|
+
multi: true;
|
|
104
|
+
selection?: T[];
|
|
105
|
+
select?: (selection: T[]) => void;
|
|
106
|
+
};
|
|
107
|
+
type SelectionHandler<T> = SingleSelectionHandler<T> | MultiSelectionHandler<T>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/modifiers/aria-listbox.d.ts
|
|
110
|
+
type ListboxOptions<T> = Simplify<SelectionHandler<T> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & {
|
|
111
|
+
disabled?: boolean;
|
|
112
|
+
}>;
|
|
113
|
+
interface ListboxSignature<T> {
|
|
114
|
+
Args: {
|
|
115
|
+
Positional: [];
|
|
116
|
+
Named: ListboxOptions<T>;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
declare class ListboxModifier<T> extends Modifier<ListboxSignature<T>> {
|
|
120
|
+
private listbox?;
|
|
121
|
+
private updater;
|
|
122
|
+
private emitter;
|
|
123
|
+
private prevItems?;
|
|
124
|
+
private prevSelection?;
|
|
125
|
+
private prevMulti?;
|
|
126
|
+
private prevDisabled?;
|
|
127
|
+
constructor(owner: Owner, args: ArgsFor<ListboxSignature<T>>);
|
|
128
|
+
modify(element: Element, _: PositionalArgs<ListboxSignature<T>>, options: NamedArgs<ListboxSignature<T>>): void;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/modifiers/aria-menu.d.ts
|
|
132
|
+
type MenuOptions<T> = Simplify<Omit<MultiSelectionHandler<T>, 'multi'> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & CheckHandler<T> & {
|
|
133
|
+
disabled?: boolean;
|
|
134
|
+
}>;
|
|
135
|
+
interface MenuSignature<T> {
|
|
136
|
+
Element: HTMLElement;
|
|
137
|
+
Args: {
|
|
138
|
+
Positional: [];
|
|
139
|
+
Named: MenuOptions<T>;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
declare class MenuModifier<T> extends Modifier<MenuSignature<T>> {
|
|
143
|
+
private menu?;
|
|
144
|
+
private updater;
|
|
145
|
+
private emitter;
|
|
146
|
+
private prevItems?;
|
|
147
|
+
private prevDisabled?;
|
|
148
|
+
constructor(owner: Owner, args: ArgsFor<MenuSignature<T>>);
|
|
149
|
+
modify(element: Element, _: PositionalArgs<MenuSignature<T>>, options: NamedArgs<MenuSignature<T>>): void;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/modifiers/aria-radiogroup.d.ts
|
|
153
|
+
type RadioGroupOptions<T> = Simplify<SingleSelectionHandler<T> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & {
|
|
154
|
+
disabled?: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
interface RadioGroupSignature<T> {
|
|
157
|
+
Element: HTMLElement;
|
|
158
|
+
Args: {
|
|
159
|
+
Positional: [];
|
|
160
|
+
Named: RadioGroupOptions<T>;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
declare class RadioGroupModifier<T> extends Modifier<RadioGroupSignature<T>> {
|
|
164
|
+
private radioGroup?;
|
|
165
|
+
private updater;
|
|
166
|
+
private emitter;
|
|
167
|
+
private prevItems?;
|
|
168
|
+
private prevDisabled?;
|
|
169
|
+
constructor(owner: Owner, args: ArgsFor<RadioGroupSignature<T>>);
|
|
170
|
+
modify(element: Element, _: PositionalArgs<RadioGroupSignature<T>>, options: NamedArgs<RadioGroupSignature<T>>): void;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/modifiers/aria-tablist.d.ts
|
|
174
|
+
type TablistOptions<T> = Simplify<Omit<SingleSelectionHandler<T>, 'multi'> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & {
|
|
175
|
+
disabled?: boolean;
|
|
176
|
+
orientation?: Orientation;
|
|
177
|
+
behavior?: TablistBehavior;
|
|
178
|
+
}>;
|
|
179
|
+
interface TablistSignature<T> {
|
|
180
|
+
Element: HTMLElement;
|
|
181
|
+
Args: {
|
|
182
|
+
Positional: [];
|
|
183
|
+
Named: TablistOptions<T>;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
declare class TablistModifier<T> extends Modifier<TablistSignature<T>> {
|
|
187
|
+
private tablist?;
|
|
188
|
+
private updater;
|
|
189
|
+
private emitter;
|
|
190
|
+
private prevItems?;
|
|
191
|
+
private prevSelection?;
|
|
192
|
+
private prevDisabled?;
|
|
193
|
+
private prevOrientation?;
|
|
194
|
+
constructor(owner: Owner, args: ArgsFor<TablistSignature<T>>);
|
|
195
|
+
modify(element: Element, _: PositionalArgs<TablistSignature<T>>, options: NamedArgs<TablistSignature<T>>): void;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { GroupModifier as a, ListboxModifier as i, RadioGroupModifier as n, MenuModifier as r, TablistModifier as t };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { IndexEmitStrategy, ItemEmitStrategy, Orientation, TablistBehavior } from "aria-voyager";
|
|
2
|
+
import Modifier, { ArgsFor, NamedArgs, PositionalArgs } from "ember-modifier";
|
|
3
|
+
import Owner from "@ember/owner";
|
|
4
|
+
|
|
5
|
+
//#region src/modifiers/aria-group.d.ts
|
|
6
|
+
interface GroupSignature<T> {
|
|
7
|
+
Element: HTMLElement;
|
|
8
|
+
Args: {
|
|
9
|
+
Positional: [];
|
|
10
|
+
Named: {
|
|
11
|
+
items?: T[];
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare class GroupModifier<T> extends Modifier<GroupSignature<T>> {
|
|
17
|
+
private group?;
|
|
18
|
+
private updater;
|
|
19
|
+
private emitter;
|
|
20
|
+
private prevItems?;
|
|
21
|
+
private prevDisabled?;
|
|
22
|
+
constructor(owner: Owner, args: ArgsFor<GroupSignature<T>>);
|
|
23
|
+
modify(element: Element, _: PositionalArgs<GroupSignature<T>>, options: NamedArgs<GroupSignature<T>>): void;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/simplify.d.ts
|
|
27
|
+
/**
|
|
28
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
29
|
+
|
|
30
|
+
@example
|
|
31
|
+
```
|
|
32
|
+
import type {Simplify} from 'type-fest';
|
|
33
|
+
|
|
34
|
+
type PositionProps = {
|
|
35
|
+
top: number;
|
|
36
|
+
left: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type SizeProps = {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
45
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
49
|
+
|
|
50
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
51
|
+
|
|
52
|
+
@example
|
|
53
|
+
```
|
|
54
|
+
import type {Simplify} from 'type-fest';
|
|
55
|
+
|
|
56
|
+
interface SomeInterface {
|
|
57
|
+
foo: number;
|
|
58
|
+
bar?: string;
|
|
59
|
+
baz: number | undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type SomeType = {
|
|
63
|
+
foo: number;
|
|
64
|
+
bar?: string;
|
|
65
|
+
baz: number | undefined;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
69
|
+
const someType: SomeType = literal;
|
|
70
|
+
const someInterface: SomeInterface = literal;
|
|
71
|
+
|
|
72
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
73
|
+
|
|
74
|
+
fn(literal); // Good: literal object type is sealed
|
|
75
|
+
fn(someType); // Good: type is sealed
|
|
76
|
+
// @ts-expect-error
|
|
77
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
78
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
82
|
+
@see {@link SimplifyDeep}
|
|
83
|
+
@category Object
|
|
84
|
+
*/
|
|
85
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/modifiers/-emitter.d.ts
|
|
88
|
+
type Items<T> = {
|
|
89
|
+
items: T[];
|
|
90
|
+
};
|
|
91
|
+
type ActivateHandler<T> = {
|
|
92
|
+
activateItem?: (item: T) => void;
|
|
93
|
+
};
|
|
94
|
+
type CheckHandler<T> = {
|
|
95
|
+
check?: (selection: T[]) => void;
|
|
96
|
+
};
|
|
97
|
+
type SingleSelectionHandler<T> = {
|
|
98
|
+
multi?: false;
|
|
99
|
+
selection?: T;
|
|
100
|
+
select?: (selection: T) => void;
|
|
101
|
+
};
|
|
102
|
+
type MultiSelectionHandler<T> = {
|
|
103
|
+
multi: true;
|
|
104
|
+
selection?: T[];
|
|
105
|
+
select?: (selection: T[]) => void;
|
|
106
|
+
};
|
|
107
|
+
type SelectionHandler<T> = SingleSelectionHandler<T> | MultiSelectionHandler<T>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/modifiers/aria-listbox.d.ts
|
|
110
|
+
type ListboxOptions<T> = Simplify<SelectionHandler<T> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & {
|
|
111
|
+
disabled?: boolean;
|
|
112
|
+
}>;
|
|
113
|
+
interface ListboxSignature<T> {
|
|
114
|
+
Args: {
|
|
115
|
+
Positional: [];
|
|
116
|
+
Named: ListboxOptions<T>;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
declare class ListboxModifier<T> extends Modifier<ListboxSignature<T>> {
|
|
120
|
+
private listbox?;
|
|
121
|
+
private updater;
|
|
122
|
+
private emitter;
|
|
123
|
+
private prevItems?;
|
|
124
|
+
private prevSelection?;
|
|
125
|
+
private prevMulti?;
|
|
126
|
+
private prevDisabled?;
|
|
127
|
+
constructor(owner: Owner, args: ArgsFor<ListboxSignature<T>>);
|
|
128
|
+
modify(element: Element, _: PositionalArgs<ListboxSignature<T>>, options: NamedArgs<ListboxSignature<T>>): void;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/modifiers/aria-menu.d.ts
|
|
132
|
+
type MenuOptions<T> = Simplify<Omit<MultiSelectionHandler<T>, 'multi'> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & CheckHandler<T> & {
|
|
133
|
+
disabled?: boolean;
|
|
134
|
+
}>;
|
|
135
|
+
interface MenuSignature<T> {
|
|
136
|
+
Element: HTMLElement;
|
|
137
|
+
Args: {
|
|
138
|
+
Positional: [];
|
|
139
|
+
Named: MenuOptions<T>;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
declare class MenuModifier<T> extends Modifier<MenuSignature<T>> {
|
|
143
|
+
private menu?;
|
|
144
|
+
private updater;
|
|
145
|
+
private emitter;
|
|
146
|
+
private prevItems?;
|
|
147
|
+
private prevDisabled?;
|
|
148
|
+
constructor(owner: Owner, args: ArgsFor<MenuSignature<T>>);
|
|
149
|
+
modify(element: Element, _: PositionalArgs<MenuSignature<T>>, options: NamedArgs<MenuSignature<T>>): void;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/modifiers/aria-radiogroup.d.ts
|
|
153
|
+
type RadioGroupOptions<T> = Simplify<SingleSelectionHandler<T> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & {
|
|
154
|
+
disabled?: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
interface RadioGroupSignature<T> {
|
|
157
|
+
Element: HTMLElement;
|
|
158
|
+
Args: {
|
|
159
|
+
Positional: [];
|
|
160
|
+
Named: RadioGroupOptions<T>;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
declare class RadioGroupModifier<T> extends Modifier<RadioGroupSignature<T>> {
|
|
164
|
+
private radioGroup?;
|
|
165
|
+
private updater;
|
|
166
|
+
private emitter;
|
|
167
|
+
private prevItems?;
|
|
168
|
+
private prevDisabled?;
|
|
169
|
+
constructor(owner: Owner, args: ArgsFor<RadioGroupSignature<T>>);
|
|
170
|
+
modify(element: Element, _: PositionalArgs<RadioGroupSignature<T>>, options: NamedArgs<RadioGroupSignature<T>>): void;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/modifiers/aria-tablist.d.ts
|
|
174
|
+
type TablistOptions<T> = Simplify<Omit<SingleSelectionHandler<T>, 'multi'> & (Items<T> | Partial<Items<T>>) & ActivateHandler<T> & {
|
|
175
|
+
disabled?: boolean;
|
|
176
|
+
orientation?: Orientation;
|
|
177
|
+
behavior?: TablistBehavior;
|
|
178
|
+
}>;
|
|
179
|
+
interface TablistSignature<T> {
|
|
180
|
+
Element: HTMLElement;
|
|
181
|
+
Args: {
|
|
182
|
+
Positional: [];
|
|
183
|
+
Named: TablistOptions<T>;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
declare class TablistModifier<T> extends Modifier<TablistSignature<T>> {
|
|
187
|
+
private tablist?;
|
|
188
|
+
private updater;
|
|
189
|
+
private emitter;
|
|
190
|
+
private prevItems?;
|
|
191
|
+
private prevSelection?;
|
|
192
|
+
private prevDisabled?;
|
|
193
|
+
private prevOrientation?;
|
|
194
|
+
constructor(owner: Owner, args: ArgsFor<TablistSignature<T>>);
|
|
195
|
+
modify(element: Element, _: PositionalArgs<TablistSignature<T>>, options: NamedArgs<TablistSignature<T>>): void;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { GroupModifier as a, ListboxModifier as i, RadioGroupModifier as n, MenuModifier as r, TablistModifier as t };
|