@kne/table-page 0.1.6 → 0.1.8

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.
@@ -1,1339 +1,50 @@
1
+ import '@kne/table-view/dist/index.css';
1
2
  import { withFetch } from '@kne/react-fetch';
2
- import { Typography, Tooltip, Tag, Space, Badge, Checkbox, Row, Col, Input, List, Button, Collapse, Popover, Empty, Table as Table$1, Dropdown, Pagination } from 'antd';
3
+ import { Checkbox, Row, Col, Input, List, Tooltip, Button, Collapse, Popover, Empty, Table as Table$1, Dropdown, Pagination } from 'antd';
3
4
  import { FilterProvider, FilterLines, SearchInput, FilterValueDisplay, getFilterValue } from '@kne/react-filter';
4
- import { useState, useCallback, useMemo, useRef, useEffect, useLayoutEffect, forwardRef } from 'react';
5
+ import { useState, useMemo, useRef, useCallback, useEffect, useLayoutEffect, forwardRef } from 'react';
5
6
  import classnames from 'classnames';
6
7
  import get from 'lodash/get';
8
+ import { isOptionsColumn, parseColumnWidth, resolveColumns, useSelectedRow, useSort, wrapColumnHeaderTitle, renderColumnTitle, getColumnEllipsis, computeColumnsValue, renderCellContent, computeDisplay, TableView } from '@kne/table-view';
9
+ export { RENDER_TYPE_NAMES, SIZE_NAMES, TableView, calcArgs, computeColumnsDisplay, computeColumnsValue, computeDisplay, defaultFormat, formatView, getColumnEllipsis, getColumnLayout, getColumnRender, getGridTemplateColumns, getRenderTypeDimensions, getRenderTypeNames, getStatusType, getTagColor, globalParams, hasColumnSpan, hasColumnWidth, isOptionsColumn, parseColumnWidth, parseRenderType, preset, renderCellContent, renderStatusItem, renderTagItem, renderTagList, resolveColumn, resolveColumnDimensions, resolveColumns, resolveRenderType, sortDataSource, useSelectedRow, useSort, wrapColumnHeaderTitle } from '@kne/table-view';
7
10
  import { isEmpty } from '@kne/is-empty';
8
- import groupBy from 'lodash/groupBy';
9
- import transform from 'lodash/transform';
10
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
- import ButtonGroup from '@kne/button-group';
12
- import '@kne/button-group/dist/index.css';
13
- import { CaretUpOutlined, CaretDownOutlined, HolderOutlined, RedoOutlined, SettingOutlined, CheckOutlined, DownOutlined } from '@ant-design/icons';
14
- import clone from 'lodash/clone';
15
- import useRefCallback from '@kne/use-ref-callback';
16
- import pick from 'lodash/pick';
17
- import findLastIndex from 'lodash/findLastIndex';
18
- import isEqual from 'lodash/isEqual';
19
- import { useDebouncedCallback } from 'use-debounce';
20
- import { ReactSortable } from 'react-sortablejs';
21
- import cloneDeep from 'lodash/cloneDeep';
22
- import { createWithIntlProvider, useIntl } from '@kne/react-intl';
23
- import filterZhCN from '@kne/react-filter/dist/locale/zh-CN';
24
- import filterEnUS from '@kne/react-filter/dist/locale/en-US';
25
- import { createPortal } from 'react-dom';
26
- import '@kne/react-filter/dist/index.css';
27
- import merge from 'lodash/merge';
28
-
29
- function _extends() {
30
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
31
- for (var e = 1; e < arguments.length; e++) {
32
- var t = arguments[e];
33
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
34
- }
35
- return n;
36
- }, _extends.apply(null, arguments);
37
- }
38
- function _objectWithoutPropertiesLoose(r, e) {
39
- if (null == r) return {};
40
- var t = {};
41
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
42
- if (-1 !== e.indexOf(n)) continue;
43
- t[n] = r[n];
44
- }
45
- return t;
46
- }
47
-
48
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
49
-
50
- function createCommonjsModule(fn) {
51
- var module = { exports: {} };
52
- return fn(module, module.exports), module.exports;
53
- }
54
-
55
- var dayjs_min = createCommonjsModule(function (module, exports) {
56
- !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}));
57
- });
58
-
59
- const calcArgs = (args, template) => {
60
- const {
61
- attr,
62
- normal
63
- } = groupBy(args, item => /^.+:.+$/.test(item) ? 'attr' : 'normal');
64
- const output = {};
65
- const typeTransform = (value, type) => {
66
- if (type === 'string') {
67
- return String(value);
68
- }
69
- if (type === 'number') {
70
- return Number(value);
71
- }
72
- if (type === 'boolean') {
73
- return value === 'true';
74
- }
75
- return value;
76
- };
77
- (normal || []).forEach((target, index) => {
78
- const currentTemplate = Object.assign({}, {
79
- type: 'string',
80
- defaultValue: ''
81
- }, get(template, index));
82
- if (currentTemplate.name && target) {
83
- output[currentTemplate.name] = typeTransform(target, currentTemplate.type);
84
- }
85
- });
86
- (attr || []).forEach(target => {
87
- const [key, value] = target.split(':');
88
- const currentTemplate = template.find(item => item.name === key);
89
- if (!currentTemplate) {
90
- return;
91
- }
92
- const {
93
- name,
94
- type
95
- } = Object.assign({}, {
96
- type: 'string',
97
- defaultValue: ''
98
- }, currentTemplate);
99
- output[name] = typeTransform(value, type);
100
- });
101
- return Object.assign({}, transform(template, (result, value) => {
102
- if (value.name && value.hasOwnProperty('defaultValue')) {
103
- result[value.name] = value.defaultValue;
104
- }
105
- }, {}), output);
106
- };
107
- const defaultFormat = {
108
- date: (value, {
109
- args
110
- }) => {
111
- const template = args[0] || 'YYYY-MM-DD';
112
- return dayjs_min(value).format(template);
113
- },
114
- datetime: (value, {
115
- args
116
- }) => {
117
- const template = args[0] || 'YYYY-MM-DD HH:mm:ss';
118
- return dayjs_min(value).format(template);
119
- },
120
- dateRange: (value, {
121
- args
122
- }) => {
123
- const template = args[0] || 'YYYY-MM-DD',
124
- allowNull = args[1];
125
- if (!isEmpty(value[0]) && !isEmpty(value[1])) {
126
- return `${dayjs_min(value[0]).format(template)}~${dayjs_min(value[1]).format(template)}`;
127
- }
128
- if (allowNull === 'allow' && !isEmpty(value[0])) {
129
- return `${dayjs_min(value[0]).format(template)}以后`;
130
- }
131
- if (allowNull === 'allow' && !isEmpty(value[1])) {
132
- return `${dayjs_min(value[1]).format(template)}以前`;
133
- }
134
- return '';
135
- },
136
- boolean: (value, {
137
- args
138
- }) => {
139
- const trueValue = args[0] || 'true';
140
- if ((value || '').toString() === trueValue) {
141
- return '是';
142
- }
143
- return '否';
144
- },
145
- number: (value, {
146
- args
147
- }) => {
148
- const {
149
- style,
150
- unit,
151
- maximumFractionDigits,
152
- useGrouping,
153
- roundingMode,
154
- suffix
155
- } = calcArgs(args, [{
156
- name: 'style',
157
- type: 'string',
158
- defaultValue: 'decimal'
159
- }, {
160
- name: 'unit',
161
- type: 'number',
162
- defaultValue: 1
163
- }, {
164
- name: 'maximumFractionDigits',
165
- type: 'number',
166
- defaultValue: 2
167
- }, {
168
- name: 'useGrouping',
169
- type: 'boolean',
170
- defaultValue: true
171
- }, {
172
- name: 'roundingMode',
173
- type: 'string',
174
- defaultValue: 'halfExpand'
175
- }, {
176
- name: 'suffix',
177
- type: 'string',
178
- defaultValue: ''
179
- }]);
180
- return new Intl.NumberFormat({}, {
181
- style,
182
- maximumFractionDigits,
183
- roundingMode,
184
- useGrouping
185
- }).format(value / unit) + suffix;
186
- },
187
- money: (value, {
188
- args
189
- }) => {
190
- const unit = args[0] || '元';
191
- return `${value}${unit}`;
192
- }
193
- };
194
- const formatView = (value, format, context) => {
195
- if (!format) {
196
- return value;
197
- }
198
- const formatList = format.split(' ').filter(item => !!item);
199
- if (formatList.length > 0) {
200
- return formatList.reduce((value, format) => {
201
- const [name, ...args] = format.split('-');
202
- if (typeof defaultFormat[name] === 'function') {
203
- return defaultFormat[name](value, Object.assign({}, context, {
204
- args: args.map(item => {
205
- return item && item.replace(/\(\)/g, ' ').replace(/\(_\)/g, '-');
206
- })
207
- }));
208
- }
209
- return value;
210
- }, value);
211
- }
212
- };
213
-
214
- const globalParams = {
215
- renderType: null,
216
- renderTypeSize: {},
217
- tagTypeColors: {},
218
- statusTypeColors: {}
219
- };
220
-
221
- const defaultRender = value => value;
222
-
223
- var ellipsisStyle = {"ellipsis":"kne-table-page_mMMw1","tooltip":"kne-table-page_CkWQu","cell-content":"kne-table-page_OXmYu","cell-full-width":"kne-table-page_jN-vq"};
224
-
225
- const _excluded$8 = ["showTitle"];
226
- const Ellipsis = ({
227
- children,
228
- ellipsis
229
- }) => {
230
- if (!ellipsis) {
231
- return children;
232
- }
233
- const userConfig = typeof ellipsis === 'object' ? ellipsis : {};
234
- const {
235
- showTitle
236
- } = userConfig,
237
- rest = _objectWithoutPropertiesLoose(userConfig, _excluded$8);
238
- return /*#__PURE__*/jsx(Typography.Text, {
239
- className: ellipsisStyle['ellipsis'],
240
- ellipsis: Object.assign({}, {
241
- tooltip: showTitle === false ? false : {
242
- rootClassName: ellipsisStyle['tooltip']
243
- }
244
- }, rest),
245
- children: children
246
- });
247
- };
248
-
249
- var style$8 = {"text":"kne-table-page_5N2-a","ellipsis":"kne-table-page_Lkl3D","hover":"kne-table-page_RnF6d","primary":"kne-table-page_g-Sky","clickable":"kne-table-page_vPcDo","loading":"kne-table-page_FeQ09"};
250
-
251
- const MainCell = ({
252
- value,
253
- column,
254
- dataSource
255
- }) => {
256
- const {
257
- ellipsis = true,
258
- hover = true,
259
- primary = true,
260
- onClick
261
- } = column || {};
262
- const [loading, setLoading] = useState(false);
263
- const isClickable = Boolean(hover || primary || onClick);
264
- if (!isClickable) {
265
- return /*#__PURE__*/jsx(Ellipsis, {
266
- ellipsis: ellipsis,
267
- children: value
268
- });
269
- }
270
- const ellipsisConfig = typeof ellipsis === 'object' ? ellipsis : {};
271
- const showTooltip = ellipsis && ellipsisConfig.showTitle !== false;
272
- const handleClick = onClick ? e => {
273
- if (loading) {
274
- return;
275
- }
276
- setLoading(true);
277
- Promise.resolve(onClick({
278
- item: value,
279
- colItem: dataSource,
280
- event: e
281
- })).finally(() => {
282
- setLoading(false);
283
- });
284
- } : undefined;
285
- const text = /*#__PURE__*/jsx("span", {
286
- className: classnames(style$8['text'], ellipsis && style$8['ellipsis'], {
287
- [style$8['hover']]: hover,
288
- [style$8['primary']]: primary,
289
- [style$8['clickable']]: Boolean(onClick),
290
- [style$8['loading']]: loading
291
- }),
292
- onClick: handleClick,
293
- children: value
294
- });
295
- if (!showTooltip) {
296
- return text;
297
- }
298
- return /*#__PURE__*/jsx(Tooltip, {
299
- title: value,
300
- rootClassName: ellipsisStyle['tooltip'],
301
- children: text
302
- });
303
- };
304
- const main = (value, {
305
- column,
306
- dataSource
307
- } = {}) => /*#__PURE__*/jsx(MainCell, {
308
- value: value,
309
- column: column,
310
- dataSource: dataSource
311
- });
312
-
313
- var style$7 = {"amount":"kne-table-page_AH-3R"};
314
-
315
- const amount = (value, {
316
- column
317
- } = {}) => {
318
- const {
319
- ellipsis = true
320
- } = column || {};
321
- return /*#__PURE__*/jsx("span", {
322
- className: style$7['amount'],
323
- children: /*#__PURE__*/jsx(Ellipsis, {
324
- ellipsis: ellipsis,
325
- children: value
326
- })
327
- });
328
- };
329
-
330
- const _excluded$7 = ["text", "type", "color", "children"];
331
- const DEFAULT_TAG_TYPE_COLORS = {
332
- default: 'default',
333
- success: 'success',
334
- progress: 'processing',
335
- processing: 'processing',
336
- danger: 'error',
337
- error: 'error',
338
- warning: 'warning',
339
- info: 'blue',
340
- other: 'purple',
341
- skill: 'default',
342
- result: 'default',
343
- filterResult: 'cyan',
344
- completed: 'success',
345
- pending: 'warning',
346
- high: 'error',
347
- medium: 'warning',
348
- low: 'default'
349
- };
350
- const getTagColor = type => {
351
- if (!type) {
352
- return 'default';
353
- }
354
- const customColors = globalParams.tagTypeColors || {};
355
- return customColors[type] || DEFAULT_TAG_TYPE_COLORS[type] || type;
356
- };
357
- const normalizeTagItem = item => {
358
- if (item == null) {
359
- return null;
360
- }
361
- if (typeof item === 'string' || typeof item === 'number') {
362
- return {
363
- text: String(item)
364
- };
365
- }
366
- if (typeof item === 'object') {
367
- var _ref, _item$text;
368
- return Object.assign({}, item, {
369
- text: (_ref = (_item$text = item.text) != null ? _item$text : item.children) != null ? _ref : item.label
370
- });
371
- }
372
- return null;
373
- };
374
- const renderTagItem = (item, key) => {
375
- const tag = normalizeTagItem(item);
376
- if (!tag || tag.text == null && tag.children == null) {
377
- return null;
378
- }
379
- const {
380
- text,
381
- type,
382
- color,
383
- children
384
- } = tag,
385
- rest = _objectWithoutPropertiesLoose(tag, _excluded$7);
386
- return /*#__PURE__*/jsx(Tag, _extends({
387
- color: color != null ? color : getTagColor(type)
388
- }, rest, {
389
- children: children != null ? children : text
390
- }), key);
391
- };
392
- const renderTagList = value => {
393
- if (!Array.isArray(value) || value.length === 0) {
394
- return null;
395
- }
396
- return /*#__PURE__*/jsx(Space, {
397
- size: [4, 4],
398
- wrap: true,
399
- children: value.map((item, index) => renderTagItem(item, index))
400
- });
401
- };
402
-
403
- const tag = value => renderTagItem(value);
404
-
405
- const tagList = value => renderTagList(value);
406
-
407
- const _excluded$6 = ["text", "type", "status", "color", "children"];
408
- const DEFAULT_STATUS_TYPE_MAP = {
409
- default: 'default',
410
- success: 'success',
411
- progress: 'processing',
412
- processing: 'processing',
413
- danger: 'error',
414
- error: 'error',
415
- warning: 'warning',
416
- info: 'processing',
417
- other: 'default',
418
- active: 'success',
419
- vacation: 'warning',
420
- resigned: 'default',
421
- probation: 'processing',
422
- completed: 'success',
423
- pending: 'warning',
424
- shipped: 'processing',
425
- paid: 'success',
426
- cancelled: 'error'
427
- };
428
- const getStatusType = type => {
429
- if (!type) {
430
- return 'default';
431
- }
432
- const customTypes = globalParams.statusTypeColors || {};
433
- return customTypes[type] || DEFAULT_STATUS_TYPE_MAP[type] || type;
434
- };
435
- const normalizeStatusItem = item => {
436
- if (item == null) {
437
- return null;
438
- }
439
- if (typeof item === 'string' || typeof item === 'number') {
440
- return {
441
- text: String(item)
442
- };
443
- }
444
- if (typeof item === 'object') {
445
- var _ref, _item$text;
446
- return Object.assign({}, item, {
447
- text: (_ref = (_item$text = item.text) != null ? _item$text : item.children) != null ? _ref : item.label
448
- });
449
- }
450
- return null;
451
- };
452
- const renderStatusItem = item => {
453
- var _ref2;
454
- const statusItem = normalizeStatusItem(item);
455
- if (!statusItem || statusItem.text == null) {
456
- return null;
457
- }
458
- const {
459
- text,
460
- type,
461
- status,
462
- color,
463
- children
464
- } = statusItem,
465
- rest = _objectWithoutPropertiesLoose(statusItem, _excluded$6);
466
- return /*#__PURE__*/jsx(Badge, _extends({
467
- status: (_ref2 = status != null ? status : color) != null ? _ref2 : getStatusType(type),
468
- text: children != null ? children : text
469
- }, rest));
470
- };
471
-
472
- const status = value => renderStatusItem(value);
473
-
474
- const DEFAULT_SPLIT = ',';
475
- const normalizeListValue = value => {
476
- if (Array.isArray(value)) {
477
- return {
478
- items: value,
479
- split: undefined
480
- };
481
- }
482
- if (value && typeof value === 'object') {
483
- var _ref, _value$items;
484
- const items = (_ref = (_value$items = value.items) != null ? _value$items : value.list) != null ? _ref : value.value;
485
- if (Array.isArray(items)) {
486
- return {
487
- items,
488
- split: value.split
489
- };
490
- }
491
- }
492
- return null;
493
- };
494
- const getListItemText = item => {
495
- if (item == null) {
496
- return null;
497
- }
498
- if (typeof item === 'object') {
499
- var _ref2, _ref3, _item$text;
500
- return (_ref2 = (_ref3 = (_item$text = item.text) != null ? _item$text : item.label) != null ? _ref3 : item.children) != null ? _ref2 : item.value;
501
- }
502
- return item;
503
- };
504
- const list = (value, {
505
- column
506
- } = {}) => {
507
- var _ref4, _normalized$split;
508
- const normalized = normalizeListValue(value);
509
- if (!normalized) {
510
- return value == null ? null : value;
511
- }
512
- const split = (_ref4 = (_normalized$split = normalized.split) != null ? _normalized$split : column == null ? void 0 : column.split) != null ? _ref4 : DEFAULT_SPLIT;
513
- const text = normalized.items.map(getListItemText).filter(item => item != null && item !== '').join(split);
514
- return text || null;
515
- };
516
-
517
- const SELECTION_CHECKBOX_WIDTH = 48;
518
- const SELECTION_RADIO_WIDTH = 30;
519
- const DEFAULT_COLUMN_WIDTH = 300;
520
- const parseColumnWidth = width => {
521
- if (width == null) {
522
- return 0;
523
- }
524
- if (typeof width === 'number' && !Number.isNaN(width)) {
525
- return width;
526
- }
527
- if (typeof width === 'string') {
528
- const trimmed = width.trim();
529
- const pxMatch = trimmed.match(/^([\d.]+)px$/i);
530
- if (pxMatch) {
531
- return parseFloat(pxMatch[1]);
532
- }
533
- const num = parseFloat(trimmed);
534
- if (!Number.isNaN(num)) {
535
- return num;
536
- }
537
- }
538
- return 0;
539
- };
540
- const getResolvedColumnWidth = column => resolveColumnDimensions(column).width;
541
- const hasColumnSpan = column => column.span != null;
542
- const getConfiguredColumnWidthPx = column => parseColumnWidth(column.width != null ? column.width : getResolvedColumnWidth(column));
543
- const usesDefaultColumnWidth = (column, columns) => {
544
- if (hasColumnSpan(column)) {
545
- return false;
546
- }
547
- if (column.width != null) {
548
- return false;
549
- }
550
- if (getConfiguredColumnWidthPx(column) > 0) {
551
- return false;
552
- }
553
- return !columns.some(hasColumnSpan);
554
- };
555
- const hasColumnWidth = (column, columns) => {
556
- if (hasColumnSpan(column)) {
557
- return false;
558
- }
559
- if (getConfiguredColumnWidthPx(column) > 0) {
560
- return true;
561
- }
562
- return usesDefaultColumnWidth(column, columns);
563
- };
564
- const shouldLastColumnFillRemaining = columns => !columns.some(hasColumnSpan);
565
- const getColumnWidthPx = (column, colsSize = {}, columns = []) => {
566
- if (hasColumnSpan(column)) {
567
- return colsSize[column.name] || 0;
568
- }
569
- const configured = getConfiguredColumnWidthPx(column);
570
- if (configured > 0) {
571
- return configured;
572
- }
573
- if (usesDefaultColumnWidth(column, columns)) {
574
- const measured = colsSize[column.name] || 0;
575
- return Math.max(DEFAULT_COLUMN_WIDTH, measured);
576
- }
577
- return colsSize[column.name] || 0;
578
- };
579
- const formatColumnWidthPx = px => `${px}px`;
580
- const getColumnTrackSize = (column, {
581
- defaultSpan,
582
- colsSize,
583
- isLastColumn,
584
- columns
585
- } = {}) => {
586
- var _ref, _column$span;
587
- const widthPx = getColumnWidthPx(column, colsSize, columns);
588
- if (hasColumnWidth(column, columns)) {
589
- if (isLastColumn && shouldLastColumnFillRemaining(columns)) {
590
- return `minmax(${widthPx}px, 1fr)`;
591
- }
592
- return `${widthPx}px`;
593
- }
594
- if (widthPx > 0) {
595
- return `minmax(${widthPx}px, 1fr)`;
596
- }
597
- const span = (_ref = (_column$span = column.span) != null ? _column$span : defaultSpan) != null ? _ref : 1;
598
- return `minmax(0, ${span}fr)`;
599
- };
600
- const getGridTemplateColumns = (columns, {
601
- defaultSpan,
602
- colsSize,
603
- rowSelection
604
- } = {}) => {
605
- const tracks = [];
606
- const lastColumnIndex = columns.length - 1;
607
- if ((rowSelection == null ? void 0 : rowSelection.type) === 'checkbox') {
608
- tracks.push(`${SELECTION_CHECKBOX_WIDTH}px`);
609
- }
610
- columns.forEach((column, index) => {
611
- tracks.push(getColumnTrackSize(column, {
612
- defaultSpan,
613
- colsSize,
614
- isLastColumn: index === lastColumnIndex,
615
- columns
616
- }));
617
- });
618
- if ((rowSelection == null ? void 0 : rowSelection.type) === 'radio') {
619
- tracks.push(`${SELECTION_RADIO_WIDTH}px`);
620
- }
621
- return tracks.join(' ');
622
- };
623
- const getColumnLayout = (column, {
624
- defaultSpan,
625
- colsSize,
626
- isLastColumn,
627
- columns
628
- } = {}) => {
629
- const widthBased = hasColumnWidth(column, columns);
630
- const widthPx = getColumnWidthPx(column, colsSize, columns);
631
- const fillRemaining = isLastColumn && widthBased && shouldLastColumnFillRemaining(columns);
632
- return {
633
- widthBased,
634
- fillRemaining,
635
- style: {
636
- '--col-width': formatColumnWidthPx(widthPx),
637
- '--col-align': column.align || 'top',
638
- '--col-justify': column.justify || 'flex-start'
639
- }
640
- };
641
- };
642
-
643
- var style$6 = {"col-item":"kne-table-page_nL1tj","options":"kne-table-page_EwzO-","options-column":"kne-table-page_im2Lc","options-btn":"kne-table-page_SJxZl"};
644
-
645
- const _excluded$5 = ["children", "label", "text", "className"],
646
- _excluded2$3 = ["list"];
647
- const normalizeOptionItem = (item, buttonClassName) => {
648
- var _ref;
649
- if (item == null) {
650
- return null;
651
- }
652
- if (typeof item === 'function') {
653
- return item;
654
- }
655
- if (typeof item === 'string') {
656
- return {
657
- children: item,
658
- type: 'link',
659
- className: buttonClassName
660
- };
661
- }
662
- const {
663
- children,
664
- label,
665
- text,
666
- className
667
- } = item,
668
- rest = _objectWithoutPropertiesLoose(item, _excluded$5);
669
- return _extends({
670
- type: 'link'
671
- }, rest, {
672
- className: classnames(buttonClassName, className),
673
- children: (_ref = children != null ? children : label) != null ? _ref : text
674
- });
675
- };
676
- const options = (value, {
677
- column
678
- } = {}) => {
679
- let list = value;
680
- let buttonGroupProps = (column == null ? void 0 : column.buttonGroup) || {};
681
- if (value && typeof value === 'object' && !Array.isArray(value) && Array.isArray(value.list)) {
682
- const {
683
- list: valueList
684
- } = value,
685
- rest = _objectWithoutPropertiesLoose(value, _excluded2$3);
686
- list = valueList;
687
- buttonGroupProps = _extends({}, buttonGroupProps, rest);
688
- }
689
- if (!Array.isArray(list) || list.length === 0) {
690
- return null;
691
- }
692
- const wrapperClassName = classnames(style$6['col-item'], style$6['options']);
693
- const buttonClassName = classnames(wrapperClassName, style$6['options-btn']);
694
- const normalizedList = list.map(item => normalizeOptionItem(item, buttonClassName)).filter(item => item != null && !item.hidden);
695
- if (normalizedList.length === 0) {
696
- return null;
697
- }
698
- const width = parseColumnWidth(column == null ? void 0 : column.width);
699
- return /*#__PURE__*/jsx("div", {
700
- className: classnames(wrapperClassName, style$6['options-column']),
701
- style: width > 0 ? {
702
- '--max-width': `${width}px`
703
- } : undefined,
704
- children: /*#__PURE__*/jsx(ButtonGroup, _extends({
705
- moreType: "link",
706
- itemClassName: "btn-no-padding",
707
- list: normalizedList
708
- }, buttonGroupProps))
709
- });
710
- };
711
-
712
- const enumRender = value => tag(value);
713
-
714
- const description = value => value;
715
-
716
- const renderType = {
717
- default: defaultRender,
718
- main,
719
- amount,
720
- tag,
721
- tagList,
722
- status,
723
- list,
724
- options,
725
- enum: enumRender,
726
- description
727
- };
728
- globalParams.renderType = renderType;
729
-
730
- const _excluded$4 = ["default"];
731
- const SIZE_NAMES = ['short', 'small', 'large'];
732
- const typeSize = {
733
- main: {
734
- width: 300,
735
- min: 160,
736
- max: 500,
737
- ellipsis: true
738
- },
739
- amount: {
740
- width: 140,
741
- min: 100,
742
- max: 300,
743
- ellipsis: true
744
- },
745
- options: {
746
- width: 180,
747
- min: 120,
748
- max: 400
749
- },
750
- enum: {
751
- width: 140,
752
- min: 100,
753
- max: 400
754
- },
755
- tag: {
756
- width: 140,
757
- min: 100,
758
- max: 400
759
- },
760
- status: {
761
- width: 100,
762
- min: 80,
763
- max: 140
764
- },
765
- tagList: {
766
- width: 300,
767
- min: 160,
768
- max: 500
769
- },
770
- list: {
771
- width: 200,
772
- min: 120,
773
- max: 400,
774
- ellipsis: true
775
- },
776
- description: {
777
- width: 400,
778
- min: 160,
779
- max: 600,
780
- ellipsis: true
781
- }
782
- };
783
- const SIZE_CONFIG = {
784
- short: {
785
- width: 120,
786
- min: 100,
787
- max: 400
788
- },
789
- small: {
790
- width: 100,
791
- min: 70,
792
- max: 400
793
- },
794
- default: {
795
- width: 300,
796
- min: 160,
797
- max: 500
798
- },
799
- large: {
800
- width: 300,
801
- min: 120,
802
- max: 500
803
- }
804
- };
805
- const getRenderTypeRegistry = () => {
806
- const _ref = globalParams.renderType || {},
807
- {
808
- default: defaultRender
809
- } = _ref,
810
- renderers = _objectWithoutPropertiesLoose(_ref, _excluded$4);
811
- return {
812
- defaultRender,
813
- renderers
814
- };
815
- };
816
- const getRenderTypeNames = () => Object.keys(getRenderTypeRegistry().renderers);
817
- const RENDER_TYPE_NAMES = getRenderTypeNames();
818
- const getRender = type => {
819
- const {
820
- defaultRender,
821
- renderers
822
- } = getRenderTypeRegistry();
823
- return renderers[type] || defaultRender;
824
- };
825
- const getColumnRender = column => {
826
- if (typeof (column == null ? void 0 : column.render) === 'function') {
827
- return column.render;
828
- }
829
- const {
830
- type
831
- } = parseRenderType(column == null ? void 0 : column.renderType);
832
- if (!type) {
833
- return null;
834
- }
835
- return getRender(type);
836
- };
837
- const getTypeConfigMap = () => {
838
- const extraTypeSize = globalParams.renderTypeSize || {};
839
- return getRenderTypeNames().reduce((result, key) => {
840
- result[key] = Object.assign({}, typeSize[key], extraTypeSize[key], {
841
- render: getRender(key)
842
- });
843
- return result;
844
- }, {});
845
- };
846
- const pickDimension = (columnValue, typeValue, sizeValue) => {
847
- if (columnValue != null) {
848
- return columnValue;
849
- }
850
- if (sizeValue != null) {
851
- return sizeValue;
852
- }
853
- if (typeValue != null) {
854
- return typeValue;
855
- }
856
- return undefined;
857
- };
858
- const parseRenderType = renderTypeValue => {
859
- if (!renderTypeValue || typeof renderTypeValue !== 'string') {
860
- return {
861
- type: null,
862
- size: null
863
- };
864
- }
865
- const renderTypeNames = getRenderTypeNames();
866
- let type = null;
867
- let size = null;
868
- renderTypeValue.split('-').forEach(part => {
869
- if (!part) {
870
- return;
871
- }
872
- if (renderTypeNames.includes(part)) {
873
- type = part;
874
- return;
875
- }
876
- if (SIZE_NAMES.includes(part)) {
877
- size = part;
878
- }
879
- });
880
- return {
881
- type,
882
- size
883
- };
884
- };
885
- const getRenderTypeDimensions = renderTypeValue => {
886
- const {
887
- type,
888
- size
889
- } = parseRenderType(renderTypeValue);
890
- const typeConfigMap = getTypeConfigMap();
891
- const typeConfig = type ? typeConfigMap[type] : null;
892
- const sizeConfig = size ? SIZE_CONFIG[size] : null;
893
- if (!typeConfig && !sizeConfig) {
894
- return null;
895
- }
896
- return {
897
- type,
898
- size,
899
- typeConfig,
900
- sizeConfig,
901
- render: typeConfig == null ? void 0 : typeConfig.render,
902
- ellipsis: typeConfig == null ? void 0 : typeConfig.ellipsis
903
- };
904
- };
905
- const resolveColumnDimensions = column => {
906
- const renderTypeDimensions = column != null && column.renderType ? getRenderTypeDimensions(column.renderType) : null;
907
- const typeConfig = renderTypeDimensions == null ? void 0 : renderTypeDimensions.typeConfig;
908
- const sizeConfig = renderTypeDimensions == null ? void 0 : renderTypeDimensions.sizeConfig;
909
- return {
910
- width: pickDimension(column == null ? void 0 : column.width, typeConfig == null ? void 0 : typeConfig.width, sizeConfig == null ? void 0 : sizeConfig.width),
911
- min: pickDimension(column == null ? void 0 : column.min, typeConfig == null ? void 0 : typeConfig.min, sizeConfig == null ? void 0 : sizeConfig.min),
912
- max: pickDimension(column == null ? void 0 : column.max, typeConfig == null ? void 0 : typeConfig.max, sizeConfig == null ? void 0 : sizeConfig.max)
913
- };
914
- };
915
- const resolveRenderType = renderTypeValue => {
916
- var _sizeConfig$width, _sizeConfig$min, _sizeConfig$max;
917
- const renderTypeDimensions = getRenderTypeDimensions(renderTypeValue);
918
- if (!renderTypeDimensions) {
919
- return null;
920
- }
921
- const {
922
- type,
923
- size,
924
- render,
925
- ellipsis,
926
- typeConfig,
927
- sizeConfig
928
- } = renderTypeDimensions;
929
- return {
930
- type,
931
- size,
932
- render,
933
- ellipsis,
934
- width: (_sizeConfig$width = sizeConfig == null ? void 0 : sizeConfig.width) != null ? _sizeConfig$width : typeConfig == null ? void 0 : typeConfig.width,
935
- min: (_sizeConfig$min = sizeConfig == null ? void 0 : sizeConfig.min) != null ? _sizeConfig$min : typeConfig == null ? void 0 : typeConfig.min,
936
- max: (_sizeConfig$max = sizeConfig == null ? void 0 : sizeConfig.max) != null ? _sizeConfig$max : typeConfig == null ? void 0 : typeConfig.max
937
- };
938
- };
939
- const ELLIPSIS_HANDLED_TYPES = ['main', 'amount'];
940
- const FULL_WIDTH_CELL_TYPES = ['options'];
941
- const resolveColumn = column => {
942
- if (!column) {
943
- return column;
944
- }
945
- const renderTypeDimensions = column.renderType ? getRenderTypeDimensions(column.renderType) : null;
946
- const {
947
- width,
948
- min,
949
- max
950
- } = resolveColumnDimensions(column);
951
- const {
952
- ellipsis,
953
- type
954
- } = renderTypeDimensions || {};
955
- const renderFn = getColumnRender(column);
956
- return Object.assign({}, column, _extends({}, renderFn && typeof column.render !== 'function' ? {
957
- render: renderFn
958
- } : {}, column.width == null && width != null ? {
959
- width
960
- } : {}, column.min == null && min != null ? {
961
- min
962
- } : {}, column.max == null && max != null ? {
963
- max
964
- } : {}, column.ellipsis == null && ellipsis != null ? {
965
- ellipsis
966
- } : {}, type && ELLIPSIS_HANDLED_TYPES.includes(type) ? {
967
- ellipsisHandledByRender: true
968
- } : {}, type && FULL_WIDTH_CELL_TYPES.includes(type) ? {
969
- cellFullWidth: true
970
- } : {}, column.type === 'options' && !type ? {
971
- cellFullWidth: true
972
- } : {}, type === 'options' && column.type !== 'options' ? {
973
- type: 'options'
974
- } : {}));
975
- };
976
- const resolveColumns = columns => (columns || []).map(resolveColumn);
977
- const isOptionsColumn = column => {
978
- if ((column == null ? void 0 : column.type) === 'options') {
979
- return true;
980
- }
981
- return parseRenderType(column == null ? void 0 : column.renderType).type === 'options';
982
- };
983
-
984
- const computeColumnsValue = ({
985
- columns,
986
- emptyIsPlaceholder,
987
- valueIsEmpty,
988
- removeEmpty: _removeEmpty = true,
989
- dataSource,
990
- context
991
- }) => {
992
- return (output => _removeEmpty ? output.filter(item => !!item) : output)(columns.map(item => {
993
- const itemValue = typeof item.getValueOf === 'function' ? item.getValueOf(dataSource, {
994
- column: item,
995
- context
996
- }) : get(dataSource, item.name);
997
- const displayValue = (value => {
998
- if (typeof item.format === 'function') {
999
- return item.format(value, {
1000
- dataSource,
1001
- column: item,
1002
- context
1003
- });
1004
- }
1005
- if (typeof item.format === 'string') {
1006
- const formatValue = formatView(value, item.format, {
1007
- dataSource,
1008
- column: item,
1009
- context
1010
- });
1011
- if (formatValue) {
1012
- return formatValue;
1013
- }
1014
- }
1015
- return value;
1016
- })(itemValue);
1017
- const itemIsEmpty = (item.valueIsEmpty || valueIsEmpty)(itemValue);
1018
- if (item.display === false || typeof item.display === 'function' && item.display(itemValue, {
1019
- dataSource,
1020
- column: item,
1021
- context
1022
- }) === false) {
1023
- return null;
1024
- }
1025
- if (!(item.hasOwnProperty('emptyIsPlaceholder') ? item.emptyIsPlaceholder : emptyIsPlaceholder) && itemIsEmpty) {
1026
- return null;
1027
- }
1028
- return Object.assign({}, item, {
1029
- isEmpty: itemIsEmpty,
1030
- value: displayValue
1031
- });
1032
- }));
1033
- };
1034
- const computeDisplay = ({
1035
- column,
1036
- dataSource,
1037
- placeholder,
1038
- context
1039
- }) => {
1040
- if (column.isEmpty) {
1041
- return typeof column.renderPlaceholder === 'function' ? column.renderPlaceholder({
1042
- column: column,
1043
- dataSource,
1044
- placeholder,
1045
- context
1046
- }) : column.placeholder || placeholder;
1047
- }
1048
- const render = getColumnRender(column);
1049
- return typeof render === 'function' ? render(column.value, {
1050
- column,
1051
- dataSource,
1052
- context
1053
- }) : column.value;
1054
- };
1055
- const computeColumnsDisplay = ({
1056
- columns,
1057
- emptyIsPlaceholder,
1058
- valueIsEmpty,
1059
- removeEmpty,
1060
- dataSource,
1061
- placeholder,
1062
- context
1063
- }) => {
1064
- return computeColumnsValue({
1065
- columns,
1066
- emptyIsPlaceholder,
1067
- valueIsEmpty,
1068
- removeEmpty,
1069
- dataSource,
1070
- context
1071
- }).map(column => {
1072
- return computeDisplay({
1073
- column,
1074
- placeholder,
1075
- dataSource,
1076
- context
1077
- });
1078
- });
1079
- };
1080
- computeColumnsValue.computeDisplay = computeDisplay;
1081
- computeColumnsValue.computeColumnsDisplay = computeColumnsDisplay;
1082
-
1083
- var style$5 = {"table":"kne-table-page_lZgIW","header":"kne-table-page_d1qN5","col":"kne-table-page_KNy4z","tableView":"kne-table-page_fUw6j","grid":"kne-table-page_JlDmf","header-cell":"kne-table-page_P-ebv","col-content":"kne-table-page_HT5Rr","body-row":"kne-table-page_Z6mVv","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","single-checked":"kne-table-page_9UAoL","col-fixed":"kne-table-page_aB-1c","empty":"kne-table-page_SRI8Q"};
1084
-
1085
- var style$4 = {"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","is-sticky":"kne-table-page_jGzIR","is-sticky-scroll-y":"kne-table-page_P6lxG","is-sticky-viewport":"kne-table-page_Kr-p6","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"};
11
+ import useRefCallback from '@kne/use-ref-callback';
12
+ import transform from 'lodash/transform';
13
+ import pick from 'lodash/pick';
14
+ import findLastIndex from 'lodash/findLastIndex';
15
+ import isEqual from 'lodash/isEqual';
16
+ import { HolderOutlined, RedoOutlined, SettingOutlined, DownOutlined } from '@ant-design/icons';
17
+ import { useDebouncedCallback } from 'use-debounce';
18
+ import groupBy from 'lodash/groupBy';
19
+ import { ReactSortable } from 'react-sortablejs';
20
+ import cloneDeep from 'lodash/cloneDeep';
21
+ import { createWithIntlProvider, useIntl } from '@kne/react-intl';
22
+ import filterZhCN from '@kne/react-filter/dist/locale/zh-CN';
23
+ import filterEnUS from '@kne/react-filter/dist/locale/en-US';
24
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
25
+ import { createPortal } from 'react-dom';
26
+ import '@kne/react-filter/dist/index.css';
1086
27
 
1087
- const useSelectedRow = options => {
1088
- const {
1089
- rowKey,
1090
- type = 'checkbox'
1091
- } = Object.assign({}, {
1092
- rowKey: 'id'
1093
- }, options);
1094
- const [selectedRows, setSelectedRows] = useState([]);
1095
- const getRowId = useCallback(item => get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey), [rowKey]);
1096
- const selectedRowKeys = useMemo(() => selectedRows.map(getRowId), [getRowId, selectedRows]);
1097
- const setSelectedRowKeys = useCallback((keys, dataSource = []) => {
1098
- const keySet = new Set(keys || []);
1099
- setSelectedRows((dataSource || []).filter(item => keySet.has(getRowId(item))));
1100
- }, [getRowId]);
1101
- const clearSelectedRows = useCallback(() => {
1102
- setSelectedRows([]);
1103
- }, []);
1104
- const onSelectAll = useCallback((checked, _selected, items) => {
1105
- const ids = (items || []).map(getRowId);
1106
- if (checked) {
1107
- setSelectedRows(value => {
1108
- const existingKeys = value.map(getRowId);
1109
- return [...value, ...(items || []).filter(item => existingKeys.indexOf(getRowId(item)) === -1)];
1110
- });
1111
- } else {
1112
- setSelectedRows(value => {
1113
- return value.filter(item => ids.indexOf(getRowId(item)) === -1);
1114
- });
1115
- }
1116
- }, [getRowId]);
1117
- const onSelect = useCallback((item, checked) => {
1118
- if (checked) {
1119
- if (type === 'radio') {
1120
- setSelectedRows([item]);
1121
- return;
1122
- }
1123
- setSelectedRows(value => {
1124
- const newValue = value.slice(0);
1125
- newValue.push(item);
1126
- return newValue;
1127
- });
1128
- } else {
1129
- setSelectedRows(value => {
1130
- const newValue = value.slice(0);
1131
- const index = newValue.findIndex(row => getRowId(row) === getRowId(item));
1132
- if (index > -1) {
1133
- newValue.splice(index, 1);
1134
- }
1135
- return newValue;
1136
- });
28
+ function _extends() {
29
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
30
+ for (var e = 1; e < arguments.length; e++) {
31
+ var t = arguments[e];
32
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
1137
33
  }
1138
- }, [getRowId, type]);
1139
- const getRowSelection = useCallback((dataSource, extra = {}) => {
1140
- const onChange = (keys, id, meta) => {
1141
- setSelectedRowKeys(keys, dataSource);
1142
- extra.onChange && extra.onChange(keys, id, meta);
1143
- };
1144
- return Object.assign({
1145
- type,
1146
- selectedRowKeys,
1147
- allowSelectedAll: type === 'checkbox',
1148
- onChange
1149
- }, extra);
1150
- }, [selectedRowKeys, setSelectedRowKeys, type]);
1151
- return {
1152
- type,
1153
- selectedRowKeys,
1154
- selectedRows,
1155
- onSelectAll,
1156
- onSelect,
1157
- setSelectedRows,
1158
- setSelectedRowKeys,
1159
- clearSelectedRows,
1160
- getRowSelection
1161
- };
1162
- };
1163
-
1164
- var style$3 = {"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"};
1165
-
1166
- var style$2 = {"ellipsis":"kne-table-page_QBxlu"};
1167
-
1168
- const isSimpleTitle = title => typeof title === 'string' || typeof title === 'number';
1169
- const wrapColumnHeaderTitle = title => {
1170
- if (title == null || title === '') {
1171
- return title;
1172
- }
1173
- if (isSimpleTitle(title)) {
1174
- return /*#__PURE__*/jsx(Ellipsis, {
1175
- ellipsis: true,
1176
- children: title
1177
- });
34
+ return n;
35
+ }, _extends.apply(null, arguments);
36
+ }
37
+ function _objectWithoutPropertiesLoose(r, e) {
38
+ if (null == r) return {};
39
+ var t = {};
40
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
41
+ if (-1 !== e.indexOf(n)) continue;
42
+ t[n] = r[n];
1178
43
  }
1179
- return /*#__PURE__*/jsx("span", {
1180
- className: style$2['ellipsis'],
1181
- children: title
1182
- });
1183
- };
44
+ return t;
45
+ }
1184
46
 
1185
- const sortArrayToMap = sort => new Map((sort || []).map(item => {
1186
- return [item.name, item.sort];
1187
- }));
1188
- const useControlValue = ({
1189
- value,
1190
- defaultValue,
1191
- onChange
1192
- }) => {
1193
- const [internalValue, setInternalValue] = useState(defaultValue);
1194
- const isControlled = value !== undefined;
1195
- const currentValue = isControlled ? value : internalValue;
1196
- const setValue = useCallback(updater => {
1197
- const nextValue = typeof updater === 'function' ? updater(currentValue) : updater;
1198
- if (!isControlled) {
1199
- setInternalValue(nextValue);
1200
- }
1201
- onChange && onChange(nextValue);
1202
- }, [currentValue, isControlled, onChange]);
1203
- return [currentValue, setValue];
1204
- };
1205
- const compareValues = (a, b, direction) => {
1206
- const emptyA = a == null || a === '';
1207
- const emptyB = b == null || b === '';
1208
- if (emptyA && emptyB) {
1209
- return 0;
1210
- }
1211
- if (emptyA) {
1212
- return 1;
1213
- }
1214
- if (emptyB) {
1215
- return -1;
1216
- }
1217
- if (typeof a === 'number' && typeof b === 'number') {
1218
- return direction === 'ASC' ? a - b : b - a;
1219
- }
1220
- const strA = String(a);
1221
- const strB = String(b);
1222
- return direction === 'ASC' ? strA.localeCompare(strB, 'zh-CN') : strB.localeCompare(strA, 'zh-CN');
1223
- };
1224
- const sortDataSource = (dataSource, sort = [], columns = []) => {
1225
- if (!(sort != null && sort.length) || !(dataSource != null && dataSource.length)) {
1226
- return dataSource;
1227
- }
1228
- const columnMap = new Map(columns.map(column => [column.name, column]));
1229
- return [...dataSource].sort((a, b) => {
1230
- for (const {
1231
- name,
1232
- sort: direction
1233
- } of sort) {
1234
- const column = columnMap.get(name) || {
1235
- name
1236
- };
1237
- const aVal = typeof column.getValueOf === 'function' ? column.getValueOf(a, {
1238
- column
1239
- }) : get(a, name);
1240
- const bVal = typeof column.getValueOf === 'function' ? column.getValueOf(b, {
1241
- column
1242
- }) : get(b, name);
1243
- const result = compareValues(aVal, bVal, direction);
1244
- if (result !== 0) {
1245
- return result;
1246
- }
1247
- }
1248
- return 0;
1249
- });
1250
- };
1251
- const getSortSingle = sortOption => {
1252
- if (typeof sortOption === 'object') {
1253
- return sortOption.single !== false;
1254
- }
1255
- return true;
1256
- };
1257
- const renderColumnTitle = (title, column, sortRender) => {
1258
- const titleContent = wrapColumnHeaderTitle(title);
1259
- if (!column.sort || typeof sortRender !== 'function') {
1260
- return titleContent;
1261
- }
1262
- return /*#__PURE__*/jsxs("span", {
1263
- className: classnames(style$3['title'], style$3['has-sort']),
1264
- children: [/*#__PURE__*/jsx("span", {
1265
- className: style$3['title-text'],
1266
- children: titleContent
1267
- }), sortRender({
1268
- name: column.name,
1269
- single: getSortSingle(column.sort)
1270
- })]
1271
- });
1272
- };
1273
- const useSort = (props = {}) => {
1274
- const [sort, setSort] = useControlValue({
1275
- value: props.sort,
1276
- defaultValue: props.defaultSort || [],
1277
- onChange: props.onSortChange
1278
- });
1279
- const mapSort = useMemo(() => {
1280
- return sortArrayToMap(sort);
1281
- }, [sort]);
1282
- const setMapSort = useCallback(callback => {
1283
- return setSort(currentSort => {
1284
- const newSort = callback(sortArrayToMap(currentSort));
1285
- return Array.from(newSort).map(([name, sortValue]) => ({
1286
- name,
1287
- sort: sortValue
1288
- }));
1289
- });
1290
- }, [setSort]);
1291
- const sortRender = useCallback(({
1292
- single,
1293
- name
1294
- }) => {
1295
- const direction = mapSort.get(name);
1296
- return /*#__PURE__*/jsxs("span", {
1297
- className: style$3['sort-btn'],
1298
- onClick: e => {
1299
- e.stopPropagation();
1300
- setMapSort(sortMap => {
1301
- const current = sortMap.get(name);
1302
- const targetValue = (() => {
1303
- if (current === 'DESC') {
1304
- return 'ASC';
1305
- }
1306
- if (current === 'ASC') {
1307
- return null;
1308
- }
1309
- return 'DESC';
1310
- })();
1311
- if (single) {
1312
- return new Map(targetValue ? [[name, targetValue]] : []);
1313
- }
1314
- const newSort = clone(sortMap);
1315
- targetValue ? newSort.set(name, targetValue) : newSort.delete(name);
1316
- return newSort;
1317
- });
1318
- },
1319
- children: [/*#__PURE__*/jsx(CaretUpOutlined, {
1320
- className: classnames(style$3['sort-icon'], style$3['sort-up'], {
1321
- [style$3['active']]: direction === 'ASC'
1322
- })
1323
- }), /*#__PURE__*/jsx(CaretDownOutlined, {
1324
- className: classnames(style$3['sort-icon'], style$3['sort-down'], {
1325
- [style$3['active']]: direction === 'DESC'
1326
- })
1327
- })]
1328
- });
1329
- }, [mapSort, setMapSort]);
1330
- return {
1331
- sort,
1332
- setSort,
1333
- sortRender
1334
- };
1335
- };
1336
- useSort.sortDataSource = sortDataSource;
47
+ var style$2 = {"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","is-sticky":"kne-table-page_jGzIR","is-sticky-scroll-y":"kne-table-page_P6lxG","is-sticky-viewport":"kne-table-page_Kr-p6","col-content":"kne-table-page_CWr3V","empty":"kne-table-page_BoatL","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"};
1337
48
 
1338
49
  const getColumnConfig = (config, columnName, field, defaultValue) => {
1339
50
  const columnConfig = config == null ? void 0 : config[columnName];
@@ -2029,28 +740,6 @@ const useElementWidth = ref => {
2029
740
  return width;
2030
741
  };
2031
742
 
2032
- const renderCellContent = (content, column, contentClassName) => {
2033
- const wrapEllipsis = column.ellipsis && !column.ellipsisHandledByRender;
2034
- const needsWidthConstraint = Boolean(column.ellipsis || column.cellFullWidth);
2035
- const inner = wrapEllipsis ? /*#__PURE__*/jsx(Ellipsis, {
2036
- ellipsis: column.ellipsis,
2037
- children: content
2038
- }) : content;
2039
- return /*#__PURE__*/jsx("span", {
2040
- className: contentClassName,
2041
- children: needsWidthConstraint ? /*#__PURE__*/jsx("span", {
2042
- className: classnames(ellipsisStyle['cell-content'], column.cellFullWidth && ellipsisStyle['cell-full-width']),
2043
- children: inner
2044
- }) : inner
2045
- });
2046
- };
2047
- const getColumnEllipsis = column => {
2048
- if (!column.ellipsis) {
2049
- return undefined;
2050
- }
2051
- return typeof column.ellipsis === 'object' ? column.ellipsis : true;
2052
- };
2053
-
2054
743
  const parsePixelValue = value => {
2055
744
  const num = parseFloat(value);
2056
745
  return Number.isNaN(num) ? 0 : num;
@@ -2297,7 +986,7 @@ const observeViewportIntersection = (element, onChange) => {
2297
986
  };
2298
987
  };
2299
988
 
2300
- const _excluded$3 = ["className", "dataSource", "columns", "rowKey", "rowSelection", "valueIsEmpty", "emptyIsPlaceholder", "placeholder", "empty", "onRowSelect", "render", "context", "sticky", "scrollTopInset", "stickyOffset", "getStickyContainer", "headerStyle", "pagination", "sortRender", "name", "controllerOpen", "tableServerApis", "scroll", "summary"],
989
+ const _excluded$2 = ["className", "dataSource", "columns", "rowKey", "rowSelection", "valueIsEmpty", "emptyIsPlaceholder", "placeholder", "empty", "onRowSelect", "render", "context", "sticky", "scrollTopInset", "stickyOffset", "getStickyContainer", "headerStyle", "pagination", "sortRender", "name", "controllerOpen", "tableServerApis", "scroll", "summary"],
2301
990
  _excluded2$2 = ["getContainer"];
2302
991
  const mapJustifyToAlign = justify => {
2303
992
  if (justify === 'center') {
@@ -2332,9 +1021,9 @@ const getColCellStyle = column => ({
2332
1021
  textAlign: mapJustifyToAlign(column.justify),
2333
1022
  verticalAlign: column.align === 'middle' ? 'middle' : column.align === 'bottom' ? 'bottom' : 'top'
2334
1023
  });
2335
- const getAntCellClassName = (...extra) => classnames(style$4['table-cell'], 'info-page-table-col', ...extra);
1024
+ const getAntCellClassName = (...extra) => classnames(style$2['table-cell'], 'info-page-table-col', ...extra);
2336
1025
  const wrapColContent = node => /*#__PURE__*/jsx("span", {
2337
- className: style$5['col-content'],
1026
+ className: style$2['col-content'],
2338
1027
  children: node
2339
1028
  });
2340
1029
  const Table = p => {
@@ -2375,7 +1064,7 @@ const Table = p => {
2375
1064
  scroll,
2376
1065
  summary
2377
1066
  } = props,
2378
- others = _objectWithoutPropertiesLoose(props, _excluded$3);
1067
+ others = _objectWithoutPropertiesLoose(props, _excluded$2);
2379
1068
  const columns = useMemo(() => resolveColumns(columnsProp), [columnsProp]);
2380
1069
  useEffect(() => {
2381
1070
  if (tableWidth) {
@@ -2464,7 +1153,7 @@ const Table = p => {
2464
1153
  key: colName,
2465
1154
  dataIndex: colName,
2466
1155
  title: /*#__PURE__*/jsx("span", {
2467
- className: style$5['col-content'],
1156
+ className: style$2['col-content'],
2468
1157
  children: renderColumnTitle(title, column, sortRender)
2469
1158
  }),
2470
1159
  width: toAntdWidth(width),
@@ -2497,7 +1186,7 @@ const Table = p => {
2497
1186
  placeholder,
2498
1187
  dataSource: record,
2499
1188
  context
2500
- }), computedColumn, style$5['col-content']);
1189
+ }), computedColumn, style$2['col-content']);
2501
1190
  }
2502
1191
  };
2503
1192
  if (!controllerOpen) {
@@ -2505,7 +1194,7 @@ const Table = p => {
2505
1194
  }
2506
1195
  const configProps = computedColumnProps(column, index, {
2507
1196
  title: /*#__PURE__*/jsx("span", {
2508
- className: style$5['col-content'],
1197
+ className: style$2['col-content'],
2509
1198
  children: renderColumnTitle(title, column, sortRender)
2510
1199
  })
2511
1200
  });
@@ -2528,7 +1217,7 @@ const Table = p => {
2528
1217
  return {
2529
1218
  key: column.name,
2530
1219
  title: /*#__PURE__*/jsx("span", {
2531
- className: style$5['col-content'],
1220
+ className: style$2['col-content'],
2532
1221
  children: wrapColumnHeaderTitle(column.title)
2533
1222
  }),
2534
1223
  onHeaderCell: () => ({
@@ -2594,13 +1283,13 @@ const Table = p => {
2594
1283
  })),
2595
1284
  renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
2596
1285
  onCell: () => ({
2597
- className: getAntCellClassName(style$4['selection-col'])
1286
+ className: getAntCellClassName(style$2['selection-col'])
2598
1287
  })
2599
1288
  } : {
2600
1289
  columnWidth: 30,
2601
1290
  renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
2602
1291
  onCell: () => ({
2603
- className: getAntCellClassName(style$4['radio-col'])
1292
+ className: getAntCellClassName(style$2['radio-col'])
2604
1293
  })
2605
1294
  });
2606
1295
  }, [context, dataSource, rowKey, rowSelection, hasFixedColumn]);
@@ -2668,22 +1357,22 @@ const Table = p => {
2668
1357
  tableLayout: controllerOpen || hasFixedColumn ? 'fixed' : undefined,
2669
1358
  scroll: tableScroll,
2670
1359
  onHeaderRow: () => ({
2671
- className: classnames(style$5['header'], 'info-page-table-header'),
1360
+ className: 'info-page-table-header',
2672
1361
  style: headerStyle
2673
1362
  }),
2674
1363
  locale: {
2675
1364
  emptyText: /*#__PURE__*/jsx("div", {
2676
- className: style$5['empty'],
1365
+ className: style$2['empty'],
2677
1366
  children: empty
2678
1367
  })
2679
1368
  },
2680
1369
  rowClassName: record => {
2681
1370
  const id = resolveRowKey(rowKey, record);
2682
1371
  const isChecked = (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) && rowSelection.selectedRowKeys.indexOf(id) > -1;
2683
- return classnames(style$5['body'], 'info-page-table-row', {
2684
- [style$5['is-selected-all']]: rowSelection == null ? void 0 : rowSelection.isSelectedAll,
2685
- [style$5['is-selected']]: isChecked,
2686
- [style$5['is-disabled']]: record.disabled
1372
+ return classnames('info-page-table-row', {
1373
+ [style$2['is-selected-all']]: rowSelection == null ? void 0 : rowSelection.isSelectedAll,
1374
+ [style$2['is-selected']]: isChecked,
1375
+ [style$2['is-disabled']]: record.disabled
2687
1376
  });
2688
1377
  },
2689
1378
  onRow: onRowSelect ? record => ({
@@ -2700,21 +1389,21 @@ const Table = p => {
2700
1389
  }));
2701
1390
  const wrappedTable = /*#__PURE__*/jsxs("div", {
2702
1391
  ref: tableRef,
2703
- className: classnames(style$4['table'], 'info-page-table', className, {
2704
- [style$4['is-resize']]: currentMoveColumnIndex !== null,
2705
- [style$4['is-computed']]: isLayout,
2706
- [style$4['has-group-header']]: hasGroupHeader,
2707
- [style$4['has-summary']]: typeof summary === 'function',
2708
- [style$4['is-sticky']]: !!sticky,
2709
- [style$4['is-sticky-scroll-y']]: !!sticky && hasScrollY,
2710
- [style$4['is-sticky-viewport']]: isStickyViewport
1392
+ className: classnames(style$2['table'], 'info-page-table', className, {
1393
+ [style$2['is-resize']]: currentMoveColumnIndex !== null,
1394
+ [style$2['is-computed']]: isLayout,
1395
+ [style$2['has-group-header']]: hasGroupHeader,
1396
+ [style$2['has-summary']]: typeof summary === 'function',
1397
+ [style$2['is-sticky']]: !!sticky,
1398
+ [style$2['is-sticky-scroll-y']]: !!sticky && hasScrollY,
1399
+ [style$2['is-sticky-viewport']]: isStickyViewport
2711
1400
  }),
2712
1401
  style: tableWrapperStyle,
2713
1402
  children: [/*#__PURE__*/jsx("div", {
2714
1403
  className: "info-page-table-body",
2715
1404
  children: !isLayout && tableElement
2716
1405
  }), currentMoveColumnIndex !== null && resizeGuideStyle && /*#__PURE__*/jsx("span", {
2717
- className: style$4['column-resize-guide'],
1406
+ className: style$2['column-resize-guide'],
2718
1407
  style: resizeGuideStyle,
2719
1408
  "aria-hidden": true
2720
1409
  })]
@@ -2731,372 +1420,6 @@ Table.useSelectedRow = useSelectedRow;
2731
1420
  Table.useSort = useSort;
2732
1421
  Table.sortDataSource = useSort.sortDataSource;
2733
1422
 
2734
- const Label = ({
2735
- className,
2736
- children,
2737
- onChange
2738
- }) => {
2739
- const ref = useRef(null);
2740
- const handlerChange = useRefCallback(onChange);
2741
- useLayoutEffect(() => {
2742
- const computed = () => {
2743
- if (!ref.current) {
2744
- return;
2745
- }
2746
- handlerChange(ref.current.getBoundingClientRect());
2747
- };
2748
- const resizeObserver = new ResizeObserver(computed);
2749
- resizeObserver.observe(ref.current);
2750
- computed();
2751
- return () => {
2752
- resizeObserver.disconnect();
2753
- };
2754
- }, [handlerChange]);
2755
- return /*#__PURE__*/jsx("span", {
2756
- ref: ref,
2757
- className: className,
2758
- children: children
2759
- });
2760
- };
2761
-
2762
- const renderHeaderCellContent = (column, {
2763
- sortRender,
2764
- widthBased,
2765
- setColsSize,
2766
- defaultSpan,
2767
- colsSize
2768
- }) => {
2769
- const titleNode = renderColumnTitle(column.title, column, sortRender);
2770
- const contentClassName = style$5['col-content'];
2771
- if (widthBased) {
2772
- return /*#__PURE__*/jsx("span", {
2773
- className: contentClassName,
2774
- children: titleNode
2775
- });
2776
- }
2777
- return /*#__PURE__*/jsx(Label, {
2778
- className: contentClassName,
2779
- onChange: size => {
2780
- setColsSize(value => Object.assign({}, value, {
2781
- [column.name]: Math.max(size.width, parseColumnWidth(resolveColumnDimensions(column).width))
2782
- }));
2783
- },
2784
- children: titleNode
2785
- });
2786
- };
2787
- const renderHeaderGridCells = ({
2788
- dataSource,
2789
- columns,
2790
- rowKey,
2791
- rowSelection,
2792
- colsSize,
2793
- setColsSize,
2794
- sortRender,
2795
- defaultSpan
2796
- }) => {
2797
- const cells = [];
2798
- if ((rowSelection == null ? void 0 : rowSelection.type) === 'checkbox') {
2799
- cells.push(/*#__PURE__*/jsx("div", {
2800
- className: classnames(style$5['col'], style$5['col-fixed'], style$5['header-cell'], 'info-page-table-col'),
2801
- children: /*#__PURE__*/jsx("span", {
2802
- className: classnames(style$5['col-content'], 'info-page-table-col-content'),
2803
- children: rowSelection.allowSelectedAll ? (() => {
2804
- const checkedAll = rowSelection.isSelectedAll || dataSource && dataSource.every(item => rowSelection.selectedRowKeys && rowSelection.selectedRowKeys.indexOf(get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey)) > -1);
2805
- return /*#__PURE__*/jsx(Checkbox, {
2806
- checked: checkedAll,
2807
- indeterminate: rowSelection.selectedRowKeys && rowSelection.selectedRowKeys.length > 0 && !checkedAll,
2808
- onChange: e => {
2809
- const checked = e.target.checked;
2810
- if (!checked) {
2811
- typeof rowSelection.onIsSelectAllChange === 'function' ? rowSelection.onIsSelectAllChange(false) : rowSelection.onChange([]);
2812
- } else {
2813
- typeof rowSelection.onIsSelectAllChange === 'function' ? rowSelection.onIsSelectAllChange(true) : dataSource && dataSource.length > 0 && rowSelection.onChange(dataSource.map(item => {
2814
- return get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey);
2815
- }));
2816
- }
2817
- }
2818
- });
2819
- })() : /*#__PURE__*/jsx(Checkbox, {
2820
- style: {
2821
- visibility: 'hidden'
2822
- }
2823
- })
2824
- })
2825
- }, "__selection__"));
2826
- }
2827
- columns.forEach((column, index) => {
2828
- const {
2829
- widthBased,
2830
- fillRemaining,
2831
- style: columnStyle
2832
- } = getColumnLayout(column, {
2833
- defaultSpan,
2834
- colsSize,
2835
- isLastColumn: index === columns.length - 1,
2836
- columns
2837
- });
2838
- cells.push(/*#__PURE__*/jsx("div", {
2839
- style: columnStyle,
2840
- className: classnames(style$5['col'], fillRemaining ? style$5['col-width-fill'] : widthBased && style$5['col-width-based'], style$5['header-cell'], 'info-page-table-col'),
2841
- children: renderHeaderCellContent(column, {
2842
- sortRender,
2843
- widthBased,
2844
- setColsSize,
2845
- defaultSpan,
2846
- colsSize
2847
- })
2848
- }, column.name));
2849
- });
2850
- if ((rowSelection == null ? void 0 : rowSelection.type) === 'radio') {
2851
- cells.push(/*#__PURE__*/jsx("div", {
2852
- className: classnames(style$5['col'], style$5['single-checked'], style$5['header-cell'], 'info-page-table-col')
2853
- }, "__radio__"));
2854
- }
2855
- return cells;
2856
- };
2857
- const Header = p => {
2858
- const {
2859
- dataSource,
2860
- columns,
2861
- rowKey,
2862
- rowSelection,
2863
- colsSize,
2864
- setColsSize,
2865
- headerStyle,
2866
- sortRender,
2867
- defaultSpan
2868
- } = Object.assign({}, {
2869
- rowKey: 'id'
2870
- }, p);
2871
- return /*#__PURE__*/jsx("div", {
2872
- style: headerStyle,
2873
- className: classnames(style$5['header'], 'info-page-table-header'),
2874
- children: renderHeaderGridCells({
2875
- dataSource,
2876
- columns,
2877
- rowKey,
2878
- rowSelection,
2879
- colsSize,
2880
- setColsSize,
2881
- sortRender,
2882
- defaultSpan
2883
- })
2884
- });
2885
- };
2886
-
2887
- const _excluded$2 = ["className", "dataSource", "columns", "rowKey", "rowSelection", "valueIsEmpty", "emptyIsPlaceholder", "placeholder", "empty", "onRowSelect", "render", "context", "sticky", "headerStyle", "sortRender"];
2888
- const getLayoutColumns = columns => columns.filter(column => column.display !== false);
2889
- const TableView = p => {
2890
- const [colsSize, setColsSize] = useState({});
2891
- const props = Object.assign({}, {
2892
- rowKey: 'id',
2893
- valueIsEmpty: isEmpty,
2894
- placeholder: '-',
2895
- emptyIsPlaceholder: true,
2896
- empty: /*#__PURE__*/jsx(Empty, {})
2897
- }, p);
2898
- const {
2899
- className,
2900
- dataSource,
2901
- columns: columnsProp,
2902
- rowKey,
2903
- rowSelection,
2904
- valueIsEmpty,
2905
- emptyIsPlaceholder,
2906
- placeholder,
2907
- empty,
2908
- onRowSelect,
2909
- render,
2910
- context,
2911
- headerStyle,
2912
- sortRender
2913
- } = props,
2914
- others = _objectWithoutPropertiesLoose(props, _excluded$2);
2915
- const columns = useMemo(() => resolveColumns(columnsProp), [columnsProp]);
2916
- const layoutColumns = useMemo(() => getLayoutColumns(columns), [columns]);
2917
- const defaultSpan = useMemo(() => {
2918
- const assignedSpan = layoutColumns.reduce((a, b) => a + (b.span || 0), 0);
2919
- const undistributedColCount = layoutColumns.filter(item => !hasColumnSpan(item) && !hasColumnWidth(item, layoutColumns)).length;
2920
- return undistributedColCount > 0 ? Math.round(Math.max(24 - assignedSpan, 0) / undistributedColCount) : 1;
2921
- }, [layoutColumns]);
2922
- const gridTemplateColumns = useMemo(() => getGridTemplateColumns(layoutColumns, {
2923
- defaultSpan,
2924
- colsSize,
2925
- rowSelection
2926
- }), [layoutColumns, defaultSpan, colsSize, rowSelection]);
2927
- const headerCellProps = {
2928
- dataSource,
2929
- columns: layoutColumns,
2930
- rowKey,
2931
- rowSelection,
2932
- colsSize,
2933
- setColsSize,
2934
- sortRender,
2935
- defaultSpan
2936
- };
2937
- const header = /*#__PURE__*/jsx(Header, _extends({}, headerCellProps, {
2938
- headerStyle: headerStyle
2939
- }));
2940
- const handleRowClick = (item, {
2941
- dataSource,
2942
- context,
2943
- id,
2944
- isChecked
2945
- }) => {
2946
- if (item.disabled) {
2947
- return;
2948
- }
2949
- onRowSelect && onRowSelect(item, {
2950
- columns: layoutColumns,
2951
- dataSource
2952
- });
2953
- if (!rowSelection || rowSelection.isSelectedAll) {
2954
- return;
2955
- }
2956
- if (rowSelection.type === 'checkbox') {
2957
- const _selectedRowKeys = (rowSelection.selectedRowKeys || []).slice(0);
2958
- isChecked ? _selectedRowKeys.splice(rowSelection.selectedRowKeys.indexOf(id), 1) : _selectedRowKeys.push(id);
2959
- rowSelection.onChange(_selectedRowKeys, id, {
2960
- context,
2961
- checked: !isChecked
2962
- });
2963
- return;
2964
- }
2965
- const selectedRowKeys = rowSelection.selectedRowKeys.length && rowSelection.selectedRowKeys[0] === id ? [] : [id];
2966
- rowSelection.onChange(selectedRowKeys, id, {
2967
- context,
2968
- checked: !isChecked
2969
- });
2970
- };
2971
- const renderBodyGridCells = (dataSource, context) => {
2972
- const getId = item => get(item, typeof rowKey === 'function' ? rowKey(item) : rowKey);
2973
- if (!dataSource || dataSource.length === 0) {
2974
- return null;
2975
- }
2976
- return dataSource.map(item => {
2977
- const id = getId(item);
2978
- const isChecked = (rowSelection == null ? void 0 : rowSelection.selectedRowKeys) && rowSelection.selectedRowKeys.indexOf(id) > -1;
2979
- const columnsValue = computeColumnsValue({
2980
- columns: layoutColumns,
2981
- emptyIsPlaceholder,
2982
- valueIsEmpty,
2983
- removeEmpty: true,
2984
- dataSource: item,
2985
- placeholder,
2986
- context
2987
- });
2988
- const columnMap = columnsValue.reduce((result, column) => Object.assign(result, {
2989
- [column.name]: column
2990
- }), {});
2991
- const rowClassName = classnames(style$5['body'], style$5['body-cell'], style$5['body-row'], 'info-page-table-row', {
2992
- [style$5['is-selected-all']]: rowSelection == null ? void 0 : rowSelection.isSelectedAll,
2993
- [style$5['is-selected']]: isChecked,
2994
- [style$5['is-disabled']]: item.disabled
2995
- });
2996
- const onSelectionChange = () => handleRowClick(item, {
2997
- dataSource,
2998
- context,
2999
- id,
3000
- isChecked
3001
- });
3002
- const cells = [];
3003
- if ((rowSelection == null ? void 0 : rowSelection.type) === 'checkbox') {
3004
- cells.push(/*#__PURE__*/jsx("div", {
3005
- className: classnames(style$5['col'], style$5['col-fixed'], 'info-page-table-col'),
3006
- children: /*#__PURE__*/jsx("span", {
3007
- className: classnames(style$5['col-content'], 'info-page-table-col-content'),
3008
- children: /*#__PURE__*/jsx(Checkbox, {
3009
- disabled: item.disabled || rowSelection.isSelectedAll,
3010
- checked: rowSelection.isSelectedAll && !item.disabled || isChecked,
3011
- onChange: onSelectionChange
3012
- })
3013
- })
3014
- }, `${id}__selection__`));
3015
- }
3016
- layoutColumns.forEach((column, index) => {
3017
- const columnValue = columnMap[column.name];
3018
- const {
3019
- widthBased,
3020
- fillRemaining,
3021
- style: columnStyle
3022
- } = getColumnLayout(column, {
3023
- defaultSpan,
3024
- colsSize,
3025
- isLastColumn: index === layoutColumns.length - 1,
3026
- columns: layoutColumns
3027
- });
3028
- cells.push(/*#__PURE__*/jsx("div", {
3029
- style: columnStyle,
3030
- className: classnames(style$5['col'], fillRemaining ? style$5['col-width-fill'] : widthBased && style$5['col-width-based'], 'info-page-table-col'),
3031
- children: columnValue ? renderCellContent(computeDisplay({
3032
- column: columnValue,
3033
- placeholder,
3034
- dataSource: item,
3035
- context
3036
- }), columnValue, style$5['col-content']) : /*#__PURE__*/jsx("span", {
3037
- className: style$5['col-content']
3038
- })
3039
- }, `${id}-${column.name}`));
3040
- });
3041
- if ((rowSelection == null ? void 0 : rowSelection.type) === 'radio') {
3042
- cells.push(/*#__PURE__*/jsx("div", {
3043
- className: classnames(style$5['col'], style$5['single-checked'], 'info-page-table-col'),
3044
- onClick: onSelectionChange,
3045
- children: isChecked && /*#__PURE__*/jsx(CheckOutlined, {})
3046
- }, `${id}__radio__`));
3047
- }
3048
- return /*#__PURE__*/jsx("div", {
3049
- className: rowClassName,
3050
- children: cells
3051
- }, id);
3052
- });
3053
- };
3054
- const renderGrid = (dataSource, context) => /*#__PURE__*/jsxs("div", {
3055
- className: style$5['grid'],
3056
- style: {
3057
- gridTemplateColumns
3058
- },
3059
- children: [renderHeaderGridCells(headerCellProps), renderBodyGridCells(dataSource, context)]
3060
- });
3061
- const renderBody = (dataSource, context) => {
3062
- if (!dataSource || dataSource.length === 0) {
3063
- return /*#__PURE__*/jsx("div", {
3064
- className: style$5['empty'],
3065
- children: empty
3066
- });
3067
- }
3068
- return /*#__PURE__*/jsx("div", {
3069
- className: classnames('info-page-table-body'),
3070
- children: renderGrid(dataSource, context)
3071
- });
3072
- };
3073
- if (typeof render === 'function') {
3074
- return render(_extends({}, others, {
3075
- header,
3076
- renderBody
3077
- }));
3078
- }
3079
- return /*#__PURE__*/jsx("div", _extends({}, others, {
3080
- className: classnames(style$5['table'], style$5['tableView'], 'info-page-table', className),
3081
- children: dataSource && dataSource.length > 0 ? renderGrid(dataSource, context) : /*#__PURE__*/jsxs(Fragment, {
3082
- children: [/*#__PURE__*/jsx("div", {
3083
- className: style$5['grid'],
3084
- style: {
3085
- gridTemplateColumns
3086
- },
3087
- children: renderHeaderGridCells(headerCellProps)
3088
- }), /*#__PURE__*/jsx("div", {
3089
- className: style$5['empty'],
3090
- children: empty
3091
- })]
3092
- })
3093
- }));
3094
- };
3095
- TableView.Header = Header;
3096
- TableView.useSelectedRow = useSelectedRow;
3097
- TableView.useSort = useSort;
3098
- TableView.sortDataSource = useSort.sortDataSource;
3099
-
3100
1423
  var style$1 = {"table-page":"kne-table-page_ut9rJ","table-content":"kne-table-page_dxN6N","table-with-toolbar":"kne-table-page_sf06r","has-summary":"kne-table-page_IRdzb","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-embedded":"kne-table-page_PIv-C","floating-scrollbar-thumb":"kne-table-page_RjZsu","is-moving":"kne-table-page_y-4Ou"};
3101
1424
 
3102
1425
  const BAR_HEIGHT = 15;
@@ -3829,11 +2152,5 @@ const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
3829
2152
  }));
3830
2153
  });
3831
2154
 
3832
- const preset = props => {
3833
- const next = merge({}, globalParams, props);
3834
- merge(globalParams, props);
3835
- return next;
3836
- };
3837
-
3838
- export { RENDER_TYPE_NAMES, SIZE_NAMES, Table, TableView, TablePage as default, getColumnRender, getRenderTypeDimensions, getRenderTypeNames, getStatusType, getTagColor, globalParams, isOptionsColumn, parseRenderType, preset, renderStatusItem, renderTagItem, renderTagList, resolveColumn, resolveColumnDimensions, resolveColumns, resolveRenderType, sortDataSource, tableLocalApis, useSelectedRow, useSort, useTableConfig };
2155
+ export { Table, TablePage as default, tableLocalApis, useTableConfig };
3839
2156
  //# sourceMappingURL=index.modern.js.map