@wisdomgarden/torque 0.2.1 → 0.2.2
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isDev: () => boolean;
|
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { offset as
|
|
4
|
-
import { useDirection as
|
|
5
|
-
import
|
|
2
|
+
import { jsx as le } from "react/jsx-runtime";
|
|
3
|
+
import { offset as ae, flip as de, size as ue, shift as fe, limitShift as me, arrow as pe, hide as he, useFloating as ve, autoUpdate as ge } from "@floating-ui/react-dom";
|
|
4
|
+
import { useDirection as Ee, getFloatingPosition as we } from "@mantine/core";
|
|
5
|
+
import K, { useRef as c, useId as xe, useCallback as r, useEffect as D, useMemo as Q } from "react";
|
|
6
|
+
import { isDev as Pe } from "../../common/is-dev.js";
|
|
6
7
|
import { useEscapeClose as Re } from "./hooks.js";
|
|
7
|
-
import { PopoverContext as
|
|
8
|
-
const
|
|
9
|
-
children:
|
|
10
|
-
position:
|
|
11
|
-
offset:
|
|
12
|
-
opened:
|
|
13
|
-
defaultOpened:
|
|
14
|
-
onOpenChange:
|
|
15
|
-
disabled:
|
|
16
|
-
withArrow:
|
|
17
|
-
arrowSize:
|
|
18
|
-
trigger:
|
|
8
|
+
import { PopoverContext as W } from "./popover-context.js";
|
|
9
|
+
const w = 8, Ie = ({
|
|
10
|
+
children: X,
|
|
11
|
+
position: Y = "bottom",
|
|
12
|
+
offset: N = 8,
|
|
13
|
+
opened: T,
|
|
14
|
+
defaultOpened: Z = !1,
|
|
15
|
+
onOpenChange: u,
|
|
16
|
+
disabled: I = !1,
|
|
17
|
+
withArrow: l = !1,
|
|
18
|
+
arrowSize: f = 8,
|
|
19
|
+
trigger: a = "click",
|
|
19
20
|
openDelay: L = 0,
|
|
20
21
|
closeDelay: M = 100,
|
|
21
|
-
closeOnClickOutside:
|
|
22
|
-
closeOnEscape:
|
|
23
|
-
restoreFocus:
|
|
24
|
-
strategy:
|
|
25
|
-
initialFocusRef:
|
|
26
|
-
trapFocus:
|
|
27
|
-
preventAutoFocus:
|
|
28
|
-
"aria-labelledby":
|
|
22
|
+
closeOnClickOutside: $ = !0,
|
|
23
|
+
closeOnEscape: z = !0,
|
|
24
|
+
restoreFocus: ee,
|
|
25
|
+
strategy: x = "absolute",
|
|
26
|
+
initialFocusRef: S,
|
|
27
|
+
trapFocus: G = !1,
|
|
28
|
+
preventAutoFocus: H = !1,
|
|
29
|
+
"aria-labelledby": j
|
|
29
30
|
}) => {
|
|
30
|
-
const
|
|
31
|
+
const P = K.useContext(W), k = P?.registerNestedFloatingElement, R = P ? P.depth + 1 : 0, d = T !== void 0, [te, ne] = K.useState(Z), o = d ? T : te, m = c(null), p = c(null), h = c(null), y = c(/* @__PURE__ */ new Set()), F = c(void 0), b = xe(), { dir: oe } = Ee(), n = r(
|
|
31
32
|
(e) => {
|
|
32
|
-
|
|
33
|
+
d || ne(e), u?.(e);
|
|
33
34
|
},
|
|
34
|
-
[
|
|
35
|
-
),
|
|
36
|
-
window.clearTimeout(
|
|
35
|
+
[d, u]
|
|
36
|
+
), C = r(() => n(!1), [n]), q = r(() => n(!o), [o, n]), s = r(() => {
|
|
37
|
+
window.clearTimeout(F.current), F.current = void 0;
|
|
37
38
|
}, []), O = r(
|
|
38
39
|
(e) => {
|
|
39
40
|
s();
|
|
@@ -42,153 +43,159 @@ const v = 8, Te = ({
|
|
|
42
43
|
n(e);
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
F.current = window.setTimeout(() => n(e), t);
|
|
46
47
|
},
|
|
47
48
|
[s, L, M, n]
|
|
48
49
|
);
|
|
49
|
-
|
|
50
|
-
const U =
|
|
50
|
+
D(() => s, [s]);
|
|
51
|
+
const U = c(!1);
|
|
52
|
+
D(() => {
|
|
53
|
+
!Pe() || U.current || !d || a === "none" || u || (U.current = !0, console.warn(
|
|
54
|
+
`[@wisdomgarden/torque] <Popover trigger="${a}"> 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.`
|
|
55
|
+
));
|
|
56
|
+
}, [d, a, u]);
|
|
57
|
+
const V = r(
|
|
51
58
|
(e) => {
|
|
52
|
-
|
|
53
|
-
const t =
|
|
59
|
+
y.current.add(e);
|
|
60
|
+
const t = k?.(e);
|
|
54
61
|
return () => {
|
|
55
|
-
|
|
62
|
+
y.current.delete(e), t?.();
|
|
56
63
|
};
|
|
57
64
|
},
|
|
58
|
-
[
|
|
59
|
-
),
|
|
60
|
-
const e =
|
|
61
|
-
return
|
|
65
|
+
[k]
|
|
66
|
+
), v = r(() => {
|
|
67
|
+
const e = h.current ? [h.current] : [];
|
|
68
|
+
return y.current.forEach((t) => {
|
|
62
69
|
t.isConnected && e.push(t);
|
|
63
70
|
}), Array.from(new Set(e));
|
|
64
71
|
}, []);
|
|
65
|
-
|
|
66
|
-
if (
|
|
72
|
+
D(() => {
|
|
73
|
+
if (!$ || !o) return;
|
|
67
74
|
const e = (t) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
75
|
+
const E = t.composedPath(), i = p.current;
|
|
76
|
+
i && E.includes(i) || v().some((ce) => E.includes(ce)) || C();
|
|
70
77
|
};
|
|
71
78
|
return document.addEventListener("mousedown", e, !0), document.addEventListener("touchstart", e, !0), () => {
|
|
72
79
|
document.removeEventListener("mousedown", e, !0), document.removeEventListener("touchstart", e, !0);
|
|
73
80
|
};
|
|
74
|
-
}, [
|
|
75
|
-
|
|
81
|
+
}, [$, o, C, v]), Re(
|
|
82
|
+
z,
|
|
76
83
|
o,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
C,
|
|
85
|
+
p,
|
|
86
|
+
b,
|
|
87
|
+
R,
|
|
88
|
+
ee
|
|
82
89
|
);
|
|
83
|
-
const
|
|
90
|
+
const re = Q(
|
|
84
91
|
() => [
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
ae(N + (l ? f / 2 : 0)),
|
|
93
|
+
de({ padding: w }),
|
|
87
94
|
// 必须在 shift 之前:否则 availableHeight 是 shift 推动后的位置算出的(≈整屏),高度约束失效
|
|
88
|
-
|
|
89
|
-
padding:
|
|
90
|
-
apply({ availableWidth: e, availableHeight: t, rects:
|
|
91
|
-
|
|
95
|
+
ue({
|
|
96
|
+
padding: w,
|
|
97
|
+
apply({ availableWidth: e, availableHeight: t, rects: E, elements: i }) {
|
|
98
|
+
i.floating.style.setProperty(
|
|
92
99
|
"--t-popover-available-width",
|
|
93
100
|
`${Math.max(0, e)}px`
|
|
94
|
-
),
|
|
101
|
+
), i.floating.style.setProperty(
|
|
95
102
|
"--t-popover-available-height",
|
|
96
103
|
`${Math.max(0, t)}px`
|
|
97
|
-
),
|
|
104
|
+
), i.floating.style.setProperty(
|
|
98
105
|
"--t-popover-reference-width",
|
|
99
|
-
`${
|
|
106
|
+
`${E.reference.width}px`
|
|
100
107
|
);
|
|
101
108
|
}
|
|
102
109
|
}),
|
|
103
|
-
|
|
104
|
-
padding:
|
|
110
|
+
fe({
|
|
111
|
+
padding: w,
|
|
105
112
|
crossAxis: !0,
|
|
106
113
|
mainAxis: !0,
|
|
107
|
-
limiter:
|
|
114
|
+
limiter: me()
|
|
108
115
|
}),
|
|
109
|
-
...
|
|
116
|
+
...l ? (
|
|
110
117
|
// floating-ui 的 arrow 中间件按设计就是收一个 ref 对象(它在定位阶段自己读
|
|
111
118
|
// .current),不是我们在渲染期读 ref 的值。没有保留该 API 的改写方式。
|
|
112
119
|
// eslint-disable-next-line react-hooks/refs
|
|
113
|
-
[
|
|
120
|
+
[pe({ element: m, padding: w })]
|
|
114
121
|
) : [],
|
|
115
|
-
|
|
122
|
+
he()
|
|
116
123
|
],
|
|
117
|
-
[
|
|
124
|
+
[N, l, f, m]
|
|
118
125
|
), {
|
|
119
|
-
x:
|
|
120
|
-
y:
|
|
121
|
-
refs:
|
|
122
|
-
placement:
|
|
123
|
-
middlewareData:
|
|
124
|
-
} =
|
|
126
|
+
x: _,
|
|
127
|
+
y: A,
|
|
128
|
+
refs: g,
|
|
129
|
+
placement: se,
|
|
130
|
+
middlewareData: B
|
|
131
|
+
} = ve({
|
|
125
132
|
open: o,
|
|
126
|
-
strategy:
|
|
127
|
-
placement:
|
|
128
|
-
middleware:
|
|
129
|
-
whileElementsMounted:
|
|
130
|
-
}),
|
|
133
|
+
strategy: x,
|
|
134
|
+
placement: we(oe, Y),
|
|
135
|
+
middleware: re,
|
|
136
|
+
whileElementsMounted: ge
|
|
137
|
+
}), J = se.split("-")[0], ie = Q(
|
|
131
138
|
() => ({
|
|
132
139
|
opened: o,
|
|
133
140
|
setOpen: n,
|
|
134
|
-
toggle:
|
|
135
|
-
trigger:
|
|
136
|
-
disabled:
|
|
137
|
-
id:
|
|
138
|
-
withArrow:
|
|
139
|
-
arrowSize:
|
|
140
|
-
x:
|
|
141
|
-
y:
|
|
142
|
-
strategy:
|
|
143
|
-
resolvedSide:
|
|
144
|
-
middlewareData:
|
|
141
|
+
toggle: q,
|
|
142
|
+
trigger: a,
|
|
143
|
+
disabled: I,
|
|
144
|
+
id: b,
|
|
145
|
+
withArrow: l,
|
|
146
|
+
arrowSize: f,
|
|
147
|
+
x: _,
|
|
148
|
+
y: A,
|
|
149
|
+
strategy: x,
|
|
150
|
+
resolvedSide: J,
|
|
151
|
+
middlewareData: B,
|
|
145
152
|
scheduleHover: O,
|
|
146
153
|
cancelHoverTimer: s,
|
|
147
|
-
referenceRef:
|
|
148
|
-
floatingRef:
|
|
149
|
-
arrowRef:
|
|
150
|
-
setReference:
|
|
151
|
-
setFloating:
|
|
152
|
-
depth:
|
|
153
|
-
registerNestedFloatingElement:
|
|
154
|
-
getFloatingScopeElements:
|
|
155
|
-
initialFocusRef:
|
|
156
|
-
trapFocus:
|
|
157
|
-
preventAutoFocus:
|
|
158
|
-
ariaLabelledby:
|
|
154
|
+
referenceRef: p,
|
|
155
|
+
floatingRef: h,
|
|
156
|
+
arrowRef: m,
|
|
157
|
+
setReference: g.setReference,
|
|
158
|
+
setFloating: g.setFloating,
|
|
159
|
+
depth: R,
|
|
160
|
+
registerNestedFloatingElement: V,
|
|
161
|
+
getFloatingScopeElements: v,
|
|
162
|
+
initialFocusRef: S,
|
|
163
|
+
trapFocus: G,
|
|
164
|
+
preventAutoFocus: H,
|
|
165
|
+
ariaLabelledby: j
|
|
159
166
|
}),
|
|
160
167
|
[
|
|
161
168
|
o,
|
|
162
169
|
n,
|
|
163
|
-
|
|
170
|
+
q,
|
|
171
|
+
a,
|
|
164
172
|
I,
|
|
165
173
|
b,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
a,
|
|
169
|
-
V,
|
|
174
|
+
l,
|
|
175
|
+
f,
|
|
170
176
|
_,
|
|
171
|
-
h,
|
|
172
177
|
A,
|
|
173
|
-
|
|
178
|
+
x,
|
|
179
|
+
J,
|
|
180
|
+
B,
|
|
174
181
|
O,
|
|
175
182
|
s,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
d,
|
|
179
|
-
p.setReference,
|
|
180
|
-
p.setFloating,
|
|
181
|
-
x,
|
|
182
|
-
U,
|
|
183
|
+
p,
|
|
184
|
+
h,
|
|
183
185
|
m,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
+
g.setReference,
|
|
187
|
+
g.setFloating,
|
|
188
|
+
R,
|
|
189
|
+
V,
|
|
190
|
+
v,
|
|
191
|
+
S,
|
|
186
192
|
G,
|
|
187
|
-
H
|
|
193
|
+
H,
|
|
194
|
+
j
|
|
188
195
|
]
|
|
189
196
|
);
|
|
190
|
-
return /* @__PURE__ */
|
|
197
|
+
return /* @__PURE__ */ le(W.Provider, { value: ie, children: X });
|
|
191
198
|
};
|
|
192
199
|
export {
|
|
193
|
-
|
|
200
|
+
Ie as Popover
|
|
194
201
|
};
|
|
@@ -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;
|
package/dist/provider/hooks.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useContext as n } from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { isDev as r } from "../common/is-dev.js";
|
|
4
|
+
import { UiContext as a } from "./ui-context.js";
|
|
5
|
+
const t = () => n(a), u = () => t().locale, p = () => {
|
|
5
6
|
const { deviceType: e } = t();
|
|
6
7
|
return { deviceType: e };
|
|
7
|
-
},
|
|
8
|
+
}, v = () => {
|
|
8
9
|
const { deviceType: e } = t();
|
|
9
10
|
return {
|
|
10
11
|
isMobile: e === "mobile",
|
|
11
12
|
isTablet: e === "tablet",
|
|
12
13
|
isDesktop: e === "desktop"
|
|
13
14
|
};
|
|
14
|
-
}, o = /* @__PURE__ */ new Set(),
|
|
15
|
-
const { linkComponent:
|
|
16
|
-
return
|
|
15
|
+
}, o = /* @__PURE__ */ new Set(), f = (e) => {
|
|
16
|
+
const { linkComponent: i, hasProvider: s } = t();
|
|
17
|
+
return r() && !s && !o.has(e) && (o.add(e), console.warn(
|
|
17
18
|
`[@wisdomgarden/torque] <${e}> rendered outside <UiProvider>, falling back to a plain <a>. On a host with a router this silently turns client-side navigation into a full page load.`
|
|
18
|
-
)),
|
|
19
|
+
)), i;
|
|
19
20
|
};
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
v as useCheckDevice,
|
|
23
|
+
p as useDeviceType,
|
|
24
|
+
u as useLocale,
|
|
24
25
|
t as useUiContext,
|
|
25
|
-
|
|
26
|
+
f as useUiLink
|
|
26
27
|
};
|