UNPKG

ivue-material-plus

Version:

A high quality UI components Library with Vue.js

233 lines (230 loc) 5.3 kB
import { h } from 'vue'; import { hasOwn } from '@vue/shared'; import IvueCheckbox from '../ivue-checkbox/index2.mjs'; import IvueIcon from '../ivue-icon/index2.mjs'; import Loading from './loading.mjs'; import { getProp } from '../../utils/objects.mjs'; const defaultClassNames = { selection: "ivue-table-column--selection", expand: "ivue-table--expand-column" }; const cellStyles = { default: { order: "" }, selection: { width: 48, minWidth: 48, columnWidth: 48, order: "" }, expand: { width: 48, minWidth: 48, columnWidth: 48, order: "" }, index: { width: 48, minWidth: 48, columnWidth: 48, order: "" } }; function mergeOptions(defaults, config) { const options = {}; let key; for (key in defaults) { options[key] = defaults[key]; } for (key in config) { if (hasOwn(config, key)) { const value = config[key]; if (typeof value !== "undefined") { options[key] = value; } } } return options; } function compose(...funcs) { if (funcs.length === 0) { return (arg) => arg; } if (funcs.length === 1) { return funcs[0]; } return funcs.reduce( (a, b) => (...args) => a(b(...args)) ); } function defaultRenderCell({ row, column, $index }) { var _a; const property = column.property; const value = property && getProp(row, property).value; if (column && column.formatter) { return column.formatter(row, column, value, $index); } return ((_a = value == null ? void 0 : value.toString) == null ? void 0 : _a.call(value)) || ""; } function treeCellPrefix({ row, treeNode, store }, createPlaceholder = false) { if (!treeNode) { if (createPlaceholder) { return [ h("span", { class: "ivue-table-indent--placeholder" }) ]; } return null; } const ele = []; const callback = (event) => { event.stopPropagation(); if (treeNode.loading) { return; } store.loadOrToggle(row); }; if (treeNode.indent) { ele.push( h("span", { class: "ivue-table-indent", style: { "padding-left": `${treeNode.indent}px` } }) ); } if (typeof treeNode.expanded === "boolean" && !treeNode.noLazyChildren) { const expandClasses = [ "ivue-table--expand-icon", { ["ivue-table--expand-icon__expandend"]: treeNode.expanded } ]; let icon = "chevron_right"; if (treeNode.loading) { icon = ""; } ele.push( h( "div", { class: expandClasses, onClick: callback }, { default: () => { return [ icon ? h(IvueIcon, null, { default: () => icon }) : h(Loading) ]; } } ) ); } else { ele.push( h("span", { class: "ivue-table-indent--placeholder" }) ); } return ele; } const cellForced = { selection: { renderHeader({ store }) { return h(IvueCheckbox, { disabled: store.states.data.value && store.states.data.value.length === 0, modelValue: store.states.isAllSelected.value, "onUpdate:modelValue": store.toggleAllSelection, indeterminate: store.states.selection.value.length > 0 && !store.states.isAllSelected.value, onClick: (event) => { event.stopPropagation(); } }); }, renderCell({ row, column, store, $index }) { return h(IvueCheckbox, { disabled: column.selectable ? !column.selectable.call(null, row, $index) : false, modelValue: store.isSelected(row), onChange: () => { store.commit("rowSelectedChanged", row); }, onClick: (event) => event.stopPropagation() }); }, sortable: false, resizable: false }, index: { renderHeader({ column }) { return column.label || "#"; }, renderCell({ column, $index }) { let i = $index + 1; const index = column.index; if (typeof index === "number") { i = $index + index; } else if (typeof index === "function") { i = index($index); } return h("div", {}, [i]); } }, expand: { renderHeader({ column }) { return column.label || ""; }, renderCell({ row, store, expanded }) { const handleToggleRowExpansion = (event) => { event.stopPropagation(); store.toggleRowExpansion(row); }; return h( "div", { class: [ "ivue-table--expand-icon", { ["ivue-table--expand-icon__expandend"]: expanded } ], onClick: handleToggleRowExpansion }, { default: () => { return [ h(IvueIcon, null, { default: () => "chevron_right" }) ]; } } ); }, sortable: false, resizable: false } }; const getDefaultClassName = (type) => { return defaultClassNames[type] || ""; }; export { cellForced, cellStyles, compose, defaultRenderCell, getDefaultClassName, mergeOptions, treeCellPrefix }; //# sourceMappingURL=config.mjs.map