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
124 lines (123 loc) • 4.26 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 i = Object.defineProperty;
var c = (o, e, a) => e in o ? i(o, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[e] = a;
var n = (o, e, a) => c(o, typeof e != "symbol" ? e + "" : e, a);
class d {
constructor() {
n(this, "categoriesKey", "html-editor-calendar-categories");
n(this, "tagsKey", "html-editor-calendar-tags");
}
// Категории
getCategories() {
const e = localStorage.getItem(this.categoriesKey);
return e ? JSON.parse(e) : this.getDefaultCategories();
}
getCategory(e) {
return this.getCategories().find((t) => t.id === e) || null;
}
createCategory(e, a) {
const t = this.getCategories(), r = {
id: crypto.randomUUID(),
name: e,
color: a,
createdAt: Date.now()
};
return t.push(r), localStorage.setItem(this.categoriesKey, JSON.stringify(t)), r;
}
updateCategory(e, a) {
const t = this.getCategories(), r = t.findIndex((g) => g.id === e);
if (r === -1)
throw new Error("Category not found");
const s = {
...t[r],
...a
};
return t[r] = s, localStorage.setItem(this.categoriesKey, JSON.stringify(t)), s;
}
deleteCategory(e) {
const a = this.getCategories().filter((t) => t.id !== e);
localStorage.setItem(this.categoriesKey, JSON.stringify(a));
}
// Теги
getTags() {
const e = localStorage.getItem(this.tagsKey);
return e ? JSON.parse(e) : this.getDefaultTags();
}
getTag(e) {
return this.getTags().find((t) => t.id === e) || null;
}
createTag(e, a) {
const t = this.getTags(), r = {
id: crypto.randomUUID(),
name: e,
color: a,
createdAt: Date.now()
};
return t.push(r), localStorage.setItem(this.tagsKey, JSON.stringify(t)), r;
}
updateTag(e, a) {
const t = this.getTags(), r = t.findIndex((g) => g.id === e);
if (r === -1)
throw new Error("Tag not found");
const s = {
...t[r],
...a
};
return t[r] = s, localStorage.setItem(this.tagsKey, JSON.stringify(t)), s;
}
deleteTag(e) {
const a = this.getTags().filter((t) => t.id !== e);
localStorage.setItem(this.tagsKey, JSON.stringify(a));
}
// Утилиты
getCategoryByName(e) {
return this.getCategories().find((t) => t.name.toLowerCase() === e.toLowerCase()) || null;
}
getTagByName(e) {
return this.getTags().find((t) => t.name.toLowerCase() === e.toLowerCase()) || null;
}
getEventsByCategory(e, a) {
return a.filter((t) => t.category === e);
}
getEventsByTag(e, a) {
return a.filter((t) => {
var r;
return (r = t.tags) == null ? void 0 : r.includes(e);
});
}
// Статистика
getCategoryStats(e) {
const a = {};
return this.getCategories().forEach((r) => {
a[r.id] = this.getEventsByCategory(r.id, e).length;
}), a;
}
getTagStats(e) {
const a = {};
return this.getTags().forEach((r) => {
a[r.id] = this.getEventsByTag(r.name, e).length;
}), a;
}
// Предустановленные категории и теги
getDefaultCategories() {
return [
{ id: "work", name: "Work", color: "#3b82f6", createdAt: Date.now() },
{ id: "personal", name: "Personal", color: "#10b981", createdAt: Date.now() },
{ id: "meeting", name: "Meeting", color: "#f59e0b", createdAt: Date.now() },
{ id: "travel", name: "Travel", color: "#8b5cf6", createdAt: Date.now() },
{ id: "health", name: "Health", color: "#ef4444", createdAt: Date.now() }
];
}
getDefaultTags() {
return [
{ id: "urgent", name: "Urgent", color: "#ef4444", createdAt: Date.now() },
{ id: "important", name: "Important", color: "#f59e0b", createdAt: Date.now() },
{ id: "follow-up", name: "Follow-up", color: "#3b82f6", createdAt: Date.now() },
{ id: "completed", name: "Completed", color: "#10b981", createdAt: Date.now() },
{ id: "cancelled", name: "Cancelled", color: "#6b7280", createdAt: Date.now() }
];
}
}
export {
d as CategoryManager
};