vue-wswg-editor 0.0.18 → 0.0.19
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/package.json
CHANGED
|
@@ -28,6 +28,8 @@ import { getIframeAppModuleUrl } from "./iframePreviewApp";
|
|
|
28
28
|
|
|
29
29
|
// Get the iframe app module URL
|
|
30
30
|
// This will be processed by the consuming app's Vite build
|
|
31
|
+
// Note: When the library is consumed as a bundled file, this URL may not resolve
|
|
32
|
+
// In that case, we'll use the postMessage fallback mechanism
|
|
31
33
|
const iframeAppModuleUrl = getIframeAppModuleUrl();
|
|
32
34
|
|
|
33
35
|
const props = defineProps<{
|
|
@@ -80,7 +82,9 @@ function onIframeLoad() {
|
|
|
80
82
|
// Generate blob URL for iframe
|
|
81
83
|
function createIframeSrc(): string {
|
|
82
84
|
console.info("[parent] Creating iframe src, module URL:", iframeAppModuleUrl);
|
|
83
|
-
|
|
85
|
+
// Always pass undefined to use postMessage mechanism
|
|
86
|
+
// The module URL will be sent via postMessage after iframe loads
|
|
87
|
+
const html = generateIframeHTML(undefined);
|
|
84
88
|
const blob = new Blob([html], { type: "text/html" });
|
|
85
89
|
const blobUrl = URL.createObjectURL(blob);
|
|
86
90
|
console.info("[parent] Iframe blob URL created:", blobUrl);
|
|
@@ -123,9 +127,9 @@ function setupMessageListener() {
|
|
|
123
127
|
|
|
124
128
|
console.info("[parent] Received message from iframe:", event.data);
|
|
125
129
|
|
|
126
|
-
// Handle
|
|
127
|
-
if (event.data && event.data.type === "
|
|
128
|
-
console.info("[parent]
|
|
130
|
+
// Handle IFRAME_READY_FOR_APP - iframe is ready and requesting module URL
|
|
131
|
+
if (event.data && event.data.type === "IFRAME_READY_FOR_APP") {
|
|
132
|
+
console.info("[parent] IFRAME_READY_FOR_APP received, sending module URL");
|
|
129
133
|
if (iframeRef.value && iframeAppModuleUrl) {
|
|
130
134
|
sendInitIframeApp(iframeRef.value, iframeAppModuleUrl);
|
|
131
135
|
} else {
|
|
@@ -134,11 +138,13 @@ function setupMessageListener() {
|
|
|
134
138
|
return;
|
|
135
139
|
}
|
|
136
140
|
|
|
137
|
-
// Handle
|
|
138
|
-
if (event.data && event.data.type === "
|
|
139
|
-
console.info("[parent]
|
|
141
|
+
// Handle IFRAME_NEEDS_MODULE_URL - same as IFRAME_READY_FOR_APP
|
|
142
|
+
if (event.data && event.data.type === "IFRAME_NEEDS_MODULE_URL") {
|
|
143
|
+
console.info("[parent] IFRAME_NEEDS_MODULE_URL received, sending module URL");
|
|
140
144
|
if (iframeRef.value && iframeAppModuleUrl) {
|
|
141
145
|
sendInitIframeApp(iframeRef.value, iframeAppModuleUrl);
|
|
146
|
+
} else {
|
|
147
|
+
console.warn("[parent] Cannot send module URL - iframe ref or module URL not available");
|
|
142
148
|
}
|
|
143
149
|
return;
|
|
144
150
|
}
|
|
@@ -99,10 +99,10 @@ function extractParentStylesheets(): string {
|
|
|
99
99
|
* This creates a standalone HTML page with a Vue app that will be loaded in the iframe
|
|
100
100
|
* The Vue app uses PageRenderer to render blocks reactively
|
|
101
101
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
102
|
+
* Note: The module URL is now sent via postMessage after iframe loads
|
|
103
|
+
* This parameter is kept for backward compatibility but is not used
|
|
104
104
|
*/
|
|
105
|
-
export function generateIframeHTML(
|
|
105
|
+
export function generateIframeHTML(_iframeAppModuleUrl?: string): string {
|
|
106
106
|
const parentStylesheets = extractParentStylesheets();
|
|
107
107
|
const parentCSSVariables = extractParentCSSVariables();
|
|
108
108
|
const vueCdnUrl = "https://unpkg.com/vue@3/dist/vue.esm-browser.js";
|
|
@@ -127,148 +127,74 @@ export function generateIframeHTML(iframeAppModuleUrl?: string): string {
|
|
|
127
127
|
</script>`;
|
|
128
128
|
|
|
129
129
|
// Generate script that loads Vue, vue-router, and initializes the iframe app
|
|
130
|
-
//
|
|
131
|
-
const appScript =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
console.info('[iframe]
|
|
151
|
-
|
|
152
|
-
|
|
130
|
+
// Always use postMessage fallback mechanism since module URLs may not resolve when bundled
|
|
131
|
+
const appScript = `<script type="module">
|
|
132
|
+
console.info('[iframe] Script module starting...');
|
|
133
|
+
|
|
134
|
+
import { createApp } from 'vue';
|
|
135
|
+
console.info('[iframe] Vue imported successfully');
|
|
136
|
+
|
|
137
|
+
import * as VueRouter from 'vue-router';
|
|
138
|
+
console.info('[iframe] VueRouter imported successfully');
|
|
139
|
+
// Make vue-router available globally so it can be accessed in the iframe app
|
|
140
|
+
window.VueRouter = VueRouter;
|
|
141
|
+
|
|
142
|
+
let appInitialized = false;
|
|
143
|
+
|
|
144
|
+
// Always use postMessage mechanism to get the module URL
|
|
145
|
+
// This works whether the library is consumed as source or bundled
|
|
146
|
+
window.addEventListener('message', async (event) => {
|
|
147
|
+
console.info('[iframe] Received message:', event.data);
|
|
148
|
+
if (event.data.type === 'INIT_IFRAME_APP' && event.data.moduleUrl && !appInitialized) {
|
|
149
|
+
appInitialized = true;
|
|
150
|
+
console.info('[iframe] Initializing app with module URL:', event.data.moduleUrl);
|
|
151
|
+
try {
|
|
152
|
+
const { createIframeApp } = await import(event.data.moduleUrl);
|
|
153
|
+
console.info('[iframe] createIframeApp imported successfully');
|
|
153
154
|
const appEl = document.getElementById('app');
|
|
154
155
|
console.info('[iframe] App element found:', appEl);
|
|
155
156
|
if (appEl) {
|
|
156
157
|
console.info('[iframe] Calling createIframeApp...');
|
|
157
|
-
|
|
158
|
-
module.createIframeApp(appEl).then(() => {
|
|
158
|
+
createIframeApp(appEl).then(() => {
|
|
159
159
|
console.info('[iframe] createIframeApp completed successfully');
|
|
160
160
|
}).catch(error => {
|
|
161
|
-
console.error('[iframe]
|
|
161
|
+
console.error('[iframe] createIframeApp failed:', error);
|
|
162
162
|
console.error('[iframe] Error stack:', error.stack);
|
|
163
|
-
});
|
|
164
|
-
} else {
|
|
165
|
-
console.error('[iframe] App element (#app) not found!');
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
console.error('[iframe] Module imported but createIframeApp not found');
|
|
169
|
-
throw new Error('createIframeApp not found in module');
|
|
170
|
-
}
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error('[iframe] Failed to import module, falling back to postMessage:', error);
|
|
173
|
-
console.error('[iframe] Error details:', error.message, error.stack);
|
|
174
|
-
|
|
175
|
-
// Fallback to postMessage mechanism
|
|
176
|
-
window.addEventListener('message', async (event) => {
|
|
177
|
-
console.info('[iframe] Received message (fallback):', event.data);
|
|
178
|
-
if (event.data.type === 'INIT_IFRAME_APP' && event.data.moduleUrl && !appInitialized) {
|
|
179
|
-
appInitialized = true;
|
|
180
|
-
console.info('[iframe] Initializing app with module URL (fallback):', event.data.moduleUrl);
|
|
181
|
-
try {
|
|
182
|
-
const { createIframeApp } = await import(event.data.moduleUrl);
|
|
183
|
-
console.info('[iframe] createIframeApp imported successfully (fallback)');
|
|
184
|
-
const appEl = document.getElementById('app');
|
|
185
|
-
console.info('[iframe] App element found (fallback):', appEl);
|
|
186
|
-
if (appEl) {
|
|
187
|
-
console.info('[iframe] Calling createIframeApp (fallback)...');
|
|
188
|
-
createIframeApp(appEl).then(() => {
|
|
189
|
-
console.info('[iframe] createIframeApp completed successfully (fallback)');
|
|
190
|
-
}).catch(err => {
|
|
191
|
-
console.error('[iframe] createIframeApp failed (fallback):', err);
|
|
192
|
-
});
|
|
193
|
-
} else {
|
|
194
|
-
console.error('[iframe] App element not found (fallback)!');
|
|
195
|
-
}
|
|
196
|
-
} catch (err) {
|
|
197
|
-
console.error('[iframe] Failed to load iframe app module (fallback):', err);
|
|
198
163
|
// Fallback: create minimal Vue app
|
|
199
164
|
const appEl = document.getElementById('app');
|
|
200
165
|
if (appEl) {
|
|
201
|
-
console.info('[iframe] Creating fallback Vue app');
|
|
166
|
+
console.info('[iframe] Creating fallback Vue app after error');
|
|
202
167
|
createApp({
|
|
203
|
-
template: '<div class="p-4">
|
|
168
|
+
template: '<div class="p-4">Error loading preview. Check console for details.</div>'
|
|
204
169
|
}).mount(appEl);
|
|
205
170
|
}
|
|
206
|
-
}
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
console.error('[iframe] App element not found!');
|
|
207
174
|
}
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// Fallback: Wait for parent to send module URL via postMessage
|
|
219
|
-
console.info('[iframe] Fallback script module starting...');
|
|
220
|
-
import { createApp } from 'vue';
|
|
221
|
-
console.info('[iframe] Vue imported successfully (fallback)');
|
|
222
|
-
import * as VueRouter from 'vue-router';
|
|
223
|
-
console.info('[iframe] VueRouter imported successfully (fallback)');
|
|
224
|
-
// Make vue-router available globally so it can be imported in the iframe app
|
|
225
|
-
window.VueRouter = VueRouter;
|
|
226
|
-
|
|
227
|
-
let appInitialized = false;
|
|
228
|
-
|
|
229
|
-
window.addEventListener('message', async (event) => {
|
|
230
|
-
console.info('[iframe] Received message:', event.data);
|
|
231
|
-
if (event.data.type === 'INIT_IFRAME_APP' && event.data.moduleUrl && !appInitialized) {
|
|
232
|
-
appInitialized = true;
|
|
233
|
-
console.info('[iframe] Initializing app with module URL:', event.data.moduleUrl);
|
|
234
|
-
try {
|
|
235
|
-
const { createIframeApp } = await import(event.data.moduleUrl);
|
|
236
|
-
console.info('[iframe] createIframeApp imported successfully (fallback)');
|
|
237
|
-
const appEl = document.getElementById('app');
|
|
238
|
-
console.info('[iframe] App element found (fallback):', appEl);
|
|
239
|
-
if (appEl) {
|
|
240
|
-
console.info('[iframe] Calling createIframeApp (fallback)...');
|
|
241
|
-
createIframeApp(appEl).then(() => {
|
|
242
|
-
console.info('[iframe] createIframeApp completed successfully (fallback)');
|
|
243
|
-
}).catch(error => {
|
|
244
|
-
console.error('[iframe] createIframeApp failed (fallback):', error);
|
|
245
|
-
});
|
|
246
|
-
} else {
|
|
247
|
-
console.error('[iframe] App element not found (fallback)!');
|
|
248
|
-
}
|
|
249
|
-
} catch (error) {
|
|
250
|
-
console.error('[iframe] Failed to load iframe app module:', error);
|
|
251
|
-
console.error('[iframe] Error stack:', error.stack);
|
|
252
|
-
// Fallback: create minimal Vue app
|
|
253
|
-
const appEl = document.getElementById('app');
|
|
254
|
-
if (appEl) {
|
|
255
|
-
console.info('[iframe] Creating fallback Vue app');
|
|
256
|
-
createApp({
|
|
257
|
-
template: '<div class="p-4">Loading preview...</div>'
|
|
258
|
-
}).mount(appEl);
|
|
259
|
-
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error('[iframe] Failed to load iframe app module:', error);
|
|
177
|
+
console.error('[iframe] Error stack:', error.stack);
|
|
178
|
+
// Fallback: create minimal Vue app
|
|
179
|
+
const appEl = document.getElementById('app');
|
|
180
|
+
if (appEl) {
|
|
181
|
+
console.info('[iframe] Creating fallback Vue app');
|
|
182
|
+
createApp({
|
|
183
|
+
template: '<div class="p-4">Loading preview...</div>'
|
|
184
|
+
}).mount(appEl);
|
|
260
185
|
}
|
|
261
186
|
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// Notify parent that we're ready to receive module URL
|
|
265
|
-
if (window.parent) {
|
|
266
|
-
console.info('[iframe] Notifying parent that iframe is ready for app');
|
|
267
|
-
window.parent.postMessage({ type: 'IFRAME_READY_FOR_APP' }, '*');
|
|
268
|
-
} else {
|
|
269
|
-
console.warn('[iframe] window.parent is not available');
|
|
270
187
|
}
|
|
271
|
-
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Notify parent that we're ready to receive module URL
|
|
191
|
+
if (window.parent) {
|
|
192
|
+
console.info('[iframe] Notifying parent that iframe is ready for app');
|
|
193
|
+
window.parent.postMessage({ type: 'IFRAME_READY_FOR_APP' }, '*');
|
|
194
|
+
} else {
|
|
195
|
+
console.warn('[iframe] window.parent is not available');
|
|
196
|
+
}
|
|
197
|
+
</script>`;
|
|
272
198
|
|
|
273
199
|
return `<!DOCTYPE html>
|
|
274
200
|
<html lang="en">
|