UNPKG

hongluan-ui

Version:
1 lines 4.7 kB
{"version":3,"file":"cell.mjs","sources":["../../../../../../../packages/components/table-v2/src/renderers/cell.tsx"],"sourcesContent":["import { renderSlot } from 'vue'\nimport { get } from 'lodash-unified'\nimport { isFunction, isObject } from '@hongluan-ui/utils'\nimport { ExpandIcon, TableCell } from '../components'\nimport { Alignment } from '../constants'\nimport { placeholderSign } from '../private'\nimport { componentToSlot, enforceUnit, tryCall } from '../utils'\n\nimport type { FunctionalComponent, UnwrapNestedRefs, VNode } from 'vue'\nimport type { TableV2RowCellRenderParam } from '../components'\nimport type { UseTableReturn } from '../use-table'\nimport type { TableV2Props } from '../table'\n\ntype CellRendererProps = TableV2RowCellRenderParam &\nPick<\nTableV2Props,\n'cellProps' | 'expandColumnKey' | 'indentSize' | 'iconSize' | 'rowKey'\n> &\nUnwrapNestedRefs<Pick<UseTableReturn, 'expandedRowKeys'>>\n\nconst CellRenderer: FunctionalComponent<CellRendererProps> = (\n {\n // renderer props\n columns,\n column,\n columnIndex,\n depth,\n expandIconProps,\n isScrolling,\n rowData,\n rowIndex,\n // from use-table\n style,\n expandedRowKeys,\n // derived props\n cellProps: _cellProps,\n expandColumnKey,\n indentSize,\n iconSize,\n rowKey,\n },\n { slots },\n) => {\n const cellStyle = enforceUnit(style)\n\n if (column.placeholderSign === placeholderSign) {\n return <div class={'table-v2-row-cell-placeholder'} style={cellStyle} />\n }\n const { cellRenderer, dataKey, dataGetter } = column\n\n const cellData = isFunction(dataGetter)\n ? dataGetter({ columns, column, columnIndex, rowData, rowIndex })\n : get(rowData, dataKey ?? '')\n\n const extraCellProps = tryCall(_cellProps, {\n cellData,\n columns,\n column,\n columnIndex,\n rowIndex,\n rowData,\n })\n\n const cellProps = {\n class: 'table-v2-cell-text',\n columns,\n column,\n columnIndex,\n cellData,\n isScrolling,\n rowData,\n rowIndex,\n }\n const columnCellRenderer = componentToSlot<typeof cellProps>(cellRenderer)\n const Cell = columnCellRenderer\n ? columnCellRenderer(cellProps)\n : renderSlot(slots, 'default', cellProps, () => [\n <TableCell {...cellProps}></TableCell>,\n ])\n\n const kls = [\n 'table-v2-row-cell',\n column.class,\n column.align === Alignment.CENTER && 'is-align-center',\n column.align === Alignment.RIGHT && 'is-align-right',\n ]\n\n const expandable =\n rowIndex >= 0 && expandColumnKey && column.key === expandColumnKey\n const expanded = rowIndex >= 0 && expandedRowKeys.includes(rowData[rowKey])\n\n let IconOrPlaceholder: VNode | undefined\n const iconStyle = `margin-inline-start: ${depth * indentSize}px;`\n if (expandable) {\n if (isObject(expandIconProps)) {\n IconOrPlaceholder = (\n <ExpandIcon\n {...expandIconProps}\n class={['table-v2-expand-icon', expanded ? 'is-expanded' : '']}\n size={iconSize}\n expanded={expanded}\n style={iconStyle}\n expandable\n />\n )\n } else {\n IconOrPlaceholder = (\n <div\n style={[\n iconStyle,\n `width: ${iconSize}px; height: ${iconSize}px;`,\n ].join(' ')}\n />\n )\n }\n }\n\n return (\n <div class={kls} style={cellStyle} {...extraCellProps} role=\"cell\">\n {IconOrPlaceholder}\n {Cell}\n </div>\n )\n}\n\nCellRenderer.inheritAttrs = false\n\nexport default CellRenderer\n"],"names":["columns","column","columnIndex","depth","expandIconProps","isScrolling","rowData","rowIndex","style","expandedRowKeys","cellProps","expandColumnKey","indentSize","iconSize","rowKey","slots","cellRenderer","dataKey","dataGetter","cellData","class","columnCellRenderer","kls","expanded","iconStyle","isObject","IconOrPlaceholder"],"mappings":";;;;;;;;;;;;AAoBA;AAEI;AACAA,EAAAA;AACAC,EAAAA;AACAC,EAAAA;AACAC,EAAAA;AACAC,EAAAA;AACAC,EAAAA;AACAC,EAAAA;AACAC,EAAAA;AACA;AACAC,EAAAA;AACAC,EAAAA;AACA;AACAC,EAAAA;AACAC;AACAC,EAAAA;AACAC;AACAC,EAAAA;AAlBF;AAoBEC;AAAF,MACG;AACH;;AAEA;AACE;AAAA;AAAA;AAAA;AACD;;AACD;AAAQC,IAAAA;AAAcC,IAAAA;AAASC,IAAAA;AAAzB,YAAN;AAEA;AACiBlB;AAASC,IAAAA;AAAQC,IAAAA;AAAaI,IAAAA;AAASC,IAAAA;AAAzC,IADE;AAIjB;AACEY,IAAAA;AACAnB;AACAC,IAAAA;AACAC,IAAAA;AACAK,IAAAA;AACAD,IAAAA;AANyC,IAA3C;AASA;AACEc,IAAAA,OAAO;AACPpB,IAAAA;AACAC,IAAAA;AACAC;AACAiB,YALgB;AAMhBd,eANgB;AAOhBC;AACAC;AARgB;AAUlB,QAAMc,oCAAoC;AAC1C;AAMA,QAAMC;AAON,qCACmBX,wBAAyB;AAC5C,QAAMY,6DAA6DT;AAEnE;AACA,QAAMU,YAAa;;AACnB;AACE,QAAIC,QAAQ;AACVC;AAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAUlB,WAAM;AACLA;AAAiB;AAAA;AAQlB;AACF;;;;;"}