@mittwald/react-tunnel 0.2.0-alpha.7 → 0.2.0-alpha.700

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,66 +1,86 @@
1
1
  "use client"
2
2
  /* */
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";
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";
9
7
  const l = "default";
10
- class c {
8
+ class o {
9
+ children = f.map(
10
+ {},
11
+ {
12
+ deep: !1
13
+ }
14
+ );
15
+ preparedChildren = /* @__PURE__ */ new Map();
16
+ nextIndex = 0;
11
17
  constructor() {
12
- o(this, "children", a.map(
13
- {},
14
- {
15
- deep: !1
16
- }
17
- ));
18
- o(this, "preparedChildren", /* @__PURE__ */ new Map());
19
- x(this, {
20
- deleteChildren: p.bound,
21
- setChildren: p.bound
18
+ b(this, {
19
+ deleteChildren: C.bound,
20
+ setChildren: C.bound
22
21
  });
23
22
  }
24
23
  static useNew() {
25
- return f(new c()).current;
24
+ const e = E(() => new o())[0];
25
+ return e.resetIndex(), e;
26
26
  }
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);
27
+ resetIndex() {
28
+ this.nextIndex = 0;
31
29
  }
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);
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);
35
53
  }
36
54
  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);
55
+ this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
39
56
  }
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());
57
+ getEntries(e = l) {
58
+ const t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
43
59
  if (t)
44
- return Array.from(t);
60
+ return Array.from(t).sort(
61
+ (r, n) => r.index - n.index
62
+ );
45
63
  }
46
64
  }
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;
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;
57
77
  return typeof e == "function" ? e() : 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;
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;
61
81
  });
62
82
  export {
63
- A as TunnelEntry,
64
- O as TunnelExit,
65
- P as TunnelProvider
83
+ R as TunnelEntry,
84
+ N as TunnelExit,
85
+ I as TunnelProvider
66
86
  };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Tunnel.browser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tunnel.browser.test.d.ts","sourceRoot":"","sources":["../../src/Tunnel.browser.test.tsx"],"names":[],"mappings":""}
@@ -1,12 +1,24 @@
1
+ import { ReactNode } from 'react';
1
2
  import { ObservableMap } from 'mobx';
2
- import { TunnelChildren } from './types';
3
+ export type TunnelChildren = ReactNode | undefined | ((tunnelChildren?: ReactNode | undefined) => ReactNode | undefined);
4
+ interface TunnelEntryState {
5
+ index: number;
6
+ id: string;
7
+ children: TunnelChildren;
8
+ }
3
9
  export declare class TunnelState {
4
- readonly children: ObservableMap<string, ObservableMap<string, TunnelChildren>>;
10
+ readonly children: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
5
11
  private readonly preparedChildren;
12
+ private nextIndex;
6
13
  constructor();
7
14
  static useNew(): TunnelState;
8
- setChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
9
- prepareChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
15
+ resetIndex(): void;
16
+ useEntryIndex(): number;
17
+ setChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
18
+ prepareChildren(tunnelId: string | undefined, entryId: string, index: number, children: TunnelChildren): void;
19
+ private deleteChildrenFromMap;
10
20
  deleteChildren(tunnelId: string | undefined, entryId: string): void;
11
- getChildren(tunnelId?: string): [string, TunnelChildren][] | undefined;
21
+ getEntries(tunnelId?: string): TunnelEntryState[] | undefined;
12
22
  }
23
+ export {};
24
+ //# sourceMappingURL=TunnelState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAK1C,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,qBAAa,WAAW;IACtB,SAAgB,QAAQ,iEAQtB;IAEF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG7B;IAEJ,OAAO,CAAC,SAAS,CAAK;;WASR,MAAM,IAAI,WAAW;IAM5B,UAAU;IAIV,aAAa;IAUb,WAAW,CAChB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,GACvB,IAAI;IAiBA,eAAe,CACpB,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;IAKnE,UAAU,CACf,QAAQ,GAAE,MAAkB,GAC3B,gBAAgB,EAAE,GAAG,SAAS;CAUlC"}
@@ -1,10 +1,11 @@
1
- import { FC } from 'react';
2
- import { TunnelChildren } from '../types';
3
- interface Props {
1
+ import { FC, ReactNode } from 'react';
2
+ export type TunnelEntryChildren = ReactNode | undefined | (() => ReactNode | undefined);
3
+ export interface TunnelEntryProps {
4
4
  id?: string;
5
- children?: TunnelChildren;
5
+ children?: TunnelEntryChildren;
6
6
  /** Static entry ID instead of generated ID by `useId` */
7
7
  staticEntryId?: string;
8
8
  }
9
- export declare const TunnelEntry: FC<Props>;
9
+ export declare const TunnelEntry: FC<TunnelEntryProps>;
10
10
  export default TunnelEntry;
11
+ //# sourceMappingURL=TunnelEntry.d.ts.map
@@ -0,0 +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;CACxB;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CA+B5C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,6 +1,10 @@
1
- import { FC, PropsWithChildren } from 'react';
2
- interface Props extends PropsWithChildren {
1
+ import { FC } from 'react';
2
+ import { TunnelChildren } from '../TunnelState';
3
+ export type TunnelExitChildren = TunnelChildren;
4
+ export interface TunnelExitProps {
3
5
  id?: string;
6
+ children?: TunnelExitChildren;
4
7
  }
5
- export declare const TunnelExit: FC<Props>;
8
+ export declare const TunnelExit: FC<TunnelExitProps>;
6
9
  export default TunnelExit;
10
+ //# sourceMappingURL=TunnelExit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TunnelExit.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelExit.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAIhC,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,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAOD,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAezC,CAAC;AAEH,eAAe,UAAU,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
2
  export declare const TunnelProvider: FC<PropsWithChildren>;
3
3
  export default TunnelProvider;
4
+ //# sourceMappingURL=TunnelProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TunnelProvider.d.ts","sourceRoot":"","sources":["../../../src/components/TunnelProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAQhD,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import { TunnelState } from './TunnelState';
2
2
  export declare const tunnelContext: import('react').Context<TunnelState>;
3
3
  export default tunnelContext;
4
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,aAAa,sCAAgD,CAAC;AAE3E,eAAe,aAAa,CAAC"}
@@ -1,3 +1,4 @@
1
- export { TunnelProvider } from './components/TunnelProvider';
2
- export { TunnelEntry } from './components/TunnelEntry';
3
- export { TunnelExit } from './components/TunnelExit';
1
+ export * from './components/TunnelProvider';
2
+ export * from './components/TunnelEntry';
3
+ export * from './components/TunnelExit';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.7",
3
+ "version": "0.2.0-alpha.700",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -23,40 +23,41 @@
23
23
  "dist"
24
24
  ],
25
25
  "scripts": {
26
- "build": "run vite build --config vite.build.config.ts",
27
- "build:deps:watch": "run -T build:deps:watch @mittwald/react-tunnel",
28
- "test": "",
29
- "test:compile": "run tsc --noEmit",
30
- "test:unit": "run vitest run"
26
+ "build": "vite build --config vite.build.config.ts",
27
+ "clean": "rimraf dist",
28
+ "test:browser": "vitest run --project=browser --browser.headless",
29
+ "test:browser:dev": "vitest dev --project=browser",
30
+ "test:compile": "tsc --noEmit"
31
31
  },
32
32
  "dependencies": {
33
- "mobx": "^6.13.5",
34
- "mobx-react-lite": "^4.1.0"
33
+ "mobx": "^6.15.0",
34
+ "mobx-react-lite": "^4.1.1"
35
35
  },
36
36
  "devDependencies": {
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",
54
- "vite-plugin-externalize-deps": "^0.8.0",
55
- "vitest": "^2.1.8"
37
+ "@mittwald/typescript-config": "workspace:*",
38
+ "@types/node": "^24.10.9",
39
+ "@types/react": "^19.2",
40
+ "@types/react-dom": "^19.2",
41
+ "@vitejs/plugin-react": "^5.1.3",
42
+ "@vitest/browser-playwright": "^4.0.18",
43
+ "@vitest/coverage-v8": "^4.0.18",
44
+ "nx": "^22.4.4",
45
+ "prettier": "^3.8.1",
46
+ "react": "^19.2.0",
47
+ "react-dom": "^19.2.0",
48
+ "rimraf": "^6.1.2",
49
+ "typescript": "^5.9.3",
50
+ "vite": "^7.3.1",
51
+ "vite-plugin-banner": "^0.8.1",
52
+ "vite-plugin-checker": "^0.12.0",
53
+ "vite-plugin-dts": "^4.5.4",
54
+ "vite-plugin-externalize-deps": "^0.10.0",
55
+ "vitest": "^4.0.18",
56
+ "vitest-browser-react": "^2.0.2"
56
57
  },
57
58
  "peerDependencies": {
58
- "react": "^19.0.0",
59
- "react-dom": "^19.0.0"
59
+ "react": "^19.2.0",
60
+ "react-dom": "^19.2.0"
60
61
  },
61
- "gitHead": "050fa81621ad4296e032878f27f24e2ac9885854"
62
+ "gitHead": "b72e8519bf337cf442b2196570e84a78a7726f79"
62
63
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export type TunnelChildren = ReactNode | undefined | (() => ReactNode | undefined);