@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.
Files changed (63) hide show
  1. package/dist/common/is-dev.d.ts +1 -0
  2. package/dist/common/is-dev.js +5 -0
  3. package/dist/components/_inner/drawer/base-bottom-drawer.d.ts +1 -1
  4. package/dist/components/_inner/drawer/base-bottom-drawer.js +52 -44
  5. package/dist/components/_inner/menu/_web/menu.web.js +83 -72
  6. package/dist/components/_inner/portal/index.d.ts +1 -0
  7. package/dist/components/_inner/portal/index.js +5 -0
  8. package/dist/components/_inner/portal/portal.d.ts +14 -0
  9. package/dist/components/_inner/portal/portal.js +19 -0
  10. package/dist/components/button/styles/button-variables.module.css.js +1 -1
  11. package/dist/components/drawer/drawer.d.ts +1 -1
  12. package/dist/components/drawer/drawer.js +42 -34
  13. package/dist/components/modal/index.d.ts +1 -1
  14. package/dist/components/modal/modal.d.ts +7 -4
  15. package/dist/components/modal/modal.js +191 -44
  16. package/dist/components/modal/modal.module.css.js +20 -6
  17. package/dist/components/modal/modal.types.d.ts +96 -0
  18. package/dist/components/modal-deprecated/index.d.ts +2 -0
  19. package/dist/components/modal-deprecated/index.js +5 -0
  20. package/dist/components/modal-deprecated/modal-deprecated.d.ts +11 -0
  21. package/dist/components/modal-deprecated/modal-deprecated.js +70 -0
  22. package/dist/components/modal-deprecated/modal-deprecated.module.css.js +10 -0
  23. package/dist/components/notifications/index.d.ts +2 -0
  24. package/dist/components/notifications/index.js +4 -2
  25. package/dist/components/notifications/notifications-container.d.ts +9 -0
  26. package/dist/components/notifications/notifications-container.js +22 -0
  27. package/dist/components/overlay-layer/constants.d.ts +14 -0
  28. package/dist/components/overlay-layer/constants.js +8 -0
  29. package/dist/components/overlay-layer/index.d.ts +5 -0
  30. package/dist/components/overlay-layer/index.js +10 -0
  31. package/dist/components/overlay-layer/overlay-parent-context.d.ts +6 -0
  32. package/dist/components/overlay-layer/overlay-parent-context.js +18 -0
  33. package/dist/components/overlay-layer/overlay-stack-debug.d.ts +24 -0
  34. package/dist/components/overlay-layer/overlay-stack-debug.js +151 -0
  35. package/dist/components/overlay-layer/overlay-stack.d.ts +38 -0
  36. package/dist/components/overlay-layer/overlay-stack.js +137 -0
  37. package/dist/components/overlay-layer/overlay-tier-scope.d.ts +12 -0
  38. package/dist/components/overlay-layer/overlay-tier-scope.js +16 -0
  39. package/dist/components/overlay-layer/types.d.ts +63 -0
  40. package/dist/components/overlay-layer/use-mantine-overlay-layer.d.ts +21 -0
  41. package/dist/components/overlay-layer/use-mantine-overlay-layer.js +24 -0
  42. package/dist/components/overlay-layer/use-overlay-layer.d.ts +26 -0
  43. package/dist/components/overlay-layer/use-overlay-layer.js +77 -0
  44. package/dist/components/popover/hooks.d.ts +0 -1
  45. package/dist/components/popover/hooks.js +69 -83
  46. package/dist/components/popover/popover-context.d.ts +0 -1
  47. package/dist/components/popover/popover-context.js +3 -4
  48. package/dist/components/popover/popover-dropdown.js +110 -91
  49. package/dist/components/popover/popover.js +120 -129
  50. package/dist/components/popover/popover.types.d.ts +18 -5
  51. package/dist/components/tooltip/index.d.ts +10 -2
  52. package/dist/components/tooltip/index.js +100 -92
  53. package/dist/index.css +1 -1
  54. package/dist/index.d.ts +2 -0
  55. package/dist/index.js +193 -182
  56. package/dist/provider/hooks.js +12 -11
  57. package/dist/provider/ui-context.d.ts +10 -0
  58. package/dist/provider/ui-context.js +8 -7
  59. package/dist/provider/ui-provider.d.ts +23 -1
  60. package/dist/provider/ui-provider.js +17 -10
  61. package/package.json +3 -3
  62. package/dist/components/popover/popover-stack.d.ts +0 -10
  63. package/dist/components/popover/popover-stack.js +0 -24
@@ -1,41 +1,40 @@
1
1
  "use client";
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(
2
+ import { useState as m, useRef as A, useEffect as b, useCallback as x, useMemo as E } from "react";
3
+ function F(u, n = !1) {
4
+ const [t, r] = m(n || u), [s, f] = m(
6
5
  u ? "open" : "closing"
7
- ), s = p(0);
8
- l(() => (u ? (e(!0), s.current = requestAnimationFrame(() => {
9
- s.current = requestAnimationFrame(() => {
10
- o("open");
6
+ ), o = A(0);
7
+ b(() => (u ? (r(!0), o.current = requestAnimationFrame(() => {
8
+ o.current = requestAnimationFrame(() => {
9
+ f("open");
11
10
  });
12
- })) : (o("closing"), t && e(!0)), () => {
13
- s.current && cancelAnimationFrame(s.current);
14
- }), [t, u]);
15
- const i = y(() => {
16
- r === "closing" && !t && e(!1);
17
- }, [r, t]);
18
- return { mounted: n, animState: r, handleTransitionEnd: i };
11
+ })) : (f("closing"), n && r(!0)), () => {
12
+ o.current && cancelAnimationFrame(o.current);
13
+ }), [n, u]);
14
+ const i = x(() => {
15
+ s === "closing" && !n && r(!1);
16
+ }, [s, n]);
17
+ return { mounted: t, animState: s, handleTransitionEnd: i };
19
18
  }
20
- function q(u, t, n, e, r, o, s, i) {
21
- const f = p(null);
22
- l(() => {
23
- u === "click" && (t ? f.current = document.activeElement : o().some(
24
- (a) => a.contains(document.activeElement)
25
- ) && f.current?.focus());
26
- }, [t, u, o]), l(() => {
27
- if (u !== "click" || n !== "open" || !e || i) return;
28
- if (s?.current) {
29
- s.current.focus();
19
+ function q(u, n, t, r, s, f, o, i) {
20
+ const e = A(null);
21
+ b(() => {
22
+ u === "click" && (n ? e.current = document.activeElement : f().some(
23
+ (c) => c.contains(document.activeElement)
24
+ ) && e.current?.focus());
25
+ }, [n, u, f]), b(() => {
26
+ if (u !== "click" || t !== "open" || !r || i) return;
27
+ if (o?.current) {
28
+ o.current.focus();
30
29
  return;
31
30
  }
32
- (L([r.current])[0] ?? r.current)?.focus();
31
+ (y([s.current])[0] ?? s.current)?.focus();
33
32
  }, [
34
- n,
35
- e,
36
- u,
33
+ t,
37
34
  r,
35
+ u,
38
36
  s,
37
+ o,
39
38
  i
40
39
  ]);
41
40
  }
@@ -47,85 +46,72 @@ const h = [
47
46
  "textarea:not([disabled])",
48
47
  '[tabindex]:not([tabindex="-1"])'
49
48
  ].join(",");
50
- function L(u) {
51
- const t = u.flatMap((n) => !n || n.inert || n.getAttribute("aria-hidden") === "true" ? [] : Array.from(
52
- n.querySelectorAll(h)
49
+ function y(u) {
50
+ const n = u.flatMap((t) => !t || t.inert || t.getAttribute("aria-hidden") === "true" ? [] : Array.from(
51
+ t.querySelectorAll(h)
53
52
  ));
54
- return Array.from(new Set(t)).filter(
55
- (n) => !n.hasAttribute("data-focus-sentinel")
53
+ return Array.from(new Set(n)).filter(
54
+ (t) => !t.hasAttribute("data-focus-sentinel")
56
55
  );
57
56
  }
58
- function v(u, t, n, e, r, o, s) {
59
- l(() => {
60
- if (t)
61
- return A(r, o);
62
- }, [o, r, t]), l(() => {
63
- if (!u || !t) return;
64
- const i = (f) => {
65
- f.key !== "Escape" || !x(r) || (f.preventDefault(), f.stopImmediatePropagation(), n(), s ? s() : e.current?.focus());
66
- };
67
- return document.addEventListener("keydown", i), () => document.removeEventListener("keydown", i);
68
- }, [u, t, n, e, r, s]);
69
- }
70
- function B(u, t, n, e) {
57
+ function C(u, n, t, r) {
71
58
  return E(() => {
72
- if (!u || !t) return {};
73
- const r = e / 2, o = {
74
- "--t-arrow-size": `${e}px`,
75
- width: e,
76
- height: e
59
+ if (!u || !n) return {};
60
+ const s = r / 2, f = {
61
+ "--t-arrow-size": `${r}px`,
62
+ width: r,
63
+ height: r
77
64
  };
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
- }, [u, t, n, e]);
65
+ return t === "bottom" ? { ...f, top: -s - 1, left: n.x ?? "", bottom: "" } : t === "top" ? { ...f, bottom: -s - 1, left: n.x ?? "", top: "" } : t === "right" ? { ...f, left: -s - 1, top: n.y ?? "" } : t === "left" ? { ...f, right: -s - 1, top: n.y ?? "" } : f;
66
+ }, [u, n, t, r]);
80
67
  }
81
- function F(u, t, n, e, r, o, s, i, f, a, m) {
82
- return E(() => u ? { ref: n } : t === "none" ? {
83
- ref: n,
84
- "aria-expanded": o,
85
- onKeyDown: m
86
- } : t === "hover" ? {
87
- ref: n,
68
+ function L(u, n, t, r, s, f, o, i, e, c, l) {
69
+ return E(() => u ? { ref: t } : n === "none" ? {
70
+ ref: t,
71
+ "aria-expanded": f,
72
+ onKeyDown: l
73
+ } : n === "hover" ? {
74
+ ref: t,
88
75
  onMouseEnter: () => i(!0),
89
76
  onMouseLeave: () => {
90
- o ? i(!1) : f();
77
+ f ? i(!1) : e();
91
78
  },
92
79
  // 键盘聚焦不走 openDelay:延迟打开对读屏 / 键盘用户只有负作用
93
80
  onFocus: () => {
94
- f(), s(!0);
81
+ e(), o(!0);
95
82
  },
96
83
  onBlur: () => i(!1),
97
- "aria-describedby": e,
98
- onKeyDown: m
84
+ "aria-describedby": r,
85
+ onKeyDown: l
99
86
  } : {
100
- ref: n,
101
- onClick: (c) => {
102
- r(), a?.(c);
87
+ ref: t,
88
+ onClick: (a) => {
89
+ s(), c?.(a);
103
90
  },
104
- onKeyDown: (c) => {
105
- c.key === "Enter" && (c.preventDefault(), r()), m?.(c);
91
+ onKeyDown: (a) => {
92
+ a.key === "Enter" && (a.preventDefault(), s()), l?.(a);
106
93
  },
107
- "aria-expanded": o,
94
+ "aria-expanded": f,
108
95
  "aria-haspopup": "dialog",
109
- "aria-controls": e
96
+ "aria-controls": r
110
97
  }, [
111
98
  u,
112
- t,
113
99
  n,
114
- e,
100
+ t,
115
101
  r,
116
- o,
117
102
  s,
118
- i,
119
103
  f,
120
- a,
121
- m
104
+ o,
105
+ i,
106
+ e,
107
+ c,
108
+ l
122
109
  ]);
123
110
  }
124
111
  export {
125
- L as getFocusableElements,
126
- k as useAnimatedMount,
127
- B as useArrowStyle,
128
- v as useEscapeClose,
112
+ y as getFocusableElements,
113
+ F as useAnimatedMount,
114
+ C as useArrowStyle,
129
115
  q as usePopoverFocus,
130
- F as useTriggerProps
116
+ L as useTriggerProps
131
117
  };
@@ -1,4 +1,3 @@
1
1
  import { PopoverContextValue } from './popover.types';
2
2
  export declare const PopoverContext: import("react").Context<PopoverContextValue | null>;
3
- export declare const PopoverLayerContext: import("react").Context<number | null>;
4
3
  export declare function usePopoverContext(): PopoverContextValue;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { createContext as e, useContext as t } from "react";
3
- const n = e(null), p = e(null);
4
- function s() {
3
+ const n = e(null);
4
+ function p() {
5
5
  const o = t(n);
6
6
  if (!o)
7
7
  throw new Error(
@@ -11,6 +11,5 @@ function s() {
11
11
  }
12
12
  export {
13
13
  n as PopoverContext,
14
- p as PopoverLayerContext,
15
- s as usePopoverContext
14
+ p as usePopoverContext
16
15
  };
@@ -1,144 +1,163 @@
1
1
  "use client";
2
- import { jsxs as E, jsx as c } from "react/jsx-runtime";
3
- import { getDefaultZIndex as te, Portal as re } from "@mantine/core";
4
- import { useMergedRef as ne } from "@mantine/hooks";
5
- import { clsx as S } from "clsx";
6
- import { useContext as ie, useRef as ae, useCallback as se } from "react";
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";
2
+ import { jsxs as I, jsx as c } from "react/jsx-runtime";
3
+ import { useMergedRef as ae } from "@mantine/hooks";
4
+ import { clsx as O } from "clsx";
5
+ import { useRef as se, useCallback as le } from "react";
6
+ import { Portal as de } from "../_inner/portal/portal.js";
7
+ import { OverlayParentProvider as ce } from "../overlay-layer/overlay-parent-context.js";
8
+ import { useOverlayLayerInternal as fe } from "../overlay-layer/use-overlay-layer.js";
9
+ import { useAnimatedMount as ue, usePopoverFocus as pe, useArrowStyle as me, getFocusableElements as ve } from "./hooks.js";
10
+ import { usePopoverContext as ge } from "./popover-context.js";
9
11
  import M from "./styles/popover.module.css.js";
10
- const Fe = ({
11
- children: A,
12
- arrowClassName: C,
13
- zIndex: D,
12
+ const Me = ({
13
+ children: z,
14
+ arrowClassName: A,
15
+ zIndex: N,
14
16
  width: t,
15
17
  maxHeight: a,
16
- matchTargetWidth: N = !1,
17
- radius: z = "sm",
18
- withinPortal: H = !0,
19
- keepMounted: L = !1,
20
- ref: T,
21
- ...e
18
+ matchTargetWidth: k = !1,
19
+ radius: C = "sm",
20
+ withinPortal: D = !0,
21
+ keepMounted: H = !1,
22
+ ref: L,
23
+ ...o
22
24
  }) => {
23
- const u = ie(I), {
25
+ const {
24
26
  opened: r,
27
+ setOpen: T,
28
+ referenceRef: f,
29
+ restoreFocus: u,
30
+ closeOnEscape: j,
31
+ closeOnClickOutside: W,
25
32
  trigger: n,
26
- strategy: Z,
27
- x: j,
28
- y: k,
29
- resolvedSide: f,
33
+ strategy: $,
34
+ x: P,
35
+ y: V,
36
+ resolvedSide: p,
30
37
  middlewareData: s,
31
38
  floatingRef: l,
32
- setFloating: W,
33
- registerNestedFloatingElement: p,
39
+ setFloating: Z,
40
+ registerNestedFloatingElement: m,
34
41
  getFloatingScopeElements: v,
35
- withArrow: m,
36
- arrowSize: $,
37
- arrowRef: P,
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(
42
+ withArrow: g,
43
+ arrowSize: q,
44
+ arrowRef: B,
45
+ scheduleHover: G,
46
+ cancelHoverTimer: J,
47
+ id: K,
48
+ initialFocusRef: Q,
49
+ trapFocus: h,
50
+ preventAutoFocus: U,
51
+ ariaLabelledby: X
52
+ } = ge(), { mounted: y, animState: x, handleTransitionEnd: Y } = ue(
46
53
  r,
47
- L
48
- ), y = ae(null), Q = se(
49
- (o) => {
50
- y.current?.(), y.current = o ? p(o) : null;
54
+ H
55
+ ), F = se(null), _ = le(
56
+ (e) => {
57
+ F.current?.(), F.current = e ? m(e) : null;
58
+ },
59
+ [m]
60
+ ), d = fe({
61
+ opened: r,
62
+ zIndex: N,
63
+ closeOnEscape: j,
64
+ closeOnClickOutside: W,
65
+ // 触发按钮算"里面":否则点它会先被当成点外面关掉,紧接着它自己的 onClick 又打开
66
+ insideRefs: [f],
67
+ close: (e) => {
68
+ T(!1), e === "escape" && (u ? u() : f.current?.focus());
51
69
  },
52
- [p]
53
- ), U = ne(
70
+ name: "popover"
71
+ }), b = d.zIndex, ee = ae(
54
72
  l,
55
- W,
56
- Q,
57
- T
58
- ), d = D ?? (u === null ? te("popover") : u + 1);
59
- de(
73
+ Z,
74
+ _,
75
+ d.ref,
76
+ L
77
+ );
78
+ pe(
60
79
  n,
61
80
  r,
62
81
  x,
63
- h,
82
+ y,
64
83
  l,
65
84
  v,
66
- G,
67
- J
85
+ Q,
86
+ U
68
87
  );
69
- const b = (o) => /* @__PURE__ */ c(
88
+ const w = (e) => /* @__PURE__ */ c(
70
89
  "span",
71
90
  {
72
91
  tabIndex: 0,
73
- "data-focus-sentinel": o,
92
+ "data-focus-sentinel": e,
74
93
  "aria-hidden": "true",
75
94
  style: { position: "fixed", width: 0, height: 0, opacity: 0 },
76
95
  onFocus: () => {
77
- const i = ue(v());
96
+ const i = ve(v());
78
97
  if (i.length === 0) {
79
98
  l.current?.focus();
80
99
  return;
81
100
  }
82
- (o === "start" ? i[i.length - 1] : i[0]).focus();
101
+ (e === "start" ? i[i.length - 1] : i[0]).focus();
83
102
  }
84
103
  }
85
- ), X = ce(
86
- m,
104
+ ), oe = me(
105
+ g,
87
106
  s.arrow,
88
- f,
89
- $
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 (!h) return null;
92
- const w = "role" in e ? e.role : n === "click" ? "dialog" : void 0, F = w === "dialog", R = /* @__PURE__ */ E(
107
+ p,
108
+ q
109
+ ), re = typeof t == "number" ? `${t}px` : t, te = t ? re : void 0, ne = typeof a == "number" ? `${a}px` : a, ie = k ? "var(--t-popover-reference-width)" : te;
110
+ if (!y) return null;
111
+ const R = "role" in o ? o.role : n === "click" ? "dialog" : void 0, E = R === "dialog", S = /* @__PURE__ */ I(
93
112
  "div",
94
113
  {
95
- id: B,
96
- role: w,
97
- "aria-modal": F ? !1 : void 0,
98
- "aria-labelledby": F ? K : void 0,
99
- ref: U,
114
+ id: K,
115
+ role: R,
116
+ "aria-modal": E ? !1 : void 0,
117
+ "aria-labelledby": E ? X : void 0,
118
+ ref: ee,
100
119
  tabIndex: -1,
101
120
  "data-state": x,
102
- "data-radius": z,
103
- "data-side": f,
121
+ "data-radius": C,
122
+ "data-side": p,
104
123
  style: {
105
- position: Z,
106
- left: j ?? 0,
107
- top: k ?? 0,
108
- zIndex: d,
109
- "--t-popover-z": d,
110
- "--t-popover-width": oe,
111
- "--t-popover-max-height": ee,
124
+ position: $,
125
+ left: P ?? 0,
126
+ top: V ?? 0,
127
+ zIndex: b,
128
+ "--t-popover-z": b,
129
+ "--t-popover-width": ie,
130
+ "--t-popover-max-height": ne,
112
131
  visibility: s.hide?.referenceHidden ? "hidden" : void 0,
113
132
  pointerEvents: s.hide?.referenceHidden ? "none" : void 0
114
133
  },
115
- onTransitionEnd: O,
116
- onMouseEnter: n === "hover" ? () => q() : void 0,
117
- onMouseLeave: n === "hover" ? () => V(!1) : void 0,
118
- ...e,
119
- "aria-hidden": r ? e["aria-hidden"] : !0,
120
- inert: r ? e.inert : !0,
121
- className: S(M.popover, e.className),
134
+ onTransitionEnd: Y,
135
+ onMouseEnter: n === "hover" ? () => J() : void 0,
136
+ onMouseLeave: n === "hover" ? () => G(!1) : void 0,
137
+ ...o,
138
+ "aria-hidden": r ? o["aria-hidden"] : !0,
139
+ inert: r ? o.inert : !0,
140
+ className: O(M.popover, o.className),
122
141
  children: [
123
- /* @__PURE__ */ E(I.Provider, { value: d, children: [
124
- g && b("start"),
125
- A,
126
- g && b("end")
142
+ /* @__PURE__ */ I(ce, { id: d.id, children: [
143
+ h && w("start"),
144
+ z,
145
+ h && w("end")
127
146
  ] }),
128
- m && /* @__PURE__ */ c(
147
+ g && /* @__PURE__ */ c(
129
148
  "div",
130
149
  {
131
- ref: P,
150
+ ref: B,
132
151
  "aria-hidden": "true",
133
- className: S(M.arrow, C),
134
- style: { ...X }
152
+ className: O(M.arrow, A),
153
+ style: { ...oe }
135
154
  }
136
155
  )
137
156
  ]
138
157
  }
139
158
  );
140
- return H ? /* @__PURE__ */ c(re, { children: R }) : R;
159
+ return D ? /* @__PURE__ */ c(de, { children: S }) : S;
141
160
  };
142
161
  export {
143
- Fe as PopoverDropdown
162
+ Me as PopoverDropdown
144
163
  };