@wisdomgarden/torque 0.2.1 → 0.2.3
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/common/is-dev.d.ts +1 -0
- package/dist/common/is-dev.js +5 -0
- package/dist/components/_inner/drawer/base-bottom-drawer.d.ts +1 -1
- package/dist/components/_inner/drawer/base-bottom-drawer.js +52 -44
- package/dist/components/_inner/menu/_web/menu.web.js +83 -72
- package/dist/components/_inner/portal/index.d.ts +1 -0
- package/dist/components/_inner/portal/index.js +5 -0
- package/dist/components/_inner/portal/portal.d.ts +14 -0
- package/dist/components/_inner/portal/portal.js +19 -0
- package/dist/components/button/styles/button-variables.module.css.js +1 -1
- package/dist/components/drawer/drawer.d.ts +1 -1
- package/dist/components/drawer/drawer.js +42 -34
- package/dist/components/modal/index.d.ts +1 -1
- package/dist/components/modal/modal.d.ts +7 -4
- package/dist/components/modal/modal.js +191 -44
- package/dist/components/modal/modal.module.css.js +20 -6
- package/dist/components/modal/modal.types.d.ts +96 -0
- package/dist/components/modal-deprecated/index.d.ts +2 -0
- package/dist/components/modal-deprecated/index.js +5 -0
- package/dist/components/modal-deprecated/modal-deprecated.d.ts +11 -0
- package/dist/components/modal-deprecated/modal-deprecated.js +70 -0
- package/dist/components/modal-deprecated/modal-deprecated.module.css.js +10 -0
- package/dist/components/notifications/index.d.ts +2 -0
- package/dist/components/notifications/index.js +4 -2
- package/dist/components/notifications/notifications-container.d.ts +9 -0
- package/dist/components/notifications/notifications-container.js +22 -0
- package/dist/components/overlay-layer/constants.d.ts +14 -0
- package/dist/components/overlay-layer/constants.js +8 -0
- package/dist/components/overlay-layer/index.d.ts +5 -0
- package/dist/components/overlay-layer/index.js +10 -0
- package/dist/components/overlay-layer/overlay-parent-context.d.ts +6 -0
- package/dist/components/overlay-layer/overlay-parent-context.js +18 -0
- package/dist/components/overlay-layer/overlay-stack-debug.d.ts +24 -0
- package/dist/components/overlay-layer/overlay-stack-debug.js +151 -0
- package/dist/components/overlay-layer/overlay-stack.d.ts +38 -0
- package/dist/components/overlay-layer/overlay-stack.js +137 -0
- package/dist/components/overlay-layer/overlay-tier-scope.d.ts +12 -0
- package/dist/components/overlay-layer/overlay-tier-scope.js +16 -0
- package/dist/components/overlay-layer/types.d.ts +63 -0
- package/dist/components/overlay-layer/use-mantine-overlay-layer.d.ts +21 -0
- package/dist/components/overlay-layer/use-mantine-overlay-layer.js +24 -0
- package/dist/components/overlay-layer/use-overlay-layer.d.ts +26 -0
- package/dist/components/overlay-layer/use-overlay-layer.js +77 -0
- package/dist/components/popover/hooks.d.ts +0 -1
- package/dist/components/popover/hooks.js +69 -83
- package/dist/components/popover/popover-context.d.ts +0 -1
- package/dist/components/popover/popover-context.js +3 -4
- package/dist/components/popover/popover-dropdown.js +110 -91
- package/dist/components/popover/popover.js +120 -129
- package/dist/components/popover/popover.types.d.ts +18 -5
- package/dist/components/tooltip/index.d.ts +10 -2
- package/dist/components/tooltip/index.js +100 -92
- package/dist/index.css +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +193 -182
- package/dist/provider/hooks.js +12 -11
- package/dist/provider/ui-context.d.ts +10 -0
- package/dist/provider/ui-context.js +8 -7
- package/dist/provider/ui-provider.d.ts +23 -1
- package/dist/provider/ui-provider.js +17 -10
- package/package.json +3 -3
- package/dist/components/popover/popover-stack.d.ts +0 -10
- package/dist/components/popover/popover-stack.js +0 -24
|
@@ -1,194 +1,185 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { offset as
|
|
4
|
-
import { useDirection as
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { PopoverContext as
|
|
8
|
-
const
|
|
9
|
-
children:
|
|
10
|
-
position:
|
|
11
|
-
offset:
|
|
12
|
-
opened:
|
|
13
|
-
defaultOpened:
|
|
14
|
-
onOpenChange:
|
|
15
|
-
disabled:
|
|
2
|
+
import { jsx as re } from "react/jsx-runtime";
|
|
3
|
+
import { offset as se, flip as ie, size as le, shift as ae, limitShift as ce, arrow as de, hide as ue, useFloating as fe, autoUpdate as pe } from "@floating-ui/react-dom";
|
|
4
|
+
import { useDirection as me, getFloatingPosition as ge } from "@mantine/core";
|
|
5
|
+
import J, { useRef as r, useId as he, useCallback as s, useEffect as K, useMemo as L } from "react";
|
|
6
|
+
import { isDev as ve } from "../../common/is-dev.js";
|
|
7
|
+
import { PopoverContext as O } from "./popover-context.js";
|
|
8
|
+
const g = 8, be = ({
|
|
9
|
+
children: Q,
|
|
10
|
+
position: W = "bottom",
|
|
11
|
+
offset: P = 8,
|
|
12
|
+
opened: w,
|
|
13
|
+
defaultOpened: X = !1,
|
|
14
|
+
onOpenChange: d,
|
|
15
|
+
disabled: y = !1,
|
|
16
16
|
withArrow: i = !1,
|
|
17
|
-
arrowSize:
|
|
18
|
-
trigger:
|
|
19
|
-
openDelay:
|
|
20
|
-
closeDelay:
|
|
21
|
-
closeOnClickOutside:
|
|
22
|
-
closeOnEscape:
|
|
23
|
-
restoreFocus:
|
|
17
|
+
arrowSize: u = 8,
|
|
18
|
+
trigger: l = "click",
|
|
19
|
+
openDelay: F = 0,
|
|
20
|
+
closeDelay: E = 100,
|
|
21
|
+
closeOnClickOutside: b = !0,
|
|
22
|
+
closeOnEscape: C = !0,
|
|
23
|
+
restoreFocus: D,
|
|
24
24
|
strategy: h = "absolute",
|
|
25
|
-
initialFocusRef:
|
|
26
|
-
trapFocus:
|
|
27
|
-
preventAutoFocus:
|
|
28
|
-
"aria-labelledby":
|
|
25
|
+
initialFocusRef: N,
|
|
26
|
+
trapFocus: T = !1,
|
|
27
|
+
preventAutoFocus: I = !1,
|
|
28
|
+
"aria-labelledby": M
|
|
29
29
|
}) => {
|
|
30
|
-
const
|
|
30
|
+
const $ = J.useContext(O)?.registerNestedFloatingElement, a = w !== void 0, [Y, Z] = J.useState(X), c = a ? w : Y, f = r(null), S = r(null), p = r(null), v = r(/* @__PURE__ */ new Set()), x = r(void 0), G = he(), { dir: z } = me(), n = s(
|
|
31
31
|
(e) => {
|
|
32
|
-
|
|
32
|
+
a || Z(e), d?.(e);
|
|
33
33
|
},
|
|
34
|
-
[
|
|
35
|
-
),
|
|
36
|
-
window.clearTimeout(
|
|
37
|
-
}, []),
|
|
34
|
+
[a, d]
|
|
35
|
+
), H = s(() => n(!c), [c, n]), o = s(() => {
|
|
36
|
+
window.clearTimeout(x.current), x.current = void 0;
|
|
37
|
+
}, []), j = s(
|
|
38
38
|
(e) => {
|
|
39
|
-
|
|
40
|
-
const t = e ?
|
|
39
|
+
o();
|
|
40
|
+
const t = e ? F : E;
|
|
41
41
|
if (t <= 0) {
|
|
42
42
|
n(e);
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
x.current = window.setTimeout(() => n(e), t);
|
|
46
46
|
},
|
|
47
|
-
[
|
|
47
|
+
[o, F, E, n]
|
|
48
48
|
);
|
|
49
|
-
|
|
50
|
-
const
|
|
49
|
+
K(() => o, [o]);
|
|
50
|
+
const k = r(!1);
|
|
51
|
+
K(() => {
|
|
52
|
+
!ve() || k.current || !a || l === "none" || d || (k.current = !0, console.warn(
|
|
53
|
+
`[@wisdomgarden/torque] <Popover trigger="${l}"> is controlled through \`opened\` but got no \`onOpenChange\`, so every built-in trigger resolves to a no-op — including the \`openDelay\` / \`closeDelay\` timers, which still run and then have nowhere to report. Pass \`onOpenChange\`, or use trigger="none" if the host owns the open state.`
|
|
54
|
+
));
|
|
55
|
+
}, [a, l, d]);
|
|
56
|
+
const q = s(
|
|
51
57
|
(e) => {
|
|
52
|
-
|
|
53
|
-
const t =
|
|
58
|
+
v.current.add(e);
|
|
59
|
+
const t = $?.(e);
|
|
54
60
|
return () => {
|
|
55
|
-
|
|
61
|
+
v.current.delete(e), t?.();
|
|
56
62
|
};
|
|
57
63
|
},
|
|
58
|
-
[
|
|
59
|
-
),
|
|
60
|
-
const e =
|
|
61
|
-
return
|
|
64
|
+
[$]
|
|
65
|
+
), U = s(() => {
|
|
66
|
+
const e = p.current ? [p.current] : [];
|
|
67
|
+
return v.current.forEach((t) => {
|
|
62
68
|
t.isConnected && e.push(t);
|
|
63
69
|
}), Array.from(new Set(e));
|
|
64
|
-
}, [])
|
|
65
|
-
J(() => {
|
|
66
|
-
if (!S || !o) return;
|
|
67
|
-
const e = (t) => {
|
|
68
|
-
const g = t.composedPath(), c = u.current;
|
|
69
|
-
c && g.includes(c) || m().some((ce) => g.includes(ce)) || w();
|
|
70
|
-
};
|
|
71
|
-
return document.addEventListener("mousedown", e, !0), document.addEventListener("touchstart", e, !0), () => {
|
|
72
|
-
document.removeEventListener("mousedown", e, !0), document.removeEventListener("touchstart", e, !0);
|
|
73
|
-
};
|
|
74
|
-
}, [S, o, w, m]), Re(
|
|
75
|
-
Z,
|
|
76
|
-
o,
|
|
77
|
-
w,
|
|
78
|
-
u,
|
|
79
|
-
y,
|
|
80
|
-
x,
|
|
81
|
-
z
|
|
82
|
-
);
|
|
83
|
-
const oe = K(
|
|
70
|
+
}, []), ee = L(
|
|
84
71
|
() => [
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
se(P + (i ? u / 2 : 0)),
|
|
73
|
+
ie({ padding: g }),
|
|
87
74
|
// 必须在 shift 之前:否则 availableHeight 是 shift 推动后的位置算出的(≈整屏),高度约束失效
|
|
88
|
-
|
|
89
|
-
padding:
|
|
90
|
-
apply({ availableWidth: e, availableHeight: t, rects:
|
|
91
|
-
|
|
75
|
+
le({
|
|
76
|
+
padding: g,
|
|
77
|
+
apply({ availableWidth: e, availableHeight: t, rects: oe, elements: R }) {
|
|
78
|
+
R.floating.style.setProperty(
|
|
92
79
|
"--t-popover-available-width",
|
|
93
80
|
`${Math.max(0, e)}px`
|
|
94
|
-
),
|
|
81
|
+
), R.floating.style.setProperty(
|
|
95
82
|
"--t-popover-available-height",
|
|
96
83
|
`${Math.max(0, t)}px`
|
|
97
|
-
),
|
|
84
|
+
), R.floating.style.setProperty(
|
|
98
85
|
"--t-popover-reference-width",
|
|
99
|
-
`${
|
|
86
|
+
`${oe.reference.width}px`
|
|
100
87
|
);
|
|
101
88
|
}
|
|
102
89
|
}),
|
|
103
|
-
|
|
104
|
-
padding:
|
|
90
|
+
ae({
|
|
91
|
+
padding: g,
|
|
105
92
|
crossAxis: !0,
|
|
106
93
|
mainAxis: !0,
|
|
107
|
-
limiter:
|
|
94
|
+
limiter: ce()
|
|
108
95
|
}),
|
|
109
96
|
...i ? (
|
|
110
97
|
// floating-ui 的 arrow 中间件按设计就是收一个 ref 对象(它在定位阶段自己读
|
|
111
98
|
// .current),不是我们在渲染期读 ref 的值。没有保留该 API 的改写方式。
|
|
112
99
|
// eslint-disable-next-line react-hooks/refs
|
|
113
|
-
[
|
|
100
|
+
[de({ element: f, padding: g })]
|
|
114
101
|
) : [],
|
|
115
|
-
|
|
102
|
+
ue()
|
|
116
103
|
],
|
|
117
|
-
[
|
|
104
|
+
[P, i, u, f]
|
|
118
105
|
), {
|
|
119
106
|
x: V,
|
|
120
107
|
y: _,
|
|
121
|
-
refs:
|
|
122
|
-
placement:
|
|
123
|
-
middlewareData:
|
|
124
|
-
} =
|
|
125
|
-
open:
|
|
108
|
+
refs: m,
|
|
109
|
+
placement: te,
|
|
110
|
+
middlewareData: A
|
|
111
|
+
} = fe({
|
|
112
|
+
open: c,
|
|
126
113
|
strategy: h,
|
|
127
|
-
placement:
|
|
128
|
-
middleware:
|
|
129
|
-
whileElementsMounted:
|
|
130
|
-
}),
|
|
114
|
+
placement: ge(z, W),
|
|
115
|
+
middleware: ee,
|
|
116
|
+
whileElementsMounted: pe
|
|
117
|
+
}), B = te.split("-")[0], ne = L(
|
|
131
118
|
() => ({
|
|
132
|
-
opened:
|
|
119
|
+
opened: c,
|
|
133
120
|
setOpen: n,
|
|
134
|
-
toggle:
|
|
135
|
-
trigger:
|
|
136
|
-
disabled:
|
|
137
|
-
id:
|
|
121
|
+
toggle: H,
|
|
122
|
+
trigger: l,
|
|
123
|
+
disabled: y,
|
|
124
|
+
id: G,
|
|
138
125
|
withArrow: i,
|
|
139
|
-
arrowSize:
|
|
126
|
+
arrowSize: u,
|
|
140
127
|
x: V,
|
|
141
128
|
y: _,
|
|
142
129
|
strategy: h,
|
|
143
|
-
resolvedSide:
|
|
144
|
-
middlewareData:
|
|
145
|
-
scheduleHover:
|
|
146
|
-
cancelHoverTimer:
|
|
147
|
-
referenceRef:
|
|
148
|
-
floatingRef:
|
|
149
|
-
arrowRef:
|
|
150
|
-
setReference:
|
|
151
|
-
setFloating:
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
130
|
+
resolvedSide: B,
|
|
131
|
+
middlewareData: A,
|
|
132
|
+
scheduleHover: j,
|
|
133
|
+
cancelHoverTimer: o,
|
|
134
|
+
referenceRef: S,
|
|
135
|
+
floatingRef: p,
|
|
136
|
+
arrowRef: f,
|
|
137
|
+
setReference: m.setReference,
|
|
138
|
+
setFloating: m.setFloating,
|
|
139
|
+
registerNestedFloatingElement: q,
|
|
140
|
+
getFloatingScopeElements: U,
|
|
141
|
+
initialFocusRef: N,
|
|
142
|
+
trapFocus: T,
|
|
143
|
+
preventAutoFocus: I,
|
|
144
|
+
ariaLabelledby: M,
|
|
145
|
+
restoreFocus: D,
|
|
146
|
+
closeOnEscape: C,
|
|
147
|
+
closeOnClickOutside: b
|
|
159
148
|
}),
|
|
160
149
|
[
|
|
161
|
-
|
|
150
|
+
c,
|
|
162
151
|
n,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
b,
|
|
152
|
+
H,
|
|
153
|
+
l,
|
|
166
154
|
y,
|
|
155
|
+
G,
|
|
167
156
|
i,
|
|
168
|
-
|
|
157
|
+
u,
|
|
169
158
|
V,
|
|
170
159
|
_,
|
|
171
160
|
h,
|
|
161
|
+
B,
|
|
172
162
|
A,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
163
|
+
j,
|
|
164
|
+
o,
|
|
165
|
+
S,
|
|
166
|
+
p,
|
|
177
167
|
f,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
x,
|
|
168
|
+
m.setReference,
|
|
169
|
+
m.setFloating,
|
|
170
|
+
q,
|
|
182
171
|
U,
|
|
183
|
-
|
|
184
|
-
|
|
172
|
+
N,
|
|
173
|
+
T,
|
|
174
|
+
I,
|
|
175
|
+
M,
|
|
185
176
|
D,
|
|
186
|
-
|
|
187
|
-
|
|
177
|
+
C,
|
|
178
|
+
b
|
|
188
179
|
]
|
|
189
180
|
);
|
|
190
|
-
return /* @__PURE__ */
|
|
181
|
+
return /* @__PURE__ */ re(O.Provider, { value: ne, children: Q });
|
|
191
182
|
};
|
|
192
183
|
export {
|
|
193
|
-
|
|
184
|
+
be as Popover
|
|
194
185
|
};
|
|
@@ -22,7 +22,11 @@ export interface PopoverProps {
|
|
|
22
22
|
*/
|
|
23
23
|
offset?: number;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* 受控模式:是否展开。
|
|
26
|
+
*
|
|
27
|
+
* 受控之后内部不再持有开关状态,所有内部触发都只转发给 `onOpenChange`,
|
|
28
|
+
* 所以除 `trigger="none"` 外**必须同时提供 `onOpenChange`** ——
|
|
29
|
+
* 漏传会让 click / hover 以及 `openDelay` / `closeDelay` 全部静默失效。
|
|
26
30
|
*/
|
|
27
31
|
opened?: boolean;
|
|
28
32
|
/**
|
|
@@ -31,7 +35,8 @@ export interface PopoverProps {
|
|
|
31
35
|
*/
|
|
32
36
|
defaultOpened?: boolean;
|
|
33
37
|
/**
|
|
34
|
-
*
|
|
38
|
+
* 展开状态变更回调。受控与非受控都会调用;受控下它是内部触发唯一的出口,
|
|
39
|
+
* 必须无条件回写,业务上的启用与否交给 `disabled`。
|
|
35
40
|
*/
|
|
36
41
|
onOpenChange?: (opened: boolean) => void;
|
|
37
42
|
/**
|
|
@@ -64,6 +69,10 @@ export interface PopoverProps {
|
|
|
64
69
|
/**
|
|
65
70
|
* hover 关闭延迟(ms),留出鼠标从触发元素移动到浮层的时间。
|
|
66
71
|
* 仅 `trigger="hover"` 生效。
|
|
72
|
+
*
|
|
73
|
+
* 设为 `0` 即取消这段缓冲:鼠标离开触发元素就同步关闭,够不到浮层,键盘也 Tab 不进去。
|
|
74
|
+
* 想要「只给看、不给进一步操作」的富文本 tooltip 就该设 `0`,但浮层内容必须纯展示;
|
|
75
|
+
* 浮层内有可交互内容时不要设 `0`。
|
|
67
76
|
* @default 100
|
|
68
77
|
*/
|
|
69
78
|
closeDelay?: number;
|
|
@@ -209,11 +218,9 @@ export interface PopoverContextValue {
|
|
|
209
218
|
arrowRef: React.RefObject<HTMLDivElement | null>;
|
|
210
219
|
setReference: (node: HTMLElement | null) => void;
|
|
211
220
|
setFloating: (node: HTMLDivElement | null) => void;
|
|
212
|
-
/** 当前 Popover 的逻辑嵌套深度,用于浮层层级和 Escape 栈排序 */
|
|
213
|
-
depth: number;
|
|
214
221
|
/** 将后代 Portal 浮层登记到当前 Popover 的交互与焦点范围中 */
|
|
215
222
|
registerNestedFloatingElement: (element: HTMLElement) => () => void;
|
|
216
|
-
/**
|
|
223
|
+
/** 返回当前浮层及所有已登记后代浮层,用于焦点范围判断 */
|
|
217
224
|
getFloatingScopeElements: () => HTMLElement[];
|
|
218
225
|
/** 外部传入的初始焦点目标;`usePopoverFocus` 有值时优先聚焦该元素 */
|
|
219
226
|
initialFocusRef?: React.RefObject<HTMLElement | null>;
|
|
@@ -223,4 +230,10 @@ export interface PopoverContextValue {
|
|
|
223
230
|
preventAutoFocus: boolean;
|
|
224
231
|
/** dialog 的 `aria-labelledby` id;由 `PopoverDropdown` 写到 role="dialog" 元素上 */
|
|
225
232
|
ariaLabelledby?: string;
|
|
233
|
+
/** Escape 关闭后恢复焦点的方法;未传时聚焦 Target */
|
|
234
|
+
restoreFocus?: () => void;
|
|
235
|
+
/** 交给层级模块:本层为栈顶时 Escape 是否关闭 */
|
|
236
|
+
closeOnEscape: boolean;
|
|
237
|
+
/** 交给层级模块:点在外面时是否关闭 */
|
|
238
|
+
closeOnClickOutside: boolean;
|
|
226
239
|
}
|
|
@@ -27,6 +27,14 @@ export type TooltipProps = React.HTMLAttributes<HTMLDivElement> & WrapperDisplay
|
|
|
27
27
|
readonly strategy?: FloatingStrategy;
|
|
28
28
|
/** 是否禁用 Tooltip 的显示 */
|
|
29
29
|
readonly disabled?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 鼠标移入浮层时是否保持显示,默认 `true`。
|
|
32
|
+
*
|
|
33
|
+
* - `true`:浮层可 hover,用户能选中并复制其中的文字,适合 info 等解释说明场景;
|
|
34
|
+
* - `false`:浮层不响应鼠标(`pointer-events: none`),鼠标移向浮层即消失,
|
|
35
|
+
* 适合列表选择等仅需查看完整文本、无复制需求的场景。
|
|
36
|
+
*/
|
|
37
|
+
readonly interactive?: boolean;
|
|
30
38
|
/** 触发 Tooltip 的目标元素 */
|
|
31
39
|
readonly children: React.ReactNode;
|
|
32
40
|
/** Tooltip 内显示的提示内容 */
|
|
@@ -41,7 +49,7 @@ export type TooltipProps = React.HTMLAttributes<HTMLDivElement> & WrapperDisplay
|
|
|
41
49
|
readonly truncateMaxLines?: number;
|
|
42
50
|
/** 透传给浮层根节点的 ref */
|
|
43
51
|
readonly ref?: React.Ref<HTMLDivElement>;
|
|
44
|
-
/** 浮层的 z-index
|
|
52
|
+
/** 浮层的 z-index 层级。不传时由层级模块按打开顺序计算(普通层从 200 起) */
|
|
45
53
|
readonly zIndex?: number;
|
|
46
54
|
};
|
|
47
55
|
/**
|
|
@@ -50,5 +58,5 @@ export type TooltipProps = React.HTMLAttributes<HTMLDivElement> & WrapperDisplay
|
|
|
50
58
|
* 基于 `@floating-ui/react-dom` 封装的工具提示组件,支持智能定位、自动翻转、箭头指示,
|
|
51
59
|
* 以及独有的「仅文本截断时才显示 (showOnlyWhenTruncated)」功能。
|
|
52
60
|
*/
|
|
53
|
-
export declare const Tooltip: ({ position, strategy, arrowProps, offset: offsetProp, label, children, disabled, showOnlyWhenTruncated, truncateMaxWidth, truncateMaxLines, ref: externalRef, inline, block, zIndex, ...others }: TooltipProps) => import("react").JSX.Element;
|
|
61
|
+
export declare const Tooltip: ({ position, strategy, arrowProps, offset: offsetProp, label, children, disabled, interactive, showOnlyWhenTruncated, truncateMaxWidth, truncateMaxLines, ref: externalRef, inline, block, zIndex: zIndexProp, ...others }: TooltipProps) => import("react").JSX.Element;
|
|
54
62
|
export type * from './types';
|
|
@@ -1,150 +1,158 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import { offset as
|
|
4
|
-
import { useDirection as
|
|
5
|
-
import { useMergedRef as
|
|
6
|
-
import { useRef as i, useState as
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
import { jsxs as H, Fragment as ie, jsx as g } from "react/jsx-runtime";
|
|
3
|
+
import { offset as ae, flip as le, shift as ce, arrow as de, hide as fe, useFloating as me, autoUpdate as ue } from "@floating-ui/react-dom";
|
|
4
|
+
import { useDirection as pe, getFloatingPosition as ge, Transition as we } from "@mantine/core";
|
|
5
|
+
import { useMergedRef as I } from "@mantine/hooks";
|
|
6
|
+
import { useRef as i, useState as Te, isValidElement as ve, useMemo as w, useCallback as r } from "react";
|
|
7
|
+
import { Portal as xe } from "../_inner/portal/portal.js";
|
|
8
|
+
import { useOverlayLayer as Ee } from "../overlay-layer/use-overlay-layer.js";
|
|
9
|
+
import { FloatingArrow as Re } from "./floating-arrow.js";
|
|
10
|
+
import L from "./styles.module.css.js";
|
|
11
|
+
import { useMergedEvents as Fe } from "./use-merged-events.js";
|
|
12
|
+
import { useTooltipTrigger as Me } from "./use-tooltip-trigger.js";
|
|
13
|
+
import { getTruncationTarget as ye, isTruncated as he } from "./utils.js";
|
|
14
|
+
const T = 8, Be = ({
|
|
15
|
+
position: b = "top",
|
|
16
|
+
strategy: z = "absolute",
|
|
17
|
+
arrowProps: D,
|
|
18
|
+
offset: v = 5,
|
|
19
|
+
label: N,
|
|
18
20
|
children: a,
|
|
19
|
-
disabled:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
disabled: x,
|
|
22
|
+
interactive: l = !0,
|
|
23
|
+
showOnlyWhenTruncated: c = !1,
|
|
24
|
+
truncateMaxWidth: P,
|
|
25
|
+
truncateMaxLines: A = 1,
|
|
26
|
+
ref: k,
|
|
27
|
+
inline: d,
|
|
28
|
+
block: E = !0,
|
|
29
|
+
zIndex: S,
|
|
27
30
|
...j
|
|
28
31
|
}) => {
|
|
29
|
-
const
|
|
30
|
-
() =>
|
|
31
|
-
[
|
|
32
|
+
const R = i(null), f = i(null), F = i(null), [m, o] = Te(!1), B = ve(a), C = w(
|
|
33
|
+
() => d !== void 0 ? !d : E ?? !0,
|
|
34
|
+
[E, d]
|
|
32
35
|
), {
|
|
33
|
-
size:
|
|
34
|
-
offset:
|
|
35
|
-
radius:
|
|
36
|
-
} =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
size: G = 6,
|
|
37
|
+
offset: V = 5,
|
|
38
|
+
radius: O = 0
|
|
39
|
+
} = D ?? {}, { dir: M } = pe(), U = w(() => [
|
|
40
|
+
ae(v),
|
|
41
|
+
le({ padding: T }),
|
|
42
|
+
ce({ padding: T }),
|
|
40
43
|
// 同 popover.tsx:floating-ui 的 arrow 中间件收的就是 ref 对象本身。
|
|
41
44
|
// eslint-disable-next-line react-hooks/refs
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
], [
|
|
45
|
+
de({ element: F, padding: T }),
|
|
46
|
+
fe()
|
|
47
|
+
], [v]), {
|
|
45
48
|
x: X,
|
|
46
49
|
y: Y,
|
|
47
|
-
refs:
|
|
50
|
+
refs: y,
|
|
48
51
|
floatingStyles: _,
|
|
49
52
|
placement: q,
|
|
50
53
|
middlewareData: { arrow: { x: J, y: K } = {} },
|
|
51
|
-
middlewareData:
|
|
52
|
-
} =
|
|
53
|
-
open:
|
|
54
|
-
strategy:
|
|
55
|
-
placement:
|
|
54
|
+
middlewareData: h
|
|
55
|
+
} = me({
|
|
56
|
+
open: m,
|
|
57
|
+
strategy: z,
|
|
58
|
+
placement: ge(M, b),
|
|
56
59
|
middleware: U,
|
|
57
|
-
whileElementsMounted:
|
|
58
|
-
}),
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
whileElementsMounted: ue
|
|
61
|
+
}), { zIndex: Q, ref: Z } = Ee({
|
|
62
|
+
opened: !x && m,
|
|
63
|
+
zIndex: S,
|
|
64
|
+
name: "tooltip"
|
|
65
|
+
}), $ = I(
|
|
66
|
+
R,
|
|
67
|
+
k,
|
|
68
|
+
y.setFloating,
|
|
69
|
+
Z
|
|
62
70
|
), t = i(0), n = r(() => {
|
|
63
71
|
t.current && (clearTimeout(t.current), t.current = 0);
|
|
64
|
-
}, []),
|
|
65
|
-
if (n(),
|
|
66
|
-
const e =
|
|
67
|
-
if (!
|
|
72
|
+
}, []), W = I(f, y.setReference), s = r(() => {
|
|
73
|
+
if (n(), c) {
|
|
74
|
+
const e = ye(f.current);
|
|
75
|
+
if (!he(e)) return;
|
|
68
76
|
}
|
|
69
77
|
o(!0);
|
|
70
|
-
}, [n,
|
|
71
|
-
const
|
|
72
|
-
|
|
78
|
+
}, [n, c]), u = r((e) => {
|
|
79
|
+
const p = e.relatedTarget instanceof Node ? e.relatedTarget : null;
|
|
80
|
+
p && (f.current?.contains(p) || R.current?.contains(p)) || (t.current = window.setTimeout(() => {
|
|
73
81
|
o(!1);
|
|
74
82
|
}, 100));
|
|
75
|
-
}, []),
|
|
83
|
+
}, []), ee = r(() => {
|
|
76
84
|
t.current = window.setTimeout(() => {
|
|
77
85
|
o(!1);
|
|
78
86
|
}, 100);
|
|
79
|
-
}, []),
|
|
87
|
+
}, []), te = r(() => {
|
|
80
88
|
n(), o(!1);
|
|
81
|
-
}, [n]),
|
|
82
|
-
userProps:
|
|
89
|
+
}, [n]), re = Fe({
|
|
90
|
+
userProps: B ? a.props : {},
|
|
83
91
|
internalProps: {
|
|
84
92
|
onMouseEnter: s,
|
|
85
93
|
onMouseLeave: u,
|
|
86
94
|
onFocus: s,
|
|
87
|
-
onBlur:
|
|
88
|
-
onClick:
|
|
95
|
+
onBlur: ee,
|
|
96
|
+
onClick: te
|
|
89
97
|
}
|
|
90
|
-
}),
|
|
91
|
-
() =>
|
|
98
|
+
}), oe = w(
|
|
99
|
+
() => l ? {
|
|
92
100
|
onMouseEnter: s,
|
|
93
101
|
onMouseLeave: u
|
|
94
|
-
}
|
|
95
|
-
[s, u]
|
|
96
|
-
), { trigger:
|
|
102
|
+
} : {},
|
|
103
|
+
[l, s, u]
|
|
104
|
+
), { trigger: ne, id: se } = Me({
|
|
97
105
|
children: a,
|
|
98
|
-
showOnlyWhenTruncated:
|
|
99
|
-
truncateMaxWidth:
|
|
100
|
-
truncateMaxLines:
|
|
101
|
-
isBlock:
|
|
102
|
-
mergedReferenceRef:
|
|
103
|
-
mergedEvents:
|
|
106
|
+
showOnlyWhenTruncated: c,
|
|
107
|
+
truncateMaxWidth: P,
|
|
108
|
+
truncateMaxLines: A,
|
|
109
|
+
isBlock: C,
|
|
110
|
+
mergedReferenceRef: W,
|
|
111
|
+
mergedEvents: re
|
|
104
112
|
});
|
|
105
|
-
return /* @__PURE__ */
|
|
106
|
-
/* @__PURE__ */
|
|
113
|
+
return /* @__PURE__ */ H(ie, { children: [
|
|
114
|
+
/* @__PURE__ */ g(xe, { children: /* @__PURE__ */ g(we, { mounted: !x && m, children: (e) => /* @__PURE__ */ H(
|
|
107
115
|
"div",
|
|
108
116
|
{
|
|
109
|
-
id:
|
|
117
|
+
id: se,
|
|
110
118
|
tabIndex: -1,
|
|
111
119
|
role: "tooltip",
|
|
112
|
-
ref:
|
|
113
|
-
className:
|
|
120
|
+
ref: $,
|
|
121
|
+
className: L.wgTooltip,
|
|
114
122
|
...j,
|
|
115
123
|
style: {
|
|
116
124
|
left: X,
|
|
117
125
|
top: Y,
|
|
118
126
|
...e,
|
|
119
127
|
..._,
|
|
120
|
-
zIndex:
|
|
121
|
-
visibility:
|
|
122
|
-
pointerEvents:
|
|
128
|
+
zIndex: Q,
|
|
129
|
+
visibility: h.hide?.referenceHidden ? "hidden" : void 0,
|
|
130
|
+
pointerEvents: !l || h.hide?.referenceHidden ? "none" : void 0
|
|
123
131
|
},
|
|
124
|
-
...
|
|
132
|
+
...oe,
|
|
125
133
|
children: [
|
|
126
|
-
|
|
127
|
-
/* @__PURE__ */
|
|
128
|
-
|
|
134
|
+
N,
|
|
135
|
+
/* @__PURE__ */ g(
|
|
136
|
+
Re,
|
|
129
137
|
{
|
|
130
138
|
"aria-hidden": "true",
|
|
131
|
-
ref:
|
|
132
|
-
className:
|
|
139
|
+
ref: F,
|
|
140
|
+
className: L.wgTooltipArrow,
|
|
133
141
|
arrowX: J,
|
|
134
142
|
arrowY: K,
|
|
135
|
-
arrowSize:
|
|
136
|
-
arrowOffset:
|
|
137
|
-
arrowRadius:
|
|
138
|
-
dir:
|
|
143
|
+
arrowSize: G,
|
|
144
|
+
arrowOffset: V,
|
|
145
|
+
arrowRadius: O,
|
|
146
|
+
dir: M,
|
|
139
147
|
placement: q
|
|
140
148
|
}
|
|
141
149
|
)
|
|
142
150
|
]
|
|
143
151
|
}
|
|
144
152
|
) }) }),
|
|
145
|
-
|
|
153
|
+
ne
|
|
146
154
|
] });
|
|
147
155
|
};
|
|
148
156
|
export {
|
|
149
|
-
|
|
157
|
+
Be as Tooltip
|
|
150
158
|
};
|