From 7a46168ed264057bf1ae9a0fd4fe867a2201e384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=94=E9=98=B3=E9=99=8C=E5=AE=A2?= Date: Thu, 25 Apr 2024 21:16:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9take()=E7=9A=84=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=80=BC=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 4 +--- src/libs/setting-utils.ts | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index df1131b..1899daa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -246,11 +246,9 @@ export default class PluginSample extends Plugin { step: 1, }, action:{ - // The callback is called after the action of Silder changes, - // so it should be the this.settingUtils.get() method. callback: () => { // Read data in real time - let value = this.settingUtils.get("Slider") + let value = this.settingUtils.take("Slider") console.log(value); } } diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index dd16ca5..e0ff2bc 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -51,8 +51,6 @@ export class SettingUtils { if (data) { for (let [key, item] of this.settings) { item.value = data?.[key] ?? item.value; - this.updateElementFromValue(key); - } } this.plugin.data[this.name] = this.dump(); @@ -82,12 +80,12 @@ export class SettingUtils { * @returns value in html */ take(key: string) { - let item = this.getElement(key) - this.settings.set(key, item) - if (item.type === 'button') { - return item.value + let element = this.elements.get(key) as any; + if (!element){ + return } - return item.value + this.settings.set(key, element.value) + return element.value } /** @@ -257,7 +255,8 @@ export class SettingUtils { } /** - * return the element information + * Set the value in the setting to the value of the element + * and return the element information * @param key key name * @returns element */ @@ -266,19 +265,21 @@ export class SettingUtils { let element = this.elements.get(key) as any; switch (item.type) { case 'checkbox': - item.value = element.checked ? true : false; + element.value = element.checked ? true : false; + element.checked = item.value; break; case 'select': - item.value = element.value; + element.value = item.value; break; case 'slider': - item.value = element.value; + element.value = item.value; + element.ariaLabel = item.value; break; case 'textinput': - item.value = element.value; + element.value = item.value; break; case 'textarea': - item.value = element.value; + element.value = item.value; break; } return element; @@ -328,5 +329,5 @@ export class SettingUtils { break; } } - + } \ No newline at end of file