@mittwald/react-tunnel 0.1.0-alpha.51

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Mittwald CM Service GmbH & Co. KG and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @mittwald/react-tunnel
2
+
3
+ It's like a Portal – but with React components
4
+
5
+ Renders everything inside `<TunnelEntry id="tunnelId" />` in the corresponding
6
+ `<TunnelExit id="tunnelId" />`.
7
+
8
+ ```jsx
9
+ import { TunnelProvider, TunnelEntry, TunnelExit } from "@mittwald/react-tunnel";
10
+
11
+ function App() {
12
+ return (
13
+ <TunnelProvider>
14
+ <h1>My cool App</h1>
15
+ <TunnelExit id="callToAction" />
16
+ <PagesRouter />
17
+ </>
18
+ );
19
+ }
20
+
21
+ function ProfilePage(props) {
22
+ const { user } = props;
23
+ return (
24
+ <Page>
25
+ <EditProfileForm />
26
+ {!user.mfaEnabled && (
27
+ <TunnelEntry id="callToAction">
28
+ <Link href="/profile/mfa">Enable MFA</Link>
29
+ </TunnelEntry>
30
+ )}
31
+ </Page>
32
+ );
33
+ }
34
+ ```
35
+
36
+ ## Components
37
+
38
+ ### `<TunnelProvider />`
39
+
40
+ This component manages the "transfer" and must be a parent of all Tunnel
41
+ components.
42
+
43
+ ### `<TunnelExit />`
44
+
45
+ This component renders the children placed inside the corresponding
46
+ `<TunnelEntry />`. All children of the `<TunnelExit />` itself are rendered, if
47
+ nothing is in the TunnelEntry.
48
+
49
+ #### Props
50
+
51
+ - `id`: Use the `id` prop to identify multiple Tunnels.
52
+
53
+ ### `<TunnelEntry />`
54
+
55
+ All children of this component are rendered inside the corresponding
56
+ `<TunnelExit />`.
57
+
58
+ #### Props
59
+
60
+ - `id`: Use the `id` prop to identify multiple Tunnels.
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use client"
2
+ /* */
3
+ import o, { createContext as d, useContext as c, useLayoutEffect as i } from "react";
4
+ import { useSignal as a } from "@preact/signals-react";
5
+ import { useSignals as s } from "@preact/signals-react/runtime";
6
+ const u = d({
7
+ children: {
8
+ value: {}
9
+ }
10
+ }), m = (l) => {
11
+ const { children: e } = l;
12
+ return /* @__PURE__ */ o.createElement(
13
+ u.Provider,
14
+ {
15
+ value: {
16
+ children: a({})
17
+ }
18
+ },
19
+ e
20
+ );
21
+ }, x = (l) => {
22
+ const { children: e, id: n = "default" } = l, t = c(u);
23
+ return i(() => {
24
+ if (e !== t.children.value[n])
25
+ return t.children.value = { ...t.children.value, [n]: e }, () => {
26
+ const r = { ...t.children.value };
27
+ delete r[n], t.children.value = r;
28
+ };
29
+ }, [e, n, e]), null;
30
+ }, C = (l) => {
31
+ const { children: e, id: n = "default" } = l;
32
+ return s(), c(u).children.value[n] ?? e;
33
+ };
34
+ export {
35
+ x as TunnelEntry,
36
+ C as TunnelExit,
37
+ m as TunnelProvider
38
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { FC, PropsWithChildren } from "react";
2
+ interface Props extends PropsWithChildren {
3
+ id?: string;
4
+ }
5
+ export declare const TunnelEntry: FC<Props>;
6
+ export default TunnelEntry;
@@ -0,0 +1,6 @@
1
+ import { FC, PropsWithChildren } from "react";
2
+ interface Props extends PropsWithChildren {
3
+ id?: string;
4
+ }
5
+ export declare const TunnelExit: FC<Props>;
6
+ export default TunnelExit;
@@ -0,0 +1,3 @@
1
+ import { FC, PropsWithChildren } from "react";
2
+ export declare const TunnelProvider: FC<PropsWithChildren>;
3
+ export default TunnelProvider;
@@ -0,0 +1,8 @@
1
+ import { Signal } from "@preact/signals-react";
2
+ import { ReactNode } from "react";
3
+ export type TunnelNodes = Record<string, ReactNode>;
4
+ export interface TunnelContext {
5
+ children: Signal<TunnelNodes>;
6
+ }
7
+ export declare const tunnelContext: import("react").Context<TunnelContext>;
8
+ export default tunnelContext;
@@ -0,0 +1,3 @@
1
+ export { TunnelProvider } from "./components/TunnelProvider";
2
+ export { TunnelEntry } from "./components/TunnelEntry";
3
+ export { TunnelExit } from "./components/TunnelExit";
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@mittwald/react-tunnel",
3
+ "version": "0.1.0-alpha.51",
4
+ "type": "module",
5
+ "description": "It's like a Portal – but with React components",
6
+ "keywords": [
7
+ "layout",
8
+ "portal",
9
+ "react",
10
+ "react tree",
11
+ "teleport"
12
+ ],
13
+ "homepage": "https://mittwald.github.io/flow",
14
+ "repository": "https://github.com/mittwald/flow",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/types/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ }
20
+ },
21
+ "types": "./dist/types/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
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"
31
+ },
32
+ "dependencies": {
33
+ "@preact/signals-react": "^2.0.1"
34
+ },
35
+ "devDependencies": {
36
+ "@testing-library/react": "^14.2.2",
37
+ "@types/node": "^20.11.30",
38
+ "@types/react": "^18.2.66",
39
+ "@types/react-dom": "^18.2.22",
40
+ "@vitejs/plugin-react": "^4.2.1",
41
+ "@vitest/coverage-v8": "^1.4.0",
42
+ "happy-dom": "^14.2.0",
43
+ "nx": "^18.1.1",
44
+ "prettier": "^3.2.5",
45
+ "react": "^18.2.0",
46
+ "react-dom": "^18.2.0",
47
+ "typescript": "^5.4.2",
48
+ "vite": "^5.2.2",
49
+ "vite-plugin-banner": "^0.7.1",
50
+ "vite-plugin-checker": "^0.6.4",
51
+ "vite-plugin-dts": "^3.7.3",
52
+ "vite-plugin-externalize-deps": "^0.8.0",
53
+ "vitest": "^1.4.0"
54
+ },
55
+ "peerDependencies": {
56
+ "react": "^18.2.0",
57
+ "react-dom": "^18.2.0"
58
+ },
59
+ "gitHead": "4477a993ec55e0fd6a384f3cf17d1e7e9c251447"
60
+ }