Compare commits
8 Commits
dani/widge
...
hackaton
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9effd8e4b5 | ||
|
|
be66af8e16 | ||
|
|
8c5fe019b8 | ||
|
|
7bf36959ca | ||
|
|
abaeb3284a | ||
|
|
7635cbe1d1 | ||
|
|
293303b59c | ||
|
|
2a809e0bd0 |
4
.github/workflows/pypi.yml
vendored
4
.github/workflows/pypi.yml
vendored
@@ -117,7 +117,7 @@ jobs:
|
|||||||
MATURIN_REPOSITORY_URL: "https://test.pypi.org/legacy/"
|
MATURIN_REPOSITORY_URL: "https://test.pypi.org/legacy/"
|
||||||
with:
|
with:
|
||||||
command: upload
|
command: upload
|
||||||
args: "--skip-existing **/*.whl"
|
args: "--skip-existing **/*.whl **/*.tar.gz"
|
||||||
working-directory: bindings/python
|
working-directory: bindings/python
|
||||||
|
|
||||||
publish-pypi:
|
publish-pypi:
|
||||||
@@ -137,5 +137,5 @@ jobs:
|
|||||||
MATURIN_REPOSITORY_URL: "https://upload.pypi.org/legacy/"
|
MATURIN_REPOSITORY_URL: "https://upload.pypi.org/legacy/"
|
||||||
with:
|
with:
|
||||||
command: upload
|
command: upload
|
||||||
args: "--skip-existing **/*.whl"
|
args: "--skip-existing **/*.whl **/*.tar.gz"
|
||||||
working-directory: bindings/python
|
working-directory: bindings/python
|
||||||
|
|||||||
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -721,11 +721,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3"
|
name = "pyo3"
|
||||||
version = "0.23.4"
|
version = "0.25.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57fe09249128b3173d092de9523eaa75136bf7ba85e0d69eca241c7939c933cc"
|
checksum = "f239d656363bcee73afef85277f1b281e8ac6212a1d42aa90e55b90ed43c47a4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
|
||||||
"indoc",
|
"indoc",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
@@ -739,9 +738,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-build-config"
|
name = "pyo3-build-config"
|
||||||
version = "0.23.4"
|
version = "0.25.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1cd3927b5a78757a0d71aa9dff669f903b1eb64b54142a9bd9f757f8fde65fd7"
|
checksum = "755ea671a1c34044fa165247aaf6f419ca39caa6003aee791a0df2713d8f1b6d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
@@ -749,9 +748,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-ffi"
|
name = "pyo3-ffi"
|
||||||
version = "0.23.4"
|
version = "0.25.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dab6bb2102bd8f991e7749f130a70d05dd557613e39ed2deeee8e9ca0c4d548d"
|
checksum = "fc95a2e67091e44791d4ea300ff744be5293f394f1bafd9f78c080814d35956e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"pyo3-build-config",
|
"pyo3-build-config",
|
||||||
@@ -759,9 +758,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-macros"
|
name = "pyo3-macros"
|
||||||
version = "0.23.4"
|
version = "0.25.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "91871864b353fd5ffcb3f91f2f703a22a9797c91b9ab497b1acac7b07ae509c7"
|
checksum = "a179641d1b93920829a62f15e87c0ed791b6c8db2271ba0fd7c2686090510214"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"pyo3-macros-backend",
|
"pyo3-macros-backend",
|
||||||
@@ -771,9 +770,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-macros-backend"
|
name = "pyo3-macros-backend"
|
||||||
version = "0.23.4"
|
version = "0.25.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "43abc3b80bc20f3facd86cd3c60beed58c3e2aa26213f3cda368de39c60a27e4"
|
checksum = "9dff85ebcaab8c441b0e3f7ae40a6963ecea8a9f5e74f647e33fcf5ec9a1e89e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -784,8 +783,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyroncalc"
|
name = "pyroncalc"
|
||||||
version = "0.5.0"
|
version = "0.5.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bitcode",
|
||||||
"ironcalc",
|
"ironcalc",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -979,9 +979,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "target-lexicon"
|
name = "target-lexicon"
|
||||||
version = "0.12.16"
|
version = "0.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
@@ -1070,7 +1070,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
version = "0.5.0"
|
version = "0.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ironcalc_base",
|
"ironcalc_base",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -405,6 +405,7 @@ impl Model {
|
|||||||
},
|
},
|
||||||
tables: HashMap::new(),
|
tables: HashMap::new(),
|
||||||
views,
|
views,
|
||||||
|
users: Vec::new(),
|
||||||
};
|
};
|
||||||
let parsed_formulas = Vec::new();
|
let parsed_formulas = Vec::new();
|
||||||
let worksheets = &workbook.worksheets;
|
let worksheets = &workbook.worksheets;
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ pub struct WorkbookView {
|
|||||||
pub window_height: i64,
|
pub window_height: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct WebUser {
|
||||||
|
pub id: String,
|
||||||
|
pub sheet: u32,
|
||||||
|
pub row: i32,
|
||||||
|
pub column: i32,
|
||||||
|
}
|
||||||
|
|
||||||
/// An internal representation of an IronCalc Workbook
|
/// An internal representation of an IronCalc Workbook
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
||||||
pub struct Workbook {
|
pub struct Workbook {
|
||||||
@@ -51,6 +59,7 @@ pub struct Workbook {
|
|||||||
pub metadata: Metadata,
|
pub metadata: Metadata,
|
||||||
pub tables: HashMap<String, Table>,
|
pub tables: HashMap<String, Table>,
|
||||||
pub views: HashMap<u32, WorkbookView>,
|
pub views: HashMap<u32, WorkbookView>,
|
||||||
|
pub users: Vec<WebUser>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A defined name. The `sheet_id` is the sheet index in case the name is local
|
/// A defined name. The `sheet_id` is the sheet index in case the name is local
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::{
|
|||||||
model::Model,
|
model::Model,
|
||||||
types::{
|
types::{
|
||||||
Alignment, BorderItem, CellType, Col, HorizontalAlignment, SheetProperties, SheetState,
|
Alignment, BorderItem, CellType, Col, HorizontalAlignment, SheetProperties, SheetState,
|
||||||
Style, VerticalAlignment,
|
Style, VerticalAlignment, WebUser,
|
||||||
},
|
},
|
||||||
utils::is_valid_hex_color,
|
utils::is_valid_hex_color,
|
||||||
};
|
};
|
||||||
@@ -293,6 +293,11 @@ impl UserModel {
|
|||||||
self.model.workbook.name = name.to_string();
|
self.model.workbook.name = name.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set users
|
||||||
|
pub fn set_users(&mut self, users: &[WebUser]) {
|
||||||
|
self.model.workbook.users = users.to_vec();
|
||||||
|
}
|
||||||
|
|
||||||
/// Undoes last change if any, places the change in the redo list and evaluates the model if needed
|
/// Undoes last change if any, places the change in the redo list and evaluates the model if needed
|
||||||
///
|
///
|
||||||
/// See also:
|
/// See also:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pyroncalc"
|
name = "pyroncalc"
|
||||||
version = "0.5.0"
|
version = "0.5.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
||||||
@@ -13,7 +13,8 @@ crate-type = ["cdylib"]
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
xlsx = { package= "ironcalc", path = "../../xlsx", version = "0.5.0" }
|
xlsx = { package= "ironcalc", path = "../../xlsx", version = "0.5.0" }
|
||||||
pyo3 = { version = "0.23", features = ["extension-module"] }
|
pyo3 = { version = "0.25", features = ["extension-module"] }
|
||||||
|
bitcode = "0.6.3"
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "ironcalc"
|
name = "ironcalc"
|
||||||
version = "0.5.0"
|
version = "0.5.6"
|
||||||
description = "Create, edit and evaluate Excel spreadsheets"
|
description = "Create, edit and evaluate Excel spreadsheets"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
keywords = [
|
keywords = [
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use pyo3::exceptions::PyException;
|
|||||||
use pyo3::{create_exception, prelude::*, wrap_pyfunction};
|
use pyo3::{create_exception, prelude::*, wrap_pyfunction};
|
||||||
|
|
||||||
use types::{PySheetProperty, PyStyle};
|
use types::{PySheetProperty, PyStyle};
|
||||||
use xlsx::base::types::Style;
|
use xlsx::base::types::{Style, Workbook};
|
||||||
use xlsx::base::Model;
|
use xlsx::base::{Model, UserModel};
|
||||||
|
|
||||||
use xlsx::export::{save_to_icalc, save_to_xlsx};
|
use xlsx::export::{save_to_icalc, save_to_xlsx};
|
||||||
use xlsx::import;
|
use xlsx::import;
|
||||||
@@ -14,6 +14,60 @@ use crate::types::PyCellType;
|
|||||||
|
|
||||||
create_exception!(_ironcalc, WorkbookError, PyException);
|
create_exception!(_ironcalc, WorkbookError, PyException);
|
||||||
|
|
||||||
|
#[pyclass]
|
||||||
|
pub struct PyUserModel {
|
||||||
|
/// The user model, which is a wrapper around the Model
|
||||||
|
pub model: UserModel,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
impl PyUserModel {
|
||||||
|
/// Saves the user model to an xlsx file
|
||||||
|
pub fn save_to_xlsx(&self, file: &str) -> PyResult<()> {
|
||||||
|
let model = self.model.get_model();
|
||||||
|
save_to_xlsx(model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Saves the user model to file in the internal binary ic format
|
||||||
|
pub fn save_to_icalc(&self, file: &str) -> PyResult<()> {
|
||||||
|
let model = self.model.get_model();
|
||||||
|
save_to_icalc(model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply_external_diffs(&mut self, external_diffs: &[u8]) -> PyResult<()> {
|
||||||
|
self.model
|
||||||
|
.apply_external_diffs(external_diffs)
|
||||||
|
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn flush_send_queue(&mut self) -> Vec<u8> {
|
||||||
|
self.model.flush_send_queue()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_user_input(
|
||||||
|
&mut self,
|
||||||
|
sheet: u32,
|
||||||
|
row: i32,
|
||||||
|
column: i32,
|
||||||
|
value: &str,
|
||||||
|
) -> PyResult<()> {
|
||||||
|
self.model
|
||||||
|
.set_user_input(sheet, row, column, value)
|
||||||
|
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_formatted_cell_value(&self, sheet: u32, row: i32, column: i32) -> PyResult<String> {
|
||||||
|
self.model
|
||||||
|
.get_formatted_cell_value(sheet, row, column)
|
||||||
|
.map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_bytes(&self) -> PyResult<Vec<u8>> {
|
||||||
|
let bytes = self.model.to_bytes();
|
||||||
|
Ok(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This is a model implementing the 'raw' API
|
/// This is a model implementing the 'raw' API
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct PyModel {
|
pub struct PyModel {
|
||||||
@@ -32,6 +86,12 @@ impl PyModel {
|
|||||||
save_to_icalc(&self.model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
save_to_icalc(&self.model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// To bytes
|
||||||
|
pub fn to_bytes(&self) -> PyResult<Vec<u8>> {
|
||||||
|
let bytes = self.model.to_bytes();
|
||||||
|
Ok(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
/// Evaluates the workbook
|
/// Evaluates the workbook
|
||||||
pub fn evaluate(&mut self) {
|
pub fn evaluate(&mut self) {
|
||||||
self.model.evaluate()
|
self.model.evaluate()
|
||||||
@@ -249,6 +309,15 @@ pub fn load_from_icalc(file_name: &str) -> PyResult<PyModel> {
|
|||||||
Ok(PyModel { model })
|
Ok(PyModel { model })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
pub fn load_from_bytes(bytes: &[u8]) -> PyResult<PyModel> {
|
||||||
|
let workbook: Workbook =
|
||||||
|
bitcode::decode(bytes).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
let model =
|
||||||
|
Model::from_workbook(workbook).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
Ok(PyModel { model })
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates an empty model
|
/// Creates an empty model
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
|
pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
|
||||||
@@ -257,6 +326,43 @@ pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
|
|||||||
Ok(PyModel { model })
|
Ok(PyModel { model })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
pub fn create_user_model(name: &str, locale: &str, tz: &str) -> PyResult<PyUserModel> {
|
||||||
|
let model = UserModel::new_empty(name, locale, tz)
|
||||||
|
.map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
Ok(PyUserModel { model })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
pub fn create_user_model_from_xlsx(
|
||||||
|
file_path: &str,
|
||||||
|
locale: &str,
|
||||||
|
tz: &str,
|
||||||
|
) -> PyResult<PyUserModel> {
|
||||||
|
let model = import::load_from_xlsx(file_path, locale, tz)
|
||||||
|
.map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
let model = UserModel::from_model(model);
|
||||||
|
Ok(PyUserModel { model })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
pub fn create_user_model_from_icalc(file_name: &str) -> PyResult<PyUserModel> {
|
||||||
|
let model =
|
||||||
|
import::load_from_icalc(file_name).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
let model = UserModel::from_model(model);
|
||||||
|
Ok(PyUserModel { model })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
pub fn create_user_model_from_bytes(bytes: &[u8]) -> PyResult<PyUserModel> {
|
||||||
|
let workbook: Workbook =
|
||||||
|
bitcode::decode(bytes).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
let model =
|
||||||
|
Model::from_workbook(workbook).map_err(|e| WorkbookError::new_err(e.to_string()))?;
|
||||||
|
let user_model = UserModel::from_model(model);
|
||||||
|
Ok(PyUserModel { model: user_model })
|
||||||
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
#[allow(clippy::panic)]
|
#[allow(clippy::panic)]
|
||||||
pub fn test_panic() {
|
pub fn test_panic() {
|
||||||
@@ -272,7 +378,14 @@ fn ironcalc(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|||||||
m.add_function(wrap_pyfunction!(create, m)?)?;
|
m.add_function(wrap_pyfunction!(create, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(load_from_xlsx, m)?)?;
|
m.add_function(wrap_pyfunction!(load_from_xlsx, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(load_from_icalc, m)?)?;
|
m.add_function(wrap_pyfunction!(load_from_icalc, m)?)?;
|
||||||
|
m.add_function(wrap_pyfunction!(load_from_bytes, m)?)?;
|
||||||
m.add_function(wrap_pyfunction!(test_panic, m)?)?;
|
m.add_function(wrap_pyfunction!(test_panic, m)?)?;
|
||||||
|
|
||||||
|
// User model functions
|
||||||
|
m.add_function(wrap_pyfunction!(create_user_model, m)?)?;
|
||||||
|
m.add_function(wrap_pyfunction!(create_user_model_from_bytes, m)?)?;
|
||||||
|
m.add_function(wrap_pyfunction!(create_user_model_from_xlsx, m)?)?;
|
||||||
|
m.add_function(wrap_pyfunction!(create_user_model_from_icalc, m)?)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,24 @@ def test_simple():
|
|||||||
model.evaluate()
|
model.evaluate()
|
||||||
|
|
||||||
assert model.get_formatted_cell_value(0, 1, 1) == "3"
|
assert model.get_formatted_cell_value(0, 1, 1) == "3"
|
||||||
|
|
||||||
|
bytes = model.to_bytes()
|
||||||
|
|
||||||
|
model2 = ic.load_from_bytes(bytes)
|
||||||
|
assert model2.get_formatted_cell_value(0, 1, 1) == "3"
|
||||||
|
|
||||||
|
|
||||||
|
def test_simple_user():
|
||||||
|
model = ic.create_user_model("model", "en", "UTC")
|
||||||
|
model.set_user_input(0, 1, 1, "=1+2")
|
||||||
|
model.set_user_input(0, 1, 2, "=A1+3")
|
||||||
|
|
||||||
|
assert model.get_formatted_cell_value(0, 1, 1) == "3"
|
||||||
|
assert model.get_formatted_cell_value(0, 1, 2) == "6"
|
||||||
|
|
||||||
|
diffs = model.flush_send_queue()
|
||||||
|
|
||||||
|
model2 = ic.create_user_model("model", "en", "UTC")
|
||||||
|
model2.apply_external_diffs(diffs)
|
||||||
|
assert model2.get_formatted_cell_value(0, 1, 1) == "3"
|
||||||
|
assert model2.get_formatted_cell_value(0, 1, 2) == "6"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
version = "0.5.0"
|
version = "0.5.3"
|
||||||
authors = ["Nicolas Hatcher <nicolas@theuniverse.today>"]
|
authors = ["Nicolas Hatcher <nicolas@theuniverse.today>"]
|
||||||
description = "IronCalc Web bindings"
|
description = "IronCalc Web bindings"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|||||||
@@ -201,6 +201,36 @@ defined_name_list_types = r"""
|
|||||||
getDefinedNameList(): DefinedName[];
|
getDefinedNameList(): DefinedName[];
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
set_users = r"""
|
||||||
|
/**
|
||||||
|
* @param {any} users
|
||||||
|
*/
|
||||||
|
setUsers(users: any): void;
|
||||||
|
"""
|
||||||
|
|
||||||
|
set_users_types = r"""
|
||||||
|
/**
|
||||||
|
* @param {WebUser[]} users
|
||||||
|
*/
|
||||||
|
setUsers(users: WebUser[]): void;
|
||||||
|
"""
|
||||||
|
|
||||||
|
get_users = r"""
|
||||||
|
/**
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
getUsers(): any;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
get_users_types = r"""
|
||||||
|
/**
|
||||||
|
* @returns {WebUser[]}
|
||||||
|
*/
|
||||||
|
getUsers(): WebUser[];
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
def fix_types(text):
|
def fix_types(text):
|
||||||
text = text.replace(get_tokens_str, get_tokens_str_types)
|
text = text.replace(get_tokens_str, get_tokens_str_types)
|
||||||
text = text.replace(update_style_str, update_style_str_types)
|
text = text.replace(update_style_str, update_style_str_types)
|
||||||
@@ -215,6 +245,8 @@ def fix_types(text):
|
|||||||
text = text.replace(clipboard, clipboard_types)
|
text = text.replace(clipboard, clipboard_types)
|
||||||
text = text.replace(paste_from_clipboard, paste_from_clipboard_types)
|
text = text.replace(paste_from_clipboard, paste_from_clipboard_types)
|
||||||
text = text.replace(defined_name_list, defined_name_list_types)
|
text = text.replace(defined_name_list, defined_name_list_types)
|
||||||
|
text = text.replace(set_users, set_users_types)
|
||||||
|
text = text.replace(get_users, get_users_types)
|
||||||
with open("types.ts") as f:
|
with open("types.ts") as f:
|
||||||
types_str = f.read()
|
types_str = f.read()
|
||||||
header_types = "{}\n\n{}".format(header, types_str)
|
header_types = "{}\n\n{}".format(header, types_str)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use wasm_bindgen::{
|
|||||||
|
|
||||||
use ironcalc_base::{
|
use ironcalc_base::{
|
||||||
expressions::{lexer::util::get_tokens as tokenizer, types::Area, utils::number_to_column},
|
expressions::{lexer::util::get_tokens as tokenizer, types::Area, utils::number_to_column},
|
||||||
types::{CellType, Style},
|
types::{CellType, Style, WebUser},
|
||||||
BorderArea, ClipboardData, UserModel as BaseModel,
|
BorderArea, ClipboardData, UserModel as BaseModel,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -672,4 +672,18 @@ impl Model {
|
|||||||
.delete_defined_name(name, scope)
|
.delete_defined_name(name, scope)
|
||||||
.map_err(|e| to_js_error(e.to_string()))
|
.map_err(|e| to_js_error(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = "setUsers")]
|
||||||
|
pub fn set_users(&mut self, users: JsValue) -> Result<(), JsError> {
|
||||||
|
let users: Vec<WebUser> =
|
||||||
|
serde_wasm_bindgen::from_value(users).map_err(|e| to_js_error(e.to_string()))?;
|
||||||
|
self.model.set_users(&users);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = "getUsers")]
|
||||||
|
pub fn get_users(&self) -> Result<JsValue, JsError> {
|
||||||
|
let users = self.model.get_model().workbook.users.clone();
|
||||||
|
serde_wasm_bindgen::to_value(&users).map_err(|e| to_js_error(e.to_string()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,4 +233,11 @@ export interface DefinedName {
|
|||||||
name: string;
|
name: string;
|
||||||
scope?: number;
|
scope?: number;
|
||||||
formula: string;
|
formula: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WebUser {
|
||||||
|
id: string;
|
||||||
|
sheet: number;
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
}
|
}
|
||||||
17
webapp/IronCalc/package-lock.json
generated
17
webapp/IronCalc/package-lock.json
generated
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "@ironcalc/workbook",
|
"name": "@ironcalc/workbook",
|
||||||
"version": "0.3.2",
|
"version": "0.5.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@ironcalc/workbook",
|
"name": "@ironcalc/workbook",
|
||||||
"version": "0.3.2",
|
"version": "0.5.5",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.0",
|
"@emotion/styled": "^11.14.0",
|
||||||
"@ironcalc/wasm": "file:../../bindings/wasm/pkg",
|
"@ironcalc/wasm": "0.5.3",
|
||||||
"@mui/material": "^6.4",
|
"@mui/material": "^6.4",
|
||||||
"@mui/system": "^6.4",
|
"@mui/system": "^6.4",
|
||||||
"i18next": "^23.11.1",
|
"i18next": "^23.11.1",
|
||||||
@@ -43,11 +43,6 @@
|
|||||||
"react-dom": "^18.0.0 || ^19.0.0"
|
"react-dom": "^18.0.0 || ^19.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"../../bindings/wasm/pkg": {
|
|
||||||
"name": "@ironcalc/wasm",
|
|
||||||
"version": "0.5.0",
|
|
||||||
"license": "MIT/Apache-2.0"
|
|
||||||
},
|
|
||||||
"node_modules/@adobe/css-tools": {
|
"node_modules/@adobe/css-tools": {
|
||||||
"version": "4.4.2",
|
"version": "4.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.2.tgz",
|
"resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.2.tgz",
|
||||||
@@ -1060,8 +1055,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ironcalc/wasm": {
|
"node_modules/@ironcalc/wasm": {
|
||||||
"resolved": "../../bindings/wasm/pkg",
|
"version": "0.5.3",
|
||||||
"link": true
|
"resolved": "https://registry.npmjs.org/@ironcalc/wasm/-/wasm-0.5.3.tgz",
|
||||||
|
"integrity": "sha512-ryQKR5ISkSQnnsxBYDnrAUN+GDiAQUx0MzkVpJr7VQXiymOSMZbHfpv5geum1eSJV4gw1ft69syuNolIhVZ4Hg==",
|
||||||
|
"license": "MIT/Apache-2.0"
|
||||||
},
|
},
|
||||||
"node_modules/@isaacs/cliui": {
|
"node_modules/@isaacs/cliui": {
|
||||||
"version": "8.0.2",
|
"version": "8.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ironcalc/workbook",
|
"name": "@ironcalc/workbook",
|
||||||
"version": "0.3.2",
|
"version": "0.5.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/ironcalc.js",
|
"main": "./dist/ironcalc.js",
|
||||||
"module": "./dist/ironcalc.js",
|
"module": "./dist/ironcalc.js",
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.0",
|
"@emotion/styled": "^11.14.0",
|
||||||
"@ironcalc/wasm": "file:../../bindings/wasm/pkg",
|
"@ironcalc/wasm": "0.5.3",
|
||||||
"@mui/material": "^6.4",
|
"@mui/material": "^6.4",
|
||||||
"@mui/system": "^6.4",
|
"@mui/system": "^6.4",
|
||||||
"i18next": "^23.11.1",
|
"i18next": "^23.11.1",
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ import {
|
|||||||
outlineColor,
|
outlineColor,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
|
|
||||||
|
export interface UserSelection {
|
||||||
|
userId: string;
|
||||||
|
color: string;
|
||||||
|
selection: [number, number, number, number, number]; // [sheet, rowStart, columnStart, rowEnd, columnEnd]
|
||||||
|
div: HTMLDivElement;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CanvasSettings {
|
export interface CanvasSettings {
|
||||||
model: Model;
|
model: Model;
|
||||||
width: number;
|
width: number;
|
||||||
@@ -1244,6 +1251,33 @@ export default class WorksheetCanvas {
|
|||||||
editor.style.height = `${height - 1}px`;
|
editor.style.height = `${height - 1}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private drawUsersSelection(): void {
|
||||||
|
const users = this.model.getUsers();
|
||||||
|
for (const handle of document.querySelectorAll(
|
||||||
|
".user-selection-ironcalc",
|
||||||
|
))
|
||||||
|
handle.remove();
|
||||||
|
users.forEach((user, index) => {
|
||||||
|
const { sheet, row, column } = user;
|
||||||
|
if (sheet !== this.model.getSelectedSheet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [x, y] = this.getCoordinatesByCell(row, column);
|
||||||
|
const width = this.getColumnWidth(sheet, column);
|
||||||
|
const height = this.getRowHeight(sheet, row);
|
||||||
|
const div = document.createElement("div");
|
||||||
|
const color = getColor(index + 1);
|
||||||
|
div.className = "user-selection-ironcalc";
|
||||||
|
div.style.left = `${x}px`;
|
||||||
|
div.style.top = `${y}px`;
|
||||||
|
div.style.width = `${width}px`;
|
||||||
|
div.style.height = `${height}px`;
|
||||||
|
div.style.border = `1px solid ${color}`;
|
||||||
|
div.style.position = "absolute";
|
||||||
|
this.canvas.parentElement?.appendChild(div);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private drawCellOutline(): void {
|
private drawCellOutline(): void {
|
||||||
const { cellOutline, areaOutline, cellOutlineHandle } = this;
|
const { cellOutline, areaOutline, cellOutlineHandle } = this;
|
||||||
if (this.workbookState.getEditingCell()) {
|
if (this.workbookState.getEditingCell()) {
|
||||||
@@ -1595,6 +1629,7 @@ export default class WorksheetCanvas {
|
|||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
this.drawCellOutline();
|
this.drawCellOutline();
|
||||||
|
this.drawUsersSelection();
|
||||||
this.drawCellEditor();
|
this.drawCellEditor();
|
||||||
this.drawExtendToArea();
|
this.drawExtendToArea();
|
||||||
this.drawActiveRanges(topLeftCell, bottomRightCell);
|
this.drawActiveRanges(topLeftCell, bottomRightCell);
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ fn load_xlsx_from_reader<R: Read + std::io::Seek>(
|
|||||||
metadata,
|
metadata,
|
||||||
tables,
|
tables,
|
||||||
views,
|
views,
|
||||||
|
users: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user