From 7159755c7074be1c7054141cc74bb50b0ece02f6 Mon Sep 17 00:00:00 2001 From: frostime Date: Tue, 30 Apr 2024 16:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20=E8=B0=83=E6=95=B4=20setting=20?= =?UTF-8?q?=E7=9A=84=20interface=20=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/index.d.ts | 32 +++++++++++++++++++++++++------- src/libs/setting-utils.ts | 8 ++++---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/libs/index.d.ts b/src/libs/index.d.ts index 9e0b889..7ca733f 100644 --- a/src/libs/index.d.ts +++ b/src/libs/index.d.ts @@ -1,10 +1,17 @@ +/* + * Copyright (c) 2024 by frostime. All Rights Reserved. + * @Author : frostime + * @Date : 2024-04-19 18:30:12 + * @FilePath : /src/libs/index.d.ts + * @LastEditTime : 2024-04-30 15:53:15 + * @Description : + */ type TSettingItemType = "checkbox" | "select" | "textinput" | "textarea" | "number" | "slider" | "button" | "hint"; -interface ISettingItem { + +interface ISettingItemCore { + type: TSettingItemType; key: string; value: any; - type: TSettingItemType; - title: string; - description?: string; placeholder?: string; slider?: { min: number; @@ -12,12 +19,23 @@ interface ISettingItem { step: number; }; options?: { [key: string | number]: string }; - action?: { - callback: () => void; - } button?: { label: string; callback: () => void; } +} + +interface ISettingItem extends ISettingItemCore { + title: string; + description: string; +} + + +//Interface for setting-utils +interface ISettingUtilsItem extends ISettingItem { + direction?: "row" | "column"; + action?: { + callback: () => void; + } createElement?: (currentVal: any) => HTMLElement; } diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index f43ab36..2a3926b 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -3,7 +3,7 @@ * @Author : frostime * @Date : 2023-12-17 18:28:19 * @FilePath : /src/libs/setting-utils.ts - * @LastEditTime : 2024-04-29 17:17:19 + * @LastEditTime : 2024-04-30 15:50:07 * @Description : */ @@ -56,7 +56,7 @@ export class SettingUtils { name: string; file: string; - settings: Map = new Map(); + settings: Map = new Map(); elements: Map = new Map(); constructor(args: { @@ -214,7 +214,7 @@ export class SettingUtils { return data; } - addItem(item: ISettingItem) { + addItem(item: ISettingUtilsItem) { this.settings.set(item.key, item); if (item.createElement === undefined) { let itemElement = this.createDefaultElement(item); @@ -242,7 +242,7 @@ export class SettingUtils { } } - createDefaultElement(item: ISettingItem) { + createDefaultElement(item: ISettingUtilsItem) { let itemElement: HTMLElement; switch (item.type) { case 'checkbox':