defmodule PhiaUi.Components.Editor.Presets do @moduledoc """ Editor Presets — 10 pre-composed editor configurations for common use cases. Each preset composes the lower-level PhiaUI editor components into a ready-to-use editor with opinionated defaults. Import one preset component and drop it into your LiveView for an instant editing experience. ## Presets ### Original (v0.1.17) - `simple_editor/1` — minimal editor with bold/italic/link/lists toolbar - `article_editor/1` — Medium-style editor for blog posts and articles - `document_editor_full/1` — full document shell with header/footer/sidebar - `academic_editor/1` — academic editor with citation toolbar - `email_composer/1` — email-style editor with To/Subject/Signature ### v2 Presets (v0.1.17) - `notion_editor/1` — Notion-style: slash commands, drag, block toolbars - `google_docs_editor/1` — GDocs: menu bar, A4 pages, track changes - `medium_editor_v2/1` — Medium: floating toolbar, clean reading, images - `code_notes_editor/1` — Dev notes: syntax hl, code sandbox, markdown - `collaborative_editor/1` — Full collab: presence, cursors, comments sidebar ## Usage # In your LiveView template: <.simple_editor id="my-editor" value={@content} /> # Or for a full document experience: <.document_editor_full id="doc" title="Q4 Report" /> """ use Phoenix.Component import PhiaUi.ClassMerger, only: [cn: 1] import PhiaUi.Components.Editor.RichEditor # ============================================================================ # 1. simple_editor/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :placeholder, :string, default: "Start writing..." attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders a minimal editor with a compact toolbar (bold, italic, link, lists). This is the simplest preset — ideal for comments, short notes, and forms where a lightweight rich text input is needed. ## Example <.simple_editor id="comment-editor" placeholder="Add a comment..." /> """ def simple_editor(assigns) do ~H""" <.rich_editor id={@id} value={@value} placeholder={@placeholder} on_update={@on_update} toolbar_variant={:compact} show_word_count={false} min_height="150px" class={@class} {@rest} /> """ end # ============================================================================ # 2. article_editor/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders a Medium-style article editor with heading selector, image support, and embeds. Features a full toolbar with text formatting, heading levels, lists, blockquotes, code blocks, and media insertion. Ideal for blog posts, documentation, and long-form content. ## Example <.article_editor id="blog-editor" value={@draft_content} /> """ def article_editor(assigns) do ~H"""
<%!-- Article-specific header bar --%>
Article Editor
<%!-- Editor --%> <.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Tell your story..." min_height="500px" toolbar_variant={:default} show_word_count={true} />
""" end # ============================================================================ # 3. document_editor_full/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :title, :string, default: "Untitled" attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders a full document editor with header, toolbar, content, sidebar, and footer. This is the most complete preset — a Google Docs-like experience with title bar, save status, collapsible sidebar, word count footer, and full formatting toolbar. ## Example <.document_editor_full id="report" title="Q4 Report" value={@content} /> """ def document_editor_full(assigns) do ~H"""
<%!-- Document header --%>

{@title}

Saved
<%!-- Main area --%>
<%!-- Editor in centered page view --%>
<.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Start writing your document..." min_height="600px" toolbar_variant={:default} show_word_count={true} />
<%!-- Footer status bar --%>
""" end # ============================================================================ # 4. academic_editor/1 # ============================================================================ @citation_styles [ %{value: :apa, label: "APA"}, %{value: :mla, label: "MLA"}, %{value: :chicago, label: "Chicago"}, %{value: :harvard, label: "Harvard"}, %{value: :ieee, label: "IEEE"}, %{value: :vancouver, label: "Vancouver"} ] attr :id, :string, required: true attr :value, :string, default: "" attr :citation_style, :atom, default: :apa attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders an academic editor with citation toolbar and formatting for papers. Includes a citation style selector, footnote insertion, bibliography tools, and standard text formatting. The toolbar is tailored for academic writing. ## Example <.academic_editor id="paper" citation_style={:mla} value={@paper_content} /> """ def academic_editor(assigns) do assigns = assign(assigns, :citation_styles, @citation_styles) ~H"""
<%!-- Academic toolbar --%>
Academic
<%!-- Citation style selector --%>
<%!-- Citation tools --%>
<%!-- Export to LaTeX --%>
<%!-- Editor --%> <.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Begin your manuscript..." min_height="600px" toolbar_variant={:default} show_word_count={true} />
""" end # ============================================================================ # 5. email_composer/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :to, :string, default: "" attr :subject, :string, default: "" attr :signature, :string, default: "" attr :class, :string, default: nil attr :rest, :global @doc """ Renders an email-style composer with To, Subject, body, and signature fields. The body uses the rich editor with a compact toolbar. The signature is appended below the editor as a preview. ## Example <.email_composer id="email" to="user@example.com" subject="Meeting Follow-Up" signature="Best regards,\\nJohn" /> """ def email_composer(assigns) do ~H"""
<%!-- Email header fields --%>
<%!-- Email body editor --%> <.rich_editor id={@id} value={@value} placeholder="Compose your email..." min_height="300px" toolbar_variant={:compact} show_word_count={false} class="rounded-none border-0 shadow-none" /> <%!-- Signature preview --%>

{line}

<%!-- Actions --%>
""" end # ============================================================================ # 6. notion_editor/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders a Notion-style editor with slash commands, drag handles, and per-block floating toolbars. Minimal chrome, maximum content focus. Features: block-level operations, drag reorder, "/" command palette, markdown input shortcuts (via v2 engine). ## Example <.notion_editor id="notes-editor" value={@content} /> """ def notion_editor(assigns) do ~H"""
<%!-- Minimal top bar --%>
Notion-style
/ for commands
<%!-- Editor with no visible toolbar --%> <.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Press '/' for commands, or just start typing..." min_height="400px" toolbar_variant={:floating} show_word_count={false} />
""" end # ============================================================================ # 7. google_docs_editor/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :title, :string, default: "Untitled Document" attr :on_update, :string, default: "editor:update" attr :track_changes, :boolean, default: false attr :class, :string, default: nil attr :rest, :global @doc """ Renders a Google Docs-style editor with a full menu bar, toolbar, A4-formatted pages, and optional track changes mode. Features: document title, save status, full formatting toolbar, A4 page layout, word count footer, track changes toggle. ## Example <.google_docs_editor id="doc" title="Q4 Report" track_changes={true} /> """ def google_docs_editor(assigns) do ~H"""
<%!-- Menu bar --%>

{@title}

<%!-- Track changes toggle --%>
Suggesting
Saved
<%!-- Content area with A4 page look --%>
<.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Start typing your document..." min_height="900px" toolbar_variant={:default} show_word_count={true} />
<%!-- Footer --%>
0 words
English Page 1 of 1 100%
""" end # ============================================================================ # 8. medium_editor_v2/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders a Medium-style writing experience with floating toolbar, clean reading typography, and image-focused layout. Features: floating selection toolbar, large headings, wide image support, drop cap option, distraction-free writing. ## Example <.medium_editor_v2 id="story" value={@story_content} /> """ def medium_editor_v2(assigns) do ~H"""
<%!-- Clean header --%>
Write
<%!-- Editor with floating toolbar --%> <.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Tell your story..." min_height="500px" toolbar_variant={:floating} show_word_count={true} class="prose prose-lg max-w-none" />
""" end # ============================================================================ # 9. code_notes_editor/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :on_update, :string, default: "editor:update" attr :class, :string, default: nil attr :rest, :global @doc """ Renders a developer-focused notes editor with syntax highlighting, code sandbox blocks, and markdown input shortcuts. Features: code blocks with language detection and highlighting, inline code formatting, monospace-friendly layout, markdown shortcuts. ## Example <.code_notes_editor id="dev-notes" value={@notes} /> """ def code_notes_editor(assigns) do ~H"""
<%!-- Dev toolbar --%>
Code Notes
Markdown shortcuts active
<%!-- Editor with full toolbar --%> <.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="# Start with a heading, or ``` for a code block..." min_height="500px" toolbar_variant={:default} show_word_count={true} class="font-mono" />
""" end # ============================================================================ # 10. collaborative_editor/1 # ============================================================================ attr :id, :string, required: true attr :value, :string, default: "" attr :title, :string, default: "Shared Document" attr :on_update, :string, default: "editor:update" attr :collaborators, :list, default: [] attr :class, :string, default: nil attr :rest, :global @doc """ Renders a full collaborative editing experience with presence indicators, cursor tracking, comments sidebar, and version history access. Designed to integrate with PhiaUI's Collab Suite (CollabRoom, CollabPresence, etc.) for real-time multi-user editing. ## Example <.collaborative_editor id="collab-doc" title="Team Notes" collaborators={@online_users} /> """ def collaborative_editor(assigns) do ~H"""
<%!-- Collab header --%>

{@title}

<%!-- Presence avatars --%>
{String.first(Map.get(user, :name, "U"))}
5} class="h-7 w-7 rounded-full border-2 border-background bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground" > +{length(@collaborators) - 5}
<%!-- Actions --%>
<%!-- Main content area --%>
<.rich_editor id={@id} value={@value} on_update={@on_update} placeholder="Start collaborating..." min_height="600px" toolbar_variant={:default} show_word_count={true} collab_enabled={true} />
<%!-- Footer --%>
""" end end