@shaper.org/vite-react-plugin 1.0.8 → 1.0.10
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 +26 -2137
- package/package.json +6 -3
- package/templates/main.ts +38 -15
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.10",
|
|
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",
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"dts": true,
|
|
52
52
|
"format": [
|
|
53
53
|
"esm"
|
|
54
|
+
],
|
|
55
|
+
"external": [
|
|
56
|
+
"esbuild"
|
|
54
57
|
]
|
|
55
58
|
},
|
|
56
59
|
"publishConfig": {
|
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,9 @@ 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
107
|
}
|
|
108
108
|
|
|
109
109
|
stop() {
|
|
@@ -117,6 +117,7 @@ export class ReactRouteMonitor {
|
|
|
117
117
|
|
|
118
118
|
window.removeEventListener("locationchange", this.onLocationChange);
|
|
119
119
|
window.removeEventListener("popstate", this.triggerRouteChange);
|
|
120
|
+
window.removeEventListener("getroutes", this.triggerRoutes);
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
patchHistory() {
|
|
@@ -131,6 +132,29 @@ export class ReactRouteMonitor {
|
|
|
131
132
|
};
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
sendAllRoutes(event: CustomEvent<{ routes?: any }>) {
|
|
136
|
+
if (!event) return;
|
|
137
|
+
|
|
138
|
+
const validRoutes = event.detail.routes.filter(
|
|
139
|
+
(route) => route.element !== undefined && route.path !== "*",
|
|
140
|
+
);
|
|
141
|
+
const routes = validRoutes.map((route) => ({
|
|
142
|
+
name: route.path,
|
|
143
|
+
path: route.path,
|
|
144
|
+
file: route.element.type().props["data-loc"],
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
this.iframeClient.sendAllRoutes(routes);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
triggerRoutes = () => {
|
|
151
|
+
window.dispatchEvent(
|
|
152
|
+
new CustomEvent("getroutes", {
|
|
153
|
+
detail: { routes: this.router.routes },
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
134
158
|
triggerRouteChange = () => {
|
|
135
159
|
window.dispatchEvent(
|
|
136
160
|
new CustomEvent("locationchange", {
|
|
@@ -154,18 +178,16 @@ export class ReactRouteMonitor {
|
|
|
154
178
|
const from = state.matches[0].route;
|
|
155
179
|
const fromPathname = this.router.state.location.pathname;
|
|
156
180
|
|
|
181
|
+
const routeInfo = {
|
|
182
|
+
name: toPathname,
|
|
183
|
+
path: toPathname,
|
|
184
|
+
file: to.element.type().props["data-loc"],
|
|
185
|
+
};
|
|
186
|
+
|
|
157
187
|
if (toPathname === fromPathname) {
|
|
158
|
-
this.iframeClient.sendRouteRefresh(
|
|
159
|
-
name: toPathname,
|
|
160
|
-
path: toPathname,
|
|
161
|
-
file: to.element.type().props["data-loc"],
|
|
162
|
-
});
|
|
188
|
+
this.iframeClient.sendRouteRefresh(routeInfo);
|
|
163
189
|
} else {
|
|
164
|
-
this.iframeClient.sendRouteChange(
|
|
165
|
-
name: toPathname,
|
|
166
|
-
path: toPathname,
|
|
167
|
-
file: to.element.type().props["data-loc"],
|
|
168
|
-
});
|
|
190
|
+
this.iframeClient.sendRouteChange(routeInfo);
|
|
169
191
|
}
|
|
170
192
|
};
|
|
171
193
|
|
|
@@ -215,3 +237,4 @@ const monitor = new ReactRouteMonitor({
|
|
|
215
237
|
});
|
|
216
238
|
|
|
217
239
|
monitor.start();
|
|
240
|
+
monitor.triggerRoutes();
|