@zag-js/popover 0.1.9 → 0.1.10

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 CHANGED
@@ -43,6 +43,22 @@ __export(src_exports, {
43
43
  module.exports = __toCommonJS(src_exports);
44
44
 
45
45
  // ../../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
+ };
46
62
  var dataAttr = (guard) => {
47
63
  return guard ? "" : void 0;
48
64
  };
@@ -51,6 +67,9 @@ var runIfFn = (v, ...a) => {
51
67
  return res != null ? res : void 0;
52
68
  };
53
69
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
70
+ function isDocument(el) {
71
+ return el.nodeType === Node.DOCUMENT_NODE;
72
+ }
54
73
  function isWindow(value) {
55
74
  return (value == null ? void 0 : value.toString()) === "[object Window]";
56
75
  }
@@ -61,11 +80,25 @@ function getDocument(el) {
61
80
  var _a;
62
81
  if (isWindow(el))
63
82
  return el.document;
83
+ if (isDocument(el))
84
+ return el;
64
85
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
65
86
  }
66
- function getEventTarget(event) {
67
- var _a, _b;
68
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
87
+ function defineDomHelpers(helpers) {
88
+ const dom2 = {
89
+ 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
+ var _a;
96
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
97
+ },
98
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
99
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
100
+ };
101
+ return __spreadValues2(__spreadValues2({}, dom2), helpers);
69
102
  }
70
103
  function contains(parent, child) {
71
104
  if (!parent)
@@ -193,52 +226,40 @@ var runIfFn2 = (v, ...a) => {
193
226
  };
194
227
 
195
228
  // src/popover.dom.ts
196
- var dom = {
197
- getDoc: (ctx) => {
198
- var _a;
199
- return (_a = ctx.doc) != null ? _a : document;
200
- },
201
- getWin: (ctx) => {
202
- var _a;
203
- return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
204
- },
229
+ var dom = defineDomHelpers({
205
230
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
206
- getRootNode: (ctx) => {
207
- var _a;
208
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
209
- },
210
231
  getAnchorId: (ctx) => {
211
232
  var _a, _b;
212
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
233
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
213
234
  },
214
235
  getTriggerId: (ctx) => {
215
236
  var _a, _b;
216
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.uid}:trigger`;
237
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
217
238
  },
218
239
  getContentId: (ctx) => {
219
240
  var _a, _b;
220
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.uid}:content`;
241
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
221
242
  },
222
- getPositionerId: (ctx) => `popover:${ctx.uid}:popper`,
223
- getArrowId: (ctx) => `popover:${ctx.uid}:arrow`,
243
+ getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
244
+ getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
224
245
  getTitleId: (ctx) => {
225
246
  var _a, _b;
226
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.uid}:title`;
247
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
227
248
  },
228
249
  getDescriptionId: (ctx) => {
229
250
  var _a, _b;
230
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.uid}:desc`;
251
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
231
252
  },
232
253
  getCloseButtonId: (ctx) => {
233
254
  var _a, _b;
234
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
255
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
235
256
  },
236
- getAnchorEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getAnchorId(ctx)),
237
- getTriggerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx)),
238
- getContentEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getContentId(ctx)),
239
- getPositionerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPositionerId(ctx)),
240
- getTitleEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTitleId(ctx)),
241
- getDescriptionEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getDescriptionId(ctx)),
257
+ getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
258
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
259
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
260
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
261
+ getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
262
+ getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
242
263
  getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
243
264
  getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
244
265
  getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
@@ -253,7 +274,7 @@ var dom = {
253
274
  el = dom.getContentEl(ctx);
254
275
  return el;
255
276
  }
256
- };
277
+ });
257
278
 
258
279
  // src/popover.connect.ts
259
280
  function connect(state, send, normalize) {
@@ -342,335 +363,16 @@ function connect(state, send, normalize) {
342
363
  // src/popover.machine.ts
343
364
  var import_aria_hidden = require("@zag-js/aria-hidden");
344
365
  var import_core = require("@zag-js/core");
345
-
346
- // ../../utilities/interact-outside/dist/index.mjs
347
- var runIfFn3 = (v, ...a) => {
348
- const res = typeof v === "function" ? v(...a) : v;
349
- return res != null ? res : void 0;
350
- };
351
- var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
352
- var isDom = () => typeof window !== "undefined";
353
- function getPlatform() {
354
- var _a;
355
- const agent = navigator.userAgentData;
356
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
357
- }
358
- var pt = (v) => isDom() && v.test(getPlatform());
359
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
360
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
361
- function isWindow2(value) {
362
- return (value == null ? void 0 : value.toString()) === "[object Window]";
363
- }
364
- function getDocument2(el) {
365
- var _a;
366
- if (isWindow2(el))
367
- return el.document;
368
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
369
- }
370
- function getWindow(el) {
371
- var _a;
372
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
373
- }
374
- function getEventTarget2(event) {
375
- var _a, _b;
376
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
377
- }
378
- function contains2(parent, child) {
379
- if (!parent)
380
- return false;
381
- return parent === child || isHTMLElement2(parent) && isHTMLElement2(child) && parent.contains(child);
382
- }
383
- function isHTMLElement2(v) {
384
- return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
385
- }
386
- function isVisible2(el) {
387
- if (!isHTMLElement2(el))
388
- return false;
389
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
390
- }
391
- var isContextMenuEvent = (e) => {
392
- return e.button === 2 || isCtrlKey(e) && e.button === 0;
393
- };
394
- var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
395
- function fireCustomEvent(el, type, init) {
396
- if (!el)
397
- return;
398
- const win = getWindow(el);
399
- const event = new win.CustomEvent(type, init);
400
- return el.dispatchEvent(event);
401
- }
402
- var focusableSelector2 = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
403
- function isFocusable2(element) {
404
- if (!element)
405
- return false;
406
- return element.matches(focusableSelector2) && isVisible2(element);
407
- }
408
- var isRef2 = (v) => hasProp2(v, "current");
409
- function addDomEvent2(target, eventName, handler, options) {
410
- const node = isRef2(target) ? target.current : runIfFn3(target);
411
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
412
- return () => {
413
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
414
- };
415
- }
416
- var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
417
- var FOCUS_OUTSIDE_EVENT = "focus.outside";
418
- function trackInteractOutside(node, options) {
419
- const { exclude, onFocusOutside, onPointerDownOutside } = options;
420
- if (!node)
421
- return;
422
- const doc = getDocument2(node);
423
- const win = getWindow(node);
424
- function isEventOutside(event) {
425
- const target = getEventTarget2(event);
426
- if (!(target instanceof win.HTMLElement)) {
427
- return false;
428
- }
429
- if (!contains2(doc.documentElement, target)) {
430
- return false;
431
- }
432
- if (contains2(node, target)) {
433
- return false;
434
- }
435
- return !(exclude == null ? void 0 : exclude(target));
436
- }
437
- let clickHandler;
438
- function onPointerDown(event) {
439
- function handler() {
440
- if (!node || !isEventOutside(event))
441
- return;
442
- if (onPointerDownOutside) {
443
- node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
444
- }
445
- fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
446
- bubbles: false,
447
- cancelable: true,
448
- detail: {
449
- originalEvent: event,
450
- contextmenu: isContextMenuEvent(event),
451
- focusable: isFocusable2(getEventTarget2(event))
452
- }
453
- });
454
- }
455
- if (event.pointerType === "touch") {
456
- doc.removeEventListener("click", handler);
457
- clickHandler = handler;
458
- doc.addEventListener("click", handler, { once: true });
459
- } else {
460
- handler();
461
- }
462
- }
463
- const cleanups = /* @__PURE__ */ new Set();
464
- const timer = setTimeout(() => {
465
- cleanups.add(addDomEvent2(doc, "pointerdown", onPointerDown, true));
466
- }, 0);
467
- function onFocusin(event) {
468
- if (!node || !isEventOutside(event))
469
- return;
470
- if (onFocusOutside) {
471
- node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
472
- }
473
- fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
474
- bubbles: false,
475
- cancelable: true,
476
- detail: {
477
- originalEvent: event,
478
- contextmenu: false,
479
- focusable: isFocusable2(getEventTarget2(event))
480
- }
481
- });
482
- }
483
- cleanups.add(addDomEvent2(doc, "focusin", onFocusin, true));
484
- return () => {
485
- clearTimeout(timer);
486
- if (clickHandler)
487
- doc.removeEventListener("click", clickHandler);
488
- cleanups.forEach((fn) => fn());
489
- };
490
- }
491
-
492
- // ../../utilities/dismissable/src/escape-keydown.ts
493
- function trackEscapeKeydown(fn) {
494
- const handleKeyDown = (event) => {
495
- if (event.key === "Escape")
496
- fn == null ? void 0 : fn(event);
497
- };
498
- return addDomEvent(document, "keydown", handleKeyDown);
499
- }
500
-
501
- // ../../utilities/dismissable/src/layer-stack.ts
502
- var layerStack = {
503
- layers: [],
504
- branches: [],
505
- count() {
506
- return this.layers.length;
507
- },
508
- pointerBlockingLayers() {
509
- return this.layers.filter((layer) => layer.pointerBlocking);
510
- },
511
- topMostPointerBlockingLayer() {
512
- return [...this.pointerBlockingLayers()].slice(-1)[0];
513
- },
514
- hasPointerBlockingLayer() {
515
- return this.pointerBlockingLayers().length > 0;
516
- },
517
- isBelowPointerBlockingLayer(node) {
518
- var _a;
519
- const index = this.indexOf(node);
520
- const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
521
- return index < highestBlockingIndex;
522
- },
523
- isTopMost(node) {
524
- const layer = this.layers[this.count() - 1];
525
- return (layer == null ? void 0 : layer.node) === node;
526
- },
527
- getNestedLayers(node) {
528
- return Array.from(this.layers).slice(this.indexOf(node) + 1);
529
- },
530
- isInNestedLayer(node, target) {
531
- return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
532
- },
533
- isInBranch(target) {
534
- return Array.from(this.branches).some((branch) => contains(branch, target));
535
- },
536
- add(layer) {
537
- this.layers.push(layer);
538
- },
539
- addBranch(node) {
540
- this.branches.push(node);
541
- },
542
- remove(node) {
543
- const index = this.indexOf(node);
544
- if (index < 0)
545
- return;
546
- if (index < this.count() - 1) {
547
- const _layers = this.getNestedLayers(node);
548
- _layers.forEach((layer) => layer.dismiss());
549
- }
550
- this.layers.splice(index, 1);
551
- },
552
- removeBranch(node) {
553
- const index = this.branches.indexOf(node);
554
- if (index >= 0)
555
- this.branches.splice(index, 1);
556
- },
557
- indexOf(node) {
558
- return this.layers.findIndex((layer) => layer.node === node);
559
- },
560
- dismiss(node) {
561
- var _a;
562
- (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
563
- },
564
- clear() {
565
- this.remove(this.layers[0].node);
566
- }
567
- };
568
-
569
- // ../../utilities/dismissable/src/pointer-event-outside.ts
570
- var originalBodyPointerEvents;
571
- function assignPointerEventToLayers() {
572
- layerStack.layers.forEach(({ node }) => {
573
- node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
574
- });
575
- }
576
- function clearPointerEvent(node) {
577
- node.style.pointerEvents = "";
578
- }
579
- var DATA_ATTR = "data-inert";
580
- function disablePointerEventsOutside(node) {
581
- const doc = getDocument(node);
582
- if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
583
- originalBodyPointerEvents = document.body.style.pointerEvents;
584
- doc.body.style.pointerEvents = "none";
585
- doc.body.setAttribute(DATA_ATTR, "");
586
- }
587
- return () => {
588
- if (layerStack.hasPointerBlockingLayer())
589
- return;
590
- doc.body.style.pointerEvents = originalBodyPointerEvents;
591
- doc.body.removeAttribute(DATA_ATTR);
592
- if (doc.body.style.length === 0)
593
- doc.body.removeAttribute("style");
594
- };
595
- }
596
-
597
- // ../../utilities/dismissable/src/dismissable-layer.ts
598
- function trackDismissableElement(node, options) {
599
- if (!node)
600
- return;
601
- const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
602
- const layer = { dismiss: onDismiss, node, pointerBlocking };
603
- layerStack.add(layer);
604
- assignPointerEventToLayers();
605
- function onPointerDownOutside(event) {
606
- var _a, _b;
607
- const target = getEventTarget(event.detail.originalEvent);
608
- if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
609
- return;
610
- (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
611
- (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
612
- if (event.defaultPrevented)
613
- return;
614
- if (debug) {
615
- console.log("onPointerDownOutside:", event.detail.originalEvent);
616
- }
617
- onDismiss == null ? void 0 : onDismiss();
618
- }
619
- function onFocusOutside(event) {
620
- var _a, _b;
621
- const target = getEventTarget(event.detail.originalEvent);
622
- if (layerStack.isInBranch(target))
623
- return;
624
- (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
625
- (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
626
- if (event.defaultPrevented)
627
- return;
628
- if (debug) {
629
- console.log("onFocusOutside:", event.detail.originalEvent);
630
- }
631
- onDismiss == null ? void 0 : onDismiss();
632
- }
633
- function onEscapeKeyDown(event) {
634
- var _a;
635
- if (!layerStack.isTopMost(node))
636
- return;
637
- (_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
638
- if (!event.defaultPrevented && onDismiss) {
639
- event.preventDefault();
640
- onDismiss();
641
- }
642
- }
643
- function exclude(target) {
644
- if (!node)
645
- return false;
646
- const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
647
- const _containers = Array.isArray(containers) ? containers : [containers];
648
- return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
649
- }
650
- const cleanups = [
651
- pointerBlocking ? disablePointerEventsOutside(node) : void 0,
652
- trackEscapeKeydown(onEscapeKeyDown),
653
- trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
654
- ];
655
- return () => {
656
- layerStack.remove(node);
657
- assignPointerEventToLayers();
658
- clearPointerEvent(node);
659
- cleanups.forEach((fn) => fn == null ? void 0 : fn());
660
- };
661
- }
662
-
663
- // src/popover.machine.ts
366
+ var import_dismissable = require("@zag-js/dismissable");
664
367
  var import_popper2 = require("@zag-js/popper");
665
368
  var import_remove_scroll = require("@zag-js/remove-scroll");
666
369
  var import_focus_trap = require("focus-trap");
667
370
  var { and, or, not } = import_core.guards;
668
- function machine(ctx = {}) {
371
+ function machine(ctx) {
669
372
  return (0, import_core.createMachine)({
670
373
  id: "popover",
671
374
  initial: "unknown",
672
375
  context: __spreadProps(__spreadValues({
673
- uid: "",
674
376
  closeOnInteractOutside: true,
675
377
  closeOnEsc: true,
676
378
  autoFocus: true,
@@ -695,12 +397,12 @@ function machine(ctx = {}) {
695
397
  on: {
696
398
  SETUP: {
697
399
  target: ctx.defaultOpen ? "open" : "closed",
698
- actions: ["setupDocument", "checkRenderedElements"]
400
+ actions: "checkRenderedElements"
699
401
  }
700
402
  }
701
403
  },
702
404
  closed: {
703
- entry: ["clearPointerDown", "invokeOnClose"],
405
+ entry: "invokeOnClose",
704
406
  on: {
705
407
  TOGGLE: "open",
706
408
  OPEN: "open"
@@ -762,7 +464,7 @@ function machine(ctx = {}) {
762
464
  }));
763
465
  },
764
466
  trackInteractionOutside(ctx2, _evt, { send }) {
765
- return trackDismissableElement(dom.getContentEl(ctx2), {
467
+ return (0, import_dismissable.trackDismissableElement)(dom.getContentEl(ctx2), {
766
468
  pointerBlocking: ctx2.modal,
767
469
  exclude: dom.getTriggerEl(ctx2),
768
470
  onEscapeKeyDown(event) {
@@ -869,16 +571,6 @@ function machine(ctx = {}) {
869
571
  });
870
572
  });
871
573
  },
872
- setupDocument(ctx2, evt) {
873
- if (evt.doc)
874
- ctx2.doc = (0, import_core.ref)(evt.doc);
875
- if (evt.root)
876
- ctx2.rootNode = (0, import_core.ref)(evt.root);
877
- ctx2.uid = evt.id;
878
- },
879
- clearPointerDown(ctx2) {
880
- ctx2.pointerdownNode = null;
881
- },
882
574
  setInitialFocus(ctx2) {
883
575
  raf(() => {
884
576
  var _a;
package/dist/index.mjs CHANGED
@@ -19,6 +19,22 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
21
  // ../../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
+ };
22
38
  var dataAttr = (guard) => {
23
39
  return guard ? "" : void 0;
24
40
  };
@@ -27,6 +43,9 @@ var runIfFn = (v, ...a) => {
27
43
  return res != null ? res : void 0;
28
44
  };
29
45
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
46
+ function isDocument(el) {
47
+ return el.nodeType === Node.DOCUMENT_NODE;
48
+ }
30
49
  function isWindow(value) {
31
50
  return (value == null ? void 0 : value.toString()) === "[object Window]";
32
51
  }
@@ -37,11 +56,25 @@ function getDocument(el) {
37
56
  var _a;
38
57
  if (isWindow(el))
39
58
  return el.document;
59
+ if (isDocument(el))
60
+ return el;
40
61
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
41
62
  }
42
- function getEventTarget(event) {
43
- var _a, _b;
44
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
63
+ function defineDomHelpers(helpers) {
64
+ const dom2 = {
65
+ 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
+ var _a;
72
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
73
+ },
74
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
75
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
76
+ };
77
+ return __spreadValues2(__spreadValues2({}, dom2), helpers);
45
78
  }
46
79
  function contains(parent, child) {
47
80
  if (!parent)
@@ -169,52 +202,40 @@ var runIfFn2 = (v, ...a) => {
169
202
  };
170
203
 
171
204
  // src/popover.dom.ts
172
- var dom = {
173
- getDoc: (ctx) => {
174
- var _a;
175
- return (_a = ctx.doc) != null ? _a : document;
176
- },
177
- getWin: (ctx) => {
178
- var _a;
179
- return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
180
- },
205
+ var dom = defineDomHelpers({
181
206
  getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
182
- getRootNode: (ctx) => {
183
- var _a;
184
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
185
- },
186
207
  getAnchorId: (ctx) => {
187
208
  var _a, _b;
188
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
209
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
189
210
  },
190
211
  getTriggerId: (ctx) => {
191
212
  var _a, _b;
192
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.uid}:trigger`;
213
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
193
214
  },
194
215
  getContentId: (ctx) => {
195
216
  var _a, _b;
196
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.uid}:content`;
217
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
197
218
  },
198
- getPositionerId: (ctx) => `popover:${ctx.uid}:popper`,
199
- getArrowId: (ctx) => `popover:${ctx.uid}:arrow`,
219
+ getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
220
+ getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
200
221
  getTitleId: (ctx) => {
201
222
  var _a, _b;
202
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.uid}:title`;
223
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
203
224
  },
204
225
  getDescriptionId: (ctx) => {
205
226
  var _a, _b;
206
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.uid}:desc`;
227
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
207
228
  },
208
229
  getCloseButtonId: (ctx) => {
209
230
  var _a, _b;
210
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
231
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.id}:close-button`;
211
232
  },
212
- getAnchorEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getAnchorId(ctx)),
213
- getTriggerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx)),
214
- getContentEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getContentId(ctx)),
215
- getPositionerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPositionerId(ctx)),
216
- getTitleEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTitleId(ctx)),
217
- getDescriptionEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getDescriptionId(ctx)),
233
+ getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
234
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
235
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
236
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
237
+ getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
238
+ getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
218
239
  getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
219
240
  getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
220
241
  getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
@@ -229,7 +250,7 @@ var dom = {
229
250
  el = dom.getContentEl(ctx);
230
251
  return el;
231
252
  }
232
- };
253
+ });
233
254
 
234
255
  // src/popover.connect.ts
235
256
  function connect(state, send, normalize) {
@@ -317,336 +338,17 @@ function connect(state, send, normalize) {
317
338
 
318
339
  // src/popover.machine.ts
319
340
  import { ariaHidden } from "@zag-js/aria-hidden";
320
- import { createMachine, guards, ref } from "@zag-js/core";
321
-
322
- // ../../utilities/interact-outside/dist/index.mjs
323
- var runIfFn3 = (v, ...a) => {
324
- const res = typeof v === "function" ? v(...a) : v;
325
- return res != null ? res : void 0;
326
- };
327
- var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
328
- var isDom = () => typeof window !== "undefined";
329
- function getPlatform() {
330
- var _a;
331
- const agent = navigator.userAgentData;
332
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
333
- }
334
- var pt = (v) => isDom() && v.test(getPlatform());
335
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
336
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
337
- function isWindow2(value) {
338
- return (value == null ? void 0 : value.toString()) === "[object Window]";
339
- }
340
- function getDocument2(el) {
341
- var _a;
342
- if (isWindow2(el))
343
- return el.document;
344
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
345
- }
346
- function getWindow(el) {
347
- var _a;
348
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
349
- }
350
- function getEventTarget2(event) {
351
- var _a, _b;
352
- return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
353
- }
354
- function contains2(parent, child) {
355
- if (!parent)
356
- return false;
357
- return parent === child || isHTMLElement2(parent) && isHTMLElement2(child) && parent.contains(child);
358
- }
359
- function isHTMLElement2(v) {
360
- return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
361
- }
362
- function isVisible2(el) {
363
- if (!isHTMLElement2(el))
364
- return false;
365
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
366
- }
367
- var isContextMenuEvent = (e) => {
368
- return e.button === 2 || isCtrlKey(e) && e.button === 0;
369
- };
370
- var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
371
- function fireCustomEvent(el, type, init) {
372
- if (!el)
373
- return;
374
- const win = getWindow(el);
375
- const event = new win.CustomEvent(type, init);
376
- return el.dispatchEvent(event);
377
- }
378
- var focusableSelector2 = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
379
- function isFocusable2(element) {
380
- if (!element)
381
- return false;
382
- return element.matches(focusableSelector2) && isVisible2(element);
383
- }
384
- var isRef2 = (v) => hasProp2(v, "current");
385
- function addDomEvent2(target, eventName, handler, options) {
386
- const node = isRef2(target) ? target.current : runIfFn3(target);
387
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
388
- return () => {
389
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
390
- };
391
- }
392
- var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
393
- var FOCUS_OUTSIDE_EVENT = "focus.outside";
394
- function trackInteractOutside(node, options) {
395
- const { exclude, onFocusOutside, onPointerDownOutside } = options;
396
- if (!node)
397
- return;
398
- const doc = getDocument2(node);
399
- const win = getWindow(node);
400
- function isEventOutside(event) {
401
- const target = getEventTarget2(event);
402
- if (!(target instanceof win.HTMLElement)) {
403
- return false;
404
- }
405
- if (!contains2(doc.documentElement, target)) {
406
- return false;
407
- }
408
- if (contains2(node, target)) {
409
- return false;
410
- }
411
- return !(exclude == null ? void 0 : exclude(target));
412
- }
413
- let clickHandler;
414
- function onPointerDown(event) {
415
- function handler() {
416
- if (!node || !isEventOutside(event))
417
- return;
418
- if (onPointerDownOutside) {
419
- node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
420
- }
421
- fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
422
- bubbles: false,
423
- cancelable: true,
424
- detail: {
425
- originalEvent: event,
426
- contextmenu: isContextMenuEvent(event),
427
- focusable: isFocusable2(getEventTarget2(event))
428
- }
429
- });
430
- }
431
- if (event.pointerType === "touch") {
432
- doc.removeEventListener("click", handler);
433
- clickHandler = handler;
434
- doc.addEventListener("click", handler, { once: true });
435
- } else {
436
- handler();
437
- }
438
- }
439
- const cleanups = /* @__PURE__ */ new Set();
440
- const timer = setTimeout(() => {
441
- cleanups.add(addDomEvent2(doc, "pointerdown", onPointerDown, true));
442
- }, 0);
443
- function onFocusin(event) {
444
- if (!node || !isEventOutside(event))
445
- return;
446
- if (onFocusOutside) {
447
- node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
448
- }
449
- fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
450
- bubbles: false,
451
- cancelable: true,
452
- detail: {
453
- originalEvent: event,
454
- contextmenu: false,
455
- focusable: isFocusable2(getEventTarget2(event))
456
- }
457
- });
458
- }
459
- cleanups.add(addDomEvent2(doc, "focusin", onFocusin, true));
460
- return () => {
461
- clearTimeout(timer);
462
- if (clickHandler)
463
- doc.removeEventListener("click", clickHandler);
464
- cleanups.forEach((fn) => fn());
465
- };
466
- }
467
-
468
- // ../../utilities/dismissable/src/escape-keydown.ts
469
- function trackEscapeKeydown(fn) {
470
- const handleKeyDown = (event) => {
471
- if (event.key === "Escape")
472
- fn == null ? void 0 : fn(event);
473
- };
474
- return addDomEvent(document, "keydown", handleKeyDown);
475
- }
476
-
477
- // ../../utilities/dismissable/src/layer-stack.ts
478
- var layerStack = {
479
- layers: [],
480
- branches: [],
481
- count() {
482
- return this.layers.length;
483
- },
484
- pointerBlockingLayers() {
485
- return this.layers.filter((layer) => layer.pointerBlocking);
486
- },
487
- topMostPointerBlockingLayer() {
488
- return [...this.pointerBlockingLayers()].slice(-1)[0];
489
- },
490
- hasPointerBlockingLayer() {
491
- return this.pointerBlockingLayers().length > 0;
492
- },
493
- isBelowPointerBlockingLayer(node) {
494
- var _a;
495
- const index = this.indexOf(node);
496
- const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
497
- return index < highestBlockingIndex;
498
- },
499
- isTopMost(node) {
500
- const layer = this.layers[this.count() - 1];
501
- return (layer == null ? void 0 : layer.node) === node;
502
- },
503
- getNestedLayers(node) {
504
- return Array.from(this.layers).slice(this.indexOf(node) + 1);
505
- },
506
- isInNestedLayer(node, target) {
507
- return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
508
- },
509
- isInBranch(target) {
510
- return Array.from(this.branches).some((branch) => contains(branch, target));
511
- },
512
- add(layer) {
513
- this.layers.push(layer);
514
- },
515
- addBranch(node) {
516
- this.branches.push(node);
517
- },
518
- remove(node) {
519
- const index = this.indexOf(node);
520
- if (index < 0)
521
- return;
522
- if (index < this.count() - 1) {
523
- const _layers = this.getNestedLayers(node);
524
- _layers.forEach((layer) => layer.dismiss());
525
- }
526
- this.layers.splice(index, 1);
527
- },
528
- removeBranch(node) {
529
- const index = this.branches.indexOf(node);
530
- if (index >= 0)
531
- this.branches.splice(index, 1);
532
- },
533
- indexOf(node) {
534
- return this.layers.findIndex((layer) => layer.node === node);
535
- },
536
- dismiss(node) {
537
- var _a;
538
- (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
539
- },
540
- clear() {
541
- this.remove(this.layers[0].node);
542
- }
543
- };
544
-
545
- // ../../utilities/dismissable/src/pointer-event-outside.ts
546
- var originalBodyPointerEvents;
547
- function assignPointerEventToLayers() {
548
- layerStack.layers.forEach(({ node }) => {
549
- node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
550
- });
551
- }
552
- function clearPointerEvent(node) {
553
- node.style.pointerEvents = "";
554
- }
555
- var DATA_ATTR = "data-inert";
556
- function disablePointerEventsOutside(node) {
557
- const doc = getDocument(node);
558
- if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
559
- originalBodyPointerEvents = document.body.style.pointerEvents;
560
- doc.body.style.pointerEvents = "none";
561
- doc.body.setAttribute(DATA_ATTR, "");
562
- }
563
- return () => {
564
- if (layerStack.hasPointerBlockingLayer())
565
- return;
566
- doc.body.style.pointerEvents = originalBodyPointerEvents;
567
- doc.body.removeAttribute(DATA_ATTR);
568
- if (doc.body.style.length === 0)
569
- doc.body.removeAttribute("style");
570
- };
571
- }
572
-
573
- // ../../utilities/dismissable/src/dismissable-layer.ts
574
- function trackDismissableElement(node, options) {
575
- if (!node)
576
- return;
577
- const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
578
- const layer = { dismiss: onDismiss, node, pointerBlocking };
579
- layerStack.add(layer);
580
- assignPointerEventToLayers();
581
- function onPointerDownOutside(event) {
582
- var _a, _b;
583
- const target = getEventTarget(event.detail.originalEvent);
584
- if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
585
- return;
586
- (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
587
- (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
588
- if (event.defaultPrevented)
589
- return;
590
- if (debug) {
591
- console.log("onPointerDownOutside:", event.detail.originalEvent);
592
- }
593
- onDismiss == null ? void 0 : onDismiss();
594
- }
595
- function onFocusOutside(event) {
596
- var _a, _b;
597
- const target = getEventTarget(event.detail.originalEvent);
598
- if (layerStack.isInBranch(target))
599
- return;
600
- (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
601
- (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
602
- if (event.defaultPrevented)
603
- return;
604
- if (debug) {
605
- console.log("onFocusOutside:", event.detail.originalEvent);
606
- }
607
- onDismiss == null ? void 0 : onDismiss();
608
- }
609
- function onEscapeKeyDown(event) {
610
- var _a;
611
- if (!layerStack.isTopMost(node))
612
- return;
613
- (_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
614
- if (!event.defaultPrevented && onDismiss) {
615
- event.preventDefault();
616
- onDismiss();
617
- }
618
- }
619
- function exclude(target) {
620
- if (!node)
621
- return false;
622
- const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
623
- const _containers = Array.isArray(containers) ? containers : [containers];
624
- return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
625
- }
626
- const cleanups = [
627
- pointerBlocking ? disablePointerEventsOutside(node) : void 0,
628
- trackEscapeKeydown(onEscapeKeyDown),
629
- trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
630
- ];
631
- return () => {
632
- layerStack.remove(node);
633
- assignPointerEventToLayers();
634
- clearPointerEvent(node);
635
- cleanups.forEach((fn) => fn == null ? void 0 : fn());
636
- };
637
- }
638
-
639
- // src/popover.machine.ts
341
+ import { createMachine, guards } from "@zag-js/core";
342
+ import { trackDismissableElement } from "@zag-js/dismissable";
640
343
  import { getPlacement } from "@zag-js/popper";
641
344
  import { preventBodyScroll } from "@zag-js/remove-scroll";
642
345
  import { createFocusTrap } from "focus-trap";
643
346
  var { and, or, not } = guards;
644
- function machine(ctx = {}) {
347
+ function machine(ctx) {
645
348
  return createMachine({
646
349
  id: "popover",
647
350
  initial: "unknown",
648
351
  context: __spreadProps(__spreadValues({
649
- uid: "",
650
352
  closeOnInteractOutside: true,
651
353
  closeOnEsc: true,
652
354
  autoFocus: true,
@@ -671,12 +373,12 @@ function machine(ctx = {}) {
671
373
  on: {
672
374
  SETUP: {
673
375
  target: ctx.defaultOpen ? "open" : "closed",
674
- actions: ["setupDocument", "checkRenderedElements"]
376
+ actions: "checkRenderedElements"
675
377
  }
676
378
  }
677
379
  },
678
380
  closed: {
679
- entry: ["clearPointerDown", "invokeOnClose"],
381
+ entry: "invokeOnClose",
680
382
  on: {
681
383
  TOGGLE: "open",
682
384
  OPEN: "open"
@@ -845,16 +547,6 @@ function machine(ctx = {}) {
845
547
  });
846
548
  });
847
549
  },
848
- setupDocument(ctx2, evt) {
849
- if (evt.doc)
850
- ctx2.doc = ref(evt.doc);
851
- if (evt.root)
852
- ctx2.rootNode = ref(evt.root);
853
- ctx2.uid = evt.id;
854
- },
855
- clearPointerDown(ctx2) {
856
- ctx2.pointerdownNode = null;
857
- },
858
550
  setInitialFocus(ctx2) {
859
551
  raf(() => {
860
552
  var _a;
@@ -1,9 +1,22 @@
1
1
  import type { MachineContext as Ctx } from "./popover.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getWin: (ctx: Ctx) => Window & typeof globalThis;
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
+ } & {
5
19
  getActiveEl: (ctx: Ctx) => Element;
6
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
7
20
  getAnchorId: (ctx: Ctx) => string;
8
21
  getTriggerId: (ctx: Ctx) => string;
9
22
  getContentId: (ctx: Ctx) => string;
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./popover.types";
2
- export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
2
+ export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,7 +1,7 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
- import type { DismissableElementHandlers } from "@zag-js/dimissable";
2
+ import type { DismissableElementHandlers } from "@zag-js/dismissable";
3
3
  import type { PositioningOptions, Placement } from "@zag-js/popper";
4
- import type { Context, MaybeElement } from "@zag-js/types";
4
+ import type { CommonProperties, Context, MaybeElement, RequiredBy } from "@zag-js/types";
5
5
  declare type ElementIds = Partial<{
6
6
  anchor: string;
7
7
  trigger: string;
@@ -10,7 +10,7 @@ declare type ElementIds = Partial<{
10
10
  description: string;
11
11
  closeBtn: string;
12
12
  }>;
13
- declare type PublicContext = DismissableElementHandlers & {
13
+ declare type PublicContext = DismissableElementHandlers & CommonProperties & {
14
14
  /**
15
15
  * The ids of the elements in the popover. Useful for composition.
16
16
  */
@@ -59,7 +59,7 @@ declare type PublicContext = DismissableElementHandlers & {
59
59
  */
60
60
  defaultOpen?: boolean;
61
61
  };
62
- export declare type UserDefinedContext = Partial<PublicContext>;
62
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
63
63
  declare type ComputedContext = Readonly<{
64
64
  /**
65
65
  * @computed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,14 +30,17 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@zag-js/aria-hidden": "0.1.0",
33
- "@zag-js/core": "0.1.7",
34
- "@zag-js/dom-utils": "0.1.6",
35
- "@zag-js/popper": "0.1.7",
36
- "@zag-js/remove-scroll": "0.1.1",
37
- "@zag-js/types": "0.2.1",
38
- "@zag-js/utils": "0.1.2",
33
+ "@zag-js/core": "0.1.8",
34
+ "@zag-js/dismissable": "0.1.2",
35
+ "@zag-js/popper": "0.1.8",
36
+ "@zag-js/remove-scroll": "0.1.2",
37
+ "@zag-js/types": "0.2.2",
39
38
  "focus-trap": "6.9.4"
40
39
  },
40
+ "devDependencies": {
41
+ "@zag-js/dom-utils": "0.1.7",
42
+ "@zag-js/utils": "0.1.2"
43
+ },
41
44
  "scripts": {
42
45
  "build:fast": "zag build",
43
46
  "start": "zag build --watch",