use-tiptap-editor.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package e00_basics
  2. // @snippet_begin(HelloWorldTipTapSample)
  3. import (
  4. "github.com/qor5/ui/tiptap"
  5. "github.com/qor5/web"
  6. . "github.com/theplant/htmlgo"
  7. "github.com/yosssi/gohtml"
  8. )
  9. func HelloWorldTipTap(ctx *web.EventContext) (pr web.PageResponse, err error) {
  10. defaultValue := ctx.R.FormValue("Content1")
  11. if len(defaultValue) == 0 {
  12. defaultValue = `
  13. <h1>Hello</h1>
  14. <p>
  15. This is a nice editor
  16. </p>
  17. <ul>
  18. <li>
  19. <p>
  20. 123
  21. </p>
  22. </li>
  23. <li>
  24. <p>
  25. 456
  26. </p>
  27. </li>
  28. <li>
  29. <p>
  30. 789
  31. </p>
  32. </li>
  33. </ul>
  34. `
  35. }
  36. pr.Body = Div(
  37. tiptap.TipTapEditor().
  38. FieldName("Content1").
  39. Value(defaultValue),
  40. Hr(),
  41. Pre(
  42. gohtml.Format(ctx.R.FormValue("Content1")),
  43. ).Style("background-color: #f8f8f8; padding: 20px;"),
  44. Button("Submit").Style("font-size: 24px").
  45. Attr("@click", web.POST().EventFunc("refresh").Go()),
  46. )
  47. return
  48. }
  49. func refresh(ctx *web.EventContext) (er web.EventResponse, err error) {
  50. er.Reload = true
  51. return
  52. }
  53. var HelloWorldTipTapPB = web.Page(HelloWorldTipTap).
  54. EventFunc("refresh", refresh)
  55. const HelloWorldTipTapPath = "/samples/hello_world_tiptap"
  56. // @snippet_end