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