-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
556 additions
and
612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,036 changes: 434 additions & 602 deletions
1,036
src/lib/api/fixtures/documents/search-highlight.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!-- | ||
@component | ||
Highlights from annotations matching a search query, like this: | ||
```json | ||
"197010": { | ||
"title": [ | ||
"<em>Boston</em> police officer dies after medical emergency" | ||
], | ||
"description": [ | ||
"<em>Boston</em> police officer dies after medical emergency. [<a href=\"http://www.bostonglobe.com/metro/2014" | ||
] | ||
} | ||
``` | ||
Note that highlights may contain broken bits of HTML. Sanitize accordingly. | ||
--> | ||
|
||
<script lang="ts"> | ||
import type { Document } from "$lib/api/types"; | ||
import DOMPurify from "isomorphic-dompurify"; | ||
import { _ } from "svelte-i18n"; | ||
import { noteUrl } from "$lib/api/notes"; | ||
export let document: Document; | ||
export let open = false; | ||
$: note_highlights = document.note_highlights; | ||
$: count = Object.keys(note_highlights).length; | ||
$: notes = new Map(document.notes.map((n) => [n.id, n])); | ||
function sanitize(s: string): string { | ||
return DOMPurify.sanitize(s, { ALLOWED_TAGS: ["em"] }); | ||
} | ||
</script> | ||
|
||
{#if count > 0} | ||
<details bind:open> | ||
<summary>{$_("document.matchingNotes", { values: { n: count } })}</summary> | ||
|
||
{#each Object.entries(note_highlights) as [note_id, highlight]} | ||
{@const note = notes.get(note_id)} | ||
<blockquote> | ||
{#if highlight.title} | ||
<h4>{@html sanitize(highlight.title.join("\n").trim())}</h4> | ||
{/if} | ||
|
||
{#if highlight.description} | ||
{#each highlight.description as segment} | ||
<p class="segment">{@html sanitize(segment)}</p> | ||
{/each} | ||
{/if} | ||
<cite> | ||
<a href={noteUrl(document, note).toString()} | ||
>{$_("document.noteLink")}</a | ||
> | ||
</cite> | ||
</blockquote> | ||
{/each} | ||
</details> | ||
{/if} | ||
|
||
<style> | ||
h4 :global(em), | ||
.segment :global(em) { | ||
background-color: var(--yellow); | ||
font-style: normal; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/lib/components/documents/stories/NoteHighlights.stories.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script context="module" lang="ts"> | ||
import type { Document } from "$lib/api/types"; | ||
import { Story } from "@storybook/addon-svelte-csf"; | ||
import NoteHighlights from "../NoteHighlights.svelte"; | ||
import search from "$lib/api/fixtures/documents/search-highlight.json"; | ||
const document = search.results.find((d) => d.id === "1501881") as Document; | ||
export const meta = { | ||
title: "Components / Documents / Note Highlights", | ||
component: NoteHighlights, | ||
tags: ["autodocs"], | ||
parameters: { layout: "centered" }, | ||
}; | ||
</script> | ||
|
||
<Story name="closed"> | ||
<NoteHighlights {document} /> | ||
</Story> | ||
|
||
<Story name="open"> | ||
<NoteHighlights {document} open /> | ||
</Story> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters