@telegraph/modal 0.0.48 → 0.0.50

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