index.tsx


Overview

This file defines a rich text editor component named PromptEditor built on top of the Lexical framework, a modern extensible text editor library by Facebook. The editor supports advanced text editing features including rich text nodes (headings, quotes, code blocks), variables insertion via a custom node (VariableNode), and custom plugins for variable picking, paste handling, and reacting to variable changes.

The PromptEditor component is highly customizable with props such as the initial value, change handlers, placeholder, toolbar visibility, and multi-line editing. It integrates UI elements such as tooltips and icons to enhance user interaction, and uses internationalization (react-i18next) for text strings.

This file is primarily responsible for:


Detailed Explanations

Imports and Dependencies


Types


Functions and Components

1. onError(error: Error): void


2. PromptContent

function PromptContent({
  showToolbar = true,
  multiLine = true,
}: PromptContentProps)

Usage Example:

<PromptContent showToolbar={false} multiLine={false} />

3. PromptEditor

export function PromptEditor({
  value,
  onChange,
  placeholder,
  showToolbar,
  multiLine = true,
  extraOptions,
}: IProps)

Usage Example:

<PromptEditor
  value="Hello world"
  onChange={(val) => console.log(val)}
  placeholder="Type your prompt..."
  showToolbar={true}
  multiLine={false}
/>

Important Implementation Details


Interaction With Other System Parts


Mermaid Diagram

The following diagram shows the component structure and plugin relationships within this file:

componentDiagram
    component PromptEditor {
        +value?: string
        +onChange?: (string) => void
        +placeholder?: ReactNode
        +showToolbar?: boolean
        +multiLine?: boolean
        +extraOptions?: any
        --
        +initialConfig: InitialConfigType
        +onValueChange(editorState)
    }

    component PromptContent {
        +showToolbar?: boolean
        +multiLine?: boolean
        --
        +insertTextAtCursor()
        +handleVariableIconClick()
        +handleBlur()
        +handleFocus()
    }

    component RichTextPlugin
    component LexicalComposer
    component VariablePickerMenuPlugin
    component PasteHandlerPlugin
    component VariableOnChangePlugin
    component LexicalErrorBoundary
    component ContentEditable
    component Tooltip

    PromptEditor --> LexicalComposer
    LexicalComposer --> RichTextPlugin
    RichTextPlugin --> PromptContent
    PromptContent --> ContentEditable
    PromptContent --> Tooltip
    PromptEditor --> VariablePickerMenuPlugin
    PromptEditor --> PasteHandlerPlugin
    PromptEditor --> VariableOnChangePlugin
    RichTextPlugin --> LexicalErrorBoundary

Summary


Additional Notes


End of Documentation for index.tsx