keystra 0.0.0-stage → 0.1.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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +177 -2
- package/dist/chunk-2BLQUBG7.js +816 -0
- package/dist/chunk-77GGU3AX.js +135 -0
- package/dist/chunk-KDOJARJD.js +29 -0
- package/dist/chunk-LYYUOTBP.js +125 -0
- package/dist/chunk-S5YVXIMA.js +61 -0
- package/dist/chunk-SSIKGDD4.js +255 -0
- package/dist/chunk-U7YK6PPT.js +1729 -0
- package/dist/chunk-XFNYIPOW.js +253 -0
- package/dist/chunk-ZOJRXXQN.js +308 -0
- package/dist/core.cjs +2861 -0
- package/dist/core.d.cts +41 -0
- package/dist/core.d.ts +41 -0
- package/dist/core.js +7 -0
- package/dist/engine-COPfXXTp.d.ts +229 -0
- package/dist/engine-DcbkGRgz.d.cts +229 -0
- package/dist/focus.cjs +374 -0
- package/dist/focus.d.cts +74 -0
- package/dist/focus.d.ts +74 -0
- package/dist/focus.js +2 -0
- package/dist/index-IZkcWAXP.d.cts +395 -0
- package/dist/index-IZkcWAXP.d.ts +395 -0
- package/dist/index.cjs +3745 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.global.js +1 -0
- package/dist/index.js +9 -0
- package/dist/layout-C2-n8aUI.d.ts +17 -0
- package/dist/layout-CBzD-87D.d.cts +17 -0
- package/dist/navigation.cjs +293 -0
- package/dist/navigation.d.cts +33 -0
- package/dist/navigation.d.ts +33 -0
- package/dist/navigation.js +2 -0
- package/dist/patterns.cjs +3505 -0
- package/dist/patterns.d.cts +12 -0
- package/dist/patterns.d.ts +12 -0
- package/dist/patterns.js +7 -0
- package/dist/roving-focus-CT7Dm6di.d.ts +63 -0
- package/dist/roving-focus-ZQ0v7hLe.d.cts +63 -0
- package/dist/selection.cjs +266 -0
- package/dist/selection.d.cts +43 -0
- package/dist/selection.d.ts +43 -0
- package/dist/selection.js +2 -0
- package/dist/utils-CkveVeIJ.d.cts +18 -0
- package/dist/utils-JmPZTlys.d.ts +18 -0
- package/dist/utils.cjs +195 -0
- package/dist/utils.d.cts +3 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +2 -0
- package/package.json +147 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { D as DropdownController, M as MenuController, c as createCommandPalette, a as createDropdown, b as createGrid, d as createList, e as createMenu, f as createRovingFocus, g as createTabs, h as createTree } from './roving-focus-ZQ0v7hLe.cjs';
|
|
2
|
+
export { C as CommandPaletteInstance, a as CommandPaletteOptions, c as DropdownInstance, d as DropdownOptions, G as GridInstance, h as GridOptions, L as ListOptions, M as MenuInstance, v as MenuOptions, R as RovingFocusOptions, T as TabsInstance, O as TabsOptions, Q as TreeInstance, U as TreeOptions } from './index-IZkcWAXP.cjs';
|
|
3
|
+
export { e as ensureId } from './utils-CkveVeIJ.cjs';
|
|
4
|
+
import './engine-DcbkGRgz.cjs';
|
|
5
|
+
import './focus.cjs';
|
|
6
|
+
import './selection.cjs';
|
|
7
|
+
import './layout-CBzD-87D.cjs';
|
|
8
|
+
|
|
9
|
+
declare function ensureRole(element: Element, role: string, enabled: boolean): void;
|
|
10
|
+
declare function setAria(element: Element | null | undefined, name: string, value: string | null, enabled: boolean): void;
|
|
11
|
+
|
|
12
|
+
export { ensureRole, setAria };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { D as DropdownController, M as MenuController, c as createCommandPalette, a as createDropdown, b as createGrid, d as createList, e as createMenu, f as createRovingFocus, g as createTabs, h as createTree } from './roving-focus-CT7Dm6di.js';
|
|
2
|
+
export { C as CommandPaletteInstance, a as CommandPaletteOptions, c as DropdownInstance, d as DropdownOptions, G as GridInstance, h as GridOptions, L as ListOptions, M as MenuInstance, v as MenuOptions, R as RovingFocusOptions, T as TabsInstance, O as TabsOptions, Q as TreeInstance, U as TreeOptions } from './index-IZkcWAXP.js';
|
|
3
|
+
export { e as ensureId } from './utils-JmPZTlys.js';
|
|
4
|
+
import './engine-COPfXXTp.js';
|
|
5
|
+
import './focus.js';
|
|
6
|
+
import './selection.js';
|
|
7
|
+
import './layout-C2-n8aUI.js';
|
|
8
|
+
|
|
9
|
+
declare function ensureRole(element: Element, role: string, enabled: boolean): void;
|
|
10
|
+
declare function setAria(element: Element | null | undefined, name: string, value: string | null, enabled: boolean): void;
|
|
11
|
+
|
|
12
|
+
export { ensureRole, setAria };
|
package/dist/patterns.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DropdownController, MenuController, createCommandPalette, createDropdown, createGrid, createList, createMenu, createRovingFocus, createTabs, createTree, ensureRole, setAria } from './chunk-2BLQUBG7.js';
|
|
2
|
+
import './chunk-U7YK6PPT.js';
|
|
3
|
+
import './chunk-XFNYIPOW.js';
|
|
4
|
+
import './chunk-ZOJRXXQN.js';
|
|
5
|
+
import './chunk-SSIKGDD4.js';
|
|
6
|
+
import './chunk-S5YVXIMA.js';
|
|
7
|
+
export { ensureId } from './chunk-77GGU3AX.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { O as TabsOptions, T as TabsInstance, v as MenuOptions, M as MenuInstance, K as KeyAction, d as DropdownOptions, c as DropdownInstance, L as ListOptions, t as KeystraInstance, h as GridOptions, G as GridInstance, U as TreeOptions, Q as TreeInstance, a as CommandPaletteOptions, C as CommandPaletteInstance, R as RovingFocusOptions } from './index-IZkcWAXP.js';
|
|
2
|
+
import { N as NavigationController } from './engine-COPfXXTp.js';
|
|
3
|
+
|
|
4
|
+
declare function createTabs<T extends HTMLElement = HTMLElement>(options?: TabsOptions<T>): TabsInstance<T>;
|
|
5
|
+
|
|
6
|
+
declare class MenuController<T extends HTMLElement = HTMLElement> extends NavigationController<T> implements MenuInstance<T> {
|
|
7
|
+
private openValue;
|
|
8
|
+
private readonly closeOnSelect;
|
|
9
|
+
private readonly returnFocusTarget;
|
|
10
|
+
private readonly manageAria;
|
|
11
|
+
private readonly toggleHiddenValue;
|
|
12
|
+
private unhidden;
|
|
13
|
+
private readonly userOnOpen;
|
|
14
|
+
private readonly userOnClose;
|
|
15
|
+
constructor(options: MenuOptions<T>);
|
|
16
|
+
protected decorateItems(): void;
|
|
17
|
+
get isOpen(): boolean;
|
|
18
|
+
open(options?: {
|
|
19
|
+
focus?: "first" | "last" | "current" | number;
|
|
20
|
+
}): void;
|
|
21
|
+
close(options?: {
|
|
22
|
+
restoreFocus?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
toggle(): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
protected ownsAction(action: KeyAction): boolean;
|
|
27
|
+
}
|
|
28
|
+
declare function createMenu<T extends HTMLElement = HTMLElement>(options?: MenuOptions<T>): MenuInstance<T>;
|
|
29
|
+
|
|
30
|
+
declare class DropdownController<T extends HTMLElement = HTMLElement> extends MenuController<T> implements DropdownInstance<T> {
|
|
31
|
+
private readonly triggerElement;
|
|
32
|
+
private readonly extra;
|
|
33
|
+
private readonly openMatcher;
|
|
34
|
+
private readonly manageTriggerAria;
|
|
35
|
+
private readonly closeOnBlurValue;
|
|
36
|
+
private readonly closeOnOutsidePointerValue;
|
|
37
|
+
private readonly menuId;
|
|
38
|
+
constructor(options: DropdownOptions<T>);
|
|
39
|
+
get trigger(): HTMLElement | null;
|
|
40
|
+
open(options?: {
|
|
41
|
+
focus?: "first" | "last" | "current" | number;
|
|
42
|
+
}): void;
|
|
43
|
+
close(options?: {
|
|
44
|
+
restoreFocus?: boolean;
|
|
45
|
+
}): void;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
private decorateTrigger;
|
|
48
|
+
private syncTriggerState;
|
|
49
|
+
private wireTrigger;
|
|
50
|
+
}
|
|
51
|
+
declare function createDropdown<T extends HTMLElement = HTMLElement>(options?: DropdownOptions<T>): DropdownInstance<T>;
|
|
52
|
+
|
|
53
|
+
declare function createList<T extends HTMLElement = HTMLElement>(options?: ListOptions<T>): KeystraInstance<T>;
|
|
54
|
+
|
|
55
|
+
declare function createGrid<T extends HTMLElement = HTMLElement>(options?: GridOptions<T>): GridInstance<T>;
|
|
56
|
+
|
|
57
|
+
declare function createTree<T extends HTMLElement = HTMLElement>(options?: TreeOptions<T>): TreeInstance<T>;
|
|
58
|
+
|
|
59
|
+
declare function createCommandPalette<T extends HTMLElement = HTMLElement>(options?: CommandPaletteOptions<T>): CommandPaletteInstance<T>;
|
|
60
|
+
|
|
61
|
+
declare function createRovingFocus<T extends HTMLElement = HTMLElement>(options?: RovingFocusOptions<T>): KeystraInstance<T>;
|
|
62
|
+
|
|
63
|
+
export { DropdownController as D, MenuController as M, createDropdown as a, createGrid as b, createCommandPalette as c, createList as d, createMenu as e, createRovingFocus as f, createTabs as g, createTree as h };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { O as TabsOptions, T as TabsInstance, v as MenuOptions, M as MenuInstance, K as KeyAction, d as DropdownOptions, c as DropdownInstance, L as ListOptions, t as KeystraInstance, h as GridOptions, G as GridInstance, U as TreeOptions, Q as TreeInstance, a as CommandPaletteOptions, C as CommandPaletteInstance, R as RovingFocusOptions } from './index-IZkcWAXP.cjs';
|
|
2
|
+
import { N as NavigationController } from './engine-DcbkGRgz.cjs';
|
|
3
|
+
|
|
4
|
+
declare function createTabs<T extends HTMLElement = HTMLElement>(options?: TabsOptions<T>): TabsInstance<T>;
|
|
5
|
+
|
|
6
|
+
declare class MenuController<T extends HTMLElement = HTMLElement> extends NavigationController<T> implements MenuInstance<T> {
|
|
7
|
+
private openValue;
|
|
8
|
+
private readonly closeOnSelect;
|
|
9
|
+
private readonly returnFocusTarget;
|
|
10
|
+
private readonly manageAria;
|
|
11
|
+
private readonly toggleHiddenValue;
|
|
12
|
+
private unhidden;
|
|
13
|
+
private readonly userOnOpen;
|
|
14
|
+
private readonly userOnClose;
|
|
15
|
+
constructor(options: MenuOptions<T>);
|
|
16
|
+
protected decorateItems(): void;
|
|
17
|
+
get isOpen(): boolean;
|
|
18
|
+
open(options?: {
|
|
19
|
+
focus?: "first" | "last" | "current" | number;
|
|
20
|
+
}): void;
|
|
21
|
+
close(options?: {
|
|
22
|
+
restoreFocus?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
toggle(): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
protected ownsAction(action: KeyAction): boolean;
|
|
27
|
+
}
|
|
28
|
+
declare function createMenu<T extends HTMLElement = HTMLElement>(options?: MenuOptions<T>): MenuInstance<T>;
|
|
29
|
+
|
|
30
|
+
declare class DropdownController<T extends HTMLElement = HTMLElement> extends MenuController<T> implements DropdownInstance<T> {
|
|
31
|
+
private readonly triggerElement;
|
|
32
|
+
private readonly extra;
|
|
33
|
+
private readonly openMatcher;
|
|
34
|
+
private readonly manageTriggerAria;
|
|
35
|
+
private readonly closeOnBlurValue;
|
|
36
|
+
private readonly closeOnOutsidePointerValue;
|
|
37
|
+
private readonly menuId;
|
|
38
|
+
constructor(options: DropdownOptions<T>);
|
|
39
|
+
get trigger(): HTMLElement | null;
|
|
40
|
+
open(options?: {
|
|
41
|
+
focus?: "first" | "last" | "current" | number;
|
|
42
|
+
}): void;
|
|
43
|
+
close(options?: {
|
|
44
|
+
restoreFocus?: boolean;
|
|
45
|
+
}): void;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
private decorateTrigger;
|
|
48
|
+
private syncTriggerState;
|
|
49
|
+
private wireTrigger;
|
|
50
|
+
}
|
|
51
|
+
declare function createDropdown<T extends HTMLElement = HTMLElement>(options?: DropdownOptions<T>): DropdownInstance<T>;
|
|
52
|
+
|
|
53
|
+
declare function createList<T extends HTMLElement = HTMLElement>(options?: ListOptions<T>): KeystraInstance<T>;
|
|
54
|
+
|
|
55
|
+
declare function createGrid<T extends HTMLElement = HTMLElement>(options?: GridOptions<T>): GridInstance<T>;
|
|
56
|
+
|
|
57
|
+
declare function createTree<T extends HTMLElement = HTMLElement>(options?: TreeOptions<T>): TreeInstance<T>;
|
|
58
|
+
|
|
59
|
+
declare function createCommandPalette<T extends HTMLElement = HTMLElement>(options?: CommandPaletteOptions<T>): CommandPaletteInstance<T>;
|
|
60
|
+
|
|
61
|
+
declare function createRovingFocus<T extends HTMLElement = HTMLElement>(options?: RovingFocusOptions<T>): KeystraInstance<T>;
|
|
62
|
+
|
|
63
|
+
export { DropdownController as D, MenuController as M, createDropdown as a, createGrid as b, createCommandPalette as c, createList as d, createMenu as e, createRovingFocus as f, createTabs as g, createTree as h };
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/dom.ts
|
|
4
|
+
function setAttribute(element, name, value) {
|
|
5
|
+
if (value === null) element.removeAttribute(name);
|
|
6
|
+
else if (element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
7
|
+
}
|
|
8
|
+
function toggleClass(element, name, on) {
|
|
9
|
+
if (!name) return;
|
|
10
|
+
const html = element;
|
|
11
|
+
if (typeof html.classList?.toggle === "function") html.classList.toggle(name, on);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/selection/selection-manager.ts
|
|
15
|
+
var SelectionManager = class {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.selectedItems = [];
|
|
18
|
+
this.itemsValue = [];
|
|
19
|
+
this.provider = null;
|
|
20
|
+
this.anchorElement = null;
|
|
21
|
+
this.touched = /* @__PURE__ */ new Set();
|
|
22
|
+
this.onDiff = null;
|
|
23
|
+
this.needsInitial = true;
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.modeValue = options.mode ?? "single";
|
|
26
|
+
this.attribute = options.attribute ?? null;
|
|
27
|
+
this.selectedClass = options.selectedClass;
|
|
28
|
+
this.aria = options.aria === true;
|
|
29
|
+
}
|
|
30
|
+
get mode() {
|
|
31
|
+
return this.modeValue;
|
|
32
|
+
}
|
|
33
|
+
get selected() {
|
|
34
|
+
return this.selectedItems;
|
|
35
|
+
}
|
|
36
|
+
get items() {
|
|
37
|
+
return this.provider ? this.provider() : this.itemsValue;
|
|
38
|
+
}
|
|
39
|
+
get selectedIndexes() {
|
|
40
|
+
const result = [];
|
|
41
|
+
for (let i = 0; i < this.selectedItems.length; i++) {
|
|
42
|
+
const index = this.items.indexOf(this.selectedItems[i]);
|
|
43
|
+
if (index !== -1) result.push(index);
|
|
44
|
+
}
|
|
45
|
+
return result.sort((a, b) => a - b);
|
|
46
|
+
}
|
|
47
|
+
get anchor() {
|
|
48
|
+
return this.anchorElement;
|
|
49
|
+
}
|
|
50
|
+
get size() {
|
|
51
|
+
return this.selectedItems.length;
|
|
52
|
+
}
|
|
53
|
+
bindItems(provider) {
|
|
54
|
+
this.provider = provider;
|
|
55
|
+
}
|
|
56
|
+
setDiffHandler(handler) {
|
|
57
|
+
this.onDiff = handler;
|
|
58
|
+
}
|
|
59
|
+
sync(items) {
|
|
60
|
+
if (this.itemsValue === items && !this.needsInitial) return;
|
|
61
|
+
this.itemsValue = items;
|
|
62
|
+
const current = this.items;
|
|
63
|
+
if (this.needsInitial) {
|
|
64
|
+
this.needsInitial = false;
|
|
65
|
+
this.applyInitial(this.options.initial);
|
|
66
|
+
}
|
|
67
|
+
if (this.aria || this.attribute || this.selectedClass) {
|
|
68
|
+
for (let i = 0; i < current.length; i++) {
|
|
69
|
+
const element = current[i];
|
|
70
|
+
this.paint(element, this.selectedItems.indexOf(element) !== -1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (this.touched.size > current.length) {
|
|
74
|
+
for (const element of this.touched) {
|
|
75
|
+
if (!element.isConnected && this.selectedItems.indexOf(element) === -1) this.touched.delete(element);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (this.selectedItems.length === 0 && this.anchorElement === null) return;
|
|
79
|
+
let changed = false;
|
|
80
|
+
const kept = [];
|
|
81
|
+
for (const element of this.selectedItems) {
|
|
82
|
+
if (current.indexOf(element) !== -1) kept.push(element);
|
|
83
|
+
else {
|
|
84
|
+
this.paint(element, false);
|
|
85
|
+
changed = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (this.anchorElement && current.indexOf(this.anchorElement) === -1) {
|
|
89
|
+
this.anchorElement = kept[0] ?? null;
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
if (changed) {
|
|
93
|
+
const previous = this.selectedItems;
|
|
94
|
+
this.selectedItems = kept;
|
|
95
|
+
this.options.onChange?.(this.selectedItems);
|
|
96
|
+
this.onDiff?.(this.selectedItems, [], previous.filter((element) => kept.indexOf(element) === -1));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
applyInitial(initial) {
|
|
100
|
+
if (initial == null) return;
|
|
101
|
+
const current = this.items;
|
|
102
|
+
if (typeof initial === "number") {
|
|
103
|
+
const element = current[initial];
|
|
104
|
+
if (element) this.select(element);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const list = Array.isArray(initial) ? initial : [initial];
|
|
108
|
+
for (const element of list) if (element) this.select(element, this.modeValue !== "single");
|
|
109
|
+
}
|
|
110
|
+
select(elementOrIndex, extend = false) {
|
|
111
|
+
if (this.modeValue === "none") return;
|
|
112
|
+
const element = this.resolve(elementOrIndex);
|
|
113
|
+
if (!element) return;
|
|
114
|
+
if (this.modeValue === "single" || !extend && this.modeValue !== "multiple") {
|
|
115
|
+
if (this.selectedItems.length === 1 && this.selectedItems[0] === element) {
|
|
116
|
+
this.anchorElement = element;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const removed = this.selectedItems.slice();
|
|
120
|
+
this.selectedItems = [element];
|
|
121
|
+
this.anchorElement = element;
|
|
122
|
+
for (const item of removed) this.paint(item, false);
|
|
123
|
+
this.paint(element, true);
|
|
124
|
+
this.emit(removed);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (this.modeValue === "range" && extend && this.anchorElement) {
|
|
128
|
+
this.selectRange(this.anchorElement, element);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (this.selectedItems.indexOf(element) === -1) {
|
|
132
|
+
const previous = this.selectedItems.slice();
|
|
133
|
+
this.selectedItems.push(element);
|
|
134
|
+
this.paint(element, true);
|
|
135
|
+
this.emit(previous);
|
|
136
|
+
}
|
|
137
|
+
if (!this.anchorElement) this.anchorElement = element;
|
|
138
|
+
}
|
|
139
|
+
toggle(elementOrIndex) {
|
|
140
|
+
if (this.modeValue === "none") return;
|
|
141
|
+
const element = this.resolve(elementOrIndex);
|
|
142
|
+
if (!element) return;
|
|
143
|
+
if (this.modeValue === "single") {
|
|
144
|
+
if (this.selectedItems[0] === element) this.clear();
|
|
145
|
+
else this.select(element);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const previous = this.selectedItems.slice();
|
|
149
|
+
const index = previous.indexOf(element);
|
|
150
|
+
if (index === -1) {
|
|
151
|
+
this.selectedItems.push(element);
|
|
152
|
+
this.paint(element, true);
|
|
153
|
+
} else {
|
|
154
|
+
this.selectedItems.splice(index, 1);
|
|
155
|
+
this.paint(element, false);
|
|
156
|
+
if (this.anchorElement === element) this.anchorElement = this.selectedItems[0] ?? null;
|
|
157
|
+
}
|
|
158
|
+
this.emit(previous);
|
|
159
|
+
if (!this.anchorElement && index === -1) this.anchorElement = element;
|
|
160
|
+
}
|
|
161
|
+
deselect(elementOrIndex) {
|
|
162
|
+
const element = this.resolve(elementOrIndex);
|
|
163
|
+
if (!element) return;
|
|
164
|
+
const index = this.selectedItems.indexOf(element);
|
|
165
|
+
if (index === -1) return;
|
|
166
|
+
const previous = this.selectedItems.slice();
|
|
167
|
+
this.selectedItems.splice(index, 1);
|
|
168
|
+
this.paint(element, false);
|
|
169
|
+
if (this.anchorElement === element) this.anchorElement = this.selectedItems[0] ?? null;
|
|
170
|
+
this.emit(previous);
|
|
171
|
+
}
|
|
172
|
+
selectRange(from, to) {
|
|
173
|
+
if (this.modeValue === "none") return;
|
|
174
|
+
const start = this.resolve(from);
|
|
175
|
+
const end = this.resolve(to);
|
|
176
|
+
if (!start || !end) return;
|
|
177
|
+
let a = this.items.indexOf(start);
|
|
178
|
+
let b = this.items.indexOf(end);
|
|
179
|
+
if (a === -1 || b === -1) return;
|
|
180
|
+
if (a > b) {
|
|
181
|
+
const swap = a;
|
|
182
|
+
a = b;
|
|
183
|
+
b = swap;
|
|
184
|
+
}
|
|
185
|
+
const previous = this.selectedItems.slice();
|
|
186
|
+
const next = [];
|
|
187
|
+
for (let i = a; i <= b; i++) {
|
|
188
|
+
const element = this.items[i];
|
|
189
|
+
if (element) next.push(element);
|
|
190
|
+
}
|
|
191
|
+
this.selectedItems = next;
|
|
192
|
+
this.anchorElement = start;
|
|
193
|
+
for (const element of previous) if (next.indexOf(element) === -1) this.paint(element, false);
|
|
194
|
+
for (const element of next) this.paint(element, true);
|
|
195
|
+
this.emit(previous);
|
|
196
|
+
}
|
|
197
|
+
selectAll() {
|
|
198
|
+
if (this.modeValue === "none" || this.modeValue === "single") {
|
|
199
|
+
if (this.modeValue === "single" && this.items[0]) this.select(this.items[0]);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const previous = this.selectedItems.slice();
|
|
203
|
+
this.selectedItems = this.items.slice();
|
|
204
|
+
for (const element of this.selectedItems) this.paint(element, true);
|
|
205
|
+
this.anchorElement = this.items[0] ?? null;
|
|
206
|
+
this.emit(previous);
|
|
207
|
+
}
|
|
208
|
+
clear() {
|
|
209
|
+
if (this.selectedItems.length === 0 && !this.anchorElement) return;
|
|
210
|
+
const previous = this.selectedItems.slice();
|
|
211
|
+
this.selectedItems = [];
|
|
212
|
+
this.anchorElement = null;
|
|
213
|
+
for (const element of previous) this.paint(element, false);
|
|
214
|
+
this.emit(previous);
|
|
215
|
+
}
|
|
216
|
+
isSelected(elementOrIndex) {
|
|
217
|
+
const element = this.resolve(elementOrIndex);
|
|
218
|
+
return element !== null && this.selectedItems.indexOf(element) !== -1;
|
|
219
|
+
}
|
|
220
|
+
indexOfSelected(element) {
|
|
221
|
+
return this.selectedItems.indexOf(element);
|
|
222
|
+
}
|
|
223
|
+
setMode(mode) {
|
|
224
|
+
if (mode === this.modeValue) return;
|
|
225
|
+
this.modeValue = mode;
|
|
226
|
+
if (mode === "single" && this.selectedItems.length > 1) {
|
|
227
|
+
const previous = this.selectedItems.slice();
|
|
228
|
+
this.selectedItems = previous.slice(0, 1);
|
|
229
|
+
for (const element of previous) if (this.selectedItems.indexOf(element) === -1) this.paint(element, false);
|
|
230
|
+
this.emit(previous);
|
|
231
|
+
}
|
|
232
|
+
if (mode === "none") this.clear();
|
|
233
|
+
}
|
|
234
|
+
dispose() {
|
|
235
|
+
this.provider = null;
|
|
236
|
+
for (const element of this.touched) {
|
|
237
|
+
if (this.aria) setAttribute(element, "aria-selected", null);
|
|
238
|
+
if (this.attribute) element.removeAttribute(this.attribute);
|
|
239
|
+
toggleClass(element, this.selectedClass, false);
|
|
240
|
+
}
|
|
241
|
+
this.touched.clear();
|
|
242
|
+
this.selectedItems = [];
|
|
243
|
+
this.anchorElement = null;
|
|
244
|
+
this.itemsValue = [];
|
|
245
|
+
}
|
|
246
|
+
resolve(elementOrIndex) {
|
|
247
|
+
if (elementOrIndex === void 0 || elementOrIndex === null) return null;
|
|
248
|
+
if (typeof elementOrIndex === "number") return this.items[elementOrIndex] ?? null;
|
|
249
|
+
return elementOrIndex;
|
|
250
|
+
}
|
|
251
|
+
paint(element, on) {
|
|
252
|
+
this.touched.add(element);
|
|
253
|
+
if (this.aria) setAttribute(element, "aria-selected", on ? "true" : "false");
|
|
254
|
+
if (this.attribute) setAttribute(element, this.attribute, on ? "true" : null);
|
|
255
|
+
toggleClass(element, this.selectedClass, on);
|
|
256
|
+
}
|
|
257
|
+
emit(previous) {
|
|
258
|
+
const added = this.selectedItems.filter((element) => previous.indexOf(element) === -1);
|
|
259
|
+
const removed = previous.filter((element) => this.selectedItems.indexOf(element) === -1);
|
|
260
|
+
if (added.length === 0 && removed.length === 0) return;
|
|
261
|
+
this.options.onChange?.(this.selectedItems);
|
|
262
|
+
this.onDiff?.(this.selectedItems, added, removed);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
exports.SelectionManager = SelectionManager;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { S as SelectionController, J as SelectionOptions, F as SelectionMode } from './index-IZkcWAXP.cjs';
|
|
2
|
+
|
|
3
|
+
type SelectionDiffHandler<T extends Element> = (selected: readonly T[], added: readonly T[], removed: readonly T[]) => void;
|
|
4
|
+
declare class SelectionManager<T extends Element = HTMLElement> implements SelectionController<T> {
|
|
5
|
+
private selectedItems;
|
|
6
|
+
private itemsValue;
|
|
7
|
+
private provider;
|
|
8
|
+
private anchorElement;
|
|
9
|
+
private modeValue;
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly attribute;
|
|
12
|
+
private readonly selectedClass;
|
|
13
|
+
private readonly aria;
|
|
14
|
+
private readonly touched;
|
|
15
|
+
private onDiff;
|
|
16
|
+
private needsInitial;
|
|
17
|
+
constructor(options?: SelectionOptions<T>);
|
|
18
|
+
get mode(): SelectionMode;
|
|
19
|
+
get selected(): readonly T[];
|
|
20
|
+
get items(): readonly T[];
|
|
21
|
+
get selectedIndexes(): readonly number[];
|
|
22
|
+
get anchor(): T | null;
|
|
23
|
+
get size(): number;
|
|
24
|
+
bindItems(provider: (() => readonly T[]) | null): void;
|
|
25
|
+
setDiffHandler(handler: SelectionDiffHandler<T> | null): void;
|
|
26
|
+
sync(items: readonly T[]): void;
|
|
27
|
+
applyInitial(initial: SelectionOptions<T>["initial"]): void;
|
|
28
|
+
select(elementOrIndex: T | number | undefined, extend?: boolean): void;
|
|
29
|
+
toggle(elementOrIndex: T | number | undefined): void;
|
|
30
|
+
deselect(elementOrIndex: T | number | undefined): void;
|
|
31
|
+
selectRange(from: T | number | undefined, to: T | number | undefined): void;
|
|
32
|
+
selectAll(): void;
|
|
33
|
+
clear(): void;
|
|
34
|
+
isSelected(elementOrIndex: T | number | undefined): boolean;
|
|
35
|
+
indexOfSelected(element: T): number;
|
|
36
|
+
setMode(mode: SelectionMode): void;
|
|
37
|
+
dispose(): void;
|
|
38
|
+
private resolve;
|
|
39
|
+
private paint;
|
|
40
|
+
private emit;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { SelectionController, type SelectionDiffHandler, SelectionManager, SelectionMode, SelectionOptions };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { S as SelectionController, J as SelectionOptions, F as SelectionMode } from './index-IZkcWAXP.js';
|
|
2
|
+
|
|
3
|
+
type SelectionDiffHandler<T extends Element> = (selected: readonly T[], added: readonly T[], removed: readonly T[]) => void;
|
|
4
|
+
declare class SelectionManager<T extends Element = HTMLElement> implements SelectionController<T> {
|
|
5
|
+
private selectedItems;
|
|
6
|
+
private itemsValue;
|
|
7
|
+
private provider;
|
|
8
|
+
private anchorElement;
|
|
9
|
+
private modeValue;
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly attribute;
|
|
12
|
+
private readonly selectedClass;
|
|
13
|
+
private readonly aria;
|
|
14
|
+
private readonly touched;
|
|
15
|
+
private onDiff;
|
|
16
|
+
private needsInitial;
|
|
17
|
+
constructor(options?: SelectionOptions<T>);
|
|
18
|
+
get mode(): SelectionMode;
|
|
19
|
+
get selected(): readonly T[];
|
|
20
|
+
get items(): readonly T[];
|
|
21
|
+
get selectedIndexes(): readonly number[];
|
|
22
|
+
get anchor(): T | null;
|
|
23
|
+
get size(): number;
|
|
24
|
+
bindItems(provider: (() => readonly T[]) | null): void;
|
|
25
|
+
setDiffHandler(handler: SelectionDiffHandler<T> | null): void;
|
|
26
|
+
sync(items: readonly T[]): void;
|
|
27
|
+
applyInitial(initial: SelectionOptions<T>["initial"]): void;
|
|
28
|
+
select(elementOrIndex: T | number | undefined, extend?: boolean): void;
|
|
29
|
+
toggle(elementOrIndex: T | number | undefined): void;
|
|
30
|
+
deselect(elementOrIndex: T | number | undefined): void;
|
|
31
|
+
selectRange(from: T | number | undefined, to: T | number | undefined): void;
|
|
32
|
+
selectAll(): void;
|
|
33
|
+
clear(): void;
|
|
34
|
+
isSelected(elementOrIndex: T | number | undefined): boolean;
|
|
35
|
+
indexOfSelected(element: T): number;
|
|
36
|
+
setMode(mode: SelectionMode): void;
|
|
37
|
+
dispose(): void;
|
|
38
|
+
private resolve;
|
|
39
|
+
private paint;
|
|
40
|
+
private emit;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { SelectionController, type SelectionDiffHandler, SelectionManager, SelectionMode, SelectionOptions };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { I as ItemSelector, E as ElementTarget } from './index-IZkcWAXP.cjs';
|
|
2
|
+
import './layout-CBzD-87D.cjs';
|
|
3
|
+
|
|
4
|
+
declare function hasDom(): boolean;
|
|
5
|
+
declare function resolveElement<T extends Element = Element>(target: ElementTarget<T> | EventTarget | null | undefined, root?: ParentNode | null): T | null;
|
|
6
|
+
declare function queryItems<T extends Element = Element>(container: Element | null, selector: ItemSelector<T>): T[];
|
|
7
|
+
declare function isDisabled(element: Element, selector?: string | null): boolean;
|
|
8
|
+
declare function isHidden(element: Element): boolean;
|
|
9
|
+
declare function isFocusable(element: Element): boolean;
|
|
10
|
+
declare function isEditableTarget(target: EventTarget | null, extraSelector?: string | null): boolean;
|
|
11
|
+
declare function getText(element: Element): string;
|
|
12
|
+
declare function setAttribute(element: Element, name: string, value: string | null): void;
|
|
13
|
+
declare function toggleClass(element: Element, name: string | undefined, on: boolean): void;
|
|
14
|
+
declare function focusElement(element: HTMLElement, preventScroll?: boolean): boolean;
|
|
15
|
+
declare function contains(parent: Node | null | undefined, child: Node | null | undefined): boolean;
|
|
16
|
+
declare function ensureId(element: Element, prefix: string): string;
|
|
17
|
+
|
|
18
|
+
export { isEditableTarget as a, isFocusable as b, contains as c, isHidden as d, ensureId as e, focusElement as f, getText as g, hasDom as h, isDisabled as i, queryItems as q, resolveElement as r, setAttribute as s, toggleClass as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { I as ItemSelector, E as ElementTarget } from './index-IZkcWAXP.js';
|
|
2
|
+
import './layout-C2-n8aUI.js';
|
|
3
|
+
|
|
4
|
+
declare function hasDom(): boolean;
|
|
5
|
+
declare function resolveElement<T extends Element = Element>(target: ElementTarget<T> | EventTarget | null | undefined, root?: ParentNode | null): T | null;
|
|
6
|
+
declare function queryItems<T extends Element = Element>(container: Element | null, selector: ItemSelector<T>): T[];
|
|
7
|
+
declare function isDisabled(element: Element, selector?: string | null): boolean;
|
|
8
|
+
declare function isHidden(element: Element): boolean;
|
|
9
|
+
declare function isFocusable(element: Element): boolean;
|
|
10
|
+
declare function isEditableTarget(target: EventTarget | null, extraSelector?: string | null): boolean;
|
|
11
|
+
declare function getText(element: Element): string;
|
|
12
|
+
declare function setAttribute(element: Element, name: string, value: string | null): void;
|
|
13
|
+
declare function toggleClass(element: Element, name: string | undefined, on: boolean): void;
|
|
14
|
+
declare function focusElement(element: HTMLElement, preventScroll?: boolean): boolean;
|
|
15
|
+
declare function contains(parent: Node | null | undefined, child: Node | null | undefined): boolean;
|
|
16
|
+
declare function ensureId(element: Element, prefix: string): string;
|
|
17
|
+
|
|
18
|
+
export { isEditableTarget as a, isFocusable as b, contains as c, isHidden as d, ensureId as e, focusElement as f, getText as g, hasDom as h, isDisabled as i, queryItems as q, resolveElement as r, setAttribute as s, toggleClass as t };
|