@zag-js/popover 0.0.0-dev-20220703125047 → 0.0.0-dev-20220704094439

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