@base44-preview/vite-plugin 0.2.20-pr.27.8bf9822 → 0.2.20-pr.29.05d7fba
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/html-injections-plugin.d.ts +2 -4
- package/dist/html-injections-plugin.d.ts.map +1 -1
- package/dist/html-injections-plugin.js +65 -42
- package/dist/html-injections-plugin.js.map +1 -1
- package/dist/injections/navigation-notifier.d.ts +1 -2
- package/dist/injections/navigation-notifier.d.ts.map +1 -1
- package/dist/injections/navigation-notifier.js +2 -2
- package/dist/injections/navigation-notifier.js.map +1 -1
- package/dist/injections/sandbox-hmr-notifier.d.ts +1 -4
- package/dist/injections/sandbox-hmr-notifier.d.ts.map +1 -1
- package/dist/injections/sandbox-hmr-notifier.js +4 -4
- package/dist/injections/sandbox-hmr-notifier.js.map +1 -1
- package/dist/injections/sandbox-mount-observer.d.ts +1 -2
- package/dist/injections/sandbox-mount-observer.d.ts.map +1 -1
- package/dist/injections/sandbox-mount-observer.js +2 -2
- package/dist/injections/sandbox-mount-observer.js.map +1 -1
- package/dist/injections/unhandled-errors-handlers.d.ts +1 -4
- package/dist/injections/unhandled-errors-handlers.d.ts.map +1 -1
- package/dist/injections/unhandled-errors-handlers.js +67 -69
- package/dist/injections/unhandled-errors-handlers.js.map +1 -1
- package/dist/injections/utils.d.ts +4 -0
- package/dist/injections/utils.d.ts.map +1 -1
- package/dist/injections/utils.js +17 -0
- package/dist/injections/utils.js.map +1 -1
- package/dist/injections/visual-edit-agent.d.ts +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +33 -2
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/package.json +2 -8
- package/src/html-injections-plugin.ts +88 -53
- package/src/injections/navigation-notifier.ts +1 -2
- package/src/injections/sandbox-hmr-notifier.ts +3 -4
- package/src/injections/sandbox-mount-observer.ts +2 -2
- package/src/injections/unhandled-errors-handlers.ts +80 -84
- package/src/injections/utils.ts +20 -1
- package/src/injections/visual-edit-agent.ts +50 -3
- package/README.md +0 -93
- package/dist/bridge.d.ts +0 -20
- package/dist/bridge.d.ts.map +0 -1
- package/dist/bridge.js +0 -33
- package/dist/bridge.js.map +0 -1
- package/dist/statics/index.mjs +0 -2
- package/dist/statics/index.mjs.map +0 -1
- package/src/bridge.ts +0 -37
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
|
|
2
|
+
export declare function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEditAgent, analyticsTracker, }: {
|
|
3
3
|
hmrNotifier: boolean;
|
|
4
4
|
navigationNotifier: boolean;
|
|
5
5
|
visualEditAgent: boolean;
|
|
6
6
|
analyticsTracker: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEditAgent, analyticsTracker, }: HtmlInjectionOptions): Plugin;
|
|
9
|
-
export {};
|
|
7
|
+
}): Plugin;
|
|
10
8
|
//# sourceMappingURL=html-injections-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injections-plugin.d.ts","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"html-injections-plugin.d.ts","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AA6EtD,wBAAgB,oBAAoB,CAAC,EACnC,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,EAAE;IACD,WAAW,EAAE,OAAO,CAAC;IACrB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GA4DM,MAAM,CACZ"}
|
|
@@ -30,7 +30,47 @@ history.replaceState = function (...args) {
|
|
|
30
30
|
window.addEventListener("popstate", trackPageView);
|
|
31
31
|
trackPageView();
|
|
32
32
|
`;
|
|
33
|
+
const INJECTIONS = {
|
|
34
|
+
unhandledErrors: {
|
|
35
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/unhandled-errors-handlers.js",
|
|
36
|
+
injectTo: "head",
|
|
37
|
+
mode: "dev",
|
|
38
|
+
},
|
|
39
|
+
sandboxMount: {
|
|
40
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/sandbox-mount-observer.js",
|
|
41
|
+
injectTo: "body",
|
|
42
|
+
mode: "dev",
|
|
43
|
+
},
|
|
44
|
+
hmrNotifier: {
|
|
45
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/sandbox-hmr-notifier.js",
|
|
46
|
+
injectTo: "head",
|
|
47
|
+
mode: "dev",
|
|
48
|
+
},
|
|
49
|
+
navigationNotifier: {
|
|
50
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/navigation-notifier.js",
|
|
51
|
+
injectTo: "head",
|
|
52
|
+
mode: "dev",
|
|
53
|
+
},
|
|
54
|
+
visualEditAgent: {
|
|
55
|
+
src: "/node_modules/@base44/vite-plugin/dist/injections/visual-edit-agent.js",
|
|
56
|
+
injectTo: "body",
|
|
57
|
+
mode: "dev",
|
|
58
|
+
},
|
|
59
|
+
analyticsTracker: {
|
|
60
|
+
injectTo: "head",
|
|
61
|
+
mode: "production",
|
|
62
|
+
inlineContent: ANALYTICS_TRACKER_SCRIPT,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
33
65
|
export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEditAgent, analyticsTracker, }) {
|
|
66
|
+
const enabledInjections = {
|
|
67
|
+
unhandledErrors: true,
|
|
68
|
+
sandboxMount: true,
|
|
69
|
+
hmrNotifier,
|
|
70
|
+
navigationNotifier,
|
|
71
|
+
visualEditAgent,
|
|
72
|
+
analyticsTracker,
|
|
73
|
+
};
|
|
34
74
|
let resolvedEnv = {};
|
|
35
75
|
return {
|
|
36
76
|
name: "html-injections",
|
|
@@ -41,50 +81,33 @@ export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEd
|
|
|
41
81
|
},
|
|
42
82
|
transformIndexHtml: {
|
|
43
83
|
handler(_html, ctx) {
|
|
44
|
-
const tags = [];
|
|
45
84
|
const currentMode = ctx.server ? "dev" : "production";
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
` ? "https://localhost:3201/index.mjs"`,
|
|
65
|
-
` : "/node_modules/@base44/vite-plugin/dist/statics/index.mjs";`,
|
|
66
|
-
` const mod = await import(url);`,
|
|
67
|
-
` if (typeof mod.init === "function") mod.init(${options}, import.meta.hot);`,
|
|
68
|
-
` } catch (e) {`,
|
|
69
|
-
` console.error("[sandbox-bridge] Failed to load:", e);`,
|
|
70
|
-
` }`,
|
|
71
|
-
` })();`,
|
|
72
|
-
`}`,
|
|
73
|
-
].join("\n"),
|
|
74
|
-
injectTo: "head",
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
// Production: inline analytics tracker with env var replacement
|
|
78
|
-
if (currentMode === "production" && analyticsTracker) {
|
|
79
|
-
let content = ANALYTICS_TRACKER_SCRIPT;
|
|
80
|
-
content = content.replace(/import\.meta\.env\.(\w+)/g, (_, envKey) => JSON.stringify(resolvedEnv[envKey] ?? ""));
|
|
81
|
-
tags.push({
|
|
85
|
+
const tags = Object.entries(INJECTIONS)
|
|
86
|
+
.filter(([key, injection]) => enabledInjections[key] && injection.mode === currentMode)
|
|
87
|
+
.map(([, injection]) => {
|
|
88
|
+
// Production injections use inline content (src paths don't work in built output)
|
|
89
|
+
if (injection.inlineContent) {
|
|
90
|
+
// Replace import.meta.env references with actual values
|
|
91
|
+
// Vite doesn't replace these in inline script content
|
|
92
|
+
let content = injection.inlineContent;
|
|
93
|
+
content = content.replace(/import\.meta\.env\.(\w+)/g, (_, envKey) => JSON.stringify(resolvedEnv[envKey] ?? ""));
|
|
94
|
+
return {
|
|
95
|
+
tag: "script",
|
|
96
|
+
attrs: { type: "module" },
|
|
97
|
+
children: content,
|
|
98
|
+
injectTo: injection.injectTo,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// Dev injections use src path (served from node_modules)
|
|
102
|
+
return {
|
|
82
103
|
tag: "script",
|
|
83
|
-
attrs: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
attrs: {
|
|
105
|
+
src: injection.src,
|
|
106
|
+
type: "module",
|
|
107
|
+
},
|
|
108
|
+
injectTo: injection.injectTo,
|
|
109
|
+
};
|
|
110
|
+
});
|
|
88
111
|
return tags;
|
|
89
112
|
},
|
|
90
113
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injections-plugin.js","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"html-injections-plugin.js","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/navigation-notifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"navigation-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/navigation-notifier.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export function setupNavigationNotifier() {
|
|
1
|
+
if (window.self !== window.top) {
|
|
3
2
|
let lastUrl = window.location.href;
|
|
4
3
|
function notifyNavigation() {
|
|
5
4
|
const currentUrl = window.location.href;
|
|
@@ -31,4 +30,5 @@ export function setupNavigationNotifier() {
|
|
|
31
30
|
url: window.location.href,
|
|
32
31
|
}, "*");
|
|
33
32
|
}
|
|
33
|
+
export {};
|
|
34
34
|
//# sourceMappingURL=navigation-notifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-notifier.js","sourceRoot":"","sources":["../../src/injections/navigation-notifier.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"navigation-notifier.js","sourceRoot":"","sources":["../../src/injections/navigation-notifier.ts"],"names":[],"mappings":"AAAA,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;IAC/B,IAAI,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAEnC,SAAS,gBAAgB;QACvB,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QACxC,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;YAC3B,OAAO,GAAG,UAAU,CAAC;YACrB,MAAM,CAAC,MAAM,EAAE,WAAW,CACxB;gBACE,IAAI,EAAE,iBAAiB;gBACvB,GAAG,EAAE,UAAU;aAChB,EACD,GAAG,CACJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED,8BAA8B;IAC9B,MAAM,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1D,OAAO,CAAC,SAAS,GAAG,UAAU,GAAG,IAAI;QACnC,iBAAiB,CAAC,GAAG,IAAI,CAAC,CAAC;QAC3B,gBAAgB,EAAE,CAAC;IACrB,CAAC,CAAC;IAEF,iCAAiC;IACjC,MAAM,oBAAoB,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChE,OAAO,CAAC,YAAY,GAAG,UAAU,GAAG,IAAI;QACtC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;QAC9B,gBAAgB,EAAE,CAAC;IACrB,CAAC,CAAC;IAEF,yCAAyC;IACzC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAEtD,6BAA6B;IAC7B,MAAM,CAAC,MAAM,EAAE,WAAW,CACxB;QACE,IAAI,EAAE,iBAAiB;QACvB,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;KAC1B,EACD,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function setupHmrNotifier(hmr: {
|
|
3
|
-
on(event: string, cb: (...args: any[]) => void): void;
|
|
4
|
-
}): void;
|
|
1
|
+
export {};
|
|
5
2
|
//# sourceMappingURL=sandbox-hmr-notifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-hmr-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-hmr-notifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sandbox-hmr-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-hmr-notifier.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
hmr.on("vite:beforeUpdate", () => {
|
|
1
|
+
if (import.meta.hot) {
|
|
2
|
+
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
4
3
|
window.parent?.postMessage({ type: "sandbox:beforeUpdate" }, "*");
|
|
5
4
|
});
|
|
6
|
-
|
|
5
|
+
import.meta.hot.on("vite:afterUpdate", () => {
|
|
7
6
|
window.parent?.postMessage({ type: "sandbox:afterUpdate" }, "*");
|
|
8
7
|
});
|
|
9
8
|
}
|
|
9
|
+
export {};
|
|
10
10
|
//# sourceMappingURL=sandbox-hmr-notifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-hmr-notifier.js","sourceRoot":"","sources":["../../src/injections/sandbox-hmr-notifier.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"sandbox-hmr-notifier.js","sourceRoot":"","sources":["../../src/injections/sandbox-hmr-notifier.ts"],"names":[],"mappings":"AAAA,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC3C,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC1C,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,GAAG,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-mount-observer.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-mount-observer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sandbox-mount-observer.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-mount-observer.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export function setupMountObserver() {
|
|
1
|
+
if (window.self !== window.top) {
|
|
3
2
|
const observer = new MutationObserver((mutations) => {
|
|
4
3
|
const nodesAdded = mutations.some((mutation) => mutation.addedNodes.length > 0);
|
|
5
4
|
const nodesRemoved = mutations.some((mutation) => mutation.removedNodes.length > 0);
|
|
@@ -15,4 +14,5 @@ export function setupMountObserver() {
|
|
|
15
14
|
});
|
|
16
15
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
17
16
|
}
|
|
17
|
+
export {};
|
|
18
18
|
//# sourceMappingURL=sandbox-mount-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-mount-observer.js","sourceRoot":"","sources":["../../src/injections/sandbox-mount-observer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sandbox-mount-observer.js","sourceRoot":"","sources":["../../src/injections/sandbox-mount-observer.ts"],"names":[],"mappings":"AACA,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,CAAC,SAAS,EAAE,EAAE;QAClD,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAC/B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAC7C,CAAC;QACF,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CACjC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAC/C,CAAC;QACF,IAAI,UAAU,IAAI,YAAY,EAAE,CAAC;YAC/B,MAAM,yBAAyB,GAC7B,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAC5B,gDAAgD,CACjD,CAAC,MAAM,GAAG,CAAC,CAAC;YAEf,IAAI,yBAAyB,EAAE,CAAC;gBAC9B,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,GAAG,CAAC,CAAC;YACjE,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,GAAG,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function setupUnhandledErrors(hmr?: {
|
|
3
|
-
on(event: string, cb: (...args: any[]) => void): void;
|
|
4
|
-
}): void;
|
|
1
|
+
export {};
|
|
5
2
|
//# sourceMappingURL=unhandled-errors-handlers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unhandled-errors-handlers.d.ts","sourceRoot":"","sources":["../../src/injections/unhandled-errors-handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unhandled-errors-handlers.d.ts","sourceRoot":"","sources":["../../src/injections/unhandled-errors-handlers.ts"],"names":[],"mappings":""}
|
|
@@ -1,74 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (suppressionTimer) {
|
|
14
|
-
clearTimeout(suppressionTimer);
|
|
15
|
-
}
|
|
16
|
-
suppressionTimer = setTimeout(() => {
|
|
17
|
-
shouldPropagateErrors = true;
|
|
18
|
-
suppressionTimer = null;
|
|
19
|
-
}, ERROR_SUPPRESSION_TIMEOUT);
|
|
20
|
-
});
|
|
21
|
-
hmr.on("vite:beforeFullReload", () => {
|
|
22
|
-
shouldPropagateErrors = false;
|
|
23
|
-
if (suppressionTimer) {
|
|
24
|
-
clearTimeout(suppressionTimer);
|
|
25
|
-
suppressionTimer = null;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function onAppError({ title, details, componentName, originalError, }) {
|
|
30
|
-
if (originalError?.response?.status === 402 || !shouldPropagateErrors) {
|
|
31
|
-
return;
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
window.removeEventListener("unhandledrejection", handleUnhandledRejection);
|
|
3
|
+
window.removeEventListener("error", handleWindowError);
|
|
4
|
+
window.addEventListener("unhandledrejection", handleUnhandledRejection);
|
|
5
|
+
window.addEventListener("error", handleWindowError);
|
|
6
|
+
let shouldPropagateErrors = true;
|
|
7
|
+
let suppressionTimer = null;
|
|
8
|
+
if (import.meta.hot) {
|
|
9
|
+
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
10
|
+
shouldPropagateErrors = false;
|
|
11
|
+
if (suppressionTimer) {
|
|
12
|
+
clearTimeout(suppressionTimer);
|
|
32
13
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function handleUnhandledRejection(event) {
|
|
44
|
-
const stack = event.reason.stack;
|
|
45
|
-
// extract function name from "at X (eval" where x is the function name
|
|
46
|
-
const functionName = stack.match(/at\s+(\w+)\s+\(eval/)?.[1];
|
|
47
|
-
const msg = functionName
|
|
48
|
-
? `Error in ${functionName}: ${event.reason.toString()}`
|
|
49
|
-
: event.reason.toString();
|
|
50
|
-
onAppError({
|
|
51
|
-
title: msg,
|
|
52
|
-
details: event.reason.toString(),
|
|
53
|
-
componentName: functionName,
|
|
54
|
-
originalError: event.reason,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function handleWindowError(event) {
|
|
58
|
-
const stack = event.error?.stack;
|
|
59
|
-
let functionName = stack.match(/at\s+(\w+)\s+\(eval/)?.[1];
|
|
60
|
-
if (functionName === "eval") {
|
|
61
|
-
functionName = null;
|
|
14
|
+
suppressionTimer = setTimeout(() => {
|
|
15
|
+
shouldPropagateErrors = true;
|
|
16
|
+
suppressionTimer = null;
|
|
17
|
+
}, import.meta.env.VITE_HMR_ERROR_SUPPRESSION_DELAY ?? 10000);
|
|
18
|
+
});
|
|
19
|
+
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
20
|
+
shouldPropagateErrors = false;
|
|
21
|
+
if (suppressionTimer) {
|
|
22
|
+
clearTimeout(suppressionTimer);
|
|
23
|
+
suppressionTimer = null;
|
|
62
24
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function onAppError({ title, details, componentName, originalError, }) {
|
|
28
|
+
if (originalError?.response?.status === 402 || !shouldPropagateErrors) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
window.parent?.postMessage({
|
|
32
|
+
type: "app_error",
|
|
33
|
+
error: {
|
|
34
|
+
title: title.toString(),
|
|
35
|
+
details: details?.toString(),
|
|
36
|
+
componentName: componentName?.toString(),
|
|
37
|
+
stack: originalError?.stack?.toString(),
|
|
38
|
+
},
|
|
39
|
+
}, "*");
|
|
40
|
+
}
|
|
41
|
+
function handleUnhandledRejection(event) {
|
|
42
|
+
const stack = event.reason.stack;
|
|
43
|
+
// extract function name from "at X (eval" where x is the function name
|
|
44
|
+
const functionName = stack.match(/at\s+(\w+)\s+\(eval/)?.[1];
|
|
45
|
+
const msg = functionName
|
|
46
|
+
? `Error in ${functionName}: ${event.reason.toString()}`
|
|
47
|
+
: event.reason.toString();
|
|
48
|
+
onAppError({
|
|
49
|
+
title: msg,
|
|
50
|
+
details: event.reason.toString(),
|
|
51
|
+
componentName: functionName,
|
|
52
|
+
originalError: event.reason,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function handleWindowError(event) {
|
|
56
|
+
const stack = event.error?.stack;
|
|
57
|
+
let functionName = stack.match(/at\s+(\w+)\s+\(eval/)?.[1];
|
|
58
|
+
if (functionName === "eval") {
|
|
59
|
+
functionName = null;
|
|
72
60
|
}
|
|
61
|
+
const msg = functionName
|
|
62
|
+
? `in ${functionName}: ${event.error.toString()}`
|
|
63
|
+
: event.error.toString();
|
|
64
|
+
onAppError({
|
|
65
|
+
title: msg,
|
|
66
|
+
details: event.error.toString(),
|
|
67
|
+
componentName: functionName,
|
|
68
|
+
originalError: event.error,
|
|
69
|
+
});
|
|
73
70
|
}
|
|
71
|
+
export {};
|
|
74
72
|
//# sourceMappingURL=unhandled-errors-handlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unhandled-errors-handlers.js","sourceRoot":"","sources":["../../src/injections/unhandled-errors-handlers.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"unhandled-errors-handlers.js","sourceRoot":"","sources":["../../src/injections/unhandled-errors-handlers.ts"],"names":[],"mappings":"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"}
|
|
@@ -5,4 +5,8 @@ export declare function findElementsById(id: string | null): Element[];
|
|
|
5
5
|
* Uses setAttribute instead of className to support both HTML and SVG elements.
|
|
6
6
|
*/
|
|
7
7
|
export declare function updateElementClasses(elements: Element[], classes: string): void;
|
|
8
|
+
/** Set a single attribute on all provided elements. */
|
|
9
|
+
export declare function updateElementAttribute(elements: Element[], attribute: string, value: string): void;
|
|
10
|
+
/** Collect attribute values from an element for a given allowlist. */
|
|
11
|
+
export declare function collectAllowedAttributes(element: Element, allowedAttributes: string[]): Record<string, string>;
|
|
8
12
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/injections/utils.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE,CAW7D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAI/E"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/injections/utils.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE,CAW7D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAI/E;AAED,uDAAuD;AACvD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIlG;AAED,sEAAsE;AACtE,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAS9G"}
|
package/dist/injections/utils.js
CHANGED
|
@@ -17,4 +17,21 @@ export function updateElementClasses(elements, classes) {
|
|
|
17
17
|
element.setAttribute("class", classes);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
/** Set a single attribute on all provided elements. */
|
|
21
|
+
export function updateElementAttribute(elements, attribute, value) {
|
|
22
|
+
elements.forEach((element) => {
|
|
23
|
+
element.setAttribute(attribute, value);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Collect attribute values from an element for a given allowlist. */
|
|
27
|
+
export function collectAllowedAttributes(element, allowedAttributes) {
|
|
28
|
+
const attributes = {};
|
|
29
|
+
for (const attr of allowedAttributes) {
|
|
30
|
+
const val = element.getAttribute(attr);
|
|
31
|
+
if (val !== null) {
|
|
32
|
+
attributes[attr] = val;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return attributes;
|
|
36
|
+
}
|
|
20
37
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/injections/utils.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,UAAU,gBAAgB,CAAC,EAAiB;IAChD,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC;IACnB,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAC/B,QAAQ,CAAC,gBAAgB,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAC5D,CAAC;IACF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CACf,QAAQ,CAAC,gBAAgB,CAAC,6BAA6B,EAAE,IAAI,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAmB,EAAE,OAAe;IACvE,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/injections/utils.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,UAAU,gBAAgB,CAAC,EAAiB;IAChD,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC;IACnB,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAC/B,QAAQ,CAAC,gBAAgB,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAC5D,CAAC;IACF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CACf,QAAQ,CAAC,gBAAgB,CAAC,6BAA6B,EAAE,IAAI,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAmB,EAAE,OAAe;IACvE,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,sBAAsB,CAAC,QAAmB,EAAE,SAAiB,EAAE,KAAa;IAC1F,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,wBAAwB,CAAC,OAAgB,EAAE,iBAA2B;IACpF,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,UAAU,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=visual-edit-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-edit-agent.d.ts","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"visual-edit-agent.d.ts","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { findElementsById, updateElementClasses } from "./utils.js";
|
|
2
|
-
|
|
1
|
+
import { findElementsById, updateElementClasses, updateElementAttribute, collectAllowedAttributes } from "./utils.js";
|
|
2
|
+
if (window.self !== window.top) {
|
|
3
3
|
// State variables (replacing React useState/useRef)
|
|
4
4
|
let isVisualEditMode = false;
|
|
5
5
|
let isPopoverDragging = false;
|
|
@@ -174,6 +174,9 @@ export function setupVisualEditAgent() {
|
|
|
174
174
|
centerX: rect.left + rect.width / 2,
|
|
175
175
|
centerY: rect.top + rect.height / 2,
|
|
176
176
|
};
|
|
177
|
+
// Collect allowed element attributes
|
|
178
|
+
const ALLOWED_ATTRIBUTES = ["src"];
|
|
179
|
+
const attributes = collectAllowedAttributes(element, ALLOWED_ATTRIBUTES);
|
|
177
180
|
// Send message to parent window with element info including position
|
|
178
181
|
const svgElement = element;
|
|
179
182
|
const elementData = {
|
|
@@ -189,6 +192,7 @@ export function setupVisualEditAgent() {
|
|
|
189
192
|
linenumber: htmlElement.dataset.linenumber,
|
|
190
193
|
filename: htmlElement.dataset.filename,
|
|
191
194
|
position: elementPosition,
|
|
195
|
+
attributes,
|
|
192
196
|
};
|
|
193
197
|
window.parent.postMessage(elementData, "*");
|
|
194
198
|
};
|
|
@@ -231,6 +235,23 @@ export function setupVisualEditAgent() {
|
|
|
231
235
|
}
|
|
232
236
|
}, 50);
|
|
233
237
|
};
|
|
238
|
+
// Update element attribute by visual selector ID
|
|
239
|
+
const updateElementAttributeAndReposition = (visualSelectorId, attribute, value) => {
|
|
240
|
+
const elements = findElementsById(visualSelectorId);
|
|
241
|
+
if (elements.length === 0)
|
|
242
|
+
return;
|
|
243
|
+
updateElementAttribute(elements, attribute, value);
|
|
244
|
+
// Reposition overlays after attribute change (e.g. image src swap can affect layout)
|
|
245
|
+
setTimeout(() => {
|
|
246
|
+
if (selectedElementId === visualSelectorId) {
|
|
247
|
+
selectedOverlays.forEach((overlay, index) => {
|
|
248
|
+
if (index < elements.length) {
|
|
249
|
+
positionOverlay(overlay, elements[index]);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}, 50);
|
|
254
|
+
};
|
|
234
255
|
// Update element content by visual selector ID
|
|
235
256
|
const updateElementContent = (visualSelectorId, content) => {
|
|
236
257
|
const elements = findElementsById(visualSelectorId);
|
|
@@ -322,6 +343,16 @@ export function setupVisualEditAgent() {
|
|
|
322
343
|
console.warn("[VisualEditAgent] Invalid update-classes message:", message);
|
|
323
344
|
}
|
|
324
345
|
break;
|
|
346
|
+
case "update-attribute":
|
|
347
|
+
if (message.data &&
|
|
348
|
+
message.data.attribute !== undefined &&
|
|
349
|
+
message.data.value !== undefined) {
|
|
350
|
+
updateElementAttributeAndReposition(message.data.visualSelectorId, message.data.attribute, message.data.value);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
console.warn("[VisualEditAgent] Invalid update-attribute message:", message);
|
|
354
|
+
}
|
|
355
|
+
break;
|
|
325
356
|
case "unselect-element":
|
|
326
357
|
unselectElement();
|
|
327
358
|
break;
|