@react-slate/core
Version:
Write interactive CLI apps with React
47 lines • 1.61 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const shallowequal_1 = __importDefault(require("shallowequal"));
const layout_1 = require("../../layout");
const events_1 = require("../../events");
class Base {
constructor() {
this.children = [];
this.layoutNode = new layout_1.Node(layout_1.allocator, {});
this.eventListener = new events_1.EventListener();
this.isAbsolute = false;
this.zIndex = 0;
this.eventListener.setValidator((_eventName, eventData) => {
return this.isWithinRect(eventData);
});
}
isWithinRect({ x, y }) {
return Boolean(this.rect &&
x - 1 >= this.rect.x &&
x - 1 < this.rect.x + this.rect.width &&
y - 1 >= this.rect.y &&
y - 1 < this.rect.y + this.rect.height);
}
notifyOnLayoutHook(layout, { offsetX, offsetY }) {
const rect = {
absolute: this.isAbsolute,
z: this.zIndex,
x: layout.x + offsetX,
y: layout.y + offsetY,
relativeX: layout.x,
relativeY: layout.y,
width: layout.width,
height: layout.height,
};
if (!shallowequal_1.default(this.rect, rect)) {
this.rect = rect;
if (this.onLayoutHook) {
this.onLayoutHook(rect);
}
}
}
}
exports.default = Base;
//# sourceMappingURL=Base.js.map