Extensions
Link
URL validation for link nodes
The Link extension provides URL validation for link nodes in the editor. It wraps Lexical's LinkPlugin with Typix's URL validation.
Demo
Loading preview...
import { EditorContent, EditorRoot, createEditorConfig, defaultExtensionNodes,} from "@typix-editor/react";import { LinkExtension } from "@typix-editor/extension-link";import { theme } from "./theme";import "./style.css";const config = createEditorConfig({ extensionNodes: defaultExtensionNodes, theme,});export default function LinkExample() { return ( <EditorRoot config={config}> <EditorContent placeholder="Select text and use Ctrl+K to add a link..." /> <LinkExtension /> </EditorRoot> );}Installation
pnpm add @typix-editor/extension-linknpm install @typix-editor/extension-linkyarn add @typix-editor/extension-linkSetup
import { LinkExtension } from '@typix-editor/extension-link';
function MyEditor() {
return (
<EditorRoot>
<EditorContent />
<LinkExtension />
</EditorRoot>
);
}LinkNode is included in defaultExtensionNodes, so no additional node registration is needed.
Custom URL validation
<LinkExtension
validateUrl={(url) => {
// Only allow HTTPS URLs
return url.startsWith('https://');
}}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
validateUrl | (url: string) => boolean | validateUrl from core | Custom URL validator function |
Exports
| Export | Type | Description |
|---|---|---|
LinkExtension | Component | The link validation plugin |
LinkExtensionProps | Type | Props type |
Related
- Floating Link — Floating link editor UI
- Auto Link — Auto-detect URLs
- URL Utilities —
sanitizeUrlandvalidateUrl