@virtuoso.dev/masonry
Advanced tools
+11
-0
| # Change Log - @virtuoso.dev/masonry | ||
| ## 1.4.1 | ||
| ### Patch Changes | ||
| - [#1361](https://github.com/petyosi/react-virtuoso/pull/1361) [`7b38166`](https://github.com/petyosi/react-virtuoso/commit/7b3816607c2b8fa3eb8818bea6e291c93a91112d) Thanks [@petyosi](https://github.com/petyosi)! - Replace ESLint and Prettier with oxlint and oxfmt for faster linting and formatting. Modernize TypeScript configuration with `verbatimModuleSyntax` and ES2022 build targets. | ||
| Source code changes are non-behavioral: stricter equality checks (`===`/`!==` instead of truthiness), `??` instead of `||` for defaults, early returns instead of else blocks, self-closing JSX tags, and removal of unnecessary JSX fragments. `LogLevel` in react-virtuoso is changed from a TypeScript enum to a const object — the named exports (`LogLevel.DEBUG`, etc.) work identically, but enum reverse-mapping (`LogLevel[0]`) is no longer supported. | ||
| - Updated dependencies [[`7b38166`](https://github.com/petyosi/react-virtuoso/commit/7b3816607c2b8fa3eb8818bea6e291c93a91112d)]: | ||
| - @virtuoso.dev/gurx@1.2.1 | ||
| ## 1.4.0 | ||
@@ -4,0 +15,0 @@ |
+3
-3
@@ -5,7 +5,7 @@ /* Excluded from this release type: Data */ | ||
| * A React component that's used to render the individual masonry item. | ||
| * @typeParam Data - The type of items in the data array. | ||
| * @typeParam Item - The type of items in the data array. | ||
| * @typeParam Context - Optional contextual data passed from the parent component. | ||
| * @group VirtuosoMasonry | ||
| */ | ||
| export declare type ItemContent<Data = any, Context = any> = React.ComponentType<{ | ||
| export declare type ItemContent<Item = any, Context = any> = React.ComponentType<{ | ||
| /** | ||
@@ -18,3 +18,3 @@ * The value of the `context` prop passed to the masonry. | ||
| */ | ||
| data: Data; | ||
| data: Item; | ||
| /** | ||
@@ -21,0 +21,0 @@ * The index of the item in the data array. |
+223
-228
@@ -1,19 +0,19 @@ | ||
| import { jsxs as Yt, jsx as M, Fragment as Dt } from "react/jsx-runtime"; | ||
| import { Cell as g, link as vt, pipe as w, filter as Rt, map as y, DerivedCell as S, combine as gt, withLatestFrom as It, changeWith as St, Signal as $t, scan as Nt, sub as jt, pub as Gt, Realm as Ut, RealmContext as qt, useRealm as Kt, useCellValues as Jt, useCellValue as Qt } from "@virtuoso.dev/gurx"; | ||
| import { forwardRef as Xt, useMemo as Zt, useImperativeHandle as te, useEffect as Et, useState as ee, useRef as ft, useCallback as _ } from "react"; | ||
| const Ct = ({ index: t }) => /* @__PURE__ */ Yt("div", { children: [ | ||
| import { jsxs as Yt, jsx as A } from "react/jsx-runtime"; | ||
| import { forwardRef as Dt, useMemo as jt, useImperativeHandle as Gt, useEffect as St, useState as Ut, useRef as ft, useCallback as _ } from "react"; | ||
| import { Cell as v, link as vt, pipe as b, filter as Rt, map as w, DerivedCell as R, combine as It, withLatestFrom as gt, changeWith as $t, Signal as Nt, scan as Ct, sub as qt, pub as Kt, Realm as Jt, RealmContext as Qt, useRealm as Xt, useCellValues as Zt, useCellValue as te } from "@virtuoso.dev/gurx"; | ||
| const Et = ({ index: t }) => /* @__PURE__ */ Yt("div", { children: [ | ||
| "Item ", | ||
| t | ||
| ] }), Mt = g(Ct), D = g(0), at = g(null), tt = g(null, () => { | ||
| ] }), Mt = v(Et), D = v(0), at = v(null), tt = v(null, () => { | ||
| vt( | ||
| w( | ||
| b( | ||
| tt, | ||
| Rt((t) => t !== null), | ||
| y((t) => t.length) | ||
| w((t) => t.length) | ||
| ), | ||
| D | ||
| ); | ||
| }), X = g(0), ht = g(0), ne = g(0), Q = g(0), et = g(0), j = g(!1), re = S(0, () => w( | ||
| gt(ht, j, et), | ||
| y(([t, e, n]) => e ? t - Math.max(n, 0) : t) | ||
| }), X = v(0), ht = v(0), ee = v(0), Q = v(0), et = v(0), j = v(!1), ne = R(0, () => b( | ||
| It(ht, j, et), | ||
| w(([t, e, n]) => e ? t - Math.max(n, 0) : t) | ||
| )), G = { lvl: 0 }; | ||
@@ -29,4 +29,5 @@ function Vt(t, e, n, r = G, o = G) { | ||
| } | ||
| function mt(t, e) { | ||
| if (a(t)) return G; | ||
| function dt(t, e) { | ||
| if (a(t)) | ||
| return G; | ||
| const { k: n, l: r, r: o } = t; | ||
@@ -39,5 +40,5 @@ if (e === n) { | ||
| const [s, l] = Ht(r); | ||
| return Z(m(t, { k: s, l: Ot(r), v: l })); | ||
| return Z(h(t, { k: s, l: Ot(r), v: l })); | ||
| } | ||
| return e < n ? Z(m(t, { l: mt(r, e) })) : Z(m(t, { r: mt(o, e) })); | ||
| return e < n ? Z(h(t, { l: dt(r, e) })) : Z(h(t, { r: dt(o, e) })); | ||
| } | ||
@@ -55,6 +56,6 @@ function U(t, e, n = "k") { | ||
| } | ||
| function k(t, e, n) { | ||
| return a(t) ? Vt(e, n, 1) : e === t.k ? m(t, { k: e, v: n }) : e < t.k ? yt(m(t, { l: k(t.l, e, n) })) : yt(m(t, { r: k(t.r, e, n) })); | ||
| function T(t, e, n) { | ||
| return a(t) ? Vt(e, n, 1) : e === t.k ? h(t, { k: e, v: n }) : e < t.k ? yt(h(t, { l: T(t.l, e, n) })) : yt(h(t, { r: T(t.r, e, n) })); | ||
| } | ||
| function dt(t, e, n) { | ||
| function mt(t, e, n) { | ||
| if (a(t)) | ||
@@ -64,3 +65,3 @@ return []; | ||
| let i = []; | ||
| return r > e && (i = i.concat(dt(o, e, n))), r >= e && r <= n && i.push({ k: r, v: l }), r <= n && (i = i.concat(dt(s, e, n))), i; | ||
| return r > e && (i = i.concat(mt(o, e, n))), r >= e && r <= n && i.push({ k: r, v: l }), r <= n && (i = i.concat(mt(s, e, n))), i; | ||
| } | ||
@@ -71,5 +72,5 @@ function Ht(t) { | ||
| function Ot(t) { | ||
| return a(t.r) ? t.l : Z(m(t, { r: Ot(t.r) })); | ||
| return a(t.r) ? t.l : Z(h(t, { r: Ot(t.r) })); | ||
| } | ||
| function m(t, e) { | ||
| function h(t, e) { | ||
| return Vt(e.k ?? t.k, e.v ?? t.v, e.lvl ?? t.lvl, e.l ?? t.l, e.r ?? t.r); | ||
@@ -89,8 +90,8 @@ } | ||
| if (ut(e)) | ||
| return kt(m(t, { lvl: n - 1 })); | ||
| return kt(h(t, { lvl: n - 1 })); | ||
| if (!a(e) && !a(e.r)) | ||
| return m(e.r, { | ||
| l: m(e, { r: e.r.l }), | ||
| return h(e.r, { | ||
| l: h(e, { r: e.r.l }), | ||
| lvl: n, | ||
| r: m(t, { | ||
| r: h(t, { | ||
| l: e.r.r, | ||
@@ -103,7 +104,7 @@ lvl: n - 1 | ||
| if (ut(t)) | ||
| return xt(m(t, { lvl: n - 1 })); | ||
| return xt(h(t, { lvl: n - 1 })); | ||
| if (!a(r) && !a(r.l)) { | ||
| const o = r.l, s = ut(o) ? r.lvl - 1 : r.lvl; | ||
| return m(o, { | ||
| l: m(t, { | ||
| return h(o, { | ||
| l: h(t, { | ||
| lvl: n - 1, | ||
@@ -113,3 +114,3 @@ r: o.l | ||
| lvl: o.lvl + 1, | ||
| r: xt(m(r, { l: o.r, lvl: s })) | ||
| r: xt(h(r, { l: o.r, lvl: s })) | ||
| }); | ||
@@ -123,3 +124,3 @@ } | ||
| const r = U(t, e)[0]; | ||
| return oe(dt(t, r, n)); | ||
| return re(mt(t, r, n)); | ||
| } | ||
@@ -138,3 +139,3 @@ function Tt(t, e) { | ||
| } | ||
| function oe(t) { | ||
| function re(t) { | ||
| return Tt(t, ({ k: e, v: n }) => ({ index: e, value: n })); | ||
@@ -144,13 +145,13 @@ } | ||
| const { lvl: e, r: n } = t; | ||
| return !a(n) && !a(n.r) && n.lvl === e && n.r.lvl === e ? m(n, { l: m(t, { r: n.l }), lvl: e + 1 }) : t; | ||
| return !a(n) && !a(n.r) && n.lvl === e && n.r.lvl === e ? h(n, { l: h(t, { r: n.l }), lvl: e + 1 }) : t; | ||
| } | ||
| function kt(t) { | ||
| const { l: e } = t; | ||
| return !a(e) && e.lvl === t.lvl ? m(e, { r: m(t, { l: e.r }) }) : t; | ||
| return !a(e) && e.lvl === t.lvl ? h(e, { r: h(t, { l: e.r }) }) : t; | ||
| } | ||
| function se(t) { | ||
| function oe(t) { | ||
| const { endIndex: e, size: n, startIndex: r } = t; | ||
| return (o) => o.start === r && (o.end === e || o.end === Number.POSITIVE_INFINITY) && o.value === n; | ||
| } | ||
| function Pt(t, e) { | ||
| function Wt(t, e) { | ||
| let n = a(t) ? 0 : Number.POSITIVE_INFINITY; | ||
@@ -160,12 +161,12 @@ for (const r of e) { | ||
| if (n = Math.min(n, l), a(t)) { | ||
| t = k(t, 0, s); | ||
| t = T(t, 0, s); | ||
| continue; | ||
| } | ||
| const i = At(t, l - 1, o + 1); | ||
| if (i.some(se(r))) | ||
| if (i.some(oe(r))) | ||
| continue; | ||
| let u = !1, c = !1; | ||
| for (const { end: d, start: $, value: R } of i) | ||
| u ? (o >= $ || s === R) && (t = mt(t, $)) : (c = R !== s, u = !0), d > o && o >= $ && R !== s && (t = k(t, o + 1, R)); | ||
| c && (t = k(t, l, s)); | ||
| let u = !1, f = !1; | ||
| for (const { end: m, start: $, value: y } of i) | ||
| u ? (o >= $ || s === y) && (t = dt(t, $)) : (f = y !== s, u = !0), m > o && o >= $ && y !== s && (t = T(t, o + 1, y)); | ||
| f && (t = T(t, l, s)); | ||
| } | ||
@@ -192,25 +193,25 @@ return [t, n]; | ||
| } | ||
| function le(t, e, n) { | ||
| function se(t, e, n) { | ||
| return t[rt(t, e, n)]; | ||
| } | ||
| function ie(t, e, n, r) { | ||
| function le(t, e, n, r) { | ||
| const o = rt(t, e, r), s = rt(t, n, r, o); | ||
| return t.slice(o, s + 1); | ||
| } | ||
| function Wt({ index: t }, e) { | ||
| function Pt({ index: t }, e) { | ||
| return e === t ? 0 : e < t ? -1 : 1; | ||
| } | ||
| function ce({ offset: t }, e) { | ||
| function ie({ offset: t }, e) { | ||
| return e === t ? 0 : e < t ? -1 : 1; | ||
| } | ||
| function ue(t) { | ||
| function ce(t) { | ||
| return { index: t.index, value: t }; | ||
| } | ||
| function fe(t, e, n, r = 0) { | ||
| return r > 0 && (e = Math.max(e, le(t, r, Wt).offset)), e = Math.max(0, e), Tt(ie(t, e, n, ce), ue); | ||
| function ue(t, e, n, r = 0) { | ||
| return r > 0 && (e = Math.max(e, se(t, r, Pt).offset)), e = Math.max(0, e), Tt(le(t, e, n, ie), ce); | ||
| } | ||
| function ae(t, [e, n]) { | ||
| function fe(t, [e, n]) { | ||
| let r = 0, o = 0, s = 0, l = 0; | ||
| if (n !== 0) { | ||
| l = rt(t, n - 1, Wt), s = t[l].offset; | ||
| l = rt(t, n - 1, Pt), s = t[l].offset; | ||
| const u = U(e, n - 1); | ||
@@ -223,19 +224,19 @@ if (u[1] === void 0) | ||
| for (const { start: i, value: u } of At(e, n, Number.POSITIVE_INFINITY)) { | ||
| const c = (i - r) * o + s; | ||
| t.push({ height: u, index: i, offset: c }), r = i, s = c, o = u; | ||
| const f = (i - r) * o + s; | ||
| t.push({ height: u, index: i, offset: f }), r = i, s = f, o = u; | ||
| } | ||
| return [t, o, s, r]; | ||
| } | ||
| function he(t, [e, n]) { | ||
| function ae(t, [e, n]) { | ||
| if (n.length > 0 && a(t) && e.length === 2) { | ||
| const r = e[0].size, o = e[1].size; | ||
| return [ | ||
| n.reduce((s, l) => k(k(s, l, r), l + 1, o), nt()), | ||
| n.reduce((s, l) => T(T(s, l, r), l + 1, o), nt()), | ||
| 0 | ||
| ]; | ||
| } | ||
| return Pt(t, e); | ||
| return Wt(t, e); | ||
| } | ||
| const zt = $t(), Ft = $t(), lt = g([], () => { | ||
| St(lt, Ft, (t, e) => { | ||
| const zt = Nt(), Ft = Nt(), lt = v([], () => { | ||
| $t(lt, Ft, (t, e) => { | ||
| const n = t.slice(); | ||
@@ -249,8 +250,8 @@ for (const [r, o] of Object.entries(e)) | ||
| }); | ||
| }), P = g(0), pt = g(0), ot = g([], () => { | ||
| }), k = v(0), pt = v(0), ot = v([], () => { | ||
| vt( | ||
| w( | ||
| P, | ||
| It(lt), | ||
| y(([t, e]) => { | ||
| b( | ||
| k, | ||
| gt(lt), | ||
| w(([t, e]) => { | ||
| const n = Array.from({ length: t }, () => [nt(), 0]); | ||
@@ -261,3 +262,3 @@ if (e.length > 0) { | ||
| const l = e[s], i = r.indexOf(Math.min(...r)), u = o[i]; | ||
| o[i]++, r[i] += l, n[i] = Pt(n[i][0], [ | ||
| o[i]++, r[i] += l, n[i] = Wt(n[i][0], [ | ||
| { endIndex: u, size: l, startIndex: u } | ||
@@ -271,3 +272,3 @@ ]); | ||
| ot | ||
| ), St(ot, zt, (t, e) => { | ||
| ), $t(ot, zt, (t, e) => { | ||
| const n = t.map(([o]) => o), r = []; | ||
@@ -280,56 +281,56 @@ for (let o = 0; o < e.length; o++) { | ||
| } | ||
| r.push(he(s, [e[o], []])); | ||
| r.push(ae(s, [e[o], []])); | ||
| } | ||
| return r; | ||
| }); | ||
| }), _t = S([], () => w( | ||
| }), _t = R([], () => b( | ||
| ot, | ||
| y((t) => t.map(([e]) => e)) | ||
| )), me = S([], (t) => t.pipe( | ||
| w((t) => t.map(([e]) => e)) | ||
| )), he = R([], (t) => t.pipe( | ||
| ot, | ||
| y((e) => e.map(([, n]) => n)) | ||
| )), it = S([], () => w( | ||
| w((e) => e.map(([, n]) => n)) | ||
| )), it = R([], () => b( | ||
| _t, | ||
| It(me), | ||
| Nt((t, [e, n]) => { | ||
| gt(he), | ||
| Ct((t, [e, n]) => { | ||
| const r = []; | ||
| for (let o = 0; o < e.length; o++) { | ||
| const s = t[o] ?? [[]]; | ||
| r.push(ae(s[0], [e[o], n[o]])); | ||
| r.push(fe(s[0], [e[o], n[o]])); | ||
| } | ||
| return r; | ||
| }, []) | ||
| )), de = S( | ||
| )), de = R( | ||
| [], | ||
| () => w( | ||
| () => b( | ||
| it, | ||
| y((t) => t.map(([e]) => e)) | ||
| w((t) => t.map(([e]) => e)) | ||
| ) | ||
| ), xe = S( | ||
| ), me = R( | ||
| [], | ||
| () => w( | ||
| () => b( | ||
| it, | ||
| y((t) => t.map(([, e]) => e)) | ||
| w((t) => t.map(([, e]) => e)) | ||
| ) | ||
| ), ve = S( | ||
| ), xe = R( | ||
| [], | ||
| () => w( | ||
| () => b( | ||
| it, | ||
| y((t) => t.map(([, , e]) => e)) | ||
| w((t) => t.map(([, , e]) => e)) | ||
| ) | ||
| ), ge = S( | ||
| ), ve = R( | ||
| [], | ||
| (t) => t.pipe( | ||
| it, | ||
| y((e) => e.map(([, , , n]) => n)) | ||
| w((e) => e.map(([, , , n]) => n)) | ||
| ) | ||
| ), Y = S([], () => w( | ||
| P, | ||
| It(D, pt, lt), | ||
| y(([t, e, n, r]) => { | ||
| ), Y = R([], () => b( | ||
| k, | ||
| gt(D, pt, lt), | ||
| w(([t, e, n, r]) => { | ||
| if (r.length > 0) { | ||
| const l = Array.from({ length: t }, () => 0), i = Array.from({ length: t }, () => []); | ||
| for (let u = 0; u < r.length; u++) { | ||
| const c = r[u], d = l.indexOf(Math.min(...l)); | ||
| i[d].push(u), l[d] += c; | ||
| const f = r[u], m = l.indexOf(Math.min(...l)); | ||
| i[m].push(u), l[m] += f; | ||
| } | ||
@@ -341,26 +342,26 @@ return i; | ||
| const u = []; | ||
| for (let c = i; c < o; c += t) | ||
| u.push(c); | ||
| for (let f = i; f < o; f += t) | ||
| u.push(f); | ||
| return u; | ||
| }); | ||
| }) | ||
| )), Ie = S( | ||
| )), Ie = R( | ||
| [], | ||
| () => w( | ||
| gt(P, D, ge, ve, xe, Y), | ||
| y(([t, e, n, r, o, s]) => { | ||
| const l = s.reduce((c, d) => c + d.length, 0), i = Math.ceil((e - l) / t); | ||
| return Array.from({ length: t }, (c, d) => { | ||
| const R = s[d].length + i - n[d]; | ||
| return r[d] + R * o[d]; | ||
| () => b( | ||
| It(k, D, ve, xe, me, Y), | ||
| w(([t, e, n, r, o, s]) => { | ||
| const l = s.reduce((f, m) => f + m.length, 0), i = Math.ceil((e - l) / t); | ||
| return Array.from({ length: t }, (f, m) => { | ||
| const y = s[m].length + i - n[m]; | ||
| return r[m] + y * o[m]; | ||
| }); | ||
| }) | ||
| ) | ||
| ), st = g({ columns: [], data: [], indexesInColumns: [], totalCount: -1 }, (t) => { | ||
| ), st = v({ columns: [], data: [], indexesInColumns: [], totalCount: -1 }, (t) => { | ||
| vt( | ||
| w( | ||
| gt( | ||
| P, | ||
| b( | ||
| It( | ||
| k, | ||
| X, | ||
| re, | ||
| ne, | ||
| _t, | ||
@@ -376,3 +377,3 @@ de, | ||
| ), | ||
| Nt( | ||
| Ct( | ||
| (e, [ | ||
@@ -386,6 +387,6 @@ n, | ||
| u, | ||
| c, | ||
| d, | ||
| f, | ||
| m, | ||
| $, | ||
| R, | ||
| y, | ||
| B | ||
@@ -395,3 +396,3 @@ ]) => { | ||
| return e; | ||
| const bt = B ? R + r : 0, f = Math.min(Math.max(r - bt, 0), Math.max(...u) - o), h = f + o, b = $ === 0 ? Math.min(n, i) : $; | ||
| const bt = B ? y + r : 0, c = Math.min(Math.max(r - bt, 0), Math.max(...u) - o), d = c + o, S = $ === 0 ? Math.min(n, i) : $; | ||
| return { | ||
@@ -401,13 +402,13 @@ columns: Array.from( | ||
| (q, I) => { | ||
| const x = e.columns[I], V = s[I] ?? nt(), E = l[I] ?? [], p = u[I] ?? 0, H = d[I] ?? []; | ||
| if (a(V) || H.length === 0) { | ||
| const A = []; | ||
| let T = 0; | ||
| for (let C = I; C < b; C += n) | ||
| A.push({ | ||
| const g = e.columns[I], E = s[I] ?? nt(), N = l[I] ?? [], p = u[I] ?? 0, M = m[I] ?? []; | ||
| if (a(E) || M.length === 0) { | ||
| const H = []; | ||
| let O = 0; | ||
| for (let C = I; C < S; C += n) | ||
| H.push({ | ||
| columnIndex: I, | ||
| data: c == null ? void 0 : c[C], | ||
| data: f?.[C], | ||
| height: 0, | ||
| index: C, | ||
| indexInColumn: T++, | ||
| indexInColumn: O++, | ||
| offset: 0 | ||
@@ -417,34 +418,31 @@ }); | ||
| index: I, | ||
| items: A, | ||
| items: H, | ||
| listBottom: 0, | ||
| listTop: 0, | ||
| offsetTree: E, | ||
| offsetTree: N, | ||
| totalHeight: 0, | ||
| viewportBottom: h | ||
| viewportBottom: d | ||
| }; | ||
| } | ||
| if ( | ||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
| (x == null ? void 0 : x.offsetTree) === E && e.totalCount === i && e.data === c && e.indexesInColumns === d && f >= x.listTop && h <= x.listBottom | ||
| ) | ||
| return x; | ||
| const K = [], W = H.length - 1, z = 0, ct = fe(E, f, h, z); | ||
| let v = 0, L = 0, O = !1; | ||
| for (const A of ct) { | ||
| if (g?.offsetTree === N && e.totalCount === i && e.data === f && e.indexesInColumns === m && c >= g.listTop && d <= g.listBottom) | ||
| return g; | ||
| const K = [], P = M.length - 1, z = 0, ct = ue(N, c, d, z); | ||
| let x = 0, L = 0, V = !1; | ||
| for (const H of ct) { | ||
| const { | ||
| value: { height: T, offset: C } | ||
| } = A; | ||
| let F = A.start; | ||
| v = C, C < f && (F += Math.floor((f - C) / T), v += (F - A.start) * T), F < z && (v += (z - F) * T, F = z); | ||
| const Bt = Math.min(A.end, W); | ||
| for (let J = F; J <= Bt && !(v >= h); J++) { | ||
| const wt = H[J], Lt = { | ||
| value: { height: O, offset: C } | ||
| } = H; | ||
| let F = H.start; | ||
| x = C, C < c && (F += Math.floor((c - C) / O), x += (F - H.start) * O), F < z && (x += (z - F) * O, F = z); | ||
| const Bt = Math.min(H.end, P); | ||
| for (let J = F; J <= Bt && !(x >= d); J++) { | ||
| const wt = M[J], Lt = { | ||
| columnIndex: I, | ||
| data: c == null ? void 0 : c[wt], | ||
| height: T, | ||
| data: f?.[wt], | ||
| height: O, | ||
| index: wt, | ||
| indexInColumn: J, | ||
| offset: v | ||
| offset: x | ||
| }; | ||
| O || (O = !0, L = v), K.push(Lt), v += T; | ||
| V || (V = !0, L = x), K.push(Lt), x += O; | ||
| } | ||
@@ -455,12 +453,12 @@ } | ||
| items: K, | ||
| listBottom: v, | ||
| listBottom: x, | ||
| listTop: L, | ||
| offsetTree: E, | ||
| offsetTree: N, | ||
| totalHeight: p, | ||
| viewportBottom: h | ||
| viewportBottom: d | ||
| }; | ||
| } | ||
| ), | ||
| data: c, | ||
| indexesInColumns: d, | ||
| data: f, | ||
| indexesInColumns: m, | ||
| totalCount: i | ||
@@ -478,4 +476,4 @@ }; | ||
| st | ||
| ), jt( | ||
| w( | ||
| ), qt( | ||
| b( | ||
| st, | ||
@@ -486,3 +484,3 @@ Rt((e) => e.columns.some((n) => n.listBottom < n.viewportBottom)) | ||
| const n = e.columns.slice().sort((l, i) => l.listBottom - i.listBottom)[0], r = t.getValue(Y), o = r.flat(), s = o.length ? Math.max(...o) + 1 : 0; | ||
| s >= t.getValue(D) || Gt( | ||
| s >= t.getValue(D) || Kt( | ||
| Y, | ||
@@ -493,8 +491,8 @@ r.map((l, i) => i === n.index ? [...l, s] : l) | ||
| ); | ||
| }), pe = Xt( | ||
| ({ columnCount: t, context: e, data: n, initialItemCount: r = 0, ItemContent: o = Ct, useWindowScroll: s = !1, ...l }, i) => { | ||
| const u = Zt(() => { | ||
| const c = new Ut(); | ||
| return c.register(Y), c.register(st), c.register(lt), c.pubIn({ | ||
| [P]: t, | ||
| }), ge = Dt( | ||
| ({ columnCount: t, context: e, data: n, initialItemCount: r = 0, ItemContent: o = Et, useWindowScroll: s = !1, ...l }, i) => { | ||
| const u = jt(() => { | ||
| const f = new Jt(); | ||
| return f.register(Y), f.register(st), f.register(lt), f.pubIn({ | ||
| [k]: t, | ||
| [at]: e, | ||
@@ -505,42 +503,41 @@ [tt]: n.slice(), | ||
| [j]: s | ||
| }), c; | ||
| }), f; | ||
| }, []); | ||
| return te(i, () => ({}), []), Et(() => { | ||
| return Gt(i, () => ({}), []), St(() => { | ||
| u.pubIn({ | ||
| [P]: t, | ||
| [k]: t, | ||
| [at]: e, | ||
| [tt]: n.slice() | ||
| }); | ||
| }), /* @__PURE__ */ M(qt.Provider, { value: u, children: /* @__PURE__ */ M(we, { ...l }) }); | ||
| }), /* @__PURE__ */ A(Qt.Provider, { value: u, children: /* @__PURE__ */ A(be, { ...l }) }); | ||
| } | ||
| // oxlint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- generic forwardRef pattern requires cast | ||
| ); | ||
| pe.displayName = "VirtuosoMasonry"; | ||
| const be = { | ||
| // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
| ge.displayName = "VirtuosoMasonry"; | ||
| const pe = { | ||
| observe: () => { | ||
| }, | ||
| // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
| unobserve: () => { | ||
| } | ||
| }, we = ({ style: t, ...e }) => { | ||
| const n = Kt(), [r] = ee(() => { | ||
| }, be = ({ style: t, ...e }) => { | ||
| const n = Xt(), [r] = Ut(() => { | ||
| if (typeof ResizeObserver > "u") { | ||
| if (typeof window < "u") | ||
| throw new Error("ResizeObserver not found. Please ensure that you have a polyfill installed."); | ||
| return be; | ||
| return pe; | ||
| } | ||
| return new ResizeObserver((f) => { | ||
| const h = f.length, b = n.getValue(P), N = n.getValue(j), q = Array.from({ length: b }, () => []), I = {}; | ||
| let x = {}; | ||
| for (let V = 0; V < h; V++) { | ||
| const E = f[V], p = E.target; | ||
| return new ResizeObserver((c) => { | ||
| const d = c.length, S = n.getValue(k), W = n.getValue(j), q = Array.from({ length: S }, () => []), I = {}; | ||
| let g = {}; | ||
| for (let E = 0; E < d; E++) { | ||
| const N = c[E], p = N.target; | ||
| if (p === l.current) { | ||
| const O = p.ownerDocument.defaultView; | ||
| x = { | ||
| ...x, | ||
| [Q]: N ? O.document.documentElement.scrollHeight : p.scrollHeight, | ||
| [X]: N ? O.scrollY : p.scrollTop, | ||
| [ht]: N ? O.innerHeight : E.contentRect.height, | ||
| [ne]: N ? O.innerWidth : p.clientWidth, | ||
| ...N ? {} : { [et]: E.contentRect.top, [Q]: p.scrollHeight } | ||
| const V = p.ownerDocument.defaultView; | ||
| g = { | ||
| ...g, | ||
| [Q]: W ? V.document.documentElement.scrollHeight : p.scrollHeight, | ||
| [X]: W ? V.scrollY : p.scrollTop, | ||
| [ht]: W ? V.innerHeight : N.contentRect.height, | ||
| [ee]: W ? V.innerWidth : p.clientWidth, | ||
| ...W ? {} : { [et]: N.contentRect.top, [Q]: p.scrollHeight } | ||
| }; | ||
@@ -550,4 +547,4 @@ continue; | ||
| if (p.dataset.role === "column") { | ||
| l.current && (x = { | ||
| ...x, | ||
| l.current && (g = { | ||
| ...g, | ||
| [Q]: l.current.scrollHeight | ||
@@ -559,62 +556,60 @@ }); | ||
| continue; | ||
| const H = Number.parseInt(p.dataset.index), K = Number.parseFloat(p.dataset.knownSize ?? ""), W = E.contentRect.height, z = Number.parseInt(p.dataset.columnIndex ?? "0"), ct = Number.parseInt(p.dataset.absoluteIndex ?? "0"); | ||
| if (I[ct] = W, W === K) | ||
| const M = Number.parseInt(p.dataset.index), K = Number.parseFloat(p.dataset.knownSize ?? ""), P = N.contentRect.height, z = Number.parseInt(p.dataset.columnIndex ?? "0"), ct = Number.parseInt(p.dataset.absoluteIndex ?? "0"); | ||
| if (I[ct] = P, P === K) | ||
| continue; | ||
| const v = q[z], L = v[v.length - 1]; | ||
| v.length === 0 || L.size !== W || L.endIndex !== H - 1 ? v.push({ endIndex: H, size: W, startIndex: H }) : v[v.length - 1].endIndex++; | ||
| const x = q[z], L = x[x.length - 1]; | ||
| x.length === 0 || L.size !== P || L.endIndex !== M - 1 ? x.push({ endIndex: M, size: P, startIndex: M }) : x[x.length - 1].endIndex++; | ||
| } | ||
| q.some((V) => V.length > 0) && (x = { | ||
| ...x, | ||
| q.some((E) => E.length > 0) && (g = { | ||
| ...g, | ||
| [zt]: q | ||
| }), Object.keys(I).length > 0 && (x = { | ||
| ...x, | ||
| }), Object.keys(I).length > 0 && (g = { | ||
| ...g, | ||
| [Ft]: I | ||
| }), n.pubIn(x); | ||
| }), n.pubIn(g); | ||
| }); | ||
| }), o = _( | ||
| (f) => { | ||
| r.observe(f); | ||
| (c) => { | ||
| r.observe(c); | ||
| }, | ||
| [r] | ||
| ), s = _( | ||
| (f) => { | ||
| r.unobserve(f); | ||
| (c) => { | ||
| r.unobserve(c); | ||
| }, | ||
| [r] | ||
| ), l = ft(null), i = ft([]), u = _( | ||
| (f) => (h) => { | ||
| if (h) | ||
| i.current[f] = h, r.observe(h, { box: "border-box" }); | ||
| (c) => (d) => { | ||
| if (d) | ||
| i.current[c] = d, r.observe(d, { box: "border-box" }); | ||
| else { | ||
| const b = i.current[f]; | ||
| b != null && (r.unobserve(b), i.current[f] = null); | ||
| const S = i.current[c]; | ||
| S != null && (r.unobserve(S), i.current[c] = null); | ||
| } | ||
| }, | ||
| [r] | ||
| ), c = _(() => { | ||
| const f = l.current; | ||
| f !== null && n.pub(X, f.scrollTop); | ||
| }, [n]), d = _( | ||
| (f) => { | ||
| f ? (l.current = f, f.addEventListener("scroll", c), r.observe(f, { box: "border-box" })) : l.current && (l.current.removeEventListener("scroll", c), r.unobserve(l.current), l.current = null); | ||
| ), f = _(() => { | ||
| const c = l.current; | ||
| c !== null && n.pub(X, c.scrollTop); | ||
| }, [n]), m = _( | ||
| (c) => { | ||
| c ? (l.current = c, c.addEventListener("scroll", f), r.observe(c, { box: "border-box" })) : l.current && (l.current.removeEventListener("scroll", f), r.unobserve(l.current), l.current = null); | ||
| }, | ||
| [r, c] | ||
| ), [$, R, B] = Jt(st, Mt, j); | ||
| return Et(() => { | ||
| var f; | ||
| [r, f] | ||
| ), [$, y, B] = Zt(st, Mt, j); | ||
| return St(() => { | ||
| if (B) { | ||
| const h = (f = l.current) == null ? void 0 : f.ownerDocument.defaultView, b = () => { | ||
| var N; | ||
| const c = l.current?.ownerDocument.defaultView, d = () => { | ||
| n.pubIn({ | ||
| [et]: ((N = l.current) == null ? void 0 : N.getBoundingClientRect().top) ?? 0, | ||
| [Q]: h.document.documentElement.scrollHeight, | ||
| [X]: h.scrollY, | ||
| [ht]: h.innerHeight | ||
| [et]: l.current?.getBoundingClientRect().top ?? 0, | ||
| [Q]: c.document.documentElement.scrollHeight, | ||
| [X]: c.scrollY, | ||
| [ht]: c.innerHeight | ||
| }); | ||
| }; | ||
| return h.addEventListener("scroll", b), b(), () => { | ||
| h.removeEventListener("scroll", b); | ||
| return c.addEventListener("scroll", d), d(), () => { | ||
| c.removeEventListener("scroll", d); | ||
| }; | ||
| } | ||
| }, [B, n]), /* @__PURE__ */ M(Dt, { children: /* @__PURE__ */ M( | ||
| }, [B, n]), /* @__PURE__ */ A( | ||
| "div", | ||
@@ -624,3 +619,3 @@ { | ||
| "data-testid": "virtuoso-scroller", | ||
| ref: d, | ||
| ref: m, | ||
| style: { | ||
@@ -639,22 +634,22 @@ ...B ? { | ||
| }, | ||
| children: $.columns.map((f, h) => /* @__PURE__ */ M( | ||
| children: $.columns.map((c, d) => /* @__PURE__ */ A( | ||
| "div", | ||
| { | ||
| "data-testid": "virtuoso-list", | ||
| ref: u(h), | ||
| ref: u(d), | ||
| style: { | ||
| boxSizing: "content-box", | ||
| flexGrow: 1, | ||
| height: f.totalHeight, | ||
| height: c.totalHeight, | ||
| overflowAnchor: "none", | ||
| position: "relative" | ||
| }, | ||
| children: f.items.map((b) => /* @__PURE__ */ M(ye, { item: b, ItemContent: R, mount: o, unmount: s }, b.index)) | ||
| children: c.items.map((S) => /* @__PURE__ */ A(we, { item: S, ItemContent: y, mount: o, unmount: s }, S.index)) | ||
| }, | ||
| `column-${h}` | ||
| `column-${d}` | ||
| )) | ||
| } | ||
| ) }); | ||
| }, ye = ({ item: t, ItemContent: e, mount: n, unmount: r }) => { | ||
| const o = Qt(at), s = ft(null), l = _( | ||
| ); | ||
| }, we = ({ item: t, ItemContent: e, mount: n, unmount: r }) => { | ||
| const o = te(at), s = ft(null), l = _( | ||
| (i) => { | ||
@@ -665,3 +660,3 @@ i ? (s.current = i, n(i)) : s.current && (r(s.current), s.current = null); | ||
| ); | ||
| return /* @__PURE__ */ M( | ||
| return /* @__PURE__ */ A( | ||
| "div", | ||
@@ -681,3 +676,3 @@ { | ||
| }, | ||
| children: /* @__PURE__ */ M(e, { context: o, data: t.data, index: t.index }) | ||
| children: /* @__PURE__ */ A(e, { context: o, data: t.data, index: t.index }) | ||
| } | ||
@@ -687,3 +682,3 @@ ); | ||
| export { | ||
| pe as VirtuosoMasonry | ||
| ge as VirtuosoMasonry | ||
| }; |
+41
-33
| { | ||
| "name": "@virtuoso.dev/masonry", | ||
| "version": "1.4.1", | ||
| "private": false, | ||
| "description": "Virtualized React component for rendering masonry layouts", | ||
| "keywords": [ | ||
| "react", | ||
| "virtual", | ||
| "masonry", | ||
| "endless scrolling", | ||
| "infinite", | ||
| "list", | ||
| "masonry", | ||
| "react", | ||
| "scrolling", | ||
| "infinite", | ||
| "virtual", | ||
| "virtualized" | ||
| ], | ||
| "homepage": "https://virtuoso.dev/virtuoso-masonry/", | ||
| "bugs": { | ||
| "email": "support@virtuoso.dev" | ||
| }, | ||
| "license": "MIT", | ||
| "author": "The Virtuoso team <support@virtuoso.dev>", | ||
| "license": "MIT", | ||
| "homepage": "https://virtuoso.dev/virtuoso-masonry/", | ||
| "repository": { | ||
@@ -23,11 +27,17 @@ "type": "git", | ||
| }, | ||
| "bugs": { | ||
| "email": "support@virtuoso.dev" | ||
| }, | ||
| "version": "1.4.0", | ||
| "files": [ | ||
| "dist", | ||
| "CHANGELOG.md" | ||
| ], | ||
| "type": "module", | ||
| "sideEffects": false, | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.js", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "sideEffects": false, | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "publishConfig": { | ||
@@ -38,12 +48,8 @@ "access": "public", | ||
| "dependencies": { | ||
| "@virtuoso.dev/gurx": "1.2.0" | ||
| "@virtuoso.dev/gurx": "1.2.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": ">= 18 || >= 19", | ||
| "react-dom": ">= 18 || >= 19" | ||
| }, | ||
| "devDependencies": { | ||
| "@ladle/react": "^5.0.1", | ||
| "@microsoft/api-extractor": "^7.55.1", | ||
| "@types/node": "^22.10.1", | ||
| "@types/node": "^22.19.1", | ||
| "@types/react": "^19.2.7", | ||
@@ -54,20 +60,17 @@ "@types/react-dom": "^19.2.3", | ||
| "@vitest/browser-playwright": "^4.0.16", | ||
| "eslint": "^9.19.0", | ||
| "jsdom": "^26.0.0", | ||
| "jsdom": "^27.4.0", | ||
| "knip": "^5.38.3", | ||
| "node-html-parser": "^6.1.13", | ||
| "playwright": "^1.33.0", | ||
| "prettier": "^3.4.2", | ||
| "react": "19.2.0", | ||
| "react-dom": "19.2.0", | ||
| "typescript": "~5.9.3", | ||
| "playwright": "^1.58.2", | ||
| "react": "^19.2.3", | ||
| "react-dom": "^19.2.3", | ||
| "typescript": "^5.9.3", | ||
| "vite": "^6.4.1", | ||
| "vite-plugin-dts": "^4.5.4", | ||
| "vitest": "^4.0.16", | ||
| "@virtuoso.dev/tooling": "0.1.0" | ||
| "vitest": "^4.0.16" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "CHANGELOG.md" | ||
| ], | ||
| "peerDependencies": { | ||
| "react": ">= 18 || >= 19", | ||
| "react-dom": ">= 18 || >= 19" | ||
| }, | ||
| "scripts": { | ||
@@ -77,7 +80,12 @@ "build": "tsc && vite build", | ||
| "ladle": "ladle serve", | ||
| "test": "vitest", | ||
| "test": "vitest run --browser.headless", | ||
| "test:browser": "vitest run --project=browser", | ||
| "test:node": "vitest run --project=\"node env\"", | ||
| "test:watch": "vitest", | ||
| "lint": "oxlint --type-aware --type-check", | ||
| "typecheck": "tsgo --noEmit", | ||
| "lint": "eslint", | ||
| "format": "oxfmt", | ||
| "format:check": "oxfmt --check", | ||
| "knip": "knip" | ||
| } | ||
| } |
30587
3.26%18
-14.29%748
-0.66%+ Added
- Removed
Updated