@zag-js/popover 0.2.5 → 0.2.7
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-AVX6BWXB.mjs +353 -0
- package/dist/chunk-KTOPDXGV.mjs +19 -0
- package/dist/chunk-NDF4K3W7.mjs +100 -0
- package/dist/chunk-VCEKTSBU.mjs +173 -0
- package/dist/index.d.ts +9 -952
- package/dist/index.js +47 -53
- package/dist/index.mjs +10 -622
- package/dist/popover.anatomy.d.ts +6 -0
- package/dist/popover.anatomy.js +44 -0
- package/dist/popover.anatomy.mjs +8 -0
- package/dist/popover.connect.d.ts +23 -0
- package/dist/popover.connect.js +299 -0
- package/dist/popover.connect.mjs +8 -0
- package/dist/popover.dom.d.ts +48 -0
- package/dist/popover.dom.js +192 -0
- package/dist/popover.dom.mjs +6 -0
- package/dist/popover.machine.d.ts +9 -0
- package/dist/popover.machine.js +541 -0
- package/dist/popover.machine.mjs +7 -0
- package/dist/popover.types.d.ts +84 -0
- package/dist/popover.types.js +18 -0
- package/dist/popover.types.mjs +0 -0
- package/package.json +25 -15
package/dist/index.js
CHANGED
|
@@ -41,15 +41,50 @@ var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
|
|
|
41
41
|
);
|
|
42
42
|
var parts = anatomy.build();
|
|
43
43
|
|
|
44
|
-
// ../../utilities/dom/
|
|
44
|
+
// ../../utilities/dom/src/attrs.ts
|
|
45
45
|
var dataAttr = (guard) => {
|
|
46
46
|
return guard ? "" : void 0;
|
|
47
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
|
|
48
68
|
var runIfFn = (v, ...a) => {
|
|
49
69
|
const res = typeof v === "function" ? v(...a) : v;
|
|
50
70
|
return res != null ? res : void 0;
|
|
51
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));
|
|
52
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
|
|
53
88
|
function isDocument(el) {
|
|
54
89
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
55
90
|
}
|
|
@@ -79,25 +114,7 @@ function defineDomHelpers(helpers) {
|
|
|
79
114
|
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
80
115
|
},
|
|
81
116
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
82
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
83
|
-
createEmitter: (ctx, target) => {
|
|
84
|
-
const win = dom2.getWin(ctx);
|
|
85
|
-
return function emit(evt, detail, options) {
|
|
86
|
-
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
87
|
-
const eventName = `zag:${evt}`;
|
|
88
|
-
const init = { bubbles, cancelable, composed, detail };
|
|
89
|
-
const event = new win.CustomEvent(eventName, init);
|
|
90
|
-
target.dispatchEvent(event);
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
createListener: (target) => {
|
|
94
|
-
return function listen(evt, handler) {
|
|
95
|
-
const eventName = `zag:${evt}`;
|
|
96
|
-
const listener = (e) => handler(e);
|
|
97
|
-
target.addEventListener(eventName, listener);
|
|
98
|
-
return () => target.removeEventListener(eventName, listener);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
117
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
101
118
|
};
|
|
102
119
|
return {
|
|
103
120
|
...dom2,
|
|
@@ -117,7 +134,11 @@ function isVisible(el) {
|
|
|
117
134
|
return false;
|
|
118
135
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
119
136
|
}
|
|
137
|
+
|
|
138
|
+
// ../../utilities/dom/src/event.ts
|
|
120
139
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
140
|
+
|
|
141
|
+
// ../../utilities/dom/src/focusable.ts
|
|
121
142
|
function hasNegativeTabIndex(element) {
|
|
122
143
|
const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
|
|
123
144
|
return tabIndex < 0;
|
|
@@ -176,6 +197,8 @@ function getLastTabbable(container, includeContainer) {
|
|
|
176
197
|
const elements = getTabbables(container, includeContainer);
|
|
177
198
|
return elements[elements.length - 1] || null;
|
|
178
199
|
}
|
|
200
|
+
|
|
201
|
+
// ../../utilities/dom/src/listener.ts
|
|
179
202
|
var isRef = (v) => hasProp(v, "current");
|
|
180
203
|
function addDomEvent(target, eventName, handler, options) {
|
|
181
204
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -184,6 +207,8 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
184
207
|
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
185
208
|
};
|
|
186
209
|
}
|
|
210
|
+
|
|
211
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
187
212
|
function nextTick(fn) {
|
|
188
213
|
const set = /* @__PURE__ */ new Set();
|
|
189
214
|
function raf2(fn2) {
|
|
@@ -207,37 +232,6 @@ function raf(fn) {
|
|
|
207
232
|
// src/popover.connect.ts
|
|
208
233
|
var import_popper = require("@zag-js/popper");
|
|
209
234
|
|
|
210
|
-
// ../../utilities/core/dist/index.mjs
|
|
211
|
-
function nextIndex(v, idx, opts = {}) {
|
|
212
|
-
const { step = 1, loop = true } = opts;
|
|
213
|
-
const next2 = idx + step;
|
|
214
|
-
const len = v.length;
|
|
215
|
-
const last2 = len - 1;
|
|
216
|
-
if (idx === -1)
|
|
217
|
-
return step > 0 ? 0 : last2;
|
|
218
|
-
if (next2 < 0)
|
|
219
|
-
return loop ? last2 : 0;
|
|
220
|
-
if (next2 >= len)
|
|
221
|
-
return loop ? 0 : idx > len ? len : idx;
|
|
222
|
-
return next2;
|
|
223
|
-
}
|
|
224
|
-
function next(v, idx, opts = {}) {
|
|
225
|
-
return v[nextIndex(v, idx, opts)];
|
|
226
|
-
}
|
|
227
|
-
var runIfFn2 = (v, ...a) => {
|
|
228
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
229
|
-
return res != null ? res : void 0;
|
|
230
|
-
};
|
|
231
|
-
var isArray = (v) => Array.isArray(v);
|
|
232
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
233
|
-
function compact(obj) {
|
|
234
|
-
if (obj === void 0)
|
|
235
|
-
return obj;
|
|
236
|
-
return Object.fromEntries(
|
|
237
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
235
|
// src/popover.dom.ts
|
|
242
236
|
var dom = defineDomHelpers({
|
|
243
237
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
@@ -280,7 +274,7 @@ var dom = defineDomHelpers({
|
|
|
280
274
|
getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
281
275
|
getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
282
276
|
getInitialFocusEl: (ctx) => {
|
|
283
|
-
let el =
|
|
277
|
+
let el = runIfFn(ctx.initialFocusEl);
|
|
284
278
|
if (!el && ctx.autoFocus)
|
|
285
279
|
el = dom.getFirstFocusableEl(ctx);
|
|
286
280
|
if (!el)
|
|
@@ -565,7 +559,7 @@ function machine(userContext) {
|
|
|
565
559
|
returnFocusOnDeactivate: true,
|
|
566
560
|
document: dom.getDoc(ctx2),
|
|
567
561
|
fallbackFocus: el,
|
|
568
|
-
initialFocus:
|
|
562
|
+
initialFocus: runIfFn(ctx2.initialFocusEl)
|
|
569
563
|
});
|
|
570
564
|
try {
|
|
571
565
|
trap.activate();
|