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

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
@@ -1,86 +1,130 @@
1
1
  "use client"
2
2
  /* */
3
- import { jsx as x } from "react/jsx-runtime";
4
- import { useState as E, useRef as h, createContext as g, useContext as m, useId as v, useEffect as p } from "react";
5
- import { observable as f, makeObservable as b, action as C } from "mobx";
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 l = "default";
8
- class o {
9
- children = f.map(
7
+ const u = "default";
8
+ class h {
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
- b(this, {
19
- deleteChildren: C.bound,
20
- setChildren: C.bound
19
+ constructor(e = {}) {
20
+ const { parentTunnelState: t, id: n } = e;
21
+ this.parentTunnelState = t, this.id = n ?? u, 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 e = E(() => new o())[0];
25
- return e.resetIndex(), e;
28
+ static useNew(e) {
29
+ const t = T(() => new h(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 = h(this), t = h(null);
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 = l, t, r, n) {
35
- const i = {
39
+ setChildren(e = u, t, n, r, s) {
40
+ if (s)
41
+ return this.getTunnelState(s)?.setChildren(
42
+ e,
43
+ t,
44
+ n,
45
+ r
46
+ );
47
+ const l = {
36
48
  id: t,
37
- index: r,
38
- children: n
39
- }, s = this.children.get(e) ?? f.map({}, { deep: !1 });
40
- s.set(t, i), this.preparedChildren.get(e)?.delete(t), this.children.set(e, s);
49
+ index: n,
50
+ 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
+ }
54
+ getTunnelState(e) {
55
+ if (e === this.id)
56
+ return this;
57
+ if (this.parentTunnelState)
58
+ return this.parentTunnelState.getTunnelState(e);
41
59
  }
42
- prepareChildren(e = l, t, r, n) {
43
- const i = {
60
+ prepareChildren(e = u, t, n, r, s) {
61
+ if (s)
62
+ return this.getTunnelState(s)?.prepareChildren(
63
+ e,
64
+ t,
65
+ n,
66
+ r
67
+ );
68
+ const l = {
44
69
  id: t,
45
- index: r,
46
- children: n
47
- }, s = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
48
- s.set(t, i), this.preparedChildren.set(e, s);
70
+ index: n,
71
+ children: r
72
+ }, i = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
73
+ i.set(t, l), this.preparedChildren.set(e, i);
49
74
  }
50
- deleteChildrenFromMap(e, t, r) {
51
- const n = e.get(t);
52
- n?.delete(r), n?.size === 0 && e.delete(t);
75
+ deleteChildrenFromMap(e, t, n, r) {
76
+ if (r)
77
+ return this.getTunnelState(r)?.deleteChildrenFromMap(
78
+ e,
79
+ t,
80
+ n
81
+ );
82
+ const s = e.get(t);
83
+ s?.delete(n), s?.size === 0 && e.delete(t);
53
84
  }
54
- deleteChildren(e = l, t) {
55
- this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
85
+ deleteChildren(e = u, t, n) {
86
+ this.deleteChildrenFromMap(this.children, e, t, n), this.deleteChildrenFromMap(
87
+ this.preparedChildren,
88
+ e,
89
+ t,
90
+ n
91
+ );
56
92
  }
57
- getEntries(e = l) {
58
- const t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
93
+ getEntries(e = u, t) {
59
94
  if (t)
60
- return Array.from(t).sort(
61
- (r, n) => r.index - n.index
95
+ return this.getTunnelState(t)?.getEntries(e);
96
+ const n = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
97
+ if (n)
98
+ return Array.from(n).sort(
99
+ (r, s) => r.index - s.index
62
100
  );
63
101
  }
64
102
  }
65
- const u = g(new o()), I = (d) => {
66
- const { children: e } = d;
67
- return /* @__PURE__ */ x(u.Provider, { value: o.useNew(), children: e });
68
- }, R = (d) => {
69
- const { children: e, id: t, staticEntryId: r } = d, n = m(u), i = v(), s = r ?? i, c = n.useEntryIndex(), a = h(!1);
70
- return a.current || n.prepareChildren(t, s, c, e), p(() => {
71
- a.current = !0, n.setChildren(t, s, c, e);
72
- }, [e, t, s, c]), p(() => () => {
73
- n.deleteChildren(t, s);
74
- }, [t, s]), null;
75
- }, y = (d) => {
76
- const { children: e } = d;
103
+ const d = g(new h()), N = (a) => {
104
+ const { children: e, id: t } = a, n = p(d);
105
+ return /* @__PURE__ */ m(
106
+ d.Provider,
107
+ {
108
+ value: h.useNew({ id: t, parentTunnelState: n }),
109
+ children: e
110
+ }
111
+ );
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;
77
121
  return typeof e == "function" ? e() : e;
78
- }, N = w((d) => {
79
- const { children: e, id: t } = d, r = m(u).getEntries(t), n = r ? r.map((i) => /* @__PURE__ */ x(y, { children: i.children }, i.id)) : null;
80
- return typeof e == "function" ? e(n) : n ?? 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;
124
+ return typeof e == "function" ? e(s) : s ?? e;
81
125
  });
82
126
  export {
83
- R as TunnelEntry,
84
- N as TunnelExit,
85
- I as TunnelProvider
127
+ P as TunnelEntry,
128
+ j as TunnelExit,
129
+ N as TunnelProvider
86
130
  };
@@ -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
- prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
23
+ setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string): void;
24
+ private getTunnelState;
25
+ prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren, providerId?: string): 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): 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":[],"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,qBAAa,WAAW;IACtB,SAAgB,QAAQ,iEAQtB;IAEF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG7B;IAEJ,OAAO,CAAC,SAAS,CAAK;;WASR,MAAM,IAAI,WAAW;IAM5B,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
+ {"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,a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AC,EAAE,MAAM,GAClB,gBAAgB,EAAE,GAAG,SAAS;CAclC"}
@@ -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;CACxB;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CA+B5C,CAAC;AAEF,eAAe,WAAW,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 declare const TunnelProvider: FC<PropsWithChildren>;
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,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAQhD,CAAC;AAEF,eAAe,cAAc,CAAC"}
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.804",
3
+ "version": "0.2.0-alpha.806",
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": "5d4495cc3bec4f235549b96c6b50ff9865efb427"
62
+ "gitHead": "454c151128421fa2e2a37d7328021a58f5e3b656"
63
63
  }