defmodule LivebookWeb.SessionLive.InsertButtonsComponent do use LivebookWeb, :live_component import LivebookWeb.NotebookComponents defguardp is_many(list) when tl(list) != [] def render(assigns) do ~H""" """ end attr :disabled, :boolean, default: false attr :rest, :global slot :inner_block def insert_button(assigns) do ~H""" """ end defp example_snippet_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 example_snippet_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_example_snippet_click(definition, variant_idx, section_id, cell_id) do JS.push("insert_example_snippet_below", value: %{ definition_name: definition.name, variant_idx: variant_idx, section_id: section_id, cell_id: cell_id } ) 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