add: custom toolkit modules example
This commit is contained in:
parent
d48a628693
commit
4a06cd0535
36
src/addon.ts
36
src/addon.ts
@ -7,6 +7,7 @@ class Addon {
|
|||||||
alive: boolean;
|
alive: boolean;
|
||||||
// Env type, see build.js
|
// Env type, see build.js
|
||||||
env: "development" | "production";
|
env: "development" | "production";
|
||||||
|
// ztoolkit: MyToolkit;
|
||||||
ztoolkit: ZoteroToolkit;
|
ztoolkit: ZoteroToolkit;
|
||||||
locale?: {
|
locale?: {
|
||||||
stringBundle: any;
|
stringBundle: any;
|
||||||
@ -26,6 +27,7 @@ class Addon {
|
|||||||
this.data = {
|
this.data = {
|
||||||
alive: true,
|
alive: true,
|
||||||
env: __env__,
|
env: __env__,
|
||||||
|
// ztoolkit: new MyToolkit(),
|
||||||
ztoolkit: new ZoteroToolkit(),
|
ztoolkit: new ZoteroToolkit(),
|
||||||
};
|
};
|
||||||
this.hooks = hooks;
|
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;
|
export default Addon;
|
||||||
|
@ -15,6 +15,8 @@ if (!basicTool.getGlobal("Zotero").AddonTemplate) {
|
|||||||
_globalThis.ztoolkit = addon.data.ztoolkit;
|
_globalThis.ztoolkit = addon.data.ztoolkit;
|
||||||
ztoolkit.basicOptions.log.prefix = `[${config.addonName}]`;
|
ztoolkit.basicOptions.log.prefix = `[${config.addonName}]`;
|
||||||
ztoolkit.basicOptions.log.disableConsole = addon.data.env === "production";
|
ztoolkit.basicOptions.log.disableConsole = addon.data.env === "production";
|
||||||
|
ztoolkit.UI.elementOptions.enableElementJSONLog =
|
||||||
|
addon.data.env === "development";
|
||||||
Zotero.AddonTemplate = addon;
|
Zotero.AddonTemplate = addon;
|
||||||
// Trigger addon hook for initialization
|
// Trigger addon hook for initialization
|
||||||
addon.hooks.onStartup();
|
addon.hooks.onStartup();
|
||||||
|
1
typing/global.d.ts
vendored
1
typing/global.d.ts
vendored
@ -9,6 +9,7 @@ declare const _globalThis: {
|
|||||||
addon: typeof addon;
|
addon: typeof addon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// declare const ztoolkit: import("../src/addon").MyToolkit;
|
||||||
declare const ztoolkit: import("zotero-plugin-toolkit").ZoteroToolkit;
|
declare const ztoolkit: import("zotero-plugin-toolkit").ZoteroToolkit;
|
||||||
|
|
||||||
declare const rootURI: string;
|
declare const rootURI: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user