UNPKG

@platform/ui.datagrid

Version:

Isolated tabular DataGrid.

67 lines (66 loc) 3.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sizeHandlers = void 0; var tslib_1 = require("tslib"); var common_1 = require("../common"); function sizeHandlers(grid) { function afterColumnResize(index, width, isDoubleClick) { var _a; if (grid.isInitialized) { var key = common_1.coord.cell.toKey(index, undefined); width = isDoubleClick ? grid.defaults.columnWidth : Math.max(grid.defaults.columnWidthMin, width); grid .changeColumns((_a = {}, _a[key] = toColumn(grid.data.columns[key], { grid: { width: width } }), _a), { source: isDoubleClick ? 'RESET/doubleClick' : 'UPDATE' }) .redraw(); } } function afterRowResize(index, height, isDoubleClick) { var _a; if (grid.isInitialized) { var key = common_1.coord.cell.toKey(undefined, index); height = isDoubleClick ? grid.defaults.rowHeight : Math.max(grid.defaults.rowHeightMin, height); grid .changeRows((_a = {}, _a[key] = toRow(grid.data.rows[key], { grid: { height: height } }), _a), { source: isDoubleClick ? 'RESET/doubleClick' : 'UPDATE' }) .redraw(); } } function modifyColWidth(width, index) { var _a, _b; if (grid.isInitialized) { var key = common_1.coord.cell.toKey(index, undefined); var column = grid.data.columns[key]; var props = column ? column.props : undefined; width = props && ((_a = props.grid) === null || _a === void 0 ? void 0 : _a.width) !== undefined ? (_b = props.grid) === null || _b === void 0 ? void 0 : _b.width : grid.defaults.columnWidth; } return width; } function modifyRowHeight(height, index) { var _a, _b; var key = common_1.coord.cell.toKey(undefined, index); var row = grid.data.rows[key]; var props = row ? row.props : undefined; height = props && ((_a = props.grid) === null || _a === void 0 ? void 0 : _a.height) !== undefined ? (_b = props.grid) === null || _b === void 0 ? void 0 : _b.height : grid.defaults.rowHeight; return height; } return { afterColumnResize: afterColumnResize, afterRowResize: afterRowResize, modifyColWidth: modifyColWidth, modifyRowHeight: modifyRowHeight, }; } exports.sizeHandlers = sizeHandlers; var toColumn = function (input, props) { var res = (0, tslib_1.__assign)({}, (input || {})); return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, res), { props: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (res.props || {})), props) }); }; var toRow = function (input, props) { var row = (0, tslib_1.__assign)({}, (input || {})); return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, row), { props: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (row.props || {})), props) }); };