@zag-js/popover 0.0.0-dev-20220704151659 → 0.0.0-dev-20220707125149
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 +54 -46
- package/dist/index.mjs +54 -46
- package/dist/popover.types.d.ts +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -46,6 +46,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
46
46
|
var dataAttr = (guard) => {
|
|
47
47
|
return guard ? "" : void 0;
|
|
48
48
|
};
|
|
49
|
+
var runIfFn = (v, ...a) => {
|
|
50
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
51
|
+
return res != null ? res : void 0;
|
|
52
|
+
};
|
|
53
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
49
54
|
function isWindow(value) {
|
|
50
55
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
51
56
|
}
|
|
@@ -75,6 +80,7 @@ function isVisible(el) {
|
|
|
75
80
|
return false;
|
|
76
81
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
77
82
|
}
|
|
83
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
78
84
|
function hasNegativeTabIndex(element) {
|
|
79
85
|
const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
|
|
80
86
|
return tabIndex < 0;
|
|
@@ -133,11 +139,6 @@ function getLastTabbable(container, includeContainer) {
|
|
|
133
139
|
const elements = getTabbables(container, includeContainer);
|
|
134
140
|
return elements[elements.length - 1] || null;
|
|
135
141
|
}
|
|
136
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
137
|
-
var runIfFn = (v, ...a) => {
|
|
138
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
139
|
-
return res != null ? res : void 0;
|
|
140
|
-
};
|
|
141
142
|
var isRef = (v) => hasProp(v, "current");
|
|
142
143
|
function addDomEvent(target, eventName, handler, options) {
|
|
143
144
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -186,7 +187,6 @@ function nextIndex(v, idx, opts = {}) {
|
|
|
186
187
|
function next(v, idx, opts = {}) {
|
|
187
188
|
return v[nextIndex(v, idx, opts)];
|
|
188
189
|
}
|
|
189
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
190
190
|
var runIfFn2 = (v, ...a) => {
|
|
191
191
|
const res = typeof v === "function" ? v(...a) : v;
|
|
192
192
|
return res != null ? res : void 0;
|
|
@@ -344,6 +344,20 @@ var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
|
344
344
|
var import_core = require("@zag-js/core");
|
|
345
345
|
|
|
346
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;
|
|
347
361
|
function isWindow2(value) {
|
|
348
362
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
349
363
|
}
|
|
@@ -374,10 +388,15 @@ function isVisible2(el) {
|
|
|
374
388
|
return false;
|
|
375
389
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
376
390
|
}
|
|
391
|
+
var isContextMenuEvent = (e) => {
|
|
392
|
+
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
393
|
+
};
|
|
394
|
+
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
377
395
|
function fireCustomEvent(el, type, init) {
|
|
378
396
|
if (!el)
|
|
379
397
|
return;
|
|
380
|
-
const
|
|
398
|
+
const win = getWindow(el);
|
|
399
|
+
const event = new win.CustomEvent(type, init);
|
|
381
400
|
return el.dispatchEvent(event);
|
|
382
401
|
}
|
|
383
402
|
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";
|
|
@@ -386,11 +405,6 @@ function isFocusable2(element) {
|
|
|
386
405
|
return false;
|
|
387
406
|
return element.matches(focusableSelector2) && isVisible2(element);
|
|
388
407
|
}
|
|
389
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
390
|
-
var runIfFn3 = (v, ...a) => {
|
|
391
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
392
|
-
return res != null ? res : void 0;
|
|
393
|
-
};
|
|
394
408
|
var isRef2 = (v) => hasProp2(v, "current");
|
|
395
409
|
function addDomEvent2(target, eventName, handler, options) {
|
|
396
410
|
const node = isRef2(target) ? target.current : runIfFn3(target);
|
|
@@ -399,19 +413,6 @@ function addDomEvent2(target, eventName, handler, options) {
|
|
|
399
413
|
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
400
414
|
};
|
|
401
415
|
}
|
|
402
|
-
var isDom = () => typeof window !== "undefined";
|
|
403
|
-
function getPlatform() {
|
|
404
|
-
var _a;
|
|
405
|
-
const agent = navigator.userAgentData;
|
|
406
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
407
|
-
}
|
|
408
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
409
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
410
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
411
|
-
var isContextMenuEvent = (e) => {
|
|
412
|
-
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
413
|
-
};
|
|
414
|
-
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
415
416
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
416
417
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
417
418
|
function trackInteractOutside(node, options) {
|
|
@@ -523,14 +524,14 @@ var layerStack = {
|
|
|
523
524
|
const layer = this.layers[this.count() - 1];
|
|
524
525
|
return (layer == null ? void 0 : layer.node) === node;
|
|
525
526
|
},
|
|
526
|
-
|
|
527
|
-
return this.layers.slice(this.indexOf(node));
|
|
527
|
+
getNestedLayers(node) {
|
|
528
|
+
return Array.from(this.layers).slice(this.indexOf(node) + 1);
|
|
528
529
|
},
|
|
529
|
-
|
|
530
|
-
return this.
|
|
530
|
+
isInNestedLayer(node, target) {
|
|
531
|
+
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
|
|
531
532
|
},
|
|
532
533
|
isInBranch(target) {
|
|
533
|
-
return
|
|
534
|
+
return Array.from(this.branches).some((branch) => contains(branch, target));
|
|
534
535
|
},
|
|
535
536
|
add(layer) {
|
|
536
537
|
this.layers.push(layer);
|
|
@@ -540,10 +541,13 @@ var layerStack = {
|
|
|
540
541
|
},
|
|
541
542
|
remove(node) {
|
|
542
543
|
const index = this.indexOf(node);
|
|
543
|
-
if (index
|
|
544
|
-
|
|
544
|
+
if (index < 0)
|
|
545
|
+
return;
|
|
546
|
+
if (index < this.count() - 1) {
|
|
547
|
+
const _layers = this.getNestedLayers(node);
|
|
548
|
+
_layers.forEach((layer) => layer.dismiss());
|
|
545
549
|
}
|
|
546
|
-
this.layers
|
|
550
|
+
this.layers.splice(index, 1);
|
|
547
551
|
},
|
|
548
552
|
removeBranch(node) {
|
|
549
553
|
const index = this.branches.indexOf(node);
|
|
@@ -594,7 +598,7 @@ function disablePointerEventsOutside(node) {
|
|
|
594
598
|
function trackDismissableElement(node, options) {
|
|
595
599
|
if (!node)
|
|
596
600
|
return;
|
|
597
|
-
const { onDismiss, pointerBlocking, exclude: excludeContainers } = options;
|
|
601
|
+
const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
|
|
598
602
|
const layer = { dismiss: onDismiss, node, pointerBlocking };
|
|
599
603
|
layerStack.add(layer);
|
|
600
604
|
assignPointerEventToLayers();
|
|
@@ -607,6 +611,9 @@ function trackDismissableElement(node, options) {
|
|
|
607
611
|
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
608
612
|
if (event.defaultPrevented)
|
|
609
613
|
return;
|
|
614
|
+
if (debug) {
|
|
615
|
+
console.log("onPointerDownOutside:", event.detail.originalEvent);
|
|
616
|
+
}
|
|
610
617
|
onDismiss == null ? void 0 : onDismiss();
|
|
611
618
|
}
|
|
612
619
|
function onFocusOutside(event) {
|
|
@@ -618,6 +625,9 @@ function trackDismissableElement(node, options) {
|
|
|
618
625
|
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
619
626
|
if (event.defaultPrevented)
|
|
620
627
|
return;
|
|
628
|
+
if (debug) {
|
|
629
|
+
console.log("onFocusOutside:", event.detail.originalEvent);
|
|
630
|
+
}
|
|
621
631
|
onDismiss == null ? void 0 : onDismiss();
|
|
622
632
|
}
|
|
623
633
|
function onEscapeKeyDown(event) {
|
|
@@ -631,9 +641,11 @@ function trackDismissableElement(node, options) {
|
|
|
631
641
|
}
|
|
632
642
|
}
|
|
633
643
|
function exclude(target) {
|
|
644
|
+
if (!node)
|
|
645
|
+
return false;
|
|
634
646
|
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
635
|
-
const
|
|
636
|
-
return
|
|
647
|
+
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
648
|
+
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
|
|
637
649
|
}
|
|
638
650
|
const cleanups = [
|
|
639
651
|
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
|
|
@@ -668,7 +680,7 @@ function machine(ctx = {}) {
|
|
|
668
680
|
}, ctx.positioning),
|
|
669
681
|
currentPlacement: void 0
|
|
670
682
|
}, ctx), {
|
|
671
|
-
|
|
683
|
+
focusTriggerOnClose: true,
|
|
672
684
|
renderedElements: {
|
|
673
685
|
title: true,
|
|
674
686
|
description: true,
|
|
@@ -758,7 +770,7 @@ function machine(ctx = {}) {
|
|
|
758
770
|
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
759
771
|
if (ctx2.closeOnEsc)
|
|
760
772
|
return;
|
|
761
|
-
ctx2.
|
|
773
|
+
ctx2.focusTriggerOnClose = true;
|
|
762
774
|
event.preventDefault();
|
|
763
775
|
},
|
|
764
776
|
onInteractOutside(event) {
|
|
@@ -766,7 +778,7 @@ function machine(ctx = {}) {
|
|
|
766
778
|
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
767
779
|
if (event.defaultPrevented)
|
|
768
780
|
return;
|
|
769
|
-
ctx2.
|
|
781
|
+
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
770
782
|
if (!ctx2.closeOnInteractOutside) {
|
|
771
783
|
event.preventDefault();
|
|
772
784
|
}
|
|
@@ -874,15 +886,11 @@ function machine(ctx = {}) {
|
|
|
874
886
|
});
|
|
875
887
|
},
|
|
876
888
|
focusTriggerIfNeeded(ctx2) {
|
|
877
|
-
|
|
889
|
+
if (!ctx2.focusTriggerOnClose)
|
|
890
|
+
return;
|
|
891
|
+
raf(() => {
|
|
878
892
|
var _a;
|
|
879
893
|
return (_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
880
|
-
};
|
|
881
|
-
raf(() => {
|
|
882
|
-
if (!ctx2.preventReturnFocus) {
|
|
883
|
-
focus();
|
|
884
|
-
ctx2.preventReturnFocus = false;
|
|
885
|
-
}
|
|
886
894
|
});
|
|
887
895
|
},
|
|
888
896
|
focusFirstTabbableElement(ctx2, evt) {
|
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
22
22
|
var dataAttr = (guard) => {
|
|
23
23
|
return guard ? "" : void 0;
|
|
24
24
|
};
|
|
25
|
+
var runIfFn = (v, ...a) => {
|
|
26
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
27
|
+
return res != null ? res : void 0;
|
|
28
|
+
};
|
|
29
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
30
|
function isWindow(value) {
|
|
26
31
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
27
32
|
}
|
|
@@ -51,6 +56,7 @@ function isVisible(el) {
|
|
|
51
56
|
return false;
|
|
52
57
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
53
58
|
}
|
|
59
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
54
60
|
function hasNegativeTabIndex(element) {
|
|
55
61
|
const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
|
|
56
62
|
return tabIndex < 0;
|
|
@@ -109,11 +115,6 @@ function getLastTabbable(container, includeContainer) {
|
|
|
109
115
|
const elements = getTabbables(container, includeContainer);
|
|
110
116
|
return elements[elements.length - 1] || null;
|
|
111
117
|
}
|
|
112
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
113
|
-
var runIfFn = (v, ...a) => {
|
|
114
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
115
|
-
return res != null ? res : void 0;
|
|
116
|
-
};
|
|
117
118
|
var isRef = (v) => hasProp(v, "current");
|
|
118
119
|
function addDomEvent(target, eventName, handler, options) {
|
|
119
120
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -162,7 +163,6 @@ function nextIndex(v, idx, opts = {}) {
|
|
|
162
163
|
function next(v, idx, opts = {}) {
|
|
163
164
|
return v[nextIndex(v, idx, opts)];
|
|
164
165
|
}
|
|
165
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
166
166
|
var runIfFn2 = (v, ...a) => {
|
|
167
167
|
const res = typeof v === "function" ? v(...a) : v;
|
|
168
168
|
return res != null ? res : void 0;
|
|
@@ -320,6 +320,20 @@ import { ariaHidden } from "@zag-js/aria-hidden";
|
|
|
320
320
|
import { createMachine, guards, ref } from "@zag-js/core";
|
|
321
321
|
|
|
322
322
|
// ../../utilities/interact-outside/dist/index.mjs
|
|
323
|
+
var runIfFn3 = (v, ...a) => {
|
|
324
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
325
|
+
return res != null ? res : void 0;
|
|
326
|
+
};
|
|
327
|
+
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
328
|
+
var isDom = () => typeof window !== "undefined";
|
|
329
|
+
function getPlatform() {
|
|
330
|
+
var _a;
|
|
331
|
+
const agent = navigator.userAgentData;
|
|
332
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
333
|
+
}
|
|
334
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
335
|
+
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
336
|
+
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
323
337
|
function isWindow2(value) {
|
|
324
338
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
325
339
|
}
|
|
@@ -350,10 +364,15 @@ function isVisible2(el) {
|
|
|
350
364
|
return false;
|
|
351
365
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
352
366
|
}
|
|
367
|
+
var isContextMenuEvent = (e) => {
|
|
368
|
+
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
369
|
+
};
|
|
370
|
+
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
353
371
|
function fireCustomEvent(el, type, init) {
|
|
354
372
|
if (!el)
|
|
355
373
|
return;
|
|
356
|
-
const
|
|
374
|
+
const win = getWindow(el);
|
|
375
|
+
const event = new win.CustomEvent(type, init);
|
|
357
376
|
return el.dispatchEvent(event);
|
|
358
377
|
}
|
|
359
378
|
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";
|
|
@@ -362,11 +381,6 @@ function isFocusable2(element) {
|
|
|
362
381
|
return false;
|
|
363
382
|
return element.matches(focusableSelector2) && isVisible2(element);
|
|
364
383
|
}
|
|
365
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
366
|
-
var runIfFn3 = (v, ...a) => {
|
|
367
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
368
|
-
return res != null ? res : void 0;
|
|
369
|
-
};
|
|
370
384
|
var isRef2 = (v) => hasProp2(v, "current");
|
|
371
385
|
function addDomEvent2(target, eventName, handler, options) {
|
|
372
386
|
const node = isRef2(target) ? target.current : runIfFn3(target);
|
|
@@ -375,19 +389,6 @@ function addDomEvent2(target, eventName, handler, options) {
|
|
|
375
389
|
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
376
390
|
};
|
|
377
391
|
}
|
|
378
|
-
var isDom = () => typeof window !== "undefined";
|
|
379
|
-
function getPlatform() {
|
|
380
|
-
var _a;
|
|
381
|
-
const agent = navigator.userAgentData;
|
|
382
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
383
|
-
}
|
|
384
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
385
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
386
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
387
|
-
var isContextMenuEvent = (e) => {
|
|
388
|
-
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
389
|
-
};
|
|
390
|
-
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
391
392
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
392
393
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
393
394
|
function trackInteractOutside(node, options) {
|
|
@@ -499,14 +500,14 @@ var layerStack = {
|
|
|
499
500
|
const layer = this.layers[this.count() - 1];
|
|
500
501
|
return (layer == null ? void 0 : layer.node) === node;
|
|
501
502
|
},
|
|
502
|
-
|
|
503
|
-
return this.layers.slice(this.indexOf(node));
|
|
503
|
+
getNestedLayers(node) {
|
|
504
|
+
return Array.from(this.layers).slice(this.indexOf(node) + 1);
|
|
504
505
|
},
|
|
505
|
-
|
|
506
|
-
return this.
|
|
506
|
+
isInNestedLayer(node, target) {
|
|
507
|
+
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
|
|
507
508
|
},
|
|
508
509
|
isInBranch(target) {
|
|
509
|
-
return
|
|
510
|
+
return Array.from(this.branches).some((branch) => contains(branch, target));
|
|
510
511
|
},
|
|
511
512
|
add(layer) {
|
|
512
513
|
this.layers.push(layer);
|
|
@@ -516,10 +517,13 @@ var layerStack = {
|
|
|
516
517
|
},
|
|
517
518
|
remove(node) {
|
|
518
519
|
const index = this.indexOf(node);
|
|
519
|
-
if (index
|
|
520
|
-
|
|
520
|
+
if (index < 0)
|
|
521
|
+
return;
|
|
522
|
+
if (index < this.count() - 1) {
|
|
523
|
+
const _layers = this.getNestedLayers(node);
|
|
524
|
+
_layers.forEach((layer) => layer.dismiss());
|
|
521
525
|
}
|
|
522
|
-
this.layers
|
|
526
|
+
this.layers.splice(index, 1);
|
|
523
527
|
},
|
|
524
528
|
removeBranch(node) {
|
|
525
529
|
const index = this.branches.indexOf(node);
|
|
@@ -570,7 +574,7 @@ function disablePointerEventsOutside(node) {
|
|
|
570
574
|
function trackDismissableElement(node, options) {
|
|
571
575
|
if (!node)
|
|
572
576
|
return;
|
|
573
|
-
const { onDismiss, pointerBlocking, exclude: excludeContainers } = options;
|
|
577
|
+
const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
|
|
574
578
|
const layer = { dismiss: onDismiss, node, pointerBlocking };
|
|
575
579
|
layerStack.add(layer);
|
|
576
580
|
assignPointerEventToLayers();
|
|
@@ -583,6 +587,9 @@ function trackDismissableElement(node, options) {
|
|
|
583
587
|
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
584
588
|
if (event.defaultPrevented)
|
|
585
589
|
return;
|
|
590
|
+
if (debug) {
|
|
591
|
+
console.log("onPointerDownOutside:", event.detail.originalEvent);
|
|
592
|
+
}
|
|
586
593
|
onDismiss == null ? void 0 : onDismiss();
|
|
587
594
|
}
|
|
588
595
|
function onFocusOutside(event) {
|
|
@@ -594,6 +601,9 @@ function trackDismissableElement(node, options) {
|
|
|
594
601
|
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
595
602
|
if (event.defaultPrevented)
|
|
596
603
|
return;
|
|
604
|
+
if (debug) {
|
|
605
|
+
console.log("onFocusOutside:", event.detail.originalEvent);
|
|
606
|
+
}
|
|
597
607
|
onDismiss == null ? void 0 : onDismiss();
|
|
598
608
|
}
|
|
599
609
|
function onEscapeKeyDown(event) {
|
|
@@ -607,9 +617,11 @@ function trackDismissableElement(node, options) {
|
|
|
607
617
|
}
|
|
608
618
|
}
|
|
609
619
|
function exclude(target) {
|
|
620
|
+
if (!node)
|
|
621
|
+
return false;
|
|
610
622
|
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
611
|
-
const
|
|
612
|
-
return
|
|
623
|
+
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
624
|
+
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
|
|
613
625
|
}
|
|
614
626
|
const cleanups = [
|
|
615
627
|
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
|
|
@@ -644,7 +656,7 @@ function machine(ctx = {}) {
|
|
|
644
656
|
}, ctx.positioning),
|
|
645
657
|
currentPlacement: void 0
|
|
646
658
|
}, ctx), {
|
|
647
|
-
|
|
659
|
+
focusTriggerOnClose: true,
|
|
648
660
|
renderedElements: {
|
|
649
661
|
title: true,
|
|
650
662
|
description: true,
|
|
@@ -734,7 +746,7 @@ function machine(ctx = {}) {
|
|
|
734
746
|
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
735
747
|
if (ctx2.closeOnEsc)
|
|
736
748
|
return;
|
|
737
|
-
ctx2.
|
|
749
|
+
ctx2.focusTriggerOnClose = true;
|
|
738
750
|
event.preventDefault();
|
|
739
751
|
},
|
|
740
752
|
onInteractOutside(event) {
|
|
@@ -742,7 +754,7 @@ function machine(ctx = {}) {
|
|
|
742
754
|
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
743
755
|
if (event.defaultPrevented)
|
|
744
756
|
return;
|
|
745
|
-
ctx2.
|
|
757
|
+
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
746
758
|
if (!ctx2.closeOnInteractOutside) {
|
|
747
759
|
event.preventDefault();
|
|
748
760
|
}
|
|
@@ -850,15 +862,11 @@ function machine(ctx = {}) {
|
|
|
850
862
|
});
|
|
851
863
|
},
|
|
852
864
|
focusTriggerIfNeeded(ctx2) {
|
|
853
|
-
|
|
865
|
+
if (!ctx2.focusTriggerOnClose)
|
|
866
|
+
return;
|
|
867
|
+
raf(() => {
|
|
854
868
|
var _a;
|
|
855
869
|
return (_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
856
|
-
};
|
|
857
|
-
raf(() => {
|
|
858
|
-
if (!ctx2.preventReturnFocus) {
|
|
859
|
-
focus();
|
|
860
|
-
ctx2.preventReturnFocus = false;
|
|
861
|
-
}
|
|
862
870
|
});
|
|
863
871
|
},
|
|
864
872
|
focusFirstTabbableElement(ctx2, evt) {
|
package/dist/popover.types.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ declare type PrivateContext = Context<{
|
|
|
90
90
|
/**
|
|
91
91
|
* Whether to prevent returning focus to the trigger
|
|
92
92
|
*/
|
|
93
|
-
|
|
93
|
+
focusTriggerOnClose?: boolean;
|
|
94
94
|
}>;
|
|
95
95
|
export declare type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
96
96
|
export declare type MachineState = {
|
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-20220707125149",
|
|
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-
|
|
34
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
35
|
-
"@zag-js/popper": "0.0.0-dev-
|
|
36
|
-
"@zag-js/remove-scroll": "0.
|
|
37
|
-
"@zag-js/types": "0.0.0-dev-
|
|
33
|
+
"@zag-js/core": "0.0.0-dev-20220707125149",
|
|
34
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220707125149",
|
|
35
|
+
"@zag-js/popper": "0.0.0-dev-20220707125149",
|
|
36
|
+
"@zag-js/remove-scroll": "0.0.0-dev-20220707125149",
|
|
37
|
+
"@zag-js/types": "0.0.0-dev-20220707125149",
|
|
38
38
|
"@zag-js/utils": "0.1.2",
|
|
39
39
|
"focus-trap": "6.9.4"
|
|
40
40
|
},
|