@simonbackx/vue-app-navigation 2.16.0 → 2.17.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/dist/index.js +115 -35
- 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
|
});
|
|
@@ -378,6 +391,9 @@ class HistoryManagerStatic {
|
|
|
378
391
|
if (!this.active) {
|
|
379
392
|
return;
|
|
380
393
|
}
|
|
394
|
+
if (this.debug) {
|
|
395
|
+
console.log("Set title: " + title + ", for index " + (index ?? this.counter) + " with current counter: " + this.counter);
|
|
396
|
+
}
|
|
381
397
|
if (index === void 0 || index === this.counter) {
|
|
382
398
|
const state = this.states[this.states.length - 1];
|
|
383
399
|
window.document.title = this.formatTitle(title);
|
|
@@ -428,19 +444,31 @@ class HistoryManagerStatic {
|
|
|
428
444
|
const c = this.counter;
|
|
429
445
|
if (state.adjustHistory) {
|
|
430
446
|
this.addToQueue(() => {
|
|
447
|
+
if (this.debug) {
|
|
448
|
+
console.log("history.pushState", c, url);
|
|
449
|
+
}
|
|
431
450
|
const formattedUrl = url === void 0 ? void 0 : "/" + UrlHelper.trim(UrlHelper.transformUrl(url));
|
|
432
451
|
history.pushState({ counter: c }, "", formattedUrl);
|
|
433
452
|
});
|
|
434
453
|
} else {
|
|
435
454
|
this.addToQueue(() => {
|
|
455
|
+
if (this.debug) {
|
|
456
|
+
console.log("history.replaceState", c);
|
|
457
|
+
}
|
|
436
458
|
history.replaceState({ counter: c }, "", void 0);
|
|
437
459
|
});
|
|
438
460
|
}
|
|
461
|
+
if (this.debug) {
|
|
462
|
+
console.log("Push new state ", this.states[this.states.length - 1]);
|
|
463
|
+
}
|
|
439
464
|
}
|
|
440
465
|
/**
|
|
441
466
|
* Call when an action is performed that breaks back/forward navigation
|
|
442
467
|
*/
|
|
443
468
|
invalidateHistory() {
|
|
469
|
+
if (this.debug) {
|
|
470
|
+
console.log("HistoryManger.invalidateHistory");
|
|
471
|
+
}
|
|
444
472
|
for (const state of this.states) {
|
|
445
473
|
state.undoAction = null;
|
|
446
474
|
state.invalid = state.index !== this.counter;
|
|
@@ -450,6 +478,9 @@ class HistoryManagerStatic {
|
|
|
450
478
|
* Return to a given history point in time, if needed
|
|
451
479
|
*/
|
|
452
480
|
returnToHistoryIndex(counter) {
|
|
481
|
+
if (this.debug) {
|
|
482
|
+
console.log("Did return to history index " + counter + ", coming from " + this.counter);
|
|
483
|
+
}
|
|
453
484
|
if (counter > this.counter) {
|
|
454
485
|
console.warn("Performed non-compatible navigation. Probably because side-by-side views navigating");
|
|
455
486
|
this.invalidateHistory();
|
|
@@ -474,10 +505,16 @@ class HistoryManagerStatic {
|
|
|
474
505
|
console.log("Deleted states", deletedStates.length);
|
|
475
506
|
const adjustHistoryCount = deletedStates.filter((state) => state.adjustHistory).length;
|
|
476
507
|
if (adjustHistoryCount > 0) {
|
|
508
|
+
if (this.debug) {
|
|
509
|
+
console.log("Adjusting browser history state: popping " + adjustHistoryCount + " items");
|
|
510
|
+
}
|
|
477
511
|
this.go(-adjustHistoryCount);
|
|
478
512
|
}
|
|
479
513
|
}
|
|
480
514
|
if (this.states[this.counter].url) {
|
|
515
|
+
if (this.debug) {
|
|
516
|
+
console.log("Setting manual url without history api: " + this.states[this.counter].url);
|
|
517
|
+
}
|
|
481
518
|
this.setUrl(this.states[this.counter].url, this.states[this.counter].title);
|
|
482
519
|
}
|
|
483
520
|
return this.counter;
|
|
@@ -486,6 +523,9 @@ class HistoryManagerStatic {
|
|
|
486
523
|
history.scrollRestoration = "manual";
|
|
487
524
|
async function onPopState(event) {
|
|
488
525
|
var _a;
|
|
526
|
+
if (this.debug) {
|
|
527
|
+
console.log("HistoryManager popstate");
|
|
528
|
+
}
|
|
489
529
|
if (this.isAdjustingState) {
|
|
490
530
|
console.warn("Duplicate popstate");
|
|
491
531
|
return;
|
|
@@ -497,8 +537,11 @@ class HistoryManagerStatic {
|
|
|
497
537
|
const newCounter = (_a = event.state) == null ? void 0 : _a.counter;
|
|
498
538
|
if (newCounter !== void 0) {
|
|
499
539
|
if (newCounter > this.counter) {
|
|
500
|
-
|
|
501
|
-
|
|
540
|
+
if (this.debug) {
|
|
541
|
+
console.log("Reloading page because going forward is not supported");
|
|
542
|
+
}
|
|
543
|
+
window.location.reload();
|
|
544
|
+
return;
|
|
502
545
|
} else {
|
|
503
546
|
const animate = this.counter - newCounter == 1 && this.animateHistoryPop;
|
|
504
547
|
this.counter = newCounter;
|
|
@@ -518,6 +561,9 @@ class HistoryManagerStatic {
|
|
|
518
561
|
}
|
|
519
562
|
for (const state of deletedStates) {
|
|
520
563
|
if (state.undoAction) {
|
|
564
|
+
if (this.debug) {
|
|
565
|
+
console.log("Executing undoAction...");
|
|
566
|
+
}
|
|
521
567
|
await state.undoAction(animate);
|
|
522
568
|
} else {
|
|
523
569
|
if (state.adjustHistory) {
|
|
@@ -567,7 +613,6 @@ class HistoryManagerStatic {
|
|
|
567
613
|
});
|
|
568
614
|
}
|
|
569
615
|
}
|
|
570
|
-
__publicField(HistoryManagerStatic, "debug", false);
|
|
571
616
|
const HistoryManager = new HistoryManagerStatic();
|
|
572
617
|
function useCurrentComponent() {
|
|
573
618
|
return inject("navigation_currentComponent", null);
|
|
@@ -781,9 +826,6 @@ const _ComponentWithProperties = class _ComponentWithProperties {
|
|
|
781
826
|
console.warn("Returning to a component that has no history index assigned. Has this component been pushed to a navigation controller properly before returning to it?", this.component.name);
|
|
782
827
|
return false;
|
|
783
828
|
}
|
|
784
|
-
_ComponentWithProperties.historyIndexOwners.set(this.historyIndex, this);
|
|
785
|
-
if (_ComponentWithProperties.debug)
|
|
786
|
-
console.log("New owner of history index ", this.historyIndex, this.component.name);
|
|
787
829
|
HistoryManager.returnToHistoryIndex(this.historyIndex);
|
|
788
830
|
return true;
|
|
789
831
|
}
|
|
@@ -846,6 +888,7 @@ const _ComponentWithProperties = class _ComponentWithProperties {
|
|
|
846
888
|
} else {
|
|
847
889
|
console.error("No unmount function for component " + this.vnode);
|
|
848
890
|
}
|
|
891
|
+
this.deleteHistoryIndex();
|
|
849
892
|
this.vnode = null;
|
|
850
893
|
}
|
|
851
894
|
}
|
|
@@ -1412,47 +1455,84 @@ const _sfc_main$4 = defineComponent({
|
|
|
1412
1455
|
if (animated) {
|
|
1413
1456
|
this.freezeSize();
|
|
1414
1457
|
}
|
|
1458
|
+
let popped = [];
|
|
1459
|
+
const adjustHistory = (options == null ? void 0 : options.adjustHistory) ?? true;
|
|
1415
1460
|
if (replace > 0) {
|
|
1416
|
-
|
|
1461
|
+
popped = this.components.splice(this.components.length - replace, replace, ...components);
|
|
1417
1462
|
if (!destroy) {
|
|
1418
1463
|
for (const comp of popped) {
|
|
1419
1464
|
comp.keepAlive = true;
|
|
1420
1465
|
}
|
|
1421
1466
|
}
|
|
1422
|
-
if (this.components.length
|
|
1423
|
-
|
|
1467
|
+
if (this.components.length <= components.length) {
|
|
1468
|
+
const lastComponent = popped[0];
|
|
1469
|
+
if (HistoryManager.active) {
|
|
1470
|
+
if (lastComponent && lastComponent.hasHistoryIndex()) {
|
|
1471
|
+
HistoryManager.returnToHistoryIndex(lastComponent.historyIndex - 1);
|
|
1472
|
+
} else {
|
|
1473
|
+
console.log("Last removed component has no history index", popped);
|
|
1474
|
+
HistoryManager.invalidateHistory();
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
} else {
|
|
1478
|
+
const lastComponent = this.components[this.components.length - components.length - 1];
|
|
1479
|
+
if (lastComponent && lastComponent.hasHistoryIndex()) {
|
|
1480
|
+
lastComponent.returnToHistoryIndex();
|
|
1481
|
+
} else {
|
|
1482
|
+
console.log("Last visible component has no history index", lastComponent);
|
|
1483
|
+
HistoryManager.invalidateHistory();
|
|
1484
|
+
}
|
|
1424
1485
|
}
|
|
1425
1486
|
} else {
|
|
1426
1487
|
this.components.push(...components);
|
|
1427
1488
|
}
|
|
1428
1489
|
if (this.mainComponent) {
|
|
1429
|
-
this.mainComponent.keepAlive = !replace;
|
|
1490
|
+
this.mainComponent.keepAlive = !replace || !destroy;
|
|
1430
1491
|
}
|
|
1431
|
-
const adjustHistory = (options == null ? void 0 : options.adjustHistory) ?? true;
|
|
1432
1492
|
if (adjustHistory) {
|
|
1433
|
-
for (const component2 of components) {
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1493
|
+
for (const [index, component2] of components.entries()) {
|
|
1494
|
+
if (index === 0 && popped.length) {
|
|
1495
|
+
HistoryManager.pushState(void 0, async (canAnimate) => {
|
|
1496
|
+
if (!this.mainComponent) {
|
|
1497
|
+
console.error("Tried to pop NavigationController, but it was already unmounted");
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
await this.push({
|
|
1501
|
+
animated: animated && canAnimate,
|
|
1502
|
+
replace: 1,
|
|
1503
|
+
components: popped,
|
|
1504
|
+
reverse: !(options.reverse ?? false),
|
|
1505
|
+
adjustHistory: false
|
|
1506
|
+
});
|
|
1507
|
+
}, {
|
|
1508
|
+
adjustHistory,
|
|
1509
|
+
invalid: options.invalidHistory ?? false
|
|
1510
|
+
});
|
|
1511
|
+
} else {
|
|
1512
|
+
HistoryManager.pushState(void 0, async (canAnimate) => {
|
|
1513
|
+
if (!this.mainComponent) {
|
|
1514
|
+
console.error("Tried to pop NavigationController, but it was already unmounted");
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
await this.pop({ animated: animated && canAnimate });
|
|
1518
|
+
}, {
|
|
1450
1519
|
adjustHistory,
|
|
1451
|
-
invalid: options.invalidHistory ??
|
|
1520
|
+
invalid: options.invalidHistory ?? false
|
|
1452
1521
|
});
|
|
1453
1522
|
}
|
|
1454
1523
|
component2.assignHistoryIndex();
|
|
1455
1524
|
}
|
|
1525
|
+
} else {
|
|
1526
|
+
for (const [index, component2] of components.entries()) {
|
|
1527
|
+
HistoryManager.pushState(void 0, !!replace && index === 0 ? async (animated2) => {
|
|
1528
|
+
await this.pop({ animated: animated2, count: components.length });
|
|
1529
|
+
} : null, {
|
|
1530
|
+
adjustHistory: !!replace && index === 0,
|
|
1531
|
+
// for the first one we need to adjust the history because we returned earlier
|
|
1532
|
+
invalid: options.invalidHistory ?? false
|
|
1533
|
+
});
|
|
1534
|
+
component2.assignHistoryIndex();
|
|
1535
|
+
}
|
|
1456
1536
|
}
|
|
1457
1537
|
this.mainComponent = component;
|
|
1458
1538
|
this.$emit("didPush");
|
|
@@ -2815,10 +2895,10 @@ const _sfc_main = defineComponent({
|
|
|
2815
2895
|
this.getScrollElement().scrollTop = 0;
|
|
2816
2896
|
HistoryManager.pushState(void 0, null, {
|
|
2817
2897
|
adjustHistory: options.adjustHistory ?? true,
|
|
2818
|
-
invalid: options.invalidHistory
|
|
2898
|
+
invalid: !!options.invalidHistory || !!this.detail
|
|
2819
2899
|
});
|
|
2900
|
+
component.assignHistoryIndex();
|
|
2820
2901
|
this.detail = component;
|
|
2821
|
-
this.detail.assignHistoryIndex();
|
|
2822
2902
|
}
|
|
2823
2903
|
} finally {
|
|
2824
2904
|
this.isChangingComponents = false;
|
|
@@ -2845,13 +2925,13 @@ const _sfc_main = defineComponent({
|
|
|
2845
2925
|
console.error("Cannot collapse while already isChangingComponents");
|
|
2846
2926
|
return;
|
|
2847
2927
|
}
|
|
2928
|
+
console.log("Collapse SplitViewController");
|
|
2848
2929
|
this.isChangingComponents = true;
|
|
2849
2930
|
try {
|
|
2850
2931
|
this.detail.keepAlive = true;
|
|
2851
2932
|
const detail = this.detail;
|
|
2852
2933
|
this.detail = null;
|
|
2853
2934
|
await this.navigationController.push({ components: [detail], animated: false });
|
|
2854
|
-
HistoryManager.invalidateHistory();
|
|
2855
2935
|
} finally {
|
|
2856
2936
|
this.isChangingComponents = false;
|
|
2857
2937
|
}
|
|
@@ -2887,12 +2967,12 @@ const _sfc_main = defineComponent({
|
|
|
2887
2967
|
console.error("Cannot expand while already isChangingComponents");
|
|
2888
2968
|
return false;
|
|
2889
2969
|
}
|
|
2970
|
+
console.log("Expand SplitViewController");
|
|
2890
2971
|
if (!this.lastIsDetail) {
|
|
2891
2972
|
if (!this.defaultHandler) {
|
|
2892
2973
|
console.error("Cannot expand when there is no defaultHandler");
|
|
2893
2974
|
return;
|
|
2894
2975
|
}
|
|
2895
|
-
HistoryManager.invalidateHistory();
|
|
2896
2976
|
this.isChangingComponents = false;
|
|
2897
2977
|
try {
|
|
2898
2978
|
const succeeded = await this.defaultHandler();
|