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