mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 10:53:02 +00:00 
			
		
		
		
	 7709d9df20
			
		
	
	
		7709d9df20
		
			
		
	
	
	
	
		
			
			Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: jZonG <jzongcode@gmail.com>
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { LexicalNode, SerializedLexicalNode } from 'lexical'
 | |
| import { DecoratorNode } from 'lexical'
 | |
| import QueryBlockComponent from './component'
 | |
| 
 | |
| export type SerializedNode = SerializedLexicalNode
 | |
| 
 | |
| export class QueryBlockNode extends DecoratorNode<React.JSX.Element> {
 | |
|   static getType(): string {
 | |
|     return 'query-block'
 | |
|   }
 | |
| 
 | |
|   static clone(): QueryBlockNode {
 | |
|     return new QueryBlockNode()
 | |
|   }
 | |
| 
 | |
|   isInline(): boolean {
 | |
|     return true
 | |
|   }
 | |
| 
 | |
|   createDOM(): HTMLElement {
 | |
|     const div = document.createElement('div')
 | |
|     div.classList.add('inline-flex', 'items-center', 'align-middle')
 | |
|     return div
 | |
|   }
 | |
| 
 | |
|   updateDOM(): false {
 | |
|     return false
 | |
|   }
 | |
| 
 | |
|   decorate(): React.JSX.Element {
 | |
|     return <QueryBlockComponent nodeKey={this.getKey()} />
 | |
|   }
 | |
| 
 | |
|   static importJSON(): QueryBlockNode {
 | |
|     const node = $createQueryBlockNode()
 | |
| 
 | |
|     return node
 | |
|   }
 | |
| 
 | |
|   exportJSON(): SerializedNode {
 | |
|     return {
 | |
|       type: 'query-block',
 | |
|       version: 1,
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   getTextContent(): string {
 | |
|     return '{{#query#}}'
 | |
|   }
 | |
| }
 | |
| export function $createQueryBlockNode(): QueryBlockNode {
 | |
|   return new QueryBlockNode()
 | |
| }
 | |
| 
 | |
| export function $isQueryBlockNode(
 | |
|   node: QueryBlockNode | LexicalNode | null | undefined,
 | |
| ): node is QueryBlockNode {
 | |
|   return node instanceof QueryBlockNode
 | |
| }
 |