Feat v0.9.0 multi surface packages (#73)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m46s
CI/CD / test-sqlite (push) Successful in 2m57s
CI/CD / build-and-deploy (push) Successful in 44s
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m46s
CI/CD / test-sqlite (push) Successful in 2m57s
CI/CD / build-and-deploy (push) Successful in 44s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #73.
This commit is contained in:
@@ -186,8 +186,46 @@ export async function boot() {
|
||||
});
|
||||
};
|
||||
|
||||
// Navigate — multi-surface intra-package routing
|
||||
sw.navigate = function (path, params) {
|
||||
const manifest = window.__MANIFEST__;
|
||||
if (!manifest?.id) {
|
||||
console.warn('[sw] navigate: no manifest — not inside an extension surface');
|
||||
return;
|
||||
}
|
||||
// Interpolate :param placeholders
|
||||
let resolved = path;
|
||||
if (params) {
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
resolved = resolved.replace(':' + k, encodeURIComponent(v));
|
||||
}
|
||||
}
|
||||
const base = window.__BASE__ || '';
|
||||
const url = base + '/s/' + manifest.id + resolved;
|
||||
|
||||
// Update globals so the package can re-render
|
||||
window.__SURFACE_PATH__ = path;
|
||||
window.__SURFACE_PARAMS__ = params || {};
|
||||
|
||||
history.pushState({ surfacePath: path, surfaceParams: params }, '', url);
|
||||
events.emit('surface.navigate', { path, params: params || {}, url }, { localOnly: true });
|
||||
};
|
||||
|
||||
// Listen for popstate (back/forward) to emit navigation events
|
||||
window.addEventListener('popstate', (e) => {
|
||||
if (e.state?.surfacePath != null) {
|
||||
window.__SURFACE_PATH__ = e.state.surfacePath;
|
||||
window.__SURFACE_PARAMS__ = e.state.surfaceParams || {};
|
||||
events.emit('surface.navigate', {
|
||||
path: e.state.surfacePath,
|
||||
params: e.state.surfaceParams || {},
|
||||
url: location.pathname,
|
||||
}, { localOnly: true });
|
||||
}
|
||||
});
|
||||
|
||||
// Marker for idempotency
|
||||
sw._sdk = '0.7.1';
|
||||
sw._sdk = '0.9.0';
|
||||
|
||||
// 8. Expose globally
|
||||
window.sw = sw;
|
||||
|
||||
Reference in New Issue
Block a user