@penwin/discord-components-core 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ // The dialog listens to clicks only to close on its backdrop; Escape closes it natively.
1
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -10,16 +11,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
11
  import { consume } from '@lit/context';
11
12
  import { createPopper } from '@popperjs/core';
12
13
  import hljs from 'highlight.js';
13
- import { LitElement, html } from 'lit';
14
+ import { LitElement, html, isServer, nothing } from 'lit';
14
15
  import { customElement, property, state } from 'lit/decorators.js';
15
16
  import { classMap } from 'lit/directives/class-map.js';
16
17
  import { ifDefined } from 'lit/directives/if-defined.js';
17
18
  import { createRef, ref } from 'lit/directives/ref.js';
18
- import { when } from 'lit/directives/when.js';
19
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
19
20
  import { resetServerRenderedRoot } from '../_private/serverRenderedRoot.js';
20
21
  import '../discord-link/DiscordLink.js';
21
22
  import { messagesLightTheme } from '../discord-messages/DiscordMessages.js';
22
23
  import AttachmentDownloadButton, { AttachmentLanguageSearchSvg, AttachmentLanguageSearchXSvg, AttachmentLanguageSelectorSvg } from '../svgs/AttachmentDownloadButton.js';
24
+ import { TextFileCheckSvg, TextFileCloseSvg, TextFileCodeSvg, TextFileExpandSvg, TextFileMaximizeSvg, TextFileMoreSvg } from '../svgs/TextFilePreview.js';
23
25
  const getAllLanguages = () => {
24
26
  const languages = new Set();
25
27
  for (const language of hljs.listLanguages()) {
@@ -34,164 +36,475 @@ const getAllLanguages = () => {
34
36
  return [...languages].sort((a, b) => a.localeCompare(b));
35
37
  };
36
38
  const allLanguages = getAllLanguages();
39
+ /**
40
+ * Lines shown before "show more", when the size cannot be measured (server rendering).
41
+ */
42
+ const COLLAPSED_LINES = 6;
43
+ const SPAN_TOKEN = /<span[^>]*>|<\/span>|\n|[^\n<]+|</g;
44
+ /**
45
+ * Split highlight.js output into one HTML string per line. A token can span lines (a block comment,
46
+ * a template string), so the spans open at a line break are closed there and reopened on the next
47
+ * line, keeping every line valid on its own.
48
+ */
49
+ function splitHighlightedLines(highlighted) {
50
+ const lines = [];
51
+ const open = [];
52
+ let current = '';
53
+ for (const [token] of highlighted.matchAll(SPAN_TOKEN)) {
54
+ if (token === '\n') {
55
+ lines.push(current + '</span>'.repeat(open.length));
56
+ current = open.join('');
57
+ }
58
+ else if (token.startsWith('<span')) {
59
+ open.push(token);
60
+ current += token;
61
+ }
62
+ else if (token === '</span>') {
63
+ open.pop();
64
+ current += token;
65
+ }
66
+ else {
67
+ current += token;
68
+ }
69
+ }
70
+ lines.push(current);
71
+ return lines;
72
+ }
73
+ /**
74
+ * "HTML" for `html`, "TypeScript" for `ts`, the language itself when highlight.js does not know it.
75
+ */
76
+ function languageLabel(language) {
77
+ if (!language)
78
+ return 'Plain Text';
79
+ const name = hljs.getLanguage(language)?.name;
80
+ if (!name)
81
+ return language.toUpperCase();
82
+ // Some definitions cover several languages ("HTML, XML"): show the one that was asked for.
83
+ const parts = name.split(',').map((part) => part.trim());
84
+ return parts.find((part) => part.toLowerCase() === language.toLowerCase()) ?? parts[0];
85
+ }
86
+ /**
87
+ * `<dialog closedby="any">` closes on a backdrop click natively; elsewhere a pointer fallback does.
88
+ */
89
+ const supportsClosedBy = !isServer && 'closedBy' in HTMLDialogElement.prototype;
37
90
  let DiscordTextFileAttachmentPreviewer = class DiscordTextFileAttachmentPreviewer extends LitElement {
38
91
  constructor() {
39
- super();
92
+ super(...arguments);
93
+ /**
94
+ * Whether long lines wrap instead of scrolling sideways, as Discord does by default. Viewers can
95
+ * toggle it from the menu. Set `wrap-text="false"` to start with it off.
96
+ */
97
+ this.wrapText = true;
40
98
  this.lightTheme = false;
99
+ /**
100
+ * Whether the inline preview shows more lines.
101
+ */
102
+ this.expanded = false;
103
+ /**
104
+ * Whether the full view (a modal dialog) is open.
105
+ */
106
+ this.fullView = false;
107
+ /**
108
+ * The open popup, and the footer (inline or full view) that opened it.
109
+ */
110
+ this.popup = null;
41
111
  this.currentSearch = '';
42
- this.inputRef = createRef();
43
- this.languageSelectorContainer = createRef();
44
- this.languageSelectorButton = createRef();
45
- this.isLanguageSelectorVisible = false;
112
+ this.lines = [];
46
113
  this.popper = null;
47
- this.isFirstClickDispatch = true;
48
- this.handleClickOutside = this.handleClickOutside.bind(this);
114
+ /**
115
+ * The trigger pressed while its popup was open. Light dismiss may already have closed the popup by
116
+ * the time its click arrives, so the click must not open it again.
117
+ */
118
+ this.pressedOpenTrigger = null;
119
+ /**
120
+ * Whether the open popup was opened from the keyboard, which moves focus into it.
121
+ */
122
+ this.openedFromKeyboard = false;
123
+ /**
124
+ * Whether the pointer went down outside the full view, for the light-dismiss fallback.
125
+ */
126
+ this.pressedOutsideDialog = false;
127
+ this.dialogRef = createRef();
128
+ this.inlineBodyRef = createRef();
129
+ this.inputRef = createRef();
49
130
  }
50
131
  createRenderRoot() {
51
132
  resetServerRenderedRoot(this, true);
52
133
  return this;
53
134
  }
54
- handleSearchInput(event) {
55
- const typedEventTarget = event.target;
56
- this.currentSearch = typedEventTarget.value.toLowerCase();
57
- }
58
- clearSearch(event) {
59
- if (this.inputRef.value)
60
- this.inputRef.value.value = '';
61
- this.currentSearch = '';
62
- event.stopPropagation();
63
- }
64
- selectLanguage(language) {
65
- this.language = language;
66
- this.hideSelector();
67
- }
135
+ /**
136
+ * Open the language selector of the inline preview. Kept for the 4.x API.
137
+ */
68
138
  showSelector() {
69
- this.currentSearch = '';
70
- this.isLanguageSelectorVisible = true;
139
+ this.openPopup('language', 'inline');
71
140
  }
141
+ /**
142
+ * Close any open popup. Kept for the 4.x API.
143
+ */
72
144
  hideSelector() {
73
- this.isLanguageSelectorVisible = false;
74
- this.currentSearch = '';
75
- this.removeHandleClickOutside();
76
- }
77
- removeHandleClickOutside(destroyPopper = false) {
78
- if (this.popper && destroyPopper)
79
- this.popper.destroy();
80
- window.removeEventListener('click', this.handleClickOutside);
81
- this.isFirstClickDispatch = true;
145
+ this.closePopup();
82
146
  }
83
147
  disconnectedCallback() {
84
148
  super.disconnectedCallback();
85
- this.removeHandleClickOutside(true);
149
+ this.closePopup();
150
+ this.dialogRef.value?.close();
86
151
  }
87
- handleClickOutside(event) {
88
- if (this.isFirstClickDispatch) {
89
- this.isFirstClickDispatch = false;
90
- return;
152
+ willUpdate(changed) {
153
+ if (changed.has('content') || changed.has('language') || this.lines.length === 0) {
154
+ const language = this.language && hljs.getLanguage(this.language) ? this.language : 'plaintext';
155
+ const content = (this.content ?? '').replaceAll(/\r\n?/g, '\n').replace(/\n$/, '');
156
+ this.lines = splitHighlightedLines(hljs.highlight(content, { language }).value);
91
157
  }
92
- let target = event.target;
93
- const languageSelectorContainer = this.languageSelectorContainer.value;
94
- if (!languageSelectorContainer) {
95
- this.hideSelector();
96
- return;
158
+ if (changed.has('content') || changed.has('wrapText'))
159
+ this.overflowing = undefined;
160
+ }
161
+ updated(changed) {
162
+ super.updated(changed);
163
+ const body = this.inlineBodyRef.value;
164
+ if (body && this.overflowing === undefined && !this.expanded) {
165
+ this.overflowing = body.scrollHeight > body.clientHeight + 1;
97
166
  }
98
- while (target) {
99
- if (target === languageSelectorContainer) {
100
- return;
101
- }
102
- target = target.parentElement;
167
+ if (changed.has('fullView')) {
168
+ const dialog = this.dialogRef.value;
169
+ if (this.fullView && dialog && !dialog.open)
170
+ dialog.showModal();
103
171
  }
104
- this.hideSelector();
172
+ if (changed.has('popup'))
173
+ this.showPopup();
105
174
  }
106
- updated(changed) {
107
- if (!this.languageSelectorContainer.value || !this.languageSelectorButton.value)
108
- return;
109
- if (!changed.has('isLanguageSelectorVisible'))
110
- return;
111
- const oldisLanguageSelectorVisibleValue = changed.get('isLanguageSelectorVisible');
112
- if (oldisLanguageSelectorVisibleValue === true) {
113
- this.removeHandleClickOutside();
175
+ isPopupOpen(kind, place) {
176
+ return this.popup?.kind === kind && this.popup.place === place;
177
+ }
178
+ openPopup(kind, place, fromKeyboard = false) {
179
+ window.clearTimeout(this.wrapCloseTimeout);
180
+ this.popper?.destroy();
181
+ this.popper = null;
182
+ this.currentSearch = '';
183
+ this.openedFromKeyboard = fromKeyboard;
184
+ this.popup = { kind, place };
185
+ }
186
+ /**
187
+ * Close the open popup. Focus goes back to its trigger when it was inside the popup, without a
188
+ * focus ring after a pointer action.
189
+ */
190
+ closePopup(focusVisible = true) {
191
+ const elements = this.popupElements();
192
+ if (elements?.popup.contains(document.activeElement)) {
193
+ elements.anchor.focus({ preventScroll: true, focusVisible });
194
+ }
195
+ window.clearTimeout(this.wrapCloseTimeout);
196
+ this.popper?.destroy();
197
+ this.popper = null;
198
+ this.popup = null;
199
+ this.currentSearch = '';
200
+ }
201
+ popupElements() {
202
+ if (!this.popup)
203
+ return null;
204
+ const { kind, place } = this.popup;
205
+ const anchor = this.querySelector(`[data-popup-anchor="${place}-${kind}"]`);
206
+ const popup = this.querySelector(`[data-popup="${place}-${kind}"]`);
207
+ return anchor && popup ? { anchor, popup } : null;
208
+ }
209
+ showPopup() {
210
+ const elements = this.popupElements();
211
+ if (!elements)
114
212
  return;
213
+ const { anchor, popup } = elements;
214
+ // A popover sits in the top layer, above later messages and inside the full view's dialog.
215
+ // `source` keeps the trigger out of light dismiss, so clicking it toggles the popup.
216
+ if (typeof popup.showPopover === 'function') {
217
+ popup.showPopover({ source: anchor });
115
218
  }
116
- this.popper = createPopper(this.languageSelectorButton.value, this.languageSelectorContainer.value, {
117
- placement: 'left-start',
219
+ this.popper = createPopper(anchor, popup, {
220
+ placement: 'top-end',
118
221
  strategy: 'fixed',
119
222
  modifiers: [
120
- {
121
- name: 'offset',
122
- options: {
123
- offset: [0, 8]
124
- }
125
- }
223
+ { name: 'offset', options: { offset: [0, 8] } },
224
+ { name: 'flip', options: { fallbackPlacements: ['bottom-end', 'left-start'] } },
225
+ { name: 'preventOverflow', options: { padding: 8 } }
126
226
  ]
127
227
  });
128
- window.addEventListener('click', this.handleClickOutside);
228
+ if (this.popup?.kind === 'language')
229
+ this.inputRef.value?.focus({ preventScroll: true });
230
+ else if (this.openedFromKeyboard)
231
+ popup.querySelector('.tfp-menu-item')?.focus({ preventScroll: true });
129
232
  }
130
- render() {
131
- let filteredLanguages = 0;
132
- return html `
133
- <discord-code-block language=${this.language} code=${this.content}></discord-code-block>
134
- <div class="file-metadata">
135
- <span class="file-metadata-name">${this.name}</span>
136
- <span class="file-metadata-size"
137
- >${this.bytes}${when(this.bytesUnit, () => html ` ${this.bytesUnit}`, () => null)}
138
- </span>
139
- <button class="discord-button-download-attachment" tabindex="-1">
140
- <a
141
- class="discord-link-download-attachment"
142
- aria-label="Download"
143
- href="${ifDefined(this.href)}"
144
- rel="noreferrer noopener"
145
- target="_blank"
146
- role="button"
147
- tabindex="0"
148
- download
149
- >
150
- ${AttachmentDownloadButton()}
151
- </a>
152
- </button>
153
- <button class="discord-button-download-attachment" @click=${this.showSelector} ${ref(this.languageSelectorButton)}>
154
- ${AttachmentLanguageSelectorSvg()}
155
- </button>
156
-
157
- ${when(this.isLanguageSelectorVisible, () => html `
158
- <div class="language-selector" ${ref(this.languageSelectorContainer)}>
159
- <label class="language-selector-input-container">
160
- <input
161
- type="text"
162
- placeholder="Search language"
163
- class="language-selector-input"
164
- @input=${this.handleSearchInput}
165
- ${ref(this.inputRef)}
166
- />
167
- ${when(this.currentSearch.length > 0, () => html `<button class="cancel-search" @click=${this.clearSearch}>${AttachmentLanguageSearchXSvg()}</button>`, () => html `<button tabindex="-1" class="search-button">${AttachmentLanguageSearchSvg()}</button>`)}
168
- </label>
169
- <ul tabindex="-1">
170
- ${allLanguages.map((language) => {
233
+ handlePopupToggle(event) {
234
+ // Light dismiss or Escape closed it natively: drop it from the state too. A late event from a
235
+ // popup that was already replaced is ignored.
236
+ if (event.newState === 'closed' && event.target === this.popupElements()?.popup)
237
+ this.closePopup();
238
+ }
239
+ handleTriggerPointerDown(kind, place) {
240
+ this.pressedOpenTrigger = this.isPopupOpen(kind, place) ? `${place}-${kind}` : null;
241
+ }
242
+ handleTriggerClick(event, kind, place) {
243
+ const wasOpen = this.pressedOpenTrigger === `${place}-${kind}` || this.isPopupOpen(kind, place);
244
+ this.pressedOpenTrigger = null;
245
+ // A click with no pointer (`detail` 0) came from Enter or Space.
246
+ if (wasOpen)
247
+ this.closePopup(event.detail === 0);
248
+ else
249
+ this.openPopup(kind, place, event.detail === 0);
250
+ }
251
+ handleMenuTriggerKeydown(event, place) {
252
+ if (event.key !== 'ArrowDown')
253
+ return;
254
+ event.preventDefault();
255
+ if (this.isPopupOpen('menu', place))
256
+ this.popupElements()?.popup.querySelector('.tfp-menu-item')?.focus();
257
+ else
258
+ this.openPopup('menu', place, true);
259
+ }
260
+ handleMenuKeydown(event) {
261
+ const items = [...event.currentTarget.querySelectorAll('.tfp-menu-item')];
262
+ const current = items.indexOf(document.activeElement);
263
+ const last = items.length - 1;
264
+ let next;
265
+ switch (event.key) {
266
+ case 'ArrowDown':
267
+ next = current >= last ? 0 : current + 1;
268
+ break;
269
+ case 'ArrowUp':
270
+ next = current <= 0 ? last : current - 1;
271
+ break;
272
+ case 'Home':
273
+ next = 0;
274
+ break;
275
+ case 'End':
276
+ next = last;
277
+ break;
278
+ case 'Tab':
279
+ // Tab leaves the menu and closes it; focus moves on as usual.
280
+ this.popper?.destroy();
281
+ this.popper = null;
282
+ this.popup = null;
283
+ return;
284
+ default:
285
+ return;
286
+ }
287
+ event.preventDefault();
288
+ items[next]?.focus();
289
+ }
290
+ toggleExpanded() {
291
+ this.expanded = !this.expanded;
292
+ }
293
+ openFullView() {
294
+ this.closePopup();
295
+ this.fullView = true;
296
+ }
297
+ closeFullView() {
298
+ this.closePopup();
299
+ this.dialogRef.value?.close();
300
+ }
301
+ handleDialogClose() {
302
+ this.fullView = false;
303
+ this.closePopup();
304
+ }
305
+ isOutsideDialog(event) {
306
+ const dialog = this.dialogRef.value;
307
+ if (!dialog || event.target.closest('[popover]'))
308
+ return false;
309
+ const rect = dialog.getBoundingClientRect();
310
+ return event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom;
311
+ }
312
+ // Light-dismiss fallback where `closedby` is missing. It tests the pointer position, not the
313
+ // target, and needs both the press and the release outside, so a text selection that ends on the
314
+ // backdrop does not close the full view.
315
+ handleDialogPointerDown(event) {
316
+ if (supportsClosedBy)
317
+ return;
318
+ this.pressedOutsideDialog = this.isOutsideDialog(event);
319
+ }
320
+ handleDialogPointerUp(event) {
321
+ if (supportsClosedBy)
322
+ return;
323
+ if (this.pressedOutsideDialog && this.isOutsideDialog(event))
324
+ this.closeFullView();
325
+ this.pressedOutsideDialog = false;
326
+ }
327
+ toggleWrap(event) {
328
+ this.wrapText = !this.wrapText;
329
+ // Keep the menu up for a moment so the changed check mark is visible.
330
+ const focusVisible = event.detail === 0;
331
+ this.wrapCloseTimeout = window.setTimeout(() => this.closePopup(focusVisible), 300);
332
+ }
333
+ selectLanguage(event, language) {
334
+ this.language = language;
335
+ this.closePopup(event.detail === 0);
336
+ }
337
+ handleSearchInput(event) {
338
+ this.currentSearch = event.target.value.toLowerCase();
339
+ }
340
+ clearSearch(event) {
341
+ if (this.inputRef.value)
342
+ this.inputRef.value.value = '';
343
+ this.currentSearch = '';
344
+ event.stopPropagation();
345
+ }
346
+ renderLines() {
347
+ return html `<div class="tfp-code">
348
+ ${this.lines.map((line, index) => html `<span class="tfp-line-number" aria-hidden="true">${index + 1}</span
349
+ ><span class="tfp-line">${line ? unsafeHTML(line) : '​'}</span>`)}
350
+ </div>`;
351
+ }
352
+ renderHeader(place) {
353
+ return html `<div class="tfp-header">
354
+ <span class="tfp-language">${TextFileCodeSvg()}<span>${languageLabel(this.language)}</span></span>
355
+ ${place === 'full'
356
+ ? html `<button class="tfp-button" aria-label="Close" @click=${this.closeFullView}>${TextFileCloseSvg()}</button>`
357
+ : nothing}
358
+ </div>`;
359
+ }
360
+ renderLanguageSelector(place) {
361
+ let shown = 0;
362
+ return html `<div
363
+ class="language-selector"
364
+ popover="auto"
365
+ aria-label="Change language"
366
+ data-popup="${place}-language"
367
+ @toggle=${this.handlePopupToggle}
368
+ >
369
+ <label class="language-selector-input-container">
370
+ <input
371
+ type="text"
372
+ placeholder="Search language"
373
+ aria-label="Search language"
374
+ class="language-selector-input"
375
+ @input=${this.handleSearchInput}
376
+ ${ref(this.inputRef)}
377
+ />
378
+ ${this.currentSearch.length > 0
379
+ ? html `<button class="cancel-search" aria-label="Clear search" @click=${this.clearSearch}>
380
+ ${AttachmentLanguageSearchXSvg()}
381
+ </button>`
382
+ : html `<span class="search-button">${AttachmentLanguageSearchSvg()}</span>`}
383
+ </label>
384
+ <ul tabindex="-1">
385
+ ${allLanguages.map((language) => {
171
386
  if (this.currentSearch && !language.toLowerCase().includes(this.currentSearch))
172
387
  return null;
173
- filteredLanguages++;
388
+ shown++;
174
389
  return html `<li>
175
- <button
176
- class=${classMap({
177
- 'language-selector-item': true,
178
- selected: this.language === language
179
- })}
180
- tabindex="-1"
181
- @click=${() => this.selectLanguage(language)}
182
- >
183
- ${language}
184
- </button>
185
- </li>`;
390
+ <button
391
+ class=${classMap({ 'language-selector-item': true, selected: this.language === language })}
392
+ @click=${(event) => this.selectLanguage(event, language)}
393
+ >
394
+ ${language}
395
+ </button>
396
+ </li>`;
186
397
  })}
187
- </ul>
188
- ${when(filteredLanguages === 0, () => html `<div class="no-results">
189
- <h3>Nop!</h3>
190
- <p>Did you make a mistake when writing?</p>
191
- </div>`)}
192
- </div>
193
- `)}
398
+ </ul>
399
+ ${shown === 0
400
+ ? html `<div class="no-results">
401
+ <h3>Nope!</h3>
402
+ <p>Did you make a mistake when writing?</p>
403
+ </div>`
404
+ : nothing}
405
+ </div>`;
406
+ }
407
+ renderMenu(place) {
408
+ return html `<div
409
+ class="tfp-menu"
410
+ role="menu"
411
+ aria-label="More"
412
+ popover="auto"
413
+ data-popup="${place}-menu"
414
+ @toggle=${this.handlePopupToggle}
415
+ @keydown=${this.handleMenuKeydown}
416
+ >
417
+ <a
418
+ class="tfp-menu-item"
419
+ role="menuitem"
420
+ href=${ifDefined(this.href)}
421
+ target="_blank"
422
+ rel="noreferrer noopener"
423
+ download=${ifDefined(this.name)}
424
+ @click=${(event) => this.closePopup(event.detail === 0)}
425
+ >
426
+ <span>Download</span>${AttachmentDownloadButton()}
427
+ </a>
428
+ <button class="tfp-menu-item" role="menuitemcheckbox" aria-checked=${this.wrapText ? 'true' : 'false'} @click=${this.toggleWrap}>
429
+ <span>Wrap Text</span>
430
+ <span class=${classMap({ 'tfp-checkbox': true, checked: this.wrapText })}>${this.wrapText ? TextFileCheckSvg() : nothing}</span>
431
+ </button>
432
+ </div>`;
433
+ }
434
+ renderFooter(place) {
435
+ const canExpand = this.overflowing ?? this.lines.length > COLLAPSED_LINES;
436
+ const open = (kind) => this.popup?.kind === kind && this.popup.place === place;
437
+ return html `<div class="tfp-footer">
438
+ ${place === 'inline' && (canExpand || this.expanded)
439
+ ? html `<button
440
+ class=${classMap({ 'tfp-button': true, 'tfp-expand': true, expanded: this.expanded })}
441
+ aria-label=${this.expanded ? 'Show less' : 'Show more'}
442
+ aria-expanded=${this.expanded ? 'true' : 'false'}
443
+ @click=${this.toggleExpanded}
444
+ >
445
+ ${TextFileExpandSvg()}
446
+ </button>`
447
+ : nothing}
448
+ <span class="tfp-file">
449
+ <span class="tfp-file-name" title=${ifDefined(this.name)}>${this.name}</span>
450
+ <span class="tfp-file-size">${this.bytes}${this.bytesUnit ? ` ${this.bytesUnit}` : ''}</span>
451
+ </span>
452
+ <span class="tfp-actions">
453
+ <button
454
+ class=${classMap({ 'tfp-button': true, active: open('language') })}
455
+ aria-label="Change language"
456
+ aria-expanded=${open('language') ? 'true' : 'false'}
457
+ data-popup-anchor="${place}-language"
458
+ @pointerdown=${() => this.handleTriggerPointerDown('language', place)}
459
+ @click=${(event) => this.handleTriggerClick(event, 'language', place)}
460
+ >
461
+ ${AttachmentLanguageSelectorSvg()}
462
+ </button>
463
+ ${place === 'inline'
464
+ ? html `<button class="tfp-button" aria-label="Expand" @click=${this.openFullView}>${TextFileMaximizeSvg()}</button>`
465
+ : nothing}
466
+ <button
467
+ class=${classMap({ 'tfp-button': true, active: open('menu') })}
468
+ aria-label="More"
469
+ aria-haspopup="menu"
470
+ aria-expanded=${open('menu') ? 'true' : 'false'}
471
+ data-popup-anchor="${place}-menu"
472
+ @pointerdown=${() => this.handleTriggerPointerDown('menu', place)}
473
+ @click=${(event) => this.handleTriggerClick(event, 'menu', place)}
474
+ @keydown=${(event) => this.handleMenuTriggerKeydown(event, place)}
475
+ >
476
+ ${TextFileMoreSvg()}
477
+ </button>
478
+ </span>
479
+ ${open('language') ? this.renderLanguageSelector(place) : nothing} ${open('menu') ? this.renderMenu(place) : nothing}
480
+ </div>`;
481
+ }
482
+ render() {
483
+ return html `
484
+ <div class=${classMap({ 'tfp-card': true, 'tfp-wrap': this.wrapText })}>
485
+ ${this.renderHeader('inline')}
486
+ <div class=${classMap({ 'tfp-body': true, expanded: this.expanded })} tabindex="0" ${ref(this.inlineBodyRef)}>
487
+ ${this.renderLines()}
488
+ </div>
489
+ ${this.renderFooter('inline')}
194
490
  </div>
491
+ <dialog
492
+ class=${classMap({ 'tfp-dialog': true, 'tfp-wrap': this.wrapText })}
493
+ aria-label=${ifDefined(this.name)}
494
+ closedby="any"
495
+ ${ref(this.dialogRef)}
496
+ @close=${this.handleDialogClose}
497
+ @pointerdown=${this.handleDialogPointerDown}
498
+ @pointerup=${this.handleDialogPointerUp}
499
+ >
500
+ ${this.fullView
501
+ ? html `<div class="tfp-card tfp-card-full">
502
+ ${this.renderHeader('full')}
503
+ <div class="tfp-body" tabindex="0">${this.renderLines()}</div>
504
+ ${this.renderFooter('full')}
505
+ </div>`
506
+ : nothing}
507
+ </dialog>
195
508
  `;
196
509
  }
197
510
  };
@@ -219,11 +532,34 @@ __decorate([
219
532
  property(),
220
533
  __metadata("design:type", String)
221
534
  ], DiscordTextFileAttachmentPreviewer.prototype, "href", void 0);
535
+ __decorate([
536
+ property({
537
+ reflect: true,
538
+ attribute: 'wrap-text',
539
+ converter: {
540
+ fromAttribute: (value) => value !== 'false',
541
+ toAttribute: (value) => (value ? '' : 'false')
542
+ }
543
+ }),
544
+ __metadata("design:type", Object)
545
+ ], DiscordTextFileAttachmentPreviewer.prototype, "wrapText", void 0);
222
546
  __decorate([
223
547
  consume({ context: messagesLightTheme, subscribe: true }),
224
548
  property({ type: Boolean, reflect: true, attribute: 'light-theme' }),
225
549
  __metadata("design:type", Object)
226
550
  ], DiscordTextFileAttachmentPreviewer.prototype, "lightTheme", void 0);
551
+ __decorate([
552
+ state(),
553
+ __metadata("design:type", Object)
554
+ ], DiscordTextFileAttachmentPreviewer.prototype, "expanded", void 0);
555
+ __decorate([
556
+ state(),
557
+ __metadata("design:type", Object)
558
+ ], DiscordTextFileAttachmentPreviewer.prototype, "fullView", void 0);
559
+ __decorate([
560
+ state(),
561
+ __metadata("design:type", Object)
562
+ ], DiscordTextFileAttachmentPreviewer.prototype, "popup", void 0);
227
563
  __decorate([
228
564
  state(),
229
565
  __metadata("design:type", Object)
@@ -231,10 +567,9 @@ __decorate([
231
567
  __decorate([
232
568
  state(),
233
569
  __metadata("design:type", Object)
234
- ], DiscordTextFileAttachmentPreviewer.prototype, "isLanguageSelectorVisible", void 0);
570
+ ], DiscordTextFileAttachmentPreviewer.prototype, "overflowing", void 0);
235
571
  DiscordTextFileAttachmentPreviewer = __decorate([
236
- customElement('discord-text-file-attachment-previewer'),
237
- __metadata("design:paramtypes", [])
572
+ customElement('discord-text-file-attachment-previewer')
238
573
  ], DiscordTextFileAttachmentPreviewer);
239
574
  export { DiscordTextFileAttachmentPreviewer };
240
575
  //# sourceMappingURL=DiscordTextFileAttachmentPreviewer.js.map