es-grid-template 1.1.8 → 1.2.1
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/assets/index.css +679 -0
- package/assets/index.scss +1006 -0
- package/es/grid-component/ColumnsChoose.d.ts +1 -0
- package/es/grid-component/ColumnsChoose.js +64 -29
- package/es/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/es/grid-component/ColumnsGroup/ColumnsGroup.js +223 -0
- package/es/grid-component/ColumnsGroup/index.d.ts +1 -0
- package/es/grid-component/ColumnsGroup/index.js +1 -0
- package/es/grid-component/ConvertColumnTable.d.ts +7 -0
- package/es/grid-component/ConvertColumnTable.js +143 -0
- package/es/grid-component/EditableCell.js +1 -1
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.js +148 -244
- package/es/grid-component/TableGrid.d.ts +7 -2
- package/es/grid-component/TableGrid.js +33 -55
- package/es/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
- package/es/grid-component/hooks/{useColumns → columns}/index.js +20 -16
- package/es/grid-component/hooks/content/HeaderContent.d.ts +11 -0
- package/es/grid-component/hooks/content/HeaderContent.js +80 -0
- package/es/grid-component/hooks/content/TooltipContent.d.ts +13 -0
- package/es/grid-component/hooks/content/TooltipContent.js +74 -0
- package/es/grid-component/hooks/useColumns.d.ts +16 -0
- package/es/grid-component/hooks/useColumns.js +272 -0
- package/es/grid-component/hooks/utils.d.ts +50 -1
- package/es/grid-component/hooks/utils.js +782 -2
- package/es/grid-component/index.js +3 -1
- package/es/grid-component/styles.scss +354 -63
- package/es/grid-component/table/Grid.d.ts +5 -0
- package/es/grid-component/table/Grid.js +1 -7
- package/es/grid-component/table/GridEdit.d.ts +4 -1
- package/es/grid-component/table/GridEdit.js +768 -264
- package/es/grid-component/table/Group.d.ts +13 -0
- package/es/grid-component/table/Group.js +154 -0
- package/es/grid-component/type.d.ts +43 -2
- package/lib/grid-component/ColumnsChoose.d.ts +1 -0
- package/lib/grid-component/ColumnsChoose.js +63 -28
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +234 -0
- package/lib/grid-component/ColumnsGroup/index.d.ts +1 -0
- package/lib/grid-component/ColumnsGroup/index.js +16 -0
- package/lib/grid-component/ConvertColumnTable.d.ts +7 -0
- package/lib/grid-component/ConvertColumnTable.js +152 -0
- package/lib/grid-component/EditableCell.js +1 -1
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.js +142 -244
- package/lib/grid-component/TableGrid.d.ts +7 -2
- package/lib/grid-component/TableGrid.js +27 -53
- package/lib/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
- package/lib/grid-component/hooks/{useColumns → columns}/index.js +20 -16
- package/lib/grid-component/hooks/content/HeaderContent.d.ts +11 -0
- package/lib/grid-component/hooks/content/HeaderContent.js +87 -0
- package/lib/grid-component/hooks/content/TooltipContent.d.ts +13 -0
- package/lib/grid-component/hooks/content/TooltipContent.js +81 -0
- package/lib/grid-component/hooks/useColumns.d.ts +16 -0
- package/lib/grid-component/hooks/useColumns.js +283 -0
- package/lib/grid-component/hooks/utils.d.ts +50 -1
- package/lib/grid-component/hooks/utils.js +809 -5
- package/lib/grid-component/index.js +2 -1
- package/lib/grid-component/styles.scss +354 -63
- package/lib/grid-component/table/Grid.d.ts +5 -0
- package/lib/grid-component/table/Grid.js +1 -7
- package/lib/grid-component/table/GridEdit.d.ts +4 -1
- package/lib/grid-component/table/GridEdit.js +764 -261
- package/lib/grid-component/table/Group.d.ts +13 -0
- package/lib/grid-component/table/Group.js +163 -0
- package/lib/grid-component/type.d.ts +43 -2
- package/package.json +106 -105
|
@@ -17,8 +17,6 @@ var _CheckboxFilter = _interopRequireDefault(require("../../CheckboxFilter"));
|
|
|
17
17
|
var _useSelection = require("rc-master-ui/es/table/hooks/useSelection");
|
|
18
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
-
// import * as React from 'react'
|
|
21
|
-
|
|
22
20
|
const {
|
|
23
21
|
RangePicker
|
|
24
22
|
} = _rcMasterUi.DatePicker;
|
|
@@ -45,15 +43,16 @@ function flatColumns(columns, parentKey = 'key') {
|
|
|
45
43
|
}];
|
|
46
44
|
}, []);
|
|
47
45
|
}
|
|
48
|
-
function flatColumns2(columns
|
|
46
|
+
function flatColumns2(columns
|
|
47
|
+
// parentKey = 'key'
|
|
48
|
+
) {
|
|
49
49
|
// @ts-ignore
|
|
50
|
-
return columns.reduce((list, column
|
|
51
|
-
const {
|
|
52
|
-
fixed
|
|
53
|
-
} = column;
|
|
50
|
+
return columns.reduce((list, column) => {
|
|
51
|
+
// const { fixed } = column
|
|
54
52
|
// Convert `fixed='true'` to `fixed='left'` instead
|
|
55
|
-
const parsedFixed = fixed === true ? 'left' : fixed
|
|
56
|
-
const mergedKey = `${parentKey}-${index}
|
|
53
|
+
// const parsedFixed = fixed === true ? 'left' : fixed
|
|
54
|
+
// const mergedKey = `${parentKey}-${index}`
|
|
55
|
+
|
|
57
56
|
const subColumns = column.children;
|
|
58
57
|
if (column === _useSelection.SELECTION_COLUMN) {
|
|
59
58
|
return [...list, {
|
|
@@ -61,15 +60,15 @@ function flatColumns2(columns, parentKey = 'key') {
|
|
|
61
60
|
}];
|
|
62
61
|
}
|
|
63
62
|
if (subColumns && subColumns.length > 0) {
|
|
64
|
-
return [...list, ...flatColumns(subColumns
|
|
65
|
-
fixed: parsedFixed,
|
|
63
|
+
return [...list, ...flatColumns(subColumns).map(subColum => ({
|
|
64
|
+
// fixed: parsedFixed,
|
|
66
65
|
...subColum
|
|
67
66
|
}))];
|
|
68
67
|
}
|
|
69
68
|
return [...list, {
|
|
70
|
-
key: mergedKey,
|
|
71
|
-
...column
|
|
72
|
-
fixed: parsedFixed
|
|
69
|
+
// key: mergedKey,
|
|
70
|
+
...column
|
|
71
|
+
// fixed: parsedFixed
|
|
73
72
|
}];
|
|
74
73
|
}, []);
|
|
75
74
|
}
|
|
@@ -138,8 +137,13 @@ const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, s
|
|
|
138
137
|
const type = (0, _utils.getTypeFilter)(column);
|
|
139
138
|
const dateFormat = (0, _utils.getDatepickerFormat)(column?.typeFilter ?? column?.type, column) ?? 'DD/MM/YYYY';
|
|
140
139
|
const dateRangeFormat = (0, _utils.getDatepickerFormat)(column?.type, column) ?? 'DD/MM/YYYY';
|
|
141
|
-
const find = dataSourceFilter?.find(it => it.key === column?.
|
|
140
|
+
const find = dataSourceFilter?.find(it => it.key === column?.field);
|
|
142
141
|
const options = find ? find.data : [];
|
|
142
|
+
|
|
143
|
+
// console.log('dataSourceFilter', dataSourceFilter)
|
|
144
|
+
// console.log('options', options)
|
|
145
|
+
// console.log('column', column)
|
|
146
|
+
|
|
143
147
|
switch (type) {
|
|
144
148
|
case 'Number':
|
|
145
149
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -374,7 +378,7 @@ const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, s
|
|
|
374
378
|
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Select
|
|
375
379
|
// options={translateOption(numberOperator, t)}
|
|
376
380
|
, {
|
|
377
|
-
options: options,
|
|
381
|
+
options: find ? options : column.source ?? [],
|
|
378
382
|
style: {
|
|
379
383
|
width: '100%',
|
|
380
384
|
marginBottom: 8
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ColumnTable } from "../../type";
|
|
3
|
+
type Props = {
|
|
4
|
+
t?: any;
|
|
5
|
+
content?: string;
|
|
6
|
+
column?: ColumnTable;
|
|
7
|
+
template?: React.ReactElement | React.ReactNode | (() => React.ReactElement | React.ReactNode);
|
|
8
|
+
tooltip?: string | number | React.ReactElement | React.ReactNode | (() => React.ReactElement | React.ReactNode);
|
|
9
|
+
};
|
|
10
|
+
declare const HeaderContent: (props: Props) => React.JSX.Element;
|
|
11
|
+
export default HeaderContent;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
+
var _react2 = require("@floating-ui/react");
|
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
+
var _utils = require("../utils");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
const TooltipStyle = _styledComponents.default.div.withConfig({
|
|
17
|
+
displayName: "TooltipStyle",
|
|
18
|
+
componentId: "es-grid-template__sc-ibhq66-0"
|
|
19
|
+
})(["width:max-content;background-color:#444;color:white;font-size:90%;padding:4px 8px;border-radius:4px;opacity:0.9;z-index:9999;max-width:450px;"]);
|
|
20
|
+
const HeaderContent = props => {
|
|
21
|
+
const {
|
|
22
|
+
t
|
|
23
|
+
} = props;
|
|
24
|
+
const {
|
|
25
|
+
headerTooltip,
|
|
26
|
+
headerText,
|
|
27
|
+
columnGroupText,
|
|
28
|
+
headerTemplate,
|
|
29
|
+
title
|
|
30
|
+
} = props.column ?? {};
|
|
31
|
+
const text = _react.default.useMemo(() => {
|
|
32
|
+
return columnGroupText ?? headerText ?? title;
|
|
33
|
+
}, [columnGroupText, headerText, title]);
|
|
34
|
+
const tooltip = _react.default.useMemo(() => {
|
|
35
|
+
return headerTooltip ?? columnGroupText ?? headerText ?? title;
|
|
36
|
+
}, [columnGroupText, headerText, headerTooltip, title]);
|
|
37
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
38
|
+
const {
|
|
39
|
+
refs,
|
|
40
|
+
floatingStyles,
|
|
41
|
+
context
|
|
42
|
+
} = (0, _react2.useFloating)({
|
|
43
|
+
open: isOpen,
|
|
44
|
+
onOpenChange: setIsOpen,
|
|
45
|
+
placement: "top",
|
|
46
|
+
whileElementsMounted: _react2.autoUpdate,
|
|
47
|
+
middleware: [(0, _react2.offset)(5), (0, _react2.flip)({
|
|
48
|
+
fallbackAxisSideDirection: "start"
|
|
49
|
+
}), (0, _react2.shift)()]
|
|
50
|
+
});
|
|
51
|
+
const hover = (0, _react2.useHover)(context, {
|
|
52
|
+
move: false
|
|
53
|
+
});
|
|
54
|
+
const focus = (0, _react2.useFocus)(context);
|
|
55
|
+
const dismiss = (0, _react2.useDismiss)(context);
|
|
56
|
+
const role = (0, _react2.useRole)(context, {
|
|
57
|
+
role: "tooltip"
|
|
58
|
+
});
|
|
59
|
+
const {
|
|
60
|
+
getReferenceProps,
|
|
61
|
+
getFloatingProps
|
|
62
|
+
} = (0, _react2.useInteractions)([hover, focus, dismiss, role]);
|
|
63
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
64
|
+
ref: refs.setReference
|
|
65
|
+
}, getReferenceProps(), {
|
|
66
|
+
tabIndex: -1,
|
|
67
|
+
style: {
|
|
68
|
+
flex: 1,
|
|
69
|
+
overflow: 'hidden',
|
|
70
|
+
textOverflow: 'ellipsis',
|
|
71
|
+
wordBreak: 'keep-all'
|
|
72
|
+
}
|
|
73
|
+
// style={{flex: 1}}
|
|
74
|
+
,
|
|
75
|
+
className: (0, _classnames.default)('', {})
|
|
76
|
+
}), headerTemplate ? (0, _utils.getTemplate)(headerTemplate) : t ? t(text) : text), isOpen && (headerTooltip !== false || headerTemplate || headerTooltip || columnGroupText || headerText || title) && /*#__PURE__*/_react.default.createElement(_react2.FloatingPortal, {
|
|
77
|
+
root: document.body
|
|
78
|
+
}, /*#__PURE__*/_react.default.createElement(TooltipStyle, (0, _extends2.default)({
|
|
79
|
+
className: "Tooltip",
|
|
80
|
+
ref: refs.setFloating,
|
|
81
|
+
style: {
|
|
82
|
+
...floatingStyles,
|
|
83
|
+
zIndex: 1999
|
|
84
|
+
}
|
|
85
|
+
}, getFloatingProps()), headerTooltip && typeof headerTooltip === 'function' ? headerTooltip() : t ? t(tooltip) : tooltip)));
|
|
86
|
+
};
|
|
87
|
+
var _default = exports.default = HeaderContent;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { ReactElement, ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
t?: any;
|
|
4
|
+
content?: any;
|
|
5
|
+
value?: any;
|
|
6
|
+
record?: any;
|
|
7
|
+
rowIndex?: any;
|
|
8
|
+
template?: React.ReactElement | React.ReactNode | (() => React.ReactElement | React.ReactNode);
|
|
9
|
+
tooltip?: ReactNode | ReactElement | ((value: any, record: any, index: number) => ReactNode | ReactElement);
|
|
10
|
+
showTooltip?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare const TooltipContent: (props: Props) => React.JSX.Element;
|
|
13
|
+
export default TooltipContent;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
+
var _react2 = require("@floating-ui/react");
|
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
+
var _useIsOverflow = require("../useIsOverflow");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
// import {getTemplate} from "../utils";
|
|
17
|
+
|
|
18
|
+
const TooltipStyle = _styledComponents.default.div.withConfig({
|
|
19
|
+
displayName: "TooltipStyle",
|
|
20
|
+
componentId: "es-grid-template__sc-7yfbzv-0"
|
|
21
|
+
})(["width:max-content;background-color:#444;color:white;font-size:90%;padding:4px 8px;border-radius:4px;opacity:0.9;z-index:9999;max-width:450px;"]);
|
|
22
|
+
const TooltipContent = props => {
|
|
23
|
+
const {
|
|
24
|
+
content,
|
|
25
|
+
tooltip,
|
|
26
|
+
value,
|
|
27
|
+
record,
|
|
28
|
+
rowIndex,
|
|
29
|
+
showTooltip
|
|
30
|
+
} = props;
|
|
31
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
32
|
+
const {
|
|
33
|
+
refs,
|
|
34
|
+
floatingStyles,
|
|
35
|
+
context
|
|
36
|
+
} = (0, _react2.useFloating)({
|
|
37
|
+
open: isOpen,
|
|
38
|
+
onOpenChange: setIsOpen,
|
|
39
|
+
placement: "top",
|
|
40
|
+
whileElementsMounted: _react2.autoUpdate,
|
|
41
|
+
middleware: [(0, _react2.offset)(5), (0, _react2.flip)({
|
|
42
|
+
fallbackAxisSideDirection: "start"
|
|
43
|
+
}), (0, _react2.shift)()]
|
|
44
|
+
});
|
|
45
|
+
const isOverflow = (0, _useIsOverflow.useIsOverflow)(refs.reference);
|
|
46
|
+
const hover = (0, _react2.useHover)(context, {
|
|
47
|
+
move: false
|
|
48
|
+
});
|
|
49
|
+
const focus = (0, _react2.useFocus)(context);
|
|
50
|
+
const dismiss = (0, _react2.useDismiss)(context);
|
|
51
|
+
const role = (0, _react2.useRole)(context, {
|
|
52
|
+
role: "tooltip"
|
|
53
|
+
});
|
|
54
|
+
const {
|
|
55
|
+
getReferenceProps,
|
|
56
|
+
getFloatingProps
|
|
57
|
+
} = (0, _react2.useInteractions)([hover, focus, dismiss, role]);
|
|
58
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
59
|
+
ref: refs.setReference
|
|
60
|
+
}, getReferenceProps(), {
|
|
61
|
+
style: {
|
|
62
|
+
flex: 1,
|
|
63
|
+
overflow: 'hidden',
|
|
64
|
+
textOverflow: 'ellipsis',
|
|
65
|
+
wordBreak: 'keep-all'
|
|
66
|
+
},
|
|
67
|
+
className: (0, _classnames.default)('', {})
|
|
68
|
+
}), content()), isOpen && showTooltip !== false && isOverflow &&
|
|
69
|
+
/*#__PURE__*/
|
|
70
|
+
// {true && (
|
|
71
|
+
_react.default.createElement(_react2.FloatingPortal, {
|
|
72
|
+
root: document.body
|
|
73
|
+
}, /*#__PURE__*/_react.default.createElement(TooltipStyle, (0, _extends2.default)({
|
|
74
|
+
className: "Tooltip",
|
|
75
|
+
ref: refs.setFloating,
|
|
76
|
+
style: {
|
|
77
|
+
...floatingStyles
|
|
78
|
+
}
|
|
79
|
+
}, getFloatingProps()), tooltip && typeof tooltip === 'function' ? tooltip(value, record, rowIndex) : tooltip ?? content())));
|
|
80
|
+
};
|
|
81
|
+
var _default = exports.default = TooltipContent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnyObject, IGroupSetting } from "../type";
|
|
2
|
+
export declare const SELECTION_COLUMN: {};
|
|
3
|
+
interface UseColumnsConfig {
|
|
4
|
+
t?: any;
|
|
5
|
+
buddhistLocale?: any;
|
|
6
|
+
dataSourceFilter?: any;
|
|
7
|
+
locale?: any;
|
|
8
|
+
format?: any;
|
|
9
|
+
handleResize?: any;
|
|
10
|
+
sortMultiple?: boolean;
|
|
11
|
+
groupAble?: boolean;
|
|
12
|
+
groupSetting?: IGroupSetting;
|
|
13
|
+
groupColumns?: string[];
|
|
14
|
+
}
|
|
15
|
+
declare const useColumns: <RecordType extends AnyObject = AnyObject>(config: UseColumnsConfig) => readonly [any];
|
|
16
|
+
export default useColumns;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.SELECTION_COLUMN = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var React = _react;
|
|
10
|
+
var _antd = require("antd");
|
|
11
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
var _constant = require("./constant");
|
|
14
|
+
var _columns = require("./columns");
|
|
15
|
+
var _icons = require("@ant-design/icons");
|
|
16
|
+
var _becoxyIcons = require("becoxy-icons");
|
|
17
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
18
|
+
var _HeaderContent = _interopRequireDefault(require("./content/HeaderContent"));
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
|
+
// import type {Key} from 'react';
|
|
22
|
+
|
|
23
|
+
// import Command from "../Command";
|
|
24
|
+
|
|
25
|
+
const ASCEND = 'ascend';
|
|
26
|
+
const DESCEND = 'descend';
|
|
27
|
+
const SELECTION_COLUMN = exports.SELECTION_COLUMN = {};
|
|
28
|
+
|
|
29
|
+
// const EMPTY_LIST: React.Key[] = [];
|
|
30
|
+
|
|
31
|
+
const useColumns = config => {
|
|
32
|
+
// const {
|
|
33
|
+
// preserveSelectedRowKeys,
|
|
34
|
+
// selectedRowKeys,
|
|
35
|
+
// defaultSelectedRowKeys,
|
|
36
|
+
// onSelectMultiple,
|
|
37
|
+
// columnWidth: selectionColWidth,
|
|
38
|
+
// type: selectionType,
|
|
39
|
+
// selections,
|
|
40
|
+
// fixed,
|
|
41
|
+
// } = rowSelection || {};
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
t,
|
|
45
|
+
dataSourceFilter,
|
|
46
|
+
buddhistLocale,
|
|
47
|
+
locale,
|
|
48
|
+
sortMultiple,
|
|
49
|
+
format,
|
|
50
|
+
handleResize,
|
|
51
|
+
groupAble,
|
|
52
|
+
groupColumns,
|
|
53
|
+
groupSetting
|
|
54
|
+
} = config;
|
|
55
|
+
|
|
56
|
+
// ====================== Selections ======================
|
|
57
|
+
|
|
58
|
+
const handleSearch = (selectedKeys, confirm) => {
|
|
59
|
+
confirm();
|
|
60
|
+
};
|
|
61
|
+
const getColumnSearchProps = (0, _react.useCallback)(column => ({
|
|
62
|
+
filterDropdown: ({
|
|
63
|
+
setSelectedKeys,
|
|
64
|
+
selectedKeys,
|
|
65
|
+
confirm,
|
|
66
|
+
// close,
|
|
67
|
+
setOperatorKey,
|
|
68
|
+
operatorKey,
|
|
69
|
+
visible,
|
|
70
|
+
searchValue,
|
|
71
|
+
setSearchValue
|
|
72
|
+
}) => {
|
|
73
|
+
const type = (0, _utils.getTypeFilter)(column);
|
|
74
|
+
// const operatorOptions = !type || type === 'Text' ? stringOperator : numberOperator
|
|
75
|
+
// const operatorOptions = type === 'Checkbox' || type === 'Dropdown' || type === 'DropTree' || ty
|
|
76
|
+
const operatorOptions = type === ('Checkbox' || 'Dropdown' || 'DropTree' || 'CheckboxDropdown') ? _constant.booleanOperator : !type || type === 'Text' ? _constant.stringOperator : _constant.numberOperator;
|
|
77
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
style: {
|
|
79
|
+
padding: 8,
|
|
80
|
+
minWidth: 275
|
|
81
|
+
},
|
|
82
|
+
onKeyDown: e => e.stopPropagation()
|
|
83
|
+
}, column?.showOperator !== false && column?.typeFilter !== 'DateRange' && column?.typeFilter !== 'NumberRange' && /*#__PURE__*/React.createElement("div", {
|
|
84
|
+
className: 'mb-1'
|
|
85
|
+
}, /*#__PURE__*/React.createElement(_rcMasterUi.Select, {
|
|
86
|
+
options: (0, _constant.translateOption)(operatorOptions, t),
|
|
87
|
+
style: {
|
|
88
|
+
width: '100%',
|
|
89
|
+
marginBottom: 8
|
|
90
|
+
},
|
|
91
|
+
value: operatorKey,
|
|
92
|
+
onChange: val => {
|
|
93
|
+
setOperatorKey(val);
|
|
94
|
+
}
|
|
95
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
style: {
|
|
97
|
+
marginBottom: 8
|
|
98
|
+
}
|
|
99
|
+
}, (0, _columns.renderFilter)(column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale, locale, t)), /*#__PURE__*/React.createElement(_antd.Space, {
|
|
100
|
+
style: {
|
|
101
|
+
justifyContent: 'end',
|
|
102
|
+
width: '100%'
|
|
103
|
+
}
|
|
104
|
+
}, /*#__PURE__*/React.createElement(_antd.Button, {
|
|
105
|
+
type: "primary",
|
|
106
|
+
onClick: () => {
|
|
107
|
+
confirm({
|
|
108
|
+
closeDropdown: false
|
|
109
|
+
});
|
|
110
|
+
handleSearch(selectedKeys, confirm);
|
|
111
|
+
},
|
|
112
|
+
icon: /*#__PURE__*/React.createElement(_icons.SearchOutlined, null),
|
|
113
|
+
size: "small",
|
|
114
|
+
style: {
|
|
115
|
+
width: 90
|
|
116
|
+
}
|
|
117
|
+
}, t ? t('Filter') : 'Filter'), /*#__PURE__*/React.createElement(_antd.Button, {
|
|
118
|
+
type: "link",
|
|
119
|
+
size: "small",
|
|
120
|
+
onClick: () => {
|
|
121
|
+
// setSearchValue('')
|
|
122
|
+
setSelectedKeys([]);
|
|
123
|
+
confirm();
|
|
124
|
+
// handleSearch()
|
|
125
|
+
// close()
|
|
126
|
+
}
|
|
127
|
+
}, t ? t("Clear") : 'Clear')));
|
|
128
|
+
},
|
|
129
|
+
filterIcon: filtered => /*#__PURE__*/React.createElement(_becoxyIcons.FilterFill, {
|
|
130
|
+
fontSize: 12
|
|
131
|
+
// onClick={() => {
|
|
132
|
+
// onFilterClick?.(column, onFilterCallback)
|
|
133
|
+
// }}
|
|
134
|
+
,
|
|
135
|
+
style: {
|
|
136
|
+
color: filtered ? '#E3165B' : '#283046'
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
filterDropdownProps: {
|
|
140
|
+
onOpenChange(open) {
|
|
141
|
+
if (open) {
|
|
142
|
+
// setTimeout(() => searchInput.current?.select(), 100)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}), [buddhistLocale, dataSourceFilter, locale, t]);
|
|
147
|
+
|
|
148
|
+
// ======================= Columns ========================
|
|
149
|
+
const transformColumns = (0, _react.useCallback)(columns => {
|
|
150
|
+
// >>>>>>>>>>> Support selection
|
|
151
|
+
const cloneColumns = [...columns];
|
|
152
|
+
const firstNonGroupColumn = (0, _columns.flatColumns2)(cloneColumns).find(col => col.field && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
153
|
+
const nonGroupColumns = (0, _columns.flatColumns2)(cloneColumns).filter(col => col.field && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
154
|
+
|
|
155
|
+
// ===================== Render =====================
|
|
156
|
+
|
|
157
|
+
const convertColumns = cols => {
|
|
158
|
+
return cols.map(col => {
|
|
159
|
+
const colIndex = (0, _columns.flatColumns2)(cols).findIndex(it => it.field === col.field);
|
|
160
|
+
if (col === SELECTION_COLUMN) {
|
|
161
|
+
return SELECTION_COLUMN;
|
|
162
|
+
}
|
|
163
|
+
const transformedColumn = {
|
|
164
|
+
...col,
|
|
165
|
+
dataIndex: col.field ?? col.dataIndex,
|
|
166
|
+
key: col.field ?? col.dataIndex ?? col.key,
|
|
167
|
+
// title: t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title,
|
|
168
|
+
// title: () => (<span>aaa</span>),
|
|
169
|
+
title: () => /*#__PURE__*/React.createElement(_HeaderContent.default, {
|
|
170
|
+
column: col,
|
|
171
|
+
t: t
|
|
172
|
+
}),
|
|
173
|
+
// title: () => (<span>{t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title}</span>),
|
|
174
|
+
ellipsis: col.ellipsis !== false,
|
|
175
|
+
align: col.textAlign ?? col.align,
|
|
176
|
+
fixed: col.frozen ? col.frozen.toLowerCase() : col.fixed
|
|
177
|
+
};
|
|
178
|
+
if (transformedColumn.children && transformedColumn.children?.length) {
|
|
179
|
+
return {
|
|
180
|
+
...transformedColumn,
|
|
181
|
+
children: convertColumns(transformedColumn.children)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (["index", "#"].includes(col.field)) {
|
|
185
|
+
return {
|
|
186
|
+
...transformedColumn,
|
|
187
|
+
onCell: () => ({
|
|
188
|
+
className: 'cell-number'
|
|
189
|
+
}),
|
|
190
|
+
render: (_, __, rowIndex) => rowIndex + 1
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (col.key === 'command') {
|
|
194
|
+
return {
|
|
195
|
+
...transformedColumn
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
...transformedColumn,
|
|
200
|
+
...(transformedColumn.allowFiltering === false ? {} : {
|
|
201
|
+
...getColumnSearchProps(col)
|
|
202
|
+
}),
|
|
203
|
+
sorter: col.sorter === false ? undefined : {
|
|
204
|
+
compare: a => a,
|
|
205
|
+
multiple: sortMultiple ? colIndex : undefined
|
|
206
|
+
},
|
|
207
|
+
sortIcon: args => {
|
|
208
|
+
const {
|
|
209
|
+
sortOrder
|
|
210
|
+
} = args;
|
|
211
|
+
return /*#__PURE__*/React.createElement(_react.Fragment, null, !sortOrder && /*#__PURE__*/React.createElement(_becoxyIcons.ArrowUp, {
|
|
212
|
+
fontSize: 15,
|
|
213
|
+
style: {
|
|
214
|
+
display: 'flex',
|
|
215
|
+
opacity: 0,
|
|
216
|
+
marginLeft: 4
|
|
217
|
+
},
|
|
218
|
+
className: (0, _classnames.default)(`ui-rc-table-column-sorter-up`, {
|
|
219
|
+
active: true
|
|
220
|
+
})
|
|
221
|
+
}), sortOrder === ASCEND && /*#__PURE__*/React.createElement("span", {
|
|
222
|
+
className: (0, _classnames.default)(`ui-rc-table-column-sorter-up`, {
|
|
223
|
+
active: sortOrder === ASCEND
|
|
224
|
+
}),
|
|
225
|
+
style: {
|
|
226
|
+
display: 'flex',
|
|
227
|
+
marginLeft: 4
|
|
228
|
+
}
|
|
229
|
+
}, /*#__PURE__*/React.createElement(_becoxyIcons.ArrowUp, {
|
|
230
|
+
fontSize: 15,
|
|
231
|
+
color: '#000'
|
|
232
|
+
})), sortOrder === DESCEND && /*#__PURE__*/React.createElement("span", {
|
|
233
|
+
className: (0, _classnames.default)(`ui-rc-table-column-sorter-up`, {
|
|
234
|
+
active: sortOrder === DESCEND
|
|
235
|
+
}),
|
|
236
|
+
style: {
|
|
237
|
+
display: 'flex',
|
|
238
|
+
marginLeft: 4
|
|
239
|
+
}
|
|
240
|
+
}, /*#__PURE__*/React.createElement(_becoxyIcons.ArrowDown, {
|
|
241
|
+
fontSize: 15,
|
|
242
|
+
color: '#000'
|
|
243
|
+
})));
|
|
244
|
+
},
|
|
245
|
+
onHeaderCell: () => ({
|
|
246
|
+
width: col.width,
|
|
247
|
+
onResize: handleResize?.(col)
|
|
248
|
+
}),
|
|
249
|
+
onCell: data => {
|
|
250
|
+
return {
|
|
251
|
+
colSpan: data.children && col.field === firstNonGroupColumn?.field ? 2 : data.children && nonGroupColumns[1].field === col.field ? 0 : 1,
|
|
252
|
+
zIndex: data.children && col.field === firstNonGroupColumn?.field ? 11 : undefined,
|
|
253
|
+
className: (0, _classnames.default)('', {
|
|
254
|
+
'cell-group': data.children,
|
|
255
|
+
'cell-group-fixed': data.children && col.field === firstNonGroupColumn?.field
|
|
256
|
+
})
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
render: (value, record, rowIndex) => {
|
|
260
|
+
if (groupSetting && groupSetting.hiddenColumnGroup === false) {
|
|
261
|
+
if (record.children) {
|
|
262
|
+
return (0, _columns.renderContent)(col, value, record, rowIndex, format);
|
|
263
|
+
}
|
|
264
|
+
if (groupColumns?.includes(col.field)) {
|
|
265
|
+
return '';
|
|
266
|
+
}
|
|
267
|
+
return (0, _columns.renderContent)(col, value, record, rowIndex, format);
|
|
268
|
+
}
|
|
269
|
+
if (col.field === firstNonGroupColumn?.field && record.children) {
|
|
270
|
+
const currentGroupColumn = (0, _columns.flatColumns2)(cols).find(it => it.field === record.field);
|
|
271
|
+
return /*#__PURE__*/React.createElement("span", null, currentGroupColumn?.headerText, ": ", (0, _columns.renderContent)(currentGroupColumn, record[record.field], record, rowIndex, format));
|
|
272
|
+
}
|
|
273
|
+
return (0, _columns.renderContent)(col, value, record, rowIndex, format);
|
|
274
|
+
},
|
|
275
|
+
hidden: groupSetting && groupSetting.hiddenColumnGroup === false ? col.hidden : groupAble && groupColumns && groupColumns.includes(col.field) ? true : col.hidden
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
return convertColumns(cloneColumns);
|
|
280
|
+
}, [format, getColumnSearchProps, groupAble, groupColumns, groupSetting, handleResize, sortMultiple, t]);
|
|
281
|
+
return [transformColumns];
|
|
282
|
+
};
|
|
283
|
+
var _default = exports.default = useColumns;
|
|
@@ -4,7 +4,8 @@ import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
|
|
|
4
4
|
import type { ColumnEditType, ColumnsType, ColumnTable, GetRowKey } from "../type";
|
|
5
5
|
import type { SelectionSettings } from "../type";
|
|
6
6
|
import type { AnyObject } from "../type";
|
|
7
|
-
import { Key } from "react";
|
|
7
|
+
import type { Key } from "react";
|
|
8
|
+
import type { ColumnsTable } from "../type";
|
|
8
9
|
export declare const newGuid: () => any;
|
|
9
10
|
export declare const sumDataByField: (data: any[], field: string) => any;
|
|
10
11
|
export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
@@ -19,6 +20,7 @@ export declare const getAllVisibleKeys: (columns: any[]) => any[];
|
|
|
19
20
|
export declare const getVisibleColumnKeys: (columns: any[]) => string[];
|
|
20
21
|
export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
|
|
21
22
|
export declare const updateColumns: (columns: any[], includes: string[]) => any[];
|
|
23
|
+
export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
|
|
22
24
|
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, col: ColumnTable<any>) => string;
|
|
23
25
|
export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
|
|
24
26
|
export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
|
|
@@ -37,3 +39,50 @@ export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], ro
|
|
|
37
39
|
export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
|
|
38
40
|
export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
|
|
39
41
|
export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
|
|
42
|
+
export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
|
|
43
|
+
export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: string, data?: RecordType[]) => RecordType[];
|
|
44
|
+
export declare const countItemsBeforeIndex: (array: any[], index: number) => number;
|
|
45
|
+
export declare const getRowNumber: (array: any[], rowKey: any, key: any) => number;
|
|
46
|
+
export declare const getDefaultValue: (defaultValue: any) => AnyObject;
|
|
47
|
+
export declare const addRowIdArray: (inputArray: any[]) => any[];
|
|
48
|
+
export declare const findItemByKey: (array: any, key: string | number, value: any) => any;
|
|
49
|
+
export declare const getLastSelectCell: (selectCells: any) => {
|
|
50
|
+
row: number;
|
|
51
|
+
col: number;
|
|
52
|
+
};
|
|
53
|
+
export declare const getFirstSelectCell: (selectCells: any) => {
|
|
54
|
+
row: number;
|
|
55
|
+
col: number;
|
|
56
|
+
};
|
|
57
|
+
export declare const getRowsPasteIndex: (pasteRows: any) => number[];
|
|
58
|
+
export declare const mmm: (string | number | boolean)[][];
|
|
59
|
+
export declare function cloneRows(array: any[], numRows: number): any[];
|
|
60
|
+
export declare function addRows1(arr: any[], n: number): any[];
|
|
61
|
+
export declare function addRows2(arr: any[], n: number): {
|
|
62
|
+
newArr: any[];
|
|
63
|
+
addedRows: any[];
|
|
64
|
+
};
|
|
65
|
+
export declare function addRows(arr: any[], n: number): {
|
|
66
|
+
newArr: any[];
|
|
67
|
+
addedRows: any[];
|
|
68
|
+
};
|
|
69
|
+
export declare function addRows4(arr: any[], n: number): {
|
|
70
|
+
newArr: any[];
|
|
71
|
+
addedRows: any[];
|
|
72
|
+
};
|
|
73
|
+
export declare function addRows6(arr: any, n: number): {
|
|
74
|
+
newArr: any[];
|
|
75
|
+
addedRows: any[];
|
|
76
|
+
};
|
|
77
|
+
export declare function addRows7(arr: any, n: number): any;
|
|
78
|
+
export declare function addRows8(arr: any, n: number): {
|
|
79
|
+
combined: any;
|
|
80
|
+
addedRows: any[];
|
|
81
|
+
} | {
|
|
82
|
+
combined: any[];
|
|
83
|
+
addedRows: any[];
|
|
84
|
+
};
|
|
85
|
+
export declare const transformColumns: <RecordType>(cols: ColumnsTable<RecordType>, convertColumns: any[], t?: any) => ColumnsTable<RecordType>;
|
|
86
|
+
export declare const transformColumns1: <RecordType>(cols: ColumnsTable<RecordType>, sortMultiple?: boolean) => ColumnsTable<RecordType>;
|
|
87
|
+
export declare const removeColumns: <RecordType>(columns: ColumnsTable, groupColumns: string[]) => ColumnsTable<RecordType>;
|
|
88
|
+
export declare const convertFlatColumn: (array: ColumnsTable) => ColumnsTable[];
|