Class MarkdownMessage

java.lang.Object
com.vaadin.flow.component.Component
org.vaadin.firitin.components.messagelist.MarkdownMessage
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, Serializable

@Tag("vaadin-message") public class MarkdownMessage extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasSize
A wrapper for vaadin-message web component, that supports Markdown formatting and appending content dynamically to the element. Typical usecase: LLM chatbots slowly giving you the answer.
See Also:
  • Nested Class Summary Link icon

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Constructs a new MarkdownMessages, without initial content.
    MarkdownMessage(String markdown, String name)
    Constructs a new MarkdownMessages, with initial content.
    MarkdownMessage(String markdown, String name, LocalDateTime timestamp)
    Constructs a new MarkdownMessages, with initial content.
    MarkdownMessage(String markdown, String name, MarkdownMessage.Color avatarColor)
    Constructs a new MarkdownMessages, with initial content.
    Constructs a new MarkdownMessages, without initial content.
    Constructs a new MarkdownMessages with all the bells and whistles, without initial content.
    Constructs a new MarkdownMessages, without initial content.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    appendMarkdown(String markdownSnippet)
    Directly adds markdown formatted text to message part.
    protected void
    appendMarkdown(String markdownSnippet, boolean uiAccess)
     
    void
    appendMarkdownAsync(String markdownSnippet)
    Adds markdown formatted text to message part.
    protected void
     
     
    protected com.vladsch.flexmark.parser.Parser
     
    protected com.vladsch.flexmark.html.HtmlRenderer
     
    com.vaadin.flow.component.UI
     
    boolean
     
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    setAutoScroll(boolean autoScroll)
     
    void
     
    void
    setMarkdown(String markdown)
     
    protected void
    setMarkdown(String markdown, boolean uiAccess)
     
    void
    setUserColorIndex(int index)
     

    Methods inherited from class com.vaadin.flow.component.Component Link icon

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier Link icon

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier Link icon

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement Link icon

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasSize Link icon

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle Link icon

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
  • Constructor Details Link icon

    • MarkdownMessage Link icon

      public MarkdownMessage(String name, LocalDateTime timestamp, MarkdownMessage.Color color)
      Constructs a new MarkdownMessages with all the bells and whistles, without initial content. Add that later with appendMarkdownAsync(String).
      Parameters:
      name - the name of the user
      timestamp - time of the message
      color - the color used for user avatar
    • MarkdownMessage Link icon

      public MarkdownMessage(String name)
      Constructs a new MarkdownMessages, without initial content. Add that later with appendMarkdownAsync(String).
      Parameters:
      name - the name of the user
    • MarkdownMessage Link icon

      public MarkdownMessage(String name, LocalDateTime timestamp)
      Constructs a new MarkdownMessages, without initial content. Add that later with appendMarkdownAsync(String).
      Parameters:
      name - the name of the user
      timestamp - the timestamp of the message
    • MarkdownMessage Link icon

      public MarkdownMessage(String name, MarkdownMessage.Color avatarColor)
      Constructs a new MarkdownMessages, without initial content. Add that later with appendMarkdownAsync(String).
      Parameters:
      name - the name of the user
      avatarColor - the avatar color
    • MarkdownMessage Link icon

      public MarkdownMessage(String markdown, String name, MarkdownMessage.Color avatarColor)
      Constructs a new MarkdownMessages, with initial content. You can add more text later with appendMarkdownAsync(String).
      Parameters:
      markdown - the initial content as markdown formatter text
      name - the name of the user
      avatarColor - the color of the avatar
    • MarkdownMessage Link icon

      public MarkdownMessage(String markdown, String name)
      Constructs a new MarkdownMessages, with initial content. You can add more text later with appendMarkdownAsync(String).
      Parameters:
      markdown - the initial content as markdown formatter text
      name - the name of the user
    • MarkdownMessage Link icon

      public MarkdownMessage(String markdown, String name, LocalDateTime timestamp)
      Constructs a new MarkdownMessages, with initial content. You can add more text later with appendMarkdownAsync(String).
      Parameters:
      markdown - the initial content as markdown formatted text
      name - the name of the user
      timestamp - the timestamp of the message
  • Method Details Link icon

    • setAvatarColor Link icon

      public void setAvatarColor(MarkdownMessage.Color color)
    • setUserColorIndex Link icon

      public void setUserColorIndex(int index)
    • getMarkdown Link icon

      public String getMarkdown()
    • setMarkdown Link icon

      protected void setMarkdown(String markdown, boolean uiAccess)
    • setMarkdown Link icon

      public void setMarkdown(String markdown)
    • getMdRenderer Link icon

      protected com.vladsch.flexmark.html.HtmlRenderer getMdRenderer()
    • getMdParser Link icon

      protected com.vladsch.flexmark.parser.Parser getMdParser()
    • onAttach Link icon

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • getUi Link icon

      public com.vaadin.flow.component.UI getUi()
    • appendMarkdown Link icon

      public void appendMarkdown(String markdownSnippet)
      Directly adds markdown formatted text to message part. Note, that this method should not be called from any other but Vaadin UI thread. Consider using the appendMarkdownAsync(String) version in case the new text is coming from a background thread.
      Parameters:
      markdownSnippet - the new markdown formatted text snippet
    • appendMarkdownAsync Link icon

      public void appendMarkdownAsync(String markdownSnippet)
      Adds markdown formatted text to message part. This method takes care of synchronization with UI.access(Command), so it is safe to call this directly from a background thread.
      Parameters:
      markdownSnippet - the new markdown formatted text snippet
    • appendMarkdown Link icon

      protected void appendMarkdown(String markdownSnippet, boolean uiAccess)
    • isAutoScroll Link icon

      public boolean isAutoScroll()
    • setAutoScroll Link icon

      public void setAutoScroll(boolean autoScroll)
    • doAutoScroll Link icon

      protected void doAutoScroll()