2021-06-24 18:15:12 +08:00
|
|
|
defmodule LivebookWeb.Output.TextComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
|
|
|
<div id={"virtualized-text-#{@id}"}
|
2021-06-24 18:15:12 +08:00
|
|
|
class="relative"
|
|
|
|
phx-hook="VirtualizedLines"
|
|
|
|
data-max-height="300"
|
2021-07-07 20:32:49 +08:00
|
|
|
data-follow={to_string(@follow)}>
|
2021-06-30 23:48:27 +08:00
|
|
|
<%# Add a newline to each element, so that multiple lines can be copied properly %>
|
|
|
|
<div data-template class="hidden"
|
2021-07-07 20:32:49 +08:00
|
|
|
id={"virtualized-text-#{@id}-template"}
|
2022-01-17 03:37:00 +08:00
|
|
|
><%= for line <- ansi_string_to_html_lines(@content) do %><div data-line><%= [line, "\n"] %></div><% end %></div>
|
2021-06-24 18:15:12 +08:00
|
|
|
<div data-content class="overflow-auto whitespace-pre font-editor text-gray-500 tiny-scrollbar"
|
2021-07-07 20:32:49 +08:00
|
|
|
id={"virtualized-text-#{@id}-content"}
|
2021-06-24 18:15:12 +08:00
|
|
|
phx-update="ignore"></div>
|
2021-12-13 03:26:10 +08:00
|
|
|
<div class="absolute right-2 top-0 z-10">
|
2021-06-30 23:48:27 +08:00
|
|
|
<button class="icon-button bg-gray-100"
|
2021-11-11 03:17:32 +08:00
|
|
|
data-element="clipcopy"
|
|
|
|
phx-click={JS.dispatch("lb:clipcopy", to: "#virtualized-text-#{@id}-template")}>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="clipboard-line" class="text-lg" />
|
2021-06-24 18:15:12 +08:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|