zotero-plugin 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ export declare const NAMESPACE: {
2
+ XUL: string;
3
+ HTML: string;
4
+ };
5
+ type Handler = (event?: any) => void | Promise<void>;
6
+ export declare class Elements {
7
+ private prefix;
8
+ private document;
9
+ static all: WeakRef<Elements>[];
10
+ static removeAll(): void;
11
+ private className;
12
+ constructor(prefix: string, document: Document);
13
+ serialize(node: HTMLElement): string;
14
+ create(name: string, attrs?: Record<string, number | string | Handler | HTMLElement[]>): HTMLElement;
15
+ remove(): void;
16
+ }
17
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Elements = exports.NAMESPACE = void 0;
4
+ exports.NAMESPACE = {
5
+ XUL: 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
6
+ HTML: 'http://www.w3.org/1999/xhtml',
7
+ };
8
+ class Elements {
9
+ static removeAll() {
10
+ for (const ref of this.all) {
11
+ try {
12
+ const elements = ref.deref();
13
+ if (elements)
14
+ elements.document.querySelectorAll(`.${elements.className}`).forEach(e => e.remove());
15
+ }
16
+ catch (_a) { }
17
+ }
18
+ this.all = [];
19
+ }
20
+ constructor(prefix, document) {
21
+ this.prefix = prefix;
22
+ this.document = document;
23
+ this.className = `${prefix}-${Math.random()}-${Date.now()}`.replace('.', '-');
24
+ if (this.document.createXULElement)
25
+ Elements.all.push(new WeakRef(this));
26
+ }
27
+ serialize(node) {
28
+ const s = new XMLSerializer();
29
+ return s.serializeToString(node);
30
+ }
31
+ create(name, attrs = {}) {
32
+ const children = attrs.$ || [];
33
+ delete attrs.$;
34
+ const namespace = name.startsWith('html:') ? exports.NAMESPACE.HTML : exports.NAMESPACE.XUL;
35
+ name = name.replace('html:', '');
36
+ const elt = this.document.createXULElement
37
+ ? this.document[namespace === exports.NAMESPACE.XUL ? 'createXULElement' : 'createElement'](name)
38
+ : this.document.createElementNS(namespace, name);
39
+ attrs.class = `${this.className} ${attrs.class || ''}`.trim();
40
+ for (const [a, v] of Object.entries(attrs)) {
41
+ if (typeof v === 'string') {
42
+ elt.setAttribute(a, v);
43
+ }
44
+ else if (typeof v === 'number') {
45
+ elt.setAttribute(a, `${v}`);
46
+ }
47
+ else if (a.startsWith('on') && typeof v === 'function') {
48
+ elt.addEventListener(a.replace('on', ''), event => {
49
+ var _a, _b;
50
+ ;
51
+ (_b = (_a = v(event)) === null || _a === void 0 ? void 0 : _a.catch) === null || _b === void 0 ? void 0 : _b.call(_a, err => {
52
+ throw err;
53
+ });
54
+ });
55
+ }
56
+ else {
57
+ throw new Error(`unexpected attribute ${a} of type ${typeof v}`);
58
+ }
59
+ }
60
+ for (const child of children) {
61
+ elt.appendChild(child);
62
+ }
63
+ return elt;
64
+ }
65
+ remove() {
66
+ for (const elt of Array.from(this.document.getElementsByClassName(this.className))) {
67
+ elt.remove();
68
+ }
69
+ }
70
+ }
71
+ exports.Elements = Elements;
72
+ Elements.all = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zotero-plugin",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Zotero plugin builder",
5
5
  "homepage": "https://github.com/retorquere/zotero-plugin/wiki",
6
6
  "bin": {
@@ -100,7 +100,9 @@
100
100
  "version.d.ts",
101
101
  "version.js",
102
102
  "debug-log.js",
103
- "debug-log.d.ts"
103
+ "debug-log.d.ts",
104
+ "create-element.js",
105
+ "create-element.d.ts"
104
106
  ],
105
107
  "bugs": {
106
108
  "url": "https://github.com/retorquere/zotero-plugin/issues"