{"version":3,"file":"event-helper.js","sources":["../../../../../../../packages/components/table/src/table-header/event-helper.ts"],"sourcesContent":["// @ts-nocheck\nimport { getCurrentInstance, inject, ref } from 'vue'\nimport {\n addClass,\n hasClass,\n isClient,\n isElement,\n removeClass,\n} from '@element-plus/utils'\nimport { TABLE_INJECTION_KEY } from '../tokens'\nimport type { TableHeaderProps } from '.'\nimport type { TableColumnCtx } from '../table-column/defaults'\n\nfunction useEvent(props: TableHeaderProps, emit) {\n const instance = getCurrentInstance()\n const parent = inject(TABLE_INJECTION_KEY)\n const handleFilterClick = (event: Event) => {\n event.stopPropagation()\n return\n }\n\n const handleHeaderClick = (event: Event, column: TableColumnCtx) => {\n if (!column.filters && column.sortable) {\n handleSortClick(event, column, false)\n } else if (column.filterable && !column.sortable) {\n handleFilterClick(event)\n }\n parent?.emit('header-click', column, event)\n }\n\n const handleHeaderContextMenu = (event: Event, column: TableColumnCtx) => {\n parent?.emit('header-contextmenu', column, event)\n }\n const draggingColumn = ref(null)\n const dragging = ref(false)\n const dragState = ref({})\n const handleMouseDown = (event: MouseEvent, column: TableColumnCtx) => {\n if (!isClient) return\n if (column.children && column.children.length > 0) return\n /* istanbul ignore if */\n if (draggingColumn.value && props.border) {\n dragging.value = true\n\n const table = parent\n emit('set-drag-visible', true)\n const tableEl = table?.vnode.el\n const tableLeft = tableEl.getBoundingClientRect().left\n const columnEl = instance.vnode.el.querySelector(`th.${column.id}`)\n const columnRect = columnEl.getBoundingClientRect()\n const minLeft = columnRect.left - tableLeft + 30\n\n addClass(columnEl, 'noclick')\n\n dragState.value = {\n startMouseLeft: event.clientX,\n startLeft: columnRect.right - tableLeft,\n startColumnLeft: columnRect.left - tableLeft,\n tableLeft,\n }\n const resizeProxy = table?.refs.resizeProxy as HTMLElement\n resizeProxy.style.left = `${(dragState.value as any).startLeft}px`\n\n document.onselectstart = function () {\n return false\n }\n document.ondragstart = function () {\n return false\n }\n\n const handleMouseMove = (event: MouseEvent) => {\n const deltaLeft =\n event.clientX - (dragState.value as any).startMouseLeft\n const proxyLeft = (dragState.value as any).startLeft + deltaLeft\n\n resizeProxy.style.left = `${Math.max(minLeft, proxyLeft)}px`\n }\n\n const handleMouseUp = () => {\n if (dragging.value) {\n const { startColumnLeft, startLeft } = dragState.value as any\n const finalLeft = Number.parseInt(resizeProxy.style.left, 10)\n const columnWidth = finalLeft - startColumnLeft\n column.width = column.realWidth = columnWidth\n table?.emit(\n 'header-dragend',\n column.width,\n startLeft - startColumnLeft,\n column,\n event\n )\n requestAnimationFrame(() => {\n props.store.scheduleLayout(false, true)\n })\n document.body.style.cursor = ''\n dragging.value = false\n draggingColumn.value = null\n dragState.value = {}\n emit('set-drag-visible', false)\n }\n\n document.removeEventListener('mousemove', handleMouseMove)\n document.removeEventListener('mouseup', handleMouseUp)\n document.onselectstart = null\n document.ondragstart = null\n\n setTimeout(() => {\n removeClass(columnEl, 'noclick')\n }, 0)\n }\n\n document.addEventListener('mousemove', handleMouseMove)\n document.addEventListener('mouseup', handleMouseUp)\n }\n }\n\n const handleMouseMove = (event: MouseEvent, column: TableColumnCtx) => {\n if (column.children && column.children.length > 0) return\n const el = event.target as HTMLElement\n if (!isElement(el)) {\n return\n }\n const target = el?.closest('th')\n\n if (!column || !column.resizable) return\n\n if (!dragging.value && props.border) {\n const rect = target.getBoundingClientRect()\n\n const bodyStyle = document.body.style\n if (rect.width > 12 && rect.right - event.pageX < 8) {\n bodyStyle.cursor = 'col-resize'\n if (hasClass(target, 'is-sortable')) {\n target.style.cursor = 'col-resize'\n }\n draggingColumn.value = column\n } else if (!dragging.value) {\n bodyStyle.cursor = ''\n if (hasClass(target, 'is-sortable')) {\n target.style.cursor = 'pointer'\n }\n draggingColumn.value = null\n }\n }\n }\n\n const handleMouseOut = () => {\n if (!isClient) return\n document.body.style.cursor = ''\n }\n const toggleOrder = ({ order, sortOrders }) => {\n if (order === '') return sortOrders[0]\n const index = sortOrders.indexOf(order || null)\n return sortOrders[index > sortOrders.length - 2 ? 0 : index + 1]\n }\n const handleSortClick = (\n event: Event,\n column: TableColumnCtx,\n givenOrder: string | boolean\n ) => {\n event.stopPropagation()\n const order =\n column.order === givenOrder ? null : givenOrder || toggleOrder(column)\n const target = (event.target as HTMLElement)?.closest('th')\n\n if (target) {\n if (hasClass(target, 'noclick')) {\n removeClass(target, 'noclick')\n return\n }\n }\n\n if (!column.sortable) return\n\n const clickTarget = event.currentTarget\n\n if (\n ['ascending', 'descending'].some(\n (str) => hasClass(clickTarget, str) && !column.sortOrders.includes(str)\n )\n ) {\n return\n }\n\n const states = props.store.states\n let sortProp = states.sortProp.value\n let sortOrder\n const sortingColumn = states.sortingColumn.value\n\n if (\n sortingColumn !== column ||\n (sortingColumn === column && sortingColumn.order === null)\n ) {\n if (sortingColumn) {\n sortingColumn.order = null\n }\n states.sortingColumn.value = column\n sortProp = column.property\n }\n if (!order) {\n sortOrder = column.order = null\n } else {\n sortOrder = column.order = order\n }\n\n states.sortProp.value = sortProp\n states.sortOrder.value = sortOrder\n\n parent?.store.commit('changeSortCondition')\n }\n\n return {\n handleHeaderClick,\n handleHeaderContextMenu,\n handleMouseDown,\n handleMouseMove,\n handleMouseOut,\n handleSortClick,\n handleFilterClick,\n }\n}\n\nexport default useEvent\n"],"names":["getCurrentInstance","inject","TABLE_INJECTION_KEY","ref","isClient","addClass","removeClass","isElement","hasClass"],"mappings":";;;;;;;;;;;AASA,SAAS,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE;AAC/B,EAAE,MAAM,QAAQ,GAAGA,sBAAkB,EAAE,CAAC;AACxC,EAAE,MAAM,MAAM,GAAGC,UAAM,CAACC,0BAAmB,CAAC,CAAC;AAC7C,EAAE,MAAM,iBAAiB,GAAG,CAAC,KAAK,KAAK;AACvC,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;AAC5B,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK;AAC/C,IAAI,IAAI,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