Skip to content

Commit

Permalink
feat: add line style update action
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Jan 18, 2025
1 parent 552acf5 commit 5e8978d
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 44 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
27 changes: 25 additions & 2 deletions crates/controller/src/container/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use logisheets_base::{
SheetId, TextId,
};

use crate::{cell::Cell, edit_action::EditPayload, Error};
use crate::{
cell::Cell,
edit_action::{EditPayload, StyleUpdateType},
Error,
};

use super::{ctx::ContainerExecCtx, DataContainer};

Expand Down Expand Up @@ -284,7 +288,7 @@ impl ContainerExecutor {
}
Ok((self, true))
}
EditPayload::StyleUpdate(style_update) => {
EditPayload::CellStyleUpdate(style_update) => {
let sheet_id = ctx
.fetch_sheet_id_by_index(style_update.sheet_idx)
.map_err(|l| BasicError::SheetIdxExceed(l))?;
Expand All @@ -305,6 +309,25 @@ impl ContainerExecutor {
}
Ok((self, true))
}
EditPayload::LineStyleUpdate(s) => {
let sheet_id = ctx
.fetch_sheet_id_by_index(s.sheet_idx)
.map_err(|l| BasicError::SheetIdxExceed(l))?;
for i in s.from..=s.to {
if s.row {
let row_id = ctx.fetch_row_id(&sheet_id, i)?;
let row = self.container.get_row_info_mut(sheet_id, row_id);
let new_id = ctx.get_new_style_id(row.style, s.ty.clone())?;
row.style = new_id;
} else {
let col_id = ctx.fetch_col_id(&sheet_id, i)?;
let col = self.container.get_col_info_mut(sheet_id, col_id);
let new_id = ctx.get_new_style_id(col.style, s.ty.clone())?;
col.style = new_id;
}
}
Ok((self, true))
}
_ => Ok((self, false)),
}
}
Expand Down
35 changes: 28 additions & 7 deletions crates/controller/src/edit_action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ pub enum EditPayload {
CreateBlock(CreateBlock),

// Style
StyleUpdate(StyleUpdate),
CellStyleUpdate(CellStyleUpdate),
LineStyleUpdate(LineStyleUpdate),
BlockStyleUpdate(BlockStyleUpdate),

CellInput(CellInput),
Expand Down Expand Up @@ -454,15 +455,28 @@ use logisheets_workbook::prelude::*;
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "gents",
gents_derives::gents_header(file_name = "style_update.ts")
gents_derives::gents_header(file_name = "cell_style_update.ts")
)]
pub struct StyleUpdate {
pub struct CellStyleUpdate {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
pub ty: StyleUpdateType,
}

#[derive(Debug, Clone)]
#[cfg_attr(
feature = "gents",
gents_derives::gents_header(file_name = "line_style_update.ts")
)]
pub struct LineStyleUpdate {
pub sheet_idx: usize,
pub from: usize,
pub to: usize,
pub ty: StyleUpdateType,
pub row: bool,
}

pub type Color = String;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -540,11 +554,17 @@ impl From<SheetRename> for EditPayload {
EditPayload::SheetRename(value)
}
}
impl From<StyleUpdate> for EditPayload {
fn from(value: StyleUpdate) -> Self {
EditPayload::StyleUpdate(value)
impl From<CellStyleUpdate> for EditPayload {
fn from(value: CellStyleUpdate) -> Self {
EditPayload::CellStyleUpdate(value)
}
}
impl From<LineStyleUpdate> for EditPayload {
fn from(value: LineStyleUpdate) -> Self {
EditPayload::LineStyleUpdate(value)
}
}

impl From<InsertCols> for EditPayload {
fn from(value: InsertCols) -> Self {
EditPayload::InsertCols(value)
Expand Down Expand Up @@ -613,7 +633,8 @@ impl Payload for SetVisible {}
impl Payload for SheetRename {}
impl Payload for CreateSheet {}
impl Payload for DeleteSheet {}
impl Payload for StyleUpdate {}
impl Payload for CellStyleUpdate {}
impl Payload for LineStyleUpdate {}
impl Payload for InsertCols {}
impl Payload for InsertRows {}
impl Payload for DeleteCols {}
Expand Down
8 changes: 7 additions & 1 deletion crates/controller/src/version_manager/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn convert_diff<C: VersionExecCtx>(
.map_err(|l| BasicError::SheetIdxExceed(l))?;
Ok(Some((Diff::Unavailable, sheet_id)))
}
EditPayload::StyleUpdate(p) => {
EditPayload::CellStyleUpdate(p) => {
let sheet_id = ctx
.fetch_sheet_id_by_index(p.sheet_idx)
.map_err(|l| BasicError::SheetIdxExceed(l))?;
Expand Down Expand Up @@ -202,5 +202,11 @@ fn convert_diff<C: VersionExecCtx>(
let cell_id = ctx.fetch_cell_id(&sheet_id, cr.row, cr.col)?;
Ok(Some((Diff::CellValue(cell_id), sheet_id)))
}
EditPayload::LineStyleUpdate(p) => {
let sheet_id = ctx
.fetch_sheet_id_by_index(p.sheet_idx)
.map_err(|l| BasicError::SheetIdxExceed(l))?;
Ok(Some((Diff::Unavailable, sheet_id)))
}
}
}
63 changes: 57 additions & 6 deletions crates/wasms/server/src/controller.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use logisheets_controller::controller::display::{CellPosition, DisplaySheetRequest};
use logisheets_controller::edit_action::{
AsyncFuncResult, BlockInput, CellClear, CellInput, CreateBlock, CreateSheet, DeleteCols,
DeleteColsInBlock, DeleteRows, DeleteRowsInBlock, DeleteSheet, EditAction, EditPayload,
InsertCols, InsertColsInBlock, InsertRows, InsertRowsInBlock, MoveBlock, PayloadsAction,
SetColWidth, SetRowHeight, SheetRename, StyleUpdate, StyleUpdateType,
AsyncFuncResult, BlockInput, CellClear, CellInput, CellStyleUpdate, CreateBlock, CreateSheet,
DeleteCols, DeleteColsInBlock, DeleteRows, DeleteRowsInBlock, DeleteSheet, EditAction,
EditPayload, InsertCols, InsertColsInBlock, InsertRows, InsertRowsInBlock, LineStyleUpdate,
MoveBlock, PayloadsAction, SetColWidth, SetRowHeight, SheetRename, StyleUpdateType,
};
use logisheets_controller::{AsyncCalcResult, AsyncErr, RowInfo, SaveFileResult, Workbook};
use logisheets_controller::{ColInfo, ErrorMessage};
Expand Down Expand Up @@ -403,6 +403,57 @@ pub fn get_display_window_within_cell(
result
}

#[wasm_bindgen]
pub fn set_line_font(
id: usize,
sheet_idx: usize,
from: usize,
to: usize,
row: bool,
bold: Option<bool>,
italic: Option<bool>,
name: Option<String>,
underline: Option<String>,
color: Option<String>,
size: Option<f64>,
outline: Option<bool>,
shadow: Option<bool>,
strike: Option<bool>,
condense: Option<bool>,
) {
let p = EditPayload::LineStyleUpdate(LineStyleUpdate {
sheet_idx,
from,
to,
row,
ty: StyleUpdateType {
set_font_bold: bold,
set_font_italic: italic,
set_font_underline: underline.map(|s| StUnderlineValues::deserialize(&s).unwrap()),
set_font_color: color,
set_font_size: size,
set_font_name: name,
set_font_outline: outline,
set_font_shadow: shadow,
set_font_strike: strike,
set_font_condense: condense,
set_left_border_color: None,
set_right_border_color: None,
set_top_border_color: None,
set_bottom_border_color: None,
set_left_border_style: None,
set_right_border_style: None,
set_top_border_style: None,
set_bottom_border_style: None,
set_border_giagonal_up: None,
set_border_giagonal_down: None,
set_border_outline: None,
set_pattern_fill: None,
},
});
MANAGER.get_mut().add_payload(id, p);
}

#[wasm_bindgen]
pub fn set_font(
id: usize,
Expand All @@ -420,7 +471,7 @@ pub fn set_font(
strike: Option<bool>,
condense: Option<bool>,
) {
let p = EditPayload::StyleUpdate(StyleUpdate {
let p = EditPayload::CellStyleUpdate(CellStyleUpdate {
sheet_idx,
row,
col,
Expand Down Expand Up @@ -470,7 +521,7 @@ pub fn set_border(
diagonal_up: Option<bool>,
diagonal_down: Option<bool>,
) {
let p = EditPayload::StyleUpdate(StyleUpdate {
let p = EditPayload::CellStyleUpdate(CellStyleUpdate {
sheet_idx,
row,
col,
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"packages/*"
],
"dependencies": {
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/icons-material": "^6.4.0",
"@mui/material": "^6.4.0",
"@types/node": "^18",
"@types/react": "^19",
"@types/react-color": "^3.0.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DO NOT EDIT. CODE GENERATED BY gents.
import {StyleUpdateType} from './style_update_type'

export interface StyleUpdate {
export interface CellStyleUpdate {
sheetIdx: number
row: number
col: number
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/bindings/edit_payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {BlockInput} from './block_input'
import {BlockStyleUpdate} from './block_style_update'
import {CellClear} from './cell_clear'
import {CellInput} from './cell_input'
import {CellStyleUpdate} from './cell_style_update'
import {CreateBlock} from './create_block'
import {CreateSheet} from './create_sheet'
import {DeleteColsInBlock} from './delete_cols_in_block'
Expand All @@ -14,13 +15,13 @@ 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 {LineStyleUpdate} from './line_style_update'
import {MoveBlock} from './move_block'
import {RemoveBlock} from './remove_block'
import {SetColWidth} from './set_col_width'
import {SetRowHeight} from './set_row_height'
import {SetVisible} from './set_visible'
import {SheetRename} from './sheet_rename'
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.
Expand All @@ -29,7 +30,8 @@ export type EditPayload =
| {moveBlock: MoveBlock}
| {removeBlock: RemoveBlock}
| {createBlock: CreateBlock}
| {styleUpdate: StyleUpdate}
| {cellStyleUpdate: CellStyleUpdate}
| {lineStyleUpdate: LineStyleUpdate}
| {blockStyleUpdate: BlockStyleUpdate}
| {cellInput: CellInput}
| {cellClear: CellClear}
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './cell_input'
export * from './cell_position'
export * from './cell_protection'
export * from './cell_style'
export * from './cell_style_update'
export * from './col_info'
export * from './color'
export * from './comment'
Expand Down Expand Up @@ -46,6 +47,7 @@ export * from './insert_cols'
export * from './insert_cols_in_block'
export * from './insert_rows'
export * from './insert_rows_in_block'
export * from './line_style_update'
export * from './merge_cell'
export * from './move_block'
export * from './msg_edit'
Expand Down Expand Up @@ -85,7 +87,6 @@ export * from './st_vertical_align_run'
export * from './st_vertical_alignment'
export * from './status_code'
export * from './style'
export * from './style_update'
export * from './style_update_type'
export * from './task'
export * from './underline_property'
Expand Down
10 changes: 10 additions & 0 deletions packages/web/src/bindings/line_style_update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// DO NOT EDIT. CODE GENERATED BY gents.
import {StyleUpdateType} from './style_update_type'

export interface LineStyleUpdate {
sheetIdx: number
from: number
to: number
ty: StyleUpdateType
row: boolean
}
Loading

0 comments on commit 5e8978d

Please sign in to comment.