@mittwald/react-tunnel 0.2.0-alpha.809 → 0.2.0-alpha.811
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 +66 -97
- package/dist/types/TunnelState.d.ts +7 -12
- package/dist/types/TunnelState.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/dist/types/context.d.ts +6 -1
- package/dist/types/context.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,140 +1,109 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
3
|
import { jsx as m } from "react/jsx-runtime";
|
|
4
|
-
import { useState as
|
|
5
|
-
import { observable as
|
|
6
|
-
import { observer as
|
|
7
|
-
const
|
|
8
|
-
class
|
|
4
|
+
import { useState as g, useRef as h, createContext as b, useContext as v, useId as I, useEffect as f } from "react";
|
|
5
|
+
import { observable as C, makeObservable as T, action as x } from "mobx";
|
|
6
|
+
import { observer as y } from "mobx-react-lite";
|
|
7
|
+
const o = "default", E = "default";
|
|
8
|
+
class c {
|
|
9
9
|
id;
|
|
10
|
-
children =
|
|
10
|
+
children = C.map(
|
|
11
11
|
{},
|
|
12
12
|
{
|
|
13
13
|
deep: !1
|
|
14
14
|
}
|
|
15
15
|
);
|
|
16
|
-
parentTunnelState;
|
|
17
16
|
preparedChildren = /* @__PURE__ */ new Map();
|
|
18
17
|
nextIndex = 0;
|
|
19
|
-
constructor(e =
|
|
20
|
-
|
|
21
|
-
this.parentTunnelState = t, this.id = n ?? d, b(this, {
|
|
18
|
+
constructor(e = E) {
|
|
19
|
+
this.id = e, T(this, {
|
|
22
20
|
id: !1,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setChildren: S.bound
|
|
21
|
+
deleteChildren: x.bound,
|
|
22
|
+
setChildren: x.bound
|
|
26
23
|
});
|
|
27
24
|
}
|
|
28
25
|
static useNew(e) {
|
|
29
|
-
const t =
|
|
26
|
+
const t = g(() => new c(e))[0];
|
|
30
27
|
return t.resetIndex(), t;
|
|
31
28
|
}
|
|
32
29
|
resetIndex() {
|
|
33
30
|
this.nextIndex = 0;
|
|
34
31
|
}
|
|
35
32
|
useEntryIndex() {
|
|
36
|
-
const e =
|
|
33
|
+
const e = h(this), t = h(null);
|
|
37
34
|
return (t.current === null || e.current !== this) && (e.current = this, t.current = this.nextIndex++), t.current;
|
|
38
35
|
}
|
|
39
|
-
setChildren(e =
|
|
40
|
-
|
|
41
|
-
return this.getTunnelState(s)?.setChildren(
|
|
42
|
-
e,
|
|
43
|
-
t,
|
|
44
|
-
n,
|
|
45
|
-
r,
|
|
46
|
-
s,
|
|
47
|
-
!1
|
|
48
|
-
);
|
|
49
|
-
const l = {
|
|
36
|
+
setChildren(e = o, t, r, n) {
|
|
37
|
+
const s = {
|
|
50
38
|
id: t,
|
|
51
|
-
index:
|
|
52
|
-
children:
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
getTunnelState(e = d) {
|
|
57
|
-
if (e === this.id)
|
|
58
|
-
return this;
|
|
59
|
-
if (this.parentTunnelState)
|
|
60
|
-
return this.parentTunnelState.getTunnelState(e);
|
|
39
|
+
index: r,
|
|
40
|
+
children: n
|
|
41
|
+
}, d = this.children.get(e) ?? C.map({}, { deep: !1 });
|
|
42
|
+
d.set(t, s), this.preparedChildren.get(e)?.delete(t), this.children.set(e, d);
|
|
61
43
|
}
|
|
62
|
-
prepareChildren(e =
|
|
63
|
-
|
|
64
|
-
return this.getTunnelState(s)?.prepareChildren(
|
|
65
|
-
e,
|
|
66
|
-
t,
|
|
67
|
-
n,
|
|
68
|
-
r,
|
|
69
|
-
s,
|
|
70
|
-
!1
|
|
71
|
-
);
|
|
72
|
-
const l = {
|
|
44
|
+
prepareChildren(e = o, t, r, n) {
|
|
45
|
+
const s = {
|
|
73
46
|
id: t,
|
|
74
|
-
index:
|
|
75
|
-
children:
|
|
76
|
-
},
|
|
77
|
-
|
|
47
|
+
index: r,
|
|
48
|
+
children: n
|
|
49
|
+
}, d = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
|
|
50
|
+
d.set(t, s), this.preparedChildren.set(e, d);
|
|
78
51
|
}
|
|
79
|
-
deleteChildrenFromMap(e, t,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
e,
|
|
83
|
-
t,
|
|
84
|
-
n,
|
|
85
|
-
r,
|
|
86
|
-
!1
|
|
87
|
-
);
|
|
88
|
-
const i = e.get(t);
|
|
89
|
-
i?.delete(n), i?.size === 0 && e.delete(t);
|
|
52
|
+
deleteChildrenFromMap(e, t, r) {
|
|
53
|
+
const n = e.get(t);
|
|
54
|
+
n?.delete(r), n?.size === 0 && e.delete(t);
|
|
90
55
|
}
|
|
91
|
-
deleteChildren(e =
|
|
92
|
-
this.deleteChildrenFromMap(this.children, e, t
|
|
93
|
-
this.preparedChildren,
|
|
94
|
-
e,
|
|
95
|
-
t,
|
|
96
|
-
n
|
|
97
|
-
);
|
|
56
|
+
deleteChildren(e = o, t) {
|
|
57
|
+
this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
|
|
98
58
|
}
|
|
99
|
-
getEntries(e =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
!1
|
|
105
|
-
);
|
|
106
|
-
const r = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
|
|
107
|
-
if (r)
|
|
108
|
-
return Array.from(r).sort(
|
|
109
|
-
(s, i) => s.index - i.index
|
|
59
|
+
getEntries(e = o) {
|
|
60
|
+
const t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
|
|
61
|
+
if (t)
|
|
62
|
+
return Array.from(t).sort(
|
|
63
|
+
(r, n) => r.index - n.index
|
|
110
64
|
);
|
|
111
65
|
}
|
|
112
66
|
}
|
|
113
|
-
const
|
|
114
|
-
|
|
67
|
+
const a = b({
|
|
68
|
+
state: new c()
|
|
69
|
+
}), w = (i = E) => {
|
|
70
|
+
let e = v(a);
|
|
71
|
+
for (; e; ) {
|
|
72
|
+
if (e.state.id === i)
|
|
73
|
+
return e.state;
|
|
74
|
+
e = e.parentContext;
|
|
75
|
+
}
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Could not get tunnel for provider ${i}. Please provider a TunnelProvider with this ID.`
|
|
78
|
+
);
|
|
79
|
+
}, N = (i) => {
|
|
80
|
+
const { children: e, id: t } = i, r = v(a);
|
|
115
81
|
return /* @__PURE__ */ m(
|
|
116
|
-
|
|
82
|
+
a.Provider,
|
|
117
83
|
{
|
|
118
|
-
value:
|
|
84
|
+
value: {
|
|
85
|
+
state: c.useNew(t),
|
|
86
|
+
parentContext: r
|
|
87
|
+
},
|
|
119
88
|
children: e
|
|
120
89
|
}
|
|
121
90
|
);
|
|
122
|
-
},
|
|
123
|
-
const { children: e, id: t, staticEntryId:
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
}, [e, t, l,
|
|
127
|
-
s.deleteChildren(t, l
|
|
128
|
-
}, [t, l,
|
|
129
|
-
}, M = (
|
|
130
|
-
const { children: e } =
|
|
91
|
+
}, j = (i) => {
|
|
92
|
+
const { children: e, id: t, staticEntryId: r, providerId: n } = i, s = w(n), d = I(), l = r ?? d, u = s.useEntryIndex(), p = h(!1);
|
|
93
|
+
return p.current || s.prepareChildren(t, l, u, e), f(() => {
|
|
94
|
+
p.current = !0, s.setChildren(t, l, u, e);
|
|
95
|
+
}, [e, t, l, u, n]), f(() => () => {
|
|
96
|
+
s.deleteChildren(t, l);
|
|
97
|
+
}, [t, l, n]), null;
|
|
98
|
+
}, M = (i) => {
|
|
99
|
+
const { children: e } = i;
|
|
131
100
|
return typeof e == "function" ? e() : e;
|
|
132
|
-
},
|
|
133
|
-
const { children: e, id: t, providerId:
|
|
101
|
+
}, k = y((i) => {
|
|
102
|
+
const { children: e, id: t, providerId: r } = i, n = w(r).getEntries(t), s = n ? n.map((d) => /* @__PURE__ */ m(M, { children: d.children }, d.id)) : null;
|
|
134
103
|
return typeof e == "function" ? e(s) : s ?? e;
|
|
135
104
|
});
|
|
136
105
|
export {
|
|
137
|
-
|
|
138
|
-
|
|
106
|
+
j as TunnelEntry,
|
|
107
|
+
k as TunnelExit,
|
|
139
108
|
N as TunnelProvider
|
|
140
109
|
};
|
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { ObservableMap } from 'mobx';
|
|
3
|
+
export declare const defaultTunnelProviderId = "default";
|
|
3
4
|
export type TunnelChildren = ReactNode | undefined | ((tunnelChildren?: ReactNode | undefined) => ReactNode | undefined);
|
|
4
5
|
interface TunnelEntryState {
|
|
5
6
|
index: number;
|
|
6
7
|
id: string;
|
|
7
8
|
children: TunnelChildren;
|
|
8
9
|
}
|
|
9
|
-
export interface TunnelStateOptions {
|
|
10
|
-
parentTunnelState?: TunnelState;
|
|
11
|
-
id?: string;
|
|
12
|
-
}
|
|
13
10
|
export declare class TunnelState {
|
|
14
11
|
readonly id: string;
|
|
15
12
|
readonly children: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
|
|
16
|
-
parentTunnelState?: TunnelState;
|
|
17
13
|
private readonly preparedChildren;
|
|
18
14
|
private nextIndex;
|
|
19
|
-
constructor(
|
|
20
|
-
static useNew(
|
|
15
|
+
constructor(id?: string);
|
|
16
|
+
static useNew(id?: string): TunnelState;
|
|
21
17
|
resetIndex(): void;
|
|
22
18
|
useEntryIndex(): number;
|
|
23
|
-
setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren
|
|
24
|
-
|
|
25
|
-
prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string, recurse?: boolean): void;
|
|
19
|
+
setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
|
|
20
|
+
prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
|
|
26
21
|
private deleteChildrenFromMap;
|
|
27
|
-
deleteChildren(tunnelId: string | undefined, entryId: string
|
|
28
|
-
getEntries(tunnelId?: string
|
|
22
|
+
deleteChildren(tunnelId: string | undefined, entryId: string): void;
|
|
23
|
+
getEntries(tunnelId?: string): TunnelEntryState[] | undefined;
|
|
29
24
|
}
|
|
30
25
|
export {};
|
|
31
26
|
//# 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,EAAoB,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,OAAO,CAAC;AACzD,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,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,qBAAa,WAAW;IACtB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAE3B,SAAgB,QAAQ,iEAQtB;IAEF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG7B;IAEJ,OAAO,CAAC,SAAS,CAAK;gBAEH,EAAE,SAA0B;WASjC,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW;IAMvC,UAAU;IAIV,aAAa;IAUb,WAAW,CAChB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,GACvB,IAAI;IAiBA,eAAe,CACpB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,GACvB,IAAI;IAgBP,OAAO,CAAC,qBAAqB;IAYtB,cAAc,CAAC,QAAQ,EAAE,MAAM,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAKnE,UAAU,CACf,QAAQ,GAAE,MAAkB,GAC3B,gBAAgB,EAAE,GAAG,SAAS;CAUlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAGhC,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,CAezC,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,CAelD,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { TunnelState } from './TunnelState';
|
|
2
|
-
|
|
2
|
+
interface TunnelContext {
|
|
3
|
+
state: TunnelState;
|
|
4
|
+
parentContext?: TunnelContext;
|
|
5
|
+
}
|
|
6
|
+
export declare const tunnelContext: import('react').Context<TunnelContext>;
|
|
3
7
|
export default tunnelContext;
|
|
8
|
+
export declare const useTunnelState: (id?: string) => TunnelState;
|
|
4
9
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,WAAW,EAAE,MAAM,eAAe,CAAC;AAErE,UAAU,aAAa;IACrB,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,eAAO,MAAM,aAAa,wCAExB,CAAC;AAEH,eAAe,aAAa,CAAC;AAE7B,eAAO,MAAM,cAAc,GAAI,WAA4B,gBAa1D,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.811",
|
|
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": "e8b062a18a8ae333d83103765f2fc3fafb193a06"
|
|
63
63
|
}
|