@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.
Files changed (38) hide show
  1. package/dist/bridge.d.ts +5 -17
  2. package/dist/bridge.d.ts.map +1 -1
  3. package/dist/bridge.js +5 -30
  4. package/dist/bridge.js.map +1 -1
  5. package/dist/html-injections-plugin.d.ts +2 -4
  6. package/dist/html-injections-plugin.d.ts.map +1 -1
  7. package/dist/html-injections-plugin.js +72 -34
  8. package/dist/html-injections-plugin.js.map +1 -1
  9. package/dist/injections/navigation-notifier.d.ts +1 -2
  10. package/dist/injections/navigation-notifier.d.ts.map +1 -1
  11. package/dist/injections/navigation-notifier.js +2 -2
  12. package/dist/injections/navigation-notifier.js.map +1 -1
  13. package/dist/injections/sandbox-hmr-notifier.d.ts +1 -4
  14. package/dist/injections/sandbox-hmr-notifier.d.ts.map +1 -1
  15. package/dist/injections/sandbox-hmr-notifier.js +4 -4
  16. package/dist/injections/sandbox-hmr-notifier.js.map +1 -1
  17. package/dist/injections/sandbox-mount-observer.d.ts +1 -2
  18. package/dist/injections/sandbox-mount-observer.d.ts.map +1 -1
  19. package/dist/injections/sandbox-mount-observer.js +2 -2
  20. package/dist/injections/sandbox-mount-observer.js.map +1 -1
  21. package/dist/injections/unhandled-errors-handlers.d.ts +1 -4
  22. package/dist/injections/unhandled-errors-handlers.d.ts.map +1 -1
  23. package/dist/injections/unhandled-errors-handlers.js +67 -69
  24. package/dist/injections/unhandled-errors-handlers.js.map +1 -1
  25. package/dist/statics/index.mjs +1 -1
  26. package/dist/statics/index.mjs.map +1 -1
  27. package/package.json +1 -1
  28. package/src/bridge.ts +5 -34
  29. package/src/html-injections-plugin.ts +96 -45
  30. package/src/injections/navigation-notifier.ts +1 -2
  31. package/src/injections/sandbox-hmr-notifier.ts +3 -4
  32. package/src/injections/sandbox-mount-observer.ts +2 -2
  33. package/src/injections/unhandled-errors-handlers.ts +80 -84
  34. package/dist/injections/analytics-tracker.d.ts +0 -2
  35. package/dist/injections/analytics-tracker.d.ts.map +0 -1
  36. package/dist/injections/analytics-tracker.js +0 -40
  37. package/dist/injections/analytics-tracker.js.map +0 -1
  38. package/src/injections/analytics-tracker.ts +0 -47
package/dist/bridge.d.ts CHANGED
@@ -1,20 +1,8 @@
1
1
  /**
2
- * Sandbox bridge entry point dynamically imported by the inline script
3
- * injected via html-injections-plugin. Conditionally initialises each
4
- * sandbox-side feature based on the supplied options.
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
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,OAAO,GAAE;IACP,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;CACtB,EACN,GAAG,CAAC,EAAE;IAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;CAAE,QAWhE"}
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 entry point dynamically imported by the inline script
3
- * injected via html-injections-plugin. Conditionally initialises each
4
- * sandbox-side feature based on the supplied options.
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
- import { setupUnhandledErrors } from "./injections/unhandled-errors-handlers.js";
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
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAClB,UAMI,EAAE,EACN,GAA+D;IAE/D,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG;QAAE,OAAO;IACvC,IAAK,UAAkB,CAAC,0BAA0B;QAAE,OAAO;IAC1D,UAAkB,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAEtD,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK;QAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACjE,IAAI,OAAO,CAAC,aAAa,KAAK,KAAK;QAAE,kBAAkB,EAAE,CAAC;IAC1D,IAAI,OAAO,CAAC,WAAW,IAAI,GAAG;QAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtD,IAAI,OAAO,CAAC,kBAAkB;QAAE,uBAAuB,EAAE,CAAC;IAC1D,IAAI,OAAO,CAAC,eAAe;QAAE,oBAAoB,EAAE,CAAC;AACtD,CAAC"}
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
- interface HtmlInjectionOptions {
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;AAmCtD,UAAU,oBAAoB;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,oBAAoB,CAAC,EACnC,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,EAAE,oBAAoB,GAAG,MAAM,CAkE/B"}
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
- if (currentMode === "dev") {
47
- // Dev mode: use sandbox-bridge dynamic loader
48
- const options = JSON.stringify({
49
- hmrNotifier,
50
- navigationNotifier,
51
- visualEditAgent,
52
- unhandledErrors: true,
53
- mountObserver: true,
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
- ` (async () => {`,
61
- ` try {`,
62
- ` const mode = new URLSearchParams(location.search).get("sandbox-bridge");`,
63
- ` const url = mode === "local"`,
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
- ` })();`,
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: "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({
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;AAE/B,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BhC,CAAC;AASF,MAAM,UAAU,oBAAoB,CAAC,EACnC,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACK;IACrB,IAAI,WAAW,GAA2B,EAAE,CAAC;IAE7C,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,cAAc,CAAC,MAAM;YACnB,iDAAiD;YACjD,0DAA0D;YAC1D,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,kBAAkB,EAAE;YAClB,OAAO,CAAC,KAAK,EAAE,GAAG;gBAChB,MAAM,IAAI,GAAwB,EAAE,CAAC;gBACrC,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;gBAEtD,IAAI,WAAW,KAAK,KAAK,EAAE,CAAC;oBAC1B,8CAA8C;oBAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;wBAC7B,WAAW;wBACX,kBAAkB;wBAClB,eAAe;wBACf,eAAe,EAAE,IAAI;wBACrB,aAAa,EAAE,IAAI;qBACpB,CAAC,CAAC;oBACH,IAAI,CAAC,IAAI,CAAC;wBACR,GAAG,EAAE,QAAQ;wBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,QAAQ,EAAE;4BACR,mCAAmC;4BACnC,kBAAkB;4BAClB,WAAW;4BACX,gFAAgF;4BAChF,oCAAoC;4BACpC,8CAA8C;4BAC9C,uEAAuE;4BACvE,sCAAsC;4BACtC,sDAAsD,OAAO,qBAAqB;4BAClF,mBAAmB;4BACnB,6DAA6D;4BAC7D,OAAO;4BACP,SAAS;4BACT,GAAG;yBACJ,CAAC,IAAI,CAAC,IAAI,CAAC;wBACZ,QAAQ,EAAE,MAAM;qBACjB,CAAC,CAAC;gBACL,CAAC;gBAED,gEAAgE;gBAChE,IAAI,WAAW,KAAK,YAAY,IAAI,gBAAgB,EAAE,CAAC;oBACrD,IAAI,OAAO,GAAG,wBAAwB,CAAC;oBACvC,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,2BAA2B,EAC3B,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CACzD,CAAC;oBACF,IAAI,CAAC,IAAI,CAAC;wBACR,GAAG,EAAE,QAAQ;wBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,QAAQ,EAAE,OAAO;wBACjB,QAAQ,EAAE,MAAM;qBACjB,CAAC,CAAC;gBACL,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
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;AAW/B,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BhC,CAAC;AAEF,MAAM,UAAU,GAA8B;IAC5C,eAAe,EAAE;QACf,GAAG,EAAE,gFAAgF;QACrF,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,YAAY,EAAE;QACZ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AAC;gBACL,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;SACF;KACQ,CAAC;AACd,CAAC"}
@@ -1,3 +1,2 @@
1
- /** Intercept pushState / replaceState / popstate and notify the parent of URL changes. */
2
- export declare function setupNavigationNotifier(): void;
1
+ export {};
3
2
  //# sourceMappingURL=navigation-notifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"navigation-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/navigation-notifier.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,wBAAgB,uBAAuB,SA0CtC"}
1
+ {"version":3,"file":"navigation-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/navigation-notifier.ts"],"names":[],"mappings":""}
@@ -1,5 +1,4 @@
1
- /** Intercept pushState / replaceState / popstate and notify the parent of URL changes. */
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,0FAA0F;AAC1F,MAAM,UAAU,uBAAuB;IACrC,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,C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ACH,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
- /** Forward Vite HMR lifecycle events (beforeUpdate / afterUpdate) to the parent window. */
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":"AAAA,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAAC,GAAG,EAAE;IAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;CAAE,QAO9F"}
1
+ {"version":3,"file":"sandbox-hmr-notifier.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-hmr-notifier.ts"],"names":[],"mappings":""}
@@ -1,10 +1,10 @@
1
- /** Forward Vite HMR lifecycle events (beforeUpdate / afterUpdate) to the parent window. */
2
- export function setupHmrNotifier(hmr) {
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
- hmr.on("vite:afterUpdate", () => {
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,2FAA2F;AAC3F,MAAM,UAAU,gBAAgB,CAAC,GAA8D;IAC7F,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC/B,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC9B,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,GAAG,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC"}
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,3 +1,2 @@
1
- /** Observe DOM mutations and notify the parent when instrumented elements are mounted or unmounted. */
2
- export declare function setupMountObserver(): void;
1
+ export {};
3
2
  //# sourceMappingURL=sandbox-mount-observer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-mount-observer.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-mount-observer.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,wBAAgB,kBAAkB,SAuBjC"}
1
+ {"version":3,"file":"sandbox-mount-observer.d.ts","sourceRoot":"","sources":["../../src/injections/sandbox-mount-observer.ts"],"names":[],"mappings":""}
@@ -1,5 +1,4 @@
1
- /** Observe DOM mutations and notify the parent when instrumented elements are mounted or unmounted. */
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":"AAAA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,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
- /** Register global error and unhandled-rejection listeners that report to the parent window. */
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":"AAAA,gGAAgG;AAIhG,wBAAgB,oBAAoB,CAAC,GAAG,CAAC,EAAE;IAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;CAAE,QA4FnG"}
1
+ {"version":3,"file":"unhandled-errors-handlers.d.ts","sourceRoot":"","sources":["../../src/injections/unhandled-errors-handlers.ts"],"names":[],"mappings":""}
@@ -1,74 +1,72 @@
1
- /** Register global error and unhandled-rejection listeners that report to the parent window. */
2
- const ERROR_SUPPRESSION_TIMEOUT = 10000;
3
- export function setupUnhandledErrors(hmr) {
4
- window.removeEventListener("unhandledrejection", handleUnhandledRejection);
5
- window.removeEventListener("error", handleWindowError);
6
- window.addEventListener("unhandledrejection", handleUnhandledRejection);
7
- window.addEventListener("error", handleWindowError);
8
- let shouldPropagateErrors = true;
9
- let suppressionTimer = null;
10
- if (hmr) {
11
- hmr.on("vite:beforeUpdate", () => {
12
- shouldPropagateErrors = false;
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
- window.parent?.postMessage({
34
- type: "app_error",
35
- error: {
36
- title: title.toString(),
37
- details: details?.toString(),
38
- componentName: componentName?.toString(),
39
- stack: originalError?.stack?.toString(),
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
- const msg = functionName
64
- ? `in ${functionName}: ${event.error.toString()}`
65
- : event.error.toString();
66
- onAppError({
67
- title: msg,
68
- details: event.error.toString(),
69
- componentName: functionName,
70
- originalError: event.error,
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,gGAAgG;AAEhG,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAExC,MAAM,UAAU,oBAAoB,CAAC,GAA+D;IAClG,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,wBAAwB,CAAC,CAAC;IAC3E,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAEvD,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,wBAAwB,CAAC,CAAC;IACxE,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAEpD,IAAI,qBAAqB,GAAG,IAAI,CAAC;IACjC,IAAI,gBAAgB,GAAyC,IAAI,CAAC;IAElE,IAAI,GAAG,EAAE,CAAC;QACR,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC/B,qBAAqB,GAAG,KAAK,CAAC;YAE9B,IAAI,gBAAgB,EAAE,CAAC;gBACrB,YAAY,CAAC,gBAAgB,CAAC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B,aAAa,EAAE,YAAY;QAC3B,aAAa,EAAE,KAAK,CAAC,KAAK;KAC3B,CAAC,CAAC;AACL,CAAC"}
@@ -1,2 +1,2 @@
1
- function I(r){window.removeEventListener("unhandledrejection",a),window.removeEventListener("error",f),window.addEventListener("unhandledrejection",a),window.addEventListener("error",f);let d=!0,p=null;r&&(r.on("vite:beforeUpdate",()=>{d=!1,p&&clearTimeout(p),p=setTimeout(()=>{d=!0,p=null},1e4)}),r.on("vite:beforeFullReload",()=>{d=!1,p&&(clearTimeout(p),p=null)}));function g({title:s,details:w,componentName:u,originalError:m}){m?.response?.status===402||!d||window.parent?.postMessage({type:"app_error",error:{title:s.toString(),details:w?.toString(),componentName:u?.toString(),stack:m?.stack?.toString()}},"*")}function a(s){let u=s.reason.stack.match(/at\s+(\w+)\s+\(eval/)?.[1],m=u?`Error in ${u}: ${s.reason.toString()}`:s.reason.toString();g({title:m,details:s.reason.toString(),componentName:u,originalError:s.reason})}function f(s){let u=(s.error?.stack).match(/at\s+(\w+)\s+\(eval/)?.[1];u==="eval"&&(u=null);let m=u?`in ${u}: ${s.error.toString()}`:s.error.toString();g({title:m,details:s.error.toString(),componentName:u,originalError:s.error})}}function x(r){r.on("vite:beforeUpdate",()=>{window.parent?.postMessage({type:"sandbox:beforeUpdate"},"*")}),r.on("vite:afterUpdate",()=>{window.parent?.postMessage({type:"sandbox:afterUpdate"},"*")})}function O(){new MutationObserver(d=>{let p=d.some(a=>a.addedNodes.length>0),g=d.some(a=>a.removedNodes.length>0);(p||g)&&(document.body.querySelectorAll("[data-source-location], [data-dynamic-content]").length>0?window.parent?.postMessage({type:"sandbox:onMounted"},"*"):window.parent?.postMessage({type:"sandbox:onUnmounted"},"*"))}).observe(document.body,{childList:!0,subtree:!0})}function k(){let r=window.location.href;function d(){let a=window.location.href;a!==r&&(r=a,window.parent?.postMessage({type:"app_changed_url",url:a},"*"))}let p=history.pushState.bind(history);history.pushState=function(...a){p(...a),d()};let g=history.replaceState.bind(history);history.replaceState=function(...a){g(...a),d()},window.addEventListener("popstate",d),window.parent?.postMessage({type:"app_changed_url",url:window.location.href},"*")}function E(r){if(!r)return[];let d=Array.from(document.querySelectorAll(`[data-source-location="${r}"]`));return d.length>0?d:Array.from(document.querySelectorAll(`[data-visual-selector-id="${r}"]`))}function C(r,d){r.forEach(p=>{p.setAttribute("class",d)})}function A(){let r=!1,d=!1,p=!1,g=[],a=[],f=[],s=null,w=(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},u=(n,e,t=!1)=>{if(!e||!r)return;e.offsetWidth;let o=e.getBoundingClientRect();n.style.top=`${o.top+window.scrollY}px`,n.style.left=`${o.left+window.scrollX}px`,n.style.width=`${o.width}px`,n.style.height=`${o.height}px`;let i=n.querySelector("div");i||(i=document.createElement("div"),i.textContent=e.tagName.toLowerCase(),i.style.position="absolute",i.style.top="-27px",i.style.left="-2px",i.style.padding="2px 8px",i.style.fontSize="11px",i.style.fontWeight=t?"500":"400",i.style.color=t?"#ffffff":"#526cff",i.style.backgroundColor=t?"#526cff":"#DBEAFE",i.style.borderRadius="3px",i.style.minWidth="24px",i.style.textAlign="center",n.appendChild(i))},m=()=>{g.forEach(n=>{n&&n.parentNode&&n.remove()}),g=[],f=[]},N=n=>{if(!r||d)return;let e=n.target;if(p){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 l=t,o=l.dataset.sourceLocation||l.dataset.visualSelectorId;if(s===o){m();return}let i=E(o||null);m(),i.forEach(c=>{let h=w(!1);document.body.appendChild(h),g.push(h),u(h,c)}),f=i},M=()=>{d||m()},S=n=>{if(!r)return;let e=n.target;if(p){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 l=t,o=l.dataset.sourceLocation||l.dataset.visualSelectorId;a.forEach(v=>{v&&v.parentNode&&v.remove()}),a=[],E(o||null).forEach(v=>{let L=w(!0);document.body.appendChild(L),a.push(L),u(L,v,!0)}),s=o||null,m();let c=t.getBoundingClientRect(),h={top:c.top,left:c.left,right:c.right,bottom:c.bottom,width:c.width,height:c.height,centerX:c.left+c.width/2,centerY:c.top+c.height/2},y=t,_={type:"element-selected",tagName:t.tagName,classes:y.className?.baseVal||t.className||"",visualSelectorId:o,content:t.innerText,dataSourceLocation:l.dataset.sourceLocation,isDynamicContent:l.dataset.dynamicContent==="true",linenumber:l.dataset.linenumber,filename:l.dataset.filename,position:h};window.parent.postMessage(_,"*")},H=()=>{a.forEach(n=>{n&&n.parentNode&&n.remove()}),a=[],s=null},R=(n,e)=>{let t=E(n);t.length!==0&&(C(t,e),setTimeout(()=>{s===n&&a.forEach((l,o)=>{o<t.length&&u(l,t[o])}),f.length>0&&f[0]?.dataset?.visualSelectorId===n&&g.forEach((i,c)=>{c<f.length&&u(i,f[c])})},50))},D=(n,e)=>{let t=E(n);t.length!==0&&(t.forEach(l=>{l.innerText=e}),setTimeout(()=>{s===n&&a.forEach((l,o)=>{o<t.length&&u(l,t[o])})},50))},U=n=>{r=n,n?(document.body.style.cursor="crosshair",document.addEventListener("mouseover",N),document.addEventListener("mouseout",M),document.addEventListener("click",S,!0)):(m(),a.forEach(e=>{e&&e.parentNode&&e.remove()}),a=[],f=[],s=null,document.body.style.cursor="default",document.removeEventListener("mouseover",N),document.removeEventListener("mouseout",M),document.removeEventListener("click",S,!0))},T=()=>{if(s){let n=E(s);if(n.length>0){let t=n[0].getBoundingClientRect(),l=window.innerHeight,o=window.innerWidth,i=t.top<l&&t.bottom>0&&t.left<o&&t.right>0,c={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:c,isInViewport:i,visualSelectorId:s},"*")}}},P=n=>{let e=n.data;switch(e.type){case"toggle-visual-edit-mode":U(e.data.enabled);break;case"update-classes":e.data&&e.data.classes!==void 0?R(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(s){let t=E(s);if(t.length>0){let o=t[0].getBoundingClientRect(),i=window.innerHeight,c=window.innerWidth,h=o.top<i&&o.bottom>0&&o.left<c&&o.right>0,y={top:o.top,left:o.left,right:o.right,bottom:o.bottom,width:o.width,height:o.height,centerX:o.left+o.width/2,centerY:o.top+o.height/2};window.parent.postMessage({type:"element-position-update",position:y,isInViewport:h,visualSelectorId:s},"*")}}break;case"popover-drag-state":e.data&&e.data.isDragging!==void 0&&(d=e.data.isDragging,e.data.isDragging&&m());break;case"dropdown-state":e.data&&e.data.isOpen!==void 0&&(p=e.data.isOpen,e.data.isOpen&&m());break;default:break}},b=()=>{if(s){let n=E(s);a.forEach((e,t)=>{t<n.length&&u(e,n[t])})}f.length>0&&g.forEach((n,e)=>{e<f.length&&u(n,f[e])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((n,e)=>{let t=n,l=`visual-id-${t.dataset.filename}-${t.dataset.linenumber}-${e}`;t.dataset.visualSelectorId=l});let V=new MutationObserver(n=>{n.some(t=>{let l=i=>{if(i.nodeType===Node.ELEMENT_NODE){let c=i;if(c.dataset&&c.dataset.visualSelectorId)return!0;for(let h=0;h<c.children.length;h++)if(l(c.children[h]))return!0}return!1};return t.type==="attributes"&&(t.attributeName==="style"||t.attributeName==="class"||t.attributeName==="width"||t.attributeName==="height")&&l(t.target)})&&setTimeout(b,50)});window.addEventListener("message",P),window.addEventListener("scroll",T,!0),document.addEventListener("scroll",T,!0),window.addEventListener("resize",b),window.addEventListener("scroll",b),V.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}function Z(r={},d){window.self!==window.top&&(globalThis.__sandboxBridgeInitialized||(globalThis.__sandboxBridgeInitialized=!0,r.unhandledErrors!==!1&&I(d),r.mountObserver!==!1&&O(),r.hmrNotifier&&d&&x(d),r.navigationNotifier&&k(),r.visualEditAgent&&A()))}export{Z as init};
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