{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../packages/components/table/src/table-body/index.ts"],"sourcesContent":["import {\n  defineComponent,\n  getCurrentInstance,\n  h,\n  inject,\n  onUnmounted,\n  watch,\n} from 'vue'\nimport { addClass, isClient, rAF, removeClass } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport useLayoutObserver from '../layout-observer'\nimport { removePopper } from '../util'\nimport { TABLE_INJECTION_KEY } from '../tokens'\nimport useRender from './render-helper'\nimport defaultProps from './defaults'\n\nimport type { VNode } from 'vue'\n\nexport default defineComponent({\n  name: 'ElTableBody',\n  props: defaultProps,\n  setup(props) {\n    const instance = getCurrentInstance()\n    const parent = inject(TABLE_INJECTION_KEY)\n    const ns = useNamespace('table')\n    const { wrappedRowRender, tooltipContent, tooltipTrigger } =\n      useRender(props)\n    const { onColumnsChange, onScrollableChange } = useLayoutObserver(parent!)\n\n    const hoveredCellList: HTMLTableCellElement[] = []\n    watch(props.store?.states.hoverRow, (newVal: any, oldVal: any) => {\n      const el = instance?.vnode.el as HTMLElement\n      const rows = Array.from(el?.children || []).filter((e) =>\n        e?.classList.contains(`${ns.e('row')}`)\n      )\n\n      // hover rowSpan > 1 choose the whole row\n      let rowNum = newVal\n      const childNodes = rows[rowNum]\n        ?.childNodes as NodeListOf<HTMLTableCellElement>\n      if (childNodes?.length) {\n        let control = 0\n        const indexes = Array.from(childNodes).reduce((acc, item, index) => {\n          // drop colsSpan\n          if (childNodes[index]?.colSpan > 1) {\n            control = childNodes[index]?.colSpan\n          }\n          if (item.nodeName !== 'TD' && control === 0) {\n            acc.push(index)\n          }\n          control > 0 && control--\n          return acc\n        }, [] as number[])\n\n        indexes.forEach((rowIndex) => {\n          rowNum = newVal\n          while (rowNum > 0) {\n            // find from previous\n            const preChildNodes = rows[rowNum - 1]\n              ?.childNodes as NodeListOf<HTMLTableCellElement>\n\n            if (\n              preChildNodes[rowIndex] &&\n              preChildNodes[rowIndex].nodeName === 'TD' &&\n              preChildNodes[rowIndex].rowSpan > 1\n            ) {\n              addClass(preChildNodes[rowIndex], 'hover-cell')\n              hoveredCellList.push(preChildNodes[rowIndex])\n              break\n            }\n            rowNum--\n          }\n        })\n      } else {\n        hoveredCellList.forEach((item) => removeClass(item, 'hover-cell'))\n        hoveredCellList.length = 0\n      }\n      if (!props.store?.states.isComplex.value || !isClient) return\n\n      rAF(() => {\n        // just get first level children; fix #9723\n        const oldRow = rows[oldVal]\n        const newRow = rows[newVal]\n        // when there is fixed row, hover on rowSpan > 1 should not clear the class\n        if (oldRow && !oldRow.classList.contains('hover-fixed-row')) {\n          removeClass(oldRow, 'hover-row')\n        }\n        if (newRow) {\n          addClass(newRow, 'hover-row')\n        }\n      })\n    })\n\n    onUnmounted(() => {\n      removePopper?.()\n    })\n\n    return {\n      ns,\n      onColumnsChange,\n      onScrollableChange,\n      wrappedRowRender,\n      tooltipContent,\n      tooltipTrigger,\n    }\n  },\n  render() {\n    const { wrappedRowRender, store } = this\n    const data = store?.states.data.value || []\n    // Why do we need tabIndex: -1 ?\n    // If you set the tabindex attribute on an element ,\n    // then its child content cannot be scrolled with the arrow keys,\n    // unless you set tabindex on the content too\n    // See https://github.com/facebook/react/issues/25462#issuecomment-1274775248 or https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes/tabindex\n    return h('tbody', { tabIndex: -1 }, [\n      data.reduce((acc: VNode[], row) => {\n        return acc.concat(wrappedRowRender(row, acc.length) as VNode[])\n      }, []),\n    ])\n  },\n})\n"],"mappings":";;;;;;;;;;;;AAkBA,yBAAe,gBAAgB;CAC7B,MAAM;CACN,OAAO;CACP,MAAM,OAAO;EACX,MAAM,WAAW,oBAAoB;EACrC,MAAM,SAAS,OAAO,oBAAoB;EAC1C,MAAM,KAAK,aAAa,QAAQ;EAChC,MAAM,EAAE,kBAAkB,gBAAgB,mBACxC,UAAU,MAAM;EAClB,MAAM,EAAE,iBAAiB,uBAAuB,kBAAkB,OAAQ;EAE1E,MAAM,kBAA0C,EAA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