mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-09 13:44:53 +08:00
* Update cell actions * Add new focus indicator * Update headings typography * Update cell actions and insert buttons * Add sidebar menu * Add settings modal * Update homepage * Update settings dialog * Rename classes * Add floating menu * Update icon colors on hover * Fix homepage tests * Format assets source * Update monaco editor * Fix editor width on resize * Add more padding to the notebook content * Update settings dialog title * Show reevaluate button when the cell is in evaluated state * Show section actions on focus or hover only * Pre-fill runtime selector with the current configuration * Ignore cmd + enter in Markdown cells
55 lines
1.7 KiB
Elixir
55 lines
1.7 KiB
Elixir
defmodule LivebookWeb.SessionLive.CellSettingsComponent do
|
|
use LivebookWeb, :live_component
|
|
|
|
alias Livebook.Session
|
|
|
|
@impl true
|
|
def update(assigns, socket) do
|
|
metadata = assigns.cell.metadata
|
|
|
|
assigns =
|
|
Map.merge(assigns, %{disable_formatting: Map.get(metadata, "disable_formatting", false)})
|
|
|
|
{:ok, assign(socket, assigns)}
|
|
end
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~L"""
|
|
<div class="p-6 pb-4 max-w-4xl flex flex-col space-y-3">
|
|
<h3 class="text-2xl font-semibold text-gray-800">
|
|
Cell settings
|
|
</h3>
|
|
<form phx-submit="save" phx-target="<%= @myself %>">
|
|
<div class="w-full flex-col space-y-3">
|
|
<label class="flex space-x-3 items-center cursor-pointer">
|
|
<%= tag :input, class: "checkbox", type: "checkbox", name: "disable_formatting", checked: @disable_formatting %>
|
|
<span>Disable code formatting (when saving to file)</span>
|
|
</label>
|
|
</div>
|
|
<div class="mt-6 flex justify-end space-x-2">
|
|
<%= live_patch "Cancel", to: @return_to, class: "button" %>
|
|
<button class="button button-primary" type="submit">
|
|
Save
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("save", params, socket) do
|
|
metadata = update_metadata(socket.assigns.cell.metadata, params)
|
|
Session.set_cell_metadata(socket.assigns.session_id, socket.assigns.cell.id, metadata)
|
|
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
|
|
end
|
|
|
|
defp update_metadata(metadata, form_data) do
|
|
if Map.has_key?(form_data, "disable_formatting") do
|
|
Map.put(metadata, "disable_formatting", true)
|
|
else
|
|
Map.delete(metadata, "disable_formatting")
|
|
end
|
|
end
|
|
end
|