First working version

This commit is contained in:
Rachit Singh
2022-12-20 17:32:39 -05:00
commit 61d00560a3
19 changed files with 1197 additions and 0 deletions

45
src/lib.rs Normal file
View File

@@ -0,0 +1,45 @@
mod obsidian;
use js_sys::JsString;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct ExampleCommand {
id: JsString,
name: JsString,
}
#[wasm_bindgen]
impl ExampleCommand {
#[wasm_bindgen(getter)]
pub fn id(&self) -> JsString {
self.id.clone()
}
#[wasm_bindgen(setter)]
pub fn set_id(&mut self, id: &str) {
self.id = JsString::from(id)
}
#[wasm_bindgen(getter)]
pub fn name(&self) -> JsString {
self.name.clone()
}
#[wasm_bindgen(setter)]
pub fn set_name(&mut self, name: &str) {
self.name = JsString::from(name)
}
pub fn callback(&self) {
obsidian::Notice::new("hello from rust");
}
}
#[wasm_bindgen]
pub fn onload(plugin: &obsidian::Plugin) {
let cmd = ExampleCommand {
id: JsString::from("example"),
name: JsString::from("Example"),
};
plugin.addCommand(JsValue::from(cmd))
}

14
src/obsidian.rs Normal file
View File

@@ -0,0 +1,14 @@
use wasm_bindgen::prelude::*;
#[wasm_bindgen(module = "obsidian")]
extern "C" {
pub type Plugin;
#[wasm_bindgen(structural, method)]
pub fn addCommand(this: &Plugin, command: JsValue);
pub type Notice;
#[wasm_bindgen(constructor)]
pub fn new(message: &str) -> Notice;
}