@mittwald/react-tunnel 0.2.0-alpha.999 → 1.0.1

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,121 +1,102 @@
1
- "use client"
2
- /* */
3
- import { jsx as x } from "react/jsx-runtime";
4
- import { useId as P, useState as w, useRef as a, createContext as I, useContext as v, useLayoutEffect as g, useEffect as b } from "react";
5
- import { observable as m, makeObservable as y, action as p } from "mobx";
6
- import { observer as R } from "mobx-react-lite";
7
- const l = "default", u = "default";
8
- class c {
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 = u, t = u) {
20
- this.id = e, this.instanceId = t, y(this, {
21
- id: !1,
22
- deleteChildren: p.bound,
23
- setChildren: p.bound
24
- });
25
- }
26
- static useNew(e) {
27
- const t = P(), n = w(() => new c(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 = l, 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 = l, 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 = l, t) {
58
- this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
59
- }
60
- takeRenderPhaseChildren(e) {
61
- if (this.renderPhaseChildren.has(e)) {
62
- const t = this.renderPhaseChildren.get(e)?.values();
63
- return typeof window < "u" && this.renderPhaseChildren.delete(e), t;
64
- }
65
- }
66
- getEntries(e = l) {
67
- const t = this.takeRenderPhaseChildren(e), n = this.committedChildren.get(e)?.values(), r = n ?? t;
68
- if (r) {
69
- const s = !!n, i = Array.from(r).sort(
70
- (o, h) => o.index - h.index
71
- );
72
- return {
73
- committed: s,
74
- entries: i
75
- };
76
- }
77
- }
78
- }
79
- const C = I({
80
- state: new c()
81
- }), E = (d = u) => {
82
- let e = v(C);
83
- for (; e; ) {
84
- if (e.state.id === d)
85
- return e.state;
86
- e = e.parentContext;
87
- }
88
- throw new Error(
89
- `Could not get tunnel for provider ${d}. Please provider a TunnelProvider with this ID.`
90
- );
91
- }, N = (d) => {
92
- const { children: e, id: t } = d, n = v(C), r = c.useNew(t);
93
- return /* @__PURE__ */ x(
94
- C.Provider,
95
- {
96
- value: {
97
- state: r,
98
- parentContext: n
99
- },
100
- children: e
101
- }
102
- );
103
- }, j = (d) => {
104
- const { children: e, id: t, staticEntryId: n, providerId: r } = d, s = E(r), i = P(), o = n ?? i, h = s.useEntryIndex(), f = a(!1);
105
- return f.current || s.setRenderPhaseChildren(t, o, h, e), g(() => {
106
- f.current = !0, s.setChildren(t, o, h, e);
107
- }, [e, t, o, h, r]), b(() => () => {
108
- s.deleteChildren(t, o);
109
- }, [t, o, r]), null;
110
- }, T = (d) => {
111
- const { children: e } = d;
112
- return typeof e == "function" ? e() : e;
113
- }, z = R((d) => {
114
- const { children: e, id: t, providerId: n } = d, s = E(n).getEntries(t)?.entries.map((i) => /* @__PURE__ */ x(T, { children: i.children }, i.id));
115
- return typeof e == "function" ? e(s) : s ?? 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;
116
100
  });
117
- export {
118
- j as TunnelEntry,
119
- z as TunnelExit,
120
- N as TunnelProvider
121
- };
101
+ //#endregion
102
+ export { y as TunnelEntry, x as TunnelExit, v as TunnelProvider };
@@ -25,8 +25,7 @@ export declare class TunnelState {
25
25
  setRenderPhaseChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
26
26
  private deleteChildrenFromMap;
27
27
  deleteChildren(tunnelId: string | undefined, entryId: string): void;
28
- private takeRenderPhaseChildren;
29
- getEntries(tunnelId?: string): TunnelEntries | undefined;
28
+ getEntries(tunnelId?: string, useRenderPhaseFallback?: boolean): TunnelEntries | undefined;
30
29
  }
31
30
  export {};
32
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,EAA2B,MAAM,OAAO,CAAC;AAChE,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,UAAU,aAAa;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED,qBAAa,WAAW;IACtB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,UAAU,CAAS;IAE3B,SAAgB,iBAAiB,iEAQ/B;IAEF,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAGhC;IAEJ,OAAO,CAAC,SAAS,CAAK;gBAGpB,EAAE,SAA0B,EAC5B,UAAU,SAA0B;WAWxB,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW;IAOvC,UAAU;IAIV,aAAa;IAUb,WAAW,CAChB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAA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IV,aAAa;IAUb,WAAW,CAChB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,GACvB,IAAI;IAiBA,sBAAsB,CAC3B,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;IAcnE,UAAU,CACf,QAAQ,SAAY,EACpB,sBAAsB,UAAQ,GAC7B,aAAa,GAAG,SAAS;CAmB7B"}
@@ -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,GAC7B,SAAS,GAAG,SAAS,GAAG,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC;AAExD,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,EAAE,KAAK,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,CAazC,CAAC;AAEH,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAwB,MAAM,OAAO,CAAC;AAGtD,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,CAmBzC,CAAC;AAEH,eAAe,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.999",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -37,30 +37,28 @@
37
37
  "mobx-react-lite": "^4.1.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@mittwald/typescript-config": "workspace:*",
40
+ "@mittwald/flow-core": "1.0.1",
41
+ "@mittwald/typescript-config": "1.0.1",
41
42
  "@types/node": "^25.9.3",
42
43
  "@types/react": "^19.2",
43
44
  "@types/react-dom": "^19.2",
44
45
  "@vitejs/plugin-react": "5.2.0",
45
- "@vitest/browser-playwright": "^4.1.10",
46
- "@vitest/coverage-v8": "^4.1.10",
46
+ "@vitest/browser-playwright": "^4.1.11",
47
+ "@vitest/coverage-v8": "^4.1.11",
47
48
  "nx": "^22.7.5",
48
- "prettier": "^3.8.4",
49
- "react": "^19.2.0",
50
- "react-dom": "^19.2.0",
49
+ "react": "^19.2.8",
50
+ "react-dom": "^19.2.8",
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.2",
57
55
  "vite-plugin-externalize-deps": "^0.10.0",
58
- "vitest": "^4.1.10",
56
+ "vitest": "^4.1.11",
59
57
  "vitest-browser-react": "^2.2.0"
60
58
  },
61
59
  "peerDependencies": {
62
60
  "react": "^19.2.0",
63
61
  "react-dom": "^19.2.0"
64
62
  },
65
- "gitHead": "60ef879e4bf0e52d2279a7e62beaea535c3abbee"
63
+ "gitHead": "293f7e960fe087fa5110a7d1bc63e530492d9316"
66
64
  }