Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

node.tsx 1.4KB

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