on-codemerge
Version:
A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product
42 lines (41 loc) • 1.43 kB
JavaScript
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */
var m = Object.defineProperty;
var p = (s, e, t) => e in s ? m(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
var r = (s, e, t) => p(s, typeof e != "symbol" ? e + "" : e, t);
class d {
constructor() {
r(this, "storageKey", "html-editor-templates");
}
getTemplates() {
const e = localStorage.getItem(this.storageKey);
return e ? JSON.parse(e) : [];
}
saveTemplate(e) {
const t = this.getTemplates(), a = {
id: crypto.randomUUID(),
name: e.name,
content: e.content,
createdAt: Date.now(),
updatedAt: Date.now()
};
return t.push(a), localStorage.setItem(this.storageKey, JSON.stringify(t)), a;
}
updateTemplate(e, t) {
const a = this.getTemplates(), o = a.findIndex((l) => l.id === e);
if (o === -1)
throw new Error("Template not found");
const n = {
...a[o],
...t,
updatedAt: Date.now()
};
return a[o] = n, localStorage.setItem(this.storageKey, JSON.stringify(a)), n;
}
deleteTemplate(e) {
const t = this.getTemplates().filter((a) => a.id !== e);
localStorage.setItem(this.storageKey, JSON.stringify(t));
}
}
export {
d as TemplateManager
};