UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

62 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.minWidth = minWidth; exports.minHeight = minHeight; exports.minDimensions = minDimensions; exports.getLayoutOptions = getLayoutOptions; exports.isValidSize = isValidSize; exports.isValidMove = isValidMove; exports.toValidElementMove = toValidElementMove; exports.toValidElementAndBounds = toValidElementAndBounds; function minWidth(element) { const layoutOptions = getLayoutOptions(element); if (layoutOptions !== undefined && typeof layoutOptions.minWidth === 'number') { return layoutOptions.minWidth; } return 1; } function minHeight(element) { const layoutOptions = getLayoutOptions(element); if (layoutOptions !== undefined && typeof layoutOptions.minHeight === 'number') { return layoutOptions.minHeight; } return 1; } function minDimensions(element) { return { width: minWidth(element), height: minHeight(element) }; } function getLayoutOptions(element) { const layoutOptions = element.layoutOptions; if (layoutOptions !== undefined) { return layoutOptions; } return undefined; } function isValidSize(element, size) { return size.width >= minWidth(element) && size.height >= minHeight(element); } 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; } function toValidElementMove(element, move, movementRestrictor) { if (!isValidMove(element, move.toPosition, movementRestrictor)) { return; } return move; } 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; } //# sourceMappingURL=layout-utils.js.map