@y14e/portal 1.0.3 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -269,14 +269,23 @@ function isUngroupedRadio(element) {
269
269
  var VISUALLY_HIDDEN_CSS = `border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;`;
270
270
  function createPortal(host, container = document.body) {
271
271
  if (!(host instanceof Element)) {
272
- throw new Error("Invalid host element");
272
+ console.warn("Invalid host element");
273
+ return () => {
274
+ };
275
+ }
276
+ if (host.hasAttribute("data-portaled")) {
277
+ console.warn("Already portaled");
278
+ return () => {
279
+ };
273
280
  }
274
281
  if (!(container instanceof Element)) {
275
282
  console.warn("Invalid container element. Fallback: <body> element.");
276
283
  container = document.body;
277
284
  }
278
285
  if (containsComposed2(host, container)) {
279
- throw new Error("Host element cannot contain container");
286
+ console.warn("Host element cannot contain the container element");
287
+ return () => {
288
+ };
280
289
  }
281
290
  const portal = new Portal(host, container);
282
291
  return () => portal.destroy();
@@ -290,10 +299,6 @@ var Portal = class {
290
299
  #controller = null;
291
300
  #isDestroyed = false;
292
301
  constructor(host, container) {
293
- if (host.hasAttribute("data-portaled")) {
294
- console.warn("Already portaled");
295
- return;
296
- }
297
302
  this.#host = host;
298
303
  this.#container = container;
299
304
  this.#entranceSentinel = this.#createSentinel();
@@ -351,14 +356,14 @@ var Portal = class {
351
356
  }
352
357
  if (current === this.#entranceSentinel) {
353
358
  if (this.#host.contains(before)) {
354
- this.#moveFocusOutside("previous");
359
+ this.#moveFocus("previous");
355
360
  } else {
356
361
  const first = this.#getFocusables()[0];
357
362
  first && focus(first);
358
363
  }
359
364
  } else if (current === this.#exitSentinel) {
360
365
  if (this.#host.contains(before)) {
361
- this.#moveFocusOutside("next");
366
+ this.#moveFocus("next");
362
367
  } else {
363
368
  const last = this.#getFocusables().at(-1);
364
369
  last && focus(last);
@@ -406,7 +411,7 @@ var Portal = class {
406
411
  include: (element) => this.#tabIndexes.has(element)
407
412
  });
408
413
  }
409
- #moveFocusOutside(direction) {
414
+ #moveFocus(direction) {
410
415
  const options = {
411
416
  anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
412
417
  composed: true
@@ -440,7 +445,7 @@ function getActiveElement2() {
440
445
  * Lightweight DOM portal (teleport) utility with fully focus management.
441
446
  * Designed for accessible dialogs, menus, overlays, popovers.
442
447
  *
443
- * @version 1.0.3
448
+ * @version 1.0.4
444
449
  * @author Yusuke Kamiyamane
445
450
  * @license MIT
446
451
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.0.3
6
+ * @version 1.0.4
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.0.3
6
+ * @version 1.0.4
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -267,14 +267,23 @@ function isUngroupedRadio(element) {
267
267
  var VISUALLY_HIDDEN_CSS = `border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;`;
268
268
  function createPortal(host, container = document.body) {
269
269
  if (!(host instanceof Element)) {
270
- throw new Error("Invalid host element");
270
+ console.warn("Invalid host element");
271
+ return () => {
272
+ };
273
+ }
274
+ if (host.hasAttribute("data-portaled")) {
275
+ console.warn("Already portaled");
276
+ return () => {
277
+ };
271
278
  }
272
279
  if (!(container instanceof Element)) {
273
280
  console.warn("Invalid container element. Fallback: <body> element.");
274
281
  container = document.body;
275
282
  }
276
283
  if (containsComposed2(host, container)) {
277
- throw new Error("Host element cannot contain container");
284
+ console.warn("Host element cannot contain the container element");
285
+ return () => {
286
+ };
278
287
  }
279
288
  const portal = new Portal(host, container);
280
289
  return () => portal.destroy();
@@ -288,10 +297,6 @@ var Portal = class {
288
297
  #controller = null;
289
298
  #isDestroyed = false;
290
299
  constructor(host, container) {
291
- if (host.hasAttribute("data-portaled")) {
292
- console.warn("Already portaled");
293
- return;
294
- }
295
300
  this.#host = host;
296
301
  this.#container = container;
297
302
  this.#entranceSentinel = this.#createSentinel();
@@ -349,14 +354,14 @@ var Portal = class {
349
354
  }
350
355
  if (current === this.#entranceSentinel) {
351
356
  if (this.#host.contains(before)) {
352
- this.#moveFocusOutside("previous");
357
+ this.#moveFocus("previous");
353
358
  } else {
354
359
  const first = this.#getFocusables()[0];
355
360
  first && focus(first);
356
361
  }
357
362
  } else if (current === this.#exitSentinel) {
358
363
  if (this.#host.contains(before)) {
359
- this.#moveFocusOutside("next");
364
+ this.#moveFocus("next");
360
365
  } else {
361
366
  const last = this.#getFocusables().at(-1);
362
367
  last && focus(last);
@@ -404,7 +409,7 @@ var Portal = class {
404
409
  include: (element) => this.#tabIndexes.has(element)
405
410
  });
406
411
  }
407
- #moveFocusOutside(direction) {
412
+ #moveFocus(direction) {
408
413
  const options = {
409
414
  anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
410
415
  composed: true
@@ -438,7 +443,7 @@ function getActiveElement2() {
438
443
  * Lightweight DOM portal (teleport) utility with fully focus management.
439
444
  * Designed for accessible dialogs, menus, overlays, popovers.
440
445
  *
441
- * @version 1.0.3
446
+ * @version 1.0.4
442
447
  * @author Yusuke Kamiyamane
443
448
  * @license MIT
444
449
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",