@zag-js/tooltip 0.1.9 → 0.1.12
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/LICENSE +21 -0
- package/dist/index.d.ts +93 -3
- package/dist/index.js +250 -272
- package/dist/index.mjs +246 -276
- package/package.json +15 -11
- package/dist/tooltip.connect.d.ts +0 -18
- package/dist/tooltip.dom.d.ts +0 -18
- package/dist/tooltip.machine.d.ts +0 -2
- package/dist/tooltip.store.d.ts +0 -8
- package/dist/tooltip.types.d.ts +0 -82
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// ../../utilities/dom/dist/index.mjs
|
|
22
2
|
var dataAttr = (guard) => {
|
|
23
3
|
return guard ? "" : void 0;
|
|
@@ -28,13 +8,12 @@ function getCache() {
|
|
|
28
8
|
return g.__styleCache;
|
|
29
9
|
}
|
|
30
10
|
function getComputedStyle(el) {
|
|
31
|
-
var _a;
|
|
32
11
|
if (!el)
|
|
33
12
|
return {};
|
|
34
13
|
const cache = getCache();
|
|
35
14
|
let style = cache.get(el);
|
|
36
15
|
if (!style) {
|
|
37
|
-
const win = (
|
|
16
|
+
const win = (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
38
17
|
style = win.getComputedStyle(el);
|
|
39
18
|
cache.set(el, style);
|
|
40
19
|
}
|
|
@@ -42,37 +21,38 @@ function getComputedStyle(el) {
|
|
|
42
21
|
}
|
|
43
22
|
var runIfFn = (v, ...a) => {
|
|
44
23
|
const res = typeof v === "function" ? v(...a) : v;
|
|
45
|
-
return res
|
|
24
|
+
return res ?? void 0;
|
|
46
25
|
};
|
|
47
26
|
var isArray = (v) => Array.isArray(v);
|
|
48
27
|
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
49
28
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
50
29
|
var isDom = () => typeof window !== "undefined";
|
|
51
30
|
function getPlatform() {
|
|
52
|
-
var _a;
|
|
53
31
|
const agent = navigator.userAgentData;
|
|
54
|
-
return (
|
|
32
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
55
33
|
}
|
|
56
34
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
57
35
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
58
36
|
var isSafari = () => isApple() && vn(/apple/i);
|
|
59
37
|
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
38
|
+
function isDocument(el) {
|
|
39
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
40
|
+
}
|
|
60
41
|
function isWindow(value) {
|
|
61
42
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
62
43
|
}
|
|
63
44
|
function getDocument(el) {
|
|
64
|
-
var _a;
|
|
65
45
|
if (isWindow(el))
|
|
66
46
|
return el.document;
|
|
67
|
-
|
|
47
|
+
if (isDocument(el))
|
|
48
|
+
return el;
|
|
49
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
68
50
|
}
|
|
69
51
|
function getWindow(el) {
|
|
70
|
-
|
|
71
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
52
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
72
53
|
}
|
|
73
54
|
function getNodeName(node) {
|
|
74
|
-
|
|
75
|
-
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : "";
|
|
55
|
+
return isWindow(node) ? "" : (node == null ? void 0 : node.localName) ?? "";
|
|
76
56
|
}
|
|
77
57
|
function getParent(el) {
|
|
78
58
|
const doc = getDocument(el);
|
|
@@ -80,6 +60,22 @@ function getParent(el) {
|
|
|
80
60
|
return el;
|
|
81
61
|
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
82
62
|
}
|
|
63
|
+
function defineDomHelpers(helpers) {
|
|
64
|
+
const dom2 = {
|
|
65
|
+
getRootNode: (ctx) => {
|
|
66
|
+
var _a;
|
|
67
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
68
|
+
},
|
|
69
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
70
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
71
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
72
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
...dom2,
|
|
76
|
+
...helpers
|
|
77
|
+
};
|
|
78
|
+
}
|
|
83
79
|
function isHTMLElement(v) {
|
|
84
80
|
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
85
81
|
}
|
|
@@ -106,8 +102,7 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
106
102
|
};
|
|
107
103
|
}
|
|
108
104
|
function addPointerEvent(target, event, listener, options) {
|
|
109
|
-
|
|
110
|
-
const type = (_a = getEventName(event)) != null ? _a : event;
|
|
105
|
+
const type = getEventName(event) ?? event;
|
|
111
106
|
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
112
107
|
}
|
|
113
108
|
function wrapHandler(fn, filter = false) {
|
|
@@ -118,8 +113,7 @@ function wrapHandler(fn, filter = false) {
|
|
|
118
113
|
}
|
|
119
114
|
function filterPrimaryPointer(fn) {
|
|
120
115
|
return (event) => {
|
|
121
|
-
|
|
122
|
-
const win = (_a = event.view) != null ? _a : window;
|
|
116
|
+
const win = event.view ?? window;
|
|
123
117
|
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
124
118
|
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
125
119
|
if (isPrimary)
|
|
@@ -151,18 +145,6 @@ function getEventName(evt) {
|
|
|
151
145
|
return mouseEventNames[evt];
|
|
152
146
|
return evt;
|
|
153
147
|
}
|
|
154
|
-
var visuallyHiddenStyle = {
|
|
155
|
-
border: "0",
|
|
156
|
-
clip: "rect(0 0 0 0)",
|
|
157
|
-
height: "1px",
|
|
158
|
-
margin: "-1px",
|
|
159
|
-
overflow: "hidden",
|
|
160
|
-
padding: "0",
|
|
161
|
-
position: "absolute",
|
|
162
|
-
width: "1px",
|
|
163
|
-
whiteSpace: "nowrap",
|
|
164
|
-
wordWrap: "normal"
|
|
165
|
-
};
|
|
166
148
|
function raf(fn) {
|
|
167
149
|
const id = globalThis.requestAnimationFrame(fn);
|
|
168
150
|
return function cleanup() {
|
|
@@ -195,39 +177,39 @@ function getScrollParents(el, list = []) {
|
|
|
195
177
|
return parents;
|
|
196
178
|
return parents.concat(getScrollParents(getParent(target)));
|
|
197
179
|
}
|
|
180
|
+
var visuallyHiddenStyle = {
|
|
181
|
+
border: "0",
|
|
182
|
+
clip: "rect(0 0 0 0)",
|
|
183
|
+
height: "1px",
|
|
184
|
+
margin: "-1px",
|
|
185
|
+
overflow: "hidden",
|
|
186
|
+
padding: "0",
|
|
187
|
+
position: "absolute",
|
|
188
|
+
width: "1px",
|
|
189
|
+
whiteSpace: "nowrap",
|
|
190
|
+
wordWrap: "normal"
|
|
191
|
+
};
|
|
198
192
|
|
|
199
193
|
// src/tooltip.connect.ts
|
|
200
194
|
import { getPlacementStyles } from "@zag-js/popper";
|
|
201
195
|
|
|
202
196
|
// src/tooltip.dom.ts
|
|
203
|
-
var dom = {
|
|
204
|
-
getDoc: (ctx) => {
|
|
205
|
-
var _a;
|
|
206
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
207
|
-
},
|
|
208
|
-
getWin: (ctx) => {
|
|
209
|
-
var _a, _b;
|
|
210
|
-
return (_b = (_a = ctx.doc) == null ? void 0 : _a.defaultView) != null ? _b : window;
|
|
211
|
-
},
|
|
212
|
-
getRootNode: (ctx) => {
|
|
213
|
-
var _a;
|
|
214
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
215
|
-
},
|
|
197
|
+
var dom = defineDomHelpers({
|
|
216
198
|
getTriggerId: (ctx) => {
|
|
217
|
-
var _a
|
|
218
|
-
return (
|
|
199
|
+
var _a;
|
|
200
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `tooltip:${ctx.id}:trigger`;
|
|
219
201
|
},
|
|
220
202
|
getContentId: (ctx) => {
|
|
221
|
-
var _a
|
|
222
|
-
return (
|
|
203
|
+
var _a;
|
|
204
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `tooltip:${ctx.id}:content`;
|
|
223
205
|
},
|
|
224
206
|
getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
|
|
225
207
|
getPositionerId: (ctx) => `tooltip:${ctx.id}:popper`,
|
|
226
208
|
portalId: "tooltip-portal",
|
|
227
|
-
getTriggerEl: (ctx) => dom.
|
|
228
|
-
getContentEl: (ctx) => dom.
|
|
229
|
-
getPositionerEl: (ctx) => dom.
|
|
230
|
-
getArrowEl: (ctx) => dom.
|
|
209
|
+
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
210
|
+
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
211
|
+
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
212
|
+
getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
|
|
231
213
|
getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx)),
|
|
232
214
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.portalId),
|
|
233
215
|
createPortalEl: (ctx) => {
|
|
@@ -235,7 +217,7 @@ var dom = {
|
|
|
235
217
|
portal.id = dom.portalId;
|
|
236
218
|
return portal;
|
|
237
219
|
}
|
|
238
|
-
};
|
|
220
|
+
});
|
|
239
221
|
|
|
240
222
|
// src/tooltip.store.ts
|
|
241
223
|
import { proxy } from "@zag-js/core";
|
|
@@ -353,234 +335,222 @@ function connect(state, send, normalize) {
|
|
|
353
335
|
}
|
|
354
336
|
|
|
355
337
|
// src/tooltip.machine.ts
|
|
356
|
-
import { createMachine,
|
|
338
|
+
import { createMachine, subscribe } from "@zag-js/core";
|
|
357
339
|
import { getPlacement } from "@zag-js/popper";
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
interactive: true,
|
|
375
|
-
currentPlacement: void 0
|
|
376
|
-
}, ctx), {
|
|
377
|
-
positioning: __spreadValues({
|
|
378
|
-
placement: "bottom"
|
|
379
|
-
}, ctx.positioning)
|
|
380
|
-
}),
|
|
381
|
-
computed: {
|
|
382
|
-
hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
|
|
383
|
-
},
|
|
384
|
-
on: {
|
|
385
|
-
OPEN: "open",
|
|
386
|
-
CLOSE: "closed"
|
|
387
|
-
},
|
|
388
|
-
states: {
|
|
389
|
-
unknown: {
|
|
390
|
-
on: {
|
|
391
|
-
SETUP: {
|
|
392
|
-
target: "closed",
|
|
393
|
-
actions: "setupDocument"
|
|
394
|
-
}
|
|
340
|
+
function machine(ctx) {
|
|
341
|
+
return createMachine(
|
|
342
|
+
{
|
|
343
|
+
id: "tooltip",
|
|
344
|
+
initial: "unknown",
|
|
345
|
+
context: {
|
|
346
|
+
openDelay: 1e3,
|
|
347
|
+
closeDelay: 500,
|
|
348
|
+
closeOnPointerDown: true,
|
|
349
|
+
closeOnEsc: true,
|
|
350
|
+
interactive: true,
|
|
351
|
+
currentPlacement: void 0,
|
|
352
|
+
...ctx,
|
|
353
|
+
positioning: {
|
|
354
|
+
placement: "bottom",
|
|
355
|
+
...ctx.positioning
|
|
395
356
|
}
|
|
396
357
|
},
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
entry: ["clearGlobalId", "invokeOnClose"],
|
|
400
|
-
on: {
|
|
401
|
-
FOCUS: "open",
|
|
402
|
-
POINTER_ENTER: [
|
|
403
|
-
{
|
|
404
|
-
guard: "noVisibleTooltip",
|
|
405
|
-
target: "opening"
|
|
406
|
-
},
|
|
407
|
-
{ target: "open" }
|
|
408
|
-
]
|
|
409
|
-
}
|
|
358
|
+
computed: {
|
|
359
|
+
hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
|
|
410
360
|
},
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
361
|
+
on: {
|
|
362
|
+
OPEN: "open",
|
|
363
|
+
CLOSE: "closed"
|
|
364
|
+
},
|
|
365
|
+
states: {
|
|
366
|
+
unknown: {
|
|
367
|
+
on: {
|
|
368
|
+
SETUP: "closed"
|
|
369
|
+
}
|
|
416
370
|
},
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
371
|
+
closed: {
|
|
372
|
+
tags: ["closed"],
|
|
373
|
+
entry: ["clearGlobalId", "invokeOnClose"],
|
|
374
|
+
on: {
|
|
375
|
+
FOCUS: "open",
|
|
376
|
+
POINTER_ENTER: [
|
|
377
|
+
{
|
|
378
|
+
guard: "noVisibleTooltip",
|
|
379
|
+
target: "opening"
|
|
380
|
+
},
|
|
381
|
+
{ target: "open" }
|
|
382
|
+
]
|
|
425
383
|
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
384
|
+
},
|
|
385
|
+
opening: {
|
|
386
|
+
tags: ["closed"],
|
|
387
|
+
activities: ["trackScroll", "trackPointerlockChange"],
|
|
388
|
+
after: {
|
|
389
|
+
OPEN_DELAY: "open"
|
|
390
|
+
},
|
|
391
|
+
on: {
|
|
392
|
+
POINTER_LEAVE: "closed",
|
|
393
|
+
BLUR: "closed",
|
|
394
|
+
SCROLL: "closed",
|
|
395
|
+
POINTER_LOCK_CHANGE: "closed",
|
|
396
|
+
POINTER_DOWN: {
|
|
397
|
+
guard: "closeOnPointerDown",
|
|
398
|
+
target: "closed"
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
open: {
|
|
403
|
+
tags: ["open"],
|
|
404
|
+
activities: [
|
|
405
|
+
"trackEscapeKey",
|
|
406
|
+
"trackDisabledTriggerOnSafari",
|
|
407
|
+
"trackScroll",
|
|
408
|
+
"trackPointerlockChange",
|
|
409
|
+
"computePlacement"
|
|
410
|
+
],
|
|
411
|
+
entry: ["setGlobalId", "invokeOnOpen"],
|
|
412
|
+
on: {
|
|
413
|
+
POINTER_LEAVE: [
|
|
414
|
+
{
|
|
415
|
+
guard: "isVisible",
|
|
416
|
+
target: "closing"
|
|
417
|
+
},
|
|
418
|
+
{ target: "closed" }
|
|
419
|
+
],
|
|
420
|
+
BLUR: "closed",
|
|
421
|
+
ESCAPE: "closed",
|
|
422
|
+
SCROLL: "closed",
|
|
423
|
+
POINTER_LOCK_CHANGE: "closed",
|
|
424
|
+
TOOLTIP_POINTER_LEAVE: {
|
|
425
|
+
guard: "isInteractive",
|
|
442
426
|
target: "closing"
|
|
443
427
|
},
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
TOOLTIP_POINTER_LEAVE: {
|
|
451
|
-
guard: "isInteractive",
|
|
452
|
-
target: "closing"
|
|
453
|
-
},
|
|
454
|
-
POINTER_DOWN: {
|
|
455
|
-
guard: "closeOnPointerDown",
|
|
456
|
-
target: "closed"
|
|
457
|
-
},
|
|
458
|
-
CLICK: "closed"
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
closing: {
|
|
462
|
-
tags: ["open"],
|
|
463
|
-
activities: ["trackStore", "computePlacement"],
|
|
464
|
-
after: {
|
|
465
|
-
CLOSE_DELAY: "closed"
|
|
428
|
+
POINTER_DOWN: {
|
|
429
|
+
guard: "closeOnPointerDown",
|
|
430
|
+
target: "closed"
|
|
431
|
+
},
|
|
432
|
+
CLICK: "closed"
|
|
433
|
+
}
|
|
466
434
|
},
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
435
|
+
closing: {
|
|
436
|
+
tags: ["open"],
|
|
437
|
+
activities: ["trackStore", "computePlacement"],
|
|
438
|
+
after: {
|
|
439
|
+
CLOSE_DELAY: "closed"
|
|
440
|
+
},
|
|
441
|
+
on: {
|
|
442
|
+
FORCE_CLOSE: "closed",
|
|
443
|
+
POINTER_ENTER: "open",
|
|
444
|
+
TOOLTIP_POINTER_ENTER: {
|
|
445
|
+
guard: "isInteractive",
|
|
446
|
+
target: "open"
|
|
447
|
+
}
|
|
473
448
|
}
|
|
474
449
|
}
|
|
475
450
|
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
activities: {
|
|
454
|
+
computePlacement(ctx2) {
|
|
455
|
+
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
456
|
+
let cleanup;
|
|
457
|
+
raf(() => {
|
|
458
|
+
cleanup = getPlacement(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
|
|
459
|
+
...ctx2.positioning,
|
|
460
|
+
onComplete(data) {
|
|
461
|
+
ctx2.currentPlacement = data.placement;
|
|
462
|
+
ctx2.isPlacementComplete = true;
|
|
463
|
+
},
|
|
464
|
+
onCleanup() {
|
|
465
|
+
ctx2.currentPlacement = void 0;
|
|
466
|
+
ctx2.isPlacementComplete = false;
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
return cleanup;
|
|
471
|
+
},
|
|
472
|
+
trackPointerlockChange(ctx2, _evt, { send }) {
|
|
473
|
+
return addPointerlockChangeListener(dom.getDoc(ctx2), () => {
|
|
474
|
+
send("POINTER_LOCK_CHANGE");
|
|
475
|
+
});
|
|
476
|
+
},
|
|
477
|
+
trackScroll(ctx2, _evt, { send }) {
|
|
478
|
+
const trigger = dom.getTriggerEl(ctx2);
|
|
479
|
+
if (!trigger)
|
|
480
|
+
return;
|
|
481
|
+
const cleanups = getScrollParents(trigger).map((el) => {
|
|
482
|
+
const opts = { passive: true, capture: true };
|
|
483
|
+
return addDomEvent(el, "scroll", () => send("SCROLL"), opts);
|
|
484
|
+
});
|
|
485
|
+
return () => {
|
|
486
|
+
cleanups.forEach((fn) => fn == null ? void 0 : fn());
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
trackStore(ctx2, _evt, { send }) {
|
|
490
|
+
return subscribe(store, () => {
|
|
491
|
+
if (store.id !== ctx2.id) {
|
|
492
|
+
send("FORCE_CLOSE");
|
|
491
493
|
}
|
|
492
|
-
})
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
return addDomEvent(el, "scroll", () => send("SCROLL"), opts);
|
|
508
|
-
});
|
|
509
|
-
return () => {
|
|
510
|
-
cleanups.forEach((fn) => fn == null ? void 0 : fn());
|
|
511
|
-
};
|
|
512
|
-
},
|
|
513
|
-
trackStore(ctx2, _evt, { send }) {
|
|
514
|
-
return subscribe(store, () => {
|
|
515
|
-
if (store.id !== ctx2.id) {
|
|
516
|
-
send("FORCE_CLOSE");
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
},
|
|
520
|
-
trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
|
|
521
|
-
if (!isSafari())
|
|
522
|
-
return noop;
|
|
523
|
-
const doc = dom.getDoc(ctx2);
|
|
524
|
-
return addPointerEvent(doc, "pointermove", (event) => {
|
|
525
|
-
const selector = "[data-part=trigger][data-expanded]";
|
|
526
|
-
if (isHTMLElement(event.target) && event.target.closest(selector))
|
|
494
|
+
});
|
|
495
|
+
},
|
|
496
|
+
trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
|
|
497
|
+
if (!isSafari())
|
|
498
|
+
return;
|
|
499
|
+
const doc = dom.getDoc(ctx2);
|
|
500
|
+
return addPointerEvent(doc, "pointermove", (event) => {
|
|
501
|
+
const selector = "[data-part=trigger][data-expanded]";
|
|
502
|
+
if (isHTMLElement(event.target) && event.target.closest(selector))
|
|
503
|
+
return;
|
|
504
|
+
send("POINTER_LEAVE");
|
|
505
|
+
});
|
|
506
|
+
},
|
|
507
|
+
trackEscapeKey(ctx2, _evt, { send }) {
|
|
508
|
+
if (!ctx2.closeOnEsc)
|
|
527
509
|
return;
|
|
528
|
-
|
|
529
|
-
|
|
510
|
+
const doc = dom.getDoc(ctx2);
|
|
511
|
+
return addDomEvent(doc, "keydown", (event) => {
|
|
512
|
+
if (event.key === "Escape") {
|
|
513
|
+
send("ESCAPE");
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}
|
|
530
517
|
},
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
|
|
518
|
+
actions: {
|
|
519
|
+
setGlobalId(ctx2) {
|
|
520
|
+
store.setId(ctx2.id);
|
|
521
|
+
},
|
|
522
|
+
clearGlobalId(ctx2) {
|
|
523
|
+
if (ctx2.id === store.id) {
|
|
524
|
+
store.setId(null);
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
invokeOnOpen(ctx2, evt) {
|
|
528
|
+
var _a;
|
|
529
|
+
const omit = ["TOOLTIP_POINTER_ENTER", "POINTER_ENTER"];
|
|
530
|
+
if (!omit.includes(evt.type)) {
|
|
531
|
+
(_a = ctx2.onOpen) == null ? void 0 : _a.call(ctx2);
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
invokeOnClose(ctx2, evt) {
|
|
535
|
+
var _a;
|
|
536
|
+
const omit = ["SETUP"];
|
|
537
|
+
if (!omit.includes(evt.type)) {
|
|
538
|
+
(_a = ctx2.onClose) == null ? void 0 : _a.call(ctx2);
|
|
538
539
|
}
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
|
-
actions: {
|
|
543
|
-
setupDocument(ctx2, evt) {
|
|
544
|
-
ctx2.id = evt.id;
|
|
545
|
-
if (evt.doc)
|
|
546
|
-
ctx2.doc = ref(evt.doc);
|
|
547
|
-
if (evt.root)
|
|
548
|
-
ctx2.rootNode = ref(evt.root);
|
|
549
|
-
},
|
|
550
|
-
setGlobalId(ctx2) {
|
|
551
|
-
store.setId(ctx2.id);
|
|
552
|
-
},
|
|
553
|
-
clearGlobalId(ctx2) {
|
|
554
|
-
if (ctx2.id === store.id) {
|
|
555
|
-
store.setId(null);
|
|
556
540
|
}
|
|
557
541
|
},
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
542
|
+
guards: {
|
|
543
|
+
closeOnPointerDown: (ctx2) => ctx2.closeOnPointerDown,
|
|
544
|
+
noVisibleTooltip: () => store.id === null,
|
|
545
|
+
isVisible: (ctx2) => ctx2.id === store.id,
|
|
546
|
+
isInteractive: (ctx2) => ctx2.interactive
|
|
564
547
|
},
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (!omit.includes(evt.type)) {
|
|
569
|
-
(_a = ctx2.onClose) == null ? void 0 : _a.call(ctx2);
|
|
570
|
-
}
|
|
548
|
+
delays: {
|
|
549
|
+
OPEN_DELAY: (ctx2) => ctx2.openDelay,
|
|
550
|
+
CLOSE_DELAY: (ctx2) => ctx2.closeDelay
|
|
571
551
|
}
|
|
572
|
-
},
|
|
573
|
-
guards: {
|
|
574
|
-
closeOnPointerDown: (ctx2) => ctx2.closeOnPointerDown,
|
|
575
|
-
noVisibleTooltip: () => store.id === null,
|
|
576
|
-
isVisible: (ctx2) => ctx2.id === store.id,
|
|
577
|
-
isInteractive: (ctx2) => ctx2.interactive
|
|
578
|
-
},
|
|
579
|
-
delays: {
|
|
580
|
-
OPEN_DELAY: (ctx2) => ctx2.openDelay,
|
|
581
|
-
CLOSE_DELAY: (ctx2) => ctx2.closeDelay
|
|
582
552
|
}
|
|
583
|
-
|
|
553
|
+
);
|
|
584
554
|
}
|
|
585
555
|
export {
|
|
586
556
|
connect,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tooltip",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Core logic for the tooltip widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,18 +29,22 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/
|
|
34
|
-
"@zag-js/
|
|
35
|
-
|
|
32
|
+
"@zag-js/core": "0.1.9",
|
|
33
|
+
"@zag-js/popper": "0.1.10",
|
|
34
|
+
"@zag-js/types": "0.2.3"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@zag-js/dom-utils": "0.1.9",
|
|
38
|
+
"@zag-js/utils": "0.1.3"
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
|
-
"build
|
|
39
|
-
"start": "
|
|
40
|
-
"build": "
|
|
41
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
42
|
+
"start": "pnpm build --watch",
|
|
43
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
41
44
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
42
45
|
"lint": "eslint src --ext .ts,.tsx",
|
|
43
|
-
"test
|
|
44
|
-
"test
|
|
46
|
+
"test-ci": "pnpm test --ci --runInBand",
|
|
47
|
+
"test-watch": "pnpm test --watch -u",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
45
49
|
}
|
|
46
|
-
}
|
|
50
|
+
}
|