🎨 refactor: setting-utils args
This commit is contained in:
parent
56be185458
commit
57cc62f7b5
2 changed files with 17 additions and 9 deletions
|
@ -163,7 +163,9 @@ export default class PluginSample extends Plugin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.settingUtils = new SettingUtils(this, STORAGE_NAME);
|
this.settingUtils = new SettingUtils({
|
||||||
|
plugin: this, name: STORAGE_NAME
|
||||||
|
});
|
||||||
this.settingUtils.addItem({
|
this.settingUtils.addItem({
|
||||||
key: "Input",
|
key: "Input",
|
||||||
value: "",
|
value: "",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author : frostime
|
* @Author : frostime
|
||||||
* @Date : 2023-12-17 18:28:19
|
* @Date : 2023-12-17 18:28:19
|
||||||
* @FilePath : /src/libs/setting-utils.ts
|
* @FilePath : /src/libs/setting-utils.ts
|
||||||
* @LastEditTime : 2024-04-28 17:43:43
|
* @LastEditTime : 2024-04-28 17:49:31
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -49,20 +49,26 @@ export class SettingUtils {
|
||||||
settings: Map<string, ISettingItem> = new Map();
|
settings: Map<string, ISettingItem> = new Map();
|
||||||
elements: Map<string, HTMLElement> = new Map();
|
elements: Map<string, HTMLElement> = new Map();
|
||||||
|
|
||||||
constructor(plugin: Plugin, name?: string, callback?: (data: any) => void, width?: string, height?: string) {
|
constructor(args: {
|
||||||
this.name = name ?? 'settings';
|
plugin: Plugin,
|
||||||
this.plugin = plugin;
|
name?: string,
|
||||||
|
callback?: (data: any) => void,
|
||||||
|
width?: string,
|
||||||
|
height?: string
|
||||||
|
}) {
|
||||||
|
this.name = args.name ?? 'settings';
|
||||||
|
this.plugin = args.plugin;
|
||||||
this.file = this.name.endsWith('.json') ? this.name : `${this.name}.json`;
|
this.file = this.name.endsWith('.json') ? this.name : `${this.name}.json`;
|
||||||
this.plugin.setting = new Setting({
|
this.plugin.setting = new Setting({
|
||||||
width: width,
|
width: args.width,
|
||||||
height: height,
|
height: args.height,
|
||||||
confirmCallback: () => {
|
confirmCallback: () => {
|
||||||
for (let key of this.settings.keys()) {
|
for (let key of this.settings.keys()) {
|
||||||
this.updateValueFromElement(key);
|
this.updateValueFromElement(key);
|
||||||
}
|
}
|
||||||
let data = this.dump();
|
let data = this.dump();
|
||||||
if (callback !== undefined) {
|
if (args.callback !== undefined) {
|
||||||
callback(data);
|
args.callback(data);
|
||||||
}
|
}
|
||||||
this.plugin.data[this.name] = data;
|
this.plugin.data[this.name] = data;
|
||||||
this.save();
|
this.save();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue