@telegraph/modal 0.0.80 → 0.0.82

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,7 +1,7 @@
1
- import { jsx as d, Fragment as q, jsxs as T } from "react/jsx-runtime";
1
+ import { jsx as d, Fragment as q, jsxs as S } from "react/jsx-runtime";
2
2
  import * as v from "@radix-ui/react-dialog";
3
3
  import * as i from "react";
4
- import E from "react";
4
+ import g from "react";
5
5
  import * as G from "react-dom";
6
6
  import { FocusScope as J } from "@radix-ui/react-focus-scope";
7
7
  import * as Q from "@radix-ui/react-portal";
@@ -9,9 +9,9 @@ import * as ee from "@radix-ui/react-visually-hidden";
9
9
  import { Button as te } from "@telegraph/button";
10
10
  import { RefToTgphRef as ne } from "@telegraph/helpers";
11
11
  import { Lucide as re } from "@telegraph/icon";
12
- import { Stack as g, Box as se } from "@telegraph/layout";
13
- import { AnimatePresence as oe, motion as B } from "framer-motion";
14
- function S(e, t, { checkForDefaultPrevented: n = !0 } = {}) {
12
+ import { Stack as E, Box as oe } from "@telegraph/layout";
13
+ import { AnimatePresence as se, motion as T } from "framer-motion";
14
+ function x(e, t, { checkForDefaultPrevented: n = !0 } = {}) {
15
15
  return function(r) {
16
16
  if (e == null || e(r), n === !1 || !r.defaultPrevented)
17
17
  return t == null ? void 0 : t(r);
@@ -25,57 +25,57 @@ function I(e, t) {
25
25
  function _(...e) {
26
26
  return (t) => {
27
27
  let n = !1;
28
- const s = e.map((r) => {
29
- const o = I(r, t);
30
- return !n && typeof o == "function" && (n = !0), o;
28
+ const o = e.map((r) => {
29
+ const s = I(r, t);
30
+ return !n && typeof s == "function" && (n = !0), s;
31
31
  });
32
32
  if (n)
33
33
  return () => {
34
- for (let r = 0; r < s.length; r++) {
35
- const o = s[r];
36
- typeof o == "function" ? o() : I(e[r], null);
34
+ for (let r = 0; r < o.length; r++) {
35
+ const s = o[r];
36
+ typeof s == "function" ? s() : I(e[r], null);
37
37
  }
38
38
  };
39
39
  };
40
40
  }
41
- function U(...e) {
41
+ function $(...e) {
42
42
  return i.useCallback(_(...e), e);
43
43
  }
44
- var z = i.forwardRef((e, t) => {
45
- const { children: n, ...s } = e, r = i.Children.toArray(n), o = r.find(ae);
46
- if (o) {
47
- const a = o.props.children, c = r.map((p) => p === o ? i.Children.count(a) > 1 ? i.Children.only(null) : i.isValidElement(a) ? a.props.children : null : p);
48
- return /* @__PURE__ */ d(W, { ...s, ref: t, children: i.isValidElement(a) ? i.cloneElement(a, void 0, c) : null });
44
+ var U = i.forwardRef((e, t) => {
45
+ const { children: n, ...o } = e, r = i.Children.toArray(n), s = r.find(ae);
46
+ if (s) {
47
+ const a = s.props.children, l = r.map((y) => y === s ? i.Children.count(a) > 1 ? i.Children.only(null) : i.isValidElement(a) ? a.props.children : null : y);
48
+ return /* @__PURE__ */ d(B, { ...o, ref: t, children: i.isValidElement(a) ? i.cloneElement(a, void 0, l) : null });
49
49
  }
50
- return /* @__PURE__ */ d(W, { ...s, ref: t, children: n });
50
+ return /* @__PURE__ */ d(B, { ...o, ref: t, children: n });
51
51
  });
52
- z.displayName = "Slot";
53
- var W = i.forwardRef((e, t) => {
54
- const { children: n, ...s } = e;
52
+ U.displayName = "Slot";
53
+ var B = i.forwardRef((e, t) => {
54
+ const { children: n, ...o } = e;
55
55
  if (i.isValidElement(n)) {
56
- const r = le(n), o = ce(s, n.props);
57
- return n.type !== i.Fragment && (o.ref = t ? _(t, r) : r), i.cloneElement(n, o);
56
+ const r = le(n), s = ce(o, n.props);
57
+ return n.type !== i.Fragment && (s.ref = t ? _(t, r) : r), i.cloneElement(n, s);
58
58
  }
59
59
  return i.Children.count(n) > 1 ? i.Children.only(null) : null;
60
60
  });
61
- W.displayName = "SlotClone";
61
+ B.displayName = "SlotClone";
62
62
  var ie = ({ children: e }) => /* @__PURE__ */ d(q, { children: e });
63
63
  function ae(e) {
64
64
  return i.isValidElement(e) && e.type === ie;
65
65
  }
66
66
  function ce(e, t) {
67
67
  const n = { ...t };
68
- for (const s in t) {
69
- const r = e[s], o = t[s];
70
- /^on[A-Z]/.test(s) ? r && o ? n[s] = (...c) => {
71
- o(...c), r(...c);
72
- } : r && (n[s] = r) : s === "style" ? n[s] = { ...r, ...o } : s === "className" && (n[s] = [r, o].filter(Boolean).join(" "));
68
+ for (const o in t) {
69
+ const r = e[o], s = t[o];
70
+ /^on[A-Z]/.test(o) ? r && s ? n[o] = (...l) => {
71
+ s(...l), r(...l);
72
+ } : r && (n[o] = r) : o === "style" ? n[o] = { ...r, ...s } : o === "className" && (n[o] = [r, s].filter(Boolean).join(" "));
73
73
  }
74
74
  return { ...e, ...n };
75
75
  }
76
76
  function le(e) {
77
- var s, r;
78
- let t = (s = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : s.get, n = t && "isReactWarning" in t && t.isReactWarning;
77
+ var o, r;
78
+ let t = (o = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : o.get, n = t && "isReactWarning" in t && t.isReactWarning;
79
79
  return n ? e.ref : (t = (r = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : r.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref);
80
80
  }
81
81
  var ue = [
@@ -95,35 +95,35 @@ var ue = [
95
95
  "span",
96
96
  "svg",
97
97
  "ul"
98
- ], V = ue.reduce((e, t) => {
99
- const n = i.forwardRef((s, r) => {
100
- const { asChild: o, ...a } = s, c = o ? z : t;
101
- return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ d(c, { ...a, ref: r });
98
+ ], z = ue.reduce((e, t) => {
99
+ const n = i.forwardRef((o, r) => {
100
+ const { asChild: s, ...a } = o, l = s ? U : t;
101
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ d(l, { ...a, ref: r });
102
102
  });
103
103
  return n.displayName = `Primitive.${t}`, { ...e, [t]: n };
104
104
  }, {});
105
105
  function de(e, t) {
106
106
  e && G.flushSync(() => e.dispatchEvent(t));
107
107
  }
108
- function L(e) {
108
+ function N(e) {
109
109
  const t = i.useRef(e);
110
110
  return i.useEffect(() => {
111
111
  t.current = e;
112
112
  }), i.useMemo(() => (...n) => {
113
- var s;
114
- return (s = t.current) == null ? void 0 : s.call(t, ...n);
113
+ var o;
114
+ return (o = t.current) == null ? void 0 : o.call(t, ...n);
115
115
  }, []);
116
116
  }
117
117
  function fe(e, t = globalThis == null ? void 0 : globalThis.document) {
118
- const n = L(e);
118
+ const n = N(e);
119
119
  i.useEffect(() => {
120
- const s = (r) => {
120
+ const o = (r) => {
121
121
  r.key === "Escape" && n(r);
122
122
  };
123
- return t.addEventListener("keydown", s, { capture: !0 }), () => t.removeEventListener("keydown", s, { capture: !0 });
123
+ return t.addEventListener("keydown", o, { capture: !0 }), () => t.removeEventListener("keydown", o, { capture: !0 });
124
124
  }, [n, t]);
125
125
  }
126
- var pe = "DismissableLayer", N = "dismissableLayer.update", ye = "dismissableLayer.pointerDownOutside", he = "dismissableLayer.focusOutside", M, $ = i.createContext({
126
+ var pe = "DismissableLayer", W = "dismissableLayer.update", ye = "dismissableLayer.pointerDownOutside", he = "dismissableLayer.focusOutside", M, V = i.createContext({
127
127
  layers: /* @__PURE__ */ new Set(),
128
128
  layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
129
129
  branches: /* @__PURE__ */ new Set()
@@ -131,43 +131,43 @@ var pe = "DismissableLayer", N = "dismissableLayer.update", ye = "dismissableLay
131
131
  (e, t) => {
132
132
  const {
133
133
  disableOutsidePointerEvents: n = !1,
134
- onEscapeKeyDown: s,
134
+ onEscapeKeyDown: o,
135
135
  onPointerDownOutside: r,
136
- onFocusOutside: o,
136
+ onFocusOutside: s,
137
137
  onInteractOutside: a,
138
- onDismiss: c,
139
- ...p
140
- } = e, l = i.useContext($), [u, y] = i.useState(null), h = (u == null ? void 0 : u.ownerDocument) ?? (globalThis == null ? void 0 : globalThis.document), [, D] = i.useState({}), b = U(t, (f) => y(f)), C = Array.from(l.layers), [P] = [...l.layersWithOutsidePointerEventsDisabled].slice(-1), m = C.indexOf(P), O = u ? C.indexOf(u) : -1, w = l.layersWithOutsidePointerEventsDisabled.size > 0, k = O >= m, Z = ge((f) => {
141
- const R = f.target, A = [...l.branches].some((x) => x.contains(R));
142
- !k || A || (r == null || r(f), a == null || a(f), f.defaultPrevented || c == null || c());
143
- }, h), F = Ee((f) => {
138
+ onDismiss: l,
139
+ ...y
140
+ } = e, u = i.useContext(V), [c, h] = i.useState(null), p = (c == null ? void 0 : c.ownerDocument) ?? (globalThis == null ? void 0 : globalThis.document), [, L] = i.useState({}), b = $(t, (f) => h(f)), C = Array.from(u.layers), [w] = [...u.layersWithOutsidePointerEventsDisabled].slice(-1), m = C.indexOf(w), D = c ? C.indexOf(c) : -1, P = u.layersWithOutsidePointerEventsDisabled.size > 0, k = D >= m, Z = Ee((f) => {
141
+ const R = f.target, A = [...u.branches].some((O) => O.contains(R));
142
+ !k || A || (r == null || r(f), a == null || a(f), f.defaultPrevented || l == null || l());
143
+ }, p), F = ge((f) => {
144
144
  const R = f.target;
145
- [...l.branches].some((x) => x.contains(R)) || (o == null || o(f), a == null || a(f), f.defaultPrevented || c == null || c());
146
- }, h);
145
+ [...u.branches].some((O) => O.contains(R)) || (s == null || s(f), a == null || a(f), f.defaultPrevented || l == null || l());
146
+ }, p);
147
147
  return fe((f) => {
148
- O === l.layers.size - 1 && (s == null || s(f), !f.defaultPrevented && c && (f.preventDefault(), c()));
149
- }, h), i.useEffect(() => {
150
- if (u)
151
- return n && (l.layersWithOutsidePointerEventsDisabled.size === 0 && (M = h.body.style.pointerEvents, h.body.style.pointerEvents = "none"), l.layersWithOutsidePointerEventsDisabled.add(u)), l.layers.add(u), j(), () => {
152
- n && l.layersWithOutsidePointerEventsDisabled.size === 1 && (h.body.style.pointerEvents = M);
148
+ D === u.layers.size - 1 && (o == null || o(f), !f.defaultPrevented && l && (f.preventDefault(), l()));
149
+ }, p), i.useEffect(() => {
150
+ if (c)
151
+ return n && (u.layersWithOutsidePointerEventsDisabled.size === 0 && (M = p.body.style.pointerEvents, p.body.style.pointerEvents = "none"), u.layersWithOutsidePointerEventsDisabled.add(c)), u.layers.add(c), j(), () => {
152
+ n && u.layersWithOutsidePointerEventsDisabled.size === 1 && (p.body.style.pointerEvents = M);
153
153
  };
154
- }, [u, h, n, l]), i.useEffect(() => () => {
155
- u && (l.layers.delete(u), l.layersWithOutsidePointerEventsDisabled.delete(u), j());
156
- }, [u, l]), i.useEffect(() => {
157
- const f = () => D({});
158
- return document.addEventListener(N, f), () => document.removeEventListener(N, f);
154
+ }, [c, p, n, u]), i.useEffect(() => () => {
155
+ c && (u.layers.delete(c), u.layersWithOutsidePointerEventsDisabled.delete(c), j());
156
+ }, [c, u]), i.useEffect(() => {
157
+ const f = () => L({});
158
+ return document.addEventListener(W, f), () => document.removeEventListener(W, f);
159
159
  }, []), /* @__PURE__ */ d(
160
- V.div,
160
+ z.div,
161
161
  {
162
- ...p,
162
+ ...y,
163
163
  ref: b,
164
164
  style: {
165
- pointerEvents: w ? k ? "auto" : "none" : void 0,
165
+ pointerEvents: P ? k ? "auto" : "none" : void 0,
166
166
  ...e.style
167
167
  },
168
- onFocusCapture: S(e.onFocusCapture, F.onFocusCapture),
169
- onBlurCapture: S(e.onBlurCapture, F.onBlurCapture),
170
- onPointerDownCapture: S(
168
+ onFocusCapture: x(e.onFocusCapture, F.onFocusCapture),
169
+ onBlurCapture: x(e.onBlurCapture, F.onBlurCapture),
170
+ onPointerDownCapture: x(
171
171
  e.onPointerDownCapture,
172
172
  Z.onPointerDownCapture
173
173
  )
@@ -177,96 +177,119 @@ var pe = "DismissableLayer", N = "dismissableLayer.update", ye = "dismissableLay
177
177
  );
178
178
  K.displayName = pe;
179
179
  var me = "DismissableLayerBranch", ve = i.forwardRef((e, t) => {
180
- const n = i.useContext($), s = i.useRef(null), r = U(t, s);
180
+ const n = i.useContext(V), o = i.useRef(null), r = $(t, o);
181
181
  return i.useEffect(() => {
182
- const o = s.current;
183
- if (o)
184
- return n.branches.add(o), () => {
185
- n.branches.delete(o);
182
+ const s = o.current;
183
+ if (s)
184
+ return n.branches.add(s), () => {
185
+ n.branches.delete(s);
186
186
  };
187
- }, [n.branches]), /* @__PURE__ */ d(V.div, { ...e, ref: r });
187
+ }, [n.branches]), /* @__PURE__ */ d(z.div, { ...e, ref: r });
188
188
  });
189
189
  ve.displayName = me;
190
- function ge(e, t = globalThis == null ? void 0 : globalThis.document) {
191
- const n = L(e), s = i.useRef(!1), r = i.useRef(() => {
190
+ function Ee(e, t = globalThis == null ? void 0 : globalThis.document) {
191
+ const n = N(e), o = i.useRef(!1), r = i.useRef(() => {
192
192
  });
193
193
  return i.useEffect(() => {
194
- const o = (c) => {
195
- if (c.target && !s.current) {
196
- let p = function() {
194
+ const s = (l) => {
195
+ if (l.target && !o.current) {
196
+ let y = function() {
197
197
  X(
198
198
  ye,
199
199
  n,
200
- l,
200
+ u,
201
201
  { discrete: !0 }
202
202
  );
203
203
  };
204
- const l = { originalEvent: c };
205
- c.pointerType === "touch" ? (t.removeEventListener("click", r.current), r.current = p, t.addEventListener("click", r.current, { once: !0 })) : p();
204
+ const u = { originalEvent: l };
205
+ l.pointerType === "touch" ? (t.removeEventListener("click", r.current), r.current = y, t.addEventListener("click", r.current, { once: !0 })) : y();
206
206
  } else
207
207
  t.removeEventListener("click", r.current);
208
- s.current = !1;
208
+ o.current = !1;
209
209
  }, a = window.setTimeout(() => {
210
- t.addEventListener("pointerdown", o);
210
+ t.addEventListener("pointerdown", s);
211
211
  }, 0);
212
212
  return () => {
213
- window.clearTimeout(a), t.removeEventListener("pointerdown", o), t.removeEventListener("click", r.current);
213
+ window.clearTimeout(a), t.removeEventListener("pointerdown", s), t.removeEventListener("click", r.current);
214
214
  };
215
215
  }, [t, n]), {
216
216
  // ensures we check React component tree (not just DOM tree)
217
- onPointerDownCapture: () => s.current = !0
217
+ onPointerDownCapture: () => o.current = !0
218
218
  };
219
219
  }
220
- function Ee(e, t = globalThis == null ? void 0 : globalThis.document) {
221
- const n = L(e), s = i.useRef(!1);
220
+ function ge(e, t = globalThis == null ? void 0 : globalThis.document) {
221
+ const n = N(e), o = i.useRef(!1);
222
222
  return i.useEffect(() => {
223
- const r = (o) => {
224
- o.target && !s.current && X(he, n, { originalEvent: o }, {
223
+ const r = (s) => {
224
+ s.target && !o.current && X(he, n, { originalEvent: s }, {
225
225
  discrete: !1
226
226
  });
227
227
  };
228
228
  return t.addEventListener("focusin", r), () => t.removeEventListener("focusin", r);
229
229
  }, [t, n]), {
230
- onFocusCapture: () => s.current = !0,
231
- onBlurCapture: () => s.current = !1
230
+ onFocusCapture: () => o.current = !0,
231
+ onBlurCapture: () => o.current = !1
232
232
  };
233
233
  }
234
234
  function j() {
235
- const e = new CustomEvent(N);
235
+ const e = new CustomEvent(W);
236
236
  document.dispatchEvent(e);
237
237
  }
238
- function X(e, t, n, { discrete: s }) {
239
- const r = n.originalEvent.target, o = new CustomEvent(e, { bubbles: !1, cancelable: !0, detail: n });
240
- t && r.addEventListener(e, t, { once: !0 }), s ? de(r, o) : r.dispatchEvent(o);
238
+ function X(e, t, n, { discrete: o }) {
239
+ const r = n.originalEvent.target, s = new CustomEvent(e, { bubbles: !1, cancelable: !0, detail: n });
240
+ t && r.addEventListener(e, t, { once: !0 }), o ? de(r, s) : r.dispatchEvent(s);
241
241
  }
242
- function be({
242
+ var be = globalThis != null && globalThis.document ? i.useLayoutEffect : () => {
243
+ }, Ce = i[" useInsertionEffect ".trim().toString()] || be;
244
+ function Le({
243
245
  prop: e,
244
246
  defaultProp: t,
245
247
  onChange: n = () => {
246
- }
248
+ },
249
+ caller: o
247
250
  }) {
248
- const [s, r] = Ce({ defaultProp: t, onChange: n }), o = e !== void 0, a = o ? e : s, c = L(n), p = i.useCallback(
249
- (l) => {
250
- if (o) {
251
- const y = typeof l == "function" ? l(e) : l;
252
- y !== e && c(y);
251
+ const [r, s, a] = we({
252
+ defaultProp: t,
253
+ onChange: n
254
+ }), l = e !== void 0, y = l ? e : r;
255
+ {
256
+ const c = i.useRef(e !== void 0);
257
+ i.useEffect(() => {
258
+ const h = c.current;
259
+ h !== l && console.warn(
260
+ `${o} is changing from ${h ? "controlled" : "uncontrolled"} to ${l ? "controlled" : "uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
261
+ ), c.current = l;
262
+ }, [l, o]);
263
+ }
264
+ const u = i.useCallback(
265
+ (c) => {
266
+ var h;
267
+ if (l) {
268
+ const p = Pe(c) ? c(e) : c;
269
+ p !== e && ((h = a.current) == null || h.call(a, p));
253
270
  } else
254
- r(l);
271
+ s(c);
255
272
  },
256
- [o, e, r, c]
273
+ [l, e, s, a]
257
274
  );
258
- return [a, p];
275
+ return [y, u];
259
276
  }
260
- function Ce({
277
+ function we({
261
278
  defaultProp: e,
262
279
  onChange: t
263
280
  }) {
264
- const n = i.useState(e), [s] = n, r = i.useRef(s), o = L(t);
265
- return i.useEffect(() => {
266
- r.current !== s && (o(s), r.current = s);
267
- }, [s, r, o]), n;
281
+ const [n, o] = i.useState(e), r = i.useRef(n), s = i.useRef(t);
282
+ return Ce(() => {
283
+ s.current = t;
284
+ }, [t]), i.useEffect(() => {
285
+ var a;
286
+ r.current !== n && ((a = s.current) == null || a.call(s, n), r.current = n);
287
+ }, [n, r]), [n, o, s];
268
288
  }
269
- const Y = E.createContext({
289
+ function Pe(e) {
290
+ return typeof e == "function";
291
+ }
292
+ const Y = g.createContext({
270
293
  layers: [],
271
294
  setLayers: () => {
272
295
  },
@@ -276,97 +299,97 @@ const Y = E.createContext({
276
299
  },
277
300
  removeTopLayer: () => {
278
301
  }
279
- }), je = ({ children: e }) => {
280
- const [t, n] = E.useState([]), s = (a) => {
281
- n((c) => [...c, a]);
302
+ }), Ue = ({ children: e }) => {
303
+ const [t, n] = g.useState([]), o = (a) => {
304
+ n((l) => [...l, a]);
282
305
  }, r = (a) => {
283
- n(t.filter((c) => c !== a));
284
- }, o = () => {
306
+ n(t.filter((l) => l !== a));
307
+ }, s = () => {
285
308
  const a = t[t.length - 1];
286
309
  a && r(a);
287
310
  };
288
311
  return /* @__PURE__ */ d(
289
312
  Y.Provider,
290
313
  {
291
- value: { layers: t, setLayers: n, addLayer: s, removeLayer: r, removeTopLayer: o },
314
+ value: { layers: t, setLayers: n, addLayer: o, removeLayer: r, removeTopLayer: s },
292
315
  children: e
293
316
  }
294
317
  );
295
- }, H = () => E.useContext(Y), Le = ({
318
+ }, H = () => g.useContext(Y), Re = ({
296
319
  defaultOpen: e,
297
320
  open: t,
298
321
  onOpenChange: n,
299
- ...s
322
+ ...o
300
323
  }) => {
301
- const [r, o] = be({
324
+ const [r, s] = Le({
302
325
  prop: t,
303
326
  onChange: n,
304
327
  defaultProp: e
305
- }), a = H(), c = s.a11yTitle;
306
- if (E.useEffect(() => {
307
- !r && a.layers.includes(c) && a.removeLayer(c);
308
- }, [c, a, r]), !!r)
309
- return /* @__PURE__ */ d(Pe, { open: r, onOpenChange: o, ...s });
310
- }, Pe = ({
328
+ }), a = H(), l = o.a11yTitle;
329
+ if (g.useEffect(() => {
330
+ !r && a.layers.includes(l) && a.removeLayer(l);
331
+ }, [l, a, r]), !!r)
332
+ return /* @__PURE__ */ d(De, { open: r, onOpenChange: s, ...o });
333
+ }, De = ({
311
334
  open: e,
312
335
  onOpenChange: t,
313
336
  a11yTitle: n,
314
- a11yDescription: s,
337
+ a11yDescription: o,
315
338
  children: r,
316
339
  // Focus scope props
317
- trapped: o,
340
+ trapped: s,
318
341
  onMountAutoFocus: a,
319
- onUnmountAutoFocus: c,
320
- ...p
342
+ onUnmountAutoFocus: l,
343
+ ...y
321
344
  }) => {
322
- var C, P;
323
- const l = n, u = H();
324
- E.useEffect(() => {
325
- !u || !e || u.layers.includes(l) || u.addLayer(l);
326
- }, [l, u, e]);
327
- const y = ((C = u.layers) == null ? void 0 : C.indexOf(l)) || 0, h = ((P = u.layers) == null ? void 0 : P.length) || 0, D = y !== 0, b = l === u.layers[u.layers.length - 1];
345
+ var C, w;
346
+ const u = n, c = H();
347
+ g.useEffect(() => {
348
+ !c || !e || c.layers.includes(u) || c.addLayer(u);
349
+ }, [u, c, e]);
350
+ const h = ((C = c.layers) == null ? void 0 : C.indexOf(u)) || 0, p = ((w = c.layers) == null ? void 0 : w.length) || 0, L = h !== 0, b = u === c.layers[c.layers.length - 1];
328
351
  return /* @__PURE__ */ d(
329
352
  K,
330
353
  {
331
354
  onEscapeKeyDown: (m) => {
332
- b && (m.preventDefault(), u.removeTopLayer(), t(!1));
355
+ b && (m.preventDefault(), c.removeTopLayer(), t(!1));
333
356
  },
334
357
  onPointerDownOutside: (m) => {
335
- b && (m.preventDefault(), u.removeTopLayer(), t(!1));
358
+ b && (m.preventDefault(), c.removeTopLayer(), t(!1));
336
359
  },
337
- children: /* @__PURE__ */ T(
360
+ children: /* @__PURE__ */ S(
338
361
  v.Root,
339
362
  {
340
363
  open: e,
341
364
  onOpenChange: (m) => {
342
- var w;
343
- if (((w = u == null ? void 0 : u.layers) == null ? void 0 : w.length) > 0)
344
- return m === !1 && l === u.layers[u.layers.length - 1] ? (u.removeLayer(l), t(!1)) : void 0;
365
+ var P;
366
+ if (((P = c == null ? void 0 : c.layers) == null ? void 0 : P.length) > 0)
367
+ return m === !1 && u === c.layers[c.layers.length - 1] ? (c.removeLayer(u), t(!1)) : void 0;
345
368
  t(m);
346
369
  },
347
370
  children: [
348
- /* @__PURE__ */ T(ee.Root, { children: [
371
+ /* @__PURE__ */ S(ee.Root, { children: [
349
372
  /* @__PURE__ */ d(v.Title, { children: n }),
350
- s && /* @__PURE__ */ d(v.Description, { children: s })
373
+ o && /* @__PURE__ */ d(v.Description, { children: o })
351
374
  ] }),
352
- /* @__PURE__ */ d(oe, { children: e && // We add the className "tgph" here so that styles within
375
+ /* @__PURE__ */ d(se, { children: e && // We add the className "tgph" here so that styles within
353
376
  // the portal get scoped properly to telegraph
354
- /* @__PURE__ */ d(Q.Root, { className: "tgph", children: /* @__PURE__ */ d(we, { layer: y, children: /* @__PURE__ */ d(
377
+ /* @__PURE__ */ d(Q.Root, { className: "tgph", children: /* @__PURE__ */ d(Oe, { layer: h, children: /* @__PURE__ */ d(
355
378
  J,
356
379
  {
357
- trapped: typeof o == "boolean" ? o : b,
380
+ trapped: typeof s == "boolean" ? s : b,
358
381
  onMountAutoFocus: a,
359
- onUnmountAutoFocus: c,
382
+ onUnmountAutoFocus: l,
360
383
  asChild: !0,
361
384
  children: /* @__PURE__ */ d(ne, { children: /* @__PURE__ */ d(
362
- g,
385
+ E,
363
386
  {
364
- as: B.div,
387
+ as: T.div,
365
388
  initial: {
366
- top: `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${h - 1})`
389
+ top: `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${p - 1})`
367
390
  },
368
391
  animate: {
369
- top: D ? `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${y} )` : "var(--tgph-spacing-16)"
392
+ top: L ? `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${h} )` : "var(--tgph-spacing-16)"
370
393
  },
371
394
  exit: { top: 0 },
372
395
  transition: { type: "spring", duration: 0.3, bounce: 0 },
@@ -377,15 +400,15 @@ const Y = E.createContext({
377
400
  left: 0,
378
401
  maxHeight: "calc(100vh - var(--tgph-spacing-32))",
379
402
  maxWidth: "calc(100vw - var(--tgph-spacing-8))",
380
- zIndex: `calc(var(--tgph-zIndex-modal) + ${y})`
403
+ zIndex: `calc(var(--tgph-zIndex-modal) + ${h})`
381
404
  },
382
405
  children: /* @__PURE__ */ d(
383
- g,
406
+ E,
384
407
  {
385
408
  direction: "column",
386
- as: B.div,
409
+ as: T.div,
387
410
  animate: {
388
- scale: 1.02 - Math.abs(h - y) * 0.02,
411
+ scale: 1.02 - Math.abs(p - h) * 0.02,
389
412
  transformOrigin: "center center"
390
413
  },
391
414
  transition: {
@@ -393,33 +416,33 @@ const Y = E.createContext({
393
416
  bounce: 0,
394
417
  type: "spring"
395
418
  },
396
- maxW: p.maxW ?? "160",
397
- w: p.w ?? "full",
419
+ maxW: y.maxW ?? "160",
420
+ w: y.w ?? "full",
398
421
  bg: "surface-1",
399
422
  border: "px",
400
423
  rounded: "4",
401
424
  shadow: "3",
402
- ...p,
425
+ ...y,
403
426
  children: r
404
427
  },
405
- `content-${l}`
428
+ `content-${u}`
406
429
  )
407
430
  },
408
- `container-${l}`
431
+ `container-${u}`
409
432
  ) })
410
433
  }
411
434
  ) }) }) })
412
435
  ]
413
436
  },
414
- l
437
+ u
415
438
  )
416
439
  }
417
440
  );
418
- }, we = ({ layer: e, children: t }) => e > 0 ? t : /* @__PURE__ */ T(v.Overlay, { children: [
441
+ }, Oe = ({ layer: e, children: t }) => e > 0 ? t : /* @__PURE__ */ S(v.Overlay, { children: [
419
442
  /* @__PURE__ */ d(
420
- se,
443
+ oe,
421
444
  {
422
- as: B.div,
445
+ as: T.div,
423
446
  initial: { opacity: 0 },
424
447
  animate: { opacity: 1 },
425
448
  exit: { opacity: 0 },
@@ -436,9 +459,9 @@ const Y = E.createContext({
436
459
  }
437
460
  ),
438
461
  t
439
- ] }), Re = E.forwardRef(
440
- ({ children: e, ...t }, n) => /* @__PURE__ */ d(v.Content, { ref: n, asChild: !0, ...t, children: /* @__PURE__ */ d(g, { direction: "column", h: "full", ...t, children: e }) })
441
- ), De = ({
462
+ ] }), xe = g.forwardRef(
463
+ ({ children: e, ...t }, n) => /* @__PURE__ */ d(v.Content, { ref: n, asChild: !0, ...t, children: /* @__PURE__ */ d(E, { direction: "column", h: "full", ...t, children: e }) })
464
+ ), Se = ({
442
465
  size: e = "1",
443
466
  variant: t = "ghost",
444
467
  ...n
@@ -450,12 +473,12 @@ const Y = E.createContext({
450
473
  size: e,
451
474
  ...n
452
475
  }
453
- ) }), Oe = ({
476
+ ) }), Te = ({
454
477
  style: e,
455
478
  children: t,
456
479
  ...n
457
480
  }) => /* @__PURE__ */ d(
458
- g,
481
+ E,
459
482
  {
460
483
  direction: "column",
461
484
  px: "6",
@@ -467,11 +490,11 @@ const Y = E.createContext({
467
490
  ...n,
468
491
  children: t
469
492
  }
470
- ), xe = ({
493
+ ), Be = ({
471
494
  children: e,
472
495
  ...t
473
496
  }) => /* @__PURE__ */ d(
474
- g,
497
+ E,
475
498
  {
476
499
  direction: "row",
477
500
  justify: "space-between",
@@ -482,11 +505,11 @@ const Y = E.createContext({
482
505
  ...t,
483
506
  children: e
484
507
  }
485
- ), Se = ({
508
+ ), We = ({
486
509
  children: e,
487
510
  ...t
488
511
  }) => /* @__PURE__ */ d(
489
- g,
512
+ E,
490
513
  {
491
514
  direction: "row",
492
515
  align: "center",
@@ -498,17 +521,17 @@ const Y = E.createContext({
498
521
  ...t,
499
522
  children: e
500
523
  }
501
- ), Te = {};
502
- Object.assign(Te, {
503
- Root: Le,
504
- Content: Re,
505
- Close: De,
506
- Body: Oe,
507
- Header: xe,
508
- Footer: Se
524
+ ), Ne = {};
525
+ Object.assign(Ne, {
526
+ Root: Re,
527
+ Content: xe,
528
+ Close: Se,
529
+ Body: Te,
530
+ Header: Be,
531
+ Footer: We
509
532
  });
510
533
  export {
511
- Te as Modal,
512
- je as ModalStackingProvider
534
+ Ne as Modal,
535
+ Ue as ModalStackingProvider
513
536
  };
514
537
  //# sourceMappingURL=index.mjs.map