UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

290 lines (286 loc) 13.3 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { _ as _typeof } from '../_chunks/dep-82805301.mjs'; import { _ as _defineProperty } from '../_chunks/dep-f9e836af.mjs'; import { isVNode, defineComponent, ref, computed, h, createVNode, mergeProps } from 'vue'; import { i as isFunction_1 } from '../_chunks/dep-1cc1c24f.mjs'; import { getColumnFixedStyles } from './hooks/useFixed.mjs'; import useClassName from './hooks/useClassName.mjs'; import { renderTitle } from './hooks/useTableHeader.mjs'; import TEllipsis from './ellipsis.mjs'; import { formatClassNames } from './utils.mjs'; import '../_chunks/dep-10a947a6.mjs'; import '../_chunks/dep-b75d8d74.mjs'; import '../_chunks/dep-6ad18815.mjs'; import '../_chunks/dep-32d4c595.mjs'; import '../_chunks/dep-89b966f4.mjs'; import '../_chunks/dep-7fa157cd.mjs'; import '../_chunks/dep-fa6608fd.mjs'; import '../_chunks/dep-a95026f2.mjs'; import '../_chunks/dep-068e912d.mjs'; import '../_chunks/dep-7dcfa37a.mjs'; import '../_chunks/dep-addc2a84.mjs'; import '../_chunks/dep-6aa0223b.mjs'; import '../_chunks/dep-db381ece.mjs'; import '../_chunks/dep-5755c21c.mjs'; import '../_chunks/dep-7f239c43.mjs'; import '../_chunks/dep-4903a8a8.mjs'; import '../_chunks/dep-0c786bea.mjs'; import '../_chunks/dep-e727a519.mjs'; import '../_chunks/dep-03412fab.mjs'; import '../_chunks/dep-26bf361a.mjs'; import '../_chunks/dep-0e832fc7.mjs'; import '../_chunks/dep-e1ab85c5.mjs'; import '../_chunks/dep-3ec3335a.mjs'; import '../_chunks/dep-d32fbbb3.mjs'; import '../_chunks/dep-29f616db.mjs'; import '../_chunks/dep-4265f69a.mjs'; import '../_chunks/dep-5f0e0453.mjs'; import '../_chunks/dep-983ce253.mjs'; import '../_chunks/dep-205ff58d.mjs'; import '../_chunks/dep-dafada74.mjs'; import '../_chunks/dep-8d1c9a23.mjs'; import '../_chunks/dep-395d33c9.mjs'; import '../_chunks/dep-e901316d.mjs'; import '../_common/js/log/index.mjs'; import '../_common/js/log/log.mjs'; import '../_common/js/utils/getScrollbarWidth.mjs'; import '../_common/js/utils/helper.mjs'; import '../_chunks/dep-5bec687c.mjs'; import '../_chunks/dep-53e379cd.mjs'; import '../_chunks/dep-11fa9c2c.mjs'; import '../_chunks/dep-5a2ce53e.mjs'; import '../_chunks/dep-1bae6a97.mjs'; import '../_chunks/dep-23f91684.mjs'; import '../utils/dom.mjs'; import '../utils/easing.mjs'; import '../hooks/useConfig.mjs'; import '../config-provider/useConfig.mjs'; import '../_chunks/dep-91ac8f71.mjs'; import '../_chunks/dep-c4737535.mjs'; import '../_chunks/dep-81c83986.mjs'; import '../_chunks/dep-6f04869e.mjs'; import '../_chunks/dep-6e7b37b8.mjs'; import '../_chunks/dep-71f84cf2.mjs'; import '../_chunks/dep-69963a8c.mjs'; import '../_chunks/dep-b09f48fa.mjs'; import '../_chunks/dep-ed4e7c50.mjs'; import '../_chunks/dep-a666b9ad.mjs'; import '../_common/js/global-config/default-config.mjs'; import '../_common/js/global-config/locale/en_US.mjs'; import '../config-provider/type.mjs'; import './hooks/useMultiHeader.mjs'; import '../utils/render-tnode.mjs'; import '../_chunks/dep-9d7ebc32.mjs'; import '../_chunks/dep-a628549d.mjs'; import '../_chunks/dep-f4eba04c.mjs'; import '../_chunks/dep-735bcd0d.mjs'; import '../_chunks/dep-765678ef.mjs'; import '../_chunks/dep-8db27830.mjs'; import '../_chunks/dep-ae4bffa5.mjs'; import '../tooltip/index.mjs'; import '../tooltip/tooltip.mjs'; import '../_chunks/dep-60f1d7ee.mjs'; import '../_chunks/dep-b57a2815.mjs'; import '../tooltip/props.mjs'; import '../popup/props.mjs'; import '../popup/index.mjs'; import '../popup/popup.mjs'; import '@popperjs/core'; import '../hooks/index.mjs'; import '../hooks/icon.mjs'; import '../hooks/slot.mjs'; import '../hooks/tnode.mjs'; import '../hooks/useCommonClassName.mjs'; import '../hooks/useDefaultValue.mjs'; import '../hooks/useDestroyOnClose.mjs'; import '../hooks/useKeepAnimation.mjs'; import '../hooks/useRipple.mjs'; import '../utils/set-style.mjs'; import '../hooks/useVirtualScroll.mjs'; import '../hooks/useVModel.mjs'; import '../hooks/useImagePreviewUrl.mjs'; import '../_common/js/upload/utils.mjs'; import '../_common/js/utils/set-style.mjs'; import '../popup/container.mjs'; import '../hooks/useResizeObserver.mjs'; import '../utils/withInstall.mjs'; import './style/css.mjs'; import '../popup/type.mjs'; import '../tooltip/util.mjs'; import '../tooltip/type.mjs'; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _isSlot(s) { return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s); } var THead = defineComponent({ name: "XHead", props: { classPrefix: String, ellipsisOverlayClassName: String, isFixedHeader: Boolean, thDraggable: Boolean, maxHeight: [String, Number], height: [String, Number], rowAndColFixedPosition: Map, thWidthList: Object, bordered: Boolean, isMultipleHeader: Boolean, resizable: Boolean, attach: [String, Function], spansAndLeafNodes: Object, thList: Array, columnResizeParams: Object, showColumnShadow: Object }, setup: function setup(props, _ref) { var slots = _ref.slots; var theadRef = ref(); var classnames = useClassName(); var tableHeaderClasses = classnames.tableHeaderClasses, tableBaseClass = classnames.tableBaseClass; var theadClasses = computed(function () { var _ref2; return [tableHeaderClasses.header, (_ref2 = {}, _defineProperty(_ref2, tableHeaderClasses.fixed, Boolean(props.maxHeight || props.height)), _defineProperty(_ref2, tableBaseClass.bordered, props.bordered && props.isMultipleHeader), _defineProperty(_ref2, tableHeaderClasses.multipleHeader, props.isMultipleHeader), _ref2)]; }); var colspanSkipMap = computed(function () { var map = {}; var list = props.thList[0]; for (var i = 0, len = list.length; i < len; i++) { var item = list[i]; if (item.colspan > 1) { for (var j = i + 1; j < i + item.colspan; j++) { if (list[j]) { map[list[j].colKey] = true; } } } } return map; }); var getTableNode = function getTableNode(thead) { var parent = thead; while (parent) { var _parent; parent = parent.parentNode; if ((_parent = parent) !== null && _parent !== void 0 && (_parent = _parent.classList) !== null && _parent !== void 0 && _parent.contains("".concat(props.classPrefix, "-table"))) { break; } } return parent; }; return _objectSpread(_objectSpread({}, classnames), {}, { colspanSkipMap: colspanSkipMap, theadClasses: theadClasses, theadRef: theadRef, slots: slots, getTableNode: getTableNode }); }, render: function render() { var _this = this; var renderThNodeList = function renderThNodeList(rowAndColFixedPosition, thWidthList) { var thBorderMap = /* @__PURE__ */new Map(); var thRowspanAndColspan = _this.spansAndLeafNodes.rowspanAndColspanMap; return _this.thList.map(function (row, rowIndex) { var thRow = row.map(function (col, index) { var _ref3, _col$children; if (_this.colspanSkipMap[col.colKey]) return null; var rowspanAndColspan = thRowspanAndColspan.get(col); if (index === 0 && rowspanAndColspan.rowspan > 1) { for (var j = rowIndex + 1; j < rowIndex + rowspanAndColspan.rowspan; j++) { thBorderMap.set(_this.thList[j][0], true); } } var thStyles = getColumnFixedStyles(col, index, rowAndColFixedPosition, _this.tableColFixedClasses); var colParams = { col: col, colIndex: index, row: {}, rowIndex: -1 }; var customClasses = formatClassNames(col.className, _objectSpread(_objectSpread({}, colParams), {}, { type: "th" })); var isLeftFixedActive = _this.showColumnShadow.left && col.fixed === "left"; var isRightFixedActive = _this.showColumnShadow.right && col.fixed === "right"; var canDragSort = _this.thDraggable && !(isLeftFixedActive || isRightFixedActive); var thClasses = [thStyles.classes, customClasses, (_ref3 = {}, _defineProperty(_ref3, _this.tableHeaderClasses.thBordered, thBorderMap.get(col)), _defineProperty(_ref3, "".concat(_this.classPrefix, "-table__th-").concat(col.colKey), col.colKey), _defineProperty(_ref3, _this.tdAlignClasses[col.align], col.align && col.align !== "left"), _defineProperty(_ref3, _this.tableDraggableClasses.dragSortTh, canDragSort), _ref3)]; var withoutChildren = !((_col$children = col.children) !== null && _col$children !== void 0 && _col$children.length); var width = withoutChildren && thWidthList !== null && thWidthList !== void 0 && thWidthList[col.colKey] ? "".concat(thWidthList === null || thWidthList === void 0 ? void 0 : thWidthList[col.colKey], "px") : void 0; var styles = _objectSpread(_objectSpread({}, thStyles.style || {}), {}, { width: width }); var innerTh = renderTitle(_this.slots, col, index); var resizeColumnListener = _this.resizable || !canDragSort ? { onMousedown: function onMousedown(e) { if (_this.resizable) { var _this$columnResizePar, _this$columnResizePar2; (_this$columnResizePar = _this.columnResizeParams) === null || _this$columnResizePar === void 0 || (_this$columnResizePar2 = _this$columnResizePar.onColumnMousedown) === null || _this$columnResizePar2 === void 0 ? void 0 : _this$columnResizePar2.call(_this$columnResizePar, e, col, index); } if (!canDragSort) { var timer = setTimeout(function () { var _thList$index; var thList = _this.theadRef.querySelectorAll("th"); (_thList$index = thList[index]) === null || _thList$index === void 0 ? void 0 : _thList$index.removeAttribute("draggable"); clearTimeout(timer); }, 10); } }, onMousemove: function onMousemove(e) { var _this$columnResizePar3, _this$columnResizePar4; _this.resizable && ((_this$columnResizePar3 = _this.columnResizeParams) === null || _this$columnResizePar3 === void 0 || (_this$columnResizePar4 = _this$columnResizePar3.onColumnMouseover) === null || _this$columnResizePar4 === void 0 ? void 0 : _this$columnResizePar4.call(_this$columnResizePar3, e, col)); } } : {}; var content = isFunction_1(col.ellipsisTitle) ? col.ellipsisTitle(h, { col: col, colIndex: index }) : void 0; var isEllipsis = col.ellipsisTitle !== void 0 ? Boolean(col.ellipsisTitle) : Boolean(col.ellipsis); var attrs = (isFunction_1(col.attrs) ? col.attrs(_objectSpread(_objectSpread({}, colParams), {}, { type: "th" })) : col.attrs) || {}; if (col.colspan > 1) { attrs.colspan = col.colspan; } return createVNode("th", mergeProps({ "key": col.colKey, "data-colkey": col.colKey, "class": thClasses, "style": styles }, attrs, rowspanAndColspan, resizeColumnListener), [createVNode("div", { "class": _this.tableBaseClass.thCellInner }, [isEllipsis ? createVNode(TEllipsis, { "placement": "bottom", "attach": _this.attach || (_this.theadRef ? function () { return _this.getTableNode(_this.theadRef); } : void 0), "tooltipContent": content && function () { return content; }, "tooltipProps": _typeof(col.ellipsisTitle) === "object" ? col.ellipsisTitle : void 0, "overlayClassName": _this.ellipsisOverlayClassName, "classPrefix": _this.classPrefix }, _isSlot(innerTh) ? innerTh : { "default": function _default() { return [innerTh]; } }) : innerTh])]); }); return createVNode("tr", { "key": rowIndex }, [thRow]); }); }; return createVNode("thead", { "ref": "theadRef", "class": this.theadClasses }, [renderThNodeList(this.rowAndColFixedPosition, this.thWidthList)]); } }); export { THead as default }; //# sourceMappingURL=thead.mjs.map