@mittwald/react-tunnel 0.2.0-alpha.816 → 0.2.0-alpha.818

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,109 +1,97 @@
1
1
  "use client"
2
2
  /* */
3
- import { jsx as m } from "react/jsx-runtime";
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 {
3
+ import { jsx as p } from "react/jsx-runtime";
4
+ import { useState as v, useRef as E, createContext as w, useContext as C, useId as y, useLayoutEffect as h } from "react";
5
+ import { observable as f, makeObservable as b, action as x } from "mobx";
6
+ import { observer as T } from "mobx-react-lite";
7
+ const u = "default", m = "default";
8
+ class l {
9
9
  id;
10
- children = C.map(
10
+ children = f.map(
11
11
  {},
12
12
  {
13
13
  deep: !1
14
14
  }
15
15
  );
16
- preparedChildren = /* @__PURE__ */ new Map();
17
16
  nextIndex = 0;
18
- constructor(e = E) {
19
- this.id = e, T(this, {
17
+ constructor(e = m) {
18
+ this.id = e, b(this, {
20
19
  id: !1,
21
20
  deleteChildren: x.bound,
22
21
  setChildren: x.bound
23
22
  });
24
23
  }
25
24
  static useNew(e) {
26
- const t = g(() => new c(e))[0];
25
+ const t = v(() => new l(e))[0];
27
26
  return t.resetIndex(), t;
28
27
  }
29
28
  resetIndex() {
30
29
  this.nextIndex = 0;
31
30
  }
32
31
  useEntryIndex() {
33
- const e = h(this), t = h(null);
34
- return (t.current === null || e.current !== this) && (e.current = this, t.current = this.nextIndex++), t.current;
32
+ const e = E(null);
33
+ return e.current === null && (e.current = this.nextIndex++), e.current;
35
34
  }
36
- setChildren(e = o, t, r, n) {
37
- const s = {
35
+ setChildren(e = u, t, n, s) {
36
+ const i = {
38
37
  id: t,
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);
38
+ index: n,
39
+ children: s
40
+ }, d = this.children.get(e) ?? f.map({}, { deep: !1 });
41
+ d.set(t, i), this.children.set(e, d);
43
42
  }
44
- prepareChildren(e = o, t, r, n) {
45
- const s = {
46
- id: t,
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);
51
- }
52
- deleteChildrenFromMap(e, t, r) {
53
- const n = e.get(t);
54
- n?.delete(r), n?.size === 0 && e.delete(t);
55
- }
56
- deleteChildren(e = o, t) {
57
- this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
43
+ deleteChildren(e = u, t) {
44
+ const n = this.children.get(e);
45
+ n?.delete(t), n?.size === 0 && this.children.delete(e);
58
46
  }
59
- getEntries(e = o) {
60
- const t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
47
+ getEntries(e = u) {
48
+ const t = this.children.get(e)?.values();
61
49
  if (t)
62
50
  return Array.from(t).sort(
63
- (r, n) => r.index - n.index
51
+ (n, s) => n.index - s.index
64
52
  );
65
53
  }
66
54
  }
67
- const a = b({
68
- state: new c()
69
- }), w = (i = E) => {
70
- let e = v(a);
55
+ const c = w({
56
+ state: new l()
57
+ }), I = (r = m) => {
58
+ let e = C(c);
71
59
  for (; e; ) {
72
- if (e.state.id === i)
60
+ if (e.state.id === r)
73
61
  return e.state;
74
62
  e = e.parentContext;
75
63
  }
76
64
  throw new Error(
77
- `Could not get tunnel for provider ${i}. Please provider a TunnelProvider with this ID.`
65
+ `Could not get tunnel for provider ${r}. Please provider a TunnelProvider with this ID.`
78
66
  );
79
- }, N = (i) => {
80
- const { children: e, id: t } = i, r = v(a);
81
- return /* @__PURE__ */ m(
82
- a.Provider,
67
+ }, j = (r) => {
68
+ const { children: e, id: t } = r, n = C(c);
69
+ return /* @__PURE__ */ p(
70
+ c.Provider,
83
71
  {
84
72
  value: {
85
- state: c.useNew(t),
86
- parentContext: r
73
+ state: l.useNew(t),
74
+ parentContext: n
87
75
  },
88
76
  children: e
89
77
  }
90
78
  );
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;
79
+ }, k = (r) => {
80
+ const { children: e, id: t, staticEntryId: n, providerId: s } = r, i = I(s), d = y(), o = n ?? d, a = i.useEntryIndex();
81
+ return h(() => {
82
+ i.setChildren(t, o, a, e);
83
+ }, [e, t, o, a, s]), h(() => () => {
84
+ i.deleteChildren(t, o);
85
+ }, [t, o, s]), null;
86
+ }, g = (r) => {
87
+ const { children: e } = r;
100
88
  return typeof e == "function" ? e() : e;
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;
103
- return typeof e == "function" ? e(s) : s ?? e;
89
+ }, z = T((r) => {
90
+ const { children: e, id: t, providerId: n } = r, s = I(n).getEntries(t), i = s ? s.map((d) => /* @__PURE__ */ p(g, { children: d.children }, d.id)) : null;
91
+ return typeof e == "function" ? e(i) : i ?? e;
104
92
  });
105
93
  export {
106
- j as TunnelEntry,
107
- k as TunnelExit,
108
- N as TunnelProvider
94
+ k as TunnelEntry,
95
+ z as TunnelExit,
96
+ j as TunnelProvider
109
97
  };
@@ -10,15 +10,12 @@ interface TunnelEntryState {
10
10
  export declare class TunnelState {
11
11
  readonly id: string;
12
12
  readonly children: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
13
- private readonly preparedChildren;
14
13
  private nextIndex;
15
14
  constructor(id?: string);
16
15
  static useNew(id?: string): TunnelState;
17
16
  resetIndex(): void;
18
17
  useEntryIndex(): number;
19
18
  setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
20
- prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
21
- private deleteChildrenFromMap;
22
19
  deleteChildren(tunnelId: string | undefined, entryId: string): void;
23
20
  getEntries(tunnelId?: string): TunnelEntryState[] | undefined;
24
21
  }
@@ -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;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,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AAE,GAAG,SAAS;CAQlC"}
@@ -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;IACvB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;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,CAwB5C,CAAC;AAEF,eAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.816",
3
+ "version": "0.2.0-alpha.818",
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": "b851bd7d44d22771160d7a805eeb17d81f1678fc"
62
+ "gitHead": "16f2d94681685aa3ca97b55c3117b4be248fe2e0"
63
63
  }