@mittwald/react-tunnel 0.2.0-alpha.1031 → 0.2.0-alpha.1033

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.
Files changed (2) hide show
  1. package/dist/index.js +101 -127
  2. package/package.json +6 -8
package/dist/index.js CHANGED
@@ -1,128 +1,102 @@
1
- "use client"
2
- /* */
3
- import { jsx as p } from "react/jsx-runtime";
4
- import { useId as v, useState as P, useRef as a, createContext as w, useContext as E, useLayoutEffect as g, useEffect as S, useSyncExternalStore as b } from "react";
5
- import { observable as m, makeObservable as y, action as x } from "mobx";
6
- import { observer as T } from "mobx-react-lite";
7
- const h = "default", C = "default";
8
- class u {
9
- id;
10
- instanceId;
11
- committedChildren = m.map(
12
- {},
13
- {
14
- deep: !1
15
- }
16
- );
17
- renderPhaseChildren = /* @__PURE__ */ new Map();
18
- nextIndex = 0;
19
- constructor(e = C, t = C) {
20
- this.id = e, this.instanceId = t, y(this, {
21
- id: !1,
22
- deleteChildren: x.bound,
23
- setChildren: x.bound
24
- });
25
- }
26
- static useNew(e) {
27
- const t = v(), n = P(() => new u(e, t))[0];
28
- return n.resetIndex(), n;
29
- }
30
- resetIndex() {
31
- this.nextIndex = 0;
32
- }
33
- useEntryIndex() {
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;
36
- }
37
- setChildren(e = h, t, n, r) {
38
- const s = {
39
- id: t,
40
- index: n,
41
- children: r
42
- }, i = this.committedChildren.get(e) ?? m.map({}, { deep: !1 });
43
- i.set(t, s), this.renderPhaseChildren.get(e)?.delete(t), this.committedChildren.set(e, i);
44
- }
45
- setRenderPhaseChildren(e = h, t, n, r) {
46
- const s = {
47
- id: t,
48
- index: n,
49
- children: r
50
- }, i = this.renderPhaseChildren.get(e) ?? /* @__PURE__ */ new Map();
51
- i.set(t, s), this.renderPhaseChildren.set(e, i);
52
- }
53
- deleteChildrenFromMap(e, t, n) {
54
- const r = e.get(t);
55
- r?.delete(n), r?.size === 0 && e.delete(t);
56
- }
57
- deleteChildren(e = h, t) {
58
- this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
59
- }
60
- // Pure read — never mutate during render. `getEntries` runs inside the
61
- // (observer) `TunnelExit` render, and React 19 may invoke a render more than
62
- // once before committing (StrictMode double-invoke, concurrent re-render), so
63
- // a consume-on-read here broke SSR hydration. Render-phase children are only a
64
- // bridge for the server render and the first (pre-effect) client render; the
65
- // exit opts into them via `useRenderPhaseFallback` while `useIsSSR()` is true.
66
- // After hydration the committed children are authoritative — even when empty —
67
- // so an entry that never committed (suspended, then removed) leaves no stale
68
- // content behind.
69
- getEntries(e = h, t = !1) {
70
- const n = this.committedChildren.get(e)?.values(), r = t ? this.renderPhaseChildren.get(e)?.values() : void 0, s = n ?? r;
71
- if (s) {
72
- const i = !!n, o = Array.from(s).sort(
73
- (l, c) => l.index - c.index
74
- );
75
- return {
76
- committed: i,
77
- entries: o
78
- };
79
- }
80
- }
81
- }
82
- const f = w({
83
- state: new u()
84
- }), I = (d = C) => {
85
- let e = E(f);
86
- for (; e; ) {
87
- if (e.state.id === d)
88
- return e.state;
89
- e = e.parentContext;
90
- }
91
- throw new Error(
92
- `Could not get tunnel for provider ${d}. Please provider a TunnelProvider with this ID.`
93
- );
94
- }, k = (d) => {
95
- const { children: e, id: t } = d, n = E(f), r = u.useNew(t);
96
- return /* @__PURE__ */ p(
97
- f.Provider,
98
- {
99
- value: {
100
- state: r,
101
- parentContext: n
102
- },
103
- children: e
104
- }
105
- );
106
- }, z = (d) => {
107
- const { children: e, id: t, staticEntryId: n, providerId: r } = d, s = I(r), i = v(), o = n ?? i, l = s.useEntryIndex(), c = a(!1);
108
- return c.current || s.setRenderPhaseChildren(t, o, l, e), g(() => {
109
- c.current = !0, s.setChildren(t, o, l, e);
110
- }, [e, t, o, l, r]), S(() => () => {
111
- s.deleteChildren(t, o);
112
- }, [t, o, r]), null;
113
- }, M = (d) => {
114
- const { children: e } = d;
115
- return typeof e == "function" ? e() : e;
116
- }, A = T((d) => {
117
- const { children: e, id: t, providerId: n } = d, r = b(
118
- () => () => null,
119
- () => !1,
120
- () => !0
121
- ), i = I(n).getEntries(t, r)?.entries.map((o) => /* @__PURE__ */ p(M, { children: o.children }, o.id));
122
- return typeof e == "function" ? e(i) : i ?? e;
1
+
2
+ import { createContext as e, useContext as t, useEffect as n, useId as r, useLayoutEffect as i, useRef as a, useState as o, useSyncExternalStore as s } from "react";
3
+ import { action as c, makeObservable as l, observable as u } from "mobx";
4
+ import { jsx as d } from "react/jsx-runtime";
5
+ import { observer as f } from "mobx-react-lite";
6
+ //#region src/TunnelState.ts
7
+ var p = "default", m = "default", h = class e {
8
+ id;
9
+ instanceId;
10
+ committedChildren = u.map({}, { deep: !1 });
11
+ renderPhaseChildren = /* @__PURE__ */ new Map();
12
+ nextIndex = 0;
13
+ constructor(e = m, t = m) {
14
+ this.id = e, this.instanceId = t, l(this, {
15
+ id: !1,
16
+ deleteChildren: c.bound,
17
+ setChildren: c.bound
18
+ });
19
+ }
20
+ static useNew(t) {
21
+ let n = r(), i = o(() => new e(t, n))[0];
22
+ return i.resetIndex(), i;
23
+ }
24
+ resetIndex() {
25
+ this.nextIndex = 0;
26
+ }
27
+ useEntryIndex() {
28
+ let e = a(this.instanceId), t = a(null);
29
+ return (t.current === null || e.current !== this.instanceId) && (e.current = this.instanceId, t.current = this.nextIndex++), t.current;
30
+ }
31
+ setChildren(e = p, t, n, r) {
32
+ let i = {
33
+ id: t,
34
+ index: n,
35
+ children: r
36
+ }, a = this.committedChildren.get(e) ?? u.map({}, { deep: !1 });
37
+ a.set(t, i), this.renderPhaseChildren.get(e)?.delete(t), this.committedChildren.set(e, a);
38
+ }
39
+ setRenderPhaseChildren(e = p, t, n, r) {
40
+ let i = {
41
+ id: t,
42
+ index: n,
43
+ children: r
44
+ }, a = this.renderPhaseChildren.get(e) ?? /* @__PURE__ */ new Map();
45
+ a.set(t, i), this.renderPhaseChildren.set(e, a);
46
+ }
47
+ deleteChildrenFromMap(e, t, n) {
48
+ let r = e.get(t);
49
+ r?.delete(n), r?.size === 0 && e.delete(t);
50
+ }
51
+ deleteChildren(e = p, t) {
52
+ this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
53
+ }
54
+ getEntries(e = p, t = !1) {
55
+ let n = this.committedChildren.get(e)?.values(), r = t ? this.renderPhaseChildren.get(e)?.values() : void 0, i = n ?? r;
56
+ if (i) return {
57
+ committed: !!n,
58
+ entries: Array.from(i).sort((e, t) => e.index - t.index)
59
+ };
60
+ }
61
+ }, g = e({ state: new h() }), _ = (e = m) => {
62
+ let n = t(g);
63
+ for (; n;) {
64
+ if (n.state.id === e) return n.state;
65
+ n = n.parentContext;
66
+ }
67
+ throw Error(`Could not get tunnel for provider ${e}. Please provider a TunnelProvider with this ID.`);
68
+ }, v = (e) => {
69
+ let { children: n, id: r } = e, i = t(g), a = h.useNew(r);
70
+ return /* @__PURE__ */ d(g.Provider, {
71
+ value: {
72
+ state: a,
73
+ parentContext: i
74
+ },
75
+ children: n
76
+ });
77
+ }, y = (e) => {
78
+ let { children: t, id: o, staticEntryId: s, providerId: c } = e, l = _(c), u = r(), d = s ?? u, f = l.useEntryIndex(), p = a(!1);
79
+ return p.current || l.setRenderPhaseChildren(o, d, f, t), i(() => {
80
+ p.current = !0, l.setChildren(o, d, f, t);
81
+ }, [
82
+ t,
83
+ o,
84
+ d,
85
+ f,
86
+ c
87
+ ]), n(() => () => {
88
+ l.deleteChildren(o, d);
89
+ }, [
90
+ o,
91
+ d,
92
+ c
93
+ ]), null;
94
+ }, b = (e) => {
95
+ let { children: t } = e;
96
+ return typeof t == "function" ? t() : t;
97
+ }, x = f((e) => {
98
+ let { children: t, id: n, providerId: r } = e, i = s(() => () => null, () => !1, () => !0), a = _(r).getEntries(n, i)?.entries.map((e) => /* @__PURE__ */ d(b, { children: e.children }, e.id));
99
+ return typeof t == "function" ? t(a) : a ?? t;
123
100
  });
124
- export {
125
- z as TunnelEntry,
126
- A as TunnelExit,
127
- k as TunnelProvider
128
- };
101
+ //#endregion
102
+ export { y as TunnelEntry, x as TunnelExit, v as TunnelProvider };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.1031",
3
+ "version": "0.2.0-alpha.1033",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -37,7 +37,8 @@
37
37
  "mobx-react-lite": "^4.1.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@mittwald/typescript-config": "0.2.0-alpha.1031",
40
+ "@mittwald/flow-core": "0.2.0-alpha.1033",
41
+ "@mittwald/typescript-config": "0.2.0-alpha.1033",
41
42
  "@types/node": "^25.9.3",
42
43
  "@types/react": "^19.2",
43
44
  "@types/react-dom": "^19.2",
@@ -45,15 +46,12 @@
45
46
  "@vitest/browser-playwright": "^4.1.10",
46
47
  "@vitest/coverage-v8": "^4.1.10",
47
48
  "nx": "^22.7.5",
48
- "prettier": "^3.8.4",
49
49
  "react": "^19.2.0",
50
50
  "react-dom": "^19.2.0",
51
51
  "rimraf": "^6.1.3",
52
52
  "typescript": "^6.0.3",
53
- "vite": "7.3.6",
54
- "vite-plugin-banner": "^0.8.1",
55
- "vite-plugin-checker": "^0.14.1",
56
- "vite-plugin-dts": "^5.0.3",
53
+ "unplugin-dts": "^1.0.3",
54
+ "vite": "^8.2.1",
57
55
  "vite-plugin-externalize-deps": "^0.10.0",
58
56
  "vitest": "^4.1.10",
59
57
  "vitest-browser-react": "^2.2.0"
@@ -62,5 +60,5 @@
62
60
  "react": "^19.2.0",
63
61
  "react-dom": "^19.2.0"
64
62
  },
65
- "gitHead": "e0185604e6a31f89fba94a69d1499115a14897a0"
63
+ "gitHead": "1e93dee00797e8702e30c53c403f9a33029c9634"
66
64
  }