asma-ui-core 3.108.2 → 3.108.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.
@@ -1,167 +1,210 @@
1
- import { cn as k } from "../../../helpers/cn.js";
2
- import { resolveSx as W } from "../../../helpers/sx.js";
3
- import { registerOpenModalDialog as se } from "../../../hooks/useTopLayer.hook.js";
4
- import { CloseIcon as ce } from "../../icons/close-icon/CloseIcon.js";
5
- import { DialogBusyContext as ue, useDialogBusyBoundary as me } from "./DialogBusyContext.js";
6
- import { StyledButton as fe } from "../../inputs/button/StyledButton.js";
7
- import { useMobileMediaQuery as xe } from "../../../hooks/useMediaQuery.hook.js";
8
- import { warnUnnamedDialog as pe } from "../../../helpers/warnUnnamedDialog.js";
9
- import he from "./StyledDialog.module.js";
10
- import { StyledDialogTitleContext as ye } from "./dialogTitleContext.js";
11
- import { useEffect as E, useId as D, useLayoutEffect as P, useMemo as we, useRef as i, useState as q } from "react";
12
- import { jsx as r, jsxs as d } from "react/jsx-runtime";
13
- var ve = {
1
+ import { cn as B } from "../../../helpers/cn.js";
2
+ import { resolveSx as K } from "../../../helpers/sx.js";
3
+ import { registerOpenModalDialog as ve } from "../../../hooks/useTopLayer.hook.js";
4
+ import { CloseIcon as xe } from "../../icons/close-icon/CloseIcon.js";
5
+ import { DialogBusyContext as ye, useDialogBusyBoundary as pe } from "./DialogBusyContext.js";
6
+ import { StyledButton as we } from "../../inputs/button/StyledButton.js";
7
+ import { useMobileMediaQuery as ge } from "../../../hooks/useMediaQuery.hook.js";
8
+ import { OverlayBackOwnerContext as be, isOverlayBackEnabled as T, requestCloseTopOverlayBack as D, useBackCloses as ke } from "../../../hooks/useBackCloses.hook.js";
9
+ import { warnUnnamedDialog as Ce } from "../../../helpers/warnUnnamedDialog.js";
10
+ import Ee from "./StyledDialog.module.js";
11
+ import { StyledDialogTitleContext as Be } from "./dialogTitleContext.js";
12
+ import { useEffect as a, useId as I, useLayoutEffect as U, useMemo as De, useRef as l, useState as X } from "react";
13
+ import { jsx as i, jsxs as d } from "react/jsx-runtime";
14
+ var Ie = {
14
15
  xs: 444,
15
16
  sm: 600,
16
17
  md: 900,
17
18
  lg: 1200,
18
19
  xl: 1536
19
- }, _e = ({ open: t, onClose: y, children: C, dataTest: a, maxWidth: I = "sm", fullWidth: z, fullScreen: K, scroll: A = "paper", disableEscapeKeyDown: F, className: L, style: U, sx: X, classes: S, PaperProps: G, slotProps: s, busyReason: Q, locale: T = "en", onCloseText: N, showCloseIcon: H = !0, dialogLabel: c, dialogTitle: u, dialogHeaderNode: V, ariaLabel: w }) => {
20
- const m = D(), R = D(), [$, J] = q(), Y = we(() => ({
21
- titleId: m,
22
- setTitleId: J
23
- }), [m]), f = u ? m : $ ?? (c ? R : void 0), Z = xe(), l = i(null), v = i(null), b = i(!1), M = i(t), x = K ?? Z, { busy: p, busyReason: ee, contextValue: te } = me(Q, T), _ = D(), [h, ne] = q(), B = i(!1);
24
- P(() => {
25
- const e = l.current, n = !!f || !!w, o = e && t && !n ? e.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]') : null;
26
- o && !o.id && (o.id = _);
27
- const O = o?.id;
28
- O !== h && ne(O), e && t && !n && !o && !B.current && (B.current = !0, pe(a));
20
+ }, Fe = ({ open: t, onClose: R, children: S, dataTest: u, maxWidth: N = "sm", fullWidth: G, fullScreen: Q, scroll: V = "paper", disableEscapeKeyDown: H, className: $, style: J, sx: Y, classes: O, PaperProps: Z, slotProps: f, busyReason: ee, locale: te = "en", onCloseText: q, showCloseIcon: M = !0, dialogLabel: m, dialogTitle: h, dialogHeaderNode: re, ariaLabel: g }) => {
21
+ const v = I(), P = I(), [ne, oe] = X(), le = De(() => ({
22
+ titleId: v,
23
+ setTitleId: oe
24
+ }), [v]), x = h ? v : ne ?? (m ? P : void 0), ie = ge(), s = l(null), b = l(null), k = l(!1), C = l(!1), c = l(!1), _ = l(t);
25
+ a(() => {
26
+ _.current = t;
27
+ }, [t]);
28
+ const L = l(t), y = Q ?? ie, { busy: p, busyReason: se, contextValue: ae } = pe(ee, te), j = I(), [w, ce] = X(), W = l(!1);
29
+ U(() => {
30
+ const e = s.current, r = !!x || !!g, n = e && t && !r ? e.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]') : null;
31
+ n && !n.id && (n.id = j);
32
+ const o = n?.id;
33
+ o !== w && ce(o), e && t && !r && !n && !W.current && (W.current = !0, Ce(u));
29
34
  }, [
30
35
  t,
31
- f,
36
+ x,
37
+ g,
38
+ S,
32
39
  w,
33
- C,
34
- h,
35
- _,
36
- a
37
- ]), E(() => {
38
- M.current && !t && s?.transition?.onExited?.(), M.current = t;
39
- }, [t, s]), P(() => {
40
- const e = l.current;
40
+ j,
41
+ u
42
+ ]), a(() => {
43
+ L.current && !t && f?.transition?.onExited?.(), L.current = t;
44
+ }, [t, f]), U(() => {
45
+ const e = s.current;
41
46
  if (!e || !t) return;
42
- e.open || (v.current = document.activeElement instanceof HTMLElement ? document.activeElement : null, e.showModal(), e.focus({ preventScroll: !0 }), requestAnimationFrame(() => e.open && e.focus({ preventScroll: !0 })));
43
- const n = se(e);
47
+ e.open || (b.current = document.activeElement instanceof HTMLElement ? document.activeElement : null, e.showModal(), e.focus({ preventScroll: !0 }), requestAnimationFrame(() => e.open && e.focus({ preventScroll: !0 })));
48
+ const r = ve(e);
44
49
  return () => {
45
- n(), v.current?.isConnected && v.current.focus({ preventScroll: !0 });
50
+ r(), b.current?.isConnected && b.current.focus({ preventScroll: !0 });
46
51
  };
47
- }, [t]), E(() => {
52
+ }, [t]), a(() => {
48
53
  if (!t) return;
49
- const e = document.body.style.overflow, n = document.documentElement.style.overflow;
54
+ const e = document.body.style.overflow, r = document.documentElement.style.overflow;
50
55
  return document.body.style.overflow = "hidden", document.documentElement.style.overflow = "hidden", () => {
51
- document.body.style.overflow = e, document.documentElement.style.overflow = n;
56
+ document.body.style.overflow = e, document.documentElement.style.overflow = r;
52
57
  };
53
58
  }, [t]);
54
- const g = {
55
- ...G,
56
- ...s?.paper
57
- }, j = I === !1 ? void 0 : ve[I], { className: oe, style: re, onClick: le, ...ie } = s?.backdrop ?? {}, de = (e) => {
58
- p || b.current || (b.current = !0, window.setTimeout(() => {
59
- b.current = !1;
60
- }, 0), y?.(e, "escapeKeyDown"));
61
- }, ae = (e) => {
62
- e.preventDefault();
59
+ const E = {
60
+ ...Z,
61
+ ...f?.paper
62
+ }, z = N === !1 ? void 0 : Ie[N], { className: de, style: ue, onClick: fe, ...me } = f?.backdrop ?? {}, A = (e, r) => {
63
+ if (p || c.current) return;
64
+ const n = R?.(e, r);
65
+ if (n && typeof n.then == "function") {
66
+ c.current = !0;
67
+ const o = () => {
68
+ c.current = !1;
69
+ };
70
+ n.then(o, o);
71
+ }
72
+ return n;
73
+ }, F = (e) => k.current ? !1 : (k.current = !0, window.setTimeout(() => {
74
+ k.current = !1;
75
+ }, 0), A(e, "escapeKeyDown"));
76
+ ke({
77
+ active: t,
78
+ requestClose: (e) => !R || H || p || c.current ? !1 : F(e ?? new Event("overlayBack")),
79
+ ownerRef: s
80
+ });
81
+ const he = (e) => {
82
+ e.cancelable && e.preventDefault(), !C.current && T() && D();
63
83
  };
64
- return E(() => {
65
- if (!t || F) return;
66
- const e = (n) => {
67
- if (n.key !== "Escape" || n.defaultPrevented) return;
68
- const o = document.activeElement;
69
- o instanceof Element && o.closest("dialog[open]") !== l.current || de(n);
84
+ return a(() => {
85
+ const e = s.current;
86
+ if (!e || !t) return;
87
+ let r = !1;
88
+ const n = () => {
89
+ requestAnimationFrame(() => {
90
+ r = !1, _.current && e.isConnected && !e.open && (e.showModal(), e.focus({ preventScroll: !0 }));
91
+ });
92
+ }, o = () => {
93
+ r || (r = !0, T() && !c.current && D(), n());
94
+ };
95
+ return e.addEventListener("close", o), () => e.removeEventListener("close", o);
96
+ }, [t]), a(() => {
97
+ if (!t || H) return;
98
+ const e = (r) => {
99
+ r.key !== "Escape" || r.defaultPrevented || (r.preventDefault(), r.stopImmediatePropagation(), D(r));
70
100
  };
71
101
  return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
72
- }), t ? /* @__PURE__ */ d("dialog", {
73
- ref: l,
102
+ }), a(() => {
103
+ if (!t) return;
104
+ const e = (r) => {
105
+ r.key === "Escape" && (C.current = !0, window.setTimeout(() => {
106
+ C.current = !1;
107
+ }, 0));
108
+ };
109
+ return window.addEventListener("keydown", e, !0), () => window.removeEventListener("keydown", e, !0);
110
+ }, [t]), t ? /* @__PURE__ */ d("dialog", {
111
+ ref: s,
74
112
  tabIndex: -1,
75
- "data-testid": a,
76
- "aria-labelledby": f ?? h,
77
- "aria-label": f || h ? void 0 : w,
78
- onCancel: ae,
113
+ "data-testid": u,
114
+ "aria-labelledby": x ?? w,
115
+ "aria-label": x || w ? void 0 : g,
116
+ onCancel: he,
79
117
  onKeyDown: (e) => {
80
- !p || e.key !== "Escape" || e.target.closest("dialog[open]") === l.current && e.preventDefault();
118
+ !p || e.key !== "Escape" || e.target.closest("dialog[open]") === s.current && e.preventDefault();
81
119
  },
82
- className: k(he.StyledDialog, "fixed inset-0 m-0 h-full max-h-none w-full max-w-none items-center justify-center overflow-hidden border-0 bg-transparent p-0 outline-none open:flex", A === "body" && "overflow-y-auto", L, S?.root),
120
+ className: B(Ee.StyledDialog, "fixed inset-0 m-0 h-full max-h-none w-full max-w-none items-center justify-center overflow-hidden border-0 bg-transparent p-0 outline-none open:flex", V === "body" && "overflow-y-auto", $, O?.root),
83
121
  style: {
84
122
  zIndex: 999,
85
- ...W(X),
86
- ...U
123
+ ...K(Y),
124
+ ...J
87
125
  },
88
- children: [/* @__PURE__ */ r("div", {
89
- ...ie,
90
- className: k("absolute inset-0 bg-[#626e7eb2]", oe),
91
- style: re,
126
+ children: [/* @__PURE__ */ i("div", {
127
+ ...me,
128
+ className: B("absolute inset-0 bg-[#626e7eb2]", de),
129
+ style: ue,
92
130
  onClick: (e) => {
93
- le?.(e), !e.defaultPrevented && !p && y?.(e, "backdropClick");
131
+ fe?.(e), e.defaultPrevented || A(e, "backdropClick");
94
132
  }
95
133
  }), /* @__PURE__ */ d("div", {
96
- className: k("relative z-[1] flex flex-col overflow-hidden rounded-lg border-0 bg-white p-0 text-delta-800 shadow-[0px_4px_40px_0px_#22213366]", x && "rounded-none", g.className, S?.paper),
134
+ className: B("relative z-[1] flex flex-col overflow-hidden rounded-lg border-0 bg-white p-0 text-delta-800 shadow-[0px_4px_40px_0px_#22213366]", y && "rounded-none", E.className, O?.paper),
97
135
  style: {
98
136
  minWidth: 0,
99
137
  minHeight: 0,
100
- ...!x && j ? { maxWidth: j } : {},
101
- ...x ? {
138
+ ...!y && z ? { maxWidth: z } : {},
139
+ ...y ? {
102
140
  width: "100%",
103
141
  maxWidth: "100%",
104
142
  height: "100%",
105
143
  maxHeight: "100%"
106
144
  } : {
107
- width: z ? "calc(100% - 64px)" : "auto",
145
+ width: G ? "calc(100% - 64px)" : "auto",
108
146
  maxHeight: "100%"
109
147
  },
110
- ...W(g.sx),
111
- ...g.style,
112
- ...x ? {
148
+ ...K(E.sx),
149
+ ...E.style,
150
+ ...y ? {
113
151
  width: "100%",
114
152
  maxWidth: "100%",
115
153
  height: "100%",
116
154
  maxHeight: "100%"
117
155
  } : { maxHeight: "calc(100% - 64px)" }
118
156
  },
119
- children: [(!!c || !!u || H) && /* @__PURE__ */ d("div", {
157
+ children: [(!!m || !!h || M) && /* @__PURE__ */ d("div", {
120
158
  className: "box-border flex w-full min-w-0 max-w-full justify-between px-4 pt-4",
121
159
  children: [/* @__PURE__ */ d("div", {
122
160
  className: "flex min-w-0 flex-1 flex-col justify-start gap-0.5",
123
- children: [c && /* @__PURE__ */ r("div", {
124
- id: R,
161
+ children: [m && /* @__PURE__ */ i("div", {
162
+ id: P,
125
163
  className: "flex h-8 items-center text-sm font-normal leading-5 text-delta-600",
126
- children: c
127
- }), u && /* @__PURE__ */ r("div", {
128
- id: m,
164
+ children: m
165
+ }), h && /* @__PURE__ */ i("div", {
166
+ id: v,
129
167
  className: "flex text-2xl font-semibold leading-8 text-delta-800",
130
- children: u
168
+ children: h
131
169
  })]
132
- }), H && /* @__PURE__ */ d("div", {
170
+ }), M && /* @__PURE__ */ d("div", {
133
171
  className: "flex min-w-0 max-w-full shrink-0 justify-end gap-2",
134
- children: [V, /* @__PURE__ */ r(fe, {
135
- dataTest: `close-button-${a}`,
136
- "aria-label": N ? void 0 : "Close",
172
+ children: [re, /* @__PURE__ */ i(we, {
173
+ dataTest: `close-button-${u}`,
174
+ "aria-label": q ? void 0 : "Close",
137
175
  variant: "textGray",
138
176
  size: "small",
139
- endIcon: /* @__PURE__ */ r(ce, {
177
+ endIcon: /* @__PURE__ */ i(xe, {
140
178
  width: 20,
141
179
  height: 20
142
180
  }),
143
181
  className: "max-w-full shrink-0 whitespace-nowrap",
144
182
  disabled: p,
145
- disabledReason: ee,
146
- onClick: (e) => y?.(e, "escapeKeyDown"),
183
+ disabledReason: se,
184
+ onClick: (e) => {
185
+ F(e);
186
+ },
147
187
  style: {
148
188
  color: "var(--colors-delta-800)",
149
189
  paddingRight: "6px",
150
190
  paddingLeft: "6px"
151
191
  },
152
- children: N
192
+ children: q
153
193
  })]
154
194
  })]
155
- }), /* @__PURE__ */ r(ye.Provider, {
156
- value: Y,
157
- children: /* @__PURE__ */ r(ue.Provider, {
158
- value: te,
159
- children: C
195
+ }), /* @__PURE__ */ i(be.Provider, {
196
+ value: s,
197
+ children: /* @__PURE__ */ i(Be.Provider, {
198
+ value: le,
199
+ children: /* @__PURE__ */ i(ye.Provider, {
200
+ value: ae,
201
+ children: S
202
+ })
160
203
  })
161
204
  })]
162
205
  })]
163
206
  }) : null;
164
207
  };
165
208
  export {
166
- _e as StyledDialog
209
+ Fe as StyledDialog
167
210
  };