@zag-js/popover 0.2.15 → 0.6.0

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.
@@ -17,7 +17,7 @@ function machine(userContext) {
17
17
  return createMachine(
18
18
  {
19
19
  id: "popover",
20
- initial: ctx.defaultOpen ? "open" : "closed",
20
+ initial: ctx.open ? "open" : "closed",
21
21
  context: {
22
22
  closeOnInteractOutside: true,
23
23
  closeOnEsc: true,
@@ -38,6 +38,9 @@ function machine(userContext) {
38
38
  computed: {
39
39
  currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
40
40
  },
41
+ watch: {
42
+ open: ["toggleVisibility"]
43
+ },
41
44
  entry: ["checkRenderedElements"],
42
45
  states: {
43
46
  closed: {
@@ -192,10 +195,13 @@ function machine(userContext) {
192
195
  raf(() => dom.getTriggerEl(ctx2)?.focus());
193
196
  },
194
197
  invokeOnOpen(ctx2) {
195
- ctx2.onOpenChange?.(true);
198
+ ctx2.onOpen?.();
196
199
  },
197
200
  invokeOnClose(ctx2) {
198
- ctx2.onOpenChange?.(false);
201
+ ctx2.onClose?.();
202
+ },
203
+ toggleVisibility(ctx2, _evt, { send }) {
204
+ send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
199
205
  }
200
206
  }
201
207
  }
package/dist/index.js CHANGED
@@ -197,7 +197,7 @@ function machine(userContext) {
197
197
  return (0, import_core.createMachine)(
198
198
  {
199
199
  id: "popover",
200
- initial: ctx.defaultOpen ? "open" : "closed",
200
+ initial: ctx.open ? "open" : "closed",
201
201
  context: {
202
202
  closeOnInteractOutside: true,
203
203
  closeOnEsc: true,
@@ -218,6 +218,9 @@ function machine(userContext) {
218
218
  computed: {
219
219
  currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
220
220
  },
221
+ watch: {
222
+ open: ["toggleVisibility"]
223
+ },
221
224
  entry: ["checkRenderedElements"],
222
225
  states: {
223
226
  closed: {
@@ -372,10 +375,13 @@ function machine(userContext) {
372
375
  (0, import_dom_query3.raf)(() => dom.getTriggerEl(ctx2)?.focus());
373
376
  },
374
377
  invokeOnOpen(ctx2) {
375
- ctx2.onOpenChange?.(true);
378
+ ctx2.onOpen?.();
376
379
  },
377
380
  invokeOnClose(ctx2) {
378
- ctx2.onOpenChange?.(false);
381
+ ctx2.onClose?.();
382
+ },
383
+ toggleVisibility(ctx2, _evt, { send }) {
384
+ send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
379
385
  }
380
386
  }
381
387
  }
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-KTOPDXGV.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-NPQGVKMX.mjs";
9
+ } from "./chunk-D27LEJFX.mjs";
10
10
  import "./chunk-4IGGT6KB.mjs";
11
11
  export {
12
12
  anatomy,
@@ -75,7 +75,7 @@ function machine(userContext) {
75
75
  return (0, import_core.createMachine)(
76
76
  {
77
77
  id: "popover",
78
- initial: ctx.defaultOpen ? "open" : "closed",
78
+ initial: ctx.open ? "open" : "closed",
79
79
  context: {
80
80
  closeOnInteractOutside: true,
81
81
  closeOnEsc: true,
@@ -96,6 +96,9 @@ function machine(userContext) {
96
96
  computed: {
97
97
  currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
98
98
  },
99
+ watch: {
100
+ open: ["toggleVisibility"]
101
+ },
99
102
  entry: ["checkRenderedElements"],
100
103
  states: {
101
104
  closed: {
@@ -250,10 +253,13 @@ function machine(userContext) {
250
253
  (0, import_dom_query2.raf)(() => dom.getTriggerEl(ctx2)?.focus());
251
254
  },
252
255
  invokeOnOpen(ctx2) {
253
- ctx2.onOpenChange?.(true);
256
+ ctx2.onOpen?.();
254
257
  },
255
258
  invokeOnClose(ctx2) {
256
- ctx2.onOpenChange?.(false);
259
+ ctx2.onClose?.();
260
+ },
261
+ toggleVisibility(ctx2, _evt, { send }) {
262
+ send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
257
263
  }
258
264
  }
259
265
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-NPQGVKMX.mjs";
3
+ } from "./chunk-D27LEJFX.mjs";
4
4
  import "./chunk-4IGGT6KB.mjs";
5
5
  export {
6
6
  machine
@@ -48,17 +48,21 @@ type PublicContext = DismissableElementHandlers & CommonProperties & {
48
48
  */
49
49
  closeOnEsc?: boolean;
50
50
  /**
51
- * Function invoked when the popover is opened.
51
+ * Function invoked when the popover is closed
52
52
  */
53
- onOpenChange?: (open: boolean) => void;
53
+ onClose?: VoidFunction;
54
+ /**
55
+ * Function invoked when the popover is opened
56
+ */
57
+ onOpen?: VoidFunction;
54
58
  /**
55
59
  * The user provided options used to position the popover content
56
60
  */
57
61
  positioning: PositioningOptions;
58
62
  /**
59
- * Whether to open the popover on page load
63
+ * Whether the popover is open
60
64
  */
61
- defaultOpen?: boolean;
65
+ open?: boolean;
62
66
  };
63
67
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
64
68
  type ComputedContext = Readonly<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "0.2.15",
3
+ "version": "0.6.0",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,14 +29,14 @@
29
29
  "focus-trap": "7.4.0",
30
30
  "@zag-js/anatomy": "0.1.4",
31
31
  "@zag-js/aria-hidden": "0.2.2",
32
- "@zag-js/core": "0.2.12",
32
+ "@zag-js/core": "0.5.0",
33
33
  "@zag-js/dom-query": "0.1.4",
34
34
  "@zag-js/utils": "0.3.4",
35
- "@zag-js/dismissable": "0.2.6",
35
+ "@zag-js/dismissable": "0.6.0",
36
+ "@zag-js/tabbable": "0.1.1",
36
37
  "@zag-js/popper": "0.2.7",
37
38
  "@zag-js/remove-scroll": "0.2.4",
38
- "@zag-js/tabbable": "0.1.1",
39
- "@zag-js/types": "0.3.4"
39
+ "@zag-js/types": "0.5.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "clean-package": "2.2.0"