mirror of
https://github.com/langgenius/dify.git
synced 2026-02-16 07:54:40 +08:00
The frontend and backend implementation for the human input node. Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zhsama <torvalds@linux.do>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import type { RequestURLBlockType } from '../../types'
|
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
|
import { mergeRegister } from '@lexical/utils'
|
|
import {
|
|
$insertNodes,
|
|
COMMAND_PRIORITY_EDITOR,
|
|
createCommand,
|
|
} from 'lexical'
|
|
import {
|
|
memo,
|
|
useEffect,
|
|
} from 'react'
|
|
import {
|
|
$createRequestURLBlockNode,
|
|
RequestURLBlockNode,
|
|
} from './node'
|
|
|
|
export const INSERT_REQUEST_URL_BLOCK_COMMAND = createCommand('INSERT_REQUEST_URL_BLOCK_COMMAND')
|
|
export const DELETE_REQUEST_URL_BLOCK_COMMAND = createCommand('DELETE_REQUEST_URL_BLOCK_COMMAND')
|
|
|
|
const RequestURLBlock = memo(({
|
|
onInsert,
|
|
onDelete,
|
|
}: RequestURLBlockType) => {
|
|
const [editor] = useLexicalComposerContext()
|
|
|
|
useEffect(() => {
|
|
if (!editor.hasNodes([RequestURLBlockNode]))
|
|
throw new Error('RequestURLBlockPlugin: RequestURLBlock not registered on editor')
|
|
|
|
return mergeRegister(
|
|
editor.registerCommand(
|
|
INSERT_REQUEST_URL_BLOCK_COMMAND,
|
|
() => {
|
|
const contextBlockNode = $createRequestURLBlockNode()
|
|
|
|
$insertNodes([contextBlockNode])
|
|
if (onInsert)
|
|
onInsert()
|
|
|
|
return true
|
|
},
|
|
COMMAND_PRIORITY_EDITOR,
|
|
),
|
|
editor.registerCommand(
|
|
DELETE_REQUEST_URL_BLOCK_COMMAND,
|
|
() => {
|
|
if (onDelete)
|
|
onDelete()
|
|
|
|
return true
|
|
},
|
|
COMMAND_PRIORITY_EDITOR,
|
|
),
|
|
)
|
|
}, [editor, onInsert, onDelete])
|
|
|
|
return null
|
|
})
|
|
RequestURLBlock.displayName = 'RequestURLBlock'
|
|
|
|
export { RequestURLBlock }
|
|
export { RequestURLBlockNode } from './node'
|
|
export { default as RequestURLBlockReplacementBlock } from './request-url-block-replacement-block'
|