mirror of
https://github.com/panatgithub/AnkiHeadingSync.git
synced 2026-07-22 06:51:43 +00:00
- 将 marker、state、writeback 的 durable identity 改为 noteId - Switch marker, state, and writeback durable identity to noteId - 支持满足标题规则的旧 ID 卡片重接进并按当前 renderer 重渲染 - Reconnect legacy ID cards that match heading rules and rerender them with the current renderer - 补充 schema migration、测试、构建验证与插件同步 - Add schema migration, tests, build verification, and plugin sync
68 lines
No EOL
1.7 KiB
TypeScript
68 lines
No EOL
1.7 KiB
TypeScript
import type { CardType } from "@/domain/card/entities/RenderedFields";
|
|
import type { DeckResolutionWarning, DeckResolutionSource } from "@/domain/manual-sync/value-objects/DeckResolution";
|
|
|
|
export interface FileState {
|
|
filePath: string;
|
|
fileHash: string;
|
|
fileStamp: string;
|
|
deckRulesFingerprint?: string;
|
|
lastIndexedAt: number;
|
|
noteIds: number[];
|
|
}
|
|
|
|
export interface CardState {
|
|
noteId: number;
|
|
filePath: string;
|
|
heading: string;
|
|
headingLevel: number;
|
|
bodyMarkdown: string;
|
|
cardType: CardType;
|
|
blockStartOffset: number;
|
|
blockEndOffset: number;
|
|
blockStartLine: number;
|
|
bodyStartLine: number;
|
|
blockEndLine: number;
|
|
contentEndLine: number;
|
|
markerLine?: number;
|
|
rawBlockText: string;
|
|
rawBlockHash: string;
|
|
renderConfigHash: string;
|
|
deck: string;
|
|
deckHint?: string;
|
|
deckHintSource?: Extract<DeckResolutionSource, "frontmatter" | "body">;
|
|
deckWarnings: DeckResolutionWarning[];
|
|
tagsHint: string[];
|
|
lastSyncedAt: number;
|
|
orphan: boolean;
|
|
}
|
|
|
|
export interface PendingWriteBackState {
|
|
filePath: string;
|
|
blockStartLine: number;
|
|
expectedFileHash: string;
|
|
targetMarker: string;
|
|
rawBlockHash: string;
|
|
targetNoteId: number;
|
|
}
|
|
|
|
export interface PluginState {
|
|
files: Record<string, FileState>;
|
|
cards: Record<string, CardState>;
|
|
pendingWriteBack: PendingWriteBackState[];
|
|
}
|
|
|
|
export function createEmptyPluginState(): PluginState {
|
|
return {
|
|
files: {},
|
|
cards: {},
|
|
pendingWriteBack: [],
|
|
};
|
|
}
|
|
|
|
export function toNoteIdKey(noteId: number): string {
|
|
return String(noteId);
|
|
}
|
|
|
|
export function createPendingWriteBackKey(filePath: string, blockStartLine: number, rawBlockHash: string): string {
|
|
return `${filePath}\u0000${blockStartLine}\u0000${rawBlockHash}`;
|
|
} |