Compare commits
1 Commits
feature/ni
...
feature/ni
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a71eaf1dd7 |
3
.gitignore
vendored
@@ -1,2 +1 @@
|
|||||||
target/*
|
target/*
|
||||||
.DS_Store
|
|
||||||
12
Cargo.lock
generated
@@ -370,6 +370,7 @@ dependencies = [
|
|||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -678,6 +679,17 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_repr"
|
||||||
|
version = "0.1.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha1"
|
name = "sha1"
|
||||||
version = "0.10.6"
|
version = "0.10.6"
|
||||||
|
|||||||
12
Makefile
@@ -1,6 +1,13 @@
|
|||||||
|
all:
|
||||||
|
cargo build --release
|
||||||
|
cd bindings/wasm/ && make
|
||||||
|
cd webapp && npm install && npm run build
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
cargo fmt -- --check
|
cargo fmt -- --check
|
||||||
cargo clippy --all-targets --all-features
|
# TODO: See issue #33
|
||||||
|
# cargo clippy --all-targets --all-features -- -D warnings -D clippy::expect_used -D clippy::unwrap_used -D clippy::panic
|
||||||
|
cargo clippy --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
format:
|
format:
|
||||||
cargo fmt
|
cargo fmt
|
||||||
@@ -10,7 +17,7 @@ tests: lint
|
|||||||
./target/debug/documentation
|
./target/debug/documentation
|
||||||
cmp functions.md wiki/functions.md || exit 1
|
cmp functions.md wiki/functions.md || exit 1
|
||||||
make remove-artifacts
|
make remove-artifacts
|
||||||
cd bindings/wasm/ && wasm-pack build --target nodejs && node tests/test.mjs
|
cd bindings/wasm/ && make tests
|
||||||
|
|
||||||
remove-artifacts:
|
remove-artifacts:
|
||||||
rm -f xlsx/hello-calc.xlsx
|
rm -f xlsx/hello-calc.xlsx
|
||||||
@@ -25,6 +32,7 @@ clean: remove-artifacts
|
|||||||
rm -f cargo-test-*
|
rm -f cargo-test-*
|
||||||
rm -f base/cargo-test-*
|
rm -f base/cargo-test-*
|
||||||
rm -f xlsx/cargo-test-*
|
rm -f xlsx/cargo-test-*
|
||||||
|
rm -r -f webapp/node_modules
|
||||||
|
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 441 B |
|
Before Width: | Height: | Size: 729 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 33 KiB |
@@ -1,8 +0,0 @@
|
|||||||
<svg width="600" height="600" viewBox="0 0 600 600" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect width="600" height="600" rx="20" fill="#F2994A"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M348.98 100C348.98 166.034 322.748 229.362 276.055 276.055C268.163 283.947 259.796 291.255 251.021 297.95L251.021 500L348.98 500H251.021C251.021 433.966 277.252 370.637 323.945 323.945C331.837 316.053 340.204 308.745 348.98 302.05L348.98 100Z" fill="white"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M251.021 100.068C251.003 140.096 235.094 178.481 206.788 206.787C178.466 235.109 140.053 251.02 100 251.02V348.979C154.873 348.979 207.877 330.866 251.021 297.95V100.068Z" fill="white"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M348.98 499.882C349.011 459.872 364.918 421.507 393.213 393.213C421.534 364.891 459.947 348.98 500 348.98V251.02C445.128 251.02 392.123 269.134 348.98 302.05V499.882Z" fill="white"/>
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M276.055 276.055C322.748 229.362 348.98 166.034 348.98 100H251.021V297.95C259.796 291.255 268.163 283.947 276.055 276.055Z" fill="white"/>
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M348.98 302.05V499.895C348.98 499.93 348.98 499.965 348.98 500L251.021 500C251.021 499.946 251.02 499.891 251.021 499.837C251.064 433.862 277.291 370.599 323.945 323.945C331.837 316.053 340.204 308.745 348.98 302.05Z" fill="white"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB |
BIN
assets/logo.png
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
@@ -12,6 +12,8 @@ readme = "README.md"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
serde_repr = "0.1"
|
||||||
ryu = "1.0"
|
ryu = "1.0"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
chrono-tz = "0.9"
|
chrono-tz = "0.9"
|
||||||
@@ -19,9 +21,6 @@ regex = "1.0"
|
|||||||
once_cell = "1.16.0"
|
once_cell = "1.16.0"
|
||||||
bitcode = "0.6.0"
|
bitcode = "0.6.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
serde_json = "1.0"
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
js-sys = { version = "0.3.69" }
|
js-sys = { version = "0.3.69" }
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
expressions::token::Error, language::Language, number_format::to_excel_precision_str, types::*,
|
expressions::token::Error, language::Language, number_format::to_excel_precision_str, types::*,
|
||||||
};
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
/// A CellValue is the representation of the cell content.
|
/// A CellValue is the representation of the cell content.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(untagged)]
|
||||||
pub enum CellValue {
|
pub enum CellValue {
|
||||||
None,
|
None,
|
||||||
String(String),
|
String(String),
|
||||||
@@ -11,6 +14,17 @@ pub enum CellValue {
|
|||||||
Boolean(bool),
|
Boolean(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CellValue {
|
||||||
|
pub fn to_json_str(&self) -> String {
|
||||||
|
match &self {
|
||||||
|
CellValue::None => "null".to_string(),
|
||||||
|
CellValue::String(s) => json!(s).to_string(),
|
||||||
|
CellValue::Number(f) => json!(f).to_string(),
|
||||||
|
CellValue::Boolean(b) => json!(b).to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<f64> for CellValue {
|
impl From<f64> for CellValue {
|
||||||
fn from(value: f64) -> Self {
|
fn from(value: f64) -> Self {
|
||||||
Self::Number(value)
|
Self::Number(value)
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ impl Parser {
|
|||||||
|
|
||||||
pub fn parse(&mut self, formula: &str, context: &Option<CellReferenceRC>) -> Node {
|
pub fn parse(&mut self, formula: &str, context: &Option<CellReferenceRC>) -> Node {
|
||||||
self.lexer.set_formula(formula);
|
self.lexer.set_formula(formula);
|
||||||
self.context.clone_from(context);
|
self.context = context.clone();
|
||||||
self.parse_expr()
|
self.parse_expr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use bitcode::{Decode, Encode};
|
use bitcode::{Decode, Encode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
use crate::language::Language;
|
use crate::language::Language;
|
||||||
|
|
||||||
@@ -80,7 +81,8 @@ impl fmt::Display for OpProduct {
|
|||||||
/// * "#ERROR!" means there was an error processing the formula (for instance "=A1+")
|
/// * "#ERROR!" means there was an error processing the formula (for instance "=A1+")
|
||||||
/// * "#N/IMPL!" means the formula or feature in Excel but has not been implemented in IronCalc
|
/// * "#N/IMPL!" means the formula or feature in Excel but has not been implemented in IronCalc
|
||||||
/// Note that they are serialized/deserialized by index
|
/// Note that they are serialized/deserialized by index
|
||||||
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize_repr, Deserialize_repr, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
|
#[repr(u8)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
REF,
|
REF,
|
||||||
NAME,
|
NAME,
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
PfrendeesD<>VRAITRUEWAHRVERDADEROTVFAUXFALSEFALSCHFALSOUw#REF!#REF!#BEZUG!#¡REF!e<>#NOM?#NAME?#NAME?#¿NOMBRE?x<>#VALEUR!#VALUE!#WERT!#¡VALOR!w<>#DIV/0!#DIV/0!#DIV/0!#¡DIV/0!<04>#N/A#N/A#NV#N/AXv#NOMBRE!#NUM!#ZAHL!#¡NUM!<02><>#N/IMPL!#N/IMPL!#N/IMPL!#N/IMPL!w{#SPILL!#SPILL!#ÜBERLAUF!#SPILL!ff#CALC!#CALC!#CALC!#CALC!ff#CIRC!#CIRC!#CIRC!#CIRC!ww#ERROR!#ERROR!#ERROR!#ERROR!ff#NULL!#NULL!#NULL!#NULL!
|
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use bitcode::{Decode, Encode};
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
|
||||||
pub struct Booleans {
|
pub struct Booleans {
|
||||||
pub r#true: String,
|
pub r#true: String,
|
||||||
pub r#false: String,
|
pub r#false: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Errors {
|
pub struct Errors {
|
||||||
pub r#ref: String,
|
pub r#ref: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@@ -25,14 +25,14 @@ pub struct Errors {
|
|||||||
pub null: String,
|
pub null: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Language {
|
pub struct Language {
|
||||||
pub booleans: Booleans,
|
pub booleans: Booleans,
|
||||||
pub errors: Errors,
|
pub errors: Errors,
|
||||||
}
|
}
|
||||||
|
|
||||||
static LANGUAGES: Lazy<HashMap<String, Language>> = Lazy::new(|| {
|
static LANGUAGES: Lazy<HashMap<String, Language>> = Lazy::new(|| {
|
||||||
bitcode::decode(include_bytes!("language.bin")).expect("Failed parsing language file")
|
serde_json::from_str(include_str!("language.json")).expect("Failed parsing language file")
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn get_language(id: &str) -> Result<&Language, String> {
|
pub fn get_language(id: &str) -> Result<&Language, String> {
|
||||||
|
|||||||
@@ -1,29 +1,32 @@
|
|||||||
use bitcode::{Decode, Encode};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Locale {
|
pub struct Locale {
|
||||||
pub dates: Dates,
|
pub dates: Dates,
|
||||||
pub numbers: NumbersProperties,
|
pub numbers: NumbersProperties,
|
||||||
pub currency: Currency,
|
pub currency: Currency,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Currency {
|
pub struct Currency {
|
||||||
pub iso: String,
|
pub iso: String,
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct NumbersProperties {
|
pub struct NumbersProperties {
|
||||||
|
#[serde(rename = "symbols-numberSystem-latn")]
|
||||||
pub symbols: NumbersSymbols,
|
pub symbols: NumbersSymbols,
|
||||||
|
#[serde(rename = "decimalFormats-numberSystem-latn")]
|
||||||
pub decimal_formats: DecimalFormats,
|
pub decimal_formats: DecimalFormats,
|
||||||
|
#[serde(rename = "currencyFormats-numberSystem-latn")]
|
||||||
pub currency_formats: CurrencyFormats,
|
pub currency_formats: CurrencyFormats,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Dates {
|
pub struct Dates {
|
||||||
pub day_names: Vec<String>,
|
pub day_names: Vec<String>,
|
||||||
pub day_names_short: Vec<String>,
|
pub day_names_short: Vec<String>,
|
||||||
@@ -32,7 +35,8 @@ pub struct Dates {
|
|||||||
pub months_letter: Vec<String>,
|
pub months_letter: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct NumbersSymbols {
|
pub struct NumbersSymbols {
|
||||||
pub decimal: String,
|
pub decimal: String,
|
||||||
pub group: String,
|
pub group: String,
|
||||||
@@ -50,23 +54,31 @@ pub struct NumbersSymbols {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See: https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
|
// See: https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct CurrencyFormats {
|
pub struct CurrencyFormats {
|
||||||
pub standard: String,
|
pub standard: String,
|
||||||
|
#[serde(rename = "standard-alphaNextToNumber")]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub standard_alpha_next_to_number: Option<String>,
|
pub standard_alpha_next_to_number: Option<String>,
|
||||||
|
#[serde(rename = "standard-noCurrency")]
|
||||||
pub standard_no_currency: String,
|
pub standard_no_currency: String,
|
||||||
pub accounting: String,
|
pub accounting: String,
|
||||||
|
#[serde(rename = "accounting-alphaNextToNumber")]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub accounting_alpha_next_to_number: Option<String>,
|
pub accounting_alpha_next_to_number: Option<String>,
|
||||||
|
#[serde(rename = "accounting-noCurrency")]
|
||||||
pub accounting_no_currency: String,
|
pub accounting_no_currency: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct DecimalFormats {
|
pub struct DecimalFormats {
|
||||||
pub standard: String,
|
pub standard: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
static LOCALES: Lazy<HashMap<String, Locale>> =
|
static LOCALES: Lazy<HashMap<String, Locale>> = Lazy::new(|| {
|
||||||
Lazy::new(|| bitcode::decode(include_bytes!("locales.bin")).expect("Failed parsing locale"));
|
serde_json::from_str(include_str!("locales.json")).expect("Failed parsing locale")
|
||||||
|
});
|
||||||
|
|
||||||
pub fn get_locale(id: &str) -> Result<&Locale, String> {
|
pub fn get_locale(id: &str) -> Result<&Locale, String> {
|
||||||
// TODO: pass the locale once we implement locales in Rust
|
// TODO: pass the locale once we implement locales in Rust
|
||||||
|
|||||||
@@ -118,8 +118,6 @@ pub struct Model {
|
|||||||
pub(crate) language: Language,
|
pub(crate) language: Language,
|
||||||
/// The timezone used to evaluate the model
|
/// The timezone used to evaluate the model
|
||||||
pub(crate) tz: Tz,
|
pub(crate) tz: Tz,
|
||||||
/// The view id. A view consist of a selected sheet and ranges.
|
|
||||||
pub(crate) view_id: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Maybe this should be the same as CellReference
|
// FIXME: Maybe this should be the same as CellReference
|
||||||
@@ -888,7 +886,6 @@ impl Model {
|
|||||||
language,
|
language,
|
||||||
locale,
|
locale,
|
||||||
tz,
|
tz,
|
||||||
view_id: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
model.parse_formulas();
|
model.parse_formulas();
|
||||||
|
|||||||
@@ -6,18 +6,14 @@ use crate::{
|
|||||||
calc_result::Range,
|
calc_result::Range,
|
||||||
expressions::{
|
expressions::{
|
||||||
lexer::LexerMode,
|
lexer::LexerMode,
|
||||||
parser::{
|
parser::stringify::{rename_sheet_in_node, to_rc_format},
|
||||||
stringify::{rename_sheet_in_node, to_rc_format},
|
parser::Parser,
|
||||||
Parser,
|
|
||||||
},
|
|
||||||
types::CellReferenceRC,
|
types::CellReferenceRC,
|
||||||
},
|
},
|
||||||
language::get_language,
|
language::get_language,
|
||||||
locale::get_locale,
|
locale::get_locale,
|
||||||
model::{get_milliseconds_since_epoch, Model, ParsedDefinedName},
|
model::{get_milliseconds_since_epoch, Model, ParsedDefinedName},
|
||||||
types::{
|
types::{Metadata, SheetState, Workbook, WorkbookSettings, Worksheet},
|
||||||
Metadata, SheetState, Workbook, WorkbookSettings, WorkbookView, Worksheet, WorksheetView,
|
|
||||||
},
|
|
||||||
utils::ParsedReference,
|
utils::ParsedReference,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,20 +33,7 @@ fn is_valid_sheet_name(name: &str) -> bool {
|
|||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
/// Creates a new worksheet. Note that it does not check if the name or the sheet_id exists
|
/// Creates a new worksheet. Note that it does not check if the name or the sheet_id exists
|
||||||
fn new_empty_worksheet(name: &str, sheet_id: u32, view_ids: &[&u32]) -> Worksheet {
|
fn new_empty_worksheet(name: &str, sheet_id: u32) -> Worksheet {
|
||||||
let mut views = HashMap::new();
|
|
||||||
for id in view_ids {
|
|
||||||
views.insert(
|
|
||||||
**id,
|
|
||||||
WorksheetView {
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [1, 1, 1, 1],
|
|
||||||
top_row: 1,
|
|
||||||
left_column: 1,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Worksheet {
|
Worksheet {
|
||||||
cols: vec![],
|
cols: vec![],
|
||||||
rows: vec![],
|
rows: vec![],
|
||||||
@@ -65,7 +48,6 @@ impl Model {
|
|||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
frozen_columns: 0,
|
frozen_columns: 0,
|
||||||
frozen_rows: 0,
|
frozen_rows: 0,
|
||||||
views,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +122,7 @@ impl Model {
|
|||||||
self.parsed_defined_names = parsed_defined_names;
|
self.parsed_defined_names = parsed_defined_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reparses all formulas and defined names
|
// Reparses all formulas and defined names
|
||||||
pub(crate) fn reset_parsed_structures(&mut self) {
|
pub(crate) fn reset_parsed_structures(&mut self) {
|
||||||
self.parser
|
self.parser
|
||||||
.set_worksheets(self.workbook.get_worksheet_names());
|
.set_worksheets(self.workbook.get_worksheet_names());
|
||||||
@@ -171,8 +153,7 @@ impl Model {
|
|||||||
let sheet_name = format!("{}{}", base_name, index);
|
let sheet_name = format!("{}{}", base_name, index);
|
||||||
// Now we need a sheet_id
|
// Now we need a sheet_id
|
||||||
let sheet_id = self.get_new_sheet_id();
|
let sheet_id = self.get_new_sheet_id();
|
||||||
let view_ids: Vec<&u32> = self.workbook.views.keys().collect();
|
let worksheet = Model::new_empty_worksheet(&sheet_name, sheet_id);
|
||||||
let worksheet = Model::new_empty_worksheet(&sheet_name, sheet_id, &view_ids);
|
|
||||||
self.workbook.worksheets.push(worksheet);
|
self.workbook.worksheets.push(worksheet);
|
||||||
self.reset_parsed_structures();
|
self.reset_parsed_structures();
|
||||||
(sheet_name, self.workbook.worksheets.len() as u32 - 1)
|
(sheet_name, self.workbook.worksheets.len() as u32 - 1)
|
||||||
@@ -203,8 +184,7 @@ impl Model {
|
|||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => self.get_new_sheet_id(),
|
None => self.get_new_sheet_id(),
|
||||||
};
|
};
|
||||||
let view_ids: Vec<&u32> = self.workbook.views.keys().collect();
|
let worksheet = Model::new_empty_worksheet(sheet_name, sheet_id);
|
||||||
let worksheet = Model::new_empty_worksheet(sheet_name, sheet_id, &view_ids);
|
|
||||||
if sheet_index as usize > self.workbook.worksheets.len() {
|
if sheet_index as usize > self.workbook.worksheets.len() {
|
||||||
return Err("Sheet index out of range".to_string());
|
return Err("Sheet index out of range".to_string());
|
||||||
}
|
}
|
||||||
@@ -351,14 +331,11 @@ impl Model {
|
|||||||
// "2020-08-06T21:20:53Z
|
// "2020-08-06T21:20:53Z
|
||||||
let now = dt.format("%Y-%m-%dT%H:%M:%SZ").to_string();
|
let now = dt.format("%Y-%m-%dT%H:%M:%SZ").to_string();
|
||||||
|
|
||||||
let mut views = HashMap::new();
|
|
||||||
views.insert(0, WorkbookView { sheet: 0 });
|
|
||||||
|
|
||||||
// String versions of the locale are added here to simplify the serialize/deserialize logic
|
// String versions of the locale are added here to simplify the serialize/deserialize logic
|
||||||
let workbook = Workbook {
|
let workbook = Workbook {
|
||||||
shared_strings: vec![],
|
shared_strings: vec![],
|
||||||
defined_names: vec![],
|
defined_names: vec![],
|
||||||
worksheets: vec![Model::new_empty_worksheet("Sheet1", 1, &[&0])],
|
worksheets: vec![Model::new_empty_worksheet("Sheet1", 1)],
|
||||||
styles: Default::default(),
|
styles: Default::default(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
settings: WorkbookSettings {
|
settings: WorkbookSettings {
|
||||||
@@ -374,7 +351,6 @@ impl Model {
|
|||||||
last_modified: now,
|
last_modified: now,
|
||||||
},
|
},
|
||||||
tables: HashMap::new(),
|
tables: HashMap::new(),
|
||||||
views,
|
|
||||||
};
|
};
|
||||||
let parsed_formulas = Vec::new();
|
let parsed_formulas = Vec::new();
|
||||||
let worksheets = &workbook.worksheets;
|
let worksheets = &workbook.worksheets;
|
||||||
@@ -395,7 +371,6 @@ impl Model {
|
|||||||
locale,
|
locale,
|
||||||
language,
|
language,
|
||||||
tz,
|
tz,
|
||||||
view_id: 0,
|
|
||||||
};
|
};
|
||||||
model.parse_formulas();
|
model.parse_formulas();
|
||||||
Ok(model)
|
Ok(model)
|
||||||
|
|||||||
@@ -76,16 +76,10 @@ fn fn_imconjugate() {
|
|||||||
fn fn_imcos() {
|
fn fn_imcos() {
|
||||||
let mut model = new_empty_model();
|
let mut model = new_empty_model();
|
||||||
model._set("A1", r#"=IMCOS("4+3i")"#);
|
model._set("A1", r#"=IMCOS("4+3i")"#);
|
||||||
// In macos non intel this is "-6.58066304055116+7.58155274274655i"
|
|
||||||
model._set("A2", r#"=COMPLEX(-6.58066304055116, 7.58155274274654)"#);
|
|
||||||
model._set("A3", r#"=IMABS(IMSUB(A1, A2)) < G1"#);
|
|
||||||
|
|
||||||
// small number
|
|
||||||
model._set("G1", "0.0000001");
|
|
||||||
|
|
||||||
model.evaluate();
|
model.evaluate();
|
||||||
|
|
||||||
assert_eq!(model._get_text("A3"), "TRUE");
|
assert_eq!(model._get_text("A1"), "-6.58066304055116+7.58155274274654i");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -53,5 +53,4 @@ mod test_frozen_rows_and_columns;
|
|||||||
mod test_get_cell_content;
|
mod test_get_cell_content;
|
||||||
mod test_percentage;
|
mod test_percentage;
|
||||||
mod test_today;
|
mod test_today;
|
||||||
mod test_types;
|
|
||||||
mod user_model;
|
mod user_model;
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use crate::types::{Alignment, HorizontalAlignment, VerticalAlignment};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn alignment_default() {
|
|
||||||
let alignment = Alignment::default();
|
|
||||||
assert_eq!(
|
|
||||||
alignment,
|
|
||||||
Alignment {
|
|
||||||
horizontal: HorizontalAlignment::General,
|
|
||||||
vertical: VerticalAlignment::Bottom,
|
|
||||||
wrap_text: false
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let s = serde_json::to_string(&alignment).unwrap();
|
|
||||||
// defaults stringifies as an empty object
|
|
||||||
assert_eq!(s, "{}");
|
|
||||||
|
|
||||||
let a: Alignment = serde_json::from_str("{}").unwrap();
|
|
||||||
|
|
||||||
assert_eq!(a, alignment)
|
|
||||||
}
|
|
||||||
@@ -8,4 +8,3 @@ mod test_row_column;
|
|||||||
mod test_styles;
|
mod test_styles;
|
||||||
mod test_to_from_bytes;
|
mod test_to_from_bytes;
|
||||||
mod test_undo_redo;
|
mod test_undo_redo;
|
||||||
mod test_view;
|
|
||||||
|
|||||||
@@ -144,18 +144,13 @@ fn basic_fill() {
|
|||||||
|
|
||||||
let style = model.get_cell_style(0, 1, 1).unwrap();
|
let style = model.get_cell_style(0, 1, 1).unwrap();
|
||||||
assert_eq!(style.fill.bg_color, None);
|
assert_eq!(style.fill.bg_color, None);
|
||||||
assert_eq!(style.fill.fg_color, None);
|
|
||||||
|
|
||||||
// bg_color
|
// bg_color
|
||||||
model
|
model
|
||||||
.update_range_style(&range, "fill.bg_color", "#F2F2F2")
|
.update_range_style(&range, "fill.bg_color", "#F2F2F2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
model
|
|
||||||
.update_range_style(&range, "fill.fg_color", "#F3F4F5")
|
|
||||||
.unwrap();
|
|
||||||
let style = model.get_cell_style(0, 1, 1).unwrap();
|
let style = model.get_cell_style(0, 1, 1).unwrap();
|
||||||
assert_eq!(style.fill.bg_color, Some("#F2F2F2".to_owned()));
|
assert_eq!(style.fill.bg_color, Some("#F2F2F2".to_owned()));
|
||||||
assert_eq!(style.fill.fg_color, Some("#F3F4F5".to_owned()));
|
|
||||||
|
|
||||||
let send_queue = model.flush_send_queue();
|
let send_queue = model.flush_send_queue();
|
||||||
|
|
||||||
@@ -164,7 +159,6 @@ fn basic_fill() {
|
|||||||
|
|
||||||
let style = model2.get_cell_style(0, 1, 1).unwrap();
|
let style = model2.get_cell_style(0, 1, 1).unwrap();
|
||||||
assert_eq!(style.fill.bg_color, Some("#F2F2F2".to_owned()));
|
assert_eq!(style.fill.bg_color, Some("#F2F2F2".to_owned()));
|
||||||
assert_eq!(style.fill.fg_color, Some("#F3F4F5".to_owned()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -177,15 +171,9 @@ fn fill_errors() {
|
|||||||
width: 1,
|
width: 1,
|
||||||
height: 1,
|
height: 1,
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert!(model
|
||||||
model.update_range_style(&range, "fill.bg_color", "#FFF"),
|
.update_range_style(&range, "fill.bg_color", "#FFF")
|
||||||
Err("Invalid color: '#FFF'.".to_string())
|
.is_err());
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
model.update_range_style(&range, "fill.fg_color", "#FFF"),
|
|
||||||
Err("Invalid color: '#FFF'.".to_string())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,216 +0,0 @@
|
|||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
constants::{LAST_COLUMN, LAST_ROW},
|
|
||||||
test::util::new_empty_model,
|
|
||||||
user_model::SelectedView,
|
|
||||||
UserModel,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn initial_view() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let model = UserModel::from_model(model);
|
|
||||||
assert_eq!(model.get_selected_sheet(), 0);
|
|
||||||
assert_eq!(model.get_selected_cell(), (0, 1, 1));
|
|
||||||
assert_eq!(
|
|
||||||
model.get_selected_view(),
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [1, 1, 1, 1],
|
|
||||||
top_row: 1,
|
|
||||||
left_column: 1
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn set_the_cell_sets_the_range() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
model.set_selected_cell(5, 4).unwrap();
|
|
||||||
assert_eq!(model.get_selected_sheet(), 0);
|
|
||||||
assert_eq!(model.get_selected_cell(), (0, 5, 4));
|
|
||||||
assert_eq!(
|
|
||||||
model.get_selected_view(),
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 5,
|
|
||||||
column: 4,
|
|
||||||
range: [5, 4, 5, 4],
|
|
||||||
top_row: 1,
|
|
||||||
left_column: 1
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn set_the_range_does_not_set_the_cell() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
model.set_selected_range(5, 4, 10, 6).unwrap();
|
|
||||||
assert_eq!(model.get_selected_sheet(), 0);
|
|
||||||
assert_eq!(model.get_selected_cell(), (0, 1, 1));
|
|
||||||
assert_eq!(
|
|
||||||
model.get_selected_view(),
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [5, 4, 10, 6],
|
|
||||||
top_row: 1,
|
|
||||||
left_column: 1
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_new_sheet_and_back() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
model.new_sheet();
|
|
||||||
assert_eq!(model.get_selected_sheet(), 0);
|
|
||||||
model.set_selected_cell(5, 4).unwrap();
|
|
||||||
model.set_selected_sheet(1).unwrap();
|
|
||||||
assert_eq!(model.get_selected_cell(), (1, 1, 1));
|
|
||||||
model.set_selected_sheet(0).unwrap();
|
|
||||||
assert_eq!(model.get_selected_cell(), (0, 5, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn set_selected_cell_errors() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_cell(-5, 4),
|
|
||||||
Err("Invalid row: '-5'".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_cell(5, -4),
|
|
||||||
Err("Invalid column: '-4'".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_range(-1, 1, 1, 1),
|
|
||||||
Err("Invalid row: '-1'".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_range(1, 0, 1, 1),
|
|
||||||
Err("Invalid column: '0'".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_range(1, 1, LAST_ROW + 1, 1),
|
|
||||||
Err("Invalid row: '1048577'".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_range(1, 1, 1, LAST_COLUMN + 1),
|
|
||||||
Err("Invalid column: '16385'".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn set_selected_cell_errors_wrong_sheet() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
// forcefully set a wrong index
|
|
||||||
model.workbook.views.get_mut(&0).unwrap().sheet = 2;
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
// It's returning the wrong number
|
|
||||||
assert_eq!(model.get_selected_sheet(), 2);
|
|
||||||
|
|
||||||
// But we can't set the selected cell anymore
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_cell(3, 4),
|
|
||||||
Err("Invalid worksheet index 2".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_selected_range(3, 4, 5, 6),
|
|
||||||
Err("Invalid worksheet index 2".to_string())
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
model.set_top_left_visible_cell(3, 4),
|
|
||||||
Err("Invalid worksheet index 2".to_string())
|
|
||||||
);
|
|
||||||
|
|
||||||
// we can fix it by setting the right cell
|
|
||||||
model.set_selected_sheet(0).unwrap();
|
|
||||||
model.set_selected_cell(3, 4).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn set_visible_cell() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
model.set_top_left_visible_cell(100, 12).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
model.get_selected_view(),
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [1, 1, 1, 1],
|
|
||||||
top_row: 100,
|
|
||||||
left_column: 12
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let s = serde_json::to_string(&model.get_selected_view()).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
serde_json::from_str::<SelectedView>(&s).unwrap(),
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [1, 1, 1, 1],
|
|
||||||
top_row: 100,
|
|
||||||
left_column: 12
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn set_visible_cell_errors() {
|
|
||||||
let model = new_empty_model();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_top_left_visible_cell(-100, 12),
|
|
||||||
Err("Invalid row: '-100'".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
model.set_top_left_visible_cell(100, -12),
|
|
||||||
Err("Invalid column: '-12'".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn errors_no_views() {
|
|
||||||
let mut model = new_empty_model();
|
|
||||||
// forcefully remove the view
|
|
||||||
model.workbook.views = HashMap::new();
|
|
||||||
// also in the sheet
|
|
||||||
model.workbook.worksheets[0].views = HashMap::new();
|
|
||||||
let mut model = UserModel::from_model(model);
|
|
||||||
// get methods will return defaults
|
|
||||||
assert_eq!(model.get_selected_sheet(), 0);
|
|
||||||
assert_eq!(model.get_selected_cell(), (0, 1, 1));
|
|
||||||
assert_eq!(
|
|
||||||
model.get_selected_view(),
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [1, 1, 1, 1],
|
|
||||||
top_row: 1,
|
|
||||||
left_column: 1
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// set methods won't complain. but won't work either
|
|
||||||
model.set_selected_sheet(0).unwrap();
|
|
||||||
model.set_selected_cell(5, 6).unwrap();
|
|
||||||
assert_eq!(model.get_selected_cell(), (0, 1, 1));
|
|
||||||
}
|
|
||||||
@@ -4,15 +4,37 @@ use std::{collections::HashMap, fmt::Display};
|
|||||||
|
|
||||||
use crate::expressions::token::Error;
|
use crate::expressions::token::Error;
|
||||||
|
|
||||||
|
// Useful for `#[serde(default = "default_as_true")]`
|
||||||
|
fn default_as_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn default_as_false() -> bool {
|
fn default_as_false() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Useful for `#[serde(skip_serializing_if = "is_true")]`
|
||||||
|
fn is_true(b: &bool) -> bool {
|
||||||
|
*b
|
||||||
|
}
|
||||||
|
|
||||||
fn is_false(b: &bool) -> bool {
|
fn is_false(b: &bool) -> bool {
|
||||||
!*b
|
!*b
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
fn is_zero(num: &i32) -> bool {
|
||||||
|
*num == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_default_alignment(o: &Option<Alignment>) -> bool {
|
||||||
|
o.is_none() || *o == Some(Alignment::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hashmap_is_empty(h: &HashMap<String, Table>) -> bool {
|
||||||
|
h.values().len() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
pub application: String,
|
pub application: String,
|
||||||
pub app_version: String,
|
pub app_version: String,
|
||||||
@@ -22,21 +44,14 @@ pub struct Metadata {
|
|||||||
pub last_modified: String, //"2020-11-20T16:24:35"
|
pub last_modified: String, //"2020-11-20T16:24:35"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct WorkbookSettings {
|
pub struct WorkbookSettings {
|
||||||
pub tz: String,
|
pub tz: String,
|
||||||
pub locale: String,
|
pub locale: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Workbook View tracks of the selected sheet for each view
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
|
||||||
pub struct WorkbookView {
|
|
||||||
/// The index of the currently selected sheet.
|
|
||||||
pub sheet: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An internal representation of an IronCalc Workbook
|
/// An internal representation of an IronCalc Workbook
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Workbook {
|
pub struct Workbook {
|
||||||
pub shared_strings: Vec<String>,
|
pub shared_strings: Vec<String>,
|
||||||
pub defined_names: Vec<DefinedName>,
|
pub defined_names: Vec<DefinedName>,
|
||||||
@@ -45,22 +60,28 @@ pub struct Workbook {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub settings: WorkbookSettings,
|
pub settings: WorkbookSettings,
|
||||||
pub metadata: Metadata,
|
pub metadata: Metadata,
|
||||||
|
#[serde(default)]
|
||||||
|
#[serde(skip_serializing_if = "hashmap_is_empty")]
|
||||||
pub tables: HashMap<String, Table>,
|
pub tables: HashMap<String, Table>,
|
||||||
pub views: HashMap<u32, WorkbookView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct DefinedName {
|
pub struct DefinedName {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub formula: String,
|
pub formula: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub sheet_id: Option<u32>,
|
pub sheet_id: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move to worksheet.rs make frozen_rows/columns private and u32
|
||||||
|
/// Internal representation of a worksheet Excel object
|
||||||
|
|
||||||
/// * state:
|
/// * state:
|
||||||
/// 18.18.68 ST_SheetState (Sheet Visibility Types)
|
/// 18.18.68 ST_SheetState (Sheet Visibility Types)
|
||||||
/// hidden, veryHidden, visible
|
/// hidden, veryHidden, visible
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum SheetState {
|
pub enum SheetState {
|
||||||
Visible,
|
Visible,
|
||||||
Hidden,
|
Hidden,
|
||||||
@@ -77,25 +98,8 @@ impl Display for SheetState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the state of the worksheet as seen by the user. This includes
|
|
||||||
/// details such as the currently selected cell, the visible range, and the
|
|
||||||
/// position of the viewport.
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
|
||||||
pub struct WorksheetView {
|
|
||||||
/// The row index of the currently selected cell.
|
|
||||||
pub row: i32,
|
|
||||||
/// The column index of the currently selected cell.
|
|
||||||
pub column: i32,
|
|
||||||
/// The selected range in the worksheet, specified as [start_row, start_column, end_row, end_column].
|
|
||||||
pub range: [i32; 4],
|
|
||||||
/// The row index of the topmost visible cell in the worksheet view.
|
|
||||||
pub top_row: i32,
|
|
||||||
/// The column index of the leftmost visible cell in the worksheet view.
|
|
||||||
pub left_column: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Internal representation of a worksheet Excel object
|
/// Internal representation of a worksheet Excel object
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
|
||||||
pub struct Worksheet {
|
pub struct Worksheet {
|
||||||
pub dimension: String,
|
pub dimension: String,
|
||||||
pub cols: Vec<Col>,
|
pub cols: Vec<Col>,
|
||||||
@@ -105,12 +109,16 @@ pub struct Worksheet {
|
|||||||
pub shared_formulas: Vec<String>,
|
pub shared_formulas: Vec<String>,
|
||||||
pub sheet_id: u32,
|
pub sheet_id: u32,
|
||||||
pub state: SheetState,
|
pub state: SheetState,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub color: Option<String>,
|
pub color: Option<String>,
|
||||||
pub merge_cells: Vec<String>,
|
pub merge_cells: Vec<String>,
|
||||||
pub comments: Vec<Comment>,
|
pub comments: Vec<Comment>,
|
||||||
|
#[serde(default)]
|
||||||
|
#[serde(skip_serializing_if = "is_zero")]
|
||||||
pub frozen_rows: i32,
|
pub frozen_rows: i32,
|
||||||
|
#[serde(default)]
|
||||||
|
#[serde(skip_serializing_if = "is_zero")]
|
||||||
pub frozen_columns: i32,
|
pub frozen_columns: i32,
|
||||||
pub views: HashMap<u32, WorksheetView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal representation of Excel's sheet_data
|
/// Internal representation of Excel's sheet_data
|
||||||
@@ -118,7 +126,7 @@ pub struct Worksheet {
|
|||||||
pub type SheetData = HashMap<i32, HashMap<i32, Cell>>;
|
pub type SheetData = HashMap<i32, HashMap<i32, Cell>>;
|
||||||
|
|
||||||
// ECMA-376-1:2016 section 18.3.1.73
|
// ECMA-376-1:2016 section 18.3.1.73
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
/// Row index
|
/// Row index
|
||||||
pub r: i32,
|
pub r: i32,
|
||||||
@@ -126,19 +134,23 @@ pub struct Row {
|
|||||||
pub custom_format: bool,
|
pub custom_format: bool,
|
||||||
pub custom_height: bool,
|
pub custom_height: bool,
|
||||||
pub s: i32,
|
pub s: i32,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub hidden: bool,
|
pub hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ECMA-376-1:2016 section 18.3.1.13
|
// ECMA-376-1:2016 section 18.3.1.13
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
|
||||||
pub struct Col {
|
pub struct Col {
|
||||||
// Column definitions are defined on ranges, unlike rows which store unique, per-row entries.
|
// Column definitions are defined on ranges, unlike rows which store unique, per-row entries.
|
||||||
/// First column affected by this record. Settings apply to column in \[min, max\] range.
|
/// First column affected by this record. Settings apply to column in \[min, max\] range.
|
||||||
pub min: i32,
|
pub min: i32,
|
||||||
/// Last column affected by this record. Settings apply to column in \[min, max\] range.
|
/// Last column affected by this record. Settings apply to column in \[min, max\] range.
|
||||||
pub max: i32,
|
pub max: i32,
|
||||||
|
|
||||||
pub width: f64,
|
pub width: f64,
|
||||||
pub custom_width: bool,
|
pub custom_width: bool,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub style: Option<i32>,
|
pub style: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,55 +165,32 @@ pub enum CellType {
|
|||||||
CompoundData = 128,
|
CompoundData = 128,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, Clone, PartialEq)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, Clone, PartialEq)]
|
||||||
|
#[serde(tag = "t", deny_unknown_fields)]
|
||||||
pub enum Cell {
|
pub enum Cell {
|
||||||
EmptyCell {
|
#[serde(rename = "empty")]
|
||||||
s: i32,
|
EmptyCell { s: i32 },
|
||||||
},
|
#[serde(rename = "b")]
|
||||||
|
BooleanCell { v: bool, s: i32 },
|
||||||
BooleanCell {
|
#[serde(rename = "n")]
|
||||||
v: bool,
|
NumberCell { v: f64, s: i32 },
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
|
|
||||||
NumberCell {
|
|
||||||
v: f64,
|
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
// Maybe we should not have this type. In Excel this is just a string
|
// Maybe we should not have this type. In Excel this is just a string
|
||||||
ErrorCell {
|
#[serde(rename = "e")]
|
||||||
ei: Error,
|
ErrorCell { ei: Error, s: i32 },
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
// Always a shared string
|
// Always a shared string
|
||||||
SharedString {
|
#[serde(rename = "s")]
|
||||||
si: i32,
|
SharedString { si: i32, s: i32 },
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
// Non evaluated Formula
|
// Non evaluated Formula
|
||||||
CellFormula {
|
#[serde(rename = "u")]
|
||||||
f: i32,
|
CellFormula { f: i32, s: i32 },
|
||||||
s: i32,
|
#[serde(rename = "fb")]
|
||||||
},
|
CellFormulaBoolean { f: i32, v: bool, s: i32 },
|
||||||
|
#[serde(rename = "fn")]
|
||||||
CellFormulaBoolean {
|
CellFormulaNumber { f: i32, v: f64, s: i32 },
|
||||||
f: i32,
|
|
||||||
v: bool,
|
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
|
|
||||||
CellFormulaNumber {
|
|
||||||
f: i32,
|
|
||||||
v: f64,
|
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
// always inline string
|
// always inline string
|
||||||
CellFormulaString {
|
#[serde(rename = "str")]
|
||||||
f: i32,
|
CellFormulaString { f: i32, v: String, s: i32 },
|
||||||
v: String,
|
#[serde(rename = "fe")]
|
||||||
s: i32,
|
|
||||||
},
|
|
||||||
|
|
||||||
CellFormulaError {
|
CellFormulaError {
|
||||||
f: i32,
|
f: i32,
|
||||||
ei: Error,
|
ei: Error,
|
||||||
@@ -220,16 +209,17 @@ impl Default for Cell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Comment {
|
pub struct Comment {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub author_name: String,
|
pub author_name: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub author_id: Option<String>,
|
pub author_id: Option<String>,
|
||||||
pub cell_ref: String,
|
pub cell_ref: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ECMA-376-1:2016 section 18.5.1.2
|
// ECMA-376-1:2016 section 18.5.1.2
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub display_name: String,
|
pub display_name: String,
|
||||||
@@ -237,24 +227,34 @@ pub struct Table {
|
|||||||
pub reference: String,
|
pub reference: String,
|
||||||
pub totals_row_count: u32,
|
pub totals_row_count: u32,
|
||||||
pub header_row_count: u32,
|
pub header_row_count: u32,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub header_row_dxf_id: Option<u32>,
|
pub header_row_dxf_id: Option<u32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub data_dxf_id: Option<u32>,
|
pub data_dxf_id: Option<u32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub totals_row_dxf_id: Option<u32>,
|
pub totals_row_dxf_id: Option<u32>,
|
||||||
pub columns: Vec<TableColumn>,
|
pub columns: Vec<TableColumn>,
|
||||||
pub style_info: TableStyleInfo,
|
pub style_info: TableStyleInfo,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub has_filters: bool,
|
pub has_filters: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// totals_row_label vs totals_row_function might be mutually exclusive. Use an enum?
|
// totals_row_label vs totals_row_function might be mutually exclusive. Use an enum?
|
||||||
// the totals_row_function is an enum not String methinks
|
// the totals_row_function is an enum not String methinks
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct TableColumn {
|
pub struct TableColumn {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub totals_row_label: Option<String>,
|
pub totals_row_label: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub header_row_dxf_id: Option<u32>,
|
pub header_row_dxf_id: Option<u32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub data_dxf_id: Option<u32>,
|
pub data_dxf_id: Option<u32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub totals_row_dxf_id: Option<u32>,
|
pub totals_row_dxf_id: Option<u32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub totals_row_function: Option<String>,
|
pub totals_row_function: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,16 +272,25 @@ impl Default for TableColumn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, Default)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, Default)]
|
||||||
pub struct TableStyleInfo {
|
pub struct TableStyleInfo {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub show_first_column: bool,
|
pub show_first_column: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub show_last_column: bool,
|
pub show_last_column: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub show_row_stripes: bool,
|
pub show_row_stripes: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub show_column_stripes: bool,
|
pub show_column_stripes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Styles {
|
pub struct Styles {
|
||||||
pub num_fmts: Vec<NumFmt>,
|
pub num_fmts: Vec<NumFmt>,
|
||||||
pub fonts: Vec<Font>,
|
pub fonts: Vec<Font>,
|
||||||
@@ -317,7 +326,7 @@ pub struct Style {
|
|||||||
pub quote_prefix: bool,
|
pub quote_prefix: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct NumFmt {
|
pub struct NumFmt {
|
||||||
pub num_fmt_id: i32,
|
pub num_fmt_id: i32,
|
||||||
pub format_code: String,
|
pub format_code: String,
|
||||||
@@ -507,17 +516,29 @@ pub struct Alignment {
|
|||||||
pub wrap_text: bool,
|
pub wrap_text: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct CellStyleXfs {
|
pub struct CellStyleXfs {
|
||||||
pub num_fmt_id: i32,
|
pub num_fmt_id: i32,
|
||||||
pub font_id: i32,
|
pub font_id: i32,
|
||||||
pub fill_id: i32,
|
pub fill_id: i32,
|
||||||
pub border_id: i32,
|
pub border_id: i32,
|
||||||
|
#[serde(default = "default_as_true")]
|
||||||
|
#[serde(skip_serializing_if = "is_true")]
|
||||||
pub apply_number_format: bool,
|
pub apply_number_format: bool,
|
||||||
|
#[serde(default = "default_as_true")]
|
||||||
|
#[serde(skip_serializing_if = "is_true")]
|
||||||
pub apply_border: bool,
|
pub apply_border: bool,
|
||||||
|
#[serde(default = "default_as_true")]
|
||||||
|
#[serde(skip_serializing_if = "is_true")]
|
||||||
pub apply_alignment: bool,
|
pub apply_alignment: bool,
|
||||||
|
#[serde(default = "default_as_true")]
|
||||||
|
#[serde(skip_serializing_if = "is_true")]
|
||||||
pub apply_protection: bool,
|
pub apply_protection: bool,
|
||||||
|
#[serde(default = "default_as_true")]
|
||||||
|
#[serde(skip_serializing_if = "is_true")]
|
||||||
pub apply_font: bool,
|
pub apply_font: bool,
|
||||||
|
#[serde(default = "default_as_true")]
|
||||||
|
#[serde(skip_serializing_if = "is_true")]
|
||||||
pub apply_fill: bool,
|
pub apply_fill: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,24 +559,39 @@ impl Default for CellStyleXfs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, Default)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, Default)]
|
||||||
pub struct CellXfs {
|
pub struct CellXfs {
|
||||||
pub xf_id: i32,
|
pub xf_id: i32,
|
||||||
pub num_fmt_id: i32,
|
pub num_fmt_id: i32,
|
||||||
pub font_id: i32,
|
pub font_id: i32,
|
||||||
pub fill_id: i32,
|
pub fill_id: i32,
|
||||||
pub border_id: i32,
|
pub border_id: i32,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub apply_number_format: bool,
|
pub apply_number_format: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub apply_border: bool,
|
pub apply_border: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub apply_alignment: bool,
|
pub apply_alignment: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub apply_protection: bool,
|
pub apply_protection: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub apply_font: bool,
|
pub apply_font: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub apply_fill: bool,
|
pub apply_fill: bool,
|
||||||
|
#[serde(default = "default_as_false")]
|
||||||
|
#[serde(skip_serializing_if = "is_false")]
|
||||||
pub quote_prefix: bool,
|
pub quote_prefix: bool,
|
||||||
|
#[serde(skip_serializing_if = "is_default_alignment")]
|
||||||
pub alignment: Option<Alignment>,
|
pub alignment: Option<Alignment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct CellStyles {
|
pub struct CellStyles {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub xf_id: i32,
|
pub xf_id: i32,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
use std::{collections::HashMap, fmt::Debug};
|
use std::{collections::HashMap, fmt::Debug};
|
||||||
|
|
||||||
use bitcode::{Decode, Encode};
|
use bitcode::{Decode, Encode};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
constants,
|
constants,
|
||||||
@@ -19,17 +18,6 @@ use crate::{
|
|||||||
utils::is_valid_hex_color,
|
utils::is_valid_hex_color,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
|
||||||
pub struct SelectedView {
|
|
||||||
pub sheet: u32,
|
|
||||||
pub row: i32,
|
|
||||||
pub column: i32,
|
|
||||||
pub range: [i32; 4],
|
|
||||||
pub top_row: i32,
|
|
||||||
pub left_column: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Encode, Decode)]
|
#[derive(Clone, Encode, Decode)]
|
||||||
struct RowData {
|
struct RowData {
|
||||||
row: Option<Row>,
|
row: Option<Row>,
|
||||||
@@ -130,7 +118,6 @@ enum Diff {
|
|||||||
old_value: String,
|
old_value: String,
|
||||||
new_value: String,
|
new_value: String,
|
||||||
},
|
},
|
||||||
// FIXME: we are missing SetViewDiffs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiffList = Vec<Diff>;
|
type DiffList = Vec<Diff>;
|
||||||
@@ -262,7 +249,7 @@ fn vertical(value: &str) -> Result<VerticalAlignment, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// # A wrapper around [`Model`] for a spreadsheet end user.
|
/// # A wrapper around [`Model`] for a spreadsheet end user.
|
||||||
/// UserModel is a wrapper around Model with undo/redo history, _diffs_, automatic evaluation and view management.
|
/// UserModel is a wrapper around Model with undo/redo history, _diffs_ and automatic evaluation.
|
||||||
///
|
///
|
||||||
/// A diff in this context (or more correctly a _user diff_) is a change created by a user.
|
/// A diff in this context (or more correctly a _user diff_) is a change created by a user.
|
||||||
///
|
///
|
||||||
@@ -862,7 +849,7 @@ impl UserModel {
|
|||||||
style.fill.fg_color = color(value)?;
|
style.fill.fg_color = color(value)?;
|
||||||
}
|
}
|
||||||
"num_fmt" => {
|
"num_fmt" => {
|
||||||
value.clone_into(&mut style.num_fmt);
|
style.num_fmt = value.to_owned();
|
||||||
}
|
}
|
||||||
"border.left" => {
|
"border.left" => {
|
||||||
style.border.left = border(value)?;
|
style.border.left = border(value)?;
|
||||||
@@ -948,165 +935,6 @@ impl UserModel {
|
|||||||
self.model.get_worksheets_properties()
|
self.model.get_worksheets_properties()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the selected sheet index
|
|
||||||
pub fn get_selected_sheet(&self) -> u32 {
|
|
||||||
if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
|
||||||
view.sheet
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the selected cell
|
|
||||||
pub fn get_selected_cell(&self) -> (u32, i32, i32) {
|
|
||||||
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
|
||||||
view.sheet
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet(sheet) {
|
|
||||||
if let Some(view) = worksheet.views.get(&self.model.view_id) {
|
|
||||||
return (sheet, view.row, view.column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return a safe default
|
|
||||||
(0, 1, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns selected view
|
|
||||||
pub fn get_selected_view(&self) -> SelectedView {
|
|
||||||
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
|
||||||
view.sheet
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet(sheet) {
|
|
||||||
if let Some(view) = worksheet.views.get(&self.model.view_id) {
|
|
||||||
return SelectedView {
|
|
||||||
sheet,
|
|
||||||
row: view.row,
|
|
||||||
column: view.column,
|
|
||||||
range: view.range,
|
|
||||||
top_row: view.top_row,
|
|
||||||
left_column: view.left_column,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return a safe default
|
|
||||||
SelectedView {
|
|
||||||
sheet: 0,
|
|
||||||
row: 1,
|
|
||||||
column: 1,
|
|
||||||
range: [1, 1, 1, 1],
|
|
||||||
top_row: 1,
|
|
||||||
left_column: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the the selected sheet
|
|
||||||
pub fn set_selected_sheet(&mut self, sheet: u32) -> Result<(), String> {
|
|
||||||
if self.model.workbook.worksheet(sheet).is_err() {
|
|
||||||
return Err(format!("Invalid worksheet index {}", sheet));
|
|
||||||
}
|
|
||||||
if let Some(view) = self.model.workbook.views.get_mut(&0) {
|
|
||||||
view.sheet = sheet;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the selected cell
|
|
||||||
pub fn set_selected_cell(&mut self, row: i32, column: i32) -> Result<(), String> {
|
|
||||||
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
|
||||||
view.sheet
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
if !is_valid_column_number(column) {
|
|
||||||
return Err(format!("Invalid column: '{column}'"));
|
|
||||||
}
|
|
||||||
if !is_valid_column_number(row) {
|
|
||||||
return Err(format!("Invalid row: '{row}'"));
|
|
||||||
}
|
|
||||||
if self.model.workbook.worksheet(sheet).is_err() {
|
|
||||||
return Err(format!("Invalid worksheet index {}", sheet));
|
|
||||||
}
|
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet_mut(sheet) {
|
|
||||||
if let Some(view) = worksheet.views.get_mut(&0) {
|
|
||||||
view.row = row;
|
|
||||||
view.column = column;
|
|
||||||
view.range = [row, column, row, column];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the selected range
|
|
||||||
pub fn set_selected_range(
|
|
||||||
&mut self,
|
|
||||||
start_row: i32,
|
|
||||||
start_column: i32,
|
|
||||||
end_row: i32,
|
|
||||||
end_column: i32,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
|
||||||
view.sheet
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
if !is_valid_column_number(start_column) {
|
|
||||||
return Err(format!("Invalid column: '{start_column}'"));
|
|
||||||
}
|
|
||||||
if !is_valid_column_number(start_row) {
|
|
||||||
return Err(format!("Invalid row: '{start_row}'"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_valid_column_number(end_column) {
|
|
||||||
return Err(format!("Invalid column: '{end_column}'"));
|
|
||||||
}
|
|
||||||
if !is_valid_column_number(end_row) {
|
|
||||||
return Err(format!("Invalid row: '{end_row}'"));
|
|
||||||
}
|
|
||||||
if self.model.workbook.worksheet(sheet).is_err() {
|
|
||||||
return Err(format!("Invalid worksheet index {}", sheet));
|
|
||||||
}
|
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet_mut(sheet) {
|
|
||||||
if let Some(view) = worksheet.views.get_mut(&0) {
|
|
||||||
view.range = [start_row, start_column, end_row, end_column];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the value of the first visible cell
|
|
||||||
pub fn set_top_left_visible_cell(
|
|
||||||
&mut self,
|
|
||||||
top_row: i32,
|
|
||||||
left_column: i32,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let sheet = if let Some(view) = self.model.workbook.views.get(&self.model.view_id) {
|
|
||||||
view.sheet
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
if !is_valid_column_number(left_column) {
|
|
||||||
return Err(format!("Invalid column: '{left_column}'"));
|
|
||||||
}
|
|
||||||
if !is_valid_column_number(top_row) {
|
|
||||||
return Err(format!("Invalid row: '{top_row}'"));
|
|
||||||
}
|
|
||||||
if self.model.workbook.worksheet(sheet).is_err() {
|
|
||||||
return Err(format!("Invalid worksheet index {}", sheet));
|
|
||||||
}
|
|
||||||
if let Ok(worksheet) = self.model.workbook.worksheet_mut(sheet) {
|
|
||||||
if let Some(view) = worksheet.views.get_mut(&0) {
|
|
||||||
view.top_row = top_row;
|
|
||||||
view.left_column = left_column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
// **** Private methods ****** //
|
// **** Private methods ****** //
|
||||||
|
|
||||||
fn push_diff_list(&mut self, diff_list: DiffList) {
|
fn push_diff_list(&mut self, diff_list: DiffList) {
|
||||||
|
|||||||
@@ -286,56 +286,4 @@ impl Model {
|
|||||||
pub fn get_worksheets_properties(&self) -> JsValue {
|
pub fn get_worksheets_properties(&self) -> JsValue {
|
||||||
serde_wasm_bindgen::to_value(&self.model.get_worksheets_properties()).unwrap()
|
serde_wasm_bindgen::to_value(&self.model.get_worksheets_properties()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "getSelectedSheet")]
|
|
||||||
pub fn get_selected_sheet(&self) -> u32 {
|
|
||||||
self.model.get_selected_sheet()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "getSelectedCell")]
|
|
||||||
pub fn get_selected_cell(&self) -> Vec<i32> {
|
|
||||||
let (sheet, row, column) = self.model.get_selected_cell();
|
|
||||||
vec![sheet as i32, row, column]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "getSelectedView")]
|
|
||||||
pub fn get_selected_view(&self) -> JsValue {
|
|
||||||
serde_wasm_bindgen::to_value(&self.model.get_selected_view()).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "setSelectedSheet")]
|
|
||||||
pub fn set_selected_sheet(&mut self, sheet: u32) -> Result<(), JsError> {
|
|
||||||
self.model.set_selected_sheet(sheet).map_err(to_js_error)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "setSelectedCell")]
|
|
||||||
pub fn set_selected_cell(&mut self, row: i32, column: i32) -> Result<(), JsError> {
|
|
||||||
self.model
|
|
||||||
.set_selected_cell(row, column)
|
|
||||||
.map_err(to_js_error)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "setSelectedRange")]
|
|
||||||
pub fn set_selected_range(
|
|
||||||
&mut self,
|
|
||||||
start_row: i32,
|
|
||||||
start_column: i32,
|
|
||||||
end_row: i32,
|
|
||||||
end_column: i32,
|
|
||||||
) -> Result<(), JsError> {
|
|
||||||
self.model
|
|
||||||
.set_selected_range(start_row, start_column, end_row, end_column)
|
|
||||||
.map_err(to_js_error)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = "setTopLeftVisibleCell")]
|
|
||||||
pub fn set_top_left_visible_cell(
|
|
||||||
&mut self,
|
|
||||||
top_row: i32,
|
|
||||||
top_column: i32,
|
|
||||||
) -> Result<(), JsError> {
|
|
||||||
self.model
|
|
||||||
.set_top_left_visible_cell(top_row, top_column)
|
|
||||||
.map_err(to_js_error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import type { StorybookConfig } from "storybook-solidjs-vite";
|
|
||||||
|
|
||||||
const config: StorybookConfig = {
|
|
||||||
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
|
|
||||||
addons: [
|
|
||||||
"@storybook/addon-links",
|
|
||||||
"@storybook/addon-essentials",
|
|
||||||
"@chromatic-com/storybook",
|
|
||||||
"@storybook/addon-interactions",
|
|
||||||
],
|
|
||||||
framework: {
|
|
||||||
name: "storybook-solidjs-vite",
|
|
||||||
options: {},
|
|
||||||
},
|
|
||||||
docs: {
|
|
||||||
autodocs: "tag",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
export default config;
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
const preview: Preview = {
|
|
||||||
parameters: {
|
|
||||||
controls: {
|
|
||||||
matchers: {
|
|
||||||
color: /(background|color)$/i,
|
|
||||||
date: /Date$/i,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default preview;
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
lint:
|
|
||||||
pnpm biome lint *
|
|
||||||
|
|
||||||
format:
|
|
||||||
pnpm biome format *
|
|
||||||
build:
|
|
||||||
pnpm run build
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
# Web IronCalc
|
|
||||||
|
|
||||||
## Widgets
|
|
||||||
|
|
||||||
Toolbar
|
|
||||||
NavigationBar
|
|
||||||
FormulaBar
|
|
||||||
ColorPicker
|
|
||||||
Number Formatter
|
|
||||||
Border Picker
|
|
||||||
|
|
||||||
|
|
||||||
## Stack
|
|
||||||
|
|
||||||
Vite
|
|
||||||
TypeScript
|
|
||||||
SolidJs
|
|
||||||
Lucide Icons
|
|
||||||
BiomeJs
|
|
||||||
Storybook
|
|
||||||
pnpm
|
|
||||||
|
|
||||||
## Recreate
|
|
||||||
|
|
||||||
Install nodejs
|
|
||||||
Activate pnpm
|
|
||||||
corepack enable pnpm
|
|
||||||
Create app
|
|
||||||
pnpm create vite
|
|
||||||
pnpm install
|
|
||||||
add biomejs
|
|
||||||
pnpm add --save-dev --save-exact @biomejs/biome
|
|
||||||
pnpm biome init
|
|
||||||
add solidjs
|
|
||||||
add storybook
|
|
||||||
pnpm dlx storybook@latest init
|
|
||||||
add i18n
|
|
||||||
pnpm add @solid-primitives/i18n
|
|
||||||
(https://github.com/jfgodoy/vite-plugin-solid-svg)
|
|
||||||
add vite-plugin-solid-svg
|
|
||||||
add script: "restore": "cp node_modules/@ironcalc/wasm/wasm_bg.wasm node_modules/.vite/deps/",
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ pnpm install # or npm install or yarn install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Available Scripts
|
|
||||||
|
|
||||||
In the project directory, you can run:
|
|
||||||
|
|
||||||
### `pnpm run dev`
|
|
||||||
|
|
||||||
Runs the app in the development mode.<br>
|
|
||||||
Open [http://localhost:5173](http://localhost:5173) to view it in the browser.
|
|
||||||
|
|
||||||
### `pnpm run build`
|
|
||||||
|
|
||||||
Builds the app for production to the `dist` folder.<br>
|
|
||||||
It correctly bundles Solid in production mode and optimizes the build for the best performance.
|
|
||||||
|
|
||||||
The build is minified and the filenames include the hashes.<br>
|
|
||||||
Your app is ready to be deployed!
|
|
||||||
|
|
||||||
## Deployment
|
|
||||||
|
|
||||||
Learn more about deploying your application with the [documentations](https://vitejs.dev/guide/static-deploy.html)
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
|
|
||||||
"organizeImports": {
|
|
||||||
"enabled": true
|
|
||||||
},
|
|
||||||
"linter": {
|
|
||||||
"enabled": true,
|
|
||||||
"rules": {
|
|
||||||
"recommended": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"formatter": {
|
|
||||||
"indentStyle": "space"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/ironcalc_icon.svg" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Vite + Solid + TS</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script type="module" src="/src/index.tsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "app",
|
|
||||||
"private": true,
|
|
||||||
"version": "0.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"restore": "cp node_modules/@ironcalc/wasm/wasm_bg.wasm node_modules/.vite/deps/",
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "tsc && vite build",
|
|
||||||
"preview": "vite preview",
|
|
||||||
"storybook": "storybook dev -p 6006",
|
|
||||||
"build-storybook": "storybook build"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@ironcalc/wasm": "file:../bindings/wasm/pkg",
|
|
||||||
"@solid-primitives/i18n": "^2.1.1",
|
|
||||||
"lucide-solid": "^0.379.0",
|
|
||||||
"solid-js": "^1.8.15"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@biomejs/biome": "1.7.0",
|
|
||||||
"@chromatic-com/storybook": "^1.3.3",
|
|
||||||
"@storybook/addon-essentials": "^8.0.8",
|
|
||||||
"@storybook/addon-interactions": "^8.0.8",
|
|
||||||
"@storybook/addon-links": "^8.0.8",
|
|
||||||
"@storybook/blocks": "^8.0.8",
|
|
||||||
"storybook": "^8.0.8",
|
|
||||||
"storybook-solidjs": "^1.0.0-beta.2",
|
|
||||||
"storybook-solidjs-vite": "^1.0.0-beta.2",
|
|
||||||
"typescript": "^5.2.2",
|
|
||||||
"vite": "^5.2.0",
|
|
||||||
"vite-plugin-solid": "^2.10.2",
|
|
||||||
"vite-plugin-solid-svg": "^0.8.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6864
solidjs_app/pnpm-lock.yaml
generated
@@ -1,8 +0,0 @@
|
|||||||
<svg width="600" height="600" viewBox="0 0 600 600" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect width="600" height="600" rx="20" fill="#F2994A"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M348.98 100C348.98 166.034 322.748 229.362 276.055 276.055C268.163 283.947 259.796 291.255 251.021 297.95L251.021 500L348.98 500H251.021C251.021 433.966 277.252 370.637 323.945 323.945C331.837 316.053 340.204 308.745 348.98 302.05L348.98 100Z" fill="white"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M251.021 100.068C251.003 140.096 235.094 178.481 206.788 206.787C178.466 235.109 140.053 251.02 100 251.02V348.979C154.873 348.979 207.877 330.866 251.021 297.95V100.068Z" fill="white"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M348.98 499.882C349.011 459.872 364.918 421.507 393.213 393.213C421.534 364.891 459.947 348.98 500 348.98V251.02C445.128 251.02 392.123 269.134 348.98 302.05V499.882Z" fill="white"/>
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M276.055 276.055C322.748 229.362 348.98 166.034 348.98 100H251.021V297.95C259.796 291.255 268.163 283.947 276.055 276.055Z" fill="white"/>
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M348.98 302.05V499.895C348.98 499.93 348.98 499.965 348.98 500L251.021 500C251.021 499.946 251.02 499.891 251.021 499.837C251.064 433.862 277.291 370.599 323.945 323.945C331.837 316.053 340.204 308.745 348.98 302.05Z" fill="white"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB |
@@ -1,7 +0,0 @@
|
|||||||
#root {
|
|
||||||
max-width: 1280px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import { Show, createResource } from "solid-js";
|
|
||||||
// import "./App.css";
|
|
||||||
// import solidLogo from "./assets/solid.svg";
|
|
||||||
|
|
||||||
import init, { Model } from "@ironcalc/wasm";
|
|
||||||
import Workbook from "./components/Workbook";
|
|
||||||
|
|
||||||
const fetchModel = async () => {
|
|
||||||
await init();
|
|
||||||
// const model_bytes = new Uint8Array(
|
|
||||||
// await (await fetch("./example.ic")).arrayBuffer(),
|
|
||||||
// );
|
|
||||||
// const _model = Model.from_bytes(model_bytes);*/
|
|
||||||
const model = new Model("en", "UTC");
|
|
||||||
model.setUserInput(0, 1, 1, "=1+1");
|
|
||||||
return model;
|
|
||||||
};
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
const [model] = createResource(fetchModel);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Show when={model()} fallback={<div>Loading...</div>}>
|
|
||||||
{(model) => <Workbook model={model()} />}
|
|
||||||
</Show>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 441 B |
|
Before Width: | Height: | Size: 729 B |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 33 KiB |
@@ -1,8 +0,0 @@
|
|||||||
<svg width="600" height="600" viewBox="0 0 600 600" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect width="600" height="600" rx="20" fill="#F2994A"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M348.98 100C348.98 166.034 322.748 229.362 276.055 276.055C268.163 283.947 259.796 291.255 251.021 297.95L251.021 500L348.98 500H251.021C251.021 433.966 277.252 370.637 323.945 323.945C331.837 316.053 340.204 308.745 348.98 302.05L348.98 100Z" fill="white"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M251.021 100.068C251.003 140.096 235.094 178.481 206.788 206.787C178.466 235.109 140.053 251.02 100 251.02V348.979C154.873 348.979 207.877 330.866 251.021 297.95V100.068Z" fill="white"/>
|
|
||||||
<path opacity="0.8" fill-rule="evenodd" clip-rule="evenodd" d="M348.98 499.882C349.011 459.872 364.918 421.507 393.213 393.213C421.534 364.891 459.947 348.98 500 348.98V251.02C445.128 251.02 392.123 269.134 348.98 302.05V499.882Z" fill="white"/>
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M276.055 276.055C322.748 229.362 348.98 166.034 348.98 100H251.021V297.95C259.796 291.255 268.163 283.947 276.055 276.055Z" fill="white"/>
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M348.98 302.05V499.895C348.98 499.93 348.98 499.965 348.98 500L251.021 500C251.021 499.946 251.02 499.891 251.021 499.837C251.064 433.862 277.291 370.599 323.945 323.945C331.837 316.053 340.204 308.745 348.98 302.05Z" fill="white"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 33 KiB |
@@ -1,23 +0,0 @@
|
|||||||
import type { Model } from "@ironcalc/wasm";
|
|
||||||
import styles from "./workbook.module.css";
|
|
||||||
import Toolbar from "./toolbar/Toolbar";
|
|
||||||
import Navigation from "./navigation/Navigation";
|
|
||||||
import FormulaBar from "./formulabar/FormulaBar";
|
|
||||||
import Worksheet from "./Worksheet/Worksheet";
|
|
||||||
|
|
||||||
function Workbook(props: { model: Model }) {
|
|
||||||
const onkeydown = (event: KeyboardEvent) => {
|
|
||||||
console.log("key pressed: ", event);
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<div class={styles.workbook} onkeydown={onkeydown} tabIndex={0}>
|
|
||||||
<Toolbar></Toolbar>
|
|
||||||
{/* {props.model.getFormattedCellValue(0, 1, 1)} */}
|
|
||||||
<FormulaBar></FormulaBar>
|
|
||||||
<Worksheet></Worksheet>
|
|
||||||
<Navigation></Navigation>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Workbook;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import styles from "./worksheet.module.css";
|
|
||||||
|
|
||||||
function Worksheet() {
|
|
||||||
const onkeydown = (event: KeyboardEvent) => {
|
|
||||||
console.log("key pressed: ", event);
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<div class={styles.worksheet} onkeydown={onkeydown} tabIndex={0}>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Worksheet;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import styles from "./formulabar.module.css";
|
|
||||||
|
|
||||||
function FormulaBar() {
|
|
||||||
const onkeydown = (event: KeyboardEvent) => {
|
|
||||||
console.log("key pressed: ", event);
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<div class={styles.toolbar} onkeydown={onkeydown} tabIndex={0}>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default FormulaBar;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import styles from "./navigation.module.css";
|
|
||||||
|
|
||||||
function Navigation() {
|
|
||||||
const onkeydown = (event: KeyboardEvent) => {
|
|
||||||
console.log("key pressed: ", event);
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<div class={styles.navigation} onkeydown={onkeydown} tabIndex={0}>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Navigation;
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
import { JSX } from "solid-js/jsx-runtime";
|
|
||||||
import styles from "./toolbar.module.css";
|
|
||||||
import {
|
|
||||||
AlignCenter,
|
|
||||||
AlignLeft,
|
|
||||||
AlignRight,
|
|
||||||
ArrowDownToLine,
|
|
||||||
ArrowUpToLine,
|
|
||||||
Bold,
|
|
||||||
ChevronDown,
|
|
||||||
Euro,
|
|
||||||
Grid2X2,
|
|
||||||
Italic,
|
|
||||||
Paintbrush2,
|
|
||||||
PaintBucket,
|
|
||||||
Percent,
|
|
||||||
Redo2,
|
|
||||||
Strikethrough,
|
|
||||||
Type,
|
|
||||||
Underline,
|
|
||||||
Undo2,
|
|
||||||
} from "lucide-solid";
|
|
||||||
import { DecimalPlacesDecreaseIcon, DecimalPlacesIncreaseIcon, ArrowMiddleFromLine } from "../../icons";
|
|
||||||
|
|
||||||
function Toolbar() {
|
|
||||||
const onkeydown = (event: KeyboardEvent) => {
|
|
||||||
console.log("key pressed: ", event);
|
|
||||||
};
|
|
||||||
|
|
||||||
const t = (s: string): string => s;
|
|
||||||
|
|
||||||
const properties = {
|
|
||||||
onUndo: () => {},
|
|
||||||
canUndo: true,
|
|
||||||
onRedo: () => {},
|
|
||||||
canRedo: true,
|
|
||||||
onCopyStyles: () => {},
|
|
||||||
canEdit: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class={styles.toolbar} onkeydown={onkeydown} tabIndex={0}>
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
onClick={properties.onUndo}
|
|
||||||
disabled={!properties.canUndo}
|
|
||||||
title={t("toolbar.undo")}
|
|
||||||
>
|
|
||||||
<Undo2 />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
onClick={properties.onRedo}
|
|
||||||
disabled={!properties.canRedo}
|
|
||||||
title={t("toolbar.redo")}
|
|
||||||
>
|
|
||||||
<Redo2 />
|
|
||||||
</StyledButton>
|
|
||||||
<div class={styles.divider} />
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
onClick={properties.onCopyStyles}
|
|
||||||
title={t("toolbar.copy_styles")}
|
|
||||||
>
|
|
||||||
<Paintbrush2 />
|
|
||||||
</StyledButton>
|
|
||||||
<div class={styles.divider} />
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
// onClick={(): void => {
|
|
||||||
// properties.onNumberFormatPicked(NumberFormats.CURRENCY_EUR);
|
|
||||||
// }}
|
|
||||||
title={t("toolbar.euro")}
|
|
||||||
>
|
|
||||||
<Euro />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
// onClick={(): void => {
|
|
||||||
// properties.onNumberFormatPicked(NumberFormats.PERCENTAGE);
|
|
||||||
// }}
|
|
||||||
title={t("toolbar.percentage")}
|
|
||||||
>
|
|
||||||
<Percent />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
// onClick={(): void => {
|
|
||||||
// properties.onNumberFormatPicked(
|
|
||||||
// decreaseDecimalPlaces(properties.numFmt)
|
|
||||||
// );
|
|
||||||
// }}
|
|
||||||
title={t("toolbar.decimal_places_decrease")}
|
|
||||||
>
|
|
||||||
<div><DecimalPlacesDecreaseIcon /></div>
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
// onClick={(): void => {
|
|
||||||
// properties.onNumberFormatPicked(
|
|
||||||
// increaseDecimalPlaces(properties.numFmt)
|
|
||||||
// );
|
|
||||||
// }}
|
|
||||||
title={t("toolbar.decimal_places_increase")}
|
|
||||||
>
|
|
||||||
<DecimalPlacesIncreaseIcon />
|
|
||||||
</StyledButton>
|
|
||||||
{/* // <FormatMenu
|
|
||||||
// numFmt={properties.numFmt}
|
|
||||||
// onChange={(numberFmt): void => {
|
|
||||||
// properties.onNumberFormatPicked(numberFmt);
|
|
||||||
// }}
|
|
||||||
// onExited={(): void => {}}
|
|
||||||
// anchorOrigin={{
|
|
||||||
// horizontal: 20, // Aligning the menu to the middle of FormatButton
|
|
||||||
// vertical: "bottom",
|
|
||||||
// }}
|
|
||||||
// >*/
|
|
||||||
<StyledButton
|
|
||||||
|
|
||||||
pressed={false}
|
|
||||||
|
|
||||||
title={t("toolbar.format_number")}
|
|
||||||
>
|
|
||||||
<div class={styles.format_menu}>{"123"}<ChevronDown /></div>
|
|
||||||
|
|
||||||
</StyledButton>
|
|
||||||
/* </FormatMenu> */}
|
|
||||||
<div class={styles.divider} />
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.bold}
|
|
||||||
// onClick={() => properties.onToggleBold(!properties.bold)}
|
|
||||||
title={t("toolbar.bold")}
|
|
||||||
>
|
|
||||||
<Bold />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.italic}
|
|
||||||
// onClick={() => properties.onToggleItalic(!properties.italic)}
|
|
||||||
title={t("toolbar.italic")}
|
|
||||||
>
|
|
||||||
<Italic />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.underline}
|
|
||||||
// onClick={() => properties.onToggleUnderline(!properties.underline)}
|
|
||||||
title={t("toolbar.underline")}
|
|
||||||
>
|
|
||||||
<Underline />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.strike}
|
|
||||||
// onClick={() => properties.onToggleStrike(!properties.strike)}
|
|
||||||
title={t("toolbar.strike_trough")}
|
|
||||||
>
|
|
||||||
<Strikethrough />
|
|
||||||
</StyledButton>
|
|
||||||
<div class={styles.divider} />
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
title={t("toolbar.font_color")}
|
|
||||||
// ref={fontColorButton}
|
|
||||||
// underlinedColor={properties.fontColor}
|
|
||||||
// onClick={() => setFontColorPickerOpen(true)}
|
|
||||||
>
|
|
||||||
<Type />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
title={t("toolbar.fill_color")}
|
|
||||||
// ref={fillColorButton}
|
|
||||||
// underlinedColor={properties.fillColor}
|
|
||||||
// onClick={() => setFillColorPickerOpen(true)}
|
|
||||||
>
|
|
||||||
<PaintBucket />
|
|
||||||
</StyledButton>
|
|
||||||
<div class={styles.divider} />
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.horizontalAlign === "left"}
|
|
||||||
// onClick={() =>
|
|
||||||
// properties.onToggleHorizontalAlign(
|
|
||||||
// properties.horizontalAlign === "left" ? "general" : "left"
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
title={t("toolbar.align_left")}
|
|
||||||
>
|
|
||||||
<AlignLeft />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.horizontalAlign === "center"}
|
|
||||||
// onClick={() =>
|
|
||||||
// properties.onToggleHorizontalAlign(
|
|
||||||
// properties.horizontalAlign === "center" ? "general" : "center"
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
title={t("toolbar.align_center")}
|
|
||||||
>
|
|
||||||
<AlignCenter />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.horizontalAlign === "right"}
|
|
||||||
// onClick={() =>
|
|
||||||
// properties.onToggleHorizontalAlign(
|
|
||||||
// properties.horizontalAlign === "right" ? "general" : "right"
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
title={t("toolbar.align_right")}
|
|
||||||
>
|
|
||||||
<AlignRight />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.verticalAlign === "top"}
|
|
||||||
// onClick={() =>
|
|
||||||
// properties.onToggleVerticalAlign(
|
|
||||||
// properties.verticalAlign === "top" ? "bottom" : "top"
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
title={t("toolbar.vertical_align_top")}
|
|
||||||
>
|
|
||||||
<ArrowUpToLine />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.verticalAlign === "center"}
|
|
||||||
// onClick={() =>
|
|
||||||
// properties.onToggleVerticalAlign(
|
|
||||||
// properties.verticalAlign === "center" ? "bottom" : "center"
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
title={t("toolbar.vertical_align_center")}
|
|
||||||
>
|
|
||||||
<ArrowMiddleFromLine />
|
|
||||||
</StyledButton>
|
|
||||||
<StyledButton
|
|
||||||
// pressed={properties.verticalAlign === "bottom"}
|
|
||||||
// onClick={() => properties.onToggleVerticalAlign("bottom")}
|
|
||||||
title={t("toolbar.vertical_align_bottom")}
|
|
||||||
>
|
|
||||||
<ArrowDownToLine />
|
|
||||||
</StyledButton>
|
|
||||||
<div class={styles.divider} />
|
|
||||||
<StyledButton
|
|
||||||
pressed={false}
|
|
||||||
// onClick={() => setBorderPickerOpen(true)}
|
|
||||||
// ref={borderButton}
|
|
||||||
title={t("toolbar.borders")}
|
|
||||||
>
|
|
||||||
<Grid2X2 />
|
|
||||||
</StyledButton>
|
|
||||||
{/* // <ColorPicker
|
|
||||||
// color={properties.fontColor}
|
|
||||||
// onChange={(color): void => {
|
|
||||||
// properties.onTextColorPicked(color);
|
|
||||||
// setFontColorPickerOpen(false);
|
|
||||||
// }}
|
|
||||||
// anchorEl={fontColorButton}
|
|
||||||
// open={fontColorPickerOpen}
|
|
||||||
// />
|
|
||||||
// <ColorPicker
|
|
||||||
// color={properties.fillColor}
|
|
||||||
// onChange={(color): void => {
|
|
||||||
// properties.onFillColorPicked(color);
|
|
||||||
// setFillColorPickerOpen(false);
|
|
||||||
// }}
|
|
||||||
// anchorEl={fillColorButton}
|
|
||||||
// open={fillColorPickerOpen}
|
|
||||||
// />
|
|
||||||
// <BorderPicker
|
|
||||||
// onChange={(border): void => {
|
|
||||||
// properties.onBorderChanged(border);
|
|
||||||
// setBorderPickerOpen(false);
|
|
||||||
// }}
|
|
||||||
// anchorEl={borderButton}
|
|
||||||
// open={borderPickerOpen}
|
|
||||||
// /> */}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function StyledButton(props: {
|
|
||||||
children: JSX.Element;
|
|
||||||
title: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
disabled?: boolean;
|
|
||||||
pressed?: boolean;
|
|
||||||
underlinedColor?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
disabled={props.disabled || false}
|
|
||||||
onClick={props.onClick}
|
|
||||||
title={props.title}
|
|
||||||
class={styles.button}
|
|
||||||
>
|
|
||||||
{props.children}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Toolbar;
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
.toolbar {
|
|
||||||
display: flex;
|
|
||||||
flex-shrink: 0;
|
|
||||||
align-items: center;
|
|
||||||
/* ${({ theme }) => theme.palette.background.paper}; */
|
|
||||||
background: #fff;
|
|
||||||
height: 40px;
|
|
||||||
line-height: 40px;
|
|
||||||
/* theme.palette.grey["600"] */
|
|
||||||
border-bottom: 1px solid #757575;
|
|
||||||
font-family: Inter;
|
|
||||||
border-radius: 4px 4px 0px 0px;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button {
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-size: 26px;
|
|
||||||
border: 0px solid #fff;
|
|
||||||
border-radius: 2px;
|
|
||||||
margin-right: 5px;
|
|
||||||
transition: all 0.2s;
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: white;
|
|
||||||
padding: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:disabled {
|
|
||||||
color: grey;
|
|
||||||
cursor: default;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:not(disabled) {
|
|
||||||
border-top: none;
|
|
||||||
border-bottom: none;
|
|
||||||
color: #21243a;
|
|
||||||
background-color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:hover {
|
|
||||||
background-color: #f1f2f8;
|
|
||||||
border-top-color: #f1f2f8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button svg {
|
|
||||||
width: 16px;
|
|
||||||
height: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.divider {
|
|
||||||
width: 0px;
|
|
||||||
height: 10px;
|
|
||||||
border-left: 1px solid #d3d6e9;
|
|
||||||
margin-left: 5px;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.format_menu {
|
|
||||||
width: 40px;
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 400;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/* @import './theme.css'; */
|
|
||||||
|
|
||||||
.workbook {
|
|
||||||
/* background-color: var(--main-bg-color); */
|
|
||||||
/* color: var(--other); */
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import DecimalPlacesDecreaseIcon from "./decrease-decimal.svg";
|
|
||||||
import DecimalPlacesIncreaseIcon from "./increase-decimal.svg";
|
|
||||||
|
|
||||||
import BorderBottomIcon from "./border-bottom.svg";
|
|
||||||
import BorderCenterHIcon from "./border-center-h.svg";
|
|
||||||
import BorderCenterVIcon from "./border-center-v.svg";
|
|
||||||
import BorderInnerIcon from "./border-inner.svg";
|
|
||||||
import BorderLeftIcon from "./border-left.svg";
|
|
||||||
import BorderOuterIcon from "./border-outer.svg";
|
|
||||||
import BorderRightIcon from "./border-right.svg";
|
|
||||||
import BorderTopIcon from "./border-top.svg";
|
|
||||||
import BorderNoneIcon from "./border-none.svg";
|
|
||||||
import BorderStyleIcon from "./border-style.svg";
|
|
||||||
|
|
||||||
import DeleteColumnIcon from "./delete-column.svg";
|
|
||||||
import DeleteRowIcon from "./delete-row.svg";
|
|
||||||
import InsertColumnLeftIcon from "./insert-column-left.svg";
|
|
||||||
import InsertColumnRightIcon from "./insert-column-right.svg";
|
|
||||||
import InsertRowAboveIcon from "./insert-row-above.svg";
|
|
||||||
import InsertRowBelow from "./insert-row-below.svg";
|
|
||||||
import ArrowMiddleFromLine from "./arrow-middle-from-line.svg";
|
|
||||||
|
|
||||||
import Fx from "./fx.svg";
|
|
||||||
|
|
||||||
export {
|
|
||||||
ArrowMiddleFromLine,
|
|
||||||
DecimalPlacesDecreaseIcon,
|
|
||||||
DecimalPlacesIncreaseIcon,
|
|
||||||
BorderBottomIcon,
|
|
||||||
BorderCenterHIcon,
|
|
||||||
BorderCenterVIcon,
|
|
||||||
BorderInnerIcon,
|
|
||||||
BorderLeftIcon,
|
|
||||||
BorderOuterIcon,
|
|
||||||
BorderRightIcon,
|
|
||||||
BorderTopIcon,
|
|
||||||
BorderNoneIcon,
|
|
||||||
BorderStyleIcon,
|
|
||||||
DeleteColumnIcon,
|
|
||||||
DeleteRowIcon,
|
|
||||||
InsertColumnLeftIcon,
|
|
||||||
InsertColumnRightIcon,
|
|
||||||
InsertRowAboveIcon,
|
|
||||||
InsertRowBelow,
|
|
||||||
Fx,
|
|
||||||
};
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
:root {
|
|
||||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
||||||
line-height: 1.5;
|
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color-scheme: light dark;
|
|
||||||
color: rgba(255, 255, 255, 0.87);
|
|
||||||
background-color: #242424;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
display: flex;
|
|
||||||
place-items: center;
|
|
||||||
min-width: 320px;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 3.2em;
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
|
||||||
color: #213547;
|
|
||||||
background-color: #ffffff;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #747bff;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/* @refresh reload */
|
|
||||||
import { render } from "solid-js/web";
|
|
||||||
|
|
||||||
import App from "./App";
|
|
||||||
// import "./index.css";
|
|
||||||
import "./theme.css";
|
|
||||||
|
|
||||||
const root = document.getElementById("root");
|
|
||||||
|
|
||||||
if (root) {
|
|
||||||
render(() => <App />, root);
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
:root {
|
|
||||||
--main-bg-color: brown;
|
|
||||||
--other: blue;
|
|
||||||
}
|
|
||||||
1
solidjs_app/src/typings.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
declare module "*.module.css";
|
|
||||||
1
solidjs_app/src/vite-env.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
/// <reference types="vite/client" />
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { defineConfig } from "vite";
|
|
||||||
import solid from "vite-plugin-solid";
|
|
||||||
import solidPlugin from "vite-plugin-solid";
|
|
||||||
import solidSvg from "vite-plugin-solid-svg";
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [solid(), solidPlugin(), solidSvg()],
|
|
||||||
});
|
|
||||||
1
solidjs_app/.gitignore → webapp/.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
node_modules/*
|
node_modules/*
|
||||||
dist/*
|
dist/*
|
||||||
|
example.json
|
||||||
19
webapp/.storybook/main.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import type { StorybookConfig } from '@storybook/react-vite';
|
||||||
|
|
||||||
|
const config: StorybookConfig = {
|
||||||
|
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
|
||||||
|
addons: [
|
||||||
|
'@storybook/addon-links',
|
||||||
|
'@storybook/addon-essentials',
|
||||||
|
'@storybook/addon-onboarding',
|
||||||
|
'@storybook/addon-interactions',
|
||||||
|
],
|
||||||
|
framework: {
|
||||||
|
name: '@storybook/react-vite',
|
||||||
|
options: {},
|
||||||
|
},
|
||||||
|
docs: {
|
||||||
|
autodocs: 'tag',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
29
webapp/.storybook/preview.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import type { Preview } from '@storybook/react';
|
||||||
|
import i18n from '../src/i18n';
|
||||||
|
import { I18nextProvider } from 'react-i18next';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
|
||||||
|
const withI18next = (Story: any) => {
|
||||||
|
return (
|
||||||
|
<I18nextProvider i18n={i18n}>
|
||||||
|
<Story />
|
||||||
|
</I18nextProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const preview: Preview = {
|
||||||
|
parameters: {
|
||||||
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||||
|
controls: {
|
||||||
|
matchers: {
|
||||||
|
color: /(background|color)$/i,
|
||||||
|
date: /Date$/i,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const decorators = [withI18next];
|
||||||
|
export default preview;
|
||||||
21
webapp/README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# IronCalc Web App
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Local development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
# Deploy
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
BIN
webapp/example.xlsx
Normal file
16
webapp/index.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<!-- <meta name="theme-color" content="#1bb566"> -->
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#F2994A" />
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="black" />
|
||||||
|
<title>Spreadsheet</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
15
webapp/jest.config.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { Config } from "jest";
|
||||||
|
// import {defaults} from 'jest-config';
|
||||||
|
|
||||||
|
const config: Config = {
|
||||||
|
// testMatch:["**.jest.mjs"],
|
||||||
|
moduleFileExtensions: ["js", "ts", "mts", "mjs"],
|
||||||
|
transform: {
|
||||||
|
"^.+\\.[jt]s?$": "ts-jest",
|
||||||
|
},
|
||||||
|
moduleNameMapper: {
|
||||||
|
"^@ironcalc/wasm$": "<rootDir>/node_modules/@ironcalc/nodejs/"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
17153
webapp/package-lock.json
generated
Normal file
55
webapp/package.json
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"restore": "cp node_modules/@ironcalc/wasm/wasm_bg.wasm node_modules/.vite/deps/",
|
||||||
|
"dev": "vite",
|
||||||
|
"test": "jest",
|
||||||
|
"build": "tsc && vite build",
|
||||||
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"storybook": "storybook dev -p 6006",
|
||||||
|
"build-storybook": "storybook build"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@emotion/react": "^11.11.4",
|
||||||
|
"@emotion/styled": "^11.11.5",
|
||||||
|
"@ironcalc/wasm": "file:../bindings/wasm/pkg",
|
||||||
|
"@mui/material": "^5.15.15",
|
||||||
|
"i18next": "^23.11.1",
|
||||||
|
"lucide-react": "^0.292.0",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-colorful": "^5.6.1",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"react-i18next": "^13.5.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@storybook/addon-essentials": "^7.6.17",
|
||||||
|
"@storybook/addon-interactions": "^7.6.17",
|
||||||
|
"@storybook/addon-links": "^7.6.17",
|
||||||
|
"@storybook/addon-onboarding": "^1.0.11",
|
||||||
|
"@storybook/blocks": "^7.5.3",
|
||||||
|
"@storybook/react": "^7.5.3",
|
||||||
|
"@storybook/react-vite": "^7.6.17",
|
||||||
|
"@storybook/testing-library": "^0.2.2",
|
||||||
|
"@types/jest": "^29.5.12",
|
||||||
|
"@types/react": "^18.2.75",
|
||||||
|
"@types/react-dom": "^18.2.24",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
|
"@typescript-eslint/parser": "^6.21.0",
|
||||||
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"eslint": "^8.57.0",
|
||||||
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.6",
|
||||||
|
"eslint-plugin-storybook": "^0.6.15",
|
||||||
|
"jest": "^29.7.0",
|
||||||
|
"storybook": "^7.6.17",
|
||||||
|
"ts-jest": "^29.1.2",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.4.5",
|
||||||
|
"vite": "^5.2.8",
|
||||||
|
"vite-plugin-svgr": "^4.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
webapp/src/App.css
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#root {
|
||||||
|
position: absolute;
|
||||||
|
inset: 10px;
|
||||||
|
border: 1px solid #AAA;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
40
webapp/src/App.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import "./App.css";
|
||||||
|
import Workbook from "./components/workbook";
|
||||||
|
import "./i18n";
|
||||||
|
import { createContext, useEffect, useState } from "react";
|
||||||
|
import init, { Model } from "@ironcalc/wasm";
|
||||||
|
import { WorkbookState } from "./components/workbookState";
|
||||||
|
import WorkbookContext from "./components/workbookContext";
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [model, setModel] = useState<Model | null>(null);
|
||||||
|
const [workbookState, setWorkbookState] = useState<WorkbookState | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
async function start() {
|
||||||
|
await init();
|
||||||
|
const model_bytes = new Uint8Array(await (await fetch("./example.ic")).arrayBuffer());
|
||||||
|
const _model = Model.from_bytes(model_bytes);
|
||||||
|
// const _model = new Model("en", "UTC");
|
||||||
|
if (!model) setModel(_model);
|
||||||
|
if (!workbookState) setWorkbookState(new WorkbookState());
|
||||||
|
}
|
||||||
|
start();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!model || !workbookState) {
|
||||||
|
return <div>Loading</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We could use context for model, but the problem is that it should initialized to null.
|
||||||
|
// Passing the property down makes sure it is always defined.
|
||||||
|
return (
|
||||||
|
// <WorkbookContext.Provider value={{}}>
|
||||||
|
<Workbook model={model} workbookState={workbookState} />
|
||||||
|
// </WorkbookContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
||||||
|
|
||||||
12
webapp/src/components/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Keyboard and mouse events architecture
|
||||||
|
|
||||||
|
This document describes the architecture of the keyboard navigation and mouse events in IronCalc Web
|
||||||
|
|
||||||
|
There are two modes for mouse events:
|
||||||
|
|
||||||
|
* Normal mode: clicking a cell selects it, clicking on a sheet opens it
|
||||||
|
* Browse mode: clicking on a cell updates the formula, etc
|
||||||
|
|
||||||
|
While in browse mode some mouse events might end the browse mode
|
||||||
|
|
||||||
|
We follow Excel's way of navigating a spreadsheet
|
||||||
25
webapp/src/components/WorksheetCanvas/constants.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export const headerCornerBackground = '#FFF';
|
||||||
|
export const headerTextColor = '#333';
|
||||||
|
export const headerBackground = '#FFF';
|
||||||
|
export const headerGlobalSelectorColor = '#EAECF4';
|
||||||
|
export const headerSelectedBackground = '#EEEEEE';
|
||||||
|
export const headerFullSelectedBackground = '#D3D6E9';
|
||||||
|
export const headerSelectedColor = '#333';
|
||||||
|
export const headerBorderColor = '#DEE0EF';
|
||||||
|
|
||||||
|
export const gridColor = '#D3D6E9';
|
||||||
|
export const gridSeparatorColor = '#D3D6E9';
|
||||||
|
export const defaultTextColor = '#2E414D';
|
||||||
|
|
||||||
|
export const outlineColor = '#F2994A';
|
||||||
|
export const outlineBackgroundColor = '#F2994A1A';
|
||||||
|
|
||||||
|
export const LAST_COLUMN = 16_384;
|
||||||
|
export const LAST_ROW = 1_048_576;
|
||||||
|
|
||||||
|
// FIXME: Browsers cannot have a height that big
|
||||||
|
// For now we will go A-IZ and 10_000 rows
|
||||||
|
export const lastColumn = 260; // TODO: Excel supports up to 16_384
|
||||||
|
// I know of a world with one million moons.
|
||||||
|
// Carl Sagan in The cosmic connection Chapter 7 "Space Exploration as a Human Enterprise"
|
||||||
|
export const lastRow = 10_000; // TODO: Excel supports up to 1_048_576
|
||||||
23
webapp/src/components/WorksheetCanvas/types.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export interface Cell {
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Area {
|
||||||
|
rowStart: number;
|
||||||
|
rowEnd: number;
|
||||||
|
columnStart: number;
|
||||||
|
columnEnd: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SheetArea extends Area {
|
||||||
|
sheet: number;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AreaWithBorderInterface extends Area {
|
||||||
|
border: "left" | "top" | "right" | "bottom";
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AreaWithBorder = AreaWithBorderInterface | null;
|
||||||
|
|
||||||
396
webapp/src/components/WorksheetCanvas/util.ts
Normal file
@@ -0,0 +1,396 @@
|
|||||||
|
const letters = [
|
||||||
|
'A',
|
||||||
|
'B',
|
||||||
|
'C',
|
||||||
|
'D',
|
||||||
|
'E',
|
||||||
|
'F',
|
||||||
|
'G',
|
||||||
|
'H',
|
||||||
|
'I',
|
||||||
|
'J',
|
||||||
|
'K',
|
||||||
|
'L',
|
||||||
|
'M',
|
||||||
|
'N',
|
||||||
|
'O',
|
||||||
|
'P',
|
||||||
|
'Q',
|
||||||
|
'R',
|
||||||
|
'S',
|
||||||
|
'T',
|
||||||
|
'U',
|
||||||
|
'V',
|
||||||
|
'W',
|
||||||
|
'X',
|
||||||
|
'Y',
|
||||||
|
'Z',
|
||||||
|
];
|
||||||
|
interface Reference {
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
absoluteRow: boolean;
|
||||||
|
absoluteColumn: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function referenceToString(rf: Reference): string {
|
||||||
|
const absC = rf.absoluteColumn ? '$' : '';
|
||||||
|
const absR = rf.absoluteRow ? '$' : '';
|
||||||
|
return absC + columnNameFromNumber(rf.column) + absR + rf.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function columnNameFromNumber(column: number): string {
|
||||||
|
let columnName = '';
|
||||||
|
let index = column;
|
||||||
|
while (index > 0) {
|
||||||
|
columnName = `${letters[(index - 1) % 26]}${columnName}`;
|
||||||
|
index = Math.floor((index - 1) / 26);
|
||||||
|
}
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function columnNumberFromName(columnName: string): number {
|
||||||
|
let column = 0;
|
||||||
|
for (const character of columnName) {
|
||||||
|
const index = (character.codePointAt(0) ?? 0) - 64;
|
||||||
|
column = column * 26 + index;
|
||||||
|
}
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
// EqualTo Color Palette
|
||||||
|
export function getColor(index: number, alpha = 1): string {
|
||||||
|
const colors = [
|
||||||
|
{
|
||||||
|
name: 'Cyan',
|
||||||
|
rgba: [89, 185, 188, 1],
|
||||||
|
hex: '#59B9BC',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Flamingo',
|
||||||
|
rgba: [236, 87, 83, 1],
|
||||||
|
hex: '#EC5753',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#3358B7',
|
||||||
|
rgba: [51, 88, 183, 1],
|
||||||
|
name: 'Blue',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#F8CD3C',
|
||||||
|
rgba: [248, 205, 60, 1],
|
||||||
|
name: 'Yellow',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#3BB68A',
|
||||||
|
rgba: [59, 182, 138, 1],
|
||||||
|
name: 'Emerald',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#523E93',
|
||||||
|
rgba: [82, 62, 147, 1],
|
||||||
|
name: 'Violet',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#A23C52',
|
||||||
|
rgba: [162, 60, 82, 1],
|
||||||
|
name: 'Burgundy',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#8CB354',
|
||||||
|
rgba: [162, 60, 82, 1],
|
||||||
|
name: 'Wasabi',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#D03627',
|
||||||
|
rgba: [208, 54, 39, 1],
|
||||||
|
name: 'Red',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: '#1B717E',
|
||||||
|
rgba: [27, 113, 126, 1],
|
||||||
|
name: 'Teal',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
if (alpha === 1) {
|
||||||
|
return colors[index % 10].hex;
|
||||||
|
}
|
||||||
|
const { rgba } = colors[index % 10];
|
||||||
|
return `rgba(${rgba[0]}, ${rgba[1]}, ${rgba[2]}, ${alpha})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mergedAreas(area1: Area, area2: Area): Area {
|
||||||
|
return {
|
||||||
|
rowStart: Math.min(area1.rowStart, area2.rowStart, area1.rowEnd, area2.rowEnd),
|
||||||
|
rowEnd: Math.max(area1.rowStart, area2.rowStart, area1.rowEnd, area2.rowEnd),
|
||||||
|
columnStart: Math.min(area1.columnStart, area2.columnStart, area1.columnEnd, area2.columnEnd),
|
||||||
|
columnEnd: Math.max(area1.columnStart, area2.columnStart, area1.columnEnd, area2.columnEnd),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getExpandToArea(area: Area, cell: Cell): AreaWithBorder {
|
||||||
|
let { rowStart, rowEnd, columnStart, columnEnd } = area;
|
||||||
|
if (rowStart > rowEnd) {
|
||||||
|
[rowStart, rowEnd] = [rowEnd, rowStart];
|
||||||
|
}
|
||||||
|
if (columnStart > columnEnd) {
|
||||||
|
[columnStart, columnEnd] = [columnEnd, columnStart];
|
||||||
|
}
|
||||||
|
const { row, column } = cell;
|
||||||
|
if (row <= rowEnd && row >= rowStart && column >= columnStart && column <= columnEnd) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Two rules:
|
||||||
|
// * The extendTo area must be larger than the selected area
|
||||||
|
// * The extendTo area must be of the same width or the same height as the selected area
|
||||||
|
if (row >= rowEnd && column >= columnStart) {
|
||||||
|
// Normal case: we are expanding down and right
|
||||||
|
if (row - rowEnd > column - columnEnd) {
|
||||||
|
// Expanding by rows (down)
|
||||||
|
return {
|
||||||
|
rowStart: rowEnd + 1,
|
||||||
|
rowEnd: row,
|
||||||
|
columnStart,
|
||||||
|
columnEnd,
|
||||||
|
border: 'top',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// expanding by columns (right)
|
||||||
|
return {
|
||||||
|
rowStart,
|
||||||
|
rowEnd,
|
||||||
|
columnStart: columnEnd + 1,
|
||||||
|
columnEnd: column,
|
||||||
|
border: 'left',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (row >= rowEnd && column <= columnStart) {
|
||||||
|
// We are expanding down and left
|
||||||
|
if (row - rowEnd > columnStart - column) {
|
||||||
|
// Expanding by rows (down)
|
||||||
|
return {
|
||||||
|
rowStart: rowEnd + 1,
|
||||||
|
rowEnd: row,
|
||||||
|
columnStart,
|
||||||
|
columnEnd,
|
||||||
|
border: 'top',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Expanding by columns (left)
|
||||||
|
return {
|
||||||
|
rowStart,
|
||||||
|
rowEnd,
|
||||||
|
columnStart: column,
|
||||||
|
columnEnd: columnStart - 1,
|
||||||
|
border: 'right',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (row <= rowEnd && column >= columnEnd) {
|
||||||
|
// We are expanding up and right
|
||||||
|
if (rowStart - row > column - columnEnd) {
|
||||||
|
// Expanding by rows (up)
|
||||||
|
return {
|
||||||
|
rowStart: row,
|
||||||
|
rowEnd: rowStart - 1,
|
||||||
|
columnStart,
|
||||||
|
columnEnd,
|
||||||
|
border: 'bottom',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Expanding by columns (right)
|
||||||
|
return {
|
||||||
|
rowStart,
|
||||||
|
rowEnd,
|
||||||
|
columnStart: columnEnd + 1,
|
||||||
|
columnEnd: column,
|
||||||
|
border: 'left',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (row <= rowEnd && column <= columnStart) {
|
||||||
|
// We are expanding up and left
|
||||||
|
if (rowStart - row > columnStart - column) {
|
||||||
|
// Expanding by rows (up)
|
||||||
|
return {
|
||||||
|
rowStart: row,
|
||||||
|
rowEnd: rowStart - 1,
|
||||||
|
columnStart,
|
||||||
|
columnEnd,
|
||||||
|
border: 'bottom',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Expanding by columns (left)
|
||||||
|
return {
|
||||||
|
rowStart,
|
||||||
|
rowEnd,
|
||||||
|
columnStart: column,
|
||||||
|
columnEnd: columnStart - 1,
|
||||||
|
border: 'right',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the keypress should start editing
|
||||||
|
*/
|
||||||
|
export function isEditingKey(key: string): boolean {
|
||||||
|
if (key.length !== 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const code = key.codePointAt(0) ?? 0;
|
||||||
|
if (code > 0 && code < 255) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// / Common types
|
||||||
|
|
||||||
|
export interface Area {
|
||||||
|
rowStart: number;
|
||||||
|
rowEnd: number;
|
||||||
|
columnStart: number;
|
||||||
|
columnEnd: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AreaWithBorderInterface extends Area {
|
||||||
|
border: 'left' | 'top' | 'right' | 'bottom';
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AreaWithBorder = AreaWithBorderInterface | null;
|
||||||
|
|
||||||
|
export interface Cell {
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ScrollPosition {
|
||||||
|
left: number;
|
||||||
|
top: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StateSettings {
|
||||||
|
selectedCell: Cell;
|
||||||
|
selectedArea: Area;
|
||||||
|
scrollPosition: ScrollPosition;
|
||||||
|
extendToArea: AreaWithBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Dispatch<A> = (value: A) => void;
|
||||||
|
export type SetStateAction<S> = S | ((prevState: S) => S);
|
||||||
|
|
||||||
|
export enum FocusType {
|
||||||
|
Cell = 'cell',
|
||||||
|
FormulaBar = 'formula-bar',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In Excel there are two "modes" of editing
|
||||||
|
* * `init`: When you start typing in a cell. In this mode arrow keys will move away from the cell
|
||||||
|
* * `edit`: If you double click on a cell or click in the cell while editing.
|
||||||
|
* In this mode arrow keys will move within the cell.
|
||||||
|
*
|
||||||
|
* In a formula bar mode is always `edit`.
|
||||||
|
*/
|
||||||
|
export type CellEditMode = 'init' | 'edit';
|
||||||
|
export interface CellEditingType {
|
||||||
|
/**
|
||||||
|
* ID of cell editing. Useful when one edit transforms into another and some code needs to run
|
||||||
|
* when target changes.
|
||||||
|
*
|
||||||
|
* Due to problems with focus management (see #339) it's possible to start a new cell editing
|
||||||
|
* without properly cleaning up previous one (lose focus in workbook, regain focus NOT in
|
||||||
|
* the input and then use the keyboard.
|
||||||
|
*/
|
||||||
|
id: number;
|
||||||
|
sheet: number;
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
text: string;
|
||||||
|
base: string;
|
||||||
|
mode: CellEditMode;
|
||||||
|
focus: FocusType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NavigationKey = 'ArrowRight' | 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'Home' | 'End';
|
||||||
|
|
||||||
|
export const isNavigationKey = (key: string): key is NavigationKey =>
|
||||||
|
['ArrowRight', 'ArrowLeft', 'ArrowDown', 'ArrowUp', 'Home', 'End'].includes(key);
|
||||||
|
|
||||||
|
function nameNeedsQuoting(name: string): boolean {
|
||||||
|
const chars = [' ', '(', ')', "'", '$', ',', ';', '-', '+', '{', '}'];
|
||||||
|
const l = chars.length;
|
||||||
|
for (let index = 0; index < l; index += 1) {
|
||||||
|
if (name.includes(chars[index])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: We should use the function of a similar name in the rust code.
|
||||||
|
export const quoteSheetName = (name: string): string => {
|
||||||
|
if (nameNeedsQuoting(name)) {
|
||||||
|
return `'${name.replace("'", "''")}'`;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function cellReprToRowColumn(cellRepr: string): { row: number; column: number } {
|
||||||
|
let row = 0;
|
||||||
|
let column = 0;
|
||||||
|
for (const character of cellRepr) {
|
||||||
|
if (Number.isNaN(Number.parseInt(character, 10))) {
|
||||||
|
column *= 26;
|
||||||
|
const characterCode = character.codePointAt(0);
|
||||||
|
const ACharacterCode = 'A'.codePointAt(0);
|
||||||
|
if (typeof characterCode === 'undefined' || typeof ACharacterCode === 'undefined') {
|
||||||
|
throw new TypeError('Failed to find character code');
|
||||||
|
}
|
||||||
|
const deltaCodes = characterCode - ACharacterCode;
|
||||||
|
if (deltaCodes < 0) {
|
||||||
|
throw new Error('Incorrect character');
|
||||||
|
}
|
||||||
|
column += deltaCodes + 1;
|
||||||
|
} else {
|
||||||
|
row *= 10;
|
||||||
|
row += Number.parseInt(character, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { row, column };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMessageCellText = (
|
||||||
|
cell: string,
|
||||||
|
getMessageSheetNumber: (sheet: string) => number | undefined,
|
||||||
|
getCellText?: (sheet: number, row: number, column: number) => string | undefined,
|
||||||
|
) => {
|
||||||
|
const messageMatch = /^=?(?<sheet>\w+)!(?<cell>\w+)/.exec(cell);
|
||||||
|
if (messageMatch && messageMatch.groups) {
|
||||||
|
const messageSheet = getMessageSheetNumber(messageMatch.groups.sheet);
|
||||||
|
const dynamicIconCell = cellReprToRowColumn(messageMatch.groups.cell);
|
||||||
|
if (messageSheet !== undefined && getCellText) {
|
||||||
|
return getCellText(messageSheet, dynamicIconCell.row, dynamicIconCell.column) || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCellAddress = (selectedArea: Area, selectedCell?: Cell) => {
|
||||||
|
const isSingleCell =
|
||||||
|
selectedArea.rowStart === selectedArea.rowEnd &&
|
||||||
|
selectedArea.columnEnd === selectedArea.columnStart;
|
||||||
|
|
||||||
|
return isSingleCell && selectedCell
|
||||||
|
? `${columnNameFromNumber(selectedCell.column)}${selectedCell.row}`
|
||||||
|
: `${columnNameFromNumber(selectedArea.columnStart)}${
|
||||||
|
selectedArea.rowStart
|
||||||
|
}:${columnNameFromNumber(selectedArea.columnEnd)}${selectedArea.rowEnd}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum Border {
|
||||||
|
Top = 'top',
|
||||||
|
Bottom = 'bottom',
|
||||||
|
Right = 'right',
|
||||||
|
Left = 'left',
|
||||||
|
}
|
||||||
1328
webapp/src/components/WorksheetCanvas/worksheetCanvas.ts
Normal file
566
webapp/src/components/borderPicker.tsx
Normal file
@@ -0,0 +1,566 @@
|
|||||||
|
import React, { useRef, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import {
|
||||||
|
BorderBottomIcon,
|
||||||
|
BorderCenterHIcon,
|
||||||
|
BorderCenterVIcon,
|
||||||
|
BorderInnerIcon,
|
||||||
|
BorderLeftIcon,
|
||||||
|
BorderOuterIcon,
|
||||||
|
BorderRightIcon,
|
||||||
|
BorderTopIcon,
|
||||||
|
BorderNoneIcon,
|
||||||
|
BorderStyleIcon,
|
||||||
|
} from "../icons";
|
||||||
|
import ColorPicker from "./colorPicker";
|
||||||
|
import Popover, { PopoverOrigin } from "@mui/material/Popover";
|
||||||
|
import {
|
||||||
|
Check,
|
||||||
|
ChevronDown,
|
||||||
|
Grid2X2 as BorderAllIcon,
|
||||||
|
PencilLine,
|
||||||
|
ChevronRight,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { styled } from "@mui/material/styles";
|
||||||
|
import { theme } from "../theme";
|
||||||
|
import { BorderOptions, BorderStyle, BorderType } from "@ironcalc/wasm";
|
||||||
|
|
||||||
|
type BorderPickerProps = {
|
||||||
|
className?: string;
|
||||||
|
onChange: (border: BorderOptions) => void;
|
||||||
|
anchorEl: React.RefObject<HTMLElement>;
|
||||||
|
anchorOrigin?: PopoverOrigin;
|
||||||
|
transformOrigin?: PopoverOrigin;
|
||||||
|
open: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const BorderPicker = (properties: BorderPickerProps) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [borderSelected, setBorderSelected] = useState(BorderType.None);
|
||||||
|
const [borderColor, setBorderColor] = useState("#000000");
|
||||||
|
const [borderStyle, setBorderStyle] = useState(BorderStyle.Thin);
|
||||||
|
const [colorPickerOpen, setColorPickerOpen] = useState(false);
|
||||||
|
const [stylePickerOpen, setStylePickerOpen] = useState(false);
|
||||||
|
const closePicker = (): void => {
|
||||||
|
properties.onChange({
|
||||||
|
color: borderColor,
|
||||||
|
style: borderStyle,
|
||||||
|
border: borderSelected,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const borderColorButton = useRef(null);
|
||||||
|
const borderStyleButton = useRef(null);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<StyledPopover
|
||||||
|
open={properties.open}
|
||||||
|
onClose={(): void => closePicker()}
|
||||||
|
anchorEl={properties.anchorEl.current}
|
||||||
|
anchorOrigin={
|
||||||
|
properties.anchorOrigin || { vertical: "bottom", horizontal: "left" }
|
||||||
|
}
|
||||||
|
transformOrigin={
|
||||||
|
properties.transformOrigin || { vertical: "top", horizontal: "left" }
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<BorderPickerDialog>
|
||||||
|
<Borders>
|
||||||
|
<Line>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderAll}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderAll) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderAll);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderAllIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderInner}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderInner) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderInner);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderInnerIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderCenterH}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderCenterH) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderCenterH);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderCenterHIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderCenterV}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderCenterV) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderCenterV);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderCenterVIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderOuter}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderOuter) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderOuter);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderOuterIcon />
|
||||||
|
</Button>
|
||||||
|
</Line>
|
||||||
|
<Line>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderNone}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderNone) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderNone);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderNoneIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderTop}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderTop) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderTop);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderTopIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderRight}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderRight) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderRight);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderRightIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderBottom}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderBottom) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderBottom);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderBottomIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={borderSelected === BorderType.BorderLeft}
|
||||||
|
onClick={() => {
|
||||||
|
if (borderSelected === BorderType.BorderLeft) {
|
||||||
|
setBorderSelected(BorderType.None);
|
||||||
|
} else {
|
||||||
|
setBorderSelected(BorderType.BorderLeft);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderLeftIcon />
|
||||||
|
</Button>
|
||||||
|
</Line>
|
||||||
|
</Borders>
|
||||||
|
<Divider />
|
||||||
|
<Styles>
|
||||||
|
<ButtonWrapper onClick={() => setColorPickerOpen(true)}>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
disabled={false}
|
||||||
|
ref={borderColorButton}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<PencilLine />
|
||||||
|
</Button>
|
||||||
|
<div style={{flexGrow:2}}>Border color</div>
|
||||||
|
<ChevronRightStyled />
|
||||||
|
</ButtonWrapper>
|
||||||
|
<ButtonWrapper onClick={() => setStylePickerOpen(true)} ref={borderStyleButton}>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
disabled={false}
|
||||||
|
title={t("workbook.toolbar.borders_button_title")}
|
||||||
|
>
|
||||||
|
<BorderStyleIcon />
|
||||||
|
</Button>
|
||||||
|
<div style={{flexGrow:2}}>Border style</div>
|
||||||
|
<ChevronRightStyled />
|
||||||
|
</ButtonWrapper>
|
||||||
|
</Styles>
|
||||||
|
</BorderPickerDialog>
|
||||||
|
<ColorPicker
|
||||||
|
color={borderColor}
|
||||||
|
onChange={(color): void => {
|
||||||
|
setBorderColor(color);
|
||||||
|
setColorPickerOpen(false);
|
||||||
|
}}
|
||||||
|
anchorEl={borderColorButton}
|
||||||
|
open={colorPickerOpen}
|
||||||
|
/>
|
||||||
|
<StyledPopover
|
||||||
|
open={stylePickerOpen}
|
||||||
|
onClose={(): void => {
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
anchorEl={borderStyleButton.current}
|
||||||
|
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
||||||
|
transformOrigin={{ vertical: 38, horizontal: -6 }}
|
||||||
|
>
|
||||||
|
<BorderStyleDialog>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Dashed);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.None}
|
||||||
|
>
|
||||||
|
<BorderDescription>None</BorderDescription>
|
||||||
|
<NoneLine />
|
||||||
|
</LineWrapper>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Thin);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.Thin}
|
||||||
|
>
|
||||||
|
<BorderDescription>Thin</BorderDescription>
|
||||||
|
<SolidLine />
|
||||||
|
</LineWrapper>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Medium);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.Medium}
|
||||||
|
>
|
||||||
|
<BorderDescription>Medium</BorderDescription>
|
||||||
|
<MediumLine />
|
||||||
|
</LineWrapper>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Thick);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.Thick}
|
||||||
|
>
|
||||||
|
<BorderDescription>Thick</BorderDescription>
|
||||||
|
<ThickLine />
|
||||||
|
</LineWrapper>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Dotted);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.Dotted}
|
||||||
|
>
|
||||||
|
<BorderDescription>Dotted</BorderDescription>
|
||||||
|
<DottedLine />
|
||||||
|
</LineWrapper>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Dashed);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.Dashed}
|
||||||
|
>
|
||||||
|
<BorderDescription>Dashed</BorderDescription>
|
||||||
|
<DashedLine />
|
||||||
|
</LineWrapper>
|
||||||
|
<LineWrapper
|
||||||
|
onClick={() => {
|
||||||
|
setBorderStyle(BorderStyle.Dashed);
|
||||||
|
setStylePickerOpen(false);
|
||||||
|
}}
|
||||||
|
$checked={borderStyle === BorderStyle.Double}
|
||||||
|
>
|
||||||
|
<BorderDescription>Double</BorderDescription>
|
||||||
|
<DoubleLine />
|
||||||
|
</LineWrapper>
|
||||||
|
</BorderStyleDialog>
|
||||||
|
</StyledPopover>
|
||||||
|
</StyledPopover>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
type LineWrapperProperties = { $checked: boolean };
|
||||||
|
const LineWrapper = styled("div")<LineWrapperProperties>`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
background-color: ${({ $checked }): string => {
|
||||||
|
if ($checked) {
|
||||||
|
return '#EEEEEE;';
|
||||||
|
} else {
|
||||||
|
return 'inherit;';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
&:hover {
|
||||||
|
border: 1px solid #EEEEEE;
|
||||||
|
}
|
||||||
|
padding:8px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid white;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const CheckIconWrapper = styled("div")`
|
||||||
|
width: 12px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
type CheckIconProperties = { $checked: boolean };
|
||||||
|
const CheckIcon = styled("div")<CheckIconProperties>`
|
||||||
|
width: 2px;
|
||||||
|
background-color: #EEE;
|
||||||
|
height: 28px;
|
||||||
|
visibility: ${({ $checked }): string => {
|
||||||
|
if ($checked) {
|
||||||
|
return "visible";
|
||||||
|
}
|
||||||
|
return "hidden";
|
||||||
|
}};
|
||||||
|
`;
|
||||||
|
const NoneLine = styled("div")`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 1px solid #E0E0E0;
|
||||||
|
`;
|
||||||
|
const SolidLine = styled("div")`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 1px solid #333333;
|
||||||
|
`;
|
||||||
|
const MediumLine = styled("div")`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 2px solid #333333;
|
||||||
|
`;
|
||||||
|
const ThickLine = styled("div")`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 3px solid #333333;
|
||||||
|
`;
|
||||||
|
const DashedLine = styled("div")`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 1px dashed #333333;
|
||||||
|
`;
|
||||||
|
const DottedLine = styled("div")`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 1px dotted #333333;
|
||||||
|
`;
|
||||||
|
const DoubleLine = styled('div')`
|
||||||
|
width: 68px;
|
||||||
|
border-top: 3px double #333333;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Divider = styled("div")`
|
||||||
|
display: inline-flex;
|
||||||
|
heigh: 1px;
|
||||||
|
border-bottom: 1px solid #EEE;
|
||||||
|
margin-left: 0px;
|
||||||
|
margin-right: 0px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Borders = styled("div")`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Styles = styled("div")`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Line = styled("div")`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ButtonWrapper = styled("div")`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
&:hover {
|
||||||
|
background-color: #EEE;
|
||||||
|
border-top-color: ${(): string => theme.palette.grey["400"]};
|
||||||
|
}
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 8px
|
||||||
|
`;
|
||||||
|
|
||||||
|
const BorderStyleDialog = styled("div")`
|
||||||
|
background: ${({ theme }): string => theme.palette.background.default};
|
||||||
|
padding: 4px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledPopover = styled(Popover)`
|
||||||
|
.MuiPopover-paper {
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 0px solid ${({ theme }): string => theme.palette.background.default};
|
||||||
|
box-shadow: 1px 2px 8px rgba(139, 143, 173, 0.5);
|
||||||
|
}
|
||||||
|
.MuiPopover-padding {
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
.MuiList-padding {
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
font-family: ${({ theme }) => theme.typography.fontFamily};
|
||||||
|
font-size: 13px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const BorderPickerDialog = styled("div")`
|
||||||
|
background: ${({ theme }): string => theme.palette.background.default};
|
||||||
|
padding: 4px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const BorderDescription = styled("div")`
|
||||||
|
width: 70px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
// type TypeButtonProperties = { $pressed: boolean; $underlinedColor?: string };
|
||||||
|
// const Button = styled.button<TypeButtonProperties>`
|
||||||
|
// width: 23px;
|
||||||
|
// height: 23px;
|
||||||
|
// display: inline-flex;
|
||||||
|
// align-items: center;
|
||||||
|
// justify-content: center;
|
||||||
|
// font-size: 14px;
|
||||||
|
// border-radius: 2px;
|
||||||
|
// margin-right: 5px;
|
||||||
|
// transition: all 0.2s;
|
||||||
|
|
||||||
|
// ${({ theme, disabled, $pressed, $underlinedColor }): string => {
|
||||||
|
// if (disabled) {
|
||||||
|
// return `
|
||||||
|
// color: ${theme.palette.grey['600']};
|
||||||
|
// cursor: default;
|
||||||
|
// `;
|
||||||
|
// }
|
||||||
|
// return `
|
||||||
|
// border-top: ${$underlinedColor ? '3px solid #FFF' : 'none'};
|
||||||
|
// border-bottom: ${$underlinedColor ? `3px solid ${$underlinedColor}` : 'none'};
|
||||||
|
// color: ${theme.palette.text.primary};
|
||||||
|
// background-color: ${$pressed ? theme.palette.grey['600'] : '#FFF'};
|
||||||
|
// &:hover {
|
||||||
|
// background-color: ${theme.palette.grey['400']};
|
||||||
|
// border-top-color: ${theme.palette.grey['400']};
|
||||||
|
// }
|
||||||
|
// `;
|
||||||
|
// }}
|
||||||
|
// `;
|
||||||
|
|
||||||
|
type TypeButtonProperties = { $pressed: boolean; $underlinedColor?: string };
|
||||||
|
const Button = styled("button")<TypeButtonProperties>(
|
||||||
|
({ disabled, $pressed, $underlinedColor }) => {
|
||||||
|
let result: Record<string, any> = {
|
||||||
|
width: "24px",
|
||||||
|
height: "24px",
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
// fontSize: "26px",
|
||||||
|
border: "0px solid #fff",
|
||||||
|
borderRadius: "2px",
|
||||||
|
marginRight: "5px",
|
||||||
|
transition: "all 0.2s",
|
||||||
|
cursor: "pointer",
|
||||||
|
padding: "0px",
|
||||||
|
};
|
||||||
|
if (disabled) {
|
||||||
|
result.color = theme.palette.grey["600"];
|
||||||
|
result.cursor = "default";
|
||||||
|
} else {
|
||||||
|
result.borderTop = $underlinedColor ? "3px solid #FFF" : "none";
|
||||||
|
result.borderBottom = $underlinedColor
|
||||||
|
? `3px solid ${$underlinedColor}`
|
||||||
|
: "none";
|
||||||
|
(result.color = "#21243A"),
|
||||||
|
(result.backgroundColor = $pressed
|
||||||
|
? theme.palette.grey["600"]
|
||||||
|
: "inherit");
|
||||||
|
result["&:hover"] = {
|
||||||
|
backgroundColor: "#F1F2F8",
|
||||||
|
borderTopColor: "#F1F2F8",
|
||||||
|
};
|
||||||
|
result["svg"] = {
|
||||||
|
width: "16px",
|
||||||
|
height: "16px",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const ChevronRightStyled = styled(ChevronRight)`
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default BorderPicker;
|
||||||
261
webapp/src/components/colorPicker.tsx
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
import styled from "@emotion/styled";
|
||||||
|
import Popover, { PopoverOrigin } from "@mui/material/Popover";
|
||||||
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
import { HexColorInput, HexColorPicker } from "react-colorful";
|
||||||
|
import { theme } from "../theme";
|
||||||
|
|
||||||
|
type ColorPickerProps = {
|
||||||
|
className?: string;
|
||||||
|
color: string;
|
||||||
|
onChange: (color: string) => void;
|
||||||
|
anchorEl: React.RefObject<HTMLElement>;
|
||||||
|
anchorOrigin?: PopoverOrigin;
|
||||||
|
transformOrigin?: PopoverOrigin;
|
||||||
|
open: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const colorPickerWidth = 240;
|
||||||
|
const colorPickerPadding = 15;
|
||||||
|
const colorfulHeight = 185; // 150 + 15 + 20
|
||||||
|
|
||||||
|
const ColorPicker = (properties: ColorPickerProps) => {
|
||||||
|
const [color, setColor] = useState<string>(properties.color);
|
||||||
|
const recentColors = useRef<string[]>([]);
|
||||||
|
|
||||||
|
const closePicker = (newColor: string): void => {
|
||||||
|
const maxRecentColors = 14;
|
||||||
|
properties.onChange(newColor);
|
||||||
|
const colors = recentColors.current.filter((c) => c !== newColor);
|
||||||
|
recentColors.current = [newColor, ...colors].slice(0, maxRecentColors);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setColor(properties.color);
|
||||||
|
}, [properties.color]);
|
||||||
|
|
||||||
|
const presetColors = [
|
||||||
|
"#FFFFFF",
|
||||||
|
"#1B717E",
|
||||||
|
"#59B9BC",
|
||||||
|
"#3BB68A",
|
||||||
|
"#8CB354",
|
||||||
|
"#F8CD3C",
|
||||||
|
"#EC5753",
|
||||||
|
"#A23C52",
|
||||||
|
"#D03627",
|
||||||
|
"#523E93",
|
||||||
|
"#3358B7",
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover
|
||||||
|
open={properties.open}
|
||||||
|
onClose={(): void => closePicker(color)}
|
||||||
|
anchorEl={properties.anchorEl.current}
|
||||||
|
anchorOrigin={
|
||||||
|
properties.anchorOrigin || { vertical: "bottom", horizontal: "left" }
|
||||||
|
}
|
||||||
|
transformOrigin={
|
||||||
|
properties.transformOrigin || { vertical: "top", horizontal: "left" }
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<ColorPickerDialog>
|
||||||
|
<HexColorPicker
|
||||||
|
color={color}
|
||||||
|
onChange={(newColor): void => {
|
||||||
|
setColor(newColor);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ColorPickerInput>
|
||||||
|
<HexWrapper>
|
||||||
|
<HexLabel>{"Hex"}</HexLabel>
|
||||||
|
<HexColorInputBox>
|
||||||
|
<HashLabel>{"#"}</HashLabel>
|
||||||
|
<HexColorInput
|
||||||
|
color={color}
|
||||||
|
onChange={(newColor): void => {
|
||||||
|
setColor(newColor);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</HexColorInputBox>
|
||||||
|
</HexWrapper>
|
||||||
|
<Swatch $color={color} />
|
||||||
|
</ColorPickerInput>
|
||||||
|
<HorizontalDivider />
|
||||||
|
<ColorList>
|
||||||
|
{presetColors.map((presetColor) => (
|
||||||
|
<Button
|
||||||
|
key={presetColor}
|
||||||
|
$color={presetColor}
|
||||||
|
onClick={(): void => {
|
||||||
|
closePicker(presetColor);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</ColorList>
|
||||||
|
<HorizontalDivider />
|
||||||
|
<RecentLabel>{"Recent"}</RecentLabel>
|
||||||
|
<ColorList>
|
||||||
|
{recentColors.current.map((recentColor) => (
|
||||||
|
<Button
|
||||||
|
key={recentColor}
|
||||||
|
$color={recentColor}
|
||||||
|
onClick={(): void => {
|
||||||
|
closePicker(recentColor);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</ColorList>
|
||||||
|
</ColorPickerDialog>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const RecentLabel = styled.div`
|
||||||
|
font-size: 12px;
|
||||||
|
color: ${theme.palette.text.secondary};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ColorList = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
flex-direction: row;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Button = styled.button<{ $color: string }>`
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
${({ $color }): string => {
|
||||||
|
if ($color.toUpperCase() === "#FFFFFF") {
|
||||||
|
return `border: 1px solid ${theme.palette.grey['600']};`;
|
||||||
|
}
|
||||||
|
return `border: 1px solid ${$color};`;
|
||||||
|
}}
|
||||||
|
background-color: ${({ $color }): string => {
|
||||||
|
return $color;
|
||||||
|
}};
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-right: 10px;
|
||||||
|
border-radius: 2px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HorizontalDivider = styled.div`
|
||||||
|
height: 0px;
|
||||||
|
width: 100%;
|
||||||
|
border-top: 1px solid ${theme.palette.grey['400']};
|
||||||
|
margin-top: 15px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
// const StyledPopover = styled(Popover)`
|
||||||
|
// .MuiPopover-paper {
|
||||||
|
// border-radius: 10px;
|
||||||
|
// border: 0px solid ${theme.palette.background.default};
|
||||||
|
// box-shadow: 1px 2px 8px rgba(139, 143, 173, 0.5);
|
||||||
|
// }
|
||||||
|
// .MuiPopover-padding {
|
||||||
|
// padding: 0px;
|
||||||
|
// }
|
||||||
|
// .MuiList-padding {
|
||||||
|
// padding: 0px;
|
||||||
|
// }
|
||||||
|
// `;
|
||||||
|
|
||||||
|
const ColorPickerDialog = styled.div`
|
||||||
|
background: ${theme.palette.background.default};
|
||||||
|
width: ${colorPickerWidth}px;
|
||||||
|
padding: 15px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
& .react-colorful {
|
||||||
|
height: ${colorfulHeight}px;
|
||||||
|
width: ${colorPickerWidth - colorPickerPadding * 2}px;
|
||||||
|
}
|
||||||
|
& .react-colorful__saturation {
|
||||||
|
border-bottom: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
& .react-colorful__hue {
|
||||||
|
height: 20px;
|
||||||
|
margin-top: 15px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
& .react-colorful__saturation-pointer {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
& .react-colorful__hue-pointer {
|
||||||
|
width: 7px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HashLabel = styled.div`
|
||||||
|
margin: auto 0px auto 10px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #7d8ec2;
|
||||||
|
font-family: ${theme.typography.button.fontFamily};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HexLabel = styled.div`
|
||||||
|
margin: auto 10px auto 0px;
|
||||||
|
font-size: 12px;
|
||||||
|
display: inline-flex;
|
||||||
|
font-family: ${theme.typography.button.fontFamily};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HexColorInputBox = styled.div`
|
||||||
|
display: inline-flex;
|
||||||
|
flex-grow: 1;
|
||||||
|
margin-right: 10px;
|
||||||
|
width: 140px;
|
||||||
|
height: 28px;
|
||||||
|
border: 1px solid ${theme.palette.grey['600']};
|
||||||
|
border-radius: 5px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HexWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-grow: 1;
|
||||||
|
& input {
|
||||||
|
min-width: 0px;
|
||||||
|
border: 0px;
|
||||||
|
background: ${theme.palette.background.default};
|
||||||
|
outline: none;
|
||||||
|
font-family: ${theme.typography.button.fontFamily};
|
||||||
|
font-size: 12px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: right;
|
||||||
|
padding-right: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
& input:focus {
|
||||||
|
border-color: #4298ef;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Swatch = styled.div<{ $color: string }>`
|
||||||
|
display: inline-flex;
|
||||||
|
${({ $color }): string => {
|
||||||
|
if ($color.toUpperCase() === "#FFFFFF") {
|
||||||
|
return `border: 1px solid ${theme.palette.grey['600']};`;
|
||||||
|
}
|
||||||
|
return `border: 1px solid ${$color};`;
|
||||||
|
}}
|
||||||
|
background-color: ${({ $color }): string => $color};
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 5px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ColorPickerInput = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 15px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default ColorPicker;
|
||||||
420
webapp/src/components/editor/editor.tsx
Normal file
@@ -0,0 +1,420 @@
|
|||||||
|
import {
|
||||||
|
CSSProperties,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
KeyboardEvent,
|
||||||
|
useContext,
|
||||||
|
} from "react";
|
||||||
|
import { useRef } from "react";
|
||||||
|
import EditorContext, { Area } from "./editorContext";
|
||||||
|
import { getStringRange } from "./util";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the Cell Editor for IronCalc
|
||||||
|
* I uses a transparent textarea and a styled mask. What you see is the HTML styled content of the mask
|
||||||
|
* and the caret from the textarea. The alternative would be to have a 'contenteditable' div.
|
||||||
|
* That turns out to be a much more difficult implementation.
|
||||||
|
*
|
||||||
|
* The editor grows horizontally with text if it fits in the screen.
|
||||||
|
* If it doesn't fit, it wraps and grows vertically. If it doesn't fit vertically it scrolls.
|
||||||
|
*
|
||||||
|
* Many keyboard and mouse events are handled gracefully by the textarea in full or in part.
|
||||||
|
* For example letter key strokes like 'q' or '1' are handled full by the textarea.
|
||||||
|
* Some keyboard events like "RightArrow" might need to be handled separately and let them bubble up,
|
||||||
|
* or might be handled by the textarea, depending on the "editor mode".
|
||||||
|
* Some other like "Enter" we need to intercept and change the normal behaviour.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const commonCSS: CSSProperties = {
|
||||||
|
fontWeight: "inherit",
|
||||||
|
fontFamily: "inherit",
|
||||||
|
fontSize: "inherit",
|
||||||
|
position: "absolute",
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
whiteSpace: "pre",
|
||||||
|
width: "100%",
|
||||||
|
padding: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
interface Cell {
|
||||||
|
sheet: number;
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EditorOptions {
|
||||||
|
minimalWidth: number;
|
||||||
|
minimalHeight: number;
|
||||||
|
textColor: string;
|
||||||
|
originalText: string;
|
||||||
|
getStyledText: (
|
||||||
|
text: string,
|
||||||
|
insertRangeText: string
|
||||||
|
) => {
|
||||||
|
html: JSX.Element[];
|
||||||
|
isInReferenceMode: boolean;
|
||||||
|
};
|
||||||
|
onEditEnd: (text: string) => void;
|
||||||
|
display: boolean;
|
||||||
|
cell: Cell;
|
||||||
|
sheetNames: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can either be editing a formula or content.
|
||||||
|
// When editing content (behaviour is common to Excel and Google Sheets):
|
||||||
|
// * If you start editing by typing you are in *accept* mode
|
||||||
|
// * If you start editing by F2 you are in *cruise* mode
|
||||||
|
// * If you start editing by double click you are in *cruise* mode
|
||||||
|
// In Google Sheets "Enter" starts editing and puts you in *cruise* mode. We do not do that
|
||||||
|
// Once you are in cruise mode it is not possible to switch to accept mode
|
||||||
|
// The only way to go from accept mode to cruise mode is clicking in the content somewhere
|
||||||
|
|
||||||
|
// When editing a formula.
|
||||||
|
// In Google Sheets you are either in insert mode or cruise mode.
|
||||||
|
// You can get back to accept mode if you delete the whole formula
|
||||||
|
// In Excel you can be either in insert or accept but if you click in the formula body
|
||||||
|
// you switch to cruise mode. Once in cruise mode you can go to insert mode by selecting a range.
|
||||||
|
// Then you are back in accept/insert modes
|
||||||
|
|
||||||
|
const Editor = (options: EditorOptions) => {
|
||||||
|
const {
|
||||||
|
minimalWidth,
|
||||||
|
minimalHeight,
|
||||||
|
textColor,
|
||||||
|
onEditEnd,
|
||||||
|
originalText,
|
||||||
|
display,
|
||||||
|
cell,
|
||||||
|
sheetNames,
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
const [width, setWidth] = useState(minimalWidth);
|
||||||
|
const [height, setHeight] = useState(minimalHeight);
|
||||||
|
|
||||||
|
const { editorContext, setEditorContext } = useContext(EditorContext);
|
||||||
|
|
||||||
|
const setBaseText = (newText: string) => {
|
||||||
|
console.log('Calling setBaseText');
|
||||||
|
setEditorContext((c) => {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
baseText: newText,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertRangeText = editorContext.insertRange
|
||||||
|
? getStringRange(editorContext.insertRange, sheetNames)
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const baseText = editorContext.baseText;
|
||||||
|
const text = baseText + insertRangeText;
|
||||||
|
console.log('baseText', baseText, 'insertRange:', insertRangeText);
|
||||||
|
|
||||||
|
const formulaRef = useRef<HTMLDivElement>(null);
|
||||||
|
const maskRef = useRef<HTMLDivElement>(null);
|
||||||
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// setBaseText(originalText);
|
||||||
|
// }, [cell]);
|
||||||
|
|
||||||
|
const { html: styledFormula, isInReferenceMode } = options.getStyledText(
|
||||||
|
baseText,
|
||||||
|
insertRangeText
|
||||||
|
);
|
||||||
|
|
||||||
|
if (display && textareaRef.current) {
|
||||||
|
textareaRef.current.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (formulaRef.current) {
|
||||||
|
const scrollWidth = formulaRef.current.scrollWidth;
|
||||||
|
if (scrollWidth > width) {
|
||||||
|
setWidth(scrollWidth);
|
||||||
|
} else if (scrollWidth <= minimalWidth) {
|
||||||
|
setWidth(minimalWidth);
|
||||||
|
}
|
||||||
|
const scrollHeight = formulaRef.current.scrollHeight;
|
||||||
|
if (scrollHeight > height) {
|
||||||
|
setHeight(scrollHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [text]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isInReferenceMode) {
|
||||||
|
setEditorContext((c) => {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
mode: "insert",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setEditorContext((c) => {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
mode: "cruise",
|
||||||
|
insertRange: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isInReferenceMode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (display && textareaRef.current) {
|
||||||
|
textareaRef.current.focus();
|
||||||
|
}
|
||||||
|
}, [display]);
|
||||||
|
|
||||||
|
console.log("Ok, this is running", text, editorContext.id);
|
||||||
|
|
||||||
|
const onKeyDown = useCallback(
|
||||||
|
(event: KeyboardEvent) => {
|
||||||
|
const { key, shiftKey, altKey } = event;
|
||||||
|
const textarea = textareaRef.current;
|
||||||
|
const mode = editorContext.mode;
|
||||||
|
if (!textarea) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (key) {
|
||||||
|
case "Enter": {
|
||||||
|
if (altKey) {
|
||||||
|
// new line
|
||||||
|
const start = textarea.selectionStart;
|
||||||
|
const end = textarea.selectionEnd;
|
||||||
|
const newText = text.slice(0, start) + "\n" + text.slice(end);
|
||||||
|
setBaseText(newText);
|
||||||
|
setTimeout(() => {
|
||||||
|
textarea.setSelectionRange(start + 1, start + 1);
|
||||||
|
}, 1);
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// end edit
|
||||||
|
onEditEnd(text);
|
||||||
|
textarea.blur();
|
||||||
|
// event bubbles up
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "Escape": {
|
||||||
|
setBaseText(originalText);
|
||||||
|
textarea.blur();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ArrowLeft": {
|
||||||
|
if (mode === "accept") {
|
||||||
|
onEditEnd(text);
|
||||||
|
textarea.blur();
|
||||||
|
// event bubbles up
|
||||||
|
return;
|
||||||
|
} else if (mode == "insert") {
|
||||||
|
if (shiftKey) {
|
||||||
|
// increase the inserted range to the left
|
||||||
|
if (!editorContext.insertRange) {
|
||||||
|
setEditorContext((c) => {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
insertRange: {
|
||||||
|
absoluteColumnEnd: false,
|
||||||
|
absoluteColumnStart: false,
|
||||||
|
absoluteRowEnd: false,
|
||||||
|
absoluteRowStart: false,
|
||||||
|
sheet: cell.sheet,
|
||||||
|
rowStart: cell.row,
|
||||||
|
rowEnd: cell.row,
|
||||||
|
columnStart: cell.column,
|
||||||
|
columnEnd: cell.column,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// const r = insertRage;
|
||||||
|
// r.columnStart = Math.max(r.columnStart - 1, 1);
|
||||||
|
// setInsertRange(r);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// move inserted cell to the left
|
||||||
|
if (!editorContext.insertRange) {
|
||||||
|
setEditorContext((c) => {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
insertRange: {
|
||||||
|
absoluteColumnEnd: false,
|
||||||
|
absoluteColumnStart: false,
|
||||||
|
absoluteRowEnd: false,
|
||||||
|
absoluteRowStart: false,
|
||||||
|
sheet: cell.sheet,
|
||||||
|
rowStart: cell.row,
|
||||||
|
rowEnd: cell.row,
|
||||||
|
columnStart: cell.column,
|
||||||
|
columnEnd: cell.column,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setEditorContext((c) => {
|
||||||
|
const range = c.insertRange as Area;
|
||||||
|
const row = range.rowStart;
|
||||||
|
let column = range.columnStart - 1;
|
||||||
|
if (column < 1) {
|
||||||
|
column = 1;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
insertRange: {
|
||||||
|
absoluteColumnEnd: false,
|
||||||
|
absoluteColumnStart: false,
|
||||||
|
absoluteRowEnd: false,
|
||||||
|
absoluteRowStart: false,
|
||||||
|
sheet: range.sheet,
|
||||||
|
rowStart: row,
|
||||||
|
rowEnd: row,
|
||||||
|
columnStart: column,
|
||||||
|
columnEnd: column,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// We don't do anything in "cruise mode" and rely on the textarea default behaviour
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ArrowDown": {
|
||||||
|
if (mode === "accept") {
|
||||||
|
onEditEnd(text);
|
||||||
|
textarea.blur();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ArrowRight": {
|
||||||
|
if (mode === "accept") {
|
||||||
|
onEditEnd(text);
|
||||||
|
textarea.blur();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ArrowUp": {
|
||||||
|
if (mode === "accept") {
|
||||||
|
onEditEnd(text);
|
||||||
|
textarea.blur();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "Tab": {
|
||||||
|
onEditEnd(text);
|
||||||
|
textarea.blur();
|
||||||
|
// event bubbles up
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (editorContext.mode === "insert") {
|
||||||
|
setBaseText(text);
|
||||||
|
setEditorContext((context) => {
|
||||||
|
return {
|
||||||
|
...context,
|
||||||
|
mode: "cruise",
|
||||||
|
insertRange: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[text, editorContext]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "relative",
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
overflow: "hidden",
|
||||||
|
background: "#FFF",
|
||||||
|
display: display ? "block" : "none",
|
||||||
|
}}
|
||||||
|
onClick={(_event) => {
|
||||||
|
console.log("Click on wrapper");
|
||||||
|
}}
|
||||||
|
onPointerDown={() => {
|
||||||
|
console.log("On pointer down wrapper");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
ref={maskRef}
|
||||||
|
style={{
|
||||||
|
...commonCSS,
|
||||||
|
textAlign: "left",
|
||||||
|
pointerEvents: "none",
|
||||||
|
height,
|
||||||
|
}}
|
||||||
|
onClick={(_event) => {
|
||||||
|
console.log("Click on mask");
|
||||||
|
}}
|
||||||
|
onPointerDown={() => {
|
||||||
|
console.log("On pointer down mask");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div ref={formulaRef}>{styledFormula}</div>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
ref={textareaRef}
|
||||||
|
rows={1}
|
||||||
|
style={{
|
||||||
|
...commonCSS,
|
||||||
|
color: "transparent",
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
caretColor: textColor,
|
||||||
|
outline: "none",
|
||||||
|
resize: "none",
|
||||||
|
border: "none",
|
||||||
|
height,
|
||||||
|
}}
|
||||||
|
spellCheck="false"
|
||||||
|
value={text}
|
||||||
|
onChange={(event) => {
|
||||||
|
console.log("onChange", event.target.value);
|
||||||
|
setBaseText(event.target.value);
|
||||||
|
}}
|
||||||
|
onScroll={() => {
|
||||||
|
if (maskRef.current && textareaRef.current) {
|
||||||
|
maskRef.current.style.left = `-${textareaRef.current.scrollLeft}px`;
|
||||||
|
maskRef.current.style.top = `-${textareaRef.current.scrollTop}px`;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
onClick={(event) => {
|
||||||
|
console.log("Setting mode");
|
||||||
|
setEditorContext((c) => {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
mode: "cruise",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
console.log("here");
|
||||||
|
// if (display) {
|
||||||
|
event.stopPropagation();
|
||||||
|
// }
|
||||||
|
}}
|
||||||
|
onBlur={() => {
|
||||||
|
// on blur
|
||||||
|
}}
|
||||||
|
onPointerDown={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Editor;
|
||||||
45
webapp/src/components/editor/editorContext.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Dispatch, SetStateAction, createContext } from "react";
|
||||||
|
|
||||||
|
export interface Area {
|
||||||
|
sheet: number | null;
|
||||||
|
rowStart: number;
|
||||||
|
rowEnd: number;
|
||||||
|
columnStart: number;
|
||||||
|
columnEnd: number;
|
||||||
|
absoluteRowStart: boolean;
|
||||||
|
absoluteRowEnd: boolean;
|
||||||
|
absoluteColumnStart: boolean;
|
||||||
|
absoluteColumnEnd: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arrow keys behave in different ways depending on the "edit mode":
|
||||||
|
// * In _cruise_ mode arrowy keys navigate within the editor
|
||||||
|
// * In _accept_ mode pressing an arrow key will end editing
|
||||||
|
// * In _insert_ mode arrow keys will change the selected range
|
||||||
|
export type EditorMode = "cruise" | "accept" | "insert";
|
||||||
|
|
||||||
|
export interface EditorState {
|
||||||
|
mode: EditorMode;
|
||||||
|
insertRange: null | Area;
|
||||||
|
baseText: string;
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EditorContextType {
|
||||||
|
editorContext: EditorState;
|
||||||
|
setEditorContext: Dispatch<
|
||||||
|
SetStateAction<{ mode: EditorMode; insertRange: null | Area }>
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EditorContext = createContext<EditorContextType>({
|
||||||
|
editorContext: {
|
||||||
|
mode: "accept",
|
||||||
|
insertRange: null,
|
||||||
|
baseText: '',
|
||||||
|
id: Math.floor(Math.random()*1000),
|
||||||
|
},
|
||||||
|
setEditorContext: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default EditorContext;
|
||||||
3
webapp/src/components/editor/index.tsx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export { default } from './editor';
|
||||||
|
|
||||||
|
|
||||||
92
webapp/src/components/editor/tokenTypes.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
type ErrorType =
|
||||||
|
| 'REF'
|
||||||
|
| 'NAME'
|
||||||
|
| 'VALUE'
|
||||||
|
| 'DIV'
|
||||||
|
| 'NA'
|
||||||
|
| 'NUM'
|
||||||
|
| 'ERROR'
|
||||||
|
| 'NIMPL'
|
||||||
|
| 'SPILL'
|
||||||
|
| 'CALC'
|
||||||
|
| 'CIRC';
|
||||||
|
|
||||||
|
type OpCompareType =
|
||||||
|
| 'LessThan'
|
||||||
|
| 'GreaterThan'
|
||||||
|
| 'Equal'
|
||||||
|
| 'LessOrEqualThan'
|
||||||
|
| 'GreaterOrEqualThan'
|
||||||
|
| 'NonEqual';
|
||||||
|
|
||||||
|
type OpSumType = 'Add' | 'Minus';
|
||||||
|
|
||||||
|
type OpProductType = 'Times' | 'Divide';
|
||||||
|
|
||||||
|
interface ReferenceType {
|
||||||
|
sheet: string | null;
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
absolute_column: boolean;
|
||||||
|
absolute_row: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ParsedReferenceType {
|
||||||
|
column: number;
|
||||||
|
row: number;
|
||||||
|
absolute_column: boolean;
|
||||||
|
absolute_row: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Reference {
|
||||||
|
Reference: ReferenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Range {
|
||||||
|
Range: {
|
||||||
|
sheet: string | null;
|
||||||
|
left: ParsedReferenceType;
|
||||||
|
right: ParsedReferenceType;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TokenType =
|
||||||
|
| 'Illegal'
|
||||||
|
| 'Eof'
|
||||||
|
| { Ident: string }
|
||||||
|
| { String: string }
|
||||||
|
| { Boolean: boolean }
|
||||||
|
| { Number: number }
|
||||||
|
| { ERROR: ErrorType }
|
||||||
|
| { COMPARE: OpCompareType }
|
||||||
|
| { SUM: OpSumType }
|
||||||
|
| { PRODUCT: OpProductType }
|
||||||
|
| 'POWER'
|
||||||
|
| 'LPAREN'
|
||||||
|
| 'RPAREN'
|
||||||
|
| 'COLON'
|
||||||
|
| 'SEMICOLON'
|
||||||
|
| 'LBRACKET'
|
||||||
|
| 'RBRACKET'
|
||||||
|
| 'LBRACE'
|
||||||
|
| 'RBRACE'
|
||||||
|
| 'COMMA'
|
||||||
|
| 'BANG'
|
||||||
|
| 'PERCENT'
|
||||||
|
| 'AND'
|
||||||
|
| Reference
|
||||||
|
| Range;
|
||||||
|
|
||||||
|
export interface MarkedToken {
|
||||||
|
token: TokenType;
|
||||||
|
start: number;
|
||||||
|
end: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tokenIsReferenceType(token: TokenType): token is Reference {
|
||||||
|
return typeof token === 'object' && 'Reference' in token;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tokenIsRangeType(token: TokenType): token is Range {
|
||||||
|
return typeof token === 'object' && 'Range' in token;
|
||||||
|
}
|
||||||
108
webapp/src/components/editor/useEditorKeyDown.ts
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import { useCallback, KeyboardEvent } from "react";
|
||||||
|
import { WorkbookState } from "../workbookState";
|
||||||
|
import { Model } from "@ironcalc/wasm";
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
// onMoveCaretToStart: () => void;
|
||||||
|
// onMoveCaretToEnd: () => void;
|
||||||
|
// onEditEnd: (delta: { deltaRow: number; deltaColumn: number }) => void;
|
||||||
|
// onEditEscape: () => void;
|
||||||
|
// onReferenceCycle: () => void;
|
||||||
|
// text: string;
|
||||||
|
// setText: (text: string) => void;
|
||||||
|
model: Model;
|
||||||
|
state: WorkbookState;
|
||||||
|
refresh: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const useEditorKeydown = (
|
||||||
|
options: Options
|
||||||
|
): {
|
||||||
|
onKeyDown: (event: KeyboardEvent) => void;
|
||||||
|
} => {
|
||||||
|
const { state, model } = options;
|
||||||
|
const onKeyDown = useCallback((event: KeyboardEvent) => {
|
||||||
|
const { key, shiftKey } = event;
|
||||||
|
const { mode, text } = state.getEditor() ?? { mode: "init", text: "" };
|
||||||
|
switch (key) {
|
||||||
|
case "Enter":
|
||||||
|
// options.onEditEnd({ deltaRow: 1, deltaColumn: 0 });
|
||||||
|
const { row, column } = state.getSelectedCell();
|
||||||
|
const sheet = state.getSelectedSheet();
|
||||||
|
model.setUserInput(sheet, row, column, text);
|
||||||
|
state.selectCell({ row: row + 1, column });
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
options.refresh();
|
||||||
|
break;
|
||||||
|
// case 'ArrowUp': {
|
||||||
|
// if (mode === 'init') {
|
||||||
|
// options.onEditEnd({ deltaRow: -1, deltaColumn: 0 });
|
||||||
|
// } else {
|
||||||
|
// options.onMoveCaretToStart();
|
||||||
|
// }
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'ArrowDown': {
|
||||||
|
// if (mode === 'init') {
|
||||||
|
// options.onEditEnd({ deltaRow: 1, deltaColumn: 0 });
|
||||||
|
// } else {
|
||||||
|
// options.onMoveCaretToEnd();
|
||||||
|
// }
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'Tab': {
|
||||||
|
// if (event.shiftKey) {
|
||||||
|
// options.onEditEnd({ deltaRow: 0, deltaColumn: -1 });
|
||||||
|
// } else {
|
||||||
|
// options.onEditEnd({ deltaRow: 0, deltaColumn: 1 });
|
||||||
|
// }
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'Escape': {
|
||||||
|
// options.onEditEscape();
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'ArrowLeft': {
|
||||||
|
// if (mode === 'init') {
|
||||||
|
// options.onEditEnd({ deltaRow: 0, deltaColumn: -1 });
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'ArrowRight': {
|
||||||
|
// if (mode === 'init') {
|
||||||
|
// options.onEditEnd({ deltaRow: 0, deltaColumn: 1 });
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'F4': {
|
||||||
|
// options.onReferenceCycle();
|
||||||
|
// event.preventDefault();
|
||||||
|
// event.stopPropagation();
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, [model, state]);
|
||||||
|
return { onKeyDown };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useEditorKeydown;
|
||||||
334
webapp/src/components/editor/util.tsx
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
import { getTokens } from "@ironcalc/wasm";
|
||||||
|
import { tokenIsRangeType, tokenIsReferenceType } from "./tokenTypes";
|
||||||
|
import { Area } from "./editorContext";
|
||||||
|
|
||||||
|
const letters = [
|
||||||
|
"A",
|
||||||
|
"B",
|
||||||
|
"C",
|
||||||
|
"D",
|
||||||
|
"E",
|
||||||
|
"F",
|
||||||
|
"G",
|
||||||
|
"H",
|
||||||
|
"I",
|
||||||
|
"J",
|
||||||
|
"K",
|
||||||
|
"L",
|
||||||
|
"M",
|
||||||
|
"N",
|
||||||
|
"O",
|
||||||
|
"P",
|
||||||
|
"Q",
|
||||||
|
"R",
|
||||||
|
"S",
|
||||||
|
"T",
|
||||||
|
"U",
|
||||||
|
"V",
|
||||||
|
"W",
|
||||||
|
"X",
|
||||||
|
"Y",
|
||||||
|
"Z",
|
||||||
|
];
|
||||||
|
interface Reference {
|
||||||
|
row: number;
|
||||||
|
column: number;
|
||||||
|
absoluteRow: boolean;
|
||||||
|
absoluteColumn: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function referenceToString(rf: Reference): string {
|
||||||
|
const absC = rf.absoluteColumn ? "$" : "";
|
||||||
|
const absR = rf.absoluteRow ? "$" : "";
|
||||||
|
return absC + columnNameFromNumber(rf.column) + absR + rf.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function columnNameFromNumber(column: number): string {
|
||||||
|
let columnName = "";
|
||||||
|
let index = column;
|
||||||
|
while (index > 0) {
|
||||||
|
columnName = `${letters[(index - 1) % 26]}${columnName}`;
|
||||||
|
index = Math.floor((index - 1) / 26);
|
||||||
|
}
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function columnNumberFromName(columnName: string): number {
|
||||||
|
let column = 0;
|
||||||
|
for (const character of columnName) {
|
||||||
|
const index = (character.codePointAt(0) ?? 0) - 64;
|
||||||
|
column = column * 26 + index;
|
||||||
|
}
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
interface Range {
|
||||||
|
sheet: number | null;
|
||||||
|
rowStart: number;
|
||||||
|
rowEnd: number;
|
||||||
|
columnStart: number;
|
||||||
|
columnEnd: number;
|
||||||
|
absoluteRowStart: boolean;
|
||||||
|
absoluteRowEnd: boolean;
|
||||||
|
absoluteColumnStart: boolean;
|
||||||
|
absoluteColumnEnd: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStringRange(range: Range, sheetNames: string[]) {
|
||||||
|
const name = range.sheet ? `${sheetNames[range.sheet]}!` : "";
|
||||||
|
const left = referenceToString({
|
||||||
|
row: range.rowStart,
|
||||||
|
column: range.columnStart,
|
||||||
|
absoluteRow: range.absoluteRowStart,
|
||||||
|
absoluteColumn: range.absoluteColumnStart,
|
||||||
|
});
|
||||||
|
if (
|
||||||
|
range.rowStart === range.rowEnd &&
|
||||||
|
range.columnStart === range.columnEnd
|
||||||
|
) {
|
||||||
|
return `${name}${left}`;
|
||||||
|
}
|
||||||
|
const right = referenceToString({
|
||||||
|
row: range.rowEnd,
|
||||||
|
column: range.columnEnd,
|
||||||
|
absoluteRow: range.absoluteRowEnd,
|
||||||
|
absoluteColumn: range.absoluteColumnEnd,
|
||||||
|
});
|
||||||
|
return `${name}${left}:${right}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ActiveRange {
|
||||||
|
sheet: number;
|
||||||
|
rowStart: number;
|
||||||
|
rowEnd: number;
|
||||||
|
columnStart: number;
|
||||||
|
columnEnd: number;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IronCalc Color Palette
|
||||||
|
export function getColor(index: number, alpha = 1): string {
|
||||||
|
const colors = [
|
||||||
|
{
|
||||||
|
name: "Cyan",
|
||||||
|
rgba: [89, 185, 188, 1],
|
||||||
|
hex: "#59B9BC",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flamingo",
|
||||||
|
rgba: [236, 87, 83, 1],
|
||||||
|
hex: "#EC5753",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#3358B7",
|
||||||
|
rgba: [51, 88, 183, 1],
|
||||||
|
name: "Blue",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#F8CD3C",
|
||||||
|
rgba: [248, 205, 60, 1],
|
||||||
|
name: "Yellow",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#3BB68A",
|
||||||
|
rgba: [59, 182, 138, 1],
|
||||||
|
name: "Emerald",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#523E93",
|
||||||
|
rgba: [82, 62, 147, 1],
|
||||||
|
name: "Violet",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#A23C52",
|
||||||
|
rgba: [162, 60, 82, 1],
|
||||||
|
name: "Burgundy",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#8CB354",
|
||||||
|
rgba: [162, 60, 82, 1],
|
||||||
|
name: "Wasabi",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#D03627",
|
||||||
|
rgba: [208, 54, 39, 1],
|
||||||
|
name: "Red",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hex: "#1B717E",
|
||||||
|
rgba: [27, 113, 126, 1],
|
||||||
|
name: "Teal",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
if (alpha === 1) {
|
||||||
|
return colors[index % 10].hex;
|
||||||
|
}
|
||||||
|
const { rgba } = colors[index % 10];
|
||||||
|
return `rgba(${rgba[0]}, ${rgba[1]}, ${rgba[2]}, ${alpha})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This function get a formula like `=A1*SUM(B5:C6)` and transforms it to:
|
||||||
|
*
|
||||||
|
* `<span>=</span><span>A1</span><span>SUM</span><span>(</span><span>B5:C6</span><span>)</span>`
|
||||||
|
*
|
||||||
|
* While also returning the set of ranges [A1, B5:C6] with specific color assignments for each range
|
||||||
|
*/
|
||||||
|
export function getFormulaHTML(
|
||||||
|
text: string,
|
||||||
|
sheet: number,
|
||||||
|
sheetList: string[],
|
||||||
|
insertRage: Area | null,
|
||||||
|
insertRangeText: string
|
||||||
|
): {
|
||||||
|
html: JSX.Element[];
|
||||||
|
activeRanges: ActiveRange[];
|
||||||
|
isInReferenceMode: boolean;
|
||||||
|
} {
|
||||||
|
let html = [];
|
||||||
|
const activeRanges: ActiveRange[] = [];
|
||||||
|
let colorCount = 0;
|
||||||
|
if (text.startsWith("=")) {
|
||||||
|
const formula = text.slice(1);
|
||||||
|
|
||||||
|
const tokens = getTokens(formula);
|
||||||
|
const tokenCount = tokens.length;
|
||||||
|
const usedColors: Record<string, string> = {};
|
||||||
|
for (let index = 0; index < tokenCount; index += 1) {
|
||||||
|
const { token, start, end } = tokens[index];
|
||||||
|
if (tokenIsReferenceType(token)) {
|
||||||
|
const { sheet: refSheet, row, column } = token.Reference;
|
||||||
|
const sheetIndex = refSheet ? sheetList.indexOf(refSheet) : sheet;
|
||||||
|
const key = `${sheetIndex}-${row}-${column}`;
|
||||||
|
let color = usedColors[key];
|
||||||
|
if (!color) {
|
||||||
|
color = getColor(colorCount);
|
||||||
|
usedColors[key] = color;
|
||||||
|
colorCount += 1;
|
||||||
|
}
|
||||||
|
html.push(
|
||||||
|
<span key={index} style={{ color }}>
|
||||||
|
{formula.slice(start, end)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
activeRanges.push({
|
||||||
|
sheet: sheetIndex,
|
||||||
|
rowStart: row,
|
||||||
|
columnStart: column,
|
||||||
|
rowEnd: row,
|
||||||
|
columnEnd: column,
|
||||||
|
color,
|
||||||
|
});
|
||||||
|
} else if (tokenIsRangeType(token)) {
|
||||||
|
let {
|
||||||
|
sheet: refSheet,
|
||||||
|
left: { row: rowStart, column: columnStart },
|
||||||
|
right: { row: rowEnd, column: columnEnd },
|
||||||
|
} = token.Range;
|
||||||
|
const sheetIndex = refSheet ? sheetList.indexOf(refSheet) : sheet;
|
||||||
|
|
||||||
|
const key = `${sheetIndex}-${rowStart}-${columnStart}:${rowEnd}-${columnEnd}`;
|
||||||
|
let color = usedColors[key];
|
||||||
|
if (!color) {
|
||||||
|
color = getColor(colorCount);
|
||||||
|
usedColors[key] = color;
|
||||||
|
colorCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowStart > rowEnd) {
|
||||||
|
[rowStart, rowEnd] = [rowEnd, rowStart];
|
||||||
|
}
|
||||||
|
if (columnStart > columnEnd) {
|
||||||
|
[columnStart, columnEnd] = [columnEnd, columnStart];
|
||||||
|
}
|
||||||
|
html.push(
|
||||||
|
<span key={index} style={{ color }}>
|
||||||
|
{formula.slice(start, end)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
colorCount += 1;
|
||||||
|
|
||||||
|
activeRanges.push({
|
||||||
|
sheet: sheetIndex,
|
||||||
|
rowStart,
|
||||||
|
columnStart,
|
||||||
|
rowEnd,
|
||||||
|
columnEnd,
|
||||||
|
color,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
html.push(<span key={index}>{formula.slice(start, end)}</span>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tokenCount > 0) {
|
||||||
|
const lastToken = tokens[tokens.length - 1];
|
||||||
|
if (lastToken.end < text.length - 1) {
|
||||||
|
html.push(
|
||||||
|
<span key="rest">{text.slice(lastToken.end + 1, text.length)}</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html = [<span key="equals">=</span>].concat(html);
|
||||||
|
} else {
|
||||||
|
html = [<span key="single">{text}</span>];
|
||||||
|
}
|
||||||
|
const isRefMode = isInReferenceMode(text, text.length);
|
||||||
|
if (isRefMode) {
|
||||||
|
if (insertRage) {
|
||||||
|
const color = getColor(colorCount);
|
||||||
|
activeRanges.push({
|
||||||
|
sheet: insertRage.sheet || sheet,
|
||||||
|
rowStart: insertRage.rowStart,
|
||||||
|
rowEnd: insertRage.rowEnd,
|
||||||
|
columnStart: insertRage.columnStart,
|
||||||
|
columnEnd: insertRage.columnEnd,
|
||||||
|
color,
|
||||||
|
});
|
||||||
|
colorCount += 1;
|
||||||
|
html.push(
|
||||||
|
<span key="insert-range" style={{ color, textDecoration: "underline" }}>
|
||||||
|
{insertRangeText}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
html.push(
|
||||||
|
<span
|
||||||
|
key="insert-cue"
|
||||||
|
style={{
|
||||||
|
border: "1px solid #d5d5d5",
|
||||||
|
height: "2px",
|
||||||
|
width: "7px",
|
||||||
|
borderTop: 0,
|
||||||
|
display: "inline-block",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// We add a clickable element that spans the rest of the available space
|
||||||
|
html.push(<span key="spacer" style={{ flexGrow: 1 }}></span>);
|
||||||
|
return { html, activeRanges, isInReferenceMode: isRefMode };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isInReferenceMode(text: string, cursor: number): boolean {
|
||||||
|
// FIXME
|
||||||
|
// This is a gross oversimplification
|
||||||
|
// Returns true if both are true:
|
||||||
|
// 1. Cursor is at the end
|
||||||
|
// 2. Last char is one of [',', '(', '+', '*', '-', '/', '<', '>', '=', '&']
|
||||||
|
// This has many false positives like '="1+' and also likely some false negatives
|
||||||
|
// The right way of doing this is to have a partial parse of the formula tree
|
||||||
|
// and check if the next token could be a reference
|
||||||
|
if (!text.startsWith("=")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (text === "=") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const l = text.length;
|
||||||
|
const chars = [",", "(", "+", "*", "-", "/", "<", ">", "=", "&"];
|
||||||
|
if (cursor === l && chars.includes(text[l - 1])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||