@codeleap/web 3.12.3 → 3.12.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/package.json
CHANGED
package/src/lib/ListMasonry.tsx
CHANGED
|
@@ -10,9 +10,7 @@ import {
|
|
|
10
10
|
useResizeObserver,
|
|
11
11
|
MasonryProps,
|
|
12
12
|
RenderComponentProps,
|
|
13
|
-
MasonryScroller,
|
|
14
13
|
} from 'masonic'
|
|
15
|
-
|
|
16
14
|
import { EmptyPlaceholder } from '../components/EmptyPlaceholder'
|
|
17
15
|
|
|
18
16
|
export type ItemMasonryProps<T> = RenderComponentProps<T>
|
|
@@ -23,37 +21,21 @@ export type ListMasonryProps<T> = MasonryProps<T> & {
|
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
|
|
26
|
-
const
|
|
27
|
-
columnCount,
|
|
28
|
-
columnGutter,
|
|
29
|
-
rowGutter,
|
|
30
|
-
items,
|
|
31
|
-
render,
|
|
32
|
-
} = props
|
|
33
|
-
|
|
34
|
-
const data = items || []
|
|
24
|
+
const data = props?.items || []
|
|
35
25
|
|
|
36
26
|
const [reloadingLayout, setReloadingLayout] = useState(false)
|
|
37
27
|
|
|
38
28
|
const dataPreviousLength = usePrevious(data?.length)
|
|
39
29
|
|
|
40
|
-
const masonryUpdater = React.useMemo(() => {
|
|
41
|
-
if (data?.length < dataPreviousLength) {
|
|
42
|
-
return data?.length
|
|
43
|
-
} else {
|
|
44
|
-
return false
|
|
45
|
-
}
|
|
46
|
-
}, [dataPreviousLength, data?.length])
|
|
47
|
-
|
|
48
30
|
onUpdate(() => {
|
|
49
|
-
if (
|
|
31
|
+
if (data?.length < dataPreviousLength) {
|
|
50
32
|
setReloadingLayout(true)
|
|
51
33
|
|
|
52
34
|
setTimeout(() => {
|
|
53
35
|
setReloadingLayout(false)
|
|
54
36
|
}, 3000)
|
|
55
37
|
}
|
|
56
|
-
}, [
|
|
38
|
+
}, [data?.length])
|
|
57
39
|
|
|
58
40
|
const containerRef = React.useRef(null)
|
|
59
41
|
|
|
@@ -64,42 +46,38 @@ export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
|
|
|
64
46
|
|
|
65
47
|
const containerPosition = useContainerPosition(containerRef, windowSize)
|
|
66
48
|
|
|
67
|
-
const listProps =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
49
|
+
const listProps = Object.assign(
|
|
50
|
+
{
|
|
51
|
+
offset: containerPosition?.offset,
|
|
52
|
+
width: containerPosition?.width || containerRef?.current?.clientWidth || windowSize?.[0],
|
|
53
|
+
height: windowSize?.[1],
|
|
54
|
+
containerRef,
|
|
55
|
+
scrollFps: props?.scrollFps || 12,
|
|
56
|
+
},
|
|
57
|
+
props
|
|
58
|
+
) as any
|
|
59
|
+
|
|
60
|
+
listProps.positioner = usePositioner({
|
|
76
61
|
width: listProps?.width,
|
|
77
|
-
columnGutter: columnGutter,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
62
|
+
columnGutter: listProps?.columnGutter,
|
|
63
|
+
columnWidth: listProps?.columnWidth,
|
|
64
|
+
columnCount: listProps?.columnCount,
|
|
65
|
+
maxColumnCount: listProps?.columnCount,
|
|
66
|
+
rowGutter: listProps?.rowGutter
|
|
67
|
+
}, [reloadingLayout])
|
|
82
68
|
|
|
83
|
-
const
|
|
69
|
+
const { scrollTop, isScrolling } = useScroller(listProps?.offset, listProps?.scrollFps)
|
|
70
|
+
|
|
71
|
+
listProps.resizeObserver = useResizeObserver(listProps.positioner)
|
|
84
72
|
|
|
85
73
|
if (reloadingLayout) {
|
|
86
|
-
return
|
|
87
|
-
<EmptyPlaceholder loading={true} />
|
|
88
|
-
)
|
|
74
|
+
return <EmptyPlaceholder loading={true} title={''} description={null} />
|
|
89
75
|
}
|
|
90
76
|
|
|
91
|
-
return (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
items={data}
|
|
98
|
-
height={listProps?.height}
|
|
99
|
-
offset={listProps?.offset}
|
|
100
|
-
overscanBy={6}
|
|
101
|
-
render={render}
|
|
102
|
-
scrollFps={listProps?.scrollFps}
|
|
103
|
-
/>
|
|
104
|
-
)
|
|
77
|
+
return useMasonry({
|
|
78
|
+
...listProps,
|
|
79
|
+
scrollTop,
|
|
80
|
+
isScrolling,
|
|
81
|
+
items: data,
|
|
82
|
+
})
|
|
105
83
|
}
|