@zag-js/popover 0.10.2 → 0.10.4
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 +4 -9
- package/dist/index.js +8 -409
- package/dist/index.mjs +3 -15
- package/dist/popover.anatomy.d.ts +3 -6
- package/dist/popover.anatomy.js +10 -33
- package/dist/popover.anatomy.mjs +16 -8
- package/dist/popover.connect.d.ts +4 -9
- package/dist/popover.connect.js +31 -104
- package/dist/popover.connect.mjs +106 -8
- package/dist/popover.dom.d.ts +24 -31
- package/dist/popover.dom.js +16 -38
- package/dist/popover.dom.mjs +37 -6
- package/dist/popover.machine.d.ts +3 -9
- package/dist/popover.machine.js +43 -102
- package/dist/popover.machine.mjs +227 -7
- package/dist/popover.types.d.ts +10 -12
- package/package.json +13 -18
- package/src/index.ts +1 -1
- package/src/popover.types.ts +2 -0
- package/dist/chunk-EDQUDEDS.mjs +0 -232
- package/dist/chunk-HRZXZNMW.mjs +0 -113
- package/dist/chunk-KTOPDXGV.mjs +0 -19
- package/dist/chunk-UA4OMIJI.mjs +0 -39
- package/dist/popover.types.js +0 -18
- package/dist/popover.types.mjs +0 -0
package/dist/popover.machine.js
CHANGED
|
@@ -1,78 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var popover_machine_exports = {};
|
|
22
|
-
__export(popover_machine_exports, {
|
|
23
|
-
machine: () => machine
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(popover_machine_exports);
|
|
26
|
-
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
27
|
-
var import_core = require("@zag-js/core");
|
|
28
|
-
var import_dismissable = require("@zag-js/dismissable");
|
|
29
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
30
|
-
var import_popper = require("@zag-js/popper");
|
|
31
|
-
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
32
|
-
var import_tabbable2 = require("@zag-js/tabbable");
|
|
33
|
-
var import_utils2 = require("@zag-js/utils");
|
|
34
|
-
var import_focus_trap = require("focus-trap");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
35
4
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getArrowId: (ctx) => ctx.ids?.arrow ?? `popover:${ctx.id}:arrow`,
|
|
47
|
-
getTitleId: (ctx) => ctx.ids?.title ?? `popover:${ctx.id}:title`,
|
|
48
|
-
getDescriptionId: (ctx) => ctx.ids?.description ?? `popover:${ctx.id}:desc`,
|
|
49
|
-
getCloseTriggerId: (ctx) => ctx.ids?.closeTrigger ?? `popover:${ctx.id}:close`,
|
|
50
|
-
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
51
|
-
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
52
|
-
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
53
|
-
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
54
|
-
getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
|
|
55
|
-
getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
|
|
56
|
-
getFocusableEls: (ctx) => (0, import_tabbable.getFocusables)(dom.getContentEl(ctx)),
|
|
57
|
-
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
58
|
-
getDocTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getDoc(ctx).body),
|
|
59
|
-
getTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getContentEl(ctx), "if-empty"),
|
|
60
|
-
getFirstTabbableEl: (ctx) => (0, import_tabbable.getFirstTabbable)(dom.getContentEl(ctx), "if-empty"),
|
|
61
|
-
getLastTabbableEl: (ctx) => (0, import_tabbable.getLastTabbable)(dom.getContentEl(ctx), "if-empty"),
|
|
62
|
-
getInitialFocusEl: (ctx) => {
|
|
63
|
-
let el = (0, import_utils.runIfFn)(ctx.initialFocusEl);
|
|
64
|
-
if (!el && ctx.autoFocus)
|
|
65
|
-
el = dom.getFirstFocusableEl(ctx);
|
|
66
|
-
if (!el)
|
|
67
|
-
el = dom.getContentEl(ctx);
|
|
68
|
-
return el;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
5
|
+
const ariaHidden = require('@zag-js/aria-hidden');
|
|
6
|
+
const core = require('@zag-js/core');
|
|
7
|
+
const dismissable = require('@zag-js/dismissable');
|
|
8
|
+
const domQuery = require('@zag-js/dom-query');
|
|
9
|
+
const popper = require('@zag-js/popper');
|
|
10
|
+
const removeScroll = require('@zag-js/remove-scroll');
|
|
11
|
+
const tabbable = require('@zag-js/tabbable');
|
|
12
|
+
const utils = require('@zag-js/utils');
|
|
13
|
+
const focusTrap = require('focus-trap');
|
|
14
|
+
const popover_dom = require('./popover.dom.js');
|
|
71
15
|
|
|
72
|
-
// src/popover.machine.ts
|
|
73
16
|
function machine(userContext) {
|
|
74
|
-
const ctx =
|
|
75
|
-
return
|
|
17
|
+
const ctx = utils.compact(userContext);
|
|
18
|
+
return core.createMachine(
|
|
76
19
|
{
|
|
77
20
|
id: "popover",
|
|
78
21
|
initial: ctx.open ? "open" : "closed",
|
|
@@ -146,9 +89,9 @@ function machine(userContext) {
|
|
|
146
89
|
activities: {
|
|
147
90
|
trackPositioning(ctx2) {
|
|
148
91
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
149
|
-
const anchorEl = dom.getAnchorEl(ctx2) ?? dom.getTriggerEl(ctx2);
|
|
150
|
-
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
151
|
-
return
|
|
92
|
+
const anchorEl = popover_dom.dom.getAnchorEl(ctx2) ?? popover_dom.dom.getTriggerEl(ctx2);
|
|
93
|
+
const getPositionerEl = () => popover_dom.dom.getPositionerEl(ctx2);
|
|
94
|
+
return popper.getPlacement(anchorEl, getPositionerEl, {
|
|
152
95
|
...ctx2.positioning,
|
|
153
96
|
defer: true,
|
|
154
97
|
onComplete(data) {
|
|
@@ -160,11 +103,11 @@ function machine(userContext) {
|
|
|
160
103
|
});
|
|
161
104
|
},
|
|
162
105
|
trackDismissableElement(ctx2, _evt, { send }) {
|
|
163
|
-
const getContentEl = () => dom.getContentEl(ctx2);
|
|
106
|
+
const getContentEl = () => popover_dom.dom.getContentEl(ctx2);
|
|
164
107
|
let restoreFocus = true;
|
|
165
|
-
return
|
|
108
|
+
return dismissable.trackDismissableElement(getContentEl, {
|
|
166
109
|
pointerBlocking: ctx2.modal,
|
|
167
|
-
exclude: dom.getTriggerEl(ctx2),
|
|
110
|
+
exclude: popover_dom.dom.getTriggerEl(ctx2),
|
|
168
111
|
defer: true,
|
|
169
112
|
onEscapeKeyDown(event) {
|
|
170
113
|
ctx2.onEscapeKeyDown?.(event);
|
|
@@ -195,9 +138,9 @@ function machine(userContext) {
|
|
|
195
138
|
proxyTabFocus(ctx2) {
|
|
196
139
|
if (ctx2.modal || !ctx2.portalled)
|
|
197
140
|
return;
|
|
198
|
-
const getContentEl = () => dom.getContentEl(ctx2);
|
|
199
|
-
return
|
|
200
|
-
triggerElement: dom.getTriggerEl(ctx2),
|
|
141
|
+
const getContentEl = () => popover_dom.dom.getContentEl(ctx2);
|
|
142
|
+
return tabbable.proxyTabFocus(getContentEl, {
|
|
143
|
+
triggerElement: popover_dom.dom.getTriggerEl(ctx2),
|
|
201
144
|
defer: true,
|
|
202
145
|
onFocus(el) {
|
|
203
146
|
el.focus({ preventScroll: true });
|
|
@@ -207,30 +150,30 @@ function machine(userContext) {
|
|
|
207
150
|
hideContentBelow(ctx2) {
|
|
208
151
|
if (!ctx2.modal)
|
|
209
152
|
return;
|
|
210
|
-
const getElements = () => [dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)];
|
|
211
|
-
return
|
|
153
|
+
const getElements = () => [popover_dom.dom.getContentEl(ctx2), popover_dom.dom.getTriggerEl(ctx2)];
|
|
154
|
+
return ariaHidden.ariaHidden(getElements, { defer: true });
|
|
212
155
|
},
|
|
213
156
|
preventScroll(ctx2) {
|
|
214
157
|
if (!ctx2.modal)
|
|
215
158
|
return;
|
|
216
|
-
return
|
|
159
|
+
return removeScroll.preventBodyScroll(popover_dom.dom.getDoc(ctx2));
|
|
217
160
|
},
|
|
218
161
|
trapFocus(ctx2) {
|
|
219
162
|
if (!ctx2.modal)
|
|
220
163
|
return;
|
|
221
164
|
let trap;
|
|
222
|
-
|
|
223
|
-
const el = dom.getContentEl(ctx2);
|
|
165
|
+
domQuery.nextTick(() => {
|
|
166
|
+
const el = popover_dom.dom.getContentEl(ctx2);
|
|
224
167
|
if (!el)
|
|
225
168
|
return;
|
|
226
|
-
trap =
|
|
169
|
+
trap = focusTrap.createFocusTrap(el, {
|
|
227
170
|
escapeDeactivates: false,
|
|
228
171
|
allowOutsideClick: true,
|
|
229
172
|
preventScroll: true,
|
|
230
173
|
returnFocusOnDeactivate: true,
|
|
231
|
-
document: dom.getDoc(ctx2),
|
|
174
|
+
document: popover_dom.dom.getDoc(ctx2),
|
|
232
175
|
fallbackFocus: el,
|
|
233
|
-
initialFocus:
|
|
176
|
+
initialFocus: utils.runIfFn(ctx2.initialFocusEl)
|
|
234
177
|
});
|
|
235
178
|
try {
|
|
236
179
|
trap.activate();
|
|
@@ -242,9 +185,9 @@ function machine(userContext) {
|
|
|
242
185
|
},
|
|
243
186
|
actions: {
|
|
244
187
|
setPositioning(ctx2, evt) {
|
|
245
|
-
const anchorEl = dom.getAnchorEl(ctx2) ?? dom.getTriggerEl(ctx2);
|
|
246
|
-
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
247
|
-
|
|
188
|
+
const anchorEl = popover_dom.dom.getAnchorEl(ctx2) ?? popover_dom.dom.getTriggerEl(ctx2);
|
|
189
|
+
const getPositionerEl = () => popover_dom.dom.getPositionerEl(ctx2);
|
|
190
|
+
popper.getPlacement(anchorEl, getPositionerEl, {
|
|
248
191
|
...ctx2.positioning,
|
|
249
192
|
...evt.options,
|
|
250
193
|
defer: true,
|
|
@@ -252,23 +195,23 @@ function machine(userContext) {
|
|
|
252
195
|
});
|
|
253
196
|
},
|
|
254
197
|
checkRenderedElements(ctx2) {
|
|
255
|
-
|
|
198
|
+
domQuery.raf(() => {
|
|
256
199
|
Object.assign(ctx2.renderedElements, {
|
|
257
|
-
title: !!dom.getTitleEl(ctx2),
|
|
258
|
-
description: !!dom.getDescriptionEl(ctx2)
|
|
200
|
+
title: !!popover_dom.dom.getTitleEl(ctx2),
|
|
201
|
+
description: !!popover_dom.dom.getDescriptionEl(ctx2)
|
|
259
202
|
});
|
|
260
203
|
});
|
|
261
204
|
},
|
|
262
205
|
setInitialFocus(ctx2) {
|
|
263
|
-
|
|
264
|
-
dom.getInitialFocusEl(ctx2)?.focus({ preventScroll: true });
|
|
206
|
+
domQuery.raf(() => {
|
|
207
|
+
popover_dom.dom.getInitialFocusEl(ctx2)?.focus({ preventScroll: true });
|
|
265
208
|
});
|
|
266
209
|
},
|
|
267
210
|
restoreFocusIfNeeded(ctx2, evt) {
|
|
268
211
|
if (!evt.restoreFocus)
|
|
269
212
|
return;
|
|
270
|
-
|
|
271
|
-
dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
|
|
213
|
+
domQuery.raf(() => {
|
|
214
|
+
popover_dom.dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
|
|
272
215
|
});
|
|
273
216
|
},
|
|
274
217
|
invokeOnOpen(ctx2) {
|
|
@@ -284,7 +227,5 @@ function machine(userContext) {
|
|
|
284
227
|
}
|
|
285
228
|
);
|
|
286
229
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
machine
|
|
290
|
-
});
|
|
230
|
+
|
|
231
|
+
exports.machine = machine;
|
package/dist/popover.machine.mjs
CHANGED
|
@@ -1,7 +1,227 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
1
|
+
import { ariaHidden } from '@zag-js/aria-hidden';
|
|
2
|
+
import { createMachine } from '@zag-js/core';
|
|
3
|
+
import { trackDismissableElement } from '@zag-js/dismissable';
|
|
4
|
+
import { nextTick, raf } from '@zag-js/dom-query';
|
|
5
|
+
import { getPlacement } from '@zag-js/popper';
|
|
6
|
+
import { preventBodyScroll } from '@zag-js/remove-scroll';
|
|
7
|
+
import { proxyTabFocus } from '@zag-js/tabbable';
|
|
8
|
+
import { compact, runIfFn } from '@zag-js/utils';
|
|
9
|
+
import { createFocusTrap } from 'focus-trap';
|
|
10
|
+
import { dom } from './popover.dom.mjs';
|
|
11
|
+
|
|
12
|
+
function machine(userContext) {
|
|
13
|
+
const ctx = compact(userContext);
|
|
14
|
+
return createMachine(
|
|
15
|
+
{
|
|
16
|
+
id: "popover",
|
|
17
|
+
initial: ctx.open ? "open" : "closed",
|
|
18
|
+
context: {
|
|
19
|
+
closeOnInteractOutside: true,
|
|
20
|
+
closeOnEsc: true,
|
|
21
|
+
autoFocus: true,
|
|
22
|
+
modal: false,
|
|
23
|
+
positioning: {
|
|
24
|
+
placement: "bottom",
|
|
25
|
+
...ctx.positioning
|
|
26
|
+
},
|
|
27
|
+
currentPlacement: void 0,
|
|
28
|
+
...ctx,
|
|
29
|
+
renderedElements: {
|
|
30
|
+
title: true,
|
|
31
|
+
description: true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
computed: {
|
|
35
|
+
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
36
|
+
},
|
|
37
|
+
watch: {
|
|
38
|
+
open: ["toggleVisibility"]
|
|
39
|
+
},
|
|
40
|
+
entry: ["checkRenderedElements"],
|
|
41
|
+
states: {
|
|
42
|
+
closed: {
|
|
43
|
+
on: {
|
|
44
|
+
TOGGLE: {
|
|
45
|
+
target: "open",
|
|
46
|
+
actions: ["invokeOnOpen"]
|
|
47
|
+
},
|
|
48
|
+
OPEN: {
|
|
49
|
+
target: "open",
|
|
50
|
+
actions: ["invokeOnOpen"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
open: {
|
|
55
|
+
activities: [
|
|
56
|
+
"trapFocus",
|
|
57
|
+
"preventScroll",
|
|
58
|
+
"hideContentBelow",
|
|
59
|
+
"trackPositioning",
|
|
60
|
+
"trackDismissableElement",
|
|
61
|
+
"proxyTabFocus"
|
|
62
|
+
],
|
|
63
|
+
entry: ["setInitialFocus"],
|
|
64
|
+
on: {
|
|
65
|
+
CLOSE: {
|
|
66
|
+
target: "closed",
|
|
67
|
+
actions: ["invokeOnClose"]
|
|
68
|
+
},
|
|
69
|
+
REQUEST_CLOSE: {
|
|
70
|
+
target: "closed",
|
|
71
|
+
actions: ["restoreFocusIfNeeded", "invokeOnClose"]
|
|
72
|
+
},
|
|
73
|
+
TOGGLE: {
|
|
74
|
+
target: "closed",
|
|
75
|
+
actions: ["invokeOnClose"]
|
|
76
|
+
},
|
|
77
|
+
SET_POSITIONING: {
|
|
78
|
+
actions: "setPositioning"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
activities: {
|
|
86
|
+
trackPositioning(ctx2) {
|
|
87
|
+
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
88
|
+
const anchorEl = dom.getAnchorEl(ctx2) ?? dom.getTriggerEl(ctx2);
|
|
89
|
+
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
90
|
+
return getPlacement(anchorEl, getPositionerEl, {
|
|
91
|
+
...ctx2.positioning,
|
|
92
|
+
defer: true,
|
|
93
|
+
onComplete(data) {
|
|
94
|
+
ctx2.currentPlacement = data.placement;
|
|
95
|
+
},
|
|
96
|
+
onCleanup() {
|
|
97
|
+
ctx2.currentPlacement = void 0;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
trackDismissableElement(ctx2, _evt, { send }) {
|
|
102
|
+
const getContentEl = () => dom.getContentEl(ctx2);
|
|
103
|
+
let restoreFocus = true;
|
|
104
|
+
return trackDismissableElement(getContentEl, {
|
|
105
|
+
pointerBlocking: ctx2.modal,
|
|
106
|
+
exclude: dom.getTriggerEl(ctx2),
|
|
107
|
+
defer: true,
|
|
108
|
+
onEscapeKeyDown(event) {
|
|
109
|
+
ctx2.onEscapeKeyDown?.(event);
|
|
110
|
+
if (ctx2.closeOnEsc)
|
|
111
|
+
return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
},
|
|
114
|
+
onInteractOutside(event) {
|
|
115
|
+
ctx2.onInteractOutside?.(event);
|
|
116
|
+
if (event.defaultPrevented)
|
|
117
|
+
return;
|
|
118
|
+
restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
119
|
+
if (!ctx2.closeOnInteractOutside) {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onPointerDownOutside(event) {
|
|
124
|
+
ctx2.onPointerDownOutside?.(event);
|
|
125
|
+
},
|
|
126
|
+
onFocusOutside(event) {
|
|
127
|
+
ctx2.onFocusOutside?.(event);
|
|
128
|
+
},
|
|
129
|
+
onDismiss() {
|
|
130
|
+
send({ type: "REQUEST_CLOSE", src: "interact-outside", restoreFocus });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
proxyTabFocus(ctx2) {
|
|
135
|
+
if (ctx2.modal || !ctx2.portalled)
|
|
136
|
+
return;
|
|
137
|
+
const getContentEl = () => dom.getContentEl(ctx2);
|
|
138
|
+
return proxyTabFocus(getContentEl, {
|
|
139
|
+
triggerElement: dom.getTriggerEl(ctx2),
|
|
140
|
+
defer: true,
|
|
141
|
+
onFocus(el) {
|
|
142
|
+
el.focus({ preventScroll: true });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
hideContentBelow(ctx2) {
|
|
147
|
+
if (!ctx2.modal)
|
|
148
|
+
return;
|
|
149
|
+
const getElements = () => [dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)];
|
|
150
|
+
return ariaHidden(getElements, { defer: true });
|
|
151
|
+
},
|
|
152
|
+
preventScroll(ctx2) {
|
|
153
|
+
if (!ctx2.modal)
|
|
154
|
+
return;
|
|
155
|
+
return preventBodyScroll(dom.getDoc(ctx2));
|
|
156
|
+
},
|
|
157
|
+
trapFocus(ctx2) {
|
|
158
|
+
if (!ctx2.modal)
|
|
159
|
+
return;
|
|
160
|
+
let trap;
|
|
161
|
+
nextTick(() => {
|
|
162
|
+
const el = dom.getContentEl(ctx2);
|
|
163
|
+
if (!el)
|
|
164
|
+
return;
|
|
165
|
+
trap = createFocusTrap(el, {
|
|
166
|
+
escapeDeactivates: false,
|
|
167
|
+
allowOutsideClick: true,
|
|
168
|
+
preventScroll: true,
|
|
169
|
+
returnFocusOnDeactivate: true,
|
|
170
|
+
document: dom.getDoc(ctx2),
|
|
171
|
+
fallbackFocus: el,
|
|
172
|
+
initialFocus: runIfFn(ctx2.initialFocusEl)
|
|
173
|
+
});
|
|
174
|
+
try {
|
|
175
|
+
trap.activate();
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return () => trap?.deactivate();
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
actions: {
|
|
183
|
+
setPositioning(ctx2, evt) {
|
|
184
|
+
const anchorEl = dom.getAnchorEl(ctx2) ?? dom.getTriggerEl(ctx2);
|
|
185
|
+
const getPositionerEl = () => dom.getPositionerEl(ctx2);
|
|
186
|
+
getPlacement(anchorEl, getPositionerEl, {
|
|
187
|
+
...ctx2.positioning,
|
|
188
|
+
...evt.options,
|
|
189
|
+
defer: true,
|
|
190
|
+
listeners: false
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
checkRenderedElements(ctx2) {
|
|
194
|
+
raf(() => {
|
|
195
|
+
Object.assign(ctx2.renderedElements, {
|
|
196
|
+
title: !!dom.getTitleEl(ctx2),
|
|
197
|
+
description: !!dom.getDescriptionEl(ctx2)
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
setInitialFocus(ctx2) {
|
|
202
|
+
raf(() => {
|
|
203
|
+
dom.getInitialFocusEl(ctx2)?.focus({ preventScroll: true });
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
restoreFocusIfNeeded(ctx2, evt) {
|
|
207
|
+
if (!evt.restoreFocus)
|
|
208
|
+
return;
|
|
209
|
+
raf(() => {
|
|
210
|
+
dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
invokeOnOpen(ctx2) {
|
|
214
|
+
ctx2.onOpen?.();
|
|
215
|
+
},
|
|
216
|
+
invokeOnClose(ctx2) {
|
|
217
|
+
ctx2.onClose?.();
|
|
218
|
+
},
|
|
219
|
+
toggleVisibility(ctx2, _evt, { send }) {
|
|
220
|
+
send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { machine };
|
package/dist/popover.types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { StateMachine } from
|
|
2
|
-
import { DismissableElementHandlers } from
|
|
3
|
-
import { PositioningOptions } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
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";
|
|
6
5
|
type ElementIds = Partial<{
|
|
7
6
|
anchor: string;
|
|
8
7
|
trigger: string;
|
|
@@ -66,7 +65,7 @@ type PublicContext = DismissableElementHandlers & CommonProperties & {
|
|
|
66
65
|
*/
|
|
67
66
|
open?: boolean;
|
|
68
67
|
};
|
|
69
|
-
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
68
|
+
export type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
70
69
|
type ComputedContext = Readonly<{
|
|
71
70
|
/**
|
|
72
71
|
* @computed
|
|
@@ -75,11 +74,10 @@ type ComputedContext = Readonly<{
|
|
|
75
74
|
currentPortalled: boolean;
|
|
76
75
|
}>;
|
|
77
76
|
type PrivateContext = Context<{}>;
|
|
78
|
-
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
79
|
-
type MachineState = {
|
|
77
|
+
export type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
78
|
+
export type MachineState = {
|
|
80
79
|
value: "open" | "closed";
|
|
81
80
|
};
|
|
82
|
-
type State =
|
|
83
|
-
type Send =
|
|
84
|
-
|
|
85
|
-
export { MachineContext, MachineState, Send, State, UserDefinedContext };
|
|
81
|
+
export type State = S.State<MachineContext, MachineState>;
|
|
82
|
+
export type Send = S.Send<S.AnyEventObject>;
|
|
83
|
+
export type { PositioningOptions, Placement };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popover",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Core logic for the popover widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"focus-trap": "7.
|
|
31
|
-
"@zag-js/anatomy": "0.10.
|
|
32
|
-
"@zag-js/aria-hidden": "0.10.
|
|
33
|
-
"@zag-js/core": "0.10.
|
|
34
|
-
"@zag-js/dom-query": "0.10.
|
|
35
|
-
"@zag-js/utils": "0.10.
|
|
36
|
-
"@zag-js/dismissable": "0.10.
|
|
37
|
-
"@zag-js/tabbable": "0.10.
|
|
38
|
-
"@zag-js/popper": "0.10.
|
|
39
|
-
"@zag-js/remove-scroll": "0.10.
|
|
40
|
-
"@zag-js/types": "0.10.
|
|
30
|
+
"focus-trap": "7.5.1",
|
|
31
|
+
"@zag-js/anatomy": "0.10.4",
|
|
32
|
+
"@zag-js/aria-hidden": "0.10.4",
|
|
33
|
+
"@zag-js/core": "0.10.4",
|
|
34
|
+
"@zag-js/dom-query": "0.10.4",
|
|
35
|
+
"@zag-js/utils": "0.10.4",
|
|
36
|
+
"@zag-js/dismissable": "0.10.4",
|
|
37
|
+
"@zag-js/tabbable": "0.10.4",
|
|
38
|
+
"@zag-js/popper": "0.10.4",
|
|
39
|
+
"@zag-js/remove-scroll": "0.10.4",
|
|
40
|
+
"@zag-js/types": "0.10.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"clean-package": "2.2.0"
|
|
@@ -55,13 +55,8 @@
|
|
|
55
55
|
"./package.json": "./package.json"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
|
-
"build
|
|
59
|
-
"start": "pnpm build --watch",
|
|
60
|
-
"build": "tsup src --dts",
|
|
61
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
58
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
62
59
|
"lint": "eslint src --ext .ts,.tsx",
|
|
63
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
64
|
-
"test-watch": "pnpm test --watch -u",
|
|
65
60
|
"typecheck": "tsc --noEmit"
|
|
66
61
|
}
|
|
67
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { anatomy } from "./popover.anatomy"
|
|
2
2
|
export { connect } from "./popover.connect"
|
|
3
3
|
export { machine } from "./popover.machine"
|
|
4
|
-
export type { UserDefinedContext as Context } from "./popover.types"
|
|
4
|
+
export type { UserDefinedContext as Context, Placement, PositioningOptions } from "./popover.types"
|