@thewhateverapp/tile-sdk 0.5.5 → 0.6.0
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.
|
@@ -19,6 +19,11 @@ export interface TileConfig {
|
|
|
19
19
|
theme?: 'light' | 'dark';
|
|
20
20
|
debug?: boolean;
|
|
21
21
|
}
|
|
22
|
+
type NextRouter = {
|
|
23
|
+
push: (href: string) => void;
|
|
24
|
+
replace: (href: string) => void;
|
|
25
|
+
back: () => void;
|
|
26
|
+
};
|
|
22
27
|
export declare class TileBridge {
|
|
23
28
|
private config;
|
|
24
29
|
private messageQueue;
|
|
@@ -26,26 +31,29 @@ export declare class TileBridge {
|
|
|
26
31
|
private eventHandlers;
|
|
27
32
|
private ready;
|
|
28
33
|
private parentOrigin;
|
|
29
|
-
|
|
34
|
+
private router;
|
|
35
|
+
constructor(expectedOrigin?: string, router?: NextRouter);
|
|
30
36
|
private initialize;
|
|
31
37
|
private handleMessage;
|
|
32
38
|
private handleConfig;
|
|
33
39
|
private handleResponse;
|
|
34
40
|
private handleEvent;
|
|
35
|
-
private handleNavigate;
|
|
36
|
-
/**
|
|
37
|
-
* Notify parent that navigation has completed
|
|
38
|
-
*/
|
|
39
|
-
private notifyNavigationComplete;
|
|
40
41
|
private sendToParent;
|
|
41
42
|
/**
|
|
42
43
|
* Request to navigate to full page view
|
|
44
|
+
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
43
45
|
*/
|
|
44
46
|
navigateToPage(): void;
|
|
45
47
|
/**
|
|
46
48
|
* Request to navigate back to tile view (from page)
|
|
49
|
+
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
47
50
|
*/
|
|
48
51
|
navigateToTile(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Set the Next.js router instance for navigation
|
|
54
|
+
* Call this from your app's layout/provider with the Next.js router
|
|
55
|
+
*/
|
|
56
|
+
setRouter(router: NextRouter): void;
|
|
49
57
|
/**
|
|
50
58
|
* Request to open a URL (with user confirmation)
|
|
51
59
|
*/
|
|
@@ -116,5 +124,6 @@ export declare class TileBridge {
|
|
|
116
124
|
private isInIframe;
|
|
117
125
|
private isValidOrigin;
|
|
118
126
|
}
|
|
119
|
-
export declare function getTileBridge(): TileBridge;
|
|
127
|
+
export declare function getTileBridge(router?: NextRouter): TileBridge;
|
|
128
|
+
export {};
|
|
120
129
|
//# sourceMappingURL=TileBridge.d.ts.map
|
|
@@ -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;
|
|
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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3
|
* This runs inside the iframe (tile side)
|
|
4
4
|
*/
|
|
5
5
|
export class TileBridge {
|
|
6
|
-
constructor(expectedOrigin = 'https://thewhatever.app') {
|
|
6
|
+
constructor(expectedOrigin = 'https://thewhatever.app', router) {
|
|
7
7
|
this.config = null;
|
|
8
8
|
this.messageQueue = [];
|
|
9
9
|
this.responseHandlers = new Map();
|
|
10
10
|
this.eventHandlers = new Map();
|
|
11
11
|
this.ready = false;
|
|
12
|
+
this.router = null;
|
|
12
13
|
this.parentOrigin = expectedOrigin;
|
|
14
|
+
this.router = router || null;
|
|
13
15
|
// Auto-detect parent origin based on environment
|
|
14
16
|
if (typeof window !== 'undefined') {
|
|
15
17
|
const isInIframe = window.self !== window.top;
|
|
@@ -78,9 +80,6 @@ export class TileBridge {
|
|
|
78
80
|
case 'parent:event':
|
|
79
81
|
this.handleEvent(message);
|
|
80
82
|
break;
|
|
81
|
-
case 'parent:navigate':
|
|
82
|
-
this.handleNavigate(message.payload);
|
|
83
|
-
break;
|
|
84
83
|
default:
|
|
85
84
|
// Handle custom messages
|
|
86
85
|
this.emitEvent(message.type, message.payload);
|
|
@@ -111,45 +110,6 @@ export class TileBridge {
|
|
|
111
110
|
handleEvent(message) {
|
|
112
111
|
this.emitEvent(message.payload?.type, message.payload?.data);
|
|
113
112
|
}
|
|
114
|
-
handleNavigate(payload) {
|
|
115
|
-
// Parent is telling us to navigate internally using Next.js router
|
|
116
|
-
if (typeof window === 'undefined')
|
|
117
|
-
return;
|
|
118
|
-
const route = payload?.route;
|
|
119
|
-
if (!route)
|
|
120
|
-
return;
|
|
121
|
-
if (this.isDevelopment() || this.isPreview()) {
|
|
122
|
-
console.log('[TileBridge] Received navigate command:', route);
|
|
123
|
-
}
|
|
124
|
-
// Emit navigate event so the app can handle it with Next.js router
|
|
125
|
-
this.emitEvent('navigate', { route });
|
|
126
|
-
// Also try using window.location if Next.js router isn't available
|
|
127
|
-
// This is a fallback, the app should preferably use the 'navigate' event
|
|
128
|
-
if (window.location.pathname !== route) {
|
|
129
|
-
window.history.pushState({}, '', route);
|
|
130
|
-
// Trigger a popstate event to notify the app
|
|
131
|
-
window.dispatchEvent(new PopStateEvent('popstate', { state: {} }));
|
|
132
|
-
}
|
|
133
|
-
// Wait for navigation to complete, then notify parent
|
|
134
|
-
// Use requestAnimationFrame + timeout to ensure DOM has updated
|
|
135
|
-
requestAnimationFrame(() => {
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
this.notifyNavigationComplete(route);
|
|
138
|
-
}, 50); // Small delay to ensure Next.js has finished mounting
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Notify parent that navigation has completed
|
|
143
|
-
*/
|
|
144
|
-
notifyNavigationComplete(route) {
|
|
145
|
-
if (this.isDevelopment() || this.isPreview()) {
|
|
146
|
-
console.log('[TileBridge] 📍 Navigation complete:', route);
|
|
147
|
-
}
|
|
148
|
-
this.sendToParent({
|
|
149
|
-
type: 'tile:navigation-complete',
|
|
150
|
-
payload: { route },
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
113
|
sendToParent(message) {
|
|
154
114
|
if (typeof window === 'undefined' || !window.parent)
|
|
155
115
|
return;
|
|
@@ -182,19 +142,24 @@ export class TileBridge {
|
|
|
182
142
|
// Public API
|
|
183
143
|
/**
|
|
184
144
|
* Request to navigate to full page view
|
|
145
|
+
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
185
146
|
*/
|
|
186
147
|
navigateToPage() {
|
|
187
148
|
if (this.isDevelopment() || this.isPreview()) {
|
|
188
|
-
console.log('[TileBridge]
|
|
189
|
-
|
|
190
|
-
parentOrigin: this.parentOrigin,
|
|
191
|
-
currentOrigin: window.location.origin,
|
|
149
|
+
console.log('[TileBridge] Navigating to /page', {
|
|
150
|
+
hasRouter: !!this.router,
|
|
192
151
|
isInIframe: this.isInIframe(),
|
|
193
152
|
});
|
|
194
153
|
}
|
|
195
|
-
//
|
|
196
|
-
this.
|
|
197
|
-
|
|
154
|
+
// 1. Navigate directly using Next.js router (if available)
|
|
155
|
+
if (this.router) {
|
|
156
|
+
this.router.push('/page');
|
|
157
|
+
}
|
|
158
|
+
else if (typeof window !== 'undefined') {
|
|
159
|
+
// Fallback: use window.location for preview mode
|
|
160
|
+
window.location.pathname = '/page';
|
|
161
|
+
}
|
|
162
|
+
// 2. Notify parent to enter fullscreen mode
|
|
198
163
|
this.sendToParent({
|
|
199
164
|
type: 'tile:navigate',
|
|
200
165
|
payload: { target: 'page' },
|
|
@@ -202,21 +167,36 @@ export class TileBridge {
|
|
|
202
167
|
}
|
|
203
168
|
/**
|
|
204
169
|
* Request to navigate back to tile view (from page)
|
|
170
|
+
* SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
|
|
205
171
|
*/
|
|
206
172
|
navigateToTile() {
|
|
207
173
|
if (this.isDevelopment() || this.isPreview()) {
|
|
208
|
-
console.log('[TileBridge]
|
|
174
|
+
console.log('[TileBridge] Navigating to /tile', {
|
|
175
|
+
hasRouter: !!this.router,
|
|
209
176
|
isInIframe: this.isInIframe(),
|
|
210
177
|
});
|
|
211
178
|
}
|
|
212
|
-
//
|
|
213
|
-
this.
|
|
214
|
-
|
|
179
|
+
// 1. Navigate directly using Next.js router (if available)
|
|
180
|
+
if (this.router) {
|
|
181
|
+
this.router.push('/tile');
|
|
182
|
+
}
|
|
183
|
+
else if (typeof window !== 'undefined') {
|
|
184
|
+
// Fallback: use window.location for preview mode
|
|
185
|
+
window.location.pathname = '/tile';
|
|
186
|
+
}
|
|
187
|
+
// 2. Notify parent to exit fullscreen mode
|
|
215
188
|
this.sendToParent({
|
|
216
189
|
type: 'tile:navigate',
|
|
217
190
|
payload: { target: 'tile' },
|
|
218
191
|
});
|
|
219
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Set the Next.js router instance for navigation
|
|
195
|
+
* Call this from your app's layout/provider with the Next.js router
|
|
196
|
+
*/
|
|
197
|
+
setRouter(router) {
|
|
198
|
+
this.router = router;
|
|
199
|
+
}
|
|
220
200
|
/**
|
|
221
201
|
* Request to open a URL (with user confirmation)
|
|
222
202
|
*/
|
|
@@ -528,9 +508,13 @@ export class TileBridge {
|
|
|
528
508
|
}
|
|
529
509
|
// Singleton instance
|
|
530
510
|
let bridgeInstance = null;
|
|
531
|
-
export function getTileBridge() {
|
|
511
|
+
export function getTileBridge(router) {
|
|
532
512
|
if (!bridgeInstance) {
|
|
533
|
-
bridgeInstance = new TileBridge();
|
|
513
|
+
bridgeInstance = new TileBridge('https://thewhatever.app', router);
|
|
514
|
+
}
|
|
515
|
+
else if (router && !bridgeInstance['router']) {
|
|
516
|
+
// Update router if provided and not already set
|
|
517
|
+
bridgeInstance.setRouter(router);
|
|
534
518
|
}
|
|
535
519
|
return bridgeInstance;
|
|
536
520
|
}
|