-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdf1bd9
commit 14a11e3
Showing
32 changed files
with
574 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {CellInfo, Value, Style} from '../bindings' | ||
|
||
export class Cell { | ||
public constructor(cellInfo: CellInfo) { | ||
this._value = CellValue.from(cellInfo.value) | ||
this._formula = cellInfo.formula | ||
this._style = cellInfo.style | ||
} | ||
|
||
public getText(): string { | ||
return this._value.valueStr ?? '' | ||
} | ||
|
||
public getStyle(): Style { | ||
return this._style | ||
} | ||
|
||
public getFormula(): string { | ||
return this._formula | ||
} | ||
|
||
private _value: CellValue | ||
private _style: Style | ||
private _formula = '' | ||
} | ||
|
||
export class CellValue { | ||
cellValueOneof?: | ||
| {$case: 'str'; str: string} | ||
| {$case: 'number'; number: number} | ||
| {$case: 'bool'; bool: boolean} | ||
| {$case: 'error'; error: string} | ||
get value() { | ||
if (this.cellValueOneof?.$case === 'str') return this.cellValueOneof.str | ||
else if (this.cellValueOneof?.$case === 'bool') | ||
return this.cellValueOneof.bool | ||
else if (this.cellValueOneof?.$case === 'error') | ||
return this.cellValueOneof.error | ||
else if (this.cellValueOneof?.$case === 'number') | ||
return this.cellValueOneof.number | ||
else return '' | ||
} | ||
get valueStr() { | ||
return this.value.toString() | ||
} | ||
static from(value: Value) { | ||
const v = new CellValue() | ||
if (hasOwnProperty(value, 'str')) | ||
v.cellValueOneof = {$case: 'str', str: value.str as string} | ||
else if (hasOwnProperty(value, 'bool')) | ||
v.cellValueOneof = {$case: 'bool', bool: value.bool as boolean} | ||
else if (hasOwnProperty(value, 'number')) | ||
v.cellValueOneof = {$case: 'number', number: value.number as number} | ||
else if (hasOwnProperty(value, 'error')) | ||
v.cellValueOneof = {$case: 'error', error: value.error as string} | ||
return v | ||
} | ||
} | ||
|
||
function hasOwnProperty<T, K extends PropertyKey>( | ||
obj: T, | ||
prop: K | ||
): obj is T & Record<K, unknown> { | ||
return Object.prototype.hasOwnProperty.call(obj, prop) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import {Payload} from './payloads' | ||
|
||
export class Transaction { | ||
public constructor(payloads: Payload[], public readonly undoable: boolean) { | ||
this.payloads = payloads | ||
public constructor( | ||
public payloads: readonly Payload[], | ||
public readonly undoable: boolean | ||
) {} | ||
} | ||
|
||
export class TransactionBuilder { | ||
public payload(p: Payload): this { | ||
this._payloads.push(p) | ||
return this | ||
} | ||
|
||
public addPayload(p: Payload): Transaction { | ||
this.payloads.push(p) | ||
public undoable(v: boolean): this { | ||
this._undoable = v | ||
return this | ||
} | ||
|
||
public payloads: Payload[] = [] | ||
public build(): Transaction { | ||
return new Transaction(this._payloads, this._undoable) | ||
} | ||
|
||
private _payloads: Payload[] = [] | ||
private _undoable = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.