mirror of
https://github.com/groldsf/obsidian_check_plugin.git
synced 2026-07-22 12:00:31 +00:00
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { CheckboxUtils } from "./checkboxUtils";
|
|
import { FileFilter } from "./FileFilter";
|
|
import { IFilePathStateHolder } from "./IFilePathStateHolder";
|
|
|
|
export default class TextSyncPipeline {
|
|
private checkboxUtils: CheckboxUtils;
|
|
private fileStateHolder: IFilePathStateHolder;
|
|
private fileFilter: FileFilter;
|
|
|
|
|
|
constructor(checkboxUtils: CheckboxUtils, fileStateHolder: IFilePathStateHolder, fileFilter: FileFilter) {
|
|
this.checkboxUtils = checkboxUtils;
|
|
this.fileStateHolder = fileStateHolder;
|
|
this.fileFilter = fileFilter;
|
|
}
|
|
|
|
public applySyncLogic(currentText: string, filePath: string): string {
|
|
return this.fileStateHolderDecorator(currentText, filePath);
|
|
}
|
|
|
|
private coreDecorator(currentText: string, textBefore: string | undefined): string {
|
|
const resultingText = this.checkboxUtils.syncText(currentText, textBefore);
|
|
return resultingText;
|
|
}
|
|
|
|
private pathAllowedDecorator(currentText: string, textBefore: string | undefined, filePath: string): string {
|
|
if (!this.fileFilter.isPathAllowed(filePath)) {
|
|
console.log(`pathAllowedDecorator "${filePath}" skip, path is not allowed.`);
|
|
return currentText;
|
|
}
|
|
return this.coreDecorator(currentText, textBefore);
|
|
}
|
|
|
|
private fileStateHolderDecorator(currentText: string, filePath: string): string {
|
|
const textBefore = this.fileStateHolder.getByPath(filePath);
|
|
const resultingText = this.pathAllowedDecorator(currentText, textBefore, filePath);
|
|
this.fileStateHolder.setByPath(filePath, resultingText);
|
|
return resultingText;
|
|
}
|
|
}
|