@mittwald/react-tunnel 0.1.0-alpha.59 → 0.1.0-alpha.65

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,51 +1,57 @@
1
1
  "use client"
2
2
  /* */
3
- var h = Object.defineProperty;
4
- var a = (t, e, n) => e in t ? h(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
5
- var s = (t, e, n) => (a(t, typeof e != "symbol" ? e + "" : e, n), n);
6
- import C, { useState as m, createContext as b, useContext as c, useLayoutEffect as f } from "react";
7
- import { makeObservable as v, observable as x, action as o } from "mobx";
8
- import { observer as u } from "mobx-react-lite";
9
- const l = "default";
10
- class i {
3
+ var f = Object.defineProperty;
4
+ var m = (r, e, t) => e in r ? f(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
5
+ var u = (r, e, t) => (m(r, typeof e != "symbol" ? e + "" : e, t), t);
6
+ import C, { useState as p, createContext as b, useContext as a, useId as v, useRef as E, useLayoutEffect as g } from "react";
7
+ import { observable as c, makeObservable as x, action as h } from "mobx";
8
+ import { observer as w } from "mobx-react-lite";
9
+ const i = "default";
10
+ class l {
11
11
  constructor() {
12
- s(this, "children", {});
13
- v(this, {
14
- children: x,
15
- deleteChildren: o.bound,
16
- setChildren: o.bound
12
+ u(this, "children", c.map(
13
+ {},
14
+ {
15
+ deep: !1
16
+ }
17
+ ));
18
+ x(this, {
19
+ deleteChildren: h.bound,
20
+ setChildren: h.bound
17
21
  });
18
22
  }
19
23
  static useNew() {
20
- return m(new i())[0];
24
+ return p(new l())[0];
21
25
  }
22
- setChildren(e = l, n) {
23
- this.children[e] = n;
26
+ setChildren(e = i, t, n) {
27
+ const s = this.children.get(e) ?? c.map({}, { deep: !1 });
28
+ s.set(t, n), this.children.set(e, s);
24
29
  }
25
- deleteChildren(e = l) {
26
- delete this.children[e];
30
+ deleteChildren(e = i, t) {
31
+ var n;
32
+ (n = this.children.get(e)) == null || n.delete(t);
27
33
  }
28
- hasChildren(e = l) {
29
- return e in this.children;
30
- }
31
- getChildren(e = l) {
32
- return this.children[e];
34
+ getChildren(e = i) {
35
+ var n;
36
+ const t = (n = this.children.get(e)) == null ? void 0 : n.values();
37
+ if (t)
38
+ return Array.from(t);
33
39
  }
34
40
  }
35
- const d = b(new i()), g = (t) => {
36
- const { children: e } = t;
37
- return /* @__PURE__ */ C.createElement(d.Provider, { value: i.useNew() }, e);
38
- }, y = u((t) => {
39
- const { children: e, id: n } = t, r = c(d);
40
- return f(() => (r.setChildren(n, e), () => {
41
- r.deleteChildren(n);
42
- }), [e, n]), r.hasChildren(n) ? null : e;
43
- }), N = u((t) => {
44
- const { children: e, id: n } = t;
45
- return c(d).getChildren(n) ?? e;
41
+ const o = b(new l()), P = (r) => {
42
+ const { children: e } = r;
43
+ return /* @__PURE__ */ C.createElement(o.Provider, { value: l.useNew() }, e);
44
+ }, R = (r) => {
45
+ const { children: e, id: t } = r, n = a(o), s = v(), d = E(!1);
46
+ return d.current || n.setChildren(t, s, e), g(() => (d.current = !0, n.setChildren(t, s, e), () => {
47
+ n.deleteChildren(t, s);
48
+ }), [e, t, s]), null;
49
+ }, k = w((r) => {
50
+ const { children: e, id: t } = r;
51
+ return a(o).getChildren(t) ?? e;
46
52
  });
47
53
  export {
48
- y as TunnelEntry,
49
- N as TunnelExit,
50
- g as TunnelProvider
54
+ R as TunnelEntry,
55
+ k as TunnelExit,
56
+ P as TunnelProvider
51
57
  };
@@ -1,13 +1,11 @@
1
+ import { ObservableMap } from 'mobx';
1
2
  import { ReactNode } from 'react';
2
3
 
3
- type TunnelNodes = Record<string, ReactNode>;
4
4
  export declare class TunnelState {
5
- readonly children: TunnelNodes;
5
+ readonly children: ObservableMap<string, ObservableMap<string, ReactNode>>;
6
6
  constructor();
7
7
  static useNew(): TunnelState;
8
- setChildren(tunnelId: string | undefined, children: ReactNode): void;
9
- deleteChildren(tunnelId?: string): void;
10
- hasChildren(tunnelId?: string): boolean;
8
+ setChildren(tunnelId: string | undefined, entryId: string, children: ReactNode): void;
9
+ deleteChildren(tunnelId: string | undefined, entryId: string): void;
11
10
  getChildren(tunnelId?: string): ReactNode;
12
11
  }
13
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.1.0-alpha.59",
3
+ "version": "0.1.0-alpha.65",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -34,18 +34,18 @@
34
34
  "mobx-react-lite": "^4.0.7"
35
35
  },
36
36
  "devDependencies": {
37
- "@testing-library/react": "^14.2.2",
38
- "@types/node": "^20.12.5",
39
- "@types/react": "^18.2.74",
37
+ "@testing-library/react": "^14.3.0",
38
+ "@types/node": "^20.12.7",
39
+ "@types/react": "^18.2.75",
40
40
  "@types/react-dom": "^18.2.24",
41
41
  "@vitejs/plugin-react": "^4.2.1",
42
42
  "@vitest/coverage-v8": "^1.4.0",
43
43
  "happy-dom": "^14.7.1",
44
- "nx": "^18.2.3",
44
+ "nx": "^18.2.4",
45
45
  "prettier": "^3.2.5",
46
46
  "react": "^18.2.0",
47
47
  "react-dom": "^18.2.0",
48
- "typescript": "^5.4.4",
48
+ "typescript": "^5.4.5",
49
49
  "vite": "^5.2.8",
50
50
  "vite-plugin-banner": "^0.7.1",
51
51
  "vite-plugin-checker": "^0.6.4",
@@ -57,5 +57,5 @@
57
57
  "react": "^18.2.0",
58
58
  "react-dom": "^18.2.0"
59
59
  },
60
- "gitHead": "3b85f0b5dd4f06c8ee3a26c23911aea3a5a4cab6"
60
+ "gitHead": "000868d3499fd78147a5a50f1d5e6571c18527b7"
61
61
  }