amis-rpc-design/node_modules/rc-table/lib/VirtualTable/index.js

88 lines
4.0 KiB
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.genVirtualTable = genVirtualTable;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _classnames = _interopRequireDefault(require("classnames"));
var _rcUtil = require("rc-util");
var React = _interopRequireWildcard(require("react"));
var _constant = require("../constant");
var _TableContext = require("../context/TableContext");
var _Table = _interopRequireWildcard(require("../Table"));
var _BodyGrid = _interopRequireDefault(require("./BodyGrid"));
var _context = require("./context");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var renderBody = function renderBody(rawData, props) {
var ref = props.ref,
onScroll = props.onScroll;
return /*#__PURE__*/React.createElement(_BodyGrid.default, {
ref: ref,
data: rawData,
onScroll: onScroll
});
};
function VirtualTable(props) {
var columns = props.columns,
scroll = props.scroll,
sticky = props.sticky,
_props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? _Table.DEFAULT_PREFIX : _props$prefixCls,
className = props.className,
listItemHeight = props.listItemHeight;
var _ref = scroll || {},
scrollX = _ref.x,
scrollY = _ref.y;
// Fill scrollX
if (typeof scrollX !== 'number') {
if (process.env.NODE_ENV !== 'production') {
(0, _rcUtil.warning)(!scrollX, '`scroll.x` in virtual table must be number.');
}
scrollX = 1;
}
// Fill scrollY
if (typeof scrollY !== 'number') {
scrollY = 500;
if (process.env.NODE_ENV !== 'production') {
(0, _rcUtil.warning)(false, '`scroll.y` in virtual table must be number.');
}
}
// ========================= Context ==========================
var context = React.useMemo(function () {
return {
sticky: sticky,
scrollY: scrollY,
listItemHeight: listItemHeight
};
}, [sticky, scrollY, listItemHeight]);
// ========================== Render ==========================
return /*#__PURE__*/React.createElement(_context.StaticContext.Provider, {
value: context
}, /*#__PURE__*/React.createElement(_Table.default, (0, _extends2.default)({}, props, {
className: (0, _classnames.default)(className, "".concat(prefixCls, "-virtual")),
scroll: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, scroll), {}, {
x: scrollX
}),
components: {
body: renderBody
},
columns: columns,
internalHooks: _constant.INTERNAL_HOOKS,
tailor: true
})));
}
function genVirtualTable(shouldTriggerRender) {
return (0, _TableContext.makeImmutable)(VirtualTable, shouldTriggerRender);
}
var _default = genVirtualTable();
exports.default = _default;