Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: link wasm-keys #72

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions leptos_hotkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ leptos = "0.6"
log = { version = "0.4", optional = true }
wasm-bindgen = "0.2"
web-sys = "0.3"
wasm-keys = { git = "https://github.com/gaucho-labs/wasm-keys" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really unsafe. Would you mind to release a version of wasm-keys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- sorry I was going to do this during the weekend


[features]
debug = ["dep:log"]
Expand Down
14 changes: 8 additions & 6 deletions leptos_hotkeys/src/hotkeys_provider.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use leptos::html::ElementDescriptor;
use leptos::*;
use std::collections::HashSet;

use wasm_keys::wasm_key::WasmKey;

Check warning on line 5 in leptos_hotkeys/src/hotkeys_provider.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `wasm_keys::wasm_key::WasmKey`

Check warning on line 5 in leptos_hotkeys/src/hotkeys_provider.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `wasm_keys::wasm_key::WasmKey`

#[cfg(not(feature = "ssr"))]
use wasm_bindgen::JsCast;

// Defining a hotkey context structure
#[derive(Clone, Copy)]
pub struct HotkeysContext {
#[cfg(not(feature = "ssr"))]
pub(crate) pressed_keys: RwSignal<std::collections::HashMap<String, web_sys::KeyboardEvent>>,
pub(crate) pressed_keys: RwSignal<std::collections::HashMap<WasmKey, web_sys::KeyboardEvent>>,

#[cfg(not(feature = "ssr"))]
pub active_ref_target: RwSignal<Option<web_sys::EventTarget>>,
Expand Down Expand Up @@ -39,7 +41,7 @@
});

#[cfg(not(feature = "ssr"))]
let pressed_keys: RwSignal<std::collections::HashMap<String, web_sys::KeyboardEvent>> =
let pressed_keys: RwSignal<std::collections::HashMap<WasmKey, web_sys::KeyboardEvent>> =
RwSignal::new(std::collections::HashMap::new());

let active_scopes: RwSignal<HashSet<String>> = RwSignal::new(initially_active_scopes);
Expand Down Expand Up @@ -79,10 +81,10 @@
}
})
});

Check failure on line 84 in leptos_hotkeys/src/hotkeys_provider.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/leptos-hotkeys/leptos-hotkeys/leptos_hotkeys/src/hotkeys_provider.rs
#[cfg(all(feature = "debug", not(feature = "ssr")))]
create_effect(move |_| {
let pressed_keys_list = move || pressed_keys.get().keys().cloned().collect::<Vec<String>>();
let pressed_keys_list = move || pressed_keys.get().keys().cloned().collect::<Vec<WasmKey>>();
logging::log!("keys pressed: {:?}", pressed_keys_list());
});

Expand All @@ -98,13 +100,13 @@
let keydown_listener =
wasm_bindgen::closure::Closure::wrap(Box::new(move |event: web_sys::KeyboardEvent| {
pressed_keys.update(|keys| {
keys.insert(event.key().to_lowercase(), event);
keys.insert(WasmKey::from(event.key()), event);
});
}) as Box<dyn Fn(_)>);
let keyup_listener =
wasm_bindgen::closure::Closure::wrap(Box::new(move |event: web_sys::KeyboardEvent| {
pressed_keys.update(|keys| {
keys.remove(&event.key().to_lowercase());
keys.remove(&WasmKey::from(event.key()));
});
}) as Box<dyn Fn(_)>);

Expand Down
1 change: 0 additions & 1 deletion leptos_hotkeys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod hotkeys_provider;
pub mod macros;
pub mod prelude;
pub mod types;
pub mod use_hotkeys;

pub use prelude::*;
179 changes: 0 additions & 179 deletions leptos_hotkeys/src/types.rs

This file was deleted.

Loading
Loading