-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add menu component, proper code block support with syntax highlighting
Syntax highlighting is being done on main thread. This is kinda slow operation and blocks the main thread. It should be done in a web worker but that is unsupported by trunk and is a hassle to get working. See: trunk-rs/trunk#46
- Loading branch information
Showing
22 changed files
with
749 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::collections::HashSet; | ||
use wasm_bindgen::{JsValue, JsCast}; | ||
|
||
#[derive(Debug)] | ||
pub enum ListIndex { | ||
Single(Option<usize>), | ||
Multi(HashSet<usize>), | ||
} | ||
|
||
|
||
impl From<JsValue> for ListIndex { | ||
fn from(val: JsValue) -> Self { | ||
if let Ok(set) = val.clone().dyn_into::<js_sys::Set>() { | ||
let indices = set.values() | ||
.into_iter() | ||
.filter_map(|item| item.ok()) | ||
.filter_map(|value| value.as_f64()) | ||
.map(|num| num as usize) | ||
.collect(); | ||
ListIndex::Multi(indices) | ||
} else if let Some(value) = val.as_f64() { | ||
ListIndex::Single(if value != -1.0 { Some(value as usize) } else { None }) | ||
} else { | ||
panic!("This should never happen") | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::list::ListIndex; | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen::JsCast; | ||
use js_sys::Object; | ||
|
||
#[derive(Debug)] | ||
pub struct SelectedDetail { | ||
index: ListIndex, | ||
diff: Option<IndexDiff>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct IndexDiff { | ||
added: Vec<usize>, | ||
removed: Vec<usize>, | ||
} | ||
|
||
impl From<JsValue> for SelectedDetail { | ||
fn from(value: JsValue) -> Self { | ||
let detail = value.unchecked_into::<SelectedDetailJS>(); | ||
let index = ListIndex::from(detail.index()); | ||
|
||
let diff = if detail.diff().is_undefined() { None } else { | ||
let diff = detail.diff(); | ||
Some(IndexDiff { | ||
added: diff.added(), | ||
removed: diff.removed(), | ||
}) | ||
}; | ||
Self { | ||
index, | ||
diff, | ||
} | ||
} | ||
} | ||
|
||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[derive(Debug)] | ||
#[wasm_bindgen(extends = Object)] | ||
type SelectedDetailJS; | ||
|
||
#[wasm_bindgen(method, getter)] | ||
pub fn index(this: &SelectedDetailJS) -> JsValue; | ||
|
||
#[wasm_bindgen(method, getter)] | ||
pub fn diff(this: &SelectedDetailJS) -> IndexDiffJS; | ||
|
||
#[derive(Debug)] | ||
#[wasm_bindgen(extends = Object)] | ||
type IndexDiffJS; | ||
|
||
#[wasm_bindgen(method, getter)] | ||
pub fn added(this: &IndexDiffJS) -> Vec<usize>; | ||
|
||
#[wasm_bindgen(method, getter)] | ||
pub fn removed(this: &IndexDiffJS) -> Vec<usize>; | ||
} | ||
|
Oops, something went wrong.