@y14e/tabs 1.4.1 → 1.5.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/dist/index.cjs +76 -26
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +76 -26
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,62 @@ function saveAttributes(elements, attributes) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// node_modules/@y14e/button/dist/index.js
|
|
54
|
+
var Button = class {
|
|
55
|
+
#element;
|
|
56
|
+
#controller = null;
|
|
57
|
+
#isDestroyed = false;
|
|
58
|
+
constructor(element) {
|
|
59
|
+
if (!(element instanceof HTMLElement)) {
|
|
60
|
+
throw new TypeError("Invalid element");
|
|
61
|
+
}
|
|
62
|
+
if (element.hasAttribute("data-button-initialized")) {
|
|
63
|
+
console.warn("Already initialized");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.#element = element;
|
|
67
|
+
this.#initialize();
|
|
68
|
+
}
|
|
69
|
+
destroy() {
|
|
70
|
+
if (this.#isDestroyed) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.#isDestroyed = true;
|
|
74
|
+
this.#controller?.abort();
|
|
75
|
+
this.#controller = null;
|
|
76
|
+
this.#element.removeAttribute("data-button-initialized");
|
|
77
|
+
}
|
|
78
|
+
#initialize() {
|
|
79
|
+
this.#controller = new AbortController();
|
|
80
|
+
this.#element.addEventListener("keydown", this.#onKeyDown, {
|
|
81
|
+
signal: this.#controller.signal
|
|
82
|
+
});
|
|
83
|
+
this.#element.setAttribute("data-button-initialized", "");
|
|
84
|
+
}
|
|
85
|
+
#onKeyDown = (event) => {
|
|
86
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
87
|
+
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!["Enter", " "].includes(key)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const active = getActiveElement();
|
|
94
|
+
if (!(active instanceof HTMLElement)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
active.click();
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
function getActiveElement() {
|
|
102
|
+
let current = document.activeElement;
|
|
103
|
+
while (current?.shadowRoot?.activeElement) {
|
|
104
|
+
current = current.shadowRoot.activeElement;
|
|
105
|
+
}
|
|
106
|
+
return current;
|
|
107
|
+
}
|
|
108
|
+
|
|
53
109
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
54
110
|
var defaultParser2 = (value) => value.split(/\s+/);
|
|
55
111
|
var defaultSerializer2 = (tokens) => tokens.join(" ");
|
|
@@ -416,7 +472,7 @@ var RovingTabIndex = class {
|
|
|
416
472
|
return;
|
|
417
473
|
}
|
|
418
474
|
}
|
|
419
|
-
const active =
|
|
475
|
+
const active = getActiveElement2();
|
|
420
476
|
if (!(active instanceof HTMLElement)) {
|
|
421
477
|
return;
|
|
422
478
|
}
|
|
@@ -542,7 +598,7 @@ var RovingTabIndex = class {
|
|
|
542
598
|
function focusElement(element) {
|
|
543
599
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
544
600
|
}
|
|
545
|
-
function
|
|
601
|
+
function getActiveElement2() {
|
|
546
602
|
let current = document.activeElement;
|
|
547
603
|
while (current?.shadowRoot?.activeElement) {
|
|
548
604
|
current = current.shadowRoot.activeElement;
|
|
@@ -589,6 +645,7 @@ var Tabs = class _Tabs {
|
|
|
589
645
|
#animationController = null;
|
|
590
646
|
#cleanupsRovingTabIndex = [];
|
|
591
647
|
#animation = null;
|
|
648
|
+
#buttons = [];
|
|
592
649
|
#indicators = [];
|
|
593
650
|
#isDestroyed = false;
|
|
594
651
|
constructor(root, options = {}) {
|
|
@@ -791,6 +848,10 @@ var Tabs = class _Tabs {
|
|
|
791
848
|
cleanup();
|
|
792
849
|
});
|
|
793
850
|
this.#cleanupsRovingTabIndex.length = 0;
|
|
851
|
+
this.#buttons.forEach((button) => {
|
|
852
|
+
button.destroy();
|
|
853
|
+
});
|
|
854
|
+
this.#buttons.length = 0;
|
|
794
855
|
this.#indicators.forEach((indicator) => {
|
|
795
856
|
indicator.destroy(force);
|
|
796
857
|
});
|
|
@@ -876,7 +937,7 @@ var Tabs = class _Tabs {
|
|
|
876
937
|
addTokenToAttribute(panel, "aria-labelledby", tab.id);
|
|
877
938
|
tab.addEventListener("click", this.#onTabClick, { signal });
|
|
878
939
|
tab.addEventListener("focus", this.#onTabFocus, { signal });
|
|
879
|
-
|
|
940
|
+
this.#buttons.push(new Button(tab));
|
|
880
941
|
});
|
|
881
942
|
saveAttributes(this.#indicatorElements, ["style"]);
|
|
882
943
|
this.#indicatorElements.forEach((indicator) => {
|
|
@@ -926,21 +987,6 @@ var Tabs = class _Tabs {
|
|
|
926
987
|
!this.#settings.manual && tab.click();
|
|
927
988
|
this.#isAvoidedTab(tab) && tab.blur();
|
|
928
989
|
};
|
|
929
|
-
#onTabKeyDown = (event) => {
|
|
930
|
-
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
931
|
-
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
if (!["Enter", " "].includes(key)) {
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
const active = getActiveElement2();
|
|
938
|
-
if (!(active instanceof HTMLElement)) {
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
event.preventDefault();
|
|
942
|
-
active.click();
|
|
943
|
-
};
|
|
944
990
|
#onPanelBeforeMatch = (event) => {
|
|
945
991
|
const panel = event.currentTarget;
|
|
946
992
|
if (!(panel instanceof HTMLElement)) {
|
|
@@ -1069,13 +1115,6 @@ var TabsIndicator = class {
|
|
|
1069
1115
|
function createBinding(tabs, panel) {
|
|
1070
1116
|
return { tabs, panel, animation: null };
|
|
1071
1117
|
}
|
|
1072
|
-
function getActiveElement2() {
|
|
1073
|
-
let current = document.activeElement;
|
|
1074
|
-
while (current?.shadowRoot?.activeElement) {
|
|
1075
|
-
current = current.shadowRoot.activeElement;
|
|
1076
|
-
}
|
|
1077
|
-
return current;
|
|
1078
|
-
}
|
|
1079
1118
|
function hasFocusable(container) {
|
|
1080
1119
|
return !![
|
|
1081
1120
|
...container.querySelectorAll(
|
|
@@ -1090,7 +1129,7 @@ function isFocusable2(element) {
|
|
|
1090
1129
|
* Tabs
|
|
1091
1130
|
* WAI-ARIA compliant tabs pattern implementation in TypeScript.
|
|
1092
1131
|
*
|
|
1093
|
-
* @version 1.
|
|
1132
|
+
* @version 1.5.0
|
|
1094
1133
|
* @author Yusuke Kamiyamane
|
|
1095
1134
|
* @license MIT
|
|
1096
1135
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -1109,6 +1148,17 @@ function isFocusable2(element) {
|
|
|
1109
1148
|
* @see {@link https://github.com/y14e/attributes-utils}
|
|
1110
1149
|
*)
|
|
1111
1150
|
|
|
1151
|
+
@y14e/button/dist/index.js:
|
|
1152
|
+
(**
|
|
1153
|
+
* Button
|
|
1154
|
+
*
|
|
1155
|
+
* @version 1.0.0
|
|
1156
|
+
* @author Yusuke Kamiyamane
|
|
1157
|
+
* @license MIT
|
|
1158
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
1159
|
+
* @see {@link https://github.com/y14e/button}
|
|
1160
|
+
*)
|
|
1161
|
+
|
|
1112
1162
|
@y14e/roving-tabindex/dist/index.js:
|
|
1113
1163
|
(**
|
|
1114
1164
|
* Roving Tabindex
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -48,6 +48,62 @@ function saveAttributes(elements, attributes) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// node_modules/@y14e/button/dist/index.js
|
|
52
|
+
var Button = class {
|
|
53
|
+
#element;
|
|
54
|
+
#controller = null;
|
|
55
|
+
#isDestroyed = false;
|
|
56
|
+
constructor(element) {
|
|
57
|
+
if (!(element instanceof HTMLElement)) {
|
|
58
|
+
throw new TypeError("Invalid element");
|
|
59
|
+
}
|
|
60
|
+
if (element.hasAttribute("data-button-initialized")) {
|
|
61
|
+
console.warn("Already initialized");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.#element = element;
|
|
65
|
+
this.#initialize();
|
|
66
|
+
}
|
|
67
|
+
destroy() {
|
|
68
|
+
if (this.#isDestroyed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.#isDestroyed = true;
|
|
72
|
+
this.#controller?.abort();
|
|
73
|
+
this.#controller = null;
|
|
74
|
+
this.#element.removeAttribute("data-button-initialized");
|
|
75
|
+
}
|
|
76
|
+
#initialize() {
|
|
77
|
+
this.#controller = new AbortController();
|
|
78
|
+
this.#element.addEventListener("keydown", this.#onKeyDown, {
|
|
79
|
+
signal: this.#controller.signal
|
|
80
|
+
});
|
|
81
|
+
this.#element.setAttribute("data-button-initialized", "");
|
|
82
|
+
}
|
|
83
|
+
#onKeyDown = (event) => {
|
|
84
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
85
|
+
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!["Enter", " "].includes(key)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const active = getActiveElement();
|
|
92
|
+
if (!(active instanceof HTMLElement)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
active.click();
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
function getActiveElement() {
|
|
100
|
+
let current = document.activeElement;
|
|
101
|
+
while (current?.shadowRoot?.activeElement) {
|
|
102
|
+
current = current.shadowRoot.activeElement;
|
|
103
|
+
}
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
|
|
51
107
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
52
108
|
var defaultParser2 = (value) => value.split(/\s+/);
|
|
53
109
|
var defaultSerializer2 = (tokens) => tokens.join(" ");
|
|
@@ -414,7 +470,7 @@ var RovingTabIndex = class {
|
|
|
414
470
|
return;
|
|
415
471
|
}
|
|
416
472
|
}
|
|
417
|
-
const active =
|
|
473
|
+
const active = getActiveElement2();
|
|
418
474
|
if (!(active instanceof HTMLElement)) {
|
|
419
475
|
return;
|
|
420
476
|
}
|
|
@@ -540,7 +596,7 @@ var RovingTabIndex = class {
|
|
|
540
596
|
function focusElement(element) {
|
|
541
597
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
542
598
|
}
|
|
543
|
-
function
|
|
599
|
+
function getActiveElement2() {
|
|
544
600
|
let current = document.activeElement;
|
|
545
601
|
while (current?.shadowRoot?.activeElement) {
|
|
546
602
|
current = current.shadowRoot.activeElement;
|
|
@@ -587,6 +643,7 @@ var Tabs = class _Tabs {
|
|
|
587
643
|
#animationController = null;
|
|
588
644
|
#cleanupsRovingTabIndex = [];
|
|
589
645
|
#animation = null;
|
|
646
|
+
#buttons = [];
|
|
590
647
|
#indicators = [];
|
|
591
648
|
#isDestroyed = false;
|
|
592
649
|
constructor(root, options = {}) {
|
|
@@ -789,6 +846,10 @@ var Tabs = class _Tabs {
|
|
|
789
846
|
cleanup();
|
|
790
847
|
});
|
|
791
848
|
this.#cleanupsRovingTabIndex.length = 0;
|
|
849
|
+
this.#buttons.forEach((button) => {
|
|
850
|
+
button.destroy();
|
|
851
|
+
});
|
|
852
|
+
this.#buttons.length = 0;
|
|
792
853
|
this.#indicators.forEach((indicator) => {
|
|
793
854
|
indicator.destroy(force);
|
|
794
855
|
});
|
|
@@ -874,7 +935,7 @@ var Tabs = class _Tabs {
|
|
|
874
935
|
addTokenToAttribute(panel, "aria-labelledby", tab.id);
|
|
875
936
|
tab.addEventListener("click", this.#onTabClick, { signal });
|
|
876
937
|
tab.addEventListener("focus", this.#onTabFocus, { signal });
|
|
877
|
-
|
|
938
|
+
this.#buttons.push(new Button(tab));
|
|
878
939
|
});
|
|
879
940
|
saveAttributes(this.#indicatorElements, ["style"]);
|
|
880
941
|
this.#indicatorElements.forEach((indicator) => {
|
|
@@ -924,21 +985,6 @@ var Tabs = class _Tabs {
|
|
|
924
985
|
!this.#settings.manual && tab.click();
|
|
925
986
|
this.#isAvoidedTab(tab) && tab.blur();
|
|
926
987
|
};
|
|
927
|
-
#onTabKeyDown = (event) => {
|
|
928
|
-
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
929
|
-
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
930
|
-
return;
|
|
931
|
-
}
|
|
932
|
-
if (!["Enter", " "].includes(key)) {
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
|
-
const active = getActiveElement2();
|
|
936
|
-
if (!(active instanceof HTMLElement)) {
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
event.preventDefault();
|
|
940
|
-
active.click();
|
|
941
|
-
};
|
|
942
988
|
#onPanelBeforeMatch = (event) => {
|
|
943
989
|
const panel = event.currentTarget;
|
|
944
990
|
if (!(panel instanceof HTMLElement)) {
|
|
@@ -1067,13 +1113,6 @@ var TabsIndicator = class {
|
|
|
1067
1113
|
function createBinding(tabs, panel) {
|
|
1068
1114
|
return { tabs, panel, animation: null };
|
|
1069
1115
|
}
|
|
1070
|
-
function getActiveElement2() {
|
|
1071
|
-
let current = document.activeElement;
|
|
1072
|
-
while (current?.shadowRoot?.activeElement) {
|
|
1073
|
-
current = current.shadowRoot.activeElement;
|
|
1074
|
-
}
|
|
1075
|
-
return current;
|
|
1076
|
-
}
|
|
1077
1116
|
function hasFocusable(container) {
|
|
1078
1117
|
return !![
|
|
1079
1118
|
...container.querySelectorAll(
|
|
@@ -1088,7 +1127,7 @@ function isFocusable2(element) {
|
|
|
1088
1127
|
* Tabs
|
|
1089
1128
|
* WAI-ARIA compliant tabs pattern implementation in TypeScript.
|
|
1090
1129
|
*
|
|
1091
|
-
* @version 1.
|
|
1130
|
+
* @version 1.5.0
|
|
1092
1131
|
* @author Yusuke Kamiyamane
|
|
1093
1132
|
* @license MIT
|
|
1094
1133
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -1107,6 +1146,17 @@ function isFocusable2(element) {
|
|
|
1107
1146
|
* @see {@link https://github.com/y14e/attributes-utils}
|
|
1108
1147
|
*)
|
|
1109
1148
|
|
|
1149
|
+
@y14e/button/dist/index.js:
|
|
1150
|
+
(**
|
|
1151
|
+
* Button
|
|
1152
|
+
*
|
|
1153
|
+
* @version 1.0.0
|
|
1154
|
+
* @author Yusuke Kamiyamane
|
|
1155
|
+
* @license MIT
|
|
1156
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
1157
|
+
* @see {@link https://github.com/y14e/button}
|
|
1158
|
+
*)
|
|
1159
|
+
|
|
1110
1160
|
@y14e/roving-tabindex/dist/index.js:
|
|
1111
1161
|
(**
|
|
1112
1162
|
* Roving Tabindex
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/tabs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "WAI-ARIA compliant tabs pattern implementation in TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"homepage": "https://github.com/y14e/tabs#readme",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@y14e/attributes-utils": "^1.0.5",
|
|
46
|
+
"@y14e/button": "^1.0.0",
|
|
46
47
|
"@y14e/roving-tabindex": "^1.3.1",
|
|
47
48
|
"bun-types": "latest",
|
|
48
49
|
"tsup": "^8.0.0",
|