@kne/super-select 0.1.48 → 0.1.50
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/README.md +70 -18
- package/dist/index.js +168 -12
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +170 -11
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.modern.js
CHANGED
|
@@ -6,7 +6,7 @@ import useControlValue from '@kne/use-control-value';
|
|
|
6
6
|
import classnames from 'classnames';
|
|
7
7
|
import isEqual from 'lodash/isEqual';
|
|
8
8
|
import last from 'lodash/last';
|
|
9
|
-
import { Tag, Modal, App, Dropdown, Flex, Checkbox, List, Empty, Row, Col, Button, Popover, Tree, Space, Badge, Spin } from 'antd';
|
|
9
|
+
import { Tag, Modal, App, Dropdown, Flex, Checkbox, List, Empty, Pagination, Row, Col, Button, Popover, Tree, Space, Badge, Spin } from 'antd';
|
|
10
10
|
import { CloseCircleFilled, DownOutlined, CheckOutlined, RightOutlined } from '@ant-design/icons';
|
|
11
11
|
import { isNotEmpty } from '@kne/is-empty';
|
|
12
12
|
import { usePopupContainer, useScrollElement, useMobilePopupMount, MOBILE_POPUP_MODE } from '@kne/responsive-utils';
|
|
@@ -19,14 +19,14 @@ import SearchInput from '@kne/search-input';
|
|
|
19
19
|
import { FetchScrollLoader } from '@kne/scroll-loader';
|
|
20
20
|
import '@kne/scroll-loader/dist/index.css';
|
|
21
21
|
import merge from 'lodash/merge';
|
|
22
|
-
import
|
|
23
|
-
export { mergeTreeChildren } from '@kne/table-
|
|
24
|
-
import '@kne/table-
|
|
22
|
+
import { Table, hasColumnWidth, isTreeDataType, normalizeTreeData, flattenAllTree } from '@kne/table-view';
|
|
23
|
+
export { mergeTreeChildren } from '@kne/table-view';
|
|
24
|
+
import '@kne/table-view/dist/index.css';
|
|
25
|
+
import Fetch, { withFetch } from '@kne/react-fetch';
|
|
25
26
|
import { CentralContent } from '@kne/info-page';
|
|
26
27
|
import '@kne/info-page/dist/index.css';
|
|
27
28
|
import memoize from 'lodash/memoize';
|
|
28
29
|
import isNil from 'lodash/isNil';
|
|
29
|
-
import Fetch from '@kne/react-fetch';
|
|
30
30
|
|
|
31
31
|
function _extends() {
|
|
32
32
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
@@ -181,7 +181,7 @@ const TagOverflowInner = ({
|
|
|
181
181
|
}, "+", hiddenCount) : null));
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
-
const _excluded$
|
|
184
|
+
const _excluded$4 = ["children"];
|
|
185
185
|
const MOBILE_SHEET_MAX_HEIGHT = '80%';
|
|
186
186
|
const MOBILE_SHEET_MIN_HEIGHT = '30%';
|
|
187
187
|
const MOBILE_MASK_Z_INDEX = 1000;
|
|
@@ -259,7 +259,7 @@ const ModalContent = _ref => {
|
|
|
259
259
|
let {
|
|
260
260
|
children: renderContent
|
|
261
261
|
} = _ref,
|
|
262
|
-
others = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
262
|
+
others = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
263
263
|
const {
|
|
264
264
|
open,
|
|
265
265
|
value: propsValue
|
|
@@ -966,12 +966,12 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
966
966
|
|
|
967
967
|
var style$3 = {"kne-responsive-boundary":"kne-super-select_Nc-y4","kne-responsive-scroll":"kne-super-select_RlrDm","list":"kne-super-select_IsXdU","empty":"kne-super-select_SQZ8k","default-list":"kne-super-select_QD1Mz","is-selected-all":"kne-super-select_M-mOy","default-list-item":"kne-super-select_KtOsz","is-selected":"kne-super-select_TQhBB","single-checked":"kne-super-select_2rUrh","is-disabled":"kne-super-select_NbwX5","selected-all":"kne-super-select_vN2Fx","selected-tag":"kne-super-select_6oITk","select-search":"kne-super-select_iAH9D","select-list-item-description":"kne-super-select_TCkeJ","footer":"kne-super-select_v3f23","is-mobile":"kne-super-select_w-WB8"};
|
|
968
968
|
|
|
969
|
-
const _excluded$
|
|
969
|
+
const _excluded$3 = ["children"];
|
|
970
970
|
const SelectList = forwardRef((_ref, ref) => {
|
|
971
971
|
let {
|
|
972
972
|
children
|
|
973
973
|
} = _ref,
|
|
974
|
-
p = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
974
|
+
p = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
975
975
|
const fetchListRef = useRef(null);
|
|
976
976
|
const props = Object.assign({}, {
|
|
977
977
|
renderItemContent: ({
|
|
@@ -1181,6 +1181,165 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
1181
1181
|
|
|
1182
1182
|
var style$2 = {"body":"kne-super-select_704J1","is-mobile":"kne-super-select_HYGUN","table-panel-wrap":"kne-super-select_Boo1a","selected-panel-wrap":"kne-super-select_q-BjK","table-panel":"kne-super-select_UAejp","filter-wrap":"kne-super-select_gmlBv","table":"kne-super-select_zE-14","list":"kne-super-select_DrEYJ","is-fit-columns":"kne-super-select_QqZxW","empty":"kne-super-select_5Tyrt","right-options-col":"kne-super-select_sNBrJ","right-options":"kne-super-select_UXi-g","no-padding-btn":"kne-super-select_iaCir","selected-tags-scroll":"kne-super-select_b-3Xk","tag":"kne-super-select_JkYqS","tag-inner":"kne-super-select_VZlBL","single-checked":"kne-super-select_Eiz-u","select-search":"kne-super-select_temy6","tags-search":"kne-super-select_7phL2","descriptions":"kne-super-select_ttNK9","footer":"kne-super-select_lISfA"};
|
|
1183
1183
|
|
|
1184
|
+
const _excluded$2 = ["data", "reload", "refresh", "requestParams", "fetchProps", "dataFormat", "pagination", "columns", "columnRenderProps"];
|
|
1185
|
+
const defaultDataFormat = data => ({
|
|
1186
|
+
list: data == null ? void 0 : data.pageData,
|
|
1187
|
+
total: data == null ? void 0 : data.totalCount,
|
|
1188
|
+
data
|
|
1189
|
+
});
|
|
1190
|
+
const FetchTableContent = _ref => {
|
|
1191
|
+
let {
|
|
1192
|
+
data,
|
|
1193
|
+
reload,
|
|
1194
|
+
refresh,
|
|
1195
|
+
requestParams,
|
|
1196
|
+
fetchProps,
|
|
1197
|
+
dataFormat = defaultDataFormat,
|
|
1198
|
+
pagination,
|
|
1199
|
+
columns,
|
|
1200
|
+
columnRenderProps
|
|
1201
|
+
} = _ref,
|
|
1202
|
+
tableProps = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
1203
|
+
const paginationMerged = Object.assign({
|
|
1204
|
+
open: true,
|
|
1205
|
+
paramsType: 'data',
|
|
1206
|
+
requestType: 'reload',
|
|
1207
|
+
currentName: 'currentPage',
|
|
1208
|
+
pageSizeName: 'perPage',
|
|
1209
|
+
pageSize: 20,
|
|
1210
|
+
showSizeChanger: false,
|
|
1211
|
+
showQuickJumper: false,
|
|
1212
|
+
hideOnSinglePage: true
|
|
1213
|
+
}, pagination);
|
|
1214
|
+
const formatData = dataFormat(data);
|
|
1215
|
+
const tableContext = Object.assign({}, columnRenderProps, {
|
|
1216
|
+
data,
|
|
1217
|
+
requestParams,
|
|
1218
|
+
fetchProps
|
|
1219
|
+
});
|
|
1220
|
+
const currentPage = get(requestParams, [paginationMerged.paramsType, paginationMerged.currentName], 1);
|
|
1221
|
+
const currentPageSize = Number(get(requestParams, [paginationMerged.paramsType, paginationMerged.pageSizeName], paginationMerged.pageSize)) || paginationMerged.pageSize || 20;
|
|
1222
|
+
const hasMore = formatData.total > currentPage * currentPageSize;
|
|
1223
|
+
const showPagination = paginationMerged.open && formatData.total > 0;
|
|
1224
|
+
const isLoadMoreMode = !paginationMerged.open;
|
|
1225
|
+
const [accumulatedList, setAccumulatedList] = useState([]);
|
|
1226
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
1227
|
+
const isLoadingMoreRef = useRef(false);
|
|
1228
|
+
const prevDataRef = useRef(null);
|
|
1229
|
+
const containerRef = useRef(null);
|
|
1230
|
+
useEffect(() => {
|
|
1231
|
+
if (!isLoadMoreMode) return;
|
|
1232
|
+
if (data === prevDataRef.current) return;
|
|
1233
|
+
prevDataRef.current = data;
|
|
1234
|
+
const newList = formatData.list || [];
|
|
1235
|
+
if (currentPage <= 1) {
|
|
1236
|
+
setAccumulatedList(newList);
|
|
1237
|
+
} else {
|
|
1238
|
+
setAccumulatedList(prev => prev.concat(newList));
|
|
1239
|
+
}
|
|
1240
|
+
setIsLoadingMore(false);
|
|
1241
|
+
isLoadingMoreRef.current = false;
|
|
1242
|
+
}, [data, isLoadMoreMode, currentPage, formatData.list]);
|
|
1243
|
+
const doLoadNextPage = useCallback(() => {
|
|
1244
|
+
if (isLoadingMoreRef.current || !hasMore || !isLoadMoreMode) return;
|
|
1245
|
+
isLoadingMoreRef.current = true;
|
|
1246
|
+
setIsLoadingMore(true);
|
|
1247
|
+
const nextPage = currentPage + 1;
|
|
1248
|
+
const currentParams = get(requestParams, paginationMerged.paramsType, {});
|
|
1249
|
+
(paginationMerged.requestType === 'refresh' ? refresh : reload)({
|
|
1250
|
+
[paginationMerged.paramsType]: Object.assign({}, currentParams, {
|
|
1251
|
+
[paginationMerged.currentName]: nextPage,
|
|
1252
|
+
[paginationMerged.pageSizeName]: currentPageSize
|
|
1253
|
+
})
|
|
1254
|
+
});
|
|
1255
|
+
}, [hasMore, isLoadMoreMode, currentPage, requestParams, paginationMerged, refresh, reload, currentPageSize]);
|
|
1256
|
+
useEffect(() => {
|
|
1257
|
+
if (!isLoadMoreMode) return;
|
|
1258
|
+
const container = containerRef.current;
|
|
1259
|
+
if (!container) return;
|
|
1260
|
+
const scrollEl = container.querySelector('.ant-table-body') || container.closest('.select-table-list-scroll-list');
|
|
1261
|
+
if (!scrollEl) return;
|
|
1262
|
+
const onScroll = () => {
|
|
1263
|
+
const {
|
|
1264
|
+
scrollTop,
|
|
1265
|
+
scrollHeight,
|
|
1266
|
+
clientHeight
|
|
1267
|
+
} = scrollEl;
|
|
1268
|
+
if (scrollHeight - scrollTop - clientHeight < 50) {
|
|
1269
|
+
doLoadNextPage();
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
scrollEl.addEventListener('scroll', onScroll, {
|
|
1273
|
+
passive: true
|
|
1274
|
+
});
|
|
1275
|
+
return () => scrollEl.removeEventListener('scroll', onScroll);
|
|
1276
|
+
}, [isLoadMoreMode, doLoadNextPage]);
|
|
1277
|
+
|
|
1278
|
+
// 如果当前列表高度没有超过容器(弹窗模式可能不出现滚动条),
|
|
1279
|
+
// 仅靠 scroll 事件无法触发 loadMore:自动补页直到出现溢出或没有更多。
|
|
1280
|
+
const autoLoadCountRef = useRef(0);
|
|
1281
|
+
useEffect(() => {
|
|
1282
|
+
if (!isLoadMoreMode) return;
|
|
1283
|
+
if (isLoadingMoreRef.current) return;
|
|
1284
|
+
if (!hasMore) return;
|
|
1285
|
+
const container = containerRef.current;
|
|
1286
|
+
if (!container) return;
|
|
1287
|
+
const scrollEl = container.querySelector('.ant-table-body') || container.closest('.select-table-list-scroll-list');
|
|
1288
|
+
if (!scrollEl) return;
|
|
1289
|
+
const isOverflowing = scrollEl.scrollHeight > scrollEl.clientHeight + 1;
|
|
1290
|
+
if (isOverflowing) {
|
|
1291
|
+
autoLoadCountRef.current = 0;
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (autoLoadCountRef.current >= 5) return;
|
|
1295
|
+
autoLoadCountRef.current += 1;
|
|
1296
|
+
setTimeout(() => doLoadNextPage(), 0);
|
|
1297
|
+
}, [isLoadMoreMode, hasMore, data, currentPage, currentPageSize, doLoadNextPage]);
|
|
1298
|
+
const displayList = isLoadMoreMode ? accumulatedList : formatData.list || [];
|
|
1299
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1300
|
+
ref: containerRef
|
|
1301
|
+
}, /*#__PURE__*/React.createElement(Table, _extends({}, tableProps, {
|
|
1302
|
+
dataSource: displayList,
|
|
1303
|
+
pagination: false,
|
|
1304
|
+
columns: columns,
|
|
1305
|
+
context: tableContext,
|
|
1306
|
+
columnRenderProps: tableContext
|
|
1307
|
+
})), showPagination ? /*#__PURE__*/React.createElement("div", {
|
|
1308
|
+
style: {
|
|
1309
|
+
padding: '8px 12px',
|
|
1310
|
+
display: 'flex',
|
|
1311
|
+
justifyContent: 'flex-end'
|
|
1312
|
+
}
|
|
1313
|
+
}, /*#__PURE__*/React.createElement(Pagination, {
|
|
1314
|
+
size: "small",
|
|
1315
|
+
total: formatData.total,
|
|
1316
|
+
current: currentPage,
|
|
1317
|
+
pageSize: currentPageSize,
|
|
1318
|
+
showSizeChanger: paginationMerged.showSizeChanger,
|
|
1319
|
+
showQuickJumper: paginationMerged.showQuickJumper,
|
|
1320
|
+
hideOnSinglePage: paginationMerged.hideOnSinglePage,
|
|
1321
|
+
onChange: (page, size) => {
|
|
1322
|
+
const currentParams = get(requestParams, paginationMerged.paramsType, {});
|
|
1323
|
+
(paginationMerged.requestType === 'refresh' ? refresh : reload)({
|
|
1324
|
+
[paginationMerged.paramsType]: Object.assign({}, currentParams, {
|
|
1325
|
+
[paginationMerged.currentName]: page,
|
|
1326
|
+
[paginationMerged.pageSizeName]: size
|
|
1327
|
+
})
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
})) : null, isLoadMoreMode ? /*#__PURE__*/React.createElement("div", {
|
|
1331
|
+
style: {
|
|
1332
|
+
textAlign: 'center',
|
|
1333
|
+
padding: '8px 0',
|
|
1334
|
+
color: '#999',
|
|
1335
|
+
fontSize: 12,
|
|
1336
|
+
height: 32,
|
|
1337
|
+
visibility: isLoadingMore ? 'visible' : 'hidden'
|
|
1338
|
+
}
|
|
1339
|
+
}, "\u52A0\u8F7D\u4E2D...") : null);
|
|
1340
|
+
};
|
|
1341
|
+
const FetchTable = withFetch(FetchTableContent);
|
|
1342
|
+
|
|
1184
1343
|
const isEmptyParentKey = value => value == null || value === '';
|
|
1185
1344
|
const flattenSelectList = (list, {
|
|
1186
1345
|
dataType,
|
|
@@ -1521,13 +1680,13 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
1521
1680
|
'is-popup': isPopup,
|
|
1522
1681
|
[style$2['is-fit-columns']]: !allColumnsHaveWidth
|
|
1523
1682
|
})
|
|
1524
|
-
}, /*#__PURE__*/React.createElement(
|
|
1683
|
+
}, /*#__PURE__*/React.createElement(FetchTable, _extends({}, tablePageFetchConfig, {
|
|
1525
1684
|
ref: tablePageRef
|
|
1526
1685
|
}, dataFormat ? {
|
|
1527
1686
|
dataFormat
|
|
1528
1687
|
} : null, {
|
|
1529
1688
|
pagination: Object.assign({
|
|
1530
|
-
open:
|
|
1689
|
+
open: true,
|
|
1531
1690
|
showSizeChanger: false,
|
|
1532
1691
|
showQuickJumper: false,
|
|
1533
1692
|
hideOnSinglePage: true
|