1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! # `canvist_model`
//!
//! The block-based rich-text document model behind the canvist editor.
//!
//! - A [`Schema`] declares which blocks, marks, and inline embeds exist. Apps
//! build it from the extensions they use, so unused features cost nothing.
//! - A [`Document`] stores blocks by stable [`BlockId`]. Text blocks hold
//! [`InlineText`]: one string plus run-length [`MarkSet`] formatting.
//! - [`Step`]s are the only way to change a document. Each is invertible,
//! reports how it moves [`Point`]s, and maps one-to-one onto CRDT
//! operations, so undo, collaboration, and rendering share one pipeline.
//! - A [`Transaction`] applies steps atomically and returns a [`Commit`]
//! describing which blocks changed, which is what the layout engine uses to
//! relayout only the affected blocks.
//!
//! # Example
//!
//! ```
//! use std::sync::Arc;
//!
//! use canvist_model::Attrs;
//! use canvist_model::BlockSpec;
//! use canvist_model::Document;
//! use canvist_model::Mark;
//! use canvist_model::MarkSet;
//! use canvist_model::MarkSpec;
//! use canvist_model::Point;
//! use canvist_model::Schema;
//!
//! let schema = Arc::new(
//! Schema::builder()
//! .block(BlockSpec::text("paragraph"))
//! .mark(MarkSpec::new("bold"))
//! .build()?,
//! );
//! let bold = Mark::new(schema.mark_type("bold").expect("registered above"));
//! let paragraph = schema.default_text_block();
//!
//! let mut doc = Document::new(schema, 1);
//! let first = doc.first_text_block().expect("new documents have one block");
//!
//! let mut transaction = doc.transaction();
//! let end = transaction.insert_text(Point::new(first, 0), "Hello world", MarkSet::empty())?;
//! transaction.add_mark(first, 6..11, bold)?;
//! transaction.split(end, paragraph, Attrs::new())?;
//! let commit = transaction.commit();
//!
//! assert_eq!(doc.plain_text(), "Hello world\n");
//!
//! // Every commit carries its own undo.
//! doc.apply_steps(commit.undo_steps())?;
//! assert_eq!(doc.plain_text(), "");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use Attrs;
pub use Value;
pub use Block;
pub use BlockTree;
pub use Content;
pub use TreeContent;
pub use Document;
pub use BlockId;
pub use IdGenerator;
pub use ParseBlockIdError;
pub use EMBED_CHAR;
pub use Embed;
pub use InlineError;
pub use InlineText;
pub use RunRef;
pub use JsonError;
pub use Mark;
pub use MarkSet;
pub use Savepoint;
pub use BlockSpec;
pub use BlockType;
pub use BlockTypeId;
pub use ContentKind;
pub use ContentSpec;
pub use EmbedSpec;
pub use EmbedType;
pub use EmbedTypeId;
pub use MarkSpec;
pub use MarkType;
pub use MarkTypeId;
pub use Schema;
pub use SchemaBuilder;
pub use SchemaError;
pub use Bias;
pub use Point;
pub use Selection;
pub use Applied;
pub use Mapped;
pub use Step;
pub use StepError;
pub use StepMap;
pub use GridCell;
pub use GridRect;
pub use TableMap;
pub use Commit;
pub use Transaction;
pub use is_safe_link_url;