set up a typescript pipeline for interpreter

This commit is contained in:
Jonathan Kelley committed 2024-02-23 18:52:21 -08:00
1 parent 53cafefdef
commit 7f60010c1e
11 files changed
+197 -44

No files matched your search

@@ -1,4 +1,5 @@
export function setAttributeInner(node, field, value, ns) {
const name = field;
if (ns === "style") {
// ????? why do we need to do this
View File
Whitespace-only changes.
+81
View File
@@ -0,0 +1,81 @@
// DO NOT EDIT THIS FILE. HASH: 9578489549991746027
export function setAttributeInner(node, field, value, ns) {
const name = field;
if (ns === "style") {
// ????? why do we need to do this
if (node.style === undefined) {
node.style = {};
}
node.style[name] = value;
}
else if (!!ns) {
node.setAttributeNS(ns, name, value);
}
else {
switch (name) {
case "value":
if (value !== node.value) {
node.value = value;
}
break;
case "initial_value":
node.defaultValue = value;
break;
case "checked":
node.checked = truthy(value);
break;
case "initial_checked":
node.defaultChecked = truthy(value);
break;
case "selected":
node.selected = truthy(value);
break;
case "initial_selected":
node.defaultSelected = truthy(value);
break;
case "dangerous_inner_html":
node.innerHTML = value;
break;
default:
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if (!truthy(value) && bool_attrs.hasOwnProperty(name)) {
node.removeAttribute(name);
}
else {
node.setAttribute(name, value);
}
}
}
}
const bool_attrs = {
allowfullscreen: true,
allowpaymentrequest: true,
async: true,
autofocus: true,
autoplay: true,
checked: true,
controls: true,
default: true,
defer: true,
disabled: true,
formnovalidate: true,
hidden: true,
ismap: true,
itemscope: true,
loop: true,
multiple: true,
muted: true,
nomodule: true,
novalidate: true,
open: true,
playsinline: true,
readonly: true,
required: true,
reversed: true,
selected: true,
truespeed: true,
webkitdirectory: true,
};
function truthy(val) {
return val === "true" || val === true;
}
+1
View File
@@ -0,0 +1 @@
// DO NOT EDIT THIS FILE. HASH: 3476900567878811119
Whitespace-only changes.
@@ -1,5 +1,7 @@
class InterpreterConfig {
constructor(intercept_link_redirects) {
intercept_link_redirects: boolean;
constructor(intercept_link_redirects: boolean) {
this.intercept_link_redirects = intercept_link_redirects;
}
}
@@ -21,6 +23,42 @@ async function handler(event, name, bubbles, config) {
let contents = await serialize_event(event);
if (
target.tagName === "FORM" &&
(event.type === "submit" || event.type === "input")
) {
const formData = new FormData(target);
for (let name of formData.keys()) {
const fieldType = target.elements[name].type;
switch (fieldType) {
case "select-multiple":
contents.values[name] = formData.getAll(name);
break;
// add cases for fieldTypes that can hold multiple values here
default:
contents.values[name] = formData.get(name);
break;
}
}
}
if (
target.tagName === "SELECT" &&
event.type === "input"
) {
const selectData = target.options;
contents.values["options"] = [];
for (let i = 0; i < selectData.length; i++) {
let option = selectData[i];
if (option.selected) {
contents.values["options"].push(option.value.toString());
}
}
}
// TODO: this should be liveview only
if (
target.tagName === "INPUT" &&
@@ -61,42 +99,6 @@ async function handler(event, name, bubbles, config) {
}
}
if (
target.tagName === "FORM" &&
(event.type === "submit" || event.type === "input")
) {
const formData = new FormData(target);
for (let name of formData.keys()) {
const fieldType = target.elements[name].type;
switch (fieldType) {
case "select-multiple":
contents.values[name] = formData.getAll(name);
break;
// add cases for fieldTypes that can hold multiple values here
default:
contents.values[name] = formData.get(name);
break;
}
}
}
if (
target.tagName === "SELECT" &&
event.type === "input"
) {
const selectData = target.options;
contents.values["options"] = [];
for (let i = 0; i < selectData.length; i++) {
let option = selectData[i];
if (option.selected) {
contents.values["options"].push(option.value.toString());
}
}
}
window.ipc.postMessage(
window.interpreter.serializeIpcMessage("user_event", {
name: name,
@@ -324,7 +326,7 @@ window.interpreter.setFocus = function (id, focus) {
return true;
}
function get_mouse_data(event) {
function get_mouse_data(event: MouseEvent) {
const {
altKey,
button,
@@ -447,7 +449,8 @@ async function serialize_event(event) {
case "dragover":
case "dragstart":
case "drop": {
let files = null;
let files = [];
if (event.dataTransfer && event.dataTransfer.files) {
files = ["a", "b", "c"];
// files = await serializeFileList(event.dataTransfer.files);
+3 -3
View File
@@ -2,8 +2,8 @@
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
pub static INTERPRETER_JS: &str = include_str!("./interpreter.js");
pub static COMMON_JS: &str = include_str!("./common.js");
pub static INTERPRETER_JS: &str = include_str!("./gen/interpreter.js");
pub static COMMON_JS: &str = include_str!("./gen/common.js");
#[cfg(feature = "sledgehammer")]
mod sledgehammer_bindings;
@@ -20,7 +20,7 @@ pub use write_native_mutations::*;
#[cfg(all(feature = "minimal_bindings", feature = "webonly"))]
pub mod minimal_bindings {
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
#[wasm_bindgen(module = "/src/common.js")]
#[wasm_bindgen(module = "/src/gen/common.js")]
extern "C" {
pub fn setAttributeInner(node: JsValue, name: &str, value: JsValue, ns: Option<&str>);
}