layerpro 3.1.5 → 3.3.0

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.
package/react.js CHANGED
@@ -1,18 +1,400 @@
1
- import { createRoot as e } from "react-dom/client";
1
+ import e, { isValidElement as t } from "react";
2
2
 
3
- var o = (o, n, r) => {
4
- const t = String(o.id);
5
- try {
6
- if (r) {
7
- const e = r.get(t);
8
- if (e) return void e.render(o.body);
3
+ import { createRoot as n } from "react-dom/client";
4
+
5
+ import { createPortal as o } from "react-dom";
6
+
7
+ var r = Object.defineProperty, i = (e, t, n) => {
8
+ return s = n, (i = "symbol" != typeof t ? t + "" : t) in (o = e) ? r(o, i, {
9
+ enumerable: !0,
10
+ configurable: !0,
11
+ writable: !0,
12
+ value: s
13
+ }) : o[i] = s;
14
+ var o, i, s;
15
+ }, s = class extends Error {
16
+ constructor(e, t, n) {
17
+ super(`[reattach:${t}] ${e}`), i(this, "code"), i(this, "details"), this.name = "ReattachError",
18
+ this.code = t, void 0 !== n && (this.details = n);
19
+ }
20
+ }, l = new WeakMap, a = new Set;
21
+
22
+ function c() {
23
+ if ("undefined" == typeof document || "undefined" == typeof window) throw new s("reattach requires a browser environment (document is not available)", "ENVIRONMENT_ERROR");
24
+ }
25
+
26
+ function d(e) {
27
+ if (c(), "string" != typeof e || 0 === e.length) throw new s("Invalid selector received: " + typeof e, "INVALID_SELECTOR");
28
+ const t = document.querySelector(e);
29
+ if (!t) throw new s(`No element found matching selector "${e}"`, "PARENT_NOT_FOUND");
30
+ return t;
31
+ }
32
+
33
+ function u(e, t) {
34
+ if (t) {
35
+ const n = Array.from(e.children).filter(e => e.id === t);
36
+ if (n.length, n.length > 0) return {
37
+ element: n[0],
38
+ created: !1
39
+ };
40
+ }
41
+ const n = document.createElement("div");
42
+ return t && (n.id = t), e.appendChild(n), a.add(n), {
43
+ element: n,
44
+ created: !0
45
+ };
46
+ }
47
+
48
+ function f(e, t) {
49
+ if (!t) return e;
50
+ const n = document.createElement("div");
51
+ return n.className = "reattach-overlay", t.zIndex ? n.style.zIndex = String(t.zIndex) : t.stackingOrder && (n.style.zIndex = String("top" === t.stackingOrder ? 9999 : "bottom" === t.stackingOrder ? 0 : 5e3)),
52
+ n.style.position = "fixed", n.style.top = "0", n.style.left = "0", n.style.width = "100vw",
53
+ n.style.height = "100vh", n.style.display = "flex", n.style.alignItems = "center",
54
+ n.style.justifyContent = "center", n.style.pointerEvents = "auto", e.appendChild(n),
55
+ n;
56
+ }
57
+
58
+ function m(e, t) {
59
+ const n = g.get(e) ?? {
60
+ zIndex: 0,
61
+ scrollLocked: !1
62
+ };
63
+ n.scrollLocked = !0, n.originalOverflow = document.body.style.overflow, document.body.style.overflow = "hidden",
64
+ g.set(e, n);
65
+ }
66
+
67
+ function h(e) {
68
+ const t = g.get(e);
69
+ t && (t.scrollLocked && (document.body.style.overflow = t.originalOverflow ?? ""),
70
+ t.focusTrapCleanup && t.focusTrapCleanup(), t.scrollLocked = !1, t.originalOverflow = void 0,
71
+ t.focusTrapCleanup = void 0, g.set(e, t));
72
+ }
73
+
74
+ function y(e, t) {
75
+ const n = [ "a[href]", "button:not([disabled])", "input:not([disabled])", "select:not([disabled])", "textarea:not([disabled])", '[tabindex]:not([tabindex="-1"])' ].join(", "), o = Array.from(e.querySelectorAll(n));
76
+ if (0 === o.length) return;
77
+ const r = o[0], i = o[o.length - 1], s = e => {
78
+ "Tab" === e.key && (e.shiftKey && document.activeElement === r ? (e.preventDefault(),
79
+ i.focus()) : e.shiftKey || document.activeElement !== i || (e.preventDefault(),
80
+ r.focus()));
81
+ }, c = t => {
82
+ if ("Escape" === t.key && e.parentElement) {
83
+ e.parentElement.removeChild(e);
84
+ const t = l.get(e);
85
+ t && (t.unmount(), l.delete(e)), a.delete(e), g.delete(e), h(e);
9
86
  }
10
- const a = e(n);
11
- a.render(o.body), r && r.set(t, a);
87
+ };
88
+ return e.addEventListener("keydown", s), document.addEventListener("keydown", c),
89
+ () => {
90
+ e.removeEventListener("keydown", s), document.removeEventListener("keydown", c);
91
+ };
92
+ }
93
+
94
+ function p(o, r, i) {
95
+ let s = i ?? l.get(o);
96
+ return s || (s = n(o), l.set(o, s)), s.render(t(r) ? r : e.createElement(e.Fragment, null, r)),
97
+ s;
98
+ }
99
+
100
+ function v(e) {
101
+ const t = w.get(e);
102
+ t && t.destroy();
103
+ const n = l.get(e);
104
+ return n && (n.unmount(), l.delete(e)), a.delete(e), T(e), h(e), g.delete(e), e.remove(),
105
+ !0;
106
+ }
107
+
108
+ function b(e, t) {
109
+ if (!t) return;
110
+ t.id && (e.id = t.id), t.class && (e.className = t.class), t.name && (e.name = t.name),
111
+ t.dataset && Object.entries(t.dataset).forEach(([t, n]) => {
112
+ e.dataset[t] = n;
113
+ }), t.style && ("string" == typeof t.style ? e.setAttribute("style", t.style) : Object.assign(e.style, t.style));
114
+ const n = new Set([ "id", "class", "name", "dataset", "style", "root", "inheritContext", "resilient", "overlay", "bubbleEvents", "isolateNativeEvents", "layout", "hydrate" ]);
115
+ Object.entries(t).forEach(([t, o]) => {
116
+ n.has(t) || "string" != typeof o && "number" != typeof o && "boolean" != typeof o || e.setAttribute(t, String(o));
117
+ });
118
+ }
119
+
120
+ var E = new Map, g = new Map, w = new WeakMap, L = new WeakMap;
121
+
122
+ function C(t = null) {
123
+ let n = t;
124
+ for (const [t, o] of E) n = e.createElement(t.Provider, {
125
+ value: o
126
+ }, n);
127
+ return n ? e.isValidElement(n) ? n : e.createElement(e.Fragment, null, n) : e.createElement(e.Fragment, null);
128
+ }
129
+
130
+ function x(t, n) {
131
+ const o = new MutationObserver(r => {
132
+ if (!document.contains(t)) {
133
+ o.disconnect();
134
+ let r = null;
135
+ try {
136
+ r = n();
137
+ } catch {
138
+ return;
139
+ }
140
+ if (r && r !== t) {
141
+ const o = l.get(t);
142
+ o && (o.unmount(), l.delete(t)), a.delete(t);
143
+ const r = n();
144
+ p(r, t.innerHTML ? e.createElement("div", {
145
+ dangerouslySetInnerHTML: {
146
+ __html: t.innerHTML
147
+ }
148
+ }) : null), x(r, n);
149
+ }
150
+ }
151
+ });
152
+ o.observe(document.documentElement, {
153
+ childList: !0,
154
+ subtree: !0
155
+ });
156
+ }
157
+
158
+ function I(e, t, n) {
159
+ const o = new Map;
160
+ L.set(e, o), n && (e.addEventListener("click", e => e.stopPropagation(), {
161
+ capture: !0
162
+ }), e.addEventListener("keydown", e => e.stopPropagation(), {
163
+ capture: !0
164
+ }), e.addEventListener("keyup", e => e.stopPropagation(), {
165
+ capture: !0
166
+ }));
167
+ const r = e.parentElement;
168
+ r && t.forEach(t => {
169
+ const n = t.slice(2).toLowerCase(), i = e => {
170
+ if (e.target === r) return;
171
+ const t = new CustomEvent(e.type, {
172
+ detail: {
173
+ originalEvent: e
174
+ },
175
+ bubbles: !0
176
+ });
177
+ r.dispatchEvent(t);
178
+ };
179
+ o.set(t, i), e.addEventListener(n, i, !0);
180
+ });
181
+ }
182
+
183
+ function T(e) {
184
+ const t = L.get(e);
185
+ t && (t.forEach((t, n) => {
186
+ const o = n.slice(2).toLowerCase();
187
+ e.removeEventListener(o, t, !0);
188
+ }), L.delete(e));
189
+ }
190
+
191
+ function k(t, n) {
192
+ const o = w.get(t);
193
+ if (o) return o;
194
+ const r = {
195
+ updateProps: t => {
196
+ const o = e.createElement("div", t);
197
+ n.render(o);
198
+ },
199
+ getContainer: () => t,
200
+ destroy: () => {
201
+ n.unmount(), l.delete(t), a.delete(t), T(t), h(t), g.delete(t), w.delete(t);
202
+ }
203
+ };
204
+ return w.set(t, r), r;
205
+ }
206
+
207
+ function N(e, t) {
208
+ if (!t.anchor) return;
209
+ const n = () => {
210
+ const n = document.querySelector(t.anchor);
211
+ if (!n || !e.parentElement) return;
212
+ const o = n.getBoundingClientRect(), r = e.getBoundingClientRect(), i = t.placement || "bottom", s = t.offset || 0;
213
+ let l = 0, a = 0;
214
+ const c = window.innerWidth, d = window.innerHeight;
215
+ i.startsWith("top") || i.startsWith("bottom") ? (l = i.startsWith("top") ? o.top - r.height - s : o.bottom + s,
216
+ a = i.endsWith("-start") ? o.left : i.endsWith("-end") ? o.right - r.width : o.left + (o.width - r.width) / 2) : (a = i.startsWith("left") ? o.left - r.width - s : o.right + s,
217
+ l = i.endsWith("-start") ? o.top : i.endsWith("-end") ? o.bottom - r.height : o.top + (o.height - r.height) / 2),
218
+ i.startsWith("bottom") && l + r.height > d && (l = o.top - r.height - s), i.startsWith("top") && l < 0 && (l = o.bottom + s),
219
+ i.startsWith("left") && a < 0 && (a = o.right + s), i.startsWith("right") && a + r.width > c && (a = o.left - r.width - s),
220
+ e.style.position = "fixed", e.style.top = `${Math.max(0, l)}px`, e.style.left = `${Math.max(0, a)}px`;
221
+ };
222
+ n();
223
+ const o = () => n(), r = () => n();
224
+ return window.addEventListener("resize", o), window.addEventListener("scroll", r, !0),
225
+ () => {
226
+ window.removeEventListener("resize", o), window.removeEventListener("scroll", r, !0);
227
+ };
228
+ }
229
+
230
+ var O = function(e, ...n) {
231
+ if (0 === n.length) {
232
+ if (c(), "string" != typeof e || 0 === e.length) throw new s("Invalid id argument", "INVALID_ID");
233
+ return document.getElementById(e) ?? null;
234
+ }
235
+ let o, r, i, l = {};
236
+ const [a, h, v] = n;
237
+ if ("string" == typeof a) {
238
+ if (o = a, r = h, v && "object" == typeof v && !Array.isArray(v)) {
239
+ const e = v;
240
+ l.inheritContext = !0 === e.inheritContext, l.resilient = !0 === e.resilient, i = e;
241
+ }
242
+ } else if (t(a)) {
243
+ if (r = a, h && "object" == typeof h && !Array.isArray(h)) {
244
+ const e = h;
245
+ l.inheritContext = !0 === e.inheritContext, l.resilient = !0 === e.resilient, i = e;
246
+ }
247
+ } else if (a && "object" == typeof a && !Array.isArray(a)) {
248
+ if (l = a, o = l.id, r = h, v && "object" == typeof v && !Array.isArray(v)) {
249
+ const e = v;
250
+ l.inheritContext = !0 === e.inheritContext, l.resilient = !0 === e.resilient, i = e;
251
+ }
252
+ } else null != a && (r = a);
253
+ if (null == r) throw new s("children is required", "CHILDREN_REQUIRED");
254
+ const E = d(e), w = u(E, o).element;
255
+ b(w, {
256
+ id: o,
257
+ class: l.class,
258
+ name: l.name,
259
+ dataset: l.dataset,
260
+ style: l.style,
261
+ ...Object.fromEntries(Object.entries(l).filter(([e]) => ![ "id", "class", "name", "dataset", "style", "inheritContext", "resilient" ].includes(e)))
262
+ });
263
+ let L = r;
264
+ if ((i?.inheritContext || l.inheritContext) && (L = C(r)), (i?.resilient || l.resilient) && x(w, () => u(E, o).element),
265
+ (i?.bubbleEvents || i?.isolateNativeEvents) && I(w, i.bubbleEvents || [], !0 === i.isolateNativeEvents),
266
+ i?.layout && N(w, i.layout), i?.overlay) {
267
+ const e = f(w, i.overlay);
268
+ if (i.overlay.lockScroll && m(w), i.overlay.trapFocus) {
269
+ const t = y(e);
270
+ if (t) {
271
+ const e = g.get(w) ?? {
272
+ zIndex: 0,
273
+ scrollLocked: !1
274
+ };
275
+ e.focusTrapCleanup = t, g.set(w, e);
276
+ }
277
+ }
278
+ k(w, p(e, L));
279
+ } else k(w, p(w, L));
280
+ return w;
281
+ };
282
+
283
+ O.mount = function(e, t, r) {
284
+ if (c(), !(e instanceof HTMLElement)) throw new s("container must be an HTMLElement", "INVALID_CONTAINER");
285
+ if (null == t) throw new s("children is required for mount()", "CHILDREN_REQUIRED");
286
+ b(e, r);
287
+ let i, d = e;
288
+ if (r?.overlay && (d = f(e, r.overlay)), r?.overlay?.lockScroll && m(e), r?.overlay?.trapFocus) {
289
+ const e = y(d);
290
+ if (e) {
291
+ const t = g.get(d) ?? {
292
+ zIndex: 0,
293
+ scrollLocked: !1
294
+ };
295
+ t.focusTrapCleanup = e, g.set(d, t);
296
+ }
297
+ }
298
+ if (r?.bubbleEvents || r?.isolateNativeEvents) {
299
+ let t = [];
300
+ r?.bubbleEvents && (t = r.bubbleEvents), I(e, t, !0 === r?.isolateNativeEvents);
301
+ }
302
+ if (r?.layout && N(e, r.layout), r?.root) {
303
+ let n = t;
304
+ r.inheritContext && (n = C(t)), r.root.render(o(n, d)), a.add(e), i = r.root;
305
+ } else {
306
+ a.add(e);
307
+ let o = t;
308
+ r?.inheritContext && (o = C(t)), i = r?.hydrate ? function(e) {
309
+ if (e.innerHTML && e.innerHTML.trim() === "".trim()) {
310
+ const t = n(e);
311
+ return l.set(e, t), t;
312
+ }
313
+ e.innerHTML = "";
314
+ const t = n(e);
315
+ return l.set(e, t), t;
316
+ }(d) : p(d, o);
317
+ }
318
+ return i && k(e, i), r?.resilient && x(e, () => e), e;
319
+ }, O.unmount = function(e, t) {
320
+ if (c(), void 0 === e && void 0 === t) {
321
+ if (0 === a.size) return !1;
322
+ const e = Array.from(a);
323
+ for (const t of e) v(t);
324
+ return !0;
325
+ }
326
+ if (e && !t) {
327
+ const t = document.getElementById(e);
328
+ return !(!t || !a.has(t)) && v(t);
329
+ }
330
+ const n = d(e), o = t ? Array.from(n.children).find(e => e.id === t) : void 0;
331
+ return !(!o || !a.has(o)) && v(o);
332
+ }, O.clear = function(e) {
333
+ if (c(), !e) {
334
+ const e = a.size, t = Array.from(a);
335
+ for (const e of t) v(e);
336
+ return e;
337
+ }
338
+ const t = d(e);
339
+ let n = 0;
340
+ const o = Array.from(a);
341
+ for (const e of o) t.contains(e) && (v(e), n++);
342
+ return n;
343
+ }, O.has = function(e, t) {
344
+ if (e && t) {
345
+ const n = document.querySelector(e);
346
+ return !!n && Array.from(n.children).some(e => e.id === t && l.has(e));
347
+ }
348
+ if (e && !t) {
349
+ const t = document.getElementById(e);
350
+ return !!t && l.has(t);
351
+ }
352
+ return a.size > 0;
353
+ }, O.when = function(e, t = 0) {
354
+ if ("undefined" == typeof document) return Promise.reject(new s("reattach requires a browser environment", "ENVIRONMENT_ERROR"));
355
+ const n = document.querySelector(e);
356
+ return n ? Promise.resolve(n) : new Promise((n, o) => {
357
+ let r;
358
+ const i = new MutationObserver(() => {
359
+ const t = document.querySelector(e);
360
+ t && (r && clearTimeout(r), i.disconnect(), n(t));
361
+ });
362
+ i.observe(document.documentElement, {
363
+ childList: !0,
364
+ subtree: !0
365
+ }), t > 0 && (r = setTimeout(() => {
366
+ i.disconnect(), o(new s(`Timeout: "${e}" not found within ${t}ms`, "TIMEOUT"));
367
+ }, t));
368
+ });
369
+ }, O.global = function() {
370
+ c();
371
+ const e = globalThis;
372
+ return e.reattach || Object.defineProperty(e, "reattach", {
373
+ value: O,
374
+ configurable: !0,
375
+ enumerable: !1,
376
+ writable: !1
377
+ }), O;
378
+ };
379
+
380
+ var R = (e, t) => {
381
+ const n = String(e.id);
382
+ try {
383
+ O.mount(t, e.body, {
384
+ id: `layerpro_body_${n}`,
385
+ inheritContext: e.inheritContext ?? !1,
386
+ resilient: e.resilient ?? !1
387
+ });
12
388
  } catch (e) {
13
- const o = e instanceof Error ? e.message : String(e);
14
- o.includes("Invalid hook call") || o.includes("hooks") ? console.error("LayerPro Error: React hooks error detected. This usually happens when:\n1. Multiple copies of React are loaded on the page\n2. The component is called as a function instead of being passed as JSX\n3. React version mismatch between the app and LayerPro\n\nMake sure body is passed as <Component /> not <Component />()") : console.error("Error rendering React component:", e);
389
+ const t = e instanceof Error ? e.message : String(e);
390
+ t.includes("Invalid hook call") || t.includes("hooks") ? console.error("LayerPro Error: React hooks error detected. This usually happens when:\n1. Multiple copies of React are loaded on the page\n2. The component is called as a function instead of being passed as JSX\n3. React version mismatch between the app and LayerPro\n\nMake sure body is passed as <Component /> not <Component />()") : console.error("Error rendering React component:", e);
15
391
  }
16
392
  };
17
393
 
18
- export { o as default };
394
+ R.unmount = e => {
395
+ O.unmount(`layerpro_body_${e}`);
396
+ };
397
+
398
+ var A = R;
399
+
400
+ export { A as default };
@@ -70,6 +70,8 @@ interface GenLayerProps {
70
70
 
71
71
  source?: string
72
72
  store?: unknown
73
+ inheritContext?: boolean
74
+ resilient?: boolean
73
75
  }
74
76
 
75
77
  /**
@@ -106,10 +108,9 @@ interface _layerpro {
106
108
  store: (element: unknown) => void
107
109
  index: (id: string | number | GenLayerProps) => void
108
110
  zIndex: (props?: GenLayerProps) => number
109
- close: (id: string | number | GenLayerProps | null | undefined) => void
110
- unmount: (id: string) => void
111
- getReactRoots: () => Map<string, { unmount: () => void }> | null
112
- cleanupEvents: (id: string) => void
111
+ close: (id: string | number | GenLayerProps | null | undefined) => void
112
+ unmount: (id: string) => void
113
+ cleanupEvents: (id: string) => void
113
114
  abortSource: (id: string) => void
114
115
  useReactAdapter?: (props: GenLayerProps, container: HTMLElement) => void
115
116
  }