add: _globalThis
This commit is contained in:
		
							parent
							
								
									4f2e81e661
								
							
						
					
					
						commit
						6426ae5198
					
				
							
								
								
									
										17
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								README.md
									
									
									
									
									
								
							@ -62,6 +62,19 @@ This is an addon/plugin template for [Zotero](https://www.zotero.org/).
 | 
				
			|||||||
   - `events.ts` > `onUninit` is called. Remove UI elements(`unInitViews`), preference panes(`uninitPrefs`), or anything created by the plugin.
 | 
					   - `events.ts` > `onUninit` is called. Remove UI elements(`unInitViews`), preference panes(`uninitPrefs`), or anything created by the plugin.
 | 
				
			||||||
   - Remove scripts and release resources.
 | 
					   - Remove scripts and release resources.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### About Global Variables
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The bootstrapped plugin runs in a sandbox, which does not have default global variables like `Zotero` or `window`, which we used to have in the overlay plugins' window environment.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This template registers the following variables to the global scope:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```ts
 | 
				
			||||||
 | 
					Zotero, ZoteroPane, Zotero_Tabs, window, document, rootURI, ZToolkit
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					See `src/events.ts` > `initGlobalVariables` for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Examples
 | 
					### Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
See https://github.com/windingwind/zotero-plugin-toolkit for more detailed API documentations.
 | 
					See https://github.com/windingwind/zotero-plugin-toolkit for more detailed API documentations.
 | 
				
			||||||
@ -134,7 +147,7 @@ There are more advanced APIs for creating elements in batch: `creatElementsFromJ
 | 
				
			|||||||
Using [Zotero Plugin Toolkit:ItemTreeTool](https://github.com/windingwind/zotero-plugin-toolkit/blob/HEAD/docs/zotero-plugin-toolkit.itemtreetool.md) to register an extra column in `src/views.ts`.
 | 
					Using [Zotero Plugin Toolkit:ItemTreeTool](https://github.com/windingwind/zotero-plugin-toolkit/blob/HEAD/docs/zotero-plugin-toolkit.itemtreetool.md) to register an extra column in `src/views.ts`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```ts
 | 
					```ts
 | 
				
			||||||
this._Addon.toolkit.ItemTree.registerExample();
 | 
					ZToolkit.ItemTree.registerExample();
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
This will register a column with dataKey `test`. Looks like:
 | 
					This will register a column with dataKey `test`. Looks like:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -143,7 +156,7 @@ This will register a column with dataKey `test`. Looks like:
 | 
				
			|||||||
Remember to unregister it when exiting.
 | 
					Remember to unregister it when exiting.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```ts
 | 
					```ts
 | 
				
			||||||
this._Addon.toolkit.ItemTree.unregister("test");
 | 
					ZToolkit.ItemTree.unregister("test");
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Directory Structure
 | 
					### Directory Structure
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										6
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@ -81,15 +81,11 @@ async function startup({ id, version, resourceURI, rootURI }, reason) {
 | 
				
			|||||||
    rootURI = resourceURI.spec;
 | 
					    rootURI = resourceURI.spec;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const window = Zotero.getMainWindow();
 | 
					 | 
				
			||||||
  // Global variables for plugin code
 | 
					  // Global variables for plugin code
 | 
				
			||||||
  const ctx = {
 | 
					  const ctx = {
 | 
				
			||||||
    Zotero,
 | 
					 | 
				
			||||||
    rootURI,
 | 
					    rootURI,
 | 
				
			||||||
    window,
 | 
					 | 
				
			||||||
    document: window.document,
 | 
					 | 
				
			||||||
    ZoteroPane: Zotero.getActiveZoteroPane(),
 | 
					 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					  ctx._globalThis = ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Services.scriptloader.loadSubScript(
 | 
					  Services.scriptloader.loadSubScript(
 | 
				
			||||||
    `${rootURI}/chrome/content/scripts/index.js`,
 | 
					    `${rootURI}/chrome/content/scripts/index.js`,
 | 
				
			||||||
 | 
				
			|||||||
@ -3,13 +3,7 @@ import AddonPrefs from "./prefs";
 | 
				
			|||||||
import AddonViews from "./views";
 | 
					import AddonViews from "./views";
 | 
				
			||||||
import AddonLocale from "./locale";
 | 
					import AddonLocale from "./locale";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ZoteroToolkit from "zotero-plugin-toolkit";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Addon {
 | 
					class Addon {
 | 
				
			||||||
  // A global Zotero instance
 | 
					 | 
				
			||||||
  public Zotero!: _ZoteroConstructable;
 | 
					 | 
				
			||||||
  // Root path to access the resources
 | 
					 | 
				
			||||||
  public rootURI!: string;
 | 
					 | 
				
			||||||
  // Env type, see build.js
 | 
					  // Env type, see build.js
 | 
				
			||||||
  public env!: "development" | "production";
 | 
					  public env!: "development" | "production";
 | 
				
			||||||
  // Lifecycle events
 | 
					  // Lifecycle events
 | 
				
			||||||
@ -20,15 +14,12 @@ class Addon {
 | 
				
			|||||||
  public prefs: AddonPrefs;
 | 
					  public prefs: AddonPrefs;
 | 
				
			||||||
  // Runtime locale with .properties
 | 
					  // Runtime locale with .properties
 | 
				
			||||||
  public locale: AddonLocale;
 | 
					  public locale: AddonLocale;
 | 
				
			||||||
  // A toolkit instance. See zotero-plugin-toolkit
 | 
					 | 
				
			||||||
  public toolkit: ZoteroToolkit;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor() {
 | 
					  constructor() {
 | 
				
			||||||
    this.events = new AddonEvents(this);
 | 
					    this.events = new AddonEvents(this);
 | 
				
			||||||
    this.views = new AddonViews(this);
 | 
					    this.views = new AddonViews(this);
 | 
				
			||||||
    this.prefs = new AddonPrefs(this);
 | 
					    this.prefs = new AddonPrefs(this);
 | 
				
			||||||
    this.locale = new AddonLocale(this);
 | 
					    this.locale = new AddonLocale(this);
 | 
				
			||||||
    this.toolkit = new ZoteroToolkit();
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
import Addon from "./addon";
 | 
					import Addon from "./addon";
 | 
				
			||||||
import AddonModule from "./module";
 | 
					import AddonModule from "./module";
 | 
				
			||||||
import { config } from "../package.json";
 | 
					import { config } from "../package.json";
 | 
				
			||||||
 | 
					import ZoteroToolkit from "zotero-plugin-toolkit";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AddonEvents extends AddonModule {
 | 
					class AddonEvents extends AddonModule {
 | 
				
			||||||
  constructor(parent: Addon) {
 | 
					  constructor(parent: Addon) {
 | 
				
			||||||
@ -9,18 +10,16 @@ class AddonEvents extends AddonModule {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // This function is the setup code of the addon
 | 
					  // This function is the setup code of the addon
 | 
				
			||||||
  public async onInit() {
 | 
					  public async onInit() {
 | 
				
			||||||
    this._Addon.Zotero = Zotero;
 | 
					    this.initGlobalVariables();
 | 
				
			||||||
    // @ts-ignore
 | 
					    // @ts-ignore
 | 
				
			||||||
    this._Addon.rootURI = rootURI;
 | 
					 | 
				
			||||||
    const development = "development";
 | 
					    const development = "development";
 | 
				
			||||||
    const production = "production";
 | 
					    const production = "production";
 | 
				
			||||||
    // The env will be replaced after esbuild
 | 
					    // The env will be replaced after esbuild
 | 
				
			||||||
    // @ts-ignore
 | 
					    // @ts-ignore
 | 
				
			||||||
    this._Addon.env = __env__;
 | 
					    this._Addon.env = __env__;
 | 
				
			||||||
    this._Addon.toolkit.Tool.logOptionsGlobal.prefix = `[${config.addonName}]`;
 | 
					    ZToolkit.Tool.logOptionsGlobal.disableConsole =
 | 
				
			||||||
    this._Addon.toolkit.Tool.logOptionsGlobal.disableConsole =
 | 
					 | 
				
			||||||
      this._Addon.env === "production";
 | 
					      this._Addon.env === "production";
 | 
				
			||||||
    this._Addon.toolkit.Tool.log("init called");
 | 
					    ZToolkit.Tool.log("init called");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Initialize locale provider
 | 
					    // Initialize locale provider
 | 
				
			||||||
    this._Addon.locale.initLocale();
 | 
					    this._Addon.locale.initLocale();
 | 
				
			||||||
@ -33,7 +32,7 @@ class AddonEvents extends AddonModule {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public onUnInit(): void {
 | 
					  public onUnInit(): void {
 | 
				
			||||||
    this._Addon.toolkit.Tool.log("uninit called");
 | 
					    ZToolkit.Tool.log("uninit called");
 | 
				
			||||||
    this.unInitPrefs();
 | 
					    this.unInitPrefs();
 | 
				
			||||||
    //  Remove elements and do clean up
 | 
					    //  Remove elements and do clean up
 | 
				
			||||||
    this._Addon.views.unInitViews();
 | 
					    this._Addon.views.unInitViews();
 | 
				
			||||||
@ -41,6 +40,17 @@ class AddonEvents extends AddonModule {
 | 
				
			|||||||
    Zotero.AddonTemplate = undefined;
 | 
					    Zotero.AddonTemplate = undefined;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private initGlobalVariables() {
 | 
				
			||||||
 | 
					    _globalThis.ZToolkit = new ZoteroToolkit();
 | 
				
			||||||
 | 
					    ZToolkit.Tool.logOptionsGlobal.prefix = `[${config.addonName}]`;
 | 
				
			||||||
 | 
					    _globalThis.Zotero = ZToolkit.Compat.getGlobal("Zotero");
 | 
				
			||||||
 | 
					    _globalThis.ZoteroPane = ZToolkit.Compat.getGlobal("ZoteroPane");
 | 
				
			||||||
 | 
					    _globalThis.Zotero_Tabs = ZToolkit.Compat.getGlobal("Zotero_Tabs");
 | 
				
			||||||
 | 
					    _globalThis.window = ZToolkit.Compat.getGlobal("window");
 | 
				
			||||||
 | 
					    _globalThis.document = ZToolkit.Compat.getGlobal("document");
 | 
				
			||||||
 | 
					    ZToolkit.Tool.log("initializeing global variables");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private initNotifier() {
 | 
					  private initNotifier() {
 | 
				
			||||||
    const callback = {
 | 
					    const callback = {
 | 
				
			||||||
      notify: async (
 | 
					      notify: async (
 | 
				
			||||||
@ -83,7 +93,7 @@ class AddonEvents extends AddonModule {
 | 
				
			|||||||
  private initPrefs() {
 | 
					  private initPrefs() {
 | 
				
			||||||
    const prefOptions = {
 | 
					    const prefOptions = {
 | 
				
			||||||
      pluginID: config.addonID,
 | 
					      pluginID: config.addonID,
 | 
				
			||||||
      src: this._Addon.rootURI + "chrome/content/preferences.xhtml",
 | 
					      src: rootURI + "chrome/content/preferences.xhtml",
 | 
				
			||||||
      label: this._Addon.locale.getString("prefs.title"),
 | 
					      label: this._Addon.locale.getString("prefs.title"),
 | 
				
			||||||
      image: `chrome://${config.addonRef}/content/icons/favicon.png`,
 | 
					      image: `chrome://${config.addonRef}/content/icons/favicon.png`,
 | 
				
			||||||
      extraDTD: [`chrome://${config.addonRef}/locale/overlay.dtd`],
 | 
					      extraDTD: [`chrome://${config.addonRef}/locale/overlay.dtd`],
 | 
				
			||||||
@ -92,16 +102,16 @@ class AddonEvents extends AddonModule {
 | 
				
			|||||||
        this._Addon.prefs.initPreferences(win);
 | 
					        this._Addon.prefs.initPreferences(win);
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    if (this._Addon.toolkit.Compat.isZotero7()) {
 | 
					    if (ZToolkit.Compat.isZotero7()) {
 | 
				
			||||||
      Zotero.PreferencePanes.register(prefOptions);
 | 
					      Zotero.PreferencePanes.register(prefOptions);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      this._Addon.toolkit.Compat.registerPrefPane(prefOptions);
 | 
					      ZToolkit.Compat.registerPrefPane(prefOptions);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private unInitPrefs() {
 | 
					  private unInitPrefs() {
 | 
				
			||||||
    if (!this._Addon.toolkit.Compat.isZotero7()) {
 | 
					    if (!ZToolkit.Compat.isZotero7()) {
 | 
				
			||||||
      this._Addon.toolkit.Compat.unregisterPrefPane();
 | 
					      ZToolkit.Compat.unregisterPrefPane();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							@ -1,15 +1,5 @@
 | 
				
			|||||||
import Addon from "./addon";
 | 
					import Addon from "./addon";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Globals: bootstrap.js > ctx
 | 
					 | 
				
			||||||
 * const ctx = {
 | 
					 | 
				
			||||||
    Zotero,
 | 
					 | 
				
			||||||
    rootURI,
 | 
					 | 
				
			||||||
    window,
 | 
					 | 
				
			||||||
    document: window.document,
 | 
					 | 
				
			||||||
    ZoteroPane: Zotero.getActiveZoteroPane(),
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
if (!Zotero.AddonTemplate) {
 | 
					if (!Zotero.AddonTemplate) {
 | 
				
			||||||
  Zotero.AddonTemplate = new Addon();
 | 
					  Zotero.AddonTemplate = new Addon();
 | 
				
			||||||
  // @ts-ignore
 | 
					  // @ts-ignore
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@ class AddonPrefs extends AddonModule {
 | 
				
			|||||||
    // This function is called when the prefs window is opened
 | 
					    // This function is called when the prefs window is opened
 | 
				
			||||||
    // See addon/chrome/content/preferences.xul onpaneload
 | 
					    // See addon/chrome/content/preferences.xul onpaneload
 | 
				
			||||||
    this._window = _window;
 | 
					    this._window = _window;
 | 
				
			||||||
    this._Addon.toolkit.Tool.log("init preferences");
 | 
					    ZToolkit.Tool.log("init preferences");
 | 
				
			||||||
    this.updatePrefsUI();
 | 
					    this.updatePrefsUI();
 | 
				
			||||||
    this.bindPrefEvents();
 | 
					    this.bindPrefEvents();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -20,14 +20,14 @@ class AddonPrefs extends AddonModule {
 | 
				
			|||||||
    // You can initialize some UI elements on prefs window
 | 
					    // You can initialize some UI elements on prefs window
 | 
				
			||||||
    // with this._window.document
 | 
					    // with this._window.document
 | 
				
			||||||
    // Or bind some events to the elements
 | 
					    // Or bind some events to the elements
 | 
				
			||||||
    this._Addon.toolkit.Tool.log("init preferences UI");
 | 
					    ZToolkit.Tool.log("init preferences UI");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private bindPrefEvents() {
 | 
					  private bindPrefEvents() {
 | 
				
			||||||
    this._window.document
 | 
					    this._window.document
 | 
				
			||||||
      .querySelector(`#zotero-prefpane-${config.addonRef}-enable`)
 | 
					      .querySelector(`#zotero-prefpane-${config.addonRef}-enable`)
 | 
				
			||||||
      ?.addEventListener("command", (e) => {
 | 
					      ?.addEventListener("command", (e) => {
 | 
				
			||||||
        this._Addon.toolkit.Tool.log(e);
 | 
					        ZToolkit.Tool.log(e);
 | 
				
			||||||
        this._window.alert(
 | 
					        this._window.alert(
 | 
				
			||||||
          `Successfully changed to ${(e.target as XUL.Checkbox).checked}!`
 | 
					          `Successfully changed to ${(e.target as XUL.Checkbox).checked}!`
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
@ -36,7 +36,7 @@ class AddonPrefs extends AddonModule {
 | 
				
			|||||||
    this._window.document
 | 
					    this._window.document
 | 
				
			||||||
      .querySelector(`#zotero-prefpane-${config.addonRef}-input`)
 | 
					      .querySelector(`#zotero-prefpane-${config.addonRef}-input`)
 | 
				
			||||||
      ?.addEventListener("change", (e) => {
 | 
					      ?.addEventListener("change", (e) => {
 | 
				
			||||||
        this._Addon.toolkit.Tool.log(e);
 | 
					        ZToolkit.Tool.log(e);
 | 
				
			||||||
        this._window.alert(
 | 
					        this._window.alert(
 | 
				
			||||||
          `Successfully changed to ${(e.target as HTMLInputElement).value}!`
 | 
					          `Successfully changed to ${(e.target as HTMLInputElement).value}!`
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										66
									
								
								src/views.ts
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								src/views.ts
									
									
									
									
									
								
							@ -18,10 +18,10 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
  public initViews() {
 | 
					  public initViews() {
 | 
				
			||||||
    // You can init the UI elements that
 | 
					    // You can init the UI elements that
 | 
				
			||||||
    // cannot be initialized with overlay.xul
 | 
					    // cannot be initialized with overlay.xul
 | 
				
			||||||
    this._Addon.toolkit.Tool.log("Initializing UI");
 | 
					    ZToolkit.Tool.log("Initializing UI");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // register style sheet
 | 
					    // register style sheet
 | 
				
			||||||
    const styles = this._Addon.toolkit.UI.creatElementsFromJSON(document, {
 | 
					    const styles = ZToolkit.UI.creatElementsFromJSON(document, {
 | 
				
			||||||
      tag: "link",
 | 
					      tag: "link",
 | 
				
			||||||
      directAttributes: {
 | 
					      directAttributes: {
 | 
				
			||||||
        type: "text/css",
 | 
					        type: "text/css",
 | 
				
			||||||
@ -36,7 +36,7 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const menuIcon = `chrome://${config.addonRef}/content/icons/favicon@0.5x.png`;
 | 
					    const menuIcon = `chrome://${config.addonRef}/content/icons/favicon@0.5x.png`;
 | 
				
			||||||
    // item menuitem with icon
 | 
					    // item menuitem with icon
 | 
				
			||||||
    this._Addon.toolkit.UI.insertMenuItem("item", {
 | 
					    ZToolkit.UI.insertMenuItem("item", {
 | 
				
			||||||
      tag: "menuitem",
 | 
					      tag: "menuitem",
 | 
				
			||||||
      id: "zotero-itemmenu-addontemplate-test",
 | 
					      id: "zotero-itemmenu-addontemplate-test",
 | 
				
			||||||
      label: this._Addon.locale.getString("menuitem.label"),
 | 
					      label: this._Addon.locale.getString("menuitem.label"),
 | 
				
			||||||
@ -44,7 +44,7 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
      icon: menuIcon,
 | 
					      icon: menuIcon,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    // item menupopup with sub-menuitems
 | 
					    // item menupopup with sub-menuitems
 | 
				
			||||||
    this._Addon.toolkit.UI.insertMenuItem(
 | 
					    ZToolkit.UI.insertMenuItem(
 | 
				
			||||||
      "item",
 | 
					      "item",
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        tag: "menu",
 | 
					        tag: "menu",
 | 
				
			||||||
@ -58,15 +58,15 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
        ],
 | 
					        ],
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "before",
 | 
					      "before",
 | 
				
			||||||
      this._Addon.Zotero.getMainWindow().document.querySelector(
 | 
					      document.querySelector(
 | 
				
			||||||
        "#zotero-itemmenu-addontemplate-test"
 | 
					        "#zotero-itemmenu-addontemplate-test"
 | 
				
			||||||
      )
 | 
					      ) as XUL.MenuItem
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    this._Addon.toolkit.UI.insertMenuItem("menuFile", {
 | 
					    ZToolkit.UI.insertMenuItem("menuFile", {
 | 
				
			||||||
      tag: "menuseparator",
 | 
					      tag: "menuseparator",
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    // menu->File menuitem
 | 
					    // menu->File menuitem
 | 
				
			||||||
    this._Addon.toolkit.UI.insertMenuItem("menuFile", {
 | 
					    ZToolkit.UI.insertMenuItem("menuFile", {
 | 
				
			||||||
      tag: "menuitem",
 | 
					      tag: "menuitem",
 | 
				
			||||||
      label: this._Addon.locale.getString("menuitem.filemenulabel"),
 | 
					      label: this._Addon.locale.getString("menuitem.filemenulabel"),
 | 
				
			||||||
      oncommand: "alert('Hello World! File Menuitem.')",
 | 
					      oncommand: "alert('Hello World! File Menuitem.')",
 | 
				
			||||||
@ -79,7 +79,7 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
     *  Example: extra column starts
 | 
					     *  Example: extra column starts
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    // Initialize extra columns
 | 
					    // Initialize extra columns
 | 
				
			||||||
    this._Addon.toolkit.ItemTree.register(
 | 
					    ZToolkit.ItemTree.register(
 | 
				
			||||||
      "test1",
 | 
					      "test1",
 | 
				
			||||||
      "text column",
 | 
					      "text column",
 | 
				
			||||||
      (
 | 
					      (
 | 
				
			||||||
@ -94,7 +94,7 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
        iconPath: "chrome://zotero/skin/cross.png",
 | 
					        iconPath: "chrome://zotero/skin/cross.png",
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    this._Addon.toolkit.ItemTree.register(
 | 
					    ZToolkit.ItemTree.register(
 | 
				
			||||||
      "test2",
 | 
					      "test2",
 | 
				
			||||||
      "custom column",
 | 
					      "custom column",
 | 
				
			||||||
      (
 | 
					      (
 | 
				
			||||||
@ -125,7 +125,7 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
     *  Example: custom cell starts
 | 
					     *  Example: custom cell starts
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    // Customize cells
 | 
					    // Customize cells
 | 
				
			||||||
    this._Addon.toolkit.ItemTree.addRenderCellHook(
 | 
					    ZToolkit.ItemTree.addRenderCellHook(
 | 
				
			||||||
      "title",
 | 
					      "title",
 | 
				
			||||||
      (index: number, data: string, column: any, original: Function) => {
 | 
					      (index: number, data: string, column: any, original: Function) => {
 | 
				
			||||||
        const span = original(index, data, column) as HTMLSpanElement;
 | 
					        const span = original(index, data, column) as HTMLSpanElement;
 | 
				
			||||||
@ -141,12 +141,10 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     *  Example: extra library tab starts
 | 
					     *  Example: extra library tab starts
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    const libTabId = this._Addon.toolkit.UI.registerLibraryTabPanel(
 | 
					    const libTabId = ZToolkit.UI.registerLibraryTabPanel(
 | 
				
			||||||
      this._Addon.locale.getString("tabpanel.lib.tab.label"),
 | 
					      this._Addon.locale.getString("tabpanel.lib.tab.label"),
 | 
				
			||||||
      (panel: XUL.Element, win: Window) => {
 | 
					      (panel: XUL.Element, win: Window) => {
 | 
				
			||||||
        const elem = this._Addon.toolkit.UI.creatElementsFromJSON(
 | 
					        const elem = ZToolkit.UI.creatElementsFromJSON(win.document, {
 | 
				
			||||||
          win.document,
 | 
					 | 
				
			||||||
          {
 | 
					 | 
				
			||||||
          tag: "vbox",
 | 
					          tag: "vbox",
 | 
				
			||||||
          namespace: "xul",
 | 
					          namespace: "xul",
 | 
				
			||||||
          subElementOptions: [
 | 
					          subElementOptions: [
 | 
				
			||||||
@ -174,16 +172,13 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                  type: "click",
 | 
					                  type: "click",
 | 
				
			||||||
                  listener: () => {
 | 
					                  listener: () => {
 | 
				
			||||||
                      this._Addon.toolkit.UI.unregisterLibraryTabPanel(
 | 
					                    ZToolkit.UI.unregisterLibraryTabPanel(libTabId);
 | 
				
			||||||
                        libTabId
 | 
					 | 
				
			||||||
                      );
 | 
					 | 
				
			||||||
                  },
 | 
					                  },
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
              ],
 | 
					              ],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
          }
 | 
					        });
 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        panel.append(elem);
 | 
					        panel.append(elem);
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
@ -198,7 +193,7 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
     *  Example: extra reader tab starts
 | 
					     *  Example: extra reader tab starts
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    const readerTabId = `${config.addonRef}-extra-reader-tab`;
 | 
					    const readerTabId = `${config.addonRef}-extra-reader-tab`;
 | 
				
			||||||
    this._Addon.toolkit.UI.registerReaderTabPanel(
 | 
					    ZToolkit.UI.registerReaderTabPanel(
 | 
				
			||||||
      this._Addon.locale.getString("tabpanel.reader.tab.label"),
 | 
					      this._Addon.locale.getString("tabpanel.reader.tab.label"),
 | 
				
			||||||
      (
 | 
					      (
 | 
				
			||||||
        panel: XUL.Element,
 | 
					        panel: XUL.Element,
 | 
				
			||||||
@ -207,15 +202,13 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
        reader: _ZoteroReaderInstance
 | 
					        reader: _ZoteroReaderInstance
 | 
				
			||||||
      ) => {
 | 
					      ) => {
 | 
				
			||||||
        if (!panel) {
 | 
					        if (!panel) {
 | 
				
			||||||
          this._Addon.toolkit.Tool.log(
 | 
					          ZToolkit.Tool.log(
 | 
				
			||||||
            "This reader do not have right-side bar. Adding reader tab skipped."
 | 
					            "This reader do not have right-side bar. Adding reader tab skipped."
 | 
				
			||||||
          );
 | 
					          );
 | 
				
			||||||
          return;
 | 
					          return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this._Addon.toolkit.Tool.log(reader);
 | 
					        ZToolkit.Tool.log(reader);
 | 
				
			||||||
        const elem = this._Addon.toolkit.UI.creatElementsFromJSON(
 | 
					        const elem = ZToolkit.UI.creatElementsFromJSON(win.document, {
 | 
				
			||||||
          win.document,
 | 
					 | 
				
			||||||
          {
 | 
					 | 
				
			||||||
          tag: "vbox",
 | 
					          tag: "vbox",
 | 
				
			||||||
          id: `${config.addonRef}-${reader._instanceID}-extra-reader-tab-div`,
 | 
					          id: `${config.addonRef}-${reader._instanceID}-extra-reader-tab-div`,
 | 
				
			||||||
          namespace: "xul",
 | 
					          namespace: "xul",
 | 
				
			||||||
@ -261,16 +254,13 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                  type: "click",
 | 
					                  type: "click",
 | 
				
			||||||
                  listener: () => {
 | 
					                  listener: () => {
 | 
				
			||||||
                      this._Addon.toolkit.UI.unregisterReaderTabPanel(
 | 
					                    ZToolkit.UI.unregisterReaderTabPanel(readerTabId);
 | 
				
			||||||
                        readerTabId
 | 
					 | 
				
			||||||
                      );
 | 
					 | 
				
			||||||
                  },
 | 
					                  },
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
              ],
 | 
					              ],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
          }
 | 
					        });
 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        panel.append(elem);
 | 
					        panel.append(elem);
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
@ -284,17 +274,17 @@ class AddonViews extends AddonModule {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public unInitViews() {
 | 
					  public unInitViews() {
 | 
				
			||||||
    this._Addon.toolkit.Tool.log("Uninitializing UI");
 | 
					    ZToolkit.Tool.log("Uninitializing UI");
 | 
				
			||||||
    this._Addon.toolkit.unregisterAll();
 | 
					    ZToolkit.unregisterAll();
 | 
				
			||||||
    // this._Addon.toolkit.UI.removeAddonElements();
 | 
					    // toolkit.UI.removeAddonElements();
 | 
				
			||||||
    // // Remove extra columns
 | 
					    // // Remove extra columns
 | 
				
			||||||
    // this._Addon.toolkit.ItemTree.unregister("test1");
 | 
					    // toolkit.ItemTree.unregister("test1");
 | 
				
			||||||
    // this._Addon.toolkit.ItemTree.unregister("test2");
 | 
					    // toolkit.ItemTree.unregister("test2");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // // Remove title cell patch
 | 
					    // // Remove title cell patch
 | 
				
			||||||
    // this._Addon.toolkit.ItemTree.removeRenderCellHook("title");
 | 
					    // toolkit.ItemTree.removeRenderCellHook("title");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // this._Addon.toolkit.UI.unregisterReaderTabPanel(
 | 
					    // toolkit.UI.unregisterReaderTabPanel(
 | 
				
			||||||
    //   `${config.addonRef}-extra-reader-tab`
 | 
					    //   `${config.addonRef}-extra-reader-tab`
 | 
				
			||||||
    // );
 | 
					    // );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								typing/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								typing/global.d.ts
									
									
									
									
										vendored
									
									
								
							@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					declare const _globalThis: {
 | 
				
			||||||
 | 
					  [key: string]: any;
 | 
				
			||||||
 | 
					  Zotero: _ZoteroConstructable;
 | 
				
			||||||
 | 
					  ZoteroPane: _ZoteroPaneConstructable;
 | 
				
			||||||
 | 
					  Zotero_Tabs: typeof Zotero_Tabs;
 | 
				
			||||||
 | 
					  window: Window;
 | 
				
			||||||
 | 
					  document: Document;
 | 
				
			||||||
 | 
					  ZToolkit: typeof ZToolkit;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare const ZToolkit: import("zotero-plugin-toolkit").ZoteroToolkit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare const rootURI: string;
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user