Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

node.tsx 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type { LexicalNode, NodeKey, SerializedLexicalNode } from 'lexical'
  2. import { DecoratorNode } from 'lexical'
  3. import CurrentBlockComponent from './component'
  4. import type { GeneratorType } from '@/app/components/app/configuration/config/automatic/types'
  5. export type SerializedNode = SerializedLexicalNode & { generatorType: GeneratorType; }
  6. export class CurrentBlockNode extends DecoratorNode<React.JSX.Element> {
  7. __generatorType: GeneratorType
  8. static getType(): string {
  9. return 'current-block'
  10. }
  11. static clone(node: CurrentBlockNode): CurrentBlockNode {
  12. return new CurrentBlockNode(node.__generatorType, node.getKey())
  13. }
  14. isInline(): boolean {
  15. return true
  16. }
  17. constructor(generatorType: GeneratorType, key?: NodeKey) {
  18. super(key)
  19. this.__generatorType = generatorType
  20. }
  21. createDOM(): HTMLElement {
  22. const div = document.createElement('div')
  23. div.classList.add('inline-flex', 'items-center', 'align-middle')
  24. return div
  25. }
  26. updateDOM(): false {
  27. return false
  28. }
  29. decorate(): React.JSX.Element {
  30. return (
  31. <CurrentBlockComponent
  32. nodeKey={this.getKey()}
  33. generatorType={this.getGeneratorType()}
  34. />
  35. )
  36. }
  37. getGeneratorType(): GeneratorType {
  38. const self = this.getLatest()
  39. return self.__generatorType
  40. }
  41. static importJSON(serializedNode: SerializedNode): CurrentBlockNode {
  42. const node = $createCurrentBlockNode(serializedNode.generatorType)
  43. return node
  44. }
  45. exportJSON(): SerializedNode {
  46. return {
  47. type: 'current-block',
  48. version: 1,
  49. generatorType: this.getGeneratorType(),
  50. }
  51. }
  52. getTextContent(): string {
  53. return '{{#current#}}'
  54. }
  55. }
  56. export function $createCurrentBlockNode(type: GeneratorType): CurrentBlockNode {
  57. return new CurrentBlockNode(type)
  58. }
  59. export function $isCurrentBlockNode(
  60. node: CurrentBlockNode | LexicalNode | null | undefined,
  61. ): boolean {
  62. return node instanceof CurrentBlockNode
  63. }