event.py 2.8 KB

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