@mittwald/react-tunnel 0.2.0-alpha.805 → 0.2.0-alpha.807
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 +107 -53
- package/dist/types/TunnelState.d.ts +13 -6
- package/dist/types/TunnelState.d.ts.map +1 -1
- package/dist/types/components/TunnelEntry.d.ts +2 -0
- package/dist/types/components/TunnelEntry.d.ts.map +1 -1
- package/dist/types/components/TunnelExit.d.ts +2 -0
- package/dist/types/components/TunnelExit.d.ts.map +1 -1
- package/dist/types/components/TunnelProvider.d.ts +8 -1
- package/dist/types/components/TunnelProvider.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,86 +1,140 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { observable as
|
|
3
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
4
|
+
import { useState as T, useRef as c, createContext as g, useContext as p, useId as E, useEffect as C } from "react";
|
|
5
|
+
import { observable as x, makeObservable as b, action as S } from "mobx";
|
|
6
6
|
import { observer as w } from "mobx-react-lite";
|
|
7
|
-
const
|
|
7
|
+
const d = "default";
|
|
8
8
|
class o {
|
|
9
|
-
|
|
9
|
+
id;
|
|
10
|
+
children = x.map(
|
|
10
11
|
{},
|
|
11
12
|
{
|
|
12
13
|
deep: !1
|
|
13
14
|
}
|
|
14
15
|
);
|
|
16
|
+
parentTunnelState;
|
|
15
17
|
preparedChildren = /* @__PURE__ */ new Map();
|
|
16
18
|
nextIndex = 0;
|
|
17
|
-
constructor() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
constructor(e = {}) {
|
|
20
|
+
const { parentTunnelState: t, id: n } = e;
|
|
21
|
+
this.parentTunnelState = t, this.id = n ?? d, b(this, {
|
|
22
|
+
id: !1,
|
|
23
|
+
parentTunnelState: !1,
|
|
24
|
+
deleteChildren: S.bound,
|
|
25
|
+
setChildren: S.bound
|
|
21
26
|
});
|
|
22
27
|
}
|
|
23
|
-
static useNew() {
|
|
24
|
-
const
|
|
25
|
-
return
|
|
28
|
+
static useNew(e) {
|
|
29
|
+
const t = T(() => new o(e))[0];
|
|
30
|
+
return t.resetIndex(), t;
|
|
26
31
|
}
|
|
27
32
|
resetIndex() {
|
|
28
33
|
this.nextIndex = 0;
|
|
29
34
|
}
|
|
30
35
|
useEntryIndex() {
|
|
31
|
-
const e =
|
|
36
|
+
const e = c(this), t = c(null);
|
|
32
37
|
return (t.current === null || e.current !== this) && (e.current = this, t.current = this.nextIndex++), t.current;
|
|
33
38
|
}
|
|
34
|
-
setChildren(e =
|
|
35
|
-
|
|
39
|
+
setChildren(e = d, t, n, r, s, i = !0) {
|
|
40
|
+
if (i)
|
|
41
|
+
return this.getTunnelState(s)?.setChildren(
|
|
42
|
+
e,
|
|
43
|
+
t,
|
|
44
|
+
n,
|
|
45
|
+
r,
|
|
46
|
+
s,
|
|
47
|
+
!1
|
|
48
|
+
);
|
|
49
|
+
const l = {
|
|
36
50
|
id: t,
|
|
37
|
-
index:
|
|
38
|
-
children:
|
|
39
|
-
},
|
|
40
|
-
|
|
51
|
+
index: n,
|
|
52
|
+
children: r
|
|
53
|
+
}, a = this.children.get(e) ?? x.map({}, { deep: !1 });
|
|
54
|
+
a.set(t, l), this.preparedChildren.get(e)?.delete(t), this.children.set(e, a);
|
|
55
|
+
}
|
|
56
|
+
getTunnelState(e = d) {
|
|
57
|
+
if (e === this.id)
|
|
58
|
+
return this;
|
|
59
|
+
if (this.parentTunnelState)
|
|
60
|
+
return this.parentTunnelState.getTunnelState(e);
|
|
41
61
|
}
|
|
42
|
-
prepareChildren(e =
|
|
43
|
-
|
|
62
|
+
prepareChildren(e = d, t, n, r, s, i = !0) {
|
|
63
|
+
if (i)
|
|
64
|
+
return this.getTunnelState(s)?.prepareChildren(
|
|
65
|
+
e,
|
|
66
|
+
t,
|
|
67
|
+
n,
|
|
68
|
+
r,
|
|
69
|
+
s,
|
|
70
|
+
!1
|
|
71
|
+
);
|
|
72
|
+
const l = {
|
|
44
73
|
id: t,
|
|
45
|
-
index:
|
|
46
|
-
children:
|
|
47
|
-
},
|
|
48
|
-
|
|
74
|
+
index: n,
|
|
75
|
+
children: r
|
|
76
|
+
}, a = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
|
|
77
|
+
a.set(t, l), this.preparedChildren.set(e, a);
|
|
49
78
|
}
|
|
50
|
-
deleteChildrenFromMap(e, t, r) {
|
|
51
|
-
|
|
52
|
-
|
|
79
|
+
deleteChildrenFromMap(e, t, n, r, s = !0) {
|
|
80
|
+
if (s)
|
|
81
|
+
return this.getTunnelState(r)?.deleteChildrenFromMap(
|
|
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);
|
|
53
90
|
}
|
|
54
|
-
deleteChildren(e =
|
|
55
|
-
this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(
|
|
91
|
+
deleteChildren(e = d, t, n) {
|
|
92
|
+
this.deleteChildrenFromMap(this.children, e, t, n), this.deleteChildrenFromMap(
|
|
93
|
+
this.preparedChildren,
|
|
94
|
+
e,
|
|
95
|
+
t,
|
|
96
|
+
n
|
|
97
|
+
);
|
|
56
98
|
}
|
|
57
|
-
getEntries(e =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
99
|
+
getEntries(e = d, t, n = !0) {
|
|
100
|
+
if (n)
|
|
101
|
+
return this.getTunnelState(t)?.getEntries(
|
|
102
|
+
e,
|
|
103
|
+
t,
|
|
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
|
|
62
110
|
);
|
|
63
111
|
}
|
|
64
112
|
}
|
|
65
|
-
const
|
|
66
|
-
const { children: e } =
|
|
67
|
-
return /* @__PURE__ */
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
|
|
113
|
+
const h = g(new o()), N = (u) => {
|
|
114
|
+
const { children: e, id: t } = u, n = p(h);
|
|
115
|
+
return /* @__PURE__ */ m(
|
|
116
|
+
h.Provider,
|
|
117
|
+
{
|
|
118
|
+
value: o.useNew({ id: t, parentTunnelState: n }),
|
|
119
|
+
children: e
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}, P = (u) => {
|
|
123
|
+
const { children: e, id: t, staticEntryId: n, providerId: r } = u, s = p(h), i = E(), l = n ?? i, a = s.useEntryIndex(), f = c(!1);
|
|
124
|
+
return f.current || s.prepareChildren(t, l, a, e, r), C(() => {
|
|
125
|
+
f.current = !0, s.setChildren(t, l, a, e, r);
|
|
126
|
+
}, [e, t, l, a, r]), C(() => () => {
|
|
127
|
+
s.deleteChildren(t, l, r);
|
|
128
|
+
}, [t, l, r]), null;
|
|
129
|
+
}, M = (u) => {
|
|
130
|
+
const { children: e } = u;
|
|
77
131
|
return typeof e == "function" ? e() : e;
|
|
78
|
-
},
|
|
79
|
-
const { children: e, id: t } =
|
|
80
|
-
return typeof e == "function" ? e(
|
|
132
|
+
}, j = w((u) => {
|
|
133
|
+
const { children: e, id: t, providerId: n } = u, r = p(h).getEntries(t, n), s = r ? r.map((i) => /* @__PURE__ */ m(M, { children: i.children }, i.id)) : null;
|
|
134
|
+
return typeof e == "function" ? e(s) : s ?? e;
|
|
81
135
|
});
|
|
82
136
|
export {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
137
|
+
P as TunnelEntry,
|
|
138
|
+
j as TunnelExit,
|
|
139
|
+
N as TunnelProvider
|
|
86
140
|
};
|
|
@@ -6,19 +6,26 @@ interface TunnelEntryState {
|
|
|
6
6
|
id: string;
|
|
7
7
|
children: TunnelChildren;
|
|
8
8
|
}
|
|
9
|
+
export interface TunnelStateOptions {
|
|
10
|
+
parentTunnelState?: TunnelState;
|
|
11
|
+
id?: string;
|
|
12
|
+
}
|
|
9
13
|
export declare class TunnelState {
|
|
14
|
+
readonly id: string;
|
|
10
15
|
readonly children: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
|
|
16
|
+
parentTunnelState?: TunnelState;
|
|
11
17
|
private readonly preparedChildren;
|
|
12
18
|
private nextIndex;
|
|
13
|
-
constructor();
|
|
14
|
-
static useNew(): TunnelState;
|
|
19
|
+
constructor(options?: TunnelStateOptions);
|
|
20
|
+
static useNew(options?: TunnelStateOptions): TunnelState;
|
|
15
21
|
resetIndex(): void;
|
|
16
22
|
useEntryIndex(): number;
|
|
17
|
-
setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
|
|
18
|
-
|
|
23
|
+
setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string, recurse?: boolean): void;
|
|
24
|
+
private getTunnelState;
|
|
25
|
+
prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string, recurse?: boolean): void;
|
|
19
26
|
private deleteChildrenFromMap;
|
|
20
|
-
deleteChildren(tunnelId: string | undefined, entryId: string): void;
|
|
21
|
-
getEntries(tunnelId?: string): TunnelEntryState[] | undefined;
|
|
27
|
+
deleteChildren(tunnelId: string | undefined, entryId: string, providerId?: string): void;
|
|
28
|
+
getEntries(tunnelId?: string, providerId?: string, recurse?: boolean): TunnelEntryState[] | undefined;
|
|
22
29
|
}
|
|
23
30
|
export {};
|
|
24
31
|
//# sourceMappingURL=TunnelState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[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EAAE,kBAAkB,GAAG,WAAW;IAMxD,UAAU;IAIV,aAAa;IAUb,WAAW,CAChB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,UAAO,GACb,IAAI;IA4BP,OAAO,CAAC,cAAc;IAWf,eAAe,CACpB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,UAAO,GACb,IAAI;IA2BP,OAAO,CAAC,qBAAqB;IA0BtB,cAAc,CACnB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI;IAUA,UAAU,CACf,QAAQ,GAAE,MAAkB,EAC5B,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,UAAO,GACb,gBAAgB,EAAE,GAAG,SAAS;CAkBlC"}
|
|
@@ -5,6 +5,8 @@ export interface TunnelEntryProps {
|
|
|
5
5
|
children?: TunnelEntryChildren;
|
|
6
6
|
/** Static entry ID instead of generated ID by `useId` */
|
|
7
7
|
staticEntryId?: string;
|
|
8
|
+
/** Select a dedicated tunnel provider by ID. */
|
|
9
|
+
providerId?: string;
|
|
8
10
|
}
|
|
9
11
|
export declare const TunnelEntry: FC<TunnelEntryProps>;
|
|
10
12
|
export default TunnelEntry;
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
|
@@ -3,6 +3,8 @@ import { TunnelChildren } from '../TunnelState';
|
|
|
3
3
|
export type TunnelExitChildren = TunnelChildren;
|
|
4
4
|
export interface TunnelExitProps {
|
|
5
5
|
id?: string;
|
|
6
|
+
/** Select a dedicated tunnel provider by ID. */
|
|
7
|
+
providerId?: string;
|
|
6
8
|
children?: TunnelExitChildren;
|
|
7
9
|
}
|
|
8
10
|
export declare const TunnelExit: FC<TunnelExitProps>;
|
|
@@ -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;AAIhC,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,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAOD,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAezC,CAAC;AAEH,eAAe,UAAU,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;AAIhC,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,4 +1,11 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
export
|
|
2
|
+
export interface TunnelProviderProps extends PropsWithChildren {
|
|
3
|
+
/**
|
|
4
|
+
* Dedicated id for this tunnel provider. If not provided, the tunnel provider
|
|
5
|
+
* will be registered as a global provider.
|
|
6
|
+
*/
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const TunnelProvider: FC<TunnelProviderProps>;
|
|
3
10
|
export default TunnelProvider;
|
|
4
11
|
//# sourceMappingURL=TunnelProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelProvider.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,
|
|
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,CAYlD,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.807",
|
|
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": "71328b3bd09ad1aff14d0216212e11b3a0cd26a2"
|
|
63
63
|
}
|