@telegraph/modal 0.0.49 → 0.0.51

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,62 +1,68 @@
1
- import { jsx as u, Fragment as I, jsxs as S } from "react/jsx-runtime";
1
+ import { jsx as d, Fragment as Z, 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";
5
- import b from "react";
6
- import * as G from "react-dom";
7
- import J from "react-dom";
3
+ import * as o from "react";
4
+ import g from "react";
5
+ import * as q from "react-dom";
6
+ import { FocusScope as G } from "@radix-ui/react-focus-scope";
7
+ import * as J from "@radix-ui/react-portal";
8
8
  import * as Q from "@radix-ui/react-visually-hidden";
9
9
  import { Button as ee } from "@telegraph/button";
10
10
  import { RefToTgphRef as te } from "@telegraph/helpers";
11
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);
12
+ import { Stack as E, Box as re } from "@telegraph/layout";
13
+ import { AnimatePresence as se, 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
+ };
19
+ }
20
+ function oe(e, t) {
21
+ typeof e == "function" ? e(t) : e != null && (e.current = t);
16
22
  }
17
- function ie(...t) {
18
- return (e) => t.forEach((n) => se(n, e));
23
+ function ie(...e) {
24
+ return (t) => e.forEach((n) => oe(n, t));
19
25
  }
20
- var W = s.forwardRef((t, e) => {
21
- const { children: n, ...r } = t, o = s.Children.toArray(n), i = o.find(ce);
26
+ var j = o.forwardRef((e, t) => {
27
+ const { children: n, ...r } = e, s = o.Children.toArray(n), i = s.find(ce);
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 a = i.props.children, c = s.map((p) => p === i ? o.Children.count(a) > 1 ? o.Children.only(null) : o.isValidElement(a) ? a.props.children : null : p);
30
+ return /* @__PURE__ */ d(B, { ...r, ref: t, children: o.isValidElement(a) ? o.cloneElement(a, void 0, c) : 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
+ j.displayName = "Slot";
35
+ var B = o.forwardRef((e, t) => {
36
+ const { children: n, ...r } = e;
37
+ if (o.isValidElement(n)) {
38
+ const s = ue(n);
39
+ return o.cloneElement(n, {
34
40
  ...le(r, n.props),
35
41
  // @ts-ignore
36
- ref: e ? ie(e, o) : o
42
+ ref: t ? ie(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 ae = ({ children: e }) => /* @__PURE__ */ d(Z, { children: e });
49
+ function ce(e) {
50
+ return o.isValidElement(e) && e.type === ae;
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 le(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] = (...c) => {
57
+ i(...c), s(...c);
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 ue(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
67
  var de = [
62
68
  "a",
@@ -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 });
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 });
84
+ ], _ = de.reduce((e, t) => {
85
+ const n = o.forwardRef((r, s) => {
86
+ const { asChild: i, ...a } = r, c = i ? j : t;
87
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ d(c, { ...a, ref: s });
157
88
  });
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 fe(e, t) {
92
+ e && q.flushSync(() => e.dispatchEvent(t));
162
93
  }
163
- function be(t, e) {
164
- typeof t == "function" ? t(e) : t != null && (t.current = e);
94
+ function pe(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 ye(...e) {
98
+ return (t) => e.forEach((n) => pe(n, t));
168
99
  }
169
- function V(...t) {
170
- return s.useCallback(Ce(...t), t);
100
+ function $(...e) {
101
+ return o.useCallback(ye(...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 me = "DismissableLayer", W = "dismissableLayer.update", ve = "dismissableLayer.pointerDownOutside", Ee = "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
132
  onInteractOutside: a,
202
133
  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());
134
+ ...p
135
+ } = e, l = o.useContext(U), [u, y] = o.useState(null), h = (u == null ? void 0 : u.ownerDocument) ?? (globalThis == null ? void 0 : globalThis.document), [, w] = o.useState({}), b = $(t, (f) => y(f)), C = Array.from(l.layers), [L] = [...l.layersWithOutsidePointerEventsDisabled].slice(-1), m = C.indexOf(L), O = u ? C.indexOf(u) : -1, P = l.layersWithOutsidePointerEventsDisabled.size > 0, k = O >= m, Y = Ce((f) => {
136
+ const R = f.target, F = [...l.branches].some((D) => D.contains(R));
137
+ !k || F || (s == null || s(f), a == null || a(f), f.defaultPrevented || c == null || c());
138
+ }, h), A = Le((f) => {
139
+ const R = f.target;
140
+ [...l.branches].some((D) => D.contains(R)) || (i == null || i(f), a == null || a(f), f.defaultPrevented || c == null || c());
210
141
  }, 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 = $);
142
+ return he((f) => {
143
+ O === l.layers.size - 1 && (r == null || r(f), !f.defaultPrevented && c && (f.preventDefault(), c()));
144
+ }, h), o.useEffect(() => {
145
+ if (u)
146
+ return n && (l.layersWithOutsidePointerEventsDisabled.size === 0 && (M = h.body.style.pointerEvents, h.body.style.pointerEvents = "none"), l.layersWithOutsidePointerEventsDisabled.add(u)), l.layers.add(u), I(), () => {
147
+ n && l.layersWithOutsidePointerEventsDisabled.size === 1 && (h.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
+ }, [u, h, n, l]), o.useEffect(() => () => {
150
+ u && (l.layers.delete(u), l.layersWithOutsidePointerEventsDisabled.delete(u), I());
151
+ }, [u, l]), o.useEffect(() => {
152
+ const f = () => w({});
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: b,
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 = me;
174
+ var ge = "DismissableLayerBranch", be = 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
+ be.displayName = ge;
185
+ function Ce(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(() => {
188
+ return o.useEffect(() => {
258
189
  const i = (c) => {
259
190
  if (c.target && !r.current) {
260
- let y = function() {
261
- Y(
262
- we,
191
+ let p = function() {
192
+ V(
193
+ ve,
263
194
  n,
264
195
  l,
265
196
  { discrete: !0 }
266
197
  );
267
198
  };
268
199
  const l = { originalEvent: c };
269
- c.pointerType === "touch" ? (e.removeEventListener("click", o.current), o.current = y, e.addEventListener("click", o.current, { once: !0 })) : y();
200
+ c.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
204
  }, a = window.setTimeout(() => {
274
- e.addEventListener("pointerdown", i);
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(a), 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 Le(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(Ee, 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 ? fe(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] = Re({ defaultProp: t, onChange: n }), i = e !== void 0, a = i ? e : r, c = K(n), p = o.useCallback(
253
+ (l) => {
254
+ if (i) {
255
+ const y = typeof l == "function" ? l(e) : l;
256
+ y !== e && c(y);
257
+ } else
258
+ s(l);
259
+ },
260
+ [i, e, s, c]
261
+ );
262
+ return [a, p];
263
+ }
264
+ function Re({
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 H = g.createContext({
312
274
  layers: [],
313
275
  setLayers: () => {
314
276
  },
@@ -318,101 +280,97 @@ 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] = g.useState([]), r = (a) => {
285
+ n((c) => [...c, a]);
286
+ }, s = (a) => {
287
+ n(t.filter((c) => c !== a));
329
288
  }, i = () => {
330
- const a = e[e.length - 1];
331
- a && o(a);
289
+ const a = t[t.length - 1];
290
+ a && s(a);
332
291
  };
333
- return /* @__PURE__ */ u(
292
+ return /* @__PURE__ */ d(
334
293
  H.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
+ }, X = () => g.useContext(H), 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
350
- });
351
- if (o)
352
- return /* @__PURE__ */ u(We, { open: o, onOpenChange: i, ...r });
353
- }, We = ({
354
- open: t,
355
- onOpenChange: e,
308
+ defaultProp: e
309
+ }), a = X(), c = r.a11yTitle;
310
+ if (g.useEffect(() => {
311
+ !s && a.layers.includes(c) && (console.log("HERE REMOVE", c, s), a.removeLayer(c));
312
+ }, [c, a, s]), !!s)
313
+ return /* @__PURE__ */ d(Oe, { open: s, onOpenChange: i, ...r });
314
+ }, Oe = ({
315
+ open: e,
316
+ onOpenChange: t,
356
317
  a11yTitle: n,
357
318
  a11yDescription: r,
358
- children: o,
359
- layer: i,
319
+ children: s,
360
320
  // Focus scope props
361
- trapped: a,
362
- onMountAutoFocus: c,
363
- onUnmountAutoFocus: y,
364
- ...l
321
+ trapped: i,
322
+ onMountAutoFocus: a,
323
+ onUnmountAutoFocus: c,
324
+ ...p
365
325
  }) => {
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,
326
+ var C, L;
327
+ const l = n, u = X();
328
+ g.useEffect(() => {
329
+ !u || !e || u.layers.includes(l) || u.addLayer(l);
330
+ }, [l, u, e]);
331
+ const y = ((C = u.layers) == null ? void 0 : C.indexOf(l)) || 0, h = ((L = u.layers) == null ? void 0 : L.length) || 0, w = y !== 0, b = l === u.layers[u.layers.length - 1];
332
+ return /* @__PURE__ */ d(
333
+ z,
374
334
  {
375
- id: d,
376
- layers: f.layers,
377
335
  onEscapeKeyDown: (m) => {
378
- m.preventDefault(), f.removeTopLayer(), e(!1);
336
+ b && (m.preventDefault(), u.removeTopLayer(), t(!1));
379
337
  },
380
338
  onPointerDownOutside: (m) => {
381
- m.preventDefault(), f.removeTopLayer(), e(!1);
339
+ b && (m.preventDefault(), u.removeTopLayer(), t(!1));
382
340
  },
383
341
  children: /* @__PURE__ */ S(
384
342
  v.Root,
385
343
  {
386
- open: t,
344
+ open: e,
387
345
  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);
346
+ var P;
347
+ if (((P = u == null ? void 0 : u.layers) == null ? void 0 : P.length) > 0)
348
+ return m === !1 && l === u.layers[u.layers.length - 1] ? (u.removeLayer(l), t(!1)) : void 0;
349
+ t(m);
392
350
  },
393
351
  children: [
394
352
  /* @__PURE__ */ S(Q.Root, { children: [
395
- /* @__PURE__ */ u(v.Title, { children: n }),
396
- r && /* @__PURE__ */ u(v.Description, { children: r })
353
+ /* @__PURE__ */ d(v.Title, { children: n }),
354
+ r && /* @__PURE__ */ d(v.Description, { children: r })
397
355
  ] }),
398
- /* @__PURE__ */ u(oe, { children: t && // We add the className "tgph" here so that styles within
356
+ /* @__PURE__ */ d(se, { children: e && // We add the className "tgph" here so that styles within
399
357
  // the portal get scoped properly to telegraph
400
- /* @__PURE__ */ u(he, { className: "tgph", children: /* @__PURE__ */ u(Ae, { layer: h, children: /* @__PURE__ */ u(
401
- q,
358
+ /* @__PURE__ */ d(J.Root, { className: "tgph", children: /* @__PURE__ */ d(De, { layer: y, children: /* @__PURE__ */ d(
359
+ G,
402
360
  {
403
- trapped: typeof a == "boolean" ? a : P,
404
- onMountAutoFocus: c,
405
- onUnmountAutoFocus: y,
361
+ trapped: typeof i == "boolean" ? i : b,
362
+ onMountAutoFocus: a,
363
+ onUnmountAutoFocus: c,
406
364
  asChild: !0,
407
- children: /* @__PURE__ */ u(te, { children: /* @__PURE__ */ u(
408
- g,
365
+ children: /* @__PURE__ */ d(te, { children: /* @__PURE__ */ d(
366
+ E,
409
367
  {
410
368
  as: T.div,
411
369
  initial: {
412
- top: `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${C - 1})`
370
+ top: `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${h - 1})`
413
371
  },
414
372
  animate: {
415
- top: D ? `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${h} )` : "var(--tgph-spacing-16)"
373
+ top: w ? `calc(var(--tgph-spacing-16) + var(--tgph-spacing-4) * ${y} )` : "var(--tgph-spacing-16)"
416
374
  },
417
375
  exit: { top: 0 },
418
376
  transition: { type: "spring", duration: 0.3, bounce: 0 },
@@ -423,15 +381,15 @@ const Te = ({
423
381
  left: 0,
424
382
  maxHeight: "calc(100vh - var(--tgph-spacing-32))",
425
383
  maxWidth: "calc(100vw - var(--tgph-spacing-8))",
426
- zIndex: `calc(var(--tgph-zIndex-modal) + ${h})`
384
+ zIndex: `calc(var(--tgph-zIndex-modal) + ${y})`
427
385
  },
428
- children: /* @__PURE__ */ u(
429
- g,
386
+ children: /* @__PURE__ */ d(
387
+ E,
430
388
  {
431
389
  direction: "column",
432
390
  as: T.div,
433
391
  animate: {
434
- scale: 1.02 - Math.abs(C - h) * 0.02,
392
+ scale: 1.02 - Math.abs(h - y) * 0.02,
435
393
  transformOrigin: "center center"
436
394
  },
437
395
  transition: {
@@ -439,30 +397,30 @@ const Te = ({
439
397
  bounce: 0,
440
398
  type: "spring"
441
399
  },
442
- maxW: l.maxW ?? "160",
443
- w: l.w ?? "full",
400
+ maxW: p.maxW ?? "160",
401
+ w: p.w ?? "full",
444
402
  bg: "surface-1",
445
403
  border: "px",
446
404
  rounded: "4",
447
405
  shadow: "3",
448
- ...l,
449
- children: o
406
+ ...p,
407
+ children: s
450
408
  },
451
- `content-${d}`
409
+ `content-${l}`
452
410
  )
453
411
  },
454
- `container-${d}`
412
+ `container-${l}`
455
413
  ) })
456
414
  }
457
415
  ) }) }) })
458
416
  ]
459
417
  },
460
- d
418
+ l
461
419
  )
462
420
  }
463
421
  );
464
- }, Ae = ({ layer: t, children: e }) => t > 0 ? e : /* @__PURE__ */ S(v.Overlay, { children: [
465
- /* @__PURE__ */ u(
422
+ }, De = ({ layer: e, children: t }) => e > 0 ? t : /* @__PURE__ */ S(v.Overlay, { children: [
423
+ /* @__PURE__ */ d(
466
424
  re,
467
425
  {
468
426
  as: T.div,
@@ -481,43 +439,43 @@ const Te = ({
481
439
  }
482
440
  }
483
441
  ),
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",
442
+ t
443
+ ] }), xe = g.forwardRef(
444
+ ({ children: e, ...t }, n) => /* @__PURE__ */ d(v.Content, { ref: n, asChild: !0, ...t, children: /* @__PURE__ */ d(E, { direction: "column", h: "full", ...t, children: e }) })
445
+ ), Se = ({
446
+ size: e = "1",
447
+ variant: t = "ghost",
490
448
  ...n
491
- }) => /* @__PURE__ */ u(v.Close, { asChild: !0, children: /* @__PURE__ */ u(
449
+ }) => /* @__PURE__ */ d(v.Close, { asChild: !0, children: /* @__PURE__ */ d(
492
450
  ee,
493
451
  {
494
452
  icon: { icon: ne.X, alt: "Close Modal" },
495
- variant: e,
496
- size: t,
453
+ variant: t,
454
+ size: e,
497
455
  ...n
498
456
  }
499
- ) }), Fe = ({
500
- style: t,
501
- children: e,
457
+ ) }), Te = ({
458
+ style: e,
459
+ children: t,
502
460
  ...n
503
- }) => /* @__PURE__ */ u(
504
- g,
461
+ }) => /* @__PURE__ */ d(
462
+ E,
505
463
  {
506
464
  direction: "column",
507
465
  px: "6",
508
466
  py: "4",
509
467
  style: {
510
468
  overflowY: "auto",
511
- ...t
469
+ ...e
512
470
  },
513
471
  ...n,
514
- children: e
472
+ children: t
515
473
  }
516
- ), $e = ({
517
- children: t,
518
- ...e
519
- }) => /* @__PURE__ */ u(
520
- g,
474
+ ), Be = ({
475
+ children: e,
476
+ ...t
477
+ }) => /* @__PURE__ */ d(
478
+ E,
521
479
  {
522
480
  direction: "row",
523
481
  justify: "space-between",
@@ -525,14 +483,14 @@ const Te = ({
525
483
  px: "6",
526
484
  py: "4",
527
485
  borderBottom: "px",
528
- ...e,
529
- children: t
486
+ ...t,
487
+ children: e
530
488
  }
531
- ), _e = ({
532
- children: t,
533
- ...e
534
- }) => /* @__PURE__ */ u(
535
- g,
489
+ ), We = ({
490
+ children: e,
491
+ ...t
492
+ }) => /* @__PURE__ */ d(
493
+ E,
536
494
  {
537
495
  direction: "row",
538
496
  align: "center",
@@ -541,20 +499,20 @@ const Te = ({
541
499
  px: "6",
542
500
  py: "4",
543
501
  borderTop: "px",
544
- ...e,
545
- children: t
502
+ ...t,
503
+ children: e
546
504
  }
547
- ), Ie = {};
548
- Object.assign(Ie, {
549
- Root: Be,
550
- Content: Me,
551
- Close: ke,
552
- Body: Fe,
553
- Header: $e,
554
- Footer: _e
505
+ ), Ne = {};
506
+ Object.assign(Ne, {
507
+ Root: we,
508
+ Content: xe,
509
+ Close: Se,
510
+ Body: Te,
511
+ Header: Be,
512
+ Footer: We
555
513
  });
556
514
  export {
557
- Ie as Modal,
558
- qe as ModalStackingProvider
515
+ Ne as Modal,
516
+ Ue as ModalStackingProvider
559
517
  };
560
518
  //# sourceMappingURL=index.mjs.map