turbo-rails 2.0.22 → 2.0.23

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: f5b83031bb1776152dde8633fce224fdc61fecb18ca74ac772d4f38500ce3fbe
4
- data.tar.gz: 3c22639a83250b6fdb679caa7304b6944e51a5aa85ebe5070d7e5dc10ab1bd81
3
+ metadata.gz: 7fa7bf2e6c2c50efa712150fffb94b7ce0c868c46766e2eefce28102249947ec
4
+ data.tar.gz: b594c86cf49a039f6c7f1cf826f446dfdf71305260f3294b0b87acf9a292d485
5
5
  SHA512:
6
- metadata.gz: 7c6e0a08203063e9be771b3d9ae4750f6d4507b45b30333b07f55795d352a5a1eac575589480b0537008f2e46228c3a353e6ceebf74297dedc4527368631fa62
7
- data.tar.gz: 4a81e1866743fe9cc99132374a0dfb6d972114c205e47a16be6fa45bcc0bcac3793a38fed3e608d2ae0adcfa79b502389be1c227fef647a97d24972b4265d295
6
+ metadata.gz: 62fb3c56ba02c3d62893326fc2d30303e0aa5aeec9b2fbdd7c9490197680c31bfb922920019086053d53b6948e4aa7972b29ae486d1a29db2ad4f03a2fd72ace
7
+ data.tar.gz: 4f7813b54b50c76ad4918f905781d8e63b63bf706fe236bd2fb66f5593179391eca2b29d899c8c9094de29cbdd4fdaaf26d5e0bd0331363fc5df9a21bd57b2c3
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Turbo 8.0.21
2
+ Turbo 8.0.23
3
3
  Copyright © 2026 37signals LLC
4
4
  */
5
5
  const FrameLoadingStyle = {
@@ -1720,12 +1720,8 @@ 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);
1726
1723
  morphChildren(ctx, oldParent, newNode, oldNode, oldNode.nextSibling);
1727
- childNodes = Array.from(oldParent.childNodes);
1728
- return childNodes.slice(index, childNodes.length - rightMargin);
1724
+ return Array.from(oldParent.childNodes);
1729
1725
  }
1730
1726
  function saveAndRestoreFocus(ctx, fn) {
1731
1727
  if (!ctx.config.restoreFocus) return fn();
@@ -1735,8 +1731,8 @@ var Idiomorph = function() {
1735
1731
  }
1736
1732
  const {id: activeElementId, selectionStart: selectionStart, selectionEnd: selectionEnd} = activeElement;
1737
1733
  const results = fn();
1738
- if (activeElementId && activeElementId !== document.activeElement?.id) {
1739
- activeElement = ctx.target.querySelector(`#${activeElementId}`);
1734
+ if (activeElementId && activeElementId !== document.activeElement?.getAttribute("id")) {
1735
+ activeElement = ctx.target.querySelector(`[id="${activeElementId}"]`);
1740
1736
  activeElement?.focus();
1741
1737
  }
1742
1738
  if (activeElement && !activeElement.selectionEnd && selectionEnd) {
@@ -1763,11 +1759,14 @@ var Idiomorph = function() {
1763
1759
  continue;
1764
1760
  }
1765
1761
  }
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;
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
+ }
1771
1770
  }
1772
1771
  const insertedNode = createNode(oldParent, newChild, insertionPoint, ctx);
1773
1772
  if (insertedNode) {
@@ -1819,7 +1818,7 @@ var Idiomorph = function() {
1819
1818
  softMatch = undefined;
1820
1819
  }
1821
1820
  }
1822
- if (cursor.contains(document.activeElement)) break;
1821
+ if (ctx.activeElementAndParents.includes(cursor)) break;
1823
1822
  cursor = cursor.nextSibling;
1824
1823
  }
1825
1824
  return softMatch || null;
@@ -1838,7 +1837,7 @@ var Idiomorph = function() {
1838
1837
  function isSoftMatch(oldNode, newNode) {
1839
1838
  const oldElt = oldNode;
1840
1839
  const newElt = newNode;
1841
- return oldElt.nodeType === newElt.nodeType && oldElt.tagName === newElt.tagName && (!oldElt.id || oldElt.id === newElt.id);
1840
+ return oldElt.nodeType === newElt.nodeType && oldElt.tagName === newElt.tagName && (!oldElt.getAttribute?.("id") || oldElt.getAttribute?.("id") === newElt.getAttribute?.("id"));
1842
1841
  }
1843
1842
  return findBestMatch;
1844
1843
  }();
@@ -1861,13 +1860,13 @@ var Idiomorph = function() {
1861
1860
  return cursor;
1862
1861
  }
1863
1862
  function moveBeforeById(parentNode, id, after, ctx) {
1864
- const target = ctx.target.querySelector(`#${id}`) || ctx.pantry.querySelector(`#${id}`);
1863
+ const target = ctx.target.getAttribute?.("id") === id && ctx.target || ctx.target.querySelector(`[id="${id}"]`) || ctx.pantry.querySelector(`[id="${id}"]`);
1865
1864
  removeElementFromAncestorsIdMaps(target, ctx);
1866
1865
  moveBefore(parentNode, target, after);
1867
1866
  return target;
1868
1867
  }
1869
1868
  function removeElementFromAncestorsIdMaps(element, ctx) {
1870
- const id = element.id;
1869
+ const id = element.getAttribute("id");
1871
1870
  while (element = element.parentNode) {
1872
1871
  let idSet = ctx.idMap.get(element);
1873
1872
  if (idSet) {
@@ -2111,6 +2110,7 @@ var Idiomorph = function() {
2111
2110
  idMap: idMap,
2112
2111
  persistentIds: persistentIds,
2113
2112
  pantry: createPantry(),
2113
+ activeElementAndParents: createActiveElementAndParents(oldNode),
2114
2114
  callbacks: mergedConfig.callbacks,
2115
2115
  head: mergedConfig.head
2116
2116
  };
@@ -2128,16 +2128,29 @@ 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
+ }
2131
2143
  function findIdElements(root) {
2132
2144
  let elements = Array.from(root.querySelectorAll("[id]"));
2133
- if (root.id) {
2145
+ if (root.getAttribute?.("id")) {
2134
2146
  elements.push(root);
2135
2147
  }
2136
2148
  return elements;
2137
2149
  }
2138
2150
  function populateIdMapWithTree(idMap, persistentIds, root, elements) {
2139
2151
  for (const elt of elements) {
2140
- if (persistentIds.has(elt.id)) {
2152
+ const id = elt.getAttribute("id");
2153
+ if (persistentIds.has(id)) {
2141
2154
  let current = elt;
2142
2155
  while (current) {
2143
2156
  let idSet = idMap.get(current);
@@ -2145,7 +2158,7 @@ var Idiomorph = function() {
2145
2158
  idSet = new Set;
2146
2159
  idMap.set(current, idSet);
2147
2160
  }
2148
- idSet.add(elt.id);
2161
+ idSet.add(id);
2149
2162
  if (current === root) break;
2150
2163
  current = current.parentElement;
2151
2164
  }
@@ -2208,7 +2221,7 @@ var Idiomorph = function() {
2208
2221
  return newContent;
2209
2222
  } else if (newContent instanceof Node) {
2210
2223
  if (newContent.parentNode) {
2211
- return createDuckTypedParent(newContent);
2224
+ return new SlicedParentNode(newContent);
2212
2225
  } else {
2213
2226
  const dummyParent = document.createElement("div");
2214
2227
  dummyParent.append(newContent);
@@ -2222,19 +2235,43 @@ var Idiomorph = function() {
2222
2235
  return dummyParent;
2223
2236
  }
2224
2237
  }
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;
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;
2236
2251
  }
2237
- };
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
+ }
2238
2275
  }
2239
2276
  function parseContent(newContent) {
2240
2277
  let parser = new DOMParser;