@cloud-app-dev/vidc 2.0.0-alpha.7 → 2.1.0-alpha.10
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/.fatherrc.js +11 -4
- package/.umirc.ts +1 -1
- package/es/Api/index.js +7 -7
- package/es/AppRedirect/index.d.ts +1 -1
- package/es/AppRedirect/index.js +7 -12
- package/es/AppRouter/index.d.ts +8 -0
- package/es/AppRouter/index.js +17 -0
- package/es/Auth/index.js +1 -1
- package/es/AutoExit/index.js +12 -10
- package/es/{ContentBox → Box}/BetweenBox/index.css +0 -0
- package/es/{ContentBox → Box}/BetweenBox/index.d.ts +0 -0
- package/es/{ContentBox → Box}/BetweenBox/index.js +0 -0
- package/es/{ContentBox → Box}/InfoBox/index.css +0 -0
- package/es/{ContentBox → Box}/InfoBox/index.d.ts +0 -0
- package/es/{ContentBox → Box}/InfoBox/index.js +0 -0
- package/es/{ContentBox → Box}/TwoColumnBox/index.css +0 -0
- package/es/{ContentBox → Box}/TwoColumnBox/index.d.ts +0 -0
- package/es/{ContentBox → Box}/TwoColumnBox/index.js +0 -0
- package/es/{ContentBox → Box}/deps/content-grid.d.ts +0 -0
- package/es/{ContentBox → Box}/deps/content-grid.js +0 -0
- package/es/{ContentBox → Box}/deps/grid-factory.d.ts +0 -0
- package/es/{ContentBox → Box}/deps/grid-factory.js +0 -0
- package/es/{ContentBox → Box}/deps/simple-grid.d.ts +0 -0
- package/es/{ContentBox → Box}/deps/simple-grid.js +0 -0
- package/es/{ContentBox → Box}/index.css +0 -0
- package/es/{ContentBox → Box}/index.d.ts +3 -3
- package/es/{ContentBox → Box}/index.js +5 -5
- package/es/CheckGroupFixed/index.js +4 -2
- package/es/Config/index.js +44 -14
- package/es/Config/interface.d.ts +12 -5
- package/es/Config/utils.d.ts +1 -1
- package/es/Config/utils.js +1 -3
- package/es/ConfigContext/index.d.ts +15 -2
- package/es/ConfigContext/index.js +25 -3
- package/es/DeviceSelect/TreeType.d.ts +6 -0
- package/es/DeviceSelect/TreeType.js +36 -0
- package/es/DeviceSelect/demo.js +2 -2
- package/es/DeviceSelect/index.css +6 -1
- package/es/DeviceSelect/index.d.ts +5 -0
- package/es/DeviceSelect/index.js +21 -52
- package/es/Dict/hook.d.ts +0 -1
- package/es/Dict/hook.js +5 -21
- package/es/Dict/index.d.ts +1 -5
- package/es/Dict/index.js +2 -6
- package/es/Dict/utils.d.ts +0 -1
- package/es/Dict/utils.js +2 -9
- package/es/IconFont/index.d.ts +0 -1
- package/es/IconFont/index.js +12 -13
- package/es/InitialConfig/index.js +7 -6
- package/es/InitialConfig/utils.d.ts +5 -0
- package/es/InitialConfig/utils.js +33 -6
- package/es/InitialRequest/index.d.ts +3 -1
- package/es/InitialRequest/index.js +20 -16
- package/es/InitialRequest/utils.d.ts +6 -4
- package/es/InitialRequest/utils.js +52 -70
- package/es/Input/index.js +3 -2
- package/es/InstanceHistory/index.d.ts +3 -0
- package/es/InstanceHistory/index.js +9 -0
- package/es/List/CheckExt.d.ts +3 -5
- package/es/List/CheckExt.js +21 -13
- package/es/{AppRoute → List/DeviceList}/index.css +0 -0
- package/es/List/DeviceList/index.d.ts +11 -0
- package/es/{DeviceList → List/DeviceList}/index.js +6 -18
- package/es/{DynamicDeviceList → List/DynamicDeviceList}/Demo.d.ts +0 -0
- package/es/{DynamicList/demo.js → List/DynamicDeviceList/Demo.js} +25 -42
- package/es/{DynamicDeviceList → List/DynamicDeviceList}/index.css +5 -17
- package/es/List/DynamicDeviceList/index.d.ts +11 -0
- package/es/List/DynamicDeviceList/index.js +205 -0
- package/es/List/DynamicDeviceList/interface.d.ts +37 -0
- package/es/List/DynamicDeviceList/utils.d.ts +16 -0
- package/es/List/DynamicDeviceList/utils.js +61 -0
- package/es/{DynamicList/demo.d.ts → List/DynamicGridList/Demo.d.ts} +0 -0
- package/es/List/DynamicGridList/Demo.js +70 -0
- package/es/List/DynamicGridList/index.d.ts +26 -0
- package/es/List/DynamicGridList/index.js +73 -0
- package/es/List/GridList/Demo.d.ts +2 -0
- package/es/List/GridList/Demo.js +91 -0
- package/es/List/GridList/hook.d.ts +13 -0
- package/es/List/GridList/hook.js +301 -0
- package/es/List/GridList/index.css +7 -0
- package/es/List/GridList/index.d.ts +15 -0
- package/es/List/GridList/index.js +47 -0
- package/es/List/GridList/interface.d.ts +59 -0
- package/es/List/GridList/utils.d.ts +9 -0
- package/es/List/GridList/utils.js +43 -0
- package/es/List/ListExt/index.css +3 -0
- package/es/{ListExt → List/ListExt}/index.d.ts +1 -1
- package/es/{ListExt → List/ListExt}/index.js +3 -3
- package/es/List/VList/index.css +6 -0
- package/es/List/VList/index.d.ts +18 -0
- package/es/List/VList/index.js +51 -0
- package/es/List/VList/utils.d.ts +14 -0
- package/es/{VList → List/VList}/utils.js +0 -0
- package/es/List/index.css +11 -12
- package/es/List/index.d.ts +5 -70
- package/es/List/index.js +32 -24
- package/es/List/interface.d.ts +87 -0
- package/es/List/renderItem.d.ts +1 -1
- package/es/List/renderItem.js +13 -10
- package/es/LoaderApp/index.d.ts +1 -1
- package/es/LoaderApp/index.js +39 -35
- package/es/LoaderApp/loader.js +2 -6
- package/es/LoaderApp/utils.d.ts +3 -1
- package/es/LoaderApp/utils.js +43 -3
- package/es/LoaderScript/index.js +7 -89
- package/es/LoaderScript/utils.d.ts +2 -0
- package/es/LoaderScript/utils.js +170 -33
- package/es/Picture/component/MoveContent/index.js +3 -3
- package/es/RefDrawer/index.js +1 -1
- package/es/RefModal/index.js +1 -1
- package/es/Service/http.d.ts +6 -4
- package/es/Service/http.js +20 -22
- package/es/Service/index.d.ts +3 -3
- package/es/Service/index.js +7 -11
- package/es/Service/interface.d.ts +5 -11
- package/es/Service/middleware.d.ts +1 -1
- package/es/Service/middleware.js +1 -1
- package/es/TableLayout/index.d.ts +3 -0
- package/es/TableLayout/index.js +14 -45
- package/es/{TreeTitle → Title}/index.css +5 -5
- package/es/{TreeTitle → Title}/index.d.ts +2 -2
- package/es/{TreeTitle → Title}/index.js +7 -4
- package/es/{TreeMode → Tree/BaseTree}/demo.d.ts +0 -0
- package/es/Tree/BaseTree/demo.js +69 -0
- package/es/Tree/BaseTree/index.css +64 -0
- package/es/Tree/BaseTree/index.d.ts +24 -0
- package/es/Tree/BaseTree/index.js +83 -0
- package/es/Tree/demo.js +19 -56
- package/es/Tree/index.css +29 -55
- package/es/Tree/index.d.ts +19 -20
- package/es/Tree/index.js +185 -70
- package/es/UserSelect/index.js +6 -4
- package/es/WorkerFlow/Form/Condition.js +2 -4
- package/es/WorkerFlow/Form/EmptyUserSet.js +2 -4
- package/es/WorkerFlow/Form/FormAuth.js +2 -2
- package/es/WorkerFlow/Form/GroupList.js +2 -2
- package/es/WorkerFlow/Form/GroupSelect.js +2 -4
- package/es/WorkerFlow/Form/GroupSelectModalContent.js +1 -1
- package/es/WorkerFlow/Form/LevelGroupSelect.js +3 -5
- package/es/WorkerFlow/Form/UserAndGroupSelect.js +2 -4
- package/es/WorkerFlow/Form/UserSelect.js +2 -4
- package/es/WorkerFlow/Form/UserSelectModalContent.js +3 -3
- package/es/WorkerFlow/Form/UserSet.js +2 -2
- package/es/WorkerFlow/Nodes/TitleElement.js +71 -34
- package/es/WorkerFlow/index.css +9 -3
- package/es/WorkerFlow/index.js +13 -8
- package/es/WorkerFlow/utils.js +2 -2
- package/es/index.d.ts +4 -11
- package/es/index.js +4 -11
- package/es/useDrawer/index.d.ts +1 -1
- package/es/useDrawer/index.js +3 -2
- package/es/useHistory/index.d.ts +2 -2
- package/es/useHistory/index.js +3 -6
- package/es/useHttp/index.js +1 -1
- package/es/useModal/index.d.ts +1 -1
- package/es/useModal/index.js +3 -2
- package/es/utils.d.ts +9 -0
- package/es/utils.js +36 -1
- package/package.json +10 -12
- package/tsconfig.json +1 -1
- package/es/AppRoute/Render.d.ts +0 -23
- package/es/AppRoute/Render.js +0 -111
- package/es/AppRoute/Rendered.d.ts +0 -4
- package/es/AppRoute/Rendered.js +0 -11
- package/es/AppRoute/index.d.ts +0 -14
- package/es/AppRoute/index.js +0 -106
- package/es/AppRoute/interface.d.ts +0 -18
- package/es/AppRoute/utils.d.ts +0 -1
- package/es/AppRoute/utils.js +0 -28
- package/es/DeviceList/index.css +0 -32
- package/es/DeviceList/index.d.ts +0 -14
- package/es/Dict/desc.d.ts +0 -64
- package/es/Dict/desc.js +0 -162
- package/es/DynamicDeviceList/CheckExt.d.ts +0 -8
- package/es/DynamicDeviceList/CheckExt.js +0 -36
- package/es/DynamicDeviceList/Demo.js +0 -17
- package/es/DynamicDeviceList/index.d.ts +0 -35
- package/es/DynamicDeviceList/index.js +0 -224
- package/es/DynamicDeviceList/utils.d.ts +0 -2
- package/es/DynamicDeviceList/utils.js +0 -15
- package/es/DynamicList/index.css +0 -7
- package/es/DynamicList/index.d.ts +0 -31
- package/es/DynamicList/index.js +0 -132
- package/es/IconFont/index.css +0 -0
- package/es/List/utils.d.ts +0 -5
- package/es/List/utils.js +0 -18
- package/es/ListExt/index.css +0 -9
- package/es/ScrollList/index.css +0 -73
- package/es/ScrollList/index.d.ts +0 -24
- package/es/ScrollList/index.js +0 -261
- package/es/ScrollList/utils.js +0 -84
- package/es/Service/logger.d.ts +0 -3
- package/es/Service/logger.js +0 -13
- package/es/Service/utils.d.ts +0 -3
- package/es/Service/utils.js +0 -11
- package/es/TreeMode/demo.js +0 -32
- package/es/TreeMode/index.css +0 -38
- package/es/TreeMode/index.d.ts +0 -23
- package/es/TreeMode/index.js +0 -201
- package/es/VList/index.css +0 -4
- package/es/VList/index.d.ts +0 -16
- package/es/VList/index.js +0 -56
- package/es/VList/utils.d.ts +0 -10
- package/es/useChangeEffect/index.d.ts +0 -3
- package/es/useChangeEffect/index.js +0 -32
- package/es/useHistory/index.css +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import GridList from './index';
|
|
3
|
+
|
|
4
|
+
function random(low, high) {
|
|
5
|
+
return Math.floor(Math.random() * high) + low;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
var IMAGES = Array.from({
|
|
9
|
+
length: 60
|
|
10
|
+
}, function (_, index) {
|
|
11
|
+
var width = 300;
|
|
12
|
+
var height = random(200, 300);
|
|
13
|
+
return {
|
|
14
|
+
url: "https://picsum.photos/id/".concat(index + 1, "/").concat(width, "/").concat(height, ".jpg"),
|
|
15
|
+
width: width,
|
|
16
|
+
height: height
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var App = function App() {
|
|
21
|
+
function loadNextPage(d) {
|
|
22
|
+
return new Promise(function (resolve) {
|
|
23
|
+
setTimeout(function () {
|
|
24
|
+
resolve({
|
|
25
|
+
list: IMAGES
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
style: {
|
|
33
|
+
height: 800,
|
|
34
|
+
overflow: 'auto'
|
|
35
|
+
}
|
|
36
|
+
}, /*#__PURE__*/React.createElement(GridList, {
|
|
37
|
+
itemKey: "url",
|
|
38
|
+
itemHeight: 300,
|
|
39
|
+
itemWidth: 250,
|
|
40
|
+
renderItem: function renderItem(image) {
|
|
41
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
style: {
|
|
43
|
+
border: '1px solid gray',
|
|
44
|
+
height: '100%',
|
|
45
|
+
display: 'flex',
|
|
46
|
+
flexDirection: 'column'
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
49
|
+
style: {
|
|
50
|
+
flex: 1,
|
|
51
|
+
overflow: 'hidden'
|
|
52
|
+
}
|
|
53
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
54
|
+
src: image.url,
|
|
55
|
+
style: {
|
|
56
|
+
objectFit: 'cover',
|
|
57
|
+
display: 'block',
|
|
58
|
+
width: '100%',
|
|
59
|
+
height: '100%'
|
|
60
|
+
}
|
|
61
|
+
})), /*#__PURE__*/React.createElement("p", null, "\u6807\u9898"), /*#__PURE__*/React.createElement("p", null, "\u63CF\u8FF0"));
|
|
62
|
+
},
|
|
63
|
+
loadNextPage: loadNextPage,
|
|
64
|
+
isNoMore: function isNoMore() {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default App;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface IDynamicGridListProps<T> {
|
|
3
|
+
itemKey: string;
|
|
4
|
+
itemHeight?: number;
|
|
5
|
+
itemWidth?: number;
|
|
6
|
+
loadNextPage: (d: IDynamicGridListResult<T>) => Promise<IDynamicGridListResult<T>>;
|
|
7
|
+
reloadDep?: any;
|
|
8
|
+
isNoMore: (d: any) => boolean;
|
|
9
|
+
renderItem: (item: T) => React.ReactNode;
|
|
10
|
+
className?: string;
|
|
11
|
+
getGridGap?: (elementWidth: number, windowHeight: number) => number;
|
|
12
|
+
}
|
|
13
|
+
export interface IDynamicGridListResult<T> {
|
|
14
|
+
list: T[];
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
declare function DynamicGridList<T>({ itemKey, itemHeight, itemWidth, loadNextPage, reloadDep, isNoMore, renderItem, className, getGridGap }: IDynamicGridListProps<T>): JSX.Element;
|
|
18
|
+
declare namespace DynamicGridList {
|
|
19
|
+
var defaultProps: {
|
|
20
|
+
itemWidth: number;
|
|
21
|
+
itemHeight: number;
|
|
22
|
+
className: string;
|
|
23
|
+
getGridGap: () => number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export default DynamicGridList;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _useUpdateEffect from "ahooks/es/useUpdateEffect";
|
|
2
|
+
import _useInfiniteScroll2 from "ahooks/es/useInfiniteScroll";
|
|
3
|
+
import React, { useRef } from 'react';
|
|
4
|
+
import GridList from '../GridList';
|
|
5
|
+
|
|
6
|
+
function DynamicGridList(_ref) {
|
|
7
|
+
var itemKey = _ref.itemKey,
|
|
8
|
+
itemHeight = _ref.itemHeight,
|
|
9
|
+
itemWidth = _ref.itemWidth,
|
|
10
|
+
loadNextPage = _ref.loadNextPage,
|
|
11
|
+
reloadDep = _ref.reloadDep,
|
|
12
|
+
isNoMore = _ref.isNoMore,
|
|
13
|
+
renderItem = _ref.renderItem,
|
|
14
|
+
className = _ref.className,
|
|
15
|
+
getGridGap = _ref.getGridGap;
|
|
16
|
+
var containerRef = useRef(null);
|
|
17
|
+
|
|
18
|
+
var _useInfiniteScroll = _useInfiniteScroll2(function (d) {
|
|
19
|
+
return loadNextPage(d);
|
|
20
|
+
}, {
|
|
21
|
+
target: containerRef,
|
|
22
|
+
threshold: 50,
|
|
23
|
+
isNoMore: isNoMore,
|
|
24
|
+
reloadDeps: [reloadDep]
|
|
25
|
+
}),
|
|
26
|
+
data = _useInfiniteScroll.data;
|
|
27
|
+
|
|
28
|
+
function getItemData(data) {
|
|
29
|
+
return {
|
|
30
|
+
key: data[itemKey],
|
|
31
|
+
height: itemHeight,
|
|
32
|
+
width: itemWidth
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getColumnCount(elementWidth, gridGap) {
|
|
37
|
+
return Math.floor((elementWidth + gridGap) / (itemWidth + gridGap));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getWindowMargin(windowHeight) {
|
|
41
|
+
return Math.round(windowHeight * 1.5);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_useUpdateEffect(function () {
|
|
45
|
+
var _a;
|
|
46
|
+
|
|
47
|
+
return (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
|
|
48
|
+
left: 0,
|
|
49
|
+
top: 0
|
|
50
|
+
});
|
|
51
|
+
}, [reloadDep]);
|
|
52
|
+
|
|
53
|
+
return /*#__PURE__*/React.createElement(GridList, {
|
|
54
|
+
className: "cloudapp-dynamic-grid-list ".concat(className),
|
|
55
|
+
items: (data === null || data === void 0 ? void 0 : data.list) || [],
|
|
56
|
+
ref: containerRef,
|
|
57
|
+
getItemData: getItemData,
|
|
58
|
+
getColumnCount: getColumnCount,
|
|
59
|
+
getWindowMargin: getWindowMargin,
|
|
60
|
+
renderItem: renderItem,
|
|
61
|
+
getGridGap: getGridGap
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
DynamicGridList.defaultProps = {
|
|
66
|
+
itemWidth: 250,
|
|
67
|
+
itemHeight: 300,
|
|
68
|
+
className: '',
|
|
69
|
+
getGridGap: function getGridGap() {
|
|
70
|
+
return 20;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export default DynamicGridList;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import GridList from './index';
|
|
3
|
+
var ITEM_WIDTH = 300;
|
|
4
|
+
|
|
5
|
+
function getGridGap(elementWidth, windowHeight) {
|
|
6
|
+
if (elementWidth > 720 && windowHeight > 480) {
|
|
7
|
+
return 20;
|
|
8
|
+
} else {
|
|
9
|
+
return 10;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getColumnCount(elementWidth, gridGap) {
|
|
14
|
+
return Math.floor((elementWidth + gridGap) / (ITEM_WIDTH + gridGap));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getWindowMargin(windowHeight) {
|
|
18
|
+
return Math.round(windowHeight * 1.5);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getItemData(image, columnWidth) {
|
|
22
|
+
return {
|
|
23
|
+
key: image.url,
|
|
24
|
+
height: 400,
|
|
25
|
+
width: 300
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function ImageGridList(props) {
|
|
30
|
+
return /*#__PURE__*/React.createElement(GridList, {
|
|
31
|
+
items: props.images,
|
|
32
|
+
getGridGap: getGridGap,
|
|
33
|
+
getColumnCount: getColumnCount,
|
|
34
|
+
getWindowMargin: getWindowMargin,
|
|
35
|
+
getItemData: getItemData,
|
|
36
|
+
fixedColumnWidth: props.fixed ? ITEM_WIDTH : null,
|
|
37
|
+
renderItem: function renderItem(image) {
|
|
38
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
39
|
+
style: {
|
|
40
|
+
border: '1px solid gray',
|
|
41
|
+
height: '100%',
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexDirection: 'column'
|
|
44
|
+
}
|
|
45
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
46
|
+
style: {
|
|
47
|
+
flex: 1,
|
|
48
|
+
overflow: 'hidden'
|
|
49
|
+
}
|
|
50
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
51
|
+
src: image.url,
|
|
52
|
+
style: {
|
|
53
|
+
objectFit: 'cover',
|
|
54
|
+
display: 'block',
|
|
55
|
+
width: '100%',
|
|
56
|
+
height: '100%'
|
|
57
|
+
}
|
|
58
|
+
})), /*#__PURE__*/React.createElement("p", null, "\u6807\u9898"), /*#__PURE__*/React.createElement("p", null, "\u63CF\u8FF0"));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function random(low, high) {
|
|
64
|
+
return Math.floor(Math.random() * high) + low;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var IMAGES = Array.from({
|
|
68
|
+
length: 10000
|
|
69
|
+
}, function (_, index) {
|
|
70
|
+
var width = 300;
|
|
71
|
+
var height = random(200, 300);
|
|
72
|
+
return {
|
|
73
|
+
url: "https://picsum.photos/id/".concat(index + 1, "/").concat(width, "/").concat(height, ".jpg"),
|
|
74
|
+
width: width,
|
|
75
|
+
height: height
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
var App = function App() {
|
|
80
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
81
|
+
style: {
|
|
82
|
+
height: 800,
|
|
83
|
+
overflow: 'auto'
|
|
84
|
+
}
|
|
85
|
+
}, /*#__PURE__*/React.createElement(ImageGridList, {
|
|
86
|
+
images: IMAGES,
|
|
87
|
+
fixed: false
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default App;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { GridListProps } from '.';
|
|
3
|
+
import { ConstRef, ElementScroll, ElementSize, GridListConfigData, GridListContainerData, GridListLayoutData, GridListRenderData } from './interface';
|
|
4
|
+
export declare function useConstRef<T>(value: T): ConstRef<T>;
|
|
5
|
+
export declare function useWindowSize(): ElementSize;
|
|
6
|
+
export declare function useElementSize(ref: RefObject<Element>): ElementSize | null;
|
|
7
|
+
export declare function useWindowScroll(): ElementScroll;
|
|
8
|
+
export declare function useElementWindowOffset(ref: RefObject<HTMLElement>): number;
|
|
9
|
+
export declare function useIntersecting(ref: RefObject<HTMLElement>, rootMargin: string): boolean;
|
|
10
|
+
export declare function useGridListContainerData(ref: RefObject<HTMLElement>): GridListContainerData;
|
|
11
|
+
export declare function useGridListConfigData<P>(containerData: GridListContainerData, props: GridListProps<P>): GridListConfigData<P> | null;
|
|
12
|
+
export declare function useGridListLayoutData<P>(configData: GridListConfigData<P> | null): GridListLayoutData<P> | null;
|
|
13
|
+
export declare function useGridListRenderData<P>(containerData: GridListContainerData, configData: GridListConfigData<P> | null, layoutData: GridListLayoutData<P> | null): GridListRenderData<P> | null;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import _useScroll from "ahooks/es/useScroll";
|
|
2
|
+
|
|
3
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
4
|
+
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
|
|
7
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
|
+
|
|
13
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
14
|
+
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
|
|
17
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
18
|
+
import { getColumnWidth, getElementOffset, getElementSize, getWindowScroll, getWindowSize, isSameElementScroll, isSameElementSize } from './utils';
|
|
19
|
+
export function useConstRef(value) {
|
|
20
|
+
var ref = useRef(value);
|
|
21
|
+
ref.current = value;
|
|
22
|
+
return ref;
|
|
23
|
+
}
|
|
24
|
+
export function useWindowSize() {
|
|
25
|
+
var _useState = useState(function () {
|
|
26
|
+
return getWindowSize();
|
|
27
|
+
}),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
windowSize = _useState2[0],
|
|
30
|
+
setWindowSize = _useState2[1];
|
|
31
|
+
|
|
32
|
+
var windowSizeRef = useConstRef(windowSize);
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
function onResize() {
|
|
35
|
+
var nextWindowSize = getWindowSize();
|
|
36
|
+
|
|
37
|
+
if (!isSameElementSize(windowSizeRef.current, nextWindowSize)) {
|
|
38
|
+
setWindowSize(nextWindowSize);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
window.addEventListener('resize', onResize);
|
|
43
|
+
return function () {
|
|
44
|
+
return window.removeEventListener('resize', onResize);
|
|
45
|
+
};
|
|
46
|
+
}, [windowSizeRef]);
|
|
47
|
+
return windowSize;
|
|
48
|
+
}
|
|
49
|
+
export function useElementSize(ref) {
|
|
50
|
+
var _useState3 = useState(function () {
|
|
51
|
+
if (ref.current) {
|
|
52
|
+
return getElementSize(ref.current);
|
|
53
|
+
} else {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
58
|
+
elementSize = _useState4[0],
|
|
59
|
+
setElementSize = _useState4[1];
|
|
60
|
+
|
|
61
|
+
var elementSizeRef = useConstRef(elementSize);
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
var observer = new ResizeObserver(function (entries) {
|
|
64
|
+
var nextElementSize = getElementSize(entries[0].target);
|
|
65
|
+
|
|
66
|
+
if (elementSizeRef.current === null || !isSameElementSize(elementSizeRef.current, nextElementSize)) {
|
|
67
|
+
setElementSize(nextElementSize);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (ref.current) observer.observe(ref.current);
|
|
71
|
+
return function () {
|
|
72
|
+
return observer.disconnect();
|
|
73
|
+
};
|
|
74
|
+
}, [ref]);
|
|
75
|
+
return elementSize;
|
|
76
|
+
}
|
|
77
|
+
export function useWindowScroll() {
|
|
78
|
+
var _useState5 = useState(getWindowScroll()),
|
|
79
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
80
|
+
scrollPosition = _useState6[0],
|
|
81
|
+
setScrollPosition = _useState6[1];
|
|
82
|
+
|
|
83
|
+
var ref = useConstRef(scrollPosition);
|
|
84
|
+
useEffect(function () {
|
|
85
|
+
function update() {
|
|
86
|
+
var nextScrollPosition = getWindowScroll();
|
|
87
|
+
|
|
88
|
+
if (!isSameElementScroll(ref.current, nextScrollPosition)) {
|
|
89
|
+
setScrollPosition(nextScrollPosition);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
window.addEventListener('scroll', update);
|
|
94
|
+
window.addEventListener('resize', update);
|
|
95
|
+
return function () {
|
|
96
|
+
window.removeEventListener('scroll', update);
|
|
97
|
+
window.removeEventListener('resize', update);
|
|
98
|
+
};
|
|
99
|
+
}, [ref]);
|
|
100
|
+
return scrollPosition;
|
|
101
|
+
}
|
|
102
|
+
export function useElementWindowOffset(ref) {
|
|
103
|
+
var _useState7 = useState(function () {
|
|
104
|
+
if (ref.current) {
|
|
105
|
+
return getElementOffset(ref.current);
|
|
106
|
+
} else {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
111
|
+
elementOffset = _useState8[0],
|
|
112
|
+
setElementOffset = _useState8[1];
|
|
113
|
+
|
|
114
|
+
useEffect(function () {
|
|
115
|
+
var observer = new ResizeObserver(function (entries) {
|
|
116
|
+
setElementOffset(getElementOffset(entries[0].target));
|
|
117
|
+
});
|
|
118
|
+
if (ref.current) observer.observe(ref.current);
|
|
119
|
+
return function () {
|
|
120
|
+
return observer.disconnect();
|
|
121
|
+
};
|
|
122
|
+
}, [ref]);
|
|
123
|
+
return elementOffset;
|
|
124
|
+
}
|
|
125
|
+
export function useIntersecting(ref, rootMargin) {
|
|
126
|
+
var _useState9 = useState(false),
|
|
127
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
128
|
+
intersecting = _useState10[0],
|
|
129
|
+
setIntersecting = _useState10[1];
|
|
130
|
+
|
|
131
|
+
useEffect(function () {
|
|
132
|
+
var observer = new IntersectionObserver(function (entries) {
|
|
133
|
+
setIntersecting(entries[0].isIntersecting);
|
|
134
|
+
}, {
|
|
135
|
+
rootMargin: rootMargin
|
|
136
|
+
});
|
|
137
|
+
if (ref.current) observer.observe(ref.current);
|
|
138
|
+
return function () {
|
|
139
|
+
return observer.disconnect();
|
|
140
|
+
};
|
|
141
|
+
}, [ref, rootMargin]);
|
|
142
|
+
return intersecting;
|
|
143
|
+
}
|
|
144
|
+
export function useGridListContainerData(ref) {
|
|
145
|
+
var windowSize = useWindowSize();
|
|
146
|
+
|
|
147
|
+
var windowScroll = _useScroll(ref);
|
|
148
|
+
|
|
149
|
+
var elementWindowOffset = useElementWindowOffset(ref);
|
|
150
|
+
var elementSize = useElementSize(ref);
|
|
151
|
+
return useMemo(function () {
|
|
152
|
+
return {
|
|
153
|
+
windowSize: windowSize,
|
|
154
|
+
windowScroll: {
|
|
155
|
+
x: (windowScroll === null || windowScroll === void 0 ? void 0 : windowScroll.left) || 0,
|
|
156
|
+
y: (windowScroll === null || windowScroll === void 0 ? void 0 : windowScroll.top) || 0
|
|
157
|
+
},
|
|
158
|
+
elementWindowOffset: elementWindowOffset,
|
|
159
|
+
elementSize: elementSize
|
|
160
|
+
};
|
|
161
|
+
}, [windowSize, windowScroll, elementWindowOffset, elementSize]);
|
|
162
|
+
}
|
|
163
|
+
export function useGridListConfigData(containerData, props) {
|
|
164
|
+
var items = props.items,
|
|
165
|
+
getWindowMargin = props.getWindowMargin,
|
|
166
|
+
getGridGap = props.getGridGap,
|
|
167
|
+
getColumnCount = props.getColumnCount,
|
|
168
|
+
getItemData = props.getItemData;
|
|
169
|
+
var elementWidth = containerData.elementSize ? containerData.elementSize.width : null;
|
|
170
|
+
var windowMargin = useMemo(function () {
|
|
171
|
+
if (getWindowMargin) {
|
|
172
|
+
return getWindowMargin(containerData.windowSize.height);
|
|
173
|
+
} else {
|
|
174
|
+
return containerData.windowSize.height;
|
|
175
|
+
}
|
|
176
|
+
}, [containerData.windowSize.height, getWindowMargin]);
|
|
177
|
+
var gridGap = useMemo(function () {
|
|
178
|
+
if (elementWidth === null) return null;
|
|
179
|
+
|
|
180
|
+
if (getGridGap) {
|
|
181
|
+
return getGridGap(elementWidth, containerData.windowSize.height);
|
|
182
|
+
} else {
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
}, [elementWidth, containerData.windowSize.height, getGridGap]);
|
|
186
|
+
var columnCount = useMemo(function () {
|
|
187
|
+
if (elementWidth === null) return null;
|
|
188
|
+
if (gridGap === null) return null;
|
|
189
|
+
return getColumnCount(elementWidth, gridGap);
|
|
190
|
+
}, [getColumnCount, elementWidth, gridGap]);
|
|
191
|
+
var columnWidth = getColumnWidth(columnCount, gridGap, elementWidth);
|
|
192
|
+
var entries = useMemo(function () {
|
|
193
|
+
if (columnWidth === null) return null;
|
|
194
|
+
var safeColumnWidth = columnWidth;
|
|
195
|
+
return items.map(function (item) {
|
|
196
|
+
return {
|
|
197
|
+
data: getItemData(item, safeColumnWidth),
|
|
198
|
+
item: item
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
}, [items, columnWidth, getItemData]);
|
|
202
|
+
return useMemo(function () {
|
|
203
|
+
if (windowMargin === null || gridGap === null || columnCount === null || entries === null) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
windowMargin: windowMargin,
|
|
209
|
+
gridGap: gridGap,
|
|
210
|
+
columnCount: columnCount,
|
|
211
|
+
entries: entries
|
|
212
|
+
};
|
|
213
|
+
}, [windowMargin, gridGap, columnCount, entries]);
|
|
214
|
+
}
|
|
215
|
+
export function useGridListLayoutData(configData) {
|
|
216
|
+
return useMemo(function () {
|
|
217
|
+
if (configData === null) return null;
|
|
218
|
+
var currentRowNumber = 1;
|
|
219
|
+
var prevRowsTotalHeight = 0;
|
|
220
|
+
var currentRowMaxHeight = 0;
|
|
221
|
+
var cells = configData.entries.map(function (entry, index) {
|
|
222
|
+
var key = entry.data.key;
|
|
223
|
+
var columnNumber = index % configData.columnCount + 1;
|
|
224
|
+
var rowNumber = Math.floor(index / configData.columnCount) + 1;
|
|
225
|
+
|
|
226
|
+
if (rowNumber !== currentRowNumber) {
|
|
227
|
+
currentRowNumber = rowNumber;
|
|
228
|
+
prevRowsTotalHeight += currentRowMaxHeight + configData.gridGap;
|
|
229
|
+
currentRowMaxHeight = 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
var offset = prevRowsTotalHeight;
|
|
233
|
+
var height = Math.round(entry.data.height);
|
|
234
|
+
var width = Math.round(entry.data.width);
|
|
235
|
+
currentRowMaxHeight = Math.max(currentRowMaxHeight, height);
|
|
236
|
+
return {
|
|
237
|
+
key: key,
|
|
238
|
+
columnNumber: columnNumber,
|
|
239
|
+
rowNumber: rowNumber,
|
|
240
|
+
offset: offset,
|
|
241
|
+
height: height,
|
|
242
|
+
width: width,
|
|
243
|
+
item: entry.item
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
var totalHeight = prevRowsTotalHeight + currentRowMaxHeight;
|
|
247
|
+
return {
|
|
248
|
+
totalHeight: totalHeight,
|
|
249
|
+
cells: cells
|
|
250
|
+
};
|
|
251
|
+
}, [configData]);
|
|
252
|
+
}
|
|
253
|
+
export function useGridListRenderData(containerData, configData, layoutData) {
|
|
254
|
+
return useMemo(function () {
|
|
255
|
+
if (layoutData === null || configData === null) return null;
|
|
256
|
+
var cellsToRender = [];
|
|
257
|
+
var firstRenderedRowNumber = null;
|
|
258
|
+
var firstRenderedRowOffset = null;
|
|
259
|
+
|
|
260
|
+
if (containerData.elementWindowOffset !== null) {
|
|
261
|
+
var elementWindowOffset = containerData.elementWindowOffset;
|
|
262
|
+
|
|
263
|
+
var _iterator = _createForOfIteratorHelper(layoutData.cells),
|
|
264
|
+
_step;
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
268
|
+
var cell = _step.value;
|
|
269
|
+
var cellTop = elementWindowOffset + cell.offset;
|
|
270
|
+
var cellBottom = cellTop + cell.height;
|
|
271
|
+
var windowTop = containerData.windowScroll.y;
|
|
272
|
+
var windowBottom = windowTop + containerData.windowSize.height;
|
|
273
|
+
var renderTop = windowTop - configData.windowMargin;
|
|
274
|
+
var renderBottom = windowBottom + configData.windowMargin;
|
|
275
|
+
if (cellTop > renderBottom) continue;
|
|
276
|
+
if (cellBottom < renderTop) continue;
|
|
277
|
+
|
|
278
|
+
if (firstRenderedRowNumber === null) {
|
|
279
|
+
firstRenderedRowNumber = cell.rowNumber;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (cell.rowNumber === firstRenderedRowNumber) {
|
|
283
|
+
firstRenderedRowOffset = firstRenderedRowOffset ? Math.min(firstRenderedRowOffset, cell.offset) : cell.offset;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
cellsToRender.push(cell);
|
|
287
|
+
}
|
|
288
|
+
} catch (err) {
|
|
289
|
+
_iterator.e(err);
|
|
290
|
+
} finally {
|
|
291
|
+
_iterator.f();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
cellsToRender: cellsToRender,
|
|
297
|
+
firstRenderedRowNumber: firstRenderedRowNumber,
|
|
298
|
+
firstRenderedRowOffset: firstRenderedRowOffset
|
|
299
|
+
};
|
|
300
|
+
}, [layoutData, configData, containerData.windowScroll.y, containerData.windowSize.height, containerData.elementWindowOffset]);
|
|
301
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { GridListItemData } from './interface';
|
|
3
|
+
import './index.less';
|
|
4
|
+
export interface GridListProps<P> {
|
|
5
|
+
items: P[];
|
|
6
|
+
getGridGap?: (elementWidth: number, windowHeight: number) => number;
|
|
7
|
+
getWindowMargin?: (windowHeight: number) => number;
|
|
8
|
+
getColumnCount: (elementWidth: number, gridGap: number) => number;
|
|
9
|
+
getItemData: (item: P, columnWidth: number) => GridListItemData;
|
|
10
|
+
renderItem: (item: P) => React.ReactNode;
|
|
11
|
+
fixedColumnWidth?: number;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const _default: React.ForwardRefExoticComponent<GridListProps<any> & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { useRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { useGridListConfigData, useGridListContainerData, useGridListLayoutData, useGridListRenderData, useIntersecting } from './hook';
|
|
3
|
+
import { getGridRowStart } from './utils';
|
|
4
|
+
import "./index.css";
|
|
5
|
+
|
|
6
|
+
function GridList(props, ref) {
|
|
7
|
+
var containerRef = useRef(null);
|
|
8
|
+
var containerData = useGridListContainerData(containerRef);
|
|
9
|
+
var configData = useGridListConfigData(containerData, props);
|
|
10
|
+
var layoutData = useGridListLayoutData(configData);
|
|
11
|
+
var renderData = useGridListRenderData(containerData, configData, layoutData);
|
|
12
|
+
var intersecting = useIntersecting(containerRef, "".concat(configData !== null ? configData.windowMargin : 0, "px"));
|
|
13
|
+
var colWidth = props.fixedColumnWidth ? "".concat(props.fixedColumnWidth, "px") : '1fr';
|
|
14
|
+
useImperativeHandle(ref, function () {
|
|
15
|
+
return containerRef.current;
|
|
16
|
+
}, []);
|
|
17
|
+
console.log(renderData);
|
|
18
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
19
|
+
ref: containerRef,
|
|
20
|
+
className: "cloudapp-grid-list ".concat(props.className || '')
|
|
21
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
22
|
+
style: {
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
height: layoutData !== null ? layoutData.totalHeight : undefined,
|
|
25
|
+
paddingTop: renderData !== null && renderData.firstRenderedRowOffset !== null ? renderData.firstRenderedRowOffset : 0
|
|
26
|
+
}
|
|
27
|
+
}, intersecting && /*#__PURE__*/React.createElement("div", {
|
|
28
|
+
style: {
|
|
29
|
+
display: 'grid',
|
|
30
|
+
gridTemplateColumns: configData !== null ? "repeat(".concat(configData.columnCount, ", ").concat(colWidth, ")") : undefined,
|
|
31
|
+
gridGap: configData ? configData.gridGap : undefined,
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
alignItems: 'center'
|
|
34
|
+
}
|
|
35
|
+
}, renderData !== null && renderData.cellsToRender.map(function (cell) {
|
|
36
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
37
|
+
key: cell.key,
|
|
38
|
+
style: {
|
|
39
|
+
height: cell.height,
|
|
40
|
+
gridColumnStart: "".concat(cell.columnNumber),
|
|
41
|
+
gridRowStart: getGridRowStart(cell, renderData)
|
|
42
|
+
}
|
|
43
|
+
}, props.renderItem(cell.item));
|
|
44
|
+
}))));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default /*#__PURE__*/React.forwardRef(GridList);
|