@mittwald/react-tunnel 0.2.0-alpha.806 → 0.2.0-alpha.808

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 CHANGED
@@ -4,8 +4,8 @@ import { jsx as m } from "react/jsx-runtime";
4
4
  import { useState as T, useRef as c, createContext as g, useContext as p, useId as E, useEffect as C } from "react";
5
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 u = "default";
8
- class h {
7
+ const d = "default";
8
+ class o {
9
9
  id;
10
10
  children = x.map(
11
11
  {},
@@ -18,7 +18,7 @@ class h {
18
18
  nextIndex = 0;
19
19
  constructor(e = {}) {
20
20
  const { parentTunnelState: t, id: n } = e;
21
- this.parentTunnelState = t, this.id = n ?? u, b(this, {
21
+ this.parentTunnelState = t, this.id = n ?? d, b(this, {
22
22
  id: !1,
23
23
  parentTunnelState: !1,
24
24
  deleteChildren: S.bound,
@@ -26,7 +26,7 @@ class h {
26
26
  });
27
27
  }
28
28
  static useNew(e) {
29
- const t = T(() => new h(e))[0];
29
+ const t = T(() => new o(e))[0];
30
30
  return t.resetIndex(), t;
31
31
  }
32
32
  resetIndex() {
@@ -36,53 +36,59 @@ class h {
36
36
  const e = c(this), t = c(null);
37
37
  return (t.current === null || e.current !== this) && (e.current = this, t.current = this.nextIndex++), t.current;
38
38
  }
39
- setChildren(e = u, t, n, r, s) {
40
- if (s)
39
+ setChildren(e = d, t, n, r, s, i = !0) {
40
+ if (i)
41
41
  return this.getTunnelState(s)?.setChildren(
42
42
  e,
43
43
  t,
44
44
  n,
45
- r
45
+ r,
46
+ s,
47
+ !1
46
48
  );
47
49
  const l = {
48
50
  id: t,
49
51
  index: n,
50
52
  children: r
51
- }, i = this.children.get(e) ?? x.map({}, { deep: !1 });
52
- i.set(t, l), this.preparedChildren.get(e)?.delete(t), this.children.set(e, i);
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);
53
55
  }
54
- getTunnelState(e) {
56
+ getTunnelState(e = d) {
55
57
  if (e === this.id)
56
58
  return this;
57
59
  if (this.parentTunnelState)
58
60
  return this.parentTunnelState.getTunnelState(e);
59
61
  }
60
- prepareChildren(e = u, t, n, r, s) {
61
- if (s)
62
+ prepareChildren(e = d, t, n, r, s, i = !0) {
63
+ if (i)
62
64
  return this.getTunnelState(s)?.prepareChildren(
63
65
  e,
64
66
  t,
65
67
  n,
66
- r
68
+ r,
69
+ s,
70
+ !1
67
71
  );
68
72
  const l = {
69
73
  id: t,
70
74
  index: n,
71
75
  children: r
72
- }, i = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
73
- i.set(t, l), this.preparedChildren.set(e, i);
76
+ }, a = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
77
+ a.set(t, l), this.preparedChildren.set(e, a);
74
78
  }
75
- deleteChildrenFromMap(e, t, n, r) {
76
- if (r)
79
+ deleteChildrenFromMap(e, t, n, r, s = !0) {
80
+ if (s)
77
81
  return this.getTunnelState(r)?.deleteChildrenFromMap(
78
82
  e,
79
83
  t,
80
- n
84
+ n,
85
+ r,
86
+ !1
81
87
  );
82
- const s = e.get(t);
83
- s?.delete(n), s?.size === 0 && e.delete(t);
88
+ const i = e.get(t);
89
+ i?.delete(n), i?.size === 0 && e.delete(t);
84
90
  }
85
- deleteChildren(e = u, t, n) {
91
+ deleteChildren(e = d, t, n) {
86
92
  this.deleteChildrenFromMap(this.children, e, t, n), this.deleteChildrenFromMap(
87
93
  this.preparedChildren,
88
94
  e,
@@ -90,37 +96,41 @@ class h {
90
96
  n
91
97
  );
92
98
  }
93
- getEntries(e = u, t) {
94
- if (t)
95
- return this.getTunnelState(t)?.getEntries(e);
96
- const n = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
99
+ getEntries(e = d, t, n = !0) {
97
100
  if (n)
98
- return Array.from(n).sort(
99
- (r, s) => r.index - s.index
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
100
110
  );
101
111
  }
102
112
  }
103
- const d = g(new h()), N = (a) => {
104
- const { children: e, id: t } = a, n = p(d);
113
+ const h = g(new o()), N = (u) => {
114
+ const { children: e, id: t } = u, n = p(h);
105
115
  return /* @__PURE__ */ m(
106
- d.Provider,
116
+ h.Provider,
107
117
  {
108
- value: h.useNew({ id: t, parentTunnelState: n }),
118
+ value: o.useNew({ id: t, parentTunnelState: n }),
109
119
  children: e
110
120
  }
111
121
  );
112
- }, P = (a) => {
113
- const { children: e, id: t, staticEntryId: n, providerId: r } = a, s = p(d), l = E(), i = n ?? l, o = s.useEntryIndex(), f = c(!1);
114
- return f.current || s.prepareChildren(t, i, o, e, r), C(() => {
115
- f.current = !0, s.setChildren(t, i, o, e, r);
116
- }, [e, t, i, o, r]), C(() => () => {
117
- s.deleteChildren(t, i, r);
118
- }, [t, i, r]), null;
119
- }, M = (a) => {
120
- const { children: e } = a;
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;
121
131
  return typeof e == "function" ? e() : e;
122
- }, j = w((a) => {
123
- const { children: e, id: t, providerId: n } = a, r = p(d).getEntries(t, n), s = r ? r.map((l) => /* @__PURE__ */ m(M, { children: l.children }, l.id)) : null;
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;
124
134
  return typeof e == "function" ? e(s) : s ?? e;
125
135
  });
126
136
  export {
@@ -20,12 +20,12 @@ export declare class TunnelState {
20
20
  static useNew(options?: TunnelStateOptions): TunnelState;
21
21
  resetIndex(): void;
22
22
  useEntryIndex(): number;
23
- setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string): void;
23
+ setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string, recurse?: boolean): void;
24
24
  private getTunnelState;
25
- prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string): void;
25
+ prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string, recurse?: boolean): void;
26
26
  private deleteChildrenFromMap;
27
27
  deleteChildren(tunnelId: string | undefined, entryId: string, providerId?: string): void;
28
- getEntries(tunnelId?: string, providerId?: string): TunnelEntryState[] | undefined;
28
+ getEntries(tunnelId?: string, providerId?: string, recurse?: boolean): TunnelEntryState[] | undefined;
29
29
  }
30
30
  export {};
31
31
  //# 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;AAK1C,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,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,CAAC,EA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HANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.806",
3
+ "version": "0.2.0-alpha.808",
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": "454c151128421fa2e2a37d7328021a58f5e3b656"
62
+ "gitHead": "f1c927b10fcbfa6934ee1213ccaa00ac5784b1b7"
63
63
  }