@solidjs/web 2.0.0-rc.3 → 2.0.0-rc.4

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/dist/web.cjs CHANGED
@@ -333,6 +333,10 @@ const waitAsset = promise => {
333
333
  }
334
334
  gate();
335
335
  };
336
+ exports.listDriver = void 0;
337
+ function installListDriver(driver) {
338
+ exports.listDriver = driver;
339
+ }
336
340
  const $$EVENT_OWNER = "_$SOLID_EVENT_OWNER";
337
341
  const INNER_OWNED = {};
338
342
  const delegatedEvents = new Set();
@@ -608,11 +612,6 @@ function ref(fn, element) {
608
612
  const resolved = solidJs.untrack(fn);
609
613
  solidJs.runWithOwner(null, () => applyRef(resolved, element));
610
614
  }
611
- const PURE_ROW = Symbol.for("solid.pure-row");
612
- function rowProof(fn) {
613
- fn[PURE_ROW] = true;
614
- return fn;
615
- }
616
615
  function scope(fn) {
617
616
  fn.$s = true;
618
617
  return fn;
@@ -676,16 +675,16 @@ function stripTextSeparators(nodes) {
676
675
  nodes.length = j;
677
676
  return nodes;
678
677
  }
679
- function patchDriver(subject, body) {
680
- {
681
- effect(() => body(subject, subject, false), () => body(subject, undefined, true));
682
- }
683
- }
684
678
  function insert(parent, accessor, marker, initial, options) {
685
679
  const multi = marker !== undefined;
686
680
  const host = options && options.host;
687
681
  if (multi && !initial) initial = [];
688
682
  if (hydrationRt !== null) initial = hydrationRt.claimInitial(parent, multi, initial);
683
+ if (exports.listDriver !== undefined && typeof accessor === "function" && accessor.$ll !== undefined) {
684
+ const listAccessor = accessor;
685
+ const owner = solidJs.getOwner();
686
+ if (exports.listDriver(parent, accessor, marker, () => solidJs.runWithOwner(owner, () => insert(parent, () => listAccessor(), marker, marker !== undefined ? [] : undefined, options)))) return;
687
+ }
689
688
  if (typeof accessor !== "function") {
690
689
  accessor = normalize(accessor, initial, multi, true);
691
690
  if (typeof accessor !== "function") {
@@ -1161,6 +1160,15 @@ function hydrate(code, element, options = {}) {
1161
1160
  solidJs.enableHydration();
1162
1161
  installHydrationRuntime();
1163
1162
  if (globalThis._$HY.done) return render(code, element, [...element.childNodes], options);
1163
+ const head = (element.nodeType === 9 ? element : element.ownerDocument).head;
1164
+ if (head && element.contains(head)) {
1165
+ let n = head.firstChild;
1166
+ while (n && n.nodeType === 1 && n.hasAttribute("data-dh") && !n.hasAttribute("data-dhf")) {
1167
+ const next = n.nextSibling;
1168
+ head.appendChild(n);
1169
+ n = next;
1170
+ }
1171
+ }
1164
1172
  options.renderId ||= "";
1165
1173
  if (!globalThis._$HY.modules) globalThis._$HY.modules = {};
1166
1174
  if (!globalThis._$HY.loading) globalThis._$HY.loading = {};
@@ -1619,6 +1627,322 @@ function getHydrationKey() {
1619
1627
  }
1620
1628
  const RequestContext = Symbol();
1621
1629
 
1630
+ const PURE_ROW = Symbol.for("solid.pure-row");
1631
+ const arm = () => {
1632
+ installListDriver(driveList);
1633
+ };
1634
+ function rowProof(fn) {
1635
+ arm();
1636
+ fn[PURE_ROW] = true;
1637
+ return fn;
1638
+ }
1639
+ let rowCollector = null;
1640
+ const lisPositions = sources => {
1641
+ const n = sources.length;
1642
+ const tails = [];
1643
+ const tailsIdx = [];
1644
+ const prev = new Array(n).fill(-1);
1645
+ for (let j = 0; j < n; j++) {
1646
+ const v = sources[j];
1647
+ if (v === -1) continue;
1648
+ let lo = 0,
1649
+ hi = tails.length;
1650
+ while (lo < hi) {
1651
+ const mid = lo + hi >> 1;
1652
+ if (tails[mid] < v) lo = mid + 1;else hi = mid;
1653
+ }
1654
+ if (lo > 0) prev[j] = tailsIdx[lo - 1];
1655
+ tails[lo] = v;
1656
+ tailsIdx[lo] = j;
1657
+ }
1658
+ const stable = new Set();
1659
+ let k = tailsIdx.length ? tailsIdx[tails.length - 1] : -1;
1660
+ while (k >= 0) {
1661
+ stable.add(k);
1662
+ k = prev[k];
1663
+ }
1664
+ return stable;
1665
+ };
1666
+ const driveList = (parent, listFn, marker, lateClassic) => {
1667
+ const meta = listFn.$ll;
1668
+ if (meta.row?.[PURE_ROW] !== true) return false;
1669
+ if (typeof meta.keyed === "function") return false;
1670
+ const evalOwner = solidJs.createOwner({
1671
+ id: "&each"
1672
+ });
1673
+ let subject = solidJs.runWithOwner(evalOwner, () => solidJs.untrack(meta.each));
1674
+ evalOwner.dispose();
1675
+ let raw = subject != null ? solidJs.patchableRaw(subject) : undefined;
1676
+ if (raw === undefined || !Array.isArray(raw)) return false;
1677
+ const optimistic = solidJs.storeHasOptimisticFamily(subject);
1678
+ if (optimistic) raw = solidJs.untrack(() => Array.from(subject));
1679
+ const hydrating = !!solidJs.sharedConfig.hydrating;
1680
+ if (hydrating && raw.length === 0) return false;
1681
+ let domRows;
1682
+ let rowIds;
1683
+ if (hydrating) {
1684
+ if (marker !== undefined) return false;
1685
+ domRows = Array.from(parent.children);
1686
+ if (domRows.length !== raw.length) return false;
1687
+ rowIds = new Array(raw.length);
1688
+ for (let i = 0; i < domRows.length; i++) {
1689
+ const key = domRows[i].getAttribute("_hk");
1690
+ if (key === null || !key.endsWith("0") || key.length < 2) return false;
1691
+ rowIds[i] = key.slice(0, -1);
1692
+ }
1693
+ }
1694
+ const rowFn = meta.row;
1695
+ const endAnchor = marker ?? null;
1696
+ const shallow = solidJs.storeIsShallow(subject);
1697
+ let lastBodies = null;
1698
+ let lastUnbinds = null;
1699
+ const collectBind = (abs, build) => {
1700
+ const prevC = rowCollector;
1701
+ rowCollector = {
1702
+ row: shallow ? subject[abs] : undefined,
1703
+ bodies: [],
1704
+ unbinds: []
1705
+ };
1706
+ try {
1707
+ return build();
1708
+ } finally {
1709
+ lastBodies = rowCollector.bodies;
1710
+ lastUnbinds = rowCollector.unbinds;
1711
+ rowCollector = prevC;
1712
+ }
1713
+ };
1714
+ const listOwner = solidJs.createOwner();
1715
+ let declined = false;
1716
+ const bindRow = (abs, claimId) => {
1717
+ return collectBind(abs, () => solidJs.runWithOwner(listOwner, () => claimId !== undefined ? solidJs.runWithOwner(solidJs.createOwner({
1718
+ id: claimId
1719
+ }), () => solidJs.untrack(() => rowFn(subject[abs]))) : solidJs.untrack(() => rowFn(subject[abs]))));
1720
+ };
1721
+ let entries = new Array(raw.length);
1722
+ let rowBodies = shallow ? new Array(raw.length) : null;
1723
+ let rowUnbinds = new Array(raw.length);
1724
+ const runUnbinds = list => {
1725
+ if (list !== undefined) for (let u = 0; u < list.length; u++) list[u]();
1726
+ };
1727
+ const unbindAllRows = () => {
1728
+ for (let j = 0; j < rowUnbinds.length; j++) runUnbinds(rowUnbinds[j]);
1729
+ rowUnbinds = [];
1730
+ };
1731
+ let prevRaws = raw.slice();
1732
+ try {
1733
+ if (hydrating) {
1734
+ for (let i = 0; i < raw.length; i++) {
1735
+ entries[i] = bindRow(i, rowIds[i]);
1736
+ if (rowBodies !== null) rowBodies[i] = lastBodies;
1737
+ rowUnbinds[i] = lastUnbinds;
1738
+ }
1739
+ } else {
1740
+ for (let i = 0; i < raw.length; i++) {
1741
+ const node = bindRow(i);
1742
+ entries[i] = node;
1743
+ if (rowBodies !== null) rowBodies[i] = lastBodies;
1744
+ rowUnbinds[i] = lastUnbinds;
1745
+ parent.insertBefore(node, endAnchor);
1746
+ }
1747
+ }
1748
+ } catch (err) {
1749
+ unbindAllRows();
1750
+ runUnbinds(lastUnbinds ?? undefined);
1751
+ for (let j = 0; j < entries.length; j++) {
1752
+ const n = entries[j];
1753
+ if (n !== undefined && n.parentNode === parent) n.remove();
1754
+ }
1755
+ listOwner.dispose();
1756
+ throw err;
1757
+ }
1758
+ const identityOps = nextArr => {
1759
+ const keyOf = r => {
1760
+ const w = r != null ? solidJs.patchableRaw(r) : undefined;
1761
+ return w !== undefined ? w : r;
1762
+ };
1763
+ const oldIndex = new Map();
1764
+ for (let j = 0; j < prevRaws.length; j++) {
1765
+ const k = keyOf(prevRaws[j]);
1766
+ const existing = oldIndex.get(k);
1767
+ if (existing === undefined) oldIndex.set(k, j);else if (Array.isArray(existing)) existing.push(j);else oldIndex.set(k, [existing, j]);
1768
+ }
1769
+ const sources = new Array(nextArr.length);
1770
+ for (let k = 0; k < nextArr.length; k++) {
1771
+ const m = oldIndex.get(keyOf(nextArr[k]));
1772
+ if (m === undefined) sources[k] = -1;else if (Array.isArray(m)) {
1773
+ sources[k] = m.shift();
1774
+ if (m.length === 1) oldIndex.set(keyOf(nextArr[k]), m[0]);
1775
+ } else {
1776
+ sources[k] = m;
1777
+ oldIndex.delete(keyOf(nextArr[k]));
1778
+ }
1779
+ }
1780
+ return {
1781
+ prefix: 0,
1782
+ sources
1783
+ };
1784
+ };
1785
+ let resyncNeeded = false;
1786
+ const applyOps = (next, ops) => {
1787
+ if (declined) return;
1788
+ if (resyncNeeded) ops = null;
1789
+ if (ops === null) ops = identityOps(next);
1790
+ const {
1791
+ prefix,
1792
+ sources
1793
+ } = ops;
1794
+ const built = new Array(sources.length);
1795
+ const builtBodies = rowBodies !== null ? new Array(sources.length) : null;
1796
+ const builtUnbinds = new Array(sources.length);
1797
+ let j = 0;
1798
+ try {
1799
+ for (; j < sources.length; j++) {
1800
+ const abs = prefix + j;
1801
+ const src = sources[j];
1802
+ if (src === -1 || refRebuild && src >= 0 && next[abs] !== prevRaws[src]) {
1803
+ built[j] = bindRow(abs);
1804
+ if (builtBodies !== null) builtBodies[j] = lastBodies;
1805
+ builtUnbinds[j] = lastUnbinds;
1806
+ }
1807
+ }
1808
+ } catch (err) {
1809
+ for (let k = 0; k < j; k++) runUnbinds(builtUnbinds[k]);
1810
+ runUnbinds(lastUnbinds ?? undefined);
1811
+ resyncNeeded = true;
1812
+ throw err;
1813
+ }
1814
+ const retained = new Set();
1815
+ for (let k = 0; k < sources.length; k++) {
1816
+ if (sources[k] >= 0 && built[k] === undefined) retained.add(sources[k]);
1817
+ }
1818
+ for (let k = prefix; k < entries.length; k++) {
1819
+ if (!retained.has(k)) {
1820
+ entries[k].remove();
1821
+ runUnbinds(rowUnbinds[k]);
1822
+ }
1823
+ }
1824
+ const newEntries = new Array(prefix + sources.length);
1825
+ const newBodies = rowBodies !== null ? new Array(prefix + sources.length) : null;
1826
+ const newUnbinds = new Array(prefix + sources.length);
1827
+ for (let i = 0; i < prefix; i++) {
1828
+ newEntries[i] = entries[i];
1829
+ if (newBodies !== null) newBodies[i] = rowBodies[i];
1830
+ newUnbinds[i] = rowUnbinds[i];
1831
+ }
1832
+ const stable = lisPositions(sources);
1833
+ let anchor = endAnchor;
1834
+ for (let k = sources.length - 1; k >= 0; k--) {
1835
+ const abs = prefix + k;
1836
+ const src = sources[k];
1837
+ let node;
1838
+ if (built[k] !== undefined) {
1839
+ node = built[k];
1840
+ if (newBodies !== null) newBodies[abs] = builtBodies[k];
1841
+ newUnbinds[abs] = builtUnbinds[k];
1842
+ parent.insertBefore(node, anchor);
1843
+ } else {
1844
+ node = entries[src];
1845
+ if (newBodies !== null) newBodies[abs] = rowBodies[src];
1846
+ newUnbinds[abs] = rowUnbinds[src];
1847
+ if (!stable.has(k)) parent.insertBefore(node, anchor);
1848
+ }
1849
+ newEntries[abs] = node;
1850
+ anchor = node;
1851
+ }
1852
+ entries = newEntries;
1853
+ if (newBodies !== null) rowBodies = newBodies;
1854
+ rowUnbinds = newUnbinds;
1855
+ prevRaws = next.slice();
1856
+ resyncNeeded = false;
1857
+ };
1858
+ let unbindOps = solidJs.runWithOwner(listOwner, () => solidJs.registerRowOps(subject, applyOps));
1859
+ const refRebuild = shallow && typeof meta.keyed !== "function";
1860
+ const rebuildSlot = i => {
1861
+ runUnbinds(rowUnbinds[i]);
1862
+ const old = entries[i];
1863
+ const node = bindRow(i);
1864
+ rowBodies[i] = lastBodies;
1865
+ rowUnbinds[i] = lastUnbinds;
1866
+ parent.insertBefore(node, old);
1867
+ old.remove();
1868
+ entries[i] = node;
1869
+ };
1870
+ const applySlot = (i, next, prev) => {
1871
+ if (declined) return;
1872
+ if (resyncNeeded) {
1873
+ const live = subject != null ? solidJs.patchableRaw(subject) : undefined;
1874
+ if (live !== undefined && Array.isArray(live)) applyOps(live, null);
1875
+ return;
1876
+ }
1877
+ if (refRebuild) {
1878
+ rebuildSlot(i);
1879
+ prevRaws[i] = next;
1880
+ return;
1881
+ }
1882
+ const bodies = rowBodies[i];
1883
+ if (bodies !== undefined) {
1884
+ for (let b = 0; b < bodies.length; b++) bodies[b](next, prev, false);
1885
+ }
1886
+ prevRaws[i] = next;
1887
+ };
1888
+ let unbindSlots = shallow ? solidJs.runWithOwner(listOwner, () => solidJs.registerSlotPatch(subject, applySlot)) : null;
1889
+ solidJs.runWithOwner(listOwner, () => effect(() => meta.each(), value => {
1890
+ if (declined || value === subject) return;
1891
+ const nextRaw = value != null ? solidJs.patchableRaw(value) : undefined;
1892
+ unbindOps();
1893
+ unbindSlots?.();
1894
+ if (nextRaw !== undefined && Array.isArray(nextRaw) && solidJs.storeIsShallow(value) !== shallow) {
1895
+ for (let j = 0; j < entries.length; j++) entries[j].remove();
1896
+ entries = [];
1897
+ prevRaws = [];
1898
+ unbindAllRows();
1899
+ subject = value;
1900
+ declined = true;
1901
+ listOwner.dispose();
1902
+ lateClassic?.();
1903
+ return;
1904
+ }
1905
+ if (nextRaw === undefined || !Array.isArray(nextRaw)) {
1906
+ for (let j = 0; j < entries.length; j++) entries[j].remove();
1907
+ entries = [];
1908
+ prevRaws = [];
1909
+ unbindAllRows();
1910
+ subject = value;
1911
+ declined = true;
1912
+ listOwner.dispose();
1913
+ lateClassic?.();
1914
+ return;
1915
+ }
1916
+ const swapOps = identityOps(nextRaw);
1917
+ subject = value;
1918
+ unbindOps = solidJs.runWithOwner(listOwner, () => solidJs.registerRowOps(subject, applyOps));
1919
+ if (shallow) unbindSlots = solidJs.runWithOwner(listOwner, () => solidJs.registerSlotPatch(subject, applySlot));
1920
+ applyOps(nextRaw, swapOps);
1921
+ }));
1922
+ solidJs.onCleanup(() => {
1923
+ unbindOps();
1924
+ unbindSlots?.();
1925
+ unbindAllRows();
1926
+ listOwner.dispose();
1927
+ });
1928
+ return true;
1929
+ };
1930
+ const patchDriver = (subject, body) => {
1931
+ const raw = solidJs.patchableRaw(subject);
1932
+ if (raw !== undefined) {
1933
+ if (!solidJs.sharedConfig.hydrating) body(raw, undefined, true);
1934
+ const unbind = solidJs.registerPatch(subject, body);
1935
+ if (rowCollector !== null) rowCollector.unbinds.push(unbind);
1936
+ else solidJs.onCleanup(unbind);
1937
+ } else if (rowCollector !== null && subject === rowCollector.row) {
1938
+ rowCollector.bodies.push(body);
1939
+ if (!solidJs.sharedConfig.hydrating) body(subject, undefined, true);
1940
+ } else {
1941
+ effect(() => body(subject, subject, false),
1942
+ () => solidJs.untrack(() => body(subject, undefined, true)));
1943
+ }
1944
+ };
1945
+
1622
1946
  function throwInBrowser(func) {
1623
1947
  const err = new Error(`${func.name} is not supported in the browser, returning undefined`);
1624
1948
  console.error(err);
@@ -1729,7 +2053,8 @@ function redirect(url, init = 302) {
1729
2053
  if (responseInit.status === undefined) {
1730
2054
  responseInit.status = 302;
1731
2055
  }
1732
- headers.set("Location", String(url));
2056
+ const target = typeof url === "string" ? url : url[HREF];
2057
+ headers.set("Location", typeof target === "string" ? target : String(url));
1733
2058
  return new Response(null, {
1734
2059
  ...responseInit,
1735
2060
  headers
@@ -1988,6 +2313,7 @@ exports.createRequestEvent = createRequestEvent;
1988
2313
  exports.createResponseStub = createResponseStub;
1989
2314
  exports.createSSRResponse = createSSRResponse;
1990
2315
  exports.delegateEvents = delegateEvents;
2316
+ exports.driveList = driveList;
1991
2317
  exports.dynamic = dynamic;
1992
2318
  exports.dynamicProperty = dynamicProperty;
1993
2319
  exports.effect = effect;
@@ -2010,6 +2336,7 @@ exports.httpStatus = httpStatus;
2010
2336
  exports.hydrate = hydrate;
2011
2337
  exports.insert = insert;
2012
2338
  exports.installHydrationRuntime = installHydrationRuntime;
2339
+ exports.installListDriver = installListDriver;
2013
2340
  exports.isDev = isDev;
2014
2341
  exports.isHref = isHref;
2015
2342
  exports.isResponseEnvelope = isResponseEnvelope;