@y14e/tabs 1.3.6 → 1.3.8
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 +39 -16
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +39 -16
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
var defaultParser = (value) => value.split(/\s+/);
|
|
5
|
+
var defaultSerializer = (tokens) => tokens.join(" ");
|
|
6
|
+
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
7
|
+
const {
|
|
8
|
+
caseInsensitive = false,
|
|
9
|
+
parse = defaultParser,
|
|
10
|
+
serialize = defaultSerializer
|
|
11
|
+
} = options;
|
|
12
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
13
|
+
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
14
|
+
if (caseInsensitive) {
|
|
15
|
+
const lower = token.toLowerCase();
|
|
16
|
+
if (tokens.some((token2) => token2.toLowerCase() === lower)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
tokens.push(token);
|
|
20
|
+
element.setAttribute(attribute, serialize(tokens));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const set = new Set(tokens);
|
|
24
|
+
set.add(token);
|
|
25
|
+
element.setAttribute(attribute, serialize([...set]));
|
|
10
26
|
}
|
|
11
27
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
12
28
|
function restoreAttributes(elements) {
|
|
13
|
-
|
|
29
|
+
for (const element of elements) {
|
|
14
30
|
const snapshot = snapshots.get(element);
|
|
15
31
|
if (!snapshot) {
|
|
16
|
-
|
|
32
|
+
continue;
|
|
17
33
|
}
|
|
18
34
|
for (const [attribute, value] of snapshot.entries()) {
|
|
19
|
-
|
|
20
|
-
element.removeAttribute(attribute);
|
|
21
|
-
} else {
|
|
22
|
-
element.setAttribute(attribute, value);
|
|
23
|
-
}
|
|
35
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
24
36
|
}
|
|
25
37
|
snapshots.delete(element);
|
|
26
|
-
}
|
|
38
|
+
}
|
|
27
39
|
}
|
|
28
40
|
function saveAttributes(elements, attributes) {
|
|
29
41
|
elements.forEach((element) => {
|
|
@@ -377,6 +389,7 @@ var Tabs = class _Tabs {
|
|
|
377
389
|
}
|
|
378
390
|
addTokenToAttribute(panel, "aria-labelledby", tab.id);
|
|
379
391
|
tab.addEventListener("click", this.#onTabClick, { signal });
|
|
392
|
+
tab.addEventListener("focusin", this.#onTabFocusIn, { signal });
|
|
380
393
|
tab.addEventListener("keydown", this.#onTabKeyDown, { signal });
|
|
381
394
|
});
|
|
382
395
|
this.#indicatorElements.forEach((indicator) => {
|
|
@@ -405,6 +418,16 @@ var Tabs = class _Tabs {
|
|
|
405
418
|
}
|
|
406
419
|
this.activate(tab);
|
|
407
420
|
};
|
|
421
|
+
#onTabFocusIn = (event) => {
|
|
422
|
+
const tab = event.currentTarget;
|
|
423
|
+
if (!(tab instanceof HTMLElement)) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (this.#isAvoidedTab(tab)) {
|
|
427
|
+
const active = getActiveElement();
|
|
428
|
+
active && "blur" in active && typeof active.blur === "function" && active.blur();
|
|
429
|
+
}
|
|
430
|
+
};
|
|
408
431
|
#onTabKeyDown = (event) => {
|
|
409
432
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
410
433
|
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
@@ -618,7 +641,7 @@ function isFocusable(element) {
|
|
|
618
641
|
* Tabs
|
|
619
642
|
* WAI-ARIA compliant tabs pattern implementation in TypeScript.
|
|
620
643
|
*
|
|
621
|
-
* @version 1.3.
|
|
644
|
+
* @version 1.3.8
|
|
622
645
|
* @author Yusuke Kamiyamane
|
|
623
646
|
* @license MIT
|
|
624
647
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -630,7 +653,7 @@ function isFocusable(element) {
|
|
|
630
653
|
(**
|
|
631
654
|
* Attributes Utils
|
|
632
655
|
*
|
|
633
|
-
* @version 1.0.
|
|
656
|
+
* @version 1.0.5
|
|
634
657
|
* @author Yusuke Kamiyamane
|
|
635
658
|
* @license MIT
|
|
636
659
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
var defaultParser = (value) => value.split(/\s+/);
|
|
3
|
+
var defaultSerializer = (tokens) => tokens.join(" ");
|
|
4
|
+
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
5
|
+
const {
|
|
6
|
+
caseInsensitive = false,
|
|
7
|
+
parse = defaultParser,
|
|
8
|
+
serialize = defaultSerializer
|
|
9
|
+
} = options;
|
|
10
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
11
|
+
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
12
|
+
if (caseInsensitive) {
|
|
13
|
+
const lower = token.toLowerCase();
|
|
14
|
+
if (tokens.some((token2) => token2.toLowerCase() === lower)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
tokens.push(token);
|
|
18
|
+
element.setAttribute(attribute, serialize(tokens));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const set = new Set(tokens);
|
|
22
|
+
set.add(token);
|
|
23
|
+
element.setAttribute(attribute, serialize([...set]));
|
|
8
24
|
}
|
|
9
25
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
10
26
|
function restoreAttributes(elements) {
|
|
11
|
-
|
|
27
|
+
for (const element of elements) {
|
|
12
28
|
const snapshot = snapshots.get(element);
|
|
13
29
|
if (!snapshot) {
|
|
14
|
-
|
|
30
|
+
continue;
|
|
15
31
|
}
|
|
16
32
|
for (const [attribute, value] of snapshot.entries()) {
|
|
17
|
-
|
|
18
|
-
element.removeAttribute(attribute);
|
|
19
|
-
} else {
|
|
20
|
-
element.setAttribute(attribute, value);
|
|
21
|
-
}
|
|
33
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
22
34
|
}
|
|
23
35
|
snapshots.delete(element);
|
|
24
|
-
}
|
|
36
|
+
}
|
|
25
37
|
}
|
|
26
38
|
function saveAttributes(elements, attributes) {
|
|
27
39
|
elements.forEach((element) => {
|
|
@@ -375,6 +387,7 @@ var Tabs = class _Tabs {
|
|
|
375
387
|
}
|
|
376
388
|
addTokenToAttribute(panel, "aria-labelledby", tab.id);
|
|
377
389
|
tab.addEventListener("click", this.#onTabClick, { signal });
|
|
390
|
+
tab.addEventListener("focusin", this.#onTabFocusIn, { signal });
|
|
378
391
|
tab.addEventListener("keydown", this.#onTabKeyDown, { signal });
|
|
379
392
|
});
|
|
380
393
|
this.#indicatorElements.forEach((indicator) => {
|
|
@@ -403,6 +416,16 @@ var Tabs = class _Tabs {
|
|
|
403
416
|
}
|
|
404
417
|
this.activate(tab);
|
|
405
418
|
};
|
|
419
|
+
#onTabFocusIn = (event) => {
|
|
420
|
+
const tab = event.currentTarget;
|
|
421
|
+
if (!(tab instanceof HTMLElement)) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (this.#isAvoidedTab(tab)) {
|
|
425
|
+
const active = getActiveElement();
|
|
426
|
+
active && "blur" in active && typeof active.blur === "function" && active.blur();
|
|
427
|
+
}
|
|
428
|
+
};
|
|
406
429
|
#onTabKeyDown = (event) => {
|
|
407
430
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
408
431
|
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
@@ -616,7 +639,7 @@ function isFocusable(element) {
|
|
|
616
639
|
* Tabs
|
|
617
640
|
* WAI-ARIA compliant tabs pattern implementation in TypeScript.
|
|
618
641
|
*
|
|
619
|
-
* @version 1.3.
|
|
642
|
+
* @version 1.3.8
|
|
620
643
|
* @author Yusuke Kamiyamane
|
|
621
644
|
* @license MIT
|
|
622
645
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -628,7 +651,7 @@ function isFocusable(element) {
|
|
|
628
651
|
(**
|
|
629
652
|
* Attributes Utils
|
|
630
653
|
*
|
|
631
|
-
* @version 1.0.
|
|
654
|
+
* @version 1.0.5
|
|
632
655
|
* @author Yusuke Kamiyamane
|
|
633
656
|
* @license MIT
|
|
634
657
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/tabs",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "WAI-ARIA compliant tabs pattern implementation in TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/y14e/tabs#readme",
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@y14e/attributes-utils": "^1.0.
|
|
45
|
+
"@y14e/attributes-utils": "^1.0.5",
|
|
46
46
|
"bun-types": "latest",
|
|
47
47
|
"tsup": "^8.0.0",
|
|
48
48
|
"typescript": "^5.6.0",
|