dioxus/packages/desktop/src/index.html

143 lines
4.4 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
2021-07-12 06:23:46 +00:00
<script>
class Interpreter {
constructor(root) {
this.stack = [root];
this.listeners = {};
this.lastNodeWasText = false;
this.nodes = [];
2021-07-12 06:23:46 +00:00
}
2021-07-12 06:23:46 +00:00
top() {
return this.stack[this.stack.length - 1];
}
2021-07-12 06:23:46 +00:00
pop() {
return this.stack.pop();
}
}
2021-07-12 06:23:46 +00:00
class OPTABLE {
PushRoot(self, edit) {
const id = edit.root;
const node = self.nodes[id];
self.stack.push(node);
}
AppendChildren(self, edit) {
let root = self.stack[self.stack.length - (edit.many + 1)];
for (let i = 0; i < edit.many; i++) {
console.log("popping ", i, edit.many);
let node = self.pop();
root.appendChild(node);
}
}
ReplaceWith(self, edit) {
2021-07-08 16:01:31 +00:00
2021-07-12 06:23:46 +00:00
let root = self.stack[self.stack.length - (edit.many + 1)];
let els = [];
for (let i = 0; i < edit.many; i++) {
els.push(self.pop());
}
2021-07-12 06:23:46 +00:00
root.replaceWith(...els);
}
2021-07-12 06:23:46 +00:00
Remove(self, edit) {
const node = self.stack.pop();
node.remove();
}
2021-07-21 21:05:48 +00:00
RemoveAllChildren(self, edit) {}
2021-07-12 06:23:46 +00:00
CreateTextNode(self, edit) {
self.stack.push(document.createTextNode(edit.text));
}
CreateElement(self, edit) {
const tagName = edit.tag;
console.log(`creating element: `, edit);
self.stack.push(document.createElement(tagName));
}
CreateElementNs(self, edit) {
2021-07-21 21:05:48 +00:00
const tagName = edit.tag;
console.log(`creating namespaced element: `, edit);
2021-07-12 06:23:46 +00:00
self.stack.push(document.createElementNS(edit.ns, edit.tag));
}
CreatePlaceholder(self, edit) {
const a = `self.stack.push(document.createElement("pre"))`;
self.stack.push(document.createComment("vroot"));
}
2021-07-21 21:05:48 +00:00
NewEventListener(self, edit) {}
RemoveEventListener(self, edit) {}
2021-07-12 06:23:46 +00:00
SetText(self, edit) {
self.top().textContent = edit.text;
}
SetAttribute(self, edit) {
const name = edit.field;
const value = edit.value;
2021-07-21 21:05:48 +00:00
const ns = edit.ns;
2021-07-12 06:23:46 +00:00
const node = self.top(self.stack);
2021-07-21 21:05:48 +00:00
if (ns == "style") {
node.style[name] = value;
} else if (ns !== undefined) {
node.setAttributeNS(ns, name, value);
} else {
node.setAttribute(name, value);
}
2021-07-12 06:23:46 +00:00
if ((name === "value", self)) {
node.value = value;
}
if ((name === "checked", self)) {
node.checked = true;
}
if ((name === "selected", self)) {
node.selected = true;
}
}
RemoveAttribute(self, edit) {
const name = edit.field;
const node = self.top(self.stack);
2021-07-21 21:05:48 +00:00
2021-07-12 06:23:46 +00:00
node.removeAttribute(name);
if ((name === "value", self)) {
node.value = null;
}
if ((name === "checked", self)) {
node.checked = false;
}
if ((name === "selected", self)) {
node.selected = false;
}
}
}
const op_table = new OPTABLE();
async function initialize() {
const reply = await rpc.call('initiate');
2021-07-15 16:18:11 +00:00
const interpreter = new Interpreter(window.document.getElementById("_dioxusroot"));
2021-07-12 06:23:46 +00:00
console.log(reply);
for (let x = 0; x < reply.length; x++) {
let edit = reply[x];
console.log(edit);
op_table[edit.type](interpreter, edit);
}
2021-07-12 06:23:46 +00:00
console.log("stack completed: ", interpreter.stack);
}
2021-07-12 06:23:46 +00:00
console.log("initializing...");
initialize();
</script>
</head>
<body>
2021-07-12 13:40:13 +00:00
<div id="_dioxusroot">
2021-07-12 06:23:46 +00:00
</div>
</body>
</html>