generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
mindMapSettings.ts
168 lines (147 loc) · 5.32 KB
/
mindMapSettings.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
import { App, debounce, Platform, PluginSettingTab, Setting } from "obsidian";
import CanvasMindMap from "./canvasMindMap";
type ModifierKey = 'Alt' | 'Mod' | 'Shift';
function supportModifierKey() {
return ['Alt', 'Mod', 'Shift'];
}
export interface MindMapSettings {
navigate: {
useNavigate: boolean;
modifierKey: string[];
};
create: {
childDirection: string;
siblingWidth: number;
siblingHeight: number;
};
layout: {
direction: 'TB' | 'BT' | 'LR' | 'RL';
autoHeight: boolean;
autoLayout: boolean;
autoLayoutDirection: 'TB' | 'BT' | 'LR' | 'RL';
};
advanced: {
transferToCommands: boolean;
};
}
export const DEFAULT_SETTINGS: MindMapSettings = {
navigate: {
useNavigate: true,
modifierKey: ['Alt'],
},
create: {
childDirection: 'right',
siblingWidth: 200,
siblingHeight: 100,
},
layout: {
direction: 'LR',
autoLayout: true,
autoLayoutDirection: 'LR',
autoHeight: true,
},
advanced: {
transferToCommands: false,
}
};
class MindMapSettingTab extends PluginSettingTab {
plugin: CanvasMindMap;
updateSettings(key: any, value: any): void {
this.plugin.settings = {
...this.plugin.settings,
[key.split('.')[0]]: {
...this.plugin.settings[key.split('.')[0]],
[key.split('.')[1]]: value,
},
};
this.applySettingsUpdate();
}
applySettingsUpdate = debounce(
async () => {
await this.plugin.saveSettings();
console.log('debounce');
},
300,
true,
);
constructor(app: App, plugin: CanvasMindMap) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
containerEl.createEl('h2', {text: 'Canvas MindMap'});
// let rowText: HTMLDivElement;
// new Setting(containerEl)
// .setName('Navigate')
// .setDesc('The number of rows in the table')
// .addSlider((slider) =>
// slider
// .setLimits(2, 12, 1)
// .setValue(this.plugin.settings.rowCount)
// .onChange(async (value) => {
// rowText.innerText = ` ${value.toString()}`;
// this.plugin.settings.rowCount = value;
// }),
// )
// .settingEl.createDiv("", (el) => {
// rowText = el;
// el.className = "table-generator-setting-text";
// el.innerText = ` ${this.plugin.settings.rowCount.toString()}`;
// });
//
// let columnText: HTMLDivElement;
// new Setting(containerEl)
// .setName('Columns Count')
// .setDesc('The number of columns in the table')
// .addSlider((slider) =>
// slider
// .setLimits(2, 12, 1)
// .setValue(this.plugin.settings.columnCount)
// .onChange(async (value) => {
// columnText.innerText = ` ${value.toString()}`;
// this.plugin.settings.columnCount = value;
// }),
// )
// .settingEl.createDiv("", (el) => {
// columnText = el;
// el.className = "table-generator-setting-text";
// el.innerText = ` ${this.plugin.settings.columnCount.toString()}`;
// });
this.containerEl.createEl('h2', {text: 'Say Thank You'});
new Setting(containerEl)
.setName('Donate')
.setDesc('If you like this plugin, consider donating to support continued development:')
.addButton((bt) => {
bt.buttonEl.outerHTML = `<a href="https://www.buymeacoffee.com/boninall"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=boninall&button_colour=6495ED&font_colour=ffffff&font_family=Inter&outline_colour=000000&coffee_colour=FFDD00"></a>`;
});
}
useNavigateHotkeySetting(containerEl: HTMLElement, setting: MindMapSettings) {
new Setting(containerEl)
.setName('Use Navigate Hotkey')
.setDesc('Use the hotkey to navigate the mind map')
.addToggle((toggle) => {
toggle.setValue(setting.navigate.useNavigate);
toggle.onChange((value) => {
this.updateSettings('navigate.useNavigate', value);
setTimeout(() => {
this.display();
}, 700);
});
});
if (setting.navigate.useNavigate) {
new Setting(containerEl)
.setName('Modifier Key')
.setDesc('The modifier key to use with the hotkey')
.addDropdown((dropdown) => {
const mods = supportModifierKey();
dropdown.addOption('None', 'None');
dropdown.setValue(setting.navigate.modifierKey[0]);
dropdown.onChange((value) => {
this.updateSettings('navigate.modifierKey.0', value);
});
});
}
}
}