component_web_markdown.go 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }
  12. func NewMarkdownComponentWeb(view View) *MarkdownComponentWeb {
  13. return &MarkdownComponentWeb{
  14. view: view,
  15. change: true,
  16. }
  17. }
  18. // Component
  19. func (this *MarkdownComponentWeb) Build(parent Component) {
  20. this.node = WebBuildDiv(
  21. this.node,
  22. parent,
  23. this.view,
  24. "",
  25. MarkdownConvert(this.content),
  26. AbstractHandlers{},
  27. )
  28. }
  29. func (this *MarkdownComponentWeb) Invalidate() bool {
  30. result := this.change
  31. this.change = false
  32. return result
  33. }
  34. func (this *MarkdownComponentWeb) Clean() {
  35. WebCleanChildren(this.node)
  36. this.change = true
  37. }
  38. // JS
  39. func (this *MarkdownComponentWeb) Node() js.Value {
  40. return this.node
  41. }
  42. // ComponentMarkdown
  43. func (this *MarkdownComponentWeb) SetMarkdown(content string) {
  44. this.content = content
  45. }