From f84497f6da331111b1f6a1b05ab1fee00a49cac9 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Sat, 13 Jan 2024 22:07:41 +0800 Subject: [PATCH] add hint type to settingUtil --- scripts/make_dev_link.js | 2 +- src/i18n/en_US.json | 4 +++- src/i18n/zh_CN.json | 5 ++++- src/index.ts | 22 ++++++++++++++++++++++ src/libs/index.d.ts | 2 +- src/libs/setting-utils.ts | 5 +++++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/scripts/make_dev_link.js b/scripts/make_dev_link.js index 845d298..3de72c1 100644 --- a/scripts/make_dev_link.js +++ b/scripts/make_dev_link.js @@ -7,7 +7,7 @@ import readline from 'node:readline'; //Please write the "workspace/data/plugins" directory here //请在这里填写你的 "workspace/data/plugins" 目录 -let targetDir = ''; +let targetDir = '/home/zxkmm/文档/siyuan_dev/data/plugins'; //Like this // let targetDir = `H:\\SiYuanDevSpace\\data\\plugins`; //******************************************************************************************** diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index c7ed102..7a11256 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -14,5 +14,7 @@ "name": "SiYuan", "hello": { "makesure": "Before using this template, please read the offical sample, make sure that you've known about the pipeline for plugin developing." - } + }, + "hintTitle":"About", + "hintDesc":"plugin-sample-vite-svelte
@frostime
@88250
@zxkmm" } \ No newline at end of file diff --git a/src/i18n/zh_CN.json b/src/i18n/zh_CN.json index 49a7af8..9b6231e 100644 --- a/src/i18n/zh_CN.json +++ b/src/i18n/zh_CN.json @@ -14,5 +14,8 @@ "name": "思源", "hello": { "makesure": "使用这个模板之前,请阅读官方教程, 确保自己已经理解了插件的基本开发流程。" - } + }, + "hintTitle":"关于", + "hintDesc":"🔗 plugin-sample-vite-svelte
💻 @frostime
💻 @88250
💻 @zxkmm" + } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d70da65..40c6da9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -160,6 +160,13 @@ export default class PluginSample extends Plugin { }); this.settingUtils = new SettingUtils(this, STORAGE_NAME); + + try { + this.settingUtils.load(); + } catch (error) { + console.error("Error loading settings storage, probably empty config json:", error); + } + this.settingUtils.addItem({ key: "Input", value: "", @@ -217,6 +224,13 @@ export default class PluginSample extends Plugin { } } }); + this.settingUtils.addItem({ + key: "Hint", + value: "", + type: "hint", + title: this.i18n.hintTitle, + description: this.i18n.hintDesc, + }); this.protyleSlash = [{ filter: ["insert emoji 😊", "插入表情 😊", "crbqwx"], @@ -234,6 +248,14 @@ export default class PluginSample extends Plugin { // this.loadData(STORAGE_NAME); this.settingUtils.load(); console.log(`frontend: ${getFrontend()}; backend: ${getBackend()}`); + + console.log( + "Official settings value calling example:\n" + + this.settingUtils.get("InputArea") + "\n" + + this.settingUtils.get("Slider") + "\n" + + this.settingUtils.get("Select") + "\n" + ); + let tabDiv = document.createElement("div"); new HelloExample({ target: tabDiv, diff --git a/src/libs/index.d.ts b/src/libs/index.d.ts index b900c9f..04b53f0 100644 --- a/src/libs/index.d.ts +++ b/src/libs/index.d.ts @@ -1,4 +1,4 @@ -type TSettingItemType = "checkbox" | "select" | "textinput" | "textarea" | "number" | "slider" | "button"; +type TSettingItemType = "checkbox" | "select" | "textinput" | "textarea" | "number" | "slider" | "button" | "hint"; interface ISettingItem { key: string; value: any; diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index 0446020..d0ae912 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -144,6 +144,11 @@ export class SettingUtils { buttonElement.onclick = item.button?.callback ?? (() => {}); itemElement = buttonElement; break; + case 'hint': + let hintElement: HTMLElement = document.createElement('div'); + hintElement.className = 'b3-label fn__flex-center'; + itemElement = hintElement; + break; } this.elements.set(item.key, itemElement); this.plugin.setting.addItem({