@y14e/portal 1.4.2 → 1.4.3

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 CHANGED
@@ -13,11 +13,11 @@ npm i @y14e/portal
13
13
  import { createPortal } from '@y14e/portal';
14
14
 
15
15
  // CDNs
16
- import { createPortal } from 'https://esm.sh/@y14e/portal@1.4.2';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@<x.x.x>';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.4.2/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@<x.x.x>/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.4.2';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@<x.x.x>';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -47,7 +47,16 @@ function getFocusables(container = document.body, options = {}) {
47
47
  skipVisibilityCheck
48
48
  } = resolveOptions(options);
49
49
  const candidates = [];
50
- if (composed || include) {
50
+ if (!composed && !include) {
51
+ for (const match of container.querySelectorAll(
52
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
53
+ )) {
54
+ match && isFocusable(match, {
55
+ skipNegativeTabIndexCheck,
56
+ skipVisibilityCheck
57
+ }) && candidates.push(match);
58
+ }
59
+ } else {
51
60
  let traverse2 = function(node) {
52
61
  if (isFocusable(node, {
53
62
  skipNegativeTabIndexCheck,
@@ -55,23 +64,16 @@ function getFocusables(container = document.body, options = {}) {
55
64
  }) || include?.(node)) {
56
65
  candidates.push(node);
57
66
  }
58
- (composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
67
+ (!composed ? [...node.children] : getComposedChildren(node)).map(
68
+ traverse2
69
+ );
59
70
  };
60
- (composed ? getComposedChildren(container) : [...container.children]).map(
71
+ (!composed ? [...container.children] : getComposedChildren(container)).map(
61
72
  traverse2
62
73
  );
63
- } else {
64
- for (const match of container.querySelectorAll(
65
- skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
66
- )) {
67
- match && isFocusable(match, {
68
- skipNegativeTabIndexCheck,
69
- skipVisibilityCheck
70
- }) && candidates.push(match);
71
- }
72
74
  }
73
75
  return normalizeRadioGroup(
74
- sortByTabIndex(filter ? candidates.filter(filter) : candidates)
76
+ sortByTabIndex(!filter ? candidates : candidates.filter(filter))
75
77
  );
76
78
  }
77
79
  function getNextFocusable(container = document.body, options = {}) {
@@ -93,7 +95,7 @@ function isFocusable(element, options = {}) {
93
95
  return false;
94
96
  }
95
97
  if (!element.matches(
96
- skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
98
+ !skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
97
99
  )) {
98
100
  return false;
99
101
  }
@@ -237,9 +239,8 @@ function containsComposed(container, element) {
237
239
  while (current) {
238
240
  if (current === container) {
239
241
  return true;
240
- } else {
241
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
242
242
  }
243
+ current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
243
244
  }
244
245
  return false;
245
246
  }
@@ -278,8 +279,7 @@ function isDisabled(element) {
278
279
  return "disabled" in element && !!element.disabled;
279
280
  }
280
281
  function isFormControl(element) {
281
- const name = element.tagName;
282
- return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
282
+ return ["BUTTON", "INPUT", "SELECT", "TEXTAREA"].includes(element.tagName);
283
283
  }
284
284
  function isInert(element) {
285
285
  return "inert" in element && !!element.inert;
@@ -425,15 +425,15 @@ var Portal = class {
425
425
  this.#update();
426
426
  const first = [...this.#focusables][0];
427
427
  first ? focusElement(first) : this.#moveFocus("next");
428
- } else {
429
- if (this.#host.contains(previous)) {
430
- this.#moveFocus("next");
431
- return;
432
- }
433
- this.#update();
434
- const last = [...this.#focusables].at(-1);
435
- last ? focusElement(last) : this.#moveFocus("previous");
428
+ return;
429
+ }
430
+ if (this.#host.contains(previous)) {
431
+ this.#moveFocus("next");
432
+ return;
436
433
  }
434
+ this.#update();
435
+ const last = [...this.#focusables].at(-1);
436
+ last ? focusElement(last) : this.#moveFocus("previous");
437
437
  };
438
438
  #onKeyDown = (event) => {
439
439
  if (!(event instanceof KeyboardEvent)) {
@@ -456,10 +456,10 @@ var Portal = class {
456
456
  const focusable = focusables[index + (shiftKey ? -1 : 1)];
457
457
  focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
458
458
  }
459
- } else {
460
- event.preventDefault();
461
- this.#moveFocus(shiftKey ? "previous" : "next");
459
+ return;
462
460
  }
461
+ event.preventDefault();
462
+ this.#moveFocus(shiftKey ? "previous" : "next");
463
463
  };
464
464
  #update() {
465
465
  const current = /* @__PURE__ */ new Set([
@@ -45,7 +45,16 @@ function getFocusables(container = document.body, options = {}) {
45
45
  skipVisibilityCheck
46
46
  } = resolveOptions(options);
47
47
  const candidates = [];
48
- if (composed || include) {
48
+ if (!composed && !include) {
49
+ for (const match of container.querySelectorAll(
50
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
51
+ )) {
52
+ match && isFocusable(match, {
53
+ skipNegativeTabIndexCheck,
54
+ skipVisibilityCheck
55
+ }) && candidates.push(match);
56
+ }
57
+ } else {
49
58
  let traverse2 = function(node) {
50
59
  if (isFocusable(node, {
51
60
  skipNegativeTabIndexCheck,
@@ -53,23 +62,16 @@ function getFocusables(container = document.body, options = {}) {
53
62
  }) || include?.(node)) {
54
63
  candidates.push(node);
55
64
  }
56
- (composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
65
+ (!composed ? [...node.children] : getComposedChildren(node)).map(
66
+ traverse2
67
+ );
57
68
  };
58
- (composed ? getComposedChildren(container) : [...container.children]).map(
69
+ (!composed ? [...container.children] : getComposedChildren(container)).map(
59
70
  traverse2
60
71
  );
61
- } else {
62
- for (const match of container.querySelectorAll(
63
- skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
64
- )) {
65
- match && isFocusable(match, {
66
- skipNegativeTabIndexCheck,
67
- skipVisibilityCheck
68
- }) && candidates.push(match);
69
- }
70
72
  }
71
73
  return normalizeRadioGroup(
72
- sortByTabIndex(filter ? candidates.filter(filter) : candidates)
74
+ sortByTabIndex(!filter ? candidates : candidates.filter(filter))
73
75
  );
74
76
  }
75
77
  function getNextFocusable(container = document.body, options = {}) {
@@ -91,7 +93,7 @@ function isFocusable(element, options = {}) {
91
93
  return false;
92
94
  }
93
95
  if (!element.matches(
94
- skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
96
+ !skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
95
97
  )) {
96
98
  return false;
97
99
  }
@@ -235,9 +237,8 @@ function containsComposed(container, element) {
235
237
  while (current) {
236
238
  if (current === container) {
237
239
  return true;
238
- } else {
239
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
240
240
  }
241
+ current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
241
242
  }
242
243
  return false;
243
244
  }
@@ -276,8 +277,7 @@ function isDisabled(element) {
276
277
  return "disabled" in element && !!element.disabled;
277
278
  }
278
279
  function isFormControl(element) {
279
- const name = element.tagName;
280
- return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
280
+ return ["BUTTON", "INPUT", "SELECT", "TEXTAREA"].includes(element.tagName);
281
281
  }
282
282
  function isInert(element) {
283
283
  return "inert" in element && !!element.inert;
@@ -423,15 +423,15 @@ var Portal = class {
423
423
  this.#update();
424
424
  const first = [...this.#focusables][0];
425
425
  first ? focusElement(first) : this.#moveFocus("next");
426
- } else {
427
- if (this.#host.contains(previous)) {
428
- this.#moveFocus("next");
429
- return;
430
- }
431
- this.#update();
432
- const last = [...this.#focusables].at(-1);
433
- last ? focusElement(last) : this.#moveFocus("previous");
426
+ return;
427
+ }
428
+ if (this.#host.contains(previous)) {
429
+ this.#moveFocus("next");
430
+ return;
434
431
  }
432
+ this.#update();
433
+ const last = [...this.#focusables].at(-1);
434
+ last ? focusElement(last) : this.#moveFocus("previous");
435
435
  };
436
436
  #onKeyDown = (event) => {
437
437
  if (!(event instanceof KeyboardEvent)) {
@@ -454,10 +454,10 @@ var Portal = class {
454
454
  const focusable = focusables[index + (shiftKey ? -1 : 1)];
455
455
  focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
456
456
  }
457
- } else {
458
- event.preventDefault();
459
- this.#moveFocus(shiftKey ? "previous" : "next");
457
+ return;
460
458
  }
459
+ event.preventDefault();
460
+ this.#moveFocus(shiftKey ? "previous" : "next");
461
461
  };
462
462
  #update() {
463
463
  const current = /* @__PURE__ */ new Set([
package/dist/index.cjs CHANGED
@@ -85,15 +85,15 @@ var Portal = class {
85
85
  this.#update();
86
86
  const first = [...this.#focusables][0];
87
87
  first ? powerFocusable.focusElement(first) : this.#moveFocus("next");
88
- } else {
89
- if (this.#host.contains(previous)) {
90
- this.#moveFocus("next");
91
- return;
92
- }
93
- this.#update();
94
- const last = [...this.#focusables].at(-1);
95
- last ? powerFocusable.focusElement(last) : this.#moveFocus("previous");
88
+ return;
96
89
  }
90
+ if (this.#host.contains(previous)) {
91
+ this.#moveFocus("next");
92
+ return;
93
+ }
94
+ this.#update();
95
+ const last = [...this.#focusables].at(-1);
96
+ last ? powerFocusable.focusElement(last) : this.#moveFocus("previous");
97
97
  };
98
98
  #onKeyDown = (event) => {
99
99
  if (!(event instanceof KeyboardEvent)) {
@@ -116,10 +116,10 @@ var Portal = class {
116
116
  const focusable = focusables[index + (shiftKey ? -1 : 1)];
117
117
  focusable ? powerFocusable.focusElement(focusable) : this.#focusSentinel(shiftKey);
118
118
  }
119
- } else {
120
- event.preventDefault();
121
- this.#moveFocus(shiftKey ? "previous" : "next");
119
+ return;
122
120
  }
121
+ event.preventDefault();
122
+ this.#moveFocus(shiftKey ? "previous" : "next");
123
123
  };
124
124
  #update() {
125
125
  const current = /* @__PURE__ */ new Set([
package/dist/index.js CHANGED
@@ -83,15 +83,15 @@ var Portal = class {
83
83
  this.#update();
84
84
  const first = [...this.#focusables][0];
85
85
  first ? focusElement(first) : this.#moveFocus("next");
86
- } else {
87
- if (this.#host.contains(previous)) {
88
- this.#moveFocus("next");
89
- return;
90
- }
91
- this.#update();
92
- const last = [...this.#focusables].at(-1);
93
- last ? focusElement(last) : this.#moveFocus("previous");
86
+ return;
94
87
  }
88
+ if (this.#host.contains(previous)) {
89
+ this.#moveFocus("next");
90
+ return;
91
+ }
92
+ this.#update();
93
+ const last = [...this.#focusables].at(-1);
94
+ last ? focusElement(last) : this.#moveFocus("previous");
95
95
  };
96
96
  #onKeyDown = (event) => {
97
97
  if (!(event instanceof KeyboardEvent)) {
@@ -114,10 +114,10 @@ var Portal = class {
114
114
  const focusable = focusables[index + (shiftKey ? -1 : 1)];
115
115
  focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
116
116
  }
117
- } else {
118
- event.preventDefault();
119
- this.#moveFocus(shiftKey ? "previous" : "next");
117
+ return;
120
118
  }
119
+ event.preventDefault();
120
+ this.#moveFocus(shiftKey ? "previous" : "next");
121
121
  };
122
122
  #update() {
123
123
  const current = /* @__PURE__ */ new Set([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "keywords": [
6
6
  "a11y",
@@ -58,7 +58,7 @@
58
58
  "esbuild": true
59
59
  },
60
60
  "dependencies": {
61
- "@y14e/attribute-utils": "^2.0.13",
62
- "power-focusable": "^4.4.4"
61
+ "@y14e/attribute-utils": "^2.0.15",
62
+ "power-focusable": "^4.4.8"
63
63
  }
64
64
  }