@shaper.org/vite-react-plugin 1.0.9 → 1.0.11
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.d.mts +19 -0
- package/dist/index.mjs +6 -1
- package/package.json +3 -3
- package/templates/main.ts +45 -15
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,25 @@ import { UserConfig } from "vite";
|
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
declare const reactPlugin: (config: UserConfig) => ({
|
|
6
|
+
name: string;
|
|
7
|
+
enforce: string;
|
|
8
|
+
resolveId(id: string): "virtual:hmr-events-plugin" | undefined;
|
|
9
|
+
load(id: string): string | undefined;
|
|
10
|
+
transformIndexHtml(html: string): {
|
|
11
|
+
html: string;
|
|
12
|
+
tags: {
|
|
13
|
+
tag: string;
|
|
14
|
+
injectTo: string;
|
|
15
|
+
type: string;
|
|
16
|
+
attrs: {
|
|
17
|
+
src: string;
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
configureServer(server: vite0.ViteDevServer): void;
|
|
23
|
+
handleHotUpdate(ctx: vite0.HmrContext): vite0.ModuleNode[];
|
|
24
|
+
} | {
|
|
6
25
|
name: string;
|
|
7
26
|
enforce: string;
|
|
8
27
|
transform(code: any, id: any): Promise<{
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import * as PathUtil from "path";
|
|
|
6
6
|
import { isAbsolute, posix, resolve, win32 } from "path";
|
|
7
7
|
import babel from "@babel/core";
|
|
8
8
|
import * as t from "@babel/types";
|
|
9
|
+
import { HMREventsPlugin } from "@shaper.org/core/node";
|
|
9
10
|
|
|
10
11
|
//#region rolldown:runtime
|
|
11
12
|
var __create = Object.create;
|
|
@@ -1820,7 +1821,11 @@ function jsxSourcePlugin(options = {}) {
|
|
|
1820
1821
|
//#endregion
|
|
1821
1822
|
//#region src/index.ts
|
|
1822
1823
|
const reactPlugin = (config) => {
|
|
1823
|
-
return [
|
|
1824
|
+
return [
|
|
1825
|
+
HMREventsPlugin(),
|
|
1826
|
+
jsxSourcePlugin(config),
|
|
1827
|
+
reactRoutesPlugin()
|
|
1828
|
+
];
|
|
1824
1829
|
};
|
|
1825
1830
|
|
|
1826
1831
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaper.org/vite-react-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"node": "^20.19.0 || >=22.12.0"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@shaper.org/core": "1.0.
|
|
19
|
+
"@shaper.org/core": "^1.0.4",
|
|
20
20
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
21
21
|
"vue": "^3.2.25"
|
|
22
22
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@jridgewell/gen-mapping": "^0.3.13",
|
|
29
29
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
30
30
|
"@rollup/pluginutils": "^5.3.0",
|
|
31
|
-
"@shaper.org/core": "1.0.
|
|
31
|
+
"@shaper.org/core": "^1.0.4",
|
|
32
32
|
"esbuild": "^0.27.0",
|
|
33
33
|
"obug": "^2.0.0",
|
|
34
34
|
"rollup": "^4.53.3",
|
package/templates/main.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import {
|
|
3
|
-
iframePostMessageClient,
|
|
4
|
-
IframePostMessageClient,
|
|
5
|
-
} from "@shaper.org/core";
|
|
2
|
+
import { IframePostMessageClient } from "@shaper.org/core/client";
|
|
6
3
|
|
|
7
4
|
export const eventMap = {
|
|
8
5
|
MouseUp: 0,
|
|
@@ -75,7 +72,7 @@ export class ReactRouteMonitor {
|
|
|
75
72
|
|
|
76
73
|
constructor({ router, eventSettings }: ReactRouteMonitorOptions) {
|
|
77
74
|
this.router = router;
|
|
78
|
-
this.iframeClient =
|
|
75
|
+
this.iframeClient = new IframePostMessageClient();
|
|
79
76
|
|
|
80
77
|
// store originals
|
|
81
78
|
this.origPush = history.pushState;
|
|
@@ -104,6 +101,16 @@ export class ReactRouteMonitor {
|
|
|
104
101
|
this.attachGlobalListeners();
|
|
105
102
|
window.addEventListener("locationchange", this.onLocationChange);
|
|
106
103
|
window.addEventListener("popstate", this.triggerRouteChange);
|
|
104
|
+
|
|
105
|
+
this.sendAllRoutes = this.sendAllRoutes.bind(this);
|
|
106
|
+
window.addEventListener("getroutes", this.sendAllRoutes);
|
|
107
|
+
|
|
108
|
+
this.iframeClient.onMessage((event) => {
|
|
109
|
+
const messageData = event.data;
|
|
110
|
+
if (messageData.type == "push-route") {
|
|
111
|
+
window.location.href = messageData.message.path;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
stop() {
|
|
@@ -117,6 +124,7 @@ export class ReactRouteMonitor {
|
|
|
117
124
|
|
|
118
125
|
window.removeEventListener("locationchange", this.onLocationChange);
|
|
119
126
|
window.removeEventListener("popstate", this.triggerRouteChange);
|
|
127
|
+
window.removeEventListener("getroutes", this.triggerRoutes);
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
patchHistory() {
|
|
@@ -131,6 +139,29 @@ export class ReactRouteMonitor {
|
|
|
131
139
|
};
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
sendAllRoutes(event: CustomEvent<{ routes?: any }>) {
|
|
143
|
+
if (!event) return;
|
|
144
|
+
|
|
145
|
+
const validRoutes = event.detail.routes.filter(
|
|
146
|
+
(route) => route.element !== undefined && route.path !== "*",
|
|
147
|
+
);
|
|
148
|
+
const routes = validRoutes.map((route) => ({
|
|
149
|
+
name: route.path,
|
|
150
|
+
path: route.path,
|
|
151
|
+
file: route.element.type().props["data-loc"],
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
this.iframeClient.sendAllRoutes(routes);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
triggerRoutes = () => {
|
|
158
|
+
window.dispatchEvent(
|
|
159
|
+
new CustomEvent("getroutes", {
|
|
160
|
+
detail: { routes: this.router.routes },
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
134
165
|
triggerRouteChange = () => {
|
|
135
166
|
window.dispatchEvent(
|
|
136
167
|
new CustomEvent("locationchange", {
|
|
@@ -154,18 +185,16 @@ export class ReactRouteMonitor {
|
|
|
154
185
|
const from = state.matches[0].route;
|
|
155
186
|
const fromPathname = this.router.state.location.pathname;
|
|
156
187
|
|
|
188
|
+
const routeInfo = {
|
|
189
|
+
name: toPathname,
|
|
190
|
+
path: toPathname,
|
|
191
|
+
file: to.element.type().props["data-loc"],
|
|
192
|
+
};
|
|
193
|
+
|
|
157
194
|
if (toPathname === fromPathname) {
|
|
158
|
-
this.iframeClient.sendRouteRefresh(
|
|
159
|
-
name: toPathname,
|
|
160
|
-
path: toPathname,
|
|
161
|
-
file: to.element.type().props["data-loc"],
|
|
162
|
-
});
|
|
195
|
+
this.iframeClient.sendRouteRefresh(routeInfo);
|
|
163
196
|
} else {
|
|
164
|
-
this.iframeClient.sendRouteChange(
|
|
165
|
-
name: toPathname,
|
|
166
|
-
path: toPathname,
|
|
167
|
-
file: to.element.type().props["data-loc"],
|
|
168
|
-
});
|
|
197
|
+
this.iframeClient.sendRouteChange(routeInfo);
|
|
169
198
|
}
|
|
170
199
|
};
|
|
171
200
|
|
|
@@ -215,3 +244,4 @@ const monitor = new ReactRouteMonitor({
|
|
|
215
244
|
});
|
|
216
245
|
|
|
217
246
|
monitor.start();
|
|
247
|
+
monitor.triggerRoutes();
|