Files
simple-react-app-kit/packages/lexical/src/content.tsx
T
Maofeng 0d817537be 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.
2026-07-31 15:07:09 +08:00

72 lines
2.0 KiB
TypeScript

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>
)
}