@zag-js/popover 0.1.16 → 0.2.0
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 +41 -19
- package/dist/index.mjs +41 -19
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var dataAttr = (guard) => {
|
|
|
31
31
|
};
|
|
32
32
|
var runIfFn = (v, ...a) => {
|
|
33
33
|
const res = typeof v === "function" ? v(...a) : v;
|
|
34
|
-
return res
|
|
34
|
+
return res != null ? res : void 0;
|
|
35
35
|
};
|
|
36
36
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
37
37
|
function isDocument(el) {
|
|
@@ -44,22 +44,44 @@ function isFrame(element) {
|
|
|
44
44
|
return element.localName === "iframe";
|
|
45
45
|
}
|
|
46
46
|
function getDocument(el) {
|
|
47
|
+
var _a;
|
|
47
48
|
if (isWindow(el))
|
|
48
49
|
return el.document;
|
|
49
50
|
if (isDocument(el))
|
|
50
51
|
return el;
|
|
51
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
52
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
52
53
|
}
|
|
53
54
|
function defineDomHelpers(helpers) {
|
|
54
55
|
const dom2 = {
|
|
55
56
|
getRootNode: (ctx) => {
|
|
56
|
-
var _a;
|
|
57
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx))
|
|
57
|
+
var _a, _b;
|
|
58
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
58
59
|
},
|
|
59
60
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
60
|
-
getWin: (ctx) =>
|
|
61
|
+
getWin: (ctx) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
64
|
+
},
|
|
61
65
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
62
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
66
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
67
|
+
createEmitter: (ctx, target) => {
|
|
68
|
+
const win = dom2.getWin(ctx);
|
|
69
|
+
return function emit(evt, detail, options) {
|
|
70
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
71
|
+
const eventName = `zag:${evt}`;
|
|
72
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
73
|
+
const event = new win.CustomEvent(eventName, init);
|
|
74
|
+
target.dispatchEvent(event);
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
createListener: (target) => {
|
|
78
|
+
return function listen(evt, handler) {
|
|
79
|
+
const eventName = `zag:${evt}`;
|
|
80
|
+
const listener = (e) => handler(e);
|
|
81
|
+
target.addEventListener(eventName, listener);
|
|
82
|
+
return () => target.removeEventListener(eventName, listener);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
63
85
|
};
|
|
64
86
|
return {
|
|
65
87
|
...dom2,
|
|
@@ -188,37 +210,37 @@ function next(v, idx, opts = {}) {
|
|
|
188
210
|
}
|
|
189
211
|
var runIfFn2 = (v, ...a) => {
|
|
190
212
|
const res = typeof v === "function" ? v(...a) : v;
|
|
191
|
-
return res
|
|
213
|
+
return res != null ? res : void 0;
|
|
192
214
|
};
|
|
193
215
|
|
|
194
216
|
// src/popover.dom.ts
|
|
195
217
|
var dom = defineDomHelpers({
|
|
196
218
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
197
219
|
getAnchorId: (ctx) => {
|
|
198
|
-
var _a;
|
|
199
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.anchor)
|
|
220
|
+
var _a, _b;
|
|
221
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
|
|
200
222
|
},
|
|
201
223
|
getTriggerId: (ctx) => {
|
|
202
|
-
var _a;
|
|
203
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger)
|
|
224
|
+
var _a, _b;
|
|
225
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
|
|
204
226
|
},
|
|
205
227
|
getContentId: (ctx) => {
|
|
206
|
-
var _a;
|
|
207
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content)
|
|
228
|
+
var _a, _b;
|
|
229
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
|
|
208
230
|
},
|
|
209
231
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
210
232
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
211
233
|
getTitleId: (ctx) => {
|
|
212
|
-
var _a;
|
|
213
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.title)
|
|
234
|
+
var _a, _b;
|
|
235
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
|
|
214
236
|
},
|
|
215
237
|
getDescriptionId: (ctx) => {
|
|
216
|
-
var _a;
|
|
217
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.description)
|
|
238
|
+
var _a, _b;
|
|
239
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
|
|
218
240
|
},
|
|
219
241
|
getCloseButtonId: (ctx) => {
|
|
220
|
-
var _a;
|
|
221
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn)
|
|
242
|
+
var _a, _b;
|
|
243
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
|
|
222
244
|
},
|
|
223
245
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
224
246
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ var dataAttr = (guard) => {
|
|
|
4
4
|
};
|
|
5
5
|
var runIfFn = (v, ...a) => {
|
|
6
6
|
const res = typeof v === "function" ? v(...a) : v;
|
|
7
|
-
return res
|
|
7
|
+
return res != null ? res : void 0;
|
|
8
8
|
};
|
|
9
9
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
10
10
|
function isDocument(el) {
|
|
@@ -17,22 +17,44 @@ function isFrame(element) {
|
|
|
17
17
|
return element.localName === "iframe";
|
|
18
18
|
}
|
|
19
19
|
function getDocument(el) {
|
|
20
|
+
var _a;
|
|
20
21
|
if (isWindow(el))
|
|
21
22
|
return el.document;
|
|
22
23
|
if (isDocument(el))
|
|
23
24
|
return el;
|
|
24
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
25
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
25
26
|
}
|
|
26
27
|
function defineDomHelpers(helpers) {
|
|
27
28
|
const dom2 = {
|
|
28
29
|
getRootNode: (ctx) => {
|
|
29
|
-
var _a;
|
|
30
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx))
|
|
30
|
+
var _a, _b;
|
|
31
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
31
32
|
},
|
|
32
33
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
33
|
-
getWin: (ctx) =>
|
|
34
|
+
getWin: (ctx) => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
37
|
+
},
|
|
34
38
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
35
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
39
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
40
|
+
createEmitter: (ctx, target) => {
|
|
41
|
+
const win = dom2.getWin(ctx);
|
|
42
|
+
return function emit(evt, detail, options) {
|
|
43
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
44
|
+
const eventName = `zag:${evt}`;
|
|
45
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
46
|
+
const event = new win.CustomEvent(eventName, init);
|
|
47
|
+
target.dispatchEvent(event);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
createListener: (target) => {
|
|
51
|
+
return function listen(evt, handler) {
|
|
52
|
+
const eventName = `zag:${evt}`;
|
|
53
|
+
const listener = (e) => handler(e);
|
|
54
|
+
target.addEventListener(eventName, listener);
|
|
55
|
+
return () => target.removeEventListener(eventName, listener);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
36
58
|
};
|
|
37
59
|
return {
|
|
38
60
|
...dom2,
|
|
@@ -161,37 +183,37 @@ function next(v, idx, opts = {}) {
|
|
|
161
183
|
}
|
|
162
184
|
var runIfFn2 = (v, ...a) => {
|
|
163
185
|
const res = typeof v === "function" ? v(...a) : v;
|
|
164
|
-
return res
|
|
186
|
+
return res != null ? res : void 0;
|
|
165
187
|
};
|
|
166
188
|
|
|
167
189
|
// src/popover.dom.ts
|
|
168
190
|
var dom = defineDomHelpers({
|
|
169
191
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
170
192
|
getAnchorId: (ctx) => {
|
|
171
|
-
var _a;
|
|
172
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.anchor)
|
|
193
|
+
var _a, _b;
|
|
194
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
|
|
173
195
|
},
|
|
174
196
|
getTriggerId: (ctx) => {
|
|
175
|
-
var _a;
|
|
176
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger)
|
|
197
|
+
var _a, _b;
|
|
198
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
|
|
177
199
|
},
|
|
178
200
|
getContentId: (ctx) => {
|
|
179
|
-
var _a;
|
|
180
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content)
|
|
201
|
+
var _a, _b;
|
|
202
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
|
|
181
203
|
},
|
|
182
204
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
183
205
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
184
206
|
getTitleId: (ctx) => {
|
|
185
|
-
var _a;
|
|
186
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.title)
|
|
207
|
+
var _a, _b;
|
|
208
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
|
|
187
209
|
},
|
|
188
210
|
getDescriptionId: (ctx) => {
|
|
189
|
-
var _a;
|
|
190
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.description)
|
|
211
|
+
var _a, _b;
|
|
212
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
|
|
191
213
|
},
|
|
192
214
|
getCloseButtonId: (ctx) => {
|
|
193
|
-
var _a;
|
|
194
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn)
|
|
215
|
+
var _a, _b;
|
|
216
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
|
|
195
217
|
},
|
|
196
218
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
197
219
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Core logic for the popover widget implemented as a state machine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/aria-hidden": "0.
|
|
33
|
-
"@zag-js/core": "0.
|
|
34
|
-
"@zag-js/dismissable": "0.
|
|
35
|
-
"@zag-js/popper": "0.
|
|
36
|
-
"@zag-js/remove-scroll": "0.
|
|
37
|
-
"@zag-js/types": "0.
|
|
32
|
+
"@zag-js/aria-hidden": "0.2.0",
|
|
33
|
+
"@zag-js/core": "0.2.0",
|
|
34
|
+
"@zag-js/dismissable": "0.2.0",
|
|
35
|
+
"@zag-js/popper": "0.2.0",
|
|
36
|
+
"@zag-js/remove-scroll": "0.2.0",
|
|
37
|
+
"@zag-js/types": "0.3.0",
|
|
38
38
|
"focus-trap": "7.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@zag-js/dom-utils": "0.
|
|
42
|
-
"@zag-js/utils": "0.
|
|
41
|
+
"@zag-js/dom-utils": "0.2.0",
|
|
42
|
+
"@zag-js/utils": "0.2.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build-fast": "tsup src/index.ts --format=esm,cjs",
|