{"version":3,"file":"index.vue.mjs","sources":["../../../../../packages/components/descriptions/src/index.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\">\nimport { computed, defineComponent, provide } from 'vue'\nimport { isValidComponentSize } from '@element-ultra/utils'\nimport { useSize, useNamespace } from '@element-ultra/hooks'\nimport DescriptionsRow from './descriptions-row.vue'\nimport { elDescriptionsKey } from './token'\n\nimport type { PropType } from 'vue'\nimport type { ComponentSize } from '@element-ultra/shared'\n\nexport default defineComponent({\n  name: 'ElDescriptions',\n  components: {\n    [DescriptionsRow.name]: DescriptionsRow,\n  },\n  props: {\n    border: {\n      type: Boolean,\n      default: false,\n    },\n    column: {\n      type: Number,\n      default: 3,\n    },\n    direction: {\n      type: String as PropType<'horizontal' | 'vertical'>,\n      default: 'horizontal',\n    },\n    size: {\n      type: String as PropType<ComponentSize>,\n      validator: isValidComponentSize,\n    },\n    title: {\n      type: String,\n      default: '',\n    },\n    extra: {\n      type: String,\n      default: '',\n    },\n  },\n  setup(props, { slots }) {\n    provide(elDescriptionsKey, props)\n\n    const descriptionsSize = useSize({ props })\n    const ns = useNamespace('descriptions')\n\n    const descriptionKls = computed(() => [\n      ns.b(),\n      ns.is(ns.m(descriptionsSize.value), !!descriptionsSize.value),\n    ])\n\n    const flattedChildren = (children) => {\n      const temp = Array.isArray(children) ? children : [children]\n      const res = []\n      temp.forEach((child) => {\n        if (Array.isArray(child.children)) {\n          res.push(...flattedChildren(child.children))\n        } else {\n          res.push(child)\n        }\n      })\n      return res\n    }\n\n    const filledNode = (node, span, count, isLast = false) => {\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\n    const getRows = () => {\n      const children = flattedChildren(slots.default?.()).filter(\n        (node) => node?.type?.name === 'ElDescriptionsItem'\n      )\n      const rows = []\n      let temp = []\n      let count = props.column\n      let totalSpan = 0 // all spans number of item\n\n      children.forEach((node, index) => {\n        const span = node.props?.span || 1\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\n    return {\n      descriptionKls,\n      getRows,\n      ns,\n    }\n  },\n})\n</script>\n"],"names":["_resolveComponent","_normalizeClass","_openBlock","_createElementBlock","_createElementVNode","_createCommentVNode","_Fragment","_renderList","_createBlock"],"mappings":";;;;;yCACEA,iBAsBM,qBAAA,CAAA,CAAA;;;;MApBI,KAAA,EAAAC,cAAS,CAAA,IAAA,CAAK,cAAW,CAAA;AAAA,KAAA;AAAA;MACzB,IAAA,CAAA,KAAA,IAAA,IAAA,CAAA,KAAA,IAAA,IAAA,CAAA,MAAA,CAAA,KAAA,IAAA,IAAA,CAAA,MAAA,CAAA,KAAA,IAAAC,SAAA,EAAA,EAAAC,kBAAA;AAAA,QAAM,KAAA;AAAA,QAAA;AAAA,UAAA,GAAA,EAAA,CAAA;AAAA,UAEZ,OAEMF,cAAA,CAAA,IAAA,CAAA,EAAA,CAAA,CAA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