import prettyBytes from 'pretty-bytes'; import { LitElement, html, css, unsafeCSS } from 'lit-element'; import "keyword-mark-element/lib/keyword-mark.js"; import { getReplayLink } from './pageutils'; import { wrapCss } from './misc'; // =========================================================================== class PageEntry extends LitElement { constructor() { super(); this.query = ""; this.textSnippet = ""; this.page = null; this.replayPrefix = ""; this.deleting = false; this.editable = false; this.iconValid = false; this.index = 0; this.isCurrent = false; this.isSidebar = false; } static get properties() { return { query: { type: String }, textSnippet: { type: String }, page: { type: Object }, replayPrefix: { type: String }, deleting: { type: Boolean }, selected: { type: Boolean }, editable: { type: Boolean }, iconValid: { type: Boolean }, index: { type: Number }, isCurrent: { type: Boolean }, isSidebar: { type: Boolean }, } } static get styles() { return wrapCss(css` :host { min-height: min-content; width: 100%; word-break: break-all; position: relative; display: flex; flex-direction: row; background: transparent; } :host(.sidebar) .column { width: unset !important; } :host(.sidebar) { width: 100%; } .check-select { padding: 0 1.0em 0 0.5em; height: 100%; margin: auto 0 auto 0; } .columns { width: 100%; } /* Overrde Bulma to add the tiniest margin, so the focus indicator isn't obscured */ .columns { margin-top: calc(-0.75rem + 2px); } .columns:last-child { margin-bottom: calc(-0.75rem + 2px); } .favicon { width: 24px !important; height: 24px !important; display: inline-block; vertical-align: text-bottom; } img.favicon { filter: drop-shadow(1px 1px 2px grey); } .media-left { align-self: center; } .delete { position: absolute; top: 8px; right: 8px; } .delete:hover { background-color: rgb(241, 70, 104); } .is-loading { line-height: 1.5em; height: 1.5em; border: 0px; background-color: transparent !important; width: auto; } @media screen and (max-width: 768px) { ${PageEntry.sidebarStyles()} } ${PageEntry.sidebarStyles(unsafeCSS`:host(.sidebar)`)} .current a { background-color: rgb(207, 243, 255); font-style: italic; display: block; } .current .curr-page { font-style: italic; font-size: 9px; color: black; } .is-inline-date { display: none; } .media-content a { display: block; } `); } static sidebarStyles(prefix = css``) { return css` ${prefix} .col-date { margin-left: calc(24px + 1rem); display: none; } ${prefix} .col-date div { display: inline; } ${prefix} .col-index { position: absolute; top: 0px; left: 0px; margin-top: -0.75em; } ${prefix} .columns { display: flex; flex-direction: column-reverse; } ${prefix} .is-inline-date { display: initial !important; font-style: italic; } `; } updated(changedProperties) { if (changedProperties.has("page") || changedProperties.has("query")) { this.updateSnippet(); this.iconValid = !!this.page.favIconUrl; //this.updateFavIcon(); this.deleting = false; } } render() { const p = this.page; const date = this.page.date; const hasSize = typeof(p.size) === "number"; const editable = this.editable && !this.isSidebar; return html` ${editable ? html`
${this.iconValid ? html`
this.iconValid = false}" src="${this.replayPrefix}/${this.page.timestamp}id_/${p.favIconUrl}"/>` : html`
`}
${date ? date.toLocaleString(): ""}
${this.textSnippet ? html`