dify/web/app/components/base/prompt-editor/plugins/current-block/node.tsx
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

68 lines
1.8 KiB
TypeScript

import type { NodeKey, SerializedLexicalNode } from 'lexical'
import type { GeneratorType } from '@/app/components/app/configuration/config/automatic/types'
import { DecoratorNode } from 'lexical'
import CurrentBlockComponent from './component'
type SerializedNode = SerializedLexicalNode & { generatorType: GeneratorType }
export class CurrentBlockNode extends DecoratorNode<React.JSX.Element> {
__generatorType: GeneratorType
static override getType(): string {
return 'current-block'
}
static override clone(node: CurrentBlockNode): CurrentBlockNode {
return new CurrentBlockNode(node.__generatorType, node.getKey())
}
override isInline(): boolean {
return true
}
constructor(generatorType: GeneratorType, key?: NodeKey) {
super(key)
this.__generatorType = generatorType
}
override createDOM(): HTMLElement {
const div = document.createElement('div')
div.classList.add('inline-flex', 'items-center', 'align-middle')
return div
}
override updateDOM(): false {
return false
}
override decorate(): React.JSX.Element {
return <CurrentBlockComponent nodeKey={this.getKey()} generatorType={this.getGeneratorType()} />
}
getGeneratorType(): GeneratorType {
const self = this.getLatest()
return self.__generatorType
}
static override importJSON(serializedNode: SerializedNode): CurrentBlockNode {
const node = $createCurrentBlockNode(serializedNode.generatorType)
return node
}
override exportJSON(): SerializedNode {
return {
type: 'current-block',
version: 1,
generatorType: this.getGeneratorType(),
}
}
override getTextContent(): string {
return '{{#current#}}'
}
}
export function $createCurrentBlockNode(type: GeneratorType): CurrentBlockNode {
return new CurrentBlockNode(type)
}