@mittwald/react-tunnel 0.1.0-alpha.99 → 0.2.0-alpha.4

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,60 +1,66 @@
1
1
  "use client"
2
2
  /* */
3
- var m = Object.defineProperty;
4
- var C = (r, e, t) => e in r ? m(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
5
- var d = (r, e, t) => (C(r, typeof e != "symbol" ? e + "" : e, t), t);
6
- import a, { useState as p, createContext as b, useContext as f, useId as E, useRef as v, useLayoutEffect as y } from "react";
7
- import { observable as u, makeObservable as g, action as h } from "mobx";
8
- import { observer as x } from "mobx-react-lite";
9
- const o = "default";
10
- class i {
3
+ var g = Object.defineProperty;
4
+ var E = (s, e, t) => e in s ? g(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
5
+ var o = (s, e, t) => E(s, typeof e != "symbol" ? e + "" : e, t);
6
+ import C, { useRef as f, createContext as b, useContext as m, useId as v, useEffect as w } from "react";
7
+ import { observable as a, makeObservable as x, action as p } from "mobx";
8
+ import { observer as y } from "mobx-react-lite";
9
+ const l = "default";
10
+ class c {
11
11
  constructor() {
12
- d(this, "children", u.map(
12
+ o(this, "children", a.map(
13
13
  {},
14
14
  {
15
15
  deep: !1
16
16
  }
17
17
  ));
18
- g(this, {
19
- deleteChildren: h.bound,
20
- setChildren: h.bound
18
+ o(this, "preparedChildren", /* @__PURE__ */ new Map());
19
+ x(this, {
20
+ deleteChildren: p.bound,
21
+ setChildren: p.bound
21
22
  });
22
23
  }
23
24
  static useNew() {
24
- return p(new i())[0];
25
+ return f(new c()).current;
25
26
  }
26
- setChildren(e = o, t, n) {
27
- const s = this.children.get(e) ?? u.map({}, { deep: !1 });
28
- s.set(t, n), this.children.set(e, s);
27
+ setChildren(e = l, t, n) {
28
+ var i;
29
+ const r = this.children.get(e) ?? a.map({}, { deep: !1 });
30
+ r.set(t, n), (i = this.preparedChildren.get(e)) == null || i.delete(t), this.children.set(e, r);
29
31
  }
30
- deleteChildren(e = o, t) {
31
- var n;
32
- (n = this.children.get(e)) == null || n.delete(t);
32
+ prepareChildren(e = l, t, n) {
33
+ const r = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
34
+ r.set(t, n), this.preparedChildren.set(e, r);
33
35
  }
34
- getChildren(e = o) {
35
- var n;
36
- const t = (n = this.children.get(e)) == null ? void 0 : n.entries();
36
+ deleteChildren(e = l, t) {
37
+ var n, r;
38
+ (n = this.children.get(e)) == null || n.delete(t), (r = this.preparedChildren.get(e)) == null || r.delete(t);
39
+ }
40
+ getChildren(e = l) {
41
+ var n, r;
42
+ const t = ((n = this.children.get(e)) == null ? void 0 : n.entries()) ?? ((r = this.preparedChildren.get(e)) == null ? void 0 : r.entries());
37
43
  if (t)
38
44
  return Array.from(t);
39
45
  }
40
46
  }
41
- const c = b(new i()), N = (r) => {
42
- const { children: e } = r;
43
- return /* @__PURE__ */ a.createElement(c.Provider, { value: i.useNew() }, e);
44
- }, P = (r) => {
45
- const { children: e, id: t } = r, n = f(c), s = E(), l = v(!1);
46
- return l.current || n.setChildren(t, s, e), y(() => (l.current = !0, n.setChildren(t, s, e), () => {
47
- n.deleteChildren(t, s);
48
- }), [e, t, s]), null;
49
- }, w = (r) => {
50
- const { children: e } = r;
47
+ const h = b(new c()), P = (s) => {
48
+ const { children: e } = s;
49
+ return /* @__PURE__ */ C.createElement(h.Provider, { value: c.useNew() }, e);
50
+ }, A = (s) => {
51
+ const { children: e, id: t, staticEntryId: n } = s, r = m(h), i = v(), d = n ?? i, u = f(!1);
52
+ return u.current || r.prepareChildren(t, d, e), w(() => (u.current = !0, r.setChildren(t, d, e), () => {
53
+ r.deleteChildren(t, d);
54
+ }), [e, t, d]), null;
55
+ }, R = (s) => {
56
+ const { children: e } = s;
51
57
  return typeof e == "function" ? e() : e;
52
- }, A = x((r) => {
53
- const { children: e, id: t } = r, n = f(c).getChildren(t);
54
- return n ? n.map(([s, l]) => /* @__PURE__ */ a.createElement(w, { key: s }, l)) : e;
58
+ }, O = y((s) => {
59
+ const { children: e, id: t } = s, n = m(h).getChildren(t);
60
+ return n ? n.map(([r, i]) => /* @__PURE__ */ C.createElement(R, { key: r }, i)) : e;
55
61
  });
56
62
  export {
57
- P as TunnelEntry,
58
- A as TunnelExit,
59
- N as TunnelProvider
63
+ A as TunnelEntry,
64
+ O as TunnelExit,
65
+ P as TunnelProvider
60
66
  };
@@ -1,11 +1,12 @@
1
- import { TunnelChildren } from './types';
2
1
  import { ObservableMap } from 'mobx';
3
-
2
+ import { TunnelChildren } from './types';
4
3
  export declare class TunnelState {
5
4
  readonly children: ObservableMap<string, ObservableMap<string, TunnelChildren>>;
5
+ private readonly preparedChildren;
6
6
  constructor();
7
7
  static useNew(): TunnelState;
8
8
  setChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
9
+ prepareChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
9
10
  deleteChildren(tunnelId: string | undefined, entryId: string): void;
10
- getChildren(tunnelId?: string): Array<[string, TunnelChildren]> | undefined;
11
+ getChildren(tunnelId?: string): [string, TunnelChildren][] | undefined;
11
12
  }
@@ -1,9 +1,10 @@
1
- import { TunnelChildren } from '../types';
2
1
  import { FC } from 'react';
3
-
2
+ import { TunnelChildren } from '../types';
4
3
  interface Props {
5
4
  id?: string;
6
5
  children?: TunnelChildren;
6
+ /** Static entry ID instead of generated ID by `useId` */
7
+ staticEntryId?: string;
7
8
  }
8
9
  export declare const TunnelEntry: FC<Props>;
9
10
  export default TunnelEntry;
@@ -1,5 +1,4 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
-
3
2
  interface Props extends PropsWithChildren {
4
3
  id?: string;
5
4
  }
@@ -1,4 +1,3 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
-
3
2
  export declare const TunnelProvider: FC<PropsWithChildren>;
4
3
  export default TunnelProvider;
@@ -1,4 +1,3 @@
1
1
  import { TunnelState } from './TunnelState';
2
-
3
2
  export declare const tunnelContext: import('react').Context<TunnelState>;
4
3
  export default tunnelContext;
@@ -1,3 +1,2 @@
1
1
  import { ReactNode } from 'react';
2
-
3
2
  export type TunnelChildren = ReactNode | undefined | (() => ReactNode | undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.1.0-alpha.99",
3
+ "version": "0.2.0-alpha.4",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -10,7 +10,7 @@
10
10
  "react tree",
11
11
  "teleport"
12
12
  ],
13
- "homepage": "https://mittwald.github.io/flow",
13
+ "homepage": "https://github.com/mittwald/flow/tree/main/packages/react-tunnel",
14
14
  "repository": "https://github.com/mittwald/flow",
15
15
  "exports": {
16
16
  ".": {
@@ -30,32 +30,33 @@
30
30
  "test:unit": "run vitest run"
31
31
  },
32
32
  "dependencies": {
33
- "mobx": "^6.12.3",
34
- "mobx-react-lite": "^4.0.7"
33
+ "mobx": "^6.13.5",
34
+ "mobx-react-lite": "^4.1.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@testing-library/react": "^15.0.6",
38
- "@types/node": "^20.12.8",
39
- "@types/react": "^18.3.1",
40
- "@types/react-dom": "^18.3.0",
41
- "@vitejs/plugin-react": "^4.2.1",
42
- "@vitest/coverage-v8": "^1.5.3",
43
- "happy-dom": "^14.7.1",
44
- "nx": "^18.3.4",
45
- "prettier": "^3.2.5",
46
- "react": "^18.3.1",
47
- "react-dom": "^18.3.1",
48
- "typescript": "^5.4.5",
49
- "vite": "^5.2.10",
50
- "vite-plugin-banner": "^0.7.1",
51
- "vite-plugin-checker": "^0.6.4",
52
- "vite-plugin-dts": "^3.9.0",
37
+ "@testing-library/dom": "^10.4.0",
38
+ "@testing-library/react": "^16.1.0",
39
+ "@types/node": "^22.10.5",
40
+ "@types/react": "^19.0.4",
41
+ "@types/react-dom": "^19.0.2",
42
+ "@vitejs/plugin-react": "^4.3.4",
43
+ "@vitest/coverage-v8": "^2.1.8",
44
+ "happy-dom": "^15.11.7",
45
+ "nx": "^20.3.1",
46
+ "prettier": "^3.4.2",
47
+ "react": "19.0.0",
48
+ "react-dom": "19.0.0",
49
+ "typescript": "^5.7.3",
50
+ "vite": "^5.4.11",
51
+ "vite-plugin-banner": "^0.8.0",
52
+ "vite-plugin-checker": "^0.8.0",
53
+ "vite-plugin-dts": "^4.4.0",
53
54
  "vite-plugin-externalize-deps": "^0.8.0",
54
- "vitest": "^1.5.3"
55
+ "vitest": "^2.1.8"
55
56
  },
56
57
  "peerDependencies": {
57
- "react": "^18.2.0",
58
- "react-dom": "^18.2.0"
58
+ "react": "^19.0.0",
59
+ "react-dom": "^19.0.0"
59
60
  },
60
- "gitHead": "81dfd5f1c9a4360327cf6fa2f8e375cb61cfc75f"
61
+ "gitHead": "24bbe11ee421ec40c75f32849d07f669600558cb"
61
62
  }