@zag-js/popover 0.0.0-dev-20220709173135 → 0.0.0-dev-20220710102425
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 +5 -334
- package/dist/index.mjs +4 -333
- package/dist/popover.dom.d.ts +7 -4
- package/dist/popover.types.d.ts +1 -1
- package/package.json +9 -6
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 defineDomHelpers(domUtils) {
|
|
92
88
|
const roots = {
|
|
93
89
|
getRootNode: (ctx) => {
|
|
@@ -99,7 +95,8 @@ function defineDomHelpers(domUtils) {
|
|
|
99
95
|
var _a;
|
|
100
96
|
return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
|
|
101
97
|
},
|
|
102
|
-
getActiveElement: (ctx) => roots.getDoc(ctx).activeElement
|
|
98
|
+
getActiveElement: (ctx) => roots.getDoc(ctx).activeElement,
|
|
99
|
+
getById: (ctx, id) => roots.getRootNode(ctx).getElementById(id)
|
|
103
100
|
};
|
|
104
101
|
return __spreadValues2(__spreadValues2({}, roots), domUtils);
|
|
105
102
|
}
|
|
@@ -366,330 +363,7 @@ function connect(state, send, normalize) {
|
|
|
366
363
|
// src/popover.machine.ts
|
|
367
364
|
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
368
365
|
var import_core = require("@zag-js/core");
|
|
369
|
-
|
|
370
|
-
// ../../utilities/interact-outside/dist/index.mjs
|
|
371
|
-
var runIfFn3 = (v, ...a) => {
|
|
372
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
373
|
-
return res != null ? res : void 0;
|
|
374
|
-
};
|
|
375
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
376
|
-
var isDom = () => typeof window !== "undefined";
|
|
377
|
-
function getPlatform() {
|
|
378
|
-
var _a;
|
|
379
|
-
const agent = navigator.userAgentData;
|
|
380
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
381
|
-
}
|
|
382
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
383
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
384
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
385
|
-
function isDocument2(el) {
|
|
386
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
387
|
-
}
|
|
388
|
-
function isWindow2(value) {
|
|
389
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
390
|
-
}
|
|
391
|
-
function getDocument2(el) {
|
|
392
|
-
var _a;
|
|
393
|
-
if (isWindow2(el))
|
|
394
|
-
return el.document;
|
|
395
|
-
if (isDocument2(el))
|
|
396
|
-
return el;
|
|
397
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
398
|
-
}
|
|
399
|
-
function getWindow(el) {
|
|
400
|
-
var _a;
|
|
401
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
402
|
-
}
|
|
403
|
-
function getEventTarget2(event) {
|
|
404
|
-
var _a, _b;
|
|
405
|
-
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
406
|
-
}
|
|
407
|
-
function contains2(parent, child) {
|
|
408
|
-
if (!parent)
|
|
409
|
-
return false;
|
|
410
|
-
return parent === child || isHTMLElement2(parent) && isHTMLElement2(child) && parent.contains(child);
|
|
411
|
-
}
|
|
412
|
-
function isHTMLElement2(v) {
|
|
413
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
414
|
-
}
|
|
415
|
-
function isVisible2(el) {
|
|
416
|
-
if (!isHTMLElement2(el))
|
|
417
|
-
return false;
|
|
418
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
419
|
-
}
|
|
420
|
-
var isContextMenuEvent = (e) => {
|
|
421
|
-
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
422
|
-
};
|
|
423
|
-
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
424
|
-
function fireCustomEvent(el, type, init) {
|
|
425
|
-
if (!el)
|
|
426
|
-
return;
|
|
427
|
-
const win = getWindow(el);
|
|
428
|
-
const event = new win.CustomEvent(type, init);
|
|
429
|
-
return el.dispatchEvent(event);
|
|
430
|
-
}
|
|
431
|
-
var focusableSelector2 = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
432
|
-
function isFocusable2(element) {
|
|
433
|
-
if (!element)
|
|
434
|
-
return false;
|
|
435
|
-
return element.matches(focusableSelector2) && isVisible2(element);
|
|
436
|
-
}
|
|
437
|
-
var isRef2 = (v) => hasProp2(v, "current");
|
|
438
|
-
function addDomEvent2(target, eventName, handler, options) {
|
|
439
|
-
const node = isRef2(target) ? target.current : runIfFn3(target);
|
|
440
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
441
|
-
return () => {
|
|
442
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
446
|
-
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
447
|
-
function trackInteractOutside(node, options) {
|
|
448
|
-
const { exclude, onFocusOutside, onPointerDownOutside } = options;
|
|
449
|
-
if (!node)
|
|
450
|
-
return;
|
|
451
|
-
const doc = getDocument2(node);
|
|
452
|
-
const win = getWindow(node);
|
|
453
|
-
function isEventOutside(event) {
|
|
454
|
-
const target = getEventTarget2(event);
|
|
455
|
-
if (!(target instanceof win.HTMLElement)) {
|
|
456
|
-
return false;
|
|
457
|
-
}
|
|
458
|
-
if (!contains2(doc.documentElement, target)) {
|
|
459
|
-
return false;
|
|
460
|
-
}
|
|
461
|
-
if (contains2(node, target)) {
|
|
462
|
-
return false;
|
|
463
|
-
}
|
|
464
|
-
return !(exclude == null ? void 0 : exclude(target));
|
|
465
|
-
}
|
|
466
|
-
let clickHandler;
|
|
467
|
-
function onPointerDown(event) {
|
|
468
|
-
function handler() {
|
|
469
|
-
if (!node || !isEventOutside(event))
|
|
470
|
-
return;
|
|
471
|
-
if (onPointerDownOutside) {
|
|
472
|
-
node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
|
|
473
|
-
}
|
|
474
|
-
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
475
|
-
bubbles: false,
|
|
476
|
-
cancelable: true,
|
|
477
|
-
detail: {
|
|
478
|
-
originalEvent: event,
|
|
479
|
-
contextmenu: isContextMenuEvent(event),
|
|
480
|
-
focusable: isFocusable2(getEventTarget2(event))
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
if (event.pointerType === "touch") {
|
|
485
|
-
doc.removeEventListener("click", handler);
|
|
486
|
-
clickHandler = handler;
|
|
487
|
-
doc.addEventListener("click", handler, { once: true });
|
|
488
|
-
} else {
|
|
489
|
-
handler();
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
493
|
-
const timer = setTimeout(() => {
|
|
494
|
-
cleanups.add(addDomEvent2(doc, "pointerdown", onPointerDown, true));
|
|
495
|
-
}, 0);
|
|
496
|
-
function onFocusin(event) {
|
|
497
|
-
if (!node || !isEventOutside(event))
|
|
498
|
-
return;
|
|
499
|
-
if (onFocusOutside) {
|
|
500
|
-
node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
|
|
501
|
-
}
|
|
502
|
-
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
503
|
-
bubbles: false,
|
|
504
|
-
cancelable: true,
|
|
505
|
-
detail: {
|
|
506
|
-
originalEvent: event,
|
|
507
|
-
contextmenu: false,
|
|
508
|
-
focusable: isFocusable2(getEventTarget2(event))
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
cleanups.add(addDomEvent2(doc, "focusin", onFocusin, true));
|
|
513
|
-
return () => {
|
|
514
|
-
clearTimeout(timer);
|
|
515
|
-
if (clickHandler)
|
|
516
|
-
doc.removeEventListener("click", clickHandler);
|
|
517
|
-
cleanups.forEach((fn) => fn());
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// ../../utilities/dismissable/src/escape-keydown.ts
|
|
522
|
-
function trackEscapeKeydown(fn) {
|
|
523
|
-
const handleKeyDown = (event) => {
|
|
524
|
-
if (event.key === "Escape")
|
|
525
|
-
fn == null ? void 0 : fn(event);
|
|
526
|
-
};
|
|
527
|
-
return addDomEvent(document, "keydown", handleKeyDown);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// ../../utilities/dismissable/src/layer-stack.ts
|
|
531
|
-
var layerStack = {
|
|
532
|
-
layers: [],
|
|
533
|
-
branches: [],
|
|
534
|
-
count() {
|
|
535
|
-
return this.layers.length;
|
|
536
|
-
},
|
|
537
|
-
pointerBlockingLayers() {
|
|
538
|
-
return this.layers.filter((layer) => layer.pointerBlocking);
|
|
539
|
-
},
|
|
540
|
-
topMostPointerBlockingLayer() {
|
|
541
|
-
return [...this.pointerBlockingLayers()].slice(-1)[0];
|
|
542
|
-
},
|
|
543
|
-
hasPointerBlockingLayer() {
|
|
544
|
-
return this.pointerBlockingLayers().length > 0;
|
|
545
|
-
},
|
|
546
|
-
isBelowPointerBlockingLayer(node) {
|
|
547
|
-
var _a;
|
|
548
|
-
const index = this.indexOf(node);
|
|
549
|
-
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
|
|
550
|
-
return index < highestBlockingIndex;
|
|
551
|
-
},
|
|
552
|
-
isTopMost(node) {
|
|
553
|
-
const layer = this.layers[this.count() - 1];
|
|
554
|
-
return (layer == null ? void 0 : layer.node) === node;
|
|
555
|
-
},
|
|
556
|
-
getNestedLayers(node) {
|
|
557
|
-
return Array.from(this.layers).slice(this.indexOf(node) + 1);
|
|
558
|
-
},
|
|
559
|
-
isInNestedLayer(node, target) {
|
|
560
|
-
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
|
|
561
|
-
},
|
|
562
|
-
isInBranch(target) {
|
|
563
|
-
return Array.from(this.branches).some((branch) => contains(branch, target));
|
|
564
|
-
},
|
|
565
|
-
add(layer) {
|
|
566
|
-
this.layers.push(layer);
|
|
567
|
-
},
|
|
568
|
-
addBranch(node) {
|
|
569
|
-
this.branches.push(node);
|
|
570
|
-
},
|
|
571
|
-
remove(node) {
|
|
572
|
-
const index = this.indexOf(node);
|
|
573
|
-
if (index < 0)
|
|
574
|
-
return;
|
|
575
|
-
if (index < this.count() - 1) {
|
|
576
|
-
const _layers = this.getNestedLayers(node);
|
|
577
|
-
_layers.forEach((layer) => layer.dismiss());
|
|
578
|
-
}
|
|
579
|
-
this.layers.splice(index, 1);
|
|
580
|
-
},
|
|
581
|
-
removeBranch(node) {
|
|
582
|
-
const index = this.branches.indexOf(node);
|
|
583
|
-
if (index >= 0)
|
|
584
|
-
this.branches.splice(index, 1);
|
|
585
|
-
},
|
|
586
|
-
indexOf(node) {
|
|
587
|
-
return this.layers.findIndex((layer) => layer.node === node);
|
|
588
|
-
},
|
|
589
|
-
dismiss(node) {
|
|
590
|
-
var _a;
|
|
591
|
-
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
|
|
592
|
-
},
|
|
593
|
-
clear() {
|
|
594
|
-
this.remove(this.layers[0].node);
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
// ../../utilities/dismissable/src/pointer-event-outside.ts
|
|
599
|
-
var originalBodyPointerEvents;
|
|
600
|
-
function assignPointerEventToLayers() {
|
|
601
|
-
layerStack.layers.forEach(({ node }) => {
|
|
602
|
-
node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
function clearPointerEvent(node) {
|
|
606
|
-
node.style.pointerEvents = "";
|
|
607
|
-
}
|
|
608
|
-
var DATA_ATTR = "data-inert";
|
|
609
|
-
function disablePointerEventsOutside(node) {
|
|
610
|
-
const doc = getDocument(node);
|
|
611
|
-
if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
|
|
612
|
-
originalBodyPointerEvents = document.body.style.pointerEvents;
|
|
613
|
-
doc.body.style.pointerEvents = "none";
|
|
614
|
-
doc.body.setAttribute(DATA_ATTR, "");
|
|
615
|
-
}
|
|
616
|
-
return () => {
|
|
617
|
-
if (layerStack.hasPointerBlockingLayer())
|
|
618
|
-
return;
|
|
619
|
-
doc.body.style.pointerEvents = originalBodyPointerEvents;
|
|
620
|
-
doc.body.removeAttribute(DATA_ATTR);
|
|
621
|
-
if (doc.body.style.length === 0)
|
|
622
|
-
doc.body.removeAttribute("style");
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// ../../utilities/dismissable/src/dismissable-layer.ts
|
|
627
|
-
function trackDismissableElement(node, options) {
|
|
628
|
-
if (!node)
|
|
629
|
-
return;
|
|
630
|
-
const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
|
|
631
|
-
const layer = { dismiss: onDismiss, node, pointerBlocking };
|
|
632
|
-
layerStack.add(layer);
|
|
633
|
-
assignPointerEventToLayers();
|
|
634
|
-
function onPointerDownOutside(event) {
|
|
635
|
-
var _a, _b;
|
|
636
|
-
const target = getEventTarget(event.detail.originalEvent);
|
|
637
|
-
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
|
|
638
|
-
return;
|
|
639
|
-
(_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
|
|
640
|
-
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
641
|
-
if (event.defaultPrevented)
|
|
642
|
-
return;
|
|
643
|
-
if (debug) {
|
|
644
|
-
console.log("onPointerDownOutside:", event.detail.originalEvent);
|
|
645
|
-
}
|
|
646
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
647
|
-
}
|
|
648
|
-
function onFocusOutside(event) {
|
|
649
|
-
var _a, _b;
|
|
650
|
-
const target = getEventTarget(event.detail.originalEvent);
|
|
651
|
-
if (layerStack.isInBranch(target))
|
|
652
|
-
return;
|
|
653
|
-
(_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
|
|
654
|
-
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
655
|
-
if (event.defaultPrevented)
|
|
656
|
-
return;
|
|
657
|
-
if (debug) {
|
|
658
|
-
console.log("onFocusOutside:", event.detail.originalEvent);
|
|
659
|
-
}
|
|
660
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
661
|
-
}
|
|
662
|
-
function onEscapeKeyDown(event) {
|
|
663
|
-
var _a;
|
|
664
|
-
if (!layerStack.isTopMost(node))
|
|
665
|
-
return;
|
|
666
|
-
(_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
|
|
667
|
-
if (!event.defaultPrevented && onDismiss) {
|
|
668
|
-
event.preventDefault();
|
|
669
|
-
onDismiss();
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
function exclude(target) {
|
|
673
|
-
if (!node)
|
|
674
|
-
return false;
|
|
675
|
-
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
676
|
-
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
677
|
-
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
|
|
678
|
-
}
|
|
679
|
-
const cleanups = [
|
|
680
|
-
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
|
|
681
|
-
trackEscapeKeydown(onEscapeKeyDown),
|
|
682
|
-
trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
|
|
683
|
-
];
|
|
684
|
-
return () => {
|
|
685
|
-
layerStack.remove(node);
|
|
686
|
-
assignPointerEventToLayers();
|
|
687
|
-
clearPointerEvent(node);
|
|
688
|
-
cleanups.forEach((fn) => fn == null ? void 0 : fn());
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
// src/popover.machine.ts
|
|
366
|
+
var import_dismissable = require("@zag-js/dismissable");
|
|
693
367
|
var import_popper2 = require("@zag-js/popper");
|
|
694
368
|
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
695
369
|
var import_focus_trap = require("focus-trap");
|
|
@@ -728,7 +402,7 @@ function machine(ctx) {
|
|
|
728
402
|
}
|
|
729
403
|
},
|
|
730
404
|
closed: {
|
|
731
|
-
entry:
|
|
405
|
+
entry: "invokeOnClose",
|
|
732
406
|
on: {
|
|
733
407
|
TOGGLE: "open",
|
|
734
408
|
OPEN: "open"
|
|
@@ -790,7 +464,7 @@ function machine(ctx) {
|
|
|
790
464
|
}));
|
|
791
465
|
},
|
|
792
466
|
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
793
|
-
return trackDismissableElement(dom.getContentEl(ctx2), {
|
|
467
|
+
return (0, import_dismissable.trackDismissableElement)(dom.getContentEl(ctx2), {
|
|
794
468
|
pointerBlocking: ctx2.modal,
|
|
795
469
|
exclude: dom.getTriggerEl(ctx2),
|
|
796
470
|
onEscapeKeyDown(event) {
|
|
@@ -897,9 +571,6 @@ function machine(ctx) {
|
|
|
897
571
|
});
|
|
898
572
|
});
|
|
899
573
|
},
|
|
900
|
-
clearPointerDown(ctx2) {
|
|
901
|
-
ctx2.pointerdownNode = null;
|
|
902
|
-
},
|
|
903
574
|
setInitialFocus(ctx2) {
|
|
904
575
|
raf(() => {
|
|
905
576
|
var _a;
|
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 defineDomHelpers(domUtils) {
|
|
68
64
|
const roots = {
|
|
69
65
|
getRootNode: (ctx) => {
|
|
@@ -75,7 +71,8 @@ function defineDomHelpers(domUtils) {
|
|
|
75
71
|
var _a;
|
|
76
72
|
return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
|
|
77
73
|
},
|
|
78
|
-
getActiveElement: (ctx) => roots.getDoc(ctx).activeElement
|
|
74
|
+
getActiveElement: (ctx) => roots.getDoc(ctx).activeElement,
|
|
75
|
+
getById: (ctx, id) => roots.getRootNode(ctx).getElementById(id)
|
|
79
76
|
};
|
|
80
77
|
return __spreadValues2(__spreadValues2({}, roots), domUtils);
|
|
81
78
|
}
|
|
@@ -342,330 +339,7 @@ function connect(state, send, normalize) {
|
|
|
342
339
|
// src/popover.machine.ts
|
|
343
340
|
import { ariaHidden } from "@zag-js/aria-hidden";
|
|
344
341
|
import { createMachine, guards } from "@zag-js/core";
|
|
345
|
-
|
|
346
|
-
// ../../utilities/interact-outside/dist/index.mjs
|
|
347
|
-
var runIfFn3 = (v, ...a) => {
|
|
348
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
349
|
-
return res != null ? res : void 0;
|
|
350
|
-
};
|
|
351
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
352
|
-
var isDom = () => typeof window !== "undefined";
|
|
353
|
-
function getPlatform() {
|
|
354
|
-
var _a;
|
|
355
|
-
const agent = navigator.userAgentData;
|
|
356
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
357
|
-
}
|
|
358
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
359
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
360
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
361
|
-
function isDocument2(el) {
|
|
362
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
363
|
-
}
|
|
364
|
-
function isWindow2(value) {
|
|
365
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
366
|
-
}
|
|
367
|
-
function getDocument2(el) {
|
|
368
|
-
var _a;
|
|
369
|
-
if (isWindow2(el))
|
|
370
|
-
return el.document;
|
|
371
|
-
if (isDocument2(el))
|
|
372
|
-
return el;
|
|
373
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
374
|
-
}
|
|
375
|
-
function getWindow(el) {
|
|
376
|
-
var _a;
|
|
377
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
378
|
-
}
|
|
379
|
-
function getEventTarget2(event) {
|
|
380
|
-
var _a, _b;
|
|
381
|
-
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
382
|
-
}
|
|
383
|
-
function contains2(parent, child) {
|
|
384
|
-
if (!parent)
|
|
385
|
-
return false;
|
|
386
|
-
return parent === child || isHTMLElement2(parent) && isHTMLElement2(child) && parent.contains(child);
|
|
387
|
-
}
|
|
388
|
-
function isHTMLElement2(v) {
|
|
389
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
390
|
-
}
|
|
391
|
-
function isVisible2(el) {
|
|
392
|
-
if (!isHTMLElement2(el))
|
|
393
|
-
return false;
|
|
394
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
395
|
-
}
|
|
396
|
-
var isContextMenuEvent = (e) => {
|
|
397
|
-
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
398
|
-
};
|
|
399
|
-
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
400
|
-
function fireCustomEvent(el, type, init) {
|
|
401
|
-
if (!el)
|
|
402
|
-
return;
|
|
403
|
-
const win = getWindow(el);
|
|
404
|
-
const event = new win.CustomEvent(type, init);
|
|
405
|
-
return el.dispatchEvent(event);
|
|
406
|
-
}
|
|
407
|
-
var focusableSelector2 = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
408
|
-
function isFocusable2(element) {
|
|
409
|
-
if (!element)
|
|
410
|
-
return false;
|
|
411
|
-
return element.matches(focusableSelector2) && isVisible2(element);
|
|
412
|
-
}
|
|
413
|
-
var isRef2 = (v) => hasProp2(v, "current");
|
|
414
|
-
function addDomEvent2(target, eventName, handler, options) {
|
|
415
|
-
const node = isRef2(target) ? target.current : runIfFn3(target);
|
|
416
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
417
|
-
return () => {
|
|
418
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
422
|
-
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
423
|
-
function trackInteractOutside(node, options) {
|
|
424
|
-
const { exclude, onFocusOutside, onPointerDownOutside } = options;
|
|
425
|
-
if (!node)
|
|
426
|
-
return;
|
|
427
|
-
const doc = getDocument2(node);
|
|
428
|
-
const win = getWindow(node);
|
|
429
|
-
function isEventOutside(event) {
|
|
430
|
-
const target = getEventTarget2(event);
|
|
431
|
-
if (!(target instanceof win.HTMLElement)) {
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
if (!contains2(doc.documentElement, target)) {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
if (contains2(node, target)) {
|
|
438
|
-
return false;
|
|
439
|
-
}
|
|
440
|
-
return !(exclude == null ? void 0 : exclude(target));
|
|
441
|
-
}
|
|
442
|
-
let clickHandler;
|
|
443
|
-
function onPointerDown(event) {
|
|
444
|
-
function handler() {
|
|
445
|
-
if (!node || !isEventOutside(event))
|
|
446
|
-
return;
|
|
447
|
-
if (onPointerDownOutside) {
|
|
448
|
-
node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
|
|
449
|
-
}
|
|
450
|
-
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
451
|
-
bubbles: false,
|
|
452
|
-
cancelable: true,
|
|
453
|
-
detail: {
|
|
454
|
-
originalEvent: event,
|
|
455
|
-
contextmenu: isContextMenuEvent(event),
|
|
456
|
-
focusable: isFocusable2(getEventTarget2(event))
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
if (event.pointerType === "touch") {
|
|
461
|
-
doc.removeEventListener("click", handler);
|
|
462
|
-
clickHandler = handler;
|
|
463
|
-
doc.addEventListener("click", handler, { once: true });
|
|
464
|
-
} else {
|
|
465
|
-
handler();
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
469
|
-
const timer = setTimeout(() => {
|
|
470
|
-
cleanups.add(addDomEvent2(doc, "pointerdown", onPointerDown, true));
|
|
471
|
-
}, 0);
|
|
472
|
-
function onFocusin(event) {
|
|
473
|
-
if (!node || !isEventOutside(event))
|
|
474
|
-
return;
|
|
475
|
-
if (onFocusOutside) {
|
|
476
|
-
node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
|
|
477
|
-
}
|
|
478
|
-
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
479
|
-
bubbles: false,
|
|
480
|
-
cancelable: true,
|
|
481
|
-
detail: {
|
|
482
|
-
originalEvent: event,
|
|
483
|
-
contextmenu: false,
|
|
484
|
-
focusable: isFocusable2(getEventTarget2(event))
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
cleanups.add(addDomEvent2(doc, "focusin", onFocusin, true));
|
|
489
|
-
return () => {
|
|
490
|
-
clearTimeout(timer);
|
|
491
|
-
if (clickHandler)
|
|
492
|
-
doc.removeEventListener("click", clickHandler);
|
|
493
|
-
cleanups.forEach((fn) => fn());
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// ../../utilities/dismissable/src/escape-keydown.ts
|
|
498
|
-
function trackEscapeKeydown(fn) {
|
|
499
|
-
const handleKeyDown = (event) => {
|
|
500
|
-
if (event.key === "Escape")
|
|
501
|
-
fn == null ? void 0 : fn(event);
|
|
502
|
-
};
|
|
503
|
-
return addDomEvent(document, "keydown", handleKeyDown);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// ../../utilities/dismissable/src/layer-stack.ts
|
|
507
|
-
var layerStack = {
|
|
508
|
-
layers: [],
|
|
509
|
-
branches: [],
|
|
510
|
-
count() {
|
|
511
|
-
return this.layers.length;
|
|
512
|
-
},
|
|
513
|
-
pointerBlockingLayers() {
|
|
514
|
-
return this.layers.filter((layer) => layer.pointerBlocking);
|
|
515
|
-
},
|
|
516
|
-
topMostPointerBlockingLayer() {
|
|
517
|
-
return [...this.pointerBlockingLayers()].slice(-1)[0];
|
|
518
|
-
},
|
|
519
|
-
hasPointerBlockingLayer() {
|
|
520
|
-
return this.pointerBlockingLayers().length > 0;
|
|
521
|
-
},
|
|
522
|
-
isBelowPointerBlockingLayer(node) {
|
|
523
|
-
var _a;
|
|
524
|
-
const index = this.indexOf(node);
|
|
525
|
-
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
|
|
526
|
-
return index < highestBlockingIndex;
|
|
527
|
-
},
|
|
528
|
-
isTopMost(node) {
|
|
529
|
-
const layer = this.layers[this.count() - 1];
|
|
530
|
-
return (layer == null ? void 0 : layer.node) === node;
|
|
531
|
-
},
|
|
532
|
-
getNestedLayers(node) {
|
|
533
|
-
return Array.from(this.layers).slice(this.indexOf(node) + 1);
|
|
534
|
-
},
|
|
535
|
-
isInNestedLayer(node, target) {
|
|
536
|
-
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
|
|
537
|
-
},
|
|
538
|
-
isInBranch(target) {
|
|
539
|
-
return Array.from(this.branches).some((branch) => contains(branch, target));
|
|
540
|
-
},
|
|
541
|
-
add(layer) {
|
|
542
|
-
this.layers.push(layer);
|
|
543
|
-
},
|
|
544
|
-
addBranch(node) {
|
|
545
|
-
this.branches.push(node);
|
|
546
|
-
},
|
|
547
|
-
remove(node) {
|
|
548
|
-
const index = this.indexOf(node);
|
|
549
|
-
if (index < 0)
|
|
550
|
-
return;
|
|
551
|
-
if (index < this.count() - 1) {
|
|
552
|
-
const _layers = this.getNestedLayers(node);
|
|
553
|
-
_layers.forEach((layer) => layer.dismiss());
|
|
554
|
-
}
|
|
555
|
-
this.layers.splice(index, 1);
|
|
556
|
-
},
|
|
557
|
-
removeBranch(node) {
|
|
558
|
-
const index = this.branches.indexOf(node);
|
|
559
|
-
if (index >= 0)
|
|
560
|
-
this.branches.splice(index, 1);
|
|
561
|
-
},
|
|
562
|
-
indexOf(node) {
|
|
563
|
-
return this.layers.findIndex((layer) => layer.node === node);
|
|
564
|
-
},
|
|
565
|
-
dismiss(node) {
|
|
566
|
-
var _a;
|
|
567
|
-
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
|
|
568
|
-
},
|
|
569
|
-
clear() {
|
|
570
|
-
this.remove(this.layers[0].node);
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
// ../../utilities/dismissable/src/pointer-event-outside.ts
|
|
575
|
-
var originalBodyPointerEvents;
|
|
576
|
-
function assignPointerEventToLayers() {
|
|
577
|
-
layerStack.layers.forEach(({ node }) => {
|
|
578
|
-
node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
function clearPointerEvent(node) {
|
|
582
|
-
node.style.pointerEvents = "";
|
|
583
|
-
}
|
|
584
|
-
var DATA_ATTR = "data-inert";
|
|
585
|
-
function disablePointerEventsOutside(node) {
|
|
586
|
-
const doc = getDocument(node);
|
|
587
|
-
if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
|
|
588
|
-
originalBodyPointerEvents = document.body.style.pointerEvents;
|
|
589
|
-
doc.body.style.pointerEvents = "none";
|
|
590
|
-
doc.body.setAttribute(DATA_ATTR, "");
|
|
591
|
-
}
|
|
592
|
-
return () => {
|
|
593
|
-
if (layerStack.hasPointerBlockingLayer())
|
|
594
|
-
return;
|
|
595
|
-
doc.body.style.pointerEvents = originalBodyPointerEvents;
|
|
596
|
-
doc.body.removeAttribute(DATA_ATTR);
|
|
597
|
-
if (doc.body.style.length === 0)
|
|
598
|
-
doc.body.removeAttribute("style");
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// ../../utilities/dismissable/src/dismissable-layer.ts
|
|
603
|
-
function trackDismissableElement(node, options) {
|
|
604
|
-
if (!node)
|
|
605
|
-
return;
|
|
606
|
-
const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
|
|
607
|
-
const layer = { dismiss: onDismiss, node, pointerBlocking };
|
|
608
|
-
layerStack.add(layer);
|
|
609
|
-
assignPointerEventToLayers();
|
|
610
|
-
function onPointerDownOutside(event) {
|
|
611
|
-
var _a, _b;
|
|
612
|
-
const target = getEventTarget(event.detail.originalEvent);
|
|
613
|
-
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
|
|
614
|
-
return;
|
|
615
|
-
(_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
|
|
616
|
-
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
617
|
-
if (event.defaultPrevented)
|
|
618
|
-
return;
|
|
619
|
-
if (debug) {
|
|
620
|
-
console.log("onPointerDownOutside:", event.detail.originalEvent);
|
|
621
|
-
}
|
|
622
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
623
|
-
}
|
|
624
|
-
function onFocusOutside(event) {
|
|
625
|
-
var _a, _b;
|
|
626
|
-
const target = getEventTarget(event.detail.originalEvent);
|
|
627
|
-
if (layerStack.isInBranch(target))
|
|
628
|
-
return;
|
|
629
|
-
(_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
|
|
630
|
-
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
631
|
-
if (event.defaultPrevented)
|
|
632
|
-
return;
|
|
633
|
-
if (debug) {
|
|
634
|
-
console.log("onFocusOutside:", event.detail.originalEvent);
|
|
635
|
-
}
|
|
636
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
637
|
-
}
|
|
638
|
-
function onEscapeKeyDown(event) {
|
|
639
|
-
var _a;
|
|
640
|
-
if (!layerStack.isTopMost(node))
|
|
641
|
-
return;
|
|
642
|
-
(_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
|
|
643
|
-
if (!event.defaultPrevented && onDismiss) {
|
|
644
|
-
event.preventDefault();
|
|
645
|
-
onDismiss();
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function exclude(target) {
|
|
649
|
-
if (!node)
|
|
650
|
-
return false;
|
|
651
|
-
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
652
|
-
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
653
|
-
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
|
|
654
|
-
}
|
|
655
|
-
const cleanups = [
|
|
656
|
-
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
|
|
657
|
-
trackEscapeKeydown(onEscapeKeyDown),
|
|
658
|
-
trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
|
|
659
|
-
];
|
|
660
|
-
return () => {
|
|
661
|
-
layerStack.remove(node);
|
|
662
|
-
assignPointerEventToLayers();
|
|
663
|
-
clearPointerEvent(node);
|
|
664
|
-
cleanups.forEach((fn) => fn == null ? void 0 : fn());
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// src/popover.machine.ts
|
|
342
|
+
import { trackDismissableElement } from "@zag-js/dismissable";
|
|
669
343
|
import { getPlacement } from "@zag-js/popper";
|
|
670
344
|
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
671
345
|
import { createFocusTrap } from "focus-trap";
|
|
@@ -704,7 +378,7 @@ function machine(ctx) {
|
|
|
704
378
|
}
|
|
705
379
|
},
|
|
706
380
|
closed: {
|
|
707
|
-
entry:
|
|
381
|
+
entry: "invokeOnClose",
|
|
708
382
|
on: {
|
|
709
383
|
TOGGLE: "open",
|
|
710
384
|
OPEN: "open"
|
|
@@ -873,9 +547,6 @@ function machine(ctx) {
|
|
|
873
547
|
});
|
|
874
548
|
});
|
|
875
549
|
},
|
|
876
|
-
clearPointerDown(ctx2) {
|
|
877
|
-
ctx2.pointerdownNode = null;
|
|
878
|
-
},
|
|
879
550
|
setInitialFocus(ctx2) {
|
|
880
551
|
raf(() => {
|
|
881
552
|
var _a;
|
package/dist/popover.dom.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import type { MachineContext as Ctx } from "./popover.types";
|
|
2
2
|
export declare const dom: {
|
|
3
3
|
getRootNode: (ctx: {
|
|
4
|
-
getRootNode?: () =>
|
|
4
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
5
5
|
}) => Document | ShadowRoot;
|
|
6
6
|
getDoc: (ctx: {
|
|
7
|
-
getRootNode?: () =>
|
|
7
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
8
8
|
}) => Document;
|
|
9
9
|
getWin: (ctx: {
|
|
10
|
-
getRootNode?: () =>
|
|
10
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
11
11
|
}) => Window & typeof globalThis;
|
|
12
12
|
getActiveElement: (ctx: {
|
|
13
|
-
getRootNode?: () =>
|
|
13
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
14
14
|
}) => HTMLElement;
|
|
15
|
+
getById: (ctx: {
|
|
16
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
17
|
+
}, id: string) => HTMLElement;
|
|
15
18
|
} & {
|
|
16
19
|
getActiveEl: (ctx: Ctx) => Element;
|
|
17
20
|
getAnchorId: (ctx: Ctx) => string;
|
package/dist/popover.types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StateMachine as S } from "@zag-js/core";
|
|
2
|
-
import type { DismissableElementHandlers } from "@zag-js/
|
|
2
|
+
import type { DismissableElementHandlers } from "@zag-js/dismissable";
|
|
3
3
|
import type { PositioningOptions, Placement } from "@zag-js/popper";
|
|
4
4
|
import type { CommonProperties, Context, MaybeElement, RequiredBy } from "@zag-js/types";
|
|
5
5
|
declare type ElementIds = Partial<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popover",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220710102425",
|
|
4
4
|
"description": "Core logic for the popover widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -31,13 +31,16 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@zag-js/aria-hidden": "0.1.0",
|
|
33
33
|
"@zag-js/core": "0.1.7",
|
|
34
|
-
"@zag-js/
|
|
35
|
-
"@zag-js/popper": "0.0.0-dev-
|
|
36
|
-
"@zag-js/remove-scroll": "0.0.0-dev-
|
|
37
|
-
"@zag-js/types": "0.0.0-dev-
|
|
38
|
-
"@zag-js/utils": "0.1.2",
|
|
34
|
+
"@zag-js/dismissable": "0.0.0-dev-20220710102425",
|
|
35
|
+
"@zag-js/popper": "0.0.0-dev-20220710102425",
|
|
36
|
+
"@zag-js/remove-scroll": "0.0.0-dev-20220710102425",
|
|
37
|
+
"@zag-js/types": "0.0.0-dev-20220710102425",
|
|
39
38
|
"focus-trap": "6.9.4"
|
|
40
39
|
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220710102425",
|
|
42
|
+
"@zag-js/utils": "0.1.2"
|
|
43
|
+
},
|
|
41
44
|
"scripts": {
|
|
42
45
|
"build:fast": "zag build",
|
|
43
46
|
"start": "zag build --watch",
|