dbgate/packages/web/src/designer/DomTableRef.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-12-26 17:57:56 +00:00
import { TableInfo } from 'dbgate-types';
2020-12-26 18:35:12 +00:00
type DesignerTableInfo = TableInfo & { designerId: string };
2020-12-26 17:57:56 +00:00
export default class DomTableRef {
domTable: Element;
domWrapper: Element;
table: DesignerTableInfo;
2020-12-26 18:35:12 +00:00
designerId: string;
domRefs: { [column: string]: Element };
2020-12-26 17:57:56 +00:00
constructor(table: DesignerTableInfo, domRefs, domWrapper: Element) {
this.domTable = domRefs[''];
this.domWrapper = domWrapper;
this.table = table;
2020-12-26 18:35:12 +00:00
this.designerId = table.designerId;
this.domRefs = domRefs;
2020-12-26 17:57:56 +00:00
}
getRect() {
2020-12-26 18:35:12 +00:00
if (!this.domWrapper) return null;
if (!this.domTable) return null;
const wrap = this.domWrapper.getBoundingClientRect();
const rect = this.domTable.getBoundingClientRect();
return {
left: rect.left - wrap.left,
top: rect.top - wrap.top,
2020-12-27 08:39:58 +00:00
right: rect.right - wrap.left,
bottom: rect.bottom - wrap.top,
2020-12-26 18:35:12 +00:00
};
2020-12-26 17:57:56 +00:00
}
2020-12-26 18:35:12 +00:00
getColumnY(columnName: string) {
let col = this.domRefs[columnName];
if (!col) return null;
const rect = col.getBoundingClientRect();
const wrap = this.domWrapper.getBoundingClientRect();
return (rect.top + rect.bottom) / 2 - wrap.top;
2020-12-26 17:57:56 +00:00
}
}