UNPKG

vuestic-ui

Version:
54 lines (53 loc) 1.69 kB
import { ref, computed } from "vue"; import { c as createItemsProp, a as useItemsTrackByProp } from "./useCommonProps.js"; import { g as getValueByPath } from "../../../utils/value-by-key.js"; const getItemKey = (source, itemsTrackBy) => typeof itemsTrackBy === "function" ? itemsTrackBy(source) : getValueByPath(source, itemsTrackBy) || source; const createRowsProps = () => ({ ...createItemsProp(), ...useItemsTrackByProp }); const buildTableCell = (rowIndex, rowKey, rowData, column) => { var _a; const source = getValueByPath(rowData, column.key); return { rowIndex, rowKey, rowData, column, source, value: ((_a = source == null ? void 0 : source.toString) == null ? void 0 : _a.call(source)) || "" }; }; const buildTableRow = (source, initialIndex, itemsTrackBy, columns) => { const itemKey = getItemKey(source, itemsTrackBy); return { initialIndex, itemKey, source, cells: columns.map((column) => buildTableCell(initialIndex, itemKey, source, column)), rowData: source }; }; const useRows = (columns, props) => { const expandableRows = ref({}); const rowsComputed = computed(() => props.items.map((rawItem, index) => ({ ...buildTableRow(rawItem, index, props.itemsTrackBy, columns.value), toggleRowDetails: (show) => { if (typeof show === "boolean") { expandableRows.value[index] = show; } else { expandableRows.value[index] = !expandableRows.value[index]; } }, isExpandableRowVisible: !!expandableRows.value[index] }))); return { rowsComputed }; }; export { createRowsProps as c, getItemKey as g, useRows as u }; //# sourceMappingURL=useRows.js.map