@opensig/opendesign
Version:
209 lines (208 loc) • 8.9 kB
JavaScript
import { defineComponent, computed, ref, toRefs, createElementBlock, openBlock, normalizeClass, createElementVNode, createCommentVNode, unref, Fragment, renderList, normalizeStyle, renderSlot, createTextVNode, toDisplayString, createVNode } from "vue";
import { IconLoading } from "../_utils/icons.mjs";
import { tableProps } from "./types.mjs";
import { getColumnData, getBodyData } from "./table.mjs";
import { DEFAULT_CELL_LAST_COL_MARKER, DEFAULT_ROW_LAST_MARKER } from "./useTableMeta.mjs";
import { useTableCommon } from "./useTableCommon.mjs";
const _hoisted_1 = { key: 0 };
const _hoisted_2 = ["rowspan", "colspan"];
const _hoisted_3 = {
key: 0,
class: "o-table-tip-wrap"
};
const _hoisted_4 = { class: "o-table-empty-label" };
const _hoisted_5 = {
key: 0,
class: "o-table-loading-wrap"
};
const _hoisted_6 = { class: "o-table-loading-label" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "OTable",
props: tableProps,
setup(__props) {
const props = __props;
const columnData = computed(() => getColumnData(props.columns));
const tableData = computed(() => getBodyData(columnData, props.data, props.cellSpan));
const tableEl = ref();
const { emptyLabel, loadingLabel, borderClass, handleMouseOver, clearHighlight, handleTouchStart } = useTableCommon({ ...toRefs(props), tableEl });
return (_ctx, _cache) => {
return openBlock(), createElementBlock(
"div",
{
class: normalizeClass(["o-table", [
{
"o-table-stripe": props.stripe,
"o-table-small": props.small,
"o-table-medium": !props.small
}
]])
},
[
createElementVNode(
"div",
{
class: normalizeClass(["o-table-wrap", unref(borderClass)])
},
[
createElementVNode(
"table",
{
ref_key: "tableEl",
ref: tableEl
},
[
createElementVNode("colgroup", null, [
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(columnData.value, (col) => {
return openBlock(), createElementBlock(
"col",
{
key: col.key,
style: normalizeStyle(col.style)
},
null,
4
/* STYLE */
);
}),
128
/* KEYED_FRAGMENT */
))
]),
columnData.value.length > 1 ? (openBlock(), createElementBlock("thead", _hoisted_1, [
renderSlot(_ctx.$slots, "header", { columns: columnData.value }, () => [
createElementVNode("tr", null, [
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(columnData.value, (col, idx) => {
return openBlock(), createElementBlock(
"th",
{
key: col.key || idx,
class: normalizeClass({ [unref(DEFAULT_CELL_LAST_COL_MARKER)]: idx + 1 === columnData.value.length })
},
[
renderSlot(_ctx.$slots, `th_${col.key}`, { column: col }, () => [
createTextVNode(
toDisplayString(col.label),
1
/* TEXT */
)
])
],
2
/* CLASS */
);
}),
128
/* KEYED_FRAGMENT */
))
])
])
])) : createCommentVNode("v-if", true),
tableData.value.length > 0 ? (openBlock(), createElementBlock(
"tbody",
{
key: 1,
onMousemove: _cache[0] || (_cache[0] = //@ts-ignore
(...args) => unref(handleMouseOver) && unref(handleMouseOver)(...args)),
onMouseleave: _cache[1] || (_cache[1] = //@ts-ignore
(...args) => unref(clearHighlight) && unref(clearHighlight)(...args)),
onTouchstart: _cache[2] || (_cache[2] = //@ts-ignore
(...args) => unref(handleTouchStart) && unref(handleTouchStart)(...args))
},
[
renderSlot(_ctx.$slots, "body", { body: tableData.value }, () => [
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(tableData.value, (row, rIdx) => {
return openBlock(), createElementBlock(
"tr",
{
key: row.key || rIdx,
class: normalizeClass({ [unref(DEFAULT_ROW_LAST_MARKER)]: rIdx + 1 === tableData.value.length })
},
[
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(row.data, (col, idx) => {
return openBlock(), createElementBlock("td", {
key: col.key || idx,
rowspan: col.rowspan,
colspan: col.colspan,
class: normalizeClass({ [unref(DEFAULT_CELL_LAST_COL_MARKER)]: col.last })
}, [
renderSlot(_ctx.$slots, `td_${col.key}`, {
row: props.data ? props.data[rIdx] : {},
rowIndex: rIdx
}, () => [
createTextVNode(
toDisplayString(col.value),
1
/* TEXT */
)
])
], 10, _hoisted_2);
}),
128
/* KEYED_FRAGMENT */
))
],
2
/* CLASS */
);
}),
128
/* KEYED_FRAGMENT */
))
])
],
32
/* NEED_HYDRATION */
)) : createCommentVNode("v-if", true)
],
512
/* NEED_PATCH */
),
!props.data || props.data.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_3, [
!props.loading ? renderSlot(_ctx.$slots, "empty", { key: 0 }, () => [
createElementVNode(
"div",
_hoisted_4,
toDisplayString(unref(emptyLabel)),
1
/* TEXT */
)
]) : createCommentVNode("v-if", true)
])) : createCommentVNode("v-if", true)
],
2
/* CLASS */
),
props.loading ? (openBlock(), createElementBlock("div", _hoisted_5, [
renderSlot(_ctx.$slots, "loading", {}, () => [
createVNode(unref(IconLoading), { class: "o-rotating" }),
createElementVNode(
"div",
_hoisted_6,
toDisplayString(unref(loadingLabel)),
1
/* TEXT */
)
])
])) : createCommentVNode("v-if", true)
],
2
/* CLASS */
);
};
}
});
export {
_sfc_main as default
};