Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/AbsoluteCellRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@
end: SimpleCellAddress,
}

export function isSimpleCellRange(obj: any): obj is SimpleCellRange {
if (obj && (typeof obj === 'object' || typeof obj === 'function')) {
/**
* Type guard that checks if an object is a valid SimpleCellRange.
* @param {unknown} val - Value to check
* @returns {boolean} True if and only if the object is a valid SimpleCellRange
*/
export function isSimpleCellRange(val: unknown): val is SimpleCellRange {
if (val && (typeof val === 'object' || typeof val === 'function')) {
const obj = val as Record<string, unknown>
return 'start' in obj && isSimpleCellAddress(obj.start) && 'end' in obj && isSimpleCellAddress(obj.end)
} else {
return false
}
}

export const simpleCellRange = (start: SimpleCellAddress, end: SimpleCellAddress) => ({start, end})

Check warning on line 43 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment

export class AbsoluteCellRange implements SimpleCellRange {

Check warning on line 45 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
public readonly start: SimpleCellAddress
public readonly end: SimpleCellAddress

constructor(

Check warning on line 49 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
start: SimpleCellAddress,
end: SimpleCellAddress,
) {
Expand All @@ -51,11 +57,11 @@
this.end = simpleCellAddress(end.sheet, end.col, end.row)
}

public get sheet() {

Check warning on line 60 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
return this.start.sheet
}

public static fromSimpleCellAddresses(start: SimpleCellAddress, end: SimpleCellAddress): AbsoluteCellRange {

Check warning on line 64 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
if (start.sheet !== end.sheet) {
throw new SheetsNotEqual(start.sheet, end.sheet)
}
Expand All @@ -74,7 +80,7 @@
return new AbsoluteColumnRange(start.sheet, start.col, end.col)
}

public static fromAst(ast: CellRangeAst | ColumnRangeAst | RowRangeAst, baseAddress: SimpleCellAddress): AbsoluteCellRange {

Check warning on line 83 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
if (ast.type === AstNodeType.CELL_RANGE) {
return AbsoluteCellRange.fromCellRange(ast, baseAddress)
} else if (ast.type === AstNodeType.COLUMN_RANGE) {
Expand All @@ -84,7 +90,7 @@
}
}

public static fromAstOrUndef(ast: CellRangeAst | ColumnRangeAst | RowRangeAst, baseAddress: SimpleCellAddress): Maybe<AbsoluteCellRange> {

Check warning on line 93 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
try {
return AbsoluteCellRange.fromAst(ast, baseAddress)
} catch (_e) {
Expand All @@ -92,14 +98,14 @@
}
}

public static fromCellRange(x: CellRange, baseAddress: SimpleCellAddress): AbsoluteCellRange {

Check warning on line 101 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
return new AbsoluteCellRange(
x.start.toSimpleCellAddress(baseAddress),
x.end.toSimpleCellAddress(baseAddress),
)
}

public static spanFrom(topLeftCorner: SimpleCellAddress, width: number, height: number): AbsoluteCellRange {

Check warning on line 108 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
const ret = AbsoluteCellRange.spanFromOrUndef(topLeftCorner, width, height)
if (ret === undefined) {
throw new Error(WRONG_RANGE_SIZE)
Expand All @@ -107,7 +113,7 @@
return ret
}

public static spanFromOrUndef(topLeftCorner: SimpleCellAddress, width: number, height: number): Maybe<AbsoluteCellRange> {

Check warning on line 116 in src/AbsoluteCellRange.ts

View workflow job for this annotation

GitHub Actions / lint (20, ubuntu-latest)

Missing JSDoc comment
if (!Number.isFinite(width) && Number.isFinite(height)) {
if (topLeftCorner.col !== 0) {
return undefined
Expand Down
14 changes: 14 additions & 0 deletions test/unit/cruds/change-cell-content.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ describe('changing cell content', () => {
expect(engine.getCellValueDetailedType({ sheet: 0, col: 0, row: 1 })).toEqual(CellValueDetailedType.NUMBER_CURRENCY)
expect(engine.getCellValueDetailedType({ sheet: 0, col: 0, row: 2 })).toEqual(CellValueDetailedType.NUMBER_PERCENT)
})

it('should work in scenario from issue https://github.com/handsontable/hyperformula/issues/1297', () => {
const engine = HyperFormula.buildFromArray([
[1, 2, '=SUM(A1:B1)'],
['=SUM(1:1)', 0, 0],
['=SUM(1:2)', 0, 0],
])

engine.setCellContents(adr('C1'), [['=SUM(A1:B1)']])
engine.setCellContents(adr('A3'), [['=SUM(A1:C2)']])
engine.setCellContents(adr('B1'), [[null]])

expect(engine.getCellValue(adr('A3'))).toEqual(4)
})
})

describe('change multiple cells contents', () => {
Expand Down
Loading