Skip to content

Instantly share code, notes, and snippets.

@wkentdag
Created September 27, 2024 17:59
Show Gist options
  • Save wkentdag/7a973d80e545d94504eabf88b4d6c64f to your computer and use it in GitHub Desktop.
Save wkentdag/7a973d80e545d94504eabf88b4d6c64f to your computer and use it in GitHub Desktop.
DisableAutoLinkFeature WIP
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',
},
],
}
},
}
}
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