@mittwald/react-tunnel 0.2.0-alpha.819 → 0.2.0-alpha.820

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,97 +1,125 @@
1
1
  "use client"
2
2
  /* */
3
- import { jsx as x } from "react/jsx-runtime";
4
- import { useState as I, useRef as v, createContext as E, useContext as p, useId as w, useLayoutEffect as y, useEffect as b } from "react";
5
- import { observable as h, makeObservable as T, action as f } from "mobx";
6
- import { observer as g } from "mobx-react-lite";
7
- const u = "default", C = "default";
3
+ import { jsx as P } from "react/jsx-runtime";
4
+ import { useId as v, useState as E, useRef as a, createContext as g, useContext as I, useEffect as f, useLayoutEffect as R } from "react";
5
+ import { observable as p, makeObservable as T, action as x } from "mobx";
6
+ import { observer as b } from "mobx-react-lite";
7
+ const h = "default", u = "default";
8
8
  class l {
9
9
  id;
10
- children = h.map(
10
+ instanceId;
11
+ committedChildren = p.map(
11
12
  {},
12
13
  {
13
14
  deep: !1
14
15
  }
15
16
  );
17
+ renderPhaseChildren = /* @__PURE__ */ new Map();
16
18
  nextIndex = 0;
17
- constructor(e = C) {
18
- this.id = e, T(this, {
19
+ constructor(e = u, t = u) {
20
+ this.id = e, this.instanceId = t, T(this, {
19
21
  id: !1,
20
- deleteChildren: f.bound,
21
- setChildren: f.bound
22
+ deleteChildren: x.bound,
23
+ setChildren: x.bound
22
24
  });
23
25
  }
24
26
  static useNew(e) {
25
- const t = I(() => new l(e))[0];
26
- return t.resetIndex(), t;
27
+ const t = v(), r = E(() => new l(e, t))[0];
28
+ return r.resetIndex(), r;
27
29
  }
28
30
  resetIndex() {
29
31
  this.nextIndex = 0;
30
32
  }
31
33
  useEntryIndex() {
32
- const e = v(null);
33
- return e.current === null && (e.current = this.nextIndex++), e.current;
34
+ const e = a(this.instanceId), t = a(null);
35
+ return (t.current === null || e.current !== this.instanceId) && (e.current = this.instanceId, t.current = this.nextIndex++), t.current;
34
36
  }
35
- setChildren(e = u, t, n, s) {
36
- const i = {
37
+ setChildren(e = h, t, r, n) {
38
+ const s = {
37
39
  id: t,
38
- index: n,
39
- children: s
40
- }, d = this.children.get(e) ?? h.map({}, { deep: !1 });
41
- d.set(t, i), this.children.set(e, d);
40
+ index: r,
41
+ children: n
42
+ }, i = this.committedChildren.get(e) ?? p.map({}, { deep: !1 });
43
+ i.set(t, s), this.renderPhaseChildren.get(e)?.delete(t), this.committedChildren.set(e, i);
42
44
  }
43
- deleteChildren(e = u, t) {
44
- const n = this.children.get(e);
45
- n?.delete(t), n?.size === 0 && this.children.delete(e);
45
+ setRenderPhaseChildren(e = h, t, r, n) {
46
+ const s = {
47
+ id: t,
48
+ index: r,
49
+ children: n
50
+ }, i = this.renderPhaseChildren.get(e) ?? /* @__PURE__ */ new Map();
51
+ i.set(t, s), this.renderPhaseChildren.set(e, i);
52
+ }
53
+ deleteChildrenFromMap(e, t, r) {
54
+ const n = e.get(t);
55
+ n?.delete(r), n?.size === 0 && e.delete(t);
56
+ }
57
+ deleteChildren(e = h, t) {
58
+ this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
46
59
  }
47
- getEntries(e = u) {
48
- const t = this.children.get(e)?.values();
49
- if (t)
50
- return Array.from(t).sort(
51
- (n, s) => n.index - s.index
60
+ takeRenderPhaseChildren(e) {
61
+ if (this.renderPhaseChildren.has(e)) {
62
+ const t = this.renderPhaseChildren.get(e)?.values();
63
+ return this.renderPhaseChildren.delete(e), t;
64
+ }
65
+ }
66
+ getEntries(e = h) {
67
+ const t = this.committedChildren.get(e)?.values(), r = t ?? this.takeRenderPhaseChildren(e);
68
+ if (r) {
69
+ const n = !!t, s = Array.from(r).sort(
70
+ (i, d) => i.index - d.index
52
71
  );
72
+ return {
73
+ committed: n,
74
+ entries: s
75
+ };
76
+ }
53
77
  }
54
78
  }
55
- const c = E({
79
+ const C = g({
56
80
  state: new l()
57
- }), m = (r = C) => {
58
- let e = p(c);
81
+ }), w = (o = u) => {
82
+ let e = I(C);
59
83
  for (; e; ) {
60
- if (e.state.id === r)
84
+ if (e.state.id === o)
61
85
  return e.state;
62
86
  e = e.parentContext;
63
87
  }
64
88
  throw new Error(
65
- `Could not get tunnel for provider ${r}. Please provider a TunnelProvider with this ID.`
89
+ `Could not get tunnel for provider ${o}. Please provider a TunnelProvider with this ID.`
66
90
  );
67
- }, k = (r) => {
68
- const { children: e, id: t } = r, n = p(c);
69
- return /* @__PURE__ */ x(
70
- c.Provider,
91
+ }, N = (o) => {
92
+ const { children: e, id: t } = o, r = I(C), n = l.useNew(t);
93
+ return /* @__PURE__ */ P(
94
+ C.Provider,
71
95
  {
72
96
  value: {
73
- state: l.useNew(t),
74
- parentContext: n
97
+ state: n,
98
+ parentContext: r
75
99
  },
76
100
  children: e
77
101
  }
78
102
  );
79
- }, z = (r) => {
80
- const { children: e, id: t, staticEntryId: n, providerId: s } = r, i = m(s), d = w(), o = n ?? d, a = i.useEntryIndex();
81
- return y(() => {
82
- i.setChildren(t, o, a, e);
83
- }, [e, t, o, a, s]), b(() => () => {
84
- i.deleteChildren(t, o);
85
- }, [t, o, s]), null;
86
- }, P = (r) => {
87
- const { children: e } = r;
103
+ }, j = (o) => {
104
+ const { children: e, id: t, staticEntryId: r, providerId: n } = o, s = w(n), i = v(), d = r ?? i, c = s.useEntryIndex(), m = a(!1);
105
+ return m.current || s.setRenderPhaseChildren(t, d, c, e), f(() => {
106
+ m.current = !0, s.setChildren(t, d, c, e);
107
+ }, [e, t, d, c, n]), f(() => () => {
108
+ s.deleteChildren(t, d);
109
+ }, [t, d, n]), null;
110
+ }, y = (o) => {
111
+ const { children: e } = o;
88
112
  return typeof e == "function" ? e() : e;
89
- }, A = g((r) => {
90
- const { children: e, id: t, providerId: n } = r, s = m(n).getEntries(t), i = s ? s.map((d) => /* @__PURE__ */ x(P, { children: d.children }, d.id)) : null;
113
+ }, z = b((o) => {
114
+ const { children: e, id: t, providerId: r } = o, n = w(r).getEntries(t), [, s] = E(0);
115
+ R(() => {
116
+ n && !n.committed && s((d) => d + 1);
117
+ }, [n?.committed]);
118
+ const i = n?.entries.map((d) => /* @__PURE__ */ P(y, { children: d.children }, d.id));
91
119
  return typeof e == "function" ? e(i) : i ?? e;
92
120
  });
93
121
  export {
94
- z as TunnelEntry,
95
- A as TunnelExit,
96
- k as TunnelProvider
122
+ j as TunnelEntry,
123
+ z as TunnelExit,
124
+ N as TunnelProvider
97
125
  };
@@ -7,17 +7,26 @@ interface TunnelEntryState {
7
7
  id: string;
8
8
  children: TunnelChildren;
9
9
  }
10
+ interface TunnelEntries {
11
+ committed: boolean;
12
+ entries: TunnelEntryState[];
13
+ }
10
14
  export declare class TunnelState {
11
15
  readonly id: string;
12
- readonly children: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
16
+ private instanceId;
17
+ readonly committedChildren: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
18
+ private readonly renderPhaseChildren;
13
19
  private nextIndex;
14
- constructor(id?: string);
20
+ constructor(id?: string, instanceId?: string);
15
21
  static useNew(id?: string): TunnelState;
16
22
  resetIndex(): void;
17
23
  useEntryIndex(): number;
18
24
  setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
25
+ setRenderPhaseChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
26
+ private deleteChildrenFromMap;
19
27
  deleteChildren(tunnelId: string | undefined, entryId: string): void;
20
- getEntries(tunnelId?: string): TunnelEntryState[] | undefined;
28
+ private takeRenderPhaseChildren;
29
+ getEntries(tunnelId?: string): TunnelEntries | undefined;
21
30
  }
22
31
  export {};
23
32
  //# 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,EAA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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"}
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 +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;AAGhC,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
+ {"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAG3D,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,CAoBzC,CAAC;AAEH,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
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,CAelD,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,CAgBlD,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.819",
3
+ "version": "0.2.0-alpha.820",
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": "f475d198902ad9e857714633d6ce7900326d9125"
62
+ "gitHead": "a113b886bd95adb2482c1c9bf387a0d6158df5b5"
63
63
  }