feat: get web working properly
This commit is contained in:
1 parent
3c19def550
commit
18d6b1ad6f
26 files changed
+674
-1422
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
use js_sys::Function;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::{Element, Node};
|
||||
use web_sys::Element;
|
||||
|
||||
#[wasm_bindgen(module = "/src/interpreter.js")]
|
||||
extern "C" {
|
||||
@@ -12,86 +12,83 @@ extern "C" {
|
||||
pub fn new(arg: Element) -> Interpreter;
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetNode(this: &Interpreter, id: usize, node: Node);
|
||||
pub fn AppendChildren(this: &Interpreter, many: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn AppendChildren(this: &Interpreter, root: Option<u64>, children: Vec<u64>);
|
||||
pub fn AssignId(this: &Interpreter, path: &[u8], id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn ReplaceWith(this: &Interpreter, root: Option<u64>, nodes: Vec<u64>);
|
||||
pub fn CreateElement(this: &Interpreter, tag: &str);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn InsertAfter(this: &Interpreter, root: Option<u64>, nodes: Vec<u64>);
|
||||
pub fn CreateElementNs(this: &Interpreter, tag: &str, ns: &str);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn InsertBefore(this: &Interpreter, root: Option<u64>, nodes: Vec<u64>);
|
||||
pub fn CreatePlaceholder(this: &Interpreter, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn Remove(this: &Interpreter, root: Option<u64>);
|
||||
pub fn CreateStaticPlaceholder(this: &Interpreter);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn CreateTextNode(this: &Interpreter, text: JsValue, root: Option<u64>);
|
||||
pub fn CreateTextPlaceholder(this: &Interpreter);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn CreateElement(this: &Interpreter, tag: &str, root: Option<u64>, children: u32);
|
||||
pub fn CreateStaticText(this: &Interpreter, value: &str);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn CreateElementNs(
|
||||
this: &Interpreter,
|
||||
tag: &str,
|
||||
root: Option<u64>,
|
||||
ns: &str,
|
||||
children: u32,
|
||||
);
|
||||
pub fn CreateTextNode(this: &Interpreter, value: JsValue, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn CreatePlaceholder(this: &Interpreter, root: Option<u64>);
|
||||
pub fn HydrateText(this: &Interpreter, path: &[u8], value: &str, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn LoadTemplate(this: &Interpreter, name: &str, index: u32, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn ReplaceWith(this: &Interpreter, id: u32, m: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn ReplacePlaceholder(this: &Interpreter, path: &[u8], m: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn InsertAfter(this: &Interpreter, id: u32, n: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn InsertBefore(this: &Interpreter, id: u32, n: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SaveTemplate(this: &Interpreter, name: &str, m: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetAttribute(this: &Interpreter, id: u32, name: &str, value: JsValue, ns: Option<&str>);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetStaticAttribute(this: &Interpreter, name: &str, value: JsValue, ns: Option<&str>);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetBoolAttribute(this: &Interpreter, id: u32, name: &str, value: bool);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetText(this: &Interpreter, id: u32, text: JsValue);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn NewEventListener(
|
||||
this: &Interpreter,
|
||||
name: &str,
|
||||
root: Option<u64>,
|
||||
id: u32,
|
||||
handler: &Function,
|
||||
bubbles: bool,
|
||||
);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn RemoveEventListener(this: &Interpreter, root: Option<u64>, name: &str, bubbles: bool);
|
||||
pub fn RemoveEventListener(this: &Interpreter, name: &str, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetText(this: &Interpreter, root: Option<u64>, text: JsValue);
|
||||
pub fn RemoveAttribute(this: &Interpreter, id: u32, field: &str, ns: Option<&str>);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetAttribute(
|
||||
this: &Interpreter,
|
||||
root: Option<u64>,
|
||||
field: &str,
|
||||
value: JsValue,
|
||||
ns: Option<&str>,
|
||||
);
|
||||
pub fn Remove(this: &Interpreter, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn RemoveAttribute(this: &Interpreter, root: Option<u64>, field: &str, ns: Option<&str>);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn CloneNode(this: &Interpreter, root: Option<u64>, new_id: u64);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn CloneNodeChildren(this: &Interpreter, root: Option<u64>, new_ids: Vec<u64>);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn FirstChild(this: &Interpreter);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn NextSibling(this: &Interpreter);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn ParentNode(this: &Interpreter);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn StoreWithId(this: &Interpreter, id: u64);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn SetLastNode(this: &Interpreter, id: u64);
|
||||
pub fn PushRoot(this: &Interpreter, id: u32);
|
||||
}
|
||||
@@ -265,7 +265,14 @@ export class Interpreter {
|
||||
SaveTemplate(name, m) {
|
||||
this.templates[name] = this.stack.splice(this.stack.length - m);
|
||||
}
|
||||
CreateStaticText(text) {
|
||||
this.CreateTextNode(text);
|
||||
}
|
||||
CreateTextPlaceholder() {
|
||||
this.CreateRawText("placeholder");
|
||||
}
|
||||
handleEdit(edit) {
|
||||
console.log(edit);
|
||||
switch (edit.type) {
|
||||
case "AppendChildren":
|
||||
this.AppendChildren(edit.m);
|
||||
@@ -283,13 +290,13 @@ export class Interpreter {
|
||||
this.CreatePlaceholder(edit.id);
|
||||
break;
|
||||
case "CreateStaticText":
|
||||
this.CreateTextNode(edit.value);
|
||||
this.CreateStaticText(edit.value)
|
||||
break;
|
||||
case "CreateStaticPlaceholder":
|
||||
this.CreateStaticPlaceholder();
|
||||
break;
|
||||
case "CreateTextPlaceholder":
|
||||
this.CreateRawText("placeholder");
|
||||
this.CreateTextPlaceholder();
|
||||
break;
|
||||
case "CreateStaticText":
|
||||
this.CreateRawText(edit.value);
|
||||
@@ -301,7 +308,7 @@ export class Interpreter {
|
||||
this.HydrateText(edit.path, edit.value, edit.id);
|
||||
break;
|
||||
case "LoadTemplate":
|
||||
this.LoadTemplate(edit.name, edit.index);
|
||||
this.LoadTemplate(edit.name, edit.index, edit.id);
|
||||
break;
|
||||
case "SaveTemplate":
|
||||
this.SaveTemplate(edit.name, edit.m);
|
||||
|
||||
Reference in new issue
Block a user