canvasframework 0.4.5 → 0.4.6

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.
@@ -687,6 +687,9 @@ class CanvasFramework {
687
687
  beforeEnter: options.beforeEnter,
688
688
  afterEnter: options.afterEnter,
689
689
  beforeLeave: options.beforeLeave,
690
+ afterLeave: options.afterLeave, // ✅ NOUVEAU
691
+ onEnter: options.onEnter, // ✅ NOUVEAU (alias de afterEnter)
692
+ onLeave: options.onLeave, // ✅ NOUVEAU (alias de beforeLeave)
690
693
  transition: options.transition || 'slide'
691
694
  };
692
695
 
@@ -783,28 +786,55 @@ class CanvasFramework {
783
786
 
784
787
  const { route, params, query, pathname } = match;
785
788
 
786
- // Hook beforeLeave de la route actuelle
789
+ // ===== LIFECYCLE: AVANT DE QUITTER L'ANCIENNE ROUTE =====
790
+
791
+ // Hook beforeLeave de la route actuelle (peut bloquer la navigation)
787
792
  const currentRouteData = this.routes.get(this.currentRoute);
788
793
  if (currentRouteData?.beforeLeave) {
789
794
  const canLeave = await currentRouteData.beforeLeave(this.currentParams, this.currentQuery);
790
- if (canLeave === false) return;
795
+ if (canLeave === false) {
796
+ console.log('Navigation cancelled by beforeLeave hook');
797
+ return;
798
+ }
799
+ }
800
+
801
+ // ✅ NOUVEAU : Hook onLeave (alias plus intuitif de beforeLeave, mais ne bloque pas)
802
+ if (currentRouteData?.onLeave) {
803
+ await currentRouteData.onLeave(this.currentParams, this.currentQuery);
791
804
  }
792
805
 
793
- // Hook beforeEnter de la nouvelle route
806
+ // ===== LIFECYCLE: AVANT D'ENTRER DANS LA NOUVELLE ROUTE =====
807
+
808
+ // Hook beforeEnter de la nouvelle route (peut bloquer la navigation)
794
809
  if (route.beforeEnter) {
795
810
  const canEnter = await route.beforeEnter(params, query);
796
- if (canEnter === false) return;
811
+ if (canEnter === false) {
812
+ console.log('Navigation cancelled by beforeEnter hook');
813
+ return;
814
+ }
815
+ }
816
+
817
+ // ✅ NOUVEAU : Hook onEnter (appelé juste avant de créer les composants)
818
+ if (route.onEnter) {
819
+ await route.onEnter(params, query);
797
820
  }
798
821
 
799
- // Sauvegarder l'ancienne route pour l'animation
822
+ // ===== SAUVEGARDER L'ÉTAT ACTUEL =====
823
+
824
+ // Sauvegarder l'ancienne route pour l'animation et les hooks
800
825
  const oldComponents = [...this.components];
826
+ const oldRoute = this.currentRoute;
827
+ const oldParams = { ...this.currentParams };
828
+ const oldQuery = { ...this.currentQuery };
801
829
 
802
- // Mettre à jour l'état
830
+ // ===== METTRE À JOUR L'ÉTAT =====
831
+
803
832
  this.currentRoute = pathname;
804
833
  this.currentParams = params;
805
834
  this.currentQuery = query;
806
835
 
807
- // Gérer l'historique
836
+ // ===== GÉRER L'HISTORIQUE =====
837
+
808
838
  if (!replace) {
809
839
  this.historyIndex++;
810
840
  this.history = this.history.slice(0, this.historyIndex);
@@ -819,28 +849,48 @@ class CanvasFramework {
819
849
  } else {
820
850
  this.history[this.historyIndex] = { path, params, query, state };
821
851
  window.history.replaceState(
822
- { route: path, params, query, state },
852
+ { route: path, params, query, state },
823
853
  '',
824
854
  path
825
855
  );
826
856
  }
827
857
 
828
- // Créer les nouveaux composants
858
+ // ===== CRÉER LES NOUVEAUX COMPOSANTS =====
859
+
829
860
  this.components = [];
830
861
  if (typeof route.component === 'function') {
831
862
  route.component(this, params, query);
832
863
  }
833
864
 
834
- // Lancer l'animation de transition
865
+ // ===== LANCER L'ANIMATION DE TRANSITION =====
866
+
835
867
  if (animate && !this.transitionState.isTransitioning) {
836
868
  const transitionType = transition || route.transition || 'slide';
837
869
  this.startTransition(oldComponents, this.components, transitionType, direction);
838
870
  }
839
871
 
840
- // Hook afterEnter
872
+ // ===== LIFECYCLE: APRÈS ÊTRE ENTRÉ DANS LA NOUVELLE ROUTE =====
873
+
874
+ // Hook afterEnter (appelé immédiatement après la création des composants)
841
875
  if (route.afterEnter) {
842
876
  route.afterEnter(params, query);
843
877
  }
878
+
879
+ // ✅ NOUVEAU : Hook afterLeave de l'ancienne route (après transition complète)
880
+ if (currentRouteData?.afterLeave) {
881
+ // Si animation, attendre la fin de la transition
882
+ if (animate && this.transitionState.isTransitioning) {
883
+ setTimeout(() => {
884
+ currentRouteData.afterLeave(oldParams, oldQuery);
885
+ }, this.transitionState.duration || 300);
886
+ } else {
887
+ // Pas d'animation, appeler immédiatement
888
+ currentRouteData.afterLeave(oldParams, oldQuery);
889
+ }
890
+ }
891
+
892
+ // ✅ OPTIONNEL : Marquer les composants comme "dirty" pour forcer le rendu
893
+ this._maxScrollDirty = true;
844
894
  }
845
895
 
846
896
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Canvas-based cross-platform UI framework (Material & Cupertino)",
5
5
  "type": "module",
6
6
  "main": "./index.js",