dify/web/app/components/base/prompt-editor/plugins/roster-reference-block/node.tsx
盐粒 Yanli 3f2d22ec0f
feat(agent-v2): sync nightly updates to main (#37599)
Co-authored-by: Jingyi-Dify <jingyi.qi@dify.ai>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: Bond Zhu <783504079@qq.com>
Co-authored-by: Yansong Zhang <916125788@qq.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-06-18 05:03:34 +00:00

77 lines
1.9 KiB
TypeScript

import type {
LexicalNode,
NodeKey,
SerializedLexicalNode,
} from 'lexical'
import type { JSX } from 'react'
import {
$applyNodeReplacement,
DecoratorNode,
} from 'lexical'
import RosterReferenceBlockComponent from './component'
type SerializedRosterReferenceBlockNode = SerializedLexicalNode & {
text: string
}
export class RosterReferenceBlockNode extends DecoratorNode<JSX.Element> {
__text: string
static override getType(): string {
return 'roster-reference-block'
}
static override clone(node: RosterReferenceBlockNode): RosterReferenceBlockNode {
return new RosterReferenceBlockNode(node.__text, node.__key)
}
constructor(text: string, key?: NodeKey) {
super(key)
this.__text = text
}
override isInline(): boolean {
return true
}
override createDOM(): HTMLElement {
const span = document.createElement('span')
span.classList.add('inline-flex', 'items-center', 'align-middle')
return span
}
override updateDOM(): false {
return false
}
override decorate(): JSX.Element {
return <RosterReferenceBlockComponent text={this.getTextContent()} />
}
static override importJSON(serializedNode: SerializedRosterReferenceBlockNode): RosterReferenceBlockNode {
return $createRosterReferenceBlockNode(serializedNode.text)
}
override exportJSON(): SerializedRosterReferenceBlockNode {
return {
text: this.getTextContent(),
type: 'roster-reference-block',
version: 1,
}
}
override getTextContent(): string {
return this.getLatest().__text
}
}
export function $createRosterReferenceBlockNode(text = ''): RosterReferenceBlockNode {
return $applyNodeReplacement(new RosterReferenceBlockNode(text))
}
export function $isRosterReferenceBlockNode(
node: LexicalNode | null | undefined,
): node is RosterReferenceBlockNode {
return node instanceof RosterReferenceBlockNode
}