UNPKG

vxe-table

Version:

A PC-end table component based on Vxe UI, supporting copy-paste, data pivot table, and high-performance virtual list table solution.

446 lines (445 loc) • 15 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var dom_exports = {}; __export(dom_exports, { addClass: () => addClass, checkTargetElement: () => checkTargetElement, getAbsolutePos: () => getAbsolutePos, getDomNode: () => getDomNode, getEventTargetNode: () => getEventTargetNode, getOffsetHeight: () => getOffsetHeight, getOffsetPos: () => getOffsetPos, getPaddingTopBottomSize: () => getPaddingTopBottomSize, getPopupAppendElement: () => getPopupAppendElement, getPopupContainer: () => getPopupContainer, getPopupWrapperElement: () => getPopupWrapperElement, getPropClass: () => getPropClass, getTpImg: () => getTpImg, hasAxternalInputTarget: () => hasAxternalInputTarget, hasClass: () => hasClass, hasControlKey: () => hasControlKey, hasEventInputTarget: () => hasEventInputTarget, initTpImg: () => initTpImg, isNodeElement: () => isNodeElement, isPx: () => isPx, isScale: () => isScale, queryElement: () => queryElement, removeClass: () => removeClass, scrollToView: () => scrollToView, scrollTopTo: () => scrollTopTo, setScrollLeft: () => setScrollLeft, setScrollTop: () => setScrollTop, toCssUnit: () => toCssUnit, triggerEvent: () => triggerEvent, updateCellTitle: () => updateCellTitle, updatePanelPlacement: () => updatePanelPlacement, wheelScrollLeftTo: () => wheelScrollLeftTo, wheelScrollTopTo: () => wheelScrollTopTo }); module.exports = __toCommonJS(dom_exports); var import_xe_utils = __toESM(require("xe-utils")); const reClsMap = {}; let tpImgEl; function initTpImg() { if (!tpImgEl) { tpImgEl = new Image(); tpImgEl.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; } return tpImgEl; } function getTpImg() { if (!tpImgEl) { return initTpImg(); } return tpImgEl; } function getPropClass(property, params) { return property ? (import_xe_utils.default.isFunction(property) ? property(params) : property) || "" : ""; } function getClsRE(cls) { if (!reClsMap[cls]) { reClsMap[cls] = new RegExp(`(?:^|\\s)${cls}(?!\\S)`, "g"); } return reClsMap[cls]; } function getNodeOffset(elem, container, rest) { if (elem) { const parentElem = elem.parentNode; rest.top += elem.offsetTop; rest.left += elem.offsetLeft; if (parentElem && parentElem !== document.documentElement && parentElem !== document.body) { rest.top -= parentElem.scrollTop; rest.left -= parentElem.scrollLeft; } if (container && (elem === container || elem.offsetParent === container) ? 0 : elem.offsetParent) { return getNodeOffset(elem.offsetParent, container, rest); } } return rest; } function isPx(val) { return val && /^\d+(\.\d+)?(px)?$/.test(val); } function isScale(val) { return val && /^\d+(\.\d+)?%$/.test(val); } function hasClass(elem, cls) { if (elem) { if (elem.classList) { return elem.classList.contains(cls); } return !!(elem.className && elem.className.match && elem.className.match(getClsRE(cls))); } return false; } function removeClass(elem, cls) { if (elem && hasClass(elem, cls)) { elem.className = elem.className.replace(getClsRE(cls), ""); } } function addClass(elem, cls) { if (elem && !hasClass(elem, cls)) { removeClass(elem, cls); elem.className = `${elem.className} ${cls}`; } } function hasControlKey(evnt) { return evnt.ctrlKey || evnt.metaKey; } function toCssUnit(val, unit = "px") { if (import_xe_utils.default.isNumber(val) || /^\d+$/.test(`${val}`)) { return `${val}${unit}`; } return `${val || ""}`; } function queryElement(elem, selector) { if (elem) { return elem.querySelector(selector); } return null; } function getDomNode() { const documentElement = document.documentElement; const bodyElem = document.body; return { scrollTop: documentElement.scrollTop || bodyElem.scrollTop, scrollLeft: documentElement.scrollLeft || bodyElem.scrollLeft, visibleHeight: documentElement.clientHeight || bodyElem.clientHeight, visibleWidth: documentElement.clientWidth || bodyElem.clientWidth }; } function getOffsetHeight(elem) { return elem ? elem.offsetHeight : 0; } function getPaddingTopBottomSize(elem) { if (elem) { const computedStyle = getComputedStyle(elem); const paddingTop = import_xe_utils.default.toNumber(computedStyle.paddingTop); const paddingBottom = import_xe_utils.default.toNumber(computedStyle.paddingBottom); return paddingTop + paddingBottom; } return 0; } function setScrollTop(elem, scrollTop) { if (elem) { elem.scrollTop = scrollTop; } } function setScrollLeft(elem, scrollLeft) { if (elem) { elem.scrollLeft = scrollLeft; } } function updateCellTitle(overflowElem, column) { const content = column.type === "html" ? overflowElem.innerText : overflowElem.textContent; if (overflowElem.getAttribute("title") !== content) { overflowElem.setAttribute("title", content); } } function checkTargetElement(target, exEls, endEl) { let targetEl = target; if (!exEls || !exEls.length) { return false; } const [exEl1, exEl2, exEl3] = exEls; while (targetEl) { if (exEl1 === targetEl || exEl2 && targetEl === exEl2 || exEl3 && targetEl === exEl3) { return true; } if (endEl && targetEl === endEl) { return false; } targetEl = targetEl.parentElement; } return false; } function getEventTargetNode(evnt, container, queryCls, queryMethod) { let targetElem; let target = evnt.target.shadowRoot && evnt.composed ? evnt.composedPath()[0] || evnt.target : evnt.target; while (target && target.nodeType && target !== document) { if (queryCls && hasClass(target, queryCls) && (!queryMethod || queryMethod(target))) { targetElem = target; } else if (target === container) { return { flag: queryCls ? !!targetElem : true, container, targetElem }; } target = target.parentNode; } return { flag: false }; } function getOffsetPos(elem, container) { return getNodeOffset(elem, container, { left: 0, top: 0 }); } function getAbsolutePos(elem) { const bounding = elem.getBoundingClientRect(); const boundingTop = bounding.top; const boundingLeft = bounding.left; const { scrollTop, scrollLeft, visibleHeight, visibleWidth } = getDomNode(); return { boundingTop, top: scrollTop + boundingTop, boundingLeft, left: scrollLeft + boundingLeft, visibleHeight, visibleWidth }; } function hasEventInputTarget(target) { const tagName = target ? target.tagName : ""; return tagName && ["input", "textarea"].includes(tagName.toLowerCase()); } function hasReusekeepControl(elem) { if (elem) { return hasClass(elem, "vxe-reusekeep-control"); } return false; } function hasAxternalInputTarget(target) { return hasEventInputTarget(target) ? !hasReusekeepControl(target) : false; } const scrollIntoViewIfNeeded = "scrollIntoViewIfNeeded"; const scrollIntoView = "scrollIntoView"; function scrollToView(elem) { if (elem) { if (elem[scrollIntoViewIfNeeded]) { elem[scrollIntoViewIfNeeded](); } else if (elem[scrollIntoView]) { elem[scrollIntoView](); } } } function triggerEvent(targetElem, type) { if (targetElem) { targetElem.dispatchEvent(new Event(type)); } } function isNodeElement(elem) { return elem && elem.nodeType === 1; } function scrollTopTo(diffNum, cb) { const duration = Math.abs(diffNum); const startTime = performance.now(); let countTop = 0; const step = (timestamp) => { let progress = (timestamp - startTime) / duration; if (progress < 0) { progress = 0; } else if (progress > 1) { progress = 1; } const easedProgress = Math.pow(progress, 2); const offsetTop = Math.floor(diffNum * easedProgress) - countTop; countTop += offsetTop; cb(offsetTop); if (progress < 1) { requestAnimationFrame(step); } }; requestAnimationFrame(step); } let wtlFrame; function wheelScrollLeftTo(scrollLeft, cb) { if (wtlFrame) { cancelAnimationFrame(wtlFrame); } wtlFrame = requestAnimationFrame(() => { cb(scrollLeft); wtlFrame = null; }); } let wtaFrame; function wheelScrollTopTo(diffNum, cb) { if (wtaFrame) { cancelAnimationFrame(wtaFrame); } wtaFrame = requestAnimationFrame(() => { const offsetTop = diffNum; cb(offsetTop); wtaFrame = null; }); } function updatePanelPlacement(targetElem, panelElem, options) { const { defaultTop, defaultLeft, placement, defaultPlacement, appendTo, teleportTo, marginSize, isMinWidth } = Object.assign( { appendTo: "", teleportTo: false, marginSize: 18, isMinWidth: true }, options ); let panelPlacement = "bottom"; let top = ""; let bottom = ""; let left = 0; let minWidth = ""; let arrowLeft = ""; const stys = {}; if (panelElem && targetElem) { const bodyEl = document.body; const parentWrapperEl = getPopupWrapperElement(teleportTo ? getPopupAppendElement(appendTo) : panelElem); if (parentWrapperEl) { const targetWidth = targetElem.offsetWidth; const targetHeight = targetElem.offsetHeight; const panelWidth = panelElem.offsetWidth; const panelHeight = panelElem.offsetHeight; const parentWrapperRect = parentWrapperEl.getBoundingClientRect(); const panelRect = panelElem.getBoundingClientRect(); const targetRect = targetElem.getBoundingClientRect(); const visibleHeight = bodyEl.clientHeight; const visibleWidth = bodyEl.clientWidth; const parentWrapperScrollLeft = parentWrapperEl.scrollLeft; const parentWrapperScrollTop = parentWrapperEl.scrollTop; const parentWrapperOffsetLeft = parentWrapperRect.left; const parentWrapperOffsetTop = parentWrapperRect.top; const targetLeft = targetRect.left; const targetTop = targetRect.top; minWidth = targetElem.offsetWidth; if (teleportTo) { left = (defaultLeft || targetLeft - (panelWidth - targetWidth) / 2) - parentWrapperScrollLeft; top = (defaultTop || targetTop + targetHeight) - parentWrapperScrollTop; if (placement === "top") { panelPlacement = "top"; top = targetTop - panelHeight; } else if (!placement) { if (defaultPlacement === "top") { panelPlacement = "top"; if (!defaultTop) { top = targetTop - panelHeight; } if (top < marginSize) { panelPlacement = "bottom"; top = targetTop + targetHeight; } if (top + panelHeight + marginSize > visibleHeight) { panelPlacement = "top"; top = targetTop - panelHeight; } } else { if (top + panelHeight + marginSize > visibleHeight) { panelPlacement = "top"; top = targetTop - panelHeight; } if (top < marginSize) { panelPlacement = "bottom"; top = targetTop + targetHeight; } } } if (left + panelWidth + marginSize > visibleWidth) { left -= left + panelWidth + marginSize - visibleWidth; } if (left < marginSize) { left = marginSize; } top -= parentWrapperOffsetTop; left -= parentWrapperOffsetLeft; } else { if (placement === "top") { panelPlacement = "top"; bottom = targetHeight; } else if (!placement) { top = targetHeight; if (targetTop + targetHeight + panelHeight + marginSize > visibleHeight) { if (targetTop - targetHeight - panelHeight > marginSize) { panelPlacement = "top"; top = ""; bottom = targetHeight; } } } if (panelRect.left + panelRect.width + marginSize > visibleWidth) { left = -(panelRect.left + panelRect.width + marginSize - visibleWidth); } } if (import_xe_utils.default.isNumber(top)) { stys.top = toCssUnit(top); } if (import_xe_utils.default.isNumber(bottom)) { stys.bottom = toCssUnit(bottom); } if (import_xe_utils.default.isNumber(left)) { stys.left = toCssUnit(left); } if (isMinWidth && import_xe_utils.default.isNumber(minWidth)) { stys.minWidth = toCssUnit(minWidth); } if (left === targetLeft) { if (targetWidth <= panelWidth) { arrowLeft = targetWidth / 2; } } else if (left < targetLeft) { if (left + panelWidth > targetLeft + targetWidth) { arrowLeft = targetLeft - left + targetWidth / 2; } else { arrowLeft = targetLeft - left + (panelWidth - (targetLeft - left)) / 2; } } } } return { top: top || 0, bottom: bottom || 0, left: left || 0, arrowLeft: arrowLeft || 0, style: stys, placement: panelPlacement }; } function getPopupWrapperElement(panelElem) { if (!panelElem) { return null; } const bodyEl = document.body; const parentEl = panelElem.parentElement; return (parentEl === bodyEl ? document.documentElement : parentEl) || null; } function getPopupContainer(appendTo) { const selectElem = appendTo && import_xe_utils.default.isFunction(appendTo) ? appendTo({}) : appendTo; return selectElem || "body"; } function getPopupAppendElement(appendTo) { const selectElem = getPopupContainer(appendTo); if (import_xe_utils.default.isString(selectElem)) { return document.querySelector(selectElem) || document.body; } return selectElem; }