use crate::conditional_formatting_manager::spec::CfRuleSpec;
use gents_derives::TS;
use logisheets_base::{BlockId, CellId, ColId, EphemeralId, RowId, SheetId, async_func::Task};
pub trait Payload: Into<EditPayload> {}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "edit_action.ts", tag = "type")]
pub enum EditAction {
Undo,
Redo,
Payloads(PayloadsAction),
Recalc(Vec<RecalcCell>),
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "recalc_cell.ts", rename_all = "camelCase")]
pub struct RecalcCell {
pub sheet_id: SheetId,
pub cell_id: CellId,
}
impl EditAction {
pub fn undo() -> Self {
Self::Undo
}
pub fn redo() -> Self {
Self::Redo
}
}
impl From<PayloadsAction> for EditAction {
fn from(value: PayloadsAction) -> Self {
EditAction::Payloads(value)
}
}
#[derive(Debug, Default, Clone, TS)]
#[ts(file_name = "payloads_action.ts")]
pub struct PayloadsAction {
pub payloads: Vec<EditPayload>,
pub undoable: bool,
pub init: bool,
}
impl PayloadsAction {
pub fn new() -> Self {
PayloadsAction {
payloads: vec![],
undoable: false,
init: false,
}
}
pub fn set_undoable(mut self, v: bool) -> Self {
self.undoable = v;
self
}
pub fn set_init(mut self, v: bool) -> Self {
self.init = v;
self.undoable = false;
self
}
pub fn add_payload<P: Payload>(mut self, payload: P) -> Self {
self.payloads.push(payload.into());
self
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "edit_payload.ts", tag = "type")]
pub enum EditPayload {
BlockInput(BlockInput),
MoveBlock(MoveBlock),
RemoveBlock(RemoveBlock),
CreateBlock(CreateBlock),
ResizeBlock(ResizeBlock),
ConvertBlock(ConvertBlock),
CreateLink(CreateLink),
BindFormSchema(BindFormSchema),
UpsertFieldFormulas(UpsertFieldFormulas),
BindRandomSchema(BindRandomSchema),
UpsertFieldRenderInfo(UpsertFieldRenderInfo),
MoveBlockLine(MoveBlockLine),
ReorderBlockLines(ReorderBlockLines),
CreateDiyCell(CreateDiyCell),
CreateDiyCellById(CreateDiyCellById),
RemoveDiyCell(RemoveDiyCell),
RemoveDiyCellById(RemoveDiyCellById),
CreateAppendix(CreateAppendix),
RemoveAppendix(RemoveAppendix),
CellStyleUpdate(CellStyleUpdate),
EphemeralCellStyleUpdate(EphemeralCellStyleUpdate),
LineStyleUpdate(LineStyleUpdate),
BlockStyleUpdate(BlockStyleUpdate),
BlockLineStyleUpdate(BlockLineStyleUpdate),
BlockLineNameFieldUpdate(BlockLineNameFieldUpdate),
CellFormatBrush(CellFormatBrush),
LineFormatBrush(LineFormatBrush),
CellInput(CellInput),
EphemeralCellInput(EphemeralCellInput),
EphemeralCellRemove(EphemeralCellRemove),
CellClear(CellClear),
SetCellImage(SetCellImage),
DeleteCellImage(DeleteCellImage),
MoveChart(MoveChart),
CreateConditionalFormattingRule(CreateConditionalFormattingRule),
UpdateConditionalFormattingRule(UpdateConditionalFormattingRule),
MoveConditionalFormattingRule(MoveConditionalFormattingRule),
DeleteConditionalFormattingRule(DeleteConditionalFormattingRule),
DeleteChart(DeleteChart),
CreateChart(CreateChart),
UpdateChart(UpdateChart),
SetColWidth(SetColWidth),
SetRowHeight(SetRowHeight),
SetVisible(SetVisible),
MergeCells(MergeCells),
SplitMergedCells(SplitMergedCells),
AddComment(AddComment),
EditComment(EditComment),
DeleteComment(DeleteComment),
ResolveComment(ResolveComment),
UpsertPerson(UpsertPerson),
SheetRename(SheetRename),
CreateSheet(CreateSheet),
DeleteSheet(DeleteSheet),
SetSheetColor(SetSheetColor),
SetSheetVisible(SetSheetVisible),
InsertCols(InsertCols),
DeleteCols(DeleteCols),
InsertRows(InsertRows),
DeleteRows(DeleteRows),
InsertColsInBlock(InsertColsInBlock),
DeleteColsInBlock(DeleteColsInBlock),
InsertRowsInBlock(InsertRowsInBlock),
DeleteRowsInBlock(DeleteRowsInBlock),
ReproduceCells(ReproduceCells),
RestoreCheckpoint(RestoreCheckpoint),
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "upsert_field_render_info.ts",
builder,
rename_all = "camelCase"
)]
pub struct UpsertFieldRenderInfo {
pub render_id: String,
pub diy_render: bool,
pub style_update: StyleUpdateType,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "restore_checkpoint.ts", builder, rename_all = "camelCase")]
pub struct RestoreCheckpoint {
pub label: String,
}
impl From<RestoreCheckpoint> for EditPayload {
fn from(value: RestoreCheckpoint) -> Self {
EditPayload::RestoreCheckpoint(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "create_sheet.ts", builder, rename_all = "camelCase")]
pub struct CreateSheet {
pub idx: usize,
pub new_name: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "delete_sheet.ts", builder, rename_all = "camelCase")]
pub struct DeleteSheet {
pub idx: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "set_sheet_color.ts", builder, rename_all = "camelCase")]
pub struct SetSheetColor {
pub idx: usize,
pub color: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "set_sheet_visible.ts", builder, rename_all = "camelCase")]
pub struct SetSheetVisible {
pub idx: usize,
pub visible: bool,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_rename.ts", builder, rename_all = "camelCase")]
pub struct SheetRename {
pub old_name: Option<String>,
pub idx: Option<usize>,
pub new_name: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_format_brush.ts", builder, rename_all = "camelCase")]
pub struct CellFormatBrush {
pub src_sheet_idx: usize,
pub src_row: usize,
pub src_col: usize,
pub dst_sheet_idx: usize,
pub dst_row_start: usize,
pub dst_col_start: usize,
pub dst_row_end: usize,
pub dst_col_end: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "line_format_brush.ts", builder, rename_all = "camelCase")]
pub struct LineFormatBrush {
pub src_sheet_idx: usize,
pub src_row: usize,
pub src_col: usize,
pub dst_sheet_idx: usize,
pub row: bool,
pub from: usize,
pub to: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "delete_rows.ts", builder, rename_all = "camelCase")]
pub struct DeleteRows {
pub sheet_idx: usize,
pub start: usize,
pub count: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "insert_rows.ts", builder, rename_all = "camelCase")]
pub struct InsertRows {
pub sheet_idx: usize,
pub start: usize,
pub count: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "delete_cols.ts", builder, rename_all = "camelCase")]
pub struct DeleteCols {
pub sheet_idx: usize,
pub start: usize,
pub count: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "insert_cols.ts", builder, rename_all = "camelCase")]
pub struct InsertCols {
pub sheet_idx: usize,
pub start: usize,
pub count: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "set_cell_image.ts", builder, rename_all = "camelCase")]
pub struct SetCellImage {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
pub image_id: String,
pub format: String,
pub data: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "delete_cell_image.ts", builder, rename_all = "camelCase")]
pub struct DeleteCellImage {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "delete_chart.ts", builder, rename_all = "camelCase")]
pub struct DeleteChart {
pub sheet_idx: usize,
pub chart_id: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "update_chart.ts", builder, rename_all = "camelCase")]
pub struct UpdateChart {
pub sheet_idx: usize,
pub chart_id: String,
pub chart_type: Option<String>,
pub title: Option<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "create_chart_series.ts",
builder,
rename_all = "camelCase"
)]
pub struct CreateChartSeries {
pub name: Option<String>,
pub value_ref: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "create_chart.ts", builder, rename_all = "camelCase")]
pub struct CreateChart {
pub sheet_idx: usize,
pub chart_id: String,
pub chart_type: String,
pub from_row: usize,
pub from_col: usize,
pub from_col_off: i64,
pub from_row_off: i64,
pub to_row: usize,
pub to_col: usize,
pub to_col_off: i64,
pub to_row_off: i64,
pub title: Option<String>,
pub categories_ref: Option<String>,
pub series: Vec<CreateChartSeries>,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "create_conditional_formatting_rule.ts",
builder,
rename_all = "camelCase"
)]
pub struct CreateConditionalFormattingRule {
pub sheet_idx: usize,
pub start_row: usize,
pub start_col: usize,
pub end_row: usize,
pub end_col: usize,
pub rule: CfRuleSpec,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "update_conditional_formatting_rule.ts",
builder,
rename_all = "camelCase"
)]
pub struct UpdateConditionalFormattingRule {
pub sheet_idx: usize,
pub rule_id: u32,
pub rule: CfRuleSpec,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "move_conditional_formatting_rule.ts",
builder,
rename_all = "camelCase"
)]
pub struct MoveConditionalFormattingRule {
pub sheet_idx: usize,
pub rule_id: u32,
pub start_row: usize,
pub start_col: usize,
pub end_row: usize,
pub end_col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "delete_conditional_formatting_rule.ts",
builder,
rename_all = "camelCase"
)]
pub struct DeleteConditionalFormattingRule {
pub sheet_idx: usize,
pub rule_id: u32,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "move_chart.ts", builder, rename_all = "camelCase")]
pub struct MoveChart {
pub sheet_idx: usize,
pub chart_id: String,
pub from_row: usize,
pub from_col: usize,
pub from_col_off: i64,
pub from_row_off: i64,
pub to_row: usize,
pub to_col: usize,
pub to_col_off: i64,
pub to_row_off: i64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_input.ts", builder, rename_all = "camelCase")]
pub struct CellInput {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
pub content: String,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "ephemeral_cell_input.ts",
builder,
rename_all = "camelCase"
)]
pub struct EphemeralCellInput {
pub sheet_idx: usize,
pub id: EphemeralId,
pub content: String,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "ephemeral_cell_remove.ts",
builder,
rename_all = "camelCase"
)]
pub struct EphemeralCellRemove {
pub sheet_idx: usize,
pub id: EphemeralId,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_clear.ts", builder, rename_all = "camelCase")]
pub struct CellClear {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "create_block.ts", builder, rename_all = "camelCase")]
pub struct CreateBlock {
pub sheet_idx: usize,
pub id: usize,
pub master_row: usize,
pub master_col: usize,
pub row_cnt: usize,
pub col_cnt: usize,
pub owner: Option<String>,
pub modify_policy: Option<ModifyPolicy>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "modify_policy.ts", tag = "type")]
pub enum ModifyPolicy {
All,
OwnerOnly,
OwnerAndUser,
}
impl Default for ModifyPolicy {
fn default() -> Self {
ModifyPolicy::All
}
}
impl ModifyPolicy {
pub fn as_wire_str(&self) -> &'static str {
match self {
ModifyPolicy::All => "all",
ModifyPolicy::OwnerOnly => "ownerOnly",
ModifyPolicy::OwnerAndUser => "ownerAndUser",
}
}
pub fn from_wire_str(s: &str) -> Self {
match s {
"ownerOnly" => ModifyPolicy::OwnerOnly,
"ownerAndUser" => ModifyPolicy::OwnerAndUser,
_ => ModifyPolicy::All,
}
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_modify_info.ts", rename_all = "camelCase")]
pub struct BlockModifyInfo {
pub owner: String,
pub modify_policy: ModifyPolicy,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "resize_block.ts", builder, rename_all = "camelCase")]
pub struct ResizeBlock {
pub sheet_idx: usize,
pub id: usize,
pub new_row_cnt: Option<usize>,
pub new_col_cnt: Option<usize>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "convert_block.ts", builder, rename_all = "camelCase")]
pub struct ConvertBlock {
pub sheet_idx: usize,
pub id: usize,
pub master_row: usize,
pub master_col: usize,
pub row_cnt: usize,
pub col_cnt: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "create_link.ts", builder, rename_all = "camelCase")]
pub struct CreateLink {
pub sheet_idx: usize,
pub master_row: usize,
pub master_col: usize,
pub row_cnt: usize,
pub col_cnt: usize,
pub block_id: usize,
pub block_sheet_idx: Option<usize>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "create_diy_cell.ts", builder, rename_all = "camelCase")]
pub struct CreateDiyCell {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "remove_diy_cell.ts", builder, rename_all = "camelCase")]
pub struct RemoveDiyCell {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "create_diy_cell_by_id.ts",
builder,
rename_all = "camelCase"
)]
pub struct CreateDiyCellById {
pub sheet_id: SheetId,
pub block_id: BlockId,
pub row_idx: usize,
pub col_idx: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "remove_diy_cell_by_id.ts",
builder,
rename_all = "camelCase"
)]
pub struct RemoveDiyCellById {
pub sheet_id: SheetId,
pub block_id: BlockId,
pub row_idx: usize,
pub col_idx: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "create_appendix.ts", builder, rename_all = "camelCase")]
pub struct CreateAppendix {
pub sheet_id: Option<SheetId>,
pub sheet_idx: Option<usize>,
pub block_id: BlockId,
pub row_idx: usize,
pub col_idx: usize,
pub craft_id: String,
pub tag: u8,
pub content: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "remove_appendix.ts", builder, rename_all = "camelCase")]
pub struct RemoveAppendix {
pub sheet_id: Option<SheetId>,
pub sheet_idx: Option<usize>,
pub block_id: BlockId,
pub row_idx: usize,
pub col_idx: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "set_row_height.ts", builder, rename_all = "camelCase")]
pub struct SetRowHeight {
pub sheet_idx: usize,
pub row: usize,
pub height: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "set_col_width.ts", builder, rename_all = "camelCase")]
pub struct SetColWidth {
pub sheet_idx: usize,
pub col: usize,
pub width: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "move_block.ts", builder, rename_all = "camelCase")]
pub struct MoveBlock {
pub sheet_idx: usize,
pub id: usize,
pub new_master_row: usize,
pub new_master_col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "remove_block.ts", builder, rename_all = "camelCase")]
pub struct RemoveBlock {
pub sheet_idx: usize,
pub id: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_input.ts", builder, rename_all = "camelCase")]
pub struct BlockInput {
pub sheet_idx: usize,
pub block_id: usize,
pub row: usize,
pub col: usize,
pub input: String,
}
impl From<BlockInput> for EditPayload {
fn from(value: BlockInput) -> Self {
EditPayload::BlockInput(value)
}
}
impl From<UpsertFieldRenderInfo> for EditPayload {
fn from(value: UpsertFieldRenderInfo) -> Self {
EditPayload::UpsertFieldRenderInfo(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "move_block_line.ts", builder, rename_all = "camelCase")]
pub struct MoveBlockLine {
pub sheet_idx: usize,
pub block_id: usize,
pub from: usize,
pub to: usize,
pub is_row: bool,
}
impl From<MoveBlockLine> for EditPayload {
fn from(value: MoveBlockLine) -> Self {
EditPayload::MoveBlockLine(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "reorder_block_lines.ts", rename_all = "camelCase")]
pub struct ReorderBlockLines {
pub sheet_idx: usize,
pub block_id: usize,
pub is_row: bool,
pub new_order: Vec<usize>,
}
impl From<ReorderBlockLines> for EditPayload {
fn from(value: ReorderBlockLines) -> Self {
EditPayload::ReorderBlockLines(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "bind_form_schema.ts", builder, rename_all = "camelCase")]
pub struct BindFormSchema {
pub ref_name: String,
pub sheet_idx: usize,
pub block_id: usize,
pub field_from: usize,
pub key_idx: usize,
pub fields: Vec<String>,
pub render_ids: Vec<String>,
pub row: bool,
pub field_formulas: Vec<Option<String>>,
pub validation_formulas: Vec<Option<String>>,
pub editability_formulas: Vec<Option<String>>,
}
impl From<BindFormSchema> for EditPayload {
fn from(value: BindFormSchema) -> Self {
EditPayload::BindFormSchema(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "upsert_field_formulas.ts",
builder,
rename_all = "camelCase"
)]
pub struct UpsertFieldFormulas {
pub sheet_idx: usize,
pub block_id: usize,
pub field_formulas: Vec<Option<String>>,
pub validation_formulas: Vec<Option<String>>,
pub editability_formulas: Vec<Option<String>>,
}
impl From<UpsertFieldFormulas> for EditPayload {
fn from(value: UpsertFieldFormulas) -> Self {
EditPayload::UpsertFieldFormulas(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "bind_random_schema.ts", builder, rename_all = "camelCase")]
pub struct BindRandomSchema {
pub ref_name: String,
pub sheet_idx: usize,
pub block_id: usize,
pub units: Vec<RandomSchemaUnit>,
}
impl From<BindRandomSchema> for EditPayload {
fn from(value: BindRandomSchema) -> Self {
EditPayload::BindRandomSchema(value)
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "random_schema_unit.ts", builder, rename_all = "camelCase")]
pub struct RandomSchemaUnit {
pub key: String,
pub render_id: String,
pub row: usize,
pub col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "delete_rows_in_block.ts",
builder,
rename_all = "camelCase"
)]
pub struct DeleteRowsInBlock {
pub sheet_idx: usize,
pub block_id: usize,
pub start: usize,
pub cnt: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "reproduce_cells.ts", builder, rename_all = "camelCase")]
pub struct ReproduceCells {
pub sheet_idx: usize,
pub start_row: usize,
pub start_col: usize,
pub cells: Vec<ReproducibleCell>,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "insert_rows_in_block.ts",
builder,
rename_all = "camelCase"
)]
pub struct InsertRowsInBlock {
pub sheet_idx: usize,
pub block_id: usize,
pub start: usize,
pub cnt: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "insert_cols_in_block.ts",
builder,
rename_all = "camelCase"
)]
pub struct InsertColsInBlock {
pub sheet_idx: usize,
pub block_id: usize,
pub start: usize,
pub cnt: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "delete_cols_in_block.ts",
builder,
rename_all = "camelCase"
)]
pub struct DeleteColsInBlock {
pub sheet_idx: usize,
pub block_id: usize,
pub start: usize,
pub cnt: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_style_update.ts", builder, rename_all = "camelCase")]
pub struct BlockStyleUpdate {
pub sheet_idx: usize,
pub block_id: usize,
pub row: usize,
pub col: usize,
pub style_update: StyleUpdateType,
}
#[derive(Default, Debug, Clone, TS)]
#[ts(file_name = "set_visible.ts", builder, rename_all = "camelCase")]
pub struct SetVisible {
pub is_row: bool,
pub sheet_idx: usize,
pub start: usize,
pub visible: bool,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_cell_id.ts", builder, rename_all = "camelCase")]
pub struct SheetCellId {
pub sheet_id: SheetId,
pub cell_id: CellId,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_row_id.ts", builder, rename_all = "camelCase")]
pub struct SheetRowId {
pub sheet_id: SheetId,
pub row_id: RowId,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_col_id.ts", builder, rename_all = "camelCase")]
pub struct SheetColId {
pub sheet_id: SheetId,
pub col_id: ColId,
}
#[derive(Default, Debug, Clone, TS)]
#[ts(file_name = "action_effect.ts", builder, rename_all = "camelCase")]
pub struct ActionEffect {
pub version: u32,
pub async_tasks: Vec<Task>,
pub status: StatusCode,
pub value_changed: Vec<SheetCellId>,
pub cell_removed: Vec<SheetCellId>,
pub style_changed: Vec<SheetCellId>,
pub row_inserted: Vec<SheetRowId>,
pub row_removed: Vec<SheetRowId>,
pub row_updated: Vec<SheetRowId>,
pub col_inserted: Vec<SheetColId>,
pub col_removed: Vec<SheetColId>,
pub col_updated: Vec<SheetColId>,
pub header_updated: Vec<u32>,
pub error_message: Option<String>,
}
impl ActionEffect {
pub fn from_err(e: u8) -> Self {
ActionEffect {
status: StatusCode::Err(e),
..Default::default()
}
}
pub fn from_err_with_message(e: u8, message: Option<String>) -> Self {
ActionEffect {
status: StatusCode::Err(e),
error_message: message,
..Default::default()
}
}
pub fn from(version: u32, tasks: Vec<Task>, ty: WorkbookUpdateType) -> Self {
ActionEffect {
version,
async_tasks: tasks,
status: StatusCode::Ok(ty),
..Default::default()
}
}
}
#[derive(Default, Debug, Clone, TS)]
#[ts(file_name = "async_func_result.ts", builder, rename_all = "camelCase")]
pub struct AsyncFuncResult {
pub tasks: Vec<Task>,
pub values: Vec<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "status_code.ts", tag = "type", rename_all = "camelCase")]
pub enum StatusCode {
Ok(WorkbookUpdateType), Err(u8),
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "workbook_update_type.ts",
tag = "type",
rename_all = "camelCase"
)]
pub enum WorkbookUpdateType {
DoNothing,
Cell,
Sheet,
SheetAndCell,
UndoNothing,
RedoNothing,
Undo,
Redo,
EphemeralCells,
}
impl Default for StatusCode {
fn default() -> Self {
Self::Ok(WorkbookUpdateType::Cell)
}
}
use crate::{ReproducibleCell, controller::style::PatternFill};
use logisheets_workbook::prelude::*;
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_style_update.ts", builder, rename_all = "camelCase")]
pub struct CellStyleUpdate {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
pub ty: StyleUpdateType,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "ephemeral_cell_style_update.ts",
builder,
rename_all = "camelCase"
)]
pub struct EphemeralCellStyleUpdate {
pub sheet_idx: usize,
pub id: EphemeralId,
pub ty: StyleUpdateType,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "line_style_update.ts", builder, rename_all = "camelCase")]
pub struct LineStyleUpdate {
pub sheet_idx: usize,
pub from: usize,
pub to: usize,
pub ty: StyleUpdateType,
pub row: bool,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "block_line_style_update.ts",
builder,
rename_all = "camelCase"
)]
pub struct BlockLineStyleUpdate {
pub sheet_idx: usize,
pub block_id: BlockId,
pub from: usize,
pub to: usize,
pub ty: StyleUpdateType,
pub row: bool,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "block_line_name_field_update.ts",
builder,
rename_all = "camelCase"
)]
pub struct BlockLineNameFieldUpdate {
pub sheet_idx: usize,
pub block_id: BlockId,
pub line: usize,
pub row: bool,
pub name: Option<String>,
pub field_id: String,
pub diy_render: Option<bool>,
}
pub type Color = String;
#[derive(Debug, Clone, TS)]
#[ts(file_name = "alignment.ts", rename_all = "camelCase")]
pub struct Alignment {
pub horizontal: Option<HorizontalAlignment>,
pub vertical: Option<VerticalAlignment>,
pub wrap_text: Option<bool>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "vertical_alignment.ts", rename_all = "camelCase")]
pub enum VerticalAlignment {
Center,
Top,
Bottom,
Justify,
Distributed,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "horizontal_alignment.ts", tag = "type")]
pub enum HorizontalAlignment {
General,
Left,
Center,
Right,
Fill,
Justify,
CenterContinuous,
Distributed,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "style_update_type.ts", builder, rename_all = "camelCase")]
pub struct StyleUpdateType {
pub set_font_bold: Option<bool>,
pub set_font_italic: Option<bool>,
pub set_font_underline: Option<StUnderlineValues>,
pub set_font_color: Option<Color>,
pub set_font_size: Option<f64>,
pub set_font_name: Option<String>,
pub set_font_outline: Option<bool>,
pub set_font_shadow: Option<bool>,
pub set_font_strike: Option<bool>,
pub set_font_condense: Option<bool>,
pub set_left_border_color: Option<Color>,
pub set_right_border_color: Option<Color>,
pub set_top_border_color: Option<Color>,
pub set_bottom_border_color: Option<Color>,
pub set_left_border_style: Option<StBorderStyle>,
pub set_right_border_style: Option<StBorderStyle>,
pub set_top_border_style: Option<StBorderStyle>,
pub set_bottom_border_style: Option<StBorderStyle>,
pub set_border_giagonal_up: Option<bool>,
pub set_border_giagonal_down: Option<bool>,
pub set_border_outline: Option<bool>,
pub set_pattern_fill: Option<PatternFill>,
pub set_alignment: Option<Alignment>,
pub set_num_fmt: Option<String>,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "merge_cells.ts", builder, rename_all = "camelCase")]
pub struct MergeCells {
pub sheet_idx: usize,
pub start_row: usize,
pub start_col: usize,
pub end_row: usize,
pub end_col: usize,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "split_merged_cells.ts", builder, rename_all = "camelCase")]
pub struct SplitMergedCells {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "author_input.ts", rename_all = "camelCase")]
pub struct AuthorInput {
pub display_name: String,
pub user_id: Option<String>,
pub provider_id: Option<String>,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "comment_mention.ts", rename_all = "camelCase")]
pub struct CommentMention {
pub start: usize,
pub len: usize,
pub author: AuthorInput,
pub mention_id: Option<String>,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "add_comment.ts", builder, rename_all = "camelCase")]
pub struct AddComment {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
pub comment_id: String,
pub parent_id: Option<String>,
pub author: AuthorInput,
pub dt: String,
pub content: String,
pub mentions: Vec<CommentMention>,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "edit_comment.ts", builder, rename_all = "camelCase")]
pub struct EditComment {
pub sheet_idx: usize,
pub comment_id: String,
pub content: String,
pub mentions: Vec<CommentMention>,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "delete_comment.ts", builder, rename_all = "camelCase")]
pub struct DeleteComment {
pub sheet_idx: usize,
pub comment_id: String,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "resolve_comment.ts", builder, rename_all = "camelCase")]
pub struct ResolveComment {
pub sheet_idx: usize,
pub comment_id: String,
pub resolved: bool,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "upsert_person.ts", builder, rename_all = "camelCase")]
pub struct UpsertPerson {
pub display_name: String,
pub user_id: Option<String>,
pub provider_id: Option<String>,
}
impl From<MergeCells> for EditPayload {
fn from(value: MergeCells) -> Self {
EditPayload::MergeCells(value)
}
}
impl From<SplitMergedCells> for EditPayload {
fn from(value: SplitMergedCells) -> Self {
EditPayload::SplitMergedCells(value)
}
}
impl From<AddComment> for EditPayload {
fn from(value: AddComment) -> Self {
EditPayload::AddComment(value)
}
}
impl From<EditComment> for EditPayload {
fn from(value: EditComment) -> Self {
EditPayload::EditComment(value)
}
}
impl From<DeleteComment> for EditPayload {
fn from(value: DeleteComment) -> Self {
EditPayload::DeleteComment(value)
}
}
impl From<ResolveComment> for EditPayload {
fn from(value: ResolveComment) -> Self {
EditPayload::ResolveComment(value)
}
}
impl From<UpsertPerson> for EditPayload {
fn from(value: UpsertPerson) -> Self {
EditPayload::UpsertPerson(value)
}
}
impl From<BlockStyleUpdate> for EditPayload {
fn from(value: BlockStyleUpdate) -> Self {
EditPayload::BlockStyleUpdate(value)
}
}
impl From<CellInput> for EditPayload {
fn from(value: CellInput) -> Self {
EditPayload::CellInput(value)
}
}
impl From<SetCellImage> for EditPayload {
fn from(value: SetCellImage) -> Self {
EditPayload::SetCellImage(value)
}
}
impl From<DeleteCellImage> for EditPayload {
fn from(value: DeleteCellImage) -> Self {
EditPayload::DeleteCellImage(value)
}
}
impl Payload for SetCellImage {}
impl Payload for DeleteCellImage {}
impl From<MoveChart> for EditPayload {
fn from(value: MoveChart) -> Self {
EditPayload::MoveChart(value)
}
}
impl Payload for MoveChart {}
impl From<CreateConditionalFormattingRule> for EditPayload {
fn from(value: CreateConditionalFormattingRule) -> Self {
EditPayload::CreateConditionalFormattingRule(value)
}
}
impl Payload for CreateConditionalFormattingRule {}
impl From<UpdateConditionalFormattingRule> for EditPayload {
fn from(value: UpdateConditionalFormattingRule) -> Self {
EditPayload::UpdateConditionalFormattingRule(value)
}
}
impl Payload for UpdateConditionalFormattingRule {}
impl From<MoveConditionalFormattingRule> for EditPayload {
fn from(value: MoveConditionalFormattingRule) -> Self {
EditPayload::MoveConditionalFormattingRule(value)
}
}
impl Payload for MoveConditionalFormattingRule {}
impl From<DeleteConditionalFormattingRule> for EditPayload {
fn from(value: DeleteConditionalFormattingRule) -> Self {
EditPayload::DeleteConditionalFormattingRule(value)
}
}
impl Payload for DeleteConditionalFormattingRule {}
impl From<DeleteChart> for EditPayload {
fn from(value: DeleteChart) -> Self {
EditPayload::DeleteChart(value)
}
}
impl Payload for DeleteChart {}
impl From<CreateChart> for EditPayload {
fn from(value: CreateChart) -> Self {
EditPayload::CreateChart(value)
}
}
impl Payload for CreateChart {}
impl From<UpdateChart> for EditPayload {
fn from(value: UpdateChart) -> Self {
EditPayload::UpdateChart(value)
}
}
impl Payload for UpdateChart {}
impl From<CreateBlock> for EditPayload {
fn from(value: CreateBlock) -> Self {
EditPayload::CreateBlock(value)
}
}
impl From<MoveBlock> for EditPayload {
fn from(value: MoveBlock) -> Self {
EditPayload::MoveBlock(value)
}
}
impl From<RemoveBlock> for EditPayload {
fn from(value: RemoveBlock) -> Self {
EditPayload::RemoveBlock(value)
}
}
impl From<SetColWidth> for EditPayload {
fn from(value: SetColWidth) -> Self {
EditPayload::SetColWidth(value)
}
}
impl From<SetRowHeight> for EditPayload {
fn from(value: SetRowHeight) -> Self {
EditPayload::SetRowHeight(value)
}
}
impl From<SetVisible> for EditPayload {
fn from(value: SetVisible) -> Self {
EditPayload::SetVisible(value)
}
}
impl From<SheetRename> for EditPayload {
fn from(value: SheetRename) -> Self {
EditPayload::SheetRename(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)
}
}
impl From<InsertRows> for EditPayload {
fn from(value: InsertRows) -> Self {
EditPayload::InsertRows(value)
}
}
impl From<DeleteRows> for EditPayload {
fn from(value: DeleteRows) -> Self {
EditPayload::DeleteRows(value)
}
}
impl From<DeleteCols> for EditPayload {
fn from(value: DeleteCols) -> Self {
EditPayload::DeleteCols(value)
}
}
impl From<InsertColsInBlock> for EditPayload {
fn from(value: InsertColsInBlock) -> Self {
EditPayload::InsertColsInBlock(value)
}
}
impl From<InsertRowsInBlock> for EditPayload {
fn from(value: InsertRowsInBlock) -> Self {
EditPayload::InsertRowsInBlock(value)
}
}
impl From<DeleteRowsInBlock> for EditPayload {
fn from(value: DeleteRowsInBlock) -> Self {
EditPayload::DeleteRowsInBlock(value)
}
}
impl From<DeleteColsInBlock> for EditPayload {
fn from(value: DeleteColsInBlock) -> Self {
EditPayload::DeleteColsInBlock(value)
}
}
impl From<CreateSheet> for EditPayload {
fn from(value: CreateSheet) -> Self {
EditPayload::CreateSheet(value)
}
}
impl From<DeleteSheet> for EditPayload {
fn from(value: DeleteSheet) -> Self {
EditPayload::DeleteSheet(value)
}
}
impl From<CellFormatBrush> for EditPayload {
fn from(value: CellFormatBrush) -> Self {
EditPayload::CellFormatBrush(value)
}
}
impl From<LineFormatBrush> for EditPayload {
fn from(value: LineFormatBrush) -> Self {
EditPayload::LineFormatBrush(value)
}
}
impl From<EphemeralCellInput> for EditPayload {
fn from(value: EphemeralCellInput) -> Self {
EditPayload::EphemeralCellInput(value)
}
}
impl From<EphemeralCellRemove> for EditPayload {
fn from(value: EphemeralCellRemove) -> Self {
EditPayload::EphemeralCellRemove(value)
}
}
impl From<ConvertBlock> for EditPayload {
fn from(value: ConvertBlock) -> Self {
EditPayload::ConvertBlock(value)
}
}
impl From<CreateLink> for EditPayload {
fn from(value: CreateLink) -> Self {
EditPayload::CreateLink(value)
}
}
impl Payload for CreateLink {}
impl Payload for BlockInput {}
impl Payload for BlockStyleUpdate {}
impl Payload for CellInput {}
impl Payload for CreateBlock {}
impl Payload for MoveBlock {}
impl Payload for RemoveBlock {}
impl Payload for SetColWidth {}
impl Payload for SetRowHeight {}
impl Payload for SetVisible {}
impl Payload for SheetRename {}
impl Payload for CreateSheet {}
impl Payload for DeleteSheet {}
impl Payload for CellStyleUpdate {}
impl Payload for LineStyleUpdate {}
impl Payload for InsertCols {}
impl Payload for InsertRows {}
impl Payload for DeleteCols {}
impl Payload for DeleteRows {}
impl Payload for InsertColsInBlock {}
impl Payload for InsertRowsInBlock {}
impl Payload for DeleteColsInBlock {}
impl Payload for DeleteRowsInBlock {}
impl Payload for CellFormatBrush {}
impl Payload for LineFormatBrush {}
impl Payload for EphemeralCellInput {}
impl Payload for EphemeralCellRemove {}
impl Payload for ConvertBlock {}
impl Payload for UpsertFieldRenderInfo {}
impl Payload for BindFormSchema {}
impl Payload for UpsertFieldFormulas {}
impl Payload for BindRandomSchema {}
impl Payload for RestoreCheckpoint {}
impl Payload for MergeCells {}
impl Payload for SplitMergedCells {}
impl Payload for AddComment {}
impl Payload for EditComment {}
impl Payload for DeleteComment {}
impl Payload for ResolveComment {}
impl Payload for UpsertPerson {}
#[cfg(test)]
mod tests {
use super::VerticalAlignment;
#[test]
fn test_should_have_double_quote() {
let s1 = "\"center\"".to_string();
let _: VerticalAlignment = serde_json::from_str(&s1).unwrap();
}
}