{"version":3,"file":"events-helper.js","sources":["../../../../../../../packages/components/table/src/table-body/events-helper.ts"],"sourcesContent":["// @ts-nocheck\nimport { h, inject, ref } from 'vue'\nimport { debounce } from 'lodash-unified'\nimport { addClass, hasClass, removeClass } from '@element-plus/utils'\nimport { createTablePopper, getCell, getColumnByCell } from '../util'\nimport { TABLE_INJECTION_KEY } from '../tokens'\nimport type { TableColumnCtx } from '../table-column/defaults'\nimport type { TableBodyProps } from './defaults'\nimport type { TableOverflowTooltipOptions } from '../util'\n\nfunction isGreaterThan(a: number, b: number, epsilon = 0.03) {\n return a - b > epsilon\n}\n\nfunction useEvents(props: Partial>) {\n const parent = inject(TABLE_INJECTION_KEY)\n const tooltipContent = ref('')\n const tooltipTrigger = ref(h('div'))\n const handleEvent = (event: Event, row: T, name: string) => {\n const table = parent\n const cell = getCell(event)\n let column: TableColumnCtx\n const namespace = table?.vnode.el?.dataset.prefix\n if (cell) {\n column = getColumnByCell(\n {\n columns: props.store.states.columns.value,\n },\n cell,\n namespace\n )\n if (column) {\n table?.emit(`cell-${name}`, row, column, cell, event)\n }\n }\n table?.emit(`row-${name}`, row, column, event)\n }\n const handleDoubleClick = (event: Event, row: T) => {\n handleEvent(event, row, 'dblclick')\n }\n const handleClick = (event: Event, row: T) => {\n props.store.commit('setCurrentRow', row)\n handleEvent(event, row, 'click')\n }\n const handleContextMenu = (event: Event, row: T) => {\n handleEvent(event, row, 'contextmenu')\n }\n const handleMouseEnter = debounce((index: number) => {\n props.store.commit('setHoverRow', index)\n }, 30)\n const handleMouseLeave = debounce(() => {\n props.store.commit('setHoverRow', null)\n }, 30)\n const getPadding = (el: HTMLElement) => {\n const style = window.getComputedStyle(el, null)\n const paddingLeft = Number.parseInt(style.paddingLeft, 10) || 0\n const paddingRight = Number.parseInt(style.paddingRight, 10) || 0\n const paddingTop = Number.parseInt(style.paddingTop, 10) || 0\n const paddingBottom = Number.parseInt(style.paddingBottom, 10) || 0\n return {\n left: paddingLeft,\n right: paddingRight,\n top: paddingTop,\n bottom: paddingBottom,\n }\n }\n\n const toggleRowClassByCell = (\n rowSpan: number,\n event: MouseEvent,\n toggle: (el: Element, cls: string) => void\n ) => {\n let node = event.target.parentNode\n while (rowSpan > 1) {\n node = node?.nextSibling\n if (!node || node.nodeName !== 'TR') break\n toggle(node, 'hover-row hover-fixed-row')\n rowSpan--\n }\n }\n\n const handleCellMouseEnter = (\n event: MouseEvent,\n row: T,\n tooltipOptions: TableOverflowTooltipOptions\n ) => {\n const table = parent\n const cell = getCell(event)\n const namespace = table?.vnode.el?.dataset.prefix\n if (cell) {\n const column = getColumnByCell(\n {\n columns: props.store.states.columns.value,\n },\n cell,\n namespace\n )\n if (cell.rowSpan > 1) {\n toggleRowClassByCell(cell.rowSpan, event, addClass)\n }\n const hoverState = (table.hoverState = { cell, column, row })\n table?.emit(\n 'cell-mouse-enter',\n hoverState.row,\n hoverState.column,\n hoverState.cell,\n event\n )\n }\n\n if (!tooltipOptions) {\n return\n }\n\n // 判断是否text-overflow, 如果是就显示tooltip\n const cellChild = (event.target as HTMLElement).querySelector(\n '.cell'\n ) as HTMLElement\n if (\n !(\n hasClass(cellChild, `${namespace}-tooltip`) &&\n cellChild.childNodes.length\n )\n ) {\n return\n }\n // use range width instead of scrollWidth to determine whether the text is overflowing\n // to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3\n const range = document.createRange()\n range.setStart(cellChild, 0)\n range.setEnd(cellChild, cellChild.childNodes.length)\n /** detail: https://github.com/element-plus/element-plus/issues/10790\n * What went wrong?\n * UI > Browser > Zoom, In Blink/WebKit, getBoundingClientRect() sometimes returns inexact values, probably due to lost precision during internal calculations. In the example above:\n * - Expected: 188\n * - Actual: 188.00000762939453\n */\n const { width: rangeWidth, height: rangeHeight } =\n range.getBoundingClientRect()\n const { width: cellChildWidth, height: cellChildHeight } =\n cellChild.getBoundingClientRect()\n\n const { top, left, right, bottom } = getPadding(cellChild)\n const horizontalPadding = left + right\n const verticalPadding = top + bottom\n if (\n isGreaterThan(rangeWidth + horizontalPadding, cellChildWidth) ||\n isGreaterThan(rangeHeight + verticalPadding, cellChildHeight) ||\n // When using a high-resolution screen, it is possible that a returns cellChild.scrollWidth value of 1921 and\n // cellChildWidth returns a value of 1920.994140625. #16856 #16673\n isGreaterThan(cellChild.scrollWidth, cellChildWidth)\n ) {\n createTablePopper(\n tooltipOptions,\n cell.innerText || cell.textContent,\n cell,\n table\n )\n }\n }\n const handleCellMouseLeave = (event) => {\n const cell = getCell(event)\n if (!cell) return\n if (cell.rowSpan > 1) {\n toggleRowClassByCell(cell.rowSpan, event, removeClass)\n }\n const oldHoverState = parent?.hoverState\n parent?.emit(\n 'cell-mouse-leave',\n oldHoverState?.row,\n oldHoverState?.column,\n oldHoverState?.cell,\n event\n )\n }\n\n return {\n handleDoubleClick,\n handleClick,\n handleContextMenu,\n handleMouseEnter,\n handleMouseLeave,\n handleCellMouseEnter,\n handleCellMouseLeave,\n tooltipContent,\n tooltipTrigger,\n }\n}\n\nexport default useEvents\n"],"names":["inject","TABLE_INJECTION_KEY","ref","h","getCell","getColumnByCell","debounce","addClass","hasClass","createTablePopper","removeClass"],"mappings":";;;;;;;;;;;AAKA,SAAS,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,IAAI,EAAE;AAC7C,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;AACzB,CAAC;AACD,SAAS,SAAS,CAAC,KAAK,EAAE;AAC1B,EAAE,MAAM,MAAM,GAAGA,UAAM,CAACC,0BAAmB,CAAC,CAAC;AAC7C,EAAE,MAAM,cAAc,GAAGC,OAAG,CAAC,EAAE,CAAC,CAAC;AACjC,EAAE,MAAM,cAAc,GAAGA,OAAG,CAACC,KAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,EAAE,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,KAAK;AAC5C,IAAI,IAAI,EAAE,CAAC;AACX,IAA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