@zag-js/tooltip 0.2.13 → 0.5.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.
@@ -20,7 +20,6 @@ function connect(state, send, normalize) {
20
20
  const contentId = dom.getContentId(state.context);
21
21
  const isDisabled = state.context.disabled;
22
22
  const popperStyles = getPlacementStyles({
23
- measured: !!state.context.isPlacementComplete,
24
23
  placement: state.context.currentPlacement
25
24
  });
26
25
  return {
@@ -49,6 +48,12 @@ function connect(state, send, normalize) {
49
48
  exit: store.id === null
50
49
  };
51
50
  },
51
+ /**
52
+ * Function to reposition the popover
53
+ */
54
+ setPositioning(options) {
55
+ send({ type: "SET_POSITIONING", options });
56
+ },
52
57
  triggerProps: normalize.button({
53
58
  ...parts.trigger.attrs,
54
59
  id: triggerId,
@@ -34,7 +34,8 @@ function machine(userContext) {
34
34
  hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
35
35
  },
36
36
  watch: {
37
- disabled: ["closeIfDisabled"]
37
+ disabled: ["closeIfDisabled"],
38
+ open: ["toggleVisibility"]
38
39
  },
39
40
  on: {
40
41
  OPEN: "open",
@@ -79,7 +80,7 @@ function machine(userContext) {
79
80
  "trackDisabledTriggerOnSafari",
80
81
  "trackScroll",
81
82
  "trackPointerlockChange",
82
- "computePlacement"
83
+ "trackPositioning"
83
84
  ],
84
85
  entry: ["setGlobalId", "invokeOnOpen"],
85
86
  on: {
@@ -102,12 +103,15 @@ function machine(userContext) {
102
103
  guard: "closeOnPointerDown",
103
104
  target: "closed"
104
105
  },
105
- CLICK: "closed"
106
+ CLICK: "closed",
107
+ SET_POSITIONING: {
108
+ actions: "setPositioning"
109
+ }
106
110
  }
107
111
  },
108
112
  closing: {
109
113
  tags: ["open"],
110
- activities: ["trackStore", "computePlacement"],
114
+ activities: ["trackStore", "trackPositioning"],
111
115
  after: {
112
116
  CLOSE_DELAY: "closed"
113
117
  },
@@ -124,7 +128,7 @@ function machine(userContext) {
124
128
  },
125
129
  {
126
130
  activities: {
127
- computePlacement(ctx2) {
131
+ trackPositioning(ctx2) {
128
132
  ctx2.currentPlacement = ctx2.positioning.placement;
129
133
  let cleanup;
130
134
  raf(() => {
@@ -132,15 +136,13 @@ function machine(userContext) {
132
136
  ...ctx2.positioning,
133
137
  onComplete(data) {
134
138
  ctx2.currentPlacement = data.placement;
135
- ctx2.isPlacementComplete = true;
136
139
  },
137
140
  onCleanup() {
138
141
  ctx2.currentPlacement = void 0;
139
- ctx2.isPlacementComplete = false;
140
142
  }
141
143
  });
142
144
  });
143
- return cleanup;
145
+ return () => cleanup?.();
144
146
  },
145
147
  trackPointerlockChange(ctx2, _evt, { send }) {
146
148
  const onChange = () => send("POINTER_LOCK_CHANGE");
@@ -209,6 +211,18 @@ function machine(userContext) {
209
211
  if (ctx2.disabled) {
210
212
  send("CLOSE");
211
213
  }
214
+ },
215
+ setPositioning(ctx2, evt) {
216
+ raf(() => {
217
+ getPlacement(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
218
+ ...ctx2.positioning,
219
+ ...evt.options,
220
+ listeners: false
221
+ });
222
+ });
223
+ },
224
+ toggleVisibility(ctx2, _evt, { send }) {
225
+ send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
212
226
  }
213
227
  },
214
228
  guards: {
package/dist/index.d.ts CHANGED
@@ -3,6 +3,6 @@ export { connect } from './tooltip.connect.js';
3
3
  export { machine } from './tooltip.machine.js';
4
4
  export { UserDefinedContext as Context } from './tooltip.types.js';
5
5
  import '@zag-js/anatomy';
6
+ import '@zag-js/popper';
6
7
  import '@zag-js/types';
7
8
  import '@zag-js/core';
8
- import '@zag-js/popper';
package/dist/index.js CHANGED
@@ -70,7 +70,6 @@ function connect(state, send, normalize) {
70
70
  const contentId = dom.getContentId(state.context);
71
71
  const isDisabled = state.context.disabled;
72
72
  const popperStyles = (0, import_popper.getPlacementStyles)({
73
- measured: !!state.context.isPlacementComplete,
74
73
  placement: state.context.currentPlacement
75
74
  });
76
75
  return {
@@ -99,6 +98,12 @@ function connect(state, send, normalize) {
99
98
  exit: store.id === null
100
99
  };
101
100
  },
101
+ /**
102
+ * Function to reposition the popover
103
+ */
104
+ setPositioning(options) {
105
+ send({ type: "SET_POSITIONING", options });
106
+ },
102
107
  triggerProps: normalize.button({
103
108
  ...parts.trigger.attrs,
104
109
  id: triggerId,
@@ -207,7 +212,8 @@ function machine(userContext) {
207
212
  hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
208
213
  },
209
214
  watch: {
210
- disabled: ["closeIfDisabled"]
215
+ disabled: ["closeIfDisabled"],
216
+ open: ["toggleVisibility"]
211
217
  },
212
218
  on: {
213
219
  OPEN: "open",
@@ -252,7 +258,7 @@ function machine(userContext) {
252
258
  "trackDisabledTriggerOnSafari",
253
259
  "trackScroll",
254
260
  "trackPointerlockChange",
255
- "computePlacement"
261
+ "trackPositioning"
256
262
  ],
257
263
  entry: ["setGlobalId", "invokeOnOpen"],
258
264
  on: {
@@ -275,12 +281,15 @@ function machine(userContext) {
275
281
  guard: "closeOnPointerDown",
276
282
  target: "closed"
277
283
  },
278
- CLICK: "closed"
284
+ CLICK: "closed",
285
+ SET_POSITIONING: {
286
+ actions: "setPositioning"
287
+ }
279
288
  }
280
289
  },
281
290
  closing: {
282
291
  tags: ["open"],
283
- activities: ["trackStore", "computePlacement"],
292
+ activities: ["trackStore", "trackPositioning"],
284
293
  after: {
285
294
  CLOSE_DELAY: "closed"
286
295
  },
@@ -297,7 +306,7 @@ function machine(userContext) {
297
306
  },
298
307
  {
299
308
  activities: {
300
- computePlacement(ctx2) {
309
+ trackPositioning(ctx2) {
301
310
  ctx2.currentPlacement = ctx2.positioning.placement;
302
311
  let cleanup;
303
312
  (0, import_dom_query3.raf)(() => {
@@ -305,15 +314,13 @@ function machine(userContext) {
305
314
  ...ctx2.positioning,
306
315
  onComplete(data) {
307
316
  ctx2.currentPlacement = data.placement;
308
- ctx2.isPlacementComplete = true;
309
317
  },
310
318
  onCleanup() {
311
319
  ctx2.currentPlacement = void 0;
312
- ctx2.isPlacementComplete = false;
313
320
  }
314
321
  });
315
322
  });
316
- return cleanup;
323
+ return () => cleanup?.();
317
324
  },
318
325
  trackPointerlockChange(ctx2, _evt, { send }) {
319
326
  const onChange = () => send("POINTER_LOCK_CHANGE");
@@ -382,6 +389,18 @@ function machine(userContext) {
382
389
  if (ctx2.disabled) {
383
390
  send("CLOSE");
384
391
  }
392
+ },
393
+ setPositioning(ctx2, evt) {
394
+ (0, import_dom_query3.raf)(() => {
395
+ (0, import_popper2.getPlacement)(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
396
+ ...ctx2.positioning,
397
+ ...evt.options,
398
+ listeners: false
399
+ });
400
+ });
401
+ },
402
+ toggleVisibility(ctx2, _evt, { send }) {
403
+ send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
385
404
  }
386
405
  },
387
406
  guards: {
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-W3OSVXCZ.mjs";
3
+ } from "./chunk-CTBIJ67E.mjs";
4
4
  import {
5
5
  anatomy
6
6
  } from "./chunk-RRQRIZBA.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-463EFHFN.mjs";
9
+ } from "./chunk-YRDFBCFW.mjs";
10
10
  import "./chunk-3LXHM7BW.mjs";
11
11
  import "./chunk-GQYNO326.mjs";
12
12
  export {
@@ -1,7 +1,7 @@
1
+ import { PositioningOptions } from '@zag-js/popper';
1
2
  import { PropTypes, NormalizeProps } from '@zag-js/types';
2
3
  import { State, Send } from './tooltip.types.js';
3
4
  import '@zag-js/core';
4
- import '@zag-js/popper';
5
5
 
6
6
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
7
7
  /**
@@ -23,6 +23,10 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
23
23
  enter: boolean;
24
24
  exit: boolean;
25
25
  };
26
+ /**
27
+ * Function to reposition the popover
28
+ */
29
+ setPositioning(options: Partial<PositioningOptions>): void;
26
30
  triggerProps: T["button"];
27
31
  arrowProps: T["element"];
28
32
  arrowTipProps: T["element"];
@@ -66,7 +66,6 @@ function connect(state, send, normalize) {
66
66
  const contentId = dom.getContentId(state.context);
67
67
  const isDisabled = state.context.disabled;
68
68
  const popperStyles = (0, import_popper.getPlacementStyles)({
69
- measured: !!state.context.isPlacementComplete,
70
69
  placement: state.context.currentPlacement
71
70
  });
72
71
  return {
@@ -95,6 +94,12 @@ function connect(state, send, normalize) {
95
94
  exit: store.id === null
96
95
  };
97
96
  },
97
+ /**
98
+ * Function to reposition the popover
99
+ */
100
+ setPositioning(options) {
101
+ send({ type: "SET_POSITIONING", options });
102
+ },
98
103
  triggerProps: normalize.button({
99
104
  ...parts.trigger.attrs,
100
105
  id: triggerId,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-W3OSVXCZ.mjs";
3
+ } from "./chunk-CTBIJ67E.mjs";
4
4
  import "./chunk-RRQRIZBA.mjs";
5
5
  import "./chunk-3LXHM7BW.mjs";
6
6
  import "./chunk-GQYNO326.mjs";
@@ -78,7 +78,8 @@ function machine(userContext) {
78
78
  hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
79
79
  },
80
80
  watch: {
81
- disabled: ["closeIfDisabled"]
81
+ disabled: ["closeIfDisabled"],
82
+ open: ["toggleVisibility"]
82
83
  },
83
84
  on: {
84
85
  OPEN: "open",
@@ -123,7 +124,7 @@ function machine(userContext) {
123
124
  "trackDisabledTriggerOnSafari",
124
125
  "trackScroll",
125
126
  "trackPointerlockChange",
126
- "computePlacement"
127
+ "trackPositioning"
127
128
  ],
128
129
  entry: ["setGlobalId", "invokeOnOpen"],
129
130
  on: {
@@ -146,12 +147,15 @@ function machine(userContext) {
146
147
  guard: "closeOnPointerDown",
147
148
  target: "closed"
148
149
  },
149
- CLICK: "closed"
150
+ CLICK: "closed",
151
+ SET_POSITIONING: {
152
+ actions: "setPositioning"
153
+ }
150
154
  }
151
155
  },
152
156
  closing: {
153
157
  tags: ["open"],
154
- activities: ["trackStore", "computePlacement"],
158
+ activities: ["trackStore", "trackPositioning"],
155
159
  after: {
156
160
  CLOSE_DELAY: "closed"
157
161
  },
@@ -168,7 +172,7 @@ function machine(userContext) {
168
172
  },
169
173
  {
170
174
  activities: {
171
- computePlacement(ctx2) {
175
+ trackPositioning(ctx2) {
172
176
  ctx2.currentPlacement = ctx2.positioning.placement;
173
177
  let cleanup;
174
178
  (0, import_dom_query2.raf)(() => {
@@ -176,15 +180,13 @@ function machine(userContext) {
176
180
  ...ctx2.positioning,
177
181
  onComplete(data) {
178
182
  ctx2.currentPlacement = data.placement;
179
- ctx2.isPlacementComplete = true;
180
183
  },
181
184
  onCleanup() {
182
185
  ctx2.currentPlacement = void 0;
183
- ctx2.isPlacementComplete = false;
184
186
  }
185
187
  });
186
188
  });
187
- return cleanup;
189
+ return () => cleanup?.();
188
190
  },
189
191
  trackPointerlockChange(ctx2, _evt, { send }) {
190
192
  const onChange = () => send("POINTER_LOCK_CHANGE");
@@ -253,6 +255,18 @@ function machine(userContext) {
253
255
  if (ctx2.disabled) {
254
256
  send("CLOSE");
255
257
  }
258
+ },
259
+ setPositioning(ctx2, evt) {
260
+ (0, import_dom_query2.raf)(() => {
261
+ (0, import_popper.getPlacement)(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
262
+ ...ctx2.positioning,
263
+ ...evt.options,
264
+ listeners: false
265
+ });
266
+ });
267
+ },
268
+ toggleVisibility(ctx2, _evt, { send }) {
269
+ send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
256
270
  }
257
271
  },
258
272
  guards: {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-463EFHFN.mjs";
3
+ } from "./chunk-YRDFBCFW.mjs";
4
4
  import "./chunk-3LXHM7BW.mjs";
5
5
  import "./chunk-GQYNO326.mjs";
6
6
  export {
@@ -57,6 +57,10 @@ type PublicContext = CommonProperties & {
57
57
  * Whether the tooltip is disabled
58
58
  */
59
59
  disabled?: boolean;
60
+ /**
61
+ * Whether the tooltip is open
62
+ */
63
+ open?: boolean;
60
64
  };
61
65
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
62
66
  type ComputedContext = Readonly<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tooltip",
3
- "version": "0.2.13",
3
+ "version": "0.5.0",
4
4
  "description": "Core logic for the tooltip widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,13 +27,13 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@zag-js/anatomy": "0.1.4",
30
- "@zag-js/core": "0.2.10",
31
- "@zag-js/popper": "0.2.5",
30
+ "@zag-js/core": "0.5.0",
31
+ "@zag-js/popper": "0.2.7",
32
32
  "@zag-js/dom-query": "0.1.4",
33
- "@zag-js/dom-event": "0.0.1",
34
- "@zag-js/utils": "0.3.3",
33
+ "@zag-js/dom-event": "0.5.0",
34
+ "@zag-js/utils": "0.3.4",
35
35
  "@zag-js/visually-hidden": "0.0.1",
36
- "@zag-js/types": "0.3.4"
36
+ "@zag-js/types": "0.5.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "clean-package": "2.2.0"