@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/dev.cjs CHANGED
@@ -334,6 +334,10 @@ const waitAsset = promise => {
334
334
  }
335
335
  gate();
336
336
  };
337
+ exports.listDriver = void 0;
338
+ function installListDriver(driver) {
339
+ exports.listDriver = driver;
340
+ }
337
341
  const $$EVENT_OWNER = "_$SOLID_EVENT_OWNER";
338
342
  const INNER_OWNED = {};
339
343
  const delegatedEvents = new Set();
@@ -617,11 +621,6 @@ function ref(fn, element) {
617
621
  const resolved = solidJs.untrack(fn);
618
622
  solidJs.runWithOwner(null, () => applyRef(resolved, element));
619
623
  }
620
- const PURE_ROW = Symbol.for("solid.pure-row");
621
- function rowProof(fn) {
622
- fn[PURE_ROW] = true;
623
- return fn;
624
- }
625
624
  function scope(fn) {
626
625
  fn.$s = true;
627
626
  return fn;
@@ -685,16 +684,16 @@ function stripTextSeparators(nodes) {
685
684
  nodes.length = j;
686
685
  return nodes;
687
686
  }
688
- function patchDriver(subject, body) {
689
- {
690
- effect(() => body(subject, subject, false), () => body(subject, undefined, true));
691
- }
692
- }
693
687
  function insert(parent, accessor, marker, initial, options) {
694
688
  const multi = marker !== undefined;
695
689
  const host = options && options.host;
696
690
  if (multi && !initial) initial = [];
697
691
  if (hydrationRt !== null) initial = hydrationRt.claimInitial(parent, multi, initial);
692
+ if (exports.listDriver !== undefined && typeof accessor === "function" && accessor.$ll !== undefined) {
693
+ const listAccessor = accessor;
694
+ const owner = solidJs.getOwner();
695
+ if (exports.listDriver(parent, accessor, marker, () => solidJs.runWithOwner(owner, () => insert(parent, () => listAccessor(), marker, marker !== undefined ? [] : undefined, options)))) return;
696
+ }
698
697
  if (typeof accessor !== "function") {
699
698
  accessor = normalize(accessor, initial, multi, true);
700
699
  if (typeof accessor !== "function") {
@@ -1173,6 +1172,15 @@ function hydrate(code, element, options = {}) {
1173
1172
  solidJs.enableHydration();
1174
1173
  installHydrationRuntime();
1175
1174
  if (globalThis._$HY.done) return render(code, element, [...element.childNodes], options);
1175
+ const head = (element.nodeType === 9 ? element : element.ownerDocument).head;
1176
+ if (head && element.contains(head)) {
1177
+ let n = head.firstChild;
1178
+ while (n && n.nodeType === 1 && n.hasAttribute("data-dh") && !n.hasAttribute("data-dhf")) {
1179
+ const next = n.nextSibling;
1180
+ head.appendChild(n);
1181
+ n = next;
1182
+ }
1183
+ }
1176
1184
  options.renderId ||= "";
1177
1185
  if (!globalThis._$HY.modules) globalThis._$HY.modules = {};
1178
1186
  if (!globalThis._$HY.loading) globalThis._$HY.loading = {};
@@ -1686,6 +1694,331 @@ function getHydrationKey() {
1686
1694
  }
1687
1695
  const RequestContext = Symbol();
1688
1696
 
1697
+ const PURE_ROW = Symbol.for("solid.pure-row");
1698
+ const arm = () => {
1699
+ installListDriver(driveList);
1700
+ };
1701
+ function rowProof(fn) {
1702
+ arm();
1703
+ fn[PURE_ROW] = true;
1704
+ return fn;
1705
+ }
1706
+ let rowCollector = null;
1707
+ const lisPositions = sources => {
1708
+ const n = sources.length;
1709
+ const tails = [];
1710
+ const tailsIdx = [];
1711
+ const prev = new Array(n).fill(-1);
1712
+ for (let j = 0; j < n; j++) {
1713
+ const v = sources[j];
1714
+ if (v === -1) continue;
1715
+ let lo = 0,
1716
+ hi = tails.length;
1717
+ while (lo < hi) {
1718
+ const mid = lo + hi >> 1;
1719
+ if (tails[mid] < v) lo = mid + 1;else hi = mid;
1720
+ }
1721
+ if (lo > 0) prev[j] = tailsIdx[lo - 1];
1722
+ tails[lo] = v;
1723
+ tailsIdx[lo] = j;
1724
+ }
1725
+ const stable = new Set();
1726
+ let k = tailsIdx.length ? tailsIdx[tails.length - 1] : -1;
1727
+ while (k >= 0) {
1728
+ stable.add(k);
1729
+ k = prev[k];
1730
+ }
1731
+ return stable;
1732
+ };
1733
+ const driveList = (parent, listFn, marker, lateClassic) => {
1734
+ const meta = listFn.$ll;
1735
+ if (meta.row?.[PURE_ROW] !== true) return false;
1736
+ if (typeof meta.keyed === "function") return false;
1737
+ const evalOwner = solidJs.createOwner({
1738
+ id: "&each"
1739
+ });
1740
+ let subject = solidJs.runWithOwner(evalOwner, () => solidJs.untrack(meta.each));
1741
+ evalOwner.dispose();
1742
+ let raw = subject != null ? solidJs.patchableRaw(subject) : undefined;
1743
+ if (raw === undefined || !Array.isArray(raw)) return false;
1744
+ const optimistic = solidJs.storeHasOptimisticFamily(subject);
1745
+ if (optimistic) raw = solidJs.untrack(() => Array.from(subject));
1746
+ const hydrating = !!solidJs.sharedConfig.hydrating;
1747
+ if (hydrating && raw.length === 0) return false;
1748
+ let domRows;
1749
+ let rowIds;
1750
+ if (hydrating) {
1751
+ if (marker !== undefined) return false;
1752
+ domRows = Array.from(parent.children);
1753
+ if (domRows.length !== raw.length) return false;
1754
+ rowIds = new Array(raw.length);
1755
+ for (let i = 0; i < domRows.length; i++) {
1756
+ const key = domRows[i].getAttribute("_hk");
1757
+ if (key === null || !key.endsWith("0") || key.length < 2) return false;
1758
+ rowIds[i] = key.slice(0, -1);
1759
+ }
1760
+ }
1761
+ const rowFn = meta.row;
1762
+ const endAnchor = marker ?? null;
1763
+ const shallow = solidJs.storeIsShallow(subject);
1764
+ let lastBodies = null;
1765
+ let lastUnbinds = null;
1766
+ const collectBind = (abs, build) => {
1767
+ const prevC = rowCollector;
1768
+ rowCollector = {
1769
+ row: shallow ? subject[abs] : undefined,
1770
+ bodies: [],
1771
+ unbinds: []
1772
+ };
1773
+ try {
1774
+ return build();
1775
+ } finally {
1776
+ lastBodies = rowCollector.bodies;
1777
+ lastUnbinds = rowCollector.unbinds;
1778
+ rowCollector = prevC;
1779
+ }
1780
+ };
1781
+ const listOwner = solidJs.createOwner();
1782
+ let declined = false;
1783
+ const bindRow = (abs, claimId) => {
1784
+ {
1785
+ const o = listOwner;
1786
+ const prevChild = o._firstChild;
1787
+ const prevDisposal = o._disposal;
1788
+ const node = collectBind(abs, () => solidJs.runWithOwner(listOwner, () => claimId !== undefined ? solidJs.runWithOwner(solidJs.createOwner({
1789
+ id: claimId
1790
+ }), () => solidJs.untrack(() => rowFn(subject[abs]))) : solidJs.untrack(() => rowFn(subject[abs]))));
1791
+ if (o._firstChild !== prevChild || o._disposal !== prevDisposal) {
1792
+ console.warn("A patch-mode list row created reactive computations or cleanups " + "during build (likely a handler/attribute value expression calling " + "createEffect/onCleanup). This work attaches to the LIST, not the " + "row, and will not dispose when the row is removed. Move owned " + "work into effects/refs (which opt the row out of patch mode).");
1793
+ }
1794
+ return node;
1795
+ }
1796
+ };
1797
+ let entries = new Array(raw.length);
1798
+ let rowBodies = shallow ? new Array(raw.length) : null;
1799
+ let rowUnbinds = new Array(raw.length);
1800
+ const runUnbinds = list => {
1801
+ if (list !== undefined) for (let u = 0; u < list.length; u++) list[u]();
1802
+ };
1803
+ const unbindAllRows = () => {
1804
+ for (let j = 0; j < rowUnbinds.length; j++) runUnbinds(rowUnbinds[j]);
1805
+ rowUnbinds = [];
1806
+ };
1807
+ let prevRaws = raw.slice();
1808
+ try {
1809
+ if (hydrating) {
1810
+ for (let i = 0; i < raw.length; i++) {
1811
+ entries[i] = bindRow(i, rowIds[i]);
1812
+ if (rowBodies !== null) rowBodies[i] = lastBodies;
1813
+ rowUnbinds[i] = lastUnbinds;
1814
+ }
1815
+ } else {
1816
+ for (let i = 0; i < raw.length; i++) {
1817
+ const node = bindRow(i);
1818
+ entries[i] = node;
1819
+ if (rowBodies !== null) rowBodies[i] = lastBodies;
1820
+ rowUnbinds[i] = lastUnbinds;
1821
+ parent.insertBefore(node, endAnchor);
1822
+ }
1823
+ }
1824
+ } catch (err) {
1825
+ unbindAllRows();
1826
+ runUnbinds(lastUnbinds ?? undefined);
1827
+ for (let j = 0; j < entries.length; j++) {
1828
+ const n = entries[j];
1829
+ if (n !== undefined && n.parentNode === parent) n.remove();
1830
+ }
1831
+ listOwner.dispose();
1832
+ throw err;
1833
+ }
1834
+ const identityOps = nextArr => {
1835
+ const keyOf = r => {
1836
+ const w = r != null ? solidJs.patchableRaw(r) : undefined;
1837
+ return w !== undefined ? w : r;
1838
+ };
1839
+ const oldIndex = new Map();
1840
+ for (let j = 0; j < prevRaws.length; j++) {
1841
+ const k = keyOf(prevRaws[j]);
1842
+ const existing = oldIndex.get(k);
1843
+ if (existing === undefined) oldIndex.set(k, j);else if (Array.isArray(existing)) existing.push(j);else oldIndex.set(k, [existing, j]);
1844
+ }
1845
+ const sources = new Array(nextArr.length);
1846
+ for (let k = 0; k < nextArr.length; k++) {
1847
+ const m = oldIndex.get(keyOf(nextArr[k]));
1848
+ if (m === undefined) sources[k] = -1;else if (Array.isArray(m)) {
1849
+ sources[k] = m.shift();
1850
+ if (m.length === 1) oldIndex.set(keyOf(nextArr[k]), m[0]);
1851
+ } else {
1852
+ sources[k] = m;
1853
+ oldIndex.delete(keyOf(nextArr[k]));
1854
+ }
1855
+ }
1856
+ return {
1857
+ prefix: 0,
1858
+ sources
1859
+ };
1860
+ };
1861
+ let resyncNeeded = false;
1862
+ const applyOps = (next, ops) => {
1863
+ if (declined) return;
1864
+ if (resyncNeeded) ops = null;
1865
+ if (ops === null) ops = identityOps(next);
1866
+ const {
1867
+ prefix,
1868
+ sources
1869
+ } = ops;
1870
+ const built = new Array(sources.length);
1871
+ const builtBodies = rowBodies !== null ? new Array(sources.length) : null;
1872
+ const builtUnbinds = new Array(sources.length);
1873
+ let j = 0;
1874
+ try {
1875
+ for (; j < sources.length; j++) {
1876
+ const abs = prefix + j;
1877
+ const src = sources[j];
1878
+ if (src === -1 || refRebuild && src >= 0 && next[abs] !== prevRaws[src]) {
1879
+ built[j] = bindRow(abs);
1880
+ if (builtBodies !== null) builtBodies[j] = lastBodies;
1881
+ builtUnbinds[j] = lastUnbinds;
1882
+ }
1883
+ }
1884
+ } catch (err) {
1885
+ for (let k = 0; k < j; k++) runUnbinds(builtUnbinds[k]);
1886
+ runUnbinds(lastUnbinds ?? undefined);
1887
+ resyncNeeded = true;
1888
+ throw err;
1889
+ }
1890
+ const retained = new Set();
1891
+ for (let k = 0; k < sources.length; k++) {
1892
+ if (sources[k] >= 0 && built[k] === undefined) retained.add(sources[k]);
1893
+ }
1894
+ for (let k = prefix; k < entries.length; k++) {
1895
+ if (!retained.has(k)) {
1896
+ entries[k].remove();
1897
+ runUnbinds(rowUnbinds[k]);
1898
+ }
1899
+ }
1900
+ const newEntries = new Array(prefix + sources.length);
1901
+ const newBodies = rowBodies !== null ? new Array(prefix + sources.length) : null;
1902
+ const newUnbinds = new Array(prefix + sources.length);
1903
+ for (let i = 0; i < prefix; i++) {
1904
+ newEntries[i] = entries[i];
1905
+ if (newBodies !== null) newBodies[i] = rowBodies[i];
1906
+ newUnbinds[i] = rowUnbinds[i];
1907
+ }
1908
+ const stable = lisPositions(sources);
1909
+ let anchor = endAnchor;
1910
+ for (let k = sources.length - 1; k >= 0; k--) {
1911
+ const abs = prefix + k;
1912
+ const src = sources[k];
1913
+ let node;
1914
+ if (built[k] !== undefined) {
1915
+ node = built[k];
1916
+ if (newBodies !== null) newBodies[abs] = builtBodies[k];
1917
+ newUnbinds[abs] = builtUnbinds[k];
1918
+ parent.insertBefore(node, anchor);
1919
+ } else {
1920
+ node = entries[src];
1921
+ if (newBodies !== null) newBodies[abs] = rowBodies[src];
1922
+ newUnbinds[abs] = rowUnbinds[src];
1923
+ if (!stable.has(k)) parent.insertBefore(node, anchor);
1924
+ }
1925
+ newEntries[abs] = node;
1926
+ anchor = node;
1927
+ }
1928
+ entries = newEntries;
1929
+ if (newBodies !== null) rowBodies = newBodies;
1930
+ rowUnbinds = newUnbinds;
1931
+ prevRaws = next.slice();
1932
+ resyncNeeded = false;
1933
+ };
1934
+ let unbindOps = solidJs.runWithOwner(listOwner, () => solidJs.registerRowOps(subject, applyOps));
1935
+ const refRebuild = shallow && typeof meta.keyed !== "function";
1936
+ const rebuildSlot = i => {
1937
+ runUnbinds(rowUnbinds[i]);
1938
+ const old = entries[i];
1939
+ const node = bindRow(i);
1940
+ rowBodies[i] = lastBodies;
1941
+ rowUnbinds[i] = lastUnbinds;
1942
+ parent.insertBefore(node, old);
1943
+ old.remove();
1944
+ entries[i] = node;
1945
+ };
1946
+ const applySlot = (i, next, prev) => {
1947
+ if (declined) return;
1948
+ if (resyncNeeded) {
1949
+ const live = subject != null ? solidJs.patchableRaw(subject) : undefined;
1950
+ if (live !== undefined && Array.isArray(live)) applyOps(live, null);
1951
+ return;
1952
+ }
1953
+ if (refRebuild) {
1954
+ rebuildSlot(i);
1955
+ prevRaws[i] = next;
1956
+ return;
1957
+ }
1958
+ const bodies = rowBodies[i];
1959
+ if (bodies !== undefined) {
1960
+ for (let b = 0; b < bodies.length; b++) bodies[b](next, prev, false);
1961
+ }
1962
+ prevRaws[i] = next;
1963
+ };
1964
+ let unbindSlots = shallow ? solidJs.runWithOwner(listOwner, () => solidJs.registerSlotPatch(subject, applySlot)) : null;
1965
+ solidJs.runWithOwner(listOwner, () => effect(() => meta.each(), value => {
1966
+ if (declined || value === subject) return;
1967
+ const nextRaw = value != null ? solidJs.patchableRaw(value) : undefined;
1968
+ unbindOps();
1969
+ unbindSlots?.();
1970
+ if (nextRaw !== undefined && Array.isArray(nextRaw) && solidJs.storeIsShallow(value) !== shallow) {
1971
+ for (let j = 0; j < entries.length; j++) entries[j].remove();
1972
+ entries = [];
1973
+ prevRaws = [];
1974
+ unbindAllRows();
1975
+ subject = value;
1976
+ declined = true;
1977
+ listOwner.dispose();
1978
+ lateClassic?.();
1979
+ return;
1980
+ }
1981
+ if (nextRaw === undefined || !Array.isArray(nextRaw)) {
1982
+ for (let j = 0; j < entries.length; j++) entries[j].remove();
1983
+ entries = [];
1984
+ prevRaws = [];
1985
+ unbindAllRows();
1986
+ subject = value;
1987
+ declined = true;
1988
+ listOwner.dispose();
1989
+ lateClassic?.();
1990
+ return;
1991
+ }
1992
+ const swapOps = identityOps(nextRaw);
1993
+ subject = value;
1994
+ unbindOps = solidJs.runWithOwner(listOwner, () => solidJs.registerRowOps(subject, applyOps));
1995
+ if (shallow) unbindSlots = solidJs.runWithOwner(listOwner, () => solidJs.registerSlotPatch(subject, applySlot));
1996
+ applyOps(nextRaw, swapOps);
1997
+ }));
1998
+ solidJs.onCleanup(() => {
1999
+ unbindOps();
2000
+ unbindSlots?.();
2001
+ unbindAllRows();
2002
+ listOwner.dispose();
2003
+ });
2004
+ return true;
2005
+ };
2006
+ const patchDriver = (subject, body) => {
2007
+ const raw = solidJs.patchableRaw(subject);
2008
+ if (raw !== undefined) {
2009
+ if (!solidJs.sharedConfig.hydrating) body(raw, undefined, true);
2010
+ const unbind = solidJs.registerPatch(subject, body);
2011
+ if (rowCollector !== null) rowCollector.unbinds.push(unbind);
2012
+ else solidJs.onCleanup(unbind);
2013
+ } else if (rowCollector !== null && subject === rowCollector.row) {
2014
+ rowCollector.bodies.push(body);
2015
+ if (!solidJs.sharedConfig.hydrating) body(subject, undefined, true);
2016
+ } else {
2017
+ effect(() => body(subject, subject, false),
2018
+ () => solidJs.untrack(() => body(subject, undefined, true)));
2019
+ }
2020
+ };
2021
+
1689
2022
  function throwInBrowser(func) {
1690
2023
  const err = new Error(`${func.name} is not supported in the browser, returning undefined`);
1691
2024
  console.error(err);
@@ -1796,7 +2129,8 @@ function redirect(url, init = 302) {
1796
2129
  if (responseInit.status === undefined) {
1797
2130
  responseInit.status = 302;
1798
2131
  }
1799
- headers.set("Location", String(url));
2132
+ const target = typeof url === "string" ? url : url[HREF];
2133
+ headers.set("Location", typeof target === "string" ? target : String(url));
1800
2134
  return new Response(null, {
1801
2135
  ...responseInit,
1802
2136
  headers
@@ -2058,6 +2392,7 @@ exports.createRequestEvent = createRequestEvent;
2058
2392
  exports.createResponseStub = createResponseStub;
2059
2393
  exports.createSSRResponse = createSSRResponse;
2060
2394
  exports.delegateEvents = delegateEvents;
2395
+ exports.driveList = driveList;
2061
2396
  exports.dynamic = dynamic;
2062
2397
  exports.dynamicProperty = dynamicProperty;
2063
2398
  exports.effect = effect;
@@ -2080,6 +2415,7 @@ exports.httpStatus = httpStatus;
2080
2415
  exports.hydrate = hydrate;
2081
2416
  exports.insert = insert;
2082
2417
  exports.installHydrationRuntime = installHydrationRuntime;
2418
+ exports.installListDriver = installListDriver;
2083
2419
  exports.isDev = isDev;
2084
2420
  exports.isHref = isHref;
2085
2421
  exports.isResponseEnvelope = isResponseEnvelope;