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