@y14e/tabs 1.4.0 → 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 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 = getActiveElement();
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 getActiveElement() {
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
- tab.addEventListener("keydown", this.#onTabKeyDown, { signal });
940
+ this.#buttons.push(new Button(tab));
880
941
  });
881
942
  saveAttributes(this.#indicatorElements, ["style"]);
882
943
  this.#indicatorElements.forEach((indicator) => {
@@ -926,26 +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
- switch (key) {
943
- case "Enter":
944
- case " ":
945
- active.click();
946
- return;
947
- }
948
- };
949
990
  #onPanelBeforeMatch = (event) => {
950
991
  const panel = event.currentTarget;
951
992
  if (!(panel instanceof HTMLElement)) {
@@ -1074,13 +1115,6 @@ var TabsIndicator = class {
1074
1115
  function createBinding(tabs, panel) {
1075
1116
  return { tabs, panel, animation: null };
1076
1117
  }
1077
- function getActiveElement2() {
1078
- let current = document.activeElement;
1079
- while (current?.shadowRoot?.activeElement) {
1080
- current = current.shadowRoot.activeElement;
1081
- }
1082
- return current;
1083
- }
1084
1118
  function hasFocusable(container) {
1085
1119
  return !![
1086
1120
  ...container.querySelectorAll(
@@ -1095,7 +1129,7 @@ function isFocusable2(element) {
1095
1129
  * Tabs
1096
1130
  * WAI-ARIA compliant tabs pattern implementation in TypeScript.
1097
1131
  *
1098
- * @version 1.4.0
1132
+ * @version 1.5.0
1099
1133
  * @author Yusuke Kamiyamane
1100
1134
  * @license MIT
1101
1135
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -1114,6 +1148,17 @@ function isFocusable2(element) {
1114
1148
  * @see {@link https://github.com/y14e/attributes-utils}
1115
1149
  *)
1116
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
+
1117
1162
  @y14e/roving-tabindex/dist/index.js:
1118
1163
  (**
1119
1164
  * Roving Tabindex
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Tabs
3
3
  * WAI-ARIA compliant tabs pattern implementation in TypeScript.
4
4
  *
5
- * @version 1.4.0
5
+ * @version 1.5.0
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Tabs
3
3
  * WAI-ARIA compliant tabs pattern implementation in TypeScript.
4
4
  *
5
- * @version 1.4.0
5
+ * @version 1.5.0
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
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 = getActiveElement();
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 getActiveElement() {
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
- tab.addEventListener("keydown", this.#onTabKeyDown, { signal });
938
+ this.#buttons.push(new Button(tab));
878
939
  });
879
940
  saveAttributes(this.#indicatorElements, ["style"]);
880
941
  this.#indicatorElements.forEach((indicator) => {
@@ -924,26 +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
- switch (key) {
941
- case "Enter":
942
- case " ":
943
- active.click();
944
- return;
945
- }
946
- };
947
988
  #onPanelBeforeMatch = (event) => {
948
989
  const panel = event.currentTarget;
949
990
  if (!(panel instanceof HTMLElement)) {
@@ -1072,13 +1113,6 @@ var TabsIndicator = class {
1072
1113
  function createBinding(tabs, panel) {
1073
1114
  return { tabs, panel, animation: null };
1074
1115
  }
1075
- function getActiveElement2() {
1076
- let current = document.activeElement;
1077
- while (current?.shadowRoot?.activeElement) {
1078
- current = current.shadowRoot.activeElement;
1079
- }
1080
- return current;
1081
- }
1082
1116
  function hasFocusable(container) {
1083
1117
  return !![
1084
1118
  ...container.querySelectorAll(
@@ -1093,7 +1127,7 @@ function isFocusable2(element) {
1093
1127
  * Tabs
1094
1128
  * WAI-ARIA compliant tabs pattern implementation in TypeScript.
1095
1129
  *
1096
- * @version 1.4.0
1130
+ * @version 1.5.0
1097
1131
  * @author Yusuke Kamiyamane
1098
1132
  * @license MIT
1099
1133
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -1112,6 +1146,17 @@ function isFocusable2(element) {
1112
1146
  * @see {@link https://github.com/y14e/attributes-utils}
1113
1147
  *)
1114
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
+
1115
1160
  @y14e/roving-tabindex/dist/index.js:
1116
1161
  (**
1117
1162
  * Roving Tabindex
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/tabs",
3
- "version": "1.4.0",
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",