feat(lexical): add declarative rich text editor

Introduce @workspace/lexical with composable actions, toolbars, embeds, rich-text nodes, media uploads, selection utilities, HTML serialization, and theme styling.\n\nLocalize built-in controls through MessageDescriptor catalogs for English and Simplified Chinese, while providing an English I18nProvider fallback for standalone editor use. Include focused unit coverage for actions, controls, serialization, plugins, public API, and catalogs.
This commit is contained in:
Maofeng
2026-07-31 15:07:09 +08:00
parent 1fe9c1021a
commit 0d817537be
65 changed files with 7453 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
import type { ComponentProps } from "react"
import { ContentEditable } from "@lexical/react/LexicalContentEditable"
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"
import { cn } from "@workspace/ui/lib/utils"
import { LexicalActionTree } from "./actions-view"
import { useLexicalActions } from "./actions-context"
import { LexicalActionRuntimeProvider } from "./toolbar"
import { useLexicalMessage } from "./i18n"
import { lexicalMessages } from "./messages"
export interface LexicalContentProps {
className?: string
placeholder?: string
}
export type LexicalFooterProps = ComponentProps<"div">
export function LexicalContent({
className,
placeholder,
}: LexicalContentProps) {
const resolvedPlaceholder = useLexicalMessage(
placeholder ?? lexicalMessages.contentPlaceholder
)
return (
<div className="relative">
<RichTextPlugin
contentEditable={
<ContentEditable
aria-placeholder={resolvedPlaceholder}
placeholder={
<div
data-slot="lexical-placeholder"
className="pointer-events-none absolute start-3 top-4 text-sm text-muted-foreground"
>
{resolvedPlaceholder}
</div>
}
className={cn("min-h-52 px-3 py-2 text-sm outline-none", className)}
/>
}
ErrorBoundary={LexicalErrorBoundary}
/>
</div>
)
}
export function LexicalFooter({
className,
children,
...props
}: LexicalFooterProps) {
const actions = useLexicalActions("footer")
if (actions.length === 0 && children == null) return null
return (
<LexicalActionRuntimeProvider>
<div
className={cn("flex items-center gap-1 border-t px-3 py-2", className)}
{...props}
>
<LexicalActionTree items={actions} />
{children}
</div>
</LexicalActionRuntimeProvider>
)
}