@zag-js/tooltip 0.1.13 → 0.1.15
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 +12 -40
- package/package.json +9 -9
- package/dist/index.mjs +0 -558
package/dist/index.js
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
connect: () => connect,
|
|
24
|
-
machine: () => machine
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
|
-
// ../../utilities/dom/dist/index.mjs
|
|
1
|
+
// ../../utilities/dom/dist/index.js
|
|
29
2
|
var dataAttr = (guard) => {
|
|
30
3
|
return guard ? "" : void 0;
|
|
31
4
|
};
|
|
@@ -218,7 +191,7 @@ var visuallyHiddenStyle = {
|
|
|
218
191
|
};
|
|
219
192
|
|
|
220
193
|
// src/tooltip.connect.ts
|
|
221
|
-
|
|
194
|
+
import { getPlacementStyles } from "@zag-js/popper";
|
|
222
195
|
|
|
223
196
|
// src/tooltip.dom.ts
|
|
224
197
|
var dom = defineDomHelpers({
|
|
@@ -247,8 +220,8 @@ var dom = defineDomHelpers({
|
|
|
247
220
|
});
|
|
248
221
|
|
|
249
222
|
// src/tooltip.store.ts
|
|
250
|
-
|
|
251
|
-
var store =
|
|
223
|
+
import { proxy } from "@zag-js/core";
|
|
224
|
+
var store = proxy({
|
|
252
225
|
id: null,
|
|
253
226
|
prevId: null,
|
|
254
227
|
setId(val) {
|
|
@@ -264,7 +237,7 @@ function connect(state, send, normalize) {
|
|
|
264
237
|
const isOpen = state.hasTag("open");
|
|
265
238
|
const triggerId = dom.getTriggerId(state.context);
|
|
266
239
|
const contentId = dom.getContentId(state.context);
|
|
267
|
-
const popperStyles =
|
|
240
|
+
const popperStyles = getPlacementStyles({
|
|
268
241
|
measured: !!state.context.isPlacementComplete,
|
|
269
242
|
placement: state.context.currentPlacement
|
|
270
243
|
});
|
|
@@ -362,10 +335,10 @@ function connect(state, send, normalize) {
|
|
|
362
335
|
}
|
|
363
336
|
|
|
364
337
|
// src/tooltip.machine.ts
|
|
365
|
-
|
|
366
|
-
|
|
338
|
+
import { createMachine, subscribe } from "@zag-js/core";
|
|
339
|
+
import { getPlacement } from "@zag-js/popper";
|
|
367
340
|
function machine(ctx) {
|
|
368
|
-
return
|
|
341
|
+
return createMachine(
|
|
369
342
|
{
|
|
370
343
|
id: "tooltip",
|
|
371
344
|
initial: "unknown",
|
|
@@ -482,7 +455,7 @@ function machine(ctx) {
|
|
|
482
455
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
483
456
|
let cleanup;
|
|
484
457
|
raf(() => {
|
|
485
|
-
cleanup =
|
|
458
|
+
cleanup = getPlacement(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
|
|
486
459
|
...ctx2.positioning,
|
|
487
460
|
onComplete(data) {
|
|
488
461
|
ctx2.currentPlacement = data.placement;
|
|
@@ -514,7 +487,7 @@ function machine(ctx) {
|
|
|
514
487
|
};
|
|
515
488
|
},
|
|
516
489
|
trackStore(ctx2, _evt, { send }) {
|
|
517
|
-
return
|
|
490
|
+
return subscribe(store, () => {
|
|
518
491
|
if (store.id !== ctx2.id) {
|
|
519
492
|
send("FORCE_CLOSE");
|
|
520
493
|
}
|
|
@@ -579,8 +552,7 @@ function machine(ctx) {
|
|
|
579
552
|
}
|
|
580
553
|
);
|
|
581
554
|
}
|
|
582
|
-
|
|
583
|
-
0 && (module.exports = {
|
|
555
|
+
export {
|
|
584
556
|
connect,
|
|
585
557
|
machine
|
|
586
|
-
}
|
|
558
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "@zag-js/tooltip",
|
|
3
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.15",
|
|
4
5
|
"description": "Core logic for the tooltip widget implemented as a state machine",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"js",
|
|
@@ -16,7 +17,6 @@
|
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"main": "dist/index.js",
|
|
18
19
|
"types": "dist/index.d.ts",
|
|
19
|
-
"module": "dist/index.mjs",
|
|
20
20
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/tooltip",
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"files": [
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/popper": "0.1.
|
|
34
|
-
"@zag-js/types": "0.2.
|
|
32
|
+
"@zag-js/core": "0.1.11",
|
|
33
|
+
"@zag-js/popper": "0.1.12",
|
|
34
|
+
"@zag-js/types": "0.2.6"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@zag-js/dom-utils": "0.1.
|
|
38
|
-
"@zag-js/utils": "0.1.
|
|
37
|
+
"@zag-js/dom-utils": "0.1.12",
|
|
38
|
+
"@zag-js/utils": "0.1.5"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build-fast": "tsup src/index.ts --format=esm
|
|
41
|
+
"build-fast": "tsup src/index.ts --format=esm",
|
|
42
42
|
"start": "pnpm build --watch",
|
|
43
|
-
"build": "tsup src/index.ts --format=esm
|
|
43
|
+
"build": "tsup src/index.ts --format=esm --dts",
|
|
44
44
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
45
45
|
"lint": "eslint src --ext .ts,.tsx",
|
|
46
46
|
"test-ci": "pnpm test --ci --runInBand",
|
package/dist/index.mjs
DELETED
|
@@ -1,558 +0,0 @@
|
|
|
1
|
-
// ../../utilities/dom/dist/index.mjs
|
|
2
|
-
var dataAttr = (guard) => {
|
|
3
|
-
return guard ? "" : void 0;
|
|
4
|
-
};
|
|
5
|
-
function getCache() {
|
|
6
|
-
const g = globalThis;
|
|
7
|
-
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
8
|
-
return g.__styleCache;
|
|
9
|
-
}
|
|
10
|
-
function getComputedStyle(el) {
|
|
11
|
-
if (!el)
|
|
12
|
-
return {};
|
|
13
|
-
const cache = getCache();
|
|
14
|
-
let style = cache.get(el);
|
|
15
|
-
if (!style) {
|
|
16
|
-
const win = (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
17
|
-
style = win.getComputedStyle(el);
|
|
18
|
-
cache.set(el, style);
|
|
19
|
-
}
|
|
20
|
-
return style;
|
|
21
|
-
}
|
|
22
|
-
var runIfFn = (v, ...a) => {
|
|
23
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
24
|
-
return res ?? void 0;
|
|
25
|
-
};
|
|
26
|
-
var isArray = (v) => Array.isArray(v);
|
|
27
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
28
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
29
|
-
var isDom = () => typeof window !== "undefined";
|
|
30
|
-
function getPlatform() {
|
|
31
|
-
const agent = navigator.userAgentData;
|
|
32
|
-
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
33
|
-
}
|
|
34
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
35
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
36
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
37
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
38
|
-
function isDocument(el) {
|
|
39
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
40
|
-
}
|
|
41
|
-
function isWindow(value) {
|
|
42
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
43
|
-
}
|
|
44
|
-
function getDocument(el) {
|
|
45
|
-
if (isWindow(el))
|
|
46
|
-
return el.document;
|
|
47
|
-
if (isDocument(el))
|
|
48
|
-
return el;
|
|
49
|
-
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
50
|
-
}
|
|
51
|
-
function getWindow(el) {
|
|
52
|
-
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
53
|
-
}
|
|
54
|
-
function getNodeName(node) {
|
|
55
|
-
return isWindow(node) ? "" : (node == null ? void 0 : node.localName) ?? "";
|
|
56
|
-
}
|
|
57
|
-
function getParent(el) {
|
|
58
|
-
const doc = getDocument(el);
|
|
59
|
-
if (getNodeName(el) === "html")
|
|
60
|
-
return el;
|
|
61
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
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
|
-
}
|
|
79
|
-
function isHTMLElement(v) {
|
|
80
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
81
|
-
}
|
|
82
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
83
|
-
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
84
|
-
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
85
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
86
|
-
var isRef = (v) => hasProp(v, "current");
|
|
87
|
-
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
88
|
-
function extractInfo(event, type = "page") {
|
|
89
|
-
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
|
|
90
|
-
return {
|
|
91
|
-
point: {
|
|
92
|
-
x: point[`${type}X`],
|
|
93
|
-
y: point[`${type}Y`]
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
98
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
99
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
100
|
-
return () => {
|
|
101
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function addPointerEvent(target, event, listener, options) {
|
|
105
|
-
const type = getEventName(event) ?? event;
|
|
106
|
-
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
107
|
-
}
|
|
108
|
-
function wrapHandler(fn, filter = false) {
|
|
109
|
-
const listener = (event) => {
|
|
110
|
-
fn(event, extractInfo(event));
|
|
111
|
-
};
|
|
112
|
-
return filter ? filterPrimaryPointer(listener) : listener;
|
|
113
|
-
}
|
|
114
|
-
function filterPrimaryPointer(fn) {
|
|
115
|
-
return (event) => {
|
|
116
|
-
const win = event.view ?? window;
|
|
117
|
-
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
118
|
-
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
119
|
-
if (isPrimary)
|
|
120
|
-
fn(event);
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
var mouseEventNames = {
|
|
124
|
-
pointerdown: "mousedown",
|
|
125
|
-
pointermove: "mousemove",
|
|
126
|
-
pointerup: "mouseup",
|
|
127
|
-
pointercancel: "mousecancel",
|
|
128
|
-
pointerover: "mouseover",
|
|
129
|
-
pointerout: "mouseout",
|
|
130
|
-
pointerenter: "mouseenter",
|
|
131
|
-
pointerleave: "mouseleave"
|
|
132
|
-
};
|
|
133
|
-
var touchEventNames = {
|
|
134
|
-
pointerdown: "touchstart",
|
|
135
|
-
pointermove: "touchmove",
|
|
136
|
-
pointerup: "touchend",
|
|
137
|
-
pointercancel: "touchcancel"
|
|
138
|
-
};
|
|
139
|
-
function getEventName(evt) {
|
|
140
|
-
if (supportsPointerEvent())
|
|
141
|
-
return evt;
|
|
142
|
-
if (supportsTouchEvent())
|
|
143
|
-
return touchEventNames[evt];
|
|
144
|
-
if (supportsMouseEvent())
|
|
145
|
-
return mouseEventNames[evt];
|
|
146
|
-
return evt;
|
|
147
|
-
}
|
|
148
|
-
function raf(fn) {
|
|
149
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
150
|
-
return function cleanup() {
|
|
151
|
-
globalThis.cancelAnimationFrame(id);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function addPointerlockChangeListener(doc, fn) {
|
|
155
|
-
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
156
|
-
}
|
|
157
|
-
function isScrollParent(el) {
|
|
158
|
-
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
159
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
160
|
-
}
|
|
161
|
-
function getScrollParent(el) {
|
|
162
|
-
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
163
|
-
return getDocument(el).body;
|
|
164
|
-
}
|
|
165
|
-
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
166
|
-
return el;
|
|
167
|
-
}
|
|
168
|
-
return getScrollParent(getParent(el));
|
|
169
|
-
}
|
|
170
|
-
function getScrollParents(el, list = []) {
|
|
171
|
-
const scrollParent = getScrollParent(el);
|
|
172
|
-
const isBody = scrollParent === getDocument(el).body;
|
|
173
|
-
const win = getWindow(scrollParent);
|
|
174
|
-
const target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
|
|
175
|
-
const parents = list.concat(target);
|
|
176
|
-
if (isBody)
|
|
177
|
-
return parents;
|
|
178
|
-
return parents.concat(getScrollParents(getParent(target)));
|
|
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
|
-
};
|
|
192
|
-
|
|
193
|
-
// src/tooltip.connect.ts
|
|
194
|
-
import { getPlacementStyles } from "@zag-js/popper";
|
|
195
|
-
|
|
196
|
-
// src/tooltip.dom.ts
|
|
197
|
-
var dom = defineDomHelpers({
|
|
198
|
-
getTriggerId: (ctx) => {
|
|
199
|
-
var _a;
|
|
200
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `tooltip:${ctx.id}:trigger`;
|
|
201
|
-
},
|
|
202
|
-
getContentId: (ctx) => {
|
|
203
|
-
var _a;
|
|
204
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `tooltip:${ctx.id}:content`;
|
|
205
|
-
},
|
|
206
|
-
getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
|
|
207
|
-
getPositionerId: (ctx) => `tooltip:${ctx.id}:popper`,
|
|
208
|
-
portalId: "tooltip-portal",
|
|
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)),
|
|
213
|
-
getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx)),
|
|
214
|
-
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.portalId),
|
|
215
|
-
createPortalEl: (ctx) => {
|
|
216
|
-
const portal = dom.getDoc(ctx).createElement(dom.portalId);
|
|
217
|
-
portal.id = dom.portalId;
|
|
218
|
-
return portal;
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// src/tooltip.store.ts
|
|
223
|
-
import { proxy } from "@zag-js/core";
|
|
224
|
-
var store = proxy({
|
|
225
|
-
id: null,
|
|
226
|
-
prevId: null,
|
|
227
|
-
setId(val) {
|
|
228
|
-
this.prevId = this.id;
|
|
229
|
-
this.id = val;
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
// src/tooltip.connect.ts
|
|
234
|
-
function connect(state, send, normalize) {
|
|
235
|
-
const id = state.context.id;
|
|
236
|
-
const hasAriaLabel = state.context.hasAriaLabel;
|
|
237
|
-
const isOpen = state.hasTag("open");
|
|
238
|
-
const triggerId = dom.getTriggerId(state.context);
|
|
239
|
-
const contentId = dom.getContentId(state.context);
|
|
240
|
-
const popperStyles = getPlacementStyles({
|
|
241
|
-
measured: !!state.context.isPlacementComplete,
|
|
242
|
-
placement: state.context.currentPlacement
|
|
243
|
-
});
|
|
244
|
-
return {
|
|
245
|
-
isOpen,
|
|
246
|
-
open() {
|
|
247
|
-
send("OPEN");
|
|
248
|
-
},
|
|
249
|
-
close() {
|
|
250
|
-
send("CLOSE");
|
|
251
|
-
},
|
|
252
|
-
getAnimationState() {
|
|
253
|
-
return {
|
|
254
|
-
enter: store.prevId === null && id === store.id,
|
|
255
|
-
exit: store.id === null
|
|
256
|
-
};
|
|
257
|
-
},
|
|
258
|
-
triggerProps: normalize.button({
|
|
259
|
-
"data-part": "trigger",
|
|
260
|
-
id: triggerId,
|
|
261
|
-
"data-expanded": dataAttr(isOpen),
|
|
262
|
-
"aria-describedby": isOpen ? contentId : void 0,
|
|
263
|
-
onClick() {
|
|
264
|
-
send("CLICK");
|
|
265
|
-
},
|
|
266
|
-
onFocus() {
|
|
267
|
-
send("FOCUS");
|
|
268
|
-
},
|
|
269
|
-
onBlur() {
|
|
270
|
-
if (id === store.id) {
|
|
271
|
-
send("BLUR");
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
onPointerDown() {
|
|
275
|
-
if (id === store.id) {
|
|
276
|
-
send("POINTER_DOWN");
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
onPointerMove() {
|
|
280
|
-
send("POINTER_ENTER");
|
|
281
|
-
},
|
|
282
|
-
onPointerLeave() {
|
|
283
|
-
send("POINTER_LEAVE");
|
|
284
|
-
},
|
|
285
|
-
onPointerCancel() {
|
|
286
|
-
send("POINTER_LEAVE");
|
|
287
|
-
}
|
|
288
|
-
}),
|
|
289
|
-
arrowProps: normalize.element({
|
|
290
|
-
id: dom.getArrowId(state.context),
|
|
291
|
-
"data-part": "arrow",
|
|
292
|
-
style: popperStyles.arrow
|
|
293
|
-
}),
|
|
294
|
-
innerArrowProps: normalize.element({
|
|
295
|
-
"data-part": "arrow-inner",
|
|
296
|
-
style: popperStyles.innerArrow
|
|
297
|
-
}),
|
|
298
|
-
positionerProps: normalize.element({
|
|
299
|
-
id: dom.getPositionerId(state.context),
|
|
300
|
-
"data-part": "positioner",
|
|
301
|
-
style: popperStyles.floating
|
|
302
|
-
}),
|
|
303
|
-
contentProps: normalize.element({
|
|
304
|
-
"data-part": "content",
|
|
305
|
-
role: hasAriaLabel ? void 0 : "tooltip",
|
|
306
|
-
id: hasAriaLabel ? void 0 : contentId,
|
|
307
|
-
"data-placement": state.context.currentPlacement,
|
|
308
|
-
onPointerEnter() {
|
|
309
|
-
send("TOOLTIP_POINTER_ENTER");
|
|
310
|
-
},
|
|
311
|
-
onPointerLeave() {
|
|
312
|
-
send("TOOLTIP_POINTER_LEAVE");
|
|
313
|
-
},
|
|
314
|
-
style: {
|
|
315
|
-
pointerEvents: state.context.interactive ? "auto" : "none"
|
|
316
|
-
}
|
|
317
|
-
}),
|
|
318
|
-
labelProps: normalize.element({
|
|
319
|
-
"data-part": "label",
|
|
320
|
-
id: contentId,
|
|
321
|
-
role: "tooltip",
|
|
322
|
-
style: visuallyHiddenStyle,
|
|
323
|
-
children: state.context["aria-label"]
|
|
324
|
-
}),
|
|
325
|
-
createPortal() {
|
|
326
|
-
const doc = dom.getDoc(state.context);
|
|
327
|
-
const exist = dom.getPortalEl(state.context);
|
|
328
|
-
if (exist)
|
|
329
|
-
return exist;
|
|
330
|
-
const portal = dom.createPortalEl(state.context);
|
|
331
|
-
doc.body.appendChild(portal);
|
|
332
|
-
return portal;
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// src/tooltip.machine.ts
|
|
338
|
-
import { createMachine, subscribe } from "@zag-js/core";
|
|
339
|
-
import { getPlacement } from "@zag-js/popper";
|
|
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
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
computed: {
|
|
359
|
-
hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
|
|
360
|
-
},
|
|
361
|
-
on: {
|
|
362
|
-
OPEN: "open",
|
|
363
|
-
CLOSE: "closed"
|
|
364
|
-
},
|
|
365
|
-
states: {
|
|
366
|
-
unknown: {
|
|
367
|
-
on: {
|
|
368
|
-
SETUP: "closed"
|
|
369
|
-
}
|
|
370
|
-
},
|
|
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
|
-
]
|
|
383
|
-
}
|
|
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",
|
|
426
|
-
target: "closing"
|
|
427
|
-
},
|
|
428
|
-
POINTER_DOWN: {
|
|
429
|
-
guard: "closeOnPointerDown",
|
|
430
|
-
target: "closed"
|
|
431
|
-
},
|
|
432
|
-
CLICK: "closed"
|
|
433
|
-
}
|
|
434
|
-
},
|
|
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
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
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");
|
|
493
|
-
}
|
|
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)
|
|
509
|
-
return;
|
|
510
|
-
const doc = dom.getDoc(ctx2);
|
|
511
|
-
return addDomEvent(doc, "keydown", (event) => {
|
|
512
|
-
if (event.key === "Escape") {
|
|
513
|
-
send("ESCAPE");
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
},
|
|
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);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
|
-
guards: {
|
|
543
|
-
closeOnPointerDown: (ctx2) => ctx2.closeOnPointerDown,
|
|
544
|
-
noVisibleTooltip: () => store.id === null,
|
|
545
|
-
isVisible: (ctx2) => ctx2.id === store.id,
|
|
546
|
-
isInteractive: (ctx2) => ctx2.interactive
|
|
547
|
-
},
|
|
548
|
-
delays: {
|
|
549
|
-
OPEN_DELAY: (ctx2) => ctx2.openDelay,
|
|
550
|
-
CLOSE_DELAY: (ctx2) => ctx2.closeDelay
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
export {
|
|
556
|
-
connect,
|
|
557
|
-
machine
|
|
558
|
-
};
|