logisheets_rs/lib.rs
1//! # logisheets-rs
2//!
3//! The Rust API for the LogiSheets spreadsheet engine: open, edit, recalculate
4//! and save `.xlsx` workbooks.
5//!
6//! This crate is a facade. The engine lives in `logisheets_controller`, file
7//! I/O in `logisheets_workbook`, shared ids in `logisheets_base`; this crate
8//! re-exports what callers need so they depend on it alone. The optional
9//! `rpc` feature adds [`rpc`], the message protocol the browser WASM binding
10//! (`logisheets_wasm_server`) and the desktop host drive the engine through.
11//!
12//! ## Quick start
13//!
14//! ```rust,no_run
15//! use logisheets_rs::{CellInput, EditAction, PayloadsAction, StatusCode, Workbook};
16//!
17//! // A new workbook already holds one sheet, "Sheet1".
18//! let mut wb = Workbook::new();
19//!
20//! // Writes are transactions of payloads. Content is parsed like typed
21//! // input: "1" is a number, "=A1*2" a formula.
22//! let action = PayloadsAction::new()
23//! .add_payload(CellInput { sheet_idx: 0, row: 0, col: 0, content: "1".into() })
24//! .add_payload(CellInput { sheet_idx: 0, row: 1, col: 0, content: "=A1*2".into() })
25//! .set_undoable(true);
26//! let effect = wb.handle_action(EditAction::Payloads(action));
27//! if let StatusCode::Err(_) = effect.status {
28//! panic!("rejected: {:?}", effect.error_message);
29//! }
30//!
31//! // Formulas recalculate as part of the write.
32//! let value = wb.get_sheet_by_idx(0).unwrap().get_value(1, 0).unwrap();
33//!
34//! // Round-trip through .xlsx bytes.
35//! let bytes = wb.save().unwrap();
36//! let reopened = Workbook::from_file(&bytes, "book.xlsx".to_string()).unwrap();
37//! ```
38//!
39//! ## Contracts worth knowing
40//!
41//! - **Coordinates are 0-based**: `row: 0, col: 0` is `A1`. A `sheet_idx` is a
42//! sheet's current position and shifts when sheets are added or removed; a
43//! [`SheetId`] is stable. Cells, rows and columns likewise have stable ids
44//! ([`CellId`], [`RowId`], [`ColId`]) that survive inserts and deletes.
45//! - **A rejected write is not an `Err`.** `handle_action` always returns an
46//! [`ActionEffect`]; check its `status`. A rejected transaction applies
47//! none of its payloads, and `error_message` names the one it stopped at.
48//! - **Payloads run in order**, each seeing the previous ones' effects, so a
49//! write to B4 before an `InsertRows` lands on a different cell than after.
50//! - **`undoable` defaults to `false`** on [`PayloadsAction::new`]; call
51//! `set_undoable(true)` for a write the user should be able to undo.
52//! - **The temp branch is workbook-wide.** `handle_action_in_temp_status`
53//! opens one branch that later temp writes accumulate on until
54//! `commit_temp_status` or `clean_temp_status`; any non-temp write
55//! discards it. Check `is_in_temp_mode` before opening one of your own.
56//! - **Reads return [`Result`]** with [`Error`]; the RPC layer flattens that
57//! to [`ErrorMessage`].
58
59// Re-export the main Workbook and Worksheet types from controller/api
60pub use logisheets_controller::api::{
61 BlockOpForPayload, BlockOpPolicy, BlockSortOrder, CellInfo, CellRefRange, CfRuleInfo,
62 DefinedNameInfo, DependentCell, DuplicateBlockKey, EnumSetInfo, EnumVariantInfo,
63 FieldValidationVerdict, FillRange, PivotExcelNote, PivotPlan, PivotSpecParts, ReproducibleCell,
64 SaveFileResult, SheetCoordinate, SheetDimension, Workbook, Worksheet,
65};
66
67// Re-export display types
68pub use logisheets_controller::controller::display::{
69 BlockCellInfo, BlockDataRow, BlockDisplayInfo, BlockField, BlockInfo, BlockSchema,
70 BlockSchemaRandomEntry, BlockSchemaType, CellCoordinate, CellCoordinateWithSheet,
71 CellImageInfo, CellPosition, ChartAxisScaleInfo, ChartDataLabelsInfo, ChartInfo,
72 ChartOfPieSplitInfo, ChartSeriesInfo, ColInfo, DisplayWindow, DisplayWindowRequest,
73 DisplayWindowWithStartPoint, LinkInfo, RowInfo, ShadowCellInfo, SheetInfo, TempCellChange,
74 TempStatusDiff,
75};
76
77// Re-export edit actions
78pub use logisheets_controller::edit_action::{
79 ActionEffect, Alignment, AsyncFuncResult, AxisScaleUpdate, BindFormSchema, BindRandomSchema,
80 BlockActor, BlockInput, BlockLineNameFieldUpdate, BlockLineStyleUpdate, BlockModifyInfo,
81 BlockOp, BlockPermissions, CellClear, CellFormatBrush, CellInput, CellStyleUpdate,
82 CreateAppendix, CreateBlock, CreateDiyCell, CreateSheet, DefineName, DeleteCellImage,
83 DeleteCols, DeleteColsInBlock, DeleteRows, DeleteRowsInBlock, DeleteSheet, EditAction,
84 EditPayload, EphemeralCellInput, HorizontalAlignment, InsertCols, InsertColsInBlock,
85 InsertRows, InsertRowsInBlock, LineFormatBrush, LineStyleUpdate, MergeCells, ModifyPolicy,
86 MoveBlock, OfPieSplitUpdate, PayloadsAction, RemoveBlock, RemoveName, RenameName,
87 ReproduceCells, ResizeBlock, SetBlockDescription, SetBlockPermissions, SetCellImage,
88 SetColWidth, SetRowHeight, SetSheetColor, SetSheetVisible, SheetCellId, SheetRename,
89 SplitMergedCells, StatusCode, StyleUpdateType, UpsertFieldRenderInfo, VerticalAlignment,
90};
91
92// Re-export style types
93pub use logisheets_controller::controller::style::{PatternFill, from_hex_str};
94
95// Re-export error types (via api module re-exports)
96pub use logisheets_controller::{Context, Error, ErrorMessage, Result, take_last_error};
97
98// Re-export shadow-cell kind so RPC payloads and host code can tag
99// which derived computation each shadow cell represents.
100pub use logisheets_controller::sid_assigner::ShadowKind;
101
102// Re-export checkpoint primitives so the WASM RPC layer can build
103// response DTOs from them.
104pub use logisheets_controller::checkpoint_manager::{CheckpointManager, CheckpointMeta};
105
106// Re-export value and style types
107pub use logisheets_controller::{Appendix, AppendixWithCell, Comment, MergeCell, Style, Value};
108
109// Re-export FormulaDisplayInfo and lex functions
110pub use logisheets_controller::{FormulaDisplayInfo, lex_and_fmt, lex_success};
111
112// Re-export async calculation types
113pub use logisheets_base::async_func::{AsyncCalcResult, AsyncErr, Task};
114
115// Re-export ID types from base
116pub use logisheets_base::{BlockCellId, BlockId, CellId, ColId, DiyCellId, RowId, SheetId, TextId};
117
118// Re-export errors from base
119pub use logisheets_base::errors::BasicError;
120
121// Re-export workbook types
122pub use logisheets_workbook::logisheets::AppData;
123pub use logisheets_workbook::prelude::{StBorderStyle, StPatternType, StUnderlineValues};
124
125// Transport-agnostic RPC layer (Manager + wire protocol + logic functions),
126// consumed by the browser WASM binding and the native desktop host. Gated so
127// the default public API stays a thin `Workbook` facade.
128#[cfg(feature = "rpc")]
129pub mod rpc;