happy-dom 13.7.7 → 13.7.8
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.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/cjs/custom-element/CustomElementRegistry.cjs +48 -3
- package/cjs/custom-element/CustomElementRegistry.cjs.map +1 -1
- package/cjs/custom-element/CustomElementRegistry.d.ts +11 -0
- package/cjs/custom-element/CustomElementRegistry.d.ts.map +1 -1
- package/cjs/nodes/document/Document.cjs +1 -1
- package/cjs/nodes/document/Document.cjs.map +1 -1
- package/cjs/nodes/node/Node.cjs.map +1 -1
- package/cjs/nodes/node/Node.d.ts +1 -1
- package/cjs/nodes/node/Node.d.ts.map +1 -1
- package/cjs/version.cjs +1 -1
- package/cjs/window/BrowserWindow.cjs +4 -1
- package/cjs/window/BrowserWindow.cjs.map +1 -1
- package/cjs/window/BrowserWindow.d.ts.map +1 -1
- package/lib/custom-element/CustomElementRegistry.d.ts +11 -0
- package/lib/custom-element/CustomElementRegistry.d.ts.map +1 -1
- package/lib/custom-element/CustomElementRegistry.js +48 -3
- package/lib/custom-element/CustomElementRegistry.js.map +1 -1
- package/lib/nodes/document/Document.js +1 -1
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/node/Node.d.ts +1 -1
- package/lib/nodes/node/Node.d.ts.map +1 -1
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/version.js +1 -1
- package/lib/window/BrowserWindow.d.ts.map +1 -1
- package/lib/window/BrowserWindow.js +4 -1
- package/lib/window/BrowserWindow.js.map +1 -1
- package/package.json +1 -1
- package/src/custom-element/CustomElementRegistry.ts +49 -0
- package/src/nodes/document/Document.ts +1 -1
- package/src/nodes/node/Node.ts +1 -1
- package/src/window/BrowserWindow.ts +5 -1
package/package.json
CHANGED
@@ -2,6 +2,8 @@ import DOMException from '../exception/DOMException.js';
|
|
2
2
|
import * as PropertySymbol from '../PropertySymbol.js';
|
3
3
|
import HTMLElement from '../nodes/html-element/HTMLElement.js';
|
4
4
|
import Node from '../nodes/node/Node.js';
|
5
|
+
import IBrowserWindow from '../window/IBrowserWindow.js';
|
6
|
+
import NamespaceURI from '../config/NamespaceURI.js';
|
5
7
|
|
6
8
|
/**
|
7
9
|
* Custom elements registry.
|
@@ -12,6 +14,16 @@ export default class CustomElementRegistry {
|
|
12
14
|
} = {};
|
13
15
|
public [PropertySymbol.registedClass]: Map<typeof HTMLElement, string> = new Map();
|
14
16
|
public [PropertySymbol.callbacks]: { [k: string]: (() => void)[] } = {};
|
17
|
+
#window: IBrowserWindow;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Constructor.
|
21
|
+
*
|
22
|
+
* @param window Window.
|
23
|
+
*/
|
24
|
+
constructor(window: IBrowserWindow) {
|
25
|
+
this.#window = window;
|
26
|
+
}
|
15
27
|
|
16
28
|
/**
|
17
29
|
* Defines a custom element class.
|
@@ -44,6 +56,31 @@ export default class CustomElementRegistry {
|
|
44
56
|
);
|
45
57
|
}
|
46
58
|
|
59
|
+
const tagName = name.toUpperCase();
|
60
|
+
|
61
|
+
elementClass[PropertySymbol.ownerDocument] = this.#window.document;
|
62
|
+
|
63
|
+
Object.defineProperty(elementClass.prototype, 'localName', {
|
64
|
+
configurable: true,
|
65
|
+
get: function () {
|
66
|
+
return this[PropertySymbol.localName] || name;
|
67
|
+
}
|
68
|
+
});
|
69
|
+
|
70
|
+
Object.defineProperty(elementClass.prototype, 'tagName', {
|
71
|
+
configurable: true,
|
72
|
+
get: function () {
|
73
|
+
return this[PropertySymbol.tagName] || tagName;
|
74
|
+
}
|
75
|
+
});
|
76
|
+
|
77
|
+
Object.defineProperty(elementClass.prototype, 'namespaceURI', {
|
78
|
+
configurable: true,
|
79
|
+
get: function () {
|
80
|
+
return this[PropertySymbol.namespaceURI] || NamespaceURI.html;
|
81
|
+
}
|
82
|
+
});
|
83
|
+
|
47
84
|
this[PropertySymbol.registry][name] = {
|
48
85
|
elementClass,
|
49
86
|
extends: options && options.extends ? options.extends.toLowerCase() : null
|
@@ -113,6 +150,18 @@ export default class CustomElementRegistry {
|
|
113
150
|
return this[PropertySymbol.registedClass].get(elementClass) || null;
|
114
151
|
}
|
115
152
|
|
153
|
+
/**
|
154
|
+
* Destroys the registry.
|
155
|
+
*/
|
156
|
+
public [PropertySymbol.destroy](): void {
|
157
|
+
for (const entity of Object.values(this[PropertySymbol.registry])) {
|
158
|
+
entity.elementClass[PropertySymbol.ownerDocument] = null;
|
159
|
+
}
|
160
|
+
this[PropertySymbol.registry] = {};
|
161
|
+
this[PropertySymbol.registedClass] = new Map();
|
162
|
+
this[PropertySymbol.callbacks] = {};
|
163
|
+
}
|
164
|
+
|
116
165
|
/**
|
117
166
|
* Validates the correctness of custom element tag names.
|
118
167
|
*
|
@@ -1122,7 +1122,7 @@ export default class Document extends Node implements IDocument {
|
|
1122
1122
|
];
|
1123
1123
|
|
1124
1124
|
if (customElement) {
|
1125
|
-
const element =
|
1125
|
+
const element = new customElement.elementClass();
|
1126
1126
|
element[PropertySymbol.tagName] = qualifiedName.toUpperCase();
|
1127
1127
|
element[PropertySymbol.localName] = qualifiedName;
|
1128
1128
|
element[PropertySymbol.namespaceURI] = namespaceURI;
|
package/src/nodes/node/Node.ts
CHANGED
@@ -297,7 +297,7 @@ export default class Node extends EventTarget implements INode {
|
|
297
297
|
* @param otherNode Node to test with.
|
298
298
|
* @returns "true" if this node contains the other node.
|
299
299
|
*/
|
300
|
-
public contains(otherNode: INode
|
300
|
+
public contains(otherNode: INode): boolean {
|
301
301
|
if (otherNode === undefined) {
|
302
302
|
return false;
|
303
303
|
}
|
@@ -520,7 +520,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
|
|
520
520
|
|
521
521
|
this.#browserFrame = browserFrame;
|
522
522
|
|
523
|
-
this.customElements = new CustomElementRegistry();
|
523
|
+
this.customElements = new CustomElementRegistry(this);
|
524
524
|
this.navigator = new Navigator(this);
|
525
525
|
this.history = new History();
|
526
526
|
this.screen = new Screen();
|
@@ -1274,6 +1274,10 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
|
|
1274
1274
|
this.document.removeChild(node);
|
1275
1275
|
}
|
1276
1276
|
|
1277
|
+
if (this.customElements[PropertySymbol.destroy]) {
|
1278
|
+
this.customElements[PropertySymbol.destroy]();
|
1279
|
+
}
|
1280
|
+
|
1277
1281
|
this.document[PropertySymbol.activeElement] = null;
|
1278
1282
|
this.document[PropertySymbol.nextActiveElement] = null;
|
1279
1283
|
this.document[PropertySymbol.currentScript] = null;
|