3
3
// https://github.com/broxamson/hcl-leptos-app/blob/6f2da694fb97e60f4d2fd7cc7038bfb483566ba3/src/pages/global_components/text_editor.rs
4
4
// https://github.com/siku2/rust-monaco/issues/50
5
5
6
+ #[ cfg( target_arch = "wasm32" ) ]
6
7
use std:: { cell:: RefCell , rc:: Rc } ;
7
8
8
9
use leptos:: {
9
- component, create_node_ref, create_rw_signal , create_signal, html:: Div , view, IntoView ,
10
- NodeRef , ReadSignal , RwSignal , SignalGetUntracked , WriteSignal ,
10
+ component, create_node_ref, create_signal, html:: Div , view, IntoView , NodeRef , ReadSignal ,
11
+ WriteSignal ,
11
12
} ;
13
+
14
+ #[ cfg( target_arch = "wasm32" ) ]
12
15
use monaco:: api:: { CodeEditor , TextModel } ;
13
16
14
17
#[ cfg( target_arch = "wasm32" ) ]
15
- use leptos:: { SignalGet , SignalSet , SignalUpdate } ;
18
+ use leptos:: { create_rw_signal , RwSignal , SignalGet , SignalGetUntracked , SignalSet , SignalUpdate } ;
16
19
#[ cfg( target_arch = "wasm32" ) ]
17
20
use monaco:: {
18
21
api:: CodeEditorOptions ,
@@ -111,12 +114,14 @@ pub fn TextEditor(
111
114
}
112
115
113
116
/// Shared reference to the underlying [`CodeEditor`].
117
+ #[ cfg( target_arch = "wasm32" ) ]
114
118
pub type CodeEditorCell = Rc < RefCell < Option < CodeEditor > > > ;
115
119
#[ cfg( target_arch = "wasm32" ) ]
116
120
pub type ClosureCell = Rc < RefCell < Option < ( Closure < dyn Fn ( ) > , IDisposable ) > > > ;
117
121
118
122
#[ derive( Copy , Clone , Debug ) ]
119
123
pub struct EditorState {
124
+ #[ cfg( target_arch = "wasm32" ) ]
120
125
pub code_editor : RwSignal < CodeEditorCell > ,
121
126
#[ cfg( target_arch = "wasm32" ) ]
122
127
pub update_fn_closure : RwSignal < ClosureCell > ,
@@ -131,12 +136,14 @@ impl Default for EditorState {
131
136
impl EditorState {
132
137
pub fn new ( ) -> Self {
133
138
Self {
139
+ #[ cfg( target_arch = "wasm32" ) ]
134
140
code_editor : create_rw_signal ( CodeEditorCell :: default ( ) ) ,
135
141
#[ cfg( target_arch = "wasm32" ) ]
136
142
update_fn_closure : create_rw_signal ( ClosureCell :: default ( ) ) ,
137
143
}
138
144
}
139
145
146
+ #[ cfg( target_arch = "wasm32" ) ]
140
147
pub fn get_value ( & self ) -> String {
141
148
self . code_editor
142
149
. get_untracked ( )
@@ -148,6 +155,7 @@ impl EditorState {
148
155
. unwrap_or_default ( )
149
156
}
150
157
158
+ #[ cfg( target_arch = "wasm32" ) ]
151
159
pub fn set_value ( & self , value : & str ) {
152
160
if let Some ( text_model) = self
153
161
. code_editor
0 commit comments