@mittwald/react-tunnel 0.2.0-alpha.819 → 0.2.0-alpha.820
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 +81 -53
- package/dist/types/TunnelState.d.ts +12 -3
- package/dist/types/TunnelState.d.ts.map +1 -1
- package/dist/types/components/TunnelEntry.d.ts.map +1 -1
- package/dist/types/components/TunnelExit.d.ts.map +1 -1
- package/dist/types/components/TunnelProvider.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,97 +1,125 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { observable as
|
|
6
|
-
import { observer as
|
|
7
|
-
const
|
|
3
|
+
import { jsx as P } from "react/jsx-runtime";
|
|
4
|
+
import { useId as v, useState as E, useRef as a, createContext as g, useContext as I, useEffect as f, useLayoutEffect as R } from "react";
|
|
5
|
+
import { observable as p, makeObservable as T, action as x } from "mobx";
|
|
6
|
+
import { observer as b } from "mobx-react-lite";
|
|
7
|
+
const h = "default", u = "default";
|
|
8
8
|
class l {
|
|
9
9
|
id;
|
|
10
|
-
|
|
10
|
+
instanceId;
|
|
11
|
+
committedChildren = p.map(
|
|
11
12
|
{},
|
|
12
13
|
{
|
|
13
14
|
deep: !1
|
|
14
15
|
}
|
|
15
16
|
);
|
|
17
|
+
renderPhaseChildren = /* @__PURE__ */ new Map();
|
|
16
18
|
nextIndex = 0;
|
|
17
|
-
constructor(e =
|
|
18
|
-
this.id = e, T(this, {
|
|
19
|
+
constructor(e = u, t = u) {
|
|
20
|
+
this.id = e, this.instanceId = t, T(this, {
|
|
19
21
|
id: !1,
|
|
20
|
-
deleteChildren:
|
|
21
|
-
setChildren:
|
|
22
|
+
deleteChildren: x.bound,
|
|
23
|
+
setChildren: x.bound
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
static useNew(e) {
|
|
25
|
-
const t =
|
|
26
|
-
return
|
|
27
|
+
const t = v(), r = E(() => new l(e, t))[0];
|
|
28
|
+
return r.resetIndex(), r;
|
|
27
29
|
}
|
|
28
30
|
resetIndex() {
|
|
29
31
|
this.nextIndex = 0;
|
|
30
32
|
}
|
|
31
33
|
useEntryIndex() {
|
|
32
|
-
const e =
|
|
33
|
-
return
|
|
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;
|
|
34
36
|
}
|
|
35
|
-
setChildren(e =
|
|
36
|
-
const
|
|
37
|
+
setChildren(e = h, t, r, n) {
|
|
38
|
+
const s = {
|
|
37
39
|
id: t,
|
|
38
|
-
index:
|
|
39
|
-
children:
|
|
40
|
-
},
|
|
41
|
-
|
|
40
|
+
index: r,
|
|
41
|
+
children: n
|
|
42
|
+
}, i = this.committedChildren.get(e) ?? p.map({}, { deep: !1 });
|
|
43
|
+
i.set(t, s), this.renderPhaseChildren.get(e)?.delete(t), this.committedChildren.set(e, i);
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
setRenderPhaseChildren(e = h, t, r, n) {
|
|
46
|
+
const s = {
|
|
47
|
+
id: t,
|
|
48
|
+
index: r,
|
|
49
|
+
children: n
|
|
50
|
+
}, i = this.renderPhaseChildren.get(e) ?? /* @__PURE__ */ new Map();
|
|
51
|
+
i.set(t, s), this.renderPhaseChildren.set(e, i);
|
|
52
|
+
}
|
|
53
|
+
deleteChildrenFromMap(e, t, r) {
|
|
54
|
+
const n = e.get(t);
|
|
55
|
+
n?.delete(r), n?.size === 0 && e.delete(t);
|
|
56
|
+
}
|
|
57
|
+
deleteChildren(e = h, t) {
|
|
58
|
+
this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
|
|
60
|
+
takeRenderPhaseChildren(e) {
|
|
61
|
+
if (this.renderPhaseChildren.has(e)) {
|
|
62
|
+
const t = this.renderPhaseChildren.get(e)?.values();
|
|
63
|
+
return this.renderPhaseChildren.delete(e), t;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
getEntries(e = h) {
|
|
67
|
+
const t = this.committedChildren.get(e)?.values(), r = t ?? this.takeRenderPhaseChildren(e);
|
|
68
|
+
if (r) {
|
|
69
|
+
const n = !!t, s = Array.from(r).sort(
|
|
70
|
+
(i, d) => i.index - d.index
|
|
52
71
|
);
|
|
72
|
+
return {
|
|
73
|
+
committed: n,
|
|
74
|
+
entries: s
|
|
75
|
+
};
|
|
76
|
+
}
|
|
53
77
|
}
|
|
54
78
|
}
|
|
55
|
-
const
|
|
79
|
+
const C = g({
|
|
56
80
|
state: new l()
|
|
57
|
-
}),
|
|
58
|
-
let e =
|
|
81
|
+
}), w = (o = u) => {
|
|
82
|
+
let e = I(C);
|
|
59
83
|
for (; e; ) {
|
|
60
|
-
if (e.state.id ===
|
|
84
|
+
if (e.state.id === o)
|
|
61
85
|
return e.state;
|
|
62
86
|
e = e.parentContext;
|
|
63
87
|
}
|
|
64
88
|
throw new Error(
|
|
65
|
-
`Could not get tunnel for provider ${
|
|
89
|
+
`Could not get tunnel for provider ${o}. Please provider a TunnelProvider with this ID.`
|
|
66
90
|
);
|
|
67
|
-
},
|
|
68
|
-
const { children: e, id: t } = r, n =
|
|
69
|
-
return /* @__PURE__ */
|
|
70
|
-
|
|
91
|
+
}, N = (o) => {
|
|
92
|
+
const { children: e, id: t } = o, r = I(C), n = l.useNew(t);
|
|
93
|
+
return /* @__PURE__ */ P(
|
|
94
|
+
C.Provider,
|
|
71
95
|
{
|
|
72
96
|
value: {
|
|
73
|
-
state:
|
|
74
|
-
parentContext:
|
|
97
|
+
state: n,
|
|
98
|
+
parentContext: r
|
|
75
99
|
},
|
|
76
100
|
children: e
|
|
77
101
|
}
|
|
78
102
|
);
|
|
79
|
-
},
|
|
80
|
-
const { children: e, id: t, staticEntryId:
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
}, [e, t,
|
|
84
|
-
|
|
85
|
-
}, [t,
|
|
86
|
-
},
|
|
87
|
-
const { children: e } =
|
|
103
|
+
}, j = (o) => {
|
|
104
|
+
const { children: e, id: t, staticEntryId: r, providerId: n } = o, s = w(n), i = v(), d = r ?? i, c = s.useEntryIndex(), m = a(!1);
|
|
105
|
+
return m.current || s.setRenderPhaseChildren(t, d, c, e), f(() => {
|
|
106
|
+
m.current = !0, s.setChildren(t, d, c, e);
|
|
107
|
+
}, [e, t, d, c, n]), f(() => () => {
|
|
108
|
+
s.deleteChildren(t, d);
|
|
109
|
+
}, [t, d, n]), null;
|
|
110
|
+
}, y = (o) => {
|
|
111
|
+
const { children: e } = o;
|
|
88
112
|
return typeof e == "function" ? e() : e;
|
|
89
|
-
},
|
|
90
|
-
const { children: e, id: t, providerId:
|
|
113
|
+
}, z = b((o) => {
|
|
114
|
+
const { children: e, id: t, providerId: r } = o, n = w(r).getEntries(t), [, s] = E(0);
|
|
115
|
+
R(() => {
|
|
116
|
+
n && !n.committed && s((d) => d + 1);
|
|
117
|
+
}, [n?.committed]);
|
|
118
|
+
const i = n?.entries.map((d) => /* @__PURE__ */ P(y, { children: d.children }, d.id));
|
|
91
119
|
return typeof e == "function" ? e(i) : i ?? e;
|
|
92
120
|
});
|
|
93
121
|
export {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
122
|
+
j as TunnelEntry,
|
|
123
|
+
z as TunnelExit,
|
|
124
|
+
N as TunnelProvider
|
|
97
125
|
};
|
|
@@ -7,17 +7,26 @@ interface TunnelEntryState {
|
|
|
7
7
|
id: string;
|
|
8
8
|
children: TunnelChildren;
|
|
9
9
|
}
|
|
10
|
+
interface TunnelEntries {
|
|
11
|
+
committed: boolean;
|
|
12
|
+
entries: TunnelEntryState[];
|
|
13
|
+
}
|
|
10
14
|
export declare class TunnelState {
|
|
11
15
|
readonly id: string;
|
|
12
|
-
|
|
16
|
+
private instanceId;
|
|
17
|
+
readonly committedChildren: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
|
|
18
|
+
private readonly renderPhaseChildren;
|
|
13
19
|
private nextIndex;
|
|
14
|
-
constructor(id?: string);
|
|
20
|
+
constructor(id?: string, instanceId?: string);
|
|
15
21
|
static useNew(id?: string): TunnelState;
|
|
16
22
|
resetIndex(): void;
|
|
17
23
|
useEntryIndex(): number;
|
|
18
24
|
setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
|
|
25
|
+
setRenderPhaseChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
|
|
26
|
+
private deleteChildrenFromMap;
|
|
19
27
|
deleteChildren(tunnelId: string | undefined, entryId: string): void;
|
|
20
|
-
|
|
28
|
+
private takeRenderPhaseChildren;
|
|
29
|
+
getEntries(tunnelId?: string): TunnelEntries | undefined;
|
|
21
30
|
}
|
|
22
31
|
export {};
|
|
23
32
|
//# sourceMappingURL=TunnelState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAI1C,eAAO,MAAM,uBAAuB,YAAY,CAAC;AAEjD,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,SAAS,GACT,CAAC,CAAC,cAAc,CAAC,EAAE,SAAS,GAAG,SAAS,KAAK,SAAS,GAAG,SAAS,CAAC,CAAC;AAExE,UAAU,gBAAgB;IACxB,KAAK,EAAE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C;AAElC,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"TunnelEntry.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelEntry.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI3C,MAAM,MAAM,mBAAmB,GAC3B,SAAS,GACT,SAAS,GACT,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC;AAElC,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CA+B5C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAOD,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAoBzC,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelProvider.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAIpE,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"TunnelProvider.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAIpE,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CAgBlD,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
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.820",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "It's like a Portal – but with React components",
|
|
6
6
|
"keywords": [
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"react": "^19.2.0",
|
|
60
60
|
"react-dom": "^19.2.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "a113b886bd95adb2482c1c9bf387a0d6158df5b5"
|
|
63
63
|
}
|