leptos_tiptap/
lib.rs

1use serde::{Deserialize, Serialize};
2
3mod js_tiptap;
4mod tiptap_instance;
5
6pub use tiptap_instance::TiptapInstance;
7pub use tiptap_instance::TiptapInstanceMsg;
8
9#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
10pub enum TiptapContent {
11    Html(String),
12    Json(String),
13}
14
15/// State of the current editor. Contains the selection state.
16#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
17pub struct TiptapEditorState {
18    editable: bool,
19    selection: TiptapSelectionState,
20}
21
22/// State of the current selection.
23#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
24pub struct TiptapSelectionState {
25    /// 'true' if the cursor is in a h1.
26    pub h1: bool,
27
28    /// 'true' if the cursor is in a h2.
29    pub h2: bool,
30
31    /// 'true' if the cursor is in a h3.
32    pub h3: bool,
33
34    /// 'true' if the cursor is in a h4.
35    pub h4: bool,
36
37    /// 'true' if the cursor is in a h5.
38    pub h5: bool,
39
40    /// 'true' if the cursor is in a h6.
41    pub h6: bool,
42
43    /// 'true' if the cursor is in a paragraph.
44    pub paragraph: bool,
45
46    /// 'true' if the cursor is in a bold text segment.
47    pub bold: bool,
48
49    /// 'true' if the cursor is in an italic text segment.
50    pub italic: bool,
51
52    /// 'true' if the cursor is in a strikethrough text segment.
53    pub strike: bool,
54
55    /// 'true' if the cursor is in a blockquote.
56    pub blockquote: bool,
57
58    /// 'true' if the cursor is in a highlighted text segment.
59    pub highlight: bool,
60
61    /// 'true' if the cursor is in a bullet-list.
62    pub bullet_list: bool,
63
64    /// 'true' if the cursor is in an ordered-list.
65    pub ordered_list: bool,
66
67    /// 'true' if the cursor is in a left-aligned text segment.
68    pub align_left: bool,
69
70    /// 'true' if the cursor is in a center-aligned text segment.
71    pub align_center: bool,
72
73    /// 'true' if the cursor is in a right-aligned text segment.
74    pub align_right: bool,
75
76    /// 'true' if the cursor is in a justify-aligned text segment.
77    pub align_justify: bool,
78
79    /// 'true' if the cursor is in a link.
80    pub link: bool,
81
82    /// 'true' if the cursor is on en embedded YouTube video.
83    pub youtube: bool,
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87pub enum TiptapHeadingLevel {
88    H1,
89    H2,
90    H3,
91    H4,
92    H5,
93    H6,
94}
95
96impl From<TiptapHeadingLevel> for i32 {
97    fn from(val: TiptapHeadingLevel) -> Self {
98        match val {
99            TiptapHeadingLevel::H1 => 1,
100            TiptapHeadingLevel::H2 => 2,
101            TiptapHeadingLevel::H3 => 3,
102            TiptapHeadingLevel::H4 => 4,
103            TiptapHeadingLevel::H5 => 5,
104            TiptapHeadingLevel::H6 => 6,
105        }
106    }
107}
108
109#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
110pub struct TiptapImageResource {
111    /// Example: image.png
112    pub title: String,
113
114    /// Example: "An example image, ..."
115    pub alt: String,
116
117    /// Example: https:://my-site.com/public/image.png
118    pub url: String,
119}
120
121#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
122pub struct TiptapLinkResource {
123    /// Example: https:://my-site.com
124    pub href: String,
125
126    /// Example: "_blank", specifies where to open the linked document
127    pub target: String,
128
129    /// Example: "alternate"
130    pub rel: String,
131}
132
133#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
134pub struct TiptapYoutubeVideoResource {
135    /// Example: https://www.youtube.com/embed/dQw4w9WgXcQ?si=6LwJzVo1t8hpLywC
136    pub src: String,
137
138    /// Example: "0", specifies when to start the video
139    pub start: String,
140
141    /// Example: "640"
142    pub width: String,
143
144    /// Example: "480"
145    pub height: String,
146}