@smwb/ui-react 2.6.0 → 2.6.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.
@@ -1,13 +1,13 @@
1
- import { jsx as s, Fragment as Tt, jsxs as N } from "react/jsx-runtime";
2
- import { forwardRef as vt, useState as Kt, useRef as _, useId as Ot, useCallback as T, useEffect as Q } from "react";
3
- import { createPortal as Ft } from "react-dom";
4
- import { CSSTransition as Ht } from "react-transition-group";
5
- import W from "clsx";
1
+ import { jsx as s, Fragment as Ht, jsxs as T } from "react/jsx-runtime";
2
+ import { forwardRef as Ut, useState as et, useRef as R, useId as $t, useCallback as A, useEffect as K } from "react";
3
+ import { createPortal as Vt } from "react-dom";
4
+ import { CSSTransition as Xt } from "react-transition-group";
5
+ import nt from "clsx";
6
6
  import { Icon as v } from "../../base/icon/icon.js";
7
- import { useControllableState as K } from "../../../hooks/useControllableState.js";
8
- import { useForkRef as Ut } from "../../../hooks/useForkRef.js";
9
- import { useSafeLayoutEffect as $t } from "../../../hooks/useSafeLayoutEffect.js";
10
- const Vt = {
7
+ import { useControllableState as O } from "../../../hooks/useControllableState.js";
8
+ import { useForkRef as Yt } from "../../../hooks/useForkRef.js";
9
+ import { useSafeLayoutEffect as Zt } from "../../../hooks/useSafeLayoutEffect.js";
10
+ const jt = {
11
11
  n: { dx: 0, dy: 1, dw: 0, dh: -1 },
12
12
  s: { dx: 0, dy: 0, dw: 0, dh: 1 },
13
13
  e: { dx: 0, dy: 0, dw: 1, dh: 0 },
@@ -16,97 +16,112 @@ const Vt = {
16
16
  nw: { dx: 1, dy: 1, dw: -1, dh: -1 },
17
17
  se: { dx: 0, dy: 0, dw: 1, dh: 1 },
18
18
  sw: { dx: 1, dy: 0, dw: -1, dh: 1 }
19
- }, Xt = ["n", "s", "e", "w", "ne", "nw", "se", "sw"], y = () => typeof window == "undefined" ? { width: 0, height: 0 } : { width: window.innerWidth, height: window.innerHeight }, Yt = { x: 24, y: 24 }, Zt = { width: 360, height: 420 }, oe = vt(
20
- function(tt, et) {
19
+ }, Gt = ["n", "s", "e", "w", "ne", "nw", "se", "sw"], u = () => typeof window == "undefined" ? { width: 0, height: 0 } : { width: window.innerWidth, height: window.innerHeight }, qt = { x: 24, y: 24 }, Bt = { width: 360, height: 420 }, se = Ut(
20
+ function(ot, it) {
21
21
  const {
22
- open: x,
23
- title: A,
24
- headerActions: nt,
25
- position: ot,
26
- defaultPosition: it = Yt,
27
- onPositionChange: rt,
28
- onMoveEnd: h,
29
- size: at,
30
- defaultSize: st = Zt,
31
- onResize: dt,
32
- onResizeEnd: u,
33
- minWidth: b = 200,
22
+ open: c,
23
+ title: I,
24
+ headerActions: rt,
25
+ position: at,
26
+ defaultPosition: st = qt,
27
+ onPositionChange: dt,
28
+ onMoveEnd: f,
29
+ size: lt,
30
+ defaultSize: ct = Bt,
31
+ onResize: wt,
32
+ onResizeEnd: p,
33
+ minWidth: P = 200,
34
34
  minHeight: D = 120,
35
35
  maxWidth: a,
36
36
  maxHeight: d,
37
- keepVisible: O = 56,
38
- moveStep: lt = 24,
39
- resizeStep: I = 24,
40
- zIndex: F,
41
- onActivate: R,
42
- collapsed: ct,
43
- defaultCollapsed: wt = !1,
44
- onCollapsedChange: ht,
45
- collapsible: ut = !0,
46
- movable: ft = !0,
47
- resizable: pt = !0,
48
- closeOnEsc: H = !1,
49
- onClose: P,
50
- moveHandleAriaLabel: mt = "Move window",
51
- resizeHandleAriaLabel: gt = "Resize window",
52
- closeAriaLabel: yt = "Close window",
53
- collapseAriaLabel: xt = "Collapse window",
54
- expandAriaLabel: bt = "Expand window",
55
- className: Pt,
56
- style: E,
57
- children: _t,
58
- ...Dt
59
- } = tt, [U, Rt] = Kt(), C = _(null), Ct = Ut(et, C), $ = Ot();
60
- $t(() => {
61
- Rt(document.body);
37
+ keepVisible: F = 56,
38
+ moveStep: ht = 24,
39
+ resizeStep: E = 24,
40
+ zIndex: H,
41
+ onActivate: M,
42
+ collapsed: ut,
43
+ defaultCollapsed: ft = !1,
44
+ onCollapsedChange: pt,
45
+ collapsible: mt = !0,
46
+ movable: gt = !0,
47
+ resizable: yt = !0,
48
+ closeOnEsc: U = !1,
49
+ onClose: _,
50
+ moveHandleAriaLabel: xt = "Move window",
51
+ resizeHandleAriaLabel: bt = "Resize window",
52
+ closeAriaLabel: Pt = "Close window",
53
+ collapseAriaLabel: _t = "Collapse window",
54
+ expandAriaLabel: Rt = "Expand window",
55
+ className: Dt,
56
+ style: S,
57
+ children: Mt,
58
+ ...Ct
59
+ } = ot, [$, kt] = et(), C = R(null), zt = Yt(it, C), V = $t();
60
+ Zt(() => {
61
+ kt(document.body);
62
62
  }, []);
63
- const [f, V] = K({
64
- value: ot,
65
- defaultValue: it,
66
- onChange: rt
67
- }), [p, X] = K({
63
+ const [m, X] = O({
68
64
  value: at,
69
65
  defaultValue: st,
70
66
  onChange: dt
71
- }), [c, Mt] = K({
72
- value: ct,
73
- defaultValue: wt,
74
- onChange: ht
75
- }), M = T(
67
+ }), [g, Y] = O({
68
+ value: lt,
69
+ defaultValue: ct,
70
+ onChange: wt
71
+ }), [w, At] = O({
72
+ value: ut,
73
+ defaultValue: ft,
74
+ onChange: pt
75
+ }), y = A(
76
76
  (t, e) => {
77
- const n = a != null ? a : e.width, i = d != null ? d : e.height, o = Math.max(b, Math.min(n, t.width)), r = Math.max(D, Math.min(i, t.height)), g = Math.min(O, o), S = Math.max(g - o, Math.min(e.width - g, t.x)), L = Math.max(0, Math.min(Math.max(0, e.height - g), t.y));
78
- return { x: S, y: L, width: o, height: r };
77
+ const n = a != null ? a : e.width, i = d != null ? d : e.height, o = Math.max(P, Math.min(n, t.width)), r = Math.max(D, Math.min(i, t.height)), b = Math.min(F, o), L = Math.max(b - o, Math.min(e.width - b, t.x)), N = Math.max(0, Math.min(Math.max(0, e.height - b), t.y));
78
+ return { x: L, y: N, width: o, height: r };
79
79
  },
80
- [O, d, a, D, b]
81
- ), w = M({ x: f.x, y: f.y, width: p.width, height: p.height }, y()), l = _(w);
82
- l.current = w;
83
- const m = T(
84
- (t) => {
85
- const e = M(t, y());
86
- (e.x !== f.x || e.y !== f.y) && V({ x: e.x, y: e.y }), (e.width !== p.width || e.height !== p.height) && X({ width: e.width, height: e.height });
80
+ [F, d, a, D, P]
81
+ ), It = A(
82
+ (t, e) => {
83
+ const n = y(t, e);
84
+ return {
85
+ ...n,
86
+ x: Math.max(0, Math.min(n.x, e.width - n.width)),
87
+ y: Math.max(0, Math.min(n.y, e.height - n.height))
88
+ };
89
+ },
90
+ [y]
91
+ ), [Et, Z] = et(!1);
92
+ K(() => {
93
+ c || Z(!1);
94
+ }, [c]);
95
+ const j = { x: m.x, y: m.y, width: g.width, height: g.height }, h = Et ? y(j, u()) : It(j, u()), l = R(h);
96
+ l.current = h;
97
+ const x = A(
98
+ (t, e = !0) => {
99
+ e && Z(!0);
100
+ const n = y(t, u());
101
+ (n.x !== m.x || n.y !== m.y) && X({ x: n.x, y: n.y }), (n.width !== g.width || n.height !== g.height) && Y({ width: n.width, height: n.height });
87
102
  },
88
- [M, f.x, f.y, V, X, p.height, p.width]
89
- ), Y = _(m);
90
- Y.current = m, Q(() => {
91
- if (!x) return;
92
- const t = () => Y.current(l.current);
103
+ [y, m.x, m.y, X, Y, g.height, g.width]
104
+ ), G = R(x);
105
+ G.current = x, K(() => {
106
+ if (!c) return;
107
+ const t = () => G.current(l.current, !1);
93
108
  return window.addEventListener("resize", t), () => window.removeEventListener("resize", t);
94
- }, [x]), Q(() => {
95
- if (!x || !H || !P) return;
109
+ }, [c]), K(() => {
110
+ if (!c || !U || !_) return;
96
111
  const t = (e) => {
97
112
  if (e.key !== "Escape") return;
98
113
  const n = C.current;
99
- !n || !n.contains(document.activeElement) || P();
114
+ !n || !n.contains(document.activeElement) || _();
100
115
  };
101
116
  return document.addEventListener("keydown", t), () => document.removeEventListener("keydown", t);
102
- }, [H, P, x]);
103
- const Z = T(() => {
104
- R == null || R();
117
+ }, [U, _, c]);
118
+ const q = A(() => {
119
+ M == null || M();
105
120
  const t = C.current;
106
121
  t && !t.contains(document.activeElement) && t.focus({ preventScroll: !0 });
107
- }, [R]), k = _(null), kt = (t) => {
122
+ }, [M]), k = R(null), St = (t) => {
108
123
  var n, i, o;
109
- if (!ft || (n = t.target) != null && n.closest("button,[data-no-drag]")) return;
124
+ if (!gt || (n = t.target) != null && n.closest("button,[data-no-drag]")) return;
110
125
  t.preventDefault();
111
126
  const e = l.current;
112
127
  k.current = { px: t.clientX, py: t.clientY, x: e.x, y: e.y };
@@ -114,51 +129,51 @@ const Vt = {
114
129
  (o = (i = t.currentTarget).setPointerCapture) == null || o.call(i, t.pointerId);
115
130
  } catch {
116
131
  }
117
- }, zt = (t) => {
132
+ }, Lt = (t) => {
118
133
  const e = k.current;
119
- e && m({
134
+ e && x({
120
135
  ...l.current,
121
136
  x: e.x + t.clientX - e.px,
122
137
  y: e.y + t.clientY - e.py
123
138
  });
124
- }, j = (t) => {
139
+ }, B = (t) => {
125
140
  var e, n, i, o;
126
141
  if (k.current) {
127
142
  k.current = null;
128
143
  const r = l.current;
129
- h == null || h({ x: r.x, y: r.y });
144
+ f == null || f({ x: r.x, y: r.y });
130
145
  }
131
146
  (n = (e = t.currentTarget).hasPointerCapture) != null && n.call(e, t.pointerId) && ((o = (i = t.currentTarget).releasePointerCapture) == null || o.call(i, t.pointerId));
132
- }, z = _(null), At = (t, e) => {
147
+ }, z = R(null), Nt = (t, e) => {
133
148
  var n, i;
134
- e.preventDefault(), e.stopPropagation(), z.current = { dir: t, px: e.clientX, py: e.clientY, rect: l.current }, Z();
149
+ e.preventDefault(), e.stopPropagation(), z.current = { dir: t, px: e.clientX, py: e.clientY, rect: l.current }, q();
135
150
  try {
136
151
  (i = (n = e.currentTarget).setPointerCapture) == null || i.call(n, e.pointerId);
137
152
  } catch {
138
153
  }
139
- }, It = (t) => {
154
+ }, Tt = (t) => {
140
155
  const e = z.current;
141
156
  if (!e) return;
142
- const n = Vt[e.dir], i = t.clientX - e.px, o = t.clientY - e.py, r = e.rect, g = y(), S = a != null ? a : g.width, L = d != null ? d : g.height, B = Math.min(S, Math.max(b, r.width + n.dw * i)), J = Math.min(L, Math.max(D, r.height + n.dh * o));
143
- m({
144
- x: n.dx ? r.x + r.width - B : r.x,
145
- y: n.dy ? r.y + r.height - J : r.y,
146
- width: B,
147
- height: J
157
+ const n = jt[e.dir], i = t.clientX - e.px, o = t.clientY - e.py, r = e.rect, b = u(), L = a != null ? a : b.width, N = d != null ? d : b.height, W = Math.min(L, Math.max(P, r.width + n.dw * i)), tt = Math.min(N, Math.max(D, r.height + n.dh * o));
158
+ x({
159
+ x: n.dx ? r.x + r.width - W : r.x,
160
+ y: n.dy ? r.y + r.height - tt : r.y,
161
+ width: W,
162
+ height: tt
148
163
  });
149
- }, G = (t) => {
164
+ }, J = (t) => {
150
165
  var e, n, i, o;
151
166
  if (z.current) {
152
167
  z.current = null;
153
168
  const r = l.current;
154
- u == null || u({ width: r.width, height: r.height });
169
+ p == null || p({ width: r.width, height: r.height });
155
170
  }
156
171
  (n = (e = t.currentTarget).hasPointerCapture) != null && n.call(e, t.pointerId) && ((o = (i = t.currentTarget).releasePointerCapture) == null || o.call(i, t.pointerId));
157
- }, q = (t, e) => {
158
- const n = M(e, y());
159
- t ? u == null || u({ width: n.width, height: n.height }) : h == null || h({ x: n.x, y: n.y });
160
- }, Et = (t) => {
161
- const e = l.current, n = t.shiftKey ? I : lt, o = {
172
+ }, Q = (t, e) => {
173
+ const n = y(e, u());
174
+ t ? p == null || p({ width: n.width, height: n.height }) : f == null || f({ x: n.x, y: n.y });
175
+ }, Kt = (t) => {
176
+ const e = l.current, n = t.shiftKey ? E : ht, o = {
162
177
  ArrowLeft: [-n, 0],
163
178
  ArrowRight: [n, 0],
164
179
  ArrowUp: [0, -n],
@@ -167,69 +182,69 @@ const Vt = {
167
182
  if (!o) return;
168
183
  t.preventDefault();
169
184
  const r = t.shiftKey ? { ...e, width: e.width + o[0], height: e.height + o[1] } : { ...e, x: e.x + o[0], y: e.y + o[1] };
170
- m(r), q(t.shiftKey, r);
171
- }, St = (t) => {
172
- const e = l.current, n = y();
185
+ x(r), Q(t.shiftKey, r);
186
+ }, vt = (t) => {
187
+ const e = l.current, n = u();
173
188
  let i;
174
189
  if (t.key === "ArrowLeft" || t.key === "ArrowRight") {
175
190
  t.preventDefault();
176
191
  const o = t.key === "ArrowRight" ? 1 : -1;
177
- i = { ...e, width: e.width + o * I };
192
+ i = { ...e, width: e.width + o * E };
178
193
  } else if (t.key === "ArrowUp" || t.key === "ArrowDown") {
179
194
  t.preventDefault();
180
195
  const o = t.key === "ArrowDown" ? 1 : -1;
181
- i = { ...e, height: e.height + o * I };
196
+ i = { ...e, height: e.height + o * E };
182
197
  } else if (t.key === "Home")
183
- t.preventDefault(), i = { ...e, width: b, height: D };
198
+ t.preventDefault(), i = { ...e, width: P, height: D };
184
199
  else if (t.key === "End")
185
200
  t.preventDefault(), i = { ...e, width: a != null ? a : n.width, height: d != null ? d : n.height };
186
201
  else
187
202
  return;
188
- m(i), q(!0, i);
189
- }, Lt = () => Mt((t) => !t);
190
- if (!U)
191
- return /* @__PURE__ */ s(Tt, {});
192
- const Nt = {
193
- left: `${w.x}px`,
194
- top: `${w.y}px`,
195
- width: `${w.width}px`,
196
- ...c ? {} : { height: `${w.height}px` },
197
- ...F === void 0 ? {} : { zIndex: F },
198
- ...E != null ? E : {}
203
+ x(i), Q(!0, i);
204
+ }, Ot = () => At((t) => !t);
205
+ if (!$)
206
+ return /* @__PURE__ */ s(Ht, {});
207
+ const Ft = {
208
+ left: `${h.x}px`,
209
+ top: `${h.y}px`,
210
+ width: `${h.width}px`,
211
+ ...w ? {} : { height: `${h.height}px` },
212
+ ...H === void 0 ? {} : { zIndex: H },
213
+ ...S != null ? S : {}
199
214
  };
200
- return Ft(
215
+ return Vt(
201
216
  /* @__PURE__ */ s(
202
- Ht,
217
+ Xt,
203
218
  {
204
- in: x,
219
+ in: c,
205
220
  timeout: 120,
206
221
  mountOnEnter: !0,
207
222
  unmountOnExit: !0,
208
223
  appear: !0,
209
224
  classNames: { enterDone: "smwb-floating-window_entered" },
210
225
  nodeRef: C,
211
- children: /* @__PURE__ */ N(
226
+ children: /* @__PURE__ */ T(
212
227
  "div",
213
228
  {
214
- ...Dt,
215
- ref: Ct,
229
+ ...Ct,
230
+ ref: zt,
216
231
  "data-testid": "floating-window",
217
232
  role: "dialog",
218
233
  tabIndex: -1,
219
- "aria-labelledby": A ? $ : void 0,
220
- className: W("smwb-floating-window", Pt, { "smwb-collapsed": c }),
221
- style: Nt,
222
- onPointerDown: Z,
234
+ "aria-labelledby": I ? V : void 0,
235
+ className: nt("smwb-floating-window", Dt, { "smwb-collapsed": w }),
236
+ style: Ft,
237
+ onPointerDown: q,
223
238
  children: [
224
- /* @__PURE__ */ N(
239
+ /* @__PURE__ */ T(
225
240
  "div",
226
241
  {
227
242
  className: "smwb-floating-window__header",
228
243
  "data-testid": "floating-window-header",
229
- onPointerDown: kt,
230
- onPointerMove: zt,
231
- onPointerUp: j,
232
- onPointerCancel: j,
244
+ onPointerDown: St,
245
+ onPointerMove: Lt,
246
+ onPointerUp: B,
247
+ onPointerCancel: B,
233
248
  children: [
234
249
  /* @__PURE__ */ s(
235
250
  "span",
@@ -238,34 +253,34 @@ const Vt = {
238
253
  "data-testid": "floating-window-move",
239
254
  role: "button",
240
255
  tabIndex: 0,
241
- "aria-label": mt,
242
- onKeyDown: Et,
256
+ "aria-label": xt,
257
+ onKeyDown: Kt,
243
258
  children: /* @__PURE__ */ s(v, { name: "drag_indicator" })
244
259
  }
245
260
  ),
246
- A ? /* @__PURE__ */ s("span", { className: "smwb-floating-window__title", id: $, children: A }) : null,
247
- /* @__PURE__ */ N("div", { className: "smwb-floating-window__actions", "data-no-drag": !0, children: [
248
- nt,
249
- ut ? /* @__PURE__ */ s(
261
+ I ? /* @__PURE__ */ s("span", { className: "smwb-floating-window__title", id: V, children: I }) : null,
262
+ /* @__PURE__ */ T("div", { className: "smwb-floating-window__actions", "data-no-drag": !0, children: [
263
+ rt,
264
+ mt ? /* @__PURE__ */ s(
250
265
  "button",
251
266
  {
252
267
  type: "button",
253
268
  className: "smwb-floating-window__action",
254
269
  "data-testid": "floating-window-collapse",
255
- "aria-label": c ? bt : xt,
256
- "aria-expanded": !c,
257
- onClick: Lt,
258
- children: /* @__PURE__ */ s(v, { name: c ? "open_in_full" : "close_fullscreen" })
270
+ "aria-label": w ? Rt : _t,
271
+ "aria-expanded": !w,
272
+ onClick: Ot,
273
+ children: /* @__PURE__ */ s(v, { name: w ? "open_in_full" : "close_fullscreen" })
259
274
  }
260
275
  ) : null,
261
- P ? /* @__PURE__ */ s(
276
+ _ ? /* @__PURE__ */ s(
262
277
  "button",
263
278
  {
264
279
  type: "button",
265
280
  className: "smwb-floating-window__action",
266
281
  "data-testid": "floating-window-close",
267
- "aria-label": yt,
268
- onClick: P,
282
+ "aria-label": Pt,
283
+ onClick: _,
269
284
  children: /* @__PURE__ */ s(v, { name: "close" })
270
285
  }
271
286
  ) : null
@@ -273,25 +288,25 @@ const Vt = {
273
288
  ]
274
289
  }
275
290
  ),
276
- c ? null : /* @__PURE__ */ s("div", { className: "smwb-floating-window__body", "data-testid": "floating-window-body", children: _t }),
277
- pt && !c ? Xt.map((t) => /* @__PURE__ */ s(
291
+ w ? null : /* @__PURE__ */ s("div", { className: "smwb-floating-window__body", "data-testid": "floating-window-body", children: Mt }),
292
+ yt && !w ? Gt.map((t) => /* @__PURE__ */ s(
278
293
  "div",
279
294
  {
280
- className: W("smwb-floating-window__resize", `smwb-floating-window__resize_${t}`),
295
+ className: nt("smwb-floating-window__resize", `smwb-floating-window__resize_${t}`),
281
296
  "data-testid": `floating-window-resize-${t}`,
282
297
  ...t === "se" ? {
283
298
  role: "separator",
284
299
  tabIndex: 0,
285
- "aria-label": gt,
286
- "aria-valuemin": b,
287
- "aria-valuemax": Math.round(a != null ? a : y().width),
288
- "aria-valuenow": Math.round(w.width),
289
- onKeyDown: St
300
+ "aria-label": bt,
301
+ "aria-valuemin": P,
302
+ "aria-valuemax": Math.round(a != null ? a : u().width),
303
+ "aria-valuenow": Math.round(h.width),
304
+ onKeyDown: vt
290
305
  } : { "aria-hidden": !0, tabIndex: -1 },
291
- onPointerDown: (e) => At(t, e),
292
- onPointerMove: It,
293
- onPointerUp: G,
294
- onPointerCancel: G
306
+ onPointerDown: (e) => Nt(t, e),
307
+ onPointerMove: Tt,
308
+ onPointerUp: J,
309
+ onPointerCancel: J
295
310
  },
296
311
  t
297
312
  )) : null
@@ -300,11 +315,11 @@ const Vt = {
300
315
  )
301
316
  }
302
317
  ),
303
- U
318
+ $
304
319
  );
305
320
  }
306
321
  );
307
322
  export {
308
- oe as FloatingWindow
323
+ se as FloatingWindow
309
324
  };
310
325
  //# sourceMappingURL=floatingWindow.js.map