UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

160 lines (153 loc) 6.16 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { openBlock, createElementBlock, createElementVNode, toRefs, computed, createVNode } from 'vue'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import get from 'lodash/get'; import useClassName from './useClassName.js'; import { useTNodeJSX } from '../../hooks/tnode.js'; import useDefaultValue from '../../hooks/useDefaultValue.js'; import { useConfig } from '../../config-provider/useConfig.js'; import '../../hooks/useConfig.js'; import 'lodash/isFunction'; import 'lodash/cloneDeep'; import 'lodash/isString'; import '../../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import '../../_common/js/global-config/default-config.js'; import '../../_common/js/global-config/locale/en_US.js'; import '../../_chunks/dep-3a1cce9f.js'; import 'lodash/isArray'; import 'lodash/camelCase'; import 'lodash/kebabCase'; import '../../utils/render-tnode.js'; import 'lodash/isEmpty'; import 'lodash/isObject'; const _hoisted_1 = { class: "x-icon", viewBox: "0 0 24 24", width: "1.1em", height: "1.1em" }; const _hoisted_2 = /*#__PURE__*/createElementVNode("path", { fill: "currentColor", d: "M12 11V8l4 4l-4 4v-3H8v-2h4Zm0-9c5.52 0 10 4.48 10 10s-4.48 10-10 10S2 17.52 2 12S6.48 2 12 2Zm0 18c4.42 0 8-3.58 8-8s-3.58-8-8-8s-8 3.58-8 8s3.58 8 8 8Z" }, null, -1 /* HOISTED */); const _hoisted_3 = [ _hoisted_2 ]; function render(_ctx, _cache) { return (openBlock(), createElementBlock("svg", _hoisted_1, _hoisted_3)) } var __unplugin_components_0 = { name: 'ri-arrow-right-circle-line', render }; /* vite-plugin-components disabled */ function useRowExpand(props, context) { var _toRefs = toRefs(props), expandedRowKeys = _toRefs.expandedRowKeys; var renderTNode = useTNodeJSX(); var _useConfig = useConfig("table"), t = _useConfig.t, globalConfig = _useConfig.globalConfig; var _useClassName = useClassName(), tableExpandClasses = _useClassName.tableExpandClasses, positiveRotate90 = _useClassName.positiveRotate90, tableFullRowClasses = _useClassName.tableFullRowClasses; var _useDefaultValue = useDefaultValue(expandedRowKeys, props.defaultExpandedRowKeys || [], props.onExpandChange, "expandedRowKeys"), _useDefaultValue2 = _slicedToArray(_useDefaultValue, 2), tExpandedRowKeys = _useDefaultValue2[0], setTExpandedRowKeys = _useDefaultValue2[1]; var showExpandedRow = computed(function () { return Boolean(props.expandedRow || context.slots.expandedRow || context.slots["expanded-row"]); }); var showExpandIconColumn = computed(function () { return props.expandIcon !== false && showExpandedRow.value; }); var isFirstColumnFixed = computed(function () { var _props$columns; return ((_props$columns = props.columns) === null || _props$columns === void 0 || (_props$columns = _props$columns[0]) === null || _props$columns === void 0 ? void 0 : _props$columns.fixed) === "left"; }); var onToggleExpand = function onToggleExpand(e, row) { props.expandOnRowClick && e.stopPropagation(); var currentId = get(row, props.rowKey || "id"); var index = tExpandedRowKeys.value.indexOf(currentId); var newKeys = _toConsumableArray(tExpandedRowKeys.value); index !== -1 ? newKeys.splice(index, 1) : newKeys.push(currentId); setTExpandedRowKeys(newKeys, { expandedRowData: props.data.filter(function (t2) { return newKeys.includes(get(t2, props.rowKey || "id")); }), currentRowData: row }); }; var renderExpandIcon = function renderExpandIcon(_, p) { var row = p.row, rowIndex = p.rowIndex; var currentId = get(row, props.rowKey || "id"); var expanded = tExpandedRowKeys.value.includes(currentId); var icon = renderTNode("expandIcon", { defaultNode: t(globalConfig.value.expandIcon) || createVNode(__unplugin_components_0, null, null), params: { row: row, index: rowIndex } }); if (!icon) return null; var classes = [tableExpandClasses.iconBox, tableExpandClasses[expanded ? "expanded" : "collapsed"], _defineProperty({}, positiveRotate90, expanded)]; return createVNode("span", { "class": classes, "onClick": function onClick(e) { return onToggleExpand(e, row); } }, [icon]); }; var getExpandColumn = function getExpandColumn() { var expandCol = { colKey: "__EXPAND_ROW_ICON_COLUMN__", width: 46, className: tableExpandClasses.iconCell, fixed: isFirstColumnFixed.value ? "left" : void 0, cell: renderExpandIcon, stopPropagation: true }; return expandCol; }; var renderExpandedRow = function renderExpandedRow(p) { var rowId = get(p.row, props.rowKey || "id"); if (!tExpandedRowKeys.value || !tExpandedRowKeys.value.includes(rowId)) return null; var isFixedLeft = p.isWidthOverflow && props.columns.find(function (item) { return item.fixed === "left"; }); return createVNode("tr", { "key": "expand_".concat(rowId), "class": [tableExpandClasses.row, _defineProperty({}, tableFullRowClasses.base, isFixedLeft)] }, [createVNode("td", { "colspan": p.columns.length }, [createVNode("div", { "class": [tableExpandClasses.rowInner, _defineProperty({}, tableFullRowClasses.innerFullRow, isFixedLeft)], "style": isFixedLeft ? { width: "".concat(p.tableWidth, "px") } : {} }, [createVNode("div", { "class": tableFullRowClasses.innerFullElement }, [renderTNode("expandedRow", { params: p })])])])]); }; var onInnerExpandRowClick = function onInnerExpandRowClick(p) { onToggleExpand(p.e, p.row); }; return { showExpandedRow: showExpandedRow, showExpandIconColumn: showExpandIconColumn, getExpandColumn: getExpandColumn, renderExpandedRow: renderExpandedRow, onInnerExpandRowClick: onInnerExpandRowClick }; } export { useRowExpand as default }; //# sourceMappingURL=useRowExpand.js.map