swup 4.3.0 → 4.3.2

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/src/Swup.ts CHANGED
@@ -167,6 +167,11 @@ export default class Swup {
167
167
 
168
168
  window.addEventListener('popstate', this.handlePopState);
169
169
 
170
+ // Set scroll restoration to manual if animating history visits
171
+ if (this.options.animateHistoryBrowsing) {
172
+ window.history.scrollRestoration = 'manual';
173
+ }
174
+
170
175
  // Initial save to cache
171
176
  if (this.options.cache) {
172
177
  // Disabled to avoid caching modified dom state: logic moved to preload plugin
@@ -279,6 +284,7 @@ export default class Swup {
279
284
  return this.performNavigation();
280
285
  case 'scroll':
281
286
  default:
287
+ updateHistoryRecord(url);
282
288
  return this.scrollToContent();
283
289
  }
284
290
  });
@@ -310,18 +316,10 @@ export default class Swup {
310
316
  }
311
317
 
312
318
  const { url, hash } = Location.fromUrl(href);
313
- const animate = this.options.animateHistoryBrowsing;
314
- const resetScroll = this.options.animateHistoryBrowsing;
315
-
316
- this.visit = this.createVisit({
317
- to: url,
318
- hash,
319
- event,
320
- animate,
321
- resetScroll
322
- });
323
319
 
324
- // Mark as popstate visit
320
+ this.visit = this.createVisit({ to: url, hash, event });
321
+
322
+ // Mark as history visit
325
323
  this.visit.history.popstate = true;
326
324
 
327
325
  // Determine direction of history visit
@@ -331,6 +329,17 @@ export default class Swup {
331
329
  this.visit.history.direction = direction;
332
330
  }
333
331
 
332
+ // Disable animation & scrolling for history visits
333
+ this.visit.animation.animate = false;
334
+ this.visit.scroll.reset = false;
335
+ this.visit.scroll.target = false;
336
+
337
+ // Animated history visit: re-enable animation & scroll reset
338
+ if (this.options.animateHistoryBrowsing) {
339
+ this.visit.animation.animate = true;
340
+ this.visit.scroll.reset = true;
341
+ }
342
+
334
343
  // Does this even do anything?
335
344
  // if (!hash) {
336
345
  // event.preventDefault();
@@ -52,7 +52,7 @@ export interface VisitScroll {
52
52
  /** Whether to reset the scroll position after the visit. Default: `true` */
53
53
  reset: boolean;
54
54
  /** Anchor element to scroll to on the next page. */
55
- target?: string;
55
+ target?: string | false;
56
56
  }
57
57
 
58
58
  export interface VisitTrigger {
@@ -82,38 +82,23 @@ export interface VisitInitOptions {
82
82
  to: string;
83
83
  from?: string;
84
84
  hash?: string;
85
- animate?: boolean;
86
- animation?: string;
87
- targets?: string[];
88
85
  el?: Element;
89
86
  event?: Event;
90
- action?: HistoryAction;
91
- resetScroll?: boolean;
92
87
  }
93
88
 
94
89
  /** Create a new visit object. */
95
90
  export function createVisit(
96
91
  this: Swup,
97
- {
98
- to,
99
- from = this.currentPageUrl,
100
- hash,
101
- animate = true,
102
- animation: name,
103
- el,
104
- event,
105
- action = 'push',
106
- resetScroll: reset = true
107
- }: VisitInitOptions
92
+ { to, from = this.currentPageUrl, hash, el, event }: VisitInitOptions
108
93
  ): Visit {
109
94
  return {
110
95
  from: { url: from },
111
96
  to: { url: to, hash },
112
97
  containers: this.options.containers,
113
98
  animation: {
114
- animate,
99
+ animate: true,
115
100
  wait: false,
116
- name,
101
+ name: undefined,
117
102
  scope: this.options.animationScope,
118
103
  selector: this.options.animationSelector
119
104
  },
@@ -126,12 +111,12 @@ export function createVisit(
126
111
  write: this.options.cache
127
112
  },
128
113
  history: {
129
- action,
114
+ action: 'push',
130
115
  popstate: false,
131
116
  direction: undefined
132
117
  },
133
118
  scroll: {
134
- reset,
119
+ reset: true,
135
120
  target: undefined
136
121
  }
137
122
  };
@@ -7,7 +7,7 @@ import Swup from '../Swup.js';
7
7
  export const scrollToContent = function (this: Swup): boolean {
8
8
  const options: ScrollIntoViewOptions = { behavior: 'auto' };
9
9
  const { target, reset } = this.visit.scroll;
10
- const scrollTarget = target || this.visit.to.hash;
10
+ const scrollTarget = target ?? this.visit.to.hash;
11
11
 
12
12
  let scrolled = false;
13
13