summaryrefslogtreecommitdiff
path: root/ui/lib/components/Message.svelte
blob: 04cbe5b5cfb5aec88d8bce3760c1c53e7ae86b96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<script>
  import { marked } from 'marked';
  import DOMPurify from 'dompurify';

  function scroll(message) {
    message.scrollIntoView();
  }

  let { at, body } = $props();
  let renderedBody = $derived(DOMPurify.sanitize(marked.parse(body, { breaks: true })));
</script>

<div class="message relative">
  <span class="timestamp chip variant-soft absolute top-0 right-0">{at}</span>
  <section use:scroll class="py-1 message-body">
    <!-- eslint-disable-next-line svelte/no-at-html-tags -->
    {@html renderedBody}
  </section>
</div>

<style>
  .message .timestamp {
    display: none;
  }
  .message:hover .timestamp {
    display: flex;
  }
  .message-body {
    overflow: auto;
    max-width: 80vw;
    @media (width > 640px) {
      /* 21rem is width of the nav bar in full-screen mode. */
      max-width: calc(90vw - 21rem);
    }
  }
  .message-body:empty:after {
    content: '.';
    visibility: hidden;
  }
  /* Without the global selector, the Svelte CSS compiler will see this as
   * unused, and purge it from the output. However, this is "plausibly used"
   * because it may occur in renderedBody.
   */
  :global(.message-body blockquote) {
    border-left: 0.25rem solid lightgrey;
    margin-left: 0.5rem;
    padding-left: 0.5rem;
  }
</style>