@kne/table-page 0.1.42 → 0.1.43
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 +5 -3
- package/dist/index.js +60 -17
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +65 -19
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -160,14 +160,22 @@ const _excluded$1 = ["getPopupContainer"],
|
|
|
160
160
|
_excluded2$1 = ["list", "displayLine", "extraExpand", "className", "searchParamsValue", "mapFilterValue", "value", "defaultValue", "onChange"],
|
|
161
161
|
_excluded3$1 = ["className", "style"];
|
|
162
162
|
const TAB_ALL_KEY = '__all__';
|
|
163
|
-
const
|
|
163
|
+
const isTabShowAll = tab => (tab == null ? void 0 : tab.showAll) !== false;
|
|
164
|
+
const getTabFirstKey = tab => {
|
|
165
|
+
var _tab$list;
|
|
166
|
+
return (tab == null || (_tab$list = tab.list) == null ? void 0 : _tab$list[0]) != null ? String(tab.list[0].value) : TAB_ALL_KEY;
|
|
167
|
+
};
|
|
168
|
+
const getTabActiveKey = (filterValue, tab) => {
|
|
164
169
|
var _entry$value;
|
|
170
|
+
const tabName = tab == null ? void 0 : tab.name;
|
|
171
|
+
const showAll = isTabShowAll(tab);
|
|
172
|
+
const fallbackKey = showAll ? TAB_ALL_KEY : getTabFirstKey(tab);
|
|
165
173
|
if (!tabName || !Array.isArray(filterValue)) {
|
|
166
|
-
return
|
|
174
|
+
return fallbackKey;
|
|
167
175
|
}
|
|
168
176
|
const entry = filterValue.find(item => (item == null ? void 0 : item.name) === tabName);
|
|
169
177
|
const value = entry == null || (_entry$value = entry.value) == null ? void 0 : _entry$value.value;
|
|
170
|
-
return value == null || value === '' ?
|
|
178
|
+
return value == null || value === '' ? fallbackKey : String(value);
|
|
171
179
|
};
|
|
172
180
|
const TablePageTabs = ({
|
|
173
181
|
filterValue,
|
|
@@ -183,6 +191,7 @@ const TablePageTabs = ({
|
|
|
183
191
|
const getPopupContainer = usePopupContainer();
|
|
184
192
|
const isMobile = useIsMobile();
|
|
185
193
|
const showTab = !!(tab != null && tab.name && Array.isArray(tab.list) && tab.list.length > 0);
|
|
194
|
+
const showAll = isTabShowAll(tab);
|
|
186
195
|
const _ref = tabProps || {},
|
|
187
196
|
{
|
|
188
197
|
getPopupContainer: userGetPopupContainer
|
|
@@ -192,16 +201,20 @@ const TablePageTabs = ({
|
|
|
192
201
|
if (!showTab) {
|
|
193
202
|
return [];
|
|
194
203
|
}
|
|
204
|
+
const items = tab.list.map(item => ({
|
|
205
|
+
key: String(item.value),
|
|
206
|
+
label: item.label
|
|
207
|
+
}));
|
|
208
|
+
if (!showAll) {
|
|
209
|
+
return items;
|
|
210
|
+
}
|
|
195
211
|
return [{
|
|
196
212
|
key: TAB_ALL_KEY,
|
|
197
213
|
label: formatMessage({
|
|
198
214
|
id: 'All'
|
|
199
215
|
})
|
|
200
|
-
}, ...
|
|
201
|
-
|
|
202
|
-
label: item.label
|
|
203
|
-
}))];
|
|
204
|
-
}, [showTab, tab == null ? void 0 : tab.list, formatMessage]);
|
|
216
|
+
}, ...items];
|
|
217
|
+
}, [showTab, showAll, tab == null ? void 0 : tab.list, formatMessage]);
|
|
205
218
|
if (!showTab) {
|
|
206
219
|
return null;
|
|
207
220
|
}
|
|
@@ -230,7 +243,7 @@ const TablePageTabs = ({
|
|
|
230
243
|
size: isMobile ? 'middle' : 'small'
|
|
231
244
|
}, restTabProps, {
|
|
232
245
|
getPopupContainer: userGetPopupContainer != null ? userGetPopupContainer : getPopupContainer,
|
|
233
|
-
activeKey: getTabActiveKey(filterValue, tab
|
|
246
|
+
activeKey: getTabActiveKey(filterValue, tab),
|
|
234
247
|
onChange: handleTabChange,
|
|
235
248
|
items: tabItems
|
|
236
249
|
}))
|
|
@@ -865,7 +878,7 @@ const isPaginationSearchParamsEnabled = pagination => {
|
|
|
865
878
|
|
|
866
879
|
const _excluded = ["data", "refresh", "reload", "requestParams", "fetchProps", "isComplete", "loadMore", "send", "dataFormat", "className", "columns", "getColumns", "pagination", "columnRenderProps", "summary", "sticky", "scrollTopInset", "stickyOffset", "renderType", "horizontalScroller", "getScrollContainer", "filter", "search", "tab", "tabProps", "batchActions", "buttonGroup", "selectedRows", "rowSelection", "renderMobile", "renderCard", "forceCard", "mobileSortToolbar", "filterSeedParams", "filterFetchApiRef"],
|
|
867
880
|
_excluded2 = ["loading"],
|
|
868
|
-
_excluded3 = ["pagination", "horizontalScroller", "getScrollContainer", "filter"],
|
|
881
|
+
_excluded3 = ["pagination", "horizontalScroller", "getScrollContainer", "filter", "tab"],
|
|
869
882
|
_excluded4 = ["searchParamsValue"];
|
|
870
883
|
const noop = () => {};
|
|
871
884
|
const EMPTY_COLUMN_RENDER_PROPS = {};
|
|
@@ -1122,6 +1135,33 @@ const resolveInitialFilterValue = filter => {
|
|
|
1122
1135
|
}
|
|
1123
1136
|
return filter.defaultValue || [];
|
|
1124
1137
|
};
|
|
1138
|
+
|
|
1139
|
+
/** tab.showAll === false 时无「全部」,缺省写入 list 首项,保证 UI 与首包请求一致 */
|
|
1140
|
+
const buildTabDefaultFilterEntry = tab => {
|
|
1141
|
+
if ((tab == null ? void 0 : tab.showAll) !== false || !(tab != null && tab.name) || !Array.isArray(tab.list) || tab.list.length === 0) {
|
|
1142
|
+
return null;
|
|
1143
|
+
}
|
|
1144
|
+
const option = tab.list[0];
|
|
1145
|
+
return {
|
|
1146
|
+
name: tab.name,
|
|
1147
|
+
label: tab.label,
|
|
1148
|
+
value: {
|
|
1149
|
+
value: option.value,
|
|
1150
|
+
label: option.label
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
};
|
|
1154
|
+
const mergeTabDefaultFilterValue = (value, tab) => {
|
|
1155
|
+
const entry = buildTabDefaultFilterEntry(tab);
|
|
1156
|
+
if (!entry) {
|
|
1157
|
+
return Array.isArray(value) ? value : [];
|
|
1158
|
+
}
|
|
1159
|
+
const list = Array.isArray(value) ? value : [];
|
|
1160
|
+
if (list.some(item => (item == null ? void 0 : item.name) === tab.name)) {
|
|
1161
|
+
return list;
|
|
1162
|
+
}
|
|
1163
|
+
return list.concat(entry);
|
|
1164
|
+
};
|
|
1125
1165
|
const readPageSize = key => {
|
|
1126
1166
|
try {
|
|
1127
1167
|
const value = localStorage.getItem(key);
|
|
@@ -1788,7 +1828,8 @@ const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
|
|
|
1788
1828
|
pagination,
|
|
1789
1829
|
horizontalScroller = true,
|
|
1790
1830
|
getScrollContainer,
|
|
1791
|
-
filter: filterProp
|
|
1831
|
+
filter: filterProp,
|
|
1832
|
+
tab
|
|
1792
1833
|
} = _ref6,
|
|
1793
1834
|
props = _objectWithoutPropertiesLoose(_ref6, _excluded3);
|
|
1794
1835
|
pagination = Object.assign({}, {
|
|
@@ -1827,6 +1868,12 @@ const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
|
|
|
1827
1868
|
} = searchParamsSnapshot;
|
|
1828
1869
|
const filter = useMemo(() => {
|
|
1829
1870
|
if (!filterProp) {
|
|
1871
|
+
// showAll:false 时仍需 defaultValue 写入首项,否则首包无 tab 筛选
|
|
1872
|
+
if ((tab == null ? void 0 : tab.showAll) === false) {
|
|
1873
|
+
return {
|
|
1874
|
+
defaultValue: mergeTabDefaultFilterValue([], tab)
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1830
1877
|
return filterProp;
|
|
1831
1878
|
}
|
|
1832
1879
|
const rest = _objectWithoutPropertiesLoose(filterProp, _excluded4);
|
|
@@ -1834,18 +1881,16 @@ const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
|
|
|
1834
1881
|
return rest;
|
|
1835
1882
|
}
|
|
1836
1883
|
return Object.assign({}, rest, {
|
|
1837
|
-
defaultValue: mergeFilterByName(filterProp.defaultValue || [], fromUrl)
|
|
1884
|
+
defaultValue: mergeTabDefaultFilterValue(mergeFilterByName(filterProp.defaultValue || [], fromUrl), tab)
|
|
1838
1885
|
});
|
|
1839
|
-
}, [filterProp, fromUrl]);
|
|
1886
|
+
}, [filterProp, fromUrl, tab]);
|
|
1840
1887
|
const params = props[pagination.paramsType];
|
|
1841
1888
|
// 仅作首包种子;后续筛选走 handleFilterChange → reload,避免受控 value 变化改 requestToken 触发 refresh 卸载表格
|
|
1842
1889
|
const [filterDefaultParams] = useState(() => {
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
const initialValue = 'value' in filterProp ? mergeFilterByName(filterProp.value || [], fromUrl) : mergeFilterByName(filterProp.defaultValue || [], fromUrl);
|
|
1848
|
-
if (!initialValue.length && !filterProp.mapFilterValue) {
|
|
1890
|
+
const mapFn = (filterProp == null ? void 0 : filterProp.mapFilterValue) || getFilterValue;
|
|
1891
|
+
const baseValue = filterProp ? 'value' in filterProp ? mergeFilterByName(filterProp.value || [], fromUrl) : mergeFilterByName(filterProp.defaultValue || [], fromUrl) : [];
|
|
1892
|
+
const initialValue = mergeTabDefaultFilterValue(baseValue, tab);
|
|
1893
|
+
if (!initialValue.length && !(filterProp != null && filterProp.mapFilterValue)) {
|
|
1849
1894
|
return {};
|
|
1850
1895
|
}
|
|
1851
1896
|
return mapFn(initialValue) || {};
|
|
@@ -1879,6 +1924,7 @@ const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
|
|
|
1879
1924
|
};
|
|
1880
1925
|
}, [params, pagination.pageSizeName, pagination.paramsType, pagination.currentName, pageSize, filterDefaultParams, paginationUrlEnabled, initialCurrent]);
|
|
1881
1926
|
return /*#__PURE__*/jsx(TablePageInner, _extends({}, props, fetchParams, {
|
|
1927
|
+
tab: tab,
|
|
1882
1928
|
filter: filter,
|
|
1883
1929
|
filterSeedParams: filterDefaultParams,
|
|
1884
1930
|
horizontalScroller: horizontalScroller,
|