saltfish 0.3.81 → 0.3.83

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.
@@ -9669,6 +9669,9 @@ class TransitionManager {
9669
9669
  __publicField(this, "triggerManager", null);
9670
9670
  // beforeunload handler for cross-page URL transitions
9671
9671
  __publicField(this, "beforeUnloadHandler", null);
9672
+ // Store original history methods so they can be restored on destroy
9673
+ __publicField(this, "originalPushState", null);
9674
+ __publicField(this, "originalReplaceState", null);
9672
9675
  /**
9673
9676
  * Handles URL changes by checking active URL path transitions and playlist triggers
9674
9677
  */
@@ -9676,6 +9679,9 @@ class TransitionManager {
9676
9679
  if (this.isStateMachineValidating) {
9677
9680
  return;
9678
9681
  }
9682
+ if (this.triggerManager) {
9683
+ this.triggerManager.clearTriggeredForNonMatchingUrls();
9684
+ }
9679
9685
  const urlPathTransitions = Array.from(this.activeTransitions.entries()).filter(([_, transition]) => {
9680
9686
  var _a;
9681
9687
  return ((_a = transition.data) == null ? void 0 : _a.type) === "url-path";
@@ -9692,6 +9698,9 @@ class TransitionManager {
9692
9698
  if (!hasValidTransition) {
9693
9699
  const isValidUrl = this.validateCurrentStepUrl();
9694
9700
  if (!isValidUrl) {
9701
+ if (this.triggerManager) {
9702
+ this.triggerManager.evaluateAllTriggers();
9703
+ }
9695
9704
  return;
9696
9705
  }
9697
9706
  }
@@ -9726,14 +9735,14 @@ class TransitionManager {
9726
9735
  * Monitors history pushState and replaceState methods to detect SPA navigation
9727
9736
  */
9728
9737
  monitorHistoryChanges() {
9729
- const originalPushState = history.pushState;
9730
- const originalReplaceState = history.replaceState;
9738
+ this.originalPushState = history.pushState;
9739
+ this.originalReplaceState = history.replaceState;
9731
9740
  history.pushState = (...args) => {
9732
- originalPushState.apply(history, args);
9741
+ this.originalPushState.apply(history, args);
9733
9742
  this.handleURLChange();
9734
9743
  };
9735
9744
  history.replaceState = (...args) => {
9736
- originalReplaceState.apply(history, args);
9745
+ this.originalReplaceState.apply(history, args);
9737
9746
  this.handleURLChange();
9738
9747
  };
9739
9748
  }
@@ -10007,8 +10016,12 @@ class TransitionManager {
10007
10016
  log(`TransitionManager: Expected pattern: '${urlRequirement.pattern}' (matchType: ${urlRequirement.matchType})`);
10008
10017
  this.cleanupTransitions();
10009
10018
  const saltfishPlayer = window._saltfishPlayer;
10010
- if (saltfishPlayer && typeof saltfishPlayer.destroy === "function") {
10011
- saltfishPlayer.destroy();
10019
+ if (saltfishPlayer && typeof saltfishPlayer.closePlaylist === "function") {
10020
+ saltfishPlayer.closePlaylist();
10021
+ } else {
10022
+ if (saltfishPlayer && typeof saltfishPlayer.destroy === "function") {
10023
+ saltfishPlayer.destroy();
10024
+ }
10012
10025
  }
10013
10026
  }
10014
10027
  /**
@@ -10132,6 +10145,14 @@ class TransitionManager {
10132
10145
  destroy() {
10133
10146
  this.cleanupTransitions();
10134
10147
  window.removeEventListener("popstate", this.handleURLChange);
10148
+ if (this.originalPushState) {
10149
+ history.pushState = this.originalPushState;
10150
+ this.originalPushState = null;
10151
+ }
10152
+ if (this.originalReplaceState) {
10153
+ history.replaceState = this.originalReplaceState;
10154
+ this.originalReplaceState = null;
10155
+ }
10135
10156
  }
10136
10157
  /**
10137
10158
  * Sets up DOM element visible transitions
@@ -10938,6 +10959,32 @@ class TriggerManager {
10938
10959
  this.triggeredPlaylistsSet.delete(playlistId);
10939
10960
  }
10940
10961
  }
10962
+ /**
10963
+ * Clears triggered state for playlists whose URL condition no longer matches the current URL.
10964
+ * This allows re-triggering when the user navigates back to a matching URL via SPA navigation.
10965
+ * Only clears playlists that have a URL trigger condition — non-URL triggers keep their state.
10966
+ */
10967
+ clearTriggeredForNonMatchingUrls() {
10968
+ var _a;
10969
+ if (this.triggeredPlaylistsSet.size === 0) {
10970
+ return;
10971
+ }
10972
+ const triggeredIds = Array.from(this.triggeredPlaylistsSet);
10973
+ log(`TriggerManager: clearTriggeredForNonMatchingUrls - checking ${triggeredIds.length} triggered playlists: [${triggeredIds.map((id) => id.substring(0, 8)).join(", ")}]`);
10974
+ for (const playlistId of triggeredIds) {
10975
+ const playlist = this.triggeredPlaylists.find((p) => p.id === playlistId);
10976
+ if (!((_a = playlist == null ? void 0 : playlist.triggers) == null ? void 0 : _a.url)) {
10977
+ log(`TriggerManager: Playlist ${playlistId.substring(0, 8)} has no URL trigger, keeping triggered state`);
10978
+ continue;
10979
+ }
10980
+ const urlStillMatches = this.evaluateURLCondition(playlist.triggers);
10981
+ if (!urlStillMatches) {
10982
+ this.triggeredPlaylistsSet.delete(playlistId);
10983
+ } else {
10984
+ log(`TriggerManager: Playlist ${playlistId.substring(0, 8)} URL still matches, keeping triggered state`);
10985
+ }
10986
+ }
10987
+ }
10941
10988
  /**
10942
10989
  * Resets the triggered playlists tracking
10943
10990
  * Useful for testing or when user context changes
@@ -12791,6 +12838,16 @@ const _SaltfishPlayer = class _SaltfishPlayer {
12791
12838
  resetPlaylist() {
12792
12839
  this.playlistOrchestrator.resetPlaylist();
12793
12840
  }
12841
+ /**
12842
+ * Close the current playlist while preserving the trigger system.
12843
+ * Used when a playlist needs to be stopped (e.g. URL validation failure)
12844
+ * but triggers should keep monitoring for future URL changes.
12845
+ */
12846
+ closePlaylist() {
12847
+ this.managerOrchestrator.cleanupPlaylist();
12848
+ const store = useSaltfishStore.getState();
12849
+ store.resetForNewPlaylist();
12850
+ }
12794
12851
  /**
12795
12852
  * Destroy the player and clean up all resources
12796
12853
  */
@@ -12857,7 +12914,7 @@ const SaltfishPlayer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
12857
12914
  __proto__: null,
12858
12915
  SaltfishPlayer
12859
12916
  }, Symbol.toStringTag, { value: "Module" }));
12860
- const version = "0.3.81";
12917
+ const version = "0.3.83";
12861
12918
  const packageJson = {
12862
12919
  version
12863
12920
  };