diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 54e908a..28fcff8 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -19,6 +19,9 @@ jobs: target: - nodejs - bundler + include: + - crate: sandbox + target: bundler steps: - uses: actions/checkout@v6 diff --git a/Cargo.lock b/Cargo.lock index 6c14a30..4b30129 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3179,6 +3179,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "saturn-v-sandbox" +version = "0.2.0" +dependencies = [ + "console_error_panic_hook", + "leptos", + "saturn-v-lsp", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "saturn-v-server" version = "0.2.0" diff --git a/Justfile b/Justfile index f73f27f..27c04e7 100644 --- a/Justfile +++ b/Justfile @@ -40,7 +40,7 @@ src := 'target/' + target + '/release/saturn-v' + binary_ext package_name := 'saturn-v-' + github_ref_name + package_postfix wasm crate target: - RUSTFLAGS="-C opt-level=z -C codegen-units=1 -C panic=abort" wasm-pack build crates/{{crate}} --release --target {{target}} + RUSTFLAGS="-C opt-level=z -C codegen-units=1 -C panic=abort" wasm-pack build crates/{{crate}} --release --target {{target}} --keep-going wasm-pack pack crates/{{crate}} mkdir -p pkg mv crates/{{crate}}/pkg/*.tgz pkg/{{crate}}-{{target}}.tgz diff --git a/crates/sandbox/.gitignore b/crates/sandbox/.gitignore new file mode 100644 index 0000000..9b1c8b1 --- /dev/null +++ b/crates/sandbox/.gitignore @@ -0,0 +1 @@ +/dist diff --git a/crates/sandbox/Cargo.toml b/crates/sandbox/Cargo.toml new file mode 100644 index 0000000..92486b4 --- /dev/null +++ b/crates/sandbox/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "saturn-v-sandbox" +license.workspace = true +edition.workspace = true +version.workspace = true +authors.workspace = true +repository.workspace = true +rust-version.workspace = true + +[lib] +crate-type = ["rlib", "cdylib"] + +[dependencies] +console_error_panic_hook.workspace = true +leptos.workspace = true +saturn-v-lsp.workspace = true +wasm-bindgen.workspace = true + +[dependencies.web-sys] +workspace = true +features = ["Element"] diff --git a/crates/sandbox/index.html b/crates/sandbox/index.html new file mode 100644 index 0000000..6c0c368 --- /dev/null +++ b/crates/sandbox/index.html @@ -0,0 +1,10 @@ + + + + + Saturn V Sandbox + + + + + diff --git a/crates/sandbox/src/lib.rs b/crates/sandbox/src/lib.rs new file mode 100644 index 0000000..a80e746 --- /dev/null +++ b/crates/sandbox/src/lib.rs @@ -0,0 +1,61 @@ +// Copyright (C) 2025-2026 Marceline Cramer +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// Saturn V is free software: you can redistribute it and/or modify it under +// the terms of the GNU Affero General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// Saturn V is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +// more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Saturn V. If not, see . + +use leptos::{html::Div, prelude::*}; +use wasm_bindgen::prelude::*; +use web_sys::{ + js_sys::{self, Reflect}, + Element, +}; + +#[wasm_bindgen] +pub fn mount(el: Element) { + console_error_panic_hook::set_once(); + mount_to(el.dyn_into().unwrap(), App).forget(); +} + +#[component] +pub fn App() -> impl IntoView { + view! { +

"The sandbox will go here."

+ + } +} + +#[component] +fn Editor() -> impl IntoView { + let node = NodeRef::
::new(); + + node.on_load(|node| { + let config = js_sys::Object::new(); + Reflect::set(&config, &"doc".into(), &"test contents\n".into()).unwrap(); + Reflect::set(&config, &"parent".into(), node.dyn_ref().unwrap()).unwrap(); + Reflect::set(&config, &"extensions".into(), &basicSetup).unwrap(); + EditorView::new(config); + }); + + view! {
} +} + +#[wasm_bindgen(module = "https://esm.sh/codemirror@6.0.2")] +extern "C" { + pub type EditorView; + + #[wasm_bindgen(constructor)] + pub fn new(args: js_sys::Object) -> EditorView; + + static basicSetup: JsValue; +} diff --git a/crates/sandbox/src/main.rs b/crates/sandbox/src/main.rs new file mode 100644 index 0000000..507137c --- /dev/null +++ b/crates/sandbox/src/main.rs @@ -0,0 +1,20 @@ +// Copyright (C) 2025-2026 Marceline Cramer +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// Saturn V is free software: you can redistribute it and/or modify it under +// the terms of the GNU Affero General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// Saturn V is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +// more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Saturn V. If not, see . + +fn main() { + console_error_panic_hook::set_once(); + leptos::mount::mount_to_body(saturn_v_sandbox::App); +}