@zag-js/popover 0.0.0-dev-20220708193601 → 0.0.0-dev-20220709094240

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.js CHANGED
@@ -84,10 +84,6 @@ function getDocument(el) {
84
84
  return el;
85
85
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
86
86
  }
87
- function getEventTarget(event) {
88
- var _a, _b;
89
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
90
- }
91
87
  function withRootHelpers(domUtils) {
92
88
  const roots = {
93
89
  getRootNode: (ctx) => {
@@ -399,7 +395,7 @@ function getWindow(el) {
399
395
  var _a;
400
396
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
401
397
  }
402
- function getEventTarget2(event) {
398
+ function getEventTarget(event) {
403
399
  var _a, _b;
404
400
  return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
405
401
  }
@@ -450,7 +446,7 @@ function trackInteractOutside(node, options) {
450
446
  const doc = getDocument2(node);
451
447
  const win = getWindow(node);
452
448
  function isEventOutside(event) {
453
- const target = getEventTarget2(event);
449
+ const target = getEventTarget(event);
454
450
  if (!(target instanceof win.HTMLElement)) {
455
451
  return false;
456
452
  }
@@ -476,7 +472,7 @@ function trackInteractOutside(node, options) {
476
472
  detail: {
477
473
  originalEvent: event,
478
474
  contextmenu: isContextMenuEvent(event),
479
- focusable: isFocusable2(getEventTarget2(event))
475
+ focusable: isFocusable2(getEventTarget(event))
480
476
  }
481
477
  });
482
478
  }
@@ -504,7 +500,7 @@ function trackInteractOutside(node, options) {
504
500
  detail: {
505
501
  originalEvent: event,
506
502
  contextmenu: false,
507
- focusable: isFocusable2(getEventTarget2(event))
503
+ focusable: isFocusable2(getEventTarget(event))
508
504
  }
509
505
  });
510
506
  }
@@ -517,16 +513,53 @@ function trackInteractOutside(node, options) {
517
513
  };
518
514
  }
519
515
 
520
- // ../../utilities/dismissable/src/escape-keydown.ts
516
+ // ../../utilities/dismissable/dist/index.mjs
517
+ var runIfFn4 = (v, ...a) => {
518
+ const res = typeof v === "function" ? v(...a) : v;
519
+ return res != null ? res : void 0;
520
+ };
521
+ var hasProp3 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
522
+ function isDocument3(el) {
523
+ return el.nodeType === Node.DOCUMENT_NODE;
524
+ }
525
+ function isWindow3(value) {
526
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
527
+ }
528
+ function getDocument3(el) {
529
+ var _a;
530
+ if (isWindow3(el))
531
+ return el.document;
532
+ if (isDocument3(el))
533
+ return el;
534
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
535
+ }
536
+ function getEventTarget2(event) {
537
+ var _a, _b;
538
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
539
+ }
540
+ function contains3(parent, child) {
541
+ if (!parent)
542
+ return false;
543
+ return parent === child || isHTMLElement3(parent) && isHTMLElement3(child) && parent.contains(child);
544
+ }
545
+ function isHTMLElement3(v) {
546
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
547
+ }
548
+ var isRef3 = (v) => hasProp3(v, "current");
549
+ function addDomEvent3(target, eventName, handler, options) {
550
+ const node = isRef3(target) ? target.current : runIfFn4(target);
551
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
552
+ return () => {
553
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
554
+ };
555
+ }
521
556
  function trackEscapeKeydown(fn) {
522
557
  const handleKeyDown = (event) => {
523
558
  if (event.key === "Escape")
524
559
  fn == null ? void 0 : fn(event);
525
560
  };
526
- return addDomEvent(document, "keydown", handleKeyDown);
561
+ return addDomEvent3(document, "keydown", handleKeyDown);
527
562
  }
528
-
529
- // ../../utilities/dismissable/src/layer-stack.ts
530
563
  var layerStack = {
531
564
  layers: [],
532
565
  branches: [],
@@ -556,10 +589,10 @@ var layerStack = {
556
589
  return Array.from(this.layers).slice(this.indexOf(node) + 1);
557
590
  },
558
591
  isInNestedLayer(node, target) {
559
- return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
592
+ return this.getNestedLayers(node).some((layer) => contains3(layer.node, target));
560
593
  },
561
594
  isInBranch(target) {
562
- return Array.from(this.branches).some((branch) => contains(branch, target));
595
+ return Array.from(this.branches).some((branch) => contains3(branch, target));
563
596
  },
564
597
  add(layer) {
565
598
  this.layers.push(layer);
@@ -593,8 +626,6 @@ var layerStack = {
593
626
  this.remove(this.layers[0].node);
594
627
  }
595
628
  };
596
-
597
- // ../../utilities/dismissable/src/pointer-event-outside.ts
598
629
  var originalBodyPointerEvents;
599
630
  function assignPointerEventToLayers() {
600
631
  layerStack.layers.forEach(({ node }) => {
@@ -606,7 +637,7 @@ function clearPointerEvent(node) {
606
637
  }
607
638
  var DATA_ATTR = "data-inert";
608
639
  function disablePointerEventsOutside(node) {
609
- const doc = getDocument(node);
640
+ const doc = getDocument3(node);
610
641
  if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
611
642
  originalBodyPointerEvents = document.body.style.pointerEvents;
612
643
  doc.body.style.pointerEvents = "none";
@@ -621,8 +652,6 @@ function disablePointerEventsOutside(node) {
621
652
  doc.body.removeAttribute("style");
622
653
  };
623
654
  }
624
-
625
- // ../../utilities/dismissable/src/dismissable-layer.ts
626
655
  function trackDismissableElement(node, options) {
627
656
  if (!node)
628
657
  return;
@@ -632,7 +661,7 @@ function trackDismissableElement(node, options) {
632
661
  assignPointerEventToLayers();
633
662
  function onPointerDownOutside(event) {
634
663
  var _a, _b;
635
- const target = getEventTarget(event.detail.originalEvent);
664
+ const target = getEventTarget2(event.detail.originalEvent);
636
665
  if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
637
666
  return;
638
667
  (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
@@ -646,7 +675,7 @@ function trackDismissableElement(node, options) {
646
675
  }
647
676
  function onFocusOutside(event) {
648
677
  var _a, _b;
649
- const target = getEventTarget(event.detail.originalEvent);
678
+ const target = getEventTarget2(event.detail.originalEvent);
650
679
  if (layerStack.isInBranch(target))
651
680
  return;
652
681
  (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
@@ -673,7 +702,7 @@ function trackDismissableElement(node, options) {
673
702
  return false;
674
703
  const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
675
704
  const _containers = Array.isArray(containers) ? containers : [containers];
676
- return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
705
+ return _containers.some((node2) => contains3(node2, target)) || layerStack.isInNestedLayer(node, target);
677
706
  }
678
707
  const cleanups = [
679
708
  pointerBlocking ? disablePointerEventsOutside(node) : void 0,
package/dist/index.mjs CHANGED
@@ -60,10 +60,6 @@ function getDocument(el) {
60
60
  return el;
61
61
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
62
62
  }
63
- function getEventTarget(event) {
64
- var _a, _b;
65
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
66
- }
67
63
  function withRootHelpers(domUtils) {
68
64
  const roots = {
69
65
  getRootNode: (ctx) => {
@@ -375,7 +371,7 @@ function getWindow(el) {
375
371
  var _a;
376
372
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
377
373
  }
378
- function getEventTarget2(event) {
374
+ function getEventTarget(event) {
379
375
  var _a, _b;
380
376
  return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
381
377
  }
@@ -426,7 +422,7 @@ function trackInteractOutside(node, options) {
426
422
  const doc = getDocument2(node);
427
423
  const win = getWindow(node);
428
424
  function isEventOutside(event) {
429
- const target = getEventTarget2(event);
425
+ const target = getEventTarget(event);
430
426
  if (!(target instanceof win.HTMLElement)) {
431
427
  return false;
432
428
  }
@@ -452,7 +448,7 @@ function trackInteractOutside(node, options) {
452
448
  detail: {
453
449
  originalEvent: event,
454
450
  contextmenu: isContextMenuEvent(event),
455
- focusable: isFocusable2(getEventTarget2(event))
451
+ focusable: isFocusable2(getEventTarget(event))
456
452
  }
457
453
  });
458
454
  }
@@ -480,7 +476,7 @@ function trackInteractOutside(node, options) {
480
476
  detail: {
481
477
  originalEvent: event,
482
478
  contextmenu: false,
483
- focusable: isFocusable2(getEventTarget2(event))
479
+ focusable: isFocusable2(getEventTarget(event))
484
480
  }
485
481
  });
486
482
  }
@@ -493,16 +489,53 @@ function trackInteractOutside(node, options) {
493
489
  };
494
490
  }
495
491
 
496
- // ../../utilities/dismissable/src/escape-keydown.ts
492
+ // ../../utilities/dismissable/dist/index.mjs
493
+ var runIfFn4 = (v, ...a) => {
494
+ const res = typeof v === "function" ? v(...a) : v;
495
+ return res != null ? res : void 0;
496
+ };
497
+ var hasProp3 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
498
+ function isDocument3(el) {
499
+ return el.nodeType === Node.DOCUMENT_NODE;
500
+ }
501
+ function isWindow3(value) {
502
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
503
+ }
504
+ function getDocument3(el) {
505
+ var _a;
506
+ if (isWindow3(el))
507
+ return el.document;
508
+ if (isDocument3(el))
509
+ return el;
510
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
511
+ }
512
+ function getEventTarget2(event) {
513
+ var _a, _b;
514
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
515
+ }
516
+ function contains3(parent, child) {
517
+ if (!parent)
518
+ return false;
519
+ return parent === child || isHTMLElement3(parent) && isHTMLElement3(child) && parent.contains(child);
520
+ }
521
+ function isHTMLElement3(v) {
522
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
523
+ }
524
+ var isRef3 = (v) => hasProp3(v, "current");
525
+ function addDomEvent3(target, eventName, handler, options) {
526
+ const node = isRef3(target) ? target.current : runIfFn4(target);
527
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
528
+ return () => {
529
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
530
+ };
531
+ }
497
532
  function trackEscapeKeydown(fn) {
498
533
  const handleKeyDown = (event) => {
499
534
  if (event.key === "Escape")
500
535
  fn == null ? void 0 : fn(event);
501
536
  };
502
- return addDomEvent(document, "keydown", handleKeyDown);
537
+ return addDomEvent3(document, "keydown", handleKeyDown);
503
538
  }
504
-
505
- // ../../utilities/dismissable/src/layer-stack.ts
506
539
  var layerStack = {
507
540
  layers: [],
508
541
  branches: [],
@@ -532,10 +565,10 @@ var layerStack = {
532
565
  return Array.from(this.layers).slice(this.indexOf(node) + 1);
533
566
  },
534
567
  isInNestedLayer(node, target) {
535
- return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
568
+ return this.getNestedLayers(node).some((layer) => contains3(layer.node, target));
536
569
  },
537
570
  isInBranch(target) {
538
- return Array.from(this.branches).some((branch) => contains(branch, target));
571
+ return Array.from(this.branches).some((branch) => contains3(branch, target));
539
572
  },
540
573
  add(layer) {
541
574
  this.layers.push(layer);
@@ -569,8 +602,6 @@ var layerStack = {
569
602
  this.remove(this.layers[0].node);
570
603
  }
571
604
  };
572
-
573
- // ../../utilities/dismissable/src/pointer-event-outside.ts
574
605
  var originalBodyPointerEvents;
575
606
  function assignPointerEventToLayers() {
576
607
  layerStack.layers.forEach(({ node }) => {
@@ -582,7 +613,7 @@ function clearPointerEvent(node) {
582
613
  }
583
614
  var DATA_ATTR = "data-inert";
584
615
  function disablePointerEventsOutside(node) {
585
- const doc = getDocument(node);
616
+ const doc = getDocument3(node);
586
617
  if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
587
618
  originalBodyPointerEvents = document.body.style.pointerEvents;
588
619
  doc.body.style.pointerEvents = "none";
@@ -597,8 +628,6 @@ function disablePointerEventsOutside(node) {
597
628
  doc.body.removeAttribute("style");
598
629
  };
599
630
  }
600
-
601
- // ../../utilities/dismissable/src/dismissable-layer.ts
602
631
  function trackDismissableElement(node, options) {
603
632
  if (!node)
604
633
  return;
@@ -608,7 +637,7 @@ function trackDismissableElement(node, options) {
608
637
  assignPointerEventToLayers();
609
638
  function onPointerDownOutside(event) {
610
639
  var _a, _b;
611
- const target = getEventTarget(event.detail.originalEvent);
640
+ const target = getEventTarget2(event.detail.originalEvent);
612
641
  if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
613
642
  return;
614
643
  (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
@@ -622,7 +651,7 @@ function trackDismissableElement(node, options) {
622
651
  }
623
652
  function onFocusOutside(event) {
624
653
  var _a, _b;
625
- const target = getEventTarget(event.detail.originalEvent);
654
+ const target = getEventTarget2(event.detail.originalEvent);
626
655
  if (layerStack.isInBranch(target))
627
656
  return;
628
657
  (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
@@ -649,7 +678,7 @@ function trackDismissableElement(node, options) {
649
678
  return false;
650
679
  const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
651
680
  const _containers = Array.isArray(containers) ? containers : [containers];
652
- return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
681
+ return _containers.some((node2) => contains3(node2, target)) || layerStack.isInNestedLayer(node, target);
653
682
  }
654
683
  const cleanups = [
655
684
  pointerBlocking ? disablePointerEventsOutside(node) : void 0,
@@ -1,13 +1,13 @@
1
1
  import type { MachineContext as Ctx } from "./popover.types";
2
2
  export declare const dom: {
3
3
  getRootNode: (ctx: {
4
- getRootNode?: () => Document | Node | ShadowRoot;
4
+ getRootNode?: () => Node | Document | ShadowRoot;
5
5
  }) => Document | ShadowRoot;
6
6
  getDoc: (ctx: {
7
- getRootNode?: () => Document | Node | ShadowRoot;
7
+ getRootNode?: () => Node | Document | ShadowRoot;
8
8
  }) => Document;
9
9
  getWin: (ctx: {
10
- getRootNode?: () => Document | Node | ShadowRoot;
10
+ getRootNode?: () => Node | Document | ShadowRoot;
11
11
  }) => Window & typeof globalThis;
12
12
  } & {
13
13
  getActiveEl: (ctx: Ctx) => Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "0.0.0-dev-20220708193601",
3
+ "version": "0.0.0-dev-20220709094240",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -31,10 +31,10 @@
31
31
  "dependencies": {
32
32
  "@zag-js/aria-hidden": "0.1.0",
33
33
  "@zag-js/core": "0.1.7",
34
- "@zag-js/dom-utils": "0.0.0-dev-20220708193601",
35
- "@zag-js/popper": "0.0.0-dev-20220708193601",
36
- "@zag-js/remove-scroll": "0.0.0-dev-20220708193601",
37
- "@zag-js/types": "0.0.0-dev-20220708193601",
34
+ "@zag-js/dom-utils": "0.0.0-dev-20220709094240",
35
+ "@zag-js/popper": "0.0.0-dev-20220709094240",
36
+ "@zag-js/remove-scroll": "0.0.0-dev-20220709094240",
37
+ "@zag-js/types": "0.0.0-dev-20220709094240",
38
38
  "@zag-js/utils": "0.1.2",
39
39
  "focus-trap": "6.9.4"
40
40
  },