@opensig/opendesign
Version:
94 lines (93 loc) • 2.8 kB
JavaScript
;
const vue = require("vue");
const useResizeObserver = require("../hooks/use-resize-observer.js");
const is = require("../_utils/is.js");
const helper = require("../_utils/helper.js");
require("../hooks/use-theme.js");
require("../_utils/global.js");
require("@vueuse/core");
const provide = require("./provide.js");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "TableColGroup",
setup(__props) {
const dataTableInjection = vue.inject(provide.dataTableInjectKey);
const getPropWidth = (column) => {
return {
minWidth: !is.isNil(column._minWidth) ? `${column._minWidth}px` : column._minWidth,
maxWidth: !is.isNil(column._maxWidth) ? `${column._maxWidth}px` : column._maxWidth
};
};
const colgroupRef = vue.ref();
const setColRef = async (col, column) => {
if (!col) {
return;
}
column.colRef = vue.markRaw(col);
};
const resizeObserver = useResizeObserver.useResizeObserver();
const resizeHandler = helper.debounceRAF(() => {
if (!colgroupRef.value || !dataTableInjection) {
return;
}
dataTableInjection.dataColumns.value.forEach((column) => {
if (!column.colRef) {
return;
}
column.resizeWidth = column.colRef.getBoundingClientRect().width;
});
});
vue.watch(
colgroupRef,
(newVal, oldVal) => {
if (oldVal) {
resizeObserver.unobserve(oldVal, resizeHandler);
}
if (newVal) {
resizeHandler();
resizeObserver.observe(newVal, resizeHandler);
}
},
{ immediate: true }
);
vue.onUnmounted(() => {
if (colgroupRef.value) {
resizeObserver.unobserve(colgroupRef.value, resizeHandler);
}
});
return (_ctx, _cache) => {
var _a;
return vue.openBlock(), vue.createElementBlock(
"colgroup",
{
ref_key: "colgroupRef",
ref: colgroupRef
},
[
(vue.openBlock(true), vue.createElementBlock(
vue.Fragment,
null,
vue.renderList((_a = vue.unref(dataTableInjection)) == null ? void 0 : _a.dataColumns.value, (column) => {
return vue.openBlock(), vue.createElementBlock(
"col",
{
key: column.key,
ref_for: true,
ref: (el) => setColRef(el, column),
style: vue.normalizeStyle(getPropWidth(column))
},
null,
4
/* STYLE */
);
}),
128
/* KEYED_FRAGMENT */
))
],
512
/* NEED_PATCH */
);
};
}
});
module.exports = _sfc_main;