@simonbackx/vue-app-navigation 2.16.0 → 2.17.0
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/dist/index.js +45 -3
- package/dist/src/HistoryManager.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -203,6 +203,7 @@ function templateToUrl(template, params) {
|
|
|
203
203
|
}
|
|
204
204
|
class HistoryManagerStatic {
|
|
205
205
|
constructor() {
|
|
206
|
+
__publicField(this, "debug", false);
|
|
206
207
|
// undoActions: Map<number, (animate: boolean) => void> = new Map();
|
|
207
208
|
__publicField(this, "states", []);
|
|
208
209
|
__publicField(this, "counter", 0);
|
|
@@ -303,6 +304,9 @@ class HistoryManagerStatic {
|
|
|
303
304
|
if (!this.active) {
|
|
304
305
|
return;
|
|
305
306
|
}
|
|
307
|
+
if (this.debug) {
|
|
308
|
+
console.log("Set url: " + url + ", for index " + index + " with current counter: " + this.counter, title);
|
|
309
|
+
}
|
|
306
310
|
if (index === void 0 || index === this.counter) {
|
|
307
311
|
const state = this.states[this.states.length - 1];
|
|
308
312
|
const count = state.index;
|
|
@@ -319,6 +323,9 @@ class HistoryManagerStatic {
|
|
|
319
323
|
if (this.counter !== count || state.url !== url) {
|
|
320
324
|
return;
|
|
321
325
|
}
|
|
326
|
+
if (this.debug) {
|
|
327
|
+
console.log("history.replaceState", count, url);
|
|
328
|
+
}
|
|
322
329
|
const formattedUrl = this.resolveUrl(count);
|
|
323
330
|
history.replaceState({ counter: count }, "", formattedUrl);
|
|
324
331
|
if (state.title) {
|
|
@@ -340,8 +347,11 @@ class HistoryManagerStatic {
|
|
|
340
347
|
console.error("Search state with index ", index, "but received state with index", state.index);
|
|
341
348
|
return;
|
|
342
349
|
}
|
|
343
|
-
if (state.url !== url)
|
|
344
|
-
|
|
350
|
+
if (state.url !== url) {
|
|
351
|
+
if (this.debug) {
|
|
352
|
+
console.info("Changed url for old state: " + state.index + " to " + url);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
345
355
|
state.url = url;
|
|
346
356
|
if (title) {
|
|
347
357
|
state.title = title;
|
|
@@ -363,6 +373,9 @@ class HistoryManagerStatic {
|
|
|
363
373
|
if (this.counter !== count) {
|
|
364
374
|
return;
|
|
365
375
|
}
|
|
376
|
+
if (this.debug) {
|
|
377
|
+
console.log("history.replaceState - updateUrl");
|
|
378
|
+
}
|
|
366
379
|
const formattedUrl = this.resolveUrl(count);
|
|
367
380
|
history.replaceState({ counter: count }, "", formattedUrl);
|
|
368
381
|
});
|
|
@@ -428,19 +441,31 @@ class HistoryManagerStatic {
|
|
|
428
441
|
const c = this.counter;
|
|
429
442
|
if (state.adjustHistory) {
|
|
430
443
|
this.addToQueue(() => {
|
|
444
|
+
if (this.debug) {
|
|
445
|
+
console.log("history.pushState", c, url);
|
|
446
|
+
}
|
|
431
447
|
const formattedUrl = url === void 0 ? void 0 : "/" + UrlHelper.trim(UrlHelper.transformUrl(url));
|
|
432
448
|
history.pushState({ counter: c }, "", formattedUrl);
|
|
433
449
|
});
|
|
434
450
|
} else {
|
|
435
451
|
this.addToQueue(() => {
|
|
452
|
+
if (this.debug) {
|
|
453
|
+
console.log("history.replaceState", c);
|
|
454
|
+
}
|
|
436
455
|
history.replaceState({ counter: c }, "", void 0);
|
|
437
456
|
});
|
|
438
457
|
}
|
|
458
|
+
if (this.debug) {
|
|
459
|
+
console.log("Push new state ", this.states[this.states.length - 1]);
|
|
460
|
+
}
|
|
439
461
|
}
|
|
440
462
|
/**
|
|
441
463
|
* Call when an action is performed that breaks back/forward navigation
|
|
442
464
|
*/
|
|
443
465
|
invalidateHistory() {
|
|
466
|
+
if (this.debug) {
|
|
467
|
+
console.log("HistoryManger.invalidateHistory");
|
|
468
|
+
}
|
|
444
469
|
for (const state of this.states) {
|
|
445
470
|
state.undoAction = null;
|
|
446
471
|
state.invalid = state.index !== this.counter;
|
|
@@ -450,6 +475,9 @@ class HistoryManagerStatic {
|
|
|
450
475
|
* Return to a given history point in time, if needed
|
|
451
476
|
*/
|
|
452
477
|
returnToHistoryIndex(counter) {
|
|
478
|
+
if (this.debug) {
|
|
479
|
+
console.log("Did return to history index " + counter + ", coming from " + this.counter);
|
|
480
|
+
}
|
|
453
481
|
if (counter > this.counter) {
|
|
454
482
|
console.warn("Performed non-compatible navigation. Probably because side-by-side views navigating");
|
|
455
483
|
this.invalidateHistory();
|
|
@@ -474,10 +502,16 @@ class HistoryManagerStatic {
|
|
|
474
502
|
console.log("Deleted states", deletedStates.length);
|
|
475
503
|
const adjustHistoryCount = deletedStates.filter((state) => state.adjustHistory).length;
|
|
476
504
|
if (adjustHistoryCount > 0) {
|
|
505
|
+
if (this.debug) {
|
|
506
|
+
console.log("Adjusting browser history state: popping " + adjustHistoryCount + " items");
|
|
507
|
+
}
|
|
477
508
|
this.go(-adjustHistoryCount);
|
|
478
509
|
}
|
|
479
510
|
}
|
|
480
511
|
if (this.states[this.counter].url) {
|
|
512
|
+
if (this.debug) {
|
|
513
|
+
console.log("Setting manual url without history api: " + this.states[this.counter].url);
|
|
514
|
+
}
|
|
481
515
|
this.setUrl(this.states[this.counter].url, this.states[this.counter].title);
|
|
482
516
|
}
|
|
483
517
|
return this.counter;
|
|
@@ -486,6 +520,9 @@ class HistoryManagerStatic {
|
|
|
486
520
|
history.scrollRestoration = "manual";
|
|
487
521
|
async function onPopState(event) {
|
|
488
522
|
var _a;
|
|
523
|
+
if (this.debug) {
|
|
524
|
+
console.log("HistoryManager popstate");
|
|
525
|
+
}
|
|
489
526
|
if (this.isAdjustingState) {
|
|
490
527
|
console.warn("Duplicate popstate");
|
|
491
528
|
return;
|
|
@@ -499,6 +536,9 @@ class HistoryManagerStatic {
|
|
|
499
536
|
if (newCounter > this.counter) {
|
|
500
537
|
const amount = newCounter - this.counter;
|
|
501
538
|
this.go(-amount);
|
|
539
|
+
if (this.debug) {
|
|
540
|
+
console.log("Not allowed to go forward, going back " + amount + " steps");
|
|
541
|
+
}
|
|
502
542
|
} else {
|
|
503
543
|
const animate = this.counter - newCounter == 1 && this.animateHistoryPop;
|
|
504
544
|
this.counter = newCounter;
|
|
@@ -518,6 +558,9 @@ class HistoryManagerStatic {
|
|
|
518
558
|
}
|
|
519
559
|
for (const state of deletedStates) {
|
|
520
560
|
if (state.undoAction) {
|
|
561
|
+
if (this.debug) {
|
|
562
|
+
console.log("Executing undoAction...");
|
|
563
|
+
}
|
|
521
564
|
await state.undoAction(animate);
|
|
522
565
|
} else {
|
|
523
566
|
if (state.adjustHistory) {
|
|
@@ -567,7 +610,6 @@ class HistoryManagerStatic {
|
|
|
567
610
|
});
|
|
568
611
|
}
|
|
569
612
|
}
|
|
570
|
-
__publicField(HistoryManagerStatic, "debug", false);
|
|
571
613
|
const HistoryManager = new HistoryManagerStatic();
|
|
572
614
|
function useCurrentComponent() {
|
|
573
615
|
return inject("navigation_currentComponent", null);
|