FIX: Fixes types for TypeScript manually (#32)
This commit is contained in:
committed by
GitHub
parent
196e074ef5
commit
b3b7dea930
@@ -3,11 +3,23 @@ use wasm_bindgen::{
|
||||
JsValue,
|
||||
};
|
||||
|
||||
use ironcalc_base::{expressions::types::Area, UserModel as BaseModel};
|
||||
use ironcalc_base::{
|
||||
expressions::{lexer::util::get_tokens as tokenizer, types::Area},
|
||||
types::CellType,
|
||||
UserModel as BaseModel,
|
||||
};
|
||||
|
||||
fn to_js_error(error: String) -> JsError {
|
||||
JsError::new(&error.to_string())
|
||||
}
|
||||
|
||||
/// Return an array with a list of all the tokens from a formula
|
||||
/// This is used by the UI to color them according to a theme.
|
||||
#[wasm_bindgen(js_name = "getTokens")]
|
||||
pub fn get_tokens(formula: &str) -> Result<JsValue, JsError> {
|
||||
let tokens = tokenizer(formula);
|
||||
serde_wasm_bindgen::to_value(&tokens).map_err(JsError::from)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub struct Model {
|
||||
model: BaseModel,
|
||||
@@ -21,6 +33,11 @@ impl Model {
|
||||
Ok(Model { model })
|
||||
}
|
||||
|
||||
pub fn from_bytes(bytes: &[u8]) -> Result<Model, JsError> {
|
||||
let model = BaseModel::from_bytes(bytes).map_err(to_js_error)?;
|
||||
Ok(Model { model })
|
||||
}
|
||||
|
||||
pub fn undo(&mut self) -> Result<(), JsError> {
|
||||
self.model.undo().map_err(to_js_error)
|
||||
}
|
||||
@@ -247,6 +264,24 @@ impl Model {
|
||||
.map(|x| serde_wasm_bindgen::to_value(&x).unwrap())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "getCellType")]
|
||||
pub fn get_cell_type(&self, sheet: u32, row: i32, column: i32) -> Result<i32, JsError> {
|
||||
Ok(
|
||||
match self
|
||||
.model
|
||||
.get_cell_type(sheet, row, column)
|
||||
.map_err(to_js_error)?
|
||||
{
|
||||
CellType::Number => 1,
|
||||
CellType::Text => 2,
|
||||
CellType::LogicalValue => 4,
|
||||
CellType::ErrorValue => 16,
|
||||
CellType::Array => 64,
|
||||
CellType::CompoundData => 128,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "getWorksheetsProperties")]
|
||||
pub fn get_worksheets_properties(&self) -> JsValue {
|
||||
serde_wasm_bindgen::to_value(&self.model.get_worksheets_properties()).unwrap()
|
||||
|
||||
Reference in New Issue
Block a user