Packages
phoenix_duskmoon
9.6.2
9.9.2
9.9.1
9.9.0
9.8.0
9.7.1
9.7.0
9.6.4
9.6.3
9.6.2
9.6.1
9.6.0
9.5.4
9.5.3
9.5.2
9.5.1
9.5.0
9.4.3
9.4.2
9.4.1
9.4.0
9.3.0
9.2.0
9.1.4
9.1.3
9.1.1
9.1.1-rc.1
retired
9.0.1
9.0.0-rc.3
9.0.0-rc.2
9.0.0-rc.1
8.0.0
7.2.1
7.2.0
7.1.3
7.1.2
7.1.1
6.3.2
6.3.1
6.3.0
6.2.0
6.1.3
6.1.2
6.1.1
6.1.0
6.0.10
6.0.9
6.0.8
6.0.7
6.0.6
6.0.5
6.0.4
6.0.3
6.0.2
6.0.1
6.0.0
5.2.0-beta.5
5.2.0-beta.4
5.2.0-beta.3
5.2.0-beta.2
5.2.0-beta.1
5.1.0
5.0.6
5.0.5
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.2
4.5.1
4.5.0
4.4.4
4.4.3
4.4.2
4.4.1
4.4.0
4.3.2
4.3.1
4.3.0
4.2.0
4.1.1
4.1.0
4.0.0
Duskmoon UI component library for Phoenix LiveView
Current section
Files
Jump to
Current section
Files
lib/phoenix_duskmoon/component/data_entry/markdown_input.ex
defmodule PhoenixDuskmoon.Component.DataEntry.MarkdownInput do
@moduledoc """
Duskmoon UI Markdown Input Component
Rich markdown editor using `<el-dm-markdown-input>` custom element from
`@duskmoon-dev/el-markdown-input`.
Provides a split-pane editor with live markdown preview, syntax highlighting,
and optional Mermaid diagram support.
Requires `@duskmoon-dev/el-markdown-input` registered in your project:
```js
import '@duskmoon-dev/el-markdown-input/register';
```
"""
use Phoenix.Component
@doc """
Renders an `<el-dm-markdown-input>` custom element for markdown editing.
Supports both standalone usage and Phoenix form field integration.
Files can be attached via drag-drop, paste, or the attach button in the
bottom bar. With `upload_url` files are POSTed immediately; without it
they are kept locally and submitted as `{name}_files` form fields.
## Examples
<.dm_markdown_input name="body" value={@body} />
<.dm_markdown_input
field={@form[:body]}
placeholder="Write markdown here…"
upload_url="/api/uploads"
/>
<.dm_markdown_input name="notes" value="" max_words={500}>
<:bottom_start>
<button type="button">Custom Action</button>
</:bottom_start>
</.dm_markdown_input>
"""
@doc type: :component
attr(:id, :any, default: nil, doc: "HTML id attribute")
attr(:name, :any, default: nil, doc: "HTML name attribute for form submission")
attr(:value, :any, default: nil, doc: "markdown content value")
attr(:field, Phoenix.HTML.FormField,
doc: "a form field struct retrieved from the form, sets id/name/value automatically"
)
attr(:label, :string, default: nil, doc: "text label displayed above the editor")
attr(:placeholder, :string, default: nil, doc: "placeholder text shown when editor is empty")
attr(:disabled, :boolean, default: false, doc: "disables the editor")
attr(:readonly, :boolean, default: false, doc: "makes the editor read-only")
attr(:theme, :string,
default: nil,
values: [nil, "github", "atom-one-dark", "atom-one-light", "auto"],
doc: "code syntax highlighting theme for the preview pane"
)
attr(:no_mermaid, :boolean,
default: false,
doc: "disable Mermaid diagram rendering in the preview pane"
)
attr(:no_preview, :boolean,
default: false,
doc: "hide the preview tab and toolbar; write-only mode"
)
attr(:upload_url, :string,
default: nil,
doc: "POST endpoint for file uploads; server must return {url: string}"
)
attr(:max_words, :integer,
default: nil,
doc: "soft word cap shown in status bar (warning at 80%, error at 100%)"
)
attr(:resize, :string,
default: nil,
values: [nil, "none", "vertical", "horizontal", "both"],
doc: "editor resize behavior"
)
attr(:live_preview, :boolean,
default: false,
doc: "enable live preview rendering"
)
attr(:debounce, :integer,
default: nil,
doc: "debounce delay (ms) for preview rendering"
)
attr(:class, :any, default: nil, doc: "additional CSS classes")
attr(:rest, :global)
slot(:bottom, doc: "replaces the entire bottom status bar") do
attr(:class, :any, doc: "wrapper CSS classes")
end
slot(:bottom_start, doc: "left section of the bottom bar (default: attach files button)") do
attr(:class, :any, doc: "wrapper CSS classes")
end
slot(:bottom_end, doc: "right section of the bottom bar (default: word/char count)") do
attr(:class, :any, doc: "wrapper CSS classes")
end
def dm_markdown_input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
assigns
|> assign(field: nil, id: assigns.id || field.id)
|> assign(:name, field.name)
|> assign(:value, field.value)
|> dm_markdown_input()
end
def dm_markdown_input(assigns) do
~H"""
<el-dm-markdown-input
id={@id}
name={@name}
value={@value}
placeholder={@placeholder}
disabled={@disabled}
readonly={@readonly}
theme={@theme}
no-mermaid={@no_mermaid}
no-preview={@no_preview}
upload-url={@upload_url}
max-words={@max_words}
resize={@resize}
live-preview={@live_preview}
debounce={@debounce}
class={@class}
{@rest}
>
<div
:for={bottom <- @bottom}
slot="bottom"
class={bottom[:class]}
>
{render_slot(bottom)}
</div>
<div
:for={bottom_start <- @bottom_start}
slot="bottom-start"
class={bottom_start[:class]}
>
{render_slot(bottom_start)}
</div>
<div
:for={bottom_end <- @bottom_end}
slot="bottom-end"
class={bottom_end[:class]}
>
{render_slot(bottom_end)}
</div>
</el-dm-markdown-input>
"""
end
end