reflex 0.6.4a3__py3-none-any.whl → 0.6.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of reflex might be problematic. Click here for more details.

Files changed (228) hide show
  1. reflex/.templates/jinja/web/pages/custom_component.js.jinja2 +0 -14
  2. reflex/.templates/jinja/web/pages/utils.js.jinja2 +4 -8
  3. reflex/.templates/web/components/shiki/code.js +16 -11
  4. reflex/.templates/web/utils/state.js +29 -21
  5. reflex/__init__.py +4 -0
  6. reflex/__init__.pyi +4 -0
  7. reflex/app.py +148 -154
  8. reflex/app_mixins/lifespan.py +5 -1
  9. reflex/app_mixins/middleware.py +3 -1
  10. reflex/app_mixins/mixin.py +3 -2
  11. reflex/base.py +2 -4
  12. reflex/compiler/compiler.py +111 -37
  13. reflex/components/base/app_wrap.pyi +17 -17
  14. reflex/components/base/bare.py +72 -3
  15. reflex/components/base/body.pyi +17 -17
  16. reflex/components/base/document.pyi +81 -81
  17. reflex/components/base/error_boundary.pyi +25 -18
  18. reflex/components/base/fragment.pyi +17 -17
  19. reflex/components/base/head.pyi +33 -33
  20. reflex/components/base/link.pyi +33 -33
  21. reflex/components/base/meta.pyi +65 -65
  22. reflex/components/base/script.py +4 -4
  23. reflex/components/base/script.pyi +23 -20
  24. reflex/components/component.py +250 -31
  25. reflex/components/core/banner.py +1 -1
  26. reflex/components/core/banner.pyi +81 -81
  27. reflex/components/core/client_side_routing.pyi +33 -33
  28. reflex/components/core/clipboard.py +2 -2
  29. reflex/components/core/clipboard.pyi +24 -18
  30. reflex/components/core/debounce.py +2 -2
  31. reflex/components/core/debounce.pyi +18 -18
  32. reflex/components/core/html.pyi +17 -17
  33. reflex/components/core/upload.py +90 -28
  34. reflex/components/core/upload.pyi +128 -72
  35. reflex/components/datadisplay/code.py +55 -40
  36. reflex/components/datadisplay/code.pyi +46 -44
  37. reflex/components/datadisplay/dataeditor.py +21 -20
  38. reflex/components/datadisplay/dataeditor.pyi +103 -35
  39. reflex/components/datadisplay/shiki_code_block.py +60 -27
  40. reflex/components/datadisplay/shiki_code_block.pyi +86 -65
  41. reflex/components/dynamic.py +9 -5
  42. reflex/components/el/element.pyi +17 -17
  43. reflex/components/el/elements/base.pyi +17 -17
  44. reflex/components/el/elements/forms.py +12 -3
  45. reflex/components/el/elements/forms.pyi +293 -233
  46. reflex/components/el/elements/inline.pyi +449 -449
  47. reflex/components/el/elements/media.pyi +401 -401
  48. reflex/components/el/elements/metadata.pyi +97 -97
  49. reflex/components/el/elements/other.pyi +113 -113
  50. reflex/components/el/elements/scripts.pyi +49 -49
  51. reflex/components/el/elements/sectioning.pyi +241 -241
  52. reflex/components/el/elements/tables.pyi +161 -161
  53. reflex/components/el/elements/typography.pyi +241 -241
  54. reflex/components/gridjs/datatable.pyi +33 -33
  55. reflex/components/lucide/icon.py +1 -1
  56. reflex/components/lucide/icon.pyi +33 -33
  57. reflex/components/markdown/markdown.py +180 -49
  58. reflex/components/markdown/markdown.pyi +36 -19
  59. reflex/components/moment/moment.py +17 -21
  60. reflex/components/moment/moment.pyi +26 -21
  61. reflex/components/next/base.pyi +17 -17
  62. reflex/components/next/image.py +3 -3
  63. reflex/components/next/image.pyi +21 -19
  64. reflex/components/next/link.pyi +17 -17
  65. reflex/components/next/video.pyi +17 -17
  66. reflex/components/plotly/plotly.py +79 -78
  67. reflex/components/plotly/plotly.pyi +91 -41
  68. reflex/components/props.py +34 -0
  69. reflex/components/radix/primitives/accordion.py +15 -8
  70. reflex/components/radix/primitives/accordion.pyi +121 -118
  71. reflex/components/radix/primitives/base.pyi +33 -33
  72. reflex/components/radix/primitives/drawer.py +41 -20
  73. reflex/components/radix/primitives/drawer.pyi +279 -190
  74. reflex/components/radix/primitives/form.py +2 -2
  75. reflex/components/radix/primitives/form.pyi +200 -167
  76. reflex/components/radix/primitives/progress.pyi +81 -81
  77. reflex/components/radix/primitives/slider.pyi +89 -83
  78. reflex/components/radix/themes/base.py +30 -1
  79. reflex/components/radix/themes/base.pyi +286 -113
  80. reflex/components/radix/themes/color_mode.py +17 -9
  81. reflex/components/radix/themes/color_mode.pyi +68 -56
  82. reflex/components/radix/themes/components/alert_dialog.py +8 -5
  83. reflex/components/radix/themes/components/alert_dialog.pyi +125 -117
  84. reflex/components/radix/themes/components/aspect_ratio.pyi +17 -17
  85. reflex/components/radix/themes/components/avatar.py +1 -5
  86. reflex/components/radix/themes/components/avatar.pyi +17 -17
  87. reflex/components/radix/themes/components/badge.py +1 -5
  88. reflex/components/radix/themes/components/badge.pyi +17 -17
  89. reflex/components/radix/themes/components/button.pyi +18 -21
  90. reflex/components/radix/themes/components/callout.py +1 -4
  91. reflex/components/radix/themes/components/callout.pyi +81 -81
  92. reflex/components/radix/themes/components/card.py +1 -3
  93. reflex/components/radix/themes/components/card.pyi +17 -17
  94. reflex/components/radix/themes/components/checkbox.py +4 -8
  95. reflex/components/radix/themes/components/checkbox.pyi +61 -52
  96. reflex/components/radix/themes/components/checkbox_cards.pyi +33 -33
  97. reflex/components/radix/themes/components/checkbox_group.pyi +33 -33
  98. reflex/components/radix/themes/components/context_menu.py +121 -28
  99. reflex/components/radix/themes/components/context_menu.pyi +250 -147
  100. reflex/components/radix/themes/components/data_list.pyi +65 -65
  101. reflex/components/radix/themes/components/dialog.py +11 -11
  102. reflex/components/radix/themes/components/dialog.pyi +135 -120
  103. reflex/components/radix/themes/components/dropdown_menu.py +14 -25
  104. reflex/components/radix/themes/components/dropdown_menu.pyi +157 -145
  105. reflex/components/radix/themes/components/hover_card.py +19 -7
  106. reflex/components/radix/themes/components/hover_card.pyi +102 -67
  107. reflex/components/radix/themes/components/icon_button.pyi +18 -21
  108. reflex/components/radix/themes/components/inset.py +1 -3
  109. reflex/components/radix/themes/components/inset.pyi +17 -17
  110. reflex/components/radix/themes/components/popover.py +22 -13
  111. reflex/components/radix/themes/components/popover.pyi +98 -72
  112. reflex/components/radix/themes/components/progress.pyi +17 -17
  113. reflex/components/radix/themes/components/radio.pyi +17 -17
  114. reflex/components/radix/themes/components/radio_cards.py +2 -2
  115. reflex/components/radix/themes/components/radio_cards.pyi +37 -34
  116. reflex/components/radix/themes/components/radio_group.py +3 -7
  117. reflex/components/radix/themes/components/radio_group.pyi +69 -66
  118. reflex/components/radix/themes/components/scroll_area.py +1 -3
  119. reflex/components/radix/themes/components/scroll_area.pyi +17 -17
  120. reflex/components/radix/themes/components/segmented_control.pyi +37 -34
  121. reflex/components/radix/themes/components/select.py +7 -11
  122. reflex/components/radix/themes/components/select.pyi +175 -154
  123. reflex/components/radix/themes/components/separator.py +1 -4
  124. reflex/components/radix/themes/components/separator.pyi +17 -17
  125. reflex/components/radix/themes/components/skeleton.pyi +17 -17
  126. reflex/components/radix/themes/components/slider.py +12 -21
  127. reflex/components/radix/themes/components/slider.pyi +47 -25
  128. reflex/components/radix/themes/components/spinner.py +1 -4
  129. reflex/components/radix/themes/components/spinner.pyi +17 -17
  130. reflex/components/radix/themes/components/switch.py +3 -6
  131. reflex/components/radix/themes/components/switch.pyi +21 -18
  132. reflex/components/radix/themes/components/table.py +21 -5
  133. reflex/components/radix/themes/components/table.pyi +392 -116
  134. reflex/components/radix/themes/components/tabs.py +3 -6
  135. reflex/components/radix/themes/components/tabs.pyi +89 -83
  136. reflex/components/radix/themes/components/text_area.py +1 -5
  137. reflex/components/radix/themes/components/text_area.pyi +43 -20
  138. reflex/components/radix/themes/components/text_field.py +1 -5
  139. reflex/components/radix/themes/components/text_field.pyi +101 -55
  140. reflex/components/radix/themes/components/tooltip.py +5 -7
  141. reflex/components/radix/themes/components/tooltip.pyi +25 -22
  142. reflex/components/radix/themes/layout/base.py +2 -27
  143. reflex/components/radix/themes/layout/base.pyi +82 -82
  144. reflex/components/radix/themes/layout/box.pyi +17 -17
  145. reflex/components/radix/themes/layout/center.pyi +17 -17
  146. reflex/components/radix/themes/layout/container.pyi +17 -17
  147. reflex/components/radix/themes/layout/flex.py +1 -6
  148. reflex/components/radix/themes/layout/flex.pyi +17 -17
  149. reflex/components/radix/themes/layout/grid.py +1 -6
  150. reflex/components/radix/themes/layout/grid.pyi +17 -17
  151. reflex/components/radix/themes/layout/list.py +20 -15
  152. reflex/components/radix/themes/layout/list.pyi +175 -92
  153. reflex/components/radix/themes/layout/section.pyi +17 -17
  154. reflex/components/radix/themes/layout/spacer.pyi +17 -17
  155. reflex/components/radix/themes/layout/stack.py +6 -6
  156. reflex/components/radix/themes/layout/stack.pyi +91 -62
  157. reflex/components/radix/themes/typography/blockquote.py +2 -8
  158. reflex/components/radix/themes/typography/blockquote.pyi +17 -17
  159. reflex/components/radix/themes/typography/code.py +4 -10
  160. reflex/components/radix/themes/typography/code.pyi +19 -18
  161. reflex/components/radix/themes/typography/heading.py +4 -11
  162. reflex/components/radix/themes/typography/heading.pyi +19 -18
  163. reflex/components/radix/themes/typography/link.py +4 -10
  164. reflex/components/radix/themes/typography/link.pyi +19 -18
  165. reflex/components/radix/themes/typography/text.py +4 -11
  166. reflex/components/radix/themes/typography/text.pyi +115 -114
  167. reflex/components/react_player/audio.pyi +58 -33
  168. reflex/components/react_player/react_player.py +17 -17
  169. reflex/components/react_player/react_player.pyi +55 -33
  170. reflex/components/react_player/video.pyi +58 -33
  171. reflex/components/recharts/cartesian.py +45 -45
  172. reflex/components/recharts/cartesian.pyi +389 -304
  173. reflex/components/recharts/charts.py +22 -22
  174. reflex/components/recharts/charts.pyi +226 -179
  175. reflex/components/recharts/general.py +26 -27
  176. reflex/components/recharts/general.pyi +106 -99
  177. reflex/components/recharts/polar.py +33 -33
  178. reflex/components/recharts/polar.pyi +70 -64
  179. reflex/components/recharts/recharts.pyi +33 -33
  180. reflex/components/sonner/toast.py +9 -36
  181. reflex/components/sonner/toast.pyi +20 -24
  182. reflex/components/suneditor/editor.py +8 -8
  183. reflex/components/suneditor/editor.pyi +50 -25
  184. reflex/components/tags/iter_tag.py +1 -10
  185. reflex/components/tags/tag.py +1 -4
  186. reflex/config.py +198 -35
  187. reflex/constants/__init__.py +4 -16
  188. reflex/constants/base.py +7 -14
  189. reflex/constants/colors.py +0 -1
  190. reflex/constants/installer.py +12 -7
  191. reflex/constants/state.py +4 -0
  192. reflex/custom_components/custom_components.py +6 -6
  193. reflex/event.py +486 -241
  194. reflex/experimental/client_state.py +9 -9
  195. reflex/experimental/layout.py +2 -2
  196. reflex/experimental/layout.pyi +95 -87
  197. reflex/experimental/misc.py +1 -1
  198. reflex/istate/__init__.py +1 -0
  199. reflex/istate/proxy.py +33 -0
  200. reflex/istate/wrappers.py +27 -0
  201. reflex/model.py +7 -7
  202. reflex/page.py +2 -1
  203. reflex/reflex.py +142 -8
  204. reflex/state.py +133 -46
  205. reflex/testing.py +9 -7
  206. reflex/utils/console.py +0 -1
  207. reflex/utils/exceptions.py +31 -3
  208. reflex/utils/exec.py +33 -14
  209. reflex/utils/format.py +15 -12
  210. reflex/utils/net.py +1 -1
  211. reflex/utils/path_ops.py +2 -2
  212. reflex/utils/prerequisites.py +82 -46
  213. reflex/utils/pyi_generator.py +63 -20
  214. reflex/utils/registry.py +1 -1
  215. reflex/utils/serializers.py +75 -36
  216. reflex/utils/telemetry.py +3 -2
  217. reflex/utils/types.py +125 -10
  218. reflex/vars/base.py +131 -119
  219. reflex/vars/function.py +59 -12
  220. reflex/vars/number.py +3 -1
  221. reflex/vars/object.py +30 -24
  222. reflex/vars/sequence.py +7 -7
  223. {reflex-0.6.4a3.dist-info → reflex-0.6.5.dist-info}/METADATA +3 -3
  224. reflex-0.6.5.dist-info/RECORD +394 -0
  225. reflex-0.6.4a3.dist-info/RECORD +0 -391
  226. {reflex-0.6.4a3.dist-info → reflex-0.6.5.dist-info}/LICENSE +0 -0
  227. {reflex-0.6.4a3.dist-info → reflex-0.6.5.dist-info}/WHEEL +0 -0
  228. {reflex-0.6.4a3.dist-info → reflex-0.6.5.dist-info}/entry_points.txt +0 -0
@@ -6,13 +6,10 @@
6
6
  from pathlib import Path
7
7
  from typing import Any, ClassVar, Dict, List, Optional, Union, overload
8
8
 
9
+ from reflex.components.base.fragment import Fragment
9
10
  from reflex.components.component import Component, ComponentNamespace, MemoizationLeaf
10
11
  from reflex.constants import Dirs
11
- from reflex.event import (
12
- CallableEventSpec,
13
- EventSpec,
14
- EventType,
15
- )
12
+ from reflex.event import BASE_STATE, CallableEventSpec, EventSpec, EventType
16
13
  from reflex.style import Style
17
14
  from reflex.utils.imports import ImportVar
18
15
  from reflex.vars import VarData
@@ -53,22 +50,22 @@ class UploadFilesProvider(Component):
53
50
  id: Optional[Any] = None,
54
51
  class_name: Optional[Any] = None,
55
52
  autofocus: Optional[bool] = None,
56
- custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
57
- on_blur: Optional[EventType[[]]] = None,
58
- on_click: Optional[EventType[[]]] = None,
59
- on_context_menu: Optional[EventType[[]]] = None,
60
- on_double_click: Optional[EventType[[]]] = None,
61
- on_focus: Optional[EventType[[]]] = None,
62
- on_mount: Optional[EventType[[]]] = None,
63
- on_mouse_down: Optional[EventType[[]]] = None,
64
- on_mouse_enter: Optional[EventType[[]]] = None,
65
- on_mouse_leave: Optional[EventType[[]]] = None,
66
- on_mouse_move: Optional[EventType[[]]] = None,
67
- on_mouse_out: Optional[EventType[[]]] = None,
68
- on_mouse_over: Optional[EventType[[]]] = None,
69
- on_mouse_up: Optional[EventType[[]]] = None,
70
- on_scroll: Optional[EventType[[]]] = None,
71
- on_unmount: Optional[EventType[[]]] = None,
53
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
54
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
55
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
56
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
57
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
58
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
59
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
60
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
61
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
62
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
63
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
64
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
65
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
66
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
67
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
68
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
72
69
  **props,
73
70
  ) -> "UploadFilesProvider":
74
71
  """Create the component.
@@ -88,6 +85,56 @@ class UploadFilesProvider(Component):
88
85
  """
89
86
  ...
90
87
 
88
+ class GhostUpload(Fragment):
89
+ @overload
90
+ @classmethod
91
+ def create( # type: ignore
92
+ cls,
93
+ *children,
94
+ style: Optional[Style] = None,
95
+ key: Optional[Any] = None,
96
+ id: Optional[Any] = None,
97
+ class_name: Optional[Any] = None,
98
+ autofocus: Optional[bool] = None,
99
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
100
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
101
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
102
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
103
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
104
+ on_drop: Optional[
105
+ Union[EventType[[], BASE_STATE], EventType[[Any], BASE_STATE]]
106
+ ] = None,
107
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
108
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
109
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
110
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
111
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
112
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
113
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
114
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
115
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
116
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
117
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
118
+ **props,
119
+ ) -> "GhostUpload":
120
+ """Create the component.
121
+
122
+ Args:
123
+ *children: The children of the component.
124
+ on_drop: Fired when files are dropped.
125
+ style: The style of the component.
126
+ key: A unique key for the component.
127
+ id: The id for the component.
128
+ class_name: The class name for the component.
129
+ autofocus: Whether the component should take the focus once the page is loaded
130
+ custom_attrs: custom attribute
131
+ **props: The props of the component.
132
+
133
+ Returns:
134
+ The component.
135
+ """
136
+ ...
137
+
91
138
  class Upload(MemoizationLeaf):
92
139
  is_used: ClassVar[bool] = False
93
140
 
@@ -110,23 +157,25 @@ class Upload(MemoizationLeaf):
110
157
  id: Optional[Any] = None,
111
158
  class_name: Optional[Any] = None,
112
159
  autofocus: Optional[bool] = None,
113
- custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
114
- on_blur: Optional[EventType[[]]] = None,
115
- on_click: Optional[EventType[[]]] = None,
116
- on_context_menu: Optional[EventType[[]]] = None,
117
- on_double_click: Optional[EventType[[]]] = None,
118
- on_drop: Optional[EventType[Any]] = None,
119
- on_focus: Optional[EventType[[]]] = None,
120
- on_mount: Optional[EventType[[]]] = None,
121
- on_mouse_down: Optional[EventType[[]]] = None,
122
- on_mouse_enter: Optional[EventType[[]]] = None,
123
- on_mouse_leave: Optional[EventType[[]]] = None,
124
- on_mouse_move: Optional[EventType[[]]] = None,
125
- on_mouse_out: Optional[EventType[[]]] = None,
126
- on_mouse_over: Optional[EventType[[]]] = None,
127
- on_mouse_up: Optional[EventType[[]]] = None,
128
- on_scroll: Optional[EventType[[]]] = None,
129
- on_unmount: Optional[EventType[[]]] = None,
160
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
161
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
162
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
163
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
164
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
165
+ on_drop: Optional[
166
+ Union[EventType[[], BASE_STATE], EventType[[Any], BASE_STATE]]
167
+ ] = None,
168
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
169
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
170
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
171
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
172
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
173
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
174
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
175
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
176
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
177
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
178
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
130
179
  **props,
131
180
  ) -> "Upload":
132
181
  """Create an upload component.
@@ -142,6 +191,7 @@ class Upload(MemoizationLeaf):
142
191
  no_click: Whether to disable click to upload.
143
192
  no_drag: Whether to disable drag and drop.
144
193
  no_keyboard: Whether to disable using the space/enter keys to upload.
194
+ on_drop: Fired when files are dropped.
145
195
  style: The style of the component.
146
196
  key: A unique key for the component.
147
197
  id: The id for the component.
@@ -175,23 +225,25 @@ class StyledUpload(Upload):
175
225
  id: Optional[Any] = None,
176
226
  class_name: Optional[Any] = None,
177
227
  autofocus: Optional[bool] = None,
178
- custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
179
- on_blur: Optional[EventType[[]]] = None,
180
- on_click: Optional[EventType[[]]] = None,
181
- on_context_menu: Optional[EventType[[]]] = None,
182
- on_double_click: Optional[EventType[[]]] = None,
183
- on_drop: Optional[EventType[Any]] = None,
184
- on_focus: Optional[EventType[[]]] = None,
185
- on_mount: Optional[EventType[[]]] = None,
186
- on_mouse_down: Optional[EventType[[]]] = None,
187
- on_mouse_enter: Optional[EventType[[]]] = None,
188
- on_mouse_leave: Optional[EventType[[]]] = None,
189
- on_mouse_move: Optional[EventType[[]]] = None,
190
- on_mouse_out: Optional[EventType[[]]] = None,
191
- on_mouse_over: Optional[EventType[[]]] = None,
192
- on_mouse_up: Optional[EventType[[]]] = None,
193
- on_scroll: Optional[EventType[[]]] = None,
194
- on_unmount: Optional[EventType[[]]] = None,
228
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
229
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
230
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
231
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
232
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
233
+ on_drop: Optional[
234
+ Union[EventType[[], BASE_STATE], EventType[[Any], BASE_STATE]]
235
+ ] = None,
236
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
237
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
238
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
239
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
240
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
241
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
242
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
243
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
244
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
245
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
246
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
195
247
  **props,
196
248
  ) -> "StyledUpload":
197
249
  """Create the styled upload component.
@@ -207,6 +259,7 @@ class StyledUpload(Upload):
207
259
  no_click: Whether to disable click to upload.
208
260
  no_drag: Whether to disable drag and drop.
209
261
  no_keyboard: Whether to disable using the space/enter keys to upload.
262
+ on_drop: Fired when files are dropped.
210
263
  style: The style of the component.
211
264
  key: A unique key for the component.
212
265
  id: The id for the component.
@@ -240,23 +293,25 @@ class UploadNamespace(ComponentNamespace):
240
293
  id: Optional[Any] = None,
241
294
  class_name: Optional[Any] = None,
242
295
  autofocus: Optional[bool] = None,
243
- custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
244
- on_blur: Optional[EventType[[]]] = None,
245
- on_click: Optional[EventType[[]]] = None,
246
- on_context_menu: Optional[EventType[[]]] = None,
247
- on_double_click: Optional[EventType[[]]] = None,
248
- on_drop: Optional[EventType[Any]] = None,
249
- on_focus: Optional[EventType[[]]] = None,
250
- on_mount: Optional[EventType[[]]] = None,
251
- on_mouse_down: Optional[EventType[[]]] = None,
252
- on_mouse_enter: Optional[EventType[[]]] = None,
253
- on_mouse_leave: Optional[EventType[[]]] = None,
254
- on_mouse_move: Optional[EventType[[]]] = None,
255
- on_mouse_out: Optional[EventType[[]]] = None,
256
- on_mouse_over: Optional[EventType[[]]] = None,
257
- on_mouse_up: Optional[EventType[[]]] = None,
258
- on_scroll: Optional[EventType[[]]] = None,
259
- on_unmount: Optional[EventType[[]]] = None,
296
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
297
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
298
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
299
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
300
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
301
+ on_drop: Optional[
302
+ Union[EventType[[], BASE_STATE], EventType[[Any], BASE_STATE]]
303
+ ] = None,
304
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
305
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
306
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
307
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
308
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
309
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
310
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
311
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
312
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
313
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
314
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
260
315
  **props,
261
316
  ) -> "StyledUpload":
262
317
  """Create the styled upload component.
@@ -272,6 +327,7 @@ class UploadNamespace(ComponentNamespace):
272
327
  no_click: Whether to disable click to upload.
273
328
  no_drag: Whether to disable drag and drop.
274
329
  no_keyboard: Whether to disable using the space/enter keys to upload.
330
+ on_drop: Fired when files are dropped.
275
331
  style: The style of the component.
276
332
  key: A unique key for the component.
277
333
  id: The id for the component.
@@ -8,13 +8,14 @@ from typing import ClassVar, Dict, Literal, Optional, Union
8
8
  from reflex.components.component import Component, ComponentNamespace
9
9
  from reflex.components.core.cond import color_mode_cond
10
10
  from reflex.components.lucide.icon import Icon
11
+ from reflex.components.markdown.markdown import _LANGUAGE, MarkdownComponentMap
11
12
  from reflex.components.radix.themes.components.button import Button
12
13
  from reflex.components.radix.themes.layout.box import Box
13
14
  from reflex.constants.colors import Color
14
15
  from reflex.event import set_clipboard
15
16
  from reflex.style import Style
16
17
  from reflex.utils import console, format
17
- from reflex.utils.imports import ImportDict, ImportVar
18
+ from reflex.utils.imports import ImportVar
18
19
  from reflex.vars.base import LiteralVar, Var, VarData
19
20
 
20
21
  LiteralCodeLanguage = Literal[
@@ -378,7 +379,7 @@ for theme_name in dir(Theme):
378
379
  setattr(Theme, theme_name, getattr(Theme, theme_name)._replace(_var_type=Theme))
379
380
 
380
381
 
381
- class CodeBlock(Component):
382
+ class CodeBlock(Component, MarkdownComponentMap):
382
383
  """A code block."""
383
384
 
384
385
  library = "react-syntax-highlighter@15.6.1"
@@ -391,7 +392,7 @@ class CodeBlock(Component):
391
392
  theme: Var[Union[Theme, str]] = Theme.one_light
392
393
 
393
394
  # The language to use.
394
- language: Var[LiteralCodeLanguage] = "python" # type: ignore
395
+ language: Var[LiteralCodeLanguage] = Var.create("python")
395
396
 
396
397
  # The code to display.
397
398
  code: Var[str]
@@ -411,53 +412,22 @@ class CodeBlock(Component):
411
412
  # Props passed down to the code tag.
412
413
  code_tag_props: Var[Dict[str, str]]
413
414
 
414
- def add_imports(self) -> ImportDict:
415
- """Add imports for the CodeBlock component.
415
+ # Whether a copy button should appear.
416
+ can_copy: Optional[bool] = False
416
417
 
417
- Returns:
418
- The import dict.
419
- """
420
- imports_: ImportDict = {}
421
-
422
- if (
423
- self.language is not None
424
- and (language_without_quotes := str(self.language).replace('"', ""))
425
- in LiteralCodeLanguage.__args__ # type: ignore
426
- ):
427
- imports_[
428
- f"react-syntax-highlighter/dist/cjs/languages/prism/{language_without_quotes}"
429
- ] = [
430
- ImportVar(
431
- tag=format.to_camel_case(language_without_quotes),
432
- is_default=True,
433
- install=False,
434
- )
435
- ]
436
-
437
- return imports_
438
-
439
- def _get_custom_code(self) -> Optional[str]:
440
- if (
441
- self.language is not None
442
- and (language_without_quotes := str(self.language).replace('"', ""))
443
- in LiteralCodeLanguage.__args__ # type: ignore
444
- ):
445
- return f"{self.alias}.registerLanguage('{language_without_quotes}', {format.to_camel_case(language_without_quotes)})"
418
+ # A custom copy button to override the default one.
419
+ copy_button: Optional[Union[bool, Component]] = None
446
420
 
447
421
  @classmethod
448
422
  def create(
449
423
  cls,
450
424
  *children,
451
- can_copy: Optional[bool] = False,
452
- copy_button: Optional[Union[bool, Component]] = None,
453
425
  **props,
454
426
  ):
455
427
  """Create a text component.
456
428
 
457
429
  Args:
458
430
  *children: The children of the component.
459
- can_copy: Whether a copy button should appears.
460
- copy_button: A custom copy button to override the default one.
461
431
  **props: The props to pass to the component.
462
432
 
463
433
  Returns:
@@ -465,6 +435,8 @@ class CodeBlock(Component):
465
435
  """
466
436
  # This component handles style in a special prop.
467
437
  custom_style = props.pop("custom_style", {})
438
+ can_copy = props.pop("can_copy", False)
439
+ copy_button = props.pop("copy_button", None)
468
440
 
469
441
  if "theme" not in props:
470
442
  # Default color scheme responds to global color mode.
@@ -530,12 +502,55 @@ class CodeBlock(Component):
530
502
 
531
503
  theme = self.theme
532
504
 
533
- out.add_props(style=theme).remove_props("theme", "code").add_props(
534
- children=self.code
505
+ out.add_props(style=theme).remove_props("theme", "code", "language").add_props(
506
+ children=self.code, language=_LANGUAGE
535
507
  )
536
508
 
537
509
  return out
538
510
 
511
+ def _exclude_props(self) -> list[str]:
512
+ return ["can_copy", "copy_button"]
513
+
514
+ @classmethod
515
+ def _get_language_registration_hook(cls) -> str:
516
+ """Get the hook to register the language.
517
+
518
+ Returns:
519
+ The hook to register the language.
520
+ """
521
+ return f"""
522
+ if ({str(_LANGUAGE)}) {{
523
+ (async () => {{
524
+ try {{
525
+ const module = await import(`react-syntax-highlighter/dist/cjs/languages/prism/${{{str(_LANGUAGE)}}}`);
526
+ SyntaxHighlighter.registerLanguage({str(_LANGUAGE)}, module.default);
527
+ }} catch (error) {{
528
+ console.error(`Error importing language module for ${{{str(_LANGUAGE)}}}:`, error);
529
+ }}
530
+ }})();
531
+ }}
532
+ """
533
+
534
+ @classmethod
535
+ def get_component_map_custom_code(cls) -> str:
536
+ """Get the custom code for the component.
537
+
538
+ Returns:
539
+ The custom code for the component.
540
+ """
541
+ return cls._get_language_registration_hook()
542
+
543
+ def add_hooks(self) -> list[str | Var]:
544
+ """Add hooks for the component.
545
+
546
+ Returns:
547
+ The hooks for the component.
548
+ """
549
+ return [
550
+ f"const {str(_LANGUAGE)} = {str(self.language)}",
551
+ self._get_language_registration_hook(),
552
+ ]
553
+
539
554
 
540
555
  class CodeblockNamespace(ComponentNamespace):
541
556
  """Namespace for the CodeBlock component."""
@@ -7,10 +7,10 @@ import dataclasses
7
7
  from typing import Any, ClassVar, Dict, Literal, Optional, Union, overload
8
8
 
9
9
  from reflex.components.component import Component, ComponentNamespace
10
+ from reflex.components.markdown.markdown import MarkdownComponentMap
10
11
  from reflex.constants.colors import Color
11
- from reflex.event import EventType
12
+ from reflex.event import BASE_STATE, EventType
12
13
  from reflex.style import Style
13
- from reflex.utils.imports import ImportDict
14
14
  from reflex.vars.base import Var
15
15
 
16
16
  LiteralCodeLanguage = Literal[
@@ -349,15 +349,12 @@ for theme_name in dir(Theme):
349
349
  continue
350
350
  setattr(Theme, theme_name, getattr(Theme, theme_name)._replace(_var_type=Theme))
351
351
 
352
- class CodeBlock(Component):
353
- def add_imports(self) -> ImportDict: ...
352
+ class CodeBlock(Component, MarkdownComponentMap):
354
353
  @overload
355
354
  @classmethod
356
355
  def create( # type: ignore
357
356
  cls,
358
357
  *children,
359
- can_copy: Optional[bool] = False,
360
- copy_button: Optional[Union[Component, bool]] = None,
361
358
  theme: Optional[Union[Theme, Var[Union[Theme, str]], str]] = None,
362
359
  language: Optional[
363
360
  Union[
@@ -933,35 +930,35 @@ class CodeBlock(Component):
933
930
  wrap_long_lines: Optional[Union[Var[bool], bool]] = None,
934
931
  custom_style: Optional[Dict[str, Union[str, Var, Color]]] = None,
935
932
  code_tag_props: Optional[Union[Dict[str, str], Var[Dict[str, str]]]] = None,
933
+ can_copy: Optional[bool] = None,
934
+ copy_button: Optional[Union[Component, bool]] = None,
936
935
  style: Optional[Style] = None,
937
936
  key: Optional[Any] = None,
938
937
  id: Optional[Any] = None,
939
938
  class_name: Optional[Any] = None,
940
939
  autofocus: Optional[bool] = None,
941
- custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
942
- on_blur: Optional[EventType[[]]] = None,
943
- on_click: Optional[EventType[[]]] = None,
944
- on_context_menu: Optional[EventType[[]]] = None,
945
- on_double_click: Optional[EventType[[]]] = None,
946
- on_focus: Optional[EventType[[]]] = None,
947
- on_mount: Optional[EventType[[]]] = None,
948
- on_mouse_down: Optional[EventType[[]]] = None,
949
- on_mouse_enter: Optional[EventType[[]]] = None,
950
- on_mouse_leave: Optional[EventType[[]]] = None,
951
- on_mouse_move: Optional[EventType[[]]] = None,
952
- on_mouse_out: Optional[EventType[[]]] = None,
953
- on_mouse_over: Optional[EventType[[]]] = None,
954
- on_mouse_up: Optional[EventType[[]]] = None,
955
- on_scroll: Optional[EventType[[]]] = None,
956
- on_unmount: Optional[EventType[[]]] = None,
940
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
941
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
942
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
943
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
944
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
945
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
946
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
947
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
948
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
949
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
950
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
951
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
952
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
953
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
954
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
955
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
957
956
  **props,
958
957
  ) -> "CodeBlock":
959
958
  """Create a text component.
960
959
 
961
960
  Args:
962
961
  *children: The children of the component.
963
- can_copy: Whether a copy button should appears.
964
- copy_button: A custom copy button to override the default one.
965
962
  theme: The theme to use ("light" or "dark").
966
963
  language: The language to use.
967
964
  code: The code to display.
@@ -970,6 +967,8 @@ class CodeBlock(Component):
970
967
  wrap_long_lines: Whether to wrap long lines.
971
968
  custom_style: A custom style for the code block.
972
969
  code_tag_props: Props passed down to the code tag.
970
+ can_copy: Whether a copy button should appear.
971
+ copy_button: A custom copy button to override the default one.
973
972
  style: The style of the component.
974
973
  key: A unique key for the component.
975
974
  id: The id for the component.
@@ -984,6 +983,9 @@ class CodeBlock(Component):
984
983
  ...
985
984
 
986
985
  def add_style(self): ...
986
+ @classmethod
987
+ def get_component_map_custom_code(cls) -> str: ...
988
+ def add_hooks(self) -> list[str | Var]: ...
987
989
 
988
990
  class CodeblockNamespace(ComponentNamespace):
989
991
  themes = Theme
@@ -991,8 +993,6 @@ class CodeblockNamespace(ComponentNamespace):
991
993
  @staticmethod
992
994
  def __call__(
993
995
  *children,
994
- can_copy: Optional[bool] = False,
995
- copy_button: Optional[Union[Component, bool]] = None,
996
996
  theme: Optional[Union[Theme, Var[Union[Theme, str]], str]] = None,
997
997
  language: Optional[
998
998
  Union[
@@ -1568,35 +1568,35 @@ class CodeblockNamespace(ComponentNamespace):
1568
1568
  wrap_long_lines: Optional[Union[Var[bool], bool]] = None,
1569
1569
  custom_style: Optional[Dict[str, Union[str, Var, Color]]] = None,
1570
1570
  code_tag_props: Optional[Union[Dict[str, str], Var[Dict[str, str]]]] = None,
1571
+ can_copy: Optional[bool] = None,
1572
+ copy_button: Optional[Union[Component, bool]] = None,
1571
1573
  style: Optional[Style] = None,
1572
1574
  key: Optional[Any] = None,
1573
1575
  id: Optional[Any] = None,
1574
1576
  class_name: Optional[Any] = None,
1575
1577
  autofocus: Optional[bool] = None,
1576
- custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
1577
- on_blur: Optional[EventType[[]]] = None,
1578
- on_click: Optional[EventType[[]]] = None,
1579
- on_context_menu: Optional[EventType[[]]] = None,
1580
- on_double_click: Optional[EventType[[]]] = None,
1581
- on_focus: Optional[EventType[[]]] = None,
1582
- on_mount: Optional[EventType[[]]] = None,
1583
- on_mouse_down: Optional[EventType[[]]] = None,
1584
- on_mouse_enter: Optional[EventType[[]]] = None,
1585
- on_mouse_leave: Optional[EventType[[]]] = None,
1586
- on_mouse_move: Optional[EventType[[]]] = None,
1587
- on_mouse_out: Optional[EventType[[]]] = None,
1588
- on_mouse_over: Optional[EventType[[]]] = None,
1589
- on_mouse_up: Optional[EventType[[]]] = None,
1590
- on_scroll: Optional[EventType[[]]] = None,
1591
- on_unmount: Optional[EventType[[]]] = None,
1578
+ custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None,
1579
+ on_blur: Optional[EventType[[], BASE_STATE]] = None,
1580
+ on_click: Optional[EventType[[], BASE_STATE]] = None,
1581
+ on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
1582
+ on_double_click: Optional[EventType[[], BASE_STATE]] = None,
1583
+ on_focus: Optional[EventType[[], BASE_STATE]] = None,
1584
+ on_mount: Optional[EventType[[], BASE_STATE]] = None,
1585
+ on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
1586
+ on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
1587
+ on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
1588
+ on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
1589
+ on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
1590
+ on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
1591
+ on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
1592
+ on_scroll: Optional[EventType[[], BASE_STATE]] = None,
1593
+ on_unmount: Optional[EventType[[], BASE_STATE]] = None,
1592
1594
  **props,
1593
1595
  ) -> "CodeBlock":
1594
1596
  """Create a text component.
1595
1597
 
1596
1598
  Args:
1597
1599
  *children: The children of the component.
1598
- can_copy: Whether a copy button should appears.
1599
- copy_button: A custom copy button to override the default one.
1600
1600
  theme: The theme to use ("light" or "dark").
1601
1601
  language: The language to use.
1602
1602
  code: The code to display.
@@ -1605,6 +1605,8 @@ class CodeblockNamespace(ComponentNamespace):
1605
1605
  wrap_long_lines: Whether to wrap long lines.
1606
1606
  custom_style: A custom style for the code block.
1607
1607
  code_tag_props: Props passed down to the code tag.
1608
+ can_copy: Whether a copy button should appear.
1609
+ copy_button: A custom copy button to override the default one.
1608
1610
  style: The style of the component.
1609
1611
  key: A unique key for the component.
1610
1612
  id: The id for the component.