turbo-rails 2.0.21 → 2.0.22

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35c2f2b4e9e10ca705b4ba5294fab88d57f9ef78e88961dcea20a28824258eb8
4
- data.tar.gz: 6d7ef38ba52b7520ac7a5b1020692f6c9b5a70946a77f0c82428a9392b3cd8d8
3
+ metadata.gz: f5b83031bb1776152dde8633fce224fdc61fecb18ca74ac772d4f38500ce3fbe
4
+ data.tar.gz: 3c22639a83250b6fdb679caa7304b6944e51a5aa85ebe5070d7e5dc10ab1bd81
5
5
  SHA512:
6
- metadata.gz: 20c414ac9121695be8dfac0ef2810483334ed76bb3d24b038f326c68a482c37b3b909d37350e6bea86c3cd1994070ba98cc984710f4697584dd9b00150aded16
7
- data.tar.gz: 85a292e90682c870097ab2b95787be27a93c55207710ec03d4340e64cfb67b8ad29804957c652e6da02c6566d6d135585e3c1a07156df10b0aca31fdfe1a1052
6
+ metadata.gz: 7c6e0a08203063e9be771b3d9ae4750f6d4507b45b30333b07f55795d352a5a1eac575589480b0537008f2e46228c3a353e6ceebf74297dedc4527368631fa62
7
+ data.tar.gz: 4a81e1866743fe9cc99132374a0dfb6d972114c205e47a16be6fa45bcc0bcac3793a38fed3e608d2ae0adcfa79b502389be1c227fef647a97d24972b4265d295
@@ -1720,8 +1720,12 @@ var Idiomorph = function() {
1720
1720
  }
1721
1721
  function morphOuterHTML(ctx, oldNode, newNode) {
1722
1722
  const oldParent = normalizeParent(oldNode);
1723
+ let childNodes = Array.from(oldParent.childNodes);
1724
+ const index = childNodes.indexOf(oldNode);
1725
+ const rightMargin = childNodes.length - (index + 1);
1723
1726
  morphChildren(ctx, oldParent, newNode, oldNode, oldNode.nextSibling);
1724
- return Array.from(oldParent.childNodes);
1727
+ childNodes = Array.from(oldParent.childNodes);
1728
+ return childNodes.slice(index, childNodes.length - rightMargin);
1725
1729
  }
1726
1730
  function saveAndRestoreFocus(ctx, fn) {
1727
1731
  if (!ctx.config.restoreFocus) return fn();
@@ -1731,8 +1735,8 @@ var Idiomorph = function() {
1731
1735
  }
1732
1736
  const {id: activeElementId, selectionStart: selectionStart, selectionEnd: selectionEnd} = activeElement;
1733
1737
  const results = fn();
1734
- if (activeElementId && activeElementId !== document.activeElement?.getAttribute("id")) {
1735
- activeElement = ctx.target.querySelector(`[id="${activeElementId}"]`);
1738
+ if (activeElementId && activeElementId !== document.activeElement?.id) {
1739
+ activeElement = ctx.target.querySelector(`#${activeElementId}`);
1736
1740
  activeElement?.focus();
1737
1741
  }
1738
1742
  if (activeElement && !activeElement.selectionEnd && selectionEnd) {
@@ -1759,14 +1763,11 @@ var Idiomorph = function() {
1759
1763
  continue;
1760
1764
  }
1761
1765
  }
1762
- if (newChild instanceof Element) {
1763
- const newChildId = newChild.getAttribute("id");
1764
- if (ctx.persistentIds.has(newChildId)) {
1765
- const movedChild = moveBeforeById(oldParent, newChildId, insertionPoint, ctx);
1766
- morphNode(movedChild, newChild, ctx);
1767
- insertionPoint = movedChild.nextSibling;
1768
- continue;
1769
- }
1766
+ if (newChild instanceof Element && ctx.persistentIds.has(newChild.id)) {
1767
+ const movedChild = moveBeforeById(oldParent, newChild.id, insertionPoint, ctx);
1768
+ morphNode(movedChild, newChild, ctx);
1769
+ insertionPoint = movedChild.nextSibling;
1770
+ continue;
1770
1771
  }
1771
1772
  const insertedNode = createNode(oldParent, newChild, insertionPoint, ctx);
1772
1773
  if (insertedNode) {
@@ -1818,7 +1819,7 @@ var Idiomorph = function() {
1818
1819
  softMatch = undefined;
1819
1820
  }
1820
1821
  }
1821
- if (ctx.activeElementAndParents.includes(cursor)) break;
1822
+ if (cursor.contains(document.activeElement)) break;
1822
1823
  cursor = cursor.nextSibling;
1823
1824
  }
1824
1825
  return softMatch || null;
@@ -1837,7 +1838,7 @@ var Idiomorph = function() {
1837
1838
  function isSoftMatch(oldNode, newNode) {
1838
1839
  const oldElt = oldNode;
1839
1840
  const newElt = newNode;
1840
- return oldElt.nodeType === newElt.nodeType && oldElt.tagName === newElt.tagName && (!oldElt.getAttribute?.("id") || oldElt.getAttribute?.("id") === newElt.getAttribute?.("id"));
1841
+ return oldElt.nodeType === newElt.nodeType && oldElt.tagName === newElt.tagName && (!oldElt.id || oldElt.id === newElt.id);
1841
1842
  }
1842
1843
  return findBestMatch;
1843
1844
  }();
@@ -1860,13 +1861,13 @@ var Idiomorph = function() {
1860
1861
  return cursor;
1861
1862
  }
1862
1863
  function moveBeforeById(parentNode, id, after, ctx) {
1863
- const target = ctx.target.getAttribute?.("id") === id && ctx.target || ctx.target.querySelector(`[id="${id}"]`) || ctx.pantry.querySelector(`[id="${id}"]`);
1864
+ const target = ctx.target.querySelector(`#${id}`) || ctx.pantry.querySelector(`#${id}`);
1864
1865
  removeElementFromAncestorsIdMaps(target, ctx);
1865
1866
  moveBefore(parentNode, target, after);
1866
1867
  return target;
1867
1868
  }
1868
1869
  function removeElementFromAncestorsIdMaps(element, ctx) {
1869
- const id = element.getAttribute("id");
1870
+ const id = element.id;
1870
1871
  while (element = element.parentNode) {
1871
1872
  let idSet = ctx.idMap.get(element);
1872
1873
  if (idSet) {
@@ -2110,7 +2111,6 @@ var Idiomorph = function() {
2110
2111
  idMap: idMap,
2111
2112
  persistentIds: persistentIds,
2112
2113
  pantry: createPantry(),
2113
- activeElementAndParents: createActiveElementAndParents(oldNode),
2114
2114
  callbacks: mergedConfig.callbacks,
2115
2115
  head: mergedConfig.head
2116
2116
  };
@@ -2128,29 +2128,16 @@ var Idiomorph = function() {
2128
2128
  document.body.insertAdjacentElement("afterend", pantry);
2129
2129
  return pantry;
2130
2130
  }
2131
- function createActiveElementAndParents(oldNode) {
2132
- let activeElementAndParents = [];
2133
- let elt = document.activeElement;
2134
- if (elt?.tagName !== "BODY" && oldNode.contains(elt)) {
2135
- while (elt) {
2136
- activeElementAndParents.push(elt);
2137
- if (elt === oldNode) break;
2138
- elt = elt.parentElement;
2139
- }
2140
- }
2141
- return activeElementAndParents;
2142
- }
2143
2131
  function findIdElements(root) {
2144
2132
  let elements = Array.from(root.querySelectorAll("[id]"));
2145
- if (root.getAttribute?.("id")) {
2133
+ if (root.id) {
2146
2134
  elements.push(root);
2147
2135
  }
2148
2136
  return elements;
2149
2137
  }
2150
2138
  function populateIdMapWithTree(idMap, persistentIds, root, elements) {
2151
2139
  for (const elt of elements) {
2152
- const id = elt.getAttribute("id");
2153
- if (persistentIds.has(id)) {
2140
+ if (persistentIds.has(elt.id)) {
2154
2141
  let current = elt;
2155
2142
  while (current) {
2156
2143
  let idSet = idMap.get(current);
@@ -2158,7 +2145,7 @@ var Idiomorph = function() {
2158
2145
  idSet = new Set;
2159
2146
  idMap.set(current, idSet);
2160
2147
  }
2161
- idSet.add(id);
2148
+ idSet.add(elt.id);
2162
2149
  if (current === root) break;
2163
2150
  current = current.parentElement;
2164
2151
  }
@@ -2221,7 +2208,7 @@ var Idiomorph = function() {
2221
2208
  return newContent;
2222
2209
  } else if (newContent instanceof Node) {
2223
2210
  if (newContent.parentNode) {
2224
- return new SlicedParentNode(newContent);
2211
+ return createDuckTypedParent(newContent);
2225
2212
  } else {
2226
2213
  const dummyParent = document.createElement("div");
2227
2214
  dummyParent.append(newContent);
@@ -2235,43 +2222,19 @@ var Idiomorph = function() {
2235
2222
  return dummyParent;
2236
2223
  }
2237
2224
  }
2238
- class SlicedParentNode {
2239
- constructor(node) {
2240
- this.originalNode = node;
2241
- this.realParentNode = node.parentNode;
2242
- this.previousSibling = node.previousSibling;
2243
- this.nextSibling = node.nextSibling;
2244
- }
2245
- get childNodes() {
2246
- const nodes = [];
2247
- let cursor = this.previousSibling ? this.previousSibling.nextSibling : this.realParentNode.firstChild;
2248
- while (cursor && cursor != this.nextSibling) {
2249
- nodes.push(cursor);
2250
- cursor = cursor.nextSibling;
2225
+ function createDuckTypedParent(newContent) {
2226
+ return {
2227
+ childNodes: [ newContent ],
2228
+ querySelectorAll: s => {
2229
+ const elements = newContent.querySelectorAll(s);
2230
+ return newContent.matches(s) ? [ newContent, ...elements ] : elements;
2231
+ },
2232
+ insertBefore: (n, r) => newContent.parentNode.insertBefore(n, r),
2233
+ moveBefore: (n, r) => newContent.parentNode.moveBefore(n, r),
2234
+ get __idiomorphRoot() {
2235
+ return newContent;
2251
2236
  }
2252
- return nodes;
2253
- }
2254
- querySelectorAll(selector) {
2255
- return this.childNodes.reduce(((results, node) => {
2256
- if (node instanceof Element) {
2257
- if (node.matches(selector)) results.push(node);
2258
- const nodeList = node.querySelectorAll(selector);
2259
- for (let i = 0; i < nodeList.length; i++) {
2260
- results.push(nodeList[i]);
2261
- }
2262
- }
2263
- return results;
2264
- }), []);
2265
- }
2266
- insertBefore(node, referenceNode) {
2267
- return this.realParentNode.insertBefore(node, referenceNode);
2268
- }
2269
- moveBefore(node, referenceNode) {
2270
- return this.realParentNode.moveBefore(node, referenceNode);
2271
- }
2272
- get __idiomorphRoot() {
2273
- return this.originalNode;
2274
- }
2237
+ };
2275
2238
  }
2276
2239
  function parseContent(newContent) {
2277
2240
  let parser = new DOMParser;
@@ -4565,7 +4528,7 @@ const deprecatedLocationPropertyDescriptors = {
4565
4528
 
4566
4529
  const session = new Session(recentRequests);
4567
4530
 
4568
- const {cache: cache, navigator: navigator} = session;
4531
+ const {cache: cache, navigator: sessionNavigator} = session;
4569
4532
 
4570
4533
  function start() {
4571
4534
  session.start();
@@ -4616,14 +4579,14 @@ function morphTurboFrameElements(currentFrame, newFrame) {
4616
4579
 
4617
4580
  var Turbo = Object.freeze({
4618
4581
  __proto__: null,
4619
- navigator: navigator,
4620
- session: session,
4621
- cache: cache,
4622
4582
  PageRenderer: PageRenderer,
4623
4583
  PageSnapshot: PageSnapshot,
4624
4584
  FrameRenderer: FrameRenderer,
4625
4585
  fetch: fetchWithTurboHeaders,
4626
4586
  config: config,
4587
+ session: session,
4588
+ cache: cache,
4589
+ navigator: sessionNavigator,
4627
4590
  start: start,
4628
4591
  registerAdapter: registerAdapter,
4629
4592
  visit: visit,
@@ -5365,7 +5328,7 @@ var Turbo$1 = Object.freeze({
5365
5328
  morphChildren: morphChildren,
5366
5329
  morphElements: morphElements,
5367
5330
  morphTurboFrameElements: morphTurboFrameElements,
5368
- navigator: navigator,
5331
+ navigator: sessionNavigator,
5369
5332
  registerAdapter: registerAdapter,
5370
5333
  renderStreamMessage: renderStreamMessage,
5371
5334
  session: session,