@zag-js/popover 0.0.0-dev-20220704163406 → 0.0.0-dev-20220706194607

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
@@ -51,22 +51,9 @@ var runIfFn = (v, ...a) => {
51
51
  return res != null ? res : void 0;
52
52
  };
53
53
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
54
- function isWindow(value) {
55
- return (value == null ? void 0 : value.toString()) === "[object Window]";
56
- }
57
54
  function isFrame(element) {
58
55
  return element.localName === "iframe";
59
56
  }
60
- function getDocument(el) {
61
- var _a;
62
- if (isWindow(el))
63
- return el.document;
64
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
65
- }
66
- function getEventTarget(event) {
67
- var _a, _b;
68
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
69
- }
70
57
  function contains(parent, child) {
71
58
  if (!parent)
72
59
  return false;
@@ -358,12 +345,12 @@ function getPlatform() {
358
345
  var pt = (v) => isDom() && v.test(getPlatform());
359
346
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
360
347
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
361
- function isWindow2(value) {
348
+ function isWindow(value) {
362
349
  return (value == null ? void 0 : value.toString()) === "[object Window]";
363
350
  }
364
- function getDocument2(el) {
351
+ function getDocument(el) {
365
352
  var _a;
366
- if (isWindow2(el))
353
+ if (isWindow(el))
367
354
  return el.document;
368
355
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
369
356
  }
@@ -371,7 +358,7 @@ function getWindow(el) {
371
358
  var _a;
372
359
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
373
360
  }
374
- function getEventTarget2(event) {
361
+ function getEventTarget(event) {
375
362
  var _a, _b;
376
363
  return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
377
364
  }
@@ -418,10 +405,10 @@ function trackInteractOutside(node, options) {
418
405
  const { exclude, onFocusOutside, onPointerDownOutside } = options;
419
406
  if (!node)
420
407
  return;
421
- const doc = getDocument2(node);
408
+ const doc = getDocument(node);
422
409
  const win = getWindow(node);
423
410
  function isEventOutside(event) {
424
- const target = getEventTarget2(event);
411
+ const target = getEventTarget(event);
425
412
  if (!(target instanceof win.HTMLElement)) {
426
413
  return false;
427
414
  }
@@ -447,7 +434,7 @@ function trackInteractOutside(node, options) {
447
434
  detail: {
448
435
  originalEvent: event,
449
436
  contextmenu: isContextMenuEvent(event),
450
- focusable: isFocusable2(getEventTarget2(event))
437
+ focusable: isFocusable2(getEventTarget(event))
451
438
  }
452
439
  });
453
440
  }
@@ -475,7 +462,7 @@ function trackInteractOutside(node, options) {
475
462
  detail: {
476
463
  originalEvent: event,
477
464
  contextmenu: false,
478
- focusable: isFocusable2(getEventTarget2(event))
465
+ focusable: isFocusable2(getEventTarget(event))
479
466
  }
480
467
  });
481
468
  }
@@ -488,16 +475,48 @@ function trackInteractOutside(node, options) {
488
475
  };
489
476
  }
490
477
 
491
- // ../../utilities/dismissable/src/escape-keydown.ts
478
+ // ../../utilities/dismissable/dist/index.mjs
479
+ var runIfFn4 = (v, ...a) => {
480
+ const res = typeof v === "function" ? v(...a) : v;
481
+ return res != null ? res : void 0;
482
+ };
483
+ var hasProp3 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
484
+ function isWindow2(value) {
485
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
486
+ }
487
+ function getDocument2(el) {
488
+ var _a;
489
+ if (isWindow2(el))
490
+ return el.document;
491
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
492
+ }
493
+ function getEventTarget2(event) {
494
+ var _a, _b;
495
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
496
+ }
497
+ function contains3(parent, child) {
498
+ if (!parent)
499
+ return false;
500
+ return parent === child || isHTMLElement3(parent) && isHTMLElement3(child) && parent.contains(child);
501
+ }
502
+ function isHTMLElement3(v) {
503
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
504
+ }
505
+ var isRef3 = (v) => hasProp3(v, "current");
506
+ function addDomEvent3(target, eventName, handler, options) {
507
+ const node = isRef3(target) ? target.current : runIfFn4(target);
508
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
509
+ return () => {
510
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
511
+ };
512
+ }
492
513
  function trackEscapeKeydown(fn) {
493
514
  const handleKeyDown = (event) => {
494
515
  if (event.key === "Escape")
495
516
  fn == null ? void 0 : fn(event);
496
517
  };
497
- return addDomEvent(document, "keydown", handleKeyDown);
518
+ return addDomEvent3(document, "keydown", handleKeyDown);
498
519
  }
499
-
500
- // ../../utilities/dismissable/src/layer-stack.ts
501
520
  var layerStack = {
502
521
  layers: [],
503
522
  branches: [],
@@ -527,10 +546,10 @@ var layerStack = {
527
546
  return this.layers.slice(this.indexOf(node));
528
547
  },
529
548
  isInChildLayer(node, target) {
530
- return this.getChildLayers(node).some((layer) => contains(layer.node, target));
549
+ return this.getChildLayers(node).some((layer) => contains3(layer.node, target));
531
550
  },
532
551
  isInBranch(target) {
533
- return [...this.branches].some((branch) => contains(branch, target));
552
+ return [...this.branches].some((branch) => contains3(branch, target));
534
553
  },
535
554
  add(layer) {
536
555
  this.layers.push(layer);
@@ -561,8 +580,6 @@ var layerStack = {
561
580
  this.remove(this.layers[0].node);
562
581
  }
563
582
  };
564
-
565
- // ../../utilities/dismissable/src/pointer-event-outside.ts
566
583
  var originalBodyPointerEvents;
567
584
  function assignPointerEventToLayers() {
568
585
  layerStack.layers.forEach(({ node }) => {
@@ -574,7 +591,7 @@ function clearPointerEvent(node) {
574
591
  }
575
592
  var DATA_ATTR = "data-inert";
576
593
  function disablePointerEventsOutside(node) {
577
- const doc = getDocument(node);
594
+ const doc = getDocument2(node);
578
595
  if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
579
596
  originalBodyPointerEvents = document.body.style.pointerEvents;
580
597
  doc.body.style.pointerEvents = "none";
@@ -589,8 +606,6 @@ function disablePointerEventsOutside(node) {
589
606
  doc.body.removeAttribute("style");
590
607
  };
591
608
  }
592
-
593
- // ../../utilities/dismissable/src/dismissable-layer.ts
594
609
  function trackDismissableElement(node, options) {
595
610
  if (!node)
596
611
  return;
@@ -600,7 +615,7 @@ function trackDismissableElement(node, options) {
600
615
  assignPointerEventToLayers();
601
616
  function onPointerDownOutside(event) {
602
617
  var _a, _b;
603
- const target = getEventTarget(event.detail.originalEvent);
618
+ const target = getEventTarget2(event.detail.originalEvent);
604
619
  if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
605
620
  return;
606
621
  (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
@@ -611,7 +626,7 @@ function trackDismissableElement(node, options) {
611
626
  }
612
627
  function onFocusOutside(event) {
613
628
  var _a, _b;
614
- const target = getEventTarget(event.detail.originalEvent);
629
+ const target = getEventTarget2(event.detail.originalEvent);
615
630
  if (layerStack.isInBranch(target))
616
631
  return;
617
632
  (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
@@ -633,7 +648,7 @@ function trackDismissableElement(node, options) {
633
648
  function exclude(target) {
634
649
  const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
635
650
  const inContainers = Array.isArray(containers) ? containers : [containers];
636
- return inContainers.some((node2) => contains(node2, target)) || layerStack.isInChildLayer(node, target);
651
+ return inContainers.some((node2) => contains3(node2, target)) || layerStack.isInChildLayer(node, target);
637
652
  }
638
653
  const cleanups = [
639
654
  pointerBlocking ? disablePointerEventsOutside(node) : void 0,
package/dist/index.mjs CHANGED
@@ -27,22 +27,9 @@ var runIfFn = (v, ...a) => {
27
27
  return res != null ? res : void 0;
28
28
  };
29
29
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
30
- function isWindow(value) {
31
- return (value == null ? void 0 : value.toString()) === "[object Window]";
32
- }
33
30
  function isFrame(element) {
34
31
  return element.localName === "iframe";
35
32
  }
36
- function getDocument(el) {
37
- var _a;
38
- if (isWindow(el))
39
- return el.document;
40
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
41
- }
42
- function getEventTarget(event) {
43
- var _a, _b;
44
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
45
- }
46
33
  function contains(parent, child) {
47
34
  if (!parent)
48
35
  return false;
@@ -334,12 +321,12 @@ function getPlatform() {
334
321
  var pt = (v) => isDom() && v.test(getPlatform());
335
322
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
336
323
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
337
- function isWindow2(value) {
324
+ function isWindow(value) {
338
325
  return (value == null ? void 0 : value.toString()) === "[object Window]";
339
326
  }
340
- function getDocument2(el) {
327
+ function getDocument(el) {
341
328
  var _a;
342
- if (isWindow2(el))
329
+ if (isWindow(el))
343
330
  return el.document;
344
331
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
345
332
  }
@@ -347,7 +334,7 @@ function getWindow(el) {
347
334
  var _a;
348
335
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
349
336
  }
350
- function getEventTarget2(event) {
337
+ function getEventTarget(event) {
351
338
  var _a, _b;
352
339
  return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
353
340
  }
@@ -394,10 +381,10 @@ function trackInteractOutside(node, options) {
394
381
  const { exclude, onFocusOutside, onPointerDownOutside } = options;
395
382
  if (!node)
396
383
  return;
397
- const doc = getDocument2(node);
384
+ const doc = getDocument(node);
398
385
  const win = getWindow(node);
399
386
  function isEventOutside(event) {
400
- const target = getEventTarget2(event);
387
+ const target = getEventTarget(event);
401
388
  if (!(target instanceof win.HTMLElement)) {
402
389
  return false;
403
390
  }
@@ -423,7 +410,7 @@ function trackInteractOutside(node, options) {
423
410
  detail: {
424
411
  originalEvent: event,
425
412
  contextmenu: isContextMenuEvent(event),
426
- focusable: isFocusable2(getEventTarget2(event))
413
+ focusable: isFocusable2(getEventTarget(event))
427
414
  }
428
415
  });
429
416
  }
@@ -451,7 +438,7 @@ function trackInteractOutside(node, options) {
451
438
  detail: {
452
439
  originalEvent: event,
453
440
  contextmenu: false,
454
- focusable: isFocusable2(getEventTarget2(event))
441
+ focusable: isFocusable2(getEventTarget(event))
455
442
  }
456
443
  });
457
444
  }
@@ -464,16 +451,48 @@ function trackInteractOutside(node, options) {
464
451
  };
465
452
  }
466
453
 
467
- // ../../utilities/dismissable/src/escape-keydown.ts
454
+ // ../../utilities/dismissable/dist/index.mjs
455
+ var runIfFn4 = (v, ...a) => {
456
+ const res = typeof v === "function" ? v(...a) : v;
457
+ return res != null ? res : void 0;
458
+ };
459
+ var hasProp3 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
460
+ function isWindow2(value) {
461
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
462
+ }
463
+ function getDocument2(el) {
464
+ var _a;
465
+ if (isWindow2(el))
466
+ return el.document;
467
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
468
+ }
469
+ function getEventTarget2(event) {
470
+ var _a, _b;
471
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
472
+ }
473
+ function contains3(parent, child) {
474
+ if (!parent)
475
+ return false;
476
+ return parent === child || isHTMLElement3(parent) && isHTMLElement3(child) && parent.contains(child);
477
+ }
478
+ function isHTMLElement3(v) {
479
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
480
+ }
481
+ var isRef3 = (v) => hasProp3(v, "current");
482
+ function addDomEvent3(target, eventName, handler, options) {
483
+ const node = isRef3(target) ? target.current : runIfFn4(target);
484
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
485
+ return () => {
486
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
487
+ };
488
+ }
468
489
  function trackEscapeKeydown(fn) {
469
490
  const handleKeyDown = (event) => {
470
491
  if (event.key === "Escape")
471
492
  fn == null ? void 0 : fn(event);
472
493
  };
473
- return addDomEvent(document, "keydown", handleKeyDown);
494
+ return addDomEvent3(document, "keydown", handleKeyDown);
474
495
  }
475
-
476
- // ../../utilities/dismissable/src/layer-stack.ts
477
496
  var layerStack = {
478
497
  layers: [],
479
498
  branches: [],
@@ -503,10 +522,10 @@ var layerStack = {
503
522
  return this.layers.slice(this.indexOf(node));
504
523
  },
505
524
  isInChildLayer(node, target) {
506
- return this.getChildLayers(node).some((layer) => contains(layer.node, target));
525
+ return this.getChildLayers(node).some((layer) => contains3(layer.node, target));
507
526
  },
508
527
  isInBranch(target) {
509
- return [...this.branches].some((branch) => contains(branch, target));
528
+ return [...this.branches].some((branch) => contains3(branch, target));
510
529
  },
511
530
  add(layer) {
512
531
  this.layers.push(layer);
@@ -537,8 +556,6 @@ var layerStack = {
537
556
  this.remove(this.layers[0].node);
538
557
  }
539
558
  };
540
-
541
- // ../../utilities/dismissable/src/pointer-event-outside.ts
542
559
  var originalBodyPointerEvents;
543
560
  function assignPointerEventToLayers() {
544
561
  layerStack.layers.forEach(({ node }) => {
@@ -550,7 +567,7 @@ function clearPointerEvent(node) {
550
567
  }
551
568
  var DATA_ATTR = "data-inert";
552
569
  function disablePointerEventsOutside(node) {
553
- const doc = getDocument(node);
570
+ const doc = getDocument2(node);
554
571
  if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
555
572
  originalBodyPointerEvents = document.body.style.pointerEvents;
556
573
  doc.body.style.pointerEvents = "none";
@@ -565,8 +582,6 @@ function disablePointerEventsOutside(node) {
565
582
  doc.body.removeAttribute("style");
566
583
  };
567
584
  }
568
-
569
- // ../../utilities/dismissable/src/dismissable-layer.ts
570
585
  function trackDismissableElement(node, options) {
571
586
  if (!node)
572
587
  return;
@@ -576,7 +591,7 @@ function trackDismissableElement(node, options) {
576
591
  assignPointerEventToLayers();
577
592
  function onPointerDownOutside(event) {
578
593
  var _a, _b;
579
- const target = getEventTarget(event.detail.originalEvent);
594
+ const target = getEventTarget2(event.detail.originalEvent);
580
595
  if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
581
596
  return;
582
597
  (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
@@ -587,7 +602,7 @@ function trackDismissableElement(node, options) {
587
602
  }
588
603
  function onFocusOutside(event) {
589
604
  var _a, _b;
590
- const target = getEventTarget(event.detail.originalEvent);
605
+ const target = getEventTarget2(event.detail.originalEvent);
591
606
  if (layerStack.isInBranch(target))
592
607
  return;
593
608
  (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
@@ -609,7 +624,7 @@ function trackDismissableElement(node, options) {
609
624
  function exclude(target) {
610
625
  const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
611
626
  const inContainers = Array.isArray(containers) ? containers : [containers];
612
- return inContainers.some((node2) => contains(node2, target)) || layerStack.isInChildLayer(node, target);
627
+ return inContainers.some((node2) => contains3(node2, target)) || layerStack.isInChildLayer(node, target);
613
628
  }
614
629
  const cleanups = [
615
630
  pointerBlocking ? disablePointerEventsOutside(node) : void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "0.0.0-dev-20220704163406",
3
+ "version": "0.0.0-dev-20220706194607",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,11 +30,11 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@zag-js/aria-hidden": "0.1.0",
33
- "@zag-js/core": "0.0.0-dev-20220704163406",
34
- "@zag-js/dom-utils": "0.0.0-dev-20220704163406",
35
- "@zag-js/popper": "0.0.0-dev-20220704163406",
36
- "@zag-js/remove-scroll": "0.0.0-dev-20220704163406",
37
- "@zag-js/types": "0.0.0-dev-20220704163406",
33
+ "@zag-js/core": "0.0.0-dev-20220706194607",
34
+ "@zag-js/dom-utils": "0.0.0-dev-20220706194607",
35
+ "@zag-js/popper": "0.0.0-dev-20220706194607",
36
+ "@zag-js/remove-scroll": "0.0.0-dev-20220706194607",
37
+ "@zag-js/types": "0.0.0-dev-20220706194607",
38
38
  "@zag-js/utils": "0.1.2",
39
39
  "focus-trap": "6.9.4"
40
40
  },