@base44/vite-plugin 1.0.11 → 1.0.13

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.
@@ -24,6 +24,12 @@ type IndexableCssRule = CSSRule & {
24
24
 
25
25
  type Debouncer = { trigger: () => void; cancel: () => void };
26
26
 
27
+ export type PageHeightBridgeController = {
28
+ freezeVhUnits: (override?: number) => void;
29
+ measurePageHeight: (origin: string, settleMs?: number) => void;
30
+ teardown: () => void;
31
+ };
32
+
27
33
  const FALLBACK_VHBASE: number = 900;
28
34
  const MIN_VHBASE: number = 400;
29
35
  const DEFAULT_SETTLE_MS: number = 2000;
@@ -45,34 +51,7 @@ export function setupPageHeightBridge(): () => void {
45
51
  if (window.self === window.top) return noop;
46
52
  started = true;
47
53
 
48
- let vhCleanups: Array<() => void> | null = null;
49
- let vhForceRun: (() => void) | null = null;
50
- let pendingResponse: number | undefined;
51
- let pendingOrigin: string = "*";
52
-
53
- const freezeVhUnits = (override: number | undefined): void => {
54
- if (vhCleanups) {
55
- vhForceRun?.();
56
- return;
57
- }
58
- const referenceVhBase: number = resolveReferenceVhBase(override);
59
- vhCleanups = [];
60
- vhForceRun = startVhNeutralizer(referenceVhBase, vhCleanups);
61
- };
62
-
63
- // Target the requester's origin so the height isn't broadcast to anyone
64
- // who happens to embed us. Falls back to "*" when origin is unavailable
65
- // (jsdom default, sandboxed iframes with `null` origin).
66
- const measurePageHeight = (origin: string, settleMs: number): void => {
67
- pendingOrigin = origin;
68
- if (pendingResponse !== undefined) window.clearTimeout(pendingResponse);
69
- pendingResponse = window.setTimeout((): void => {
70
- requestAnimationFrame((): void => {
71
- const height: number = measureContentHeight();
72
- window.parent.postMessage({ type: "page-height-measured", height }, pendingOrigin);
73
- });
74
- }, settleMs);
75
- };
54
+ const controller: PageHeightBridgeController = createPageHeightBridgeController();
76
55
 
77
56
  const onMessage = (event: MessageEvent): void => {
78
57
  const data: IncomingMessage | null = (event.data ?? null) as IncomingMessage | null;
@@ -81,7 +60,7 @@ export function setupPageHeightBridge(): () => void {
81
60
  case "freeze-vh-units": {
82
61
  const override: number | undefined =
83
62
  typeof data.referenceVhBase === "number" ? data.referenceVhBase : undefined;
84
- freezeVhUnits(override);
63
+ controller.freezeVhUnits(override);
85
64
  return;
86
65
  }
87
66
  case "measure-page-height": {
@@ -89,7 +68,7 @@ export function setupPageHeightBridge(): () => void {
89
68
  typeof data.settleMs === "number" ? data.settleMs : DEFAULT_SETTLE_MS;
90
69
  const origin: string =
91
70
  event.origin && event.origin !== "null" ? event.origin : "*";
92
- measurePageHeight(origin, settleMs);
71
+ controller.measurePageHeight(origin, settleMs);
93
72
  return;
94
73
  }
95
74
  }
@@ -103,12 +82,49 @@ export function setupPageHeightBridge(): () => void {
103
82
  torn = true;
104
83
  started = false;
105
84
  window.removeEventListener("message", onMessage);
106
- if (vhCleanups) {
107
- for (const c of vhCleanups) c();
108
- vhCleanups = null;
109
- vhForceRun = null;
110
- }
111
- if (pendingResponse !== undefined) window.clearTimeout(pendingResponse);
85
+ controller.teardown();
86
+ };
87
+ }
88
+
89
+ export function createPageHeightBridgeController(): PageHeightBridgeController {
90
+ let vhCleanups: Array<() => void> | null = null;
91
+ let vhForceRun: (() => void) | null = null;
92
+ let pendingResponse: number | undefined;
93
+ let pendingOrigin: string = "*";
94
+
95
+ return {
96
+ freezeVhUnits: (override: number | undefined): void => {
97
+ if (vhCleanups) {
98
+ vhForceRun?.();
99
+ return;
100
+ }
101
+ const referenceVhBase: number = resolveReferenceVhBase(override);
102
+ vhCleanups = [];
103
+ vhForceRun = startVhNeutralizer(referenceVhBase, vhCleanups);
104
+ },
105
+
106
+ // Target the requester's origin so the height isn't broadcast to anyone
107
+ // who happens to embed us. Falls back to "*" when origin is unavailable
108
+ // (jsdom default, sandboxed iframes with `null` origin).
109
+ measurePageHeight: (origin: string, settleMs: number = DEFAULT_SETTLE_MS): void => {
110
+ pendingOrigin = origin;
111
+ if (pendingResponse !== undefined) window.clearTimeout(pendingResponse);
112
+ pendingResponse = window.setTimeout((): void => {
113
+ requestAnimationFrame((): void => {
114
+ const height: number = measureContentHeight();
115
+ window.parent.postMessage({ type: "page-height-measured", height }, pendingOrigin);
116
+ });
117
+ }, settleMs);
118
+ },
119
+
120
+ teardown: (): void => {
121
+ if (vhCleanups) {
122
+ for (const c of vhCleanups) c();
123
+ vhCleanups = null;
124
+ vhForceRun = null;
125
+ }
126
+ if (pendingResponse !== undefined) window.clearTimeout(pendingResponse);
127
+ },
112
128
  };
113
129
  }
114
130
 
@@ -3,10 +3,13 @@ import { createLayerController } from "./layer-dropdown/controller.js";
3
3
  import { LAYER_DROPDOWN_ATTR } from "./layer-dropdown/consts.js";
4
4
  import { createInlineEditController } from "../capabilities/inline-edit/index.js";
5
5
  import { THEME_FONT_PREVIEW_ID } from "../consts.js";
6
+ import { createPageHeightBridgeController } from "./page-height-bridge.js";
6
7
 
7
8
  const REPOSITION_DELAY_MS = 50;
8
9
 
9
10
  export function setupVisualEditAgent() {
11
+ const pageHeightBridge = createPageHeightBridgeController();
12
+
10
13
  // State variables (replacing React useState/useRef)
11
14
  let isVisualEditMode = false;
12
15
  let isPopoverDragging = false;
@@ -638,6 +641,21 @@ export function setupVisualEditAgent() {
638
641
  }
639
642
  break;
640
643
 
644
+ case "freeze-vh-units":
645
+ pageHeightBridge.freezeVhUnits(
646
+ typeof message.referenceVhBase === "number"
647
+ ? message.referenceVhBase
648
+ : undefined
649
+ );
650
+ break;
651
+
652
+ case "measure-page-height":
653
+ pageHeightBridge.measurePageHeight(
654
+ event.origin && event.origin !== "null" ? event.origin : "*",
655
+ typeof message.settleMs === "number" ? message.settleMs : undefined
656
+ );
657
+ break;
658
+
641
659
  default:
642
660
  break;
643
661
  }
@@ -723,4 +741,4 @@ export function setupVisualEditAgent() {
723
741
 
724
742
  // Send ready message to parent
725
743
  window.parent.postMessage({ type: "visual-edit-agent-ready" }, "*");
726
- }
744
+ }