handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
102 lines (98 loc) • 3.67 kB
JavaScript
import { getScrollbarWidth, outerHeight, outerWidth, resetCssTransform } from "../../../../helpers/dom/element.mjs";
import BottomInlineStartCornerOverlayTable from "../table/bottomInlineStartCorner.mjs";
import { Overlay } from "./_base.mjs";
import { CLONE_BOTTOM_INLINE_START_CORNER } from "./constants.mjs";
/**
* @class BottomInlineStartCornerOverlay
*/
export class BottomInlineStartCornerOverlay extends Overlay {
/**
* @param {Walkontable} wotInstance The Walkontable instance. @TODO refactoring: check if can be deleted.
* @param {FacadeGetter} facadeGetter Function which return proper facade.
* @param {Settings} wtSettings The Walkontable settings.
* @param {DomBindings} domBindings Dom elements bound to the current instance.
* @param {BottomOverlay} bottomOverlay The instance of the Top overlay.
* @param {InlineStartOverlay} inlineStartOverlay The instance of the InlineStart overlay.
*/
constructor(wotInstance, facadeGetter, wtSettings, domBindings, bottomOverlay, inlineStartOverlay) {
super(wotInstance, facadeGetter, CLONE_BOTTOM_INLINE_START_CORNER, wtSettings, domBindings);
this.bottomOverlay = bottomOverlay;
this.inlineStartOverlay = inlineStartOverlay;
}
/**
* Factory method to create a subclass of `Table` that is relevant to this overlay.
*
* @see Table#constructor
* @param {...*} args Parameters that will be forwarded to the `Table` constructor.
* @returns {BottomInlineStartCornerOverlayTable}
*/
createTable() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return new BottomInlineStartCornerOverlayTable(...args);
}
/**
* Checks if overlay should be fully rendered.
*
* @returns {boolean}
*/
shouldBeRendered() {
return this.wtSettings.getSetting('shouldRenderBottomOverlay') && this.wtSettings.getSetting('shouldRenderInlineStartOverlay');
}
/**
* Updates the corner overlay position.
*
* @returns {boolean}
*/
resetFixedPosition() {
const {
wot
} = this;
this.updateTrimmingContainer();
if (!wot.wtTable.holder.parentNode) {
// removed from DOM
return false;
}
const overlayRoot = this.clone.wtTable.holder.parentNode;
overlayRoot.style.top = '';
if (this.trimmingContainer === this.domBindings.rootWindow) {
const inlineStartOffset = this.inlineStartOverlay.getOverlayOffset();
const bottom = this.bottomOverlay.getOverlayOffset();
overlayRoot.style[this.isRtl() ? 'right' : 'left'] = `${inlineStartOffset}px`;
overlayRoot.style.bottom = `${bottom}px`;
} else {
resetCssTransform(overlayRoot);
this.repositionOverlay();
}
let tableHeight = outerHeight(this.clone.wtTable.TABLE);
const tableWidth = outerWidth(this.clone.wtTable.TABLE);
if (!this.wot.wtTable.hasDefinedSize()) {
tableHeight = 0;
}
overlayRoot.style.height = `${tableHeight}px`;
overlayRoot.style.width = `${tableWidth}px`;
return false;
}
/**
* Reposition the overlay.
*/
repositionOverlay() {
const {
wtTable,
wtViewport
} = this.wot;
const {
rootDocument
} = this.domBindings;
const cloneRoot = this.clone.wtTable.holder.parentNode;
let bottomOffset = 0;
if (!wtViewport.hasVerticalScroll()) {
bottomOffset += wtViewport.getWorkspaceHeight() - wtTable.getTotalHeight();
}
if (wtViewport.hasVerticalScroll() && wtViewport.hasHorizontalScroll()) {
bottomOffset += getScrollbarWidth(rootDocument);
}
cloneRoot.style.bottom = `${bottomOffset}px`;
}
}