mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 03:50:52 +00:00
* feat: rebuild plugin pages with host rendering and native settings * fix(plugins): contain host-view errors, isolate editing, and migrate fixtures * fix(plugins): migrate remaining permission fixture hosts
29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
export function mount(root, context, viewId, stateScope) {
|
|
const cleanup = [];
|
|
const draft = root.querySelector("#" + "draft");
|
|
const status = root.querySelector("#" + "status");
|
|
let busy = false;
|
|
async function save(clear) {
|
|
if (busy) return;
|
|
busy = true;
|
|
try {
|
|
const text = clear ? "" : draft.value;
|
|
await context.views.setState(viewId, stateScope, { version: 1, text });
|
|
if (clear) draft.value = "";
|
|
status.textContent = clear ? "Draft cleared." : "Draft saved in this plugin only.";
|
|
} catch { status.textContent = "Could not save this draft."; }
|
|
finally { busy = false; }
|
|
}
|
|
root.querySelector("#" + "save").addEventListener("click", () => { void save(false); });
|
|
root.querySelector("#" + "clear").addEventListener("click", () => { void save(true); });
|
|
context.views.getState(viewId, stateScope).then((state) => {
|
|
if (state?.version === 1 && typeof state.text === "string" && state.text.length <= 4096) draft.value = state.text;
|
|
status.textContent = "Ready. Use synthetic text for this example.";
|
|
draft.disabled = false;
|
|
root.querySelector("#" + "save").disabled = false;
|
|
root.querySelector("#" + "clear").disabled = false;
|
|
}).catch(() => { status.textContent = "Could not load this plugin draft."; });
|
|
|
|
return () => { for (const stop of cleanup) stop(); };
|
|
}
|