1
0
mirror of https://codeberg.org/setop/elm-scripting synced 2025-11-08 21:49:57 +00:00

Compare commits

2 Commits

Author SHA1 Message Date
5916566385 feat: can pass content as flags 2025-10-15 13:44:19 +02:00
0758e1e9b4 feat: handle innerHTML 2025-10-07 22:19:07 +02:00

42
dom.js
View File

@@ -14,7 +14,7 @@ function Node(parent, tag) {
this.replaceChild = (newNode, domNode) => { this.replaceChild = (newNode, domNode) => {
this.children[domNode.pos-1] = newNode; this.children[domNode.pos-1] = newNode;
newNode.pos = domNode.pos; newNode.pos = domNode.pos;
}; };
if (parent != null) { if (parent != null) {
this.pos = parent.children.push(this); this.pos = parent.children.push(this);
} }
@@ -24,17 +24,17 @@ function Node(parent, tag) {
this.replaceData = (offset, count, data) => { this.replaceData = (offset, count, data) => {
this.text = data; // elm runtime will always replace the whole text this.text = data; // elm runtime will always replace the whole text
} }
this.dump = (d=0) => { this.dump = (d=0) => {
if (this.text != null) { if (this.text != null) {
print(this.text); print(this.text);
return return
} }
if (this.innerHTML) { if (this.innerHTML) {
print(this.innerHTML); print(this.innerHTML);
return return
} }
std.printf("<%s", this.tagName) std.printf("<%s", this.tagName)
// Set.difference(other) is not avalable in qjs // Set.difference(other) is not avalable in qjs
for (a of Object.keys(this)) { for (a of Object.keys(this)) {
if (!NodeKeys.has(a)) { if (!NodeKeys.has(a)) {
std.printf(' %s="%s"', a, this[a]) std.printf(' %s="%s"', a, this[a])
@@ -43,18 +43,18 @@ function Node(parent, tag) {
if (this.children.length==0) { if (this.children.length==0) {
print("/>") print("/>")
} else { } else {
print(">") print(">")
for (c of this.children) { for (c of this.children) {
c.dump(d+1) c.dump(d+1)
} }
print("</"+this.tagName+">"); print("</"+this.tagName+">");
} }
} }
return this; return this;
} }
var document = new Node(null, "document"); const document = new Node(null, "document");
var target = new Node(document, "target"); const target = new Node(document, "target");
const NodeKeys = new Set(Object.keys(target)); const NodeKeys = new Set(Object.keys(target));
// getElementById is only used once, to get node Elm must hook into. // getElementById is only used once, to get node Elm must hook into.
@@ -67,6 +67,6 @@ document.createTextNode = (text) => { t = new Node(null, "#text" ); t.text = tex
// workaround for elm-explorations/markdown Markdown.toHtml // workaround for elm-explorations/markdown Markdown.toHtml
global = {}; const global = {};