j-templates 7.0.94 → 7.0.96

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.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DOMNodeConfig = void 0;
4
- const window_1 = require("./window");
5
4
  const list_1 = require("../Utils/list");
5
+ const scheduling_1 = require("../Utils/scheduling");
6
6
  const createPropertyAssignment_1 = require("./createPropertyAssignment");
7
7
  const createEventAssignment_1 = require("./createEventAssignment");
8
8
  const createAssignment_1 = require("./createAssignment");
@@ -20,7 +20,7 @@ function processUpdates() {
20
20
  updateScheduled = false;
21
21
  else {
22
22
  frameStart = Date.now();
23
- window_1.wndw.requestAnimationFrame(processUpdates);
23
+ (0, scheduling_1._requestAnimationFrame)(processUpdates);
24
24
  }
25
25
  }
26
26
  let highPriority = false;
@@ -33,10 +33,10 @@ function scheduleUpdate(callback) {
33
33
  const now = Date.now();
34
34
  updateScheduled = true;
35
35
  if (now - frameStart < frameTime)
36
- queueMicrotask(processUpdates);
36
+ (0, scheduling_1._queueMicrotask)(processUpdates);
37
37
  else {
38
38
  frameStart = now;
39
- window_1.wndw.requestAnimationFrame(processUpdates);
39
+ (0, scheduling_1._requestAnimationFrame)(processUpdates);
40
40
  }
41
41
  }
42
42
  }
@@ -60,14 +60,12 @@ function getHTMLNode(from, current) {
60
60
  }
61
61
  exports.DOMNodeConfig = {
62
62
  createNode(type, namespace) {
63
- if (type === "text")
64
- return window_1.wndw.document.createTextNode("");
65
63
  return namespace
66
- ? window_1.wndw.document.createElementNS(namespace, type)
67
- : window_1.wndw.document.createElement(type);
64
+ ? document.createElementNS(namespace, type)
65
+ : document.createElement(type);
68
66
  },
69
67
  createTextNode(value = "") {
70
- return window_1.wndw.document.createTextNode(value);
68
+ return document.createTextNode(value);
71
69
  },
72
70
  isTextNode(target) {
73
71
  return target?.nodeType === Node.TEXT_NODE;
@@ -196,5 +194,38 @@ exports.DOMNodeConfig = {
196
194
  }
197
195
  while (target.lastChild !== lastChild)
198
196
  target.removeChild(target.lastChild);
197
+ },
198
+ // start is exclusive (null for beginning), end is also exclusive (null for end)
199
+ reconcileRange(target, start, end, children) {
200
+ if ((start && start.parentNode !== target) || (end && end.parentNode !== target))
201
+ throw new Error("Can't reconcile range against elements that are not children of the provided parent");
202
+ if (start && end && start === end)
203
+ throw new Error("Can't reconcile zero element range. Provided elements are equal.");
204
+ let currentChild = (start?.nextSibling ?? target.firstChild);
205
+ let inNextChildren = false;
206
+ for (let x = 0; x < children.length; x++) {
207
+ const nextAddedChild = getHTMLNode(children[x], currentChild);
208
+ if (!currentChild)
209
+ target.appendChild(nextAddedChild);
210
+ else if (currentChild === end)
211
+ target.insertBefore(nextAddedChild, currentChild);
212
+ else if (nextAddedChild !== currentChild) {
213
+ while (currentChild && currentChild !== end && (!(inNextChildren = inNextChildren || children.indexOf(currentChild, x + 1) >= 0))) {
214
+ const toRemove = currentChild;
215
+ currentChild = currentChild.nextSibling;
216
+ target.removeChild(toRemove);
217
+ }
218
+ nextAddedChild !== currentChild &&
219
+ target.insertBefore(nextAddedChild, currentChild);
220
+ }
221
+ else
222
+ inNextChildren = false;
223
+ currentChild = nextAddedChild.nextSibling;
224
+ }
225
+ while (currentChild !== end) {
226
+ const toRemove = currentChild;
227
+ currentChild = currentChild.nextSibling;
228
+ target.removeChild(toRemove);
229
+ }
199
230
  }
200
231
  };