This repository has been archived by the owner on Feb 11, 2023. It is now read-only.
generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
93 lines (81 loc) · 2.33 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { App, Command, TFile } from 'obsidian';
import type { ReadOnlyReference } from 'model/ref';
export class ExtApp extends App {
internalPlugins: any;
plugins: {
getPluginFolder(): string;
getPlugin(id: string): {
settings: any;
};
};
commands: {
commands: { [id: string]: Command };
editorCommands: { [id: string]: Command };
findCommand(id: string): Command;
executeCommandById(id: string): void;
listCommands(): Command[];
};
customCss: {
getSnippetPath(file: string): string;
readSnippets(): void;
setCssEnabledStatus(snippet: string, enabled: boolean): void;
};
}
export interface PasteFunction {
(this: HTMLElement, ev: ClipboardEvent): void;
}
export class ExtTFile extends TFile {
override basename!: string;
}
export class OneDay {
file!: TFile;
oldContent = '';
constructor(protected fileVal: TFile, protected oldContentVal: string) {
this.file = fileVal;
this.oldContent = oldContentVal;
}
}
export class UndoHistoryInstance {
previousDay!: OneDay;
today!: OneDay;
constructor(protected previousDayVal: OneDay, protected todayVal: OneDay) {
this.previousDay = previousDayVal;
this.today = todayVal;
}
}
export class Tag {
color = 'var(--white)';
bgColor = 'var(--stag1-bg)';
type: string;
icon: {
name: string;
};
font: {
fontFamily: 'var(--font-family-special-tag)';
size: 'calc(var(--font-size-tag) - 0.3em)';
};
constructor(colorVal: string, bgColorVal: string, typeVal: string, iconVal, fontVal) {
this.color = colorVal;
this.bgColor = bgColorVal;
this.type = typeVal;
this.icon = iconVal;
this.font = fontVal;
}
}
export class EditDetector {
private lastModified?: Date;
constructor(private editDetectionSec: ReadOnlyReference<number>) {}
fileChanged() {
this.lastModified = new Date();
}
isEditing(): boolean {
if (this.editDetectionSec.value <= 0) {
return false;
}
if (this.lastModified == null) {
return false;
}
const elapsedSec = (new Date().getTime() - this.lastModified.getTime()) / 1000;
return elapsedSec < this.editDetectionSec.value;
}
}