1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof3 = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10 | var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
11 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
12 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13 | var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
14 | var _context = require("@rc-component/context");
|
15 | var _classnames = _interopRequireDefault(require("classnames"));
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 | var _TableContext = _interopRequireDefault(require("../context/TableContext"));
|
18 | var _useRenderTimes = _interopRequireDefault(require("../hooks/useRenderTimes"));
|
19 | var _useCellRender3 = _interopRequireDefault(require("./useCellRender"));
|
20 | var _useHoverState3 = _interopRequireDefault(require("./useHoverState"));
|
21 | var _rcUtil = require("rc-util");
|
22 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
23 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(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; }
|
24 | var getTitleFromCellRenderChildren = function getTitleFromCellRenderChildren(_ref) {
|
25 | var ellipsis = _ref.ellipsis,
|
26 | rowType = _ref.rowType,
|
27 | children = _ref.children;
|
28 | var title;
|
29 | var ellipsisConfig = ellipsis === true || ellipsis === undefined ? {
|
30 | showTitle: true
|
31 | } : ellipsis;
|
32 | if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) {
|
33 | if (typeof children === 'string' || typeof children === 'number') {
|
34 | title = children.toString();
|
35 | } else if ( React.isValidElement(children) && typeof children.props.children === 'string') {
|
36 | title = children.props.children;
|
37 | }
|
38 | }
|
39 | return title;
|
40 | };
|
41 | function Cell(props) {
|
42 | var _ref2, _ref3, _legacyCellProps$colS, _ref4, _ref5, _legacyCellProps$rowS, _additionalProps$titl, _classNames;
|
43 | if (process.env.NODE_ENV !== 'production') {
|
44 | (0, _useRenderTimes.default)(props);
|
45 | }
|
46 | var Component = props.component,
|
47 | children = props.children,
|
48 | ellipsis = props.ellipsis,
|
49 | scope = props.scope,
|
50 | prefixCls = props.prefixCls,
|
51 | className = props.className,
|
52 | align = props.align,
|
53 | record = props.record,
|
54 | render = props.render,
|
55 | dataIndex = props.dataIndex,
|
56 | renderIndex = props.renderIndex,
|
57 | shouldCellUpdate = props.shouldCellUpdate,
|
58 | index = props.index,
|
59 | rowType = props.rowType,
|
60 | colSpan = props.colSpan,
|
61 | rowSpan = props.rowSpan,
|
62 | fixLeft = props.fixLeft,
|
63 | fixRight = props.fixRight,
|
64 | firstFixLeft = props.firstFixLeft,
|
65 | lastFixLeft = props.lastFixLeft,
|
66 | firstFixRight = props.firstFixRight,
|
67 | lastFixRight = props.lastFixRight,
|
68 | appendNode = props.appendNode,
|
69 | _props$additionalProp = props.additionalProps,
|
70 | additionalProps = _props$additionalProp === void 0 ? {} : _props$additionalProp,
|
71 | isSticky = props.isSticky;
|
72 | var cellPrefixCls = "".concat(prefixCls, "-cell");
|
73 | var _useContext = (0, _context.useContext)(_TableContext.default, ['supportSticky', 'allColumnsFixedLeft', 'rowHoverable']),
|
74 | supportSticky = _useContext.supportSticky,
|
75 | allColumnsFixedLeft = _useContext.allColumnsFixedLeft,
|
76 | rowHoverable = _useContext.rowHoverable;
|
77 |
|
78 |
|
79 | var _useCellRender = (0, _useCellRender3.default)(record, dataIndex, renderIndex, children, render, shouldCellUpdate),
|
80 | _useCellRender2 = (0, _slicedToArray2.default)(_useCellRender, 2),
|
81 | childNode = _useCellRender2[0],
|
82 | legacyCellProps = _useCellRender2[1];
|
83 |
|
84 |
|
85 | var fixedStyle = {};
|
86 | var isFixLeft = typeof fixLeft === 'number' && supportSticky;
|
87 | var isFixRight = typeof fixRight === 'number' && supportSticky;
|
88 | if (isFixLeft) {
|
89 | fixedStyle.position = 'sticky';
|
90 | fixedStyle.left = fixLeft;
|
91 | }
|
92 | if (isFixRight) {
|
93 | fixedStyle.position = 'sticky';
|
94 | fixedStyle.right = fixRight;
|
95 | }
|
96 |
|
97 |
|
98 | var mergedColSpan = (_ref2 = (_ref3 = (_legacyCellProps$colS = legacyCellProps === null || legacyCellProps === void 0 ? void 0 : legacyCellProps.colSpan) !== null && _legacyCellProps$colS !== void 0 ? _legacyCellProps$colS : additionalProps.colSpan) !== null && _ref3 !== void 0 ? _ref3 : colSpan) !== null && _ref2 !== void 0 ? _ref2 : 1;
|
99 | var mergedRowSpan = (_ref4 = (_ref5 = (_legacyCellProps$rowS = legacyCellProps === null || legacyCellProps === void 0 ? void 0 : legacyCellProps.rowSpan) !== null && _legacyCellProps$rowS !== void 0 ? _legacyCellProps$rowS : additionalProps.rowSpan) !== null && _ref5 !== void 0 ? _ref5 : rowSpan) !== null && _ref4 !== void 0 ? _ref4 : 1;
|
100 |
|
101 |
|
102 | var _useHoverState = (0, _useHoverState3.default)(index, mergedRowSpan),
|
103 | _useHoverState2 = (0, _slicedToArray2.default)(_useHoverState, 2),
|
104 | hovering = _useHoverState2[0],
|
105 | onHover = _useHoverState2[1];
|
106 | var onMouseEnter = (0, _rcUtil.useEvent)(function (event) {
|
107 | var _additionalProps$onMo;
|
108 | if (record) {
|
109 | onHover(index, index + mergedRowSpan - 1);
|
110 | }
|
111 | additionalProps === null || additionalProps === void 0 || (_additionalProps$onMo = additionalProps.onMouseEnter) === null || _additionalProps$onMo === void 0 || _additionalProps$onMo.call(additionalProps, event);
|
112 | });
|
113 | var onMouseLeave = (0, _rcUtil.useEvent)(function (event) {
|
114 | var _additionalProps$onMo2;
|
115 | if (record) {
|
116 | onHover(-1, -1);
|
117 | }
|
118 | additionalProps === null || additionalProps === void 0 || (_additionalProps$onMo2 = additionalProps.onMouseLeave) === null || _additionalProps$onMo2 === void 0 || _additionalProps$onMo2.call(additionalProps, event);
|
119 | });
|
120 |
|
121 |
|
122 | if (mergedColSpan === 0 || mergedRowSpan === 0) {
|
123 | return null;
|
124 | }
|
125 |
|
126 |
|
127 | var title = (_additionalProps$titl = additionalProps.title) !== null && _additionalProps$titl !== void 0 ? _additionalProps$titl : getTitleFromCellRenderChildren({
|
128 | rowType: rowType,
|
129 | ellipsis: ellipsis,
|
130 | children: childNode
|
131 | });
|
132 |
|
133 |
|
134 | var mergedClassName = (0, _classnames.default)(cellPrefixCls, className, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-left"), isFixLeft && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-left-first"), firstFixLeft && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-left-last"), lastFixLeft && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-left-all"), lastFixLeft && allColumnsFixedLeft && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-right"), isFixRight && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-right-first"), firstFixRight && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-right-last"), lastFixRight && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-ellipsis"), ellipsis), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-with-append"), appendNode), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-fix-sticky"), (isFixLeft || isFixRight) && isSticky && supportSticky), (0, _defineProperty2.default)(_classNames, "".concat(cellPrefixCls, "-row-hover"), !legacyCellProps && hovering), _classNames), additionalProps.className, legacyCellProps === null || legacyCellProps === void 0 ? void 0 : legacyCellProps.className);
|
135 |
|
136 |
|
137 | var alignStyle = {};
|
138 | if (align) {
|
139 | alignStyle.textAlign = align;
|
140 | }
|
141 | var mergedStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fixedStyle), additionalProps.style), alignStyle), legacyCellProps === null || legacyCellProps === void 0 ? void 0 : legacyCellProps.style);
|
142 |
|
143 |
|
144 | var mergedChildNode = childNode;
|
145 |
|
146 |
|
147 | if ((0, _typeof2.default)(mergedChildNode) === 'object' && !Array.isArray(mergedChildNode) && ! React.isValidElement(mergedChildNode)) {
|
148 | mergedChildNode = null;
|
149 | }
|
150 | if (ellipsis && (lastFixLeft || firstFixRight)) {
|
151 | mergedChildNode = React.createElement("span", {
|
152 | className: "".concat(cellPrefixCls, "-content")
|
153 | }, mergedChildNode);
|
154 | }
|
155 | return React.createElement(Component, (0, _extends2.default)({}, legacyCellProps, additionalProps, {
|
156 | className: mergedClassName,
|
157 | style: mergedStyle
|
158 |
|
159 | ,
|
160 | title: title,
|
161 | scope: scope
|
162 |
|
163 | ,
|
164 | onMouseEnter: rowHoverable ? onMouseEnter : undefined,
|
165 | onMouseLeave: rowHoverable ? onMouseLeave : undefined
|
166 |
|
167 | ,
|
168 | colSpan: mergedColSpan !== 1 ? mergedColSpan : null,
|
169 | rowSpan: mergedRowSpan !== 1 ? mergedRowSpan : null
|
170 | }), appendNode, mergedChildNode);
|
171 | }
|
172 | var _default = exports.default = React.memo(Cell); |
\ | No newline at end of file |