Separate out into files

This commit is contained in:
2026-07-22 11:37:46 +00:00
parent 6aed7606ad
commit 5a514906eb
11 changed files with 906 additions and 657 deletions

View File

@@ -0,0 +1,51 @@
import { shallowRef } from "vue";
import type { NativeTransaction, NativeViewEntry } from "../types";
export class NativeHistoryLedger {
readonly keys = shallowRef<string[]>([]);
get length() {
return this.keys.value.length;
}
get previousKey() {
return this.keys.value.at(-2);
}
initialize(key: string) {
this.keys.value = [key];
}
contains(key: string) {
return this.keys.value.includes(key);
}
indexOf(key: string) {
return this.keys.value.lastIndexOf(key);
}
accept(target: NativeViewEntry, transaction: NativeTransaction | null) {
const history = this.keys.value;
if (!history.length) return this.initialize(target.key);
if (
transaction?.kind === "pop" ||
transaction?.kind === "dismiss" ||
transaction?.replace
) {
const targetIndex = history.lastIndexOf(target.key);
this.keys.value =
targetIndex >= 0
? history.slice(0, targetIndex + 1)
: [...history.slice(0, -1), target.key];
return;
}
const existingIndex = history.lastIndexOf(target.key);
this.keys.value = transaction
? [...history, target.key]
: existingIndex >= 0
? history.slice(0, existingIndex + 1)
: [...history, target.key];
}
}