ivue-material-plus
Version:
A high quality UI components Library with Vue.js
164 lines (161 loc) • 4.89 kB
JavaScript
import { defineComponent, getCurrentInstance, ref, computed, onBeforeMount, onMounted, onBeforeUnmount, Fragment, h } from 'vue';
import { isString } from '@vue/shared';
import defaultProps from './defaults.mjs';
import useRender from './render.mjs';
import useWatcher from './watcher.mjs';
import { cellStyles, mergeOptions, compose } from '../config.mjs';
const prefixCls = "ivue-table-column";
let columnIdSeed = 1;
var TableColumn = defineComponent({
name: prefixCls,
props: defaultProps,
setup(props, { slots }) {
const vm = getCurrentInstance();
const columnConfig = ref({});
const parentDom = computed(() => {
let parent2 = vm.parent;
while (parent2 && !parent2.tableId) {
parent2 = parent2.parent;
}
return parent2;
});
const initData = () => {
var _a;
const children = isSubColumn.value ? parent.vnode.el.children : (_a = parent.refs.hiddenColumns) == null ? void 0 : _a.children;
const getColumnIndex = () => {
return getColumnDomIndex(children || [], vm.vnode.el);
};
columnConfig.value.getColumnIndex = getColumnIndex;
const columnIndex = getColumnIndex();
if (columnIndex > -1) {
parentDom.value.store.commit(
"insertColumn",
columnConfig.value,
isSubColumn.value ? parent.columnConfig.value : null
);
}
};
const initBeforeMount = () => {
isSubColumn.value = parentDom.value !== parent;
const type = props.type || "default";
const sortable = props.sortable === "" ? true : props.sortable;
const defaults = {
...cellStyles[type],
id: columnId.value,
type,
property: props.prop || props.property,
align,
headerAlign,
showOverflowTooltip: props.showOverflowTooltip,
filterable: props.filters || props.filterMethod,
filterPlacement: "",
filterOpened: false,
isSubColumn: false,
sortable,
index: props.index,
rawColumnKey: vm.vnode.key,
filteredValue: []
};
const basicProps = [
"columnKey",
"label",
"className",
"labelClassName",
"type",
"renderHeader",
"formatter",
"fixed",
"resizable"
];
const sortProps = ["sortMethod", "sortBy", "sortOrders"];
const selectProps = ["selectable", "reserveSelection"];
const filterProps = [
"filterMethod",
"filters",
"filterMultiple",
"filterOpened",
"filteredValue",
"filterPlacement"
];
let column = getPropsData(
basicProps,
sortProps,
selectProps,
filterProps
);
column = mergeOptions(defaults, column);
const chains = compose(
columnRender,
setColumnWidth,
setColumnProps
);
column = chains(column);
columnConfig.value = column;
registerNormalWatchers();
registerComplexWatchers();
};
onBeforeMount(() => {
initBeforeMount();
});
onMounted(() => {
initData();
});
onBeforeUnmount(() => {
parentDom.value.store.commit(
"removeColumn",
columnConfig.value,
isSubColumn.value ? parent.columnConfig.value : null
);
});
const {
columnId,
isSubColumn,
align,
headerAlign,
columnParent,
getPropsData,
getColumnDomIndex,
columnRender,
setColumnWidth,
setColumnProps
} = useRender(props, slots, parentDom);
const { registerNormalWatchers, registerComplexWatchers } = useWatcher(
parentDom,
props
);
const parent = columnParent.value;
columnId.value = `${parent.tableId || parent.columnId}-column-${columnIdSeed++}`;
vm.columnId = columnId.value;
vm.columnConfig = columnConfig;
},
render() {
var _a, _b, _c;
try {
const slotsList = (_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a, {
row: {},
column: {},
$index: -1
});
const slot = [];
if (Array.isArray(slotsList)) {
for (const childNode of slotsList) {
if (((_c = childNode.type) == null ? void 0 : _c.name) === prefixCls || childNode.shapeFlag & 2) {
slot.push(childNode);
} else if (childNode.type === Fragment && Array.isArray(childNode.children)) {
childNode.children.forEach((vnode2) => {
if ((vnode2 == null ? void 0 : vnode2.patchFlag) !== 1024 && !isString(vnode2 == null ? void 0 : vnode2.children)) {
slot.push(vnode2);
}
});
}
}
}
const vnode = h("div", slot);
return vnode;
} catch (e) {
return h("div", []);
}
}
});
export { TableColumn as default };
//# sourceMappingURL=index.mjs.map