se-design 1.0.84 → 1.0.85-dev.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.
package/dist/index19.js CHANGED
@@ -1,34 +1,34 @@
1
- import B, { forwardRef as we, useState as F, useRef as te, useEffect as M, useImperativeHandle as ge } from "react";
1
+ import S, { forwardRef as we, useState as F, useRef as te, useEffect as B, useImperativeHandle as ge } from "react";
2
2
  import he from "react-dom";
3
3
  import { getA11yNameAttributes as be } from "./index81.js";
4
4
  import { useDismissOnFocusOut as ye } from "./index80.js";
5
- import { getFirstFocusableElement as D, getLastFocusableElement as Ee, getFocusableElements as N, FOCUSABLE_WITH_ROLES_SELECTOR as ke } from "./index71.js";
5
+ import { getFirstFocusableElement as M, getLastFocusableElement as Ee, getFocusableElements as N, FOCUSABLE_WITH_ROLES_SELECTOR as Pe } from "./index71.js";
6
6
  import "./index72.js";
7
- import { useRegisterPortalWithFocusTrap as Pe } from "./index208.js";
8
- function T() {
9
- return T = Object.assign ? Object.assign.bind() : function(y) {
7
+ import { useRegisterPortalWithFocusTrap as ke } from "./index208.js";
8
+ function q() {
9
+ return q = Object.assign ? Object.assign.bind() : function(y) {
10
10
  for (var E = 1; E < arguments.length; E++) {
11
11
  var m = arguments[E];
12
12
  for (var h in m) ({}).hasOwnProperty.call(m, h) && (y[h] = m[h]);
13
13
  }
14
14
  return y;
15
- }, T.apply(null, arguments);
15
+ }, q.apply(null, arguments);
16
16
  }
17
17
  const He = /* @__PURE__ */ we(({
18
18
  className: y = "",
19
19
  automationId: E = "",
20
20
  position: m = "bottom-center",
21
21
  popoverContentAutomationId: h = "",
22
- contentWidth: R = "max",
22
+ contentWidth: D = "max",
23
23
  renderPopoverContents: K,
24
24
  renderPopoverSrcElement: oe,
25
- onPopoverToggle: z,
26
- isPopoverOpen: C,
27
- disabled: k = !1,
28
- isWithPortal: f = !1,
25
+ onPopoverToggle: T,
26
+ isPopoverOpen: z,
27
+ disabled: P = !1,
28
+ isWithPortal: p = !1,
29
29
  ariaLabel: ne,
30
30
  ariaLabelledBy: re,
31
- sourceRole: q = "button",
31
+ sourceRole: C = "button",
32
32
  popupType: _ = "true",
33
33
  popoverContentStyleProperty: $ = {
34
34
  zIndex: 1e3,
@@ -42,8 +42,8 @@ const He = /* @__PURE__ */ we(({
42
42
  focusFirstOnOpen: ie = !1,
43
43
  ...ce
44
44
  }, ae) => {
45
- const [i, p] = F(!1), [P, U] = F(m), [le, V] = F(!1), l = te(null), c = te(null);
46
- Pe(c, f && i);
45
+ const [i, f] = F(!1), [k, U] = F(m), [le, W] = F(!1), l = te(null), a = te(null);
46
+ ke(a, p && i);
47
47
  const ue = be({
48
48
  ariaLabel: ne,
49
49
  ariaLabelledBy: re,
@@ -52,30 +52,30 @@ const He = /* @__PURE__ */ we(({
52
52
  }), {
53
53
  onBlurCapture: fe
54
54
  } = ye({
55
- disabled: !i || v || f,
56
- onFocusOut: () => p(!1),
55
+ disabled: !i || v || p,
56
+ onFocusOut: () => f(!1),
57
57
  closeOnEscape: !1
58
- }), [L, A] = F({
58
+ }), [R, A] = F({
59
59
  top: 0,
60
60
  left: 0,
61
61
  srcWidth: 0
62
- }), [pe, W] = F(!1), b = () => {
63
- g ? (D({
62
+ }), [pe, V] = F(!1), b = () => {
63
+ g ? (M({
64
64
  container: l.current,
65
65
  includeRoles: !0
66
66
  }) ?? l.current)?.focus() : l.current?.focus();
67
67
  }, X = (e) => {
68
- p(!1), e?.returnFocus !== !1 && requestAnimationFrame(() => {
68
+ f(!1), e?.returnFocus !== !1 && requestAnimationFrame(() => {
69
69
  e?.returnFocusTo ? (e.returnFocusTo instanceof HTMLElement ? e.returnFocusTo : e.returnFocusTo.current)?.focus() : b();
70
70
  });
71
- }, O = (e = "bottom-center") => {
71
+ }, L = (e = "bottom-center") => {
72
72
  if (!l.current) return {
73
73
  top: 0,
74
74
  left: 0,
75
75
  srcWidth: 0
76
76
  };
77
77
  let o = e;
78
- const t = l.current.getBoundingClientRect(), r = window.innerWidth - document.documentElement.clientWidth, u = window.innerWidth - Math.max(r, 16), a = window.innerHeight;
78
+ const t = l.current.getBoundingClientRect(), r = window.innerWidth - document.documentElement.clientWidth, u = window.innerWidth - Math.max(r, 16), c = window.innerHeight;
79
79
  let n = 0, s = 0;
80
80
  switch (o) {
81
81
  case "bottom-left":
@@ -100,100 +100,107 @@ const He = /* @__PURE__ */ we(({
100
100
  n = t.bottom, s = t.left;
101
101
  break;
102
102
  }
103
- const d = c.current?.getBoundingClientRect(), x = (R === "full" ? Math.max(t.width, d?.width || 0) : d?.width) || 0, w = d?.height || 0;
104
- if ((o === "bottom-center" || o === "top-center") && (s = s - x / 2), s + x > u && (s = Math.max(0, u - x)), s < 0 && (s = 0), n + w > a) {
105
- const ee = t.top, ve = a - t.bottom;
106
- ee >= w || ee > ve ? (n = t.top - w, n < 48 && (n = 48)) : n = Math.max(48, a - w);
103
+ const d = a.current?.getBoundingClientRect(), x = (D === "full" ? Math.max(t.width, d?.width || 0) : d?.width) || 0, w = d?.height || 0;
104
+ if ((o === "bottom-center" || o === "top-center") && (s = s - x / 2), s + x > u && (s = Math.max(0, u - x)), s < 0 && (s = 0), n + w > c) {
105
+ const ee = t.top, ve = c - t.bottom;
106
+ ee >= w || ee > ve ? (n = t.top - w, n < 48 && (n = 48)) : n = Math.max(48, c - w);
107
107
  }
108
- return n < 48 && (n = t.bottom, n + w > a && (n = Math.max(48, a - w))), {
108
+ return n < 48 && (n = t.bottom, n + w > c && (n = Math.max(48, c - w))), {
109
109
  top: Math.round(n),
110
110
  left: Math.round(s),
111
111
  srcWidth: t.width
112
112
  };
113
113
  };
114
- M(() => {
115
- if (z && z(i), i && !f)
114
+ B(() => {
115
+ if (T && T(i), i && !p)
116
116
  return v || document.body.addEventListener("click", j, !0), de(), () => {
117
117
  v || document.body.removeEventListener("click", j, !0);
118
118
  };
119
- if (i && f) {
120
- v ? window.addEventListener("scroll", G) : (document.body.addEventListener("click", I, !0), window.addEventListener("scroll", I)), window.addEventListener("resize", Y);
119
+ if (i && p) {
120
+ v ? window.addEventListener("scroll", G) : (document.body.addEventListener("click", H, !0), window.addEventListener("scroll", H)), window.addEventListener("resize", Y);
121
121
  const e = (r) => {
122
- r.key === "Escape" && c.current?.contains(document.activeElement) && (r.preventDefault(), r.stopPropagation(), p(!1), requestAnimationFrame(() => b()));
122
+ r.key === "Escape" && a.current?.contains(document.activeElement) && (r.preventDefault(), r.stopPropagation(), f(!1), requestAnimationFrame(() => b()));
123
123
  };
124
- window.addEventListener("keydown", e, !0), H();
124
+ window.addEventListener("keydown", e, !0), I();
125
125
  let o, t;
126
126
  return o = requestAnimationFrame(() => {
127
127
  t = requestAnimationFrame(() => {
128
- const r = O(P);
129
- r && A(r), W(!0);
128
+ const r = L(k);
129
+ r && A(r), V(!0);
130
130
  });
131
131
  }), () => {
132
- v ? window.removeEventListener("scroll", G) : (document.body.removeEventListener("click", I, !0), window.removeEventListener("scroll", I)), window.removeEventListener("resize", Y), window.removeEventListener("keydown", e, !0), cancelAnimationFrame(o), cancelAnimationFrame(t), W(!1);
132
+ v ? window.removeEventListener("scroll", G) : (document.body.removeEventListener("click", H, !0), window.removeEventListener("scroll", H)), window.removeEventListener("resize", Y), window.removeEventListener("keydown", e, !0), cancelAnimationFrame(o), cancelAnimationFrame(t), V(!1);
133
133
  };
134
134
  }
135
- }, [i, f, v]);
136
- const H = () => {
135
+ }, [i, p, v]);
136
+ const I = () => {
137
137
  if (!l.current) {
138
- V(!1);
138
+ W(!1);
139
139
  return;
140
140
  }
141
141
  const e = l.current.getBoundingClientRect(), o = window.innerHeight, t = window.innerWidth, r = e.top < o && e.bottom > 0 && e.left < t && e.right > 0;
142
- V(r);
142
+ W(r);
143
143
  };
144
- M(() => {
145
- p(C ?? !1);
146
- }, [C]), M(() => {
147
- i && setTimeout(() => {
148
- const e = D({
149
- container: c.current,
150
- includeRoles: !0
151
- });
152
- e && (ie || document.activeElement === l.current) && e.focus();
153
- }, f ? 60 : 0);
144
+ B(() => {
145
+ f(z ?? !1);
146
+ }, [z]), B(() => {
147
+ if (i) {
148
+ let e, o;
149
+ return e = requestAnimationFrame(() => {
150
+ o = requestAnimationFrame(() => {
151
+ const t = M({
152
+ container: a.current,
153
+ includeRoles: !0
154
+ });
155
+ t && (ie || document.activeElement === l.current) && t.focus();
156
+ });
157
+ }), () => {
158
+ cancelAnimationFrame(e), cancelAnimationFrame(o);
159
+ };
160
+ }
154
161
  }, [i]);
155
162
  const de = () => {
156
- if (!c.current) return;
157
- const e = c.current.getBoundingClientRect(), o = window.innerHeight;
163
+ if (!a.current) return;
164
+ const e = a.current.getBoundingClientRect(), o = window.innerHeight;
158
165
  e?.bottom > o ? U(m.includes("left") ? "top-left" : m.includes("right") ? "top-right" : "top-center") : e?.top < 0 && U(m.includes("left") ? "bottom-left" : m.includes("right") ? "bottom-right" : "bottom-center");
159
166
  }, j = (e) => {
160
167
  const o = l.current;
161
168
  if (!o) return;
162
- const t = e.target, r = o.contains(t), u = c.current?.contains(t), n = t.closest?.(".se-design-popover-wrapper"), s = n && n !== o, d = c.current?.contains(n);
163
- v || (!r && !u || s && !d) && p(!1);
164
- }, I = (e) => {
165
- const o = l.current, t = c.current;
169
+ const t = e.target, r = o.contains(t), u = a.current?.contains(t), n = t.closest?.(".se-design-popover-wrapper"), s = n && n !== o, d = a.current?.contains(n);
170
+ v || (!r && !u || s && !d) && f(!1);
171
+ }, H = (e) => {
172
+ const o = l.current, t = a.current;
166
173
  if (!o) return;
167
- if (H(), e.type === "scroll" && i) {
168
- const w = O(P);
174
+ if (I(), e.type === "scroll" && i) {
175
+ const w = L(k);
169
176
  w && A(w);
170
177
  }
171
- const r = e.target, u = o.contains(r), a = t?.contains(r), s = r.closest?.(".se-design-popover-wrapper"), d = s && s !== o, x = c.current?.contains(s);
172
- v || (!u && !a || d && !x) && p(!1);
178
+ const r = e.target, u = o.contains(r), c = t?.contains(r), s = r.closest?.(".se-design-popover-wrapper"), d = s && s !== o, x = a.current?.contains(s);
179
+ v || (!u && !c || d && !x) && f(!1);
173
180
  }, Y = () => {
174
- if (i && f && l.current) {
175
- H();
176
- const e = O(P);
181
+ if (i && p && l.current) {
182
+ I();
183
+ const e = L(k);
177
184
  e && A(e);
178
185
  }
179
186
  }, G = () => {
180
- if (i && f && l.current) {
181
- H();
182
- const e = O(P);
187
+ if (i && p && l.current) {
188
+ I();
189
+ const e = L(k);
183
190
  e && A(e);
184
191
  }
185
- }, S = (e = !1) => {
192
+ }, O = (e = !1) => {
186
193
  const o = i;
187
- p((t) => !t), !o && e && setTimeout(() => {
194
+ f((t) => !t), !o && e && setTimeout(() => {
188
195
  if (e === "last") {
189
196
  const t = Ee({
190
- container: c.current,
197
+ container: a.current,
191
198
  includeRoles: !0
192
199
  });
193
200
  t && t.focus();
194
201
  } else {
195
- const t = D({
196
- container: c.current,
202
+ const t = M({
203
+ container: a.current,
197
204
  includeRoles: !0
198
205
  });
199
206
  t && t.focus();
@@ -204,36 +211,36 @@ const He = /* @__PURE__ */ we(({
204
211
  const t = document.activeElement;
205
212
  if (t?.tagName === "INPUT" || t?.tagName === "TEXTAREA" || t?.tagName === "SELECT")
206
213
  return;
207
- const r = Array.from(o.querySelectorAll(ke)).filter((n) => {
214
+ const r = Array.from(o.querySelectorAll(Pe)).filter((n) => {
208
215
  const s = window.getComputedStyle(n);
209
216
  return !n.hasAttribute("disabled") && n.getAttribute("aria-disabled") !== "true" && s.display !== "none" && s.visibility !== "hidden" && (n.tabIndex >= 0 || n.hasAttribute("role"));
210
217
  });
211
218
  if (r.length === 0) return;
212
219
  const u = r.findIndex((n) => n === document.activeElement);
213
- let a = -1;
214
- e.key === "ArrowDown" ? (e.preventDefault(), e.stopPropagation(), a = u < r.length - 1 ? u + 1 : 0) : e.key === "ArrowUp" ? (e.preventDefault(), e.stopPropagation(), a = u > 0 ? u - 1 : r.length - 1) : e.key === "Home" ? (e.preventDefault(), e.stopPropagation(), a = 0) : e.key === "End" && (e.preventDefault(), e.stopPropagation(), a = r.length - 1), a >= 0 && r[a] ? r[a].focus() : u === -1 && r.length > 0 && r[0].focus();
220
+ let c = -1;
221
+ e.key === "ArrowDown" ? (e.preventDefault(), e.stopPropagation(), c = u < r.length - 1 ? u + 1 : 0) : e.key === "ArrowUp" ? (e.preventDefault(), e.stopPropagation(), c = u > 0 ? u - 1 : r.length - 1) : e.key === "Home" ? (e.preventDefault(), e.stopPropagation(), c = 0) : e.key === "End" && (e.preventDefault(), e.stopPropagation(), c = r.length - 1), c >= 0 && r[c] ? r[c].focus() : u === -1 && r.length > 0 && r[0].focus();
215
222
  }, Q = (e) => {
216
223
  if (e.key === "Escape")
217
- e.preventDefault(), e.stopPropagation(), p(!1), requestAnimationFrame(() => b());
224
+ e.preventDefault(), e.stopPropagation(), f(!1), requestAnimationFrame(() => b());
218
225
  else if (e.key === "Tab") {
219
226
  if (_ === "dialog") {
220
227
  const o = N({
221
- container: c.current,
228
+ container: a.current,
222
229
  filterHidden: !0
223
230
  }), t = o.indexOf(e.target), r = t === o.length - 1, u = t === 0 || t === -1;
224
231
  if (e.shiftKey && u)
225
- e.preventDefault(), p(!1), b();
226
- else if (!e.shiftKey && r && (p(!1), f)) {
232
+ e.preventDefault(), f(!1), b();
233
+ else if (!e.shiftKey && r && (f(!1), p)) {
227
234
  e.preventDefault();
228
- const a = l.current, n = N({
235
+ const c = l.current, n = N({
229
236
  container: document.body,
230
237
  filterHidden: !0
231
- }), s = a ? n.indexOf(a) : -1, d = n[s + 1];
232
- d ? d.focus() : a?.focus();
238
+ }), s = c ? n.indexOf(c) : -1, d = n[s + 1];
239
+ d ? d.focus() : c?.focus();
233
240
  }
234
- } else if (p(!1), e.shiftKey)
241
+ } else if (f(!1), e.shiftKey)
235
242
  e.preventDefault(), b();
236
- else if (f) {
243
+ else if (p) {
237
244
  e.preventDefault();
238
245
  const o = l.current, t = N({
239
246
  container: document.body,
@@ -241,10 +248,10 @@ const He = /* @__PURE__ */ we(({
241
248
  }), r = o ? t.indexOf(o) : -1, u = t[r + 1];
242
249
  u ? u.focus() : o?.focus();
243
250
  }
244
- } else e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End" ? J(e, c.current) : (e.key === "Enter" || e.key === " ") && e.stopPropagation();
251
+ } else e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End" ? J(e, a.current) : (e.key === "Enter" || e.key === " ") && e.stopPropagation();
245
252
  };
246
253
  ge(ae, () => ({
247
- togglePopover: S,
254
+ togglePopover: O,
248
255
  focusTrigger: () => b(),
249
256
  element: l.current
250
257
  }), []);
@@ -276,83 +283,69 @@ const He = /* @__PURE__ */ we(({
276
283
  bottom: "100%"
277
284
  }
278
285
  }, Z = se ? "" : "shadow-md border rounded-md";
279
- return /* @__PURE__ */ B.createElement("div", T({
280
- className: "se-design-popover-wrapper cursor-pointer relative focus-outline rounded-md" + (y.length > 0 ? ` ${y}` : "") + (i ? " open" : "") + (k ? " opacity-50 cursor-not-allowed pointer-events-none" : ""),
286
+ return /* @__PURE__ */ S.createElement("div", q({
287
+ className: "se-design-popover-wrapper cursor-pointer relative focus-outline rounded-md" + (y.length > 0 ? ` ${y}` : "") + (i ? " open" : "") + (P ? " opacity-50 cursor-not-allowed pointer-events-none" : ""),
281
288
  ref: l,
282
289
  onClick: (e) => {
283
- k || g || (e.stopPropagation(), S());
290
+ P || g || (e.stopPropagation(), O());
284
291
  },
285
292
  onKeyDown: (e) => {
286
- if (!(k || g))
287
- if (e.key === "Enter" || e.key === " ") {
288
- e.preventDefault(), e.stopPropagation();
289
- const o = i;
290
- S(), o || setTimeout(() => {
291
- const t = D({
292
- container: c.current,
293
- includeRoles: !0
294
- });
295
- t && t.focus();
296
- }, f ? 60 : 0);
297
- } else if (e.key === "Escape" && i)
298
- e.preventDefault(), e.stopPropagation(), p(!1);
293
+ if (!(P || g))
294
+ if (e.key === "Enter" || e.key === " ")
295
+ e.preventDefault(), e.stopPropagation(), O();
296
+ else if (e.key === "Escape" && i)
297
+ e.preventDefault(), e.stopPropagation(), f(!1);
299
298
  else if ((e.key === "ArrowDown" || e.key === "ArrowUp") && i) {
300
- const o = c.current;
299
+ const o = a.current;
301
300
  o && J(e, o);
302
- } else e.key === "ArrowDown" && !i && (e.preventDefault(), e.stopPropagation(), p(!0), setTimeout(() => {
303
- const o = D({
304
- container: c.current,
305
- includeRoles: !0
306
- });
307
- o && o.focus();
308
- }, 0));
301
+ } else e.key === "ArrowDown" && !i && (e.preventDefault(), e.stopPropagation(), f(!0));
309
302
  },
310
303
  onBlurCapture: fe,
311
304
  onBlur: (e) => {
312
- if (!i || v || !f) return;
313
- const o = e.relatedTarget, t = !!(o && l.current?.contains(o)), r = !!(o && c.current?.contains(o));
314
- !t && !r && p(!1);
305
+ if (!i || v || !p) return;
306
+ const o = e.relatedTarget, t = !!(o && l.current?.contains(o)), r = !!(o && a.current?.contains(o));
307
+ !t && !r && f(!1);
315
308
  },
316
- role: g ? "none" : q,
309
+ role: g ? "none" : C,
317
310
  "aria-expanded": g ? void 0 : i ? "true" : "false",
318
- "aria-haspopup": g ? void 0 : q === "combobox" ? "listbox" : _,
319
- tabIndex: k || g ? -1 : 0,
320
- "aria-disabled": g ? void 0 : k ? "true" : void 0
311
+ "aria-haspopup": g ? void 0 : C === "combobox" ? "listbox" : _,
312
+ tabIndex: P || g ? -1 : 0,
313
+ "aria-disabled": g ? void 0 : P ? "true" : void 0
321
314
  }, ue, {
322
315
  "data-automation-id": E
323
316
  }, ce), oe({
324
317
  displayPopover: i,
325
- togglePopover: S
326
- }), i && !f && /* @__PURE__ */ B.createElement("div", {
327
- className: `popover-content absolute ${Z} z-[1000] ${R == "full" ? "w-full" : "w-max"}`,
318
+ togglePopover: O
319
+ }), i && !p && /* @__PURE__ */ S.createElement("div", {
320
+ className: `popover-content absolute ${Z} z-[1000] ${D == "full" ? "w-full" : "w-max"}`,
328
321
  style: {
329
322
  ...$,
330
- ...me[P]
323
+ ...me[k]
331
324
  },
332
325
  onClick: (e) => e.stopPropagation(),
333
326
  onKeyDown: Q,
334
- ref: c,
327
+ ref: a,
335
328
  "data-automation-id": h
336
329
  }, K({
337
330
  closePopoverCb: X
338
- })), f && i && le && /* @__PURE__ */ he.createPortal(/* @__PURE__ */ B.createElement("div", {
339
- className: `popover-content-with-portal z-[2002] ${Z} ${R == "full" ? "" : "w-max"}`,
331
+ })), p && i && le && /* @__PURE__ */ he.createPortal(/* @__PURE__ */ S.createElement("div", {
332
+ className: `popover-content-with-portal z-[2002] ${Z} ${D == "full" ? "" : "w-max"}`,
340
333
  style: {
341
334
  position: "fixed",
342
- top: L.top,
343
- left: L.left,
335
+ top: R.top,
336
+ left: R.left,
344
337
  visibility: pe ? "visible" : "hidden",
345
338
  maxHeight: "calc(100vh - 96px)",
346
339
  overflowY: "hidden",
347
- ...R === "full" && L.srcWidth ? {
348
- width: `${L.srcWidth}px`
340
+ ...D === "full" && R.srcWidth ? {
341
+ width: `${R.srcWidth}px`
349
342
  } : {},
350
343
  ...$,
351
344
  zIndex: 2002
352
345
  },
353
346
  onClick: (e) => e.stopPropagation(),
354
347
  onKeyDown: Q,
355
- ref: c,
348
+ ref: a,
356
349
  "data-automation-id": h
357
350
  }, K({
358
351
  closePopoverCb: X