node.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import type { LexicalNode, SerializedLexicalNode } from 'lexical'
  2. import { DecoratorNode } from 'lexical'
  3. import QueryBlockComponent from './component'
  4. export type SerializedNode = SerializedLexicalNode
  5. export class QueryBlockNode extends DecoratorNode<JSX.Element> {
  6. static getType(): string {
  7. return 'query-block'
  8. }
  9. static clone(): QueryBlockNode {
  10. return new QueryBlockNode()
  11. }
  12. isInline(): boolean {
  13. return true
  14. }
  15. createDOM(): HTMLElement {
  16. const div = document.createElement('div')
  17. div.classList.add('inline-flex', 'items-center', 'align-middle')
  18. return div
  19. }
  20. updateDOM(): false {
  21. return false
  22. }
  23. decorate(): JSX.Element {
  24. return <QueryBlockComponent nodeKey={this.getKey()} />
  25. }
  26. static importJSON(): QueryBlockNode {
  27. const node = $createQueryBlockNode()
  28. return node
  29. }
  30. exportJSON(): SerializedNode {
  31. return {
  32. type: 'query-block',
  33. version: 1,
  34. }
  35. }
  36. getTextContent(): string {
  37. return '{{#query#}}'
  38. }
  39. }
  40. export function $createQueryBlockNode(): QueryBlockNode {
  41. return new QueryBlockNode()
  42. }
  43. export function $isQueryBlockNode(
  44. node: QueryBlockNode | LexicalNode | null | undefined,
  45. ): node is QueryBlockNode {
  46. return node instanceof QueryBlockNode
  47. }