defmodule LivebookWeb.SessionLive.InsertButtonsComponent do use LivebookWeb, :live_component import LivebookWeb.SessionHelpers defguardp is_many(list) when tl(list) != [] def render(assigns) do ~H""" """ end defp code_block_insert_button(assigns) when is_many(assigns.definition.variants) do ~H""" <.submenu> <:primary> <.menu_item :for={{variant, idx} <- Enum.with_index(@definition.variants)}> """ end defp code_block_insert_button(assigns) do ~H""" """ end defp smart_cell_insert_button(assigns) when is_many(assigns.definition.requirement_presets) do ~H""" <.submenu> <:primary> <.menu_item :for={{preset, idx} <- Enum.with_index(@definition.requirement_presets)}> """ end defp smart_cell_insert_button(assigns) do ~H""" """ end defp on_code_block_click(definition, variant_idx, runtime, section_id, cell_id) do if Livebook.Runtime.connected?(runtime) do JS.push("insert_code_block_below", value: %{ definition_name: definition.name, variant_idx: variant_idx, section_id: section_id, cell_id: cell_id } ) else JS.push("setup_default_runtime", value: %{reason: "To insert this block, you need a connected runtime."} ) end end defp on_smart_cell_click(definition, section_id, cell_id) do preset_idx = if definition.requirement_presets == [], do: nil, else: 0 on_smart_cell_click(definition, preset_idx, section_id, cell_id) end defp on_smart_cell_click(definition, preset_idx, section_id, cell_id) do JS.push("insert_smart_cell_below", value: %{ kind: definition.kind, section_id: section_id, cell_id: cell_id, preset_idx: preset_idx } ) end end