From 786cc5e93311b94440c7277519be090f0369e8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=94=E9=98=B3=E9=99=8C=E5=AE=A2?= Date: Wed, 24 Apr 2024 12:17:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9getElement()=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8C=E6=96=B9=E6=B3=95=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/setting-utils.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index 321b019..a6fd592 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -255,8 +255,7 @@ export class SettingUtils { } /** - * Set the value in the setting to the value of the element - * and return the element information + * return the element information * @param key key name * @returns element */ @@ -265,21 +264,21 @@ export class SettingUtils { let element = this.elements.get(key) as any; switch (item.type) { case 'checkbox': - element.value = element.checked ? true : false; - element.checked = item.value; + item.value = element.checked ? true : false; + element.checked = element.value; break; case 'select': - element.value = item.value; + item.value = element.value; break; case 'slider': - element.value = item.value; + item.value = element.value; element.ariaLabel = item.value; break; case 'textinput': - element.value = item.value; + item.value = element.value; break; case 'textarea': - element.value = item.value; + item.value = element.value; break; } return element; From 8f27804c8397a541acb69c15b909327b1e3b0973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=94=E9=98=B3=E9=99=8C=E5=AE=A2?= Date: Wed, 24 Apr 2024 14:23:51 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/setting-utils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index a6fd592..8ef8074 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -265,14 +265,12 @@ export class SettingUtils { switch (item.type) { case 'checkbox': item.value = element.checked ? true : false; - element.checked = element.value; break; case 'select': item.value = element.value; break; case 'slider': item.value = element.value; - element.ariaLabel = item.value; break; case 'textinput': item.value = element.value; From 587d5f21125c213d726af5be03d3ded7682002a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=94=E9=98=B3=E9=99=8C=E5=AE=A2?= Date: Wed, 24 Apr 2024 14:46:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=90=8E,=E6=95=B0=E6=8D=AE=E5=B7=B2?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD,=E4=BD=86=E6=B2=A1=E6=9C=89=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=88=B0=E8=AE=BE=E7=BD=AE=E9=A1=B5=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/setting-utils.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index 8ef8074..dd16ca5 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -51,6 +51,8 @@ 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(); 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 4/4] =?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