-
diff --git a/lib/mishka_template_creator/components/blocks/element_menu.ex b/lib/mishka_template_creator/components/blocks/element_menu.ex
index 45eef71..17f18f1 100644
--- a/lib/mishka_template_creator/components/blocks/element_menu.ex
+++ b/lib/mishka_template_creator/components/blocks/element_menu.ex
@@ -1,33 +1,6 @@
defmodule MishkaTemplateCreator.Components.Blocks.ElementMenu do
use Phoenix.Component
-
- @layout_items [
- {"layout", "Layout", "Heroicons.inbox_stack"},
- {"section", "Section", "Heroicons.inbox_stack"},
- {"text", "Text", "Heroicons.inbox_stack"},
- {"tabs", "Tabs", "Heroicons.inbox_stack"},
- {"columns", "Columns", "Heroicons.inbox_stack"},
- {"table", "Table", "Heroicons.inbox_stack"},
- {"accordion", "Accordion", "Heroicons.inbox_stack"}
- ]
- @elements_items [
- {"alerts", "Alerts", "Heroicons.inbox_stack"},
- {"quotes", "Quotes", "Heroicons.inbox_stack"},
- {"buttons", "Buttons", "Heroicons.inbox_stack"},
- {"links", "Links", "Heroicons.inbox_stack"},
- {"code", "Code", "Heroicons.inbox_stack"},
- {"notes", "Notes", "Heroicons.inbox_stack"}
- ]
- @media_items [
- {"image", "Image", "Heroicons.inbox_stack"},
- {"video", "Video", "Heroicons.inbox_stack"},
- {"gallery", "Gallery", "Heroicons.inbox_stack"},
- {"thumbnails", "Thumbnails", "Heroicons.inbox_stack"},
- {"audio", "Audio", "Heroicons.inbox_stack"},
- {"file", "File", "Heroicons.inbox_stack"},
- {"pdf", "PDF", "Heroicons.inbox_stack"},
- {"comparison", "Comparison", "Heroicons.inbox_stack"}
- ]
+ alias MishkaTemplateCreator.Data.Elements
attr :id, :string, required: true
attr :title, :string, required: true
@@ -77,17 +50,17 @@ defmodule MishkaTemplateCreator.Components.Blocks.ElementMenu do
def aside_menu(assigns) do
assigns =
assign(assigns,
- layout_items: @layout_items,
- elements_items: @elements_items,
- media_items: @media_items
+ layout_items: Elements.elements(:layout_items),
+ elements_items: Elements.elements(:elements_items),
+ media_items: Elements.elements(:media_items)
)
~H"""
- <.items id="layout" items={@layout_items} title="Layout" />
+ <.items id="layout" items={Elements.elements(:layout_items)} title="Layout" />
- <.items id="elements" items={@elements_items} title="Elements" />
+ <.items id="elements" items={Elements.elements(:elements_items)} title="Elements" />
- <.items id="media" items={@media_items} title="Media" />
+ <.items id="media" items={Elements.elements(:media_items)} title="Media" />
"""
end
diff --git a/lib/mishka_template_creator/components/mishka_core_component.ex b/lib/mishka_template_creator/components/mishka_core_component.ex
index ec73141..85c4d8c 100644
--- a/lib/mishka_template_creator/components/mishka_core_component.ex
+++ b/lib/mishka_template_creator/components/mishka_core_component.ex
@@ -1,12 +1,13 @@
defmodule MishkaTemplateCreatorWeb.MishkaCoreComponent do
use Phoenix.Component
import Phoenix.HTML.Form
+ import MishkaTemplateCreatorWeb.CoreComponents
alias MishkaTemplateCreator.Data.TailwindSetting
alias MishkaTemplateCreator.Components.Blocks.{Content, Aside, History}
alias Phoenix.LiveView.JS
- import MishkaTemplateCreatorWeb.CoreComponents
+ alias MishkaTemplateCreator.Data.Elements
- @elements_type ["text", "tabs"]
+ @elements Elements.elements(:all, :id)
attr :elemens, :list, required: true
attr :selected_block, :string, required: true
@@ -180,7 +181,7 @@ defmodule MishkaTemplateCreatorWeb.MishkaCoreComponent do
type == "section" and parent == "layout" ->
Map.merge(params, %{id: id, children: [], class: TailwindSetting.default_section()})
- type in @elements_type and parent == "section" ->
+ type in Elements.elements(:all, :id) and parent == "section" ->
Map.merge(params, %{id: id, children: []})
true ->
@@ -251,8 +252,7 @@ defmodule MishkaTemplateCreatorWeb.MishkaCoreComponent do
end)
end
- def change_order(elements, current_index, new_index, parent_id, type)
- when type in @elements_type do
+ def change_order(elements, current_index, new_index, parent_id, type) when type in @elements do
Enum.map(elements, fn %{type: "layout", children: children} = layout ->
updated_children =
Enum.map(children, fn data ->
diff --git a/lib/mishka_template_creator/data/elements.ex b/lib/mishka_template_creator/data/elements.ex
new file mode 100644
index 0000000..a307051
--- /dev/null
+++ b/lib/mishka_template_creator/data/elements.ex
@@ -0,0 +1,43 @@
+defmodule MishkaTemplateCreator.Data.Elements do
+ @layout_items [
+ {"layout", "Layout", "Heroicons.inbox_stack"},
+ {"section", "Section", "Heroicons.inbox_stack"},
+ {"text", "Text", "Heroicons.inbox_stack"},
+ {"tabs", "Tabs", "Heroicons.inbox_stack"},
+ {"columns", "Columns", "Heroicons.inbox_stack"},
+ {"table", "Table", "Heroicons.inbox_stack"},
+ {"accordion", "Accordion", "Heroicons.inbox_stack"}
+ ]
+ @elements_items [
+ {"alerts", "Alerts", "Heroicons.inbox_stack"},
+ {"quotes", "Quotes", "Heroicons.inbox_stack"},
+ {"buttons", "Buttons", "Heroicons.inbox_stack"},
+ {"links", "Links", "Heroicons.inbox_stack"},
+ {"code", "Code", "Heroicons.inbox_stack"},
+ {"notes", "Notes", "Heroicons.inbox_stack"}
+ ]
+ @media_items [
+ {"image", "Image", "Heroicons.inbox_stack"},
+ {"video", "Video", "Heroicons.inbox_stack"},
+ {"gallery", "Gallery", "Heroicons.inbox_stack"},
+ {"thumbnails", "Thumbnails", "Heroicons.inbox_stack"},
+ {"audio", "Audio", "Heroicons.inbox_stack"},
+ {"file", "File", "Heroicons.inbox_stack"},
+ {"pdf", "PDF", "Heroicons.inbox_stack"},
+ {"comparison", "Comparison", "Heroicons.inbox_stack"}
+ ]
+
+ @spec elements :: [{String.t(), String.t(), String.t()}]
+ def elements(), do: @layout_items ++ @elements_items ++ @media_items
+
+ @spec elements(:elements_items | :layout_items | :media_items) :: [
+ {String.t(), String.t(), String.t()}
+ ]
+ def elements(:layout_items), do: @layout_items
+ def elements(:elements_items), do: @elements_items
+ def elements(:media_items), do: @media_items
+
+ @spec elements(:all | :elements_items | :layout_items | :media_items, :id) :: list(String.t())
+ def elements(:all, :id), do: elements() |> Enum.map(fn {id, _, _} -> id end)
+ def elements(type, :id), do: elements(type) |> Enum.map(fn {id, _, _} -> id end)
+end