aboutsummaryrefslogtreecommitdiff
path: root/src/runtime.ffi.mjs
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2023-11-30 23:31:33 +0000
committerHayleigh Thompson <me@hayleigh.dev>2023-11-30 23:31:33 +0000
commit6423cce9fab80619cca2c3bd215cec49ea06613a (patch)
treedf6be654b13f6dbf3fa618cb6379635b8a0b8d66 /src/runtime.ffi.mjs
parent2067b58c301d92c1ecbd5045fd1da2b89a9fe6d7 (diff)
downloadlustre-6423cce9fab80619cca2c3bd215cec49ea06613a.tar.gz
lustre-6423cce9fab80619cca2c3bd215cec49ea06613a.zip
:sparkles: Add undocumented ability to directly set an element's inner html.
Diffstat (limited to 'src/runtime.ffi.mjs')
-rw-r--r--src/runtime.ffi.mjs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime.ffi.mjs b/src/runtime.ffi.mjs
index 03e741a..45b05bf 100644
--- a/src/runtime.ffi.mjs
+++ b/src/runtime.ffi.mjs
@@ -42,11 +42,15 @@ function createElement(prev, curr, ns, dispatch, parent = null) {
el.$lustre = {};
let attr = curr[1];
+ let dangerousUnescapedHtml = "";
+
while (attr.head) {
if (attr.head[0] === "class") {
morphAttr(el, attr.head[0], `${el.className} ${attr.head[1]}`);
} else if (attr.head[0] === "style") {
morphAttr(el, attr.head[0], `${el.style.cssText} ${attr.head[1]}`);
+ } else if (attr.head[0] === "dangerous-unescaped-html") {
+ dangerousUnescapedHtml += attr.head[1];
} else {
morphAttr(el, attr.head[0], attr.head[1], dispatch);
}
@@ -73,6 +77,8 @@ function createElement(prev, curr, ns, dispatch, parent = null) {
el.appendChild(morph(null, child.head, dispatch, el));
child = child.tail;
}
+ } else if (dangerousUnescapedHtml) {
+ el.innerHTML = dangerousUnescapedHtml;
} else {
let child = curr[2];
while (child.head) {
@@ -106,6 +112,14 @@ function morphElement(prev, curr, ns, dispatch, parent) {
currAttr.head[0],
`${currAttrs.get("style")} ${currAttr.head[1]}`
);
+ } else if (
+ currAttr.head[0] === "dangerous-unescaped-html" &&
+ currAttrs.has("dangerous-unescaped-html")
+ ) {
+ currAttrs.set(
+ currAttr.head[0],
+ `${currAttrs.get("dangerous-unescaped-html")} ${currAttr.head[1]}`
+ );
} else {
currAttrs.set(currAttr.head[0], currAttr.head[1]);
}
@@ -159,6 +173,8 @@ function morphElement(prev, curr, ns, dispatch, parent) {
prev.appendChild(morph(null, currChild.head, dispatch, prev));
currChild = currChild.tail;
}
+ } else if (currAttrs.has("dangerous-unescaped-html")) {
+ prev.innerHTML = currAttrs.get("dangerous-unescaped-html");
} else {
let prevChild = prev.firstChild;
let currChild = curr[2];