Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 1 | import {css, html, LitElement} from 'lit'; |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 2 | import {customElement} from 'lit/decorators.js'; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 3 | import {map} from 'lit/directives/map.js'; |
| 4 | import {unsafeHTML} from 'lit/directives/unsafe-html.js'; |
| 5 | |
Adrià Vilanova Martínez | 5bdc473 | 2022-05-31 20:12:21 +0200 | [diff] [blame] | 6 | import {msg} from '../../../common/i18n'; |
Adrià Vilanova Martínez | 5bdc473 | 2022-05-31 20:12:21 +0200 | [diff] [blame] | 7 | import {DIALOG_STYLES} from '../../shared/dialog-styles'; |
| 8 | import {SHARED_STYLES} from '../../shared/shared-styles'; |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 9 | import {credits, i18nCredits} from '../../tsCredits'; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 10 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 11 | @customElement('credits-dialog') |
| 12 | export default class CreditsDialog extends LitElement { |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 13 | static get styles() { |
| 14 | return [ |
| 15 | SHARED_STYLES, |
| 16 | DIALOG_STYLES, |
| 17 | css` |
| 18 | dialog { |
| 19 | max-height: 430px; |
| 20 | width: 400px; |
| 21 | } |
| 22 | |
| 23 | dialog[open] { |
| 24 | display: flex; |
| 25 | flex-direction: column; |
| 26 | } |
| 27 | |
| 28 | .content_area h4 { |
| 29 | margin-bottom: 0; |
| 30 | } |
| 31 | |
| 32 | .entry { |
| 33 | position: relative; |
| 34 | } |
| 35 | |
| 36 | .entry a.homepage { |
| 37 | position: absolute; |
| 38 | inset-inline-end: 16px; |
| 39 | font-size: 14px; |
| 40 | } |
| 41 | |
| 42 | p, |
| 43 | span { |
| 44 | font-size: 14px; |
| 45 | } |
| 46 | |
| 47 | p.author { |
| 48 | margin-top: 7px; |
| 49 | } |
| 50 | |
| 51 | #translators .name { |
| 52 | font-weight: bold; |
| 53 | } |
| 54 | |
| 55 | .createdby { |
| 56 | font-style: italic; |
| 57 | } |
| 58 | `, |
| 59 | ]; |
| 60 | } |
| 61 | |
| 62 | constructor() { |
| 63 | super(); |
| 64 | this.addEventListener('show-credits-dialog', this.showDialog); |
| 65 | } |
| 66 | |
| 67 | render() { |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 68 | const translators = map(i18nCredits, (contributor) => { |
| 69 | const languagesArray = |
| 70 | contributor?.languages?.map?.((lang) => lang?.name ?? 'undefined'); |
| 71 | const languages = |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 72 | languagesArray.length > 0 ? ': ' + languagesArray.join(', ') : ''; |
| 73 | return html` |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 74 | <li><span class="name">${contributor?.name}</span>${languages}</li> |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 75 | `; |
| 76 | }); |
| 77 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 78 | const homepageMsg = msg('options_credits_homepage'); |
| 79 | const creditsByMsg = msg('options_credits_by'); |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 80 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 81 | const otherCredits = map(credits, (c) => { |
| 82 | const url = c.url ? |
| 83 | html` <a href=${c?.url} target="_blank" class="homepage"> |
| 84 | ${homepageMsg} |
| 85 | </a>` : |
| 86 | undefined; |
| 87 | const license = c.license ? ' - ' + c.license : ''; |
| 88 | const author = c.author ? |
| 89 | html` <p class="author">${creditsByMsg} ${c.author}${license}</p> ` : |
| 90 | undefined; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 91 | |
| 92 | return html` |
| 93 | <div class="entry"> |
| 94 | ${url} |
| 95 | <h4>${c?.name}</h4> |
| 96 | ${author} |
| 97 | </div> |
| 98 | `; |
| 99 | }); |
| 100 | |
| 101 | return html` |
| 102 | <dialog> |
| 103 | <div class="scrollable"> |
| 104 | <h3>${msg('options_credits')}</h3> |
| 105 | <div class="entry createdby"> |
| 106 | <div>${unsafeHTML(msg('options_credits_createdby'))}</div> |
| 107 | </div> |
| 108 | <div class="entry"> |
| 109 | <a href="https://gtranslate.avm99963.com/" class="homepage" target="_blank"> |
| 110 | ${msg('options_credits_homepage')} |
| 111 | </a> |
| 112 | <h4>${msg('options_credits_translations')}</h4> |
| 113 | <div>${msg('options_credits_translations_paragraph')}</div> |
| 114 | <ul id="translators"> |
| 115 | ${translators} |
| 116 | </ul> |
| 117 | </div> |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 118 | <div class="content_area">${otherCredits}</div> |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 119 | </div> |
| 120 | <div class="action_buttons"> |
| 121 | <button id="credits_ok" @click="${this.closeDialog}"> |
| 122 | ${msg('options_ok')} |
| 123 | </button> |
| 124 | </div> |
| 125 | </dialog> |
| 126 | `; |
| 127 | } |
| 128 | |
| 129 | showDialog() { |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 130 | const dialog = this.renderRoot.querySelector('dialog'); |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 131 | dialog.showModal(); |
| 132 | dialog.querySelector('.scrollable').scrollTo(0, 0); |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 133 | (dialog.querySelector('#credits_ok') as HTMLElement).focus(); |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | closeDialog() { |
| 137 | this.renderRoot.querySelector('dialog').close(); |
| 138 | } |
| 139 | } |