musae 0.1.34 → 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.
|
@@ -127,7 +127,9 @@ const Input = forwardRef((props$1, ref) => {
|
|
|
127
127
|
}
|
|
128
128
|
}), []);
|
|
129
129
|
/// controlled value
|
|
130
|
-
const [_value, _setValue] = useControlledState(props$1.value
|
|
130
|
+
const [_value, _setValue] = useControlledState(props$1.value, {
|
|
131
|
+
defaultState: ""
|
|
132
|
+
});
|
|
131
133
|
/// events
|
|
132
134
|
const inputEvents = useInputEvents({
|
|
133
135
|
setValue: _setValue,
|
|
@@ -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,10 @@ 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(() => {
|
|
16
|
+
// only 1 columns, no need to repaint, just display as flex
|
|
17
|
+
if (columns <= 1)
|
|
18
|
+
return;
|
|
15
19
|
const [columnHeights, _orders] = Array.from(items.current.entries()).reduce((prev, [index, child]) => {
|
|
16
20
|
if (!child)
|
|
17
21
|
return prev;
|
|
@@ -25,7 +29,9 @@ const useRepaint = ({ columns, rowGap }) => {
|
|
|
25
29
|
}, [new Array(columns).fill(0), new Map()]);
|
|
26
30
|
setMaxHeight(Math.max(...columnHeights));
|
|
27
31
|
setOrders(_orders);
|
|
28
|
-
|
|
32
|
+
});
|
|
33
|
+
useUpdateEffect(() => {
|
|
34
|
+
repaint();
|
|
29
35
|
}, [rowGap]);
|
|
30
36
|
const getOrder = useCallback((index) => {
|
|
31
37
|
return orders.get(index) ?? null;
|
|
@@ -34,6 +40,8 @@ const useRepaint = ({ columns, rowGap }) => {
|
|
|
34
40
|
maxHeight,
|
|
35
41
|
collect,
|
|
36
42
|
getOrder,
|
|
43
|
+
items,
|
|
44
|
+
repaint,
|
|
37
45
|
};
|
|
38
46
|
};
|
|
39
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),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "musae",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"description": "musae-ui",
|
|
5
5
|
"author": "tutu@fantufantu.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@aiszlab/relax": "^1.2.
|
|
25
|
+
"@aiszlab/relax": "^1.2.32",
|
|
26
26
|
"@popperjs/core": "^2.11.8",
|
|
27
27
|
"@tanstack/react-table": "^8.11.3",
|
|
28
28
|
"clsx": "^2.1.0",
|