{"version":3,"file":"description2.mjs","names":[],"sources":["../../../../../../packages/components/descriptions/src/description.vue"],"sourcesContent":["<template>\n  <div :class=\"descriptionKls\">\n    <div\n      v-if=\"title || extra || $slots.title || $slots.extra\"\n      :class=\"ns.e('header')\"\n    >\n      <div :class=\"ns.e('title')\">\n        <slot name=\"title\">{{ title }}</slot>\n      </div>\n      <div :class=\"ns.e('extra')\">\n        <slot name=\"extra\">{{ extra }}</slot>\n      </div>\n    </div>\n\n    <div :class=\"ns.e('body')\">\n      <table :class=\"[ns.e('table'), ns.is('bordered', border)]\">\n        <tbody>\n          <template v-for=\"(row, _index) in getRows()\" :key=\"_index\">\n            <el-descriptions-row :row=\"row\" />\n          </template>\n        </tbody>\n      </table>\n    </div>\n  </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, provide, useSlots } from 'vue'\nimport { flattedChildren } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { useFormSize } from '@element-plus/components/form'\nimport ElDescriptionsRow from './descriptions-row.vue'\nimport { descriptionsKey } from './token'\nimport { COMPONENT_NAME } from './constants'\n\nimport type { DescriptionProps } from './description'\nimport type { IDescriptionsInject } from './descriptions.type'\nimport type { DescriptionItemVNode } from './description-item'\n\ndefineOptions({\n  name: 'ElDescriptions',\n})\n\nconst props = withDefaults(defineProps<DescriptionProps>(), {\n  column: 3,\n  direction: 'horizontal',\n  title: '',\n  extra: '',\n})\n\nconst ns = useNamespace('descriptions')\n\nconst descriptionsSize = useFormSize()\n\nconst slots = useSlots()\n\nprovide(descriptionsKey, props as IDescriptionsInject)\n\nconst descriptionKls = computed(() => [ns.b(), ns.m(descriptionsSize.value)])\n\nconst filledNode = (\n  node: DescriptionItemVNode,\n  span: number,\n  count: number,\n  isLast = false\n) => {\n  if (!node.props) {\n    node.props = {}\n  }\n  if (span > count) {\n    node.props.span = count\n  }\n  if (isLast) {\n    // set the last span\n    node.props.span = span\n  }\n  return node\n}\n\nconst getRows = () => {\n  if (!slots.default) return []\n\n  const children = flattedChildren(slots.default()).filter(\n    (node): node is DescriptionItemVNode =>\n      (node as any)?.type?.name === COMPONENT_NAME\n  )\n  const rows: DescriptionItemVNode[][] = []\n  let temp: DescriptionItemVNode[] = []\n  let count = props.column\n  let totalSpan = 0 // all spans number of item\n  const rowspanTemp: number[] = [] // the number of row spans\n\n  children.forEach((node, index) => {\n    const span = node.props?.span || 1\n    const rowspan = node.props?.rowspan || 1\n    const rowNo = rows.length\n    rowspanTemp[rowNo] ||= 0\n\n    if (rowspan > 1) {\n      for (let i = 1; i < rowspan; i++) {\n        rowspanTemp[rowNo + i] ||= 0\n        rowspanTemp[rowNo + i]++\n        totalSpan++\n      }\n    }\n    if (rowspanTemp[rowNo] > 0) {\n      count -= rowspanTemp[rowNo]\n      rowspanTemp[rowNo] = 0\n    }\n    if (index < children.length - 1) {\n      totalSpan += span > count ? count : span\n    }\n\n    if (index === children.length - 1) {\n      // calculate the last item span\n      const lastSpan = props.column - (totalSpan % props.column)\n      temp.push(filledNode(node, lastSpan, count, true))\n      rows.push(temp)\n      return\n    }\n\n    if (span < count) {\n      count -= span\n      temp.push(node)\n    } else {\n      temp.push(filledNode(node, span, count))\n      rows.push(temp)\n      count = props.column\n      temp = []\n    }\n  })\n\n  return rows\n}\n</script>\n"],"mappings":""}