bliss/bliss-cli/live-editor/template-editor.eta

26 lines
1.4 KiB
Text
Raw Normal View History

2026-08-03 01:24:54 -04:00
<div data-bliss-ui>
<div class="mb-2 flex items-center justify-between border-b-4 border-double border-black pb-2"><strong><%= it.sourceTemplate.name %></strong><span data-status class="text-xs"></span></div>
<div data-source class="h-[55vh] w-full border-2 border-black"><%= it.sourceTemplate.content %></div>
<button data-save type="button" class="mt-2 border-2 border-black bg-white px-3 py-2 font-bold shadow-[3px_3px_0_#000] active:translate-x-0.5 active:translate-y-0.5 active:shadow-none">Save Template</button>
</div>
<script>
(function () {
const box = document.currentScript.previousElementSibling;
if (!box) return;
const editor = ace.edit(box.querySelector("[data-source]"));
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/html");
box.querySelector("[data-save]").onclick = async () => {
const status = box.querySelector("[data-status]");
status.textContent = "Saving…";
const response = await fetch("/workshop/<%= it.sourceTemplate.structure_id %>/template/<%= it.sourceTemplate.id %>", {
method: "PUT", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content: editor.getValue() })
});
if (!response.ok) return void (status.textContent = "Save failed");
status.textContent = "Saved";
document.dispatchEvent(new CustomEvent("bliss:source-saved", { detail: { kind: "template", id: "<%= it.sourceTemplate.id %>" } }));
};
})();
</script>