@mittwald/react-tunnel 0.2.0-alpha.783 → 0.2.0-alpha.785

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 +83 -79
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -1,82 +1,86 @@
1
1
  "use client"
2
2
  /* */
3
- import { createContext as e, useContext as t, useEffect as n, useId as r, useRef as i, useState as a } from "react";
4
- import { action as o, makeObservable as s, observable as c } from "mobx";
5
- import { jsx as l } from "react/jsx-runtime";
6
- import { observer as u } from "mobx-react-lite";
7
- //#region src/TunnelState.ts
8
- var d = "default", f = class e {
9
- children = c.map({}, { deep: !1 });
10
- preparedChildren = /* @__PURE__ */ new Map();
11
- nextIndex = 0;
12
- constructor() {
13
- s(this, {
14
- deleteChildren: o.bound,
15
- setChildren: o.bound
16
- });
17
- }
18
- static useNew() {
19
- let t = a(() => new e())[0];
20
- return t.resetIndex(), t;
21
- }
22
- resetIndex() {
23
- this.nextIndex = 0;
24
- }
25
- useEntryIndex() {
26
- let e = i(this), t = i(null);
27
- return (t.current === null || e.current !== this) && (e.current = this, t.current = this.nextIndex++), t.current;
28
- }
29
- setChildren(e = d, t, n, r) {
30
- let i = {
31
- id: t,
32
- index: n,
33
- children: r
34
- }, a = this.children.get(e) ?? c.map({}, { deep: !1 });
35
- a.set(t, i), this.preparedChildren.get(e)?.delete(t), this.children.set(e, a);
36
- }
37
- prepareChildren(e = d, t, n, r) {
38
- let i = {
39
- id: t,
40
- index: n,
41
- children: r
42
- }, a = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
43
- a.set(t, i), this.preparedChildren.set(e, a);
44
- }
45
- deleteChildrenFromMap(e, t, n) {
46
- let r = e.get(t);
47
- r?.delete(n), r?.size === 0 && e.delete(t);
48
- }
49
- deleteChildren(e = d, t) {
50
- this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
51
- }
52
- getEntries(e = d) {
53
- let t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
54
- if (t) return Array.from(t).sort((e, t) => e.index - t.index);
55
- }
56
- }, p = e(new f()), m = (e) => {
57
- let { children: t } = e;
58
- return /* @__PURE__ */ l(p.Provider, {
59
- value: f.useNew(),
60
- children: t
61
- });
62
- }, h = (e) => {
63
- let { children: a, id: o, staticEntryId: s } = e, c = t(p), l = r(), u = s ?? l, d = c.useEntryIndex(), f = i(!1);
64
- return f.current || c.prepareChildren(o, u, d, a), n(() => {
65
- f.current = !0, c.setChildren(o, u, d, a);
66
- }, [
67
- a,
68
- o,
69
- u,
70
- d
71
- ]), n(() => () => {
72
- c.deleteChildren(o, u);
73
- }, [o, u]), null;
74
- }, g = (e) => {
75
- let { children: t } = e;
76
- return typeof t == "function" ? t() : t;
77
- }, _ = u((e) => {
78
- let { children: n, id: r } = e, i = t(p).getEntries(r), a = i ? i.map((e) => /* @__PURE__ */ l(g, { children: e.children }, e.id)) : null;
79
- return typeof n == "function" ? n(a) : a ?? n;
3
+ import { jsx as x } from "react/jsx-runtime";
4
+ import { useState as E, useRef as h, createContext as g, useContext as m, useId as v, useEffect as p } from "react";
5
+ import { observable as f, makeObservable as b, action as C } from "mobx";
6
+ import { observer as w } from "mobx-react-lite";
7
+ const l = "default";
8
+ class o {
9
+ children = f.map(
10
+ {},
11
+ {
12
+ deep: !1
13
+ }
14
+ );
15
+ preparedChildren = /* @__PURE__ */ new Map();
16
+ nextIndex = 0;
17
+ constructor() {
18
+ b(this, {
19
+ deleteChildren: C.bound,
20
+ setChildren: C.bound
21
+ });
22
+ }
23
+ static useNew() {
24
+ const e = E(() => new o())[0];
25
+ return e.resetIndex(), e;
26
+ }
27
+ resetIndex() {
28
+ this.nextIndex = 0;
29
+ }
30
+ useEntryIndex() {
31
+ const e = h(this), t = h(null);
32
+ return (t.current === null || e.current !== this) && (e.current = this, t.current = this.nextIndex++), t.current;
33
+ }
34
+ setChildren(e = l, t, r, n) {
35
+ const i = {
36
+ id: t,
37
+ index: r,
38
+ children: n
39
+ }, s = this.children.get(e) ?? f.map({}, { deep: !1 });
40
+ s.set(t, i), this.preparedChildren.get(e)?.delete(t), this.children.set(e, s);
41
+ }
42
+ prepareChildren(e = l, t, r, n) {
43
+ const i = {
44
+ id: t,
45
+ index: r,
46
+ children: n
47
+ }, s = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
48
+ s.set(t, i), this.preparedChildren.set(e, s);
49
+ }
50
+ deleteChildrenFromMap(e, t, r) {
51
+ const n = e.get(t);
52
+ n?.delete(r), n?.size === 0 && e.delete(t);
53
+ }
54
+ deleteChildren(e = l, t) {
55
+ this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
56
+ }
57
+ getEntries(e = l) {
58
+ const t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
59
+ if (t)
60
+ return Array.from(t).sort(
61
+ (r, n) => r.index - n.index
62
+ );
63
+ }
64
+ }
65
+ const u = g(new o()), I = (d) => {
66
+ const { children: e } = d;
67
+ return /* @__PURE__ */ x(u.Provider, { value: o.useNew(), children: e });
68
+ }, R = (d) => {
69
+ const { children: e, id: t, staticEntryId: r } = d, n = m(u), i = v(), s = r ?? i, c = n.useEntryIndex(), a = h(!1);
70
+ return a.current || n.prepareChildren(t, s, c, e), p(() => {
71
+ a.current = !0, n.setChildren(t, s, c, e);
72
+ }, [e, t, s, c]), p(() => () => {
73
+ n.deleteChildren(t, s);
74
+ }, [t, s]), null;
75
+ }, y = (d) => {
76
+ const { children: e } = d;
77
+ return typeof e == "function" ? e() : e;
78
+ }, N = w((d) => {
79
+ const { children: e, id: t } = d, r = m(u).getEntries(t), n = r ? r.map((i) => /* @__PURE__ */ x(y, { children: i.children }, i.id)) : null;
80
+ return typeof e == "function" ? e(n) : n ?? e;
80
81
  });
81
- //#endregion
82
- export { h as TunnelEntry, _ as TunnelExit, m as TunnelProvider };
82
+ export {
83
+ R as TunnelEntry,
84
+ N as TunnelExit,
85
+ I as TunnelProvider
86
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.783",
3
+ "version": "0.2.0-alpha.785",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -38,26 +38,26 @@
38
38
  "@types/node": "^24.10.9",
39
39
  "@types/react": "^19.2",
40
40
  "@types/react-dom": "^19.2",
41
- "@vitejs/plugin-react": "^6.0.1",
42
- "@vitest/browser-playwright": "^4.1.3",
43
- "@vitest/coverage-v8": "^4.1.3",
41
+ "@vitejs/plugin-react": "^5.1.3",
42
+ "@vitest/browser-playwright": "^4.0.18",
43
+ "@vitest/coverage-v8": "^4.0.18",
44
44
  "nx": "^22.4.4",
45
45
  "prettier": "^3.8.1",
46
46
  "react": "^19.2.0",
47
47
  "react-dom": "^19.2.0",
48
48
  "rimraf": "^6.1.2",
49
49
  "typescript": "^5.9.3",
50
- "vite": "^8.0.8",
50
+ "vite": "^7.3.1",
51
51
  "vite-plugin-banner": "^0.8.1",
52
52
  "vite-plugin-checker": "^0.12.0",
53
53
  "vite-plugin-dts": "^4.5.4",
54
54
  "vite-plugin-externalize-deps": "^0.10.0",
55
- "vitest": "^4.1.3",
56
- "vitest-browser-react": "^2.2.0"
55
+ "vitest": "^4.0.18",
56
+ "vitest-browser-react": "^2.0.2"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": "^19.2.0",
60
60
  "react-dom": "^19.2.0"
61
61
  },
62
- "gitHead": "433184ac008344ac57082a1505fa6041b82e1bcc"
62
+ "gitHead": "1d5c6f9e7ca4758ab179250a39ee01ce6cbfa222"
63
63
  }