feat: disable mention input and paste rules temporarily
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { formatNpub } from '@/lib/pubkey'
|
import { formatNpub } from '@/lib/pubkey'
|
||||||
import { ExtendedRegExpMatchArray, InputRule, PasteRule, Range, SingleCommands } from '@tiptap/core'
|
|
||||||
import Mention from '@tiptap/extension-mention'
|
import Mention from '@tiptap/extension-mention'
|
||||||
import { ReactNodeViewRenderer } from '@tiptap/react'
|
import { ReactNodeViewRenderer } from '@tiptap/react'
|
||||||
import MentionNode from './MentionNode'
|
import MentionNode from './MentionNode'
|
||||||
@@ -12,7 +11,7 @@ declare module '@tiptap/core' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MENTION_REGEX = /(nostr:)?(npub1[a-z0-9]{58}|nprofile1[a-z0-9]+)/g
|
// const MENTION_REGEX = /(nostr:)?(npub1[a-z0-9]{58}|nprofile1[a-z0-9]+)/g
|
||||||
|
|
||||||
const CustomMention = Mention.extend({
|
const CustomMention = Mention.extend({
|
||||||
selectable: true,
|
selectable: true,
|
||||||
@@ -48,45 +47,45 @@ const CustomMention = Mention.extend({
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
addInputRules() {
|
|
||||||
return [
|
|
||||||
new InputRule({
|
|
||||||
find: MENTION_REGEX,
|
|
||||||
handler: (props) => handler(props)
|
|
||||||
})
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
addPasteRules() {
|
|
||||||
return [
|
|
||||||
new PasteRule({
|
|
||||||
find: MENTION_REGEX,
|
|
||||||
handler: (props) => handler(props)
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addInputRules() {
|
||||||
|
// return [
|
||||||
|
// new InputRule({
|
||||||
|
// find: MENTION_REGEX,
|
||||||
|
// handler: (props) => handler(props)
|
||||||
|
// })
|
||||||
|
// ]
|
||||||
|
// },
|
||||||
|
|
||||||
|
// addPasteRules() {
|
||||||
|
// return [
|
||||||
|
// new PasteRule({
|
||||||
|
// find: MENTION_REGEX,
|
||||||
|
// handler: (props) => handler(props)
|
||||||
|
// })
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
export default CustomMention
|
export default CustomMention
|
||||||
|
|
||||||
function handler({
|
// function handler({
|
||||||
range,
|
// range,
|
||||||
match,
|
// match,
|
||||||
commands
|
// commands
|
||||||
}: {
|
// }: {
|
||||||
commands: SingleCommands
|
// commands: SingleCommands
|
||||||
match: ExtendedRegExpMatchArray
|
// match: ExtendedRegExpMatchArray
|
||||||
range: Range
|
// range: Range
|
||||||
}) {
|
// }) {
|
||||||
const mention = match[0]
|
// const mention = match[0]
|
||||||
if (!mention) return
|
// if (!mention) return
|
||||||
const npub = mention.replace('nostr:', '')
|
// const npub = mention.replace('nostr:', '')
|
||||||
|
|
||||||
const matchLength = mention.length
|
// const matchLength = mention.length
|
||||||
const end = range.to
|
// const end = range.to
|
||||||
const start = Math.max(0, end - matchLength)
|
// const start = Math.max(0, end - matchLength)
|
||||||
|
|
||||||
commands.deleteRange({ from: start, to: end })
|
// commands.deleteRange({ from: start, to: end })
|
||||||
commands.createMention(npub)
|
// commands.createMention(npub)
|
||||||
}
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user