logisheets 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/src/api/block_manager.d.ts +21 -0
  2. package/dist/src/api/block_manager.js +35 -0
  3. package/dist/src/api/calculator.d.ts +19 -0
  4. package/dist/src/api/calculator.js +46 -0
  5. package/dist/src/api/cell.d.ts +28 -0
  6. package/dist/src/api/cell.js +52 -0
  7. package/dist/src/api/index.d.ts +5 -0
  8. package/dist/src/api/index.js +3 -0
  9. package/dist/src/api/utils.d.ts +3 -1
  10. package/dist/src/api/utils.js +5 -0
  11. package/dist/src/api/workbook.d.ts +30 -8
  12. package/dist/src/api/workbook.js +161 -21
  13. package/dist/src/api/worksheet.d.ts +20 -12
  14. package/dist/src/api/worksheet.js +58 -20
  15. package/dist/src/bindings/alignment.d.ts +6 -0
  16. package/dist/src/bindings/alignment.js +1 -0
  17. package/dist/src/bindings/block_cell_id.d.ts +1 -1
  18. package/dist/src/bindings/cell_clear.d.ts +5 -0
  19. package/dist/src/bindings/cell_clear.js +2 -0
  20. package/dist/src/bindings/cell_format_brush.d.ts +10 -0
  21. package/dist/src/bindings/cell_format_brush.js +2 -0
  22. package/dist/src/bindings/cell_id.d.ts +5 -3
  23. package/dist/src/bindings/cell_info.d.ts +1 -0
  24. package/dist/src/bindings/cell_position.d.ts +4 -0
  25. package/dist/src/bindings/cell_position.js +2 -0
  26. package/dist/src/bindings/cell_style_update.d.ts +7 -0
  27. package/dist/src/bindings/cell_style_update.js +1 -0
  28. package/dist/src/bindings/display_window.d.ts +14 -0
  29. package/dist/src/bindings/display_window.js +1 -0
  30. package/dist/src/bindings/display_window_request.d.ts +7 -0
  31. package/dist/src/bindings/display_window_request.js +2 -0
  32. package/dist/src/bindings/display_window_with_start_point.d.ts +6 -0
  33. package/dist/src/bindings/display_window_with_start_point.js +1 -0
  34. package/dist/src/bindings/edit_action.d.ts +1 -1
  35. package/dist/src/bindings/edit_payload.d.ts +27 -3
  36. package/dist/src/bindings/ephemeral_cell_input.d.ts +5 -0
  37. package/dist/src/bindings/ephemeral_cell_input.js +2 -0
  38. package/dist/src/bindings/ephemeral_cell_style_update.d.ts +6 -0
  39. package/dist/src/bindings/ephemeral_cell_style_update.js +1 -0
  40. package/dist/src/bindings/fill.d.ts +1 -1
  41. package/dist/src/bindings/horizontal_alignment.d.ts +1 -0
  42. package/dist/src/bindings/horizontal_alignment.js +2 -0
  43. package/dist/src/bindings/index.d.ts +19 -17
  44. package/dist/src/bindings/index.js +19 -17
  45. package/dist/src/bindings/line_format_brush.d.ts +9 -0
  46. package/dist/src/bindings/line_format_brush.js +2 -0
  47. package/dist/src/bindings/line_style_update.d.ts +8 -0
  48. package/dist/src/bindings/line_style_update.js +1 -0
  49. package/dist/src/bindings/merge_cell.d.ts +4 -4
  50. package/dist/src/bindings/merge_cells.d.ts +7 -0
  51. package/dist/src/bindings/merge_cells.js +2 -0
  52. package/dist/src/bindings/msg_sequencer_message.d.ts +1 -1
  53. package/dist/src/bindings/msg_user_message.d.ts +1 -1
  54. package/dist/src/bindings/payloads_action.d.ts +1 -0
  55. package/dist/src/bindings/sheet_dimension.d.ts +6 -0
  56. package/dist/src/bindings/sheet_dimension.js +2 -0
  57. package/dist/src/bindings/sheet_info.d.ts +6 -0
  58. package/dist/src/bindings/sheet_info.js +2 -0
  59. package/dist/src/bindings/split_merged_cells.d.ts +5 -0
  60. package/dist/src/bindings/split_merged_cells.js +2 -0
  61. package/dist/src/bindings/st_border_style.d.ts +1 -1
  62. package/dist/src/bindings/st_font_scheme.d.ts +1 -1
  63. package/dist/src/bindings/st_gradient_type.d.ts +1 -1
  64. package/dist/src/bindings/st_pattern_type.d.ts +1 -1
  65. package/dist/src/bindings/st_underline_values.d.ts +1 -1
  66. package/dist/src/bindings/st_vertical_align_run.d.ts +1 -1
  67. package/dist/src/bindings/status_code.d.ts +3 -2
  68. package/dist/src/bindings/status_code.js +0 -1
  69. package/dist/src/bindings/style.d.ts +2 -2
  70. package/dist/src/bindings/style_update_type.d.ts +2 -0
  71. package/dist/src/bindings/value.d.ts +1 -1
  72. package/dist/src/bindings/vertical_alignment.d.ts +1 -0
  73. package/dist/src/bindings/vertical_alignment.js +2 -0
  74. package/dist/src/bindings/workbook_update_type.d.ts +1 -0
  75. package/dist/src/bindings/workbook_update_type.js +2 -0
  76. package/dist/src/client.d.ts +82 -0
  77. package/dist/src/client.js +1 -0
  78. package/dist/src/index.d.ts +2 -1
  79. package/dist/src/index.js +1 -0
  80. package/dist/src/payloads/cell_clear.d.ts +15 -0
  81. package/dist/src/payloads/cell_clear.js +31 -0
  82. package/dist/src/payloads/cell_format_brush.d.ts +30 -0
  83. package/dist/src/payloads/cell_format_brush.js +71 -0
  84. package/dist/src/payloads/index.d.ts +28 -6
  85. package/dist/src/payloads/index.js +14 -3
  86. package/dist/src/payloads/line_format_brush.d.ts +27 -0
  87. package/dist/src/payloads/line_format_brush.js +63 -0
  88. package/dist/src/payloads/merge_cells.d.ts +21 -0
  89. package/dist/src/payloads/merge_cells.js +47 -0
  90. package/dist/src/payloads/set_cell_alignment.d.ts +19 -0
  91. package/dist/src/payloads/set_cell_alignment.js +39 -0
  92. package/dist/src/payloads/set_cell_border.d.ts +49 -0
  93. package/dist/src/payloads/set_cell_border.js +97 -0
  94. package/dist/src/payloads/set_cell_font.d.ts +46 -0
  95. package/dist/src/payloads/set_cell_font.js +91 -0
  96. package/dist/src/payloads/set_cell_pattern_fill.d.ts +25 -0
  97. package/dist/src/payloads/set_cell_pattern_fill.js +49 -0
  98. package/dist/src/payloads/set_line_alignment.d.ts +22 -0
  99. package/dist/src/payloads/set_line_alignment.js +47 -0
  100. package/dist/src/payloads/set_line_border.d.ts +49 -0
  101. package/dist/src/payloads/set_line_border.js +97 -0
  102. package/dist/src/payloads/set_line_font.d.ts +49 -0
  103. package/dist/src/payloads/set_line_font.js +99 -0
  104. package/dist/src/payloads/set_line_pattern_fill.d.ts +28 -0
  105. package/dist/src/payloads/set_line_pattern_fill.js +57 -0
  106. package/dist/src/payloads/split_merged_cells.d.ts +15 -0
  107. package/dist/src/payloads/split_merged_cells.js +31 -0
  108. package/dist/src/transactions.d.ts +9 -3
  109. package/dist/src/transactions.js +15 -4
  110. package/package.json +2 -2
  111. package/wasm/.gitignore +0 -1
  112. package/wasm/logisheets_wasm_server.d.ts +0 -255
  113. package/wasm/logisheets_wasm_server.js +0 -946
  114. package/wasm/logisheets_wasm_server_bg.wasm +0 -0
  115. package/wasm/logisheets_wasm_server_bg.wasm.d.ts +0 -40
  116. package/wasm/package.json +0 -14
@@ -0,0 +1,21 @@
1
+ export declare class BlockManager {
2
+ constructor(checkBindBlock: (sheetIdx: number, blockId: number, rowCount: number, colCount: number) => boolean, getAvailableBlockId: (sheetIdx: number) => number);
3
+ /**
4
+ * Todo: make sure that the block/craft will never be changed by other
5
+ * crafts.
6
+ */
7
+ bindBlock(sheetIdx: number, blockId: number, rowCount: number, colCount: number): boolean;
8
+ /**
9
+ * This function should only find the greatest block id when the available block id
10
+ * has been set. After that, it will always use the cached value.
11
+ * This means that every time you call this function after initialization,
12
+ * it will return a new block id. It will lead to the waste of block ids if you don't create
13
+ * a block with this id.
14
+ *
15
+ * Block id is `usize` in `WASM` side. It should be enough for most cases even we waste some of the ids.
16
+ */
17
+ getAvailableBlockId(sheetIdx: number): number;
18
+ private sheetAvailableBlockIds;
19
+ private _checkBindBlock;
20
+ private _getAvailableBlockId;
21
+ }
@@ -0,0 +1,35 @@
1
+ export class BlockManager {
2
+ constructor(checkBindBlock, getAvailableBlockId) {
3
+ this._checkBindBlock = checkBindBlock;
4
+ this._getAvailableBlockId = getAvailableBlockId;
5
+ }
6
+ /**
7
+ * Todo: make sure that the block/craft will never be changed by other
8
+ * crafts.
9
+ */
10
+ bindBlock(sheetIdx, blockId, rowCount, colCount) {
11
+ return this._checkBindBlock(sheetIdx, blockId, rowCount, colCount);
12
+ }
13
+ /**
14
+ * This function should only find the greatest block id when the available block id
15
+ * has been set. After that, it will always use the cached value.
16
+ * This means that every time you call this function after initialization,
17
+ * it will return a new block id. It will lead to the waste of block ids if you don't create
18
+ * a block with this id.
19
+ *
20
+ * Block id is `usize` in `WASM` side. It should be enough for most cases even we waste some of the ids.
21
+ */
22
+ getAvailableBlockId(sheetIdx) {
23
+ if (this.sheetAvailableBlockIds.has(sheetIdx)) {
24
+ const result = this.sheetAvailableBlockIds.get(sheetIdx);
25
+ this.sheetAvailableBlockIds.set(sheetIdx, result + 1);
26
+ return result;
27
+ }
28
+ const id = this._getAvailableBlockId(sheetIdx);
29
+ this.sheetAvailableBlockIds.set(sheetIdx, id);
30
+ return id;
31
+ }
32
+ sheetAvailableBlockIds = new Map();
33
+ _checkBindBlock;
34
+ _getAvailableBlockId;
35
+ }
@@ -0,0 +1,19 @@
1
+ import { AsyncFuncResult, Task } from '../bindings';
2
+ export declare const enum CalcException {
3
+ Unspecified = 0,
4
+ ArgErr = 1,
5
+ TimeOut = 2,
6
+ NotFound = 3
7
+ }
8
+ export type Executor = (args: readonly string[]) => Promise<string | CalcException>;
9
+ export declare class CustomFunc {
10
+ readonly funcName: string;
11
+ executor: Executor;
12
+ constructor(funcName: string, executor: Executor);
13
+ }
14
+ export declare class Calculator {
15
+ calc(tasks: readonly Task[]): Promise<AsyncFuncResult>;
16
+ registry(f: CustomFunc): void;
17
+ private _exec;
18
+ private _registry;
19
+ }
@@ -0,0 +1,46 @@
1
+ export class CustomFunc {
2
+ funcName;
3
+ executor;
4
+ constructor(funcName, executor) {
5
+ this.funcName = funcName;
6
+ this.executor = executor;
7
+ }
8
+ }
9
+ export class Calculator {
10
+ async calc(tasks) {
11
+ const promises = tasks.map((t) => this._exec(t.asyncFunc, t.args));
12
+ return Promise.all(promises).then((values) => {
13
+ const res = values.map((v) => {
14
+ if (typeof v === 'string') {
15
+ return v;
16
+ }
17
+ switch (v) {
18
+ case 1 /* CalcException.ArgErr */:
19
+ return '#ARGERR!';
20
+ case 2 /* CalcException.TimeOut */:
21
+ return '#TIMEOUT!';
22
+ case 3 /* CalcException.NotFound */:
23
+ return '#NOTFOUND!';
24
+ default:
25
+ return '#UNKNOWN!';
26
+ }
27
+ });
28
+ const asyncFuncResult = {
29
+ tasks,
30
+ values: res,
31
+ };
32
+ return asyncFuncResult;
33
+ });
34
+ }
35
+ registry(f) {
36
+ this._registry.set(f.funcName, f.executor);
37
+ }
38
+ async _exec(func, args) {
39
+ const executor = this._registry.get(func);
40
+ if (executor === undefined) {
41
+ return 3 /* CalcException.NotFound */;
42
+ }
43
+ return executor(args);
44
+ }
45
+ _registry = new Map();
46
+ }
@@ -0,0 +1,28 @@
1
+ import { CellInfo, Value, Style } from '../bindings';
2
+ export declare class Cell {
3
+ constructor(cellInfo: CellInfo);
4
+ getText(): string;
5
+ getStyle(): Style;
6
+ getFormula(): string;
7
+ private _value;
8
+ private _style;
9
+ private _formula;
10
+ }
11
+ export declare class CellValue {
12
+ cellValueOneof?: {
13
+ $case: 'str';
14
+ str: string;
15
+ } | {
16
+ $case: 'number';
17
+ number: number;
18
+ } | {
19
+ $case: 'bool';
20
+ bool: boolean;
21
+ } | {
22
+ $case: 'error';
23
+ error: string;
24
+ };
25
+ get value(): string | number | boolean;
26
+ get valueStr(): string;
27
+ static from(value: Value): CellValue;
28
+ }
@@ -0,0 +1,52 @@
1
+ export class Cell {
2
+ constructor(cellInfo) {
3
+ this._value = CellValue.from(cellInfo.value);
4
+ this._formula = cellInfo.formula;
5
+ this._style = cellInfo.style;
6
+ }
7
+ getText() {
8
+ return this._value.valueStr ?? '';
9
+ }
10
+ getStyle() {
11
+ return this._style;
12
+ }
13
+ getFormula() {
14
+ return this._formula;
15
+ }
16
+ _value;
17
+ _style;
18
+ _formula = '';
19
+ }
20
+ export class CellValue {
21
+ cellValueOneof;
22
+ get value() {
23
+ if (this.cellValueOneof?.$case === 'str')
24
+ return this.cellValueOneof.str;
25
+ else if (this.cellValueOneof?.$case === 'bool')
26
+ return this.cellValueOneof.bool;
27
+ else if (this.cellValueOneof?.$case === 'error')
28
+ return this.cellValueOneof.error;
29
+ else if (this.cellValueOneof?.$case === 'number')
30
+ return this.cellValueOneof.number;
31
+ else
32
+ return '';
33
+ }
34
+ get valueStr() {
35
+ return this.value.toString();
36
+ }
37
+ static from(value) {
38
+ const v = new CellValue();
39
+ if (hasOwnProperty(value, 'str'))
40
+ v.cellValueOneof = { $case: 'str', str: value.str };
41
+ else if (hasOwnProperty(value, 'bool'))
42
+ v.cellValueOneof = { $case: 'bool', bool: value.bool };
43
+ else if (hasOwnProperty(value, 'number'))
44
+ v.cellValueOneof = { $case: 'number', number: value.number };
45
+ else if (hasOwnProperty(value, 'error'))
46
+ v.cellValueOneof = { $case: 'error', error: value.error };
47
+ return v;
48
+ }
49
+ }
50
+ function hasOwnProperty(obj, prop) {
51
+ return Object.prototype.hasOwnProperty.call(obj, prop);
52
+ }
@@ -1,2 +1,7 @@
1
1
  export * from './workbook';
2
2
  export * from './worksheet';
3
+ export { CalcException, CustomFunc, Calculator } from './calculator';
4
+ export type { Executor } from './calculator';
5
+ export * from './cell';
6
+ export { isErrorMessage, getPatternFill } from './utils';
7
+ export type { Result } from './utils';
@@ -1,2 +1,5 @@
1
1
  export * from './workbook';
2
2
  export * from './worksheet';
3
+ export { CustomFunc, Calculator } from './calculator';
4
+ export * from './cell';
5
+ export { isErrorMessage, getPatternFill } from './utils';
@@ -1,3 +1,5 @@
1
+ import { Fill, PatternFill } from '../bindings';
1
2
  import { ErrorMessage } from '../bindings/error_message';
2
3
  export declare function isErrorMessage(v: any): v is ErrorMessage;
3
- export declare type Result<V> = V | ErrorMessage;
4
+ export type Result<V> = V | ErrorMessage;
5
+ export declare function getPatternFill(v: Fill): PatternFill | null;
@@ -2,3 +2,8 @@
2
2
  export function isErrorMessage(v) {
3
3
  return 'msg' in v && 'ty' in v;
4
4
  }
5
+ export function getPatternFill(v) {
6
+ if ('patternFill' in v)
7
+ return v.patternFill;
8
+ return null;
9
+ }
@@ -1,18 +1,40 @@
1
- import { ActionEffect, AsyncFuncResult, DisplayResponse } from '../bindings';
1
+ import { ActionEffect, SheetInfo } from '../bindings';
2
2
  import { Transaction } from '../transactions';
3
3
  import { Worksheet } from './worksheet';
4
- export declare type ReturnCode = number;
4
+ import { CustomFunc } from './calculator';
5
+ import { Result } from './utils';
6
+ export type ReturnCode = number;
7
+ export type Callback = () => void;
5
8
  export declare class Workbook {
6
9
  constructor();
10
+ /**
11
+ * @returns the block id if success, otherwise the error message
12
+ *
13
+ * It is caller's responsibility to store the block id.
14
+ */
15
+ createBlockForNewCraft(sheetIdx: number, masterRow: number, masterCol: number, rowCount: number, colCount: number): Result<number>;
7
16
  undo(): boolean;
8
17
  redo(): boolean;
9
- execTransaction(tx: Transaction, undoable: boolean): ActionEffect;
10
- load(buf: Uint8Array, book_name: string): ReturnCode;
18
+ registerCellUpdatedCallback(callback: Callback): void;
19
+ registerSheetInfoUpdateCallback(callback: Callback): void;
20
+ getAllSheetInfo(): Array<SheetInfo>;
21
+ checkFormula(f: string): boolean;
22
+ calcCondition(sheetIdx: number, f: string): Result<boolean>;
23
+ getSheetId(sheetIdx: number): Result<number>;
24
+ execTransaction(tx: Transaction): ActionEffect;
25
+ load(buf: Uint8Array, bookName: string): ReturnCode;
11
26
  release(): void;
12
- inputAsyncResult(r: AsyncFuncResult): ActionEffect;
13
- getPatches(sheet_idx: number, version: number): DisplayResponse;
14
- get_sheet_count(): number;
15
- get_worksheet(idx: number): Worksheet;
27
+ getSheetCount(): number;
28
+ getWorksheet(idx: number): Worksheet;
29
+ getWorksheetById(id: number): Worksheet;
30
+ registryCustomFunc(customFunc: CustomFunc): void;
16
31
  private _addPayload;
32
+ private _inputAsyncResult;
33
+ private _onCellUpdate;
34
+ private _onSheetUpdate;
35
+ private _cellUpdatedCallbacks;
36
+ private _sheetInfoUpdatedCallbacks;
17
37
  private _id;
38
+ private _blockManager;
39
+ private _calculator;
18
40
  }
@@ -1,43 +1,140 @@
1
- import { new_workbook, undo, redo, transaction_end, transaction_start, cell_input, row_insert, row_delete, col_insert, col_delete, create_block, move_block, block_input, set_font, set_border, read_file, release, input_async_result, get_patches, block_line_shift, sheet_rename_by_idx, sheet_rename_by_name, create_sheet, delete_sheet, get_sheet_count, } from '../../wasm/logisheets_wasm_server';
1
+ import { block_input, block_line_shift, calc_condition, cell_clear, cell_input, check_bind_block, check_formula, col_delete, col_insert, create_block, create_sheet, delete_sheet, get_all_sheet_info, get_available_block_id, get_sheet_count, get_sheet_id, input_async_result, merge_cells, move_block, new_workbook, read_file, redo, release, row_delete, row_insert, set_cell_alignment, set_cell_border, set_cell_format_brush, set_cell_pattern_fill, set_col_width, set_font, set_line_alignment, set_line_border, set_line_font, set_line_format_brush, set_line_pattern_fill, set_row_height, sheet_rename_by_idx, sheet_rename_by_name, split_merged_cells, transaction_end, transaction_start, undo, } from '../../wasm/logisheets_wasm_server';
2
+ import { Transaction } from '../transactions';
2
3
  import { Worksheet } from './worksheet';
4
+ import { Calculator } from './calculator';
5
+ import { BlockManager } from './block_manager';
3
6
  export class Workbook {
4
7
  constructor() {
5
8
  this._id = new_workbook();
9
+ this._blockManager = new BlockManager((sheetIdx, blockId, rowCount, colCount) => {
10
+ return check_bind_block(this._id, sheetIdx, blockId, rowCount, colCount);
11
+ }, (sheetIdx) => {
12
+ return get_available_block_id(this._id, sheetIdx);
13
+ });
14
+ }
15
+ /**
16
+ * @returns the block id if success, otherwise the error message
17
+ *
18
+ * It is caller's responsibility to store the block id.
19
+ */
20
+ createBlockForNewCraft(sheetIdx, masterRow, masterCol, rowCount, colCount) {
21
+ const id = this._blockManager.getAvailableBlockId(sheetIdx);
22
+ const effect = this.execTransaction(new Transaction([
23
+ {
24
+ type: 'createBlock',
25
+ sheetIdx,
26
+ blockId: id,
27
+ masterRow,
28
+ masterCol,
29
+ rowCnt: rowCount,
30
+ colCnt: colCount,
31
+ },
32
+ ], false));
33
+ if ('err' in effect.status) {
34
+ return {
35
+ msg: 'failed to create block',
36
+ ty: effect.status.err,
37
+ };
38
+ }
39
+ const bind = this._blockManager.bindBlock(sheetIdx, id, rowCount, colCount);
40
+ if (!bind) {
41
+ return {
42
+ msg: 'failed to bind block',
43
+ ty: 1,
44
+ };
45
+ }
46
+ return id;
6
47
  }
7
48
  undo() {
8
- return undo(this._id);
49
+ const result = undo(this._id);
50
+ if (result) {
51
+ this._onCellUpdate();
52
+ this._onSheetUpdate();
53
+ }
54
+ return result;
9
55
  }
10
56
  redo() {
11
- return redo(this._id);
57
+ const result = redo(this._id);
58
+ if (result) {
59
+ this._onCellUpdate();
60
+ this._onSheetUpdate();
61
+ }
62
+ return result;
63
+ }
64
+ registerCellUpdatedCallback(callback) {
65
+ this._cellUpdatedCallbacks.push(callback);
12
66
  }
13
- execTransaction(tx, undoable) {
67
+ registerSheetInfoUpdateCallback(callback) {
68
+ this._sheetInfoUpdatedCallbacks.push(callback);
69
+ }
70
+ getAllSheetInfo() {
71
+ return get_all_sheet_info(this._id);
72
+ }
73
+ checkFormula(f) {
74
+ return check_formula(this._id, f);
75
+ }
76
+ calcCondition(sheetIdx, f) {
77
+ return calc_condition(this._id, sheetIdx, f);
78
+ }
79
+ getSheetId(sheetIdx) {
80
+ return get_sheet_id(this._id, sheetIdx);
81
+ }
82
+ execTransaction(tx) {
14
83
  transaction_start(this._id);
15
84
  tx.payloads.forEach((p) => {
16
85
  this._addPayload(p);
17
86
  });
18
- return transaction_end(this._id, undoable);
87
+ const result = transaction_end(this._id, tx.undoable);
88
+ if (result.asyncTasks.length > 0) {
89
+ const asyncResult = this._calculator.calc(result.asyncTasks);
90
+ asyncResult.then((result) => {
91
+ this._inputAsyncResult(result);
92
+ this._onCellUpdate();
93
+ });
94
+ }
95
+ if ('ok' in result.status) {
96
+ switch (result.status.ok) {
97
+ case 'cell':
98
+ this._onCellUpdate();
99
+ break;
100
+ case 'sheet':
101
+ this._onSheetUpdate();
102
+ break;
103
+ case 'sheetAndCell':
104
+ this._onCellUpdate();
105
+ this._onSheetUpdate();
106
+ break;
107
+ case 'undoNothing':
108
+ case 'redoNothing':
109
+ case 'doNothing':
110
+ break;
111
+ default:
112
+ this._onCellUpdate();
113
+ this._onSheetUpdate();
114
+ }
115
+ }
116
+ return result;
19
117
  }
20
- load(buf, book_name) {
21
- return read_file(this._id, book_name, buf);
118
+ load(buf, bookName) {
119
+ return read_file(this._id, bookName, buf);
22
120
  }
23
121
  release() {
24
122
  release(this._id);
25
123
  }
26
- inputAsyncResult(r) {
27
- return input_async_result(this._id, r);
28
- }
29
- getPatches(sheet_idx, version) {
30
- const res = get_patches(this._id, sheet_idx, version);
31
- return res;
32
- }
33
- get_sheet_count() {
124
+ getSheetCount() {
34
125
  return get_sheet_count(this._id);
35
126
  }
36
- get_worksheet(idx) {
37
- if (idx >= this.get_sheet_count())
127
+ getWorksheet(idx) {
128
+ if (idx >= this.getSheetCount())
38
129
  throw Error(`invalid sheet index: ${idx}`);
39
130
  return new Worksheet(this._id, idx);
40
131
  }
132
+ getWorksheetById(id) {
133
+ return new Worksheet(this._id, id, false);
134
+ }
135
+ registryCustomFunc(customFunc) {
136
+ this._calculator.registry(customFunc);
137
+ }
41
138
  _addPayload(p) {
42
139
  if (p.type === 'cellInput')
43
140
  return cell_input(this._id, p.sheetIdx, p.row, p.col, p.input);
@@ -53,10 +150,14 @@ export class Workbook {
53
150
  return create_block(this._id, p.sheetIdx, p.blockId, p.masterRow, p.masterCol, p.rowCnt, p.colCnt);
54
151
  if (p.type === 'moveBlock')
55
152
  return move_block(this._id, p.sheetIdx, p.blockId, p.newMasterRow, p.newMasterCol);
56
- if (p.type === 'setBorder')
57
- return set_border(this._id, p.sheetIdx, p.row, p.col, p.leftColor, p.rightColor, p.topColor, p.bottomColor, p.leftBorderType, p.rightBorderType, p.topBorderType, p.bottomBorderType, p.outline, p.diagonalUp, p.diagonalDown);
58
- if (p.type === 'setFont')
153
+ if (p.type === 'setCellBorder')
154
+ return set_cell_border(this._id, p.sheetIdx, p.row, p.col, p.leftColor, p.rightColor, p.topColor, p.bottomColor, p.leftBorderType, p.rightBorderType, p.topBorderType, p.bottomBorderType, p.outline, p.diagonalUp, p.diagonalDown);
155
+ if (p.type === 'setLineBorder')
156
+ return set_line_border(this._id, p.sheetIdx, p.row, p.line, p.leftColor, p.rightColor, p.topColor, p.bottomColor, p.leftBorderType, p.rightBorderType, p.topBorderType, p.bottomBorderType, p.outline, p.diagonalUp, p.diagonalDown);
157
+ if (p.type === 'setCellFont')
59
158
  return set_font(this._id, p.sheetIdx, p.row, p.col, p.bold, p.italic, p.name, p.underline, p.color, p.size, p.outline, p.shadow, p.strike, p.condense);
159
+ if (p.type === 'setLineFont')
160
+ return set_line_font(this._id, p.sheetIdx, p.from, p.to, p.row, p.bold, p.italic, p.name, p.underline, p.color, p.size, p.outline, p.shadow, p.strike, p.condense);
60
161
  if (p.type === 'blockInput')
61
162
  return block_input(this._id, p.sheetIdx, p.blockId, p.row, p.col, p.input);
62
163
  if (p.type === 'insertBlockCols')
@@ -79,9 +180,48 @@ export class Workbook {
79
180
  return delete_sheet(this._id, p.sheetIdx);
80
181
  if (p.type === 'insertSheet')
81
182
  return create_sheet(this._id, p.sheetIdx, p.name);
183
+ if (p.type === 'cellClear')
184
+ return cell_clear(this._id, p.sheetIdx, p.row, p.col);
185
+ if (p.type === 'setColWidth')
186
+ return set_col_width(this._id, p.sheetIdx, p.col, p.width);
187
+ if (p.type === 'setRowHeight')
188
+ return set_row_height(this._id, p.sheetIdx, p.row, p.height);
189
+ if (p.type === 'setLineAlignment')
190
+ return set_line_alignment(this._id, p.sheetIdx, p.row, p.from, p.to, p.alignment.horizontal, p.alignment.vertical);
191
+ if (p.type === 'setCellAlignment')
192
+ return set_cell_alignment(this._id, p.sheetIdx, p.row, p.col, p.alignment.horizontal, p.alignment.vertical);
193
+ if (p.type === 'setCellPatternFill')
194
+ return set_cell_pattern_fill(this._id, p.sheetIdx, p.row, p.col, p.fgColor, p.bgColor, p.pattern);
195
+ if (p.type === 'setLinePatternFill')
196
+ return set_line_pattern_fill(this._id, p.sheetIdx, p.row, p.from, p.to, p.fgColor, p.bgColor, p.pattern);
197
+ if (p.type === 'mergeCells')
198
+ return merge_cells(this._id, p.sheetIdx, p.startRow, p.startCol, p.endRow, p.endCol);
199
+ if (p.type === 'splitMergedCells')
200
+ return split_merged_cells(this._id, p.sheetIdx, p.row, p.col);
201
+ if (p.type === 'cellFormatBrush')
202
+ return set_cell_format_brush(this._id, p.srcSheetIdx, p.srcRow, p.srcCol, p.dstSheetIdx, p.dstRowStart, p.dstColStart, p.dstRowEnd, p.dstColEnd);
203
+ if (p.type === 'lineFormatBrush')
204
+ return set_line_format_brush(this._id, p.srcSheetIdx, p.srcRow, p.srcCol, p.dstSheetIdx, p.row, p.from, p.to);
82
205
  // eslint-disable-next-line no-console
83
- console.log('Unimplemented!');
206
+ console.log(`Unimplemented!: ${p.type}`);
207
+ }
208
+ _inputAsyncResult(r) {
209
+ return input_async_result(this._id, r);
210
+ }
211
+ _onCellUpdate() {
212
+ this._cellUpdatedCallbacks.forEach((exec) => {
213
+ exec();
214
+ });
215
+ }
216
+ _onSheetUpdate() {
217
+ this._sheetInfoUpdatedCallbacks.forEach((exec) => {
218
+ exec();
219
+ });
84
220
  }
221
+ _cellUpdatedCallbacks = [];
222
+ _sheetInfoUpdatedCallbacks = [];
85
223
  // The book id which is generated by `WASM`
86
224
  _id;
225
+ _blockManager;
226
+ _calculator = new Calculator();
87
227
  }
@@ -1,16 +1,24 @@
1
- import { ColInfo, RowInfo, Style, Value } from '../bindings';
2
- import { CellInfo } from '../bindings/cell_info';
1
+ import { BlockInfo, CellPosition, ColInfo, DisplayWindow, DisplayWindowWithStartPoint, RowInfo, Style, Value, CellInfo, SheetDimension, MergeCell } from '../bindings';
2
+ import { Cell } from './cell';
3
3
  import { Result } from './utils';
4
4
  export declare class Worksheet {
5
- constructor(id: number, idx: number);
6
- get_row_height(row_idx: number): Result<number>;
7
- get_col_width(col_idx: number): Result<number>;
8
- get_row_info(row_idx: number): Result<RowInfo>;
9
- get_col_info(col_idx: number): Result<ColInfo>;
10
- get_cell_info(row_idx: number, col_idx: number): Result<CellInfo>;
11
- get_formula(row_idx: number, col_idx: number): Result<string>;
12
- get_style(row_idx: number, col_idx: number): Result<Style>;
13
- get_value(row_idx: number, col_idx: number): Result<Value>;
5
+ constructor(id: number, sheetIdxOrId: number, isSheetIdx?: boolean);
6
+ getSheetDimension(): Result<SheetDimension>;
7
+ getDisplayWindow(startRow: number, endRow: number, startCol: number, endCol: number): Result<DisplayWindow>;
8
+ getDisplayWindowWithStartPoint(startX: number, startY: number, height: number, width: number): DisplayWindowWithStartPoint;
9
+ getCellPosition(row: number, col: number): CellPosition;
10
+ getDisplayWindowWithCellPosition(row: number, col: number, height: number, width: number): DisplayWindowWithStartPoint;
11
+ getRowHeight(rowIdx: number): Result<number>;
12
+ getColWidth(colIdx: number): Result<number>;
13
+ getRowInfo(rowIdx: number): Result<RowInfo>;
14
+ getColInfo(colIdx: number): Result<ColInfo>;
15
+ getCellInfo(rowIdx: number, colIdx: number): Result<CellInfo>;
16
+ getMergedCells(startRow: number, startCol: number, endRow: number, endCol: number): readonly MergeCell[];
17
+ getCell(rowIdx: number, colIdx: number): Result<Cell>;
18
+ getFormula(rowIdx: number, colIdx: number): Result<string>;
19
+ getStyle(rowIdx: number, colIdx: number): Result<Style>;
20
+ getValue(rowIdx: number, colIdx: number): Result<Value>;
21
+ getFullyCoveredBlocks(rowIdx: number, colIdx: number, rowCnt: number, colCnt: number): Result<BlockInfo[]>;
14
22
  private _id;
15
- private _sheetIdx;
23
+ private _sheetId;
16
24
  }
@@ -1,33 +1,71 @@
1
- import { get_cell_info, get_col_info, get_col_width, get_formula, get_row_height, get_row_info, get_style, get_value, } from '../../wasm';
1
+ import { get_cell_info, get_col_info, get_col_width, get_formula, get_row_height, get_row_info, get_style, get_value, get_display_window, get_display_window_with_start_point, get_display_window_within_cell, get_cell_position, get_all_fully_covered_blocks, get_sheet_dimension, get_sheet_id, } from '../../wasm';
2
+ import { get_merged_cells } from '../../wasm/logisheets_wasm_server';
3
+ import { Cell } from './cell';
4
+ import { isErrorMessage } from './utils';
2
5
  export class Worksheet {
3
- constructor(id, idx) {
6
+ constructor(id, sheetIdxOrId, isSheetIdx = true) {
4
7
  this._id = id;
5
- this._sheetIdx = idx;
8
+ if (isSheetIdx) {
9
+ this._sheetId = get_sheet_id(id, sheetIdxOrId);
10
+ }
11
+ else {
12
+ this._sheetId = sheetIdxOrId;
13
+ }
6
14
  }
7
- get_row_height(row_idx) {
8
- return get_row_height(this._id, this._sheetIdx, row_idx);
15
+ getSheetDimension() {
16
+ return get_sheet_dimension(this._id, this._sheetId);
9
17
  }
10
- get_col_width(col_idx) {
11
- return get_col_width(this._id, this._sheetIdx, col_idx);
18
+ getDisplayWindow(startRow, endRow, startCol, endCol) {
19
+ return get_display_window(this._id, this._sheetId, startRow, endRow, startCol, endCol);
12
20
  }
13
- get_row_info(row_idx) {
14
- return get_row_info(this._id, this._sheetIdx, row_idx);
21
+ getDisplayWindowWithStartPoint(startX, startY, height, width) {
22
+ return get_display_window_with_start_point(this._id, this._sheetId, startX, startY, height, width);
15
23
  }
16
- get_col_info(col_idx) {
17
- return get_col_info(this._id, this._sheetIdx, col_idx);
24
+ getCellPosition(row, col) {
25
+ const result = get_cell_position(this._id, this._sheetId, row, col);
26
+ return result;
18
27
  }
19
- get_cell_info(row_idx, col_idx) {
20
- return get_cell_info(this._id, this._sheetIdx, row_idx, col_idx);
28
+ getDisplayWindowWithCellPosition(row, col, height, width) {
29
+ return get_display_window_within_cell(this._id, this._sheetId, row, col, height, width);
21
30
  }
22
- get_formula(row_idx, col_idx) {
23
- return get_formula(this._id, this._sheetIdx, row_idx, col_idx);
31
+ getRowHeight(rowIdx) {
32
+ return get_row_height(this._id, this._sheetId, rowIdx);
24
33
  }
25
- get_style(row_idx, col_idx) {
26
- return get_style(this._id, this._sheetIdx, row_idx, col_idx);
34
+ getColWidth(colIdx) {
35
+ return get_col_width(this._id, this._sheetId, colIdx);
27
36
  }
28
- get_value(row_idx, col_idx) {
29
- return get_value(this._id, this._sheetIdx, row_idx, col_idx);
37
+ getRowInfo(rowIdx) {
38
+ return get_row_info(this._id, this._sheetId, rowIdx);
39
+ }
40
+ getColInfo(colIdx) {
41
+ return get_col_info(this._id, this._sheetId, colIdx);
42
+ }
43
+ getCellInfo(rowIdx, colIdx) {
44
+ const cellInfo = get_cell_info(this._id, this._sheetId, rowIdx, colIdx);
45
+ return cellInfo;
46
+ }
47
+ getMergedCells(startRow, startCol, endRow, endCol) {
48
+ return get_merged_cells(this._id, this._sheetId, startRow, startCol, endRow, endCol);
49
+ }
50
+ getCell(rowIdx, colIdx) {
51
+ const cellInfo = this.getCellInfo(rowIdx, colIdx);
52
+ if (isErrorMessage(cellInfo)) {
53
+ return cellInfo;
54
+ }
55
+ return new Cell(cellInfo);
56
+ }
57
+ getFormula(rowIdx, colIdx) {
58
+ return get_formula(this._id, this._sheetId, rowIdx, colIdx);
59
+ }
60
+ getStyle(rowIdx, colIdx) {
61
+ return get_style(this._id, this._sheetId, rowIdx, colIdx);
62
+ }
63
+ getValue(rowIdx, colIdx) {
64
+ return get_value(this._id, this._sheetId, rowIdx, colIdx);
65
+ }
66
+ getFullyCoveredBlocks(rowIdx, colIdx, rowCnt, colCnt) {
67
+ return get_all_fully_covered_blocks(this._id, this._sheetId, rowIdx, colIdx, rowCnt, colCnt);
30
68
  }
31
69
  _id;
32
- _sheetIdx;
70
+ _sheetId;
33
71
  }
@@ -0,0 +1,6 @@
1
+ import { HorizontalAlignment } from './horizontal_alignment';
2
+ import { VerticalAlignment } from './vertical_alignment';
3
+ export interface Alignment {
4
+ horizontal?: HorizontalAlignment;
5
+ vertical?: VerticalAlignment;
6
+ }
@@ -0,0 +1 @@
1
+ export {};