yanzhen-design-vue
Version:
145 lines (144 loc) • 5.31 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const utils = require("@yanzhen-libs/utils");
const lodashEs = require("lodash-es");
const constants = require("../constants.cjs");
function unrefTbodyElement(target) {
var _a;
const el = vue.unref(target);
if (!el || !lodashEs.isElement(el)) return null;
return ((_a = el.querySelector) == null ? void 0 : _a.call(el, ".vxe-table--body-wrapper table.vxe-table--body tbody")) ?? null;
}
function isTableRow(element) {
if (!element || !lodashEs.isElement(element)) return false;
return element.tagName.toLowerCase() === "tr";
}
function isTableCol(element) {
if (!element || !lodashEs.isElement(element)) return false;
return element.tagName.toLowerCase() === "td";
}
function isTableTbody(element) {
if (!element || !lodashEs.isElement(element)) return false;
return element.tagName.toLowerCase() === "tbody";
}
function unrefTbodyRowElements(target) {
var _a;
const tbody = isTableTbody(target) ? target : unrefTbodyElement(target);
if (!tbody || !lodashEs.isElement(tbody)) return null;
const rows = (_a = tbody == null ? void 0 : tbody.getElementsByTagName) == null ? void 0 : _a.call(tbody, "tr");
return (rows == null ? void 0 : rows.length) > 0 ? [...rows] : null;
}
function unrefTbodyColElements(target) {
var _a;
const tbody = isTableTbody(target) || isTableRow(target) ? target : unrefTbodyElement(target);
if (!tbody || !lodashEs.isElement(tbody)) return null;
const cols = (_a = tbody == null ? void 0 : tbody.getElementsByTagName) == null ? void 0 : _a.call(tbody, "td");
return (cols == null ? void 0 : cols.length) > 0 ? [...cols] : null;
}
const ROW_RECORD_ENUMS = {
$rowIndex: "index",
row: "item",
items: true,
rowid: true
};
function unrefTbodyRowRecord(target, tableRef, callback) {
var _a;
if (lodashEs.isArray(target)) {
return target.map((item) => {
const record = unrefTbodyRowRecord(item, tableRef);
if (record && lodashEs.isFunction(callback)) {
callback(record);
}
return record;
});
}
const getRowNode = (_a = vue.unref(tableRef)) == null ? void 0 : _a.getRowNode;
if (!target || !isTableRow(target) || !lodashEs.isFunction(getRowNode)) return null;
const rowNode = getRowNode(target);
const _record = Object.entries(ROW_RECORD_ENUMS).reduce((prev, [k1, k2]) => {
prev[k1] = k2 === true ? rowNode[k1] : rowNode[k2];
return prev;
}, {});
return {
..._record,
type: "body",
target
};
}
const COL_RECORD_ENUMS = {
$columnIndex: "index",
column: "item",
colid: true
};
function unrefTbodyColRecord(target, tableRef, ...args) {
var _a;
const callback = args.find((value) => lodashEs.isFunction(value));
const isRowRecord = args.find((value) => lodashEs.isBoolean(value));
if (lodashEs.isArray(target)) {
const rowRecords = /* @__PURE__ */ new Map();
return target.map((item) => {
const colRecord2 = unrefTbodyColRecord(item, tableRef, callback);
if (!colRecord2) return null;
const parent = item.parentElement;
let rowRecord = rowRecords.get(parent);
if (isRowRecord) {
if (!rowRecord) {
rowRecord = unrefTbodyRowRecord(parent, tableRef);
rowRecords.set(parent, rowRecord);
}
}
const record = {
...rowRecord ?? {},
...colRecord2
};
if (lodashEs.isFunction(callback)) {
callback(record);
}
return record;
});
}
const getColumnNode = (_a = vue.unref(tableRef)) == null ? void 0 : _a.getColumnNode;
if (!target || !isTableCol(target) || !lodashEs.isFunction(getColumnNode)) return null;
const columnNode = getColumnNode(target);
const colRecord = Object.entries(COL_RECORD_ENUMS).reduce((prev, [k1, k2]) => {
prev[k1] = k2 === true ? columnNode[k1] : columnNode[k2];
return prev;
}, {});
if (isRowRecord) {
const parent = target.parentElement;
const rowRecord = unrefTbodyRowRecord(parent, tableRef) ?? {};
return {
...rowRecord,
...colRecord,
parent,
target,
type: "body"
};
}
return {
...colRecord,
target,
type: "body"
};
}
function isVirtualDom(target) {
var _a;
if (!target || !lodashEs.isElement(target)) return false;
return utils.parseJson((_a = target.getAttribute) == null ? void 0 : _a.call(target, "data-virtual")) ?? String(target.className).includes(constants.VIRTUAL_CLASS) ?? target.classList.contains(constants.VIRTUAL_CLASS);
}
function isHiddenDom(target) {
var _a;
if (!target || !lodashEs.isElement(target)) return false;
return utils.parseJson((_a = target.getAttribute) == null ? void 0 : _a.call(target, "data-hidden")) ?? String(target.className).includes(constants.HIDDEN_CLASS) ?? target.classList.contains(constants.HIDDEN_CLASS);
}
exports.isHiddenDom = isHiddenDom;
exports.isTableCol = isTableCol;
exports.isTableRow = isTableRow;
exports.isTableTbody = isTableTbody;
exports.isVirtualDom = isVirtualDom;
exports.unrefTbodyColElements = unrefTbodyColElements;
exports.unrefTbodyColRecord = unrefTbodyColRecord;
exports.unrefTbodyElement = unrefTbodyElement;
exports.unrefTbodyRowElements = unrefTbodyRowElements;
exports.unrefTbodyRowRecord = unrefTbodyRowRecord;