Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Dec 28, 2023
1 parent 8813747 commit dfb026a
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 42 deletions.
11 changes: 4 additions & 7 deletions packages/web/src/api/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
block_line_shift,
sheet_rename_by_idx,
sheet_rename_by_name,
sheet_shift,
create_sheet,
delete_sheet,
} from '../../wasm/logisheets_wasm_server'
import {ActionEffect, AsyncFuncResult, DisplayResponse} from '../bindings'
import {Transaction} from '../transactions'
Expand Down Expand Up @@ -190,13 +191,9 @@ export class Workbook {
return sheet_rename_by_idx(this._id, p.idx, p.newName)
}
}
if (p.type === 'deleteSheet')
return sheet_shift(this._id, p.sheetIdx, false)
if (p.type === 'deleteSheet') return delete_sheet(this._id, p.sheetIdx)
if (p.type === 'insertSheet')
return sheet_shift(this._id, p.sheetIdx, true)
// if (hasOwnProperty(p, 'SheetShift')) {
// const sheetShift = p.SheetShift as SheetShift
// }
return create_sheet(this._id, p.sheetIdx, p.name)
// eslint-disable-next-line no-console
console.log('Unimplemented!')
}
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/bindings/block_cell_id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface BlockCellId {
block_id: number
row: number
col: number
}
7 changes: 7 additions & 0 deletions packages/web/src/bindings/cell_id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.
import {BlockCellId} from './block_cell_id'
import {NormalCellId} from './normal_cell_id'

export type CellId =
| {NormalCell: NormalCellId}
| {BlockCell: BlockCellId}
6 changes: 6 additions & 0 deletions packages/web/src/bindings/create_sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface CreateSheet {
idx: number
newName: string
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface ColShift {
export interface DeleteCols {
sheetIdx: number
col: number
start: number
count: number
insert: boolean
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface LineShiftInBlock {
export interface DeleteColsInBlock {
sheetIdx: number
blockId: number
idx: number
start: number
cnt: number
horizontal: boolean
insert: boolean
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface RowShift {
export interface DeleteRows {
sheetIdx: number
row: number
start: number
count: number
insert: boolean
}
8 changes: 8 additions & 0 deletions packages/web/src/bindings/delete_rows_in_block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface DeleteRowsInBlock {
sheetIdx: number
blockId: number
start: number
cnt: number
}
5 changes: 5 additions & 0 deletions packages/web/src/bindings/delete_sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface DeleteSheet {
idx: number
}
2 changes: 2 additions & 0 deletions packages/web/src/bindings/edit_action.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// DO NOT EDIT. CODE GENERATED BY gents.
import {PayloadsAction} from './payloads_action'
import {RecalcCell} from './recalc_cell'

// `EditAction` represents your update behavior to the workbook.
export type EditAction =
| 'undo'
| 'redo'
| {payloads: PayloadsAction}
| {recalc: readonly RecalcCell[]}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@
import {BlockInput} from './block_input'
import {BlockStyleUpdate} from './block_style_update'
import {CellInput} from './cell_input'
import {ColShift} from './col_shift'
import {CreateBlock} from './create_block'
import {LineShiftInBlock} from './line_shift_in_block'
import {CreateSheet} from './create_sheet'
import {DeleteColsInBlock} from './delete_cols_in_block'
import {DeleteCols} from './delete_cols'
import {DeleteRowsInBlock} from './delete_rows_in_block'
import {DeleteRows} from './delete_rows'
import {DeleteSheet} from './delete_sheet'
import {InsertColsInBlock} from './insert_cols_in_block'
import {InsertCols} from './insert_cols'
import {InsertRowsInBlock} from './insert_rows_in_block'
import {InsertRows} from './insert_rows'
import {MoveBlock} from './move_block'
import {RemoveBlock} from './remove_block'
import {RowShift} from './row_shift'
import {SetColWidth} from './set_col_width'
import {SetRowHeight} from './set_row_height'
import {SetVisible} from './set_visible'
import {SheetRename} from './sheet_rename'
import {SheetShift} from './sheet_shift'
import {StyleUpdate} from './style_update'

// `EditPayload` is the basic update unit of the Workbook. Developers can config their own
// `EditAction` (e.g. setting a button to create a table) to facilitate their users.
export type EditPayload =
| {blockInput: BlockInput}
| {blockStyleUpdate: BlockStyleUpdate}
| {cellInput: CellInput}
| {colShift: ColShift}
| {createBlock: CreateBlock}
| {lineShiftInBlock: LineShiftInBlock}
| {moveBlock: MoveBlock}
| {removeBlock: RemoveBlock}
| {rowShift: RowShift}
| {createBlock: CreateBlock}
| {styleUpdate: StyleUpdate}
| {blockStyleUpdate: BlockStyleUpdate}
| {cellInput: CellInput}
| {setColWidth: SetColWidth}
| {setRowHeight: SetRowHeight}
| {setVisible: SetVisible}
| {sheetRename: SheetRename}
| {sheetShift: SheetShift}
| {styleUpdate: StyleUpdate}
| {createSheet: CreateSheet}
| {deleteSheet: DeleteSheet}
| {insertCols: InsertCols}
| {deleteCols: DeleteCols}
| {insertRows: InsertRows}
| {deleteRows: DeleteRows}
| {insertColsInBlock: InsertColsInBlock}
| {deleteColsInBlock: DeleteColsInBlock}
| {insertRowsInBlock: InsertRowsInBlock}
| {deleteRowsInBlock: DeleteRowsInBlock}
20 changes: 15 additions & 5 deletions packages/web/src/bindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
// DO NOT EDIT. CODE GENERATED BY gents.
export * from './action_effect'
export * from './async_func_result'
export * from './block_cell_id'
export * from './block_info'
export * from './block_input'
export * from './block_style_update'
export * from './border'
export * from './border_pr'
export * from './cell_alignment'
export * from './cell_formula_value'
export * from './cell_id'
export * from './cell_input'
export * from './cell_protection'
export * from './cell_style'
export * from './col_info'
export * from './col_shift'
export * from './color'
export * from './comment'
export * from './create_block'
export * from './create_sheet'
export * from './delete_cols'
export * from './delete_cols_in_block'
export * from './delete_rows'
export * from './delete_rows_in_block'
export * from './delete_sheet'
export * from './display_patch'
export * from './display_request'
export * from './display_response'
export * from './edit_action'
export * from './edit_payload'
export * from './fill'
export * from './font'
export * from './font_family'
export * from './font_name'
export * from './font_scheme'
export * from './gradient_fill'
export * from './gradient_stop'
export * from './line_shift_in_block'
export * from './insert_cols'
export * from './insert_cols_in_block'
export * from './insert_rows'
export * from './insert_rows_in_block'
export * from './merge_cell'
export * from './move_block'
export * from './msg_edit'
Expand All @@ -37,12 +48,12 @@ export * from './msg_sequencer_action_message'
export * from './msg_sequencer_init_workbook'
export * from './msg_sequencer_message'
export * from './msg_user_message'
export * from './normal_cell_id'
export * from './pattern_fill'
export * from './payload'
export * from './payloads_action'
export * from './recalc_cell'
export * from './remove_block'
export * from './row_info'
export * from './row_shift'
export * from './set_col_width'
export * from './set_row_height'
export * from './set_visible'
Expand All @@ -53,7 +64,6 @@ export * from './sheet_merge_cells'
export * from './sheet_names'
export * from './sheet_rename'
export * from './sheet_row_info'
export * from './sheet_shift'
export * from './sheet_styles'
export * from './sheet_values'
export * from './st_border_style'
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/bindings/insert_cols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface InsertCols {
sheetIdx: number
start: number
count: number
}
8 changes: 8 additions & 0 deletions packages/web/src/bindings/insert_cols_in_block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface InsertColsInBlock {
sheetIdx: number
blockId: number
start: number
cnt: number
}
7 changes: 7 additions & 0 deletions packages/web/src/bindings/insert_rows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface InsertRows {
sheetIdx: number
start: number
count: number
}
8 changes: 8 additions & 0 deletions packages/web/src/bindings/insert_rows_in_block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface InsertRowsInBlock {
sheetIdx: number
blockId: number
start: number
cnt: number
}
6 changes: 6 additions & 0 deletions packages/web/src/bindings/normal_cell_id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// DO NOT EDIT. CODE GENERATED BY gents.

export interface NormalCellId {
row: number
col: number
}
2 changes: 1 addition & 1 deletion packages/web/src/bindings/payloads_action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT EDIT. CODE GENERATED BY gents.
import {EditPayload} from './payload'
import {EditPayload} from './edit_payload'

// A `PayloadsAction` contains one or more `EditPayload`.
// These `EditPayload`s will be withdrawn at the same time if user undo it.
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/bindings/recalc_cell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.
import {CellId} from './cell_id'

export interface RecalcCell {
sheetId: number
cellId: CellId
}
7 changes: 0 additions & 7 deletions packages/web/src/bindings/sheet_shift.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/web/src/payloads/insert_sheet.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
export interface InsertSheet {
type: 'insertSheet'
sheetIdx: number
name: string
}

export class InsertSheetBuilder {
private _sheetIdx?: number
private _name?: string
public sheetIdx(sheetIdx: number): this {
this._sheetIdx = sheetIdx
return this
}
public name(name: string): this {
this._name = name
return this
}
public build(): InsertSheet {
if (this._sheetIdx === undefined) throw Error('sheetIdx is undefined!')
if (this._name === undefined) throw Error('name is undefined!')
return {
type: 'insertSheet',
sheetIdx: this._sheetIdx,
name: this._name,
}
}
}

0 comments on commit dfb026a

Please sign in to comment.