@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 CHANGED
@@ -1,9 +1,4 @@
1
- export { anatomy } from './popover.anatomy.js';
2
- export { connect } from './popover.connect.js';
3
- export { machine } from './popover.machine.js';
4
- export { UserDefinedContext as Context } from './popover.types.js';
5
- import '@zag-js/anatomy';
6
- import '@zag-js/popper';
7
- import '@zag-js/types';
8
- import '@zag-js/core';
9
- import '@zag-js/dismissable';
1
+ export { anatomy } from "./popover.anatomy";
2
+ export { connect } from "./popover.connect";
3
+ export { machine } from "./popover.machine";
4
+ export type { UserDefinedContext as Context, Placement, PositioningOptions } from "./popover.types";
package/dist/index.js CHANGED
@@ -1,414 +1,13 @@
1
- "use strict";
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
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- anatomy: () => anatomy,
24
- connect: () => connect,
25
- machine: () => machine
26
- });
27
- module.exports = __toCommonJS(src_exports);
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
28
4
 
29
- // src/popover.anatomy.ts
30
- var import_anatomy = require("@zag-js/anatomy");
31
- var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
32
- "arrow",
33
- "arrowTip",
34
- "anchor",
35
- "trigger",
36
- "positioner",
37
- "content",
38
- "title",
39
- "description",
40
- "closeTrigger"
41
- );
42
- var parts = anatomy.build();
5
+ const popover_anatomy = require('./popover.anatomy.js');
6
+ const popover_connect = require('./popover.connect.js');
7
+ const popover_machine = require('./popover.machine.js');
43
8
 
44
- // src/popover.connect.ts
45
- var import_dom_query2 = require("@zag-js/dom-query");
46
- var import_popper = require("@zag-js/popper");
47
9
 
48
- // src/popover.dom.ts
49
- var import_dom_query = require("@zag-js/dom-query");
50
- var import_tabbable = require("@zag-js/tabbable");
51
- var import_utils = require("@zag-js/utils");
52
- var dom = (0, import_dom_query.createScope)({
53
- getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
54
- getAnchorId: (ctx) => ctx.ids?.anchor ?? `popover:${ctx.id}:anchor`,
55
- getTriggerId: (ctx) => ctx.ids?.trigger ?? `popover:${ctx.id}:trigger`,
56
- getContentId: (ctx) => ctx.ids?.content ?? `popover:${ctx.id}:content`,
57
- getPositionerId: (ctx) => ctx.ids?.positioner ?? `popover:${ctx.id}:popper`,
58
- getArrowId: (ctx) => ctx.ids?.arrow ?? `popover:${ctx.id}:arrow`,
59
- getTitleId: (ctx) => ctx.ids?.title ?? `popover:${ctx.id}:title`,
60
- getDescriptionId: (ctx) => ctx.ids?.description ?? `popover:${ctx.id}:desc`,
61
- getCloseTriggerId: (ctx) => ctx.ids?.closeTrigger ?? `popover:${ctx.id}:close`,
62
- getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
63
- getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
64
- getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
65
- getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
66
- getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
67
- getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
68
- getFocusableEls: (ctx) => (0, import_tabbable.getFocusables)(dom.getContentEl(ctx)),
69
- getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
70
- getDocTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getDoc(ctx).body),
71
- getTabbableEls: (ctx) => (0, import_tabbable.getTabbables)(dom.getContentEl(ctx), "if-empty"),
72
- getFirstTabbableEl: (ctx) => (0, import_tabbable.getFirstTabbable)(dom.getContentEl(ctx), "if-empty"),
73
- getLastTabbableEl: (ctx) => (0, import_tabbable.getLastTabbable)(dom.getContentEl(ctx), "if-empty"),
74
- getInitialFocusEl: (ctx) => {
75
- let el = (0, import_utils.runIfFn)(ctx.initialFocusEl);
76
- if (!el && ctx.autoFocus)
77
- el = dom.getFirstFocusableEl(ctx);
78
- if (!el)
79
- el = dom.getContentEl(ctx);
80
- return el;
81
- }
82
- });
83
10
 
84
- // src/popover.connect.ts
85
- function connect(state, send, normalize) {
86
- const isOpen = state.matches("open");
87
- const currentPlacement = state.context.currentPlacement;
88
- const portalled = state.context.currentPortalled;
89
- const rendered = state.context.renderedElements;
90
- const popperStyles = (0, import_popper.getPlacementStyles)({
91
- placement: currentPlacement
92
- });
93
- return {
94
- /**
95
- * Whether the popover is portalled
96
- */
97
- portalled,
98
- /**
99
- * Whether the popover is open
100
- */
101
- isOpen,
102
- /**
103
- * Function to open the popover
104
- */
105
- open() {
106
- send("OPEN");
107
- },
108
- /**
109
- * Function to close the popover
110
- */
111
- close() {
112
- send("CLOSE");
113
- },
114
- /**
115
- * Function to reposition the popover
116
- */
117
- setPositioning(options = {}) {
118
- send({ type: "SET_POSITIONING", options });
119
- },
120
- arrowProps: normalize.element({
121
- id: dom.getArrowId(state.context),
122
- ...parts.arrow.attrs,
123
- style: popperStyles.arrow
124
- }),
125
- arrowTipProps: normalize.element({
126
- ...parts.arrowTip.attrs,
127
- style: popperStyles.arrowTip
128
- }),
129
- anchorProps: normalize.element({
130
- ...parts.anchor.attrs,
131
- id: dom.getAnchorId(state.context)
132
- }),
133
- triggerProps: normalize.button({
134
- ...parts.trigger.attrs,
135
- type: "button",
136
- "data-placement": currentPlacement,
137
- id: dom.getTriggerId(state.context),
138
- "aria-haspopup": "dialog",
139
- "aria-expanded": isOpen,
140
- "data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
141
- "aria-controls": dom.getContentId(state.context),
142
- onClick() {
143
- send("TOGGLE");
144
- },
145
- onBlur(event) {
146
- send({ type: "TRIGGER_BLUR", target: event.relatedTarget });
147
- }
148
- }),
149
- positionerProps: normalize.element({
150
- id: dom.getPositionerId(state.context),
151
- ...parts.positioner.attrs,
152
- style: popperStyles.floating
153
- }),
154
- contentProps: normalize.element({
155
- ...parts.content.attrs,
156
- id: dom.getContentId(state.context),
157
- tabIndex: -1,
158
- role: "dialog",
159
- hidden: !isOpen,
160
- "data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
161
- "aria-labelledby": rendered.title ? dom.getTitleId(state.context) : void 0,
162
- "aria-describedby": rendered.description ? dom.getDescriptionId(state.context) : void 0,
163
- "data-placement": currentPlacement
164
- }),
165
- titleProps: normalize.element({
166
- ...parts.title.attrs,
167
- id: dom.getTitleId(state.context)
168
- }),
169
- descriptionProps: normalize.element({
170
- ...parts.description.attrs,
171
- id: dom.getDescriptionId(state.context)
172
- }),
173
- closeTriggerProps: normalize.button({
174
- ...parts.closeTrigger.attrs,
175
- id: dom.getCloseTriggerId(state.context),
176
- type: "button",
177
- "aria-label": "close",
178
- onClick() {
179
- send("REQUEST_CLOSE");
180
- }
181
- })
182
- };
183
- }
184
-
185
- // src/popover.machine.ts
186
- var import_aria_hidden = require("@zag-js/aria-hidden");
187
- var import_core = require("@zag-js/core");
188
- var import_dismissable = require("@zag-js/dismissable");
189
- var import_dom_query3 = require("@zag-js/dom-query");
190
- var import_popper2 = require("@zag-js/popper");
191
- var import_remove_scroll = require("@zag-js/remove-scroll");
192
- var import_tabbable2 = require("@zag-js/tabbable");
193
- var import_utils2 = require("@zag-js/utils");
194
- var import_focus_trap = require("focus-trap");
195
- function machine(userContext) {
196
- const ctx = (0, import_utils2.compact)(userContext);
197
- return (0, import_core.createMachine)(
198
- {
199
- id: "popover",
200
- initial: ctx.open ? "open" : "closed",
201
- context: {
202
- closeOnInteractOutside: true,
203
- closeOnEsc: true,
204
- autoFocus: true,
205
- modal: false,
206
- positioning: {
207
- placement: "bottom",
208
- ...ctx.positioning
209
- },
210
- currentPlacement: void 0,
211
- ...ctx,
212
- renderedElements: {
213
- title: true,
214
- description: true
215
- }
216
- },
217
- computed: {
218
- currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
219
- },
220
- watch: {
221
- open: ["toggleVisibility"]
222
- },
223
- entry: ["checkRenderedElements"],
224
- states: {
225
- closed: {
226
- on: {
227
- TOGGLE: {
228
- target: "open",
229
- actions: ["invokeOnOpen"]
230
- },
231
- OPEN: {
232
- target: "open",
233
- actions: ["invokeOnOpen"]
234
- }
235
- }
236
- },
237
- open: {
238
- activities: [
239
- "trapFocus",
240
- "preventScroll",
241
- "hideContentBelow",
242
- "trackPositioning",
243
- "trackDismissableElement",
244
- "proxyTabFocus"
245
- ],
246
- entry: ["setInitialFocus"],
247
- on: {
248
- CLOSE: {
249
- target: "closed",
250
- actions: ["invokeOnClose"]
251
- },
252
- REQUEST_CLOSE: {
253
- target: "closed",
254
- actions: ["restoreFocusIfNeeded", "invokeOnClose"]
255
- },
256
- TOGGLE: {
257
- target: "closed",
258
- actions: ["invokeOnClose"]
259
- },
260
- SET_POSITIONING: {
261
- actions: "setPositioning"
262
- }
263
- }
264
- }
265
- }
266
- },
267
- {
268
- activities: {
269
- trackPositioning(ctx2) {
270
- ctx2.currentPlacement = ctx2.positioning.placement;
271
- const anchorEl = dom.getAnchorEl(ctx2) ?? dom.getTriggerEl(ctx2);
272
- const getPositionerEl = () => dom.getPositionerEl(ctx2);
273
- return (0, import_popper2.getPlacement)(anchorEl, getPositionerEl, {
274
- ...ctx2.positioning,
275
- defer: true,
276
- onComplete(data) {
277
- ctx2.currentPlacement = data.placement;
278
- },
279
- onCleanup() {
280
- ctx2.currentPlacement = void 0;
281
- }
282
- });
283
- },
284
- trackDismissableElement(ctx2, _evt, { send }) {
285
- const getContentEl = () => dom.getContentEl(ctx2);
286
- let restoreFocus = true;
287
- return (0, import_dismissable.trackDismissableElement)(getContentEl, {
288
- pointerBlocking: ctx2.modal,
289
- exclude: dom.getTriggerEl(ctx2),
290
- defer: true,
291
- onEscapeKeyDown(event) {
292
- ctx2.onEscapeKeyDown?.(event);
293
- if (ctx2.closeOnEsc)
294
- return;
295
- event.preventDefault();
296
- },
297
- onInteractOutside(event) {
298
- ctx2.onInteractOutside?.(event);
299
- if (event.defaultPrevented)
300
- return;
301
- restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
302
- if (!ctx2.closeOnInteractOutside) {
303
- event.preventDefault();
304
- }
305
- },
306
- onPointerDownOutside(event) {
307
- ctx2.onPointerDownOutside?.(event);
308
- },
309
- onFocusOutside(event) {
310
- ctx2.onFocusOutside?.(event);
311
- },
312
- onDismiss() {
313
- send({ type: "REQUEST_CLOSE", src: "interact-outside", restoreFocus });
314
- }
315
- });
316
- },
317
- proxyTabFocus(ctx2) {
318
- if (ctx2.modal || !ctx2.portalled)
319
- return;
320
- const getContentEl = () => dom.getContentEl(ctx2);
321
- return (0, import_tabbable2.proxyTabFocus)(getContentEl, {
322
- triggerElement: dom.getTriggerEl(ctx2),
323
- defer: true,
324
- onFocus(el) {
325
- el.focus({ preventScroll: true });
326
- }
327
- });
328
- },
329
- hideContentBelow(ctx2) {
330
- if (!ctx2.modal)
331
- return;
332
- const getElements = () => [dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)];
333
- return (0, import_aria_hidden.ariaHidden)(getElements, { defer: true });
334
- },
335
- preventScroll(ctx2) {
336
- if (!ctx2.modal)
337
- return;
338
- return (0, import_remove_scroll.preventBodyScroll)(dom.getDoc(ctx2));
339
- },
340
- trapFocus(ctx2) {
341
- if (!ctx2.modal)
342
- return;
343
- let trap;
344
- (0, import_dom_query3.nextTick)(() => {
345
- const el = dom.getContentEl(ctx2);
346
- if (!el)
347
- return;
348
- trap = (0, import_focus_trap.createFocusTrap)(el, {
349
- escapeDeactivates: false,
350
- allowOutsideClick: true,
351
- preventScroll: true,
352
- returnFocusOnDeactivate: true,
353
- document: dom.getDoc(ctx2),
354
- fallbackFocus: el,
355
- initialFocus: (0, import_utils2.runIfFn)(ctx2.initialFocusEl)
356
- });
357
- try {
358
- trap.activate();
359
- } catch {
360
- }
361
- });
362
- return () => trap?.deactivate();
363
- }
364
- },
365
- actions: {
366
- setPositioning(ctx2, evt) {
367
- const anchorEl = dom.getAnchorEl(ctx2) ?? dom.getTriggerEl(ctx2);
368
- const getPositionerEl = () => dom.getPositionerEl(ctx2);
369
- (0, import_popper2.getPlacement)(anchorEl, getPositionerEl, {
370
- ...ctx2.positioning,
371
- ...evt.options,
372
- defer: true,
373
- listeners: false
374
- });
375
- },
376
- checkRenderedElements(ctx2) {
377
- (0, import_dom_query3.raf)(() => {
378
- Object.assign(ctx2.renderedElements, {
379
- title: !!dom.getTitleEl(ctx2),
380
- description: !!dom.getDescriptionEl(ctx2)
381
- });
382
- });
383
- },
384
- setInitialFocus(ctx2) {
385
- (0, import_dom_query3.raf)(() => {
386
- dom.getInitialFocusEl(ctx2)?.focus({ preventScroll: true });
387
- });
388
- },
389
- restoreFocusIfNeeded(ctx2, evt) {
390
- if (!evt.restoreFocus)
391
- return;
392
- (0, import_dom_query3.raf)(() => {
393
- dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
394
- });
395
- },
396
- invokeOnOpen(ctx2) {
397
- ctx2.onOpen?.();
398
- },
399
- invokeOnClose(ctx2) {
400
- ctx2.onClose?.();
401
- },
402
- toggleVisibility(ctx2, _evt, { send }) {
403
- send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
404
- }
405
- }
406
- }
407
- );
408
- }
409
- // Annotate the CommonJS export names for ESM import in node:
410
- 0 && (module.exports = {
411
- anatomy,
412
- connect,
413
- machine
414
- });
11
+ exports.anatomy = popover_anatomy.anatomy;
12
+ exports.connect = popover_connect.connect;
13
+ exports.machine = popover_machine.machine;
package/dist/index.mjs CHANGED
@@ -1,15 +1,3 @@
1
- import {
2
- connect
3
- } from "./chunk-HRZXZNMW.mjs";
4
- import {
5
- anatomy
6
- } from "./chunk-KTOPDXGV.mjs";
7
- import {
8
- machine
9
- } from "./chunk-EDQUDEDS.mjs";
10
- import "./chunk-UA4OMIJI.mjs";
11
- export {
12
- anatomy,
13
- connect,
14
- machine
15
- };
1
+ export { anatomy } from './popover.anatomy.mjs';
2
+ export { connect } from './popover.connect.mjs';
3
+ export { machine } from './popover.machine.mjs';
@@ -1,6 +1,3 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
2
-
3
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"arrow" | "arrowTip" | "anchor" | "trigger" | "positioner" | "content" | "title" | "description" | "closeTrigger">;
4
- declare const parts: Record<"arrow" | "arrowTip" | "anchor" | "trigger" | "positioner" | "content" | "title" | "description" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
5
-
6
- export { anatomy, parts };
1
+ import { AnatomyInstance, AnatomyPart } from '@zag-js/anatomy';
2
+ export declare const anatomy: AnatomyInstance<"arrow" | "arrowTip" | "anchor" | "trigger" | "positioner" | "content" | "title" | "description" | "closeTrigger">;
3
+ export declare const parts: Record<"arrow" | "arrowTip" | "anchor" | "trigger" | "positioner" | "content" | "title" | "description" | "closeTrigger", AnatomyPart>;
@@ -1,31 +1,10 @@
1
- "use strict";
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
- // src/popover.anatomy.ts
21
- var popover_anatomy_exports = {};
22
- __export(popover_anatomy_exports, {
23
- anatomy: () => anatomy,
24
- parts: () => parts
25
- });
26
- module.exports = __toCommonJS(popover_anatomy_exports);
27
- var import_anatomy = require("@zag-js/anatomy");
28
- var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const anatomy$1 = require('@zag-js/anatomy');
6
+
7
+ const anatomy = anatomy$1.createAnatomy("popover").parts(
29
8
  "arrow",
30
9
  "arrowTip",
31
10
  "anchor",
@@ -36,9 +15,7 @@ var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
36
15
  "description",
37
16
  "closeTrigger"
38
17
  );
39
- var parts = anatomy.build();
40
- // Annotate the CommonJS export names for ESM import in node:
41
- 0 && (module.exports = {
42
- anatomy,
43
- parts
44
- });
18
+ const parts = anatomy.build();
19
+
20
+ exports.anatomy = anatomy;
21
+ exports.parts = parts;
@@ -1,8 +1,16 @@
1
- import {
2
- anatomy,
3
- parts
4
- } from "./chunk-KTOPDXGV.mjs";
5
- export {
6
- anatomy,
7
- parts
8
- };
1
+ import { createAnatomy } from '@zag-js/anatomy';
2
+
3
+ const anatomy = createAnatomy("popover").parts(
4
+ "arrow",
5
+ "arrowTip",
6
+ "anchor",
7
+ "trigger",
8
+ "positioner",
9
+ "content",
10
+ "title",
11
+ "description",
12
+ "closeTrigger"
13
+ );
14
+ const parts = anatomy.build();
15
+
16
+ export { anatomy, parts };
@@ -1,10 +1,7 @@
1
- import { PositioningOptions } from '@zag-js/popper';
2
- import { PropTypes, NormalizeProps } from '@zag-js/types';
3
- import { State, Send } from './popover.types.js';
4
- import '@zag-js/core';
5
- import '@zag-js/dismissable';
6
-
7
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
1
+ import type { PositioningOptions } from "@zag-js/popper";
2
+ import type { NormalizeProps, PropTypes } from "@zag-js/types";
3
+ import type { Send, State } from "./popover.types";
4
+ export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
8
5
  /**
9
6
  * Whether the popover is portalled
10
7
  */
@@ -35,5 +32,3 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
35
32
  descriptionProps: T["element"];
36
33
  closeTriggerProps: T["button"];
37
34
  };
38
-
39
- export { connect };