@mittwald/react-tunnel 0.2.0-alpha.614 → 0.2.0-alpha.616

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,11 +1,11 @@
1
1
  "use client"
2
2
  /* */
3
- import { jsx as C } from "react/jsx-runtime";
4
- import { useState as m, createContext as g, useContext as f, useId as E, useRef as b, useEffect as u } from "react";
5
- import { observable as p, makeObservable as v, action as a } from "mobx";
3
+ import { jsx as f } from "react/jsx-runtime";
4
+ import { useState as m, createContext as g, useContext as x, useId as E, useRef as v, useEffect as a } from "react";
5
+ import { observable as p, makeObservable as b, action as C } from "mobx";
6
6
  import { observer as w } from "mobx-react-lite";
7
- const d = "default";
8
- class l {
7
+ const l = "default";
8
+ class o {
9
9
  children = p.map(
10
10
  {},
11
11
  {
@@ -13,55 +13,73 @@ class l {
13
13
  }
14
14
  );
15
15
  preparedChildren = /* @__PURE__ */ new Map();
16
+ nextIndex = 0;
16
17
  constructor() {
17
- v(this, {
18
- deleteChildren: a.bound,
19
- setChildren: a.bound
18
+ b(this, {
19
+ deleteChildren: C.bound,
20
+ setChildren: C.bound
20
21
  });
21
22
  }
22
23
  static useNew() {
23
- return m(() => new l())[0];
24
+ const e = m(() => new o())[0];
25
+ return e.resetIndex(), e;
24
26
  }
25
- setChildren(e = d, r, n) {
26
- const t = this.children.get(e) ?? p.map({}, { deep: !1 });
27
- t.set(r, n), this.preparedChildren.get(e)?.delete(r), this.children.set(e, t);
27
+ resetIndex() {
28
+ this.nextIndex = 0;
28
29
  }
29
- prepareChildren(e = d, r, n) {
30
- const t = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
31
- t.set(r, n), this.preparedChildren.set(e, t);
30
+ getIndex() {
31
+ return this.nextIndex++;
32
32
  }
33
- deleteChildrenFromMap(e, r, n) {
34
- const t = e.get(r);
35
- t?.delete(n), t?.size === 0 && e.delete(r);
33
+ setChildren(e = l, t, r, n) {
34
+ const i = {
35
+ id: t,
36
+ index: r,
37
+ children: n
38
+ }, s = this.children.get(e) ?? p.map({}, { deep: !1 });
39
+ s.set(t, i), this.preparedChildren.get(e)?.delete(t), this.children.set(e, s);
36
40
  }
37
- deleteChildren(e = d, r) {
38
- this.deleteChildrenFromMap(this.children, e, r), this.deleteChildrenFromMap(this.preparedChildren, e, r);
41
+ prepareChildren(e = l, t, r, n) {
42
+ const i = {
43
+ id: t,
44
+ index: r,
45
+ children: n
46
+ }, s = this.preparedChildren.get(e) ?? /* @__PURE__ */ new Map();
47
+ s.set(t, i), this.preparedChildren.set(e, s);
39
48
  }
40
- getChildren(e = d) {
41
- const r = this.children.get(e)?.entries() ?? this.preparedChildren.get(e)?.entries();
42
- if (r)
43
- return Array.from(r);
49
+ deleteChildrenFromMap(e, t, r) {
50
+ const n = e.get(t);
51
+ n?.delete(r), n?.size === 0 && e.delete(t);
52
+ }
53
+ deleteChildren(e = l, t) {
54
+ this.deleteChildrenFromMap(this.children, e, t), this.deleteChildrenFromMap(this.preparedChildren, e, t);
55
+ }
56
+ getEntries(e = l) {
57
+ const t = this.children.get(e)?.values() ?? this.preparedChildren.get(e)?.values();
58
+ if (t)
59
+ return Array.from(t).sort(
60
+ (r, n) => r.index - n.index
61
+ );
44
62
  }
45
63
  }
46
- const h = g(new l()), N = (i) => {
47
- const { children: e } = i;
48
- return /* @__PURE__ */ C(h.Provider, { value: l.useNew(), children: e });
49
- }, P = (i) => {
50
- const { children: e, id: r, staticEntryId: n } = i, t = f(h), o = E(), s = n ?? o, c = b(!1);
51
- return c.current || t.prepareChildren(r, s, e), u(() => {
52
- c.current = !0, t.setChildren(r, s, e);
53
- }, [e, r, s]), u(() => () => {
54
- t.deleteChildren(r, s);
55
- }, [r, s]), null;
56
- }, x = (i) => {
57
- const { children: e } = i;
64
+ const h = g(new o()), I = (d) => {
65
+ const { children: e } = d;
66
+ return /* @__PURE__ */ f(h.Provider, { value: o.useNew(), children: e });
67
+ }, N = (d) => {
68
+ const { children: e, id: t, staticEntryId: r } = d, n = x(h), i = E(), s = r ?? i, c = n.getIndex(), u = v(!1);
69
+ return u.current || n.prepareChildren(t, s, c, e), a(() => {
70
+ u.current = !0, n.setChildren(t, s, c, e);
71
+ }, [e, t, s, c]), a(() => () => {
72
+ n.deleteChildren(t, s);
73
+ }, [t, s]), null;
74
+ }, M = (d) => {
75
+ const { children: e } = d;
58
76
  return typeof e == "function" ? e() : e;
59
- }, R = w((i) => {
60
- const { children: e, id: r } = i, n = f(h).getChildren(r), t = n ? n.map(([o, s]) => /* @__PURE__ */ C(x, { children: s }, o)) : null;
61
- return typeof e == "function" ? e(t) : t ?? e;
77
+ }, P = w((d) => {
78
+ const { children: e, id: t } = d, r = x(h).getEntries(t), n = r ? r.map((i) => /* @__PURE__ */ f(M, { children: i.children }, i.id)) : null;
79
+ return typeof e == "function" ? e(n) : n ?? e;
62
80
  });
63
81
  export {
64
- P as TunnelEntry,
65
- R as TunnelExit,
66
- N as TunnelProvider
82
+ N as TunnelEntry,
83
+ P as TunnelExit,
84
+ I as TunnelProvider
67
85
  };
@@ -1,15 +1,24 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { ObservableMap } from 'mobx';
3
3
  export type TunnelChildren = ReactNode | undefined | ((tunnelChildren?: ReactNode | undefined) => ReactNode | undefined);
4
+ interface TunnelEntryState {
5
+ index: number;
6
+ id: string;
7
+ children: TunnelChildren;
8
+ }
4
9
  export declare class TunnelState {
5
- readonly children: ObservableMap<string, ObservableMap<string, TunnelChildren>>;
10
+ readonly children: ObservableMap<string, ObservableMap<string, TunnelEntryState>>;
6
11
  private readonly preparedChildren;
12
+ private nextIndex;
7
13
  constructor();
8
14
  static useNew(): TunnelState;
9
- setChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
10
- prepareChildren(tunnelId: string | undefined, entryId: string, children: TunnelChildren): void;
15
+ resetIndex(): void;
16
+ getIndex(): 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;
11
19
  private deleteChildrenFromMap;
12
20
  deleteChildren(tunnelId: string | undefined, entryId: string): void;
13
- getChildren(tunnelId?: string): [string, TunnelChildren][] | undefined;
21
+ getEntries(tunnelId?: string): TunnelEntryState[] | undefined;
14
22
  }
23
+ export {};
15
24
  //# sourceMappingURL=TunnelState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AACjD,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,qBAAa,WAAW;IACtB,SAAgB,QAAQ,+DAQtB;IAEF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG7B;;WASU,MAAM,IAAI,WAAW;IAI5B,WAAW,CAChB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,cAAc,GACvB,IAAI;IAWA,eAAe,CACpB,QAAQ,EAAE,MAAM,YAAY,EAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,cAAc,GACvB,IAAI;IASP,OAAO,CAAC,qBAAqB;IAYtB,cAAc,CAAC,QAAQ,EAAE,MAAM,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAKnE,WAAW,CAChB,QAAQ,GAAE,MAAkB,GAC3B,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG,SAAS;CAQ1C"}
1
+ {"version":3,"file":"TunnelState.d.ts","sourceRoot":"","sources":["../../src/TunnelState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,K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C,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,CA8B5C,CAAC;AAEF,eAAe,WAAW,CAAC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-tunnel",
3
- "version": "0.2.0-alpha.614",
3
+ "version": "0.2.0-alpha.616",
4
4
  "type": "module",
5
5
  "description": "It's like a Portal – but with React components",
6
6
  "keywords": [
@@ -60,5 +60,5 @@
60
60
  "react": "^19.2.0",
61
61
  "react-dom": "^19.2.0"
62
62
  },
63
- "gitHead": "b704cea3a2be396c38115fcb10dd6415595d1e62"
63
+ "gitHead": "c31bc94a88165571af4a28f3f03b972edbc27fc7"
64
64
  }