@visactor/react-vtable
Version:
The react version of VTable
33 lines (29 loc) • 1.84 kB
JavaScript
import { getTargetCell } from "@visactor/vtable";
import { ContainerModule, EnvContribution, BrowserEnvContribution } from "@visactor/vtable/es/vrender";
import { isString } from "@visactor/vutils";
export const reactEnvModule = new ContainerModule(((bind, unbind, isBound, rebind) => {
bind(VTableBrowserEnvContribution).toSelf().inSingletonScope(), isBound(EnvContribution) ? rebind(EnvContribution).toService(VTableBrowserEnvContribution) : bind(EnvContribution).toService(VTableBrowserEnvContribution);
}));
class VTableBrowserEnvContribution extends BrowserEnvContribution {
updateDom(dom, params) {
var _a, _b;
const tableDiv = dom.parentElement;
if (tableDiv && params.graphic) {
const top = parseInt(params.style.top, 10), left = parseInt(params.style.left, 10);
let domWidth, domHeight;
if (dom.style.display = "none") {
const cellGroup = getTargetCell(params.graphic);
domWidth = null !== (_a = cellGroup.attribute.width) && void 0 !== _a ? _a : 1,
domHeight = null !== (_b = cellGroup.attribute.height) && void 0 !== _b ? _b : 1;
} else domWidth = dom.offsetWidth, domHeight = dom.offsetHeight;
if (top + domHeight < 0 || left + domWidth < 0 || top > tableDiv.offsetHeight || left > tableDiv.offsetWidth) return dom.style.display = "none",
!1;
}
const {width: width, height: height, style: style} = params;
return style && (isString(style) ? dom.setAttribute("style", style) : Object.keys(style).forEach((k => {
dom.style[k] = style[k];
}))), null != width && (dom.style.width = `${width}px`), null != height && (dom.style.height = `${height}px`),
!0;
}
}
//# sourceMappingURL=vtable-browser-env-contribution.js.map