@wisdomgarden/torque 0.2.0 → 0.2.1

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.
@@ -12,6 +12,6 @@ export declare function useArrowStyle(withArrow: boolean, arrowData: {
12
12
  x?: number;
13
13
  y?: number;
14
14
  } | undefined, resolvedSide: PopoverSide, arrowSize: number): React.CSSProperties;
15
- export declare function useTriggerProps(disabled: boolean, trigger: PopoverTrigger, mergedReferenceRef: React.Ref<HTMLElement>, id: string, toggle: () => void, opened: boolean, setOpen: (next: boolean) => void, hoverTimerRef: React.RefObject<number | undefined>, userOnClick?: React.MouseEventHandler<HTMLElement>, userOnKeyDown?: React.KeyboardEventHandler<HTMLElement>): React.HTMLAttributes<HTMLElement> & {
15
+ export declare function useTriggerProps(disabled: boolean, trigger: PopoverTrigger, mergedReferenceRef: React.Ref<HTMLElement>, id: string, toggle: () => void, opened: boolean, setOpen: (next: boolean) => void, scheduleHover: (next: boolean) => void, cancelHoverTimer: () => void, userOnClick?: React.MouseEventHandler<HTMLElement>, userOnKeyDown?: React.KeyboardEventHandler<HTMLElement>): React.HTMLAttributes<HTMLElement> & {
16
16
  ref?: React.Ref<HTMLElement>;
17
17
  };
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { useEffect as l, useState as m, useRef as b, useCallback as p, useMemo as E } from "react";
3
- import { registerOpenPopover as y, isTopmostOpenPopover as A } from "./popover-stack.js";
4
- function L(u, t = !1) {
5
- const [n, e] = m(t || u), [r, o] = m(
2
+ import { useEffect as l, useState as b, useRef as p, useCallback as y, useMemo as E } from "react";
3
+ import { registerOpenPopover as A, isTopmostOpenPopover as x } from "./popover-stack.js";
4
+ function k(u, t = !1) {
5
+ const [n, e] = b(t || u), [r, o] = b(
6
6
  u ? "open" : "closing"
7
- ), s = b(0);
7
+ ), s = p(0);
8
8
  l(() => (u ? (e(!0), s.current = requestAnimationFrame(() => {
9
9
  s.current = requestAnimationFrame(() => {
10
10
  o("open");
@@ -12,24 +12,24 @@ function L(u, t = !1) {
12
12
  })) : (o("closing"), t && e(!0)), () => {
13
13
  s.current && cancelAnimationFrame(s.current);
14
14
  }), [t, u]);
15
- const i = p(() => {
15
+ const i = y(() => {
16
16
  r === "closing" && !t && e(!1);
17
17
  }, [r, t]);
18
18
  return { mounted: n, animState: r, handleTransitionEnd: i };
19
19
  }
20
- function P(u, t, n, e, r, o, s, i) {
21
- const c = b(null);
20
+ function q(u, t, n, e, r, o, s, i) {
21
+ const f = p(null);
22
22
  l(() => {
23
- u === "click" && (t ? c.current = document.activeElement : o().some(
24
- (f) => f.contains(document.activeElement)
25
- ) && c.current?.focus());
23
+ u === "click" && (t ? f.current = document.activeElement : o().some(
24
+ (a) => a.contains(document.activeElement)
25
+ ) && f.current?.focus());
26
26
  }, [t, u, o]), l(() => {
27
27
  if (u !== "click" || n !== "open" || !e || i) return;
28
28
  if (s?.current) {
29
29
  s.current.focus();
30
30
  return;
31
31
  }
32
- (h([r.current])[0] ?? r.current)?.focus();
32
+ (L([r.current])[0] ?? r.current)?.focus();
33
33
  }, [
34
34
  n,
35
35
  e,
@@ -39,7 +39,7 @@ function P(u, t, n, e, r, o, s, i) {
39
39
  i
40
40
  ]);
41
41
  }
42
- const x = [
42
+ const h = [
43
43
  "a[href]",
44
44
  "button:not([disabled])",
45
45
  "input:not([disabled])",
@@ -47,27 +47,27 @@ const x = [
47
47
  "textarea:not([disabled])",
48
48
  '[tabindex]:not([tabindex="-1"])'
49
49
  ].join(",");
50
- function h(u) {
50
+ function L(u) {
51
51
  const t = u.flatMap((n) => !n || n.inert || n.getAttribute("aria-hidden") === "true" ? [] : Array.from(
52
- n.querySelectorAll(x)
52
+ n.querySelectorAll(h)
53
53
  ));
54
54
  return Array.from(new Set(t)).filter(
55
55
  (n) => !n.hasAttribute("data-focus-sentinel")
56
56
  );
57
57
  }
58
- function C(u, t, n, e, r, o, s) {
58
+ function v(u, t, n, e, r, o, s) {
59
59
  l(() => {
60
60
  if (t)
61
- return y(r, o);
61
+ return A(r, o);
62
62
  }, [o, r, t]), l(() => {
63
63
  if (!u || !t) return;
64
- const i = (c) => {
65
- c.key !== "Escape" || !A(r) || (c.preventDefault(), c.stopImmediatePropagation(), n(), s ? s() : e.current?.focus());
64
+ const i = (f) => {
65
+ f.key !== "Escape" || !x(r) || (f.preventDefault(), f.stopImmediatePropagation(), n(), s ? s() : e.current?.focus());
66
66
  };
67
67
  return document.addEventListener("keydown", i), () => document.removeEventListener("keydown", i);
68
68
  }, [u, t, n, e, r, s]);
69
69
  }
70
- function T(u, t, n, e) {
70
+ function B(u, t, n, e) {
71
71
  return E(() => {
72
72
  if (!u || !t) return {};
73
73
  const r = e / 2, o = {
@@ -78,32 +78,31 @@ function T(u, t, n, e) {
78
78
  return n === "bottom" ? { ...o, top: -r - 1, left: t.x ?? "", bottom: "" } : n === "top" ? { ...o, bottom: -r - 1, left: t.x ?? "", top: "" } : n === "right" ? { ...o, left: -r - 1, top: t.y ?? "" } : n === "left" ? { ...o, right: -r - 1, top: t.y ?? "" } : o;
79
79
  }, [u, t, n, e]);
80
80
  }
81
- function k(u, t, n, e, r, o, s, i, c, f) {
81
+ function F(u, t, n, e, r, o, s, i, f, a, m) {
82
82
  return E(() => u ? { ref: n } : t === "none" ? {
83
83
  ref: n,
84
84
  "aria-expanded": o,
85
- onKeyDown: f
85
+ onKeyDown: m
86
86
  } : t === "hover" ? {
87
87
  ref: n,
88
- onMouseEnter: () => {
89
- clearTimeout(i.current), s(!0);
90
- },
88
+ onMouseEnter: () => i(!0),
91
89
  onMouseLeave: () => {
92
- i.current = window.setTimeout(() => s(!1), 100);
90
+ o ? i(!1) : f();
93
91
  },
94
- onFocus: () => s(!0),
95
- onBlur: () => {
96
- i.current = window.setTimeout(() => s(!1), 100);
92
+ // 键盘聚焦不走 openDelay:延迟打开对读屏 / 键盘用户只有负作用
93
+ onFocus: () => {
94
+ f(), s(!0);
97
95
  },
96
+ onBlur: () => i(!1),
98
97
  "aria-describedby": e,
99
- onKeyDown: f
98
+ onKeyDown: m
100
99
  } : {
101
100
  ref: n,
102
- onClick: (a) => {
103
- r(), c?.(a);
101
+ onClick: (c) => {
102
+ r(), a?.(c);
104
103
  },
105
- onKeyDown: (a) => {
106
- a.key === "Enter" && (a.preventDefault(), r()), f?.(a);
104
+ onKeyDown: (c) => {
105
+ c.key === "Enter" && (c.preventDefault(), r()), m?.(c);
107
106
  },
108
107
  "aria-expanded": o,
109
108
  "aria-haspopup": "dialog",
@@ -117,15 +116,16 @@ function k(u, t, n, e, r, o, s, i, c, f) {
117
116
  o,
118
117
  s,
119
118
  i,
120
- c,
121
- f
119
+ f,
120
+ a,
121
+ m
122
122
  ]);
123
123
  }
124
124
  export {
125
- h as getFocusableElements,
126
- L as useAnimatedMount,
127
- T as useArrowStyle,
128
- C as useEscapeClose,
129
- P as usePopoverFocus,
130
- k as useTriggerProps
125
+ L as getFocusableElements,
126
+ k as useAnimatedMount,
127
+ B as useArrowStyle,
128
+ v as useEscapeClose,
129
+ q as usePopoverFocus,
130
+ F as useTriggerProps
131
131
  };
@@ -1,6 +1,6 @@
1
1
  import { PopoverDropdown } from './popover-dropdown';
2
2
  import { PopoverTarget } from './popover-target';
3
- export declare const Popover: (({ children, position, offset: offsetProp, opened: openedProp, defaultOpened, onOpenChange, disabled, withArrow, arrowSize, trigger, closeOnClickOutside, closeOnEscape, restoreFocus, strategy, initialFocusRef, trapFocus, preventAutoFocus, "aria-labelledby": ariaLabelledby, }: import("./popover.types").PopoverProps) => import("react").JSX.Element) & {
3
+ export declare const Popover: (({ children, position, offset: offsetProp, opened: openedProp, defaultOpened, onOpenChange, disabled, withArrow, arrowSize, trigger, openDelay, closeDelay, closeOnClickOutside, closeOnEscape, restoreFocus, strategy, initialFocusRef, trapFocus, preventAutoFocus, "aria-labelledby": ariaLabelledby, }: import("./popover.types").PopoverProps) => import("react").JSX.Element) & {
4
4
  Target: ({ children, ref, onClick, onKeyDown, ...restProps }: import("./popover.types").PopoverTargetProps) => import("react").JSX.Element;
5
5
  Dropdown: ({ children, arrowClassName, zIndex, width, maxHeight, matchTargetWidth, radius, withinPortal, keepMounted, ref, ...restProps }: import("./popover.types").PopoverDropdownProps) => import("react").JSX.Element | null;
6
6
  };
@@ -1,12 +1,12 @@
1
1
  "use client";
2
- import { jsxs as S, jsx as c } from "react/jsx-runtime";
2
+ import { jsxs as E, jsx as c } from "react/jsx-runtime";
3
3
  import { getDefaultZIndex as te, Portal as re } from "@mantine/core";
4
4
  import { useMergedRef as ne } from "@mantine/hooks";
5
- import { clsx as I } from "clsx";
5
+ import { clsx as S } from "clsx";
6
6
  import { useContext as ie, useRef as ae, useCallback as se } from "react";
7
- import { useAnimatedMount as de, usePopoverFocus as le, useArrowStyle as ce, getFocusableElements as ue } from "./hooks.js";
8
- import { PopoverLayerContext as M, usePopoverContext as fe } from "./popover-context.js";
9
- import T from "./styles/popover.module.css.js";
7
+ import { useAnimatedMount as le, usePopoverFocus as de, useArrowStyle as ce, getFocusableElements as ue } from "./hooks.js";
8
+ import { PopoverLayerContext as I, usePopoverContext as fe } from "./popover-context.js";
9
+ import M from "./styles/popover.module.css.js";
10
10
  const Fe = ({
11
11
  children: A,
12
12
  arrowClassName: C,
@@ -15,56 +15,56 @@ const Fe = ({
15
15
  maxHeight: a,
16
16
  matchTargetWidth: N = !1,
17
17
  radius: z = "sm",
18
- withinPortal: L = !0,
19
- keepMounted: Z = !1,
20
- ref: j,
18
+ withinPortal: H = !0,
19
+ keepMounted: L = !1,
20
+ ref: T,
21
21
  ...e
22
22
  }) => {
23
- const u = ie(M), {
23
+ const u = ie(I), {
24
24
  opened: r,
25
25
  trigger: n,
26
- strategy: k,
27
- x: W,
28
- y: $,
26
+ strategy: Z,
27
+ x: j,
28
+ y: k,
29
29
  resolvedSide: f,
30
30
  middlewareData: s,
31
- floatingRef: d,
32
- setFloating: H,
31
+ floatingRef: l,
32
+ setFloating: W,
33
33
  registerNestedFloatingElement: p,
34
34
  getFloatingScopeElements: v,
35
35
  withArrow: m,
36
- arrowSize: O,
36
+ arrowSize: $,
37
37
  arrowRef: P,
38
- hoverTimerRef: g,
39
- setOpen: V,
40
- id: q,
41
- initialFocusRef: B,
42
- trapFocus: h,
43
- preventAutoFocus: G,
44
- ariaLabelledby: J
45
- } = fe(), { mounted: x, animState: w, handleTransitionEnd: K } = de(
38
+ scheduleHover: V,
39
+ cancelHoverTimer: q,
40
+ id: B,
41
+ initialFocusRef: G,
42
+ trapFocus: g,
43
+ preventAutoFocus: J,
44
+ ariaLabelledby: K
45
+ } = fe(), { mounted: h, animState: x, handleTransitionEnd: O } = le(
46
46
  r,
47
- Z
47
+ L
48
48
  ), y = ae(null), Q = se(
49
49
  (o) => {
50
50
  y.current?.(), y.current = o ? p(o) : null;
51
51
  },
52
52
  [p]
53
53
  ), U = ne(
54
- d,
55
- H,
54
+ l,
55
+ W,
56
56
  Q,
57
- j
58
- ), l = D ?? (u === null ? te("popover") : u + 1);
59
- le(
57
+ T
58
+ ), d = D ?? (u === null ? te("popover") : u + 1);
59
+ de(
60
60
  n,
61
61
  r,
62
- w,
63
62
  x,
64
- d,
63
+ h,
64
+ l,
65
65
  v,
66
- B,
67
- G
66
+ G,
67
+ J
68
68
  );
69
69
  const b = (o) => /* @__PURE__ */ c(
70
70
  "span",
@@ -76,7 +76,7 @@ const Fe = ({
76
76
  onFocus: () => {
77
77
  const i = ue(v());
78
78
  if (i.length === 0) {
79
- d.current?.focus();
79
+ l.current?.focus();
80
80
  return;
81
81
  }
82
82
  (o === "start" ? i[i.length - 1] : i[0]).focus();
@@ -86,63 +86,58 @@ const Fe = ({
86
86
  m,
87
87
  s.arrow,
88
88
  f,
89
- O
89
+ $
90
90
  ), Y = typeof t == "number" ? `${t}px` : t, _ = t ? Y : void 0, ee = typeof a == "number" ? `${a}px` : a, oe = N ? "var(--t-popover-reference-width)" : _;
91
- if (!x) return null;
92
- const F = "role" in e ? e.role : n === "click" ? "dialog" : void 0, R = F === "dialog", E = /* @__PURE__ */ S(
91
+ if (!h) return null;
92
+ const w = "role" in e ? e.role : n === "click" ? "dialog" : void 0, F = w === "dialog", R = /* @__PURE__ */ E(
93
93
  "div",
94
94
  {
95
- id: q,
96
- role: F,
97
- "aria-modal": R ? !1 : void 0,
98
- "aria-labelledby": R ? J : void 0,
95
+ id: B,
96
+ role: w,
97
+ "aria-modal": F ? !1 : void 0,
98
+ "aria-labelledby": F ? K : void 0,
99
99
  ref: U,
100
100
  tabIndex: -1,
101
- "data-state": w,
101
+ "data-state": x,
102
102
  "data-radius": z,
103
103
  "data-side": f,
104
104
  style: {
105
- position: k,
106
- left: W ?? 0,
107
- top: $ ?? 0,
108
- zIndex: l,
109
- "--t-popover-z": l,
105
+ position: Z,
106
+ left: j ?? 0,
107
+ top: k ?? 0,
108
+ zIndex: d,
109
+ "--t-popover-z": d,
110
110
  "--t-popover-width": oe,
111
111
  "--t-popover-max-height": ee,
112
112
  visibility: s.hide?.referenceHidden ? "hidden" : void 0,
113
113
  pointerEvents: s.hide?.referenceHidden ? "none" : void 0
114
114
  },
115
- onTransitionEnd: K,
116
- onMouseEnter: n === "hover" ? () => clearTimeout(g.current) : void 0,
117
- onMouseLeave: n === "hover" ? () => {
118
- g.current = window.setTimeout(
119
- () => V(!1),
120
- 100
121
- );
122
- } : void 0,
115
+ onTransitionEnd: O,
116
+ onMouseEnter: n === "hover" ? () => q() : void 0,
117
+ onMouseLeave: n === "hover" ? () => V(!1) : void 0,
123
118
  ...e,
124
119
  "aria-hidden": r ? e["aria-hidden"] : !0,
125
120
  inert: r ? e.inert : !0,
126
- className: I(T.popover, e.className),
121
+ className: S(M.popover, e.className),
127
122
  children: [
128
- /* @__PURE__ */ S(M.Provider, { value: l, children: [
129
- h && b("start"),
123
+ /* @__PURE__ */ E(I.Provider, { value: d, children: [
124
+ g && b("start"),
130
125
  A,
131
- h && b("end")
126
+ g && b("end")
132
127
  ] }),
133
128
  m && /* @__PURE__ */ c(
134
129
  "div",
135
130
  {
136
131
  ref: P,
137
132
  "aria-hidden": "true",
138
- className: I(T.arrow, C),
133
+ className: S(M.arrow, C),
139
134
  style: { ...X }
140
135
  }
141
136
  )
142
137
  ]
143
138
  }
144
139
  );
145
- return L ? /* @__PURE__ */ c(re, { children: E }) : E;
140
+ return H ? /* @__PURE__ */ c(re, { children: R }) : R;
146
141
  };
147
142
  export {
148
143
  Fe as PopoverDropdown
@@ -1,39 +1,41 @@
1
1
  "use client";
2
2
  import { jsx as b } from "react/jsx-runtime";
3
- import { useMergedRef as v } from "@mantine/hooks";
4
- import { clsx as T } from "clsx";
3
+ import { useMergedRef as T } from "@mantine/hooks";
4
+ import { clsx as E } from "clsx";
5
5
  import r from "react";
6
- import { useTriggerProps as E } from "./hooks.js";
6
+ import { useTriggerProps as H } from "./hooks.js";
7
7
  import { usePopoverContext as N } from "./popover-context.js";
8
8
  import P from "./styles/popover.module.css.js";
9
9
  const q = ({
10
10
  children: e,
11
11
  ref: s,
12
12
  onClick: m,
13
- onKeyDown: f,
13
+ onKeyDown: i,
14
14
  ...o
15
15
  }) => {
16
16
  const {
17
- disabled: i,
18
- trigger: n,
19
- id: a,
20
- toggle: p,
17
+ disabled: n,
18
+ trigger: a,
19
+ id: f,
20
+ toggle: c,
21
21
  opened: l,
22
- setOpen: c,
23
- hoverTimerRef: g,
24
- referenceRef: d,
25
- setReference: u
26
- } = N(), R = r.isValidElement(e) ? e.props.ref : void 0, x = v(d, u, s, R), t = E(
27
- i,
22
+ setOpen: p,
23
+ scheduleHover: g,
24
+ cancelHoverTimer: d,
25
+ referenceRef: u,
26
+ setReference: R
27
+ } = N(), v = r.isValidElement(e) ? e.props.ref : void 0, x = T(u, R, s, v), t = H(
28
28
  n,
29
- x,
30
29
  a,
31
- p,
32
- l,
30
+ x,
31
+ f,
33
32
  c,
33
+ l,
34
+ p,
34
35
  g,
36
+ d,
35
37
  m,
36
- f
38
+ i
37
39
  );
38
40
  return r.isValidElement(e) ? r.cloneElement(
39
41
  e,
@@ -45,7 +47,7 @@ const q = ({
45
47
  tabIndex: 0,
46
48
  ...t,
47
49
  ...o,
48
- className: T(P.fallbackTarget, o.className),
50
+ className: E(P.fallbackTarget, o.className),
49
51
  children: e
50
52
  }
51
53
  );
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import { PopoverProps } from './popover.types';
3
- export declare const Popover: ({ children, position, offset: offsetProp, opened: openedProp, defaultOpened, onOpenChange, disabled, withArrow, arrowSize, trigger, closeOnClickOutside, closeOnEscape, restoreFocus, strategy, initialFocusRef, trapFocus, preventAutoFocus, "aria-labelledby": ariaLabelledby, }: PopoverProps) => React.JSX.Element;
3
+ export declare const Popover: ({ children, position, offset: offsetProp, opened: openedProp, defaultOpened, onOpenChange, disabled, withArrow, arrowSize, trigger, openDelay, closeDelay, closeOnClickOutside, closeOnEscape, restoreFocus, strategy, initialFocusRef, trapFocus, preventAutoFocus, "aria-labelledby": ariaLabelledby, }: PopoverProps) => React.JSX.Element;
@@ -1,175 +1,194 @@
1
1
  "use client";
2
- import { jsx as ne } from "react/jsx-runtime";
3
- import { offset as oe, flip as se, size as re, shift as le, limitShift as ce, arrow as ae, hide as ie, useFloating as de, autoUpdate as ue } from "@floating-ui/react-dom";
4
- import { useDirection as fe, getFloatingPosition as pe } from "@mantine/core";
5
- import _, { useRef as l, useId as me, useCallback as c, useEffect as ge, useMemo as q } from "react";
6
- import { useEscapeClose as ve } from "./hooks.js";
7
- import { PopoverContext as A } from "./popover-context.js";
8
- const g = 8, ye = ({
9
- children: B,
10
- position: H = "bottom",
11
- offset: y = 8,
12
- opened: C,
13
- defaultOpened: J = !1,
14
- onOpenChange: N,
2
+ import { jsx as ie } from "react/jsx-runtime";
3
+ import { offset as le, flip as ae, size as de, shift as ue, limitShift as fe, arrow as me, hide as pe, useFloating as ge, autoUpdate as ve } from "@floating-ui/react-dom";
4
+ import { useDirection as he, getFloatingPosition as Ee } from "@mantine/core";
5
+ import B, { useRef as l, useId as xe, useCallback as r, useEffect as J, useMemo as K } from "react";
6
+ import { useEscapeClose as Re } from "./hooks.js";
7
+ import { PopoverContext as Q } from "./popover-context.js";
8
+ const v = 8, Te = ({
9
+ children: W,
10
+ position: X = "bottom",
11
+ offset: C = 8,
12
+ opened: N,
13
+ defaultOpened: Y = !1,
14
+ onOpenChange: T,
15
15
  disabled: b = !1,
16
- withArrow: r = !1,
16
+ withArrow: i = !1,
17
17
  arrowSize: a = 8,
18
- trigger: D = "click",
19
- closeOnClickOutside: I = !0,
20
- closeOnEscape: K = !0,
21
- restoreFocus: Q,
22
- strategy: v = "absolute",
23
- initialFocusRef: L,
24
- trapFocus: M = !1,
25
- preventAutoFocus: S = !1,
26
- "aria-labelledby": $
18
+ trigger: I = "click",
19
+ openDelay: L = 0,
20
+ closeDelay: M = 100,
21
+ closeOnClickOutside: S = !0,
22
+ closeOnEscape: Z = !0,
23
+ restoreFocus: z,
24
+ strategy: h = "absolute",
25
+ initialFocusRef: $,
26
+ trapFocus: D = !1,
27
+ preventAutoFocus: G = !1,
28
+ "aria-labelledby": H
27
29
  }) => {
28
- const h = _.useContext(A), G = h?.registerNestedFloatingElement, x = h ? h.depth + 1 : 0, E = C !== void 0, [W, X] = _.useState(J), t = E ? C : W, i = l(null), d = l(null), u = l(null), R = l(/* @__PURE__ */ new Set()), T = l(0), F = me(), { dir: Y } = fe(), o = c(
30
+ const E = B.useContext(Q), j = E?.registerNestedFloatingElement, x = E ? E.depth + 1 : 0, R = N !== void 0, [ee, te] = B.useState(Y), o = R ? N : ee, d = l(null), u = l(null), f = l(null), F = l(/* @__PURE__ */ new Set()), P = l(void 0), y = xe(), { dir: ne } = he(), n = r(
29
31
  (e) => {
30
- E || X(e), N?.(e);
32
+ R || te(e), T?.(e);
31
33
  },
32
- [E, N]
33
- ), P = c(() => o(!1), [o]), j = c(() => o(!t), [t, o]), k = c(
34
+ [R, T]
35
+ ), w = r(() => n(!1), [n]), k = r(() => n(!o), [o, n]), s = r(() => {
36
+ window.clearTimeout(P.current), P.current = void 0;
37
+ }, []), O = r(
34
38
  (e) => {
35
- R.current.add(e);
36
- const n = G?.(e);
39
+ s();
40
+ const t = e ? L : M;
41
+ if (t <= 0) {
42
+ n(e);
43
+ return;
44
+ }
45
+ P.current = window.setTimeout(() => n(e), t);
46
+ },
47
+ [s, L, M, n]
48
+ );
49
+ J(() => s, [s]);
50
+ const U = r(
51
+ (e) => {
52
+ F.current.add(e);
53
+ const t = j?.(e);
37
54
  return () => {
38
- R.current.delete(e), n?.();
55
+ F.current.delete(e), t?.();
39
56
  };
40
57
  },
41
- [G]
42
- ), f = c(() => {
43
- const e = u.current ? [u.current] : [];
44
- return R.current.forEach((n) => {
45
- n.isConnected && e.push(n);
58
+ [j]
59
+ ), m = r(() => {
60
+ const e = f.current ? [f.current] : [];
61
+ return F.current.forEach((t) => {
62
+ t.isConnected && e.push(t);
46
63
  }), Array.from(new Set(e));
47
64
  }, []);
48
- ge(() => {
49
- if (!I || !t) return;
50
- const e = (n) => {
51
- const m = n.composedPath(), s = d.current;
52
- s && m.includes(s) || f().some((te) => m.includes(te)) || P();
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();
53
70
  };
54
71
  return document.addEventListener("mousedown", e, !0), document.addEventListener("touchstart", e, !0), () => {
55
72
  document.removeEventListener("mousedown", e, !0), document.removeEventListener("touchstart", e, !0);
56
73
  };
57
- }, [I, t, P, f]), ve(
58
- K,
59
- t,
60
- P,
61
- d,
62
- F,
74
+ }, [S, o, w, m]), Re(
75
+ Z,
76
+ o,
77
+ w,
78
+ u,
79
+ y,
63
80
  x,
64
- Q
81
+ z
65
82
  );
66
- const Z = q(
83
+ const oe = K(
67
84
  () => [
68
- oe(y + (r ? a / 2 : 0)),
69
- se({ padding: g }),
85
+ le(C + (i ? a / 2 : 0)),
86
+ ae({ padding: v }),
70
87
  // 必须在 shift 之前:否则 availableHeight 是 shift 推动后的位置算出的(≈整屏),高度约束失效
71
- re({
72
- padding: g,
73
- apply({ availableWidth: e, availableHeight: n, rects: m, elements: s }) {
74
- s.floating.style.setProperty(
88
+ de({
89
+ padding: v,
90
+ apply({ availableWidth: e, availableHeight: t, rects: g, elements: c }) {
91
+ c.floating.style.setProperty(
75
92
  "--t-popover-available-width",
76
93
  `${Math.max(0, e)}px`
77
- ), s.floating.style.setProperty(
94
+ ), c.floating.style.setProperty(
78
95
  "--t-popover-available-height",
79
- `${Math.max(0, n)}px`
80
- ), s.floating.style.setProperty(
96
+ `${Math.max(0, t)}px`
97
+ ), c.floating.style.setProperty(
81
98
  "--t-popover-reference-width",
82
- `${m.reference.width}px`
99
+ `${g.reference.width}px`
83
100
  );
84
101
  }
85
102
  }),
86
- le({
87
- padding: g,
103
+ ue({
104
+ padding: v,
88
105
  crossAxis: !0,
89
106
  mainAxis: !0,
90
- limiter: ce()
107
+ limiter: fe()
91
108
  }),
92
- ...r ? (
109
+ ...i ? (
93
110
  // floating-ui 的 arrow 中间件按设计就是收一个 ref 对象(它在定位阶段自己读
94
111
  // .current),不是我们在渲染期读 ref 的值。没有保留该 API 的改写方式。
95
112
  // eslint-disable-next-line react-hooks/refs
96
- [ae({ element: i, padding: g })]
113
+ [me({ element: d, padding: v })]
97
114
  ) : [],
98
- ie()
115
+ pe()
99
116
  ],
100
- [y, r, a, i]
117
+ [C, i, a, d]
101
118
  ), {
102
- x: w,
103
- y: O,
119
+ x: V,
120
+ y: _,
104
121
  refs: p,
105
- placement: z,
106
- middlewareData: U
107
- } = de({
108
- open: t,
109
- strategy: v,
110
- placement: pe(Y, H),
111
- middleware: Z,
112
- whileElementsMounted: ue
113
- }), V = z.split("-")[0], ee = q(
122
+ placement: re,
123
+ middlewareData: q
124
+ } = ge({
125
+ open: o,
126
+ strategy: h,
127
+ placement: Ee(ne, X),
128
+ middleware: oe,
129
+ whileElementsMounted: ve
130
+ }), A = re.split("-")[0], se = K(
114
131
  () => ({
115
- opened: t,
116
- setOpen: o,
117
- toggle: j,
118
- trigger: D,
132
+ opened: o,
133
+ setOpen: n,
134
+ toggle: k,
135
+ trigger: I,
119
136
  disabled: b,
120
- id: F,
121
- withArrow: r,
137
+ id: y,
138
+ withArrow: i,
122
139
  arrowSize: a,
123
- x: w,
124
- y: O,
125
- strategy: v,
126
- resolvedSide: V,
127
- middlewareData: U,
128
- hoverTimerRef: T,
129
- referenceRef: d,
130
- floatingRef: u,
131
- arrowRef: i,
140
+ x: V,
141
+ y: _,
142
+ strategy: h,
143
+ resolvedSide: A,
144
+ middlewareData: q,
145
+ scheduleHover: O,
146
+ cancelHoverTimer: s,
147
+ referenceRef: u,
148
+ floatingRef: f,
149
+ arrowRef: d,
132
150
  setReference: p.setReference,
133
151
  setFloating: p.setFloating,
134
152
  depth: x,
135
- registerNestedFloatingElement: k,
136
- getFloatingScopeElements: f,
137
- initialFocusRef: L,
138
- trapFocus: M,
139
- preventAutoFocus: S,
140
- ariaLabelledby: $
153
+ registerNestedFloatingElement: U,
154
+ getFloatingScopeElements: m,
155
+ initialFocusRef: $,
156
+ trapFocus: D,
157
+ preventAutoFocus: G,
158
+ ariaLabelledby: H
141
159
  }),
142
160
  [
143
- t,
144
161
  o,
145
- j,
146
- D,
162
+ n,
163
+ k,
164
+ I,
147
165
  b,
148
- F,
149
- r,
166
+ y,
167
+ i,
150
168
  a,
151
- w,
152
- O,
153
- v,
154
169
  V,
155
- U,
156
- T,
157
- d,
170
+ _,
171
+ h,
172
+ A,
173
+ q,
174
+ O,
175
+ s,
158
176
  u,
159
- i,
177
+ f,
178
+ d,
160
179
  p.setReference,
161
180
  p.setFloating,
162
181
  x,
163
- k,
164
- f,
165
- L,
166
- M,
167
- S,
168
- $
182
+ U,
183
+ m,
184
+ $,
185
+ D,
186
+ G,
187
+ H
169
188
  ]
170
189
  );
171
- return /* @__PURE__ */ ne(A.Provider, { value: ee, children: B });
190
+ return /* @__PURE__ */ ie(Q.Provider, { value: se, children: W });
172
191
  };
173
192
  export {
174
- ye as Popover
193
+ Te as Popover
175
194
  };
@@ -55,6 +55,18 @@ export interface PopoverProps {
55
55
  * @default 'click'
56
56
  */
57
57
  trigger?: PopoverTrigger;
58
+ /**
59
+ * hover 打开延迟(ms),0 表示立即打开。
60
+ * 仅 `trigger="hover"` 的鼠标移入生效;键盘聚焦始终立即打开。
61
+ * @default 0
62
+ */
63
+ openDelay?: number;
64
+ /**
65
+ * hover 关闭延迟(ms),留出鼠标从触发元素移动到浮层的时间。
66
+ * 仅 `trigger="hover"` 生效。
67
+ * @default 100
68
+ */
69
+ closeDelay?: number;
58
70
  /**
59
71
  * 点击外部区域时关闭
60
72
  * @default true
@@ -188,7 +200,10 @@ export interface PopoverContextValue {
188
200
  escaped?: boolean;
189
201
  };
190
202
  };
191
- hoverTimerRef: React.MutableRefObject<number | undefined>;
203
+ /** hover 触发的延迟开关调度:同一时刻只保留一个待执行任务,延迟为 0 时同步执行 */
204
+ scheduleHover: (next: boolean) => void;
205
+ /** 取消尚未执行的 hover 开关任务 */
206
+ cancelHoverTimer: () => void;
192
207
  referenceRef: React.RefObject<HTMLElement | null>;
193
208
  floatingRef: React.RefObject<HTMLDivElement | null>;
194
209
  arrowRef: React.RefObject<HTMLDivElement | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wisdomgarden/torque",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Torque Design — Wisdom Garden's base UI component library for React.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",