@remote-dom/polyfill 1.2.1 → 1.3.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.
- package/CHANGELOG.md +170 -0
- package/build/cjs/Attr.cjs +1 -1
- package/build/cjs/CustomElementRegistry.cjs +2 -2
- package/build/cjs/Document.cjs +4 -2
- package/build/cjs/DocumentFragment.cjs +2 -2
- package/build/cjs/Element.cjs +5 -2
- package/build/cjs/Event.cjs +19 -25
- package/build/cjs/EventTarget.cjs +9 -14
- package/build/cjs/Node.cjs +1 -1
- package/build/cjs/ParentNode.cjs +4 -2
- package/build/cjs/SVGElement.cjs +1 -1
- package/build/cjs/Text.cjs +1 -1
- package/build/cjs/Window.cjs +20 -20
- package/build/cjs/constants.cjs +4 -0
- package/build/esm/Attr.mjs +1 -1
- package/build/esm/CustomElementRegistry.mjs +2 -2
- package/build/esm/Document.mjs +5 -3
- package/build/esm/DocumentFragment.mjs +2 -2
- package/build/esm/Element.mjs +5 -2
- package/build/esm/Event.mjs +20 -26
- package/build/esm/EventTarget.mjs +10 -15
- package/build/esm/Node.mjs +1 -1
- package/build/esm/ParentNode.mjs +4 -2
- package/build/esm/SVGElement.mjs +1 -1
- package/build/esm/Text.mjs +1 -1
- package/build/esm/Window.mjs +20 -20
- package/build/esm/constants.mjs +3 -1
- package/build/esnext/Document.esnext +4 -2
- package/build/esnext/Element.esnext +3 -0
- package/build/esnext/Event.esnext +15 -21
- package/build/esnext/EventTarget.esnext +10 -15
- package/build/esnext/ParentNode.esnext +2 -0
- package/build/esnext/constants.esnext +3 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/Document.d.ts.map +1 -1
- package/build/typescript/Element.d.ts +1 -0
- package/build/typescript/Element.d.ts.map +1 -1
- package/build/typescript/Event.d.ts +5 -5
- package/build/typescript/Event.d.ts.map +1 -1
- package/build/typescript/EventTarget.d.ts.map +1 -1
- package/build/typescript/ParentNode.d.ts.map +1 -1
- package/build/typescript/constants.d.ts +2 -0
- package/build/typescript/constants.d.ts.map +1 -1
- package/package.json +1 -1
- package/source/Document.ts +3 -1
- package/source/Element.ts +4 -0
- package/source/Event.ts +24 -26
- package/source/EventTarget.ts +14 -15
- package/source/ParentNode.ts +2 -0
- package/source/constants.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,175 @@
|
|
|
1
1
|
# @remote-dom/polyfill
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#436](https://github.com/Shopify/remote-dom/pull/436) [`5979797`](https://github.com/Shopify/remote-dom/commit/59797975a3ccf2bee825809f67e05ca4a28e2647) Thanks [@jakearchibald](https://github.com/jakearchibald)! - Ensure the `createText` hook is called when creating a new text node
|
|
8
|
+
|
|
9
|
+
## 1.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#389](https://github.com/Shopify/remote-dom/pull/389) [`2479b21`](https://github.com/Shopify/remote-dom/commit/2479b21406f6149063bfc095dbb6c3a019386403) Thanks [@lemonmade](https://github.com/lemonmade)! - Added native support for synchronizing attributes and event listeners
|
|
14
|
+
|
|
15
|
+
Previously, Remote DOM only offered “remote properties” as a way to synchronize element state between the host and remote environments. These remote properties effectively synchronize a subset of a custom element’s instance properties. The `RemoteElement` class offers [a declarative way to define the properties that should be synchronized](/packages/core/README.md#remote-properties).
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {RemoteElement} from '@remote-dom/core/elements';
|
|
19
|
+
|
|
20
|
+
class MyElement extends RemoteElement {
|
|
21
|
+
static get remoteProperties() {
|
|
22
|
+
return ['label'];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
customElements.define('my-element', MyElement);
|
|
27
|
+
|
|
28
|
+
const myElement = document.createElement('my-element');
|
|
29
|
+
myElement.label = 'Hello, World!';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The same `remoteProperties` configuration can create special handling for attributes and event listeners. By default, a remote property is automatically updated when setting an [attribute](https://developer.mozilla.org/en-US/docs/Glossary/Attribute) of the same name:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const myElement = document.createElement('my-element');
|
|
36
|
+
myElement.setAttribute('label', 'Hello, World!');
|
|
37
|
+
|
|
38
|
+
// myElement.label === 'Hello, World!', and this value is synchronized
|
|
39
|
+
// with the host environment as a “remote property”
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Similarly, a remote property can be automatically updated when adding an event listener based on a conventional `on` property naming prefix:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {RemoteElement} from '@remote-dom/core/elements';
|
|
46
|
+
|
|
47
|
+
class MyElement extends RemoteElement {
|
|
48
|
+
static get remoteProperties() {
|
|
49
|
+
return {
|
|
50
|
+
onChange: {
|
|
51
|
+
event: true,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
customElements.define('my-element', MyElement);
|
|
58
|
+
|
|
59
|
+
const myElement = document.createElement('my-element');
|
|
60
|
+
|
|
61
|
+
// This adds a callback property that is synchronized with the host environment
|
|
62
|
+
myElement.onChange = () => console.log('Changed!');
|
|
63
|
+
|
|
64
|
+
// And so does this, but using the `addEventListener` method instead
|
|
65
|
+
myElement.addEventListener('change', () => console.log('Changed!'));
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
These utilities are handy, but they don’t align with patterns in native DOM elements, particularly when it comes to events. Now, both of these can be represented in a fashion that is more conventional in HTML. The `remoteAttributes` configuration allows you to define a set of element attributes that will be synchronized directly the host environment, instead of being treated as instance properties:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import {RemoteElement} from '@remote-dom/core/elements';
|
|
72
|
+
|
|
73
|
+
class MyElement extends RemoteElement {
|
|
74
|
+
static get remoteAttributes() {
|
|
75
|
+
return ['label'];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// If you want to add instance properties, you can do it with getters and
|
|
79
|
+
// setters that manipulate the attribute value:
|
|
80
|
+
//
|
|
81
|
+
// get label() {
|
|
82
|
+
// return this.getAttribute('label');
|
|
83
|
+
// }
|
|
84
|
+
//
|
|
85
|
+
// set label(value) {
|
|
86
|
+
// this.setAttribute('label', value);
|
|
87
|
+
// }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
customElements.define('my-element', MyElement);
|
|
91
|
+
|
|
92
|
+
const myElement = document.createElement('my-element');
|
|
93
|
+
myElement.setAttribute('label', 'Hello, World!');
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Similarly, the `remoteEvents` configuration allows you to define a set of event listeners that will be synchronized directly with the host environment:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import {RemoteElement} from '@remote-dom/core/elements';
|
|
100
|
+
|
|
101
|
+
class MyElement extends RemoteElement {
|
|
102
|
+
static get remoteEvents() {
|
|
103
|
+
return ['change'];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
customElements.define('my-element', MyElement);
|
|
108
|
+
|
|
109
|
+
const myElement = document.createElement('my-element');
|
|
110
|
+
|
|
111
|
+
// And so does this, but using the `addEventListener` method instead
|
|
112
|
+
myElement.addEventListener('change', () => console.log('Changed!'));
|
|
113
|
+
|
|
114
|
+
// No `myElement.onChange` property is created
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The `remoteProperties` configuration will continue to be supported for cases where you want to synchronize instance properties. Because instance properties can be any JavaScript type, properties are the highest-fidelity field that can be synchronized between the remote and host environments. However, adding event listeners using the `remoteProperties.event` configuration is **deprecated and will be removed in the next major version**. You should use the `remoteEvents` configuration instead. If you were previously defining remote properties which only accepted strings, consider using the `remoteAttributes` configuration, which stores the value entirely in an HTML attribute instead.
|
|
118
|
+
|
|
119
|
+
This change is being released in a backwards-compatible way, so you can continue to use the existing `remoteProperties` configuration on host and/or remote environments without any code changes.
|
|
120
|
+
|
|
121
|
+
All host utilities have been updated to support the new `attributes` and `eventListeners` property that are synchronized with the remote environment. This includes updates to the [React](/packages/react/README.md#event-listener-props) and [Preact hosts to map events to conventional callback props](/packages/preact/README.md#event-listener-props), and updates to the [`DOMRemoteReceiver` class](/packages/core/README.md#domremotereceiver), which now applies fields to the host element exactly as they were applied in the remote environment:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
// Remote environment:
|
|
125
|
+
|
|
126
|
+
class MyElement extends RemoteElement {
|
|
127
|
+
static get remoteEvents() {
|
|
128
|
+
return ['change'];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
customElements.define('my-element', MyElement);
|
|
133
|
+
|
|
134
|
+
const myElement = document.createElement('my-element');
|
|
135
|
+
|
|
136
|
+
myElement.addEventListener('change', (event) => {
|
|
137
|
+
console.log('Changed! New value: ', event.detail);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Host environment:
|
|
141
|
+
|
|
142
|
+
class MyElement extends HTMLElement {
|
|
143
|
+
connectedCallback() {
|
|
144
|
+
// Emit a change event on this element, with detail that will be passed
|
|
145
|
+
// to the remote environment
|
|
146
|
+
this.addEventListener('change', (event) => {
|
|
147
|
+
event.stopImmediatePropagation();
|
|
148
|
+
|
|
149
|
+
this.dispatchEvent(
|
|
150
|
+
new CustomEvent('change', {
|
|
151
|
+
detail: this.value,
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Additional implementation details of the host custom element...
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
customElements.define('my-element', MyElement);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Patch Changes
|
|
164
|
+
|
|
165
|
+
- [#389](https://github.com/Shopify/remote-dom/pull/389) [`2479b21`](https://github.com/Shopify/remote-dom/commit/2479b21406f6149063bfc095dbb6c3a019386403) Thanks [@lemonmade](https://github.com/lemonmade)! - Bug fixes to event dispatching
|
|
166
|
+
|
|
167
|
+
- Listeners on the target are now called during both the capture and bubble phases.
|
|
168
|
+
- `stopPropagation` now respected.
|
|
169
|
+
- `stopImmediatePropagation` now also stops regular propagation.
|
|
170
|
+
|
|
171
|
+
- [#389](https://github.com/Shopify/remote-dom/pull/389) [`2479b21`](https://github.com/Shopify/remote-dom/commit/2479b21406f6149063bfc095dbb6c3a019386403) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix `Event.bubbles` and `Event.composedPath()` implementations
|
|
172
|
+
|
|
3
173
|
## 1.2.1
|
|
4
174
|
|
|
5
175
|
### Patch Changes
|
package/build/cjs/Attr.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const constants = require('./constants.cjs');
|
|
|
6
6
|
const Node = require('./Node.cjs');
|
|
7
7
|
|
|
8
8
|
class Attr extends Node.Node {
|
|
9
|
-
nodeType = constants.NodeType.ATTRIBUTE_NODE;
|
|
9
|
+
nodeType = (() => constants.NodeType.ATTRIBUTE_NODE)();
|
|
10
10
|
[constants.NS] = null;
|
|
11
11
|
[constants.NEXT] = null;
|
|
12
12
|
[constants.OWNER_ELEMENT] = null;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
class CustomElementRegistryImplementation {
|
|
6
|
-
registry = new Map();
|
|
7
|
-
listenersByName = new Map();
|
|
6
|
+
registry = (() => new Map())();
|
|
7
|
+
listenersByName = (() => new Map())();
|
|
8
8
|
define(name, Constructor, _options) {
|
|
9
9
|
this.registry.set(name, Constructor);
|
|
10
10
|
const listeners = this.listenersByName.get(name);
|
package/build/cjs/Document.cjs
CHANGED
|
@@ -17,7 +17,7 @@ const HTMLHeadElement = require('./HTMLHeadElement.cjs');
|
|
|
17
17
|
const HTMLHtmlElement = require('./HTMLHtmlElement.cjs');
|
|
18
18
|
|
|
19
19
|
class Document extends ParentNode.ParentNode {
|
|
20
|
-
nodeType = constants.NodeType.DOCUMENT_NODE;
|
|
20
|
+
nodeType = (() => constants.NodeType.DOCUMENT_NODE)();
|
|
21
21
|
[constants.NAME] = '#document';
|
|
22
22
|
constructor(defaultView) {
|
|
23
23
|
super();
|
|
@@ -36,7 +36,9 @@ class Document extends ParentNode.ParentNode {
|
|
|
36
36
|
return createElement(this, localName, namespaceURI);
|
|
37
37
|
}
|
|
38
38
|
createTextNode(data) {
|
|
39
|
-
|
|
39
|
+
const text = createNode(new Text.Text(data), this);
|
|
40
|
+
this[constants.HOOKS].createText?.(text, String(data));
|
|
41
|
+
return text;
|
|
40
42
|
}
|
|
41
43
|
createComment(data) {
|
|
42
44
|
return createNode(new Comment.Comment(data), this);
|
|
@@ -6,9 +6,9 @@ const constants = require('./constants.cjs');
|
|
|
6
6
|
const ParentNode = require('./ParentNode.cjs');
|
|
7
7
|
|
|
8
8
|
class DocumentFragment extends ParentNode.ParentNode {
|
|
9
|
-
nodeType = constants.NodeType.DOCUMENT_FRAGMENT_NODE;
|
|
9
|
+
nodeType = (() => constants.NodeType.DOCUMENT_FRAGMENT_NODE)();
|
|
10
10
|
[constants.NAME] = '#document-fragment';
|
|
11
|
-
[constants.OWNER_DOCUMENT] = window.document;
|
|
11
|
+
[constants.OWNER_DOCUMENT] = (() => window.document)();
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
exports.DocumentFragment = DocumentFragment;
|
package/build/cjs/Element.cjs
CHANGED
|
@@ -9,8 +9,8 @@ const Attr = require('./Attr.cjs');
|
|
|
9
9
|
const serialization = require('./serialization.cjs');
|
|
10
10
|
|
|
11
11
|
class Element extends ParentNode.ParentNode {
|
|
12
|
-
nodeType = constants.NodeType.ELEMENT_NODE;
|
|
13
|
-
[constants.NS] = constants.NamespaceURI.XHTML;
|
|
12
|
+
nodeType = (() => constants.NodeType.ELEMENT_NODE)();
|
|
13
|
+
[constants.NS] = (() => constants.NamespaceURI.XHTML)();
|
|
14
14
|
get namespaceURI() {
|
|
15
15
|
return this[constants.NS];
|
|
16
16
|
}
|
|
@@ -34,6 +34,9 @@ class Element extends ParentNode.ParentNode {
|
|
|
34
34
|
}
|
|
35
35
|
return attributes;
|
|
36
36
|
}
|
|
37
|
+
getAttributeNames() {
|
|
38
|
+
return [...this.attributes].map(attr => attr.name);
|
|
39
|
+
}
|
|
37
40
|
get firstElementChild() {
|
|
38
41
|
return this.children[0] ?? null;
|
|
39
42
|
}
|
package/build/cjs/Event.cjs
CHANGED
|
@@ -14,17 +14,17 @@ let EventPhase = /*#__PURE__*/function (EventPhase) {
|
|
|
14
14
|
const CAPTURE_MARKER = '@';
|
|
15
15
|
const now = typeof performance === 'undefined' ? Date.now : performance.now.bind(performance);
|
|
16
16
|
class Event {
|
|
17
|
-
static NONE = EventPhase.NONE;
|
|
18
|
-
static CAPTURING_PHASE = EventPhase.CAPTURING_PHASE;
|
|
19
|
-
static AT_TARGET = EventPhase.AT_TARGET;
|
|
20
|
-
static BUBBLING_PHASE = EventPhase.BUBBLING_PHASE;
|
|
17
|
+
static NONE = (() => EventPhase.NONE)();
|
|
18
|
+
static CAPTURING_PHASE = (() => EventPhase.CAPTURING_PHASE)();
|
|
19
|
+
static AT_TARGET = (() => EventPhase.AT_TARGET)();
|
|
20
|
+
static BUBBLING_PHASE = (() => EventPhase.BUBBLING_PHASE)();
|
|
21
21
|
|
|
22
22
|
// NONE = EventPhase.NONE;
|
|
23
23
|
// CAPTURING_PHASE = EventPhase.CAPTURING_PHASE;
|
|
24
24
|
// AT_TARGET = EventPhase.AT_TARGET;
|
|
25
25
|
// BUBBLING_PHASE = EventPhase.BUBBLING_PHASE;
|
|
26
26
|
|
|
27
|
-
timeStamp = now();
|
|
27
|
+
timeStamp = (() => now())();
|
|
28
28
|
target = null;
|
|
29
29
|
currentTarget = null;
|
|
30
30
|
srcElement = null;
|
|
@@ -33,11 +33,11 @@ class Event {
|
|
|
33
33
|
composed = false;
|
|
34
34
|
defaultPrevented = false;
|
|
35
35
|
cancelBubble = false;
|
|
36
|
-
immediatePropagationStopped = false;
|
|
37
36
|
eventPhase = 0;
|
|
38
|
-
path = [];
|
|
39
37
|
// private inPassiveListener = false;
|
|
40
38
|
|
|
39
|
+
[constants.PATH] = [];
|
|
40
|
+
[constants.STOP_IMMEDIATE_PROPAGATION] = false;
|
|
41
41
|
constructor(type, options) {
|
|
42
42
|
this.type = type;
|
|
43
43
|
Object.defineProperty(this, constants.IS_TRUSTED, {
|
|
@@ -50,17 +50,18 @@ class Event {
|
|
|
50
50
|
if (options.composed) this.composed = options.composed;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
get composedPath() {
|
|
54
|
-
return this.path;
|
|
55
|
-
}
|
|
56
53
|
get isTrusted() {
|
|
57
54
|
return this[constants.IS_TRUSTED];
|
|
58
55
|
}
|
|
56
|
+
composedPath() {
|
|
57
|
+
return this[constants.PATH];
|
|
58
|
+
}
|
|
59
59
|
stopPropagation() {
|
|
60
60
|
this.cancelBubble = true;
|
|
61
61
|
}
|
|
62
62
|
stopImmediatePropagation() {
|
|
63
|
-
this.
|
|
63
|
+
this[constants.STOP_IMMEDIATE_PROPAGATION] = true;
|
|
64
|
+
this.cancelBubble = true;
|
|
64
65
|
}
|
|
65
66
|
preventDefault() {
|
|
66
67
|
this.defaultPrevented = true;
|
|
@@ -79,31 +80,24 @@ class Event {
|
|
|
79
80
|
this.cancelable = Boolean(cancelable);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
function fireEvent(event,
|
|
83
|
-
const listeners =
|
|
83
|
+
function fireEvent(event, currentTarget, phase) {
|
|
84
|
+
const listeners = currentTarget[constants.LISTENERS];
|
|
84
85
|
const list = listeners?.get(`${event.type}${phase === EventPhase.CAPTURING_PHASE ? CAPTURE_MARKER : ''}`);
|
|
85
|
-
if (!list) return
|
|
86
|
-
let defaultPrevented = false;
|
|
86
|
+
if (!list) return;
|
|
87
87
|
for (const listener of list) {
|
|
88
|
-
event.eventPhase = phase;
|
|
89
|
-
event.currentTarget =
|
|
88
|
+
event.eventPhase = event.target === currentTarget ? EventPhase.AT_TARGET : phase;
|
|
89
|
+
event.currentTarget = currentTarget;
|
|
90
90
|
try {
|
|
91
91
|
if (typeof listener === 'object') {
|
|
92
92
|
listener.handleEvent(event);
|
|
93
93
|
} else {
|
|
94
|
-
listener.call(
|
|
94
|
+
listener.call(currentTarget, event);
|
|
95
95
|
}
|
|
96
96
|
} catch (err) {
|
|
97
97
|
setTimeout(thrower, 0, err);
|
|
98
98
|
}
|
|
99
|
-
if (event.
|
|
100
|
-
defaultPrevented = true;
|
|
101
|
-
}
|
|
102
|
-
if (event.immediatePropagationStopped) {
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
99
|
+
if (event[constants.STOP_IMMEDIATE_PROPAGATION]) break;
|
|
105
100
|
}
|
|
106
|
-
return defaultPrevented;
|
|
107
101
|
}
|
|
108
102
|
function thrower(error) {
|
|
109
103
|
throw error;
|
|
@@ -71,22 +71,17 @@ class EventTarget {
|
|
|
71
71
|
// }
|
|
72
72
|
event.target = this;
|
|
73
73
|
event.srcElement = this;
|
|
74
|
-
event.
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
defaultPrevented = true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (Event.fireEvent(event, this, Event.EventPhase.AT_TARGET)) {
|
|
82
|
-
defaultPrevented = true;
|
|
74
|
+
event[constants.PATH] = path;
|
|
75
|
+
for (let i = path.length; i--;) {
|
|
76
|
+
Event.fireEvent(event, path[i], Event.EventPhase.CAPTURING_PHASE);
|
|
77
|
+
if (event.cancelBubble) return event.defaultPrevented;
|
|
83
78
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
const bubblePath = event.bubbles ? path : path.slice(0, 1);
|
|
80
|
+
for (let i = 0; i < bubblePath.length; i++) {
|
|
81
|
+
Event.fireEvent(event, bubblePath[i], Event.EventPhase.BUBBLING_PHASE);
|
|
82
|
+
if (event.cancelBubble) return event.defaultPrevented;
|
|
88
83
|
}
|
|
89
|
-
return
|
|
84
|
+
return event.defaultPrevented;
|
|
90
85
|
}
|
|
91
86
|
}
|
|
92
87
|
function removeEventListener(type, listener, options) {
|
package/build/cjs/Node.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const EventTarget = require('./EventTarget.cjs');
|
|
|
7
7
|
const shared = require('./shared.cjs');
|
|
8
8
|
|
|
9
9
|
class Node extends EventTarget.EventTarget {
|
|
10
|
-
nodeType = constants.NodeType.NODE;
|
|
10
|
+
nodeType = (() => constants.NodeType.NODE)();
|
|
11
11
|
[constants.NAME] = '';
|
|
12
12
|
[constants.PARENT] = null;
|
|
13
13
|
[constants.CHILD] = null;
|
package/build/cjs/ParentNode.cjs
CHANGED
|
@@ -8,8 +8,8 @@ const NodeList = require('./NodeList.cjs');
|
|
|
8
8
|
const selectors = require('./selectors.cjs');
|
|
9
9
|
|
|
10
10
|
class ParentNode extends ChildNode.ChildNode {
|
|
11
|
-
childNodes = new NodeList.NodeList();
|
|
12
|
-
children = new NodeList.NodeList();
|
|
11
|
+
childNodes = (() => new NodeList.NodeList())();
|
|
12
|
+
children = (() => new NodeList.NodeList())();
|
|
13
13
|
appendChild(child) {
|
|
14
14
|
this.insertInto(child, null);
|
|
15
15
|
}
|
|
@@ -49,6 +49,7 @@ class ParentNode extends ChildNode.ChildNode {
|
|
|
49
49
|
const children = this.children;
|
|
50
50
|
children.splice(children.indexOf(child), 1);
|
|
51
51
|
}
|
|
52
|
+
child.disconnectedCallback?.();
|
|
52
53
|
this[constants.HOOKS].removeChild?.(this, child, childNodesIndex);
|
|
53
54
|
}
|
|
54
55
|
replaceChild(newChild, oldChild) {
|
|
@@ -124,6 +125,7 @@ class ParentNode extends ChildNode.ChildNode {
|
|
|
124
125
|
childNodes.push(child);
|
|
125
126
|
if (isElement) this.children.push(child);
|
|
126
127
|
}
|
|
128
|
+
child.connectedCallback?.();
|
|
127
129
|
this[constants.HOOKS].insertChild?.(this, child, insertIndex);
|
|
128
130
|
}
|
|
129
131
|
}
|
package/build/cjs/SVGElement.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const constants = require('./constants.cjs');
|
|
|
6
6
|
const Element = require('./Element.cjs');
|
|
7
7
|
|
|
8
8
|
class SVGElement extends Element.Element {
|
|
9
|
-
[constants.NS] = constants.NamespaceURI.SVG;
|
|
9
|
+
[constants.NS] = (() => constants.NamespaceURI.SVG)();
|
|
10
10
|
get ownerSVGElement() {
|
|
11
11
|
let root = null;
|
|
12
12
|
let parent = this.parentNode;
|
package/build/cjs/Text.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const constants = require('./constants.cjs');
|
|
|
6
6
|
const CharacterData = require('./CharacterData.cjs');
|
|
7
7
|
|
|
8
8
|
class Text extends CharacterData.CharacterData {
|
|
9
|
-
nodeType = constants.NodeType.TEXT_NODE;
|
|
9
|
+
nodeType = (() => constants.NodeType.TEXT_NODE)();
|
|
10
10
|
[constants.NAME] = '#text';
|
|
11
11
|
}
|
|
12
12
|
|
package/build/cjs/Window.cjs
CHANGED
|
@@ -27,26 +27,26 @@ class Window extends EventTarget.EventTarget {
|
|
|
27
27
|
parent = this;
|
|
28
28
|
self = this;
|
|
29
29
|
top = this;
|
|
30
|
-
document = new Document.Document(this);
|
|
31
|
-
customElements = new CustomElementRegistry.CustomElementRegistryImplementation();
|
|
32
|
-
location = globalThis.location;
|
|
33
|
-
navigator = globalThis.navigator;
|
|
34
|
-
Event = Event.Event;
|
|
35
|
-
EventTarget = EventTarget.EventTarget;
|
|
36
|
-
CustomEvent = CustomEvent.CustomEvent;
|
|
37
|
-
Node = Node.Node;
|
|
38
|
-
ParentNode = ParentNode.ParentNode;
|
|
39
|
-
ChildNode = ChildNode.ChildNode;
|
|
40
|
-
DocumentFragment = DocumentFragment.DocumentFragment;
|
|
41
|
-
Document = Document.Document;
|
|
42
|
-
CharacterData = CharacterData.CharacterData;
|
|
43
|
-
Comment = Comment.Comment;
|
|
44
|
-
Text = Text.Text;
|
|
45
|
-
Element = Element.Element;
|
|
46
|
-
HTMLElement = HTMLElement.HTMLElement;
|
|
47
|
-
SVGElement = SVGElement.SVGElement;
|
|
48
|
-
HTMLTemplateElement = HTMLTemplateElement.HTMLTemplateElement;
|
|
49
|
-
MutationObserver = MutationObserver.MutationObserver;
|
|
30
|
+
document = (() => new Document.Document(this))();
|
|
31
|
+
customElements = (() => new CustomElementRegistry.CustomElementRegistryImplementation())();
|
|
32
|
+
location = (() => globalThis.location)();
|
|
33
|
+
navigator = (() => globalThis.navigator)();
|
|
34
|
+
Event = (() => Event.Event)();
|
|
35
|
+
EventTarget = (() => EventTarget.EventTarget)();
|
|
36
|
+
CustomEvent = (() => CustomEvent.CustomEvent)();
|
|
37
|
+
Node = (() => Node.Node)();
|
|
38
|
+
ParentNode = (() => ParentNode.ParentNode)();
|
|
39
|
+
ChildNode = (() => ChildNode.ChildNode)();
|
|
40
|
+
DocumentFragment = (() => DocumentFragment.DocumentFragment)();
|
|
41
|
+
Document = (() => Document.Document)();
|
|
42
|
+
CharacterData = (() => CharacterData.CharacterData)();
|
|
43
|
+
Comment = (() => Comment.Comment)();
|
|
44
|
+
Text = (() => Text.Text)();
|
|
45
|
+
Element = (() => Element.Element)();
|
|
46
|
+
HTMLElement = (() => HTMLElement.HTMLElement)();
|
|
47
|
+
SVGElement = (() => SVGElement.SVGElement)();
|
|
48
|
+
HTMLTemplateElement = (() => HTMLTemplateElement.HTMLTemplateElement)();
|
|
49
|
+
MutationObserver = (() => MutationObserver.MutationObserver)();
|
|
50
50
|
static setGlobal(window) {
|
|
51
51
|
const properties = Object.getOwnPropertyDescriptors(window);
|
|
52
52
|
delete properties.self;
|
package/build/cjs/constants.cjs
CHANGED
|
@@ -15,6 +15,8 @@ const PARENT = Symbol('parent');
|
|
|
15
15
|
const DATA = Symbol('data');
|
|
16
16
|
const LISTENERS = Symbol('listeners');
|
|
17
17
|
const IS_TRUSTED = Symbol('isTrusted');
|
|
18
|
+
const PATH = Symbol('path');
|
|
19
|
+
const STOP_IMMEDIATE_PROPAGATION = Symbol('stop_immediate_propagation');
|
|
18
20
|
const CONTENT = Symbol('content');
|
|
19
21
|
const HOOKS = Symbol('hooks');
|
|
20
22
|
|
|
@@ -55,5 +57,7 @@ exports.NodeType = NodeType;
|
|
|
55
57
|
exports.OWNER_DOCUMENT = OWNER_DOCUMENT;
|
|
56
58
|
exports.OWNER_ELEMENT = OWNER_ELEMENT;
|
|
57
59
|
exports.PARENT = PARENT;
|
|
60
|
+
exports.PATH = PATH;
|
|
58
61
|
exports.PREV = PREV;
|
|
62
|
+
exports.STOP_IMMEDIATE_PROPAGATION = STOP_IMMEDIATE_PROPAGATION;
|
|
59
63
|
exports.VALUE = VALUE;
|
package/build/esm/Attr.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { NodeType, NS, NEXT, OWNER_ELEMENT, NAME, VALUE, HOOKS } from './constan
|
|
|
2
2
|
import { Node } from './Node.mjs';
|
|
3
3
|
|
|
4
4
|
class Attr extends Node {
|
|
5
|
-
nodeType = NodeType.ATTRIBUTE_NODE;
|
|
5
|
+
nodeType = (() => NodeType.ATTRIBUTE_NODE)();
|
|
6
6
|
[NS] = null;
|
|
7
7
|
[NEXT] = null;
|
|
8
8
|
[OWNER_ELEMENT] = null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class CustomElementRegistryImplementation {
|
|
2
|
-
registry = new Map();
|
|
3
|
-
listenersByName = new Map();
|
|
2
|
+
registry = (() => new Map())();
|
|
3
|
+
listenersByName = (() => new Map())();
|
|
4
4
|
define(name, Constructor, _options) {
|
|
5
5
|
this.registry.set(name, Constructor);
|
|
6
6
|
const listeners = this.listenersByName.get(name);
|
package/build/esm/Document.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeType, NAME, OWNER_DOCUMENT, NamespaceURI, NS
|
|
1
|
+
import { NodeType, NAME, OWNER_DOCUMENT, HOOKS, NamespaceURI, NS } from './constants.mjs';
|
|
2
2
|
import { Event } from './Event.mjs';
|
|
3
3
|
import { ParentNode } from './ParentNode.mjs';
|
|
4
4
|
import { Element } from './Element.mjs';
|
|
@@ -13,7 +13,7 @@ import { HTMLHeadElement } from './HTMLHeadElement.mjs';
|
|
|
13
13
|
import { HTMLHtmlElement } from './HTMLHtmlElement.mjs';
|
|
14
14
|
|
|
15
15
|
class Document extends ParentNode {
|
|
16
|
-
nodeType = NodeType.DOCUMENT_NODE;
|
|
16
|
+
nodeType = (() => NodeType.DOCUMENT_NODE)();
|
|
17
17
|
[NAME] = '#document';
|
|
18
18
|
constructor(defaultView) {
|
|
19
19
|
super();
|
|
@@ -32,7 +32,9 @@ class Document extends ParentNode {
|
|
|
32
32
|
return createElement(this, localName, namespaceURI);
|
|
33
33
|
}
|
|
34
34
|
createTextNode(data) {
|
|
35
|
-
|
|
35
|
+
const text = createNode(new Text(data), this);
|
|
36
|
+
this[HOOKS].createText?.(text, String(data));
|
|
37
|
+
return text;
|
|
36
38
|
}
|
|
37
39
|
createComment(data) {
|
|
38
40
|
return createNode(new Comment(data), this);
|
|
@@ -2,9 +2,9 @@ import { NodeType, NAME, OWNER_DOCUMENT } from './constants.mjs';
|
|
|
2
2
|
import { ParentNode } from './ParentNode.mjs';
|
|
3
3
|
|
|
4
4
|
class DocumentFragment extends ParentNode {
|
|
5
|
-
nodeType = NodeType.DOCUMENT_FRAGMENT_NODE;
|
|
5
|
+
nodeType = (() => NodeType.DOCUMENT_FRAGMENT_NODE)();
|
|
6
6
|
[NAME] = '#document-fragment';
|
|
7
|
-
[OWNER_DOCUMENT] = window.document;
|
|
7
|
+
[OWNER_DOCUMENT] = (() => window.document)();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export { DocumentFragment };
|
package/build/esm/Element.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import { Attr } from './Attr.mjs';
|
|
|
5
5
|
import { serializeNode, serializeChildren, parseHtml } from './serialization.mjs';
|
|
6
6
|
|
|
7
7
|
class Element extends ParentNode {
|
|
8
|
-
nodeType = NodeType.ELEMENT_NODE;
|
|
9
|
-
[NS] = NamespaceURI.XHTML;
|
|
8
|
+
nodeType = (() => NodeType.ELEMENT_NODE)();
|
|
9
|
+
[NS] = (() => NamespaceURI.XHTML)();
|
|
10
10
|
get namespaceURI() {
|
|
11
11
|
return this[NS];
|
|
12
12
|
}
|
|
@@ -30,6 +30,9 @@ class Element extends ParentNode {
|
|
|
30
30
|
}
|
|
31
31
|
return attributes;
|
|
32
32
|
}
|
|
33
|
+
getAttributeNames() {
|
|
34
|
+
return [...this.attributes].map(attr => attr.name);
|
|
35
|
+
}
|
|
33
36
|
get firstElementChild() {
|
|
34
37
|
return this.children[0] ?? null;
|
|
35
38
|
}
|