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