@m3e/core 1.0.0-rc.1 → 1.0.0-rc.3

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.
Files changed (179) hide show
  1. package/README.md +1 -2
  2. package/dist/a11y.js +6 -18
  3. package/dist/a11y.js.map +1 -1
  4. package/dist/a11y.min.js +5 -5
  5. package/dist/a11y.min.js.map +1 -1
  6. package/dist/css-custom-data.json +20 -0
  7. package/dist/custom-elements.json +3605 -3375
  8. package/dist/html-custom-data.json +36 -6
  9. package/dist/index.js +417 -33
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.min.js +95 -84
  12. package/dist/index.min.js.map +1 -1
  13. package/dist/src/a11y/FocusTrapElement.d.ts +1 -1
  14. package/dist/src/a11y/FocusTrapElement.d.ts.map +1 -1
  15. package/dist/src/shared/controllers/PressedController.d.ts +2 -0
  16. package/dist/src/shared/controllers/PressedController.d.ts.map +1 -1
  17. package/dist/src/shared/mixins/AttachInternals.d.ts.map +1 -1
  18. package/dist/src/shared/mixins/Checked.d.ts.map +1 -1
  19. package/dist/src/shared/mixins/CheckedIndeterminate.d.ts.map +1 -1
  20. package/dist/src/shared/mixins/ConstraintValidation.d.ts.map +1 -1
  21. package/dist/src/shared/mixins/Dirty.d.ts.map +1 -1
  22. package/dist/src/shared/mixins/Disabled.d.ts.map +1 -1
  23. package/dist/src/shared/mixins/DisabledInteractive.d.ts.map +1 -1
  24. package/dist/src/shared/mixins/EventAttribute.d.ts.map +1 -1
  25. package/dist/src/shared/mixins/Focusable.d.ts.map +1 -1
  26. package/dist/src/shared/mixins/FormAssociated.d.ts.map +1 -1
  27. package/dist/src/shared/mixins/FormSubmitter.d.ts +4 -1
  28. package/dist/src/shared/mixins/FormSubmitter.d.ts.map +1 -1
  29. package/dist/src/shared/mixins/HtmlFor.d.ts.map +1 -1
  30. package/dist/src/shared/mixins/KeyboardClick.d.ts.map +1 -1
  31. package/dist/src/shared/mixins/Labelled.d.ts.map +1 -1
  32. package/dist/src/shared/mixins/LinkButton.d.ts +13 -3
  33. package/dist/src/shared/mixins/LinkButton.d.ts.map +1 -1
  34. package/dist/src/shared/mixins/ReadOnly.d.ts.map +1 -1
  35. package/dist/src/shared/mixins/Required.d.ts.map +1 -1
  36. package/dist/src/shared/mixins/RequiredConstraintValidation.d.ts.map +1 -1
  37. package/dist/src/shared/mixins/Role.d.ts.map +1 -1
  38. package/dist/src/shared/mixins/Selected.d.ts.map +1 -1
  39. package/dist/src/shared/mixins/Touched.d.ts.map +1 -1
  40. package/dist/src/shared/mixins/Vertical.d.ts.map +1 -1
  41. package/dist/src/shared/primitives/CollapsibleElement.d.ts +1 -1
  42. package/dist/src/shared/primitives/CollapsibleElement.d.ts.map +1 -1
  43. package/dist/src/shared/primitives/ElevationElement.d.ts +0 -1
  44. package/dist/src/shared/primitives/ElevationElement.d.ts.map +1 -1
  45. package/dist/src/shared/primitives/FocusRingElement.d.ts +0 -1
  46. package/dist/src/shared/primitives/FocusRingElement.d.ts.map +1 -1
  47. package/dist/src/shared/primitives/PseudoCheckboxElement.d.ts +0 -1
  48. package/dist/src/shared/primitives/PseudoCheckboxElement.d.ts.map +1 -1
  49. package/dist/src/shared/primitives/PseudoRadioElement.d.ts +0 -1
  50. package/dist/src/shared/primitives/PseudoRadioElement.d.ts.map +1 -1
  51. package/dist/src/shared/primitives/RippleElement.d.ts +0 -1
  52. package/dist/src/shared/primitives/RippleElement.d.ts.map +1 -1
  53. package/dist/src/shared/primitives/ScrollContainerElement.d.ts +1 -4
  54. package/dist/src/shared/primitives/ScrollContainerElement.d.ts.map +1 -1
  55. package/dist/src/shared/primitives/SlideElement.d.ts +1 -3
  56. package/dist/src/shared/primitives/SlideElement.d.ts.map +1 -1
  57. package/dist/src/shared/primitives/StateLayerElement.d.ts +0 -1
  58. package/dist/src/shared/primitives/StateLayerElement.d.ts.map +1 -1
  59. package/dist/src/shared/primitives/TextHighlightElement.d.ts +81 -0
  60. package/dist/src/shared/primitives/TextHighlightElement.d.ts.map +1 -0
  61. package/dist/src/shared/primitives/TextOverflowElement.d.ts +0 -1
  62. package/dist/src/shared/primitives/TextOverflowElement.d.ts.map +1 -1
  63. package/dist/src/shared/primitives/index.d.ts +1 -0
  64. package/dist/src/shared/primitives/index.d.ts.map +1 -1
  65. package/dist/src/shared/utils/scrollIntoViewIfNeeded.d.ts +2 -2
  66. package/dist/src/shared/utils/scrollIntoViewIfNeeded.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/cem.config.mjs +0 -16
  69. package/demo/index.html +0 -58
  70. package/eslint.config.mjs +0 -21
  71. package/rollup.config.js +0 -132
  72. package/src/a11y/AriaDescriber.ts +0 -130
  73. package/src/a11y/FocusTrapElement.ts +0 -136
  74. package/src/a11y/InteractivityChecker.ts +0 -62
  75. package/src/a11y/LiveAnnouncer.ts +0 -143
  76. package/src/a11y/aria-reference.ts +0 -51
  77. package/src/a11y/index.ts +0 -8
  78. package/src/a11y/keycodes/KeyCode.ts +0 -128
  79. package/src/a11y/keycodes/ModifierKeys.ts +0 -5
  80. package/src/a11y/keycodes/getKeyCode.ts +0 -8
  81. package/src/a11y/keycodes/hasModifierKey.ts +0 -11
  82. package/src/a11y/keycodes/index.ts +0 -5
  83. package/src/a11y/keycodes/isModifierAllowed.ts +0 -12
  84. package/src/a11y/list-key/FocusKeyManager.ts +0 -25
  85. package/src/a11y/list-key/ListKeyManager.ts +0 -350
  86. package/src/a11y/list-key/ListManager.ts +0 -66
  87. package/src/a11y/list-key/RadioKeyManager.ts +0 -49
  88. package/src/a11y/list-key/RovingTabIndexManager.ts +0 -56
  89. package/src/a11y/list-key/SelectionManager.ts +0 -132
  90. package/src/a11y/list-key/Typeahead.ts +0 -131
  91. package/src/a11y/list-key/index.ts +0 -7
  92. package/src/a11y/visuallyHide.ts +0 -18
  93. package/src/anchoring/AnchorOptions.ts +0 -19
  94. package/src/anchoring/AnchorPosition.ts +0 -14
  95. package/src/anchoring/index.ts +0 -3
  96. package/src/anchoring/positionAnchor.ts +0 -53
  97. package/src/bidi/Directionality.ts +0 -85
  98. package/src/bidi/index.ts +0 -1
  99. package/src/index.ts +0 -1
  100. package/src/layout/Breakpoint.ts +0 -26
  101. package/src/layout/BreakpointObserver.ts +0 -44
  102. package/src/layout/index.ts +0 -2
  103. package/src/platform/Platform.ts +0 -67
  104. package/src/platform/index.ts +0 -1
  105. package/src/shared/controllers/FocusController.ts +0 -60
  106. package/src/shared/controllers/HoverController.ts +0 -140
  107. package/src/shared/controllers/IntersectionController.ts +0 -81
  108. package/src/shared/controllers/LongPressController.ts +0 -87
  109. package/src/shared/controllers/MonitorControllerBase.ts +0 -99
  110. package/src/shared/controllers/MutationController.ts +0 -89
  111. package/src/shared/controllers/PressedController.ts +0 -137
  112. package/src/shared/controllers/ResizeController.ts +0 -83
  113. package/src/shared/controllers/ScrollController.ts +0 -100
  114. package/src/shared/controllers/index.ts +0 -8
  115. package/src/shared/decorators/debounce.ts +0 -19
  116. package/src/shared/decorators/index.ts +0 -1
  117. package/src/shared/directives/index.ts +0 -1
  118. package/src/shared/directives/safeStyleMap.ts +0 -108
  119. package/src/shared/index.ts +0 -7
  120. package/src/shared/mixins/AttachInternals.ts +0 -48
  121. package/src/shared/mixins/Checked.ts +0 -50
  122. package/src/shared/mixins/CheckedIndeterminate.ts +0 -47
  123. package/src/shared/mixins/CheckedOrSelected.ts +0 -36
  124. package/src/shared/mixins/ConstraintValidation.ts +0 -213
  125. package/src/shared/mixins/Constructor.ts +0 -2
  126. package/src/shared/mixins/Dirty.ts +0 -71
  127. package/src/shared/mixins/Disabled.ts +0 -49
  128. package/src/shared/mixins/DisabledInteractive.ts +0 -78
  129. package/src/shared/mixins/EventAttribute.ts +0 -25
  130. package/src/shared/mixins/Focusable.ts +0 -52
  131. package/src/shared/mixins/FormAssociated.ts +0 -152
  132. package/src/shared/mixins/FormSubmitter.ts +0 -123
  133. package/src/shared/mixins/HtmlFor.ts +0 -89
  134. package/src/shared/mixins/KeyboardClick.ts +0 -46
  135. package/src/shared/mixins/Labelled.ts +0 -88
  136. package/src/shared/mixins/LinkButton.ts +0 -169
  137. package/src/shared/mixins/ReadOnly.ts +0 -48
  138. package/src/shared/mixins/Required.ts +0 -50
  139. package/src/shared/mixins/RequiredConstraintValidation.ts +0 -45
  140. package/src/shared/mixins/Role.ts +0 -134
  141. package/src/shared/mixins/Selected.ts +0 -50
  142. package/src/shared/mixins/Touched.ts +0 -71
  143. package/src/shared/mixins/Vertical.ts +0 -44
  144. package/src/shared/mixins/hasKeys.ts +0 -10
  145. package/src/shared/mixins/index.ts +0 -24
  146. package/src/shared/primitives/CollapsibleElement.ts +0 -227
  147. package/src/shared/primitives/ElevationElement.ts +0 -254
  148. package/src/shared/primitives/ElevationLevel.ts +0 -2
  149. package/src/shared/primitives/ElevationToken.ts +0 -18
  150. package/src/shared/primitives/FocusRingElement.ts +0 -199
  151. package/src/shared/primitives/FocusRingToken.ts +0 -24
  152. package/src/shared/primitives/PseudoCheckboxElement.ts +0 -116
  153. package/src/shared/primitives/PseudoRadioElement.ts +0 -83
  154. package/src/shared/primitives/RippleElement.ts +0 -289
  155. package/src/shared/primitives/RippleToken.ts +0 -15
  156. package/src/shared/primitives/ScrollContainerElement.ts +0 -151
  157. package/src/shared/primitives/ScrollDividers.ts +0 -2
  158. package/src/shared/primitives/SlideElement.ts +0 -128
  159. package/src/shared/primitives/StateLayerElement.ts +0 -191
  160. package/src/shared/primitives/StateLayerToken.ts +0 -16
  161. package/src/shared/primitives/TextOverflowElement.ts +0 -60
  162. package/src/shared/primitives/index.ts +0 -12
  163. package/src/shared/tokens/ColorToken.ts +0 -142
  164. package/src/shared/tokens/DensityToken.ts +0 -23
  165. package/src/shared/tokens/DesignToken.ts +0 -35
  166. package/src/shared/tokens/ElevationToken.ts +0 -115
  167. package/src/shared/tokens/MotionToken.ts +0 -107
  168. package/src/shared/tokens/ScrollbarToken.ts +0 -13
  169. package/src/shared/tokens/ShapeToken.ts +0 -138
  170. package/src/shared/tokens/StateToken.ts +0 -13
  171. package/src/shared/tokens/TypescaleToken.ts +0 -230
  172. package/src/shared/tokens/index.ts +0 -1
  173. package/src/shared/utils/getTextContent.ts +0 -31
  174. package/src/shared/utils/guid.ts +0 -11
  175. package/src/shared/utils/hasAssignedNodes.ts +0 -8
  176. package/src/shared/utils/index.ts +0 -5
  177. package/src/shared/utils/prefersReducedMotion.ts +0 -9
  178. package/src/shared/utils/scrollIntoViewIfNeeded.ts +0 -18
  179. package/tsconfig.json +0 -9
@@ -1,51 +0,0 @@
1
- /**
2
- * Adapted from Angular Material CDK AriaDescriber
3
- * Source: https://github.com/angular/components/blob/main/src/cdk/a11y/aria-describer/aria-reference.ts
4
- *
5
- * @license MIT
6
- * Copyright (c) 2025 Google LLC
7
- * See LICENSE file in the project root for full license text.
8
- */
9
-
10
- /**
11
- * Gets a list of IDs referenced by an element for the specified ARIA attribute.
12
- * @param {Element} element The element from which to get referenced IDs.
13
- * @param {`aria-${string}`} attribute The ARIA attribute from which to get referenced IDs.
14
- * @returns {string[]} a list of IDs referenced by `element` for `attribute`.
15
- */
16
- export function getAriaReferenceIds(element: Element, attribute: `aria-${string}`): string[] {
17
- return element.getAttribute(attribute)?.match(/\S+/g) ?? [];
18
- }
19
-
20
- /**
21
- * Adds an ID to the list of IDs referenced by an element for a given ARIA attribute.
22
- * @param {Element} element The element to which to add a referenced ID.
23
- * @param {`aria-${string}`} attribute The ARIA attribute to which to add an ID.
24
- * @param {string} id The ID to add.
25
- */
26
- export function addAriaReferencedId(element: Element, attribute: `aria-${string}`, id: string): void {
27
- id = id.trim();
28
-
29
- const ids = getAriaReferenceIds(element, attribute);
30
- if (!ids.some((existingId) => existingId.trim() === id)) {
31
- ids.push(id);
32
- element.setAttribute(attribute, ids.join(" "));
33
- }
34
- }
35
-
36
- /**
37
- * Removes an ID from a list of IDs referenced by an element for the specified ARIA attribute.
38
- * @param {Element} element The element from which to remove an ID.
39
- * @param {`aria-${string}`} attribute The ARIA attribute from which to remove an ID.
40
- * @param {string} id The ID to remove.
41
- */
42
- export function removeAriaReferencedId(element: Element, attribute: `aria-${string}`, id: string): void {
43
- id = id.trim();
44
- const ids = getAriaReferenceIds(element, attribute).filter((val) => val !== id);
45
-
46
- if (ids.length > 0) {
47
- element.setAttribute(attribute, ids.join(" "));
48
- } else {
49
- element.removeAttribute(attribute);
50
- }
51
- }
package/src/a11y/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export * from "./list-key";
2
- export * from "./keycodes";
3
-
4
- export * from "./aria-reference";
5
- export * from "./AriaDescriber";
6
- export * from "./FocusTrapElement";
7
- export * from "./InteractivityChecker";
8
- export * from "./LiveAnnouncer";
@@ -1,128 +0,0 @@
1
- /** Specifies known key code values. */
2
- export enum KeyCode {
3
- Backspace = 8,
4
- Tab = 9,
5
- Enter = 13,
6
- Shift = 16,
7
- Ctrl = 17,
8
- Alt = 18,
9
- PauseBreak = 19,
10
- CapsLock = 20,
11
- Escape = 27,
12
- Space = 32,
13
- PageUp = 33,
14
- PageDown = 34,
15
- End = 35,
16
- Home = 36,
17
-
18
- LeftArrow = 37,
19
- UpArrow = 38,
20
- RightArrow = 39,
21
- DownArrow = 40,
22
-
23
- Insert = 45,
24
- Delete = 46,
25
-
26
- Zero = 48,
27
- ClosedParen = Zero,
28
- One = 49,
29
- ExclamationMark = One,
30
- Two = 50,
31
- AtSign = Two,
32
- Three = 51,
33
- PoundSign = Three,
34
- Hash = PoundSign,
35
- Four = 52,
36
- DollarSign = Four,
37
- Five = 53,
38
- PercentSign = Five,
39
- Six = 54,
40
- Caret = Six,
41
- Hat = Caret,
42
- Seven = 55,
43
- Ampersand = Seven,
44
- Eight = 56,
45
- Star = Eight,
46
- Asterik = Star,
47
- Nine = 57,
48
- OpenParen = Nine,
49
-
50
- A = 65,
51
- B = 66,
52
- C = 67,
53
- D = 68,
54
- E = 69,
55
- F = 70,
56
- G = 71,
57
- H = 72,
58
- I = 73,
59
- J = 74,
60
- K = 75,
61
- L = 76,
62
- M = 77,
63
- N = 78,
64
- O = 79,
65
- P = 80,
66
- Q = 81,
67
- R = 82,
68
- S = 83,
69
- T = 84,
70
- U = 85,
71
- V = 86,
72
- W = 87,
73
- X = 88,
74
- Y = 89,
75
- Z = 90,
76
-
77
- LeftWindowKey = 91,
78
- RightWindowKey = 92,
79
- SelectKey = 93,
80
-
81
- Numpad0 = 96,
82
- Numpad1 = 97,
83
- Numpad2 = 98,
84
- Numpad3 = 99,
85
- Numpad4 = 100,
86
- Numpad5 = 101,
87
- Numpad6 = 102,
88
- Numpad7 = 103,
89
- Numpad8 = 104,
90
- Numpad9 = 105,
91
-
92
- Multiply = 106,
93
- Add = 107,
94
- Subtract = 109,
95
- DecimalPoint = 110,
96
- Divide = 111,
97
-
98
- F1 = 112,
99
- F2 = 113,
100
- F3 = 114,
101
- F4 = 115,
102
- F5 = 116,
103
- F6 = 117,
104
- F7 = 118,
105
- F8 = 119,
106
- F9 = 120,
107
- F10 = 121,
108
- F11 = 122,
109
- F12 = 123,
110
-
111
- NumLock = 144,
112
- ScrollLock = 145,
113
-
114
- SemiColon = 186,
115
- Equals = 187,
116
- Comma = 188,
117
- Dash = 189,
118
- Period = 190,
119
- UnderScore = Dash,
120
- PlusSign = Equals,
121
- ForwardSlash = 191,
122
- Tilde = 192,
123
- GraveAccent = Tilde,
124
-
125
- OpenBracket = 219,
126
- ClosedBracket = 221,
127
- Quote = 222,
128
- }
@@ -1,5 +0,0 @@
1
- /** Specifies the keyboard modifier keys. */
2
- export type ModifierKey = "alt" | "shift" | "ctrl" | "meta";
3
-
4
- /** The modifier keys. */
5
- export const ModifierKeys: readonly ModifierKey[] = ["alt", "shift", "ctrl", "meta"];
@@ -1,8 +0,0 @@
1
- /**
2
- * Resolves the key code for the specified `KeyboardEvent`.
3
- * @param {KeyboardEvent} e The `KeyboardEvent` for which to resolve the key code.
4
- * @returns {number} The key code for `e`.
5
- */
6
- export function getKeyCode(e: KeyboardEvent): number {
7
- return e.which || e.charCode || e.keyCode;
8
- }
@@ -1,11 +0,0 @@
1
- import { ModifierKey } from "./ModifierKeys";
2
-
3
- /**
4
- * Determines whether a modifier key is pressed.
5
- * @param {KeyboardEvent} e The `KeyboardEvent` to test.
6
- * @param {ModifierKey[]} modifiers The modifier keys to test.
7
- * @returns {boolean} A value indicating whether a modifier key is pressed.
8
- */
9
- export function hasModifierKey(e: KeyboardEvent, ...modifiers: ModifierKey[]): boolean {
10
- return modifiers.length ? modifiers.some((x) => e[`${x}Key`]) : e.altKey || e.shiftKey || e.ctrlKey || e.metaKey;
11
- }
@@ -1,5 +0,0 @@
1
- export * from "./ModifierKeys";
2
- export * from "./KeyCode";
3
- export * from "./getKeyCode";
4
- export * from "./hasModifierKey";
5
- export * from "./isModifierAllowed";
@@ -1,12 +0,0 @@
1
- import { hasModifierKey } from "./hasModifierKey";
2
- import { ModifierKey, ModifierKeys } from "./ModifierKeys";
3
-
4
- /**
5
- * Determines whether the specified modifier keys are allowed.
6
- * @param {KeyboardEvent} e The `KeyboardEvent` to test.
7
- * @param {ModifierKey[]} modifiers The allowed modifier keys.
8
- * @returns {boolean} A value indicating whether `modifiers` are allowed.
9
- */
10
- export function isModifierAllowed(e: KeyboardEvent, ...modifiers: ModifierKey[]): boolean {
11
- return ModifierKeys.every((x) => !hasModifierKey(e, x) || modifiers.includes(x));
12
- }
@@ -1,25 +0,0 @@
1
- import { ListKeyManager } from "./ListKeyManager";
2
-
3
- /**
4
- * Utility for managing keyboard events for selectable lists whose items directly receive focus.
5
- * @template T The type of managed item.
6
- */
7
- export class FocusKeyManager<T extends HTMLElement> extends ListKeyManager<T> {
8
- /** @private */ #focusOptions?: FocusOptions;
9
-
10
- /** @inheritdoc */
11
- override setActiveItem(item: T | null | undefined): void {
12
- super.setActiveItem(item);
13
- item?.focus(this.#focusOptions);
14
- }
15
-
16
- /**
17
- * Configures the key manager with options used to focus items.
18
- * @param {FocusOptions} options Options used to focus items.
19
- * @returns {FocusKeyManager<T>} The configured key manager.
20
- */
21
- withOptions(options: FocusOptions): this {
22
- this.#focusOptions = options;
23
- return this;
24
- }
25
- }
@@ -1,350 +0,0 @@
1
- /**
2
- * Adapted from Angular Material CDK KeyManager
3
- * Source: https://github.com/angular/components/blob/main/src/cdk/a11y/key-manager/list-key-manager.ts
4
- *
5
- * @license MIT
6
- * Copyright (c) 2025 Google LLC
7
- * See LICENSE file in the project root for full license text.
8
- */
9
-
10
- import { hasModifierKey, isModifierAllowed, ModifierKey } from "../keycodes";
11
- import { isDisabledMixin } from "../../shared/mixins/Disabled";
12
-
13
- import { ListManager } from "./ListManager";
14
- import { Typeahead, TypeaheadItem } from "./Typeahead";
15
-
16
- /**
17
- * Utility for managing keyboard events for selectable lists.
18
- * @template T The type of managed item.
19
- */
20
- export class ListKeyManager<T extends HTMLElement & TypeaheadItem> extends ListManager<T> {
21
- /** @private */ #typeahead?: Typeahead<T>;
22
-
23
- /**
24
- * Whether the active item will wrap to the other end of
25
- * list when there are no more items in the given direction.
26
- * @default false
27
- */
28
- public wrap = false;
29
-
30
- /**
31
- * Whether to activate the first and last items respectively when
32
- * the `HOME` or `END` key is pressed.
33
- * @default false
34
- */
35
- public homeAndEnd = false;
36
-
37
- /**
38
- * Whether to activate every 10th (or configured) first/last item
39
- * in the up/down direction when the `PAGEUP` or `PAGEDOWN` key is pressed.
40
- * @default false
41
- */
42
- public pageUpAndDown = false;
43
-
44
- /**
45
- * The number of items to skip when the `PAGEUP` or `PAGEDOWN` key is pressed.
46
- * @default 10
47
- */
48
- public pageDelta = 10;
49
-
50
- /**
51
- * Whether to the list is oriented vertically.
52
- * @default false
53
- */
54
- public vertical = false;
55
-
56
- /** The allowed modifier keys.
57
- * @default []
58
- */
59
- public allowedModifiers: ModifierKey[] = [];
60
-
61
- /**
62
- * A function used to skip items.
63
- * @param {T} item The item to test.
64
- * @returns {boolean} Whether `item` should be skipped.
65
- */
66
- public skipPredicate: (item: T) => boolean = (item) => isDisabledMixin(item) && item.disabled;
67
-
68
- /** @inheritdoc */
69
- override setItems(items: T[]): { added: readonly T[]; removed: readonly T[] } {
70
- this.#typeahead?.setItems(items);
71
- return super.setItems(items);
72
- }
73
-
74
- /** @inheritdoc */
75
- override updateActiveItem(item: T | null | undefined): void {
76
- super.updateActiveItem(item);
77
- if (this.#typeahead) {
78
- this.#typeahead.setSelectedIndex(item ? this.items.indexOf(item) : -1);
79
- }
80
- }
81
-
82
- /**
83
- * Configures the key manager to activate the first and last items respectively when the `HOME` or `END` key is pressed.
84
- * @param {boolean} [enabled = true] Whether to activate the first and last items respectively when
85
- * the `HOME` or `END` key is pressed.
86
- * @returns {ListKeyManager<T>} The configured key manager.
87
- */
88
- withHomeAndEnd(enabled: boolean = true): this {
89
- this.homeAndEnd = enabled;
90
- return this;
91
- }
92
-
93
- /**
94
- * Configures the key manager to page up and down when the `PAGEUP` or `PAGEDOWN` key is pressed.
95
- * @param {boolean} [enabled = true] Whether to activate page up and down when the `PAGEUP` or `PAGEDOWN` key is pressed.
96
- * @param {number} [pageDelta=10] The number of items to skip when the `PAGEUP` or `PAGEDOWN` key is pressed.
97
- * @returns {ListKeyManager<T>} The configured key manager.
98
- */
99
- withPageUpAndDown(enabled: boolean = true, pageDelta: number = 10): this {
100
- this.pageUpAndDown = enabled;
101
- this.pageDelta = pageDelta;
102
- return this;
103
- }
104
-
105
- /**
106
- * Configures wrapping mode, which determines whether the active item will wrap to the other end of list when there are no more items in the given direction.
107
- * @param {boolean} [enabled = true] Whether the active item will wrap to the other end of
108
- * list when there are no more items in the given direction.
109
- * @returns {ListKeyManager<T>} The configured key manager.
110
- */
111
- withWrap(enabled: boolean = true): this {
112
- this.wrap = enabled;
113
- return this;
114
- }
115
-
116
- /**
117
- * Configures whether to move the selection vertically.
118
- * @param {boolean} [enabled = true] Whether to move selection vertically.
119
- * @returns {ListKeyManager<T>} The configured key manager.
120
- */
121
- withVerticalOrientation(enabled: boolean = true): this {
122
- this.vertical = enabled;
123
- return this;
124
- }
125
-
126
- /**
127
- * Configured allowed modifier keys.
128
- * @param {ModifierKey[]} modifiers The allowed modifier keys.
129
- * @returns {ListKeyManager<T>} The configured key manager.
130
- */
131
- withAllowedModifiers(...modifiers: ModifierKey[]): this {
132
- this.allowedModifiers = modifiers;
133
- return this;
134
- }
135
-
136
- /**
137
- * Configures whether typeahead is enabled.
138
- * @param {boolean} [enabled = true] Whether typeahead is enabled.
139
- * @returns {ListKeyManager<T>} The configured key manager.
140
- */
141
- withTypeahead(enabled: boolean = true): this {
142
- if (enabled) {
143
- this.#typeahead = new Typeahead<T>({ callback: (item) => this.setActiveItem(item) });
144
- } else {
145
- this.#typeahead = undefined;
146
- }
147
- return this;
148
- }
149
-
150
- /**
151
- * Configures a function used to test whether an item should be skipped.
152
- * @param skipPredicate A function used to determine whether an item should be skipped.
153
- * @returns {ListKeyManager<T>} The configured key manager.
154
- */
155
- withSkipPredicate(skipPredicate: (item: T) => boolean): this {
156
- this.skipPredicate = skipPredicate;
157
- return this;
158
- }
159
-
160
- /**
161
- * Sets the active item depending on the key event passed in.
162
- * @param {KeyboardEvent} e The keyboard event to be used for determining which element should be active.
163
- */
164
- onKeyDown(e: KeyboardEvent): void {
165
- if (e.defaultPrevented) return;
166
-
167
- const modifierAllowed = isModifierAllowed(e, ...this.allowedModifiers);
168
-
169
- switch (e.key) {
170
- case "Left":
171
- case "ArrowLeft":
172
- if (modifierAllowed && !this.vertical) {
173
- e.preventDefault();
174
- const prev = this.#findPrevious();
175
- if (prev) {
176
- this.setActiveItem(prev);
177
- }
178
- }
179
- break;
180
- case "Up":
181
- case "ArrowUp":
182
- if (modifierAllowed) {
183
- e.preventDefault();
184
- const prev = this.#findPrevious();
185
- if (prev) {
186
- this.setActiveItem(prev);
187
- }
188
- }
189
-
190
- break;
191
-
192
- case "Right":
193
- case "ArrowRight":
194
- if (modifierAllowed && !this.vertical) {
195
- e.preventDefault();
196
- const next = this.#findNext();
197
- if (next) {
198
- this.setActiveItem(next);
199
- }
200
- }
201
- break;
202
-
203
- case "Down":
204
- case "ArrowDown":
205
- if (modifierAllowed) {
206
- e.preventDefault();
207
- const next = this.#findNext();
208
- if (next) {
209
- this.setActiveItem(next);
210
- }
211
- }
212
-
213
- break;
214
-
215
- case "Home":
216
- if (modifierAllowed && this.homeAndEnd) {
217
- e.preventDefault();
218
- const first = this.#findFirst();
219
- if (first) {
220
- this.setActiveItem(first);
221
- }
222
- }
223
-
224
- break;
225
-
226
- case "End":
227
- if (modifierAllowed && this.homeAndEnd) {
228
- e.preventDefault();
229
- const last = this.#findLast();
230
- if (last) {
231
- this.setActiveItem(last);
232
- }
233
- }
234
-
235
- break;
236
-
237
- case "PageUp":
238
- if (modifierAllowed && this.pageUpAndDown) {
239
- e.preventDefault();
240
- const prev = this.#findPreviousByIndex(
241
- this.activeItem ? Math.max(0, this.items.indexOf(this.activeItem) - this.pageDelta) : 0
242
- );
243
- if (prev) {
244
- this.setActiveItem(prev);
245
- }
246
- }
247
-
248
- break;
249
-
250
- case "PageDown":
251
- if (modifierAllowed && this.pageUpAndDown) {
252
- e.preventDefault();
253
- const next = this.#findNextByIndex(
254
- this.activeItem
255
- ? Math.min(this.items.length - 1, this.items.indexOf(this.activeItem) + this.pageDelta)
256
- : this.items.length - 1
257
- );
258
- if (next) {
259
- this.setActiveItem(next);
260
- }
261
- }
262
-
263
- break;
264
-
265
- default:
266
- if (modifierAllowed || hasModifierKey(e, "shift")) {
267
- this.#typeahead?.onKeyDown(e);
268
- }
269
- break;
270
- }
271
- }
272
-
273
- /** @private */
274
- #findFirst(): T | null {
275
- for (let i = 0; i < this.items.length; i++) {
276
- if (this.items[i] === this.activeItem) break;
277
- const test = this.items[i];
278
- if (!this.skipPredicate(test)) {
279
- return test;
280
- }
281
- }
282
- return null;
283
- }
284
-
285
- /** @private */
286
- #findLast(): T | null {
287
- for (let i = this.items.length - 1; i >= 0; i--) {
288
- if (this.items[i] === this.activeItem) break;
289
- const test = this.items[i];
290
- if (!this.skipPredicate(test)) {
291
- return test;
292
- }
293
- }
294
- return null;
295
- }
296
-
297
- /** @private */
298
- #findNext(): T | null {
299
- for (let i = 0; i < this.items.length; i++) {
300
- if (this.items[i] === this.activeItem) {
301
- for (let j = i + 1; j < this.items.length; j++) {
302
- const test = this.items[j];
303
- if (!this.skipPredicate(test)) {
304
- return test;
305
- }
306
- }
307
- break;
308
- }
309
- }
310
- return this.wrap ? this.#findFirst() : null;
311
- }
312
-
313
- /** @private */
314
- #findPrevious(): T | null {
315
- for (let i = 0; i < this.items.length; i++) {
316
- if (this.items[i] === this.activeItem) {
317
- for (let j = i - 1; j >= 0; j--) {
318
- const test = this.items[j];
319
- if (!this.skipPredicate(test)) {
320
- return test;
321
- }
322
- }
323
- break;
324
- }
325
- }
326
- return this.wrap ? this.#findLast() : null;
327
- }
328
-
329
- /** @private */
330
- #findPreviousByIndex(index: number): T | null {
331
- for (let i = index; i >= 0; i--) {
332
- const test = this.items[i];
333
- if (!this.skipPredicate(test)) {
334
- return test;
335
- }
336
- }
337
- return null;
338
- }
339
-
340
- /** @private */
341
- #findNextByIndex(index: number): T | null {
342
- for (let i = index; i < this.items.length; i++) {
343
- const test = this.items[i];
344
- if (!this.skipPredicate(test)) {
345
- return test;
346
- }
347
- }
348
- return null;
349
- }
350
- }
@@ -1,66 +0,0 @@
1
- /**
2
- * Utility for managing a list of items which supports activation.
3
- * @template T The type of managed item.
4
- */
5
- export class ListManager<T> {
6
- /** @private */ #items = new Array<T>();
7
- /** @private */ #activeItem: T | null = null;
8
- /** @private */ #onActiveItemChangeCallback?: () => void;
9
-
10
- /** The items being managed. */
11
- get items(): ReadonlyArray<T> {
12
- return this.#items;
13
- }
14
-
15
- /** The active item. */
16
- get activeItem(): T | null {
17
- return this.#activeItem;
18
- }
19
-
20
- /**
21
- * Sets the items to manage.
22
- * @param {Array<T>} items The new items.
23
- * @returns {{ added: ReadonlyArray<T>; removed: ReadonlyArray<T> }} An object specifying added and removed items.
24
- */
25
- setItems(items: Array<T>): { added: ReadonlyArray<T>; removed: ReadonlyArray<T> } {
26
- const removed = this.items.filter((x) => !items.includes(x));
27
- const added = items.filter((x) => !this.items.includes(x));
28
-
29
- this.#items = items;
30
-
31
- if (this.activeItem && !this.items.includes(this.activeItem)) {
32
- this.updateActiveItem(null);
33
- }
34
-
35
- return { added, removed };
36
- }
37
-
38
- /**
39
- * Sets the active item.
40
- * @param {T | null | undefined} item The new active item.
41
- */
42
- setActiveItem(item: T | null | undefined): void {
43
- if (this.activeItem !== item) {
44
- this.updateActiveItem(item);
45
- this.#onActiveItemChangeCallback?.();
46
- }
47
- }
48
-
49
- /**
50
- * Updates the active item.
51
- * @param {T | null | undefined} item The active item.
52
- */
53
- updateActiveItem(item: T | null | undefined): void {
54
- this.#activeItem = item ?? null;
55
- }
56
-
57
- /**
58
- * Configures the list manager with a callback invoked when an item is activated.
59
- * @param {() => void} callback The callback invoked when an item is activated.
60
- * @returns {ListManager<T>} The configured list manager.
61
- */
62
- onActiveItemChange(callback: () => void): this {
63
- this.#onActiveItemChangeCallback = callback;
64
- return this;
65
- }
66
- }