UNPKG

tav-ui

Version:
90 lines (87 loc) 3.06 kB
import { unref } from 'vue'; import { $Tooltip } from '../../../../hooks/web/useTooltip2.mjs'; import { isBoolean } from '../../../../utils/is2.mjs'; import { ContentPrefixCls } from '../components/cell2.mjs'; import { TOOLTIP_PLACEMENT } from '../const2.mjs'; function showCellTooltip(instances, tablePropsRef, params) { const { cell, column, _rowIndex, _columnIndex, rowid } = params; const { params: columnParams = {} } = column; const { showTooltip: columnShowTooltip } = columnParams; const { showTooltip, id: tableId } = unref(tablePropsRef); const isColumnShowTooltip = isBoolean(columnShowTooltip) ? columnShowTooltip : showTooltip; if (isColumnShowTooltip) { const id = `${tableId}:row_${_rowIndex}-${_columnIndex}-${rowid}`; const el = cell.querySelector(`.${ContentPrefixCls}`); let title = ""; let isCellOverflow = false; if (el) { title = ((column.type === "html" ? el.innerText : el.textContent) ?? "").trim(); isCellOverflow = el.scrollWidth > el.clientWidth; } const instance = $Tooltip(el, { placement: TOOLTIP_PLACEMENT, title, id, delay: 100 }); instances.set(id, instance); isCellOverflow && instance?.showTooltip(el); } } function hideCellTooltip(instances, tablePropsRef, params) { const { column, _rowIndex, _columnIndex, rowid } = params; const { params: columnParams = {} } = column; const { showTooltip: columnShowTooltip } = columnParams; const { showTooltip, id: tableId } = unref(tablePropsRef); const isColumnShowTooltip = isBoolean(columnShowTooltip) ? columnShowTooltip : showTooltip; if (isColumnShowTooltip) { const id = `${tableId}:row_${_rowIndex}-${_columnIndex}-${rowid}`; const instance = instances.get(id); instance?.hideTooltip(); } } function hideCellAllTooltip(instances) { if (instances.size > 0) { instances.forEach((instance) => { instance?.hideTooltip(); }); } } function deleteTitle(cellEl) { const targetCls = ["vxe-header--column", "vxe-body--column", "vxe-footer--column"]; const cotainsNum = targetCls.reduce((total, cur) => { if (cellEl.classList.contains(cur)) { total += 1; } return total; }, 0); const isColumnTdEL = cotainsNum > 0; if (isColumnTdEL) { cellEl.removeAttribute("title"); cellEl.querySelector(".vxe-cell").removeAttribute("title"); } } function useCellHover(tablePropsRef, emit) { const instances = /* @__PURE__ */ new Map(); const onCellMouseenter = (params) => { if (!params || ["action", "actions"].includes(params.column.field)) return; showCellTooltip(instances, tablePropsRef, params); emit("CellMouseenter", params); }; const onCellMouseleave = (params) => { if (!params) { hideCellAllTooltip(instances); } else { hideCellTooltip(instances, tablePropsRef, params); emit("CellMouseleave", params); } }; return { onCellMouseenter, onCellMouseleave, instances }; } export { useCellHover }; //# sourceMappingURL=useCellHover2.mjs.map