musae 0.1.35 → 0.1.36
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
/**
|
|
2
3
|
* @description
|
|
3
4
|
* repaint child
|
|
@@ -9,4 +10,6 @@ export declare const useRepaint: ({ columns, rowGap }: {
|
|
|
9
10
|
maxHeight: number;
|
|
10
11
|
collect: (index: number, ref: HTMLDivElement | null) => void;
|
|
11
12
|
getOrder: (index: number) => number | null;
|
|
13
|
+
items: import("react").MutableRefObject<Map<number, HTMLDivElement | null>>;
|
|
14
|
+
repaint: () => void;
|
|
12
15
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEvent, useUpdateEffect } from '@aiszlab/relax';
|
|
2
|
+
import { useRef, useState, useCallback } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @description
|
|
@@ -11,7 +12,7 @@ const useRepaint = ({ columns, rowGap }) => {
|
|
|
11
12
|
const collect = useCallback((index, ref) => {
|
|
12
13
|
items.current.set(index, ref);
|
|
13
14
|
}, []);
|
|
14
|
-
|
|
15
|
+
const repaint = useEvent(() => {
|
|
15
16
|
// only 1 columns, no need to repaint, just display as flex
|
|
16
17
|
if (columns <= 1)
|
|
17
18
|
return;
|
|
@@ -28,7 +29,9 @@ const useRepaint = ({ columns, rowGap }) => {
|
|
|
28
29
|
}, [new Array(columns).fill(0), new Map()]);
|
|
29
30
|
setMaxHeight(Math.max(...columnHeights));
|
|
30
31
|
setOrders(_orders);
|
|
31
|
-
|
|
32
|
+
});
|
|
33
|
+
useUpdateEffect(() => {
|
|
34
|
+
repaint();
|
|
32
35
|
}, [rowGap]);
|
|
33
36
|
const getOrder = useCallback((index) => {
|
|
34
37
|
return orders.get(index) ?? null;
|
|
@@ -37,6 +40,8 @@ const useRepaint = ({ columns, rowGap }) => {
|
|
|
37
40
|
maxHeight,
|
|
38
41
|
collect,
|
|
39
42
|
getOrder,
|
|
43
|
+
items,
|
|
44
|
+
repaint,
|
|
40
45
|
};
|
|
41
46
|
};
|
|
42
47
|
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { useRepaint } from './hooks.mjs';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useGutters } from '../../hooks/use-gutters.mjs';
|
|
6
|
+
import { useMounted } from '@aiszlab/relax';
|
|
6
7
|
|
|
7
8
|
const styles = {
|
|
8
9
|
waterfall: props => [{
|
|
@@ -51,7 +52,9 @@ const Waterfall = ({
|
|
|
51
52
|
const {
|
|
52
53
|
collect,
|
|
53
54
|
maxHeight,
|
|
54
|
-
getOrder
|
|
55
|
+
getOrder,
|
|
56
|
+
items,
|
|
57
|
+
repaint
|
|
55
58
|
} = useRepaint({
|
|
56
59
|
columns,
|
|
57
60
|
rowGap
|
|
@@ -62,6 +65,19 @@ const Waterfall = ({
|
|
|
62
65
|
}), maxHeight > 0 && styles.repainted({
|
|
63
66
|
maxHeight: maxHeight
|
|
64
67
|
}));
|
|
68
|
+
useMounted(() => {
|
|
69
|
+
// observer will be called when the component is mounted
|
|
70
|
+
// so in waterfall we use current time to first render
|
|
71
|
+
const resizer = new ResizeObserver(() => {
|
|
72
|
+
repaint();
|
|
73
|
+
});
|
|
74
|
+
Array.from(items.current.values()).forEach(node => {
|
|
75
|
+
node && resizer.observe(node);
|
|
76
|
+
});
|
|
77
|
+
return () => {
|
|
78
|
+
resizer.disconnect();
|
|
79
|
+
};
|
|
80
|
+
});
|
|
65
81
|
if (children.length === 0) return null;
|
|
66
82
|
return React.createElement("div", {
|
|
67
83
|
className: clsx(props$1.className, styled.className),
|