@thewhateverapp/tile-sdk 0.8.5 → 0.8.7
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.
|
@@ -44,12 +44,14 @@ export declare class TileBridge {
|
|
|
44
44
|
* Request to navigate to full page view
|
|
45
45
|
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
46
46
|
* In preview mode, only sends event to parent (no route change)
|
|
47
|
+
* Includes fallback for when router.push fails (e.g., due to hydration errors)
|
|
47
48
|
*/
|
|
48
49
|
navigateToPage(): void;
|
|
49
50
|
/**
|
|
50
51
|
* Request to navigate back to tile view (from page)
|
|
51
52
|
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
52
53
|
* In preview mode, only sends event to parent (no route change)
|
|
54
|
+
* Includes fallback for when router.push fails (e.g., due to hydration errors)
|
|
53
55
|
*/
|
|
54
56
|
navigateToTile(): void;
|
|
55
57
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/TileBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAGD,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE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AAM,GAAG,IAAI;IAWzD;;OAEG;IACU,OAAO,CAAC,OAAO,CAAC,EAAE;QAC7B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,GAAG,CAAC;IAiChB;;OAEG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA8B9D;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAuB3C;;OAEG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAgBlE;;OAEG;IACI,SAAS,IAAI,UAAU,GAAG,IAAI;IAIrC;;OAEG;IACI,OAAO,IAAI,OAAO;IAIzB;;;;;OAKG;IACU,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC;IAuBhD,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,aAAa;CAgCtB;AAKD,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,UAAU,CAQ7D"}
|
|
@@ -48,6 +48,13 @@ export class TileBridge {
|
|
|
48
48
|
}
|
|
49
49
|
// Listen for messages from parent
|
|
50
50
|
window.addEventListener('message', this.handleMessage.bind(this));
|
|
51
|
+
// Listen for CustomEvents from parent (mobile WebView uses dispatchEvent)
|
|
52
|
+
window.addEventListener('parent:navigateToPage', () => {
|
|
53
|
+
this.handleParentNavigate({ target: 'page' });
|
|
54
|
+
});
|
|
55
|
+
window.addEventListener('parent:navigateToTile', () => {
|
|
56
|
+
this.handleParentNavigate({ target: 'tile' });
|
|
57
|
+
});
|
|
51
58
|
// Mark as ready immediately - no config handshake needed
|
|
52
59
|
// This was previously set only after receiving parent:config, but that handshake
|
|
53
60
|
// was removed. Tiles are ready immediately after initialization.
|
|
@@ -83,6 +90,12 @@ export class TileBridge {
|
|
|
83
90
|
case 'parent:navigate':
|
|
84
91
|
this.handleParentNavigate(message.payload);
|
|
85
92
|
break;
|
|
93
|
+
case 'parent:navigateToPage':
|
|
94
|
+
this.handleParentNavigate({ target: 'page' });
|
|
95
|
+
break;
|
|
96
|
+
case 'parent:navigateToTile':
|
|
97
|
+
this.handleParentNavigate({ target: 'tile' });
|
|
98
|
+
break;
|
|
86
99
|
default:
|
|
87
100
|
// Handle custom messages
|
|
88
101
|
this.emitEvent(message.type, message.payload);
|
|
@@ -165,14 +178,16 @@ export class TileBridge {
|
|
|
165
178
|
* Request to navigate to full page view
|
|
166
179
|
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
167
180
|
* In preview mode, only sends event to parent (no route change)
|
|
181
|
+
* Includes fallback for when router.push fails (e.g., due to hydration errors)
|
|
168
182
|
*/
|
|
169
183
|
navigateToPage() {
|
|
170
184
|
const inPreview = this.isPreview();
|
|
185
|
+
const currentPath = typeof window !== 'undefined' ? window.location.pathname : 'unknown';
|
|
171
186
|
console.log('[TileBridge] 🚀 navigateToPage() called', {
|
|
172
187
|
hasRouter: !!this.router,
|
|
173
188
|
isInIframe: this.isInIframe(),
|
|
174
189
|
inPreview,
|
|
175
|
-
currentPath
|
|
190
|
+
currentPath,
|
|
176
191
|
});
|
|
177
192
|
// In preview mode, only notify parent - don't change routes in iframe
|
|
178
193
|
if (inPreview) {
|
|
@@ -186,11 +201,29 @@ export class TileBridge {
|
|
|
186
201
|
// 1. Navigate directly using Next.js router (deployed apps only)
|
|
187
202
|
if (this.router) {
|
|
188
203
|
console.log('[TileBridge] ✅ Using router.push("/page")');
|
|
189
|
-
|
|
204
|
+
try {
|
|
205
|
+
this.router.push('/page');
|
|
206
|
+
// Fallback: Check if navigation actually happened after a short delay
|
|
207
|
+
// This handles cases where router is broken due to hydration errors
|
|
208
|
+
if (typeof window !== 'undefined') {
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
if (window.location.pathname !== '/page') {
|
|
211
|
+
console.log('[TileBridge] ⚠️ router.push failed, falling back to window.location');
|
|
212
|
+
window.location.href = '/page';
|
|
213
|
+
}
|
|
214
|
+
}, 100);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
console.error('[TileBridge] router.push error, falling back:', err);
|
|
219
|
+
if (typeof window !== 'undefined') {
|
|
220
|
+
window.location.href = '/page';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
190
223
|
}
|
|
191
224
|
else if (typeof window !== 'undefined') {
|
|
192
225
|
console.log('[TileBridge] ⚠️ No router, using window.location fallback');
|
|
193
|
-
window.location.
|
|
226
|
+
window.location.href = '/page';
|
|
194
227
|
}
|
|
195
228
|
// 2. Notify parent to enter fullscreen mode
|
|
196
229
|
console.log('[TileBridge] 📤 Sending tile:navigate message to parent');
|
|
@@ -203,6 +236,7 @@ export class TileBridge {
|
|
|
203
236
|
* Request to navigate back to tile view (from page)
|
|
204
237
|
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
205
238
|
* In preview mode, only sends event to parent (no route change)
|
|
239
|
+
* Includes fallback for when router.push fails (e.g., due to hydration errors)
|
|
206
240
|
*/
|
|
207
241
|
navigateToTile() {
|
|
208
242
|
const inPreview = this.isPreview();
|
|
@@ -224,10 +258,27 @@ export class TileBridge {
|
|
|
224
258
|
}
|
|
225
259
|
// 1. Navigate directly using Next.js router (deployed apps only)
|
|
226
260
|
if (this.router) {
|
|
227
|
-
|
|
261
|
+
try {
|
|
262
|
+
this.router.push('/tile');
|
|
263
|
+
// Fallback: Check if navigation actually happened after a short delay
|
|
264
|
+
if (typeof window !== 'undefined') {
|
|
265
|
+
setTimeout(() => {
|
|
266
|
+
if (window.location.pathname !== '/tile') {
|
|
267
|
+
console.log('[TileBridge] ⚠️ router.push failed, falling back to window.location');
|
|
268
|
+
window.location.href = '/tile';
|
|
269
|
+
}
|
|
270
|
+
}, 100);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
console.error('[TileBridge] router.push error, falling back:', err);
|
|
275
|
+
if (typeof window !== 'undefined') {
|
|
276
|
+
window.location.href = '/tile';
|
|
277
|
+
}
|
|
278
|
+
}
|
|
228
279
|
}
|
|
229
280
|
else if (typeof window !== 'undefined') {
|
|
230
|
-
window.location.
|
|
281
|
+
window.location.href = '/tile';
|
|
231
282
|
}
|
|
232
283
|
// 2. Notify parent to exit fullscreen mode
|
|
233
284
|
this.sendToParent({
|