@zag-js/popover 0.1.10 → 0.1.11
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/LICENSE +21 -0
- package/dist/index.d.ts +103 -3
- package/dist/index.js +39 -66
- package/dist/index.mjs +34 -69
- package/package.json +16 -15
- package/dist/popover.connect.d.ts +0 -17
- package/dist/popover.dom.d.ts +0 -41
- package/dist/popover.machine.d.ts +0 -2
- package/dist/popover.types.d.ts +0 -101
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Chakra UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { RequiredBy, CommonProperties, MaybeElement, Context, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
3
|
+
import { StateMachine } from '@zag-js/core';
|
|
4
|
+
import { DismissableElementHandlers } from '@zag-js/dismissable';
|
|
5
|
+
import { PositioningOptions } from '@zag-js/popper';
|
|
6
|
+
|
|
7
|
+
declare type ElementIds = Partial<{
|
|
8
|
+
anchor: string;
|
|
9
|
+
trigger: string;
|
|
10
|
+
content: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
closeBtn: string;
|
|
14
|
+
}>;
|
|
15
|
+
declare type PublicContext = DismissableElementHandlers & CommonProperties & {
|
|
16
|
+
/**
|
|
17
|
+
* The ids of the elements in the popover. Useful for composition.
|
|
18
|
+
*/
|
|
19
|
+
ids?: ElementIds;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the popover should be modal. When set to `true`:
|
|
22
|
+
* - interaction with outside elements will be disabled
|
|
23
|
+
* - only popover content will be visible to screen readers
|
|
24
|
+
* - scrolling is blocked
|
|
25
|
+
* - focus is trapped within the popover
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
modal?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the popover is rendered in a portal
|
|
32
|
+
*/
|
|
33
|
+
portalled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to automatically set focus on the first focusable
|
|
36
|
+
* content within the popover when opened.
|
|
37
|
+
*/
|
|
38
|
+
autoFocus?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The element to focus on when the popover is opened.
|
|
41
|
+
*/
|
|
42
|
+
initialFocusEl?: MaybeElement | (() => MaybeElement);
|
|
43
|
+
/**
|
|
44
|
+
* Whether to close the popover when the user clicks outside of the popover.
|
|
45
|
+
*/
|
|
46
|
+
closeOnInteractOutside?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to close the popover when the escape key is pressed.
|
|
49
|
+
*/
|
|
50
|
+
closeOnEsc?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Function invoked when the popover is opened.
|
|
53
|
+
*/
|
|
54
|
+
onOpenChange?: (open: boolean) => void;
|
|
55
|
+
/**
|
|
56
|
+
* The user provided options used to position the popover content
|
|
57
|
+
*/
|
|
58
|
+
positioning: PositioningOptions;
|
|
59
|
+
/**
|
|
60
|
+
* Whether to open the popover on page load
|
|
61
|
+
*/
|
|
62
|
+
defaultOpen?: boolean;
|
|
63
|
+
};
|
|
64
|
+
declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
65
|
+
declare type ComputedContext = Readonly<{
|
|
66
|
+
/**
|
|
67
|
+
* @computed
|
|
68
|
+
* The computed value of `portalled`
|
|
69
|
+
*/
|
|
70
|
+
currentPortalled: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
declare type PrivateContext = Context<{
|
|
73
|
+
/**
|
|
74
|
+
* Whether to prevent returning focus to the trigger
|
|
75
|
+
*/
|
|
76
|
+
focusTriggerOnClose?: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
declare type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
79
|
+
declare type MachineState = {
|
|
80
|
+
value: "unknown" | "open" | "closed";
|
|
81
|
+
};
|
|
82
|
+
declare type State = StateMachine.State<MachineContext, MachineState>;
|
|
83
|
+
declare type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
84
|
+
|
|
85
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
86
|
+
portalled: boolean;
|
|
87
|
+
isOpen: boolean;
|
|
88
|
+
open(): void;
|
|
89
|
+
close(): void;
|
|
90
|
+
arrowProps: T["element"];
|
|
91
|
+
innerArrowProps: T["element"];
|
|
92
|
+
anchorProps: T["element"];
|
|
93
|
+
triggerProps: T["button"];
|
|
94
|
+
positionerProps: T["element"];
|
|
95
|
+
contentProps: T["element"];
|
|
96
|
+
titleProps: T["element"];
|
|
97
|
+
descriptionProps: T["element"];
|
|
98
|
+
closeButtonProps: T["button"];
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
102
|
+
|
|
103
|
+
export { UserDefinedContext as Context, connect, machine };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
6
|
var __export = (target, all) => {
|
|
24
7
|
for (var name in all)
|
|
25
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,28 +26,12 @@ __export(src_exports, {
|
|
|
43
26
|
module.exports = __toCommonJS(src_exports);
|
|
44
27
|
|
|
45
28
|
// ../../utilities/dom/dist/index.mjs
|
|
46
|
-
var __defProp2 = Object.defineProperty;
|
|
47
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
48
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
49
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
50
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
51
|
-
var __spreadValues2 = (a, b) => {
|
|
52
|
-
for (var prop in b || (b = {}))
|
|
53
|
-
if (__hasOwnProp2.call(b, prop))
|
|
54
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
55
|
-
if (__getOwnPropSymbols2)
|
|
56
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
57
|
-
if (__propIsEnum2.call(b, prop))
|
|
58
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
59
|
-
}
|
|
60
|
-
return a;
|
|
61
|
-
};
|
|
62
29
|
var dataAttr = (guard) => {
|
|
63
30
|
return guard ? "" : void 0;
|
|
64
31
|
};
|
|
65
32
|
var runIfFn = (v, ...a) => {
|
|
66
33
|
const res = typeof v === "function" ? v(...a) : v;
|
|
67
|
-
return res
|
|
34
|
+
return res ?? void 0;
|
|
68
35
|
};
|
|
69
36
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
70
37
|
function isDocument(el) {
|
|
@@ -77,28 +44,27 @@ function isFrame(element) {
|
|
|
77
44
|
return element.localName === "iframe";
|
|
78
45
|
}
|
|
79
46
|
function getDocument(el) {
|
|
80
|
-
var _a;
|
|
81
47
|
if (isWindow(el))
|
|
82
48
|
return el.document;
|
|
83
49
|
if (isDocument(el))
|
|
84
50
|
return el;
|
|
85
|
-
return (
|
|
51
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
86
52
|
}
|
|
87
53
|
function defineDomHelpers(helpers) {
|
|
88
54
|
const dom2 = {
|
|
89
55
|
getRootNode: (ctx) => {
|
|
90
|
-
var _a, _b;
|
|
91
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
92
|
-
},
|
|
93
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
94
|
-
getWin: (ctx) => {
|
|
95
56
|
var _a;
|
|
96
|
-
return (_a =
|
|
57
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
97
58
|
},
|
|
59
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
60
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
98
61
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
99
62
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
100
63
|
};
|
|
101
|
-
return
|
|
64
|
+
return {
|
|
65
|
+
...dom2,
|
|
66
|
+
...helpers
|
|
67
|
+
};
|
|
102
68
|
}
|
|
103
69
|
function contains(parent, child) {
|
|
104
70
|
if (!parent)
|
|
@@ -222,37 +188,37 @@ function next(v, idx, opts = {}) {
|
|
|
222
188
|
}
|
|
223
189
|
var runIfFn2 = (v, ...a) => {
|
|
224
190
|
const res = typeof v === "function" ? v(...a) : v;
|
|
225
|
-
return res
|
|
191
|
+
return res ?? void 0;
|
|
226
192
|
};
|
|
227
193
|
|
|
228
194
|
// src/popover.dom.ts
|
|
229
195
|
var dom = defineDomHelpers({
|
|
230
196
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
231
197
|
getAnchorId: (ctx) => {
|
|
232
|
-
var _a
|
|
233
|
-
return (
|
|
198
|
+
var _a;
|
|
199
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.anchor) ?? `popover:${ctx.id}:anchor`;
|
|
234
200
|
},
|
|
235
201
|
getTriggerId: (ctx) => {
|
|
236
|
-
var _a
|
|
237
|
-
return (
|
|
202
|
+
var _a;
|
|
203
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `popover:${ctx.id}:trigger`;
|
|
238
204
|
},
|
|
239
205
|
getContentId: (ctx) => {
|
|
240
|
-
var _a
|
|
241
|
-
return (
|
|
206
|
+
var _a;
|
|
207
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `popover:${ctx.id}:content`;
|
|
242
208
|
},
|
|
243
209
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
244
210
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
245
211
|
getTitleId: (ctx) => {
|
|
246
|
-
var _a
|
|
247
|
-
return (
|
|
212
|
+
var _a;
|
|
213
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.title) ?? `popover:${ctx.id}:title`;
|
|
248
214
|
},
|
|
249
215
|
getDescriptionId: (ctx) => {
|
|
250
|
-
var _a
|
|
251
|
-
return (
|
|
216
|
+
var _a;
|
|
217
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.description) ?? `popover:${ctx.id}:desc`;
|
|
252
218
|
},
|
|
253
219
|
getCloseButtonId: (ctx) => {
|
|
254
|
-
var _a
|
|
255
|
-
return (
|
|
220
|
+
var _a;
|
|
221
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn) ?? `popover:${ctx.id}:close-button`;
|
|
256
222
|
},
|
|
257
223
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
258
224
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
@@ -372,23 +338,24 @@ function machine(ctx) {
|
|
|
372
338
|
return (0, import_core.createMachine)({
|
|
373
339
|
id: "popover",
|
|
374
340
|
initial: "unknown",
|
|
375
|
-
context:
|
|
341
|
+
context: {
|
|
376
342
|
closeOnInteractOutside: true,
|
|
377
343
|
closeOnEsc: true,
|
|
378
344
|
autoFocus: true,
|
|
379
345
|
modal: false,
|
|
380
|
-
positioning:
|
|
381
|
-
placement: "bottom"
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
346
|
+
positioning: {
|
|
347
|
+
placement: "bottom",
|
|
348
|
+
...ctx.positioning
|
|
349
|
+
},
|
|
350
|
+
currentPlacement: void 0,
|
|
351
|
+
...ctx,
|
|
385
352
|
focusTriggerOnClose: true,
|
|
386
353
|
renderedElements: {
|
|
387
354
|
title: true,
|
|
388
355
|
description: true,
|
|
389
356
|
anchor: false
|
|
390
357
|
}
|
|
391
|
-
}
|
|
358
|
+
},
|
|
392
359
|
computed: {
|
|
393
360
|
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
394
361
|
},
|
|
@@ -452,7 +419,8 @@ function machine(ctx) {
|
|
|
452
419
|
computePlacement(ctx2) {
|
|
453
420
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
454
421
|
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
455
|
-
return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2),
|
|
422
|
+
return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2), {
|
|
423
|
+
...ctx2.positioning,
|
|
456
424
|
onComplete(data) {
|
|
457
425
|
ctx2.currentPlacement = data.placement;
|
|
458
426
|
ctx2.isPlacementComplete = true;
|
|
@@ -461,7 +429,7 @@ function machine(ctx) {
|
|
|
461
429
|
ctx2.currentPlacement = void 0;
|
|
462
430
|
ctx2.isPlacementComplete = false;
|
|
463
431
|
}
|
|
464
|
-
})
|
|
432
|
+
});
|
|
465
433
|
},
|
|
466
434
|
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
467
435
|
return (0, import_dismissable.trackDismissableElement)(dom.getContentEl(ctx2), {
|
|
@@ -546,7 +514,7 @@ function machine(ctx) {
|
|
|
546
514
|
});
|
|
547
515
|
try {
|
|
548
516
|
trap.activate();
|
|
549
|
-
} catch
|
|
517
|
+
} catch {
|
|
550
518
|
}
|
|
551
519
|
});
|
|
552
520
|
return () => trap == null ? void 0 : trap.deactivate();
|
|
@@ -624,3 +592,8 @@ function machine(ctx) {
|
|
|
624
592
|
}
|
|
625
593
|
});
|
|
626
594
|
}
|
|
595
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
596
|
+
0 && (module.exports = {
|
|
597
|
+
connect,
|
|
598
|
+
machine
|
|
599
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// ../../utilities/dom/dist/index.mjs
|
|
22
|
-
var __defProp2 = Object.defineProperty;
|
|
23
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
24
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
25
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
26
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
27
|
-
var __spreadValues2 = (a, b) => {
|
|
28
|
-
for (var prop in b || (b = {}))
|
|
29
|
-
if (__hasOwnProp2.call(b, prop))
|
|
30
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
31
|
-
if (__getOwnPropSymbols2)
|
|
32
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
33
|
-
if (__propIsEnum2.call(b, prop))
|
|
34
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
35
|
-
}
|
|
36
|
-
return a;
|
|
37
|
-
};
|
|
38
2
|
var dataAttr = (guard) => {
|
|
39
3
|
return guard ? "" : void 0;
|
|
40
4
|
};
|
|
41
5
|
var runIfFn = (v, ...a) => {
|
|
42
6
|
const res = typeof v === "function" ? v(...a) : v;
|
|
43
|
-
return res
|
|
7
|
+
return res ?? void 0;
|
|
44
8
|
};
|
|
45
9
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
46
10
|
function isDocument(el) {
|
|
@@ -53,28 +17,27 @@ function isFrame(element) {
|
|
|
53
17
|
return element.localName === "iframe";
|
|
54
18
|
}
|
|
55
19
|
function getDocument(el) {
|
|
56
|
-
var _a;
|
|
57
20
|
if (isWindow(el))
|
|
58
21
|
return el.document;
|
|
59
22
|
if (isDocument(el))
|
|
60
23
|
return el;
|
|
61
|
-
return (
|
|
24
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
62
25
|
}
|
|
63
26
|
function defineDomHelpers(helpers) {
|
|
64
27
|
const dom2 = {
|
|
65
28
|
getRootNode: (ctx) => {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
68
|
-
},
|
|
69
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
70
|
-
getWin: (ctx) => {
|
|
71
29
|
var _a;
|
|
72
|
-
return (_a =
|
|
30
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
73
31
|
},
|
|
32
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
33
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
74
34
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
75
35
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
76
36
|
};
|
|
77
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...dom2,
|
|
39
|
+
...helpers
|
|
40
|
+
};
|
|
78
41
|
}
|
|
79
42
|
function contains(parent, child) {
|
|
80
43
|
if (!parent)
|
|
@@ -198,37 +161,37 @@ function next(v, idx, opts = {}) {
|
|
|
198
161
|
}
|
|
199
162
|
var runIfFn2 = (v, ...a) => {
|
|
200
163
|
const res = typeof v === "function" ? v(...a) : v;
|
|
201
|
-
return res
|
|
164
|
+
return res ?? void 0;
|
|
202
165
|
};
|
|
203
166
|
|
|
204
167
|
// src/popover.dom.ts
|
|
205
168
|
var dom = defineDomHelpers({
|
|
206
169
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
207
170
|
getAnchorId: (ctx) => {
|
|
208
|
-
var _a
|
|
209
|
-
return (
|
|
171
|
+
var _a;
|
|
172
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.anchor) ?? `popover:${ctx.id}:anchor`;
|
|
210
173
|
},
|
|
211
174
|
getTriggerId: (ctx) => {
|
|
212
|
-
var _a
|
|
213
|
-
return (
|
|
175
|
+
var _a;
|
|
176
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `popover:${ctx.id}:trigger`;
|
|
214
177
|
},
|
|
215
178
|
getContentId: (ctx) => {
|
|
216
|
-
var _a
|
|
217
|
-
return (
|
|
179
|
+
var _a;
|
|
180
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `popover:${ctx.id}:content`;
|
|
218
181
|
},
|
|
219
182
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
220
183
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
221
184
|
getTitleId: (ctx) => {
|
|
222
|
-
var _a
|
|
223
|
-
return (
|
|
185
|
+
var _a;
|
|
186
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.title) ?? `popover:${ctx.id}:title`;
|
|
224
187
|
},
|
|
225
188
|
getDescriptionId: (ctx) => {
|
|
226
|
-
var _a
|
|
227
|
-
return (
|
|
189
|
+
var _a;
|
|
190
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.description) ?? `popover:${ctx.id}:desc`;
|
|
228
191
|
},
|
|
229
192
|
getCloseButtonId: (ctx) => {
|
|
230
|
-
var _a
|
|
231
|
-
return (
|
|
193
|
+
var _a;
|
|
194
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn) ?? `popover:${ctx.id}:close-button`;
|
|
232
195
|
},
|
|
233
196
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
234
197
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
@@ -348,23 +311,24 @@ function machine(ctx) {
|
|
|
348
311
|
return createMachine({
|
|
349
312
|
id: "popover",
|
|
350
313
|
initial: "unknown",
|
|
351
|
-
context:
|
|
314
|
+
context: {
|
|
352
315
|
closeOnInteractOutside: true,
|
|
353
316
|
closeOnEsc: true,
|
|
354
317
|
autoFocus: true,
|
|
355
318
|
modal: false,
|
|
356
|
-
positioning:
|
|
357
|
-
placement: "bottom"
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
319
|
+
positioning: {
|
|
320
|
+
placement: "bottom",
|
|
321
|
+
...ctx.positioning
|
|
322
|
+
},
|
|
323
|
+
currentPlacement: void 0,
|
|
324
|
+
...ctx,
|
|
361
325
|
focusTriggerOnClose: true,
|
|
362
326
|
renderedElements: {
|
|
363
327
|
title: true,
|
|
364
328
|
description: true,
|
|
365
329
|
anchor: false
|
|
366
330
|
}
|
|
367
|
-
}
|
|
331
|
+
},
|
|
368
332
|
computed: {
|
|
369
333
|
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
370
334
|
},
|
|
@@ -428,7 +392,8 @@ function machine(ctx) {
|
|
|
428
392
|
computePlacement(ctx2) {
|
|
429
393
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
430
394
|
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
431
|
-
return getPlacement(anchorEl, dom.getPositionerEl(ctx2),
|
|
395
|
+
return getPlacement(anchorEl, dom.getPositionerEl(ctx2), {
|
|
396
|
+
...ctx2.positioning,
|
|
432
397
|
onComplete(data) {
|
|
433
398
|
ctx2.currentPlacement = data.placement;
|
|
434
399
|
ctx2.isPlacementComplete = true;
|
|
@@ -437,7 +402,7 @@ function machine(ctx) {
|
|
|
437
402
|
ctx2.currentPlacement = void 0;
|
|
438
403
|
ctx2.isPlacementComplete = false;
|
|
439
404
|
}
|
|
440
|
-
})
|
|
405
|
+
});
|
|
441
406
|
},
|
|
442
407
|
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
443
408
|
return trackDismissableElement(dom.getContentEl(ctx2), {
|
|
@@ -522,7 +487,7 @@ function machine(ctx) {
|
|
|
522
487
|
});
|
|
523
488
|
try {
|
|
524
489
|
trap.activate();
|
|
525
|
-
} catch
|
|
490
|
+
} catch {
|
|
526
491
|
}
|
|
527
492
|
});
|
|
528
493
|
return () => trap == null ? void 0 : trap.deactivate();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popover",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Core logic for the popover widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,25 +29,26 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/aria-hidden": "0.1.
|
|
33
|
-
"@zag-js/core": "0.1.
|
|
34
|
-
"@zag-js/dismissable": "0.1.
|
|
35
|
-
"@zag-js/popper": "0.1.
|
|
36
|
-
"@zag-js/remove-scroll": "0.1.
|
|
37
|
-
"@zag-js/types": "0.2.
|
|
32
|
+
"@zag-js/aria-hidden": "0.1.1",
|
|
33
|
+
"@zag-js/core": "0.1.9",
|
|
34
|
+
"@zag-js/dismissable": "0.1.3",
|
|
35
|
+
"@zag-js/popper": "0.1.9",
|
|
36
|
+
"@zag-js/remove-scroll": "0.1.3",
|
|
37
|
+
"@zag-js/types": "0.2.3",
|
|
38
38
|
"focus-trap": "6.9.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@zag-js/dom-utils": "0.1.
|
|
42
|
-
"@zag-js/utils": "0.1.
|
|
41
|
+
"@zag-js/dom-utils": "0.1.8",
|
|
42
|
+
"@zag-js/utils": "0.1.3"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"build
|
|
46
|
-
"start": "
|
|
47
|
-
"build": "
|
|
45
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
46
|
+
"start": "pnpm build --watch",
|
|
47
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
48
48
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
49
49
|
"lint": "eslint src --ext .ts,.tsx",
|
|
50
|
-
"test
|
|
51
|
-
"test
|
|
50
|
+
"test-ci": "pnpm test --ci --runInBand",
|
|
51
|
+
"test-watch": "pnpm test --watch -u",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { Send, State } from "./popover.types";
|
|
3
|
-
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
|
-
portalled: boolean;
|
|
5
|
-
isOpen: boolean;
|
|
6
|
-
open(): void;
|
|
7
|
-
close(): void;
|
|
8
|
-
arrowProps: T["element"];
|
|
9
|
-
innerArrowProps: T["element"];
|
|
10
|
-
anchorProps: T["element"];
|
|
11
|
-
triggerProps: T["button"];
|
|
12
|
-
positionerProps: T["element"];
|
|
13
|
-
contentProps: T["element"];
|
|
14
|
-
titleProps: T["element"];
|
|
15
|
-
descriptionProps: T["element"];
|
|
16
|
-
closeButtonProps: T["button"];
|
|
17
|
-
};
|
package/dist/popover.dom.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { MachineContext as Ctx } from "./popover.types";
|
|
2
|
-
export declare const dom: {
|
|
3
|
-
getRootNode: (ctx: {
|
|
4
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
5
|
-
}) => Document | ShadowRoot;
|
|
6
|
-
getDoc: (ctx: {
|
|
7
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
8
|
-
}) => Document;
|
|
9
|
-
getWin: (ctx: {
|
|
10
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
11
|
-
}) => Window & typeof globalThis;
|
|
12
|
-
getActiveElement: (ctx: {
|
|
13
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
14
|
-
}) => HTMLElement;
|
|
15
|
-
getById: <T_1 = HTMLElement>(ctx: {
|
|
16
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
17
|
-
}, id: string) => T_1;
|
|
18
|
-
} & {
|
|
19
|
-
getActiveEl: (ctx: Ctx) => Element;
|
|
20
|
-
getAnchorId: (ctx: Ctx) => string;
|
|
21
|
-
getTriggerId: (ctx: Ctx) => string;
|
|
22
|
-
getContentId: (ctx: Ctx) => string;
|
|
23
|
-
getPositionerId: (ctx: Ctx) => string;
|
|
24
|
-
getArrowId: (ctx: Ctx) => string;
|
|
25
|
-
getTitleId: (ctx: Ctx) => string;
|
|
26
|
-
getDescriptionId: (ctx: Ctx) => string;
|
|
27
|
-
getCloseButtonId: (ctx: Ctx) => string;
|
|
28
|
-
getAnchorEl: (ctx: Ctx) => HTMLElement;
|
|
29
|
-
getTriggerEl: (ctx: Ctx) => HTMLElement;
|
|
30
|
-
getContentEl: (ctx: Ctx) => HTMLElement;
|
|
31
|
-
getPositionerEl: (ctx: Ctx) => HTMLElement;
|
|
32
|
-
getTitleEl: (ctx: Ctx) => HTMLElement;
|
|
33
|
-
getDescriptionEl: (ctx: Ctx) => HTMLElement;
|
|
34
|
-
getFocusableEls: (ctx: Ctx) => HTMLElement[];
|
|
35
|
-
getFirstFocusableEl: (ctx: Ctx) => HTMLElement;
|
|
36
|
-
getDocTabbableEls: (ctx: Ctx) => HTMLElement[];
|
|
37
|
-
getTabbableEls: (ctx: Ctx) => HTMLElement[];
|
|
38
|
-
getFirstTabbableEl: (ctx: Ctx) => HTMLElement;
|
|
39
|
-
getLastTabbableEl: (ctx: Ctx) => HTMLElement;
|
|
40
|
-
getInitialFocusEl: (ctx: Ctx) => HTMLElement;
|
|
41
|
-
};
|
package/dist/popover.types.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { StateMachine as S } from "@zag-js/core";
|
|
2
|
-
import type { DismissableElementHandlers } from "@zag-js/dismissable";
|
|
3
|
-
import type { PositioningOptions, Placement } from "@zag-js/popper";
|
|
4
|
-
import type { CommonProperties, Context, MaybeElement, RequiredBy } from "@zag-js/types";
|
|
5
|
-
declare type ElementIds = Partial<{
|
|
6
|
-
anchor: string;
|
|
7
|
-
trigger: string;
|
|
8
|
-
content: string;
|
|
9
|
-
title: string;
|
|
10
|
-
description: string;
|
|
11
|
-
closeBtn: string;
|
|
12
|
-
}>;
|
|
13
|
-
declare type PublicContext = DismissableElementHandlers & CommonProperties & {
|
|
14
|
-
/**
|
|
15
|
-
* The ids of the elements in the popover. Useful for composition.
|
|
16
|
-
*/
|
|
17
|
-
ids?: ElementIds;
|
|
18
|
-
/**
|
|
19
|
-
* Whether the popover should be modal. When set to `true`:
|
|
20
|
-
* - interaction with outside elements will be disabled
|
|
21
|
-
* - only popover content will be visible to screen readers
|
|
22
|
-
* - scrolling is blocked
|
|
23
|
-
* - focus is trapped within the popover
|
|
24
|
-
*
|
|
25
|
-
* @default false
|
|
26
|
-
*/
|
|
27
|
-
modal?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Whether the popover is rendered in a portal
|
|
30
|
-
*/
|
|
31
|
-
portalled?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Whether to automatically set focus on the first focusable
|
|
34
|
-
* content within the popover when opened.
|
|
35
|
-
*/
|
|
36
|
-
autoFocus?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* The element to focus on when the popover is opened.
|
|
39
|
-
*/
|
|
40
|
-
initialFocusEl?: MaybeElement | (() => MaybeElement);
|
|
41
|
-
/**
|
|
42
|
-
* Whether to close the popover when the user clicks outside of the popover.
|
|
43
|
-
*/
|
|
44
|
-
closeOnInteractOutside?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Whether to close the popover when the escape key is pressed.
|
|
47
|
-
*/
|
|
48
|
-
closeOnEsc?: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Function invoked when the popover is opened.
|
|
51
|
-
*/
|
|
52
|
-
onOpenChange?: (open: boolean) => void;
|
|
53
|
-
/**
|
|
54
|
-
* The user provided options used to position the popover content
|
|
55
|
-
*/
|
|
56
|
-
positioning: PositioningOptions;
|
|
57
|
-
/**
|
|
58
|
-
* Whether to open the popover on page load
|
|
59
|
-
*/
|
|
60
|
-
defaultOpen?: boolean;
|
|
61
|
-
};
|
|
62
|
-
export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
63
|
-
declare type ComputedContext = Readonly<{
|
|
64
|
-
/**
|
|
65
|
-
* @computed
|
|
66
|
-
* The computed value of `portalled`
|
|
67
|
-
*/
|
|
68
|
-
currentPortalled: boolean;
|
|
69
|
-
}>;
|
|
70
|
-
declare type PrivateContext = Context<{
|
|
71
|
-
/**
|
|
72
|
-
* @internal
|
|
73
|
-
* The elements that are rendered on mount
|
|
74
|
-
*/
|
|
75
|
-
renderedElements: {
|
|
76
|
-
title: boolean;
|
|
77
|
-
description: boolean;
|
|
78
|
-
anchor: boolean;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* @internal
|
|
82
|
-
* The computed placement (maybe different from initial placement)
|
|
83
|
-
*/
|
|
84
|
-
currentPlacement?: Placement;
|
|
85
|
-
/**
|
|
86
|
-
* @internal
|
|
87
|
-
* Whether the dynamic placement has been computed
|
|
88
|
-
*/
|
|
89
|
-
isPlacementComplete?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Whether to prevent returning focus to the trigger
|
|
92
|
-
*/
|
|
93
|
-
focusTriggerOnClose?: boolean;
|
|
94
|
-
}>;
|
|
95
|
-
export declare type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
96
|
-
export declare type MachineState = {
|
|
97
|
-
value: "unknown" | "open" | "closed";
|
|
98
|
-
};
|
|
99
|
-
export declare type State = S.State<MachineContext, MachineState>;
|
|
100
|
-
export declare type Send = S.Send<S.AnyEventObject>;
|
|
101
|
-
export {};
|