@zag-js/tooltip 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.
@@ -1,242 +0,0 @@
1
- import {
2
- dom
3
- } from "./chunk-BML2QVAG.mjs";
4
- import {
5
- store
6
- } from "./chunk-GQYNO326.mjs";
7
-
8
- // src/tooltip.machine.ts
9
- import { createMachine, subscribe } from "@zag-js/core";
10
- import { addDomEvent } from "@zag-js/dom-event";
11
- import { getScrollParents, isHTMLElement, isSafari } from "@zag-js/dom-query";
12
- import { getPlacement } from "@zag-js/popper";
13
- import { compact } from "@zag-js/utils";
14
- function machine(userContext) {
15
- const ctx = compact(userContext);
16
- return createMachine(
17
- {
18
- id: "tooltip",
19
- initial: "closed",
20
- context: {
21
- openDelay: 1e3,
22
- closeDelay: 500,
23
- closeOnPointerDown: true,
24
- closeOnEsc: true,
25
- interactive: true,
26
- currentPlacement: void 0,
27
- ...ctx,
28
- positioning: {
29
- placement: "bottom",
30
- ...ctx.positioning
31
- }
32
- },
33
- computed: {
34
- hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
35
- },
36
- watch: {
37
- disabled: ["closeIfDisabled"],
38
- open: ["toggleVisibility"]
39
- },
40
- on: {
41
- OPEN: "open",
42
- CLOSE: "closed"
43
- },
44
- states: {
45
- closed: {
46
- tags: ["closed"],
47
- entry: ["clearGlobalId", "invokeOnClose"],
48
- on: {
49
- FOCUS: "open",
50
- POINTER_ENTER: [
51
- {
52
- guard: "noVisibleTooltip",
53
- target: "opening"
54
- },
55
- { target: "open" }
56
- ]
57
- }
58
- },
59
- opening: {
60
- tags: ["closed"],
61
- activities: ["trackScroll", "trackPointerlockChange"],
62
- after: {
63
- OPEN_DELAY: "open"
64
- },
65
- on: {
66
- POINTER_LEAVE: "closed",
67
- BLUR: "closed",
68
- SCROLL: "closed",
69
- POINTER_LOCK_CHANGE: "closed",
70
- POINTER_DOWN: {
71
- guard: "closeOnPointerDown",
72
- target: "closed"
73
- }
74
- }
75
- },
76
- open: {
77
- tags: ["open"],
78
- activities: [
79
- "trackEscapeKey",
80
- "trackDisabledTriggerOnSafari",
81
- "trackScroll",
82
- "trackPointerlockChange",
83
- "trackPositioning"
84
- ],
85
- entry: ["setGlobalId", "invokeOnOpen"],
86
- on: {
87
- POINTER_LEAVE: [
88
- {
89
- guard: "isVisible",
90
- target: "closing"
91
- },
92
- { target: "closed" }
93
- ],
94
- BLUR: "closed",
95
- ESCAPE: "closed",
96
- SCROLL: "closed",
97
- POINTER_LOCK_CHANGE: "closed",
98
- TOOLTIP_POINTER_LEAVE: {
99
- guard: "isInteractive",
100
- target: "closing"
101
- },
102
- POINTER_DOWN: {
103
- guard: "closeOnPointerDown",
104
- target: "closed"
105
- },
106
- CLICK: "closed",
107
- SET_POSITIONING: {
108
- actions: "setPositioning"
109
- }
110
- }
111
- },
112
- closing: {
113
- tags: ["open"],
114
- activities: ["trackStore", "trackPositioning"],
115
- after: {
116
- CLOSE_DELAY: "closed"
117
- },
118
- on: {
119
- FORCE_CLOSE: "closed",
120
- POINTER_ENTER: "open",
121
- TOOLTIP_POINTER_ENTER: {
122
- guard: "isInteractive",
123
- target: "open"
124
- }
125
- }
126
- }
127
- }
128
- },
129
- {
130
- activities: {
131
- trackPositioning(ctx2) {
132
- ctx2.currentPlacement = ctx2.positioning.placement;
133
- const getPositionerEl = () => dom.getPositionerEl(ctx2);
134
- return getPlacement(dom.getTriggerEl(ctx2), getPositionerEl, {
135
- ...ctx2.positioning,
136
- defer: true,
137
- onComplete(data) {
138
- ctx2.currentPlacement = data.placement;
139
- },
140
- onCleanup() {
141
- ctx2.currentPlacement = void 0;
142
- }
143
- });
144
- },
145
- trackPointerlockChange(ctx2, _evt, { send }) {
146
- const onChange = () => send("POINTER_LOCK_CHANGE");
147
- return addDomEvent(dom.getDoc(ctx2), "pointerlockchange", onChange, false);
148
- },
149
- trackScroll(ctx2, _evt, { send }) {
150
- const trigger = dom.getTriggerEl(ctx2);
151
- if (!trigger)
152
- return;
153
- const cleanups = getScrollParents(trigger).map((el) => {
154
- const opts = { passive: true, capture: true };
155
- return addDomEvent(el, "scroll", () => send("SCROLL"), opts);
156
- });
157
- return () => {
158
- cleanups.forEach((fn) => fn?.());
159
- };
160
- },
161
- trackStore(ctx2, _evt, { send }) {
162
- return subscribe(store, () => {
163
- if (store.id !== ctx2.id) {
164
- send("FORCE_CLOSE");
165
- }
166
- });
167
- },
168
- trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
169
- if (!isSafari())
170
- return;
171
- const doc = dom.getDoc(ctx2);
172
- return addDomEvent(doc, "pointermove", (event) => {
173
- const selector = "[data-part=trigger][data-expanded]";
174
- if (isHTMLElement(event.target) && event.target.closest(selector))
175
- return;
176
- send("POINTER_LEAVE");
177
- });
178
- },
179
- trackEscapeKey(ctx2, _evt, { send }) {
180
- if (!ctx2.closeOnEsc)
181
- return;
182
- const doc = dom.getDoc(ctx2);
183
- return addDomEvent(doc, "keydown", (event) => {
184
- if (event.key === "Escape") {
185
- send("ESCAPE");
186
- }
187
- });
188
- }
189
- },
190
- actions: {
191
- setGlobalId(ctx2) {
192
- store.setId(ctx2.id);
193
- },
194
- clearGlobalId(ctx2) {
195
- if (ctx2.id === store.id) {
196
- store.setId(null);
197
- }
198
- },
199
- invokeOnOpen(ctx2, evt) {
200
- const omit = ["TOOLTIP_POINTER_ENTER", "POINTER_ENTER"];
201
- if (!omit.includes(evt.type)) {
202
- ctx2.onOpen?.();
203
- }
204
- },
205
- invokeOnClose(ctx2) {
206
- ctx2.onClose?.();
207
- },
208
- closeIfDisabled(ctx2, _evt, { send }) {
209
- if (ctx2.disabled) {
210
- send("CLOSE");
211
- }
212
- },
213
- setPositioning(ctx2, evt) {
214
- const getPositionerEl = () => dom.getPositionerEl(ctx2);
215
- getPlacement(dom.getTriggerEl(ctx2), getPositionerEl, {
216
- ...ctx2.positioning,
217
- ...evt.options,
218
- defer: true,
219
- listeners: false
220
- });
221
- },
222
- toggleVisibility(ctx2, _evt, { send }) {
223
- send({ type: ctx2.open ? "OPEN" : "CLOSE", src: "controlled" });
224
- }
225
- },
226
- guards: {
227
- closeOnPointerDown: (ctx2) => ctx2.closeOnPointerDown,
228
- noVisibleTooltip: () => store.id === null,
229
- isVisible: (ctx2) => ctx2.id === store.id,
230
- isInteractive: (ctx2) => ctx2.interactive
231
- },
232
- delays: {
233
- OPEN_DELAY: (ctx2) => ctx2.openDelay,
234
- CLOSE_DELAY: (ctx2) => ctx2.closeDelay
235
- }
236
- }
237
- );
238
- }
239
-
240
- export {
241
- machine
242
- };
@@ -1,9 +0,0 @@
1
- // src/tooltip.anatomy.ts
2
- import { createAnatomy } from "@zag-js/anatomy";
3
- var anatomy = createAnatomy("tooltip").parts("trigger", "arrow", "arrowTip", "positioner", "content", "label");
4
- var parts = anatomy.build();
5
-
6
- export {
7
- anatomy,
8
- parts
9
- };
@@ -1,18 +0,0 @@
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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/tooltip.types.ts
17
- var tooltip_types_exports = {};
18
- module.exports = __toCommonJS(tooltip_types_exports);
File without changes