@telegraph/modal 0.0.47 → 0.0.49

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