@zag-js/popover 0.1.16 → 0.2.1
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.d.ts +1 -1
- package/dist/index.js +52 -20
- package/dist/index.mjs +52 -20
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,6 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
98
98
|
closeButtonProps: T["button"];
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
declare function machine(
|
|
101
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
102
102
|
|
|
103
103
|
export { UserDefinedContext as Context, connect, machine };
|
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,46 @@ 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
|
};
|
|
215
|
+
var isArray = (v) => Array.isArray(v);
|
|
216
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
217
|
+
function compact(obj) {
|
|
218
|
+
if (obj === void 0)
|
|
219
|
+
return obj;
|
|
220
|
+
return Object.fromEntries(
|
|
221
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
222
|
+
);
|
|
223
|
+
}
|
|
193
224
|
|
|
194
225
|
// src/popover.dom.ts
|
|
195
226
|
var dom = defineDomHelpers({
|
|
196
227
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
197
228
|
getAnchorId: (ctx) => {
|
|
198
|
-
var _a;
|
|
199
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.anchor)
|
|
229
|
+
var _a, _b;
|
|
230
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
|
|
200
231
|
},
|
|
201
232
|
getTriggerId: (ctx) => {
|
|
202
|
-
var _a;
|
|
203
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger)
|
|
233
|
+
var _a, _b;
|
|
234
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
|
|
204
235
|
},
|
|
205
236
|
getContentId: (ctx) => {
|
|
206
|
-
var _a;
|
|
207
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content)
|
|
237
|
+
var _a, _b;
|
|
238
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
|
|
208
239
|
},
|
|
209
240
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
210
241
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
211
242
|
getTitleId: (ctx) => {
|
|
212
|
-
var _a;
|
|
213
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.title)
|
|
243
|
+
var _a, _b;
|
|
244
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
|
|
214
245
|
},
|
|
215
246
|
getDescriptionId: (ctx) => {
|
|
216
|
-
var _a;
|
|
217
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.description)
|
|
247
|
+
var _a, _b;
|
|
248
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
|
|
218
249
|
},
|
|
219
250
|
getCloseButtonId: (ctx) => {
|
|
220
|
-
var _a;
|
|
221
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn)
|
|
251
|
+
var _a, _b;
|
|
252
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
|
|
222
253
|
},
|
|
223
254
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
224
255
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
@@ -334,7 +365,8 @@ var import_popper2 = require("@zag-js/popper");
|
|
|
334
365
|
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
335
366
|
var import_focus_trap = require("focus-trap");
|
|
336
367
|
var { and, or, not } = import_core.guards;
|
|
337
|
-
function machine(
|
|
368
|
+
function machine(userContext) {
|
|
369
|
+
const ctx = compact(userContext);
|
|
338
370
|
return (0, import_core.createMachine)(
|
|
339
371
|
{
|
|
340
372
|
id: "popover",
|
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,46 @@ 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
|
};
|
|
188
|
+
var isArray = (v) => Array.isArray(v);
|
|
189
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
190
|
+
function compact(obj) {
|
|
191
|
+
if (obj === void 0)
|
|
192
|
+
return obj;
|
|
193
|
+
return Object.fromEntries(
|
|
194
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
195
|
+
);
|
|
196
|
+
}
|
|
166
197
|
|
|
167
198
|
// src/popover.dom.ts
|
|
168
199
|
var dom = defineDomHelpers({
|
|
169
200
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
170
201
|
getAnchorId: (ctx) => {
|
|
171
|
-
var _a;
|
|
172
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.anchor)
|
|
202
|
+
var _a, _b;
|
|
203
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
|
|
173
204
|
},
|
|
174
205
|
getTriggerId: (ctx) => {
|
|
175
|
-
var _a;
|
|
176
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger)
|
|
206
|
+
var _a, _b;
|
|
207
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
|
|
177
208
|
},
|
|
178
209
|
getContentId: (ctx) => {
|
|
179
|
-
var _a;
|
|
180
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content)
|
|
210
|
+
var _a, _b;
|
|
211
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
|
|
181
212
|
},
|
|
182
213
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
183
214
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
184
215
|
getTitleId: (ctx) => {
|
|
185
|
-
var _a;
|
|
186
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.title)
|
|
216
|
+
var _a, _b;
|
|
217
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
|
|
187
218
|
},
|
|
188
219
|
getDescriptionId: (ctx) => {
|
|
189
|
-
var _a;
|
|
190
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.description)
|
|
220
|
+
var _a, _b;
|
|
221
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
|
|
191
222
|
},
|
|
192
223
|
getCloseButtonId: (ctx) => {
|
|
193
|
-
var _a;
|
|
194
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn)
|
|
224
|
+
var _a, _b;
|
|
225
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
|
|
195
226
|
},
|
|
196
227
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
197
228
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
@@ -307,7 +338,8 @@ import { getPlacement } from "@zag-js/popper";
|
|
|
307
338
|
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
308
339
|
import { createFocusTrap } from "focus-trap";
|
|
309
340
|
var { and, or, not } = guards;
|
|
310
|
-
function machine(
|
|
341
|
+
function machine(userContext) {
|
|
342
|
+
const ctx = compact(userContext);
|
|
311
343
|
return createMachine(
|
|
312
344
|
{
|
|
313
345
|
id: "popover",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popover",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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.1
|
|
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.1",
|
|
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.3.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build-fast": "tsup src/index.ts --format=esm,cjs",
|