diff --git a/src/addon.ts b/src/addon.ts index 3bd83c3..bf24463 100644 --- a/src/addon.ts +++ b/src/addon.ts @@ -7,6 +7,7 @@ class Addon { alive: boolean; // Env type, see build.js env: "development" | "production"; + // ztoolkit: MyToolkit; ztoolkit: ZoteroToolkit; locale?: { stringBundle: any; @@ -26,6 +27,7 @@ class Addon { this.data = { alive: true, env: __env__, + // ztoolkit: new MyToolkit(), ztoolkit: new ZoteroToolkit(), }; this.hooks = hooks; @@ -33,4 +35,38 @@ class Addon { } } +/** + * Alternatively, import toolkit modules you use to minify the plugin size. + * + * Steps to replace the default `ztoolkit: ZoteroToolkit` with your `ztoolkit: MyToolkit`: + * + * 1. Uncomment this file's line 30: `ztoolkit: new MyToolkit(),` + * and comment line 31: `ztoolkit: new ZoteroToolkit(),`. + * 2. Uncomment this file's line 10: `ztoolkit: MyToolkit;` in this file + * and comment line 11: `ztoolkit: ZoteroToolkit;`. + * 3. Uncomment `./typing/global.d.ts` line 12: `declare const ztoolkit: import("../src/addon").MyToolkit;` + * and comment line 13: `declare const ztoolkit: import("zotero-plugin-toolkit").ZoteroToolkit;`. + * + * You can now add the modules under the `MyToolkit` class. + */ + +import { BasicTool, unregister } from "zotero-plugin-toolkit/dist/basic"; +import { UITool } from "zotero-plugin-toolkit/dist/tools/ui"; +import { PreferencePaneManager } from "zotero-plugin-toolkit/dist/managers/preferencePane"; + +export class MyToolkit extends BasicTool { + UI: UITool; + PreferencePane: PreferencePaneManager; + + constructor() { + super(); + this.UI = new UITool(this); + this.PreferencePane = new PreferencePaneManager(this); + } + + unregisterAll() { + unregister(this); + } +} + export default Addon; diff --git a/src/index.ts b/src/index.ts index 370021e..0b008dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,8 @@ if (!basicTool.getGlobal("Zotero").AddonTemplate) { _globalThis.ztoolkit = addon.data.ztoolkit; ztoolkit.basicOptions.log.prefix = `[${config.addonName}]`; ztoolkit.basicOptions.log.disableConsole = addon.data.env === "production"; + ztoolkit.UI.elementOptions.enableElementJSONLog = + addon.data.env === "development"; Zotero.AddonTemplate = addon; // Trigger addon hook for initialization addon.hooks.onStartup(); diff --git a/typing/global.d.ts b/typing/global.d.ts index fb221a3..2415475 100644 --- a/typing/global.d.ts +++ b/typing/global.d.ts @@ -9,6 +9,7 @@ declare const _globalThis: { addon: typeof addon; }; +// declare const ztoolkit: import("../src/addon").MyToolkit; declare const ztoolkit: import("zotero-plugin-toolkit").ZoteroToolkit; declare const rootURI: string;