{#if mode === "categories"}
{#if show_legend}
{#if _color_map}
{#each Object.entries(_color_map) as [category, color], i}
handle_mouseover(category)}
on:focus={() => handle_mouseover(category)}
on:mouseout={() => handle_mouseout()}
on:blur={() => handle_mouseout()}
class="category-label"
style={"background-color:" + color.secondary}
>
{category}
{/each}
{/if}
{/if}
{#each value as [text, category], i}
{#each splitTextByNewline(text) as line, j}
{#if line.trim() !== ""}
{
if (category !== null) {
handleSelect(i, text, category);
}
}}
on:keydown={(e) => {
if (category !== null) {
labelToEdit = i;
handleSelect(i, text, category);
} else {
handleKeydownSelection(e);
}
}}
on:focus={() => (activeElementIndex = i)}
on:mouseover={() => (activeElementIndex = i)}
>
handleKeydownSelection(e)}
on:focus={() => (activeElementIndex = i)}
on:mouseover={() => (activeElementIndex = i)}
on:click={() => (labelToEdit = i)}
tabindex="0">{line}
{#if !show_legend && category !== null && labelToEdit !== i}
(labelToEdit = i)}
on:keydown={() => (labelToEdit = i)}
>
{category}
{/if}
{#if labelToEdit === i && category !== null}
{/if}
{#if category !== null}
removeHighlightedText(i)}
on:keydown={(event) => {
if (event.key === "Enter") {
removeHighlightedText(i);
}
}}
>×
{/if}
{/if}
{#if j < splitTextByNewline(text).length - 1}
{/if}
{/each}
{/each}
{:else}
{#if show_legend}
-1
0
+1
{/if}
{#each value as [text, _score], i}
{@const score = typeof _score === "string" ? parseInt(_score) : _score}
(activeElementIndex = i)}
on:focus={() => (activeElementIndex = i)}
on:click={() => (labelToEdit = i)}
on:keydown={(e) => {
if (e.key === "Enter") {
labelToEdit = i;
}
}}
style={"background-color: rgba(" +
(score && score < 0
? "128, 90, 213," + -score
: "239, 68, 60," + score) +
")"}
>
{text}
{#if _score && labelToEdit === i}
{/if}
{#if _score && activeElementIndex === i}
removeHighlightedText(i)}
on:keydown={(event) => {
if (event.key === "Enter") {
removeHighlightedText(i);
}
}}
>×
{/if}
{/each}
{/if}