import { API } from '../api.js'; import { LitElement, css, html, repeat } from '../vendor/lit-html/lit-all.min.js'; import './document-queue-entry-page.js'; import './document-queue-entry-separator.js'; /** @typedef {{selected: boolean}} DocumentQueueEntryEventChangeSelectionDetails */ /** @typedef {CustomEvent} DocumentQueueEntryEventChangeSelection */ export class DocumentQueueEntry extends LitElement { static properties = { selected: { type: Boolean }, queueEntry: { type: Object }, api: { type: Object, state: true }, }; constructor() { super(); this.selected = false; /** @type {API} */ this.api; /** @type {import('model').APIQueueEntry} */ this.queueEntry; } static styles = css` :host { padding: 8px; display: flex; flex-direction: row; gap: 8px; background-color: rgba(0, 0, 0, 0.1); border-radius: 8px; } #left-bar { position: relative; display: flex; flex-direction: column; justify-content: center; } #checkbox-selected { align-self: center; width: 24px; height: 24px; } #button-swap { width: 32px; height: 32px; padding: 0px; position: absolute; bottom: 0px; } `; // @ts-ignore render() { let embeddedElement; switch (this.queueEntry.type) { case "Page": embeddedElement = html``; break; case "Separator": embeddedElement = html``; break; default: embeddedElement = html`Unsupported entry type!` } return html`
${embeddedElement} `; } /** @param {Event} event */ onCheckboxChange(event) { // @ts-ignore this.selected = event.target.checked; /** @type {CustomEventInit} */ const eventData = { detail: { selected: this.selected } }; this.dispatchEvent(new CustomEvent("changeselection", eventData)); } /** * Used for FLIP animations. * @type {DOMRect} */ #oldBoundingClientRect; prepareFLIP() { this.#oldBoundingClientRect = this.getBoundingClientRect(); } doFLIP() { const oldRect = this.#oldBoundingClientRect; if (oldRect == undefined) { return; } const newRect = this.getBoundingClientRect(); const deltaX = oldRect.left - newRect.left; const deltaY = oldRect.top - newRect.top; if (Math.abs(deltaX) >= 1 || Math.abs(deltaY) >= 1) { this.animate([{ transform: `translate(${deltaX}px, ${deltaY}px)` }, { transform: 'none' }], { duration: 150, easing: 'ease-out', fill: 'both', }); } } } customElements.define("document-queue-entry", DocumentQueueEntry);