mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-10 09:03:02 +08:00
Support toggling smart cell editor visibility (#2761)
This commit is contained in:
parent
8ff63bea01
commit
0142d4720b
6 changed files with 36 additions and 9 deletions
|
@ -712,7 +712,8 @@ defprotocol Livebook.Runtime do
|
|||
language: String.t() | nil,
|
||||
placement: :bottom | :top,
|
||||
source: String.t(),
|
||||
intellisense_node: {atom(), atom()} | nil
|
||||
intellisense_node: {atom(), atom()} | nil,
|
||||
visible: boolean()
|
||||
}
|
||||
|
||||
@typedoc """
|
||||
|
@ -1030,7 +1031,7 @@ defprotocol Livebook.Runtime do
|
|||
The cell can also update some of the editor configuration or source
|
||||
by sending:
|
||||
|
||||
* `{:runtime_smart_cell_editor_update, ref, %{optional(:source) => String.t(), optional(:intellisense_node) => {atom(), atom()} | nil}}`
|
||||
* `{:runtime_smart_cell_editor_update, ref, %{optional(:source) => String.t(), optional(:intellisense_node) => {atom(), atom()} | nil}, optional(:visible) => boolean()}`
|
||||
|
||||
"""
|
||||
@spec start_smart_cell(
|
||||
|
|
|
@ -423,7 +423,8 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServer do
|
|||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info({message, _node, _info}, state) when message in [:nodeup, :nodedown] do
|
||||
def handle_info({message, _node, _info}, state)
|
||||
when message in [:nodeup, :nodedown] and state.owner != nil do
|
||||
report_connected_nodes(state)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
|
|
@ -1828,9 +1828,9 @@ defmodule Livebook.Session do
|
|||
end
|
||||
|
||||
state =
|
||||
case options do
|
||||
%{intellisense_node: intellisense_node} ->
|
||||
editor = %{cell.editor | intellisense_node: intellisense_node}
|
||||
case Map.take(options, [:intellisense_node, :visible]) do
|
||||
updates when updates != %{} ->
|
||||
editor = Map.merge(cell.editor, updates)
|
||||
operation = {:set_cell_attributes, @client_id, cell.id, %{editor: editor}}
|
||||
handle_operation(state, operation)
|
||||
|
||||
|
@ -3264,5 +3264,10 @@ defmodule Livebook.Session do
|
|||
normalize_smart_cell_started_info(put_in(info.editor[:intellisense_node], nil))
|
||||
end
|
||||
|
||||
defp normalize_smart_cell_started_info(info)
|
||||
when info.editor != nil and not is_map_key(info.editor, :visible) do
|
||||
normalize_smart_cell_started_info(put_in(info.editor[:visible], true))
|
||||
end
|
||||
|
||||
defp normalize_smart_cell_started_info(info), do: info
|
||||
end
|
||||
|
|
|
@ -1935,7 +1935,8 @@ defmodule LivebookWeb.SessionLive do
|
|||
%{
|
||||
empty: cell.editor.source == "",
|
||||
language: cell.editor.language,
|
||||
placement: cell.editor.placement
|
||||
placement: cell.editor.placement,
|
||||
visible: cell.editor.visible
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -230,6 +230,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do
|
|||
language={@cell_view.editor.language}
|
||||
rounded={@cell_view.editor.placement}
|
||||
intellisense={@cell_view.editor.language == "elixir"}
|
||||
hidden={not @cell_view.editor.visible}
|
||||
/>
|
||||
</div>
|
||||
<% :dead -> %>
|
||||
|
@ -609,12 +610,13 @@ defmodule LivebookWeb.SessionLive.CellComponent do
|
|||
attr :intellisense, :boolean, default: false
|
||||
attr :read_only, :boolean, default: false
|
||||
attr :rounded, :atom, default: :both
|
||||
attr :hidden, :boolean, default: false
|
||||
|
||||
defp cell_editor(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
class={[@hidden && "hidden"]}
|
||||
id={"cell-editor-#{@cell_id}-#{@tag}"}
|
||||
phx-update="ignore"
|
||||
phx-hook="CellEditor"
|
||||
data-p-cell-id={hook_prop(@cell_id)}
|
||||
data-p-tag={hook_prop(@tag)}
|
||||
|
@ -622,7 +624,12 @@ defmodule LivebookWeb.SessionLive.CellComponent do
|
|||
data-p-intellisense={hook_prop(@intellisense)}
|
||||
data-p-read-only={hook_prop(@read_only)}
|
||||
>
|
||||
<div class={["bg-editor", rounded_class(@rounded)]} data-el-editor-container>
|
||||
<div
|
||||
id={"cell-editor-#{@cell_id}-#{@tag}-container"}
|
||||
phx-update="ignore"
|
||||
class={["bg-editor", rounded_class(@rounded)]}
|
||||
data-el-editor-container
|
||||
>
|
||||
<div data-el-skeleton>
|
||||
<div class="py-3 px-8">
|
||||
<.content_skeleton bg_class="bg-gray-500" empty={@empty} />
|
||||
|
|
|
@ -1079,6 +1079,18 @@ defmodule Livebook.SessionTest do
|
|||
sections: [%{cells: [%{editor: %{intellisense_node: {:test@test, :test}}}]}]
|
||||
}
|
||||
} = Session.get_data(session.pid)
|
||||
|
||||
# Update visibility
|
||||
send(
|
||||
session.pid,
|
||||
{:runtime_smart_cell_editor_update, smart_cell.id, %{visible: false}}
|
||||
)
|
||||
|
||||
assert %{
|
||||
notebook: %{
|
||||
sections: [%{cells: [%{editor: %{visible: false}}]}]
|
||||
}
|
||||
} = Session.get_data(session.pid)
|
||||
end
|
||||
|
||||
test "pings the smart cell before evaluation to await all incoming messages" do
|
||||
|
|
Loading…
Reference in a new issue