react-photo-album
Advanced tools
Comparing version 2.0.0-rc.4 to 2.0.0-rc.5
@@ -103,4 +103,2 @@ import * as React from 'react'; | ||
renderColumnContainer?: RenderColumnContainer<T>; | ||
/** Internal instrumentation - use on your own risk. */ | ||
instrumentation?: Instrumentation; | ||
}; | ||
@@ -187,11 +185,5 @@ declare type RenderPhoto<T extends Photo = Photo> = (props: PhotoProps<T>) => React.ReactNode; | ||
}; | ||
/** internal instrumentation for research and performance testing purposes, subject to change without notice */ | ||
declare type Instrumentation = { | ||
fullGraphSearch?: boolean; | ||
onStartLayout?: () => void; | ||
onFinishLayout?: (...params: any) => void; | ||
}; | ||
declare const PhotoAlbum: <T extends Photo>(props: PhotoAlbumProps<T>) => JSX.Element; | ||
export { ClickHandler, ColumnContainerProps, ColumnsLayoutOptions, ComponentsProps, ComponentsPropsParameter, ContainerProps, GenericLayoutOptions, Image, Instrumentation, LayoutOptions, LayoutType, Photo, PhotoAlbum, PhotoAlbumProps, PhotoLayout, PhotoProps, RenderColumnContainer, RenderContainer, RenderContainerProps, RenderPhoto, RenderRowContainer, ResponsiveParameter, ResponsiveParameterProvider, ResponsiveSizes, RowConstraints, RowContainerProps, RowsLayoutOptions, PhotoAlbum as default }; | ||
export { ClickHandler, ColumnContainerProps, ColumnsLayoutOptions, ComponentsProps, ComponentsPropsParameter, ContainerProps, GenericLayoutOptions, Image, LayoutOptions, LayoutType, Photo, PhotoAlbum, PhotoAlbumProps, PhotoLayout, PhotoProps, RenderColumnContainer, RenderContainer, RenderContainerProps, RenderPhoto, RenderRowContainer, ResponsiveParameter, ResponsiveParameterProvider, ResponsiveSizes, RowConstraints, RowContainerProps, RowsLayoutOptions, PhotoAlbum as default }; |
@@ -142,3 +142,3 @@ 'use strict'; | ||
}; | ||
const makeGetRowNeighbors = ({ photos, layoutOptions, targetRowHeight, limitNodeSearch, rowConstraints, instrumentation, }) => (node) => { | ||
const makeGetRowNeighbors = ({ photos, layoutOptions, targetRowHeight, limitNodeSearch, rowConstraints, }) => (node) => { | ||
var _a, _b; | ||
@@ -152,3 +152,3 @@ const { containerWidth, spacing, padding } = layoutOptions; | ||
for (let i = start + startOffset; i < photos.length + 1; i += 1) { | ||
if (i - start > endOffset && !(instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.fullGraphSearch)) | ||
if (i - start > endOffset) | ||
break; | ||
@@ -162,6 +162,4 @@ const currentCost = cost(photos, start, i, containerWidth, targetRowHeight, spacing, padding); | ||
}; | ||
const computeRowsLayout = ({ photos, layoutOptions, instrumentation, }) => { | ||
var _a, _b; | ||
const computeRowsLayout = ({ photos, layoutOptions, }) => { | ||
const { spacing, padding, containerWidth, targetRowHeight, rowConstraints } = layoutOptions; | ||
(_a = instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.onStartLayout) === null || _a === void 0 ? void 0 : _a.call(instrumentation); | ||
const limitNodeSearch = findIdealNodeSearch({ photos, containerWidth, targetRowHeight }); | ||
@@ -174,3 +172,2 @@ const getNeighbors = makeGetRowNeighbors({ | ||
rowConstraints, | ||
instrumentation, | ||
}); | ||
@@ -195,3 +192,2 @@ const path = findShortestPath(getNeighbors, "0", `${photos.length}`); | ||
} | ||
(_b = instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.onFinishLayout) === null || _b === void 0 ? void 0 : _b.call(instrumentation, layout); | ||
return layout; | ||
@@ -317,4 +313,4 @@ }; | ||
const RowsLayout = (props) => { | ||
const { photos, layoutOptions, renderPhoto, renderRowContainer, componentsProps, instrumentation } = props; | ||
const rowsLayout = computeRowsLayout({ photos, layoutOptions, instrumentation }); | ||
const { photos, layoutOptions, renderPhoto, renderRowContainer, componentsProps } = props; | ||
const rowsLayout = computeRowsLayout({ photos, layoutOptions }); | ||
if (!rowsLayout) | ||
@@ -365,3 +361,3 @@ return null; | ||
const makeGetColumnNeighbors = ({ photos, spacing, padding, targetColumnWidth, targetColumnHeight, instrumentation, }) => (node) => { | ||
const makeGetColumnNeighbors = ({ photos, spacing, padding, targetColumnWidth, targetColumnHeight, }) => (node) => { | ||
const results = []; | ||
@@ -372,3 +368,3 @@ const cutOffHeight = targetColumnHeight * 1.5; | ||
results.push({ neighbor: i, weight: (targetColumnHeight - height) ** 2 }); | ||
if ((height > cutOffHeight && !(instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.fullGraphSearch)) || i === photos.length) { | ||
if (height > cutOffHeight || i === photos.length) { | ||
break; | ||
@@ -402,3 +398,3 @@ } | ||
}; | ||
const computeColumnsModel = ({ photos, layoutOptions, targetColumnWidth, instrumentation, }) => { | ||
const computeColumnsModel = ({ photos, layoutOptions, targetColumnWidth, }) => { | ||
const { columns, spacing, padding, containerWidth } = layoutOptions; | ||
@@ -434,3 +430,2 @@ const columnsGaps = []; | ||
padding, | ||
instrumentation, | ||
}); | ||
@@ -455,3 +450,3 @@ const path = findShortestPathLengthN(getNeighbors, columns, 0, photos.length).map((node) => +node); | ||
const computeLayout = (props) => { | ||
const { photos, layoutOptions, instrumentation } = props; | ||
const { photos, layoutOptions } = props; | ||
const { columns, spacing, padding, containerWidth } = layoutOptions; | ||
@@ -463,14 +458,6 @@ const targetColumnWidth = (containerWidth - spacing * (columns - 1) - 2 * padding * columns) / columns; | ||
targetColumnWidth, | ||
instrumentation, | ||
}); | ||
if (columnsModel.findIndex((columnModel) => columnModel.findIndex(({ layout: { width, height } }) => width < 0 || height < 0) >= 0) >= 0) { | ||
if (columns > 1) { | ||
return computeLayout({ | ||
photos, | ||
layoutOptions: { | ||
...layoutOptions, | ||
columns: columns - 1, | ||
}, | ||
instrumentation, | ||
}); | ||
return computeLayout({ photos, layoutOptions: { ...layoutOptions, columns: columns - 1 } }); | ||
} | ||
@@ -483,9 +470,6 @@ else { | ||
}; | ||
const computeColumnsLayout = ({ photos, layoutOptions, instrumentation, }) => { | ||
var _a, _b; | ||
(_a = instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.onStartLayout) === null || _a === void 0 ? void 0 : _a.call(instrumentation); | ||
const layout = computeLayout({ photos, layoutOptions, instrumentation }); | ||
(_b = instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.onFinishLayout) === null || _b === void 0 ? void 0 : _b.call(instrumentation, layout); | ||
return layout; | ||
}; | ||
const computeColumnsLayout = ({ photos, layoutOptions, }) => computeLayout({ | ||
photos, | ||
layoutOptions, | ||
}); | ||
@@ -527,4 +511,4 @@ const defaultRenderColumnContainer = ({ columnContainerProps, children, }) => React__namespace.createElement("div", { ...columnContainerProps }, children); | ||
const ColumnsLayout = (props) => { | ||
const { photos, layoutOptions, renderPhoto, renderColumnContainer, componentsProps, instrumentation } = props; | ||
const columnsLayout = computeColumnsLayout({ photos, layoutOptions, instrumentation }); | ||
const { photos, layoutOptions, renderPhoto, renderColumnContainer, componentsProps } = props; | ||
const columnsLayout = computeColumnsLayout({ photos, layoutOptions }); | ||
if (!columnsLayout) | ||
@@ -537,6 +521,4 @@ return null; | ||
const computeMasonryLayout = (props) => { | ||
var _a, _b; | ||
const { photos, layoutOptions, instrumentation } = props; | ||
const { photos, layoutOptions } = props; | ||
const { columns, spacing, padding, containerWidth } = layoutOptions; | ||
(_a = instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.onStartLayout) === null || _a === void 0 ? void 0 : _a.call(instrumentation); | ||
const columnWidth = (containerWidth - spacing * (columns - 1) - 2 * padding * columns) / columns; | ||
@@ -562,3 +544,3 @@ if (columnWidth <= 0) { | ||
}, Array.from({ length: columns }).map(() => [])); | ||
const layout = columnsModel.map((column) => column.map(({ photo, index }, photoIndex) => ({ | ||
return columnsModel.map((column) => column.map(({ photo, index }, photoIndex) => ({ | ||
photo, | ||
@@ -573,9 +555,7 @@ layout: { | ||
}))); | ||
(_b = instrumentation === null || instrumentation === void 0 ? void 0 : instrumentation.onFinishLayout) === null || _b === void 0 ? void 0 : _b.call(instrumentation, layout); | ||
return layout; | ||
}; | ||
const MasonryLayout = (props) => { | ||
const { photos, layoutOptions, renderPhoto, renderColumnContainer, componentsProps, instrumentation } = props; | ||
const masonryLayout = computeMasonryLayout({ photos, layoutOptions, instrumentation }); | ||
const { photos, layoutOptions, renderPhoto, renderColumnContainer, componentsProps } = props; | ||
const masonryLayout = computeMasonryLayout({ photos, layoutOptions }); | ||
if (!masonryLayout) | ||
@@ -694,5 +674,5 @@ return null; | ||
const renderLayout = (props, containerWidth, componentsProps) => { | ||
const { photos, layout, renderPhoto, renderRowContainer, renderColumnContainer, instrumentation } = props; | ||
const { photos, layout, renderPhoto, renderRowContainer, renderColumnContainer } = props; | ||
const layoutOptions = resolveLayoutOptions({ containerWidth, ...props }); | ||
const commonLayoutProps = { photos, renderPhoto, componentsProps, instrumentation }; | ||
const commonLayoutProps = { photos, renderPhoto, componentsProps }; | ||
return (React__namespace.createElement(React__namespace.Fragment, null, layout === "rows" ? (React__namespace.createElement(RowsLayout, { layoutOptions: layoutOptions, renderRowContainer: renderRowContainer, ...commonLayoutProps })) : layout === "columns" ? (React__namespace.createElement(ColumnsLayout, { layoutOptions: layoutOptions, renderColumnContainer: renderColumnContainer, ...commonLayoutProps })) : (React__namespace.createElement(MasonryLayout, { layoutOptions: layoutOptions, renderColumnContainer: renderColumnContainer, ...commonLayoutProps })))); | ||
@@ -699,0 +679,0 @@ }; |
{ | ||
"name": "react-photo-album", | ||
"version": "2.0.0-rc.4", | ||
"version": "2.0.0-rc.5", | ||
"description": "Responsive photo gallery component for React", | ||
@@ -5,0 +5,0 @@ "author": "Igor Danchenko", |
Sorry, the diff of this file is not supported yet
79855
1476