-
Notifications
You must be signed in to change notification settings - Fork 10
/
TldrawSettingsTab.ts
235 lines (209 loc) · 7.09 KB
/
TldrawSettingsTab.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import { clamp, msToSeconds } from "src/utils/utils";
import TldrawPlugin from "../main";
import { App, PluginSettingTab, Setting } from "obsidian";
import {
DEFAULT_SAVE_DELAY,
MAX_SAVE_DELAY,
MIN_SAVE_DELAY,
} from "src/utils/constants";
export type ThemePreference = "match-theme" | "dark" | "light";
export interface TldrawPluginSettings {
folder: string;
saveFileDelay: number; // in seconds
newFilePrefix: string;
newFileTimeFormat: string;
toolSelected: string;
themeMode: ThemePreference;
gridMode: boolean;
snapMode: boolean;
debugMode: boolean;
focusMode: boolean;
}
export const DEFAULT_SETTINGS: TldrawPluginSettings = {
folder: "tldraw",
saveFileDelay: 0.5,
newFilePrefix: "Tldraw ",
newFileTimeFormat: "YYYY-MM-DD h.mmA",
toolSelected: "select",
themeMode: "light",
gridMode: false,
snapMode: false,
debugMode: false,
focusMode: false,
};
export class TldrawSettingsTab extends PluginSettingTab {
plugin: TldrawPlugin;
constructor(app: App, plugin: TldrawPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
this.containerEl.createEl("h1", { text: "File" });
new Setting(containerEl)
.setName("Save folder")
.setDesc("The folder that tldraw files will be created in.")
.addText((text) =>
text
.setPlaceholder("root")
.setValue(this.plugin.settings.folder)
.onChange(async (value) => {
this.plugin.settings.folder = value;
await this.plugin.saveSettings();
})
);
const defaultDelay = msToSeconds(DEFAULT_SAVE_DELAY);
const minDelay = msToSeconds(MIN_SAVE_DELAY);
const maxDelay = msToSeconds(MAX_SAVE_DELAY);
const saveDelaySetting = new Setting(containerEl)
.setName("Save delay")
.setDesc(
`The delay in seconds to automatically save after a change has been made to a tlraw drawing. Must be a value between ${minDelay} and ${maxDelay} (1 hour). Requires reloading any tldraw files you may have open in a tab.`
)
.addText((text) =>
text
.setPlaceholder(`${defaultDelay}`)
.setValue(`${this.plugin.settings.saveFileDelay}`)
.onChange(async (value) => {
const parsedValue = parseInt(value);
this.plugin.settings.saveFileDelay = clamp(
isNaN(parsedValue) ? defaultDelay : parsedValue,
minDelay,
maxDelay
);
await this.plugin.saveSettings();
})
);
saveDelaySetting.descEl.createEl("code", {
cls: "ptl-default-code",
text: `DEFAULT: [${DEFAULT_SETTINGS.saveFileDelay}]`,
});
const filePrefixSettings = new Setting(containerEl)
.setName("New file prefix")
.setDesc(
"When creating a new tldraw file, the file name will automatically prepend the prefix. Can be left empty, however if both the prefix and time format are empty, it will use the defaults to name the file."
)
.addText((text) =>
text
.setPlaceholder("Prefix")
.setValue(this.plugin.settings.newFilePrefix)
.onChange(async (value) => {
this.plugin.settings.newFilePrefix = value;
await this.plugin.saveSettings();
})
);
filePrefixSettings.descEl.createEl("code", {
text: `DEFAULT: [${DEFAULT_SETTINGS.newFilePrefix} ]`,
cls: "ptl-default-code",
});
const timeFormatSetting = new Setting(containerEl)
.setName("New file time format")
.setDesc(
"When creating a new tldraw file, this represents the time format that will get appended to the file name. Can be left empty, however if both the Prefix and Time Format are empty, it will use the defaults to name the file. The meanings of each token can be found on "
)
.addText((text) =>
text
.setPlaceholder("Time Format")
.setValue(this.plugin.settings.newFileTimeFormat)
.onChange(async (value) => {
this.plugin.settings.newFileTimeFormat = value;
await this.plugin.saveSettings();
})
);
timeFormatSetting.descEl.createEl("a", {
href: "https://momentjs.com/docs/#/displaying/format/",
text: "moment.js.",
});
timeFormatSetting.descEl.createEl("code", {
cls: "ptl-default-code",
text: `DEFAULT: [${DEFAULT_SETTINGS.newFileTimeFormat}]`,
});
this.containerEl.createEl("h1", { text: "Start up" });
new Setting(containerEl)
.setName("Theme")
.setDesc(
"When opening a tldraw file, this setting decides what theme should be applied."
)
.addDropdown((cb) => {
cb.addOption("light", "Light theme")
.addOption("dark", "Dark theme")
.addOption("match-theme", "Match theme")
.setValue(this.plugin.settings.themeMode)
.onChange(async (value) => {
this.plugin.settings.themeMode =
value as ThemePreference;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Default tool")
.setDesc(
"When opening a tldraw file, this setting decides which tool should be selected."
)
.addDropdown((cb) => {
cb.addOption("select", "Select")
.addOption("hand", "Hand")
.addOption("draw", "Draw")
.addOption("text", "Text")
.addOption("eraser", "Eraser")
.addOption("highlight", "Highlight")
.addOption("rectangle", "Rectangle")
.addOption("ellipse", "Ellipse")
.setValue(this.plugin.settings.toolSelected)
.onChange(async (value) => {
this.plugin.settings.toolSelected =
value as ThemePreference;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Grid mode")
.setDesc(
"When opening tldraw files, this setting determines whether grid mode is enabled. Keep in mind that enabling grid mode will both show a grid and enforce snap-to-grid functionality."
)
.addToggle((cb) => {
cb.setValue(this.plugin.settings.gridMode);
cb.onChange(async (value) => {
this.plugin.settings.gridMode = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Snap mode")
.setDesc(
"When opening tldraw files, this setting determines whether snap mode is enabled. Snap mode is a feature that places guides on shapes as you move them, ensuring they align with specific points or positions for precise placement."
)
.addToggle((cb) => {
cb.setValue(this.plugin.settings.snapMode);
cb.onChange(async (value) => {
this.plugin.settings.snapMode = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Focus mode")
.setDesc(
"When opening tldraw files, this setting determines whether to launch tldraw in focus mode. Great if you like to use tldraw to quickly jot something down."
)
.addToggle((cb) => {
cb.setValue(this.plugin.settings.focusMode);
cb.onChange(async (value) => {
this.plugin.settings.focusMode = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Debug mode")
.setDesc(
"When opening tldraw files, this setting toggles the tldraw debug mode. Debug mode is useful for the developer."
)
.addToggle((cb) => {
cb.setValue(this.plugin.settings.debugMode);
cb.onChange(async (value) => {
this.plugin.settings.debugMode = value;
await this.plugin.saveSettings();
});
});
}
}