event.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. """Event-related constants."""
  2. from enum import Enum
  3. from types import SimpleNamespace
  4. class Endpoint(Enum):
  5. """Endpoints for the reflex backend API."""
  6. PING = "ping"
  7. EVENT = "_event"
  8. UPLOAD = "_upload"
  9. AUTH_CODESPACE = "auth-codespace"
  10. HEALTH = "_health"
  11. def __str__(self) -> str:
  12. """Get the string representation of the endpoint.
  13. Returns:
  14. The path for the endpoint.
  15. """
  16. return f"/{self.value}"
  17. def get_url(self) -> str:
  18. """Get the URL for the endpoint.
  19. Returns:
  20. The full URL for the endpoint.
  21. """
  22. # Import here to avoid circular imports.
  23. from reflex.config import get_config
  24. # Get the API URL from the config.
  25. config = get_config()
  26. url = "".join([config.api_url, str(self)])
  27. # The event endpoint is a websocket.
  28. if self == Endpoint.EVENT:
  29. # Replace the protocol with ws.
  30. url = url.replace("https://", "wss://").replace("http://", "ws://")
  31. # Return the url.
  32. return url
  33. class SocketEvent(SimpleNamespace):
  34. """Socket events sent by the reflex backend API."""
  35. PING = "ping"
  36. EVENT = "event"
  37. def __str__(self) -> str:
  38. """Get the string representation of the event name.
  39. Returns:
  40. The event name string.
  41. """
  42. return str(self.value)
  43. class EventTriggers(SimpleNamespace):
  44. """All trigger names used in Reflex."""
  45. ON_FOCUS = "on_focus"
  46. ON_BLUR = "on_blur"
  47. ON_CANCEL = "on_cancel"
  48. ON_CLICK = "on_click"
  49. ON_CHANGE = "on_change"
  50. ON_CHANGE_END = "on_change_end"
  51. ON_CHANGE_START = "on_change_start"
  52. ON_COMPLETE = "on_complete"
  53. ON_CONTEXT_MENU = "on_context_menu"
  54. ON_DOUBLE_CLICK = "on_double_click"
  55. ON_DROP = "on_drop"
  56. ON_EDIT = "on_edit"
  57. ON_KEY_DOWN = "on_key_down"
  58. ON_KEY_UP = "on_key_up"
  59. ON_MOUSE_DOWN = "on_mouse_down"
  60. ON_MOUSE_ENTER = "on_mouse_enter"
  61. ON_MOUSE_LEAVE = "on_mouse_leave"
  62. ON_MOUSE_MOVE = "on_mouse_move"
  63. ON_MOUSE_OUT = "on_mouse_out"
  64. ON_MOUSE_OVER = "on_mouse_over"
  65. ON_MOUSE_UP = "on_mouse_up"
  66. ON_OPEN_CHANGE = "on_open_change"
  67. ON_OPEN_AUTO_FOCUS = "on_open_auto_focus"
  68. ON_CLOSE_AUTO_FOCUS = "on_close_auto_focus"
  69. ON_FOCUS_OUTSIDE = "on_focus_outside"
  70. ON_ESCAPE_KEY_DOWN = "on_escape_key_down"
  71. ON_POINTER_DOWN_OUTSIDE = "on_pointer_down_outside"
  72. ON_INTERACT_OUTSIDE = "on_interact_outside"
  73. ON_SCROLL = "on_scroll"
  74. ON_SUBMIT = "on_submit"
  75. ON_MOUNT = "on_mount"
  76. ON_UNMOUNT = "on_unmount"
  77. ON_CLEAR_SERVER_ERRORS = "on_clear_server_errors"
  78. ON_VALUE_COMMIT = "on_value_commit"
  79. ON_SELECT = "on_select"
  80. ON_ANIMATION_START = "on_animation_start"
  81. ON_ANIMATION_END = "on_animation_end"