wimui 0.39.0 → 0.40.0

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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../media/Icon/Icon.cjs"),r=require("./swipe-action.module.cjs"),i=require("./SwipeableList.cjs");let a=require("react");a=e.__toESM(a,1);let o=require("classnames");o=e.__toESM(o,1);let s=require("react/jsx-runtime");var c=a.default.forwardRef(({as:e=`div`,leftActions:c=[],rightActions:l=[],children:u,asChild:d=!1,id:f,closeOnAction:p=!0,className:m,...h},g)=>{let _=(0,a.useId)(),v=f||_,y=i.useSwipeableList(),[b,x]=(0,a.useState)(0),[S,C]=(0,a.useState)(!1),w=(0,a.useRef)(0),T=(0,a.useRef)(0),E=(0,a.useRef)(null);(0,a.useImperativeHandle)(g,()=>({close:()=>{x(0),y?.reportClose(v)}}));let D=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(S){D.current=!0;return}if(D.current){let e=setTimeout(()=>{D.current=!1},100);return()=>clearTimeout(e)}y?.openedId&&y.openedId!==v&&x(0)},[y?.openedId,v,S]);let O=c.length*80,k=l.length*80,A=e=>{w.current=`touches`in e?e.touches[0].clientX:e.clientX,T.current=b,C(!0)},j=e=>{if(!S)return;let t=(`touches`in e?e.touches[0].clientX:e.clientX)-w.current,n=T.current+t;Math.abs(t)>5&&y?.openedId!==v&&y?.reportOpen(v),n>O&&(n=O+(n-O)*.3),n<-k&&(n=-k+(n+k)*.3),x(n)},M=()=>{S&&(C(!1),b>O/2?(x(O),y?.reportOpen(v)):b<-k/2?(x(-k),y?.reportOpen(v)):(x(0),y?.reportClose(v)))},N=d?t.Root:`div`,P=(0,a.useRef)(null),F=O>0||k>0,I=e=>{let t=e===`left`?O:-k;b!==t&&x(t),y?.reportOpen(v)},L=e=>{let t=e.relatedTarget;t&&E.current?.contains(t)||b!==0&&!S&&(x(0),y?.reportClose(v))},R=(e,t)=>{e.onClick(),p&&(x(0),y?.reportClose(v),document.activeElement===t.currentTarget&&P.current?.focus())},z=(e,t,i)=>(0,s.jsx)(`div`,{className:(0,o.default)(r.default.actions,r.default[e]),style:{width:i},children:t.map((t,i)=>(0,s.jsxs)(`button`,{className:(0,o.default)(r.default.action,t.intent&&r.default[t.intent]),style:{backgroundColor:t.color},onFocus:()=>I(e),onClick:e=>R(t,e),type:`button`,children:[(0,s.jsx)(n.Icon,{name:t.icon,size:`md`}),(0,s.jsx)(`span`,{className:r.default.label,children:t.label})]},i))});return(0,s.jsxs)(e,{ref:E,className:(0,o.default)(`wim-swipe-action`,r.default.container,m),onMouseLeave:M,onBlur:L,...h,children:[(0,s.jsx)(N,{ref:P,className:r.default.content,tabIndex:F?-1:void 0,style:{transform:`translateX(${b}px)`,transition:S?`none`:`transform 0.4s cubic-bezier(0.16, 1, 0.3, 1)`},onTouchStart:A,onTouchMove:j,onTouchEnd:M,onMouseDown:A,onMouseMove:j,onMouseUp:M,children:u}),O>0&&z(`left`,c,O),k>0&&z(`right`,l,k)]})});c.displayName=`SwipeAction`,exports.SwipeAction=c;
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../media/Icon/Icon.cjs"),r=require("./swipe-action.module.cjs"),i=require("./SwipeableList.cjs");let a=require("react");a=e.__toESM(a,1);let o=require("classnames");o=e.__toESM(o,1);let s=require("react/jsx-runtime");var c=a.default.forwardRef(({as:e=`div`,leftActions:c=[],rightActions:l=[],children:u,asChild:d=!1,id:f,closeOnAction:p=!0,fullSwipe:m,className:h,...g},_)=>{let v=(0,a.useId)(),y=f||v,b=i.useSwipeableList(),[x,S]=(0,a.useState)(0),[C,w]=(0,a.useState)(!1),T=(0,a.useRef)(0),E=(0,a.useRef)(0),D=(0,a.useRef)(null);(0,a.useImperativeHandle)(_,()=>({close:()=>{S(0),b?.reportClose(y)}}));let O=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(C){O.current=!0;return}if(O.current){let e=setTimeout(()=>{O.current=!1},100);return()=>clearTimeout(e)}b?.openedId&&b.openedId!==y&&S(0)},[b?.openedId,y,C]);let k=c.length*80,A=l.length*80,j=k>0&&(m===`left`||m===`both`),M=A>0&&(m===`right`||m===`both`),N=D.current?.offsetWidth??0,P=e=>Math.max(e+40,N/2),F=C&&j&&x>=P(k)?`left`:C&&M&&-x>=P(A)?`right`:null,I=e=>{T.current=`touches`in e?e.touches[0].clientX:e.clientX,E.current=x,w(!0)},L=e=>{if(!C)return;let t=(`touches`in e?e.touches[0].clientX:e.clientX)-T.current,n=E.current+t;Math.abs(t)>5&&b?.openedId!==y&&b?.reportOpen(y),n>k&&!j&&(n=k+(n-k)*.3),n<-A&&!M&&(n=-A+(n+A)*.3),S(n)},R=(e=!0)=>{if(C){if(w(!1),F){let t=F===`left`?c[0]:l[l.length-1];if(e){W(t),p||(S(F===`left`?k:-A),b?.reportOpen(y));return}}x>k/2?(S(k),b?.reportOpen(y)):x<-A/2?(S(-A),b?.reportOpen(y)):(S(0),b?.reportClose(y))}},z=d?t.Root:`div`,B=(0,a.useRef)(null),V=k>0||A>0,H=e=>{let t=e===`left`?k:-A;x!==t&&S(t),b?.reportOpen(y)},U=e=>{let t=e.relatedTarget;t&&D.current?.contains(t)||x!==0&&!C&&(S(0),b?.reportClose(y))},W=(e,t)=>{e.onClick(),p&&(S(0),b?.reportClose(y),t&&document.activeElement===t&&B.current?.focus())},G=(e,t,i)=>{let a=e===`left`?j:M,c=e===`left`?Math.max(0,x):Math.max(0,-x),l=e===`left`?0:t.length-1;return(0,s.jsx)(`div`,{className:(0,o.default)(r.default.actions,r.default[e],a&&c>i&&r.default.stretched,F===e&&r.default.armed),style:{width:a?Math.max(i,c):i,"--_action-w":`80px`},children:t.map((t,i)=>(0,s.jsxs)(`button`,{className:(0,o.default)(r.default.action,t.intent&&r.default[t.intent],a&&i===l&&r.default.outer),style:{backgroundColor:t.color},onFocus:()=>H(e),onClick:e=>W(t,e.currentTarget),type:`button`,children:[(0,s.jsx)(n.Icon,{name:t.icon,size:`md`}),(0,s.jsx)(`span`,{className:r.default.label,children:t.label})]},i))})};return(0,s.jsxs)(e,{ref:D,className:(0,o.default)(`wim-swipe-action`,r.default.container,h),onMouseLeave:()=>R(!1),onBlur:U,...g,children:[(0,s.jsx)(z,{ref:B,className:r.default.content,tabIndex:V?-1:void 0,style:{transform:`translateX(${x}px)`,transition:C?`none`:`transform 0.4s cubic-bezier(0.16, 1, 0.3, 1)`},onTouchStart:I,onTouchMove:L,onTouchEnd:()=>R(),onMouseDown:I,onMouseMove:L,onMouseUp:()=>R(),children:u}),k>0&&G(`left`,c,k),A>0&&G(`right`,l,A)]})});c.displayName=`SwipeAction`,exports.SwipeAction=c;
@@ -27,6 +27,12 @@ export interface SwipeActionProps extends React.HTMLAttributes<HTMLDivElement> {
27
27
  id?: string;
28
28
  /** Whether to automatically close the actions when an action is clicked. Default is true. */
29
29
  closeOnAction?: boolean;
30
+ /**
31
+ * Sides where swiping all the way across runs the outermost action without a tap
32
+ * (`leftActions[0]` / the last of `rightActions`), as in iOS Mail. Off by default so a
33
+ * destructive action is never triggered by momentum; the action stays available as a button.
34
+ */
35
+ fullSwipe?: "left" | "right" | "both";
30
36
  }
31
37
  export interface SwipeActionRef {
32
38
  /** Method to programmatically close the swipe actions */
@@ -7,88 +7,103 @@ import i, { useEffect as a, useId as o, useImperativeHandle as s, useRef as c, u
7
7
  import u from "classnames";
8
8
  import { jsx as d, jsxs as f } from "react/jsx-runtime";
9
9
  //#region src/components/data-display/SwipeAction/SwipeAction.tsx
10
- var p = i.forwardRef(({ as: i = "div", leftActions: p = [], rightActions: m = [], children: h, asChild: g = !1, id: _, closeOnAction: v = !0, className: y, ...b }, x) => {
11
- let S = o(), C = _ || S, w = r(), [T, E] = l(0), [D, O] = l(!1), k = c(0), A = c(0), j = c(null);
12
- s(x, () => ({ close: () => {
13
- E(0), w?.reportClose(C);
10
+ var p = i.forwardRef(({ as: i = "div", leftActions: p = [], rightActions: m = [], children: h, asChild: g = !1, id: _, closeOnAction: v = !0, fullSwipe: y, className: b, ...x }, S) => {
11
+ let C = o(), w = _ || C, T = r(), [E, D] = l(0), [O, k] = l(!1), A = c(0), j = c(0), M = c(null);
12
+ s(S, () => ({ close: () => {
13
+ D(0), T?.reportClose(w);
14
14
  } }));
15
- let M = c(!1);
15
+ let N = c(!1);
16
16
  a(() => {
17
- if (D) {
18
- M.current = !0;
17
+ if (O) {
18
+ N.current = !0;
19
19
  return;
20
20
  }
21
- if (M.current) {
21
+ if (N.current) {
22
22
  let e = setTimeout(() => {
23
- M.current = !1;
23
+ N.current = !1;
24
24
  }, 100);
25
25
  return () => clearTimeout(e);
26
26
  }
27
- w?.openedId && w.openedId !== C && E(0);
27
+ T?.openedId && T.openedId !== w && D(0);
28
28
  }, [
29
- w?.openedId,
30
- C,
31
- D
29
+ T?.openedId,
30
+ w,
31
+ O
32
32
  ]);
33
- let N = p.length * 80, P = m.length * 80, F = (e) => {
34
- k.current = "touches" in e ? e.touches[0].clientX : e.clientX, A.current = T, O(!0);
35
- }, I = (e) => {
36
- if (!D) return;
37
- let t = ("touches" in e ? e.touches[0].clientX : e.clientX) - k.current, n = A.current + t;
38
- Math.abs(t) > 5 && w?.openedId !== C && w?.reportOpen(C), n > N && (n = N + (n - N) * .3), n < -P && (n = -P + (n + P) * .3), E(n);
39
- }, L = () => {
40
- D && (O(!1), T > N / 2 ? (E(N), w?.reportOpen(C)) : T < -P / 2 ? (E(-P), w?.reportOpen(C)) : (E(0), w?.reportClose(C)));
41
- }, R = g ? e : "div", z = c(null), B = N > 0 || P > 0, V = (e) => {
42
- let t = e === "left" ? N : -P;
43
- T !== t && E(t), w?.reportOpen(C);
33
+ let P = p.length * 80, F = m.length * 80, I = P > 0 && (y === "left" || y === "both"), L = F > 0 && (y === "right" || y === "both"), R = M.current?.offsetWidth ?? 0, z = (e) => Math.max(e + 40, R / 2), B = O && I && E >= z(P) ? "left" : O && L && -E >= z(F) ? "right" : null, V = (e) => {
34
+ A.current = "touches" in e ? e.touches[0].clientX : e.clientX, j.current = E, k(!0);
44
35
  }, H = (e) => {
36
+ if (!O) return;
37
+ let t = ("touches" in e ? e.touches[0].clientX : e.clientX) - A.current, n = j.current + t;
38
+ Math.abs(t) > 5 && T?.openedId !== w && T?.reportOpen(w), n > P && !I && (n = P + (n - P) * .3), n < -F && !L && (n = -F + (n + F) * .3), D(n);
39
+ }, U = (e = !0) => {
40
+ if (O) {
41
+ if (k(!1), B) {
42
+ let t = B === "left" ? p[0] : m[m.length - 1];
43
+ if (e) {
44
+ Y(t), v || (D(B === "left" ? P : -F), T?.reportOpen(w));
45
+ return;
46
+ }
47
+ }
48
+ E > P / 2 ? (D(P), T?.reportOpen(w)) : E < -F / 2 ? (D(-F), T?.reportOpen(w)) : (D(0), T?.reportClose(w));
49
+ }
50
+ }, W = g ? e : "div", G = c(null), K = P > 0 || F > 0, q = (e) => {
51
+ let t = e === "left" ? P : -F;
52
+ E !== t && D(t), T?.reportOpen(w);
53
+ }, J = (e) => {
45
54
  let t = e.relatedTarget;
46
- t && j.current?.contains(t) || T !== 0 && !D && (E(0), w?.reportClose(C));
47
- }, U = (e, t) => {
48
- e.onClick(), v && (E(0), w?.reportClose(C), document.activeElement === t.currentTarget && z.current?.focus());
49
- }, W = (e, r, i) => /* @__PURE__ */ d("div", {
50
- className: u(n.actions, n[e]),
51
- style: { width: i },
52
- children: r.map((r, i) => /* @__PURE__ */ f("button", {
53
- className: u(n.action, r.intent && n[r.intent]),
54
- style: { backgroundColor: r.color },
55
- onFocus: () => V(e),
56
- onClick: (e) => U(r, e),
57
- type: "button",
58
- children: [/* @__PURE__ */ d(t, {
59
- name: r.icon,
60
- size: "md"
61
- }), /* @__PURE__ */ d("span", {
62
- className: n.label,
63
- children: r.label
64
- })]
65
- }, i))
66
- });
55
+ t && M.current?.contains(t) || E !== 0 && !O && (D(0), T?.reportClose(w));
56
+ }, Y = (e, t) => {
57
+ e.onClick(), v && (D(0), T?.reportClose(w), t && document.activeElement === t && G.current?.focus());
58
+ }, X = (e, r, i) => {
59
+ let a = e === "left" ? I : L, o = e === "left" ? Math.max(0, E) : Math.max(0, -E), s = e === "left" ? 0 : r.length - 1;
60
+ return /* @__PURE__ */ d("div", {
61
+ className: u(n.actions, n[e], a && o > i && n.stretched, B === e && n.armed),
62
+ style: {
63
+ width: a ? Math.max(i, o) : i,
64
+ "--_action-w": "80px"
65
+ },
66
+ children: r.map((r, i) => /* @__PURE__ */ f("button", {
67
+ className: u(n.action, r.intent && n[r.intent], a && i === s && n.outer),
68
+ style: { backgroundColor: r.color },
69
+ onFocus: () => q(e),
70
+ onClick: (e) => Y(r, e.currentTarget),
71
+ type: "button",
72
+ children: [/* @__PURE__ */ d(t, {
73
+ name: r.icon,
74
+ size: "md"
75
+ }), /* @__PURE__ */ d("span", {
76
+ className: n.label,
77
+ children: r.label
78
+ })]
79
+ }, i))
80
+ });
81
+ };
67
82
  return /* @__PURE__ */ f(i, {
68
- ref: j,
69
- className: u("wim-swipe-action", n.container, y),
70
- onMouseLeave: L,
71
- onBlur: H,
72
- ...b,
83
+ ref: M,
84
+ className: u("wim-swipe-action", n.container, b),
85
+ onMouseLeave: () => U(!1),
86
+ onBlur: J,
87
+ ...x,
73
88
  children: [
74
- /* @__PURE__ */ d(R, {
75
- ref: z,
89
+ /* @__PURE__ */ d(W, {
90
+ ref: G,
76
91
  className: n.content,
77
- tabIndex: B ? -1 : void 0,
92
+ tabIndex: K ? -1 : void 0,
78
93
  style: {
79
- transform: `translateX(${T}px)`,
80
- transition: D ? "none" : "transform 0.4s cubic-bezier(0.16, 1, 0.3, 1)"
94
+ transform: `translateX(${E}px)`,
95
+ transition: O ? "none" : "transform 0.4s cubic-bezier(0.16, 1, 0.3, 1)"
81
96
  },
82
- onTouchStart: F,
83
- onTouchMove: I,
84
- onTouchEnd: L,
85
- onMouseDown: F,
86
- onMouseMove: I,
87
- onMouseUp: L,
97
+ onTouchStart: V,
98
+ onTouchMove: H,
99
+ onTouchEnd: () => U(),
100
+ onMouseDown: V,
101
+ onMouseMove: H,
102
+ onMouseUp: () => U(),
88
103
  children: h
89
104
  }),
90
- N > 0 && W("left", p, N),
91
- P > 0 && W("right", m, P)
105
+ P > 0 && X("left", p, P),
106
+ F > 0 && X("right", m, F)
92
107
  ]
93
108
  });
94
109
  });
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var e=`_container_8pbgw_2`,t=`_actions_8pbgw_10`,n=`_left_8pbgw_17`,r=`_right_8pbgw_20`,i=`_action_8pbgw_10`,a=`_primary_8pbgw_45`,o=`_danger_8pbgw_48`,s=`_warning_8pbgw_51`,c=`_success_8pbgw_55`,l=`_neutral_8pbgw_58`,u=`_label_8pbgw_61`,d=`_content_8pbgw_64`,f={container:e,actions:t,left:n,right:r,action:i,primary:a,danger:o,warning:s,success:c,neutral:l,label:u,content:d};exports.action=i,exports.actions=t,exports.container=e,exports.content=d,exports.danger=o,exports.default=f,exports.label=u,exports.left=n,exports.neutral=l,exports.primary=a,exports.right=r,exports.success=c,exports.warning=s;
2
+ var e=`_container_13gak_3`,t=`_actions_13gak_11`,n=`_left_13gak_18`,r=`_right_13gak_21`,i=`_stretched_13gak_28`,a=`_action_13gak_11`,o=`_outer_13gak_28`,s=`_armed_13gak_35`,c=`_primary_13gak_63`,l=`_danger_13gak_66`,u=`_warning_13gak_69`,d=`_success_13gak_73`,f=`_neutral_13gak_76`,p=`_label_13gak_79`,m=`_content_13gak_82`,h={container:e,actions:t,left:n,right:r,stretched:i,action:a,outer:o,armed:s,primary:c,danger:l,warning:u,success:d,neutral:f,label:p,content:m};exports.action=a,exports.actions=t,exports.armed=s,exports.container=e,exports.content=m,exports.danger=l,exports.default=h,exports.label=p,exports.left=n,exports.neutral=f,exports.outer=o,exports.primary=c,exports.right=r,exports.stretched=i,exports.success=d,exports.warning=u;
@@ -1,18 +1,21 @@
1
1
  "use client";
2
2
  //#region src/components/data-display/SwipeAction/swipe-action.module.scss
3
- var e = "_container_8pbgw_2", t = "_actions_8pbgw_10", n = "_left_8pbgw_17", r = "_right_8pbgw_20", i = "_action_8pbgw_10", a = "_primary_8pbgw_45", o = "_danger_8pbgw_48", s = "_warning_8pbgw_51", c = "_success_8pbgw_55", l = "_neutral_8pbgw_58", u = "_label_8pbgw_61", d = "_content_8pbgw_64", f = {
3
+ var e = "_container_13gak_3", t = "_actions_13gak_11", n = "_left_13gak_18", r = "_right_13gak_21", i = "_stretched_13gak_28", a = "_action_13gak_11", o = "_outer_13gak_28", s = "_armed_13gak_35", c = "_primary_13gak_63", l = "_danger_13gak_66", u = "_warning_13gak_69", d = "_success_13gak_73", f = "_neutral_13gak_76", p = "_label_13gak_79", m = "_content_13gak_82", h = {
4
4
  container: e,
5
5
  actions: t,
6
6
  left: n,
7
7
  right: r,
8
- action: i,
9
- primary: a,
10
- danger: o,
11
- warning: s,
12
- success: c,
13
- neutral: l,
14
- label: u,
15
- content: d
8
+ stretched: i,
9
+ action: a,
10
+ outer: o,
11
+ armed: s,
12
+ primary: c,
13
+ danger: l,
14
+ warning: u,
15
+ success: d,
16
+ neutral: f,
17
+ label: p,
18
+ content: m
16
19
  };
17
20
  //#endregion
18
- export { i as action, t as actions, e as container, d as content, o as danger, f as default, u as label, n as left, l as neutral, a as primary, r as right, c as success, s as warning };
21
+ export { a as action, t as actions, s as armed, e as container, m as content, l as danger, h as default, p as label, n as left, f as neutral, o as outer, c as primary, r as right, i as stretched, d as success, u as warning };