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"""
|
2022-08-02 21:51:02 +08:00
|
|
|
<div
|
|
|
|
id={"virtualized-text-#{@id}"}
|
2021-06-24 18:15:12 +08:00
|
|
|
class="relative"
|
|
|
|
phx-hook="VirtualizedLines"
|
2022-08-02 21:51:02 +08:00
|
|
|
data-max-height="300"
|
|
|
|
>
|
|
|
|
<% # Add a newline to each element, so that multiple lines can be copied properly %>
|
2022-08-22 21:59:32 +08:00
|
|
|
<div data-template class="hidden" id={"virtualized-text-#{@id}-template"} phx-no-format><%= for line <- ansi_string_to_html_lines(@content) do %><div data-line><%= [
|
|
|
|
line,
|
|
|
|
"\n"
|
|
|
|
] %></div><% end %></div>
|
2022-08-02 21:51:02 +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"}
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-update="ignore"
|
2022-08-03 00:22:49 +08:00
|
|
|
phx-no-format
|
2022-10-04 14:46:55 +08:00
|
|
|
>
|
|
|
|
</div>
|
2021-12-13 03:26:10 +08:00
|
|
|
<div class="absolute right-2 top-0 z-10">
|
2022-08-02 21:51:02 +08:00
|
|
|
<button
|
|
|
|
class="icon-button bg-gray-100"
|
2022-04-04 18:19:11 +08:00
|
|
|
data-el-clipcopy
|
2022-08-02 21:51:02 +08:00
|
|
|
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
|