"use client"; import { AutoLinkNode, LinkNode } from "@lexical/link"; import { ListItemNode, ListNode } from "@lexical/list"; import { LexicalComposer } from "@lexical/react/LexicalComposer"; import { ContentEditable } from "@lexical/react/LexicalContentEditable"; import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"; import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin"; import { HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode"; import { HorizontalRulePlugin } from "@lexical/react/LexicalHorizontalRulePlugin"; import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin"; import { ListPlugin } from "@lexical/react/LexicalListPlugin"; import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"; import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin"; import { TablePlugin } from "@lexical/react/LexicalTablePlugin"; import { HeadingNode, QuoteNode } from "@lexical/rich-text"; import { TableCellNode, TableNode, TableRowNode } from "@lexical/table"; import { cn } from "@suphark/ui/lib/utils"; import { LineBreakNode, ParagraphNode, TextNode } from "lexical"; import { type Ref, useMemo } from "react"; import { StyleNode } from "./nodes/style-node"; import { VariableNode } from "./nodes/variable-node"; import { ImperativeHandlePlugin, type RichTextEditorRef } from "./plugins/imperative-handle-plugin"; import { SyncPlugin } from "./plugins/sync-plugin"; import { TableCellResizerPlugin } from "./plugins/table-cell-resizer-plugin"; import { TableSelectionHighlightPlugin } from "./plugins/table-selection-highlight-plugin"; import { ToolbarPlugin } from "./plugins/toolbar-plugin"; import { VariableSelectionPlugin } from "./plugins/variable-selection-plugin"; import { VariableTypeaheadPlugin } from "./plugins/variable-typeahead-plugin"; import { useRichTextText } from "./rich-text-text"; import { normalizeLinkUrl } from "./rich-text-utils"; import { customStyles, theme } from "./theme"; export type { RichTextEditorRef }; export interface RichTextEditorProps { /** HTML */ value: string; onChange: (value: string) => void; /** ไม่ส่ง = ข้อความจาก UiText (`richText.placeholder`) */ placeholder?: string; /** คลาสของพื้นที่พิมพ์ (เช่น `min-h-64`) */ className?: string; /** สงวนไว้ (ยังไม่มีผล) — คงไว้ให้ API เดิมของ supplychain */ mode?: "template" | "instance"; /** เลื่อนเคอร์เซอร์เข้า/ออกตัวแปร `{{…}}` — ได้ชื่อตัวแปร หรือ null */ onSelectVariable?: (variableName: string | null) => void; /** พิมพ์ `{{` แล้วสร้างตัวแปรได้ (เทมเพลตเอกสาร/อีเมล) — ค่าเริ่มต้น true */ variables?: boolean; /** ref ของ editor (`insertContent`, `isFocused`) — prop ธรรมดาเพราะตัวห่อโหลดแบบ lazy */ editorRef?: Ref; /** ป้ายสำหรับโปรแกรมอ่านจอ เมื่อไม่มี `