ivue-material-plus
Version:
A high quality UI components Library with Vue.js
80 lines (77 loc) • 2.17 kB
JavaScript
import { getCurrentInstance, watch } from 'vue';
import { hasOwn } from '@vue/shared';
import { parseWidth, parseMinWidth } from '../utils.mjs';
function getAllAliases(props, aliases) {
return props.reduce((prev, cur) => {
prev[cur] = cur;
return prev;
}, aliases);
}
function useWatcher(parentDom, _props) {
const vm = getCurrentInstance();
const registerComplexWatchers = () => {
const props = ["fixed"];
const aliases = {
columnWidth: "width",
columnMinWidth: "minWidth"
};
const allAliases = getAllAliases(props, aliases);
Object.keys(allAliases).forEach((key) => {
const columnKey = aliases[key];
if (hasOwn(_props, columnKey)) {
watch(
() => _props[columnKey],
(newVal) => {
let value = newVal;
if (columnKey === "width" && key === "columnWidth") {
value = parseWidth(newVal);
}
if (columnKey === "minWidth" && key === "columnMinWidth") {
value = parseMinWidth(newVal);
}
vm.columnConfig.value[columnKey] = value;
vm.columnConfig.value[key] = value;
const updateColumns = columnKey === "fixed";
parentDom.value.store.scheduleLayout(updateColumns);
}
);
}
});
};
const registerNormalWatchers = () => {
const props = [
"label",
"filters",
"filterMultiple",
"sortable",
"index",
"formatter",
"className",
"labelClassName",
"showOverflowTooltip"
];
const aliases = {
property: "prop",
align: "align",
headerAlign: "headerAlign"
};
const allAliases = getAllAliases(props, aliases);
Object.keys(allAliases).forEach((key) => {
const columnKey = aliases[key];
if (hasOwn(_props, columnKey)) {
watch(
() => _props[columnKey],
(newVal) => {
vm.columnConfig.value[key] = newVal;
}
);
}
});
};
return {
registerNormalWatchers,
registerComplexWatchers
};
}
export { useWatcher as default };
//# sourceMappingURL=watcher.mjs.map