@y14e/disclosure 2.0.0 → 2.0.2
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/README.md +6 -6
- package/dist/index.bundle.cjs +38 -32
- package/dist/index.bundle.js +38 -32
- package/dist/index.cjs +18 -9
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i @y14e/disclosure
|
|
|
13
13
|
import Disclosure from '@y14e/disclosure';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import Disclosure from 'https://esm.sh/@y14e/disclosure@2.0.
|
|
16
|
+
import Disclosure from 'https://esm.sh/@y14e/disclosure@2.0.2';
|
|
17
17
|
// or
|
|
18
|
-
import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure@2.0.
|
|
18
|
+
import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure@2.0.2/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure@2.0.
|
|
20
|
+
import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure@2.0.2';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
@@ -28,7 +28,6 @@ new Disclosure(root, options);
|
|
|
28
28
|
//
|
|
29
29
|
// root: HTMLElement
|
|
30
30
|
// options (optional): DisclosureOptions
|
|
31
|
-
|
|
32
31
|
```
|
|
33
32
|
|
|
34
33
|
## 🪄 Options
|
|
@@ -36,9 +35,10 @@ new Disclosure(root, options);
|
|
|
36
35
|
```ts
|
|
37
36
|
interface DisclosureOptions {
|
|
38
37
|
animation?: {
|
|
39
|
-
duration?: number;
|
|
40
|
-
easing?: string;
|
|
38
|
+
duration?: number; // ms (default: 300)
|
|
39
|
+
easing?: string; // <easing-function> (default: 'ease')
|
|
41
40
|
};
|
|
41
|
+
collapsible?: boolean; // default: true
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
var DEFAULT_PARSER = (value) => value.split(/\s+/);
|
|
5
5
|
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
6
6
|
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
7
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
7
8
|
const {
|
|
8
9
|
caseInsensitive = false,
|
|
9
10
|
parse = DEFAULT_PARSER,
|
|
10
11
|
serialize = DEFAULT_SERIALIZER
|
|
11
12
|
} = options;
|
|
12
|
-
const value = element.getAttribute(attribute)?.trim();
|
|
13
13
|
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
14
14
|
if (caseInsensitive) {
|
|
15
15
|
const lower = token.toLowerCase();
|
|
@@ -353,13 +353,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
353
353
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
354
354
|
wrap = false;
|
|
355
355
|
}
|
|
356
|
-
this.#settings = {
|
|
357
|
-
navigationOnly,
|
|
358
|
-
noMemory,
|
|
359
|
-
noStart,
|
|
360
|
-
typeahead,
|
|
361
|
-
wrap
|
|
362
|
-
};
|
|
356
|
+
this.#settings = { navigationOnly, noMemory, noStart, typeahead, wrap };
|
|
363
357
|
direction && Object.assign(this.#settings, { direction });
|
|
364
358
|
selector && Object.assign(this.#settings, { selector });
|
|
365
359
|
this.#selectorFilter = this.#createSelectorFilter();
|
|
@@ -378,29 +372,32 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
378
372
|
}
|
|
379
373
|
#initialize() {
|
|
380
374
|
this.#update(getActiveElement());
|
|
381
|
-
if (!(this.#container instanceof HTMLElement)) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
375
|
this.#controller = new AbortController();
|
|
385
376
|
const { signal } = this.#controller;
|
|
386
|
-
|
|
387
|
-
this.#settings.noMemory &&
|
|
377
|
+
this.#container.addEventListener("focusin", this.#onFocusIn, { signal });
|
|
378
|
+
this.#settings.noMemory && this.#container.addEventListener("focusout", this.#onFocusOut, {
|
|
379
|
+
signal
|
|
380
|
+
});
|
|
388
381
|
this.#container.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
389
382
|
}
|
|
390
383
|
#onFocusIn = (event) => {
|
|
391
|
-
|
|
392
|
-
if (!(target instanceof Element)) {
|
|
384
|
+
if (!(event instanceof FocusEvent)) {
|
|
393
385
|
return;
|
|
394
386
|
}
|
|
395
|
-
const
|
|
396
|
-
|
|
387
|
+
const { target } = event;
|
|
388
|
+
target instanceof Element && this.#update(target);
|
|
397
389
|
};
|
|
398
390
|
#onFocusOut = (event) => {
|
|
399
|
-
if (!event
|
|
400
|
-
|
|
391
|
+
if (!(event instanceof FocusEvent)) {
|
|
392
|
+
return;
|
|
401
393
|
}
|
|
394
|
+
const target = event.relatedTarget;
|
|
395
|
+
(!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
|
|
402
396
|
};
|
|
403
397
|
#onKeyDown = (event) => {
|
|
398
|
+
if (!(event instanceof KeyboardEvent)) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
404
401
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
405
402
|
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
406
403
|
return;
|
|
@@ -419,7 +416,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
419
416
|
}
|
|
420
417
|
}
|
|
421
418
|
const active = getActiveElement();
|
|
422
|
-
if (!(active instanceof
|
|
419
|
+
if (!(active instanceof Element)) {
|
|
423
420
|
return;
|
|
424
421
|
}
|
|
425
422
|
const current = this.#getFocusables();
|
|
@@ -541,7 +538,8 @@ var Disclosure = class _Disclosure {
|
|
|
541
538
|
animation: {
|
|
542
539
|
duration: 300,
|
|
543
540
|
easing: "ease"
|
|
544
|
-
}
|
|
541
|
+
},
|
|
542
|
+
collapsible: true
|
|
545
543
|
};
|
|
546
544
|
#settings;
|
|
547
545
|
#detailsElements;
|
|
@@ -596,12 +594,13 @@ var Disclosure = class _Disclosure {
|
|
|
596
594
|
this.#detailsElements.forEach((details, i) => {
|
|
597
595
|
const summary = this.#summaryElements[i];
|
|
598
596
|
const content = this.#contentElements[i];
|
|
599
|
-
if (summary
|
|
600
|
-
|
|
601
|
-
this.#bindings.set(details, binding);
|
|
602
|
-
this.#bindings.set(summary, binding);
|
|
603
|
-
this.#bindings.set(content, binding);
|
|
597
|
+
if (!summary || !content) {
|
|
598
|
+
return;
|
|
604
599
|
}
|
|
600
|
+
const binding = this.#createBinding(details, summary, content);
|
|
601
|
+
this.#bindings.set(details, binding);
|
|
602
|
+
this.#bindings.set(summary, binding);
|
|
603
|
+
this.#bindings.set(content, binding);
|
|
605
604
|
});
|
|
606
605
|
this.#initialize();
|
|
607
606
|
}
|
|
@@ -723,17 +722,22 @@ var Disclosure = class _Disclosure {
|
|
|
723
722
|
content.style.removeProperty(name2);
|
|
724
723
|
});
|
|
725
724
|
}
|
|
726
|
-
#toggle(details, isExpand) {
|
|
725
|
+
#toggle(details, isExpand, isProgrammatic = false) {
|
|
727
726
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
728
727
|
return;
|
|
729
728
|
}
|
|
729
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
730
|
+
(details2) => details2.hasAttribute("data-disclosure-open")
|
|
731
|
+
).length <= 1) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
730
734
|
const name = details.getAttribute("data-disclosure-name");
|
|
731
735
|
if (name && isExpand) {
|
|
732
736
|
details.removeAttribute("name");
|
|
733
737
|
const expanded = this.#detailsElements.find(
|
|
734
738
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
735
739
|
);
|
|
736
|
-
expanded && this.#toggle(expanded, false);
|
|
740
|
+
expanded && this.#toggle(expanded, false, true);
|
|
737
741
|
}
|
|
738
742
|
const binding = this.#bindings.get(details);
|
|
739
743
|
if (!binding) {
|
|
@@ -782,6 +786,8 @@ var Disclosure = class _Disclosure {
|
|
|
782
786
|
}
|
|
783
787
|
#mergeOptions(target, source) {
|
|
784
788
|
return {
|
|
789
|
+
...target,
|
|
790
|
+
...source,
|
|
785
791
|
animation: { ...target.animation, ...source.animation ?? {} }
|
|
786
792
|
};
|
|
787
793
|
}
|
|
@@ -804,7 +810,7 @@ function waitAnimationFinish(animation) {
|
|
|
804
810
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
805
811
|
* Using the <details> and <summary> element.
|
|
806
812
|
*
|
|
807
|
-
* @version 2.0.
|
|
813
|
+
* @version 2.0.2
|
|
808
814
|
* @author Yusuke Kamiyamane
|
|
809
815
|
* @license MIT
|
|
810
816
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -816,7 +822,7 @@ function waitAnimationFinish(animation) {
|
|
|
816
822
|
(**
|
|
817
823
|
* Attributes Utils
|
|
818
824
|
*
|
|
819
|
-
* @version 1.1.
|
|
825
|
+
* @version 1.1.3
|
|
820
826
|
* @author Yusuke Kamiyamane
|
|
821
827
|
* @license MIT
|
|
822
828
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -829,7 +835,7 @@ power-focusable/dist/index.js:
|
|
|
829
835
|
* High-precision focus management utility with full composed tree support.
|
|
830
836
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
831
837
|
*
|
|
832
|
-
* @version 4.3.
|
|
838
|
+
* @version 4.3.8
|
|
833
839
|
* @author Yusuke Kamiyamane
|
|
834
840
|
* @license MIT
|
|
835
841
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -842,7 +848,7 @@ power-focusable/dist/index.js:
|
|
|
842
848
|
* Lightweight roving tabindex utility with fully focus management.
|
|
843
849
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
844
850
|
*
|
|
845
|
-
* @version 3.1.
|
|
851
|
+
* @version 3.1.6
|
|
846
852
|
* @author Yusuke Kamiyamane
|
|
847
853
|
* @license MIT
|
|
848
854
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
var DEFAULT_PARSER = (value) => value.split(/\s+/);
|
|
3
3
|
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
4
4
|
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
5
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
5
6
|
const {
|
|
6
7
|
caseInsensitive = false,
|
|
7
8
|
parse = DEFAULT_PARSER,
|
|
8
9
|
serialize = DEFAULT_SERIALIZER
|
|
9
10
|
} = options;
|
|
10
|
-
const value = element.getAttribute(attribute)?.trim();
|
|
11
11
|
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
12
12
|
if (caseInsensitive) {
|
|
13
13
|
const lower = token.toLowerCase();
|
|
@@ -351,13 +351,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
351
351
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
352
352
|
wrap = false;
|
|
353
353
|
}
|
|
354
|
-
this.#settings = {
|
|
355
|
-
navigationOnly,
|
|
356
|
-
noMemory,
|
|
357
|
-
noStart,
|
|
358
|
-
typeahead,
|
|
359
|
-
wrap
|
|
360
|
-
};
|
|
354
|
+
this.#settings = { navigationOnly, noMemory, noStart, typeahead, wrap };
|
|
361
355
|
direction && Object.assign(this.#settings, { direction });
|
|
362
356
|
selector && Object.assign(this.#settings, { selector });
|
|
363
357
|
this.#selectorFilter = this.#createSelectorFilter();
|
|
@@ -376,29 +370,32 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
376
370
|
}
|
|
377
371
|
#initialize() {
|
|
378
372
|
this.#update(getActiveElement());
|
|
379
|
-
if (!(this.#container instanceof HTMLElement)) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
373
|
this.#controller = new AbortController();
|
|
383
374
|
const { signal } = this.#controller;
|
|
384
|
-
|
|
385
|
-
this.#settings.noMemory &&
|
|
375
|
+
this.#container.addEventListener("focusin", this.#onFocusIn, { signal });
|
|
376
|
+
this.#settings.noMemory && this.#container.addEventListener("focusout", this.#onFocusOut, {
|
|
377
|
+
signal
|
|
378
|
+
});
|
|
386
379
|
this.#container.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
387
380
|
}
|
|
388
381
|
#onFocusIn = (event) => {
|
|
389
|
-
|
|
390
|
-
if (!(target instanceof Element)) {
|
|
382
|
+
if (!(event instanceof FocusEvent)) {
|
|
391
383
|
return;
|
|
392
384
|
}
|
|
393
|
-
const
|
|
394
|
-
|
|
385
|
+
const { target } = event;
|
|
386
|
+
target instanceof Element && this.#update(target);
|
|
395
387
|
};
|
|
396
388
|
#onFocusOut = (event) => {
|
|
397
|
-
if (!event
|
|
398
|
-
|
|
389
|
+
if (!(event instanceof FocusEvent)) {
|
|
390
|
+
return;
|
|
399
391
|
}
|
|
392
|
+
const target = event.relatedTarget;
|
|
393
|
+
(!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
|
|
400
394
|
};
|
|
401
395
|
#onKeyDown = (event) => {
|
|
396
|
+
if (!(event instanceof KeyboardEvent)) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
402
399
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
403
400
|
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
404
401
|
return;
|
|
@@ -417,7 +414,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
417
414
|
}
|
|
418
415
|
}
|
|
419
416
|
const active = getActiveElement();
|
|
420
|
-
if (!(active instanceof
|
|
417
|
+
if (!(active instanceof Element)) {
|
|
421
418
|
return;
|
|
422
419
|
}
|
|
423
420
|
const current = this.#getFocusables();
|
|
@@ -539,7 +536,8 @@ var Disclosure = class _Disclosure {
|
|
|
539
536
|
animation: {
|
|
540
537
|
duration: 300,
|
|
541
538
|
easing: "ease"
|
|
542
|
-
}
|
|
539
|
+
},
|
|
540
|
+
collapsible: true
|
|
543
541
|
};
|
|
544
542
|
#settings;
|
|
545
543
|
#detailsElements;
|
|
@@ -594,12 +592,13 @@ var Disclosure = class _Disclosure {
|
|
|
594
592
|
this.#detailsElements.forEach((details, i) => {
|
|
595
593
|
const summary = this.#summaryElements[i];
|
|
596
594
|
const content = this.#contentElements[i];
|
|
597
|
-
if (summary
|
|
598
|
-
|
|
599
|
-
this.#bindings.set(details, binding);
|
|
600
|
-
this.#bindings.set(summary, binding);
|
|
601
|
-
this.#bindings.set(content, binding);
|
|
595
|
+
if (!summary || !content) {
|
|
596
|
+
return;
|
|
602
597
|
}
|
|
598
|
+
const binding = this.#createBinding(details, summary, content);
|
|
599
|
+
this.#bindings.set(details, binding);
|
|
600
|
+
this.#bindings.set(summary, binding);
|
|
601
|
+
this.#bindings.set(content, binding);
|
|
603
602
|
});
|
|
604
603
|
this.#initialize();
|
|
605
604
|
}
|
|
@@ -721,17 +720,22 @@ var Disclosure = class _Disclosure {
|
|
|
721
720
|
content.style.removeProperty(name2);
|
|
722
721
|
});
|
|
723
722
|
}
|
|
724
|
-
#toggle(details, isExpand) {
|
|
723
|
+
#toggle(details, isExpand, isProgrammatic = false) {
|
|
725
724
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
726
725
|
return;
|
|
727
726
|
}
|
|
727
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
728
|
+
(details2) => details2.hasAttribute("data-disclosure-open")
|
|
729
|
+
).length <= 1) {
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
728
732
|
const name = details.getAttribute("data-disclosure-name");
|
|
729
733
|
if (name && isExpand) {
|
|
730
734
|
details.removeAttribute("name");
|
|
731
735
|
const expanded = this.#detailsElements.find(
|
|
732
736
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
733
737
|
);
|
|
734
|
-
expanded && this.#toggle(expanded, false);
|
|
738
|
+
expanded && this.#toggle(expanded, false, true);
|
|
735
739
|
}
|
|
736
740
|
const binding = this.#bindings.get(details);
|
|
737
741
|
if (!binding) {
|
|
@@ -780,6 +784,8 @@ var Disclosure = class _Disclosure {
|
|
|
780
784
|
}
|
|
781
785
|
#mergeOptions(target, source) {
|
|
782
786
|
return {
|
|
787
|
+
...target,
|
|
788
|
+
...source,
|
|
783
789
|
animation: { ...target.animation, ...source.animation ?? {} }
|
|
784
790
|
};
|
|
785
791
|
}
|
|
@@ -802,7 +808,7 @@ function waitAnimationFinish(animation) {
|
|
|
802
808
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
803
809
|
* Using the <details> and <summary> element.
|
|
804
810
|
*
|
|
805
|
-
* @version 2.0.
|
|
811
|
+
* @version 2.0.2
|
|
806
812
|
* @author Yusuke Kamiyamane
|
|
807
813
|
* @license MIT
|
|
808
814
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -814,7 +820,7 @@ function waitAnimationFinish(animation) {
|
|
|
814
820
|
(**
|
|
815
821
|
* Attributes Utils
|
|
816
822
|
*
|
|
817
|
-
* @version 1.1.
|
|
823
|
+
* @version 1.1.3
|
|
818
824
|
* @author Yusuke Kamiyamane
|
|
819
825
|
* @license MIT
|
|
820
826
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -827,7 +833,7 @@ power-focusable/dist/index.js:
|
|
|
827
833
|
* High-precision focus management utility with full composed tree support.
|
|
828
834
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
829
835
|
*
|
|
830
|
-
* @version 4.3.
|
|
836
|
+
* @version 4.3.8
|
|
831
837
|
* @author Yusuke Kamiyamane
|
|
832
838
|
* @license MIT
|
|
833
839
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -840,7 +846,7 @@ power-focusable/dist/index.js:
|
|
|
840
846
|
* Lightweight roving tabindex utility with fully focus management.
|
|
841
847
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
842
848
|
*
|
|
843
|
-
* @version 3.1.
|
|
849
|
+
* @version 3.1.6
|
|
844
850
|
* @author Yusuke Kamiyamane
|
|
845
851
|
* @license MIT
|
|
846
852
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,8 @@ var Disclosure = class _Disclosure {
|
|
|
11
11
|
animation: {
|
|
12
12
|
duration: 300,
|
|
13
13
|
easing: "ease"
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
collapsible: true
|
|
15
16
|
};
|
|
16
17
|
#settings;
|
|
17
18
|
#detailsElements;
|
|
@@ -66,12 +67,13 @@ var Disclosure = class _Disclosure {
|
|
|
66
67
|
this.#detailsElements.forEach((details, i) => {
|
|
67
68
|
const summary = this.#summaryElements[i];
|
|
68
69
|
const content = this.#contentElements[i];
|
|
69
|
-
if (summary
|
|
70
|
-
|
|
71
|
-
this.#bindings.set(details, binding);
|
|
72
|
-
this.#bindings.set(summary, binding);
|
|
73
|
-
this.#bindings.set(content, binding);
|
|
70
|
+
if (!summary || !content) {
|
|
71
|
+
return;
|
|
74
72
|
}
|
|
73
|
+
const binding = this.#createBinding(details, summary, content);
|
|
74
|
+
this.#bindings.set(details, binding);
|
|
75
|
+
this.#bindings.set(summary, binding);
|
|
76
|
+
this.#bindings.set(content, binding);
|
|
75
77
|
});
|
|
76
78
|
this.#initialize();
|
|
77
79
|
}
|
|
@@ -193,17 +195,22 @@ var Disclosure = class _Disclosure {
|
|
|
193
195
|
content.style.removeProperty(name2);
|
|
194
196
|
});
|
|
195
197
|
}
|
|
196
|
-
#toggle(details, isExpand) {
|
|
198
|
+
#toggle(details, isExpand, isProgrammatic = false) {
|
|
197
199
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
198
200
|
return;
|
|
199
201
|
}
|
|
202
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
203
|
+
(details2) => details2.hasAttribute("data-disclosure-open")
|
|
204
|
+
).length <= 1) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
200
207
|
const name = details.getAttribute("data-disclosure-name");
|
|
201
208
|
if (name && isExpand) {
|
|
202
209
|
details.removeAttribute("name");
|
|
203
210
|
const expanded = this.#detailsElements.find(
|
|
204
211
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
205
212
|
);
|
|
206
|
-
expanded && this.#toggle(expanded, false);
|
|
213
|
+
expanded && this.#toggle(expanded, false, true);
|
|
207
214
|
}
|
|
208
215
|
const binding = this.#bindings.get(details);
|
|
209
216
|
if (!binding) {
|
|
@@ -252,6 +259,8 @@ var Disclosure = class _Disclosure {
|
|
|
252
259
|
}
|
|
253
260
|
#mergeOptions(target, source) {
|
|
254
261
|
return {
|
|
262
|
+
...target,
|
|
263
|
+
...source,
|
|
255
264
|
animation: { ...target.animation, ...source.animation ?? {} }
|
|
256
265
|
};
|
|
257
266
|
}
|
|
@@ -274,7 +283,7 @@ function waitAnimationFinish(animation) {
|
|
|
274
283
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
275
284
|
* Using the <details> and <summary> element.
|
|
276
285
|
*
|
|
277
|
-
* @version 2.0.
|
|
286
|
+
* @version 2.0.2
|
|
278
287
|
* @author Yusuke Kamiyamane
|
|
279
288
|
* @license MIT
|
|
280
289
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
4
4
|
* Using the <details> and <summary> element.
|
|
5
5
|
*
|
|
6
|
-
* @version 2.0.
|
|
6
|
+
* @version 2.0.2
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -14,6 +14,7 @@ interface DisclosureOptions {
|
|
|
14
14
|
readonly duration?: number;
|
|
15
15
|
readonly easing?: string;
|
|
16
16
|
};
|
|
17
|
+
readonly collapsible?: boolean;
|
|
17
18
|
}
|
|
18
19
|
declare class Disclosure {
|
|
19
20
|
#private;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
4
4
|
* Using the <details> and <summary> element.
|
|
5
5
|
*
|
|
6
|
-
* @version 2.0.
|
|
6
|
+
* @version 2.0.2
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -14,6 +14,7 @@ interface DisclosureOptions {
|
|
|
14
14
|
readonly duration?: number;
|
|
15
15
|
readonly easing?: string;
|
|
16
16
|
};
|
|
17
|
+
readonly collapsible?: boolean;
|
|
17
18
|
}
|
|
18
19
|
declare class Disclosure {
|
|
19
20
|
#private;
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ var Disclosure = class _Disclosure {
|
|
|
9
9
|
animation: {
|
|
10
10
|
duration: 300,
|
|
11
11
|
easing: "ease"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
collapsible: true
|
|
13
14
|
};
|
|
14
15
|
#settings;
|
|
15
16
|
#detailsElements;
|
|
@@ -64,12 +65,13 @@ var Disclosure = class _Disclosure {
|
|
|
64
65
|
this.#detailsElements.forEach((details, i) => {
|
|
65
66
|
const summary = this.#summaryElements[i];
|
|
66
67
|
const content = this.#contentElements[i];
|
|
67
|
-
if (summary
|
|
68
|
-
|
|
69
|
-
this.#bindings.set(details, binding);
|
|
70
|
-
this.#bindings.set(summary, binding);
|
|
71
|
-
this.#bindings.set(content, binding);
|
|
68
|
+
if (!summary || !content) {
|
|
69
|
+
return;
|
|
72
70
|
}
|
|
71
|
+
const binding = this.#createBinding(details, summary, content);
|
|
72
|
+
this.#bindings.set(details, binding);
|
|
73
|
+
this.#bindings.set(summary, binding);
|
|
74
|
+
this.#bindings.set(content, binding);
|
|
73
75
|
});
|
|
74
76
|
this.#initialize();
|
|
75
77
|
}
|
|
@@ -191,17 +193,22 @@ var Disclosure = class _Disclosure {
|
|
|
191
193
|
content.style.removeProperty(name2);
|
|
192
194
|
});
|
|
193
195
|
}
|
|
194
|
-
#toggle(details, isExpand) {
|
|
196
|
+
#toggle(details, isExpand, isProgrammatic = false) {
|
|
195
197
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
196
198
|
return;
|
|
197
199
|
}
|
|
200
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
201
|
+
(details2) => details2.hasAttribute("data-disclosure-open")
|
|
202
|
+
).length <= 1) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
198
205
|
const name = details.getAttribute("data-disclosure-name");
|
|
199
206
|
if (name && isExpand) {
|
|
200
207
|
details.removeAttribute("name");
|
|
201
208
|
const expanded = this.#detailsElements.find(
|
|
202
209
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
203
210
|
);
|
|
204
|
-
expanded && this.#toggle(expanded, false);
|
|
211
|
+
expanded && this.#toggle(expanded, false, true);
|
|
205
212
|
}
|
|
206
213
|
const binding = this.#bindings.get(details);
|
|
207
214
|
if (!binding) {
|
|
@@ -250,6 +257,8 @@ var Disclosure = class _Disclosure {
|
|
|
250
257
|
}
|
|
251
258
|
#mergeOptions(target, source) {
|
|
252
259
|
return {
|
|
260
|
+
...target,
|
|
261
|
+
...source,
|
|
253
262
|
animation: { ...target.animation, ...source.animation ?? {} }
|
|
254
263
|
};
|
|
255
264
|
}
|
|
@@ -272,7 +281,7 @@ function waitAnimationFinish(animation) {
|
|
|
272
281
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
273
282
|
* Using the <details> and <summary> element.
|
|
274
283
|
*
|
|
275
|
-
* @version 2.0.
|
|
284
|
+
* @version 2.0.2
|
|
276
285
|
* @author Yusuke Kamiyamane
|
|
277
286
|
* @license MIT
|
|
278
287
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"node": ">=18"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@y14e/attributes-utils": "^1.1.
|
|
56
|
-
"@y14e/roving-tabindex": "^3.1.
|
|
55
|
+
"@y14e/attributes-utils": "^1.1.3",
|
|
56
|
+
"@y14e/roving-tabindex": "^3.1.6"
|
|
57
57
|
}
|
|
58
58
|
}
|