@base44-preview/vite-plugin 0.2.20-pr.27.3c8770e → 0.2.20-pr.27.45bb4b6
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/bridge.d.ts +5 -17
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js +5 -30
- package/dist/bridge.js.map +1 -1
- 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 +72 -34
- 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/statics/index.mjs +1 -1
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/bridge.ts +5 -34
- package/src/html-injections-plugin.ts +96 -45
- 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/dist/injections/analytics-tracker.d.ts +0 -2
- package/dist/injections/analytics-tracker.d.ts.map +0 -1
- package/dist/injections/analytics-tracker.js +0 -40
- package/dist/injections/analytics-tracker.js.map +0 -1
- package/src/injections/analytics-tracker.ts +0 -47
package/dist/bridge.d.ts
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sandbox bridge
|
|
3
|
-
*
|
|
4
|
-
* sandbox-
|
|
2
|
+
* Sandbox bridge — bundled via tsup into dist/statics/index.mjs.
|
|
3
|
+
* Only the visual edit agent needs the bridge (for local dev iteration
|
|
4
|
+
* via ?sandbox-bridge=local). All other features load as individual
|
|
5
|
+
* sync script tags from node_modules.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
* Initialise the sandbox bridge. Called once from the injected inline script.
|
|
8
|
-
* @param options Feature flags — each defaults to enabled unless explicitly disabled.
|
|
9
|
-
* @param hmr Vite's HMR client (`import.meta.hot`), passed only in dev mode.
|
|
10
|
-
*/
|
|
11
|
-
export declare function init(options?: {
|
|
12
|
-
unhandledErrors?: boolean;
|
|
13
|
-
mountObserver?: boolean;
|
|
14
|
-
hmrNotifier?: boolean;
|
|
15
|
-
navigationNotifier?: boolean;
|
|
16
|
-
visualEditAgent?: boolean;
|
|
17
|
-
}, hmr?: {
|
|
18
|
-
on(event: string, cb: (...args: any[]) => void): void;
|
|
19
|
-
}): void;
|
|
7
|
+
export { setupVisualEditAgent } from "./injections/visual-edit-agent.js";
|
|
20
8
|
//# sourceMappingURL=bridge.d.ts.map
|
package/dist/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/bridge.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sandbox bridge
|
|
3
|
-
*
|
|
4
|
-
* sandbox-
|
|
2
|
+
* Sandbox bridge — bundled via tsup into dist/statics/index.mjs.
|
|
3
|
+
* Only the visual edit agent needs the bridge (for local dev iteration
|
|
4
|
+
* via ?sandbox-bridge=local). All other features load as individual
|
|
5
|
+
* sync script tags from node_modules.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
import { setupHmrNotifier } from "./injections/sandbox-hmr-notifier.js";
|
|
8
|
-
import { setupMountObserver } from "./injections/sandbox-mount-observer.js";
|
|
9
|
-
import { setupNavigationNotifier } from "./injections/navigation-notifier.js";
|
|
10
|
-
import { setupVisualEditAgent } from "./injections/visual-edit-agent.js";
|
|
11
|
-
/**
|
|
12
|
-
* Initialise the sandbox bridge. Called once from the injected inline script.
|
|
13
|
-
* @param options Feature flags — each defaults to enabled unless explicitly disabled.
|
|
14
|
-
* @param hmr Vite's HMR client (`import.meta.hot`), passed only in dev mode.
|
|
15
|
-
*/
|
|
16
|
-
export function init(options = {}, hmr) {
|
|
17
|
-
if (window.self === window.top)
|
|
18
|
-
return;
|
|
19
|
-
if (globalThis.__sandboxBridgeInitialized)
|
|
20
|
-
return;
|
|
21
|
-
globalThis.__sandboxBridgeInitialized = true;
|
|
22
|
-
if (options.unhandledErrors !== false)
|
|
23
|
-
setupUnhandledErrors(hmr);
|
|
24
|
-
if (options.mountObserver !== false)
|
|
25
|
-
setupMountObserver();
|
|
26
|
-
if (options.hmrNotifier && hmr)
|
|
27
|
-
setupHmrNotifier(hmr);
|
|
28
|
-
if (options.navigationNotifier)
|
|
29
|
-
setupNavigationNotifier();
|
|
30
|
-
if (options.visualEditAgent)
|
|
31
|
-
setupVisualEditAgent();
|
|
32
|
-
}
|
|
7
|
+
export { setupVisualEditAgent } from "./injections/visual-edit-agent.js";
|
|
33
8
|
//# sourceMappingURL=bridge.js.map
|
package/dist/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -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;AAwEtD,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,GAiFM,MAAM,CACZ"}
|
|
@@ -30,7 +30,41 @@ 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
|
+
analyticsTracker: {
|
|
55
|
+
injectTo: "head",
|
|
56
|
+
mode: "production",
|
|
57
|
+
inlineContent: ANALYTICS_TRACKER_SCRIPT,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
33
60
|
export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEditAgent, analyticsTracker, }) {
|
|
61
|
+
const enabledInjections = {
|
|
62
|
+
unhandledErrors: true,
|
|
63
|
+
sandboxMount: true,
|
|
64
|
+
hmrNotifier,
|
|
65
|
+
navigationNotifier,
|
|
66
|
+
analyticsTracker,
|
|
67
|
+
};
|
|
34
68
|
let resolvedEnv = {};
|
|
35
69
|
return {
|
|
36
70
|
name: "html-injections",
|
|
@@ -41,48 +75,52 @@ export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEd
|
|
|
41
75
|
},
|
|
42
76
|
transformIndexHtml: {
|
|
43
77
|
handler(_html, ctx) {
|
|
44
|
-
const tags = [];
|
|
45
78
|
const currentMode = ctx.server ? "dev" : "production";
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
79
|
+
const tags = Object.entries(INJECTIONS)
|
|
80
|
+
.filter(([key, injection]) => enabledInjections[key] && injection.mode === currentMode)
|
|
81
|
+
.map(([, injection]) => {
|
|
82
|
+
// Production injections use inline content (src paths don't work in built output)
|
|
83
|
+
if (injection.inlineContent) {
|
|
84
|
+
// Replace import.meta.env references with actual values
|
|
85
|
+
// Vite doesn't replace these in inline script content
|
|
86
|
+
let content = injection.inlineContent;
|
|
87
|
+
content = content.replace(/import\.meta\.env\.(\w+)/g, (_, envKey) => JSON.stringify(resolvedEnv[envKey] ?? ""));
|
|
88
|
+
return {
|
|
89
|
+
tag: "script",
|
|
90
|
+
attrs: { type: "module" },
|
|
91
|
+
children: content,
|
|
92
|
+
injectTo: injection.injectTo,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Dev injections use src path (served from node_modules)
|
|
96
|
+
return {
|
|
97
|
+
tag: "script",
|
|
98
|
+
attrs: {
|
|
99
|
+
src: injection.src,
|
|
100
|
+
type: "module",
|
|
101
|
+
},
|
|
102
|
+
injectTo: injection.injectTo,
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
// Visual edit agent — loaded via dynamic import to support
|
|
106
|
+
// local dev iteration with ?sandbox-bridge=local
|
|
107
|
+
if (currentMode === "dev" && visualEditAgent) {
|
|
108
|
+
const dist = "/node_modules/@base44/vite-plugin/dist";
|
|
55
109
|
tags.push({
|
|
56
110
|
tag: "script",
|
|
57
111
|
attrs: { type: "module" },
|
|
58
112
|
children: [
|
|
59
113
|
`if (window.self !== window.top) {`,
|
|
60
|
-
`
|
|
61
|
-
`
|
|
62
|
-
`
|
|
63
|
-
`
|
|
64
|
-
`
|
|
65
|
-
`
|
|
66
|
-
`
|
|
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
|
-
` })();`,
|
|
114
|
+
` const mode = new URLSearchParams(location.search).get("sandbox-bridge");`,
|
|
115
|
+
` const url = mode === "local"`,
|
|
116
|
+
` ? "https://localhost:3201/index.mjs"`,
|
|
117
|
+
` : "${dist}/statics/index.mjs";`,
|
|
118
|
+
` import(url)`,
|
|
119
|
+
` .then(mod => { if (typeof mod.setupVisualEditAgent === "function") mod.setupVisualEditAgent(); })`,
|
|
120
|
+
` .catch(e => console.error("[visual-edit-agent] Failed to load:", e));`,
|
|
72
121
|
`}`,
|
|
73
122
|
].join("\n"),
|
|
74
|
-
injectTo: "
|
|
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({
|
|
82
|
-
tag: "script",
|
|
83
|
-
attrs: { type: "module" },
|
|
84
|
-
children: content,
|
|
85
|
-
injectTo: "head",
|
|
123
|
+
injectTo: "body",
|
|
86
124
|
});
|
|
87
125
|
}
|
|
88
126
|
return tags;
|
|
@@ -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":"AACA,OAAO,EAAE,OAAO,EA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ACzB,QAAQ,EAAE;4BACR,mCAAmC;4BACnC,4EAA4E;4BAC5E,gCAAgC;4BAChC,0CAA0C;4BAC1C,UAAU,IAAI,sBAAsB;4BACpC,eAAe;4BACf,uGAAuG;4BACvG,2EAA2E;4BAC3E,GAAG;yBACJ,CAAC,IAAI,CAAC,IAAI,CAAC;wBACZ,QAAQ,EAAE,MAAM;qBACjB,CAAC,CAAC;gBACL,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;SACF;KACQ,CAAC;AACd,CAAC"}
|
|
@@ -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":"AAAA,qCAAqC;AAErC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,wBAAwB,CAAC,CAAC;AAC3E,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;AAEvD,MAAM,CAAC,gBAAgB,CA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,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE;QAC/B,aAAa,EAAE,YAAY;QAC3B,aAAa,EAAE,KAAK,CAAC,KAAK;KAC3B,CAAC,CAAC;AACL,CAAC"}
|
package/dist/statics/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(d){if(!d)return[];let h=Array.from(document.querySelectorAll(`[data-source-location="${d}"]`));return h.length>0?h:Array.from(document.querySelectorAll(`[data-visual-selector-id="${d}"]`))}function T(d,h){d.forEach(g=>{g.setAttribute("class",h)})}function V(){let d=!1,h=!1,g=!1,E=[],c=[],u=[],l=null,L=(n=!1)=>{let e=document.createElement("div");return e.style.position="absolute",e.style.pointerEvents="none",e.style.transition="all 0.1s ease-in-out",e.style.zIndex="9999",n?e.style.border="2px solid #2563EB":(e.style.border="2px solid #95a5fc",e.style.backgroundColor="rgba(99, 102, 241, 0.05)"),e},p=(n,e,t=!1)=>{if(!e||!d)return;e.offsetWidth;let s=e.getBoundingClientRect();n.style.top=`${s.top+window.scrollY}px`,n.style.left=`${s.left+window.scrollX}px`,n.style.width=`${s.width}px`,n.style.height=`${s.height}px`;let o=n.querySelector("div");o||(o=document.createElement("div"),o.textContent=e.tagName.toLowerCase(),o.style.position="absolute",o.style.top="-27px",o.style.left="-2px",o.style.padding="2px 8px",o.style.fontSize="11px",o.style.fontWeight=t?"500":"400",o.style.color=t?"#ffffff":"#526cff",o.style.backgroundColor=t?"#526cff":"#DBEAFE",o.style.borderRadius="3px",o.style.minWidth="24px",o.style.textAlign="center",n.appendChild(o))},m=()=>{E.forEach(n=>{n&&n.parentNode&&n.remove()}),E=[],u=[]},M=n=>{if(!d||h)return;let e=n.target;if(g){m();return}if(e.tagName.toLowerCase()==="path"){m();return}let t=e.closest("[data-source-location], [data-visual-selector-id]");if(!t){m();return}let a=t,s=a.dataset.sourceLocation||a.dataset.visualSelectorId;if(l===s){m();return}let o=f(s||null);m(),o.forEach(i=>{let r=L(!1);document.body.appendChild(r),E.push(r),p(r,i)}),u=o},I=()=>{h||m()},C=n=>{if(!d)return;let e=n.target;if(g){n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}if(e.tagName.toLowerCase()==="path")return;n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation();let t=e.closest("[data-source-location], [data-visual-selector-id]");if(!t)return;let a=t,s=a.dataset.sourceLocation||a.dataset.visualSelectorId;c.forEach(v=>{v&&v.parentNode&&v.remove()}),c=[],f(s||null).forEach(v=>{let y=L(!0);document.body.appendChild(y),c.push(y),p(y,v,!0)}),l=s||null,m();let i=t.getBoundingClientRect(),r={top:i.top,left:i.left,right:i.right,bottom:i.bottom,width:i.width,height:i.height,centerX:i.left+i.width/2,centerY:i.top+i.height/2},b=t,O={type:"element-selected",tagName:t.tagName,classes:b.className?.baseVal||t.className||"",visualSelectorId:s,content:t.innerText,dataSourceLocation:a.dataset.sourceLocation,isDynamicContent:a.dataset.dynamicContent==="true",linenumber:a.dataset.linenumber,filename:a.dataset.filename,position:r};window.parent.postMessage(O,"*")},H=()=>{c.forEach(n=>{n&&n.parentNode&&n.remove()}),c=[],l=null},x=(n,e)=>{let t=f(n);t.length!==0&&(T(t,e),setTimeout(()=>{l===n&&c.forEach((a,s)=>{s<t.length&&p(a,t[s])}),u.length>0&&u[0]?.dataset?.visualSelectorId===n&&E.forEach((o,i)=>{i<u.length&&p(o,u[i])})},50))},D=(n,e)=>{let t=f(n);t.length!==0&&(t.forEach(a=>{a.innerText=e}),setTimeout(()=>{l===n&&c.forEach((a,s)=>{s<t.length&&p(a,t[s])})},50))},S=n=>{d=n,n?(document.body.style.cursor="crosshair",document.addEventListener("mouseover",M),document.addEventListener("mouseout",I),document.addEventListener("click",C,!0)):(m(),c.forEach(e=>{e&&e.parentNode&&e.remove()}),c=[],u=[],l=null,document.body.style.cursor="default",document.removeEventListener("mouseover",M),document.removeEventListener("mouseout",I),document.removeEventListener("click",C,!0))},N=()=>{if(l){let n=f(l);if(n.length>0){let t=n[0].getBoundingClientRect(),a=window.innerHeight,s=window.innerWidth,o=t.top<a&&t.bottom>0&&t.left<s&&t.right>0,i={top:t.top,left:t.left,right:t.right,bottom:t.bottom,width:t.width,height:t.height,centerX:t.left+t.width/2,centerY:t.top+t.height/2};window.parent.postMessage({type:"element-position-update",position:i,isInViewport:o,visualSelectorId:l},"*")}}},k=n=>{let e=n.data;switch(e.type){case"toggle-visual-edit-mode":S(e.data.enabled);break;case"update-classes":e.data&&e.data.classes!==void 0?x(e.data.visualSelectorId,e.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",e);break;case"unselect-element":H();break;case"refresh-page":window.location.reload();break;case"update-content":e.data&&e.data.content!==void 0?D(e.data.visualSelectorId,e.data.content):console.warn("[VisualEditAgent] Invalid update-content message:",e);break;case"request-element-position":if(l){let t=f(l);if(t.length>0){let s=t[0].getBoundingClientRect(),o=window.innerHeight,i=window.innerWidth,r=s.top<o&&s.bottom>0&&s.left<i&&s.right>0,b={top:s.top,left:s.left,right:s.right,bottom:s.bottom,width:s.width,height:s.height,centerX:s.left+s.width/2,centerY:s.top+s.height/2};window.parent.postMessage({type:"element-position-update",position:b,isInViewport:r,visualSelectorId:l},"*")}}break;case"popover-drag-state":e.data&&e.data.isDragging!==void 0&&(h=e.data.isDragging,e.data.isDragging&&m());break;case"dropdown-state":e.data&&e.data.isOpen!==void 0&&(g=e.data.isOpen,e.data.isOpen&&m());break;default:break}},w=()=>{if(l){let n=f(l);c.forEach((e,t)=>{t<n.length&&p(e,n[t])})}u.length>0&&E.forEach((n,e)=>{e<u.length&&p(n,u[e])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((n,e)=>{let t=n,a=`visual-id-${t.dataset.filename}-${t.dataset.linenumber}-${e}`;t.dataset.visualSelectorId=a});let A=new MutationObserver(n=>{n.some(t=>{let a=o=>{if(o.nodeType===Node.ELEMENT_NODE){let i=o;if(i.dataset&&i.dataset.visualSelectorId)return!0;for(let r=0;r<i.children.length;r++)if(a(i.children[r]))return!0}return!1};return t.type==="attributes"&&(t.attributeName==="style"||t.attributeName==="class"||t.attributeName==="width"||t.attributeName==="height")&&a(t.target)})&&setTimeout(w,50)});window.addEventListener("message",k),window.addEventListener("scroll",N,!0),document.addEventListener("scroll",N,!0),window.addEventListener("resize",w),window.addEventListener("scroll",w),A.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{V as setupVisualEditAgent};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|