autumn_plugin_univer/lib.rs
1//! Univer spreadsheets for Autumn, with Maud + htmx ergonomics.
2//!
3//! Add [`UniverPlugin`] to the app. Put [`univer_stylesheet()`] and
4//! [`univer_script()`] in the page `<head>`. Render a [`Spreadsheet`]:
5//!
6//! ```rust,no_run
7//! use autumn_plugin_univer::{
8//! Cell, Sheet, Spreadsheet, UniverPlugin, Workbook, univer_script, univer_stylesheet,
9//! };
10//! use autumn_web::prelude::*;
11//!
12//! #[get("/")]
13//! async fn index() -> Markup {
14//! let workbook = Workbook::builder("budget", "Budget")
15//! .sheet(
16//! Sheet::new("q1", "Q1")
17//! .with_row(0, [Cell::text("Rent"), Cell::number(1200.0)])
18//! .with_cell(1, 1, Cell::formula("=B1*12")),
19//! )
20//! .build()
21//! .unwrap_or_else(|_| Workbook::empty("budget"));
22//! html! {
23//! html {
24//! head { (univer_stylesheet()) (univer_script()) }
25//! body {
26//! (Spreadsheet::new("budget").workbook(&workbook).save_url("/budget"))
27//! }
28//! }
29//! }
30//! }
31//!
32//! # async fn run() {
33//! autumn_web::app()
34//! .plugin(UniverPlugin::new())
35//! .routes(routes![index])
36//! .run()
37//! .await;
38//! # }
39//! ```
40//!
41//! The plugin vendors [Univer](https://univer.ai) 1.0 (Apache-2.0) as one
42//! code-split ES module bundle. No npm, no bundler and no CDN in the host
43//! app. The bundle is the [`UNIVER_ASSETS`] Autumn plugin asset bundle. It
44//! serves from memory under `/static/_plugins/univer/` with content-hashed,
45//! immutable URLs and SRI hashes.
46//!
47//! Read a saved sheet back with the [`WorkbookSnapshot`] extractor. It
48//! validates the data against the [`Workbook`] invariants and [`Limits`].
49//!
50//! # Limits
51//!
52//! - Only the open-source sheets core preset is in. Univer Pro features
53//! (XLSX import and export, collaboration, charts) are not.
54//! - Each plugin release pins one Univer version (see
55//! [`UNIVER_VERSION`]).
56//! - Without JavaScript, the page shows a `<noscript>` notice.
57
58mod assets;
59mod bundle_files;
60mod extract;
61#[cfg(test)]
62mod init_js_tests;
63mod locale;
64mod plugin;
65mod script;
66mod spreadsheet;
67mod workbook;
68
69pub use assets::{ASSETS_NAMESPACE, UNIVER_ASSETS, UNIVER_VERSION};
70pub use extract::WorkbookSnapshot;
71pub use locale::{Locale, UnknownLocale};
72pub use plugin::{PLUGIN_NAME, UniverPlugin};
73pub use script::{univer_script, univer_stylesheet};
74pub use spreadsheet::{Spreadsheet, save_button};
75pub use workbook::{
76 Cell, CellRef, CellType, CellValue, Limits, Sheet, SheetId, Workbook, WorkbookBuilder,
77 WorkbookError, WorkbookId,
78};