Created
September 27, 2024 17:59
-
-
Save wkentdag/7a973d80e545d94504eabf88b4d6c64f to your computer and use it in GitHub Desktop.
DisableAutoLinkFeature WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FeatureProvider } from '@payloadcms/richtext-lexical' | |
export const DisableAutoLinkFeature = (): FeatureProvider => { | |
return { | |
key: 'disable-auto-link', | |
feature: () => { | |
return { | |
props: null, | |
plugins: [ | |
{ | |
Component: () => | |
import('./plugin').then((module) => module.DisableAutoLinkPlugin), | |
position: 'normal', | |
}, | |
], | |
} | |
}, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' | |
import { AutoLinkNode } from '@payloadcms/richtext-lexical' | |
import { useEffect } from 'react' | |
export function DisableAutoLinkPlugin(): JSX.Element | null { | |
const [editor] = useLexicalComposerContext() | |
useEffect(() => { | |
editor.registerNodeTransform(AutoLinkNode, (autoLinkNode: AutoLinkNode) => { | |
// console.log('AutoLinkNode') | |
// const parent = autoLinkNode.getParent() | |
// const children = autoLinkNode.getChildren() | |
// console.log(parent) | |
// console.log(children) | |
// const p = $createCustomParagraphNode() | |
// parent.append(...children) | |
// console.log('created new nodes') | |
// autoLinkNode.replace(newNode, true).select() | |
// const newTextNode = $createTextNode | |
// console.log('replaced nodes') | |
// const nodeSelection = $createNodeSelection() | |
// $setSelection(nodeSelection) | |
// console.log('set selection') | |
// const childrenLength = children.length | |
// // const replacementNode = $createCustomParagraphNode() | |
// for (let j = childrenLength - 1; j >= 0; j--) { | |
// parent.append(children[j]) | |
// // replacementNode.append(children[j]) | |
// } | |
// parent.append(replacementNode) | |
autoLinkNode.remove(false) | |
// console.log('autolink deleted') | |
}) | |
}, [editor]) | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment