@shaper.org/vite-react-plugin 1.0.13 → 1.0.15
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.mjs +34 -8
- package/package.json +1 -1
- package/templates/main.ts +3 -32
package/dist/index.mjs
CHANGED
|
@@ -1799,14 +1799,40 @@ function jsxSourcePlugin(options = {}) {
|
|
|
1799
1799
|
runtime: "automatic"
|
|
1800
1800
|
}], "@babel/preset-typescript"],
|
|
1801
1801
|
plugins: [function injectSourceFile() {
|
|
1802
|
-
return { visitor: {
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1802
|
+
return { visitor: {
|
|
1803
|
+
Program(programPath, state) {
|
|
1804
|
+
const root = state.file.opts.root;
|
|
1805
|
+
const filename = state.file.opts.filename;
|
|
1806
|
+
const relativeFilename = PathUtil.relative(root, filename);
|
|
1807
|
+
const injected = /* @__PURE__ */ new Set();
|
|
1808
|
+
function injectAtProgramEnd(name) {
|
|
1809
|
+
if (injected.has(name)) return;
|
|
1810
|
+
injected.add(name);
|
|
1811
|
+
programPath.pushContainer("body", t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier(name), t.identifier("__file")), t.stringLiteral(relativeFilename))));
|
|
1812
|
+
}
|
|
1813
|
+
programPath.traverse({
|
|
1814
|
+
ExportNamedDeclaration(path) {
|
|
1815
|
+
const decl = path.node.declaration;
|
|
1816
|
+
if (t.isFunctionDeclaration(decl) && decl.id) injectAtProgramEnd(decl.id.name);
|
|
1817
|
+
if (t.isVariableDeclaration(decl)) {
|
|
1818
|
+
for (const d of decl.declarations) if (t.isIdentifier(d.id) && (t.isArrowFunctionExpression(d.init) || t.isFunctionExpression(d.init))) injectAtProgramEnd(d.id.name);
|
|
1819
|
+
}
|
|
1820
|
+
},
|
|
1821
|
+
ExportDefaultDeclaration(path) {
|
|
1822
|
+
const decl = path.node.declaration;
|
|
1823
|
+
if (t.isIdentifier(decl)) injectAtProgramEnd(decl.name);
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
1826
|
+
},
|
|
1827
|
+
JSXOpeningElement(path, state) {
|
|
1828
|
+
const root = state.file.opts.root;
|
|
1829
|
+
const filename = state.file.opts.filename;
|
|
1830
|
+
const relativeFilename = PathUtil.relative(root, filename);
|
|
1831
|
+
const { line, column } = path.node.loc.start;
|
|
1832
|
+
const attr = t.jsxAttribute(t.jsxIdentifier("data-loc"), t.stringLiteral(`${relativeFilename}:${line}:${column}`));
|
|
1833
|
+
path.node.attributes.push(attr);
|
|
1834
|
+
}
|
|
1835
|
+
} };
|
|
1810
1836
|
}]
|
|
1811
1837
|
});
|
|
1812
1838
|
if (!result) return null;
|
package/package.json
CHANGED
package/templates/main.ts
CHANGED
|
@@ -104,17 +104,6 @@ export class ReactRouteMonitor {
|
|
|
104
104
|
|
|
105
105
|
this.sendAllRoutes = this.sendAllRoutes.bind(this);
|
|
106
106
|
window.addEventListener("getroutes", this.sendAllRoutes);
|
|
107
|
-
|
|
108
|
-
this.iframeClient.onMessage((event) => {
|
|
109
|
-
const messageData = event.data;
|
|
110
|
-
if (messageData.type == "push-route") {
|
|
111
|
-
history.pushState(
|
|
112
|
-
{ type: "from-iframe-parent" },
|
|
113
|
-
"",
|
|
114
|
-
messageData.message.path,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
107
|
}
|
|
119
108
|
|
|
120
109
|
stop() {
|
|
@@ -133,13 +122,8 @@ export class ReactRouteMonitor {
|
|
|
133
122
|
|
|
134
123
|
patchHistory() {
|
|
135
124
|
history.pushState = (...args) => {
|
|
136
|
-
let shouldTrigger = true;
|
|
137
|
-
if (args[0] && args[0].type === "from-iframe-parent") {
|
|
138
|
-
args[0] = {};
|
|
139
|
-
shouldTrigger = false;
|
|
140
|
-
}
|
|
141
125
|
this.origPush.apply(history, args);
|
|
142
|
-
|
|
126
|
+
this.triggerRouteChange();
|
|
143
127
|
};
|
|
144
128
|
|
|
145
129
|
history.replaceState = (...args) => {
|
|
@@ -154,10 +138,11 @@ export class ReactRouteMonitor {
|
|
|
154
138
|
const validRoutes = event.detail.routes.filter(
|
|
155
139
|
(route) => route.element !== undefined && route.path !== "*",
|
|
156
140
|
);
|
|
141
|
+
|
|
157
142
|
const routes = validRoutes.map((route) => ({
|
|
158
143
|
name: route.path,
|
|
159
144
|
path: route.path,
|
|
160
|
-
file: route.element.type
|
|
145
|
+
file: route.element.type.__file,
|
|
161
146
|
}));
|
|
162
147
|
|
|
163
148
|
this.iframeClient.sendAllRoutes(routes);
|
|
@@ -254,17 +239,3 @@ const monitor = new ReactRouteMonitor({
|
|
|
254
239
|
|
|
255
240
|
monitor.start();
|
|
256
241
|
monitor.triggerRoutes();
|
|
257
|
-
|
|
258
|
-
// // simulate parent message
|
|
259
|
-
// setTimeout(() => {
|
|
260
|
-
// console.log("Simulating parent message");
|
|
261
|
-
// window.dispatchEvent(
|
|
262
|
-
// new MessageEvent("message", {
|
|
263
|
-
// data: {
|
|
264
|
-
// type: "push-route",
|
|
265
|
-
// message: { path: "/test" },
|
|
266
|
-
// },
|
|
267
|
-
// origin: "http://localhost:5173",
|
|
268
|
-
// }),
|
|
269
|
-
// );
|
|
270
|
-
// }, 1000);
|