@mittwald/react-tunnel 0.2.0-alpha.868 → 0.2.0-alpha.869
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/dist/index.js +118 -106
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,109 +1,121 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { observer as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
|
|
3
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
4
|
+
import { useId as P, useState as w, useRef as a, createContext as I, useContext as v, useLayoutEffect as g, useEffect as b } from "react";
|
|
5
|
+
import { observable as m, makeObservable as y, action as p } from "mobx";
|
|
6
|
+
import { observer as R } from "mobx-react-lite";
|
|
7
|
+
const l = "default", u = "default";
|
|
8
|
+
class c {
|
|
9
|
+
id;
|
|
10
|
+
instanceId;
|
|
11
|
+
committedChildren = m.map(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
deep: !1
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
renderPhaseChildren = /* @__PURE__ */ new Map();
|
|
18
|
+
nextIndex = 0;
|
|
19
|
+
constructor(e = u, t = u) {
|
|
20
|
+
this.id = e, this.instanceId = t, y(this, {
|
|
21
|
+
id: !1,
|
|
22
|
+
deleteChildren: p.bound,
|
|
23
|
+
setChildren: p.bound
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static useNew(e) {
|
|
27
|
+
const t = P(), n = w(() => new c(e, t))[0];
|
|
28
|
+
return n.resetIndex(), n;
|
|
29
|
+
}
|
|
30
|
+
resetIndex() {
|
|
31
|
+
this.nextIndex = 0;
|
|
32
|
+
}
|
|
33
|
+
useEntryIndex() {
|
|
34
|
+
const e = a(this.instanceId), t = a(null);
|
|
35
|
+
return (t.current === null || e.current !== this.instanceId) && (e.current = this.instanceId, t.current = this.nextIndex++), t.current;
|
|
36
|
+
}
|
|
37
|
+
setChildren(e = l, t, n, r) {
|
|
38
|
+
const s = {
|
|
39
|
+
id: t,
|
|
40
|
+
index: n,
|
|
41
|
+
children: r
|
|
42
|
+
}, i = this.committedChildren.get(e) ?? m.map({}, { deep: !1 });
|
|
43
|
+
i.set(t, s), this.renderPhaseChildren.get(e)?.delete(t), this.committedChildren.set(e, i);
|
|
44
|
+
}
|
|
45
|
+
setRenderPhaseChildren(e = l, t, n, r) {
|
|
46
|
+
const s = {
|
|
47
|
+
id: t,
|
|
48
|
+
index: n,
|
|
49
|
+
children: r
|
|
50
|
+
}, i = this.renderPhaseChildren.get(e) ?? /* @__PURE__ */ new Map();
|
|
51
|
+
i.set(t, s), this.renderPhaseChildren.set(e, i);
|
|
52
|
+
}
|
|
53
|
+
deleteChildrenFromMap(e, t, n) {
|
|
54
|
+
const r = e.get(t);
|
|
55
|
+
r?.delete(n), r?.size === 0 && e.delete(t);
|
|
56
|
+
}
|
|
57
|
+
deleteChildren(e = l, t) {
|
|
58
|
+
this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
|
|
59
|
+
}
|
|
60
|
+
takeRenderPhaseChildren(e) {
|
|
61
|
+
if (this.renderPhaseChildren.has(e)) {
|
|
62
|
+
const t = this.renderPhaseChildren.get(e)?.values();
|
|
63
|
+
return typeof window < "u" && this.renderPhaseChildren.delete(e), t;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
getEntries(e = l) {
|
|
67
|
+
const t = this.takeRenderPhaseChildren(e), n = this.committedChildren.get(e)?.values(), r = n ?? t;
|
|
68
|
+
if (r) {
|
|
69
|
+
const s = !!n, i = Array.from(r).sort(
|
|
70
|
+
(o, h) => o.index - h.index
|
|
71
|
+
);
|
|
72
|
+
return {
|
|
73
|
+
committed: s,
|
|
74
|
+
entries: i
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const C = I({
|
|
80
|
+
state: new c()
|
|
81
|
+
}), E = (d = u) => {
|
|
82
|
+
let e = v(C);
|
|
83
|
+
for (; e; ) {
|
|
84
|
+
if (e.state.id === d)
|
|
85
|
+
return e.state;
|
|
86
|
+
e = e.parentContext;
|
|
87
|
+
}
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Could not get tunnel for provider ${d}. Please provider a TunnelProvider with this ID.`
|
|
90
|
+
);
|
|
91
|
+
}, N = (d) => {
|
|
92
|
+
const { children: e, id: t } = d, n = v(C), r = c.useNew(t);
|
|
93
|
+
return /* @__PURE__ */ x(
|
|
94
|
+
C.Provider,
|
|
95
|
+
{
|
|
96
|
+
value: {
|
|
97
|
+
state: r,
|
|
98
|
+
parentContext: n
|
|
99
|
+
},
|
|
100
|
+
children: e
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}, j = (d) => {
|
|
104
|
+
const { children: e, id: t, staticEntryId: n, providerId: r } = d, s = E(r), i = P(), o = n ?? i, h = s.useEntryIndex(), f = a(!1);
|
|
105
|
+
return f.current || s.setRenderPhaseChildren(t, o, h, e), g(() => {
|
|
106
|
+
f.current = !0, s.setChildren(t, o, h, e);
|
|
107
|
+
}, [e, t, o, h, r]), b(() => () => {
|
|
108
|
+
s.deleteChildren(t, o);
|
|
109
|
+
}, [t, o, r]), null;
|
|
110
|
+
}, T = (d) => {
|
|
111
|
+
const { children: e } = d;
|
|
112
|
+
return typeof e == "function" ? e() : e;
|
|
113
|
+
}, z = R((d) => {
|
|
114
|
+
const { children: e, id: t, providerId: n } = d, s = E(n).getEntries(t)?.entries.map((i) => /* @__PURE__ */ x(T, { children: i.children }, i.id));
|
|
115
|
+
return typeof e == "function" ? e(s) : s ?? e;
|
|
107
116
|
});
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
export {
|
|
118
|
+
j as TunnelEntry,
|
|
119
|
+
z as TunnelExit,
|
|
120
|
+
N as TunnelProvider
|
|
121
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/react-tunnel",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.869",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "It's like a Portal – but with React components",
|
|
6
6
|
"keywords": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/node": "^25.9.3",
|
|
39
39
|
"@types/react": "^19.2",
|
|
40
40
|
"@types/react-dom": "^19.2",
|
|
41
|
-
"@vitejs/plugin-react": "
|
|
41
|
+
"@vitejs/plugin-react": "5.2.0",
|
|
42
42
|
"@vitest/browser-playwright": "^4.1.9",
|
|
43
43
|
"@vitest/coverage-v8": "^4.1.9",
|
|
44
44
|
"nx": "^22.7.5",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"react-dom": "^19.2.0",
|
|
48
48
|
"rimraf": "^6.1.3",
|
|
49
49
|
"typescript": "^6.0.3",
|
|
50
|
-
"vite": "
|
|
50
|
+
"vite": "7.3.5",
|
|
51
51
|
"vite-plugin-banner": "^0.8.1",
|
|
52
52
|
"vite-plugin-checker": "^0.14.1",
|
|
53
53
|
"vite-plugin-dts": "^5.0.2",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"react": "^19.2.0",
|
|
60
60
|
"react-dom": "^19.2.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "9bcd013dc5744a62ce98a00795a67dfd259b0ce4"
|
|
63
63
|
}
|