@angular/cdk-experimental 20.2.0-next.2 → 20.2.0-next.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 (65) hide show
  1. package/accordion/index.d.ts +3 -3
  2. package/{accordion.d-CC6dGMlv.d.ts → accordion.d.d.ts} +7 -5
  3. package/{expansion.d-Zkcf-XJU.d.ts → expansion.d.d.ts} +3 -3
  4. package/fesm2022/accordion.mjs +17 -17
  5. package/fesm2022/accordion.mjs.map +1 -1
  6. package/fesm2022/{accordion-D9JoxtzT.mjs → accordion2.mjs} +8 -6
  7. package/fesm2022/accordion2.mjs.map +1 -0
  8. package/fesm2022/cdk-experimental.mjs +1 -1
  9. package/fesm2022/cdk-experimental.mjs.map +1 -1
  10. package/fesm2022/column-resize.mjs +54 -54
  11. package/fesm2022/combobox.mjs +10 -10
  12. package/fesm2022/deferred-content.mjs +6 -6
  13. package/fesm2022/{expansion-C9iQLHOG.mjs → expansion.mjs} +2 -2
  14. package/fesm2022/expansion.mjs.map +1 -0
  15. package/fesm2022/{list-focus-Czul8jzR.mjs → list-navigation.mjs} +63 -62
  16. package/fesm2022/list-navigation.mjs.map +1 -0
  17. package/fesm2022/list.mjs +355 -0
  18. package/fesm2022/list.mjs.map +1 -0
  19. package/fesm2022/listbox.mjs +10 -11
  20. package/fesm2022/listbox.mjs.map +1 -1
  21. package/fesm2022/option.mjs +231 -0
  22. package/fesm2022/option.mjs.map +1 -0
  23. package/fesm2022/{polyfill-CXksG4af.mjs → polyfill.mjs} +2 -2
  24. package/fesm2022/polyfill.mjs.map +1 -0
  25. package/fesm2022/popover-edit.mjs +44 -44
  26. package/fesm2022/{radio-button-92xc4w-A.mjs → radio-button.mjs} +33 -70
  27. package/fesm2022/radio-button.mjs.map +1 -0
  28. package/fesm2022/radio-group.mjs +10 -10
  29. package/fesm2022/radio-group.mjs.map +1 -1
  30. package/fesm2022/scrolling.mjs +7 -7
  31. package/fesm2022/selection.mjs +19 -19
  32. package/fesm2022/table-scroll-container.mjs +7 -7
  33. package/fesm2022/tabs.mjs +20 -20
  34. package/fesm2022/tabs.mjs.map +1 -1
  35. package/fesm2022/{tabs-hMdwtXv2.mjs → tabs2.mjs} +34 -70
  36. package/fesm2022/tabs2.mjs.map +1 -0
  37. package/fesm2022/tree.mjs +87 -159
  38. package/fesm2022/tree.mjs.map +1 -1
  39. package/fesm2022/ui-patterns.mjs +7 -8
  40. package/fesm2022/ui-patterns.mjs.map +1 -1
  41. package/list.d.d.ts +207 -0
  42. package/listbox/index.d.ts +3 -4
  43. package/{listbox.d-Ckp1is82.d.ts → listbox.d.d.ts} +9 -62
  44. package/package.json +2 -2
  45. package/{pointer-event-manager.d-BqSm9Jh5.d.ts → pointer-event-manager.d.d.ts} +12 -8
  46. package/radio-group/index.d.ts +4 -4
  47. package/{radio-group.d-CFC0aKQM.d.ts → radio-group.d.d.ts} +12 -31
  48. package/tabs/index.d.ts +4 -4
  49. package/{tabs.d-Db8oTrMB.d.ts → tabs.d.d.ts} +15 -30
  50. package/tree/index.d.ts +10 -39
  51. package/ui-patterns/index.d.ts +7 -8
  52. package/fesm2022/accordion-D9JoxtzT.mjs.map +0 -1
  53. package/fesm2022/expansion-C9iQLHOG.mjs.map +0 -1
  54. package/fesm2022/list-focus-Czul8jzR.mjs.map +0 -1
  55. package/fesm2022/list-selection-C41ApAbt.mjs +0 -136
  56. package/fesm2022/list-selection-C41ApAbt.mjs.map +0 -1
  57. package/fesm2022/list-typeahead-DIIbNJrP.mjs +0 -64
  58. package/fesm2022/list-typeahead-DIIbNJrP.mjs.map +0 -1
  59. package/fesm2022/option-CgeKz9_Q.mjs +0 -321
  60. package/fesm2022/option-CgeKz9_Q.mjs.map +0 -1
  61. package/fesm2022/polyfill-CXksG4af.mjs.map +0 -1
  62. package/fesm2022/radio-button-92xc4w-A.mjs.map +0 -1
  63. package/fesm2022/tabs-hMdwtXv2.mjs.map +0 -1
  64. package/list-selection.d-fbAPr_N_.d.ts +0 -69
  65. package/list-typeahead.d-ljh3nJ9y.d.ts +0 -48
@@ -1 +0,0 @@
1
- {"version":3,"file":"list-focus-Czul8jzR.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/event-manager/event-manager.ts","../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/event-manager/keyboard-event-manager.ts","../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/event-manager/pointer-event-manager.ts","../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/list-navigation/list-navigation.ts","../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/list-focus/list-focus.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\n/**\n * An event that supports modifier keys.\n *\n * Matches the native KeyboardEvent, MouseEvent, and TouchEvent.\n */\nexport interface EventWithModifiers extends Event {\n ctrlKey: boolean;\n shiftKey: boolean;\n altKey: boolean;\n metaKey: boolean;\n}\n\n/**\n * Options that are applicable to all event handlers.\n *\n * This library has not yet had a need for stopPropagationImmediate.\n */\nexport interface EventHandlerOptions {\n stopPropagation: boolean;\n preventDefault: boolean;\n}\n\n/** A basic event handler. */\nexport type EventHandler<T extends Event> = (event: T) => void;\n\n/** A function that determines whether an event is to be handled. */\nexport type EventMatcher<T extends Event> = (event: T) => boolean;\n\n/** A config that specifies how to handle a particular event. */\nexport interface EventHandlerConfig<T extends Event> extends EventHandlerOptions {\n matcher: EventMatcher<T>;\n handler: EventHandler<T>;\n}\n\n/** Bit flag representation of the possible modifier keys that can be present on an event. */\nexport enum Modifier {\n None = 0,\n Ctrl = 0b1,\n Shift = 0b10,\n Alt = 0b100,\n Meta = 0b1000,\n Any = 'Any',\n}\n\nexport type ModifierInputs = Modifier | Modifier[];\n\n/**\n * Abstract base class for all event managers.\n *\n * Event managers are designed to normalize how event handlers are authored and create a safety net\n * for common event handling gotchas like remembering to call preventDefault or stopPropagation.\n */\nexport abstract class EventManager<T extends Event> {\n protected configs: EventHandlerConfig<T>[] = [];\n abstract options: EventHandlerOptions;\n\n /** Runs the handlers that match with the given event. */\n handle(event: T): void {\n for (const config of this.configs) {\n if (config.matcher(event)) {\n config.handler(event);\n\n if (config.preventDefault) {\n event.preventDefault();\n }\n\n if (config.stopPropagation) {\n event.stopPropagation();\n }\n }\n }\n }\n\n /** Configures the event manager to handle specific events. (See subclasses for more). */\n abstract on(...args: [...unknown[]]): this;\n}\n\n/** Gets bit flag representation of the modifier keys present on the given event. */\nexport function getModifiers(event: EventWithModifiers): number {\n return (\n (+event.ctrlKey && Modifier.Ctrl) |\n (+event.shiftKey && Modifier.Shift) |\n (+event.altKey && Modifier.Alt) |\n (+event.metaKey && Modifier.Meta)\n );\n}\n\n/**\n * Checks if the given event has modifiers that are an exact match for any of the given modifier\n * flag combinations.\n */\nexport function hasModifiers(event: EventWithModifiers, modifiers: ModifierInputs): boolean {\n const eventModifiers = getModifiers(event);\n const modifiersList = Array.isArray(modifiers) ? modifiers : [modifiers];\n\n if (modifiersList.includes(Modifier.Any)) {\n return true;\n }\n\n return modifiersList.some(modifiers => eventModifiers === modifiers);\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {SignalLike} from '../signal-like/signal-like';\nimport {\n EventHandler,\n EventHandlerOptions,\n EventManager,\n hasModifiers,\n ModifierInputs,\n Modifier,\n} from './event-manager';\n\n/**\n * Used to represent a keycode.\n *\n * This is used to match whether an events keycode should be handled. The ability to match using a\n * string, SignalLike, or Regexp gives us more flexibility when authoring event handlers.\n */\ntype KeyCode = string | SignalLike<string> | RegExp;\n\n/**\n * An event manager that is specialized for handling keyboard events. By default this manager stops\n * propagation and prevents default on all events it handles.\n */\nexport class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<T> {\n options: EventHandlerOptions = {\n preventDefault: true,\n stopPropagation: true,\n };\n\n /** Configures this event manager to handle events with a specific key and no modifiers. */\n on(key: KeyCode, handler: EventHandler<T>): this;\n\n /** Configures this event manager to handle events with a specific modifer and key combination. */\n on(modifiers: ModifierInputs, key: KeyCode, handler: EventHandler<T>): this;\n\n on(...args: any[]) {\n const {modifiers, key, handler} = this._normalizeInputs(...args);\n\n this.configs.push({\n handler: handler,\n matcher: event => this._isMatch(event, key, modifiers),\n ...this.options,\n });\n\n return this;\n }\n\n private _normalizeInputs(...args: any[]) {\n const key = args.length === 3 ? args[1] : args[0];\n const handler = args.length === 3 ? args[2] : args[1];\n const modifiers = args.length === 3 ? args[0] : Modifier.None;\n\n return {\n key: key as KeyCode,\n handler: handler as EventHandler<T>,\n modifiers: modifiers as ModifierInputs,\n };\n }\n\n private _isMatch(event: T, key: KeyCode, modifiers: ModifierInputs) {\n if (!hasModifiers(event, modifiers)) {\n return false;\n }\n\n if (key instanceof RegExp) {\n return key.test(event.key);\n }\n\n const keyStr = typeof key === 'string' ? key : key();\n return keyStr.toLowerCase() === event.key.toLowerCase();\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {\n EventHandler,\n EventHandlerOptions,\n EventManager,\n hasModifiers,\n ModifierInputs,\n Modifier,\n} from './event-manager';\n\n/**\n * The different mouse buttons that may appear on a pointer event.\n */\nexport enum MouseButton {\n Main = 0,\n Auxiliary = 1,\n Secondary = 2,\n}\n\n/** An event manager that is specialized for handling pointer events. */\nexport class PointerEventManager<T extends PointerEvent> extends EventManager<T> {\n options: EventHandlerOptions = {\n preventDefault: false,\n stopPropagation: false,\n };\n\n /**\n * Configures this event manager to handle events with a specific modifer and mouse button\n * combination.\n */\n on(button: MouseButton, modifiers: ModifierInputs, handler: EventHandler<T>): this;\n\n /**\n * Configures this event manager to handle events with a specific mouse button and no modifiers.\n */\n on(modifiers: ModifierInputs, handler: EventHandler<T>): this;\n\n /**\n * Configures this event manager to handle events with the main mouse button and no modifiers.\n *\n * @param handler The handler function\n * @param options Options for whether to stop propagation or prevent default.\n */\n on(handler: EventHandler<T>): this;\n\n on(...args: any[]) {\n const {button, handler, modifiers} = this._normalizeInputs(...args);\n\n this.configs.push({\n handler,\n matcher: event => this._isMatch(event, button, modifiers),\n ...this.options,\n });\n return this;\n }\n\n private _normalizeInputs(...args: any[]) {\n if (args.length === 3) {\n return {\n button: args[0] as MouseButton,\n modifiers: args[1] as ModifierInputs,\n handler: args[2] as EventHandler<T>,\n };\n }\n\n if (typeof args[0] === 'number' && typeof args[1] === 'function') {\n return {\n button: MouseButton.Main,\n modifiers: args[0] as ModifierInputs,\n handler: args[1] as EventHandler<T>,\n };\n }\n\n return {\n button: MouseButton.Main,\n modifiers: Modifier.None,\n handler: args[0] as EventHandler<T>,\n };\n }\n\n _isMatch(event: PointerEvent, button: MouseButton, modifiers: ModifierInputs) {\n return button === (event.button ?? 0) && hasModifiers(event, modifiers);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {SignalLike} from '../signal-like/signal-like';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\n\n/** Represents an item in a collection, such as a listbox option, than can be navigated to. */\nexport interface ListNavigationItem extends ListFocusItem {}\n\n/** Represents the required inputs for a collection that has navigable items. */\nexport interface ListNavigationInputs<T extends ListNavigationItem> extends ListFocusInputs<T> {\n /** Whether focus should wrap when navigating. */\n wrap: SignalLike<boolean>;\n\n /** Whether the list is vertically or horizontally oriented. */\n orientation: SignalLike<'vertical' | 'horizontal'>;\n\n /** The direction that text is read based on the users locale. */\n textDirection: SignalLike<'rtl' | 'ltr'>;\n}\n\n/** Controls navigation for a list of items. */\nexport class ListNavigation<T extends ListNavigationItem> {\n constructor(readonly inputs: ListNavigationInputs<T> & {focusManager: ListFocus<T>}) {}\n\n /** Navigates to the given item. */\n goto(item?: T): boolean {\n return item ? this.inputs.focusManager.focus(item) : false;\n }\n\n /** Navigates to the next item in the list. */\n next(): boolean {\n return this._advance(1);\n }\n\n /** Navigates to the previous item in the list. */\n prev(): boolean {\n return this._advance(-1);\n }\n\n /** Navigates to the first item in the list. */\n first(): boolean {\n const item = this.inputs.items().find(i => this.inputs.focusManager.isFocusable(i));\n return item ? this.goto(item) : false;\n }\n\n /** Navigates to the last item in the list. */\n last(): boolean {\n const items = this.inputs.items();\n for (let i = items.length - 1; i >= 0; i--) {\n if (this.inputs.focusManager.isFocusable(items[i])) {\n return this.goto(items[i]);\n }\n }\n return false;\n }\n\n /** Advances to the next or previous focusable item in the list based on the given delta. */\n private _advance(delta: 1 | -1): boolean {\n const items = this.inputs.items();\n const itemCount = items.length;\n const startIndex = this.inputs.activeIndex();\n const step = (i: number) =>\n this.inputs.wrap() ? (i + delta + itemCount) % itemCount : i + delta;\n\n // If wrapping is enabled, this loop ultimately terminates when `i` gets back to `startIndex`\n // in the case that all options are disabled. If wrapping is disabled, the loop terminates\n // when the index goes out of bounds.\n for (let i = step(startIndex); i !== startIndex && i < itemCount && i >= 0; i = step(i)) {\n if (this.inputs.focusManager.isFocusable(items[i])) {\n return this.goto(items[i]);\n }\n }\n\n return false;\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {SignalLike, WritableSignalLike} from '../signal-like/signal-like';\n\n/** Represents an item in a collection, such as a listbox option, than may receive focus. */\nexport interface ListFocusItem {\n /** A unique identifier for the item. */\n id: SignalLike<string>;\n\n /** The html element that should receive focus. */\n element: SignalLike<HTMLElement>;\n\n /** Whether an item is disabled. */\n disabled: SignalLike<boolean>;\n}\n\n/** Represents the required inputs for a collection that contains focusable items. */\nexport interface ListFocusInputs<T extends ListFocusItem> {\n /** The focus strategy used by the list. */\n focusMode: SignalLike<'roving' | 'activedescendant'>;\n\n /** Whether the list is disabled. */\n disabled: SignalLike<boolean>;\n\n /** The items in the list. */\n items: SignalLike<T[]>;\n\n /** The index of the current active item. */\n activeIndex: WritableSignalLike<number>;\n\n /** Whether disabled items in the list should be skipped when navigating. */\n skipDisabled: SignalLike<boolean>;\n}\n\n/** Controls focus for a list of items. */\nexport class ListFocus<T extends ListFocusItem> {\n /** The last index that was active. */\n prevActiveIndex = signal(0);\n\n /** The current active item. */\n activeItem = computed(() => this.inputs.items()[this.inputs.activeIndex()]);\n\n constructor(readonly inputs: ListFocusInputs<T>) {}\n\n /** Whether the list is in a disabled state. */\n isListDisabled(): boolean {\n return this.inputs.disabled() || this.inputs.items().every(i => i.disabled());\n }\n\n /** The id of the current active item. */\n getActiveDescendant(): string | undefined {\n if (this.isListDisabled()) {\n return undefined;\n }\n if (this.inputs.focusMode() === 'roving') {\n return undefined;\n }\n return this.inputs.items()[this.inputs.activeIndex()].id();\n }\n\n /** The tabindex for the list. */\n getListTabindex(): -1 | 0 {\n if (this.isListDisabled()) {\n return 0;\n }\n return this.inputs.focusMode() === 'activedescendant' ? 0 : -1;\n }\n\n /** Returns the tabindex for the given item. */\n getItemTabindex(item: T): -1 | 0 {\n if (this.isListDisabled()) {\n return -1;\n }\n if (this.inputs.focusMode() === 'activedescendant') {\n return -1;\n }\n return this.activeItem() === item ? 0 : -1;\n }\n\n /** Moves focus to the given item if it is focusable. */\n focus(item: T): boolean {\n if (this.isListDisabled() || !this.isFocusable(item)) {\n return false;\n }\n\n this.prevActiveIndex.set(this.inputs.activeIndex());\n const index = this.inputs.items().indexOf(item);\n this.inputs.activeIndex.set(index);\n\n if (this.inputs.focusMode() === 'roving') {\n item.element().focus();\n }\n\n return true;\n }\n\n /** Returns true if the given item can be navigated to. */\n isFocusable(item: T): boolean {\n return !item.disabled() || !this.inputs.skipDisabled();\n }\n}\n"],"names":[],"mappings":";;AA0CA;IACY;AAAZ,CAAA,UAAY,QAAQ,EAAA;AAClB,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAU;AACV,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAY;AACZ,IAAA,QAAA,CAAA,QAAA,CAAA,KAAA,CAAA,GAAA,CAAA,CAAA,GAAA,KAAW;AACX,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAa;AACb,IAAA,QAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACb,CAAC,EAPW,QAAQ,KAAR,QAAQ,GAOnB,EAAA,CAAA,CAAA;AAID;;;;;AAKG;MACmB,YAAY,CAAA;IACtB,OAAO,GAA4B,EAAE;;AAI/C,IAAA,MAAM,CAAC,KAAQ,EAAA;AACb,QAAA,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE;AACjC,YAAA,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACzB,gBAAA,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;AAErB,gBAAA,IAAI,MAAM,CAAC,cAAc,EAAE;oBACzB,KAAK,CAAC,cAAc,EAAE;;AAGxB,gBAAA,IAAI,MAAM,CAAC,eAAe,EAAE;oBAC1B,KAAK,CAAC,eAAe,EAAE;;;;;AAQhC;AAED;AACM,SAAU,YAAY,CAAC,KAAyB,EAAA;IACpD,QACE,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI;SAC/B,CAAC,KAAK,CAAC,QAAQ,IAAI,QAAQ,C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,IAAA,WAAW,CAAC,IAAO,EAAA;AACjB,QAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;;AAEzD;;;;"}
@@ -1,136 +0,0 @@
1
- import { signal, computed } from '@angular/core';
2
-
3
- /** Controls selection for a list of items. */
4
- class ListSelection {
5
- inputs;
6
- /** The start index to use for range selection. */
7
- rangeStartIndex = signal(0);
8
- /** The end index to use for range selection. */
9
- rangeEndIndex = signal(0);
10
- /** The currently selected items. */
11
- selectedItems = computed(() => this.inputs.items().filter(item => this.inputs.value().includes(item.value())));
12
- constructor(inputs) {
13
- this.inputs = inputs;
14
- }
15
- /** Selects the item at the current active index. */
16
- select(item, opts = { anchor: true }) {
17
- item = item ?? this.inputs.focusManager.activeItem();
18
- if (item.disabled() || this.inputs.value().includes(item.value())) {
19
- return;
20
- }
21
- if (!this.inputs.multi()) {
22
- this.deselectAll();
23
- }
24
- const index = this.inputs.items().findIndex(i => i === item);
25
- if (opts.anchor) {
26
- this.beginRangeSelection(index);
27
- }
28
- this.inputs.value.update(values => values.concat(item.value()));
29
- }
30
- /** Deselects the item at the current active index. */
31
- deselect(item) {
32
- item = item ?? this.inputs.focusManager.activeItem();
33
- if (!item.disabled()) {
34
- this.inputs.value.update(values => values.filter(value => value !== item.value()));
35
- }
36
- }
37
- /** Toggles the item at the current active index. */
38
- toggle() {
39
- const item = this.inputs.focusManager.activeItem();
40
- this.inputs.value().includes(item.value()) ? this.deselect() : this.select();
41
- }
42
- /** Toggles only the item at the current active index. */
43
- toggleOne() {
44
- const item = this.inputs.focusManager.activeItem();
45
- this.inputs.value().includes(item.value()) ? this.deselect() : this.selectOne();
46
- }
47
- /** Selects all items in the list. */
48
- selectAll() {
49
- if (!this.inputs.multi()) {
50
- return; // Should we log a warning?
51
- }
52
- for (const item of this.inputs.items()) {
53
- this.select(item, { anchor: false });
54
- }
55
- this.beginRangeSelection();
56
- }
57
- /** Deselects all items in the list. */
58
- deselectAll() {
59
- for (const item of this.inputs.items()) {
60
- this.deselect(item);
61
- }
62
- }
63
- /**
64
- * Selects all items in the list or deselects all
65
- * items in the list if all items are already selected.
66
- */
67
- toggleAll() {
68
- const selectableValues = this.inputs
69
- .items()
70
- .filter(i => !i.disabled())
71
- .map(i => i.value());
72
- selectableValues.every(i => this.inputs.value().includes(i))
73
- ? this.deselectAll()
74
- : this.selectAll();
75
- }
76
- /** Sets the selection to only the current active item. */
77
- selectOne() {
78
- if (this.inputs.focusManager.activeItem().disabled()) {
79
- return;
80
- }
81
- this.deselectAll();
82
- if (this.inputs.value().length > 0 && !this.inputs.multi()) {
83
- return;
84
- }
85
- this.select();
86
- }
87
- /**
88
- * Selects all items in the list up to the anchor item.
89
- *
90
- * Deselects all items that were previously within the
91
- * selected range that are now outside of the selected range
92
- */
93
- selectRange(opts = { anchor: true }) {
94
- const isStartOfRange = this.inputs.focusManager.prevActiveIndex() === this.rangeStartIndex();
95
- if (isStartOfRange && opts.anchor) {
96
- this.beginRangeSelection(this.inputs.focusManager.prevActiveIndex());
97
- }
98
- const itemsInRange = this._getItemsFromIndex(this.rangeStartIndex());
99
- const itemsOutOfRange = this._getItemsFromIndex(this.rangeEndIndex()).filter(i => !itemsInRange.includes(i));
100
- for (const item of itemsOutOfRange) {
101
- this.deselect(item);
102
- }
103
- for (const item of itemsInRange) {
104
- this.select(item, { anchor: false });
105
- }
106
- if (itemsInRange.length) {
107
- const item = itemsInRange.pop();
108
- const index = this.inputs.items().findIndex(i => i === item);
109
- this.rangeEndIndex.set(index);
110
- }
111
- }
112
- /** Marks the given index as the start of a range selection. */
113
- beginRangeSelection(index = this.inputs.activeIndex()) {
114
- this.rangeStartIndex.set(index);
115
- this.rangeEndIndex.set(index);
116
- }
117
- /** Returns the items in the list starting from the given index. */
118
- _getItemsFromIndex(index) {
119
- if (index === -1) {
120
- return [];
121
- }
122
- const upper = Math.max(this.inputs.activeIndex(), index);
123
- const lower = Math.min(this.inputs.activeIndex(), index);
124
- const items = [];
125
- for (let i = lower; i <= upper; i++) {
126
- items.push(this.inputs.items()[i]);
127
- }
128
- if (this.inputs.activeIndex() < index) {
129
- return items.reverse();
130
- }
131
- return items;
132
- }
133
- }
134
-
135
- export { ListSelection as L };
136
- //# sourceMappingURL=list-selection-C41ApAbt.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"list-selection-C41ApAbt.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/list-selection/list-selection.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {SignalLike, WritableSignalLike} from '../signal-like/signal-like';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\n\n/** Represents an item in a collection, such as a listbox option, than can be selected. */\nexport interface ListSelectionItem<V> extends ListFocusItem {\n /** The value of the item. */\n value: SignalLike<V>;\n}\n\n/** Represents the required inputs for a collection that contains selectable items. */\nexport interface ListSelectionInputs<T extends ListSelectionItem<V>, V> extends ListFocusInputs<T> {\n /** Whether multiple items in the list can be selected at once. */\n multi: SignalLike<boolean>;\n\n /** The current value of the list selection. */\n value: WritableSignalLike<V[]>;\n\n /** The selection strategy used by the list. */\n selectionMode: SignalLike<'follow' | 'explicit'>;\n}\n\n/** Controls selection for a list of items. */\nexport class ListSelection<T extends ListSelectionItem<V>, V> {\n /** The start index to use for range selection. */\n rangeStartIndex = signal<number>(0);\n\n /** The end index to use for range selection. */\n rangeEndIndex = signal<number>(0);\n\n /** The currently selected items. */\n selectedItems = computed(() =>\n this.inputs.items().filter(item => this.inputs.value().includes(item.value())),\n );\n\n constructor(readonly inputs: ListSelectionInputs<T, V> & {focusManager: ListFocus<T>}) {}\n\n /** Selects the item at the current active index. */\n select(item?: ListSelectionItem<V>, opts = {anchor: true}) {\n item = item ?? (this.inputs.focusManager.activeItem() as ListSelectionItem<V>);\n\n if (item.disabled() || this.inputs.value().includes(item.value())) {\n return;\n }\n\n if (!this.inputs.multi()) {\n this.deselectAll();\n }\n\n const index = this.inputs.items().findIndex(i => i === item);\n if (opts.anchor) {\n this.beginRangeSelection(index);\n }\n this.inputs.value.update(values => values.concat(item.value()));\n }\n\n /** Deselects the item at the current active index. */\n deselect(item?: T) {\n item = item ?? this.inputs.focusManager.activeItem();\n\n if (!item.disabled()) {\n this.inputs.value.update(values => values.filter(value => value !== item.value()));\n }\n }\n\n /** Toggles the item at the current active index. */\n toggle() {\n const item = this.inputs.focusManager.activeItem();\n this.inputs.value().includes(item.value()) ? this.deselect() : this.select();\n }\n\n /** Toggles only the item at the current active index. */\n toggleOne() {\n const item = this.inputs.focusManager.activeItem();\n this.inputs.value().includes(item.value()) ? this.deselect() : this.selectOne();\n }\n\n /** Selects all items in the list. */\n selectAll() {\n if (!this.inputs.multi()) {\n return; // Should we log a warning?\n }\n\n for (const item of this.inputs.items()) {\n this.select(item, {anchor: false});\n }\n\n this.beginRangeSelection();\n }\n\n /** Deselects all items in the list. */\n deselectAll() {\n for (const item of this.inputs.items()) {\n this.deselect(item);\n }\n }\n\n /**\n * Selects all items in the list or deselects all\n * items in the list if all items are already selected.\n */\n toggleAll() {\n const selectableValues = this.inputs\n .items()\n .filter(i => !i.disabled())\n .map(i => i.value());\n\n selectableValues.every(i => this.inputs.value().includes(i))\n ? this.deselectAll()\n : this.selectAll();\n }\n\n /** Sets the selection to only the current active item. */\n selectOne() {\n if (this.inputs.focusManager.activeItem().disabled()) {\n return;\n }\n\n this.deselectAll();\n\n if (this.inputs.value().length > 0 && !this.inputs.multi()) {\n return;\n }\n\n this.select();\n }\n\n /**\n * Selects all items in the list up to the anchor item.\n *\n * Deselects all items that were previously within the\n * selected range that are now outside of the selected range\n */\n selectRange(opts = {anchor: true}) {\n const isStartOfRange = this.inputs.focusManager.prevActiveIndex() === this.rangeStartIndex();\n\n if (isStartOfRange && opts.anchor) {\n this.beginRangeSelection(this.inputs.focusManager.prevActiveIndex());\n }\n\n const itemsInRange = this._getItemsFromIndex(this.rangeStartIndex());\n const itemsOutOfRange = this._getItemsFromIndex(this.rangeEndIndex()).filter(\n i => !itemsInRange.includes(i),\n );\n\n for (const item of itemsOutOfRange) {\n this.deselect(item);\n }\n\n for (const item of itemsInRange) {\n this.select(item, {anchor: false});\n }\n\n if (itemsInRange.length) {\n const item = itemsInRange.pop();\n const index = this.inputs.items().findIndex(i => i === item);\n this.rangeEndIndex.set(index);\n }\n }\n\n /** Marks the given index as the start of a range selection. */\n beginRangeSelection(index: number = this.inputs.activeIndex()) {\n this.rangeStartIndex.set(index);\n this.rangeEndIndex.set(index);\n }\n\n /** Returns the items in the list starting from the given index. */\n private _getItemsFromIndex(index: number) {\n if (index === -1) {\n return [];\n }\n\n const upper = Math.max(this.inputs.activeIndex(), index);\n const lower = Math.min(this.inputs.activeIndex(), index);\n\n const items = [];\n for (let i = lower; i <= upper; i++) {\n items.push(this.inputs.items()[i]);\n }\n\n if (this.inputs.activeIndex() < index) {\n return items.reverse();\n }\n\n return items;\n }\n}\n"],"names":[],"mappings":";;AA8BA;MACa,aAAa,CAAA;AAYH,IAAA,MAAA;;AAVrB,IAAA,eAAe,GAAG,MAAM,CAAS,CAAC,CAAC;;AAGnC,IAAA,aAAa,GAAG,MAAM,CAAS,CAAC,CAAC;;AAGjC,IAAA,aAAa,GAAG,QAAQ,CAAC,MACvB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAC/E;AAED,IAAA,WAAA,CAAqB,MAAgE,EAAA;QAAhE,IAAM,CAAA,MAAA,GAAN,MAAM;;;IAG3B,MAAM,CAAC,IAA2B,EAAE,IAAI,GAAG,EAAC,MAAM,EAAE,I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AI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;;;;AAKjC,IAAA,mBAAmB,CAAC,KAAgB,GAAA,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAA;AAC3D,QAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC;AAC/B,QAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;;;AAIvB,IAAA,kBAAkB,CAAC,KAAa,EAAA;AACtC,QAAA,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;AAChB,YAAA,OAAO,EAAE;;AAGX,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC;AACxD,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC;QAExD,MAAM,KAAK,GAAG,EAAE;AAChB,QAAA,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE;AACnC,YAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;;QAGpC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,KAAK,EAAE;AACrC,YAAA,OAAO,KAAK,CAAC,OAAO,EAAE;;AAGxB,QAAA,OAAO,KAAK;;AAEf;;;;"}
@@ -1,64 +0,0 @@
1
- import { computed, signal } from '@angular/core';
2
-
3
- /** Controls typeahead for a list of items. */
4
- class ListTypeahead {
5
- inputs;
6
- /** A reference to the timeout for resetting the typeahead search. */
7
- timeout;
8
- /** The focus controller of the parent list. */
9
- focusManager;
10
- /** Whether the user is actively typing a typeahead search query. */
11
- isTyping = computed(() => this._query().length > 0);
12
- /** Keeps track of the characters that typeahead search is being called with. */
13
- _query = signal('');
14
- /** The index where that the typeahead search was initiated from. */
15
- _startIndex = signal(undefined);
16
- constructor(inputs) {
17
- this.inputs = inputs;
18
- this.focusManager = inputs.focusManager;
19
- }
20
- /** Performs a typeahead search, appending the given character to the search string. */
21
- search(char) {
22
- if (char.length !== 1) {
23
- return false;
24
- }
25
- if (!this.isTyping() && char === ' ') {
26
- return false;
27
- }
28
- if (this._startIndex() === undefined) {
29
- this._startIndex.set(this.focusManager.inputs.activeIndex());
30
- }
31
- clearTimeout(this.timeout);
32
- this._query.update(q => q + char.toLowerCase());
33
- const item = this._getItem();
34
- if (item) {
35
- this.focusManager.focus(item);
36
- }
37
- this.timeout = setTimeout(() => {
38
- this._query.set('');
39
- this._startIndex.set(undefined);
40
- }, this.inputs.typeaheadDelay() * 1000);
41
- return true;
42
- }
43
- /**
44
- * Returns the first item whose search term matches the
45
- * current query starting from the the current anchor index.
46
- */
47
- _getItem() {
48
- let items = this.focusManager.inputs.items();
49
- const after = items.slice(this._startIndex() + 1);
50
- const before = items.slice(0, this._startIndex());
51
- items = after.concat(before);
52
- items.push(this.inputs.items()[this._startIndex()]);
53
- const focusableItems = [];
54
- for (const item of items) {
55
- if (this.focusManager.isFocusable(item)) {
56
- focusableItems.push(item);
57
- }
58
- }
59
- return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query()));
60
- }
61
- }
62
-
63
- export { ListTypeahead as L };
64
- //# sourceMappingURL=list-typeahead-DIIbNJrP.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"list-typeahead-DIIbNJrP.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/cdk-experimental/ui-patterns/behaviors/list-typeahead/list-typeahead.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {computed, signal} from '@angular/core';\nimport {SignalLike} from '../signal-like/signal-like';\nimport {ListFocus, ListFocusInputs, ListFocusItem} from '../list-focus/list-focus';\n\n/**\n * Represents an item in a collection, such as a listbox option, than can be navigated to by\n * typeahead.\n */\nexport interface ListTypeaheadItem extends ListFocusItem {\n /** The text used by the typeahead search. */\n searchTerm: SignalLike<string>;\n}\n\n/**\n * Represents the required inputs for a collection that contains items that can be navigated to by\n * typeahead.\n */\nexport interface ListTypeaheadInputs<T extends ListTypeaheadItem> extends ListFocusInputs<T> {\n /** The amount of time before the typeahead search is reset. */\n typeaheadDelay: SignalLike<number>;\n}\n\n/** Controls typeahead for a list of items. */\nexport class ListTypeahead<T extends ListTypeaheadItem> {\n /** A reference to the timeout for resetting the typeahead search. */\n timeout?: ReturnType<typeof setTimeout> | undefined;\n\n /** The focus controller of the parent list. */\n focusManager: ListFocus<T>;\n\n /** Whether the user is actively typing a typeahead search query. */\n isTyping = computed(() => this._query().length > 0);\n\n /** Keeps track of the characters that typeahead search is being called with. */\n private _query = signal('');\n\n /** The index where that the typeahead search was initiated from. */\n private _startIndex = signal<number | undefined>(undefined);\n\n constructor(readonly inputs: ListTypeaheadInputs<T> & {focusManager: ListFocus<T>}) {\n this.focusManager = inputs.focusManager;\n }\n\n /** Performs a typeahead search, appending the given character to the search string. */\n search(char: string): boolean {\n if (char.length !== 1) {\n return false;\n }\n\n if (!this.isTyping() && char === ' ') {\n return false;\n }\n\n if (this._startIndex() === undefined) {\n this._startIndex.set(this.focusManager.inputs.activeIndex());\n }\n\n clearTimeout(this.timeout);\n this._query.update(q => q + char.toLowerCase());\n const item = this._getItem();\n\n if (item) {\n this.focusManager.focus(item);\n }\n\n this.timeout = setTimeout(() => {\n this._query.set('');\n this._startIndex.set(undefined);\n }, this.inputs.typeaheadDelay() * 1000);\n\n return true;\n }\n\n /**\n * Returns the first item whose search term matches the\n * current query starting from the the current anchor index.\n */\n private _getItem() {\n let items = this.focusManager.inputs.items();\n const after = items.slice(this._startIndex()! + 1);\n const before = items.slice(0, this._startIndex()!);\n items = after.concat(before);\n items.push(this.inputs.items()[this._startIndex()!]);\n\n const focusableItems = [];\n for (const item of items) {\n if (this.focusManager.isFocusable(item)) {\n focusableItems.push(item);\n }\n }\n\n return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query()));\n }\n}\n"],"names":[],"mappings":";;AA8BA;MACa,aAAa,CAAA;AAgBH,IAAA,MAAA;;AAdrB,IAAA,OAAO;;AAGP,IAAA,YAAY;;AAGZ,IAAA,QAAQ,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;;AAG3C,IAAA,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;;AAGnB,IAAA,WAAW,GAAG,MAAM,CAAqB,SAAS,CAAC;AAE3D,IAAA,WAAA,CAAqB,MAA6D,EAAA;QAA7D,IAAM,CAAA,MAAA,GAAN,MAAM;AACzB,QAAA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY;;;AAIzC,IAAA,MAAM,CAAC,IAAY,EAAA;AACjB,QAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,YAAA,OAAO,KAAK;;QAGd,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,KAAK,GAAG,EAAE;AACpC,YAAA,OAAO,KAAK;;AAGd,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE;AACpC,YAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;;AAG9D,QAAA,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;AAC1B,QAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;AAC/C,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE;QAE5B,IAAI,IAAI,EAAE;AACR,YAAA,IAAI,CAAC,YAAY,CAAC,KAAK,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as Modifier, L as ListFocus, a as ListNavigation, K as KeyboardEventManager, P as PointerEventManager } from './list-focus-Czul8jzR.mjs';
4
- import { computed, signal } from '@angular/core';
5
-
6
- /** Controls the state of a listbox. */
7
- class ListboxPattern {
8
- inputs;
9
- /** Controls navigation for the listbox. */
10
- navigation;
11
- /** Controls selection for the listbox. */
12
- selection;
13
- /** Controls typeahead for the listbox. */
14
- typeahead;
15
- /** Controls focus for the listbox. */
16
- focusManager;
17
- /** Whether the list is vertically or horizontally oriented. */
18
- orientation;
19
- /** Whether the listbox is disabled. */
20
- disabled = computed(() => this.focusManager.isListDisabled());
21
- /** Whether the listbox is readonly. */
22
- readonly;
23
- /** The tabindex of the listbox. */
24
- tabindex = computed(() => this.focusManager.getListTabindex());
25
- /** The id of the current active item. */
26
- activedescendant = computed(() => this.focusManager.getActiveDescendant());
27
- /** Whether multiple items in the list can be selected at once. */
28
- multi;
29
- /** The number of items in the listbox. */
30
- setsize = computed(() => this.navigation.inputs.items().length);
31
- /** Whether the listbox selection follows focus. */
32
- followFocus = computed(() => this.inputs.selectionMode() === 'follow');
33
- /** Whether the listbox should wrap. Used to disable wrapping while range selecting. */
34
- wrap = signal(true);
35
- /** The key used to navigate to the previous item in the list. */
36
- prevKey = computed(() => {
37
- if (this.inputs.orientation() === 'vertical') {
38
- return 'ArrowUp';
39
- }
40
- return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
41
- });
42
- /** The key used to navigate to the next item in the list. */
43
- nextKey = computed(() => {
44
- if (this.inputs.orientation() === 'vertical') {
45
- return 'ArrowDown';
46
- }
47
- return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
48
- });
49
- /** Represents the space key. Does nothing when the user is actively using typeahead. */
50
- dynamicSpaceKey = computed(() => (this.typeahead.isTyping() ? '' : ' '));
51
- /** The regexp used to decide if a key should trigger typeahead. */
52
- typeaheadRegexp = /^.$/; // TODO: Ignore spaces?
53
- /**
54
- * The uncommitted index for selecting a range of options.
55
- *
56
- * NOTE: This is subtly distinct from the "rangeStartIndex" in the ListSelection behavior.
57
- * The anchorIndex does not necessarily represent the start of a range, but represents the most
58
- * recent index where the user showed intent to begin a range selection. Usually, this is wherever
59
- * the user most recently pressed the "Shift" key, but if the user presses shift + space to select
60
- * from the anchor, the user is not intending to start a new range from this index.
61
- *
62
- * In other words, "rangeStartIndex" is only set when a user commits to starting a range selection
63
- * while "anchorIndex" is set whenever a user indicates they may be starting a range selection.
64
- */
65
- anchorIndex = signal(0);
66
- /** The keydown event manager for the listbox. */
67
- keydown = computed(() => {
68
- const manager = new KeyboardEventManager();
69
- if (this.readonly()) {
70
- return manager
71
- .on(this.prevKey, () => this.prev())
72
- .on(this.nextKey, () => this.next())
73
- .on('Home', () => this.first())
74
- .on('End', () => this.last())
75
- .on(this.typeaheadRegexp, e => this.search(e.key));
76
- }
77
- if (!this.followFocus()) {
78
- manager
79
- .on(this.prevKey, () => this.prev())
80
- .on(this.nextKey, () => this.next())
81
- .on('Home', () => this.first())
82
- .on('End', () => this.last())
83
- .on(this.typeaheadRegexp, e => this.search(e.key));
84
- }
85
- if (this.followFocus()) {
86
- manager
87
- .on(this.prevKey, () => this.prev({ selectOne: true }))
88
- .on(this.nextKey, () => this.next({ selectOne: true }))
89
- .on('Home', () => this.first({ selectOne: true }))
90
- .on('End', () => this.last({ selectOne: true }))
91
- .on(this.typeaheadRegexp, e => this.search(e.key, { selectOne: true }));
92
- }
93
- if (this.inputs.multi()) {
94
- manager
95
- .on(Modifier.Any, 'Shift', () => this.anchorIndex.set(this.inputs.activeIndex()))
96
- .on(Modifier.Shift, this.prevKey, () => this.prev({ selectRange: true }))
97
- .on(Modifier.Shift, this.nextKey, () => this.next({ selectRange: true }))
98
- .on([Modifier.Ctrl | Modifier.Shift, Modifier.Meta | Modifier.Shift], 'Home', () => this.first({ selectRange: true, anchor: false }))
99
- .on([Modifier.Ctrl | Modifier.Shift, Modifier.Meta | Modifier.Shift], 'End', () => this.last({ selectRange: true, anchor: false }))
100
- .on(Modifier.Shift, 'Enter', () => this._updateSelection({ selectRange: true, anchor: false }))
101
- .on(Modifier.Shift, this.dynamicSpaceKey, () => this._updateSelection({ selectRange: true, anchor: false }));
102
- }
103
- if (!this.followFocus() && this.inputs.multi()) {
104
- manager
105
- .on(this.dynamicSpaceKey, () => this.selection.toggle())
106
- .on('Enter', () => this.selection.toggle())
107
- .on([Modifier.Ctrl, Modifier.Meta], 'A', () => this.selection.toggleAll());
108
- }
109
- if (!this.followFocus() && !this.inputs.multi()) {
110
- manager.on(this.dynamicSpaceKey, () => this.selection.toggleOne());
111
- manager.on('Enter', () => this.selection.toggleOne());
112
- }
113
- if (this.inputs.multi() && this.followFocus()) {
114
- manager
115
- .on([Modifier.Ctrl, Modifier.Meta], this.prevKey, () => this.prev())
116
- .on([Modifier.Ctrl, Modifier.Meta], this.nextKey, () => this.next())
117
- .on([Modifier.Ctrl, Modifier.Meta], ' ', () => this.selection.toggle())
118
- .on([Modifier.Ctrl, Modifier.Meta], 'Enter', () => this.selection.toggle())
119
- .on([Modifier.Ctrl, Modifier.Meta], 'Home', () => this.first())
120
- .on([Modifier.Ctrl, Modifier.Meta], 'End', () => this.last())
121
- .on([Modifier.Ctrl, Modifier.Meta], 'A', () => {
122
- this.selection.toggleAll();
123
- this.selection.select(); // Ensure the currect option remains selected.
124
- });
125
- }
126
- return manager;
127
- });
128
- /** The pointerdown event manager for the listbox. */
129
- pointerdown = computed(() => {
130
- const manager = new PointerEventManager();
131
- if (this.readonly()) {
132
- return manager.on(e => this.goto(e));
133
- }
134
- if (this.multi()) {
135
- manager.on(Modifier.Shift, e => this.goto(e, { selectRange: true }));
136
- }
137
- if (!this.multi() && this.followFocus()) {
138
- return manager.on(e => this.goto(e, { selectOne: true }));
139
- }
140
- if (!this.multi() && !this.followFocus()) {
141
- return manager.on(e => this.goto(e, { toggle: true }));
142
- }
143
- if (this.multi() && this.followFocus()) {
144
- return manager
145
- .on(e => this.goto(e, { selectOne: true }))
146
- .on(Modifier.Ctrl, e => this.goto(e, { toggle: true }));
147
- }
148
- if (this.multi() && !this.followFocus()) {
149
- return manager.on(e => this.goto(e, { toggle: true }));
150
- }
151
- return manager;
152
- });
153
- constructor(inputs) {
154
- this.inputs = inputs;
155
- this.readonly = inputs.readonly;
156
- this.orientation = inputs.orientation;
157
- this.multi = inputs.multi;
158
- this.focusManager = new ListFocus(inputs);
159
- this.selection = new ListSelection({ ...inputs, focusManager: this.focusManager });
160
- this.typeahead = new ListTypeahead({ ...inputs, focusManager: this.focusManager });
161
- this.navigation = new ListNavigation({
162
- ...inputs,
163
- focusManager: this.focusManager,
164
- wrap: computed(() => this.wrap() && this.inputs.wrap()),
165
- });
166
- }
167
- /** Returns a set of violations */
168
- validate() {
169
- const violations = [];
170
- if (!this.inputs.multi() && this.inputs.value().length > 1) {
171
- violations.push(`A single-select listbox should not have multiple selected options. Selected options: ${this.inputs.value().join(', ')}`);
172
- }
173
- if (this.inputs.items.length &&
174
- (this.inputs.activeIndex() < 0 || this.inputs.activeIndex() >= this.inputs.items().length)) {
175
- violations.push(`The active index is out of bounds. Number of options: ${this.inputs.items().length} Active index: ${this.inputs.activeIndex()}.`);
176
- }
177
- return violations;
178
- }
179
- /** Handles keydown events for the listbox. */
180
- onKeydown(event) {
181
- if (!this.disabled()) {
182
- this.keydown().handle(event);
183
- }
184
- }
185
- onPointerdown(event) {
186
- if (!this.disabled()) {
187
- this.pointerdown().handle(event);
188
- }
189
- }
190
- /** Navigates to the first option in the listbox. */
191
- first(opts) {
192
- this._navigate(opts, () => this.navigation.first());
193
- }
194
- /** Navigates to the last option in the listbox. */
195
- last(opts) {
196
- this._navigate(opts, () => this.navigation.last());
197
- }
198
- /** Navigates to the next option in the listbox. */
199
- next(opts) {
200
- this._navigate(opts, () => this.navigation.next());
201
- }
202
- /** Navigates to the previous option in the listbox. */
203
- prev(opts) {
204
- this._navigate(opts, () => this.navigation.prev());
205
- }
206
- /** Navigates to the given item in the listbox. */
207
- goto(event, opts) {
208
- const item = this._getItem(event);
209
- this._navigate(opts, () => this.navigation.goto(item));
210
- }
211
- /** Handles typeahead search navigation for the listbox. */
212
- search(char, opts) {
213
- this._navigate(opts, () => this.typeahead.search(char));
214
- }
215
- /**
216
- * Sets the listbox to it's default initial state.
217
- *
218
- * Sets the active index of the listbox to the first focusable selected
219
- * item if one exists. Otherwise, sets focus to the first focusable item.
220
- *
221
- * This method should be called once the listbox and it's options are properly initialized,
222
- * meaning the ListboxPattern and OptionPatterns should have references to each other before this
223
- * is called.
224
- */
225
- setDefaultState() {
226
- let firstItem = null;
227
- for (const item of this.inputs.items()) {
228
- if (this.focusManager.isFocusable(item)) {
229
- if (!firstItem) {
230
- firstItem = item;
231
- }
232
- if (item.selected()) {
233
- this.inputs.activeIndex.set(item.index());
234
- return;
235
- }
236
- }
237
- }
238
- if (firstItem) {
239
- this.inputs.activeIndex.set(firstItem.index());
240
- }
241
- }
242
- /**
243
- * Safely performs a navigation operation.
244
- *
245
- * Handles conditionally disabling wrapping for when a navigation
246
- * operation is occurring while the user is selecting a range of options.
247
- *
248
- * Handles boilerplate calling of focus & selection operations. Also ensures these
249
- * additional operations are only called if the navigation operation moved focus to a new option.
250
- */
251
- _navigate(opts = {}, operation) {
252
- if (opts?.selectRange) {
253
- this.wrap.set(false);
254
- this.selection.rangeStartIndex.set(this.anchorIndex());
255
- }
256
- const moved = operation();
257
- if (moved) {
258
- this._updateSelection(opts);
259
- }
260
- this.wrap.set(true);
261
- }
262
- /** Handles updating selection for the listbox. */
263
- _updateSelection(opts = { anchor: true }) {
264
- if (opts.toggle) {
265
- this.selection.toggle();
266
- }
267
- if (opts.selectOne) {
268
- this.selection.selectOne();
269
- }
270
- if (opts.selectRange) {
271
- this.selection.selectRange();
272
- }
273
- if (!opts.anchor) {
274
- this.anchorIndex.set(this.selection.rangeStartIndex());
275
- }
276
- }
277
- _getItem(e) {
278
- if (!(e.target instanceof HTMLElement)) {
279
- return;
280
- }
281
- const element = e.target.closest('[role="option"]');
282
- return this.inputs.items().find(i => i.element() === element);
283
- }
284
- }
285
-
286
- /** Represents an option in a listbox. */
287
- class OptionPattern {
288
- /** A unique identifier for the option. */
289
- id;
290
- /** The value of the option. */
291
- value;
292
- /** The position of the option in the list. */
293
- index = computed(() => this.listbox()
294
- ?.navigation.inputs.items()
295
- .findIndex(i => i.id() === this.id()) ?? -1);
296
- /** Whether the option is active. */
297
- active = computed(() => this.listbox()?.focusManager.activeItem() === this);
298
- /** Whether the option is selected. */
299
- selected = computed(() => this.listbox()?.selection.inputs.value().includes(this.value()));
300
- /** Whether the option is disabled. */
301
- disabled;
302
- /** The text used by the typeahead search. */
303
- searchTerm;
304
- /** A reference to the parent listbox. */
305
- listbox;
306
- /** The tabindex of the option. */
307
- tabindex = computed(() => this.listbox()?.focusManager.getItemTabindex(this));
308
- /** The html element that should receive focus. */
309
- element;
310
- constructor(args) {
311
- this.id = args.id;
312
- this.value = args.value;
313
- this.listbox = args.listbox;
314
- this.element = args.element;
315
- this.disabled = args.disabled;
316
- this.searchTerm = args.searchTerm;
317
- }
318
- }
319
-
320
- export { ListboxPattern as L, OptionPattern as O };
321
- //# sourceMappingURL=option-CgeKz9_Q.mjs.map