@kne/table-page 0.1.0

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.
@@ -0,0 +1,3453 @@
1
+ import { withFetch } from '@kne/react-fetch';
2
+ import { Typography, Tooltip, Tag, Space, Checkbox, Row, Col, Input, List, Button, Collapse, Popover, Empty, Table as Table$1, Dropdown, Pagination } from 'antd';
3
+ import { FilterProvider, FilterLines, SearchInput, FilterValueDisplay, getFilterValue } from '@kne/react-filter';
4
+ import { useState, useCallback, useMemo, useRef, useEffect, useLayoutEffect, forwardRef } from 'react';
5
+ import classnames from 'classnames';
6
+ import get from 'lodash/get';
7
+ import { isEmpty } from '@kne/is-empty';
8
+ import groupBy from 'lodash/groupBy';
9
+ import transform from 'lodash/transform';
10
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
+ import ButtonGroup from '@kne/button-group';
12
+ import '@kne/button-group/dist/index.css';
13
+ import { CaretUpOutlined, CaretDownOutlined, HolderOutlined, RedoOutlined, SettingOutlined, CheckOutlined, DownOutlined } from '@ant-design/icons';
14
+ import clone from 'lodash/clone';
15
+ import useRefCallback from '@kne/use-ref-callback';
16
+ import pick from 'lodash/pick';
17
+ import findLastIndex from 'lodash/findLastIndex';
18
+ import isEqual from 'lodash/isEqual';
19
+ import { useDebouncedCallback } from 'use-debounce';
20
+ import { ReactSortable } from 'react-sortablejs';
21
+ import set from 'lodash/set';
22
+ import cloneDeep from 'lodash/cloneDeep';
23
+ import { createWithIntlProvider, useIntl } from '@kne/react-intl';
24
+ import filterZhCN from '@kne/react-filter/dist/locale/zh-CN';
25
+ import filterEnUS from '@kne/react-filter/dist/locale/en-US';
26
+ import { createPortal } from 'react-dom';
27
+ import '@kne/react-filter/dist/index.css';
28
+ import merge from 'lodash/merge';
29
+
30
+ function _extends() {
31
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
32
+ for (var e = 1; e < arguments.length; e++) {
33
+ var t = arguments[e];
34
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
35
+ }
36
+ return n;
37
+ }, _extends.apply(null, arguments);
38
+ }
39
+ function _objectWithoutPropertiesLoose(r, e) {
40
+ if (null == r) return {};
41
+ var t = {};
42
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
43
+ if (-1 !== e.indexOf(n)) continue;
44
+ t[n] = r[n];
45
+ }
46
+ return t;
47
+ }
48
+
49
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
50
+
51
+ function createCommonjsModule(fn) {
52
+ var module = { exports: {} };
53
+ return fn(module, module.exports), module.exports;
54
+ }
55
+
56
+ var dayjs_min = createCommonjsModule(function (module, exports) {
57
+ !function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),Y=_.prototype;return O.prototype=Y,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){Y[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
58
+ });
59
+
60
+ const calcArgs = (args, template) => {
61
+ const {
62
+ attr,
63
+ normal
64
+ } = groupBy(args, item => /^.+:.+$/.test(item) ? 'attr' : 'normal');
65
+ const output = {};
66
+ const typeTransform = (value, type) => {
67
+ if (type === 'string') {
68
+ return String(value);
69
+ }
70
+ if (type === 'number') {
71
+ return Number(value);
72
+ }
73
+ if (type === 'boolean') {
74
+ return value === 'true';
75
+ }
76
+ return value;
77
+ };
78
+ (normal || []).forEach((target, index) => {
79
+ const currentTemplate = Object.assign({}, {
80
+ type: 'string',
81
+ defaultValue: ''
82
+ }, get(template, index));
83
+ if (currentTemplate.name && target) {
84
+ output[currentTemplate.name] = typeTransform(target, currentTemplate.type);
85
+ }
86
+ });
87
+ (attr || []).forEach(target => {
88
+ const [key, value] = target.split(':');
89
+ const currentTemplate = template.find(item => item.name === key);
90
+ if (!currentTemplate) {
91
+ return;
92
+ }
93
+ const {
94
+ name,
95
+ type
96
+ } = Object.assign({}, {
97
+ type: 'string',
98
+ defaultValue: ''
99
+ }, currentTemplate);
100
+ output[name] = typeTransform(value, type);
101
+ });
102
+ return Object.assign({}, transform(template, (result, value) => {
103
+ if (value.name && value.hasOwnProperty('defaultValue')) {
104
+ result[value.name] = value.defaultValue;
105
+ }
106
+ }, {}), output);
107
+ };
108
+ const defaultFormat = {
109
+ date: (value, {
110
+ args
111
+ }) => {
112
+ const template = args[0] || 'YYYY-MM-DD';
113
+ return dayjs_min(value).format(template);
114
+ },
115
+ datetime: (value, {
116
+ args
117
+ }) => {
118
+ const template = args[0] || 'YYYY-MM-DD HH:mm:ss';
119
+ return dayjs_min(value).format(template);
120
+ },
121
+ dateRange: (value, {
122
+ args
123
+ }) => {
124
+ const template = args[0] || 'YYYY-MM-DD',
125
+ allowNull = args[1];
126
+ if (!isEmpty(value[0]) && !isEmpty(value[1])) {
127
+ return `${dayjs_min(value[0]).format(template)}~${dayjs_min(value[1]).format(template)}`;
128
+ }
129
+ if (allowNull === 'allow' && !isEmpty(value[0])) {
130
+ return `${dayjs_min(value[0]).format(template)}以后`;
131
+ }
132
+ if (allowNull === 'allow' && !isEmpty(value[1])) {
133
+ return `${dayjs_min(value[1]).format(template)}以前`;
134
+ }
135
+ return '';
136
+ },
137
+ boolean: (value, {
138
+ args
139
+ }) => {
140
+ const trueValue = args[0] || 'true';
141
+ if ((value || '').toString() === trueValue) {
142
+ return '是';
143
+ }
144
+ return '否';
145
+ },
146
+ number: (value, {
147
+ args
148
+ }) => {
149
+ const {
150
+ style,
151
+ unit,
152
+ maximumFractionDigits,
153
+ useGrouping,
154
+ roundingMode,
155
+ suffix
156
+ } = calcArgs(args, [{
157
+ name: 'style',
158
+ type: 'string',
159
+ defaultValue: 'decimal'
160
+ }, {
161
+ name: 'unit',
162
+ type: 'number',
163
+ defaultValue: 1
164
+ }, {
165
+ name: 'maximumFractionDigits',
166
+ type: 'number',
167
+ defaultValue: 2
168
+ }, {
169
+ name: 'useGrouping',
170
+ type: 'boolean',
171
+ defaultValue: true
172
+ }, {
173
+ name: 'roundingMode',
174
+ type: 'string',
175
+ defaultValue: 'halfExpand'
176
+ }, {
177
+ name: 'suffix',
178
+ type: 'string',
179
+ defaultValue: ''
180
+ }]);
181
+ return new Intl.NumberFormat({}, {
182
+ style,
183
+ maximumFractionDigits,
184
+ roundingMode,
185
+ useGrouping
186
+ }).format(value / unit) + suffix;
187
+ },
188
+ money: (value, {
189
+ args
190
+ }) => {
191
+ const unit = args[0] || '元';
192
+ return `${value}${unit}`;
193
+ }
194
+ };
195
+ const formatView = (value, format, context) => {
196
+ if (!format) {
197
+ return value;
198
+ }
199
+ const formatList = format.split(' ').filter(item => !!item);
200
+ if (formatList.length > 0) {
201
+ return formatList.reduce((value, format) => {
202
+ const [name, ...args] = format.split('-');
203
+ if (typeof defaultFormat[name] === 'function') {
204
+ return defaultFormat[name](value, Object.assign({}, context, {
205
+ args: args.map(item => {
206
+ return item && item.replace(/\(\)/g, ' ').replace(/\(_\)/g, '-');
207
+ })
208
+ }));
209
+ }
210
+ return value;
211
+ }, value);
212
+ }
213
+ };
214
+
215
+ const globalParams = {
216
+ renderType: null,
217
+ renderTypeSize: {},
218
+ tagTypeColors: {}
219
+ };
220
+
221
+ const defaultRender = value => value;
222
+
223
+ var ellipsisStyle = {"ellipsis":"kne-table-page_mMMw1","tooltip":"kne-table-page_CkWQu","cell-content":"kne-table-page_OXmYu","cell-full-width":"kne-table-page_jN-vq"};
224
+
225
+ const _excluded$7 = ["showTitle"];
226
+ const Ellipsis = ({
227
+ children,
228
+ ellipsis
229
+ }) => {
230
+ if (!ellipsis) {
231
+ return children;
232
+ }
233
+ const userConfig = typeof ellipsis === 'object' ? ellipsis : {};
234
+ const {
235
+ showTitle
236
+ } = userConfig,
237
+ rest = _objectWithoutPropertiesLoose(userConfig, _excluded$7);
238
+ return /*#__PURE__*/jsx(Typography.Text, {
239
+ className: ellipsisStyle['ellipsis'],
240
+ ellipsis: Object.assign({}, {
241
+ tooltip: showTitle === false ? false : {
242
+ rootClassName: ellipsisStyle['tooltip']
243
+ }
244
+ }, rest),
245
+ children: children
246
+ });
247
+ };
248
+
249
+ var style$7 = {"text":"kne-table-page_5N2-a","ellipsis":"kne-table-page_Lkl3D","hover":"kne-table-page_RnF6d","primary":"kne-table-page_g-Sky"};
250
+
251
+ const main = (value, {
252
+ column,
253
+ dataSource
254
+ } = {}) => {
255
+ const {
256
+ ellipsis = true,
257
+ hover = true,
258
+ primary = true,
259
+ onClick
260
+ } = column || {};
261
+ if (!hover && !primary && !onClick) {
262
+ return /*#__PURE__*/jsx(Ellipsis, {
263
+ ellipsis: ellipsis,
264
+ children: value
265
+ });
266
+ }
267
+ const ellipsisConfig = typeof ellipsis === 'object' ? ellipsis : {};
268
+ const showTooltip = ellipsis && ellipsisConfig.showTitle !== false;
269
+ const text = /*#__PURE__*/jsx("span", {
270
+ className: classnames(style$7['text'], ellipsis && style$7['ellipsis'], {
271
+ [style$7['hover']]: hover,
272
+ [style$7['primary']]: primary
273
+ }),
274
+ onClick: onClick ? e => onClick({
275
+ item: value,
276
+ colItem: dataSource,
277
+ event: e
278
+ }) : undefined,
279
+ children: value
280
+ });
281
+ if (!showTooltip) {
282
+ return text;
283
+ }
284
+ return /*#__PURE__*/jsx(Tooltip, {
285
+ title: value,
286
+ rootClassName: ellipsisStyle['tooltip'],
287
+ children: text
288
+ });
289
+ };
290
+
291
+ var style$6 = {"amount":"kne-table-page_AH-3R"};
292
+
293
+ const amount = (value, {
294
+ column
295
+ } = {}) => {
296
+ const {
297
+ ellipsis = true
298
+ } = column || {};
299
+ return /*#__PURE__*/jsx("span", {
300
+ className: style$6['amount'],
301
+ children: /*#__PURE__*/jsx(Ellipsis, {
302
+ ellipsis: ellipsis,
303
+ children: value
304
+ })
305
+ });
306
+ };
307
+
308
+ const _excluded$6 = ["text", "type", "color", "children"];
309
+ const DEFAULT_TAG_TYPE_COLORS = {
310
+ default: 'default',
311
+ success: 'success',
312
+ progress: 'processing',
313
+ processing: 'processing',
314
+ danger: 'error',
315
+ error: 'error',
316
+ warning: 'warning',
317
+ info: 'blue',
318
+ other: 'purple',
319
+ skill: 'default',
320
+ result: 'default',
321
+ filterResult: 'cyan',
322
+ completed: 'success',
323
+ pending: 'warning',
324
+ high: 'error',
325
+ medium: 'warning',
326
+ low: 'default'
327
+ };
328
+ const getTagColor = type => {
329
+ if (!type) {
330
+ return 'default';
331
+ }
332
+ const customColors = globalParams.tagTypeColors || {};
333
+ return customColors[type] || DEFAULT_TAG_TYPE_COLORS[type] || type;
334
+ };
335
+ const normalizeTagItem = item => {
336
+ if (item == null) {
337
+ return null;
338
+ }
339
+ if (typeof item === 'string' || typeof item === 'number') {
340
+ return {
341
+ text: String(item)
342
+ };
343
+ }
344
+ if (typeof item === 'object') {
345
+ var _ref, _item$text;
346
+ return Object.assign({}, item, {
347
+ text: (_ref = (_item$text = item.text) != null ? _item$text : item.children) != null ? _ref : item.label
348
+ });
349
+ }
350
+ return null;
351
+ };
352
+ const renderTagItem = (item, key) => {
353
+ const tag = normalizeTagItem(item);
354
+ if (!tag || tag.text == null && tag.children == null) {
355
+ return null;
356
+ }
357
+ const {
358
+ text,
359
+ type,
360
+ color,
361
+ children
362
+ } = tag,
363
+ rest = _objectWithoutPropertiesLoose(tag, _excluded$6);
364
+ return /*#__PURE__*/jsx(Tag, _extends({
365
+ color: color != null ? color : getTagColor(type)
366
+ }, rest, {
367
+ children: children != null ? children : text
368
+ }), key);
369
+ };
370
+ const renderTagList = value => {
371
+ if (!Array.isArray(value) || value.length === 0) {
372
+ return null;
373
+ }
374
+ return /*#__PURE__*/jsx(Space, {
375
+ size: [4, 4],
376
+ wrap: true,
377
+ children: value.map((item, index) => renderTagItem(item, index))
378
+ });
379
+ };
380
+
381
+ const tag = value => renderTagItem(value);
382
+
383
+ const tagList = value => renderTagList(value);
384
+
385
+ const DEFAULT_SPLIT = ',';
386
+ const normalizeListValue = value => {
387
+ if (Array.isArray(value)) {
388
+ return {
389
+ items: value,
390
+ split: undefined
391
+ };
392
+ }
393
+ if (value && typeof value === 'object') {
394
+ var _ref, _value$items;
395
+ const items = (_ref = (_value$items = value.items) != null ? _value$items : value.list) != null ? _ref : value.value;
396
+ if (Array.isArray(items)) {
397
+ return {
398
+ items,
399
+ split: value.split
400
+ };
401
+ }
402
+ }
403
+ return null;
404
+ };
405
+ const getListItemText = item => {
406
+ if (item == null) {
407
+ return null;
408
+ }
409
+ if (typeof item === 'object') {
410
+ var _ref2, _ref3, _item$text;
411
+ return (_ref2 = (_ref3 = (_item$text = item.text) != null ? _item$text : item.label) != null ? _ref3 : item.children) != null ? _ref2 : item.value;
412
+ }
413
+ return item;
414
+ };
415
+ const list = (value, {
416
+ column
417
+ } = {}) => {
418
+ var _ref4, _normalized$split;
419
+ const normalized = normalizeListValue(value);
420
+ if (!normalized) {
421
+ return value == null ? null : value;
422
+ }
423
+ const split = (_ref4 = (_normalized$split = normalized.split) != null ? _normalized$split : column == null ? void 0 : column.split) != null ? _ref4 : DEFAULT_SPLIT;
424
+ const text = normalized.items.map(getListItemText).filter(item => item != null && item !== '').join(split);
425
+ return text || null;
426
+ };
427
+
428
+ const SELECTION_CHECKBOX_WIDTH = 48;
429
+ const SELECTION_RADIO_WIDTH = 30;
430
+ const DEFAULT_COLUMN_WIDTH = 300;
431
+ const parseColumnWidth = width => {
432
+ if (width == null) {
433
+ return 0;
434
+ }
435
+ if (typeof width === 'number' && !Number.isNaN(width)) {
436
+ return width;
437
+ }
438
+ if (typeof width === 'string') {
439
+ const trimmed = width.trim();
440
+ const pxMatch = trimmed.match(/^([\d.]+)px$/i);
441
+ if (pxMatch) {
442
+ return parseFloat(pxMatch[1]);
443
+ }
444
+ const num = parseFloat(trimmed);
445
+ if (!Number.isNaN(num)) {
446
+ return num;
447
+ }
448
+ }
449
+ return 0;
450
+ };
451
+ const getResolvedColumnWidth = column => resolveColumnDimensions(column).width;
452
+ const hasColumnSpan = column => column.span != null;
453
+ const getConfiguredColumnWidthPx = column => parseColumnWidth(column.width != null ? column.width : getResolvedColumnWidth(column));
454
+ const usesDefaultColumnWidth = (column, columns) => {
455
+ if (hasColumnSpan(column)) {
456
+ return false;
457
+ }
458
+ if (column.width != null) {
459
+ return false;
460
+ }
461
+ if (getConfiguredColumnWidthPx(column) > 0) {
462
+ return false;
463
+ }
464
+ return !columns.some(hasColumnSpan);
465
+ };
466
+ const hasColumnWidth = (column, columns) => {
467
+ if (hasColumnSpan(column)) {
468
+ return false;
469
+ }
470
+ if (getConfiguredColumnWidthPx(column) > 0) {
471
+ return true;
472
+ }
473
+ return usesDefaultColumnWidth(column, columns);
474
+ };
475
+ const shouldLastColumnFillRemaining = columns => !columns.some(hasColumnSpan);
476
+ const getColumnWidthPx = (column, colsSize = {}, columns = []) => {
477
+ if (hasColumnSpan(column)) {
478
+ return colsSize[column.name] || 0;
479
+ }
480
+ const configured = getConfiguredColumnWidthPx(column);
481
+ if (configured > 0) {
482
+ return configured;
483
+ }
484
+ if (usesDefaultColumnWidth(column, columns)) {
485
+ const measured = colsSize[column.name] || 0;
486
+ return Math.max(DEFAULT_COLUMN_WIDTH, measured);
487
+ }
488
+ return colsSize[column.name] || 0;
489
+ };
490
+ const formatColumnWidthPx = px => `${px}px`;
491
+ const getColumnTrackSize = (column, {
492
+ defaultSpan,
493
+ colsSize,
494
+ isLastColumn,
495
+ columns
496
+ } = {}) => {
497
+ var _ref, _column$span;
498
+ const widthPx = getColumnWidthPx(column, colsSize, columns);
499
+ if (hasColumnWidth(column, columns)) {
500
+ if (isLastColumn && shouldLastColumnFillRemaining(columns)) {
501
+ return `minmax(${widthPx}px, 1fr)`;
502
+ }
503
+ return `${widthPx}px`;
504
+ }
505
+ if (widthPx > 0) {
506
+ return `minmax(${widthPx}px, 1fr)`;
507
+ }
508
+ const span = (_ref = (_column$span = column.span) != null ? _column$span : defaultSpan) != null ? _ref : 1;
509
+ return `minmax(0, ${span}fr)`;
510
+ };
511
+ const getGridTemplateColumns = (columns, {
512
+ defaultSpan,
513
+ colsSize,
514
+ rowSelection
515
+ } = {}) => {
516
+ const tracks = [];
517
+ const lastColumnIndex = columns.length - 1;
518
+ if ((rowSelection == null ? void 0 : rowSelection.type) === 'checkbox') {
519
+ tracks.push(`${SELECTION_CHECKBOX_WIDTH}px`);
520
+ }
521
+ columns.forEach((column, index) => {
522
+ tracks.push(getColumnTrackSize(column, {
523
+ defaultSpan,
524
+ colsSize,
525
+ isLastColumn: index === lastColumnIndex,
526
+ columns
527
+ }));
528
+ });
529
+ if ((rowSelection == null ? void 0 : rowSelection.type) === 'radio') {
530
+ tracks.push(`${SELECTION_RADIO_WIDTH}px`);
531
+ }
532
+ return tracks.join(' ');
533
+ };
534
+ const getColumnLayout = (column, {
535
+ defaultSpan,
536
+ colsSize,
537
+ isLastColumn,
538
+ columns
539
+ } = {}) => {
540
+ const widthBased = hasColumnWidth(column, columns);
541
+ const widthPx = getColumnWidthPx(column, colsSize, columns);
542
+ const fillRemaining = isLastColumn && widthBased && shouldLastColumnFillRemaining(columns);
543
+ return {
544
+ widthBased,
545
+ fillRemaining,
546
+ style: {
547
+ '--col-width': formatColumnWidthPx(widthPx),
548
+ '--col-align': column.align || 'top',
549
+ '--col-justify': column.justify || 'flex-start'
550
+ }
551
+ };
552
+ };
553
+
554
+ var style$5 = {"col-item":"kne-table-page_nL1tj","options":"kne-table-page_EwzO-","options-column":"kne-table-page_im2Lc","options-btn":"kne-table-page_SJxZl"};
555
+
556
+ const _excluded$5 = ["children", "label", "text", "className"],
557
+ _excluded2$2 = ["list"];
558
+ const normalizeOptionItem = (item, buttonClassName) => {
559
+ var _ref;
560
+ if (item == null) {
561
+ return null;
562
+ }
563
+ if (typeof item === 'function') {
564
+ return item;
565
+ }
566
+ if (typeof item === 'string') {
567
+ return {
568
+ children: item,
569
+ type: 'link',
570
+ className: buttonClassName
571
+ };
572
+ }
573
+ const {
574
+ children,
575
+ label,
576
+ text,
577
+ className
578
+ } = item,
579
+ rest = _objectWithoutPropertiesLoose(item, _excluded$5);
580
+ return _extends({
581
+ type: 'link'
582
+ }, rest, {
583
+ className: classnames(buttonClassName, className),
584
+ children: (_ref = children != null ? children : label) != null ? _ref : text
585
+ });
586
+ };
587
+ const options = (value, {
588
+ column
589
+ } = {}) => {
590
+ let list = value;
591
+ let buttonGroupProps = (column == null ? void 0 : column.buttonGroup) || {};
592
+ if (value && typeof value === 'object' && !Array.isArray(value) && Array.isArray(value.list)) {
593
+ const {
594
+ list: valueList
595
+ } = value,
596
+ rest = _objectWithoutPropertiesLoose(value, _excluded2$2);
597
+ list = valueList;
598
+ buttonGroupProps = _extends({}, buttonGroupProps, rest);
599
+ }
600
+ if (!Array.isArray(list) || list.length === 0) {
601
+ return null;
602
+ }
603
+ const wrapperClassName = classnames(style$5['col-item'], style$5['options']);
604
+ const buttonClassName = classnames(wrapperClassName, style$5['options-btn']);
605
+ const normalizedList = list.map(item => normalizeOptionItem(item, buttonClassName)).filter(item => item != null && !item.hidden);
606
+ if (normalizedList.length === 0) {
607
+ return null;
608
+ }
609
+ const width = parseColumnWidth(column == null ? void 0 : column.width);
610
+ return /*#__PURE__*/jsx("div", {
611
+ className: classnames(wrapperClassName, style$5['options-column']),
612
+ style: width > 0 ? {
613
+ '--max-width': `${width}px`
614
+ } : undefined,
615
+ children: /*#__PURE__*/jsx(ButtonGroup, _extends({
616
+ moreType: "link",
617
+ itemClassName: "btn-no-padding",
618
+ list: normalizedList
619
+ }, buttonGroupProps))
620
+ });
621
+ };
622
+
623
+ const enumRender = value => tag(value);
624
+
625
+ const description = value => value;
626
+
627
+ const renderType = {
628
+ default: defaultRender,
629
+ main,
630
+ amount,
631
+ tag,
632
+ tagList,
633
+ list,
634
+ options,
635
+ enum: enumRender,
636
+ description
637
+ };
638
+ globalParams.renderType = renderType;
639
+
640
+ const _excluded$4 = ["default"];
641
+ const SIZE_NAMES = ['short', 'small', 'large'];
642
+ const typeSize = {
643
+ main: {
644
+ width: 300,
645
+ min: 160,
646
+ max: 500,
647
+ ellipsis: true
648
+ },
649
+ amount: {
650
+ width: 140,
651
+ min: 100,
652
+ max: 300,
653
+ ellipsis: true
654
+ },
655
+ options: {
656
+ width: 180,
657
+ min: 120,
658
+ max: 400
659
+ },
660
+ enum: {
661
+ width: 140,
662
+ min: 100,
663
+ max: 400
664
+ },
665
+ tag: {
666
+ width: 140,
667
+ min: 100,
668
+ max: 400
669
+ },
670
+ tagList: {
671
+ width: 300,
672
+ min: 160,
673
+ max: 500
674
+ },
675
+ list: {
676
+ width: 200,
677
+ min: 120,
678
+ max: 400,
679
+ ellipsis: true
680
+ },
681
+ description: {
682
+ width: 400,
683
+ min: 160,
684
+ max: 600,
685
+ ellipsis: true
686
+ }
687
+ };
688
+ const SIZE_CONFIG = {
689
+ short: {
690
+ width: 120,
691
+ min: 100,
692
+ max: 400
693
+ },
694
+ small: {
695
+ width: 100,
696
+ min: 70,
697
+ max: 400
698
+ },
699
+ default: {
700
+ width: 300,
701
+ min: 160,
702
+ max: 500
703
+ },
704
+ large: {
705
+ width: 300,
706
+ min: 120,
707
+ max: 500
708
+ }
709
+ };
710
+ const getRenderTypeRegistry = () => {
711
+ const _ref = globalParams.renderType || {},
712
+ {
713
+ default: defaultRender
714
+ } = _ref,
715
+ renderers = _objectWithoutPropertiesLoose(_ref, _excluded$4);
716
+ return {
717
+ defaultRender,
718
+ renderers
719
+ };
720
+ };
721
+ const getRenderTypeNames = () => Object.keys(getRenderTypeRegistry().renderers);
722
+ const RENDER_TYPE_NAMES = getRenderTypeNames();
723
+ const getRender = type => {
724
+ const {
725
+ defaultRender,
726
+ renderers
727
+ } = getRenderTypeRegistry();
728
+ return renderers[type] || defaultRender;
729
+ };
730
+ const getColumnRender = column => {
731
+ if (typeof (column == null ? void 0 : column.render) === 'function') {
732
+ return column.render;
733
+ }
734
+ const {
735
+ type
736
+ } = parseRenderType(column == null ? void 0 : column.renderType);
737
+ if (!type) {
738
+ return null;
739
+ }
740
+ return getRender(type);
741
+ };
742
+ const getTypeConfigMap = () => {
743
+ const extraTypeSize = globalParams.renderTypeSize || {};
744
+ return getRenderTypeNames().reduce((result, key) => {
745
+ result[key] = Object.assign({}, typeSize[key], extraTypeSize[key], {
746
+ render: getRender(key)
747
+ });
748
+ return result;
749
+ }, {});
750
+ };
751
+ const pickDimension = (columnValue, typeValue, sizeValue) => {
752
+ if (columnValue != null) {
753
+ return columnValue;
754
+ }
755
+ if (sizeValue != null) {
756
+ return sizeValue;
757
+ }
758
+ if (typeValue != null) {
759
+ return typeValue;
760
+ }
761
+ return undefined;
762
+ };
763
+ const parseRenderType = renderTypeValue => {
764
+ if (!renderTypeValue || typeof renderTypeValue !== 'string') {
765
+ return {
766
+ type: null,
767
+ size: null
768
+ };
769
+ }
770
+ const renderTypeNames = getRenderTypeNames();
771
+ let type = null;
772
+ let size = null;
773
+ renderTypeValue.split('-').forEach(part => {
774
+ if (!part) {
775
+ return;
776
+ }
777
+ if (renderTypeNames.includes(part)) {
778
+ type = part;
779
+ return;
780
+ }
781
+ if (SIZE_NAMES.includes(part)) {
782
+ size = part;
783
+ }
784
+ });
785
+ return {
786
+ type,
787
+ size
788
+ };
789
+ };
790
+ const getRenderTypeDimensions = renderTypeValue => {
791
+ const {
792
+ type,
793
+ size
794
+ } = parseRenderType(renderTypeValue);
795
+ const typeConfigMap = getTypeConfigMap();
796
+ const typeConfig = type ? typeConfigMap[type] : null;
797
+ const sizeConfig = size ? SIZE_CONFIG[size] : null;
798
+ if (!typeConfig && !sizeConfig) {
799
+ return null;
800
+ }
801
+ return {
802
+ type,
803
+ size,
804
+ typeConfig,
805
+ sizeConfig,
806
+ render: typeConfig == null ? void 0 : typeConfig.render,
807
+ ellipsis: typeConfig == null ? void 0 : typeConfig.ellipsis
808
+ };
809
+ };
810
+ const resolveColumnDimensions = column => {
811
+ const renderTypeDimensions = column != null && column.renderType ? getRenderTypeDimensions(column.renderType) : null;
812
+ const typeConfig = renderTypeDimensions == null ? void 0 : renderTypeDimensions.typeConfig;
813
+ const sizeConfig = renderTypeDimensions == null ? void 0 : renderTypeDimensions.sizeConfig;
814
+ return {
815
+ width: pickDimension(column == null ? void 0 : column.width, typeConfig == null ? void 0 : typeConfig.width, sizeConfig == null ? void 0 : sizeConfig.width),
816
+ min: pickDimension(column == null ? void 0 : column.min, typeConfig == null ? void 0 : typeConfig.min, sizeConfig == null ? void 0 : sizeConfig.min),
817
+ max: pickDimension(column == null ? void 0 : column.max, typeConfig == null ? void 0 : typeConfig.max, sizeConfig == null ? void 0 : sizeConfig.max)
818
+ };
819
+ };
820
+ const resolveRenderType = renderTypeValue => {
821
+ var _sizeConfig$width, _sizeConfig$min, _sizeConfig$max;
822
+ const renderTypeDimensions = getRenderTypeDimensions(renderTypeValue);
823
+ if (!renderTypeDimensions) {
824
+ return null;
825
+ }
826
+ const {
827
+ type,
828
+ size,
829
+ render,
830
+ ellipsis,
831
+ typeConfig,
832
+ sizeConfig
833
+ } = renderTypeDimensions;
834
+ return {
835
+ type,
836
+ size,
837
+ render,
838
+ ellipsis,
839
+ width: (_sizeConfig$width = sizeConfig == null ? void 0 : sizeConfig.width) != null ? _sizeConfig$width : typeConfig == null ? void 0 : typeConfig.width,
840
+ min: (_sizeConfig$min = sizeConfig == null ? void 0 : sizeConfig.min) != null ? _sizeConfig$min : typeConfig == null ? void 0 : typeConfig.min,
841
+ max: (_sizeConfig$max = sizeConfig == null ? void 0 : sizeConfig.max) != null ? _sizeConfig$max : typeConfig == null ? void 0 : typeConfig.max
842
+ };
843
+ };
844
+ const ELLIPSIS_HANDLED_TYPES = ['main', 'amount'];
845
+ const FULL_WIDTH_CELL_TYPES = ['options'];
846
+ const resolveColumn = column => {
847
+ if (!column) {
848
+ return column;
849
+ }
850
+ const renderTypeDimensions = column.renderType ? getRenderTypeDimensions(column.renderType) : null;
851
+ const {
852
+ width,
853
+ min,
854
+ max
855
+ } = resolveColumnDimensions(column);
856
+ const {
857
+ ellipsis,
858
+ type
859
+ } = renderTypeDimensions || {};
860
+ const renderFn = getColumnRender(column);
861
+ return Object.assign({}, column, _extends({}, renderFn && typeof column.render !== 'function' ? {
862
+ render: renderFn
863
+ } : {}, column.width == null && width != null ? {
864
+ width
865
+ } : {}, column.min == null && min != null ? {
866
+ min
867
+ } : {}, column.max == null && max != null ? {
868
+ max
869
+ } : {}, column.ellipsis == null && ellipsis != null ? {
870
+ ellipsis
871
+ } : {}, type && ELLIPSIS_HANDLED_TYPES.includes(type) ? {
872
+ ellipsisHandledByRender: true
873
+ } : {}, type && FULL_WIDTH_CELL_TYPES.includes(type) ? {
874
+ cellFullWidth: true
875
+ } : {}, column.type === 'options' && !type ? {
876
+ cellFullWidth: true
877
+ } : {}, type === 'options' && column.type !== 'options' ? {
878
+ type: 'options'
879
+ } : {}));
880
+ };
881
+ const resolveColumns = columns => (columns || []).map(resolveColumn);
882
+ const isOptionsColumn = column => {
883
+ if ((column == null ? void 0 : column.type) === 'options') {
884
+ return true;
885
+ }
886
+ return parseRenderType(column == null ? void 0 : column.renderType).type === 'options';
887
+ };
888
+
889
+ const computeColumnsValue = ({
890
+ columns,
891
+ emptyIsPlaceholder,
892
+ valueIsEmpty,
893
+ removeEmpty: _removeEmpty = true,
894
+ dataSource,
895
+ context
896
+ }) => {
897
+ return (output => _removeEmpty ? output.filter(item => !!item) : output)(columns.map(item => {
898
+ const itemValue = typeof item.getValueOf === 'function' ? item.getValueOf(dataSource, {
899
+ column: item,
900
+ context
901
+ }) : get(dataSource, item.name);
902
+ const displayValue = (value => {
903
+ if (typeof item.format === 'function') {
904
+ return item.format(value, {
905
+ dataSource,
906
+ column: item,
907
+ context
908
+ });
909
+ }
910
+ if (typeof item.format === 'string') {
911
+ const formatValue = formatView(value, item.format, {
912
+ dataSource,
913
+ column: item,
914
+ context
915
+ });
916
+ if (formatValue) {
917
+ return formatValue;
918
+ }
919
+ }
920
+ return value;
921
+ })(itemValue);
922
+ const itemIsEmpty = (item.valueIsEmpty || valueIsEmpty)(itemValue);
923
+ if (item.display === false || typeof item.display === 'function' && item.display(itemValue, {
924
+ dataSource,
925
+ column: item,
926
+ context
927
+ }) === false) {
928
+ return null;
929
+ }
930
+ if (!(item.hasOwnProperty('emptyIsPlaceholder') ? item.emptyIsPlaceholder : emptyIsPlaceholder) && itemIsEmpty) {
931
+ return null;
932
+ }
933
+ return Object.assign({}, item, {
934
+ isEmpty: itemIsEmpty,
935
+ value: displayValue
936
+ });
937
+ }));
938
+ };
939
+ const computeDisplay = ({
940
+ column,
941
+ dataSource,
942
+ placeholder,
943
+ context
944
+ }) => {
945
+ if (column.isEmpty) {
946
+ return typeof column.renderPlaceholder === 'function' ? column.renderPlaceholder({
947
+ column: column,
948
+ dataSource,
949
+ placeholder,
950
+ context
951
+ }) : column.placeholder || placeholder;
952
+ }
953
+ const render = getColumnRender(column);
954
+ return typeof render === 'function' ? render(column.value, {
955
+ column,
956
+ dataSource,
957
+ context
958
+ }) : column.value;
959
+ };
960
+ const computeColumnsDisplay = ({
961
+ columns,
962
+ emptyIsPlaceholder,
963
+ valueIsEmpty,
964
+ removeEmpty,
965
+ dataSource,
966
+ placeholder,
967
+ context
968
+ }) => {
969
+ return computeColumnsValue({
970
+ columns,
971
+ emptyIsPlaceholder,
972
+ valueIsEmpty,
973
+ removeEmpty,
974
+ dataSource,
975
+ context
976
+ }).map(column => {
977
+ return computeDisplay({
978
+ column,
979
+ placeholder,
980
+ dataSource,
981
+ context
982
+ });
983
+ });
984
+ };
985
+ computeColumnsValue.computeDisplay = computeDisplay;
986
+ computeColumnsValue.computeColumnsDisplay = computeColumnsDisplay;
987
+
988
+ var style$4 = {"table":"kne-table-page_lZgIW","tableView":"kne-table-page_fUw6j","grid":"kne-table-page_JlDmf","header-cell":"kne-table-page_P-ebv","body-row":"kne-table-page_Z6mVv","col":"kne-table-page_KNy4z","body-cell":"kne-table-page_BSOzz","body":"kne-table-page_9qon1","is-selected-all":"kne-table-page_f2i1e","is-selected":"kne-table-page_n3V6m","is-disabled":"kne-table-page_AfmkR","col-width-based":"kne-table-page_ZvnDi","col-width-fill":"kne-table-page_cV7PE","col-content":"kne-table-page_HT5Rr","single-checked":"kne-table-page_9UAoL","col-fixed":"kne-table-page_aB-1c","empty":"kne-table-page_SRI8Q"};
989
+
990
+ var style$3 = {"table":"kne-table-page_awa1L","is-selected-all":"kne-table-page_692q3","is-selected":"kne-table-page_IWgjl","is-disabled":"kne-table-page_YUG4k","has-summary":"kne-table-page_Cb-du","has-group-header":"kne-table-page_7qTC5","table-cell":"kne-table-page_HPmr3","selection-col":"kne-table-page_D7YhS","radio-col":"kne-table-page_df9z3","is-computed":"kne-table-page_ZA1Je","is-resize":"kne-table-page_CA0uL","column-resize-guide":"kne-table-page_JARA2"};
991
+
992
+ const useSelectedRow = options => {
993
+ const {
994
+ rowKey,
995
+ type = 'checkbox'
996
+ } = Object.assign({}, {
997
+ rowKey: 'id'
998
+ }, options);
999
+ const [selectedRows, setSelectedRows] = useState([]);
1000
+ const getRowId = useCallback(item => get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey), [rowKey]);
1001
+ const selectedRowKeys = useMemo(() => selectedRows.map(getRowId), [getRowId, selectedRows]);
1002
+ const setSelectedRowKeys = useCallback((keys, dataSource = []) => {
1003
+ const keySet = new Set(keys || []);
1004
+ setSelectedRows((dataSource || []).filter(item => keySet.has(getRowId(item))));
1005
+ }, [getRowId]);
1006
+ const clearSelectedRows = useCallback(() => {
1007
+ setSelectedRows([]);
1008
+ }, []);
1009
+ const onSelectAll = useCallback((checked, _selected, items) => {
1010
+ const ids = (items || []).map(getRowId);
1011
+ if (checked) {
1012
+ setSelectedRows(value => {
1013
+ const existingKeys = value.map(getRowId);
1014
+ return [...value, ...(items || []).filter(item => existingKeys.indexOf(getRowId(item)) === -1)];
1015
+ });
1016
+ } else {
1017
+ setSelectedRows(value => {
1018
+ return value.filter(item => ids.indexOf(getRowId(item)) === -1);
1019
+ });
1020
+ }
1021
+ }, [getRowId]);
1022
+ const onSelect = useCallback((item, checked) => {
1023
+ if (checked) {
1024
+ if (type === 'radio') {
1025
+ setSelectedRows([item]);
1026
+ return;
1027
+ }
1028
+ setSelectedRows(value => {
1029
+ const newValue = value.slice(0);
1030
+ newValue.push(item);
1031
+ return newValue;
1032
+ });
1033
+ } else {
1034
+ setSelectedRows(value => {
1035
+ const newValue = value.slice(0);
1036
+ const index = newValue.findIndex(row => getRowId(row) === getRowId(item));
1037
+ if (index > -1) {
1038
+ newValue.splice(index, 1);
1039
+ }
1040
+ return newValue;
1041
+ });
1042
+ }
1043
+ }, [getRowId, type]);
1044
+ const getRowSelection = useCallback((dataSource, extra = {}) => {
1045
+ const onChange = (keys, id, meta) => {
1046
+ setSelectedRowKeys(keys, dataSource);
1047
+ extra.onChange && extra.onChange(keys, id, meta);
1048
+ };
1049
+ return Object.assign({
1050
+ type,
1051
+ selectedRowKeys,
1052
+ allowSelectedAll: type === 'checkbox',
1053
+ onChange
1054
+ }, extra);
1055
+ }, [selectedRowKeys, setSelectedRowKeys, type]);
1056
+ return {
1057
+ type,
1058
+ selectedRowKeys,
1059
+ selectedRows,
1060
+ onSelectAll,
1061
+ onSelect,
1062
+ setSelectedRows,
1063
+ setSelectedRowKeys,
1064
+ clearSelectedRows,
1065
+ getRowSelection
1066
+ };
1067
+ };
1068
+
1069
+ var style$2 = {"title":"kne-table-page_Yn7Wc","title-text":"kne-table-page_QhSty","has-sort":"kne-table-page_YaVIX","sort-btn":"kne-table-page_XkYCi","sort-icon":"kne-table-page_SSGYi","active":"kne-table-page_VT0uN","sort-up":"kne-table-page_CIokw","sort-down":"kne-table-page_5xrlc"};
1070
+
1071
+ const sortArrayToMap = sort => new Map((sort || []).map(item => {
1072
+ return [item.name, item.sort];
1073
+ }));
1074
+ const useControlValue = ({
1075
+ value,
1076
+ defaultValue,
1077
+ onChange
1078
+ }) => {
1079
+ const [internalValue, setInternalValue] = useState(defaultValue);
1080
+ const isControlled = value !== undefined;
1081
+ const currentValue = isControlled ? value : internalValue;
1082
+ const setValue = useCallback(updater => {
1083
+ const nextValue = typeof updater === 'function' ? updater(currentValue) : updater;
1084
+ if (!isControlled) {
1085
+ setInternalValue(nextValue);
1086
+ }
1087
+ onChange && onChange(nextValue);
1088
+ }, [currentValue, isControlled, onChange]);
1089
+ return [currentValue, setValue];
1090
+ };
1091
+ const compareValues = (a, b, direction) => {
1092
+ const emptyA = a == null || a === '';
1093
+ const emptyB = b == null || b === '';
1094
+ if (emptyA && emptyB) {
1095
+ return 0;
1096
+ }
1097
+ if (emptyA) {
1098
+ return 1;
1099
+ }
1100
+ if (emptyB) {
1101
+ return -1;
1102
+ }
1103
+ if (typeof a === 'number' && typeof b === 'number') {
1104
+ return direction === 'ASC' ? a - b : b - a;
1105
+ }
1106
+ const strA = String(a);
1107
+ const strB = String(b);
1108
+ return direction === 'ASC' ? strA.localeCompare(strB, 'zh-CN') : strB.localeCompare(strA, 'zh-CN');
1109
+ };
1110
+ const sortDataSource = (dataSource, sort = [], columns = []) => {
1111
+ if (!(sort != null && sort.length) || !(dataSource != null && dataSource.length)) {
1112
+ return dataSource;
1113
+ }
1114
+ const columnMap = new Map(columns.map(column => [column.name, column]));
1115
+ return [...dataSource].sort((a, b) => {
1116
+ for (const {
1117
+ name,
1118
+ sort: direction
1119
+ } of sort) {
1120
+ const column = columnMap.get(name) || {
1121
+ name
1122
+ };
1123
+ const aVal = typeof column.getValueOf === 'function' ? column.getValueOf(a, {
1124
+ column
1125
+ }) : get(a, name);
1126
+ const bVal = typeof column.getValueOf === 'function' ? column.getValueOf(b, {
1127
+ column
1128
+ }) : get(b, name);
1129
+ const result = compareValues(aVal, bVal, direction);
1130
+ if (result !== 0) {
1131
+ return result;
1132
+ }
1133
+ }
1134
+ return 0;
1135
+ });
1136
+ };
1137
+ const getSortSingle = sortOption => {
1138
+ if (typeof sortOption === 'object') {
1139
+ return sortOption.single !== false;
1140
+ }
1141
+ return true;
1142
+ };
1143
+ const renderColumnTitle = (title, column, sortRender) => {
1144
+ if (!column.sort || typeof sortRender !== 'function') {
1145
+ return title;
1146
+ }
1147
+ return /*#__PURE__*/jsxs("span", {
1148
+ className: classnames(style$2['title'], style$2['has-sort']),
1149
+ children: [/*#__PURE__*/jsx("span", {
1150
+ className: style$2['title-text'],
1151
+ children: title
1152
+ }), sortRender({
1153
+ name: column.name,
1154
+ single: getSortSingle(column.sort)
1155
+ })]
1156
+ });
1157
+ };
1158
+ const useSort = props => {
1159
+ const [sort, setSort] = useControlValue({
1160
+ value: props.sort,
1161
+ defaultValue: props.defaultSort || [],
1162
+ onChange: props.onSortChange
1163
+ });
1164
+ const mapSort = useMemo(() => {
1165
+ return sortArrayToMap(sort);
1166
+ }, [sort]);
1167
+ const setMapSort = useCallback(callback => {
1168
+ return setSort(currentSort => {
1169
+ const newSort = callback(sortArrayToMap(currentSort));
1170
+ return Array.from(newSort).map(([name, sortValue]) => ({
1171
+ name,
1172
+ sort: sortValue
1173
+ }));
1174
+ });
1175
+ }, [setSort]);
1176
+ const sortRender = useCallback(({
1177
+ single,
1178
+ name
1179
+ }) => {
1180
+ const direction = mapSort.get(name);
1181
+ return /*#__PURE__*/jsxs("span", {
1182
+ className: style$2['sort-btn'],
1183
+ onClick: e => {
1184
+ e.stopPropagation();
1185
+ setMapSort(sortMap => {
1186
+ const current = sortMap.get(name);
1187
+ const targetValue = (() => {
1188
+ if (current === 'DESC') {
1189
+ return 'ASC';
1190
+ }
1191
+ if (current === 'ASC') {
1192
+ return null;
1193
+ }
1194
+ return 'DESC';
1195
+ })();
1196
+ if (single) {
1197
+ return new Map(targetValue ? [[name, targetValue]] : []);
1198
+ }
1199
+ const newSort = clone(sortMap);
1200
+ targetValue ? newSort.set(name, targetValue) : newSort.delete(name);
1201
+ return newSort;
1202
+ });
1203
+ },
1204
+ children: [/*#__PURE__*/jsx(CaretUpOutlined, {
1205
+ className: classnames(style$2['sort-icon'], style$2['sort-up'], {
1206
+ [style$2['active']]: direction === 'ASC'
1207
+ })
1208
+ }), /*#__PURE__*/jsx(CaretDownOutlined, {
1209
+ className: classnames(style$2['sort-icon'], style$2['sort-down'], {
1210
+ [style$2['active']]: direction === 'DESC'
1211
+ })
1212
+ })]
1213
+ });
1214
+ }, [mapSort, setMapSort]);
1215
+ return {
1216
+ sort,
1217
+ setSort,
1218
+ sortRender
1219
+ };
1220
+ };
1221
+ useSort.sortDataSource = sortDataSource;
1222
+
1223
+ var configStyle = {"cell-resize-bar":"kne-table-page_PNaAP","table-changer-setting":"kne-table-page_B0U-O","is-active":"kne-table-page_vHrQo","table-config-header":"kne-table-page_Zp8MN","table-config-header-title":"kne-table-page_Pc6jR","columns-control-content":"kne-table-page_saJmr","columns-control-content-title":"kne-table-page_YmHni","columns-control-content-scroller":"kne-table-page_rgqWB","columns-control-sortable-list":"kne-table-page_JRcBW","columns-control-content-footer":"kne-table-page_nLwW1","columns-control-content-input":"kne-table-page_9qyJs","columns-control-content-list":"kne-table-page_Sslzr","columns-control-content-item":"kne-table-page_7CamD","is-drag":"kne-table-page_X18rq","columns-control-content-item-icon":"kne-table-page_Eab-e","columns-control-overlay":"kne-table-page_eT4HV","header-col":"kne-table-page_bjDly","header-cell-inner":"kne-table-page_9FKgD"};
1224
+
1225
+ const locale$1 = {
1226
+ TotalText: '共',
1227
+ ItemText: '条',
1228
+ UnnamedColumn: '未命名列',
1229
+ EditTable: '编辑表格',
1230
+ RestoreDefault: '恢复默认',
1231
+ VisibleInfo: '显示的信息',
1232
+ HiddenInfo: '隐藏的信息',
1233
+ Search: '搜索',
1234
+ BatchOperations: '批量操作',
1235
+ BatchOperationsWithCount: '批量操作(已选:{count}条)',
1236
+ Cancel: '取消',
1237
+ Confirm: '确定'
1238
+ };
1239
+
1240
+ const locale = {
1241
+ TotalText: 'Total',
1242
+ ItemText: 'items',
1243
+ UnnamedColumn: 'Unnamed',
1244
+ EditTable: 'Edit Table',
1245
+ RestoreDefault: 'Restore Default',
1246
+ VisibleInfo: 'Visible Columns',
1247
+ HiddenInfo: 'Hidden Columns',
1248
+ Search: 'Search',
1249
+ BatchOperations: 'Batch Actions',
1250
+ BatchOperationsWithCount: 'Batch Actions (Selected: {count})',
1251
+ Cancel: 'Cancel',
1252
+ Confirm: 'Confirm'
1253
+ };
1254
+
1255
+ const withLocale = createWithIntlProvider({
1256
+ defaultLocale: 'zh-CN',
1257
+ messages: {
1258
+ 'zh-CN': _extends({}, filterZhCN, locale$1),
1259
+ 'en-US': _extends({}, filterEnUS, locale)
1260
+ },
1261
+ namespace: 'table-page'
1262
+ });
1263
+
1264
+ const ColumnsControlContent = withLocale(({
1265
+ close,
1266
+ onConfirm,
1267
+ columns,
1268
+ config: defaultValue
1269
+ }) => {
1270
+ const {
1271
+ formatMessage
1272
+ } = useIntl();
1273
+ const [config, onChange] = useState(defaultValue || {});
1274
+ const [searchText, setSearchText] = useState('');
1275
+ const [confirmLoading, setConfirmLoading] = useState(false);
1276
+ const [scrollEl, setScrollEl] = useState(null);
1277
+ const {
1278
+ leftFixedColumns,
1279
+ rightFixedColumns,
1280
+ visibleColumns,
1281
+ hiddenColumns
1282
+ } = useMemo(() => {
1283
+ return transform(Object.assign({
1284
+ leftFixedColumns: [],
1285
+ rightFixedColumns: [],
1286
+ visibleColumns: [],
1287
+ hiddenColumns: []
1288
+ }, groupBy(columns, item => {
1289
+ if (item.fixed === 'right') {
1290
+ return 'rightFixedColumns';
1291
+ }
1292
+ if (item.fixed === true || item.fixed === 'left') {
1293
+ return 'leftFixedColumns';
1294
+ }
1295
+ return get(config, `${item.name}.visible`) !== true && item.hidden || get(config, `${item.name}.visible`) === false ? 'hiddenColumns' : 'visibleColumns';
1296
+ })), (result, value, key) => {
1297
+ result[key] = value.sort((a, b) => get(config, `${a.name}.rank`, 0) - get(config, `${b.name}.rank`, 0));
1298
+ }, {});
1299
+ }, [columns, config]);
1300
+ const sortableVisibleColumns = useMemo(() => {
1301
+ return visibleColumns.map(column => Object.assign({}, column, {
1302
+ id: column.name
1303
+ }));
1304
+ }, [visibleColumns]);
1305
+ const handlerColumnsChange = columnsState => {
1306
+ const newConfig = cloneDeep(config);
1307
+ const columnsList = [].concat(columnsState.leftFixedColumns, columnsState.visibleColumns, columnsState.rightFixedColumns);
1308
+ (columnsState.hiddenColumns || []).forEach(col => {
1309
+ set(newConfig, `${col.name}.visible`, false);
1310
+ });
1311
+ columnsList.forEach((col, index) => {
1312
+ set(newConfig, `${col.name}.rank`, index + 1);
1313
+ });
1314
+ onChange(newConfig);
1315
+ };
1316
+ const renderColumn = item => {
1317
+ return /*#__PURE__*/jsxs(Fragment, {
1318
+ children: [item.titleText || item.title || formatMessage({
1319
+ id: 'UnnamedColumn'
1320
+ }), item.groupHeader && item.groupHeader.length > 0 ? `(${item.groupHeader.map(({
1321
+ title
1322
+ }) => title).join('-')})` : '']
1323
+ });
1324
+ };
1325
+ const collapseItems = useMemo(() => {
1326
+ return [{
1327
+ key: 'active',
1328
+ label: formatMessage({
1329
+ id: 'VisibleInfo'
1330
+ }),
1331
+ children: /*#__PURE__*/jsxs("div", {
1332
+ className: configStyle['columns-control-content-list'],
1333
+ children: [leftFixedColumns.map((item, index) => /*#__PURE__*/jsx("div", {
1334
+ className: configStyle['columns-control-content-item'],
1335
+ children: /*#__PURE__*/jsx(Checkbox, {
1336
+ checked: true,
1337
+ disabled: true,
1338
+ children: renderColumn(item)
1339
+ })
1340
+ }, item.name || `left-${index}`)), /*#__PURE__*/jsx(ReactSortable, {
1341
+ tag: "div",
1342
+ className: configStyle['columns-control-sortable-list'],
1343
+ list: sortableVisibleColumns,
1344
+ filter: ".ignore-elements",
1345
+ dragClass: "table-page-sortable-drag",
1346
+ ghostClass: "table-page-sortable-ghost",
1347
+ chosenClass: "table-page-sortable-chosen",
1348
+ forceFallback: true,
1349
+ fallbackOnBody: true,
1350
+ scroll: scrollEl || true,
1351
+ bubbleScroll: true,
1352
+ setList: nextVisibleColumns => {
1353
+ handlerColumnsChange({
1354
+ leftFixedColumns,
1355
+ visibleColumns: nextVisibleColumns,
1356
+ hiddenColumns,
1357
+ rightFixedColumns
1358
+ });
1359
+ },
1360
+ animation: 300,
1361
+ delayOnTouchStart: true,
1362
+ delay: 2,
1363
+ children: sortableVisibleColumns.map(item => /*#__PURE__*/jsxs("div", {
1364
+ className: classnames(configStyle['columns-control-content-item'], configStyle['is-drag']),
1365
+ children: [/*#__PURE__*/jsx(HolderOutlined, {
1366
+ className: configStyle['columns-control-content-item-icon']
1367
+ }), /*#__PURE__*/jsx(Checkbox, {
1368
+ checked: true,
1369
+ disabled: item.fixed || leftFixedColumns.length + visibleColumns.length + rightFixedColumns.length <= 1,
1370
+ onChange: e => {
1371
+ e.stopPropagation();
1372
+ e.preventDefault();
1373
+ const newConfig = Object.assign({}, config);
1374
+ newConfig[item.name] = Object.assign({}, newConfig[item.name], {
1375
+ visible: false
1376
+ });
1377
+ onChange(newConfig);
1378
+ },
1379
+ children: renderColumn(item)
1380
+ })]
1381
+ }, item.id))
1382
+ }), rightFixedColumns.map((item, index) => /*#__PURE__*/jsx("div", {
1383
+ className: configStyle['columns-control-content-item'],
1384
+ children: /*#__PURE__*/jsx(Checkbox, {
1385
+ checked: true,
1386
+ disabled: true,
1387
+ children: item.titleText || item.title || formatMessage({
1388
+ id: 'UnnamedColumn'
1389
+ })
1390
+ })
1391
+ }, item.name || `right-${index}`))]
1392
+ })
1393
+ }, {
1394
+ key: 'un-active',
1395
+ label: /*#__PURE__*/jsxs(Row, {
1396
+ wrap: false,
1397
+ justify: "space-between",
1398
+ children: [/*#__PURE__*/jsx(Col, {
1399
+ children: formatMessage({
1400
+ id: 'HiddenInfo'
1401
+ })
1402
+ }), /*#__PURE__*/jsx(Col, {
1403
+ onClick: e => {
1404
+ e.stopPropagation();
1405
+ e.preventDefault();
1406
+ },
1407
+ children: /*#__PURE__*/jsx(Input.Search, {
1408
+ placeholder: formatMessage({
1409
+ id: 'Search'
1410
+ }),
1411
+ onSearch: value => setSearchText(value),
1412
+ className: configStyle['columns-control-content-input'],
1413
+ size: "small",
1414
+ allowClear: true
1415
+ })
1416
+ })]
1417
+ }),
1418
+ children: /*#__PURE__*/jsx(List, {
1419
+ dataSource: hiddenColumns.filter(item => {
1420
+ const title = item.titleText || item.title;
1421
+ return typeof title === 'string' && title.indexOf(searchText) > -1;
1422
+ }),
1423
+ renderItem: item => /*#__PURE__*/jsx(List.Item, {
1424
+ className: configStyle['columns-control-content-item'],
1425
+ children: /*#__PURE__*/jsx(Checkbox, {
1426
+ checked: false,
1427
+ onChange: e => {
1428
+ e.stopPropagation();
1429
+ e.preventDefault();
1430
+ const newConfig = Object.assign({}, config);
1431
+ newConfig[item.name] = Object.assign({}, newConfig[item.name], {
1432
+ visible: true
1433
+ });
1434
+ onChange(newConfig);
1435
+ },
1436
+ children: item.titleText || item.title || formatMessage({
1437
+ id: 'UnnamedColumn'
1438
+ })
1439
+ })
1440
+ }, item.name)
1441
+ })
1442
+ }];
1443
+ }, [config, formatMessage, hiddenColumns, leftFixedColumns, onChange, rightFixedColumns, scrollEl, searchText, sortableVisibleColumns, visibleColumns.length]);
1444
+ return /*#__PURE__*/jsxs("div", {
1445
+ className: configStyle['columns-control-content'],
1446
+ children: [/*#__PURE__*/jsx("div", {
1447
+ className: configStyle['columns-control-content-title'],
1448
+ children: /*#__PURE__*/jsxs(Row, {
1449
+ align: "middle",
1450
+ justify: "space-between",
1451
+ children: [/*#__PURE__*/jsx(Col, {
1452
+ children: formatMessage({
1453
+ id: 'EditTable'
1454
+ })
1455
+ }), /*#__PURE__*/jsx(Col, {
1456
+ children: /*#__PURE__*/jsx(Tooltip, {
1457
+ title: formatMessage({
1458
+ id: 'RestoreDefault'
1459
+ }),
1460
+ children: /*#__PURE__*/jsx(Button, {
1461
+ type: "text",
1462
+ icon: /*#__PURE__*/jsx(RedoOutlined, {}),
1463
+ onClick: async () => {
1464
+ onConfirm && (await onConfirm({}));
1465
+ close();
1466
+ }
1467
+ })
1468
+ })
1469
+ })]
1470
+ })
1471
+ }), /*#__PURE__*/jsx("div", {
1472
+ className: configStyle['columns-control-content-scroller'],
1473
+ ref: setScrollEl,
1474
+ children: /*#__PURE__*/jsx(Collapse, {
1475
+ defaultActiveKey: ['active', 'un-active'],
1476
+ ghost: true,
1477
+ bordered: true,
1478
+ items: collapseItems
1479
+ })
1480
+ }), /*#__PURE__*/jsxs(Row, {
1481
+ className: configStyle['columns-control-content-footer'],
1482
+ justify: "end",
1483
+ gutter: 10,
1484
+ children: [/*#__PURE__*/jsx(Col, {
1485
+ children: /*#__PURE__*/jsx(Button, {
1486
+ size: "small",
1487
+ onClick: () => {
1488
+ onChange(defaultValue || {});
1489
+ close();
1490
+ },
1491
+ children: formatMessage({
1492
+ id: 'Cancel'
1493
+ })
1494
+ })
1495
+ }), /*#__PURE__*/jsx(Col, {
1496
+ children: /*#__PURE__*/jsx(Button, {
1497
+ type: "primary",
1498
+ size: "small",
1499
+ loading: confirmLoading,
1500
+ onClick: async () => {
1501
+ setConfirmLoading(true);
1502
+ try {
1503
+ onConfirm && (await onConfirm(config));
1504
+ close();
1505
+ } finally {
1506
+ setConfirmLoading(false);
1507
+ }
1508
+ },
1509
+ children: formatMessage({
1510
+ id: 'Confirm'
1511
+ })
1512
+ })
1513
+ })]
1514
+ })]
1515
+ });
1516
+ });
1517
+
1518
+ const storageKey = 'TABLE_PAGE_TABLE_CONFIG';
1519
+ const readStorage = () => {
1520
+ try {
1521
+ return JSON.parse(localStorage.getItem(storageKey) || '{}');
1522
+ } catch (_unused) {
1523
+ return {};
1524
+ }
1525
+ };
1526
+ const writeStorage = data => {
1527
+ try {
1528
+ localStorage.setItem(storageKey, JSON.stringify(data));
1529
+ } catch (_unused2) {
1530
+ // ignore quota errors
1531
+ }
1532
+ };
1533
+ const getData = name => {
1534
+ if (!name) {
1535
+ return {};
1536
+ }
1537
+ return get(readStorage(), name, {});
1538
+ };
1539
+ const setData = (name, data) => {
1540
+ if (!name) {
1541
+ return;
1542
+ }
1543
+ writeStorage(Object.assign({}, readStorage(), {
1544
+ [name]: data
1545
+ }));
1546
+ };
1547
+ const tableLocalApis = {
1548
+ getData,
1549
+ setData
1550
+ };
1551
+
1552
+ const TABLE_CONFIG_COLUMN_EXTRA_WIDTH = 48;
1553
+
1554
+ const DEFAULT_WIDTH = 160;
1555
+ const DEFAULT_MIN = 80;
1556
+ const DEFAULT_MAX = 600;
1557
+ const getColumnSize = column => {
1558
+ var _column$min, _column$max;
1559
+ const width = parseColumnWidth(column.width) || DEFAULT_WIDTH;
1560
+ return {
1561
+ width,
1562
+ min: (_column$min = column.min) != null ? _column$min : DEFAULT_MIN,
1563
+ max: (_column$max = column.max) != null ? _column$max : DEFAULT_MAX
1564
+ };
1565
+ };
1566
+ const getConfigColumnExtraWidth = (index, columnCount, controllerOpen) => {
1567
+ if (!controllerOpen || index !== columnCount - 1) {
1568
+ return 0;
1569
+ }
1570
+ return TABLE_CONFIG_COLUMN_EXTRA_WIDTH;
1571
+ };
1572
+ const withConfigColumnExtra = (contentWidth, index, columnCount, controllerOpen) => {
1573
+ return contentWidth + getConfigColumnExtraWidth(index, columnCount, controllerOpen);
1574
+ };
1575
+ const TableConfigButton = ({
1576
+ title,
1577
+ columns,
1578
+ config,
1579
+ setConfig
1580
+ }) => {
1581
+ const [open, setOpen] = useState(false);
1582
+ return /*#__PURE__*/jsxs(Row, {
1583
+ wrap: false,
1584
+ align: "middle",
1585
+ className: configStyle['table-config-header'],
1586
+ children: [/*#__PURE__*/jsx(Col, {
1587
+ flex: 1,
1588
+ className: configStyle['table-config-header-title'],
1589
+ children: title
1590
+ }), /*#__PURE__*/jsx(Col, {
1591
+ flex: "none",
1592
+ children: /*#__PURE__*/jsx(Popover, {
1593
+ open: open,
1594
+ onOpenChange: setOpen,
1595
+ trigger: "click",
1596
+ placement: "bottomLeft",
1597
+ rootClassName: configStyle['columns-control-overlay'],
1598
+ styles: {
1599
+ container: {
1600
+ padding: 0
1601
+ }
1602
+ },
1603
+ content: /*#__PURE__*/jsx(ColumnsControlContent, {
1604
+ columns: columns,
1605
+ config: config,
1606
+ close: () => setOpen(false),
1607
+ onConfirm: newConfig => {
1608
+ setConfig(configValue => {
1609
+ return transform(newConfig, (result, value, key) => {
1610
+ result[key] = Object.assign({}, configValue[key], pick(value, ['visible', 'rank']));
1611
+ }, {});
1612
+ });
1613
+ }
1614
+ }),
1615
+ children: /*#__PURE__*/jsx("span", {
1616
+ className: classnames(configStyle['table-changer-setting'], open && configStyle['is-active']),
1617
+ children: /*#__PURE__*/jsx(SettingOutlined, {})
1618
+ })
1619
+ })
1620
+ })]
1621
+ });
1622
+ };
1623
+ const useTableConfig = ({
1624
+ columns,
1625
+ name,
1626
+ controllerOpen: _controllerOpen = true,
1627
+ tableWidth: _tableWidth = 0,
1628
+ rowKey,
1629
+ tableServerApis: _tableServerApis = tableLocalApis
1630
+ }) => {
1631
+ const [currentMoveColumnIndex, setCurrentMoveColumnIndex] = useState(null);
1632
+ const currentMoveColumnIndexRef = useRef(currentMoveColumnIndex);
1633
+ currentMoveColumnIndexRef.current = currentMoveColumnIndex;
1634
+ const currentMoveColumnRef = useRef(null);
1635
+ const startPointRef = useRef(null);
1636
+ const [config, setConfigBase] = useState({});
1637
+ const saveConfig = useDebouncedCallback((tableName, target) => {
1638
+ _tableServerApis == null || _tableServerApis.setData(tableName, target);
1639
+ }, 500);
1640
+ const setConfig = useCallback(newConfig => {
1641
+ setConfigBase(prevConfig => {
1642
+ const target = typeof newConfig === 'function' ? newConfig(prevConfig) : newConfig;
1643
+ if (name && _controllerOpen) {
1644
+ saveConfig(name, target);
1645
+ }
1646
+ return target;
1647
+ });
1648
+ }, [name, _controllerOpen, saveConfig]);
1649
+ useEffect(() => {
1650
+ if (name && _controllerOpen) {
1651
+ setConfigBase(Object.assign({}, _tableServerApis.getData(name)));
1652
+ }
1653
+ }, [name, _controllerOpen, _tableServerApis]);
1654
+ const visibleColumns = useMemo(() => {
1655
+ return columns.filter(col => !(get(config, `${col.name}.visible`) === false || get(config, `${col.name}.visible`) !== true && col.hidden === true)).sort((a, b) => {
1656
+ const computedIndex = item => get(config, `${item.name}.rank`, 0) + (item.fixed === 'left' || item.fixed === true ? -10000 : 0) + (item.fixed === 'right' ? 10000 : 0);
1657
+ return computedIndex(a) - computedIndex(b);
1658
+ });
1659
+ }, [columns, config]);
1660
+ const columnCount = visibleColumns.length;
1661
+ const hasFixedColumn = useMemo(() => visibleColumns.some(col => col.fixed === 'right' || col.fixed === 'left' || col.fixed === true), [visibleColumns]);
1662
+ const lastNotFixedColumnIndex = useMemo(() => {
1663
+ return findLastIndex(visibleColumns, col => col.fixed !== 'right' && !isOptionsColumn(col));
1664
+ }, [visibleColumns]);
1665
+ const totalWidth = useMemo(() => {
1666
+ return visibleColumns.reduce((sum, col, index) => {
1667
+ const {
1668
+ width
1669
+ } = getColumnSize(col);
1670
+ const contentWidth = get(config, `${col.name}.width`) || width;
1671
+ return sum + withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen);
1672
+ }, 0);
1673
+ }, [visibleColumns, config, columnCount, _controllerOpen]);
1674
+ const computedRealWidth = useCallback(({
1675
+ width,
1676
+ index
1677
+ }) => {
1678
+ const contentWidth = width;
1679
+ if (currentMoveColumnIndex !== null && currentMoveColumnIndex === index) {
1680
+ return withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen);
1681
+ }
1682
+ if (hasFixedColumn || lastNotFixedColumnIndex !== index) {
1683
+ return withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen);
1684
+ }
1685
+ return withConfigColumnExtra(contentWidth, index, columnCount, _controllerOpen) + Math.max(_tableWidth - totalWidth - 2, 0);
1686
+ }, [hasFixedColumn, lastNotFixedColumnIndex, _tableWidth, totalWidth, currentMoveColumnIndex, columnCount, _controllerOpen]);
1687
+ const getConfigWidth = useCallback(column => {
1688
+ const {
1689
+ width,
1690
+ min,
1691
+ max
1692
+ } = getColumnSize(column);
1693
+ const currentWidth = Math.min(Math.max(get(config, `${column.name}.width`) || width, min), max);
1694
+ return {
1695
+ currentWidth,
1696
+ min,
1697
+ max
1698
+ };
1699
+ }, [config]);
1700
+ const resizeBarRender = useCallback((column, index) => {
1701
+ return /*#__PURE__*/jsx("span", {
1702
+ className: classnames(configStyle['cell-resize-bar'], 'table-cell-resize-bar'),
1703
+ onMouseDown: e => {
1704
+ e.stopPropagation();
1705
+ const {
1706
+ currentWidth,
1707
+ min,
1708
+ max
1709
+ } = getConfigWidth(column);
1710
+ currentMoveColumnRef.current = Object.assign({}, column, {
1711
+ index,
1712
+ width: currentWidth,
1713
+ min,
1714
+ max
1715
+ });
1716
+ startPointRef.current = e.clientX;
1717
+ setCurrentMoveColumnIndex(index);
1718
+ },
1719
+ children: /*#__PURE__*/jsx(HolderOutlined, {})
1720
+ });
1721
+ }, [getConfigWidth]);
1722
+ const resize = useRefCallback(delta => {
1723
+ if (currentMoveColumnIndexRef.current === null || !currentMoveColumnRef.current) {
1724
+ return;
1725
+ }
1726
+ const {
1727
+ name: colName,
1728
+ width,
1729
+ min,
1730
+ max
1731
+ } = currentMoveColumnRef.current;
1732
+ const currentWidth = Math.min(Math.max(width + delta, min), max);
1733
+ if (currentWidth < min) {
1734
+ return;
1735
+ }
1736
+ setConfig(prevConfig => Object.assign({}, prevConfig, {
1737
+ [colName]: Object.assign({}, prevConfig[colName], {
1738
+ width: currentWidth
1739
+ })
1740
+ }));
1741
+ });
1742
+ const renderColumnTitle = useCallback((title, column, index, {
1743
+ withResize: _withResize = true,
1744
+ withConfig: _withConfig = false
1745
+ } = {}) => {
1746
+ const titleNode = _withConfig ? /*#__PURE__*/jsx(TableConfigButton, {
1747
+ title: title,
1748
+ columns: columns,
1749
+ config: config,
1750
+ setConfig: setConfig
1751
+ }) : title;
1752
+ const content = /*#__PURE__*/jsxs(Fragment, {
1753
+ children: [titleNode, _withResize && _controllerOpen && resizeBarRender(column, index)]
1754
+ });
1755
+ if (!_withResize || !_controllerOpen) {
1756
+ return content;
1757
+ }
1758
+ return /*#__PURE__*/jsx("span", {
1759
+ className: configStyle['header-cell-inner'],
1760
+ children: content
1761
+ });
1762
+ }, [columns, config, _controllerOpen, resizeBarRender, setConfig]);
1763
+ const getHeaderCellClassName = useCallback(index => classnames(configStyle['header-col'], {
1764
+ 'is-moving': currentMoveColumnIndexRef.current === index
1765
+ }), []);
1766
+ const computedColumnProps = useCallback((column, index, {
1767
+ title
1768
+ }) => {
1769
+ const {
1770
+ currentWidth
1771
+ } = getConfigWidth(column);
1772
+ const realWidth = computedRealWidth({
1773
+ width: currentWidth,
1774
+ index
1775
+ });
1776
+ const isLastColumn = index === columnCount - 1;
1777
+ const movingClass = () => ({
1778
+ className: classnames({
1779
+ 'is-moving': currentMoveColumnIndex === index,
1780
+ 'has-config-btn': isLastColumn && _controllerOpen
1781
+ })
1782
+ });
1783
+ return {
1784
+ onHeaderCell: movingClass,
1785
+ onCell: movingClass,
1786
+ width: realWidth,
1787
+ shouldCellUpdate: (record, prevRecord) => {
1788
+ const itemKey = typeof rowKey === 'function' ? rowKey(record) : record[rowKey];
1789
+ const prevItemKey = typeof rowKey === 'function' ? rowKey(prevRecord) : prevRecord[rowKey];
1790
+ return currentMoveColumnIndexRef.current === null || currentMoveColumnIndexRef.current === index || !(itemKey === prevItemKey && isEqual(record[column.name], prevRecord[column.name]));
1791
+ },
1792
+ title: renderColumnTitle(title, column, index, {
1793
+ withResize: true,
1794
+ withConfig: isLastColumn && _controllerOpen
1795
+ })
1796
+ };
1797
+ }, [columnCount, _controllerOpen, computedRealWidth, getConfigWidth, renderColumnTitle, rowKey, currentMoveColumnIndex]);
1798
+ useEffect(() => {
1799
+ const handlerCancelResize = () => {
1800
+ setCurrentMoveColumnIndex(null);
1801
+ startPointRef.current = null;
1802
+ currentMoveColumnRef.current = null;
1803
+ };
1804
+ const handlerResize = e => {
1805
+ if (currentMoveColumnIndexRef.current === null || currentMoveColumnRef.current === null || startPointRef.current === null) {
1806
+ return;
1807
+ }
1808
+ resize(e.clientX - startPointRef.current);
1809
+ };
1810
+ document.documentElement.addEventListener('mouseup', handlerCancelResize, true);
1811
+ document.documentElement.addEventListener('mousemove', handlerResize, true);
1812
+ return () => {
1813
+ document.documentElement.removeEventListener('mouseup', handlerCancelResize, true);
1814
+ document.documentElement.removeEventListener('mousemove', handlerResize, true);
1815
+ };
1816
+ }, [resize]);
1817
+ return {
1818
+ visibleColumns,
1819
+ columnsConfig: config,
1820
+ setConfig,
1821
+ currentMoveColumnIndex,
1822
+ totalWidth,
1823
+ hasFixedColumn,
1824
+ computedColumnProps,
1825
+ renderColumnTitle,
1826
+ getHeaderCellClassName,
1827
+ getConfigWidth,
1828
+ computedRealWidth,
1829
+ resizeBarRender
1830
+ };
1831
+ };
1832
+
1833
+ const useGroupHeader = columns => {
1834
+ return useMemo(() => {
1835
+ const groupHeaderColumns = columns.filter(item => item.groupHeader && item.groupHeader.length > 0);
1836
+ if (groupHeaderColumns.length > 0) {
1837
+ const newColumns = columns.slice(0);
1838
+ const group = [];
1839
+ const appendGroupHeader = column => {
1840
+ const {
1841
+ groupHeader
1842
+ } = column;
1843
+ if (!(groupHeader && groupHeader.length > 0)) {
1844
+ return;
1845
+ }
1846
+ const columnIndex = newColumns.indexOf(column);
1847
+ const core = (groupHeader, groupList) => {
1848
+ const [targetHeader, ...otherHeader] = groupHeader;
1849
+ let currentGroup = groupList.find(item => item.name === targetHeader.name);
1850
+ if (!currentGroup) {
1851
+ currentGroup = Object.assign({
1852
+ startIndex: columnIndex
1853
+ }, targetHeader, {
1854
+ children: []
1855
+ });
1856
+ groupList.push(currentGroup);
1857
+ }
1858
+ if (otherHeader.length > 0) {
1859
+ core(otherHeader, currentGroup.children);
1860
+ } else {
1861
+ currentGroup.children.push(column);
1862
+ }
1863
+ };
1864
+ core(groupHeader, group);
1865
+ newColumns.splice(columnIndex, 1);
1866
+ };
1867
+ groupHeaderColumns.forEach(appendGroupHeader);
1868
+ group.forEach((groupColumn, index) => {
1869
+ newColumns.splice(groupColumn.startIndex + index, 0, groupColumn);
1870
+ });
1871
+ return {
1872
+ columns: newColumns,
1873
+ hasGroupHeader: true
1874
+ };
1875
+ }
1876
+ return {
1877
+ columns,
1878
+ hasGroupHeader: false
1879
+ };
1880
+ }, [columns]);
1881
+ };
1882
+
1883
+ const useElementWidth = ref => {
1884
+ const [width, setWidth] = useState(0);
1885
+ useEffect(() => {
1886
+ const el = ref.current;
1887
+ if (!el) {
1888
+ return;
1889
+ }
1890
+ const update = () => setWidth(el.clientWidth);
1891
+ const resizeObserver = new ResizeObserver(update);
1892
+ resizeObserver.observe(el);
1893
+ update();
1894
+ return () => resizeObserver.disconnect();
1895
+ }, [ref]);
1896
+ return width;
1897
+ };
1898
+
1899
+ const renderCellContent = (content, column, contentClassName) => {
1900
+ const wrapEllipsis = column.ellipsis && !column.ellipsisHandledByRender;
1901
+ const needsWidthConstraint = Boolean(column.ellipsis || column.cellFullWidth);
1902
+ const inner = wrapEllipsis ? /*#__PURE__*/jsx(Ellipsis, {
1903
+ ellipsis: column.ellipsis,
1904
+ children: content
1905
+ }) : content;
1906
+ return /*#__PURE__*/jsx("span", {
1907
+ className: contentClassName,
1908
+ children: needsWidthConstraint ? /*#__PURE__*/jsx("span", {
1909
+ className: classnames(ellipsisStyle['cell-content'], column.cellFullWidth && ellipsisStyle['cell-full-width']),
1910
+ children: inner
1911
+ }) : inner
1912
+ });
1913
+ };
1914
+ const getColumnEllipsis = column => {
1915
+ if (!column.ellipsis) {
1916
+ return undefined;
1917
+ }
1918
+ return typeof column.ellipsis === 'object' ? column.ellipsis : true;
1919
+ };
1920
+
1921
+ const _excluded$3 = ["className", "dataSource", "columns", "rowKey", "rowSelection", "valueIsEmpty", "emptyIsPlaceholder", "placeholder", "empty", "onRowSelect", "render", "context", "sticky", "headerStyle", "pagination", "sortRender", "name", "controllerOpen", "tableServerApis", "scroll", "summary"];
1922
+ const mapJustifyToAlign = justify => {
1923
+ if (justify === 'center') {
1924
+ return 'center';
1925
+ }
1926
+ if (justify === 'flex-end') {
1927
+ return 'right';
1928
+ }
1929
+ return 'left';
1930
+ };
1931
+ const resolveRowKey = (rowKey, record) => get(record, typeof rowKey === 'function' ? rowKey(record) : rowKey);
1932
+ const toAntdWidth = width => {
1933
+ if (width == null) {
1934
+ return undefined;
1935
+ }
1936
+ if (typeof width === 'number') {
1937
+ return width;
1938
+ }
1939
+ const parsed = parseColumnWidth(width);
1940
+ return parsed || width;
1941
+ };
1942
+ const toAntdFixed = fixed => {
1943
+ if (fixed === 'right') {
1944
+ return 'right';
1945
+ }
1946
+ if (fixed === true || fixed === 'left') {
1947
+ return 'left';
1948
+ }
1949
+ return undefined;
1950
+ };
1951
+ const getColCellStyle = column => ({
1952
+ textAlign: mapJustifyToAlign(column.justify),
1953
+ verticalAlign: column.align === 'middle' ? 'middle' : column.align === 'bottom' ? 'bottom' : 'top'
1954
+ });
1955
+ const getAntCellClassName = (...extra) => classnames(style$3['table-cell'], 'info-page-table-col', ...extra);
1956
+ const wrapColContent = node => /*#__PURE__*/jsx("span", {
1957
+ className: style$4['col-content'],
1958
+ children: node
1959
+ });
1960
+ const Table = p => {
1961
+ const tableRef = useRef(null);
1962
+ const tableWidth = useElementWidth(tableRef);
1963
+ const [isLayout, setIsLayout] = useState(true);
1964
+ const props = Object.assign({}, {
1965
+ rowKey: 'id',
1966
+ valueIsEmpty: isEmpty,
1967
+ placeholder: '-',
1968
+ emptyIsPlaceholder: true,
1969
+ empty: /*#__PURE__*/jsx(Empty, {}),
1970
+ controllerOpen: true
1971
+ }, p);
1972
+ const {
1973
+ className,
1974
+ dataSource,
1975
+ columns: columnsProp,
1976
+ rowKey,
1977
+ rowSelection,
1978
+ valueIsEmpty,
1979
+ emptyIsPlaceholder,
1980
+ placeholder,
1981
+ empty,
1982
+ onRowSelect,
1983
+ render,
1984
+ context,
1985
+ sticky,
1986
+ headerStyle,
1987
+ pagination = false,
1988
+ sortRender,
1989
+ name,
1990
+ controllerOpen,
1991
+ tableServerApis,
1992
+ scroll,
1993
+ summary
1994
+ } = props,
1995
+ others = _objectWithoutPropertiesLoose(props, _excluded$3);
1996
+ const columns = useMemo(() => resolveColumns(columnsProp), [columnsProp]);
1997
+ useEffect(() => {
1998
+ if (tableWidth) {
1999
+ setTimeout(() => setIsLayout(false), 0);
2000
+ }
2001
+ }, [tableWidth]);
2002
+ const {
2003
+ visibleColumns,
2004
+ columnsConfig,
2005
+ currentMoveColumnIndex,
2006
+ totalWidth,
2007
+ computedColumnProps,
2008
+ hasFixedColumn
2009
+ } = useTableConfig({
2010
+ columns,
2011
+ name,
2012
+ controllerOpen,
2013
+ tableWidth,
2014
+ rowKey,
2015
+ tableServerApis
2016
+ });
2017
+ const [resizeGuideStyle, setResizeGuideStyle] = useState(null);
2018
+ const updateResizeGuide = useCallback(() => {
2019
+ var _barRect$right;
2020
+ if (currentMoveColumnIndex === null || !tableRef.current) {
2021
+ setResizeGuideStyle(null);
2022
+ return;
2023
+ }
2024
+ const root = tableRef.current;
2025
+ const headerCell = root.querySelector('.ant-table-thead .ant-table-cell.is-moving');
2026
+ const tableContainer = root.querySelector('.ant-table-container');
2027
+ if (!headerCell || !tableContainer) {
2028
+ setResizeGuideStyle(null);
2029
+ return;
2030
+ }
2031
+ const headerRect = headerCell.getBoundingClientRect();
2032
+ const resizeBar = headerCell.querySelector('.table-cell-resize-bar');
2033
+ const barRect = resizeBar == null ? void 0 : resizeBar.getBoundingClientRect();
2034
+ const containerRect = tableContainer.getBoundingClientRect();
2035
+ setResizeGuideStyle({
2036
+ position: 'fixed',
2037
+ left: Math.round((_barRect$right = barRect == null ? void 0 : barRect.right) != null ? _barRect$right : headerRect.right),
2038
+ top: Math.round(containerRect.top),
2039
+ height: Math.round(containerRect.height),
2040
+ zIndex: 100
2041
+ });
2042
+ }, [currentMoveColumnIndex]);
2043
+ useLayoutEffect(() => {
2044
+ updateResizeGuide();
2045
+ }, [updateResizeGuide, columnsConfig, tableWidth, dataSource, isLayout]);
2046
+ useEffect(() => {
2047
+ if (currentMoveColumnIndex === null) {
2048
+ return;
2049
+ }
2050
+ const handleUpdate = () => updateResizeGuide();
2051
+ window.addEventListener('mousemove', handleUpdate);
2052
+ window.addEventListener('scroll', handleUpdate, true);
2053
+ const resizeObserver = new ResizeObserver(handleUpdate);
2054
+ if (tableRef.current) {
2055
+ resizeObserver.observe(tableRef.current);
2056
+ }
2057
+ return () => {
2058
+ window.removeEventListener('mousemove', handleUpdate);
2059
+ window.removeEventListener('scroll', handleUpdate, true);
2060
+ resizeObserver.disconnect();
2061
+ };
2062
+ }, [currentMoveColumnIndex, updateResizeGuide]);
2063
+ const targetColumns = useMemo(() => visibleColumns.map((column, index) => Object.assign({}, column, {
2064
+ __index: index
2065
+ })), [visibleColumns]);
2066
+ const {
2067
+ columns: groupedColumns,
2068
+ hasGroupHeader
2069
+ } = useGroupHeader(targetColumns);
2070
+ const antdColumns = useMemo(() => {
2071
+ const buildLeafColumn = (column, index) => {
2072
+ const {
2073
+ name: colName,
2074
+ title,
2075
+ width,
2076
+ align,
2077
+ justify,
2078
+ fixed
2079
+ } = column;
2080
+ const baseColumn = {
2081
+ key: colName,
2082
+ dataIndex: colName,
2083
+ title: /*#__PURE__*/jsx("span", {
2084
+ className: style$4['col-content'],
2085
+ children: renderColumnTitle(title, column, sortRender)
2086
+ }),
2087
+ width: toAntdWidth(width),
2088
+ fixed: toAntdFixed(fixed),
2089
+ align: mapJustifyToAlign(justify),
2090
+ ellipsis: getColumnEllipsis(column),
2091
+ onHeaderCell: () => ({
2092
+ className: getAntCellClassName(),
2093
+ style: getColCellStyle(column)
2094
+ }),
2095
+ onCell: () => ({
2096
+ className: getAntCellClassName(),
2097
+ style: getColCellStyle(column)
2098
+ }),
2099
+ render: (_, record) => {
2100
+ const [computedColumn] = computeColumnsValue({
2101
+ columns: [column],
2102
+ emptyIsPlaceholder,
2103
+ valueIsEmpty,
2104
+ removeEmpty: false,
2105
+ dataSource: record,
2106
+ placeholder,
2107
+ context
2108
+ });
2109
+ if (!computedColumn) {
2110
+ return null;
2111
+ }
2112
+ return renderCellContent(computeDisplay({
2113
+ column: computedColumn,
2114
+ placeholder,
2115
+ dataSource: record,
2116
+ context
2117
+ }), computedColumn, style$4['col-content']);
2118
+ }
2119
+ };
2120
+ if (!controllerOpen) {
2121
+ return baseColumn;
2122
+ }
2123
+ const configProps = computedColumnProps(column, index, {
2124
+ title: /*#__PURE__*/jsx("span", {
2125
+ className: style$4['col-content'],
2126
+ children: renderColumnTitle(title, column, sortRender)
2127
+ })
2128
+ });
2129
+ const antdFixed = toAntdFixed(fixed);
2130
+ return Object.assign({}, baseColumn, configProps, {
2131
+ width: configProps.width,
2132
+ fixed: antdFixed,
2133
+ onHeaderCell: () => ({
2134
+ className: getAntCellClassName(configProps.onHeaderCell == null ? void 0 : configProps.onHeaderCell().className),
2135
+ style: getColCellStyle(column)
2136
+ }),
2137
+ onCell: () => ({
2138
+ className: getAntCellClassName(configProps.onCell == null ? void 0 : configProps.onCell().className),
2139
+ style: getColCellStyle(column)
2140
+ })
2141
+ });
2142
+ };
2143
+ const mapColumn = column => {
2144
+ if (column.children && column.children.length > 0) {
2145
+ return {
2146
+ key: column.name,
2147
+ title: /*#__PURE__*/jsx("span", {
2148
+ className: style$4['col-content'],
2149
+ children: column.title
2150
+ }),
2151
+ onHeaderCell: () => ({
2152
+ className: getAntCellClassName(),
2153
+ style: {
2154
+ textAlign: 'center',
2155
+ verticalAlign: 'middle'
2156
+ }
2157
+ }),
2158
+ children: column.children.map(mapColumn)
2159
+ };
2160
+ }
2161
+ return buildLeafColumn(column, column.__index);
2162
+ };
2163
+ return groupedColumns.map(mapColumn);
2164
+ }, [groupedColumns, context, emptyIsPlaceholder, placeholder, sortRender, valueIsEmpty, controllerOpen, computedColumnProps, currentMoveColumnIndex]);
2165
+ const antdRowSelection = useMemo(() => {
2166
+ if (!rowSelection) {
2167
+ return undefined;
2168
+ }
2169
+ const getRowKey = record => resolveRowKey(rowKey, record);
2170
+ return _extends({
2171
+ type: rowSelection.type === 'radio' ? 'radio' : 'checkbox'
2172
+ }, hasFixedColumn ? {
2173
+ fixed: 'left'
2174
+ } : {}, {
2175
+ selectedRowKeys: rowSelection.isSelectedAll ? (dataSource || []).filter(item => !item.disabled).map(getRowKey) : rowSelection.selectedRowKeys,
2176
+ onChange: (selectedRowKeys, selectedRows, info) => {
2177
+ if (info.type === 'all') {
2178
+ const _checked = selectedRowKeys.length > 0;
2179
+ if (typeof rowSelection.onIsSelectAllChange === 'function') {
2180
+ rowSelection.onIsSelectAllChange(_checked);
2181
+ return;
2182
+ }
2183
+ if (!_checked) {
2184
+ rowSelection.onChange([], undefined, {
2185
+ context,
2186
+ checked: false
2187
+ });
2188
+ return;
2189
+ }
2190
+ rowSelection.onChange((dataSource || []).map(getRowKey), undefined, {
2191
+ context,
2192
+ checked: true
2193
+ });
2194
+ return;
2195
+ }
2196
+ const currentKey = selectedRows.length > 0 ? getRowKey(selectedRows[selectedRows.length - 1]) : selectedRowKeys[selectedRowKeys.length - 1];
2197
+ const checked = selectedRowKeys.indexOf(currentKey) > -1;
2198
+ rowSelection.onChange(selectedRowKeys, currentKey, {
2199
+ context,
2200
+ checked
2201
+ });
2202
+ },
2203
+ getCheckboxProps: record => ({
2204
+ disabled: record.disabled || rowSelection.isSelectedAll
2205
+ })
2206
+ }, rowSelection.type === 'checkbox' ? {
2207
+ columnTitle: rowSelection.allowSelectedAll ? checkboxNode => wrapColContent(checkboxNode) : wrapColContent(/*#__PURE__*/jsx(Checkbox, {
2208
+ style: {
2209
+ visibility: 'hidden'
2210
+ }
2211
+ })),
2212
+ renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
2213
+ onCell: () => ({
2214
+ className: getAntCellClassName(style$3['selection-col'])
2215
+ })
2216
+ } : {
2217
+ columnWidth: 30,
2218
+ renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
2219
+ onCell: () => ({
2220
+ className: getAntCellClassName(style$3['radio-col'])
2221
+ })
2222
+ });
2223
+ }, [context, dataSource, rowKey, rowSelection, hasFixedColumn]);
2224
+ const tableScroll = useMemo(() => {
2225
+ let x;
2226
+ if (hasFixedColumn) {
2227
+ x = totalWidth;
2228
+ } else if (controllerOpen) {
2229
+ x = Math.max(tableWidth, totalWidth);
2230
+ }
2231
+ return Object.assign({}, x != null ? {
2232
+ x
2233
+ } : {}, scroll);
2234
+ }, [hasFixedColumn, controllerOpen, totalWidth, tableWidth, scroll]);
2235
+ const tableElement = /*#__PURE__*/jsx(Table$1, _extends({}, others, {
2236
+ showHeader: true,
2237
+ dataSource: dataSource,
2238
+ columns: antdColumns,
2239
+ rowKey: typeof rowKey === 'function' ? rowKey : record => get(record, rowKey),
2240
+ rowSelection: antdRowSelection,
2241
+ pagination: pagination,
2242
+ summary: typeof summary === 'function' ? (pageData, ...args) => summary(pageData, ...args) : undefined,
2243
+ sticky: sticky ? {
2244
+ offsetHeader: 0
2245
+ } : undefined,
2246
+ tableLayout: controllerOpen || hasFixedColumn ? 'fixed' : undefined,
2247
+ scroll: tableScroll,
2248
+ onHeaderRow: () => ({
2249
+ className: classnames(style$4['header'], 'info-page-table-header', {
2250
+ [style$4['sticky']]: sticky && !hasFixedColumn
2251
+ }),
2252
+ style: headerStyle
2253
+ }),
2254
+ locale: {
2255
+ emptyText: /*#__PURE__*/jsx("div", {
2256
+ className: style$4['empty'],
2257
+ children: empty
2258
+ })
2259
+ },
2260
+ rowClassName: record => {
2261
+ const id = resolveRowKey(rowKey, record);
2262
+ const isChecked = (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) && rowSelection.selectedRowKeys.indexOf(id) > -1;
2263
+ return classnames(style$4['body'], 'info-page-table-row', {
2264
+ [style$4['is-selected-all']]: rowSelection == null ? void 0 : rowSelection.isSelectedAll,
2265
+ [style$4['is-selected']]: isChecked,
2266
+ [style$4['is-disabled']]: record.disabled
2267
+ });
2268
+ },
2269
+ onRow: record => ({
2270
+ onClick: () => {
2271
+ if (record.disabled) {
2272
+ return;
2273
+ }
2274
+ onRowSelect && onRowSelect(record, {
2275
+ columns: visibleColumns,
2276
+ dataSource
2277
+ });
2278
+ }
2279
+ })
2280
+ }));
2281
+ const wrappedTable = /*#__PURE__*/jsxs("div", {
2282
+ ref: tableRef,
2283
+ className: classnames(style$4['table'], style$3['table'], 'info-page-table', className, {
2284
+ [style$3['is-resize']]: currentMoveColumnIndex !== null,
2285
+ [style$3['is-computed']]: isLayout,
2286
+ [style$3['has-group-header']]: hasGroupHeader,
2287
+ [style$3['has-summary']]: typeof summary === 'function'
2288
+ }),
2289
+ children: [/*#__PURE__*/jsx("div", {
2290
+ className: "info-page-table-body",
2291
+ children: !isLayout && tableElement
2292
+ }), currentMoveColumnIndex !== null && resizeGuideStyle && /*#__PURE__*/jsx("span", {
2293
+ className: style$3['column-resize-guide'],
2294
+ style: resizeGuideStyle,
2295
+ "aria-hidden": true
2296
+ })]
2297
+ });
2298
+ if (typeof render === 'function') {
2299
+ return render(_extends({}, others, {
2300
+ header: null,
2301
+ renderBody: () => wrappedTable
2302
+ }));
2303
+ }
2304
+ return wrappedTable;
2305
+ };
2306
+ Table.useSelectedRow = useSelectedRow;
2307
+ Table.useSort = useSort;
2308
+ Table.sortDataSource = useSort.sortDataSource;
2309
+
2310
+ const Label = ({
2311
+ className,
2312
+ children,
2313
+ onChange
2314
+ }) => {
2315
+ const ref = useRef(null);
2316
+ const handlerChange = useRefCallback(onChange);
2317
+ useLayoutEffect(() => {
2318
+ const computed = () => {
2319
+ if (!ref.current) {
2320
+ return;
2321
+ }
2322
+ handlerChange(ref.current.getBoundingClientRect());
2323
+ };
2324
+ const resizeObserver = new ResizeObserver(computed);
2325
+ resizeObserver.observe(ref.current);
2326
+ computed();
2327
+ return () => {
2328
+ resizeObserver.disconnect();
2329
+ };
2330
+ }, [handlerChange]);
2331
+ return /*#__PURE__*/jsx("span", {
2332
+ ref: ref,
2333
+ className: className,
2334
+ children: children
2335
+ });
2336
+ };
2337
+
2338
+ const renderHeaderCellContent = (column, {
2339
+ sortRender,
2340
+ widthBased,
2341
+ setColsSize,
2342
+ defaultSpan,
2343
+ colsSize
2344
+ }) => {
2345
+ const titleNode = renderColumnTitle(column.title, column, sortRender);
2346
+ const contentClassName = style$4['col-content'];
2347
+ if (widthBased) {
2348
+ return /*#__PURE__*/jsx("span", {
2349
+ className: contentClassName,
2350
+ children: titleNode
2351
+ });
2352
+ }
2353
+ return /*#__PURE__*/jsx(Label, {
2354
+ className: contentClassName,
2355
+ onChange: size => {
2356
+ setColsSize(value => Object.assign({}, value, {
2357
+ [column.name]: Math.max(size.width, parseColumnWidth(resolveColumnDimensions(column).width))
2358
+ }));
2359
+ },
2360
+ children: titleNode
2361
+ });
2362
+ };
2363
+ const renderHeaderGridCells = ({
2364
+ dataSource,
2365
+ columns,
2366
+ rowKey,
2367
+ rowSelection,
2368
+ colsSize,
2369
+ setColsSize,
2370
+ sortRender,
2371
+ defaultSpan
2372
+ }) => {
2373
+ const cells = [];
2374
+ if ((rowSelection == null ? void 0 : rowSelection.type) === 'checkbox') {
2375
+ cells.push(/*#__PURE__*/jsx("div", {
2376
+ className: classnames(style$4['col'], style$4['col-fixed'], style$4['header-cell'], 'info-page-table-col'),
2377
+ children: /*#__PURE__*/jsx("span", {
2378
+ className: classnames(style$4['col-content'], 'info-page-table-col-content'),
2379
+ children: rowSelection.allowSelectedAll ? (() => {
2380
+ const checkedAll = rowSelection.isSelectedAll || dataSource && dataSource.every(item => rowSelection.selectedRowKeys && rowSelection.selectedRowKeys.indexOf(get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey)) > -1);
2381
+ return /*#__PURE__*/jsx(Checkbox, {
2382
+ checked: checkedAll,
2383
+ indeterminate: rowSelection.selectedRowKeys && rowSelection.selectedRowKeys.length > 0 && !checkedAll,
2384
+ onChange: e => {
2385
+ const checked = e.target.checked;
2386
+ if (!checked) {
2387
+ typeof rowSelection.onIsSelectAllChange === 'function' ? rowSelection.onIsSelectAllChange(false) : rowSelection.onChange([]);
2388
+ } else {
2389
+ typeof rowSelection.onIsSelectAllChange === 'function' ? rowSelection.onIsSelectAllChange(true) : dataSource && dataSource.length > 0 && rowSelection.onChange(dataSource.map(item => {
2390
+ return get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey);
2391
+ }));
2392
+ }
2393
+ }
2394
+ });
2395
+ })() : /*#__PURE__*/jsx(Checkbox, {
2396
+ style: {
2397
+ visibility: 'hidden'
2398
+ }
2399
+ })
2400
+ })
2401
+ }, "__selection__"));
2402
+ }
2403
+ columns.forEach((column, index) => {
2404
+ const {
2405
+ widthBased,
2406
+ fillRemaining,
2407
+ style: columnStyle
2408
+ } = getColumnLayout(column, {
2409
+ defaultSpan,
2410
+ colsSize,
2411
+ isLastColumn: index === columns.length - 1,
2412
+ columns
2413
+ });
2414
+ cells.push(/*#__PURE__*/jsx("div", {
2415
+ style: columnStyle,
2416
+ className: classnames(style$4['col'], fillRemaining ? style$4['col-width-fill'] : widthBased && style$4['col-width-based'], style$4['header-cell'], 'info-page-table-col'),
2417
+ children: renderHeaderCellContent(column, {
2418
+ sortRender,
2419
+ widthBased,
2420
+ setColsSize,
2421
+ defaultSpan,
2422
+ colsSize
2423
+ })
2424
+ }, column.name));
2425
+ });
2426
+ if ((rowSelection == null ? void 0 : rowSelection.type) === 'radio') {
2427
+ cells.push(/*#__PURE__*/jsx("div", {
2428
+ className: classnames(style$4['col'], style$4['single-checked'], style$4['header-cell'], 'info-page-table-col')
2429
+ }, "__radio__"));
2430
+ }
2431
+ return cells;
2432
+ };
2433
+ const Header = p => {
2434
+ const {
2435
+ dataSource,
2436
+ columns,
2437
+ rowKey,
2438
+ rowSelection,
2439
+ colsSize,
2440
+ setColsSize,
2441
+ headerStyle,
2442
+ sortRender,
2443
+ defaultSpan
2444
+ } = Object.assign({}, {
2445
+ rowKey: 'id'
2446
+ }, p);
2447
+ return /*#__PURE__*/jsx("div", {
2448
+ style: headerStyle,
2449
+ className: classnames(style$4['header'], 'info-page-table-header'),
2450
+ children: renderHeaderGridCells({
2451
+ dataSource,
2452
+ columns,
2453
+ rowKey,
2454
+ rowSelection,
2455
+ colsSize,
2456
+ setColsSize,
2457
+ sortRender,
2458
+ defaultSpan
2459
+ })
2460
+ });
2461
+ };
2462
+
2463
+ const _excluded$2 = ["className", "dataSource", "columns", "rowKey", "rowSelection", "valueIsEmpty", "emptyIsPlaceholder", "placeholder", "empty", "onRowSelect", "render", "context", "sticky", "headerStyle", "sortRender"];
2464
+ const getLayoutColumns = columns => columns.filter(column => column.display !== false);
2465
+ const TableView = p => {
2466
+ const [colsSize, setColsSize] = useState({});
2467
+ const props = Object.assign({}, {
2468
+ rowKey: 'id',
2469
+ valueIsEmpty: isEmpty,
2470
+ placeholder: '-',
2471
+ emptyIsPlaceholder: true,
2472
+ empty: /*#__PURE__*/jsx(Empty, {})
2473
+ }, p);
2474
+ const {
2475
+ className,
2476
+ dataSource,
2477
+ columns: columnsProp,
2478
+ rowKey,
2479
+ rowSelection,
2480
+ valueIsEmpty,
2481
+ emptyIsPlaceholder,
2482
+ placeholder,
2483
+ empty,
2484
+ onRowSelect,
2485
+ render,
2486
+ context,
2487
+ headerStyle,
2488
+ sortRender
2489
+ } = props,
2490
+ others = _objectWithoutPropertiesLoose(props, _excluded$2);
2491
+ const columns = useMemo(() => resolveColumns(columnsProp), [columnsProp]);
2492
+ const layoutColumns = useMemo(() => getLayoutColumns(columns), [columns]);
2493
+ const defaultSpan = useMemo(() => {
2494
+ const assignedSpan = layoutColumns.reduce((a, b) => a + (b.span || 0), 0);
2495
+ const undistributedColCount = layoutColumns.filter(item => !hasColumnSpan(item) && !hasColumnWidth(item, layoutColumns)).length;
2496
+ return undistributedColCount > 0 ? Math.round(Math.max(24 - assignedSpan, 0) / undistributedColCount) : 1;
2497
+ }, [layoutColumns]);
2498
+ const gridTemplateColumns = useMemo(() => getGridTemplateColumns(layoutColumns, {
2499
+ defaultSpan,
2500
+ colsSize,
2501
+ rowSelection
2502
+ }), [layoutColumns, defaultSpan, colsSize, rowSelection]);
2503
+ const headerCellProps = {
2504
+ dataSource,
2505
+ columns: layoutColumns,
2506
+ rowKey,
2507
+ rowSelection,
2508
+ colsSize,
2509
+ setColsSize,
2510
+ sortRender,
2511
+ defaultSpan
2512
+ };
2513
+ const header = /*#__PURE__*/jsx(Header, _extends({}, headerCellProps, {
2514
+ headerStyle: headerStyle
2515
+ }));
2516
+ const handleRowClick = (item, {
2517
+ dataSource,
2518
+ context,
2519
+ id,
2520
+ isChecked
2521
+ }) => {
2522
+ if (item.disabled) {
2523
+ return;
2524
+ }
2525
+ onRowSelect && onRowSelect(item, {
2526
+ columns: layoutColumns,
2527
+ dataSource
2528
+ });
2529
+ if (!rowSelection || rowSelection.isSelectedAll) {
2530
+ return;
2531
+ }
2532
+ if (rowSelection.type === 'checkbox') {
2533
+ const _selectedRowKeys = (rowSelection.selectedRowKeys || []).slice(0);
2534
+ isChecked ? _selectedRowKeys.splice(rowSelection.selectedRowKeys.indexOf(id), 1) : _selectedRowKeys.push(id);
2535
+ rowSelection.onChange(_selectedRowKeys, id, {
2536
+ context,
2537
+ checked: !isChecked
2538
+ });
2539
+ return;
2540
+ }
2541
+ const selectedRowKeys = rowSelection.selectedRowKeys.length && rowSelection.selectedRowKeys[0] === id ? [] : [id];
2542
+ rowSelection.onChange(selectedRowKeys, id, {
2543
+ context,
2544
+ checked: !isChecked
2545
+ });
2546
+ };
2547
+ const renderBodyGridCells = (dataSource, context) => {
2548
+ const getId = item => get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey);
2549
+ if (!dataSource || dataSource.length === 0) {
2550
+ return null;
2551
+ }
2552
+ return dataSource.map(item => {
2553
+ const id = getId(item);
2554
+ const isChecked = (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) && rowSelection.selectedRowKeys.indexOf(id) > -1;
2555
+ const columnsValue = computeColumnsValue({
2556
+ columns: layoutColumns,
2557
+ emptyIsPlaceholder,
2558
+ valueIsEmpty,
2559
+ removeEmpty: true,
2560
+ dataSource: item,
2561
+ placeholder,
2562
+ context
2563
+ });
2564
+ const columnMap = columnsValue.reduce((result, column) => Object.assign(result, {
2565
+ [column.name]: column
2566
+ }), {});
2567
+ const rowClassName = classnames(style$4['body'], style$4['body-cell'], style$4['body-row'], 'info-page-table-row', {
2568
+ [style$4['is-selected-all']]: rowSelection == null ? void 0 : rowSelection.isSelectedAll,
2569
+ [style$4['is-selected']]: isChecked,
2570
+ [style$4['is-disabled']]: item.disabled
2571
+ });
2572
+ const onSelectionChange = () => handleRowClick(item, {
2573
+ dataSource,
2574
+ context,
2575
+ id,
2576
+ isChecked
2577
+ });
2578
+ const cells = [];
2579
+ if ((rowSelection == null ? void 0 : rowSelection.type) === 'checkbox') {
2580
+ cells.push(/*#__PURE__*/jsx("div", {
2581
+ className: classnames(style$4['col'], style$4['col-fixed'], 'info-page-table-col'),
2582
+ children: /*#__PURE__*/jsx("span", {
2583
+ className: classnames(style$4['col-content'], 'info-page-table-col-content'),
2584
+ children: /*#__PURE__*/jsx(Checkbox, {
2585
+ disabled: item.disabled || rowSelection.isSelectedAll,
2586
+ checked: rowSelection.isSelectedAll && !item.disabled || isChecked,
2587
+ onChange: onSelectionChange
2588
+ })
2589
+ })
2590
+ }, `${id}__selection__`));
2591
+ }
2592
+ layoutColumns.forEach((column, index) => {
2593
+ const columnValue = columnMap[column.name];
2594
+ const {
2595
+ widthBased,
2596
+ fillRemaining,
2597
+ style: columnStyle
2598
+ } = getColumnLayout(column, {
2599
+ defaultSpan,
2600
+ colsSize,
2601
+ isLastColumn: index === layoutColumns.length - 1,
2602
+ columns: layoutColumns
2603
+ });
2604
+ cells.push(/*#__PURE__*/jsx("div", {
2605
+ style: columnStyle,
2606
+ className: classnames(style$4['col'], fillRemaining ? style$4['col-width-fill'] : widthBased && style$4['col-width-based'], 'info-page-table-col'),
2607
+ children: columnValue ? renderCellContent(computeDisplay({
2608
+ column: columnValue,
2609
+ placeholder,
2610
+ dataSource: item,
2611
+ context
2612
+ }), columnValue, style$4['col-content']) : /*#__PURE__*/jsx("span", {
2613
+ className: style$4['col-content']
2614
+ })
2615
+ }, `${id}-${column.name}`));
2616
+ });
2617
+ if ((rowSelection == null ? void 0 : rowSelection.type) === 'radio') {
2618
+ cells.push(/*#__PURE__*/jsx("div", {
2619
+ className: classnames(style$4['col'], style$4['single-checked'], 'info-page-table-col'),
2620
+ onClick: onSelectionChange,
2621
+ children: isChecked && /*#__PURE__*/jsx(CheckOutlined, {})
2622
+ }, `${id}__radio__`));
2623
+ }
2624
+ return /*#__PURE__*/jsx("div", {
2625
+ className: rowClassName,
2626
+ children: cells
2627
+ }, id);
2628
+ });
2629
+ };
2630
+ const renderGrid = (dataSource, context) => /*#__PURE__*/jsxs("div", {
2631
+ className: style$4['grid'],
2632
+ style: {
2633
+ gridTemplateColumns
2634
+ },
2635
+ children: [renderHeaderGridCells(headerCellProps), renderBodyGridCells(dataSource, context)]
2636
+ });
2637
+ const renderBody = (dataSource, context) => {
2638
+ if (!dataSource || dataSource.length === 0) {
2639
+ return /*#__PURE__*/jsx("div", {
2640
+ className: style$4['empty'],
2641
+ children: empty
2642
+ });
2643
+ }
2644
+ return /*#__PURE__*/jsx("div", {
2645
+ className: classnames('info-page-table-body'),
2646
+ children: renderGrid(dataSource, context)
2647
+ });
2648
+ };
2649
+ if (typeof render === 'function') {
2650
+ return render(_extends({}, others, {
2651
+ header,
2652
+ renderBody
2653
+ }));
2654
+ }
2655
+ return /*#__PURE__*/jsx("div", _extends({}, others, {
2656
+ className: classnames(style$4['table'], style$4['tableView'], 'info-page-table', className),
2657
+ children: dataSource && dataSource.length > 0 ? renderGrid(dataSource, context) : /*#__PURE__*/jsxs(Fragment, {
2658
+ children: [/*#__PURE__*/jsx("div", {
2659
+ className: style$4['grid'],
2660
+ style: {
2661
+ gridTemplateColumns
2662
+ },
2663
+ children: renderHeaderGridCells(headerCellProps)
2664
+ }), /*#__PURE__*/jsx("div", {
2665
+ className: style$4['empty'],
2666
+ children: empty
2667
+ })]
2668
+ })
2669
+ }));
2670
+ };
2671
+ TableView.Header = Header;
2672
+ TableView.useSelectedRow = useSelectedRow;
2673
+ TableView.useSort = useSort;
2674
+ TableView.sortDataSource = useSort.sortDataSource;
2675
+
2676
+ var style$1 = {"table-page":"kne-table-page_ut9rJ","table-content":"kne-table-page_dxN6N","table-with-toolbar":"kne-table-page_sf06r","table-in-toolbar":"kne-table-page_sawIT","pagination":"kne-table-page_DSTEf","total_text":"kne-table-page_pJhKr","floating-scrollbar":"kne-table-page_iu8E1","floating-scrollbar-thumb":"kne-table-page_RjZsu","is-moving":"kne-table-page_y-4Ou"};
2677
+
2678
+ const parsePixelValue = value => {
2679
+ const num = parseFloat(value);
2680
+ return Number.isNaN(num) ? 0 : num;
2681
+ };
2682
+ const getViewportRect = () => {
2683
+ const visualViewport = window.visualViewport;
2684
+ if (visualViewport) {
2685
+ return {
2686
+ top: visualViewport.offsetTop,
2687
+ bottom: visualViewport.offsetTop + visualViewport.height,
2688
+ left: visualViewport.offsetLeft,
2689
+ right: visualViewport.offsetLeft + visualViewport.width,
2690
+ height: visualViewport.height
2691
+ };
2692
+ }
2693
+ return {
2694
+ top: 0,
2695
+ bottom: window.innerHeight,
2696
+ left: 0,
2697
+ right: window.innerWidth,
2698
+ height: window.innerHeight
2699
+ };
2700
+ };
2701
+ const getTableElement = root => {
2702
+ if (!root) {
2703
+ return null;
2704
+ }
2705
+ return root.querySelector('.info-page-table') || root;
2706
+ };
2707
+ const getTableScrollElement = root => {
2708
+ if (!root) {
2709
+ return null;
2710
+ }
2711
+ return root.querySelector('.ant-table-body') || root.querySelector('.ant-table-content');
2712
+ };
2713
+ const getElementViewportState = element => {
2714
+ if (!element) {
2715
+ return {
2716
+ isBottomInViewport: true,
2717
+ isPartiallyInViewport: false,
2718
+ isTopInViewport: true,
2719
+ rect: null,
2720
+ viewport: getViewportRect()
2721
+ };
2722
+ }
2723
+ const rect = element.getBoundingClientRect();
2724
+ const viewport = getViewportRect();
2725
+ return {
2726
+ isBottomInViewport: rect.bottom > viewport.top && rect.bottom <= viewport.bottom,
2727
+ isPartiallyInViewport: rect.top < viewport.bottom && rect.bottom > viewport.top,
2728
+ isTopInViewport: rect.top >= viewport.top && rect.top < viewport.bottom,
2729
+ rect,
2730
+ viewport
2731
+ };
2732
+ };
2733
+ const isTopEdgeInViewport = (element, scrollMarginTop = 0) => {
2734
+ const {
2735
+ isTopInViewport,
2736
+ rect,
2737
+ viewport
2738
+ } = getElementViewportState(element);
2739
+ if (!rect) {
2740
+ return true;
2741
+ }
2742
+ const viewportTop = viewport.top + scrollMarginTop;
2743
+ return rect.top >= viewportTop && rect.top < viewport.bottom;
2744
+ };
2745
+ const shouldShowFloatingScrollbar = (scrollEl, viewportState) => {
2746
+ if (!scrollEl || scrollEl.scrollWidth <= scrollEl.clientWidth + 1) {
2747
+ return false;
2748
+ }
2749
+ const state = viewportState || getElementViewportState(scrollEl);
2750
+ if (!state.isPartiallyInViewport) {
2751
+ return false;
2752
+ }
2753
+ return !state.isBottomInViewport;
2754
+ };
2755
+ const observeViewportIntersection = (element, onChange) => {
2756
+ var _window$visualViewpor, _window$visualViewpor2;
2757
+ if (!element) {
2758
+ return () => {};
2759
+ }
2760
+ const notify = entry => {
2761
+ onChange(getElementViewportState(element));
2762
+ };
2763
+ const observer = new IntersectionObserver(([entry]) => {
2764
+ notify();
2765
+ }, {
2766
+ root: null,
2767
+ threshold: [0, 0.01, 0.25, 0.5, 0.75, 1]
2768
+ });
2769
+ observer.observe(element);
2770
+ const handleViewportChange = () => {
2771
+ notify();
2772
+ };
2773
+ window.addEventListener('scroll', handleViewportChange, true);
2774
+ window.addEventListener('resize', handleViewportChange);
2775
+ (_window$visualViewpor = window.visualViewport) == null || _window$visualViewpor.addEventListener('resize', handleViewportChange);
2776
+ (_window$visualViewpor2 = window.visualViewport) == null || _window$visualViewpor2.addEventListener('scroll', handleViewportChange);
2777
+ notify();
2778
+ return () => {
2779
+ var _window$visualViewpor3, _window$visualViewpor4;
2780
+ observer.disconnect();
2781
+ window.removeEventListener('scroll', handleViewportChange, true);
2782
+ window.removeEventListener('resize', handleViewportChange);
2783
+ (_window$visualViewpor3 = window.visualViewport) == null || _window$visualViewpor3.removeEventListener('resize', handleViewportChange);
2784
+ (_window$visualViewpor4 = window.visualViewport) == null || _window$visualViewpor4.removeEventListener('scroll', handleViewportChange);
2785
+ };
2786
+ };
2787
+
2788
+ const BAR_HEIGHT = 15;
2789
+ const THUMB_MARGIN = 2;
2790
+ const computeBarMetrics = (scrollEl, viewportState) => {
2791
+ const rect = scrollEl.getBoundingClientRect();
2792
+ const viewport = getViewportRect();
2793
+ const trackWidth = rect.width;
2794
+ const thumbWidth = Math.max(trackWidth * scrollEl.clientWidth / scrollEl.scrollWidth - THUMB_MARGIN * 2, 24);
2795
+ const maxThumbOffset = trackWidth - thumbWidth - THUMB_MARGIN * 2;
2796
+ const scrollRatio = scrollEl.scrollWidth > scrollEl.clientWidth ? scrollEl.scrollLeft / (scrollEl.scrollWidth - scrollEl.clientWidth) : 0;
2797
+ return {
2798
+ left: rect.left,
2799
+ width: trackWidth,
2800
+ bottom: window.innerHeight - viewport.bottom,
2801
+ thumbWidth,
2802
+ thumbLeft: THUMB_MARGIN + maxThumbOffset * scrollRatio,
2803
+ visible: shouldShowFloatingScrollbar(scrollEl, viewportState)
2804
+ };
2805
+ };
2806
+ const FloatingScrollBar = ({
2807
+ metrics,
2808
+ onThumbDrag,
2809
+ getPortalContainer
2810
+ }) => {
2811
+ const startRef = useRef(0);
2812
+ const [moving, setMoving] = useState(false);
2813
+ const movingRef = useRef(false);
2814
+ const onThumbDragRef = useRef(onThumbDrag);
2815
+ onThumbDragRef.current = onThumbDrag;
2816
+ useEffect(() => {
2817
+ movingRef.current = moving;
2818
+ }, [moving]);
2819
+ useEffect(() => {
2820
+ const moveHandler = event => {
2821
+ if (!movingRef.current) {
2822
+ return;
2823
+ }
2824
+ onThumbDragRef.current(event.clientX - startRef.current);
2825
+ startRef.current = event.clientX;
2826
+ };
2827
+ const upHandler = () => {
2828
+ setMoving(false);
2829
+ };
2830
+ document.addEventListener('mousemove', moveHandler, true);
2831
+ document.addEventListener('mouseup', upHandler, true);
2832
+ return () => {
2833
+ document.removeEventListener('mousemove', moveHandler, true);
2834
+ document.removeEventListener('mouseup', upHandler, true);
2835
+ };
2836
+ }, []);
2837
+ if (!(metrics != null && metrics.visible)) {
2838
+ return null;
2839
+ }
2840
+ const portalTarget = (getPortalContainer == null ? void 0 : getPortalContainer()) || document.body;
2841
+ return /*#__PURE__*/createPortal(/*#__PURE__*/jsx("div", {
2842
+ className: classnames(style$1['floating-scrollbar'], 'table-page-floating-scrollbar'),
2843
+ style: {
2844
+ left: metrics.left,
2845
+ width: metrics.width,
2846
+ height: BAR_HEIGHT,
2847
+ bottom: metrics.bottom
2848
+ },
2849
+ children: /*#__PURE__*/jsx("div", {
2850
+ className: classnames(style$1['floating-scrollbar-thumb'], {
2851
+ [style$1['is-moving']]: moving
2852
+ }),
2853
+ style: {
2854
+ width: metrics.thumbWidth,
2855
+ left: metrics.thumbLeft
2856
+ },
2857
+ onMouseDown: event => {
2858
+ event.preventDefault();
2859
+ startRef.current = event.clientX;
2860
+ setMoving(true);
2861
+ }
2862
+ })
2863
+ }), portalTarget);
2864
+ };
2865
+ const HorizontalScroller = /*#__PURE__*/forwardRef(({
2866
+ className,
2867
+ enabled: _enabled = true,
2868
+ getPortalContainer,
2869
+ children
2870
+ }, forwardedRef) => {
2871
+ const [metrics, setMetrics] = useState(null);
2872
+ const containerRef = useRef(null);
2873
+ const scrollElRef = useRef(null);
2874
+ const viewportStateRef = useRef(null);
2875
+ const setContainerRef = useRefCallback(node => {
2876
+ containerRef.current = node;
2877
+ if (typeof forwardedRef === 'function') {
2878
+ forwardedRef(node);
2879
+ } else if (forwardedRef) {
2880
+ forwardedRef.current = node;
2881
+ }
2882
+ });
2883
+ const updateMetrics = useRefCallback(() => {
2884
+ const scrollEl = scrollElRef.current;
2885
+ if (!scrollEl) {
2886
+ setMetrics(null);
2887
+ return;
2888
+ }
2889
+ setMetrics(computeBarMetrics(scrollEl, viewportStateRef.current));
2890
+ });
2891
+ const handleThumbDrag = useRefCallback(deltaX => {
2892
+ const scrollEl = scrollElRef.current;
2893
+ if (!scrollEl) {
2894
+ return;
2895
+ }
2896
+ const trackWidth = scrollEl.clientWidth;
2897
+ const scrollableWidth = scrollEl.scrollWidth - scrollEl.clientWidth;
2898
+ const thumbWidth = Math.max(trackWidth * scrollEl.clientWidth / scrollEl.scrollWidth - THUMB_MARGIN * 2, 24);
2899
+ const thumbTravel = trackWidth - thumbWidth - THUMB_MARGIN * 2;
2900
+ if (thumbTravel <= 0) {
2901
+ return;
2902
+ }
2903
+ scrollEl.scrollLeft += deltaX / thumbTravel * scrollableWidth;
2904
+ updateMetrics();
2905
+ });
2906
+ useEffect(() => {
2907
+ if (!_enabled) {
2908
+ scrollElRef.current = null;
2909
+ viewportStateRef.current = null;
2910
+ setMetrics(null);
2911
+ return undefined;
2912
+ }
2913
+ const root = containerRef.current;
2914
+ if (!root) {
2915
+ return undefined;
2916
+ }
2917
+ let scrollEl = null;
2918
+ let unobserveViewport = null;
2919
+ let contentResizeObserver = null;
2920
+ const detachScrollEl = () => {
2921
+ var _contentResizeObserve;
2922
+ unobserveViewport == null || unobserveViewport();
2923
+ unobserveViewport = null;
2924
+ if (!scrollEl) {
2925
+ return;
2926
+ }
2927
+ scrollEl.removeEventListener('scroll', updateMetrics);
2928
+ (_contentResizeObserve = contentResizeObserver) == null || _contentResizeObserve.disconnect();
2929
+ contentResizeObserver = null;
2930
+ scrollElRef.current = null;
2931
+ viewportStateRef.current = null;
2932
+ scrollEl = null;
2933
+ };
2934
+ const attachScrollEl = nextScrollEl => {
2935
+ if (!nextScrollEl || nextScrollEl === scrollEl) {
2936
+ return;
2937
+ }
2938
+ detachScrollEl();
2939
+ scrollEl = nextScrollEl;
2940
+ scrollElRef.current = scrollEl;
2941
+ unobserveViewport = observeViewportIntersection(scrollEl, state => {
2942
+ viewportStateRef.current = state;
2943
+ updateMetrics();
2944
+ });
2945
+ scrollEl.addEventListener('scroll', updateMetrics, {
2946
+ passive: true
2947
+ });
2948
+ contentResizeObserver = new ResizeObserver(updateMetrics);
2949
+ contentResizeObserver.observe(scrollEl);
2950
+ Array.from(scrollEl.children).forEach(child => {
2951
+ contentResizeObserver.observe(child);
2952
+ });
2953
+ };
2954
+ const onLayoutChange = () => {
2955
+ attachScrollEl(getTableScrollElement(root));
2956
+ updateMetrics();
2957
+ };
2958
+ const containerResizeObserver = new ResizeObserver(onLayoutChange);
2959
+ containerResizeObserver.observe(root);
2960
+ onLayoutChange();
2961
+ return () => {
2962
+ detachScrollEl();
2963
+ containerResizeObserver.disconnect();
2964
+ };
2965
+ }, [_enabled, updateMetrics]);
2966
+ return /*#__PURE__*/jsxs(Fragment, {
2967
+ children: [/*#__PURE__*/jsx("div", {
2968
+ ref: setContainerRef,
2969
+ className: className,
2970
+ children: children
2971
+ }), _enabled ? /*#__PURE__*/jsx(FloatingScrollBar, {
2972
+ metrics: metrics,
2973
+ onThumbDrag: handleThumbDrag,
2974
+ getPortalContainer: getPortalContainer
2975
+ }) : null]
2976
+ });
2977
+ });
2978
+
2979
+ var style = {"table-toolbar-section":"kne-table-page_I21Xn","has-value-display":"kne-table-page_COnMY","table-toolbar":"kne-table-page_x6mv7","table-toolbar-value-display":"kne-table-page_vbwMg","table-toolbar-batch":"kne-table-page_k8-Ku","table-toolbar-search":"kne-table-page_pB5en","table-toolbar-batch-btn":"kne-table-page_gZtbT","table-toolbar-filter":"kne-table-page_Jyfm7","table-toolbar-divider":"kne-table-page_z--2N","table-toolbar-filter-inner":"kne-table-page_AX3aK"};
2980
+
2981
+ const _excluded$1 = ["list", "displayLine", "extraExpand", "className"],
2982
+ _excluded2$1 = ["className", "style"];
2983
+ const TableToolbar = ({
2984
+ filterValue,
2985
+ onFilterChange,
2986
+ filter,
2987
+ search,
2988
+ batchActions,
2989
+ rowSelection,
2990
+ selectedRows,
2991
+ batchContext
2992
+ }) => {
2993
+ var _filter$list;
2994
+ const {
2995
+ formatMessage
2996
+ } = useIntl();
2997
+ const selectedRowKeys = (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) || [];
2998
+ const hasSelection = selectedRowKeys.length > 0;
2999
+ const batchMenuItems = useMemo(() => {
3000
+ if (!Array.isArray(batchActions) || batchActions.length === 0) {
3001
+ return [];
3002
+ }
3003
+ return batchActions.map(item => {
3004
+ const {
3005
+ key,
3006
+ label,
3007
+ disabled,
3008
+ danger,
3009
+ onClick
3010
+ } = item;
3011
+ const isDisabled = disabled != null ? disabled : !hasSelection;
3012
+ return {
3013
+ key: key || label,
3014
+ label,
3015
+ danger,
3016
+ disabled: isDisabled,
3017
+ onClick: () => {
3018
+ if (isDisabled) {
3019
+ return;
3020
+ }
3021
+ onClick == null || onClick(_extends({
3022
+ selectedRowKeys,
3023
+ selectedRows: selectedRows || [],
3024
+ rowSelection
3025
+ }, batchContext));
3026
+ }
3027
+ };
3028
+ });
3029
+ }, [batchActions, batchContext, hasSelection, rowSelection, selectedRowKeys, selectedRows]);
3030
+ const showBatch = batchMenuItems.length > 0;
3031
+ const showFilter = (filter == null || (_filter$list = filter.list) == null ? void 0 : _filter$list.length) > 0;
3032
+ const showSearch = search && search.name;
3033
+ if (!showBatch && !showFilter && !showSearch) {
3034
+ return null;
3035
+ }
3036
+ const _ref = filter || {},
3037
+ {
3038
+ list: filterList,
3039
+ displayLine = 1,
3040
+ extraExpand,
3041
+ className: filterClassName
3042
+ } = _ref,
3043
+ filterRest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
3044
+ const _ref2 = search || {},
3045
+ {
3046
+ className: searchClassName,
3047
+ style: searchStyle
3048
+ } = _ref2,
3049
+ searchRest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
3050
+ const hasValueDisplay = (filterValue == null ? void 0 : filterValue.length) > 0;
3051
+ return /*#__PURE__*/jsx(FilterProvider, {
3052
+ value: filterValue,
3053
+ onChange: onFilterChange,
3054
+ children: /*#__PURE__*/jsxs("div", {
3055
+ className: classnames(style['table-toolbar-section'], 'table-page-toolbar-section', {
3056
+ [style['has-value-display']]: hasValueDisplay,
3057
+ 'table-page-toolbar-section--has-value': hasValueDisplay
3058
+ }),
3059
+ children: [/*#__PURE__*/jsxs("div", {
3060
+ className: style['table-toolbar'],
3061
+ children: [showBatch ? /*#__PURE__*/jsxs(Fragment, {
3062
+ children: [/*#__PURE__*/jsx("div", {
3063
+ className: style['table-toolbar-batch'],
3064
+ children: /*#__PURE__*/jsx(Dropdown, {
3065
+ disabled: !hasSelection,
3066
+ menu: {
3067
+ items: batchMenuItems
3068
+ },
3069
+ trigger: ['click'],
3070
+ children: /*#__PURE__*/jsxs(Button, {
3071
+ size: "small",
3072
+ disabled: !hasSelection,
3073
+ className: style['table-toolbar-batch-btn'],
3074
+ children: [hasSelection ? formatMessage({
3075
+ id: 'BatchOperationsWithCount'
3076
+ }, {
3077
+ count: selectedRowKeys.length
3078
+ }) : formatMessage({
3079
+ id: 'BatchOperations'
3080
+ }), /*#__PURE__*/jsx(DownOutlined, {})]
3081
+ })
3082
+ })
3083
+ }), (showFilter || showSearch) && /*#__PURE__*/jsx("span", {
3084
+ className: style['table-toolbar-divider'],
3085
+ "aria-hidden": true
3086
+ })]
3087
+ }) : null, showFilter ? /*#__PURE__*/jsx("div", {
3088
+ className: style['table-toolbar-filter'],
3089
+ children: /*#__PURE__*/jsx("div", {
3090
+ className: classnames(style['table-toolbar-filter-inner'], filterClassName),
3091
+ children: /*#__PURE__*/jsx(FilterLines, _extends({
3092
+ list: filterList,
3093
+ displayLine: displayLine,
3094
+ label: ""
3095
+ }, filterRest))
3096
+ })
3097
+ }) : null, showSearch ? /*#__PURE__*/jsxs(Fragment, {
3098
+ children: [showFilter && /*#__PURE__*/jsx("span", {
3099
+ className: style['table-toolbar-divider'],
3100
+ "aria-hidden": true
3101
+ }), /*#__PURE__*/jsx("div", {
3102
+ className: style['table-toolbar-search'],
3103
+ children: /*#__PURE__*/jsx(SearchInput, _extends({
3104
+ allowClear: true,
3105
+ bordered: false,
3106
+ variant: "filled",
3107
+ size: "small",
3108
+ className: classnames(style['table-toolbar-search-input'], searchClassName),
3109
+ style: searchStyle
3110
+ }, searchRest))
3111
+ })]
3112
+ }) : null]
3113
+ }), hasValueDisplay ? /*#__PURE__*/jsx("div", {
3114
+ className: style['table-toolbar-value-display'],
3115
+ children: /*#__PURE__*/jsx(FilterValueDisplay, {
3116
+ value: filterValue,
3117
+ onChange: onFilterChange,
3118
+ extraExpand: extraExpand
3119
+ })
3120
+ }) : null]
3121
+ })
3122
+ });
3123
+ };
3124
+
3125
+ const _excluded = ["data", "refresh", "reload", "requestParams", "fetchProps", "isComplete", "loadMore", "send", "dataFormat", "className", "columns", "getColumns", "pagination", "columnRenderProps", "summary", "sticky", "renderType", "horizontalScroller", "getScrollContainer", "filter", "search", "batchActions", "selectedRows", "rowSelection"],
3126
+ _excluded2 = ["pagination", "horizontalScroller", "getScrollContainer"];
3127
+ const readPageSize = key => {
3128
+ try {
3129
+ const value = localStorage.getItem(key);
3130
+ if (value == null || value === '') {
3131
+ return null;
3132
+ }
3133
+ const num = Number(value);
3134
+ return Number.isNaN(num) ? null : num;
3135
+ } catch (_unused) {
3136
+ return null;
3137
+ }
3138
+ };
3139
+ const writePageSize = (key, size) => {
3140
+ try {
3141
+ localStorage.setItem(key, String(size));
3142
+ } catch (_unused2) {
3143
+ // ignore quota errors
3144
+ }
3145
+ };
3146
+ const isTableTopInViewport = target => {
3147
+ const scrollMarginTop = parsePixelValue(getComputedStyle(target).scrollMarginTop);
3148
+ return isTopEdgeInViewport(target, scrollMarginTop);
3149
+ };
3150
+ const scrollTableIntoView = root => {
3151
+ const target = getTableElement(root);
3152
+ if (!target) {
3153
+ return;
3154
+ }
3155
+ requestAnimationFrame(() => {
3156
+ requestAnimationFrame(() => {
3157
+ if (isTableTopInViewport(target)) {
3158
+ return;
3159
+ }
3160
+ target.scrollIntoView({
3161
+ block: 'start',
3162
+ inline: 'nearest'
3163
+ });
3164
+ });
3165
+ });
3166
+ };
3167
+ const TABLE_COMPONENTS = {
3168
+ Table,
3169
+ TableView
3170
+ };
3171
+ const collectFilterFieldNames = (filter, search) => {
3172
+ const names = new Set();
3173
+ if (search != null && search.name) {
3174
+ names.add(search.name);
3175
+ }
3176
+ if (Array.isArray(filter == null ? void 0 : filter.list)) {
3177
+ filter.list.forEach(row => {
3178
+ if (!Array.isArray(row)) {
3179
+ return;
3180
+ }
3181
+ row.forEach(item => {
3182
+ var _item$props;
3183
+ const name = item == null || (_item$props = item.props) == null ? void 0 : _item$props.name;
3184
+ if (name) {
3185
+ names.add(name);
3186
+ }
3187
+ });
3188
+ });
3189
+ }
3190
+ return names;
3191
+ };
3192
+ const omitFilterParams = (params, filterFieldNames) => {
3193
+ const next = Object.assign({}, params);
3194
+ filterFieldNames.forEach(name => {
3195
+ delete next[name];
3196
+ });
3197
+ return next;
3198
+ };
3199
+ const TablePageInnerContent = withLocale(_ref => {
3200
+ var _filter$list;
3201
+ let {
3202
+ data,
3203
+ refresh,
3204
+ reload,
3205
+ requestParams,
3206
+ fetchProps,
3207
+ isComplete,
3208
+ loadMore,
3209
+ send,
3210
+ dataFormat = data => {
3211
+ return {
3212
+ list: data.pageData,
3213
+ total: data.totalCount,
3214
+ data
3215
+ };
3216
+ },
3217
+ className,
3218
+ columns,
3219
+ getColumns,
3220
+ pagination = {},
3221
+ columnRenderProps = {},
3222
+ summary,
3223
+ sticky,
3224
+ renderType = 'Table',
3225
+ horizontalScroller = true,
3226
+ getScrollContainer,
3227
+ filter,
3228
+ search,
3229
+ batchActions,
3230
+ selectedRows,
3231
+ rowSelection
3232
+ } = _ref,
3233
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
3234
+ const {
3235
+ formatMessage
3236
+ } = useIntl();
3237
+ const tableContentRef = useRef(null);
3238
+ const pendingScrollRef = useRef(false);
3239
+ const handlerDataFormat = useRefCallback(dataFormat);
3240
+ const isFilterControlled = filter && filter.value !== undefined;
3241
+ const [internalFilterValue, setInternalFilterValue] = useState(() => (filter == null ? void 0 : filter.defaultValue) || []);
3242
+ const filterValue = isFilterControlled ? filter.value : internalFilterValue;
3243
+ const mapFilterValue = (filter == null ? void 0 : filter.mapFilterValue) || getFilterValue;
3244
+ const getFilterParams = useRefCallback(value => {
3245
+ return mapFilterValue(value || []);
3246
+ });
3247
+ const filterFieldNames = useMemo(() => collectFilterFieldNames(filter, search), [filter, search]);
3248
+ const buildRequestParamsWithFilter = useRefCallback((value, extra = {}) => {
3249
+ return Object.assign({}, omitFilterParams(get(requestParams, pagination.paramsType), filterFieldNames), extra, getFilterParams(value));
3250
+ });
3251
+ const formatData = useMemo(() => {
3252
+ return handlerDataFormat(data);
3253
+ }, [data, handlerDataFormat]);
3254
+ const resolvedColumns = typeof getColumns === 'function' ? getColumns(data) : typeof columns === 'function' ? columns(data) : columns;
3255
+ const fetchContext = useMemo(() => ({
3256
+ data,
3257
+ fetchProps,
3258
+ requestParams,
3259
+ refresh,
3260
+ reload,
3261
+ loadMore,
3262
+ send,
3263
+ dataFormat,
3264
+ pagination
3265
+ }), [data, fetchProps, requestParams, refresh, reload, loadMore, send, dataFormat, pagination]);
3266
+ const scrollTable = useRefCallback(() => {
3267
+ scrollTableIntoView(tableContentRef.current);
3268
+ });
3269
+ const handleFilterChange = useRefCallback(value => {
3270
+ if (!isFilterControlled) {
3271
+ setInternalFilterValue(value);
3272
+ }
3273
+ filter == null || filter.onChange == null || filter.onChange(value);
3274
+ reload({
3275
+ [pagination.paramsType]: buildRequestParamsWithFilter(value, {
3276
+ [pagination.currentName]: 1
3277
+ })
3278
+ });
3279
+ });
3280
+ useEffect(() => {
3281
+ if (!pendingScrollRef.current || !isComplete) {
3282
+ return;
3283
+ }
3284
+ pendingScrollRef.current = false;
3285
+ scrollTable();
3286
+ }, [isComplete, data, scrollTable]);
3287
+ const handlePaginationChange = useRefCallback((page, size) => {
3288
+ pendingScrollRef.current = true;
3289
+ if (typeof pagination.onChange === 'function') {
3290
+ pagination.onChange(page, size);
3291
+ return;
3292
+ }
3293
+ if (page !== get(requestParams, [pagination.paramsType, pagination.currentName], 1)) {
3294
+ (pagination.requestType === 'refresh' ? refresh : reload)({
3295
+ [pagination.paramsType]: buildRequestParamsWithFilter(filterValue, {
3296
+ [pagination.currentName]: page,
3297
+ [pagination.pageSizeName]: Number(size)
3298
+ })
3299
+ });
3300
+ } else {
3301
+ pagination.onShowSizeChange && pagination.onShowSizeChange(page, Number(size));
3302
+ }
3303
+ });
3304
+ const paginationConfig = useMemo(() => {
3305
+ if (!pagination.open) {
3306
+ return null;
3307
+ }
3308
+ return {
3309
+ total: formatData.total,
3310
+ showTotal: typeof pagination.showTotal === 'function' ? pagination.showTotal : total => /*#__PURE__*/jsxs(Fragment, {
3311
+ children: [formatMessage({
3312
+ id: 'TotalText'
3313
+ }), "\xA0", /*#__PURE__*/jsx("span", {
3314
+ className: style$1['total_text'],
3315
+ children: total
3316
+ }), "\xA0", formatMessage({
3317
+ id: 'ItemText'
3318
+ })]
3319
+ }),
3320
+ current: get(requestParams, [pagination.paramsType, pagination.currentName], 1),
3321
+ pageSize: Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 20,
3322
+ onChange: handlePaginationChange,
3323
+ size: pagination.size,
3324
+ hideOnSinglePage: pagination.hideOnSinglePage,
3325
+ showSizeChanger: pagination.showSizeChanger,
3326
+ showQuickJumper: pagination.showQuickJumper,
3327
+ pageSizeOptions: pagination.pageSizeOptions
3328
+ };
3329
+ }, [pagination, formatData.total, requestParams, formatMessage, handlePaginationChange]);
3330
+ const hasToolbar = !!(filter != null && (_filter$list = filter.list) != null && _filter$list.length || search && search.name || batchActions && batchActions.length);
3331
+ const batchContext = useMemo(() => ({
3332
+ data,
3333
+ fetchProps,
3334
+ requestParams,
3335
+ refresh,
3336
+ reload,
3337
+ loadMore,
3338
+ send,
3339
+ dataFormat,
3340
+ pagination
3341
+ }), [data, fetchProps, requestParams, refresh, reload, loadMore, send, dataFormat, pagination]);
3342
+ const tableProps = _extends({}, props, {
3343
+ rowSelection,
3344
+ dataSource: formatData.list,
3345
+ pagination: false,
3346
+ sticky,
3347
+ className: classnames(className, {
3348
+ [style$1['table-in-toolbar']]: hasToolbar
3349
+ }),
3350
+ columns: resolvedColumns,
3351
+ columnRenderProps: _extends({}, columnRenderProps, {
3352
+ requestParams,
3353
+ fetchProps,
3354
+ data
3355
+ }),
3356
+ summary: typeof summary === 'function' ? (pageData, ...args) => {
3357
+ return summary(Object.assign({}, fetchContext, {
3358
+ pageData
3359
+ }, ...args));
3360
+ } : null
3361
+ });
3362
+ const TableComponent = TABLE_COMPONENTS[renderType] || Table;
3363
+ const tableElement = /*#__PURE__*/jsx(TableComponent, _extends({}, tableProps));
3364
+ return /*#__PURE__*/jsxs("div", {
3365
+ className: style$1['table-page'],
3366
+ children: [/*#__PURE__*/jsx(HorizontalScroller, {
3367
+ ref: tableContentRef,
3368
+ enabled: horizontalScroller && renderType === 'Table',
3369
+ getPortalContainer: getScrollContainer,
3370
+ className: classnames(style$1['table-content'], 'loading-container', {
3371
+ 'is-loading': !isComplete && !data
3372
+ }),
3373
+ children: hasToolbar ? /*#__PURE__*/jsxs("div", {
3374
+ className: style$1['table-with-toolbar'],
3375
+ children: [/*#__PURE__*/jsx(TableToolbar, {
3376
+ filterValue: filterValue,
3377
+ onFilterChange: handleFilterChange,
3378
+ filter: filter,
3379
+ search: search,
3380
+ batchActions: batchActions,
3381
+ rowSelection: rowSelection,
3382
+ selectedRows: selectedRows,
3383
+ batchContext: batchContext
3384
+ }), tableElement]
3385
+ }) : tableElement
3386
+ }), paginationConfig ? /*#__PURE__*/jsx(Pagination, _extends({
3387
+ className: style$1['pagination']
3388
+ }, paginationConfig)) : null]
3389
+ });
3390
+ });
3391
+ const TablePageInner = withFetch(TablePageInnerContent);
3392
+ const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
3393
+ let {
3394
+ pagination,
3395
+ horizontalScroller = true,
3396
+ getScrollContainer
3397
+ } = _ref2,
3398
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
3399
+ pagination = Object.assign({}, {
3400
+ showSizeChanger: true,
3401
+ showQuickJumper: true,
3402
+ hideOnSinglePage: false,
3403
+ open: true,
3404
+ paramsType: 'data',
3405
+ requestType: 'reload',
3406
+ currentName: 'currentPage',
3407
+ pageSizeName: 'perPage',
3408
+ pageSize: 20
3409
+ }, pagination);
3410
+ const pageSizeKey = `${(props.name || 'common').toUpperCase()}_TABLE_PAGE_SIZE`;
3411
+ const [pageSize, setPageSize] = useState(() => {
3412
+ var _readPageSize;
3413
+ return (_readPageSize = readPageSize(pageSizeKey)) != null ? _readPageSize : pagination.pageSize;
3414
+ });
3415
+ const params = props[pagination.paramsType];
3416
+ const filterDefaultParams = useMemo(() => {
3417
+ var _props$filter;
3418
+ if (!((_props$filter = props.filter) != null && (_props$filter = _props$filter.defaultValue) != null && _props$filter.length)) {
3419
+ return {};
3420
+ }
3421
+ const mapFilterValue = props.filter.mapFilterValue || getFilterValue;
3422
+ return mapFilterValue(props.filter.defaultValue);
3423
+ }, [props.filter]);
3424
+ const fetchParams = useMemo(() => {
3425
+ return {
3426
+ [pagination.paramsType]: Object.assign({}, params, filterDefaultParams, {
3427
+ [pagination.pageSizeName]: pageSize
3428
+ })
3429
+ };
3430
+ }, [params, pagination.pageSizeName, pagination.paramsType, pageSize, filterDefaultParams]);
3431
+ return /*#__PURE__*/jsx(TablePageInner, _extends({}, props, fetchParams, {
3432
+ horizontalScroller: horizontalScroller,
3433
+ getScrollContainer: getScrollContainer,
3434
+ pagination: Object.assign({}, pagination, {
3435
+ pageSize,
3436
+ onShowSizeChange: (current, size) => {
3437
+ const nextSize = Number(size);
3438
+ writePageSize(pageSizeKey, nextSize);
3439
+ setPageSize(nextSize);
3440
+ }
3441
+ }),
3442
+ ref: ref
3443
+ }));
3444
+ });
3445
+
3446
+ const preset = props => {
3447
+ const next = merge({}, globalParams, props);
3448
+ merge(globalParams, props);
3449
+ return next;
3450
+ };
3451
+
3452
+ export { RENDER_TYPE_NAMES, SIZE_NAMES, Table, TableView, TablePage as default, getColumnRender, getRenderTypeDimensions, getRenderTypeNames, getTagColor, globalParams, isOptionsColumn, parseRenderType, preset, renderTagItem, renderTagList, resolveColumn, resolveColumnDimensions, resolveColumns, resolveRenderType, sortDataSource, tableLocalApis, useSelectedRow, useSort, useTableConfig };
3453
+ //# sourceMappingURL=index.modern.js.map