gestalt
Advanced tools
Comparing version 150.1.0 to 150.1.1
{ | ||
"name": "gestalt", | ||
"version": "150.1.0", | ||
"version": "150.1.1", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "homepage": "https://gestalt.pinterest.systems/", |
import { Align, Layout } from 'gestalt/src//Masonry/types'; | ||
import { Cache } from './Cache'; | ||
import mindex from './mindex'; | ||
import multiColumnLayout from './multiColumnLayout'; | ||
import { Position } from './types'; | ||
@@ -44,5 +45,8 @@ | ||
const defaultLayout = | ||
<T>({ | ||
< | ||
T extends { | ||
readonly [key: string]: unknown; | ||
}, | ||
>({ | ||
align, | ||
cache, | ||
columnWidth = 236, | ||
@@ -54,2 +58,5 @@ gutter = 14, | ||
width, | ||
measurementCache, | ||
_twoColItems = false, | ||
...otherProps | ||
}: { | ||
@@ -60,6 +67,10 @@ columnWidth?: number; | ||
layout: Layout; | ||
cache: Cache<T, number>; | ||
minCols?: number; | ||
rawItemCount: number; | ||
width?: number | null | undefined; | ||
positionCache: Cache<T, Position>; | ||
measurementCache: Cache<T, number>; | ||
_twoColItems?: boolean; | ||
whitespaceThreshold?: number; | ||
logWhitespace?: (arg1: number) => void; | ||
}): ((items: ReadonlyArray<T>) => ReadonlyArray<Position>) => | ||
@@ -86,23 +97,33 @@ (items): ReadonlyArray<Position> => { | ||
return items.reduce<Array<any>>((acc, item) => { | ||
const positions = acc; | ||
const height = cache.get(item); | ||
let position; | ||
return _twoColItems | ||
? multiColumnLayout({ | ||
items, | ||
columnWidth, | ||
columnCount, | ||
centerOffset, | ||
gutter, | ||
measurementCache, | ||
...otherProps, | ||
}) | ||
: items.reduce<Array<any>>((acc, item) => { | ||
const positions = acc; | ||
const height = measurementCache.get(item); | ||
let position; | ||
if (height == null) { | ||
position = offscreen(columnWidth); | ||
} else { | ||
const heightAndGutter = height + gutter; | ||
const col = mindex(heights); | ||
const top = heights[col]; | ||
const left = col * columnWidthAndGutter + centerOffset; | ||
if (height == null) { | ||
position = offscreen(columnWidth); | ||
} else { | ||
const heightAndGutter = height + gutter; | ||
const col = mindex(heights); | ||
const top = heights[col]; | ||
const left = col * columnWidthAndGutter + centerOffset; | ||
heights[col] += heightAndGutter; | ||
position = { top, left, width: columnWidth, height }; | ||
} | ||
positions.push(position); | ||
return positions; | ||
}, []); | ||
heights[col] += heightAndGutter; | ||
position = { top, left, width: columnWidth, height }; | ||
} | ||
positions.push(position); | ||
return positions; | ||
}, []); | ||
}; | ||
export default defaultLayout; |
import { Cache } from './Cache'; | ||
import mindex from './mindex'; | ||
import multiColumnLayout from './multiColumnLayout'; | ||
import { Position } from './types'; | ||
const fullWidthLayout = <T>({ | ||
const fullWidthLayout = < | ||
T extends { | ||
readonly [key: string]: unknown; | ||
}, | ||
>({ | ||
width, | ||
idealColumnWidth = 240, | ||
gutter = 0, | ||
cache, | ||
minCols = 2, | ||
idealColumnWidth = 240, | ||
width, | ||
measurementCache, | ||
_twoColItems = false, | ||
_legacyFlexibleGutterLogic = true, | ||
...otherProps | ||
}: { | ||
idealColumnWidth?: number; | ||
gutter?: number; | ||
cache: Cache<T, number>; | ||
minCols?: number; | ||
idealColumnWidth?: number; | ||
width?: number | null | undefined; | ||
positionCache: Cache<T, Position>; | ||
measurementCache: Cache<T, number>; | ||
_twoColItems?: boolean; | ||
_legacyFlexibleGutterLogic?: boolean; | ||
whitespaceThreshold?: number; | ||
logWhitespace?: (arg1: number) => void; | ||
}): ((items: ReadonlyArray<T>) => ReadonlyArray<Position>) => { | ||
@@ -33,36 +46,46 @@ if (width == null) { | ||
const columnCount = Math.max(Math.floor((width - colguess * gutter) / idealColumnWidth), minCols); | ||
const columnWidth = Math.floor(width / columnCount); | ||
const columnWidth = Math.floor(width / columnCount) - gutter; | ||
const columnWidthAndGutter = columnWidth + gutter; | ||
const centerOffset = gutter / 2; | ||
return (items: ReadonlyArray<T>) => { | ||
// the total height of each column | ||
const heights = new Array<number>(columnCount).fill(0); | ||
return _twoColItems | ||
? multiColumnLayout({ | ||
items, | ||
columnWidth, | ||
columnCount, | ||
centerOffset, | ||
gutter, | ||
measurementCache, | ||
...otherProps, | ||
}) | ||
: items.reduce<Array<any>>((acc, item) => { | ||
const positions = acc; | ||
const height = measurementCache.get(item); | ||
let position; | ||
return items.reduce<Array<any>>((acc, item) => { | ||
const positions = acc; | ||
const height = cache.get(item); | ||
let position; | ||
if (height == null) { | ||
position = { | ||
top: Infinity, | ||
left: Infinity, | ||
width: columnWidth, | ||
height: Infinity, | ||
}; | ||
} else { | ||
const col = mindex(heights); | ||
const top = heights[col]; | ||
const left = col * columnWidthAndGutter + centerOffset; | ||
if (height == null) { | ||
position = { | ||
top: Infinity, | ||
left: Infinity, | ||
width: columnWidth, | ||
height: Infinity, | ||
}; | ||
} else { | ||
const col = mindex(heights); | ||
const top = heights[col]; | ||
const left = col * columnWidth + gutter / 2; | ||
heights[col] += height; | ||
position = { | ||
top, | ||
left, | ||
width: columnWidth - gutter, | ||
height, | ||
}; | ||
} | ||
positions.push(position); | ||
return positions; | ||
}, []); | ||
heights[col] += height + (_legacyFlexibleGutterLogic ? 0 : gutter); | ||
position = { | ||
top, | ||
left, | ||
width: columnWidth, | ||
height, | ||
}; | ||
} | ||
positions.push(position); | ||
return positions; | ||
}, []); | ||
}; | ||
@@ -69,0 +92,0 @@ }; |
import { Cache } from './Cache'; | ||
import defaultLayout from './defaultLayout'; | ||
import defaultTwoColumnModuleLayout from './defaultTwoColumnModuleLayout'; | ||
import fullWidthLayout from './fullWidthLayout'; | ||
@@ -24,2 +23,3 @@ import { Align, Layout, Position } from './types'; | ||
_logTwoColWhitespace, | ||
_legacyFlexibleGutterLogic, | ||
}: { | ||
@@ -37,2 +37,3 @@ align: Align; | ||
_logTwoColWhitespace?: (arg1: number) => void; | ||
_legacyFlexibleGutterLogic?: boolean; | ||
}): (forItems: ReadonlyArray<T>) => ReadonlyArray<Position> { | ||
@@ -42,6 +43,10 @@ if ((layout === 'flexible' || layout === 'serverRenderedFlexible') && width !== null) { | ||
gutter, | ||
cache: measurementStore, | ||
measurementCache: measurementStore, | ||
positionCache: positionStore, | ||
minCols, | ||
idealColumnWidth: columnWidth, | ||
width, | ||
logWhitespace: _logTwoColWhitespace, | ||
_twoColItems, | ||
_legacyFlexibleGutterLogic, | ||
}); | ||
@@ -58,25 +63,15 @@ } | ||
} | ||
if (_twoColItems === true) { | ||
return defaultTwoColumnModuleLayout({ | ||
align: layout === 'basicCentered' ? 'center' : 'start', | ||
measurementCache: measurementStore, | ||
positionCache: positionStore, | ||
columnWidth, | ||
gutter, | ||
logWhitespace: _logTwoColWhitespace, | ||
minCols, | ||
rawItemCount: items.length, | ||
width, | ||
}); | ||
} | ||
return defaultLayout({ | ||
align, | ||
cache: measurementStore, | ||
measurementCache: measurementStore, | ||
positionCache: positionStore, | ||
columnWidth, | ||
gutter, | ||
layout, | ||
logWhitespace: _logTwoColWhitespace, | ||
minCols, | ||
rawItemCount: items.length, | ||
width, | ||
_twoColItems, | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7695345
67968