@mml-io/networked-dom-web-client 0.6.0 → 0.7.0
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/build/index.js +424 -486
- package/build/index.js.map +4 -4
- package/package.json +6 -5
package/build/index.js
CHANGED
|
@@ -1,524 +1,462 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
1
|
// ../networked-dom-web/build/index.js
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var __export = (target, all) => {
|
|
35
|
-
for (var name in all)
|
|
36
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
37
|
-
};
|
|
38
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
39
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
40
|
-
for (let key of __getOwnPropNames2(from))
|
|
41
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
42
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
43
|
-
}
|
|
44
|
-
return to;
|
|
45
|
-
};
|
|
46
|
-
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
47
|
-
var src_exports = {};
|
|
48
|
-
__export(src_exports, {
|
|
49
|
-
DOMSanitizer: () => DOMSanitizer,
|
|
50
|
-
NetworkedDOMWebsocket: () => NetworkedDOMWebsocket2,
|
|
51
|
-
NetworkedDOMWebsocketStatus: () => NetworkedDOMWebsocketStatus
|
|
52
|
-
});
|
|
53
|
-
module2.exports = __toCommonJS(src_exports);
|
|
54
|
-
var DOMSanitizer = class _DOMSanitizer {
|
|
55
|
-
static sanitise(node) {
|
|
56
|
-
if (node.getAttributeNames) {
|
|
57
|
-
for (const attr of node.getAttributeNames()) {
|
|
58
|
-
if (!_DOMSanitizer.IsValidAttributeName(attr)) {
|
|
59
|
-
node.removeAttribute(attr);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (node.nodeName === "SCRIPT") {
|
|
64
|
-
node.innerText = "";
|
|
65
|
-
} else {
|
|
66
|
-
if (node.getAttributeNames) {
|
|
67
|
-
for (const attr of node.getAttributeNames()) {
|
|
68
|
-
if (!_DOMSanitizer.shouldAcceptAttribute(attr)) {
|
|
69
|
-
node.removeAttribute(attr);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
for (let i = 0; i < node.childNodes.length; i++) {
|
|
74
|
-
_DOMSanitizer.sanitise(node.childNodes[i]);
|
|
75
|
-
}
|
|
2
|
+
var DOMSanitizer = class _DOMSanitizer {
|
|
3
|
+
static sanitise(node) {
|
|
4
|
+
if (node.getAttributeNames) {
|
|
5
|
+
for (const attr of node.getAttributeNames()) {
|
|
6
|
+
if (!_DOMSanitizer.IsValidAttributeName(attr)) {
|
|
7
|
+
node.removeAttribute(attr);
|
|
76
8
|
}
|
|
77
9
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (!(_DOMSanitizer.IsASCIIAlpha(c) || c === ":" || c === "_")) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
for (let i = 1; i < characters.length; i++) {
|
|
90
|
-
const c2 = characters[i];
|
|
91
|
-
if (!(_DOMSanitizer.IsASCIIDigit(c2) || _DOMSanitizer.IsASCIIAlpha(c2) || c2 === ":" || c2 === "_" || c2 === "-" || c2 === ".")) {
|
|
92
|
-
return false;
|
|
10
|
+
}
|
|
11
|
+
if (node.nodeName === "SCRIPT") {
|
|
12
|
+
node.innerText = "";
|
|
13
|
+
} else {
|
|
14
|
+
if (node.getAttributeNames) {
|
|
15
|
+
for (const attr of node.getAttributeNames()) {
|
|
16
|
+
if (!_DOMSanitizer.shouldAcceptAttribute(attr)) {
|
|
17
|
+
node.removeAttribute(attr);
|
|
93
18
|
}
|
|
94
19
|
}
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
static shouldAcceptAttribute(attribute) {
|
|
98
|
-
if (!_DOMSanitizer.IsValidAttributeName(attribute)) {
|
|
99
|
-
console.warn("Invalid attribute name", attribute);
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
return !attribute.startsWith("on");
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
var websocketProtocol = "networked-dom-v0.1";
|
|
106
|
-
var startingBackoffTimeMilliseconds = 100;
|
|
107
|
-
var maximumBackoffTimeMilliseconds = 1e4;
|
|
108
|
-
var maximumWebsocketConnectionTimeout = 5e3;
|
|
109
|
-
var NetworkedDOMWebsocketStatus = /* @__PURE__ */ ((NetworkedDOMWebsocketStatus2) => {
|
|
110
|
-
NetworkedDOMWebsocketStatus2[NetworkedDOMWebsocketStatus2["Connecting"] = 0] = "Connecting";
|
|
111
|
-
NetworkedDOMWebsocketStatus2[NetworkedDOMWebsocketStatus2["Connected"] = 1] = "Connected";
|
|
112
|
-
NetworkedDOMWebsocketStatus2[NetworkedDOMWebsocketStatus2["Reconnecting"] = 2] = "Reconnecting";
|
|
113
|
-
NetworkedDOMWebsocketStatus2[NetworkedDOMWebsocketStatus2["Disconnected"] = 3] = "Disconnected";
|
|
114
|
-
return NetworkedDOMWebsocketStatus2;
|
|
115
|
-
})(NetworkedDOMWebsocketStatus || {});
|
|
116
|
-
var NetworkedDOMWebsocket2 = class {
|
|
117
|
-
constructor(url, websocketFactory, parentElement, timeCallback, statusUpdateCallback) {
|
|
118
|
-
this.idToElement = /* @__PURE__ */ new Map();
|
|
119
|
-
this.elementToId = /* @__PURE__ */ new Map();
|
|
120
|
-
this.websocket = null;
|
|
121
|
-
this.currentRoot = null;
|
|
122
|
-
this.stopped = false;
|
|
123
|
-
this.backoffTime = startingBackoffTimeMilliseconds;
|
|
124
|
-
this.status = null;
|
|
125
|
-
this.url = url;
|
|
126
|
-
this.websocketFactory = websocketFactory;
|
|
127
|
-
this.parentElement = parentElement;
|
|
128
|
-
this.timeCallback = timeCallback || (() => {
|
|
129
|
-
});
|
|
130
|
-
this.statusUpdateCallback = statusUpdateCallback || (() => {
|
|
131
|
-
});
|
|
132
|
-
this.setStatus(
|
|
133
|
-
0
|
|
134
|
-
/* Connecting */
|
|
135
|
-
);
|
|
136
|
-
this.startWebSocketConnectionAttempt();
|
|
137
|
-
}
|
|
138
|
-
static createWebSocket(url) {
|
|
139
|
-
return new WebSocket(url, [websocketProtocol]);
|
|
140
|
-
}
|
|
141
|
-
setStatus(status) {
|
|
142
|
-
if (this.status !== status) {
|
|
143
|
-
this.status = status;
|
|
144
|
-
this.statusUpdateCallback(status);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
isHTMLElement(node) {
|
|
148
|
-
if (node instanceof HTMLElement) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
if (!this.parentElement.ownerDocument.defaultView) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
return node instanceof this.parentElement.ownerDocument.defaultView.HTMLElement;
|
|
155
20
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
if (!this.parentElement.ownerDocument.defaultView) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
return node instanceof this.parentElement.ownerDocument.defaultView.Text;
|
|
21
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
22
|
+
_DOMSanitizer.sanitise(node.childNodes[i]);
|
|
164
23
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const onWebsocketClose = async () => {
|
|
183
|
-
const hadContents = this.currentRoot !== null;
|
|
184
|
-
this.clearContents();
|
|
185
|
-
if (this.stopped) {
|
|
186
|
-
this.setStatus(
|
|
187
|
-
3
|
|
188
|
-
/* Disconnected */
|
|
189
|
-
);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (!hadContents) {
|
|
193
|
-
await this.waitBackoffTime();
|
|
194
|
-
}
|
|
195
|
-
this.setStatus(
|
|
196
|
-
2
|
|
197
|
-
/* Reconnecting */
|
|
198
|
-
);
|
|
199
|
-
this.startWebSocketConnectionAttempt();
|
|
200
|
-
};
|
|
201
|
-
websocket.addEventListener("close", (e) => {
|
|
202
|
-
if (websocket !== this.websocket) {
|
|
203
|
-
console.warn("Ignoring websocket close event because it is no longer current");
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
console.log("NetworkedDOMWebsocket close", e);
|
|
207
|
-
onWebsocketClose();
|
|
208
|
-
});
|
|
209
|
-
websocket.addEventListener("error", (e) => {
|
|
210
|
-
if (websocket !== this.websocket) {
|
|
211
|
-
console.log("Ignoring websocket error event because it is no longer current");
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
console.error("NetworkedDOMWebsocket error", e);
|
|
215
|
-
onWebsocketClose();
|
|
216
|
-
});
|
|
217
|
-
resolve(websocket);
|
|
218
|
-
});
|
|
219
|
-
websocket.addEventListener("error", (e) => {
|
|
220
|
-
clearTimeout(timeoutId);
|
|
221
|
-
reject(e);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
async waitBackoffTime() {
|
|
226
|
-
console.warn(`Websocket connection to '${this.url}' failed: retrying in ${this.backoffTime}ms`);
|
|
227
|
-
await new Promise((resolve) => setTimeout(resolve, this.backoffTime));
|
|
228
|
-
this.backoffTime = Math.min(
|
|
229
|
-
// Introduce a small amount of randomness to prevent clients from retrying in lockstep
|
|
230
|
-
this.backoffTime * (1.5 + Math.random() * 0.5),
|
|
231
|
-
maximumBackoffTimeMilliseconds
|
|
232
|
-
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static IsASCIIDigit(c) {
|
|
27
|
+
return c >= "0" && c <= "9";
|
|
28
|
+
}
|
|
29
|
+
static IsASCIIAlpha(c) {
|
|
30
|
+
return c >= "a" && c <= "z";
|
|
31
|
+
}
|
|
32
|
+
static IsValidAttributeName(characters) {
|
|
33
|
+
const c = characters[0];
|
|
34
|
+
if (!(_DOMSanitizer.IsASCIIAlpha(c) || c === ":" || c === "_")) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
for (let i = 1; i < characters.length; i++) {
|
|
38
|
+
const c2 = characters[i];
|
|
39
|
+
if (!(_DOMSanitizer.IsASCIIDigit(c2) || _DOMSanitizer.IsASCIIAlpha(c2) || c2 === ":" || c2 === "_" || c2 === "-" || c2 === ".")) {
|
|
40
|
+
return false;
|
|
233
41
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
static shouldAcceptAttribute(attribute) {
|
|
46
|
+
if (!_DOMSanitizer.IsValidAttributeName(attribute)) {
|
|
47
|
+
console.warn("Invalid attribute name", attribute);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return !attribute.startsWith("on");
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var websocketProtocol = "networked-dom-v0.1";
|
|
54
|
+
var startingBackoffTimeMilliseconds = 100;
|
|
55
|
+
var maximumBackoffTimeMilliseconds = 1e4;
|
|
56
|
+
var maximumWebsocketConnectionTimeout = 5e3;
|
|
57
|
+
var NetworkedDOMWebsocket = class {
|
|
58
|
+
constructor(url, websocketFactory, parentElement, timeCallback, statusUpdateCallback) {
|
|
59
|
+
this.idToElement = /* @__PURE__ */ new Map();
|
|
60
|
+
this.elementToId = /* @__PURE__ */ new Map();
|
|
61
|
+
this.websocket = null;
|
|
62
|
+
this.currentRoot = null;
|
|
63
|
+
this.stopped = false;
|
|
64
|
+
this.backoffTime = startingBackoffTimeMilliseconds;
|
|
65
|
+
this.status = null;
|
|
66
|
+
this.url = url;
|
|
67
|
+
this.websocketFactory = websocketFactory;
|
|
68
|
+
this.parentElement = parentElement;
|
|
69
|
+
this.timeCallback = timeCallback || (() => {
|
|
70
|
+
});
|
|
71
|
+
this.statusUpdateCallback = statusUpdateCallback || (() => {
|
|
72
|
+
});
|
|
73
|
+
this.setStatus(
|
|
74
|
+
0
|
|
75
|
+
/* Connecting */
|
|
76
|
+
);
|
|
77
|
+
this.startWebSocketConnectionAttempt();
|
|
78
|
+
}
|
|
79
|
+
static createWebSocket(url) {
|
|
80
|
+
return new WebSocket(url, [websocketProtocol]);
|
|
81
|
+
}
|
|
82
|
+
setStatus(status) {
|
|
83
|
+
if (this.status !== status) {
|
|
84
|
+
this.status = status;
|
|
85
|
+
this.statusUpdateCallback(status);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
isHTMLElement(node) {
|
|
89
|
+
if (node instanceof HTMLElement) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (!this.parentElement.ownerDocument.defaultView) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return node instanceof this.parentElement.ownerDocument.defaultView.HTMLElement;
|
|
96
|
+
}
|
|
97
|
+
isText(node) {
|
|
98
|
+
if (node instanceof Text) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (!this.parentElement.ownerDocument.defaultView) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return node instanceof this.parentElement.ownerDocument.defaultView.Text;
|
|
105
|
+
}
|
|
106
|
+
createWebsocketWithTimeout(timeout) {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
const timeoutId = setTimeout(() => {
|
|
109
|
+
reject(new Error("websocket connection timed out"));
|
|
110
|
+
}, timeout);
|
|
111
|
+
const websocket = this.websocketFactory(this.url);
|
|
112
|
+
websocket.addEventListener("open", () => {
|
|
113
|
+
clearTimeout(timeoutId);
|
|
114
|
+
this.websocket = websocket;
|
|
115
|
+
websocket.addEventListener("message", (event) => {
|
|
116
|
+
if (websocket !== this.websocket) {
|
|
117
|
+
console.log("Ignoring websocket message event because it is no longer current");
|
|
118
|
+
websocket.close();
|
|
240
119
|
return;
|
|
241
120
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
121
|
+
this.handleIncomingWebsocketMessage(event);
|
|
122
|
+
});
|
|
123
|
+
const onWebsocketClose = async () => {
|
|
124
|
+
const hadContents = this.currentRoot !== null;
|
|
125
|
+
this.clearContents();
|
|
126
|
+
if (this.stopped) {
|
|
246
127
|
this.setStatus(
|
|
247
|
-
|
|
248
|
-
/*
|
|
128
|
+
3
|
|
129
|
+
/* Disconnected */
|
|
249
130
|
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (!hadContents) {
|
|
250
134
|
await this.waitBackoffTime();
|
|
251
135
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
console.warn("Warning from server", message);
|
|
263
|
-
break;
|
|
264
|
-
default: {
|
|
265
|
-
if (message.documentTime) {
|
|
266
|
-
if (this.timeCallback) {
|
|
267
|
-
this.timeCallback(message.documentTime);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
switch (message.type) {
|
|
271
|
-
case "snapshot":
|
|
272
|
-
this.handleSnapshot(message);
|
|
273
|
-
break;
|
|
274
|
-
case "attributeChange":
|
|
275
|
-
this.handleAttributeChange(message);
|
|
276
|
-
break;
|
|
277
|
-
case "childrenChanged":
|
|
278
|
-
this.handleChildrenChanged(message);
|
|
279
|
-
break;
|
|
280
|
-
case "textChanged":
|
|
281
|
-
this.handleTextChanged(message);
|
|
282
|
-
break;
|
|
283
|
-
case "ping":
|
|
284
|
-
this.send({
|
|
285
|
-
type: "pong",
|
|
286
|
-
pong: message.ping
|
|
287
|
-
});
|
|
288
|
-
break;
|
|
289
|
-
default:
|
|
290
|
-
console.warn("unknown message type", message);
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
136
|
+
this.setStatus(
|
|
137
|
+
2
|
|
138
|
+
/* Reconnecting */
|
|
139
|
+
);
|
|
140
|
+
this.startWebSocketConnectionAttempt();
|
|
141
|
+
};
|
|
142
|
+
websocket.addEventListener("close", (e) => {
|
|
143
|
+
if (websocket !== this.websocket) {
|
|
144
|
+
console.warn("Ignoring websocket close event because it is no longer current");
|
|
145
|
+
return;
|
|
294
146
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
147
|
+
console.log("NetworkedDOMWebsocket close", e);
|
|
148
|
+
onWebsocketClose();
|
|
149
|
+
});
|
|
150
|
+
websocket.addEventListener("error", (e) => {
|
|
151
|
+
if (websocket !== this.websocket) {
|
|
152
|
+
console.log("Ignoring websocket error event because it is no longer current");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
console.error("NetworkedDOMWebsocket error", e);
|
|
156
|
+
onWebsocketClose();
|
|
157
|
+
});
|
|
158
|
+
resolve(websocket);
|
|
159
|
+
});
|
|
160
|
+
websocket.addEventListener("error", (e) => {
|
|
161
|
+
clearTimeout(timeoutId);
|
|
162
|
+
reject(e);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
async waitBackoffTime() {
|
|
167
|
+
console.warn(`Websocket connection to '${this.url}' failed: retrying in ${this.backoffTime}ms`);
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, this.backoffTime));
|
|
169
|
+
this.backoffTime = Math.min(
|
|
170
|
+
// Introduce a small amount of randomness to prevent clients from retrying in lockstep
|
|
171
|
+
this.backoffTime * (1.5 + Math.random() * 0.5),
|
|
172
|
+
maximumBackoffTimeMilliseconds
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
async startWebSocketConnectionAttempt() {
|
|
176
|
+
if (this.stopped) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
while (true) {
|
|
180
|
+
if (this.stopped) {
|
|
181
|
+
return;
|
|
303
182
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
183
|
+
try {
|
|
184
|
+
await this.createWebsocketWithTimeout(maximumWebsocketConnectionTimeout);
|
|
185
|
+
break;
|
|
186
|
+
} catch (e) {
|
|
187
|
+
this.setStatus(
|
|
188
|
+
2
|
|
189
|
+
/* Reconnecting */
|
|
311
190
|
);
|
|
312
|
-
|
|
313
|
-
...event.detail
|
|
314
|
-
};
|
|
315
|
-
delete detailWithoutElement.element;
|
|
316
|
-
const remoteEvent = {
|
|
317
|
-
type: "event",
|
|
318
|
-
nodeId,
|
|
319
|
-
name: event.type,
|
|
320
|
-
bubbles: event.bubbles,
|
|
321
|
-
params: detailWithoutElement
|
|
322
|
-
};
|
|
323
|
-
this.send(remoteEvent);
|
|
324
|
-
}
|
|
325
|
-
send(fromClientMessage) {
|
|
326
|
-
if (!this.websocket) {
|
|
327
|
-
throw new Error("No websocket created");
|
|
328
|
-
}
|
|
329
|
-
this.websocket.send(JSON.stringify(fromClientMessage));
|
|
330
|
-
}
|
|
331
|
-
handleTextChanged(message) {
|
|
332
|
-
const { nodeId, text } = message;
|
|
333
|
-
if (nodeId === void 0 || nodeId === null) {
|
|
334
|
-
console.warn("No nodeId in textChanged message");
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
const node = this.idToElement.get(nodeId);
|
|
338
|
-
if (!node) {
|
|
339
|
-
throw new Error("No node found for textChanged message");
|
|
340
|
-
}
|
|
341
|
-
if (!this.isText(node)) {
|
|
342
|
-
throw new Error("Node for textChanged message is not a Text node");
|
|
343
|
-
}
|
|
344
|
-
node.textContent = text;
|
|
191
|
+
await this.waitBackoffTime();
|
|
345
192
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
let previousElement;
|
|
363
|
-
if (previousNodeId) {
|
|
364
|
-
previousElement = this.idToElement.get(previousNodeId);
|
|
365
|
-
if (!previousElement) {
|
|
366
|
-
throw new Error("No previous element found for childrenChanged message");
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
for (const addedNode of addedNodes) {
|
|
370
|
-
const childElement = this.handleNewElement(addedNode);
|
|
371
|
-
if (childElement) {
|
|
372
|
-
if (previousElement) {
|
|
373
|
-
const nextElement = previousElement.nextSibling;
|
|
374
|
-
if (nextElement) {
|
|
375
|
-
parent.insertBefore(childElement, nextElement);
|
|
376
|
-
} else {
|
|
377
|
-
parent.append(childElement);
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
parent.append(childElement);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
handleIncomingWebsocketMessage(event) {
|
|
196
|
+
const messages = JSON.parse(event.data);
|
|
197
|
+
for (const message of messages) {
|
|
198
|
+
switch (message.type) {
|
|
199
|
+
case "error":
|
|
200
|
+
console.error("Error from server", message);
|
|
201
|
+
break;
|
|
202
|
+
case "warning":
|
|
203
|
+
console.warn("Warning from server", message);
|
|
204
|
+
break;
|
|
205
|
+
default: {
|
|
206
|
+
if (message.documentTime) {
|
|
207
|
+
if (this.timeCallback) {
|
|
208
|
+
this.timeCallback(message.documentTime);
|
|
381
209
|
}
|
|
382
210
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
this.idToElement.delete(childId);
|
|
211
|
+
switch (message.type) {
|
|
212
|
+
case "snapshot":
|
|
213
|
+
this.handleSnapshot(message);
|
|
214
|
+
break;
|
|
215
|
+
case "attributeChange":
|
|
216
|
+
this.handleAttributeChange(message);
|
|
217
|
+
break;
|
|
218
|
+
case "childrenChanged":
|
|
219
|
+
this.handleChildrenChanged(message);
|
|
220
|
+
break;
|
|
221
|
+
case "textChanged":
|
|
222
|
+
this.handleTextChanged(message);
|
|
223
|
+
break;
|
|
224
|
+
case "ping":
|
|
225
|
+
this.send({
|
|
226
|
+
type: "pong",
|
|
227
|
+
pong: message.ping
|
|
228
|
+
});
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
console.warn("unknown message type", message);
|
|
232
|
+
break;
|
|
406
233
|
}
|
|
407
|
-
this.removeChildElementIds(child);
|
|
408
234
|
}
|
|
409
235
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
stop() {
|
|
239
|
+
this.stopped = true;
|
|
240
|
+
if (this.websocket !== null) {
|
|
241
|
+
this.websocket.close();
|
|
242
|
+
this.websocket = null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
handleEvent(element, event) {
|
|
246
|
+
const nodeId = this.elementToId.get(element);
|
|
247
|
+
if (nodeId === void 0 || nodeId === null) {
|
|
248
|
+
throw new Error("Element not found");
|
|
249
|
+
}
|
|
250
|
+
console.log(
|
|
251
|
+
`Sending event to websocket: "${event.type}" on node: ${nodeId} type: ${element.tagName}`
|
|
252
|
+
);
|
|
253
|
+
const detailWithoutElement = {
|
|
254
|
+
...event.detail
|
|
255
|
+
};
|
|
256
|
+
delete detailWithoutElement.element;
|
|
257
|
+
const remoteEvent = {
|
|
258
|
+
type: "event",
|
|
259
|
+
nodeId,
|
|
260
|
+
name: event.type,
|
|
261
|
+
bubbles: event.bubbles,
|
|
262
|
+
params: detailWithoutElement
|
|
263
|
+
};
|
|
264
|
+
this.send(remoteEvent);
|
|
265
|
+
}
|
|
266
|
+
send(fromClientMessage) {
|
|
267
|
+
if (!this.websocket) {
|
|
268
|
+
throw new Error("No websocket created");
|
|
269
|
+
}
|
|
270
|
+
this.websocket.send(JSON.stringify(fromClientMessage));
|
|
271
|
+
}
|
|
272
|
+
handleTextChanged(message) {
|
|
273
|
+
const { nodeId, text } = message;
|
|
274
|
+
if (nodeId === void 0 || nodeId === null) {
|
|
275
|
+
console.warn("No nodeId in textChanged message");
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const node = this.idToElement.get(nodeId);
|
|
279
|
+
if (!node) {
|
|
280
|
+
throw new Error("No node found for textChanged message");
|
|
281
|
+
}
|
|
282
|
+
if (!this.isText(node)) {
|
|
283
|
+
throw new Error("Node for textChanged message is not a Text node");
|
|
284
|
+
}
|
|
285
|
+
node.textContent = text;
|
|
286
|
+
}
|
|
287
|
+
handleChildrenChanged(message) {
|
|
288
|
+
const { nodeId, addedNodes, removedNodes, previousNodeId } = message;
|
|
289
|
+
if (nodeId === void 0 || nodeId === null) {
|
|
290
|
+
console.warn("No nodeId in childrenChanged message");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const parent = this.idToElement.get(nodeId);
|
|
294
|
+
if (!parent) {
|
|
295
|
+
throw new Error("No parent found for childrenChanged message");
|
|
296
|
+
}
|
|
297
|
+
if (!parent.isConnected) {
|
|
298
|
+
console.error("Parent is not connected", parent);
|
|
299
|
+
}
|
|
300
|
+
if (!this.isHTMLElement(parent)) {
|
|
301
|
+
throw new Error("Parent is not an HTMLElement (that supports children)");
|
|
302
|
+
}
|
|
303
|
+
let previousElement;
|
|
304
|
+
if (previousNodeId) {
|
|
305
|
+
previousElement = this.idToElement.get(previousNodeId);
|
|
306
|
+
if (!previousElement) {
|
|
307
|
+
throw new Error("No previous element found for childrenChanged message");
|
|
431
308
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (this.isHTMLElement(element)) {
|
|
441
|
-
if (newValue === null) {
|
|
442
|
-
element.removeAttribute(attribute);
|
|
443
|
-
} else {
|
|
444
|
-
if (DOMSanitizer.shouldAcceptAttribute(attribute)) {
|
|
445
|
-
element.setAttribute(attribute, newValue);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
309
|
+
}
|
|
310
|
+
for (const addedNode of addedNodes) {
|
|
311
|
+
const childElement = this.handleNewElement(addedNode);
|
|
312
|
+
if (childElement) {
|
|
313
|
+
if (previousElement) {
|
|
314
|
+
const nextElement = previousElement.nextSibling;
|
|
315
|
+
if (nextElement) {
|
|
316
|
+
parent.insertBefore(childElement, nextElement);
|
|
448
317
|
} else {
|
|
449
|
-
|
|
318
|
+
parent.append(childElement);
|
|
450
319
|
}
|
|
451
320
|
} else {
|
|
452
|
-
|
|
321
|
+
parent.append(childElement);
|
|
453
322
|
}
|
|
454
323
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
324
|
+
}
|
|
325
|
+
for (const removedNode of removedNodes) {
|
|
326
|
+
const childElement = this.idToElement.get(removedNode);
|
|
327
|
+
if (!childElement) {
|
|
328
|
+
throw new Error(`Child element not found: ${removedNode}`);
|
|
329
|
+
}
|
|
330
|
+
this.elementToId.delete(childElement);
|
|
331
|
+
this.idToElement.delete(removedNode);
|
|
332
|
+
parent.removeChild(childElement);
|
|
333
|
+
if (this.isHTMLElement(childElement)) {
|
|
334
|
+
this.removeChildElementIds(childElement);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
removeChildElementIds(parent) {
|
|
339
|
+
for (let i = 0; i < parent.children.length; i++) {
|
|
340
|
+
const child = parent.children[i];
|
|
341
|
+
const childId = this.elementToId.get(child);
|
|
342
|
+
if (!childId) {
|
|
343
|
+
console.error("Inner child of removed element had no id", child);
|
|
344
|
+
} else {
|
|
345
|
+
this.elementToId.delete(child);
|
|
346
|
+
this.idToElement.delete(childId);
|
|
347
|
+
}
|
|
348
|
+
this.removeChildElementIds(child);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
handleSnapshot(message) {
|
|
352
|
+
this.backoffTime = startingBackoffTimeMilliseconds;
|
|
353
|
+
this.setStatus(
|
|
354
|
+
1
|
|
355
|
+
/* Connected */
|
|
356
|
+
);
|
|
357
|
+
if (this.currentRoot) {
|
|
358
|
+
this.currentRoot.remove();
|
|
359
|
+
this.currentRoot = null;
|
|
360
|
+
this.elementToId.clear();
|
|
361
|
+
this.idToElement.clear();
|
|
362
|
+
}
|
|
363
|
+
const element = this.handleNewElement(message.snapshot);
|
|
364
|
+
if (!element) {
|
|
365
|
+
throw new Error("Snapshot element not created");
|
|
366
|
+
}
|
|
367
|
+
if (!this.isHTMLElement(element)) {
|
|
368
|
+
throw new Error("Snapshot element is not an HTMLElement");
|
|
369
|
+
}
|
|
370
|
+
this.currentRoot = element;
|
|
371
|
+
this.parentElement.append(element);
|
|
372
|
+
}
|
|
373
|
+
handleAttributeChange(message) {
|
|
374
|
+
const { nodeId, attribute, newValue } = message;
|
|
375
|
+
if (nodeId === void 0 || nodeId === null) {
|
|
376
|
+
console.warn("No nodeId in attributeChange message");
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const element = this.idToElement.get(nodeId);
|
|
380
|
+
if (element) {
|
|
381
|
+
if (this.isHTMLElement(element)) {
|
|
382
|
+
if (newValue === null) {
|
|
383
|
+
element.removeAttribute(attribute);
|
|
384
|
+
} else {
|
|
385
|
+
if (DOMSanitizer.shouldAcceptAttribute(attribute)) {
|
|
386
|
+
element.setAttribute(attribute, newValue);
|
|
504
387
|
}
|
|
505
388
|
}
|
|
506
|
-
|
|
389
|
+
} else {
|
|
390
|
+
console.error("Element is not an HTMLElement and cannot support attributes", element);
|
|
507
391
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
392
|
+
} else {
|
|
393
|
+
console.error("No element found for attributeChange message");
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
handleNewElement(message) {
|
|
397
|
+
if (message.type === "text") {
|
|
398
|
+
const { nodeId: nodeId2, text: text2 } = message;
|
|
399
|
+
const textNode = document.createTextNode("");
|
|
400
|
+
textNode.textContent = text2;
|
|
401
|
+
this.idToElement.set(nodeId2, textNode);
|
|
402
|
+
this.elementToId.set(textNode, nodeId2);
|
|
403
|
+
return textNode;
|
|
404
|
+
}
|
|
405
|
+
const { tag, nodeId, attributes, children, text } = message;
|
|
406
|
+
if (nodeId === void 0 || nodeId === null) {
|
|
407
|
+
console.warn("No nodeId in handleNewElement message", message);
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
if (this.idToElement.has(nodeId)) {
|
|
411
|
+
console.error(
|
|
412
|
+
"Received nodeId to add that is already present",
|
|
413
|
+
nodeId,
|
|
414
|
+
this.idToElement.get(nodeId)
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
if (tag === "#text") {
|
|
418
|
+
const textNode = document.createTextNode("");
|
|
419
|
+
textNode.textContent = text || null;
|
|
420
|
+
this.idToElement.set(nodeId, textNode);
|
|
421
|
+
this.elementToId.set(textNode, nodeId);
|
|
422
|
+
return textNode;
|
|
423
|
+
}
|
|
424
|
+
let element;
|
|
425
|
+
try {
|
|
426
|
+
element = document.createElement(tag);
|
|
427
|
+
} catch (e) {
|
|
428
|
+
console.error(`Error creating element: (${tag})`, e);
|
|
429
|
+
element = document.createElement("div");
|
|
430
|
+
}
|
|
431
|
+
this.idToElement.set(nodeId, element);
|
|
432
|
+
this.elementToId.set(element, nodeId);
|
|
433
|
+
for (const key in attributes) {
|
|
434
|
+
if (DOMSanitizer.shouldAcceptAttribute(key)) {
|
|
435
|
+
const value = attributes[key];
|
|
436
|
+
element.setAttribute(key, value);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (children) {
|
|
440
|
+
for (const child of children) {
|
|
441
|
+
const childElement = this.handleNewElement(child);
|
|
442
|
+
if (childElement) {
|
|
443
|
+
element.append(childElement);
|
|
514
444
|
}
|
|
515
445
|
}
|
|
516
|
-
}
|
|
446
|
+
}
|
|
447
|
+
return element;
|
|
517
448
|
}
|
|
518
|
-
|
|
449
|
+
clearContents() {
|
|
450
|
+
this.idToElement.clear();
|
|
451
|
+
this.elementToId.clear();
|
|
452
|
+
if (this.currentRoot) {
|
|
453
|
+
this.currentRoot.remove();
|
|
454
|
+
this.currentRoot = null;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
};
|
|
519
458
|
|
|
520
459
|
// src/index.ts
|
|
521
|
-
var import_networked_dom_web = __toESM(require_build());
|
|
522
460
|
var thisScript = document.currentScript;
|
|
523
461
|
var scriptUrl = new URL(thisScript.src);
|
|
524
462
|
(function() {
|
|
@@ -543,9 +481,9 @@ var scriptUrl = new URL(thisScript.src);
|
|
|
543
481
|
eventHandler(event.target, event);
|
|
544
482
|
return false;
|
|
545
483
|
});
|
|
546
|
-
const websocket = new
|
|
484
|
+
const websocket = new NetworkedDOMWebsocket(
|
|
547
485
|
documentWebsocketUrl,
|
|
548
|
-
|
|
486
|
+
NetworkedDOMWebsocket.createWebSocket,
|
|
549
487
|
remoteDocumentHolder
|
|
550
488
|
);
|
|
551
489
|
overriddenHandler = (element, event) => {
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../networked-dom-web/src/
|
|
4
|
-
"sourcesContent": ["export * from \"./NetworkedDOMWebsocket\";\nexport * from \"./DOMSanitizer\";\n", "export class DOMSanitizer {\n static sanitise(node: HTMLElement) {\n if (node.getAttributeNames) {\n for (const attr of node.getAttributeNames()) {\n if (!DOMSanitizer.IsValidAttributeName(attr)) {\n node.removeAttribute(attr);\n }\n }\n }\n if (node.nodeName === \"SCRIPT\") {\n // set text to empty string\n node.innerText = \"\";\n } else {\n if (node.getAttributeNames) {\n for (const attr of node.getAttributeNames()) {\n if (!DOMSanitizer.shouldAcceptAttribute(attr)) {\n node.removeAttribute(attr);\n }\n }\n }\n for (let i = 0; i < node.childNodes.length; i++) {\n DOMSanitizer.sanitise(node.childNodes[i] as HTMLElement);\n }\n }\n }\n\n static IsASCIIDigit(c: string): boolean {\n return c >= \"0\" && c <= \"9\";\n }\n\n static IsASCIIAlpha(c: string) {\n return c >= \"a\" && c <= \"z\";\n }\n\n static IsValidAttributeName(characters: string): boolean {\n const c = characters[0];\n if (!(DOMSanitizer.IsASCIIAlpha(c) || c === \":\" || c === \"_\")) {\n return false;\n }\n\n for (let i = 1; i < characters.length; i++) {\n const c = characters[i];\n if (\n !(\n DOMSanitizer.IsASCIIDigit(c) ||\n DOMSanitizer.IsASCIIAlpha(c) ||\n c === \":\" ||\n c === \"_\" ||\n c === \"-\" ||\n c === \".\"\n )\n ) {\n return false;\n }\n }\n\n return true;\n }\n\n static shouldAcceptAttribute(attribute: string) {\n if (!DOMSanitizer.IsValidAttributeName(attribute)) {\n console.warn(\"Invalid attribute name\", attribute);\n return false;\n }\n\n // TODO - this might be overly restrictive - apologies to someone that finds this because you have a non-event attribute filtered by this\n return !attribute.startsWith(\"on\");\n }\n}\n", "import {\n AttributeChangedDiff,\n ChildrenChangedDiff,\n ClientMessage,\n NodeDescription,\n RemoteEvent,\n ServerMessage,\n SnapshotMessage,\n TextChangedDiff,\n} from \"@mml-io/networked-dom-protocol\";\n\nimport { DOMSanitizer } from \"./DOMSanitizer\";\n\nconst websocketProtocol = \"networked-dom-v0.1\";\n\nconst startingBackoffTimeMilliseconds = 100;\nconst maximumBackoffTimeMilliseconds = 10000;\nconst maximumWebsocketConnectionTimeout = 5000;\n\nexport type NetworkedDOMWebsocketFactory = (url: string) => WebSocket;\n\nexport enum NetworkedDOMWebsocketStatus {\n Connecting,\n Connected,\n Reconnecting,\n Disconnected,\n}\n\nexport class NetworkedDOMWebsocket {\n private idToElement = new Map<number, Node>();\n private elementToId = new Map<Node, number>();\n private websocket: WebSocket | null = null;\n private currentRoot: HTMLElement | null = null;\n\n private url: string;\n private websocketFactory: NetworkedDOMWebsocketFactory;\n private parentElement: HTMLElement;\n private timeCallback: (time: number) => void;\n private statusUpdateCallback: (status: NetworkedDOMWebsocketStatus) => void;\n private stopped = false;\n private backoffTime = startingBackoffTimeMilliseconds;\n private status: NetworkedDOMWebsocketStatus | null = null;\n\n public static createWebSocket(url: string): WebSocket {\n return new WebSocket(url, [websocketProtocol]);\n }\n\n constructor(\n url: string,\n websocketFactory: NetworkedDOMWebsocketFactory,\n parentElement: HTMLElement,\n timeCallback?: (time: number) => void,\n statusUpdateCallback?: (status: NetworkedDOMWebsocketStatus) => void,\n ) {\n this.url = url;\n this.websocketFactory = websocketFactory;\n this.parentElement = parentElement;\n this.timeCallback =\n timeCallback ||\n (() => {\n // no-op\n });\n this.statusUpdateCallback =\n statusUpdateCallback ||\n (() => {\n // no-op\n });\n this.setStatus(NetworkedDOMWebsocketStatus.Connecting);\n this.startWebSocketConnectionAttempt();\n }\n\n private setStatus(status: NetworkedDOMWebsocketStatus) {\n if (this.status !== status) {\n this.status = status;\n this.statusUpdateCallback(status);\n }\n }\n\n private isHTMLElement(node: unknown): node is HTMLElement {\n if (node instanceof HTMLElement) {\n return true;\n }\n if (!this.parentElement.ownerDocument.defaultView) {\n return false;\n }\n return node instanceof this.parentElement.ownerDocument.defaultView.HTMLElement;\n }\n\n private isText(node: unknown): node is Text {\n if (node instanceof Text) {\n return true;\n }\n if (!this.parentElement.ownerDocument.defaultView) {\n return false;\n }\n return node instanceof this.parentElement.ownerDocument.defaultView.Text;\n }\n\n private createWebsocketWithTimeout(timeout: number): Promise<WebSocket> {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(new Error(\"websocket connection timed out\"));\n }, timeout);\n const websocket = this.websocketFactory(this.url);\n websocket.addEventListener(\"open\", () => {\n clearTimeout(timeoutId);\n\n this.websocket = websocket;\n\n websocket.addEventListener(\"message\", (event) => {\n if (websocket !== this.websocket) {\n console.log(\"Ignoring websocket message event because it is no longer current\");\n websocket.close();\n return;\n }\n this.handleIncomingWebsocketMessage(event);\n });\n\n const onWebsocketClose = async () => {\n const hadContents = this.currentRoot !== null;\n this.clearContents();\n if (this.stopped) {\n // This closing is expected. The client closed the websocket.\n this.setStatus(NetworkedDOMWebsocketStatus.Disconnected);\n return;\n }\n if (!hadContents) {\n // The websocket did not deliver any contents. It may have been successfully opened, but immediately closed. This client should back off to prevent this happening in a rapid loop.\n await this.waitBackoffTime();\n }\n // The websocket closed unexpectedly. Try to reconnect.\n this.setStatus(NetworkedDOMWebsocketStatus.Reconnecting);\n this.startWebSocketConnectionAttempt();\n };\n\n websocket.addEventListener(\"close\", (e) => {\n if (websocket !== this.websocket) {\n console.warn(\"Ignoring websocket close event because it is no longer current\");\n return;\n }\n console.log(\"NetworkedDOMWebsocket close\", e);\n onWebsocketClose();\n });\n websocket.addEventListener(\"error\", (e) => {\n if (websocket !== this.websocket) {\n console.log(\"Ignoring websocket error event because it is no longer current\");\n return;\n }\n console.error(\"NetworkedDOMWebsocket error\", e);\n onWebsocketClose();\n });\n\n resolve(websocket);\n });\n websocket.addEventListener(\"error\", (e) => {\n clearTimeout(timeoutId);\n reject(e);\n });\n });\n }\n\n private async waitBackoffTime(): Promise<void> {\n console.warn(`Websocket connection to '${this.url}' failed: retrying in ${this.backoffTime}ms`);\n await new Promise((resolve) => setTimeout(resolve, this.backoffTime));\n this.backoffTime = Math.min(\n // Introduce a small amount of randomness to prevent clients from retrying in lockstep\n this.backoffTime * (1.5 + Math.random() * 0.5),\n maximumBackoffTimeMilliseconds,\n );\n }\n\n private async startWebSocketConnectionAttempt() {\n if (this.stopped) {\n return;\n }\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (this.stopped) {\n return;\n }\n try {\n await this.createWebsocketWithTimeout(maximumWebsocketConnectionTimeout);\n break;\n } catch (e) {\n // Connection failed, retry with backoff\n this.setStatus(NetworkedDOMWebsocketStatus.Reconnecting);\n await this.waitBackoffTime();\n }\n }\n }\n\n private handleIncomingWebsocketMessage(event: MessageEvent) {\n const messages = JSON.parse(event.data) as Array<ServerMessage>;\n for (const message of messages) {\n switch (message.type) {\n case \"error\":\n console.error(\"Error from server\", message);\n break;\n case \"warning\":\n console.warn(\"Warning from server\", message);\n break;\n default: {\n if (message.documentTime) {\n if (this.timeCallback) {\n this.timeCallback(message.documentTime);\n }\n }\n switch (message.type) {\n case \"snapshot\":\n this.handleSnapshot(message);\n break;\n case \"attributeChange\":\n this.handleAttributeChange(message);\n break;\n case \"childrenChanged\":\n this.handleChildrenChanged(message);\n break;\n case \"textChanged\":\n this.handleTextChanged(message);\n break;\n case \"ping\":\n this.send({\n type: \"pong\",\n pong: message.ping,\n });\n break;\n default:\n console.warn(\"unknown message type\", message);\n break;\n }\n }\n }\n }\n }\n\n public stop() {\n this.stopped = true;\n if (this.websocket !== null) {\n this.websocket.close();\n this.websocket = null;\n }\n }\n\n public handleEvent(element: HTMLElement, event: CustomEvent<{ element: HTMLElement }>) {\n const nodeId = this.elementToId.get(element);\n if (nodeId === undefined || nodeId === null) {\n throw new Error(\"Element not found\");\n }\n\n console.log(\n `Sending event to websocket: \"${event.type}\" on node: ${nodeId} type: ${element.tagName}`,\n );\n\n const detailWithoutElement: Partial<typeof event.detail> = {\n ...event.detail,\n };\n delete detailWithoutElement.element;\n\n const remoteEvent: RemoteEvent = {\n type: \"event\",\n nodeId,\n name: event.type,\n bubbles: event.bubbles,\n params: detailWithoutElement,\n };\n\n this.send(remoteEvent);\n }\n\n private send(fromClientMessage: ClientMessage) {\n if (!this.websocket) {\n throw new Error(\"No websocket created\");\n }\n this.websocket.send(JSON.stringify(fromClientMessage));\n }\n\n private handleTextChanged(message: TextChangedDiff) {\n const { nodeId, text } = message;\n\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in textChanged message\");\n return;\n }\n const node = this.idToElement.get(nodeId);\n if (!node) {\n throw new Error(\"No node found for textChanged message\");\n }\n if (!this.isText(node)) {\n throw new Error(\"Node for textChanged message is not a Text node\");\n }\n node.textContent = text;\n }\n\n private handleChildrenChanged(message: ChildrenChangedDiff) {\n const { nodeId, addedNodes, removedNodes, previousNodeId } = message;\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in childrenChanged message\");\n return;\n }\n const parent = this.idToElement.get(nodeId);\n if (!parent) {\n throw new Error(\"No parent found for childrenChanged message\");\n }\n if (!parent.isConnected) {\n console.error(\"Parent is not connected\", parent);\n }\n if (!this.isHTMLElement(parent)) {\n throw new Error(\"Parent is not an HTMLElement (that supports children)\");\n }\n let previousElement;\n if (previousNodeId) {\n previousElement = this.idToElement.get(previousNodeId);\n if (!previousElement) {\n throw new Error(\"No previous element found for childrenChanged message\");\n }\n }\n\n for (const addedNode of addedNodes) {\n const childElement = this.handleNewElement(addedNode);\n if (childElement) {\n if (previousElement) {\n const nextElement = previousElement.nextSibling;\n if (nextElement) {\n parent.insertBefore(childElement, nextElement);\n } else {\n parent.append(childElement);\n }\n } else {\n parent.append(childElement);\n }\n }\n }\n for (const removedNode of removedNodes) {\n const childElement = this.idToElement.get(removedNode);\n if (!childElement) {\n throw new Error(`Child element not found: ${removedNode}`);\n }\n this.elementToId.delete(childElement);\n this.idToElement.delete(removedNode);\n parent.removeChild(childElement);\n if (this.isHTMLElement(childElement)) {\n // If child is capable of supporting children then remove any that exist\n this.removeChildElementIds(childElement);\n }\n }\n }\n\n private removeChildElementIds(parent: HTMLElement) {\n for (let i = 0; i < parent.children.length; i++) {\n const child = parent.children[i];\n const childId = this.elementToId.get(child as HTMLElement);\n if (!childId) {\n console.error(\"Inner child of removed element had no id\", child);\n } else {\n this.elementToId.delete(child);\n this.idToElement.delete(childId);\n }\n this.removeChildElementIds(child as HTMLElement);\n }\n }\n\n private handleSnapshot(message: SnapshotMessage) {\n // This websocket is successfully connected. Reset the backoff time.\n this.backoffTime = startingBackoffTimeMilliseconds;\n this.setStatus(NetworkedDOMWebsocketStatus.Connected);\n\n if (this.currentRoot) {\n this.currentRoot.remove();\n this.currentRoot = null;\n this.elementToId.clear();\n this.idToElement.clear();\n }\n\n // create a tree of DOM elements\n // NOTE: the MElement constructors are not executed during this stage\n const element = this.handleNewElement(message.snapshot);\n if (!element) {\n throw new Error(\"Snapshot element not created\");\n }\n if (!this.isHTMLElement(element)) {\n throw new Error(\"Snapshot element is not an HTMLElement\");\n }\n this.currentRoot = element;\n // appending to the tree causes MElements to be constructed\n this.parentElement.append(element);\n }\n\n private handleAttributeChange(message: AttributeChangedDiff) {\n const { nodeId, attribute, newValue } = message;\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in attributeChange message\");\n return;\n }\n const element = this.idToElement.get(nodeId);\n if (element) {\n if (this.isHTMLElement(element)) {\n if (newValue === null) {\n element.removeAttribute(attribute);\n } else {\n if (DOMSanitizer.shouldAcceptAttribute(attribute)) {\n element.setAttribute(attribute, newValue);\n }\n }\n } else {\n console.error(\"Element is not an HTMLElement and cannot support attributes\", element);\n }\n } else {\n console.error(\"No element found for attributeChange message\");\n }\n }\n\n private handleNewElement(message: NodeDescription): Node | null {\n if (message.type === \"text\") {\n const { nodeId, text } = message;\n const textNode = document.createTextNode(\"\");\n textNode.textContent = text;\n this.idToElement.set(nodeId, textNode);\n this.elementToId.set(textNode, nodeId);\n return textNode;\n }\n const { tag, nodeId, attributes, children, text } = message;\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in handleNewElement message\", message);\n return null;\n }\n if (this.idToElement.has(nodeId)) {\n console.error(\n \"Received nodeId to add that is already present\",\n nodeId,\n this.idToElement.get(nodeId),\n );\n }\n if (tag === \"#text\") {\n const textNode = document.createTextNode(\"\");\n textNode.textContent = text || null;\n this.idToElement.set(nodeId, textNode);\n this.elementToId.set(textNode, nodeId);\n return textNode;\n }\n\n let element;\n try {\n element = document.createElement(tag);\n } catch (e) {\n console.error(`Error creating element: (${tag})`, e);\n element = document.createElement(\"div\");\n }\n this.idToElement.set(nodeId, element);\n this.elementToId.set(element, nodeId);\n for (const key in attributes) {\n if (DOMSanitizer.shouldAcceptAttribute(key)) {\n const value = attributes[key];\n element.setAttribute(key, value);\n }\n }\n if (children) {\n for (const child of children) {\n const childElement = this.handleNewElement(child);\n if (childElement) {\n element.append(childElement);\n }\n }\n }\n return element;\n }\n\n private clearContents() {\n this.idToElement.clear();\n this.elementToId.clear();\n if (this.currentRoot) {\n this.currentRoot.remove();\n this.currentRoot = null;\n }\n }\n}\n", "import { NetworkedDOMWebsocket } from \"@mml-io/networked-dom-web\";\n\nconst thisScript = document.currentScript as HTMLScriptElement;\nconst scriptUrl = new URL(thisScript.src);\n\n(function () {\n const websocketUrl = scriptUrl.searchParams.get(\"websocketUrl\");\n if (!websocketUrl) {\n console.error(\"websocketUrl not set\");\n return;\n }\n window.addEventListener(\"load\", () => {\n const documentWebsocketUrls = websocketUrl.split(\",\");\n\n for (const documentWebsocketUrl of documentWebsocketUrls) {\n let overriddenHandler: ((element: HTMLElement, event: CustomEvent) => void) | null = null;\n const eventHandler = (element: HTMLElement, event: CustomEvent) => {\n if (!overriddenHandler) {\n throw new Error(\"overriddenHandler not set\");\n }\n overriddenHandler(element, event);\n };\n const remoteDocumentHolder = document.createElement(\"div\");\n document.body.append(remoteDocumentHolder);\n\n remoteDocumentHolder.addEventListener(\"click\", (event: Event) => {\n eventHandler(event.target as HTMLElement, event as CustomEvent);\n return false;\n });\n\n const websocket = new NetworkedDOMWebsocket(\n documentWebsocketUrl,\n NetworkedDOMWebsocket.createWebSocket,\n remoteDocumentHolder,\n );\n overriddenHandler = (element: HTMLElement, event: CustomEvent) => {\n websocket.handleEvent(element, event);\n };\n }\n });\n})();\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../networked-dom-web/src/DOMSanitizer.ts", "../../networked-dom-web/src/NetworkedDOMWebsocket.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export class DOMSanitizer {\n static sanitise(node: HTMLElement) {\n if (node.getAttributeNames) {\n for (const attr of node.getAttributeNames()) {\n if (!DOMSanitizer.IsValidAttributeName(attr)) {\n node.removeAttribute(attr);\n }\n }\n }\n if (node.nodeName === \"SCRIPT\") {\n // set text to empty string\n node.innerText = \"\";\n } else {\n if (node.getAttributeNames) {\n for (const attr of node.getAttributeNames()) {\n if (!DOMSanitizer.shouldAcceptAttribute(attr)) {\n node.removeAttribute(attr);\n }\n }\n }\n for (let i = 0; i < node.childNodes.length; i++) {\n DOMSanitizer.sanitise(node.childNodes[i] as HTMLElement);\n }\n }\n }\n\n static IsASCIIDigit(c: string): boolean {\n return c >= \"0\" && c <= \"9\";\n }\n\n static IsASCIIAlpha(c: string) {\n return c >= \"a\" && c <= \"z\";\n }\n\n static IsValidAttributeName(characters: string): boolean {\n const c = characters[0];\n if (!(DOMSanitizer.IsASCIIAlpha(c) || c === \":\" || c === \"_\")) {\n return false;\n }\n\n for (let i = 1; i < characters.length; i++) {\n const c = characters[i];\n if (\n !(\n DOMSanitizer.IsASCIIDigit(c) ||\n DOMSanitizer.IsASCIIAlpha(c) ||\n c === \":\" ||\n c === \"_\" ||\n c === \"-\" ||\n c === \".\"\n )\n ) {\n return false;\n }\n }\n\n return true;\n }\n\n static shouldAcceptAttribute(attribute: string) {\n if (!DOMSanitizer.IsValidAttributeName(attribute)) {\n console.warn(\"Invalid attribute name\", attribute);\n return false;\n }\n\n // TODO - this might be overly restrictive - apologies to someone that finds this because you have a non-event attribute filtered by this\n return !attribute.startsWith(\"on\");\n }\n}\n", "import {\n AttributeChangedDiff,\n ChildrenChangedDiff,\n ClientMessage,\n NodeDescription,\n RemoteEvent,\n ServerMessage,\n SnapshotMessage,\n TextChangedDiff,\n} from \"@mml-io/networked-dom-protocol\";\n\nimport { DOMSanitizer } from \"./DOMSanitizer\";\n\nconst websocketProtocol = \"networked-dom-v0.1\";\n\nconst startingBackoffTimeMilliseconds = 100;\nconst maximumBackoffTimeMilliseconds = 10000;\nconst maximumWebsocketConnectionTimeout = 5000;\n\nexport type NetworkedDOMWebsocketFactory = (url: string) => WebSocket;\n\nexport enum NetworkedDOMWebsocketStatus {\n Connecting,\n Connected,\n Reconnecting,\n Disconnected,\n}\n\nexport class NetworkedDOMWebsocket {\n private idToElement = new Map<number, Node>();\n private elementToId = new Map<Node, number>();\n private websocket: WebSocket | null = null;\n private currentRoot: HTMLElement | null = null;\n\n private url: string;\n private websocketFactory: NetworkedDOMWebsocketFactory;\n private parentElement: HTMLElement;\n private timeCallback: (time: number) => void;\n private statusUpdateCallback: (status: NetworkedDOMWebsocketStatus) => void;\n private stopped = false;\n private backoffTime = startingBackoffTimeMilliseconds;\n private status: NetworkedDOMWebsocketStatus | null = null;\n\n public static createWebSocket(url: string): WebSocket {\n return new WebSocket(url, [websocketProtocol]);\n }\n\n constructor(\n url: string,\n websocketFactory: NetworkedDOMWebsocketFactory,\n parentElement: HTMLElement,\n timeCallback?: (time: number) => void,\n statusUpdateCallback?: (status: NetworkedDOMWebsocketStatus) => void,\n ) {\n this.url = url;\n this.websocketFactory = websocketFactory;\n this.parentElement = parentElement;\n this.timeCallback =\n timeCallback ||\n (() => {\n // no-op\n });\n this.statusUpdateCallback =\n statusUpdateCallback ||\n (() => {\n // no-op\n });\n this.setStatus(NetworkedDOMWebsocketStatus.Connecting);\n this.startWebSocketConnectionAttempt();\n }\n\n private setStatus(status: NetworkedDOMWebsocketStatus) {\n if (this.status !== status) {\n this.status = status;\n this.statusUpdateCallback(status);\n }\n }\n\n private isHTMLElement(node: unknown): node is HTMLElement {\n if (node instanceof HTMLElement) {\n return true;\n }\n if (!this.parentElement.ownerDocument.defaultView) {\n return false;\n }\n return node instanceof this.parentElement.ownerDocument.defaultView.HTMLElement;\n }\n\n private isText(node: unknown): node is Text {\n if (node instanceof Text) {\n return true;\n }\n if (!this.parentElement.ownerDocument.defaultView) {\n return false;\n }\n return node instanceof this.parentElement.ownerDocument.defaultView.Text;\n }\n\n private createWebsocketWithTimeout(timeout: number): Promise<WebSocket> {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(new Error(\"websocket connection timed out\"));\n }, timeout);\n const websocket = this.websocketFactory(this.url);\n websocket.addEventListener(\"open\", () => {\n clearTimeout(timeoutId);\n\n this.websocket = websocket;\n\n websocket.addEventListener(\"message\", (event) => {\n if (websocket !== this.websocket) {\n console.log(\"Ignoring websocket message event because it is no longer current\");\n websocket.close();\n return;\n }\n this.handleIncomingWebsocketMessage(event);\n });\n\n const onWebsocketClose = async () => {\n const hadContents = this.currentRoot !== null;\n this.clearContents();\n if (this.stopped) {\n // This closing is expected. The client closed the websocket.\n this.setStatus(NetworkedDOMWebsocketStatus.Disconnected);\n return;\n }\n if (!hadContents) {\n // The websocket did not deliver any contents. It may have been successfully opened, but immediately closed. This client should back off to prevent this happening in a rapid loop.\n await this.waitBackoffTime();\n }\n // The websocket closed unexpectedly. Try to reconnect.\n this.setStatus(NetworkedDOMWebsocketStatus.Reconnecting);\n this.startWebSocketConnectionAttempt();\n };\n\n websocket.addEventListener(\"close\", (e) => {\n if (websocket !== this.websocket) {\n console.warn(\"Ignoring websocket close event because it is no longer current\");\n return;\n }\n console.log(\"NetworkedDOMWebsocket close\", e);\n onWebsocketClose();\n });\n websocket.addEventListener(\"error\", (e) => {\n if (websocket !== this.websocket) {\n console.log(\"Ignoring websocket error event because it is no longer current\");\n return;\n }\n console.error(\"NetworkedDOMWebsocket error\", e);\n onWebsocketClose();\n });\n\n resolve(websocket);\n });\n websocket.addEventListener(\"error\", (e) => {\n clearTimeout(timeoutId);\n reject(e);\n });\n });\n }\n\n private async waitBackoffTime(): Promise<void> {\n console.warn(`Websocket connection to '${this.url}' failed: retrying in ${this.backoffTime}ms`);\n await new Promise((resolve) => setTimeout(resolve, this.backoffTime));\n this.backoffTime = Math.min(\n // Introduce a small amount of randomness to prevent clients from retrying in lockstep\n this.backoffTime * (1.5 + Math.random() * 0.5),\n maximumBackoffTimeMilliseconds,\n );\n }\n\n private async startWebSocketConnectionAttempt() {\n if (this.stopped) {\n return;\n }\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (this.stopped) {\n return;\n }\n try {\n await this.createWebsocketWithTimeout(maximumWebsocketConnectionTimeout);\n break;\n } catch (e) {\n // Connection failed, retry with backoff\n this.setStatus(NetworkedDOMWebsocketStatus.Reconnecting);\n await this.waitBackoffTime();\n }\n }\n }\n\n private handleIncomingWebsocketMessage(event: MessageEvent) {\n const messages = JSON.parse(event.data) as Array<ServerMessage>;\n for (const message of messages) {\n switch (message.type) {\n case \"error\":\n console.error(\"Error from server\", message);\n break;\n case \"warning\":\n console.warn(\"Warning from server\", message);\n break;\n default: {\n if (message.documentTime) {\n if (this.timeCallback) {\n this.timeCallback(message.documentTime);\n }\n }\n switch (message.type) {\n case \"snapshot\":\n this.handleSnapshot(message);\n break;\n case \"attributeChange\":\n this.handleAttributeChange(message);\n break;\n case \"childrenChanged\":\n this.handleChildrenChanged(message);\n break;\n case \"textChanged\":\n this.handleTextChanged(message);\n break;\n case \"ping\":\n this.send({\n type: \"pong\",\n pong: message.ping,\n });\n break;\n default:\n console.warn(\"unknown message type\", message);\n break;\n }\n }\n }\n }\n }\n\n public stop() {\n this.stopped = true;\n if (this.websocket !== null) {\n this.websocket.close();\n this.websocket = null;\n }\n }\n\n public handleEvent(element: HTMLElement, event: CustomEvent<{ element: HTMLElement }>) {\n const nodeId = this.elementToId.get(element);\n if (nodeId === undefined || nodeId === null) {\n throw new Error(\"Element not found\");\n }\n\n console.log(\n `Sending event to websocket: \"${event.type}\" on node: ${nodeId} type: ${element.tagName}`,\n );\n\n const detailWithoutElement: Partial<typeof event.detail> = {\n ...event.detail,\n };\n delete detailWithoutElement.element;\n\n const remoteEvent: RemoteEvent = {\n type: \"event\",\n nodeId,\n name: event.type,\n bubbles: event.bubbles,\n params: detailWithoutElement,\n };\n\n this.send(remoteEvent);\n }\n\n private send(fromClientMessage: ClientMessage) {\n if (!this.websocket) {\n throw new Error(\"No websocket created\");\n }\n this.websocket.send(JSON.stringify(fromClientMessage));\n }\n\n private handleTextChanged(message: TextChangedDiff) {\n const { nodeId, text } = message;\n\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in textChanged message\");\n return;\n }\n const node = this.idToElement.get(nodeId);\n if (!node) {\n throw new Error(\"No node found for textChanged message\");\n }\n if (!this.isText(node)) {\n throw new Error(\"Node for textChanged message is not a Text node\");\n }\n node.textContent = text;\n }\n\n private handleChildrenChanged(message: ChildrenChangedDiff) {\n const { nodeId, addedNodes, removedNodes, previousNodeId } = message;\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in childrenChanged message\");\n return;\n }\n const parent = this.idToElement.get(nodeId);\n if (!parent) {\n throw new Error(\"No parent found for childrenChanged message\");\n }\n if (!parent.isConnected) {\n console.error(\"Parent is not connected\", parent);\n }\n if (!this.isHTMLElement(parent)) {\n throw new Error(\"Parent is not an HTMLElement (that supports children)\");\n }\n let previousElement;\n if (previousNodeId) {\n previousElement = this.idToElement.get(previousNodeId);\n if (!previousElement) {\n throw new Error(\"No previous element found for childrenChanged message\");\n }\n }\n\n for (const addedNode of addedNodes) {\n const childElement = this.handleNewElement(addedNode);\n if (childElement) {\n if (previousElement) {\n const nextElement = previousElement.nextSibling;\n if (nextElement) {\n parent.insertBefore(childElement, nextElement);\n } else {\n parent.append(childElement);\n }\n } else {\n parent.append(childElement);\n }\n }\n }\n for (const removedNode of removedNodes) {\n const childElement = this.idToElement.get(removedNode);\n if (!childElement) {\n throw new Error(`Child element not found: ${removedNode}`);\n }\n this.elementToId.delete(childElement);\n this.idToElement.delete(removedNode);\n parent.removeChild(childElement);\n if (this.isHTMLElement(childElement)) {\n // If child is capable of supporting children then remove any that exist\n this.removeChildElementIds(childElement);\n }\n }\n }\n\n private removeChildElementIds(parent: HTMLElement) {\n for (let i = 0; i < parent.children.length; i++) {\n const child = parent.children[i];\n const childId = this.elementToId.get(child as HTMLElement);\n if (!childId) {\n console.error(\"Inner child of removed element had no id\", child);\n } else {\n this.elementToId.delete(child);\n this.idToElement.delete(childId);\n }\n this.removeChildElementIds(child as HTMLElement);\n }\n }\n\n private handleSnapshot(message: SnapshotMessage) {\n // This websocket is successfully connected. Reset the backoff time.\n this.backoffTime = startingBackoffTimeMilliseconds;\n this.setStatus(NetworkedDOMWebsocketStatus.Connected);\n\n if (this.currentRoot) {\n this.currentRoot.remove();\n this.currentRoot = null;\n this.elementToId.clear();\n this.idToElement.clear();\n }\n\n // create a tree of DOM elements\n // NOTE: the MElement constructors are not executed during this stage\n const element = this.handleNewElement(message.snapshot);\n if (!element) {\n throw new Error(\"Snapshot element not created\");\n }\n if (!this.isHTMLElement(element)) {\n throw new Error(\"Snapshot element is not an HTMLElement\");\n }\n this.currentRoot = element;\n // appending to the tree causes MElements to be constructed\n this.parentElement.append(element);\n }\n\n private handleAttributeChange(message: AttributeChangedDiff) {\n const { nodeId, attribute, newValue } = message;\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in attributeChange message\");\n return;\n }\n const element = this.idToElement.get(nodeId);\n if (element) {\n if (this.isHTMLElement(element)) {\n if (newValue === null) {\n element.removeAttribute(attribute);\n } else {\n if (DOMSanitizer.shouldAcceptAttribute(attribute)) {\n element.setAttribute(attribute, newValue);\n }\n }\n } else {\n console.error(\"Element is not an HTMLElement and cannot support attributes\", element);\n }\n } else {\n console.error(\"No element found for attributeChange message\");\n }\n }\n\n private handleNewElement(message: NodeDescription): Node | null {\n if (message.type === \"text\") {\n const { nodeId, text } = message;\n const textNode = document.createTextNode(\"\");\n textNode.textContent = text;\n this.idToElement.set(nodeId, textNode);\n this.elementToId.set(textNode, nodeId);\n return textNode;\n }\n const { tag, nodeId, attributes, children, text } = message;\n if (nodeId === undefined || nodeId === null) {\n console.warn(\"No nodeId in handleNewElement message\", message);\n return null;\n }\n if (this.idToElement.has(nodeId)) {\n console.error(\n \"Received nodeId to add that is already present\",\n nodeId,\n this.idToElement.get(nodeId),\n );\n }\n if (tag === \"#text\") {\n const textNode = document.createTextNode(\"\");\n textNode.textContent = text || null;\n this.idToElement.set(nodeId, textNode);\n this.elementToId.set(textNode, nodeId);\n return textNode;\n }\n\n let element;\n try {\n element = document.createElement(tag);\n } catch (e) {\n console.error(`Error creating element: (${tag})`, e);\n element = document.createElement(\"div\");\n }\n this.idToElement.set(nodeId, element);\n this.elementToId.set(element, nodeId);\n for (const key in attributes) {\n if (DOMSanitizer.shouldAcceptAttribute(key)) {\n const value = attributes[key];\n element.setAttribute(key, value);\n }\n }\n if (children) {\n for (const child of children) {\n const childElement = this.handleNewElement(child);\n if (childElement) {\n element.append(childElement);\n }\n }\n }\n return element;\n }\n\n private clearContents() {\n this.idToElement.clear();\n this.elementToId.clear();\n if (this.currentRoot) {\n this.currentRoot.remove();\n this.currentRoot = null;\n }\n }\n}\n", "import { NetworkedDOMWebsocket } from \"@mml-io/networked-dom-web\";\n\nconst thisScript = document.currentScript as HTMLScriptElement;\nconst scriptUrl = new URL(thisScript.src);\n\n(function () {\n const websocketUrl = scriptUrl.searchParams.get(\"websocketUrl\");\n if (!websocketUrl) {\n console.error(\"websocketUrl not set\");\n return;\n }\n window.addEventListener(\"load\", () => {\n const documentWebsocketUrls = websocketUrl.split(\",\");\n\n for (const documentWebsocketUrl of documentWebsocketUrls) {\n let overriddenHandler: ((element: HTMLElement, event: CustomEvent) => void) | null = null;\n const eventHandler = (element: HTMLElement, event: CustomEvent) => {\n if (!overriddenHandler) {\n throw new Error(\"overriddenHandler not set\");\n }\n overriddenHandler(element, event);\n };\n const remoteDocumentHolder = document.createElement(\"div\");\n document.body.append(remoteDocumentHolder);\n\n remoteDocumentHolder.addEventListener(\"click\", (event: Event) => {\n eventHandler(event.target as HTMLElement, event as CustomEvent);\n return false;\n });\n\n const websocket = new NetworkedDOMWebsocket(\n documentWebsocketUrl,\n NetworkedDOMWebsocket.createWebSocket,\n remoteDocumentHolder,\n );\n overriddenHandler = (element: HTMLElement, event: CustomEvent) => {\n websocket.handleEvent(element, event);\n };\n }\n });\n})();\n"],
|
|
5
|
+
"mappings": ";AAAO,IAAM,eAAN,MAAM,cAAa;EACxB,OAAO,SAAS,MAAmB;AACjC,QAAI,KAAK,mBAAmB;AAC1B,iBAAW,QAAQ,KAAK,kBAAkB,GAAG;AAC3C,YAAI,CAAC,cAAa,qBAAqB,IAAI,GAAG;AAC5C,eAAK,gBAAgB,IAAI;QAC3B;MACF;IACF;AACA,QAAI,KAAK,aAAa,UAAU;AAE9B,WAAK,YAAY;IACnB,OAAO;AACL,UAAI,KAAK,mBAAmB;AAC1B,mBAAW,QAAQ,KAAK,kBAAkB,GAAG;AAC3C,cAAI,CAAC,cAAa,sBAAsB,IAAI,GAAG;AAC7C,iBAAK,gBAAgB,IAAI;UAC3B;QACF;MACF;AACA,eAAS,I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"@mml-io/networked-dom-web-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"files": [
|
|
8
8
|
"/build"
|
|
9
9
|
],
|
|
10
|
+
"type": "module",
|
|
10
11
|
"main": "build/index.js",
|
|
11
12
|
"scripts": {
|
|
12
13
|
"type-check": "tsc --noEmit",
|
|
13
14
|
"build": "tsx ./build.ts --build",
|
|
14
15
|
"iterate": "cross-env PORT=28892 tsx ./build.ts --serve",
|
|
15
|
-
"lint": "eslint \"./src/**/*.{js,jsx,ts,tsx}\" --max-warnings 0",
|
|
16
|
-
"lint-fix": "eslint \"./src/**/*.{js,jsx,ts,tsx}\" --fix"
|
|
16
|
+
"lint": "eslint \"./{src,test}/**/*.{js,jsx,ts,tsx}\" --max-warnings 0",
|
|
17
|
+
"lint-fix": "eslint \"./{src,test}/**/*.{js,jsx,ts,tsx}\" --fix"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@mml-io/networked-dom-web": "^0.
|
|
20
|
+
"@mml-io/networked-dom-web": "^0.7.0"
|
|
20
21
|
},
|
|
21
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "aa75274d1ee99afdb8d5ff7432cb57c23d09186e"
|
|
22
23
|
}
|