From 4a8de1cc33c12f74a0d80d46af23ebf9bc69a56e Mon Sep 17 00:00:00 2001 From: frostime Date: Thu, 3 Oct 2024 15:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20perf:=20=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=BC=98=E5=8C=96=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- plugin.json | 2 +- src/index.ts | 10 +++- src/libs/inject.ts | 19 ++++++ src/types/i18n.d.ts | 138 ++++++++++++++++++++++++++++++++++++++++++++ src/utils/i18n.ts | 7 +-- 6 files changed, 170 insertions(+), 10 deletions(-) create mode 100644 src/libs/inject.ts create mode 100644 src/types/i18n.d.ts diff --git a/package.json b/package.json index 4ac6e8e..27bdb2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sy-bookmark-plus", - "version": "1.3.3", + "version": "1.4.0-dev1", "type": "module", "description": "A more powerful bookmark", "repository": "", @@ -24,7 +24,7 @@ "minimist": "^1.2.8", "rollup-plugin-livereload": "^2.0.5", "sass": "^1.72.0", - "siyuan": "0.9.9", + "siyuan": "1.0.3", "solid-js": "^1.8.17", "solid-styled-jsx": "^0.27.1", "ts-node": "^10.9.2", diff --git a/plugin.json b/plugin.json index d2492a4..b320dda 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "sy-bookmark-plus", "author": "frostime", "url": "https://github.com/frostime/sy-bookmark-plus", - "version": "1.3.3", + "version": "1.4.0-dev1", "minAppVersion": "3.0.12", "backends": [ "all" diff --git a/src/index.ts b/src/index.ts index 2512ab4..c215d3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ * @Author : frostime * @Date : 2024-06-12 19:48:53 * @FilePath : /src/index.ts - * @LastEditTime : 2024-08-15 17:38:22 + * @LastEditTime : 2024-10-03 14:55:24 * @Description : */ import { @@ -26,11 +26,11 @@ import { setI18n } from "@/utils/i18n"; import "@/index.scss"; import { isMobile } from "./utils"; +import { provide, purge } from "./libs/inject"; let model: BookmarkDataModel; const initBookmark = async (ele: HTMLElement, plugin: PluginBookmarkPlus) => { - await model.updateAll(); ele.classList.add('fn__flex-column'); if (isMobile()) { @@ -42,6 +42,7 @@ const initBookmark = async (ele: HTMLElement, plugin: PluginBookmarkPlus) => { plugin: plugin, model: model }), ele); + await model.updateAll(); }; const destroyBookmark = () => { @@ -65,7 +66,9 @@ export default class PluginBookmarkPlus extends Plugin { } async onload() { - setI18n(this.i18n); + setI18n(this.i18n as I18n); + provide('i18n', this.i18n as I18n); + provide('plugin', this); let svgs = Object.values(Svg); this.addIcons(svgs.join('')); @@ -120,6 +123,7 @@ export default class PluginBookmarkPlus extends Plugin { } onunload(): void { + purge(); destroyBookmark(); bookmarkKeymap.custom = bookmarkKeymap.default; // this.commands = this.commands.filter((command) => command.langKey !== 'F-Misc::Bookmark'); diff --git a/src/libs/inject.ts b/src/libs/inject.ts new file mode 100644 index 0000000..6867186 --- /dev/null +++ b/src/libs/inject.ts @@ -0,0 +1,19 @@ +const Storage = {}; + +export const provide = (key: string, value: T) => { + Storage[key] = value; +} + +export const inject = (key: string): T => { + return Storage[key]; +} + +export const purge = (key?: string) => { + if (key) { + delete Storage[key]; + } else { + for (const key in Storage) { + delete Storage[key]; + } + } +} diff --git a/src/types/i18n.d.ts b/src/types/i18n.d.ts new file mode 100644 index 0000000..3851226 --- /dev/null +++ b/src/types/i18n.d.ts @@ -0,0 +1,138 @@ +interface I18n { + msg: { + ruleFailed: string; + ruleInvalid: string; + itemHasInGroup: string; + itemNotFoundInGroup: string; + groupNameEmpty: string; + }; + itemErr: { + closed: string; + deleted: string; + }; + setting: { + replaceDefault: { + title: string; + description: string; + }; + viewMode: { + title: string; + description: string; + }; + hideClosed: { + title: string; + description: string; + }; + hideDeleted: { + title: string; + description: string; + }; + grouplist: { + title: string; + description: string; + }; + autoRefreshOnExpand: { + title: string; + description: string; + }; + ariaLabel: { + title: string; + description: string; + }; + }; + viewMode: { + bookmark: string; + card: string; + }; + bookmark: { + new: string; + delete: { + title: string; + desc: string; + }; + cache: string; + logo: { + name: string; + setting: string; + add: string; + refresh: string; + expand: string; + collapse: string; + min: string; + }; + }; + group: { + msgexist: string; + msg404: string; + refresh: string; + copyref: string; + copylink: string; + msgcopy: string; + docflow: string; + rename: string; + edit: string; + delete: string; + move: string; + top: string; + up: string; + down: string; + bottom: string; + fromclipboard: string; + msgparse: string; + currentdoc: string; + msgdelconfirm: string[]; + }; + item: { + copyref: string; + copylink: string; + msgcopy: string; + style: string; + transfer: string; + move: string; + top: string; + bottom: string; + del: string; + checkerritem: string; + copyitem: string; + }; + newgroup: { + name: string[]; + type: string[]; + rtype: string[]; + rinput: string; + desc: { + sql: string; + backlinks: string; + attr: string; + }; + choosetemplate: string; + postprocess: { + ariaLabel: string; + name: string; + omit: string; + fb2p: string; + b2doc: string; + }; + }; + bookmarktype: { + normal: string; + dynamic: string; + composed: string; + }; + ruletype: { + sql: string; + backlinks: string; + attr: string; + }; + template: { + sql: { + random: string; + updated: string; + thisday: string; + todo: string; + }; + attr: { + dailynote: string; + }; + }; +} diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts index c42391d..0282af5 100644 --- a/src/utils/i18n.ts +++ b/src/utils/i18n.ts @@ -3,14 +3,13 @@ * @Author : frostime * @Date : 2024-07-07 18:57:06 * @FilePath : /src/utils/i18n.ts - * @LastEditTime : 2024-07-07 21:24:01 + * @LastEditTime : 2024-09-28 22:07:01 * @Description : */ -import type I18n from '@/../dev/i18n/zh_CN.json'; -export let i18n: typeof I18n = {} as any; +export let i18n: I18n = {} as any; -export const setI18n = (_i18n_: any) => { +export const setI18n = (_i18n_: I18n) => { i18n = new Proxy(_i18n_, { set: (..._) => { console.warn("Attempt to modify read-only i18n object");