@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
63 lines • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toValidElementAndBounds = exports.toValidElementMove = exports.isValidMove = exports.isValidSize = exports.getLayoutOptions = exports.minDimensions = exports.minHeight = exports.minWidth = void 0;
function minWidth(element) {
const layoutOptions = getLayoutOptions(element);
if (layoutOptions !== undefined && typeof layoutOptions.minWidth === 'number') {
return layoutOptions.minWidth;
}
return 1;
}
exports.minWidth = minWidth;
function minHeight(element) {
const layoutOptions = getLayoutOptions(element);
if (layoutOptions !== undefined && typeof layoutOptions.minHeight === 'number') {
return layoutOptions.minHeight;
}
return 1;
}
exports.minHeight = minHeight;
function minDimensions(element) {
return { width: minWidth(element), height: minHeight(element) };
}
exports.minDimensions = minDimensions;
function getLayoutOptions(element) {
const layoutOptions = element.layoutOptions;
if (layoutOptions !== undefined) {
return layoutOptions;
}
return undefined;
}
exports.getLayoutOptions = getLayoutOptions;
function isValidSize(element, size) {
return size.width >= minWidth(element) && size.height >= minHeight(element);
}
exports.isValidSize = isValidSize;
function isValidMove(element, newPosition, movementRestrictor) {
var _a;
return (_a = movementRestrictor === null || movementRestrictor === void 0 ? void 0 : movementRestrictor.validate(element, newPosition)) !== null && _a !== void 0 ? _a : true;
}
exports.isValidMove = isValidMove;
function toValidElementMove(element, move, movementRestrictor) {
if (!isValidMove(element, move.toPosition, movementRestrictor)) {
return;
}
return move;
}
exports.toValidElementMove = toValidElementMove;
function toValidElementAndBounds(element, bounds, movementRestrictor) {
if (!isValidMove(element, bounds.newPosition, movementRestrictor)) {
return;
}
const elementMinWidth = minWidth(element);
if (bounds.newSize.width < elementMinWidth) {
bounds.newSize.width = elementMinWidth;
}
const elementMinHeight = minHeight(element);
if (bounds.newSize.height < elementMinHeight) {
bounds.newSize.height = elementMinHeight;
}
return bounds;
}
exports.toValidElementAndBounds = toValidElementAndBounds;
//# sourceMappingURL=layout-utils.js.map