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