Complete redo of content indexing and querying (#517)
Complete redo of data store Introduces live queries and live templates
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
export const panelHtml = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<base target="_top">
|
||||
<script>
|
||||
const pendingRequests = new Map();
|
||||
let syscallReqId = 0;
|
||||
|
||||
self.syscall = async (name, ...args) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
syscallReqId++;
|
||||
pendingRequests.set(syscallReqId, { resolve, reject });
|
||||
window.parent.postMessage({
|
||||
type: "syscall",
|
||||
id: syscallReqId,
|
||||
name,
|
||||
args,
|
||||
}, "*");
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("message", (message) => {
|
||||
const data = message.data;
|
||||
switch (data.type) {
|
||||
case "html":
|
||||
document.body.innerHTML = data.html;
|
||||
if(data.theme) {
|
||||
document.getElementsByTagName("html")[0].setAttribute("data-theme", data.theme);
|
||||
}
|
||||
if (data.script) {
|
||||
try {
|
||||
eval(data.script);
|
||||
} catch (e) {
|
||||
console.error("Error evaling script", e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "syscall-response":
|
||||
{
|
||||
const syscallId = data.id;
|
||||
const lookup = pendingRequests.get(syscallId);
|
||||
if (!lookup) {
|
||||
console.log(
|
||||
"Current outstanding requests",
|
||||
pendingRequests,
|
||||
"looking up",
|
||||
syscallId,
|
||||
);
|
||||
throw Error("Invalid request id");
|
||||
}
|
||||
pendingRequests.delete(syscallId);
|
||||
if (data.error) {
|
||||
lookup.reject(new Error(data.error));
|
||||
} else {
|
||||
lookup.resolve(data.result);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
function api(obj) {
|
||||
window.parent.postMessage(obj, "*");
|
||||
}
|
||||
|
||||
let oldHeight = undefined;
|
||||
let heightChecks = 0;
|
||||
function updateHeight() {
|
||||
const body = document.body, html = document.documentElement;
|
||||
let height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
||||
heightChecks++;
|
||||
if(height !== oldHeight) {
|
||||
oldHeight = height;
|
||||
api({
|
||||
type: "setHeight",
|
||||
height: height,
|
||||
});
|
||||
}
|
||||
if(heightChecks < 25) {
|
||||
setTimeout(updateHeight, 100);
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
updateHeight();
|
||||
});
|
||||
|
||||
function loadJsByUrl(url) {
|
||||
const script = document.createElement("script");
|
||||
script.src = url;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
script.onload = resolve;
|
||||
document.documentElement.firstChild.appendChild(script);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>`;
|
||||
Reference in New Issue
Block a user