throw error when block width is greater than column width

This commit is contained in:
darshanr0107
2025-07-04 18:26:39 +05:30
parent 91f141f772
commit 27185f62e4
2 changed files with 26 additions and 0 deletions

View File

@@ -92,7 +92,18 @@ export const setCssClass = function (itemIds: string, cssClassName: string) {
const populateBlockDatabase = (_blockList: Block[], parent: Block): void => {
const blockList = _blockList.flat();
const children = [];
const columnSettingBlock = blockList.find((b) => b?.type === 'column-setting');
const column = columnSettingBlock?.columns ?? -1;
for (const block of blockList) {
if (
typeof column === 'number' &&
column > 0 &&
block.type !== 'column-setting' &&
typeof block.widthInColumns === 'number' &&
block.widthInColumns > column
) {
throw new Error(`width of block ${block.id} is greater than the column width`);
}
if (block.label) {
block.label = sanitizeText(block.label);
}

View File

@@ -402,6 +402,21 @@ columns 1
const B = blocks[0];
expect(B.styles).toContain('fill:#f9F');
});
it('should throw error when block width exceeds column width', () => {
const str = `block-beta
columns 1
A:1
B:2
C:3
D:4
E:3
F:2
G:1`;
expect(() => block.parse(str)).toThrowError(
'width of block B is greater than the column width'
);
});
});
describe('prototype properties', function () {