From 9f54e7046cf6070ac2ae5547240ea8d45e0425ae Mon Sep 17 00:00:00 2001 From: frostime Date: Tue, 30 Apr 2024 22:15:50 +0800 Subject: [PATCH 01/27] =?UTF-8?q?=E2=9C=A8=20misc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/setting-utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index 948dc2f..33c5cac 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-30 16:42:23 + * @LastEditTime : 2024-04-30 22:15:25 * @Description : */ @@ -105,7 +105,7 @@ export class SettingUtils { args.callback(data); } this.plugin.data[this.name] = data; - this.save(); + this.save(data); }, destroyCallback: () => { //Restore the original value @@ -128,8 +128,8 @@ export class SettingUtils { return data; } - async save() { - let data = this.dump(); + async save(data?: any) { + data = data ?? this.dump(); await this.plugin.saveData(this.file, this.dump()); console.debug('Save config:', data); return data; From 03ab34f5523274b3c416801359d8df32f8617141 Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 1 May 2024 17:45:05 +0800 Subject: [PATCH 02/27] =?UTF-8?q?=E2=9A=A1=20=E7=A6=81=E7=94=A8=E6=80=9D?= =?UTF-8?q?=E6=BA=90=E5=86=85=E9=83=A8=E7=9A=84=20enter=20confirm=20?= =?UTF-8?q?=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/setting-utils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index 33c5cac..ae316e2 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-30 22:15:25 + * @LastEditTime : 2024-05-01 17:44:16 * @Description : */ @@ -285,6 +285,13 @@ export class SettingUtils { createDefaultElement(item: ISettingUtilsItem) { let itemElement: HTMLElement; + //阻止思源内置的回车键确认 + const preventEnterConfirm = (e) => { + if (e.key === 'Enter') { + e.preventDefault(); + e.stopImmediatePropagation(); + } + } switch (item.type) { case 'checkbox': let element: HTMLInputElement = document.createElement('input'); @@ -330,7 +337,7 @@ export class SettingUtils { textInputElement.value = item.value; textInputElement.onchange = item.action?.callback ?? (() => { }); itemElement = textInputElement; - + textInputElement.addEventListener('keydown', preventEnterConfirm); break; case 'textarea': let textareaElement: HTMLTextAreaElement = document.createElement('textarea'); @@ -345,6 +352,7 @@ export class SettingUtils { numberElement.className = 'b3-text-field fn__flex-center fn__size200'; numberElement.value = item.value; itemElement = numberElement; + numberElement.addEventListener('keydown', preventEnterConfirm); break; case 'button': let buttonElement: HTMLButtonElement = document.createElement('button'); From 67d6024a04dce60765347c35c6d2422c33971321 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 1 Jun 2024 16:29:07 +0800 Subject: [PATCH 03/27] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20kits=20about=20?= =?UTF-8?q?dialogs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/dialog.ts | 121 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/libs/dialog.ts diff --git a/src/libs/dialog.ts b/src/libs/dialog.ts new file mode 100644 index 0000000..ea2b187 --- /dev/null +++ b/src/libs/dialog.ts @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2024 by frostime. All Rights Reserved. + * @Author : frostime + * @Date : 2024-03-23 21:37:33 + * @FilePath : /src/libs/dialog.ts + * @LastEditTime : 2024-06-01 16:28:30 + * @Description : Kits about dialogs + */ +import { Dialog } from "siyuan"; + +export const inputDialog = (args: { + title: string, placeholder?: string, defaultText?: string, + confirm?: (text: string) => void, cancel?: () => void, + width?: string, height?: string +}) => { + const dialog = new Dialog({ + title: args.title, + content: `
+
+
+
+
+ +
`, + width: args.width ?? "520px", + height: args.height + }); + const target: HTMLTextAreaElement = dialog.element.querySelector(".b3-dialog__content>div.ft__breakword>textarea"); + const btnsElement = dialog.element.querySelectorAll(".b3-button"); + btnsElement[0].addEventListener("click", () => { + if (args?.cancel) { + args.cancel(); + } + dialog.destroy(); + }); + btnsElement[1].addEventListener("click", () => { + if (args?.confirm) { + args.confirm(target.value); + } + dialog.destroy(); + }); +}; + +export const inputDialogSync = async (args: { + title: string, placeholder?: string, defaultText?: string, + width?: string, height?: string +}) => { + return new Promise((resolve) => { + let newargs = { + ...args, confirm: (text) => { + resolve(text); + }, cancel: () => { + resolve(null); + } + }; + inputDialog(newargs); + }); +} + + +interface IConfirmDialogArgs { + title: string; + content: string | HTMLElement; + confirm?: (ele?: HTMLElement) => void; + cancel?: (ele?: HTMLElement) => void; + width?: string; + height?: string; +} + +export const confirmDialog = (args: IConfirmDialogArgs) => { + const { title, content, confirm, cancel, width, height } = args; + + const dialog = new Dialog({ + title, + content: `
+
+
+
+
+
+ +
`, + width: width, + height: height + }); + + const target: HTMLElement = dialog.element.querySelector(".b3-dialog__content>div.ft__breakword"); + if (typeof content === "string") { + target.innerHTML = content; + } else { + target.appendChild(content); + } + + const btnsElement = dialog.element.querySelectorAll(".b3-button"); + btnsElement[0].addEventListener("click", () => { + if (cancel) { + cancel(target); + } + dialog.destroy(); + }); + btnsElement[1].addEventListener("click", () => { + if (confirm) { + confirm(target); + } + dialog.destroy(); + }); +}; + + +export const confirmDialogSync = async (args: IConfirmDialogArgs) => { + return new Promise((resolve) => { + let newargs = { + ...args, confirm: (ele: HTMLElement) => { + resolve(ele); + }, cancel: (ele: HTMLElement) => { + resolve(ele); + } + }; + confirmDialog(newargs); + }); +}; From 81d5bee160e9b8b505a09b523c27fea2f89d18a3 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 1 Jun 2024 16:35:02 +0800 Subject: [PATCH 04/27] =?UTF-8?q?=F0=9F=93=9Ddocs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 ++++- README.md | 2 +- README_zh_CN.md | 2 +- package.json | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce36ec8..af04807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -## 0.3.5 2024-03 +## v0.3.5 2024-04-30 + +* [Add `direction` to plugin method `Setting.addItem`](https://github.com/siyuan-note/siyuan/issues/11183) + ## 0.3.4 2024-02-20 diff --git a/README.md b/README.md index 09c8cdd..5f3c813 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ 2. Use symbolic linking instead of putting the project into the plugins directory program development 3. Built-in support for the svelte framework - > If don't want svelte, turn to this template: [frostime/plugin-sample-vite](https://github.com/frostime/plugin-sample-vite) + > **If don't want svelte, turn to this template**: [frostime/plugin-sample-vite](https://github.com/frostime/plugin-sample-vite) 4. Provides a github action template to automatically generate package.zip and upload to new release diff --git a/README_zh_CN.md b/README_zh_CN.md index ca35f7c..9f447fa 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -10,7 +10,7 @@ 2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发 3. 内置对 svelte 框架的支持 - > 如果不想要 svelte,请移步 [frostime/plugin-sample-vite](https://github.com/frostime/plugin-sample-vite) + > **如果不想要 svelte,请移步这个模板:** [frostime/plugin-sample-vite](https://github.com/frostime/plugin-sample-vite) 4. 提供一个github action 模板,能自动生成package.zip并上传到新版本中 diff --git a/package.json b/package.json index 44cdd78..fd49b9c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "minimist": "^1.2.8", "rollup-plugin-livereload": "^2.0.5", "sass": "^1.63.3", - "siyuan": "0.9.8", + "siyuan": "0.9.9", "svelte": "^4.2.0", "ts-node": "^10.9.1", "typescript": "^5.1.3", From 9c7572b820189d61320b84f25132a1d44782f71b Mon Sep 17 00:00:00 2001 From: frostime Date: Tue, 4 Jun 2024 15:04:07 +0800 Subject: [PATCH 05/27] =?UTF-8?q?=F0=9F=90=9B=20getFile=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/api.ts b/src/api.ts index c227518..0a421ce 100644 --- a/src/api.ts +++ b/src/api.ts @@ -6,7 +6,7 @@ * API 文档见 [API_zh_CN.md](https://github.com/siyuan-note/siyuan/blob/master/API_zh_CN.md) */ -import { fetchSyncPost, IWebSocketData } from "siyuan"; +import { fetchPost, fetchSyncPost, IWebSocketData } from "siyuan"; export async function request(url: string, data: any) { @@ -328,12 +328,11 @@ export async function getFile(path: string): Promise { path: path } let url = '/api/file/getFile'; - try { - let file = await fetchSyncPost(url, data); - return file; - } catch (error_msg) { - return null; - } + return new Promise((resolve, _) => { + fetchPost(url, data, (content: any) => { + resolve(content) + }); + }); } export async function putFile(path: string, isDir: boolean, file: any) { From 49eb06330da596e276afd399f993a340957f691f Mon Sep 17 00:00:00 2001 From: Frostime Date: Thu, 6 Jun 2024 22:31:20 +0800 Subject: [PATCH 06/27] =?UTF-8?q?=F0=9F=94=A8=20Remove=20the=20default=20f?= =?UTF-8?q?und=20in=20plugin.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.json b/plugin.json index 071b2a3..865a240 100644 --- a/plugin.json +++ b/plugin.json @@ -32,7 +32,7 @@ }, "funding": { "custom": [ - "https://afdian.net/a/frostime" + "" ] }, "keywords": [ From 6d75a46a56c0aad62a74b0ee7943fc4e1601fc56 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 8 Jun 2024 18:30:53 +0800 Subject: [PATCH 07/27] =?UTF-8?q?=F0=9F=94=A8=20refactor:=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E5=9F=BA=E4=BA=8E=20svelte=20=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=9D=A2=E6=9D=BF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/index.d.ts | 2 +- src/libs/item-input.svelte | 108 ++++++++++++++++++++++++++++++++++ src/libs/item-wrap.svelte | 51 ++++++++++++++++ src/libs/setting-item.svelte | 105 --------------------------------- src/libs/setting-panel.svelte | 31 ++++++---- src/setting-example.svelte | 9 +++ 6 files changed, 187 insertions(+), 119 deletions(-) create mode 100644 src/libs/item-input.svelte create mode 100644 src/libs/item-wrap.svelte delete mode 100644 src/libs/setting-item.svelte diff --git a/src/libs/index.d.ts b/src/libs/index.d.ts index ab2f6c3..27a27ed 100644 --- a/src/libs/index.d.ts +++ b/src/libs/index.d.ts @@ -28,12 +28,12 @@ interface ISettingItemCore { interface ISettingItem extends ISettingItemCore { title: string; description: string; + direction?: "row" | "column"; } //Interface for setting-utils interface ISettingUtilsItem extends ISettingItem { - direction?: "row" | "column"; action?: { callback: () => void; } diff --git a/src/libs/item-input.svelte b/src/libs/item-input.svelte new file mode 100644 index 0000000..3a42b45 --- /dev/null +++ b/src/libs/item-input.svelte @@ -0,0 +1,108 @@ + + + +{#if type === "checkbox"} + + +{:else if type === "textinput"} + + +{:else if type === "textarea"} +