canvasframework 0.5.65 → 0.6.1
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/components/Camera.js +315 -368
- package/components/FloatedCamera.js +4 -5
- package/components/PDFViewer.js +1026 -722
- package/core/CanvasFramework.js +67 -10
- package/package.json +1 -1
package/core/CanvasFramework.js
CHANGED
|
@@ -585,6 +585,7 @@ class CanvasFramework {
|
|
|
585
585
|
|
|
586
586
|
this.setupEventListeners();
|
|
587
587
|
this.setupHistoryListener();
|
|
588
|
+
this._initNavigationGuard(); // ← AJOUTER
|
|
588
589
|
|
|
589
590
|
this.startRenderLoop();
|
|
590
591
|
|
|
@@ -635,6 +636,13 @@ class CanvasFramework {
|
|
|
635
636
|
}
|
|
636
637
|
|
|
637
638
|
}
|
|
639
|
+
|
|
640
|
+
_initNavigationGuard() {
|
|
641
|
+
// Injecter 2 entrées : une base + la route actuelle
|
|
642
|
+
// Ainsi le navigateur a toujours une entrée "avant" à consommer
|
|
643
|
+
window.history.replaceState({ route: '/', _guard: true }, '', '/');
|
|
644
|
+
window.history.pushState({ route: '/', _app: true }, '', '/');
|
|
645
|
+
}
|
|
638
646
|
|
|
639
647
|
/**
|
|
640
648
|
* Crée un élément DOM temporaire, l'ajoute au body, exécute une callback, puis le supprime
|
|
@@ -1963,16 +1971,51 @@ class CanvasFramework {
|
|
|
1963
1971
|
* @private
|
|
1964
1972
|
*/
|
|
1965
1973
|
setupHistoryListener() {
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1974
|
+
window.addEventListener('popstate', (e) => {
|
|
1975
|
+
// Cas 1 : L'app a un historique interne → naviguer en arrière dans l'app
|
|
1976
|
+
if (this.historyIndex > 0) {
|
|
1977
|
+
this.historyIndex--;
|
|
1978
|
+
const entry = this.history[this.historyIndex];
|
|
1979
|
+
|
|
1980
|
+
// Recharger la vue précédente sans toucher window.history
|
|
1981
|
+
this._navigateInternal(entry.path, {
|
|
1982
|
+
replace: true,
|
|
1983
|
+
animate: true,
|
|
1984
|
+
direction: 'back'
|
|
1985
|
+
});
|
|
1986
|
+
|
|
1987
|
+
// Réinjecter une entrée pour ne jamais vider la pile navigateur
|
|
1988
|
+
window.history.pushState({ route: entry.path, _app: true }, '', entry.path);
|
|
1989
|
+
|
|
1990
|
+
} else {
|
|
1991
|
+
// Cas 2 : Plus d'historique interne → réinjecter et ignorer
|
|
1992
|
+
// (empêche de quitter l'app)
|
|
1993
|
+
const currentPath = this.currentRoute || '/';
|
|
1994
|
+
window.history.pushState({ route: currentPath, _app: true }, '', currentPath);
|
|
1995
|
+
|
|
1996
|
+
// Optionnel : afficher un toast "Appuyez encore pour quitter"
|
|
1997
|
+
this._handleBackExitAttempt();
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
_handleBackExitAttempt() {
|
|
2003
|
+
const now = Date.now();
|
|
2004
|
+
|
|
2005
|
+
if (this._lastBackAttempt && (now - this._lastBackAttempt) < 2000) {
|
|
2006
|
+
// Deux back rapides → vraiment quitter (sur PWA/WebView)
|
|
2007
|
+
// Sur navigateur standard ce n'est pas possible, mais sur Capacitor/Cordova oui
|
|
2008
|
+
if (window.navigator.app?.exitApp) {
|
|
2009
|
+
window.navigator.app.exitApp(); // Cordova
|
|
2010
|
+
} else if (window.Capacitor?.Plugins?.App) {
|
|
2011
|
+
window.Capacitor.Plugins.App.exitApp(); // Capacitor
|
|
2012
|
+
}
|
|
2013
|
+
this._lastBackAttempt = null;
|
|
2014
|
+
} else {
|
|
2015
|
+
this._lastBackAttempt = now;
|
|
2016
|
+
this.showToast('Appuyez encore pour quitter', 2000);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
1976
2019
|
|
|
1977
2020
|
// ===== MÉTHODES DE ROUTING =====
|
|
1978
2021
|
|
|
@@ -2207,6 +2250,20 @@ class CanvasFramework {
|
|
|
2207
2250
|
}
|
|
2208
2251
|
|
|
2209
2252
|
this._maxScrollDirty = true;
|
|
2253
|
+
|
|
2254
|
+
// Historique navigateur : seulement si ce n'est pas un retour interne
|
|
2255
|
+
if (!options._internal) {
|
|
2256
|
+
if (!replace) {
|
|
2257
|
+
window.history.pushState({ route: path, _app: true }, '', path);
|
|
2258
|
+
} else {
|
|
2259
|
+
window.history.replaceState({ route: path, _app: true }, '', path);
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// Alias pour usage interne (sans toucher window.history)
|
|
2265
|
+
_navigateInternal(path, options = {}) {
|
|
2266
|
+
return this.navigateTo(path, { ...options, _internal: true });
|
|
2210
2267
|
}
|
|
2211
2268
|
|
|
2212
2269
|
/**
|