@y14e/disclosure 2.2.3 → 2.2.4

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.
@@ -344,6 +344,7 @@ function isFocusable(element, options = {}) {
344
344
  }
345
345
 
346
346
  // node_modules/@y14e/roving-tabindex/dist/index.js
347
+ var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
347
348
  function getCellCoords(cell) {
348
349
  const { left, top, width, height } = cell.getBoundingClientRect();
349
350
  return { x: left + width / 2, y: top + height / 2 };
@@ -402,7 +403,6 @@ function getNextCell(cells, key, wrap) {
402
403
  }
403
404
  return result;
404
405
  }
405
- var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
406
406
  function resolveOptions3(options) {
407
407
  let {
408
408
  direction = "both",
@@ -416,7 +416,7 @@ function resolveOptions3(options) {
416
416
  if (typeof direction === "string") {
417
417
  direction = direction.toLowerCase();
418
418
  }
419
- if (!DIRECTIONS.includes(direction)) {
419
+ if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
420
420
  console.warn("Invalid direction option. Fallback: 'both'.");
421
421
  direction = "both";
422
422
  }
@@ -516,7 +516,7 @@ var RovingTabIndex = class _RovingTabIndex {
516
516
  (!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
517
517
  };
518
518
  #onKeyDown = (event) => {
519
- const { direction, typeahead, wrap = false } = this.#settings;
519
+ const direction = this.#getDirection();
520
520
  const isGrid = direction === "grid";
521
521
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
522
522
  if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
@@ -524,6 +524,7 @@ var RovingTabIndex = class _RovingTabIndex {
524
524
  }
525
525
  const isBoth = direction === "both";
526
526
  const isHorizontal = direction === "horizontal";
527
+ const { typeahead, wrap = false } = this.#settings;
527
528
  if (![
528
529
  "End",
529
530
  "Home",
@@ -662,6 +663,14 @@ var RovingTabIndex = class _RovingTabIndex {
662
663
  #getCellsOfActiveRow() {
663
664
  return getCellsOfActiveRow(this.#getFocusables());
664
665
  }
666
+ #getDirection() {
667
+ const { direction } = this.#settings;
668
+ if (typeof direction === "string") {
669
+ return direction;
670
+ }
671
+ const d = direction();
672
+ return DIRECTIONS.includes(d) ? d : "both";
673
+ }
665
674
  #getFocusables() {
666
675
  return getFocusables(this.#container, {
667
676
  composed: true,
@@ -880,19 +889,11 @@ var Disclosure = class _Disclosure {
880
889
  if (!(summary instanceof HTMLElement)) {
881
890
  return;
882
891
  }
883
- const binding = this.#bindings.get(summary);
884
- if (!binding) {
885
- return;
886
- }
887
- const { details } = binding;
888
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
892
+ const details = this.#bindings.get(summary)?.details;
893
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
889
894
  };
890
895
  #onContentAnimationFinish(content) {
891
- const binding = this.#bindings.get(content);
892
- if (!binding) {
893
- return;
894
- }
895
- const details = binding.details;
896
+ const details = this.#bindings.get(content)?.details;
896
897
  if (!details) {
897
898
  return;
898
899
  }
@@ -342,6 +342,7 @@ function isFocusable(element, options = {}) {
342
342
  }
343
343
 
344
344
  // node_modules/@y14e/roving-tabindex/dist/index.js
345
+ var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
345
346
  function getCellCoords(cell) {
346
347
  const { left, top, width, height } = cell.getBoundingClientRect();
347
348
  return { x: left + width / 2, y: top + height / 2 };
@@ -400,7 +401,6 @@ function getNextCell(cells, key, wrap) {
400
401
  }
401
402
  return result;
402
403
  }
403
- var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
404
404
  function resolveOptions3(options) {
405
405
  let {
406
406
  direction = "both",
@@ -414,7 +414,7 @@ function resolveOptions3(options) {
414
414
  if (typeof direction === "string") {
415
415
  direction = direction.toLowerCase();
416
416
  }
417
- if (!DIRECTIONS.includes(direction)) {
417
+ if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
418
418
  console.warn("Invalid direction option. Fallback: 'both'.");
419
419
  direction = "both";
420
420
  }
@@ -514,7 +514,7 @@ var RovingTabIndex = class _RovingTabIndex {
514
514
  (!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
515
515
  };
516
516
  #onKeyDown = (event) => {
517
- const { direction, typeahead, wrap = false } = this.#settings;
517
+ const direction = this.#getDirection();
518
518
  const isGrid = direction === "grid";
519
519
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
520
520
  if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
@@ -522,6 +522,7 @@ var RovingTabIndex = class _RovingTabIndex {
522
522
  }
523
523
  const isBoth = direction === "both";
524
524
  const isHorizontal = direction === "horizontal";
525
+ const { typeahead, wrap = false } = this.#settings;
525
526
  if (![
526
527
  "End",
527
528
  "Home",
@@ -660,6 +661,14 @@ var RovingTabIndex = class _RovingTabIndex {
660
661
  #getCellsOfActiveRow() {
661
662
  return getCellsOfActiveRow(this.#getFocusables());
662
663
  }
664
+ #getDirection() {
665
+ const { direction } = this.#settings;
666
+ if (typeof direction === "string") {
667
+ return direction;
668
+ }
669
+ const d = direction();
670
+ return DIRECTIONS.includes(d) ? d : "both";
671
+ }
663
672
  #getFocusables() {
664
673
  return getFocusables(this.#container, {
665
674
  composed: true,
@@ -878,19 +887,11 @@ var Disclosure = class _Disclosure {
878
887
  if (!(summary instanceof HTMLElement)) {
879
888
  return;
880
889
  }
881
- const binding = this.#bindings.get(summary);
882
- if (!binding) {
883
- return;
884
- }
885
- const { details } = binding;
886
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
890
+ const details = this.#bindings.get(summary)?.details;
891
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
887
892
  };
888
893
  #onContentAnimationFinish(content) {
889
- const binding = this.#bindings.get(content);
890
- if (!binding) {
891
- return;
892
- }
893
- const details = binding.details;
894
+ const details = this.#bindings.get(content)?.details;
894
895
  if (!details) {
895
896
  return;
896
897
  }
package/dist/index.cjs CHANGED
@@ -210,19 +210,11 @@ var Disclosure = class _Disclosure {
210
210
  if (!(summary instanceof HTMLElement)) {
211
211
  return;
212
212
  }
213
- const binding = this.#bindings.get(summary);
214
- if (!binding) {
215
- return;
216
- }
217
- const { details } = binding;
218
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
213
+ const details = this.#bindings.get(summary)?.details;
214
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
219
215
  };
220
216
  #onContentAnimationFinish(content) {
221
- const binding = this.#bindings.get(content);
222
- if (!binding) {
223
- return;
224
- }
225
- const details = binding.details;
217
+ const details = this.#bindings.get(content)?.details;
226
218
  if (!details) {
227
219
  return;
228
220
  }
package/dist/index.js CHANGED
@@ -208,19 +208,11 @@ var Disclosure = class _Disclosure {
208
208
  if (!(summary instanceof HTMLElement)) {
209
209
  return;
210
210
  }
211
- const binding = this.#bindings.get(summary);
212
- if (!binding) {
213
- return;
214
- }
215
- const { details } = binding;
216
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
211
+ const details = this.#bindings.get(summary)?.details;
212
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
217
213
  };
218
214
  #onContentAnimationFinish(content) {
219
- const binding = this.#bindings.get(content);
220
- if (!binding) {
221
- return;
222
- }
223
- const details = binding.details;
215
+ const details = this.#bindings.get(content)?.details;
224
216
  if (!details) {
225
217
  return;
226
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/disclosure",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
5
5
  "keywords": [
6
6
  "a11y",
@@ -54,7 +54,7 @@
54
54
  "esbuild": true
55
55
  },
56
56
  "dependencies": {
57
- "@y14e/attribute-utils": "^2.0.16",
58
- "@y14e/roving-tabindex": "^3.4.1"
57
+ "@y14e/attribute-utils": "^2.0.18",
58
+ "@y14e/roving-tabindex": "^3.5.1"
59
59
  }
60
60
  }