component_web_markdown.go 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //go:build js && wasm
  2. package ultraviolet
  3. import (
  4. "syscall/js"
  5. )
  6. type MarkdownComponentWeb struct {
  7. node js.Value
  8. view View
  9. change bool
  10. content string
  11. paragraph bool
  12. }
  13. func NewMarkdownComponentWeb(view View) *MarkdownComponentWeb {
  14. return &MarkdownComponentWeb{
  15. view: view,
  16. change: true,
  17. }
  18. }
  19. // Component
  20. func (this *MarkdownComponentWeb) Build(parent Component) {
  21. this.node = WebBuildDiv(
  22. this.node,
  23. parent,
  24. this.view,
  25. "",
  26. MarkdownConvert(this.content, this.paragraph),
  27. AbstractHandlers{},
  28. )
  29. }
  30. func (this *MarkdownComponentWeb) Invalidate() bool {
  31. result := this.change
  32. this.change = false
  33. return result
  34. }
  35. func (this *MarkdownComponentWeb) Clean() {
  36. WebCleanChildren(this.node)
  37. this.change = true
  38. }
  39. // JS
  40. func (this *MarkdownComponentWeb) Node() js.Value {
  41. return this.node
  42. }
  43. // ComponentMarkdown
  44. func (this *MarkdownComponentWeb) SetMarkdown(content string, paragraph bool) {
  45. this.content = content
  46. this.paragraph = paragraph
  47. }