import { t } from "../services/i18n.js"; import NoteContextAwareWidget from "./note_context_aware_widget.js"; import attributeService from "../services/attributes.js"; import server from "../services/server.js"; import type FNote from "../entities/fnote.js"; import type { EventData } from "../components/app_context.js"; import type { Icon } from "./icon_list.js"; import { Dropdown } from "bootstrap"; const TPL = /*html*/` `; interface IconToCountCache { iconClassToCountMap: Record; } export default class NoteIconWidget extends NoteContextAwareWidget { private dropdown!: bootstrap.Dropdown; private $icon!: JQuery; private $iconList!: JQuery; private $iconCategory!: JQuery; private $iconSearch!: JQuery; private iconToCountCache!: Promise | null; doRender() { this.$widget = $(TPL); this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']")[0]); this.$icon = this.$widget.find("button.note-icon"); this.$iconList = this.$widget.find(".icon-list"); this.$iconList.on("click", "span", async (e) => { const clazz = $(e.target).attr("class"); if (this.noteId && this.note) { await attributeService.setLabel(this.noteId, this.note.hasOwnedLabel("workspace") ? "workspaceIconClass" : "iconClass", clazz); } }); this.$iconCategory = this.$widget.find("select[name='icon-category']"); this.$iconCategory.on("change", () => this.renderDropdown()); this.$iconCategory.on("click", (e) => e.stopPropagation()); this.$iconSearch = this.$widget.find("input[name='icon-search']"); this.$iconSearch.on("input", () => this.renderDropdown()); this.$widget.on("show.bs.dropdown", async () => { const { categories } = (await import("./icon_list.js")).default; this.$iconCategory.empty(); for (const category of categories) { this.$iconCategory.append($("