@mittwald/react-tunnel 0.1.0-alpha.115 → 0.1.0-alpha.117
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 +40 -34
- package/dist/types/TunnelState.d.ts +2 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
import
|
|
7
|
-
import { observable as
|
|
3
|
+
var C = Object.defineProperty;
|
|
4
|
+
var f = (i, e, t) => e in i ? C(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
5
|
+
var o = (i, e, t) => (f(i, typeof e != "symbol" ? e + "" : e, t), t);
|
|
6
|
+
import u, { useState as m, createContext as g, useContext as p, useId as E, useRef as b, useLayoutEffect as v } from "react";
|
|
7
|
+
import { observable as h, makeObservable as w, action as a } from "mobx";
|
|
8
8
|
import { observer as x } from "mobx-react-lite";
|
|
9
|
-
const
|
|
10
|
-
class
|
|
9
|
+
const l = "default";
|
|
10
|
+
class d {
|
|
11
11
|
constructor() {
|
|
12
|
-
|
|
12
|
+
o(this, "children", h.map(
|
|
13
13
|
{},
|
|
14
14
|
{
|
|
15
15
|
deep: !1
|
|
16
16
|
}
|
|
17
17
|
));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
o(this, "preparedChildren", /* @__PURE__ */ new Map());
|
|
19
|
+
w(this, {
|
|
20
|
+
deleteChildren: a.bound,
|
|
21
|
+
setChildren: a.bound
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
static useNew() {
|
|
24
|
-
return
|
|
25
|
+
return m(new d())[0];
|
|
25
26
|
}
|
|
26
|
-
setChildren(e =
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
setChildren(e = l, t, n) {
|
|
28
|
+
var s;
|
|
29
|
+
const r = this.children.get(e) ?? h.map({}, { deep: !1 });
|
|
30
|
+
r.set(t, n), (s = this.preparedChildren.get(e)) == null || s.delete(t), this.children.set(e, r);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(n
|
|
32
|
+
prepareChildren(e = l, t, n) {
|
|
33
|
+
const r = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
|
|
34
|
+
r.set(t, n), this.preparedChildren.set(e, r);
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
var n;
|
|
36
|
-
|
|
36
|
+
deleteChildren(e = l, t) {
|
|
37
|
+
var n, r;
|
|
38
|
+
(n = this.children.get(e)) == null || n.delete(t), (r = this.preparedChildren.get(e)) == null || r.delete(t);
|
|
39
|
+
}
|
|
40
|
+
getChildren(e = l) {
|
|
41
|
+
var n, r;
|
|
42
|
+
const t = ((n = this.children.get(e)) == null ? void 0 : n.entries()) ?? ((r = this.preparedChildren.get(e)) == null ? void 0 : r.entries());
|
|
37
43
|
if (t)
|
|
38
44
|
return Array.from(t);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
|
-
const c =
|
|
42
|
-
const { children: e } =
|
|
43
|
-
return /* @__PURE__ */
|
|
44
|
-
}, P = (
|
|
45
|
-
const { children: e, id: t } =
|
|
46
|
-
return
|
|
47
|
-
n.deleteChildren(t,
|
|
48
|
-
}), [e, t,
|
|
49
|
-
},
|
|
50
|
-
const { children: e } =
|
|
47
|
+
const c = g(new d()), N = (i) => {
|
|
48
|
+
const { children: e } = i;
|
|
49
|
+
return /* @__PURE__ */ u.createElement(c.Provider, { value: d.useNew() }, e);
|
|
50
|
+
}, P = (i) => {
|
|
51
|
+
const { children: e, id: t } = i, n = p(c), r = E(), s = b(!1);
|
|
52
|
+
return s.current || n.prepareChildren(t, r, e), v(() => (s.current = !0, n.setChildren(t, r, e), () => {
|
|
53
|
+
n.deleteChildren(t, r);
|
|
54
|
+
}), [e, t, r]), null;
|
|
55
|
+
}, y = (i) => {
|
|
56
|
+
const { children: e } = i;
|
|
51
57
|
return typeof e == "function" ? e() : e;
|
|
52
|
-
}, A = x((
|
|
53
|
-
const { children: e, id: t } =
|
|
54
|
-
return n ? n.map(([
|
|
58
|
+
}, A = x((i) => {
|
|
59
|
+
const { children: e, id: t } = i, n = p(c).getChildren(t);
|
|
60
|
+
return n ? n.map(([r, s]) => /* @__PURE__ */ u.createElement(y, { key: r }, s)) : e;
|
|
55
61
|
});
|
|
56
62
|
export {
|
|
57
63
|
P as TunnelEntry,
|
|
@@ -3,9 +3,11 @@ import { TunnelChildren } from './types';
|
|
|
3
3
|
|
|
4
4
|
export declare class TunnelState {
|
|
5
5
|
readonly children: ObservableMap<string, ObservableMap<string, TunnelChildren>>;
|
|
6
|
+
private readonly preparedChildren;
|
|
6
7
|
constructor();
|
|
7
8
|
static useNew(): TunnelState;
|
|
8
9
|
setChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
|
|
10
|
+
prepareChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
|
|
9
11
|
deleteChildren(tunnelId: string | undefined, entryId: string): void;
|
|
10
12
|
getChildren(tunnelId?: string): [string, TunnelChildren][] | undefined;
|
|
11
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/react-tunnel",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.117",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "It's like a Portal – but with React components",
|
|
6
6
|
"keywords": [
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"react": "^18.2.0",
|
|
58
58
|
"react-dom": "^18.2.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "c61520c0afb82b14362f61743df779f05b62fdba"
|
|
61
61
|
}
|