factory_web.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. return NewContainerComponentWeb(optionsContainer.View)
  15. }
  16. func (this *WebFactory) NewButton(options any) Component {
  17. optionsButton := options.(ButtonComponentOptions)
  18. result := NewButtonComponentWeb(optionsButton.View)
  19. if optionsButton.Controller.Handler != nil {
  20. result.SetHandler(optionsButton.Controller.Handler)
  21. }
  22. if optionsButton.Model.Format != "" && optionsButton.Model.Values != nil {
  23. result.SetValue(
  24. optionsButton.Model.Format,
  25. optionsButton.Model.Values,
  26. )
  27. }
  28. return result
  29. }
  30. func (this *WebFactory) NewImage(options any) Component {
  31. optionsImage := options.(ImageComponentOptions)
  32. result := NewImageComponentWeb(optionsImage.View)
  33. if optionsImage.Model.Path != "" {
  34. result.SetPath(optionsImage.Model.Path)
  35. }
  36. return result
  37. }
  38. func (this *WebFactory) NewMarkdown(options any) Component {
  39. optionsMarkdown := options.(MarkdownComponentOptions)
  40. result := NewMarkdownComponentWeb(optionsMarkdown.View)
  41. if optionsMarkdown.Model.Content != "" {
  42. result.SetMarkdown(optionsMarkdown.Model.Content)
  43. }
  44. return result
  45. }
  46. func (this *WebFactory) NewFrame(options any) Component {
  47. optionsFrame := options.(FrameComponentOptions)
  48. result := NewFrameComponentWeb(optionsFrame.View)
  49. if optionsFrame.Model.URL != "" {
  50. result.SetUrl(optionsFrame.Model.URL)
  51. }
  52. return result
  53. }
  54. func (this *WebFactory) NewCode(options any) Component {
  55. optionsCode := options.(CodeComponentOptions)
  56. result := NewCodeComponentWeb(optionsCode.View)
  57. if optionsCode.Model.Language != "" && optionsCode.Model.Content != "" {
  58. result.SetCode(
  59. optionsCode.Model.Language,
  60. optionsCode.Model.Content,
  61. )
  62. }
  63. return result
  64. }