use crate::CellInfo;
use crate::block_manager::schema_manager::field_type::FieldTypeParts;
use super::style::Style;
use gents_derives::TS;
use logisheets_base::{BlockId, SheetId};
use crate::block_manager::schema_manager::schema::RenderId;
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_position.ts", rename_all = "camelCase")]
pub struct CellPosition {
pub x: f64,
pub y: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_coordinate.ts", rename_all = "camelCase")]
pub struct CellCoordinate {
pub x: usize,
pub y: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_data_row.ts", rename_all = "camelCase")]
pub struct BlockDataRow {
pub cells: Vec<crate::Value>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_coordinate_with_sheet.ts", rename_all = "camelCase")]
pub struct CellCoordinateWithSheet {
pub sheet_idx: usize,
pub coordinate: CellCoordinate,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "shadow_cell_info.ts", rename_all = "camelCase")]
pub struct ShadowCellInfo {
pub start_position: CellPosition,
pub end_position: CellPosition,
pub value: Value,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "display_window.ts", rename_all = "camelCase")]
pub struct DisplayWindow {
pub cells: Vec<CellInfo>,
pub rows: Vec<RowInfo>,
pub cols: Vec<ColInfo>,
pub comments: Vec<Comment>,
pub merge_cells: Vec<MergeCell>,
pub blocks: Vec<BlockDisplayInfo>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_display_info.ts", rename_all = "camelCase")]
pub struct BlockDisplayInfo {
pub info: BlockInfo,
pub start_position: CellPosition,
pub end_position: CellPosition,
}
#[derive(Debug, Clone, TS)]
#[ts(
file_name = "display_window_with_start_point.ts",
rename_all = "camelCase"
)]
pub struct DisplayWindowWithStartPoint {
pub window: DisplayWindow,
pub start_x: f64,
pub start_y: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_names.ts", rename_all = "camelCase")]
pub struct SheetNames {
pub names: Vec<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_info.ts", rename_all = "camelCase")]
pub struct SheetInfo {
pub name: String,
pub id: SheetId,
pub hidden: bool,
pub tab_color: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_blocks.ts", rename_all = "camelCase")]
pub struct SheetBlocks {
pub sheet_idx: usize,
pub blocks: Vec<BlockInfo>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_info.ts", rename_all = "camelCase")]
pub struct BlockInfo {
pub sheet_idx: usize,
pub sheet_id: SheetId,
pub block_id: BlockId,
pub row_start: usize,
pub row_cnt: usize,
pub col_start: usize,
pub col_cnt: usize,
pub schema: Option<BlockSchema>,
pub field_renders: Vec<FieldRenderEntry>,
pub cells: Vec<BlockCellInfo>,
pub description: String,
pub owner: String,
pub modify_policy: crate::edit_action::ModifyPolicy,
pub permissions: crate::edit_action::BlockPermissions,
pub analyzes: Option<BlockId>,
pub analyzed_by: Vec<BlockId>,
pub pivot: Option<crate::block_manager::schema_manager::field_type::PivotSpecParts>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "link_info.ts", rename_all = "camelCase")]
pub struct LinkInfo {
pub sheet_idx: usize,
pub block_id: BlockId,
pub start_row: usize,
pub start_col: usize,
pub end_row: usize,
pub end_col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_schema.ts", rename_all = "camelCase")]
pub struct BlockSchema {
pub name: String,
pub schema_type: BlockSchemaType,
pub keys: Vec<BlockSchemaKeyEntry>,
pub fields: Vec<BlockSchemaFieldEntry>,
pub random_entries: Vec<BlockSchemaRandomEntry>,
pub header_idx: Option<usize>,
pub key_idx: Option<usize>,
pub unique_together: Vec<crate::edit_action::UniqueTogetherGroup>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_schema_type.ts", rename_all = "camelCase")]
pub enum BlockSchemaType {
Row,
Col,
Random,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "block_schema_key_entry.ts", rename_all = "camelCase")]
pub struct BlockSchemaKeyEntry {
pub key: String,
pub idx: usize,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "block_schema_field_entry.ts", rename_all = "camelCase")]
pub struct BlockSchemaFieldEntry {
pub field: String,
pub idx: usize,
pub render_id: RenderId,
pub value_formula: Option<String>,
pub validation_formula: Option<String>,
pub editability_formula: Option<String>,
pub field_type: Option<FieldTypeParts>,
pub description: Option<String>,
pub required: bool,
pub unique: bool,
pub default_value: Option<String>,
pub write_policy: String,
pub agg_func: Option<String>,
pub agg_field: Option<String>,
pub pivot_col_value: Option<String>,
pub pivot_measure: Option<String>,
pub pivot_func: Option<String>,
}
impl BlockSchemaFieldEntry {
pub fn from_entry<F>(
name: &str,
idx: usize,
entry: &crate::block_manager::schema_manager::schema::FieldEntry<F>,
) -> Self {
let parts = entry.field_type.to_parts();
Self {
field: name.to_string(),
idx,
render_id: entry.render_id.clone(),
value_formula: entry.value_formula.clone(),
validation_formula: entry.validation_formula.clone(),
editability_formula: entry.editability_formula.clone(),
field_type: parts.kind.is_some().then_some(parts),
description: entry.description.clone(),
required: entry.required,
unique: entry.unique,
default_value: entry.default_value.clone(),
write_policy: entry.write_policy.as_str().to_string(),
agg_func: entry
.aggregate
.as_ref()
.map(|a| a.func.as_str().to_string()),
agg_field: entry.aggregate.as_ref().map(|a| a.source_field.clone()),
pivot_col_value: entry.pivot_column.as_ref().map(|c| c.col_value_str()),
pivot_measure: entry.pivot_column.as_ref().and_then(|c| c.measure.clone()),
pivot_func: entry
.pivot_column
.as_ref()
.and_then(|c| c.func.map(|f| f.as_str().to_string())),
}
}
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "block_schema_random_entry.ts", rename_all = "camelCase")]
pub struct BlockSchemaRandomEntry {
pub key: String,
pub row: usize,
pub col: usize,
pub render_id: RenderId,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "field_render_entry.ts", rename_all = "camelCase")]
pub struct FieldRenderEntry {
pub render_id: RenderId,
pub style: Option<Style>,
pub diy_render: bool,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_cell_info.ts", rename_all = "camelCase")]
pub struct BlockCellInfo {
pub value: Value,
pub shadow_value: Option<Value>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "display_window_request.ts", rename_all = "camelCase")]
pub struct DisplayWindowRequest {
pub sheet_idx: usize,
pub height: f64,
pub width: f64,
pub start_x: f64,
pub start_y: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_merge_cells.ts", rename_all = "camelCase")]
pub struct SheetMergeCells {
pub sheet_idx: usize,
pub merge_cells: Vec<MergeCell>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_comments.ts", rename_all = "camelCase")]
pub struct SheetComments {
pub sheet_idx: usize,
pub comments: Vec<Comment>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "merge_cell.ts", rename_all = "camelCase")]
pub struct MergeCell {
pub start_row: usize,
pub start_col: usize,
pub end_row: usize,
pub end_col: usize,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_image_info.ts", rename_all = "camelCase")]
pub struct CellImageInfo {
pub row: usize,
pub col: usize,
pub id: String,
pub format: String,
pub data: String,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "chart_series_info.ts", rename_all = "camelCase")]
pub struct ChartSeriesInfo {
pub name: Option<String>,
pub values: Vec<Option<f64>>,
pub color: Option<String>,
pub formatted_values: Vec<Option<String>>,
pub sizes: Vec<Option<f64>>,
pub size_ref: Option<String>,
pub series_type: Option<String>,
pub val_ref: Option<String>,
pub num_fmt: Option<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "chart_axis_scale_info.ts", rename_all = "camelCase")]
pub struct ChartAxisScaleInfo {
pub min: Option<f64>,
pub max: Option<f64>,
pub log_base: Option<f64>,
pub reversed: bool,
pub major_unit: Option<f64>,
pub minor_unit: Option<f64>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "chart_of_pie_split_info.ts", rename_all = "camelCase")]
pub struct ChartOfPieSplitInfo {
pub by: Option<String>,
pub pos: Option<f64>,
pub second_size: Option<f64>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "chart_data_labels_info.ts", rename_all = "camelCase")]
pub struct ChartDataLabelsInfo {
pub show_value: bool,
pub show_category: bool,
pub show_series: bool,
pub show_percent: bool,
pub show_legend_key: bool,
pub position: Option<String>,
pub num_fmt: Option<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "chart_info.ts", rename_all = "camelCase")]
pub struct ChartInfo {
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,
pub ext_cx: Option<i64>,
pub ext_cy: Option<i64>,
pub chart_type: String,
pub stacked: bool,
pub title: Option<String>,
pub legend_pos: Option<String>,
pub categories: Vec<String>,
pub cat_ref: Option<String>,
pub series: Vec<ChartSeriesInfo>,
pub cat_axis_title: Option<String>,
pub val_axis_title: Option<String>,
pub data_labels: ChartDataLabelsInfo,
pub of_pie_split: ChartOfPieSplitInfo,
pub val_axis_scale: ChartAxisScaleInfo,
pub cat_axis_scale: ChartAxisScaleInfo,
pub val_axis_num_fmt: Option<String>,
pub block_source: Option<ChartBlockSourceInfo>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "chart_block_source_info.ts", rename_all = "camelCase")]
pub struct ChartBlockSourceInfo {
pub block_id: usize,
pub category_field: Option<String>,
pub value_fields: Vec<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment_person.ts", rename_all = "camelCase")]
pub struct CommentPerson {
pub display_name: String,
pub user_id: Option<String>,
pub provider_id: Option<String>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment_mention_info.ts", rename_all = "camelCase")]
pub struct CommentMentionInfo {
pub start: usize,
pub len: usize,
pub person: CommentPerson,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment_note.ts", rename_all = "camelCase")]
pub struct CommentNote {
pub id: String,
pub author: CommentPerson,
pub dt: String,
pub content: String,
pub parent_id: Option<String>,
pub mentions: Vec<CommentMentionInfo>,
pub resolved: bool,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "comment.ts", rename_all = "camelCase")]
pub struct Comment {
pub row: usize,
pub col: usize,
pub notes: Vec<CommentNote>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_row_info.ts", rename_all = "camelCase")]
pub struct SheetRowInfo {
pub sheet_idx: usize,
pub info: Vec<RowInfo>,
pub default_height: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "row_info.ts", rename_all = "camelCase")]
pub struct RowInfo {
pub idx: usize,
pub height: f64,
pub hidden: bool,
}
impl RowInfo {
pub fn default(idx: usize) -> RowInfo {
Self {
idx,
height: get_default_row_height(),
hidden: false,
}
}
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_col_info.ts", rename_all = "camelCase")]
pub struct SheetColInfo {
pub sheet_idx: usize,
pub info: Vec<ColInfo>,
pub default_width: f64,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "col_info.ts", rename_all = "camelCase")]
pub struct ColInfo {
pub idx: usize,
pub width: f64,
pub hidden: bool,
}
impl ColInfo {
pub fn default(idx: usize) -> Self {
Self {
idx,
width: get_default_col_width(),
hidden: false,
}
}
}
pub fn get_default_row_height() -> f64 {
15.
}
pub fn get_default_col_width() -> f64 {
8.43
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "value.ts", tag = "type")]
pub enum Value {
Str(String),
Bool(bool),
Number(f64),
Error(String),
#[default]
Empty,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_formula_value.ts", rename_all = "camelCase")]
pub struct CellFormulaValue {
pub row: usize,
pub col: usize,
pub formula: String,
pub value: Value,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_values.ts", rename_all = "camelCase")]
pub struct SheetValues {
pub sheet_idx: usize,
pub values: Vec<CellFormulaValue>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "cell_style.ts", rename_all = "camelCase")]
pub struct CellStyle {
pub row: usize,
pub col: usize,
pub style: Style,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "sheet_styles.ts", rename_all = "camelCase")]
pub struct SheetStyles {
pub sheet_idx: usize,
pub styles: Vec<CellStyle>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "temp_cell_change.ts", rename_all = "camelCase")]
pub struct TempCellChange {
pub sheet_idx: usize,
pub row: usize,
pub col: usize,
pub old_value: Value,
pub new_value: Value,
}
#[derive(Debug, Clone, Default, TS)]
#[ts(file_name = "temp_status_diff.ts", rename_all = "camelCase")]
pub struct TempStatusDiff {
pub cells: Vec<TempCellChange>,
}
#[derive(Debug, Clone, TS)]
#[ts(file_name = "block_field.ts", rename_all = "camelCase")]
pub struct BlockField {
pub sheet_id: SheetId,
pub block_id: BlockId,
pub field_id: String,
}