Options
All
  • Public
  • Public/Protected
  • All
Menu

A collection of helper functions and utility methods related to the rich text editor

Hierarchy

  • TextEditor

Index

Constructors

Methods

  • create(options?: { engine: string }, content?: string): Promise<any>
  • Create a Rich Text Editor. The current implementation uses TinyMCE

    Parameters

    • options: { engine: string } = {}

      Configuration options provided to the Editor init

      • engine: string
    • content: string = ""

      Initial HTML or text content to populate the editor with

    Returns Promise<any>

    The editor instance.

  • decodeHTML(html: string): string
  • Safely decode an HTML string, removing invalid tags and converting entities back to unicode characters.

    Parameters

    • html: string

      The original encoded HTML string

    Returns string

    The decoded unicode string

  • Enrich HTML content by replacing or augmenting components of it

    Parameters

    • content: string

      The original HTML content (as a string)

    • options: EnrichmentOptions = {}

    Returns string | Promise<string>

    The enriched HTML content

  • previewHTML(content: string, length?: number): string
  • Preview an HTML fragment by constructing a substring of a given length from its inner text.

    Parameters

    • content: string

      The raw HTML to preview

    • length: number = 250

      The desired length

    Returns string

    The previewed HTML

  • truncateHTML(html: HTMLElement): HTMLElement
  • Sanitises an HTML fragment and removes any non-paragraph-style text.

    Parameters

    • html: HTMLElement

      The root HTML element.

    Returns HTMLElement

  • truncateText(text: string, [options]?: { maxLength: number; splitWords: boolean; suffix: string }): string
  • Truncate a fragment of text to a maximum number of characters.

    Parameters

    • text: string

      The original text fragment that should be truncated to a maximum length

    • [options]: { maxLength: number; splitWords: boolean; suffix: string } = {}

      Options which affect the behavior of text truncation

      • maxLength: number
      • splitWords: boolean
      • suffix: string

    Returns string

    The truncated text string

  • _createInlineRoll(match: RegExpMatchArray, rollData: any, options: any): HTMLAnchorElement | Promise<HTMLAnchorElement>
  • Replace an inline roll formula with a rollable <a> element or an eagerly evaluated roll result

    Parameters

    • match: RegExpMatchArray

      The regular expression match array

    • rollData: any

      Provided roll data for use in roll evaluation

    • options: any

    Returns HTMLAnchorElement | Promise<HTMLAnchorElement>

    The replaced match, returned as a Promise if async was true and the message contained an immediate inline roll.

  • activateListeners(): void
  • Activate interaction listeners for the interior content of the editor frame.

    Returns void

  • getDragEventData(event: DragEvent): any
  • Extract JSON data from a drag/drop event.

    Parameters

    • event: DragEvent

      The drag event which contains JSON data.

    Returns any

    The extracted JSON data. The object will be empty if the DragEvent did not contain JSON-parseable data.

  • getContentLink(eventData: any, options?: { relativeTo: ClientDocument; label: string }): Promise<string>
  • Given a Drop event, returns a Content link if possible such as @Actor[ABC123], else null

    Parameters

    • eventData: any

      The parsed object of data provided by the transfer event

    • options: { relativeTo: ClientDocument; label: string } = {}
      • relativeTo: ClientDocument
      • label: string

    Returns Promise<string>

  • _uploadImage(uuid: string, file: File): Promise<string>
  • Upload an image to a document's asset path.

    internal

    Parameters

    • uuid: string

      The document's UUID.

    • file: File

      The image file to upload.

    Returns Promise<string>

    The path to the uploaded image.

  • _createTinyMCE(options?: any, content?: string): Promise<Editor>
  • Create a TinyMCE editor instance.

    Parameters

    • options: any = {}
    • content: string = ""

    Returns Promise<Editor>

    The TinyMCE editor instance.

  • _enrichContentLinks(text: Text[], [options]?: EnrichmentOptions): boolean | Promise<boolean>
  • Convert text of the form @UUID[uuid]{name} to anchor elements.

    Parameters

    • text: Text[]

      The existing text content

    • [options]: EnrichmentOptions = {}

      Options provided to customize text enrichment

    Returns boolean | Promise<boolean>

    Whether any content links were replaced and the text nodes need to be updated.

  • Convert URLs into anchor elements.

    Parameters

    Returns boolean

    Whether any hyperlinks were replaced and the text nodes need to be updated

  • _enrichInlineRolls(rollData: any, text: Text[], [options]?: EnrichmentOptions): boolean | Promise<boolean>
  • Convert text of the form roll to anchor elements.

    Parameters

    • rollData: any

      The data object providing context for inline rolls.

    • text: Text[]

      The existing text content.

    • [options]: EnrichmentOptions = {}

      Options provided to customize text enrichment

    Returns boolean | Promise<boolean>

    Whether any inline rolls were replaced and the text nodes need to be updated.

  • Match any custom registered regex patterns and apply their replacements.

    Parameters

    • pattern: RegExp

      The pattern to match against.

    • enricher: TextEditorEnricher

      The function that will be run for each match.

    • text: Text[]

      The existing text content.

    • options: EnrichmentOptions

    Returns Promise<boolean>

    Whether any replacements were made, requiring the text nodes to be updated.

  • _createContentLink(match: RegExpMatchArray, [options]?: { async: boolean; relativeTo: ClientDocument }): HTMLAnchorElement | Promise<HTMLAnchorElement>
  • Create a dynamic document link from a regular expression match

    Parameters

    • match: RegExpMatchArray

      The regular expression match

    • [options]: { async: boolean; relativeTo: ClientDocument } = {}

      Additional options to configure enrichment behaviour

      • async: boolean
      • relativeTo: ClientDocument

    Returns HTMLAnchorElement | Promise<HTMLAnchorElement>

    An HTML element for the document link, returned as a Promise if async was true and the message contained a UUID link.

  • _getTextNodes(parent: HTMLElement): Text[]
  • Recursively identify the text nodes within a parent HTML node for potential content replacement.

    Parameters

    • parent: HTMLElement

      The parent HTML Element

    Returns Text[]

    An array of contained Text nodes

  • _replaceTextContent(text: Text, rgx: RegExp, func: ((arg0: RegExpMatchArray) => HTMLElement | Promise<HTMLElement>)): boolean | Promise<boolean>
  • Facilitate the replacement of text node content using a matching regex rule and a provided replacement function.

    Parameters

    • text: Text

      The target text to replace

    • rgx: RegExp

      The provided regular expression for matching and replacement

    • func: ((arg0: RegExpMatchArray) => HTMLElement | Promise<HTMLElement>)

      The replacement function

        • (arg0: RegExpMatchArray): HTMLElement | Promise<HTMLElement>
        • Parameters

          • arg0: RegExpMatchArray

          Returns HTMLElement | Promise<HTMLElement>

    Returns boolean | Promise<boolean>

  • _replaceTextNode(text: Text, match: RegExpMatchArray, replacement: Node): void
  • Replace a matched portion of a Text node with a replacement Node

    Parameters

    • text: Text
    • match: RegExpMatchArray
    • replacement: Node

    Returns void

  • _createLegacyContentLink(type: string, target: string, name: string, data: any): boolean
  • Create a dynamic document link from an old-form document link expression.

    Parameters

    • type: string

      The matched document type, or "Compendium".

    • target: string

      The requested match target (_id or name).

    • name: string

      A customized or overridden display name for the link.

    • data: any

      Data containing the properties of the resulting link element.

    Returns boolean

    Whether the resulting link is broken or not.

  • _createHyperlink(match: RegExpMatchArray, options: any): HTMLAnchorElement
  • Replace a hyperlink-like string with an actual HTML <a> tag

    Parameters

    • match: RegExpMatchArray

      The regular expression match

    • options: any

    Returns HTMLAnchorElement

    An HTML element for the document link

  • _onClickContentLink(event: Event): Promise<any>
  • Handle click events on Document Links

    Parameters

    • event: Event

    Returns Promise<any>

  • _onClickInlineRoll(event: MouseEvent): Promise<any>
  • Handle left-mouse clicks on an inline roll, dispatching the formula or displaying the tooltip

    Parameters

    • event: MouseEvent

      The initiating click event

    Returns Promise<any>

  • _onDragContentLink(event: Event): boolean
  • Begin a Drag+Drop workflow for a dynamic content link

    Parameters

    • event: Event

      The originating drag event

    Returns boolean

  • _onDropEditorData(event: DragEvent, editor: TinyMCE): Promise<void>
  • Handle dropping of transferred data onto the active rich text editor

    Parameters

    • event: DragEvent

      The originating drop event which triggered the data transfer

    • editor: TinyMCE

      The TinyMCE editor instance being dropped on

    Returns Promise<void>

Properties

#decoder: HTMLTextAreaElement = ...

A singleton text area used for HTML decoding.

_PARAGRAPH_ELEMENTS: Set<string> = ...

A list of elements that are retained when truncating HTML.