@mittwald/react-tunnel 0.2.0-alpha.867 → 0.2.0-alpha.869

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 +118 -106
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,109 +1,121 @@
1
1
  "use client"
2
2
  /* */
3
- import { createContext as e, useContext as t, useEffect as n, useId as r, useLayoutEffect as i, useRef as a, useState as o } from "react";
4
- import { action as s, makeObservable as c, observable as l } from "mobx";
5
- import { jsx as u } from "react/jsx-runtime";
6
- import { observer as d } from "mobx-react-lite";
7
- //#region src/TunnelState.ts
8
- var f = "default", p = "default", m = class e {
9
- id;
10
- instanceId;
11
- committedChildren = l.map({}, { deep: !1 });
12
- renderPhaseChildren = /* @__PURE__ */ new Map();
13
- nextIndex = 0;
14
- constructor(e = p, t = p) {
15
- this.id = e, this.instanceId = t, c(this, {
16
- id: !1,
17
- deleteChildren: s.bound,
18
- setChildren: s.bound
19
- });
20
- }
21
- static useNew(t) {
22
- let n = r(), i = o(() => new e(t, n))[0];
23
- return i.resetIndex(), i;
24
- }
25
- resetIndex() {
26
- this.nextIndex = 0;
27
- }
28
- useEntryIndex() {
29
- let e = a(this.instanceId), t = a(null);
30
- return (t.current === null || e.current !== this.instanceId) && (e.current = this.instanceId, t.current = this.nextIndex++), t.current;
31
- }
32
- setChildren(e = f, t, n, r) {
33
- let i = {
34
- id: t,
35
- index: n,
36
- children: r
37
- }, a = this.committedChildren.get(e) ?? l.map({}, { deep: !1 });
38
- a.set(t, i), this.renderPhaseChildren.get(e)?.delete(t), this.committedChildren.set(e, a);
39
- }
40
- setRenderPhaseChildren(e = f, t, n, r) {
41
- let i = {
42
- id: t,
43
- index: n,
44
- children: r
45
- }, a = this.renderPhaseChildren.get(e) ?? /* @__PURE__ */ new Map();
46
- a.set(t, i), this.renderPhaseChildren.set(e, a);
47
- }
48
- deleteChildrenFromMap(e, t, n) {
49
- let r = e.get(t);
50
- r?.delete(n), r?.size === 0 && e.delete(t);
51
- }
52
- deleteChildren(e = f, t) {
53
- this.deleteChildrenFromMap(this.committedChildren, e, t), this.deleteChildrenFromMap(this.renderPhaseChildren, e, t);
54
- }
55
- takeRenderPhaseChildren(e) {
56
- if (this.renderPhaseChildren.has(e)) {
57
- let t = this.renderPhaseChildren.get(e)?.values();
58
- return typeof window < "u" && this.renderPhaseChildren.delete(e), t;
59
- }
60
- }
61
- getEntries(e = f) {
62
- let t = this.takeRenderPhaseChildren(e), n = this.committedChildren.get(e)?.values(), r = n ?? t;
63
- if (r) return {
64
- committed: !!n,
65
- entries: Array.from(r).sort((e, t) => e.index - t.index)
66
- };
67
- }
68
- }, h = e({ state: new m() }), g = (e = p) => {
69
- let n = t(h);
70
- for (; n;) {
71
- if (n.state.id === e) return n.state;
72
- n = n.parentContext;
73
- }
74
- throw Error(`Could not get tunnel for provider ${e}. Please provider a TunnelProvider with this ID.`);
75
- }, _ = (e) => {
76
- let { children: n, id: r } = e, i = t(h), a = m.useNew(r);
77
- return /* @__PURE__ */ u(h.Provider, {
78
- value: {
79
- state: a,
80
- parentContext: i
81
- },
82
- children: n
83
- });
84
- }, v = (e) => {
85
- let { children: t, id: o, staticEntryId: s, providerId: c } = e, l = g(c), u = r(), d = s ?? u, f = l.useEntryIndex(), p = a(!1);
86
- return p.current || l.setRenderPhaseChildren(o, d, f, t), i(() => {
87
- p.current = !0, l.setChildren(o, d, f, t);
88
- }, [
89
- t,
90
- o,
91
- d,
92
- f,
93
- c
94
- ]), n(() => () => {
95
- l.deleteChildren(o, d);
96
- }, [
97
- o,
98
- d,
99
- c
100
- ]), null;
101
- }, y = (e) => {
102
- let { children: t } = e;
103
- return typeof t == "function" ? t() : t;
104
- }, b = d((e) => {
105
- let { children: t, id: n, providerId: r } = e, i = g(r).getEntries(n)?.entries.map((e) => /* @__PURE__ */ u(y, { children: e.children }, e.id));
106
- return typeof t == "function" ? t(i) : i ?? t;
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;
107
116
  });
108
- //#endregion
109
- export { v as TunnelEntry, b as TunnelExit, _ as TunnelProvider };
117
+ export {
118
+ j as TunnelEntry,
119
+ z as TunnelExit,
120
+ N as TunnelProvider
121
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.867",
3
+ "version": "0.2.0-alpha.869",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -38,7 +38,7 @@
38
38
  "@types/node": "^25.9.3",
39
39
  "@types/react": "^19.2",
40
40
  "@types/react-dom": "^19.2",
41
- "@vitejs/plugin-react": "^6.0.2",
41
+ "@vitejs/plugin-react": "5.2.0",
42
42
  "@vitest/browser-playwright": "^4.1.9",
43
43
  "@vitest/coverage-v8": "^4.1.9",
44
44
  "nx": "^22.7.5",
@@ -47,7 +47,7 @@
47
47
  "react-dom": "^19.2.0",
48
48
  "rimraf": "^6.1.3",
49
49
  "typescript": "^6.0.3",
50
- "vite": "^8.0.16",
50
+ "vite": "7.3.5",
51
51
  "vite-plugin-banner": "^0.8.1",
52
52
  "vite-plugin-checker": "^0.14.1",
53
53
  "vite-plugin-dts": "^5.0.2",
@@ -59,5 +59,5 @@
59
59
  "react": "^19.2.0",
60
60
  "react-dom": "^19.2.0"
61
61
  },
62
- "gitHead": "d528599de15d6c9d5e93ff4c7fd4034bf2d7d87d"
62
+ "gitHead": "9bcd013dc5744a62ce98a00795a67dfd259b0ce4"
63
63
  }