2021-04-02 20:00:49 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.SectionComponent do
|
2021-03-04 05:56:28 +08:00
|
|
|
use LivebookWeb, :live_component
|
2021-02-11 23:35:32 +08:00
|
|
|
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2022-04-04 18:19:11 +08:00
|
|
|
<section data-el-section data-section-id={@section_view.id}>
|
2022-08-02 21:51:02 +08:00
|
|
|
<div
|
|
|
|
class="flex space-x-4 items-center"
|
2022-04-04 18:19:11 +08:00
|
|
|
data-el-section-headline
|
2021-11-17 04:57:10 +08:00
|
|
|
id={@section_view.id}
|
|
|
|
data-focusable-id={@section_view.id}
|
|
|
|
phx-hook="Headline"
|
|
|
|
data-on-value-change="set_section_name"
|
2022-08-02 21:51:02 +08:00
|
|
|
data-metadata={@section_view.id}
|
|
|
|
>
|
|
|
|
<h2
|
|
|
|
class="grow text-gray-800 font-semibold text-2xl px-1 -ml-1 rounded-lg border border-transparent whitespace-pre-wrap cursor-text"
|
2021-11-17 04:57:10 +08:00
|
|
|
tabindex="0"
|
2021-07-07 20:32:49 +08:00
|
|
|
id={@section_view.html_id}
|
2022-04-04 18:19:11 +08:00
|
|
|
data-el-heading
|
2022-08-02 21:51:02 +08:00
|
|
|
spellcheck="false"
|
|
|
|
phx-no-format
|
|
|
|
><%= @section_view.name %></h2>
|
|
|
|
<div
|
|
|
|
class="flex space-x-2 items-center"
|
|
|
|
data-el-section-actions
|
2021-11-17 04:57:10 +08:00
|
|
|
role="toolbar"
|
2022-08-02 21:51:02 +08:00
|
|
|
aria-label="section actions"
|
|
|
|
>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip top" data-tooltip="Link">
|
|
|
|
<a href={"##{@section_view.html_id}"} class="icon-button" aria-label="link to section">
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="link" class="text-xl" />
|
2021-04-26 21:24:43 +08:00
|
|
|
</a>
|
|
|
|
</span>
|
2023-02-23 02:34:54 +08:00
|
|
|
<.menu
|
|
|
|
:if={@section_view.valid_parents != [] and not @section_view.has_children?}
|
|
|
|
id={"section-#{@section_view.id}-branch-menu"}
|
|
|
|
>
|
|
|
|
<:toggle>
|
|
|
|
<span class="tooltip top" data-tooltip="Branch out from">
|
|
|
|
<button class="icon-button" aria-label="branch out from other section">
|
|
|
|
<.remix_icon icon="git-branch-line" class="text-xl flip-horizontally" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</:toggle>
|
|
|
|
<:content>
|
|
|
|
<%= for parent <- @section_view.valid_parents do %>
|
|
|
|
<%= if @section_view.parent && @section_view.parent.id == parent.id do %>
|
|
|
|
<button
|
|
|
|
class="menu-item text-gray-900"
|
|
|
|
phx-click="unset_section_parent"
|
|
|
|
phx-value-section_id={@section_view.id}
|
|
|
|
>
|
|
|
|
<.remix_icon icon="arrow-right-s-line" />
|
|
|
|
<span class="font-medium"><%= parent.name %></span>
|
|
|
|
</button>
|
|
|
|
<% else %>
|
|
|
|
<button
|
|
|
|
class="menu-item text-gray-500"
|
|
|
|
phx-click="set_section_parent"
|
|
|
|
phx-value-section_id={@section_view.id}
|
|
|
|
phx-value-parent_id={parent.id}
|
|
|
|
>
|
|
|
|
<.remix_icon
|
|
|
|
:if={@section_view.parent && @section_view.parent.id}
|
|
|
|
icon="arrow-right-s-line"
|
|
|
|
class="invisible"
|
|
|
|
/>
|
|
|
|
<span class="font-medium"><%= parent.name %></span>
|
2021-11-11 02:28:09 +08:00
|
|
|
</button>
|
2021-07-16 00:19:36 +08:00
|
|
|
<% end %>
|
2023-02-23 02:34:54 +08:00
|
|
|
<% end %>
|
|
|
|
</:content>
|
|
|
|
</.menu>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip top" data-tooltip="Move up">
|
2022-08-02 21:51:02 +08:00
|
|
|
<button
|
|
|
|
class="icon-button"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="move section up"
|
2021-04-20 18:12:29 +08:00
|
|
|
phx-click="move_section"
|
2021-07-07 20:32:49 +08:00
|
|
|
phx-value-section_id={@section_view.id}
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-value-offset="-1"
|
|
|
|
>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="arrow-up-s-line" class="text-xl" />
|
2021-04-20 18:12:29 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip top" data-tooltip="Move down">
|
2022-08-02 21:51:02 +08:00
|
|
|
<button
|
|
|
|
class="icon-button"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="move section down"
|
2021-04-20 18:12:29 +08:00
|
|
|
phx-click="move_section"
|
2021-07-07 20:32:49 +08:00
|
|
|
phx-value-section_id={@section_view.id}
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-value-offset="1"
|
|
|
|
>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="arrow-down-s-line" class="text-xl" />
|
2021-04-20 18:12:29 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
2022-08-02 21:51:02 +08:00
|
|
|
<span {if @section_view.has_children?,
|
2021-11-17 04:57:10 +08:00
|
|
|
do: [class: "tooltip left", data_tooltip: "Cannot delete this section because\nother sections branch from it"],
|
|
|
|
else: [class: "tooltip top", data_tooltip: "Delete"]}>
|
2022-08-02 21:51:02 +08:00
|
|
|
<button
|
2023-02-23 02:34:54 +08:00
|
|
|
class={["icon-button", @section_view.has_children? && "disabled"]}
|
2021-12-28 01:42:27 +08:00
|
|
|
aria-label="delete section"
|
|
|
|
phx-click="delete_section"
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-value-section_id={@section_view.id}
|
|
|
|
>
|
2021-10-21 00:10:11 +08:00
|
|
|
<.remix_icon icon="delete-bin-6-line" class="text-xl" />
|
2021-12-28 01:42:27 +08:00
|
|
|
</button>
|
2021-10-21 00:10:11 +08:00
|
|
|
</span>
|
2021-02-11 23:35:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-23 02:34:54 +08:00
|
|
|
<h3
|
|
|
|
:if={@section_view.parent}
|
|
|
|
class="mt-1 flex items-end space-x-1 text-sm font-semibold text-gray-800"
|
|
|
|
data-el-section-subheadline
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
class="tooltip bottom"
|
|
|
|
data-tooltip="This section branches out from the main flow
|
2022-08-02 21:51:02 +08:00
|
|
|
and can be evaluated in parallel"
|
2023-02-23 02:34:54 +08:00
|
|
|
>
|
|
|
|
<.remix_icon
|
|
|
|
icon="git-branch-line"
|
|
|
|
class="text-lg font-normal flip-horizontally leading-none"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span class="leading-none">from ”<%= @section_view.parent.name %>”</span>
|
|
|
|
</h3>
|
2021-03-30 18:35:11 +08:00
|
|
|
<div class="container">
|
2021-03-20 21:10:15 +08:00
|
|
|
<div class="flex flex-col space-y-1">
|
2022-08-02 21:51:02 +08:00
|
|
|
<.live_component
|
|
|
|
module={LivebookWeb.SessionLive.InsertButtonsComponent}
|
|
|
|
id={"insert-buttons-#{@section_view.id}-first"}
|
|
|
|
persistent={@section_view.cell_views == []}
|
|
|
|
smart_cell_definitions={@smart_cell_definitions}
|
|
|
|
runtime={@runtime}
|
|
|
|
section_id={@section_view.id}
|
|
|
|
cell_id={nil}
|
2022-12-30 05:32:52 +08:00
|
|
|
session_id={@session_id}
|
2022-08-02 21:51:02 +08:00
|
|
|
/>
|
|
|
|
<%= for {cell_view, index} <- Enum.with_index(@section_view.cell_views) do %>
|
|
|
|
<.live_component
|
|
|
|
module={LivebookWeb.SessionLive.CellComponent}
|
|
|
|
id={cell_view.id}
|
|
|
|
session_id={@session_id}
|
2023-02-02 01:49:12 +08:00
|
|
|
session_pid={@session_pid}
|
2022-08-05 20:43:41 +08:00
|
|
|
client_id={@client_id}
|
2022-08-02 21:51:02 +08:00
|
|
|
runtime={@runtime}
|
|
|
|
installing?={@installing?}
|
2023-02-16 05:18:13 +08:00
|
|
|
allowed_uri_schemes={@allowed_uri_schemes}
|
2022-08-02 21:51:02 +08:00
|
|
|
cell_view={cell_view}
|
|
|
|
/>
|
|
|
|
<.live_component
|
|
|
|
module={LivebookWeb.SessionLive.InsertButtonsComponent}
|
|
|
|
id={"insert-buttons-#{@section_view.id}-#{index}"}
|
|
|
|
persistent={false}
|
2022-02-28 20:53:33 +08:00
|
|
|
smart_cell_definitions={@smart_cell_definitions}
|
2022-03-31 03:55:50 +08:00
|
|
|
runtime={@runtime}
|
2021-11-17 04:57:10 +08:00
|
|
|
section_id={@section_view.id}
|
2022-08-02 21:51:02 +08:00
|
|
|
cell_id={cell_view.id}
|
2022-12-30 05:32:52 +08:00
|
|
|
session_id={@session_id}
|
2022-08-02 21:51:02 +08:00
|
|
|
/>
|
2021-03-25 01:37:50 +08:00
|
|
|
<% end %>
|
2021-02-11 23:35:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-17 04:57:10 +08:00
|
|
|
</section>
|
2021-02-11 23:35:32 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|