import * as sfw from 'sfw'; const { Div, Img } = sfw.element.native; import * as api from '../../api/index.js'; const css = await sfw.css(import.meta.url, './index.css') export default class Image extends sfw.element.Container { #container #image #menu #id constructor() { super ({ css }) this.body.append( this.#container = Div.new({ id: 'container', children: [ this.#image = Img.new({ onload: () => this.#container.classList.add('loaded'), }), Div.new({ id: 'loading' }), this.#menu = Div.new({ id: 'menu', children: [ Div.new({ id: 'delete', innerText: 'Delete', onclick: () => { api.images.remove(this.#id); this.parentNode.removeChild(this); } }), ] }) ], oncontextmenu: (e) => { this.#menu.classList.toggle('open'); e.preventDefault(); } }) ); } set id(id) { this.#id = id; this.#container.classList.remove('loaded'); this.#image.src = `/api/image/load/${id}`; } }