@zag-js/popover 0.2.11 → 0.2.13
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/chunk-4IGGT6KB.mjs +39 -0
- package/dist/{chunk-JNFEFPEH.mjs → chunk-GKHXQZZB.mjs} +14 -6
- package/dist/{chunk-NMCDKPIS.mjs → chunk-JT2RXXW4.mjs} +5 -72
- package/dist/index.js +42 -204
- package/dist/index.mjs +3 -3
- package/dist/popover.connect.d.ts +12 -0
- package/dist/popover.connect.js +40 -136
- package/dist/popover.connect.mjs +2 -2
- package/dist/popover.dom.d.ts +4 -1
- package/dist/popover.dom.js +10 -114
- package/dist/popover.dom.mjs +1 -1
- package/dist/popover.machine.js +27 -199
- package/dist/popover.machine.mjs +2 -2
- package/package.json +11 -9
- package/dist/chunk-2EVL5G6H.mjs +0 -148
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/popover.dom.ts
|
|
2
|
+
import { createScope } from "@zag-js/dom-query";
|
|
3
|
+
import { getFirstTabbable, getFocusables, getLastTabbable, getTabbables } from "@zag-js/tabbable";
|
|
4
|
+
import { runIfFn } from "@zag-js/utils";
|
|
5
|
+
var dom = createScope({
|
|
6
|
+
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
7
|
+
getAnchorId: (ctx) => ctx.ids?.anchor ?? `popover:${ctx.id}:anchor`,
|
|
8
|
+
getTriggerId: (ctx) => ctx.ids?.trigger ?? `popover:${ctx.id}:trigger`,
|
|
9
|
+
getContentId: (ctx) => ctx.ids?.content ?? `popover:${ctx.id}:content`,
|
|
10
|
+
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
11
|
+
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
12
|
+
getTitleId: (ctx) => ctx.ids?.title ?? `popover:${ctx.id}:title`,
|
|
13
|
+
getDescriptionId: (ctx) => ctx.ids?.description ?? `popover:${ctx.id}:desc`,
|
|
14
|
+
getCloseTriggerId: (ctx) => ctx.ids?.closeTrigger ?? `popover:${ctx.id}:close`,
|
|
15
|
+
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
16
|
+
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
17
|
+
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
18
|
+
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
19
|
+
getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
|
|
20
|
+
getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
|
|
21
|
+
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
22
|
+
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
23
|
+
getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
|
|
24
|
+
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
25
|
+
getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
26
|
+
getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
27
|
+
getInitialFocusEl: (ctx) => {
|
|
28
|
+
let el = runIfFn(ctx.initialFocusEl);
|
|
29
|
+
if (!el && ctx.autoFocus)
|
|
30
|
+
el = dom.getFirstFocusableEl(ctx);
|
|
31
|
+
if (!el)
|
|
32
|
+
el = dom.getContentEl(ctx);
|
|
33
|
+
return el;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
dom
|
|
39
|
+
};
|
|
@@ -3,14 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-KTOPDXGV.mjs";
|
|
4
4
|
import {
|
|
5
5
|
dom
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
|
|
8
|
-
// ../../utilities/dom/src/attrs.ts
|
|
9
|
-
var dataAttr = (guard) => {
|
|
10
|
-
return guard ? "" : void 0;
|
|
11
|
-
};
|
|
6
|
+
} from "./chunk-4IGGT6KB.mjs";
|
|
12
7
|
|
|
13
8
|
// src/popover.connect.ts
|
|
9
|
+
import { dataAttr } from "@zag-js/dom-query";
|
|
14
10
|
import { getPlacementStyles } from "@zag-js/popper";
|
|
15
11
|
function connect(state, send, normalize) {
|
|
16
12
|
const isOpen = state.matches("open");
|
|
@@ -22,11 +18,23 @@ function connect(state, send, normalize) {
|
|
|
22
18
|
placement: currentPlacement
|
|
23
19
|
});
|
|
24
20
|
return {
|
|
21
|
+
/**
|
|
22
|
+
* Whether the popover is portalled
|
|
23
|
+
*/
|
|
25
24
|
portalled,
|
|
25
|
+
/**
|
|
26
|
+
* Whether the popover is open
|
|
27
|
+
*/
|
|
26
28
|
isOpen,
|
|
29
|
+
/**
|
|
30
|
+
* Function to open the popover
|
|
31
|
+
*/
|
|
27
32
|
open() {
|
|
28
33
|
send("OPEN");
|
|
29
34
|
},
|
|
35
|
+
/**
|
|
36
|
+
* Function to close the popover
|
|
37
|
+
*/
|
|
30
38
|
close() {
|
|
31
39
|
send("CLOSE");
|
|
32
40
|
},
|
|
@@ -1,83 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
runIfFn
|
|
5
|
-
} from "./chunk-2EVL5G6H.mjs";
|
|
2
|
+
dom
|
|
3
|
+
} from "./chunk-4IGGT6KB.mjs";
|
|
6
4
|
|
|
7
5
|
// src/popover.machine.ts
|
|
8
6
|
import { ariaHidden } from "@zag-js/aria-hidden";
|
|
9
7
|
import { createMachine, guards } from "@zag-js/core";
|
|
10
8
|
import { trackDismissableElement } from "@zag-js/dismissable";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function nextIndex(v, idx, opts = {}) {
|
|
14
|
-
const { step = 1, loop = true } = opts;
|
|
15
|
-
const next2 = idx + step;
|
|
16
|
-
const len = v.length;
|
|
17
|
-
const last = len - 1;
|
|
18
|
-
if (idx === -1)
|
|
19
|
-
return step > 0 ? 0 : last;
|
|
20
|
-
if (next2 < 0)
|
|
21
|
-
return loop ? last : 0;
|
|
22
|
-
if (next2 >= len)
|
|
23
|
-
return loop ? 0 : idx > len ? len : idx;
|
|
24
|
-
return next2;
|
|
25
|
-
}
|
|
26
|
-
function next(v, idx, opts = {}) {
|
|
27
|
-
return v[nextIndex(v, idx, opts)];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// ../../utilities/core/src/guard.ts
|
|
31
|
-
var isArray = (v) => Array.isArray(v);
|
|
32
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
33
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
34
|
-
|
|
35
|
-
// ../../utilities/core/src/object.ts
|
|
36
|
-
function compact(obj) {
|
|
37
|
-
if (obj === void 0)
|
|
38
|
-
return obj;
|
|
39
|
-
return Object.fromEntries(
|
|
40
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ../../utilities/dom/src/event.ts
|
|
45
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
46
|
-
|
|
47
|
-
// ../../utilities/dom/src/listener.ts
|
|
48
|
-
var isRef = (v) => hasProp(v, "current");
|
|
49
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
50
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
51
|
-
node?.addEventListener(eventName, handler, options);
|
|
52
|
-
return () => {
|
|
53
|
-
node?.removeEventListener(eventName, handler, options);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
58
|
-
function nextTick(fn) {
|
|
59
|
-
const set = /* @__PURE__ */ new Set();
|
|
60
|
-
function raf2(fn2) {
|
|
61
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
62
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
63
|
-
}
|
|
64
|
-
raf2(() => raf2(fn));
|
|
65
|
-
return function cleanup() {
|
|
66
|
-
set.forEach(function(fn2) {
|
|
67
|
-
fn2();
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function raf(fn) {
|
|
72
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
73
|
-
return function cleanup() {
|
|
74
|
-
globalThis.cancelAnimationFrame(id);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// src/popover.machine.ts
|
|
9
|
+
import { contains, nextTick, raf } from "@zag-js/dom-query";
|
|
10
|
+
import { addDomEvent, isModifiedEvent } from "@zag-js/dom-event";
|
|
79
11
|
import { getPlacement } from "@zag-js/popper";
|
|
80
12
|
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
13
|
+
import { compact, next, runIfFn } from "@zag-js/utils";
|
|
81
14
|
import { createFocusTrap } from "focus-trap";
|
|
82
15
|
var { and, or, not } = guards;
|
|
83
16
|
function machine(userContext) {
|
package/dist/index.js
CHANGED
|
@@ -41,192 +41,15 @@ var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
|
|
|
41
41
|
);
|
|
42
42
|
var parts = anatomy.build();
|
|
43
43
|
|
|
44
|
-
// ../../utilities/dom/src/attrs.ts
|
|
45
|
-
var dataAttr = (guard) => {
|
|
46
|
-
return guard ? "" : void 0;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// ../../utilities/core/src/array.ts
|
|
50
|
-
function nextIndex(v, idx, opts = {}) {
|
|
51
|
-
const { step = 1, loop = true } = opts;
|
|
52
|
-
const next2 = idx + step;
|
|
53
|
-
const len = v.length;
|
|
54
|
-
const last = len - 1;
|
|
55
|
-
if (idx === -1)
|
|
56
|
-
return step > 0 ? 0 : last;
|
|
57
|
-
if (next2 < 0)
|
|
58
|
-
return loop ? last : 0;
|
|
59
|
-
if (next2 >= len)
|
|
60
|
-
return loop ? 0 : idx > len ? len : idx;
|
|
61
|
-
return next2;
|
|
62
|
-
}
|
|
63
|
-
function next(v, idx, opts = {}) {
|
|
64
|
-
return v[nextIndex(v, idx, opts)];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ../../utilities/core/src/functions.ts
|
|
68
|
-
var runIfFn = (v, ...a) => {
|
|
69
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
70
|
-
return res ?? void 0;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// ../../utilities/core/src/guard.ts
|
|
74
|
-
var isArray = (v) => Array.isArray(v);
|
|
75
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
76
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
77
|
-
|
|
78
|
-
// ../../utilities/core/src/object.ts
|
|
79
|
-
function compact(obj) {
|
|
80
|
-
if (obj === void 0)
|
|
81
|
-
return obj;
|
|
82
|
-
return Object.fromEntries(
|
|
83
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ../../utilities/dom/src/query.ts
|
|
88
|
-
function isDocument(el) {
|
|
89
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
90
|
-
}
|
|
91
|
-
function isWindow(value) {
|
|
92
|
-
return value?.toString() === "[object Window]";
|
|
93
|
-
}
|
|
94
|
-
function isFrame(element) {
|
|
95
|
-
return element.localName === "iframe";
|
|
96
|
-
}
|
|
97
|
-
function getDocument(el) {
|
|
98
|
-
if (isWindow(el))
|
|
99
|
-
return el.document;
|
|
100
|
-
if (isDocument(el))
|
|
101
|
-
return el;
|
|
102
|
-
return el?.ownerDocument ?? document;
|
|
103
|
-
}
|
|
104
|
-
function defineDomHelpers(helpers) {
|
|
105
|
-
const dom2 = {
|
|
106
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
107
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
108
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
109
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
110
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
111
|
-
};
|
|
112
|
-
return {
|
|
113
|
-
...dom2,
|
|
114
|
-
...helpers
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function contains(parent, child) {
|
|
118
|
-
if (!parent)
|
|
119
|
-
return false;
|
|
120
|
-
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
|
|
121
|
-
}
|
|
122
|
-
function isHTMLElement(v) {
|
|
123
|
-
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
124
|
-
}
|
|
125
|
-
function isVisible(el) {
|
|
126
|
-
if (!isHTMLElement(el))
|
|
127
|
-
return false;
|
|
128
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ../../utilities/dom/src/event.ts
|
|
132
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
133
|
-
|
|
134
|
-
// ../../utilities/dom/src/focusable.ts
|
|
135
|
-
function hasNegativeTabIndex(element) {
|
|
136
|
-
const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
|
|
137
|
-
return tabIndex < 0;
|
|
138
|
-
}
|
|
139
|
-
var focusableSelector = "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";
|
|
140
|
-
var getFocusables = (container, includeContainer = false) => {
|
|
141
|
-
if (!container)
|
|
142
|
-
return [];
|
|
143
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
144
|
-
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
145
|
-
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
146
|
-
elements.unshift(container);
|
|
147
|
-
}
|
|
148
|
-
const focusableElements = elements.filter(isFocusable);
|
|
149
|
-
focusableElements.forEach((element, i) => {
|
|
150
|
-
if (isFrame(element) && element.contentDocument) {
|
|
151
|
-
const frameBody = element.contentDocument.body;
|
|
152
|
-
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return focusableElements;
|
|
156
|
-
};
|
|
157
|
-
function isFocusable(element) {
|
|
158
|
-
if (!element)
|
|
159
|
-
return false;
|
|
160
|
-
return element.matches(focusableSelector) && isVisible(element);
|
|
161
|
-
}
|
|
162
|
-
function getTabbables(container, includeContainer) {
|
|
163
|
-
if (!container)
|
|
164
|
-
return [];
|
|
165
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
166
|
-
const tabbableElements = elements.filter(isTabbable);
|
|
167
|
-
if (includeContainer && isTabbable(container)) {
|
|
168
|
-
tabbableElements.unshift(container);
|
|
169
|
-
}
|
|
170
|
-
tabbableElements.forEach((element, i) => {
|
|
171
|
-
if (isFrame(element) && element.contentDocument) {
|
|
172
|
-
const frameBody = element.contentDocument.body;
|
|
173
|
-
const allFrameTabbable = getTabbables(frameBody);
|
|
174
|
-
tabbableElements.splice(i, 1, ...allFrameTabbable);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
if (!tabbableElements.length && includeContainer) {
|
|
178
|
-
return elements;
|
|
179
|
-
}
|
|
180
|
-
return tabbableElements;
|
|
181
|
-
}
|
|
182
|
-
function isTabbable(el) {
|
|
183
|
-
return isFocusable(el) && !hasNegativeTabIndex(el);
|
|
184
|
-
}
|
|
185
|
-
function getFirstTabbable(container, includeContainer) {
|
|
186
|
-
const [first] = getTabbables(container, includeContainer);
|
|
187
|
-
return first || null;
|
|
188
|
-
}
|
|
189
|
-
function getLastTabbable(container, includeContainer) {
|
|
190
|
-
const elements = getTabbables(container, includeContainer);
|
|
191
|
-
return elements[elements.length - 1] || null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// ../../utilities/dom/src/listener.ts
|
|
195
|
-
var isRef = (v) => hasProp(v, "current");
|
|
196
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
197
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
198
|
-
node?.addEventListener(eventName, handler, options);
|
|
199
|
-
return () => {
|
|
200
|
-
node?.removeEventListener(eventName, handler, options);
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
205
|
-
function nextTick(fn) {
|
|
206
|
-
const set = /* @__PURE__ */ new Set();
|
|
207
|
-
function raf2(fn2) {
|
|
208
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
209
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
210
|
-
}
|
|
211
|
-
raf2(() => raf2(fn));
|
|
212
|
-
return function cleanup() {
|
|
213
|
-
set.forEach(function(fn2) {
|
|
214
|
-
fn2();
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
function raf(fn) {
|
|
219
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
220
|
-
return function cleanup() {
|
|
221
|
-
globalThis.cancelAnimationFrame(id);
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
44
|
// src/popover.connect.ts
|
|
45
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
226
46
|
var import_popper = require("@zag-js/popper");
|
|
227
47
|
|
|
228
48
|
// src/popover.dom.ts
|
|
229
|
-
var
|
|
49
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
50
|
+
var import_tabbable = require("@zag-js/tabbable");
|
|
51
|
+
var import_utils = require("@zag-js/utils");
|
|
52
|
+
var dom = (0, import_dom_query.createScope)({
|
|
230
53
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
231
54
|
getAnchorId: (ctx) => ctx.ids?.anchor ?? `popover:${ctx.id}:anchor`,
|
|
232
55
|
getTriggerId: (ctx) => ctx.ids?.trigger ?? `popover:${ctx.id}:trigger`,
|
|
@@ -242,14 +65,14 @@ var dom = defineDomHelpers({
|
|
|
242
65
|
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
243
66
|
getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
|
|
244
67
|
getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
|
|
245
|
-
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
68
|
+
getFocusableEls: (ctx) => (0, import_tabbable.getFocusables)(dom.getContentEl(ctx)),
|
|
246
69
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
247
|
-
getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
|
|
248
|
-
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
249
|
-
getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
250
|
-
getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
70
|
+
getDocTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getDoc(ctx).body),
|
|
71
|
+
getTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getContentEl(ctx), "if-empty"),
|
|
72
|
+
getFirstTabbableEl: (ctx) => (0, import_tabbable.getFirstTabbable)(dom.getContentEl(ctx), "if-empty"),
|
|
73
|
+
getLastTabbableEl: (ctx) => (0, import_tabbable.getLastTabbable)(dom.getContentEl(ctx), "if-empty"),
|
|
251
74
|
getInitialFocusEl: (ctx) => {
|
|
252
|
-
let el = runIfFn(ctx.initialFocusEl);
|
|
75
|
+
let el = (0, import_utils.runIfFn)(ctx.initialFocusEl);
|
|
253
76
|
if (!el && ctx.autoFocus)
|
|
254
77
|
el = dom.getFirstFocusableEl(ctx);
|
|
255
78
|
if (!el)
|
|
@@ -269,11 +92,23 @@ function connect(state, send, normalize) {
|
|
|
269
92
|
placement: currentPlacement
|
|
270
93
|
});
|
|
271
94
|
return {
|
|
95
|
+
/**
|
|
96
|
+
* Whether the popover is portalled
|
|
97
|
+
*/
|
|
272
98
|
portalled,
|
|
99
|
+
/**
|
|
100
|
+
* Whether the popover is open
|
|
101
|
+
*/
|
|
273
102
|
isOpen,
|
|
103
|
+
/**
|
|
104
|
+
* Function to open the popover
|
|
105
|
+
*/
|
|
274
106
|
open() {
|
|
275
107
|
send("OPEN");
|
|
276
108
|
},
|
|
109
|
+
/**
|
|
110
|
+
* Function to close the popover
|
|
111
|
+
*/
|
|
277
112
|
close() {
|
|
278
113
|
send("CLOSE");
|
|
279
114
|
},
|
|
@@ -297,7 +132,7 @@ function connect(state, send, normalize) {
|
|
|
297
132
|
id: dom.getTriggerId(state.context),
|
|
298
133
|
"aria-haspopup": "dialog",
|
|
299
134
|
"aria-expanded": isOpen,
|
|
300
|
-
"data-expanded": dataAttr(isOpen),
|
|
135
|
+
"data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
|
|
301
136
|
"aria-controls": dom.getContentId(state.context),
|
|
302
137
|
onClick() {
|
|
303
138
|
send("TOGGLE");
|
|
@@ -317,7 +152,7 @@ function connect(state, send, normalize) {
|
|
|
317
152
|
tabIndex: -1,
|
|
318
153
|
role: "dialog",
|
|
319
154
|
hidden: !isOpen,
|
|
320
|
-
"data-expanded": dataAttr(isOpen),
|
|
155
|
+
"data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
|
|
321
156
|
"aria-labelledby": rendered.title ? dom.getTitleId(state.context) : void 0,
|
|
322
157
|
"aria-describedby": rendered.description ? dom.getDescriptionId(state.context) : void 0,
|
|
323
158
|
"data-placement": currentPlacement
|
|
@@ -346,12 +181,15 @@ function connect(state, send, normalize) {
|
|
|
346
181
|
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
347
182
|
var import_core = require("@zag-js/core");
|
|
348
183
|
var import_dismissable = require("@zag-js/dismissable");
|
|
184
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
185
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
349
186
|
var import_popper2 = require("@zag-js/popper");
|
|
350
187
|
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
188
|
+
var import_utils2 = require("@zag-js/utils");
|
|
351
189
|
var import_focus_trap = require("focus-trap");
|
|
352
190
|
var { and, or, not } = import_core.guards;
|
|
353
191
|
function machine(userContext) {
|
|
354
|
-
const ctx = compact(userContext);
|
|
192
|
+
const ctx = (0, import_utils2.compact)(userContext);
|
|
355
193
|
return (0, import_core.createMachine)(
|
|
356
194
|
{
|
|
357
195
|
id: "popover",
|
|
@@ -480,11 +318,11 @@ function machine(userContext) {
|
|
|
480
318
|
trackTabKeyDown(ctx2, _evt, { send }) {
|
|
481
319
|
if (ctx2.modal)
|
|
482
320
|
return;
|
|
483
|
-
return addDomEvent(
|
|
321
|
+
return (0, import_dom_event.addDomEvent)(
|
|
484
322
|
dom.getWin(ctx2),
|
|
485
323
|
"keydown",
|
|
486
324
|
(event) => {
|
|
487
|
-
const isTabKey = event.key === "Tab" && !isModifiedEvent(event);
|
|
325
|
+
const isTabKey = event.key === "Tab" && !(0, import_dom_event.isModifiedEvent)(event);
|
|
488
326
|
if (!isTabKey)
|
|
489
327
|
return;
|
|
490
328
|
send({
|
|
@@ -499,7 +337,7 @@ function machine(userContext) {
|
|
|
499
337
|
if (!ctx2.modal)
|
|
500
338
|
return;
|
|
501
339
|
let cleanup;
|
|
502
|
-
nextTick(() => {
|
|
340
|
+
(0, import_dom_query3.nextTick)(() => {
|
|
503
341
|
cleanup = (0, import_aria_hidden.ariaHidden)([dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]);
|
|
504
342
|
});
|
|
505
343
|
return () => cleanup?.();
|
|
@@ -513,7 +351,7 @@ function machine(userContext) {
|
|
|
513
351
|
if (!ctx2.modal)
|
|
514
352
|
return;
|
|
515
353
|
let trap;
|
|
516
|
-
nextTick(() => {
|
|
354
|
+
(0, import_dom_query3.nextTick)(() => {
|
|
517
355
|
const el = dom.getContentEl(ctx2);
|
|
518
356
|
if (!el)
|
|
519
357
|
return;
|
|
@@ -523,7 +361,7 @@ function machine(userContext) {
|
|
|
523
361
|
returnFocusOnDeactivate: true,
|
|
524
362
|
document: dom.getDoc(ctx2),
|
|
525
363
|
fallbackFocus: el,
|
|
526
|
-
initialFocus: runIfFn(ctx2.initialFocusEl)
|
|
364
|
+
initialFocus: (0, import_utils2.runIfFn)(ctx2.initialFocusEl)
|
|
527
365
|
});
|
|
528
366
|
try {
|
|
529
367
|
trap.activate();
|
|
@@ -535,7 +373,7 @@ function machine(userContext) {
|
|
|
535
373
|
},
|
|
536
374
|
guards: {
|
|
537
375
|
portalled: (ctx2) => ctx2.currentPortalled,
|
|
538
|
-
isRelatedTargetWithinContent: (ctx2, evt) => contains(dom.getContentEl(ctx2), evt.target),
|
|
376
|
+
isRelatedTargetWithinContent: (ctx2, evt) => (0, import_dom_query3.contains)(dom.getContentEl(ctx2), evt.target),
|
|
539
377
|
closeOnInteractOutside: (ctx2) => !!ctx2.closeOnInteractOutside,
|
|
540
378
|
isContentFocused: (ctx2) => dom.getContentEl(ctx2) === dom.getActiveEl(ctx2),
|
|
541
379
|
isTriggerFocused: (ctx2) => dom.getTriggerEl(ctx2) === dom.getActiveEl(ctx2),
|
|
@@ -544,7 +382,7 @@ function machine(userContext) {
|
|
|
544
382
|
},
|
|
545
383
|
actions: {
|
|
546
384
|
checkRenderedElements(ctx2) {
|
|
547
|
-
raf(() => {
|
|
385
|
+
(0, import_dom_query3.raf)(() => {
|
|
548
386
|
Object.assign(ctx2.renderedElements, {
|
|
549
387
|
title: !!dom.getTitleEl(ctx2),
|
|
550
388
|
description: !!dom.getDescriptionEl(ctx2),
|
|
@@ -553,14 +391,14 @@ function machine(userContext) {
|
|
|
553
391
|
});
|
|
554
392
|
},
|
|
555
393
|
setInitialFocus(ctx2) {
|
|
556
|
-
raf(() => {
|
|
394
|
+
(0, import_dom_query3.raf)(() => {
|
|
557
395
|
dom.getInitialFocusEl(ctx2)?.focus();
|
|
558
396
|
});
|
|
559
397
|
},
|
|
560
398
|
focusTriggerIfNeeded(ctx2) {
|
|
561
399
|
if (!ctx2.focusTriggerOnClose)
|
|
562
400
|
return;
|
|
563
|
-
raf(() => dom.getTriggerEl(ctx2)?.focus());
|
|
401
|
+
(0, import_dom_query3.raf)(() => dom.getTriggerEl(ctx2)?.focus());
|
|
564
402
|
},
|
|
565
403
|
focusFirstTabbableElement(ctx2, evt) {
|
|
566
404
|
evt.preventDefault();
|
|
@@ -585,15 +423,15 @@ function machine(userContext) {
|
|
|
585
423
|
if (lastTabbable !== dom.getActiveEl(ctx2))
|
|
586
424
|
return;
|
|
587
425
|
let tabbables = dom.getDocTabbableEls(ctx2);
|
|
588
|
-
let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
426
|
+
let elementAfterTrigger = (0, import_utils2.next)(tabbables, tabbables.indexOf(button), { loop: false });
|
|
589
427
|
if (elementAfterTrigger === content) {
|
|
590
|
-
tabbables = tabbables.filter((el) => !contains(content, el));
|
|
591
|
-
elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
428
|
+
tabbables = tabbables.filter((el) => !(0, import_dom_query3.contains)(content, el));
|
|
429
|
+
elementAfterTrigger = (0, import_utils2.next)(tabbables, tabbables.indexOf(button), { loop: false });
|
|
592
430
|
}
|
|
593
431
|
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
594
432
|
return;
|
|
595
433
|
evt.preventDefault();
|
|
596
|
-
raf(() => elementAfterTrigger?.focus());
|
|
434
|
+
(0, import_dom_query3.raf)(() => elementAfterTrigger?.focus());
|
|
597
435
|
}
|
|
598
436
|
}
|
|
599
437
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GKHXQZZB.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-KTOPDXGV.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-JT2RXXW4.mjs";
|
|
10
|
+
import "./chunk-4IGGT6KB.mjs";
|
|
11
11
|
export {
|
|
12
12
|
anatomy,
|
|
13
13
|
connect,
|
|
@@ -5,9 +5,21 @@ import '@zag-js/dismissable';
|
|
|
5
5
|
import '@zag-js/popper';
|
|
6
6
|
|
|
7
7
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the popover is portalled
|
|
10
|
+
*/
|
|
8
11
|
portalled: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the popover is open
|
|
14
|
+
*/
|
|
9
15
|
isOpen: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Function to open the popover
|
|
18
|
+
*/
|
|
10
19
|
open(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Function to close the popover
|
|
22
|
+
*/
|
|
11
23
|
close(): void;
|
|
12
24
|
arrowProps: T["element"];
|
|
13
25
|
arrowTipProps: T["element"];
|