factory_web.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //go:build js && wasm
  2. package ultraviolet
  3. type WebFactory struct {
  4. }
  5. func NewWebFactory() Factory {
  6. return &WebFactory{}
  7. }
  8. func (this *WebFactory) NewRoot(options any) Component {
  9. optionsRoot := options.(RootComponentOptions)
  10. return NewRootComponentWeb(optionsRoot.View)
  11. }
  12. func (this *WebFactory) NewContainer(options any) Component {
  13. optionsContainer := options.(ContainerComponentOptions)
  14. result := NewContainerComponentWeb(optionsContainer.View)
  15. if optionsContainer.Controller.Handler != nil {
  16. result.SetHandler(optionsContainer.Controller.Handler)
  17. }
  18. if optionsContainer.Model.Value != nil {
  19. result.SetValue(optionsContainer.Model.Value)
  20. }
  21. return result
  22. }
  23. func (this *WebFactory) NewText(options any) Component {
  24. optionsText := options.(TextComponentOptions)
  25. result := NewTextComponentWeb(optionsText.View)
  26. if optionsText.Model.Format != "" && optionsText.Model.Values != nil {
  27. result.SetValue(
  28. optionsText.Model.Format,
  29. optionsText.Model.Values,
  30. )
  31. }
  32. return result
  33. }
  34. func (this *WebFactory) NewButton(options any) Component {
  35. optionsButton := options.(ButtonComponentOptions)
  36. result := NewButtonComponentWeb(optionsButton.View)
  37. if optionsButton.Controller.Handler != nil {
  38. result.SetHandler(optionsButton.Controller.Handler)
  39. }
  40. if optionsButton.Model.Format != "" && optionsButton.Model.Values != nil {
  41. result.SetValue(
  42. optionsButton.Model.Format,
  43. optionsButton.Model.Values,
  44. )
  45. }
  46. return result
  47. }
  48. func (this *WebFactory) NewImage(options any) Component {
  49. optionsImage := options.(ImageComponentOptions)
  50. result := NewImageComponentWeb(optionsImage.View)
  51. if optionsImage.Model.Path != "" {
  52. result.SetPath(optionsImage.Model.Path)
  53. }
  54. if optionsImage.Model.Width != 0 {
  55. result.SetWidth(optionsImage.Model.Width)
  56. }
  57. return result
  58. }
  59. func (this *WebFactory) NewMarkdown(options any) Component {
  60. optionsMarkdown := options.(MarkdownComponentOptions)
  61. result := NewMarkdownComponentWeb(optionsMarkdown.View)
  62. if optionsMarkdown.Model.Content != "" {
  63. result.SetMarkdown(optionsMarkdown.Model.Content, optionsMarkdown.Model.Paragraph)
  64. }
  65. return result
  66. }
  67. func (this *WebFactory) NewFrame(options any) Component {
  68. optionsFrame := options.(FrameComponentOptions)
  69. result := NewFrameComponentWeb(optionsFrame.View)
  70. if optionsFrame.Model.URL != "" {
  71. result.SetUrl(optionsFrame.Model.URL)
  72. }
  73. return result
  74. }
  75. func (this *WebFactory) NewCode(options any) Component {
  76. optionsCode := options.(CodeComponentOptions)
  77. result := NewCodeComponentWeb(optionsCode.View)
  78. if optionsCode.Model.Language != "" && optionsCode.Model.Content != "" {
  79. result.SetCode(
  80. optionsCode.Model.Language,
  81. optionsCode.Model.Content,
  82. )
  83. }
  84. return result
  85. }