reflex 0.5.2a1__py3-none-any.whl → 0.5.3__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 (166) hide show
  1. reflex/.templates/web/postcss.config.js +1 -0
  2. reflex/.templates/web/styles/tailwind.css +4 -1
  3. reflex/__init__.py +298 -204
  4. reflex/__init__.pyi +196 -157
  5. reflex/app.py +13 -2
  6. reflex/compiler/compiler.py +1 -1
  7. reflex/components/__init__.py +31 -17
  8. reflex/components/__init__.pyi +26 -0
  9. reflex/components/base/__init__.py +25 -9
  10. reflex/components/base/__init__.pyi +26 -0
  11. reflex/components/base/fragment.py +3 -0
  12. reflex/components/base/fragment.pyi +2 -0
  13. reflex/components/base/head.py +3 -0
  14. reflex/components/base/head.pyi +2 -0
  15. reflex/components/base/script.py +3 -0
  16. reflex/components/base/script.pyi +2 -0
  17. reflex/components/core/__init__.py +51 -37
  18. reflex/components/core/__init__.pyi +39 -0
  19. reflex/components/core/banner.py +7 -1
  20. reflex/components/core/banner.pyi +6 -1
  21. reflex/components/core/debounce.py +3 -0
  22. reflex/components/core/debounce.pyi +2 -0
  23. reflex/components/core/foreach.py +3 -0
  24. reflex/components/core/html.py +4 -1
  25. reflex/components/core/html.pyi +2 -0
  26. reflex/components/core/match.py +3 -0
  27. reflex/components/core/responsive.py +1 -1
  28. reflex/components/core/upload.py +5 -2
  29. reflex/components/core/upload.pyi +4 -2
  30. reflex/components/datadisplay/__init__.py +17 -8
  31. reflex/components/datadisplay/__init__.pyi +14 -0
  32. reflex/components/datadisplay/code.py +3 -0
  33. reflex/components/datadisplay/code.pyi +2 -0
  34. reflex/components/datadisplay/dataeditor.py +4 -0
  35. reflex/components/datadisplay/dataeditor.pyi +3 -0
  36. reflex/components/el/__init__.py +15 -1
  37. reflex/components/el/__init__.pyi +228 -0
  38. reflex/components/el/elements/__init__.py +129 -220
  39. reflex/components/el/elements/__init__.pyi +342 -0
  40. reflex/components/el/elements/forms.py +15 -0
  41. reflex/components/el/elements/forms.pyi +14 -0
  42. reflex/components/el/elements/inline.py +30 -0
  43. reflex/components/el/elements/inline.pyi +29 -0
  44. reflex/components/el/elements/media.py +16 -0
  45. reflex/components/el/elements/media.pyi +15 -0
  46. reflex/components/el/elements/metadata.py +7 -0
  47. reflex/components/el/elements/metadata.pyi +6 -0
  48. reflex/components/el/elements/other.py +9 -0
  49. reflex/components/el/elements/other.pyi +8 -0
  50. reflex/components/el/elements/scripts.py +5 -0
  51. reflex/components/el/elements/scripts.pyi +4 -0
  52. reflex/components/el/elements/sectioning.py +17 -0
  53. reflex/components/el/elements/sectioning.pyi +16 -0
  54. reflex/components/el/elements/tables.py +12 -0
  55. reflex/components/el/elements/tables.pyi +11 -0
  56. reflex/components/el/elements/typography.py +16 -0
  57. reflex/components/el/elements/typography.pyi +15 -0
  58. reflex/components/moment/__init__.py +1 -1
  59. reflex/components/plotly/plotly.py +185 -7
  60. reflex/components/plotly/plotly.pyi +62 -4
  61. reflex/components/radix/__init__.py +14 -2
  62. reflex/components/radix/__init__.pyi +73 -0
  63. reflex/components/radix/primitives/__init__.py +13 -5
  64. reflex/components/radix/primitives/__init__.pyi +11 -0
  65. reflex/components/radix/themes/__init__.py +20 -6
  66. reflex/components/radix/themes/__init__.pyi +13 -0
  67. reflex/components/radix/themes/base.py +26 -20
  68. reflex/components/radix/themes/base.pyi +4 -1
  69. reflex/components/radix/themes/color_mode.py +3 -1
  70. reflex/components/radix/themes/color_mode.pyi +3 -1
  71. reflex/components/radix/themes/components/__init__.py +11 -79
  72. reflex/components/radix/themes/components/__init__.pyi +44 -0
  73. reflex/components/radix/themes/components/alert_dialog.py +2 -2
  74. reflex/components/radix/themes/components/alert_dialog.pyi +2 -2
  75. reflex/components/radix/themes/components/badge.py +2 -2
  76. reflex/components/radix/themes/components/badge.pyi +2 -2
  77. reflex/components/radix/themes/components/button.py +2 -2
  78. reflex/components/radix/themes/components/button.pyi +2 -2
  79. reflex/components/radix/themes/components/callout.py +4 -4
  80. reflex/components/radix/themes/components/callout.pyi +4 -4
  81. reflex/components/radix/themes/components/card.py +2 -2
  82. reflex/components/radix/themes/components/card.pyi +2 -2
  83. reflex/components/radix/themes/components/dialog.py +2 -2
  84. reflex/components/radix/themes/components/dialog.pyi +2 -2
  85. reflex/components/radix/themes/components/hover_card.py +2 -2
  86. reflex/components/radix/themes/components/hover_card.pyi +2 -2
  87. reflex/components/radix/themes/components/icon_button.py +2 -2
  88. reflex/components/radix/themes/components/icon_button.pyi +2 -2
  89. reflex/components/radix/themes/components/inset.py +2 -2
  90. reflex/components/radix/themes/components/inset.pyi +2 -2
  91. reflex/components/radix/themes/components/popover.py +2 -2
  92. reflex/components/radix/themes/components/popover.pyi +2 -2
  93. reflex/components/radix/themes/components/table.py +8 -8
  94. reflex/components/radix/themes/components/table.pyi +8 -8
  95. reflex/components/radix/themes/components/text_area.py +11 -2
  96. reflex/components/radix/themes/components/text_area.pyi +18 -3
  97. reflex/components/radix/themes/components/text_field.py +3 -3
  98. reflex/components/radix/themes/components/text_field.pyi +3 -3
  99. reflex/components/radix/themes/layout/__init__.py +12 -38
  100. reflex/components/radix/themes/layout/__init__.pyi +21 -0
  101. reflex/components/radix/themes/layout/box.py +5 -2
  102. reflex/components/radix/themes/layout/box.pyi +4 -2
  103. reflex/components/radix/themes/layout/center.py +3 -0
  104. reflex/components/radix/themes/layout/center.pyi +2 -0
  105. reflex/components/radix/themes/layout/container.py +5 -2
  106. reflex/components/radix/themes/layout/container.pyi +4 -2
  107. reflex/components/radix/themes/layout/flex.py +5 -2
  108. reflex/components/radix/themes/layout/flex.pyi +4 -2
  109. reflex/components/radix/themes/layout/grid.py +5 -2
  110. reflex/components/radix/themes/layout/grid.pyi +4 -2
  111. reflex/components/radix/themes/layout/list.py +14 -0
  112. reflex/components/radix/themes/layout/list.pyi +3 -0
  113. reflex/components/radix/themes/layout/section.py +7 -4
  114. reflex/components/radix/themes/layout/section.pyi +5 -3
  115. reflex/components/radix/themes/layout/spacer.py +3 -0
  116. reflex/components/radix/themes/layout/spacer.pyi +2 -0
  117. reflex/components/radix/themes/layout/stack.py +5 -0
  118. reflex/components/radix/themes/layout/stack.pyi +4 -0
  119. reflex/components/radix/themes/typography/__init__.py +11 -16
  120. reflex/components/radix/themes/typography/__init__.pyi +12 -0
  121. reflex/components/radix/themes/typography/blockquote.py +5 -2
  122. reflex/components/radix/themes/typography/blockquote.pyi +4 -2
  123. reflex/components/radix/themes/typography/code.py +5 -2
  124. reflex/components/radix/themes/typography/code.pyi +4 -2
  125. reflex/components/radix/themes/typography/heading.py +5 -2
  126. reflex/components/radix/themes/typography/heading.pyi +4 -2
  127. reflex/components/radix/themes/typography/link.py +3 -0
  128. reflex/components/radix/themes/typography/link.pyi +2 -0
  129. reflex/components/radix/themes/typography/text.py +6 -6
  130. reflex/components/radix/themes/typography/text.pyi +6 -6
  131. reflex/components/recharts/__init__.py +114 -104
  132. reflex/components/recharts/__init__.pyi +106 -0
  133. reflex/components/recharts/cartesian.py +17 -0
  134. reflex/components/recharts/cartesian.pyi +16 -0
  135. reflex/components/recharts/charts.py +12 -0
  136. reflex/components/recharts/charts.pyi +11 -0
  137. reflex/components/recharts/general.py +7 -0
  138. reflex/components/recharts/general.pyi +6 -0
  139. reflex/components/recharts/polar.py +11 -0
  140. reflex/components/recharts/polar.pyi +9 -0
  141. reflex/config.py +3 -0
  142. reflex/constants/__init__.py +0 -2
  143. reflex/constants/base.py +5 -1
  144. reflex/constants/installer.py +2 -1
  145. reflex/experimental/__init__.py +2 -0
  146. reflex/experimental/assets.py +56 -0
  147. reflex/experimental/client_state.py +4 -2
  148. reflex/experimental/hooks.py +8 -6
  149. reflex/experimental/layout.py +3 -1
  150. reflex/state.py +54 -4
  151. reflex/utils/exec.py +8 -0
  152. reflex/utils/format.py +8 -4
  153. reflex/utils/lazy_loader.py +33 -0
  154. reflex/utils/prerequisites.py +1 -14
  155. reflex/utils/pyi_generator.py +71 -20
  156. reflex/utils/serializers.py +9 -4
  157. reflex/utils/types.py +3 -1
  158. reflex/vars.py +92 -6
  159. reflex/vars.pyi +16 -0
  160. {reflex-0.5.2a1.dist-info → reflex-0.5.3.dist-info}/METADATA +2 -1
  161. {reflex-0.5.2a1.dist-info → reflex-0.5.3.dist-info}/RECORD +164 -151
  162. reflex/config.pyi +0 -112
  163. reflex/constants/base.pyi +0 -94
  164. {reflex-0.5.2a1.dist-info → reflex-0.5.3.dist-info}/LICENSE +0 -0
  165. {reflex-0.5.2a1.dist-info → reflex-0.5.3.dist-info}/WHEEL +0 -0
  166. {reflex-0.5.2a1.dist-info → reflex-0.5.3.dist-info}/entry_points.txt +0 -0
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  plugins: {
3
+ "postcss-import": {},
3
4
  tailwindcss: {},
4
5
  autoprefixer: {},
5
6
  },
@@ -1,3 +1,6 @@
1
- @tailwind base;
1
+ @import "tailwindcss/base";
2
+
3
+ @import "@radix-ui/themes/styles.css";
4
+
2
5
  @tailwind components;
3
6
  @tailwind utilities;
reflex/__init__.py CHANGED
@@ -1,141 +1,281 @@
1
1
  """Import all classes and functions the end user will need to make an app.
2
2
 
3
3
  Anything imported here will be available in the default Reflex import as `rx.*`.
4
- To signal to typecheckers that something should be reexported,
5
- we use the Flask "import name as name" syntax.
4
+
5
+ Dynamic Imports
6
+ ---------------
7
+ Reflex utilizes dynamic imports, or lazy loading, to reduce startup/import times.
8
+ With this approach, imports are delayed until they are actually needed. We use
9
+ the `lazy_loader` library(https://github.com/scientific-python/lazy_loader) to achieve this.
10
+
11
+ How it works
12
+ --------------
13
+ `lazy_loader.attach` takes two optional arguments: `submodules` and `submod_attrs`.
14
+ - `submodules` typically points to directories or files to be accessed.
15
+ - `submod_attrs` defines a mapping of directory or file names as keys with a list
16
+ of attributes or modules to access.
17
+
18
+ Example directory structure:
19
+
20
+ reflex/
21
+ |_ components/
22
+ |_ radix/
23
+ |_ themes/
24
+ |_ components/
25
+ |_ box.py
26
+
27
+ To add `box` under the `rx` namespace (`rx.box`), add the relative path to `submod_attrs` in
28
+ `reflex/__init__.py` (this file):
29
+
30
+ ```python
31
+ lazy_loader.attach(
32
+ submodules={"components"},
33
+ submod_attrs={
34
+ "components.radix.themes.components.box": ["box"]
35
+ }
36
+ )
37
+ ```
38
+
39
+ This implies that `box` will be imported from `reflex/components/radix/themes/components/box.py`.
40
+
41
+ To add box under the `rx.radix` namespace (`rx.radix.box`), add the relative path to the
42
+ submod_attrs argument in `reflex/components/radix/__init__.py`:
43
+
44
+ ```python
45
+ lazy_loader.attach(
46
+ submodules = {"themes"},
47
+ submod_attrs = {
48
+ "themes.components.box": ["box"]
49
+ }
50
+ )
51
+ ```
52
+
53
+ Note: It is important to specify the immediate submodules of a directory in the submodules
54
+ argument to ensure they are registered at runtime. For example, 'components' for reflex,
55
+ 'radix' for components, 'themes' for radix, etc.
56
+
57
+
58
+ Pyi_generator
59
+ --------------
60
+ To generate `.pyi` files for `__init__.py` files, we read the `_SUBMODULES` and `_SUBMOD_ATTRS`
61
+ attributes to generate the import statements. It is highly recommended to define these with
62
+ the provided annotations to facilitate their generation.
63
+
64
+
65
+ Aliases
66
+ ------------
67
+ This is a special case to specify an alias for a component.
68
+ As an example, we use this typically for `rx.list` where defining `list` attribute in the list.py
69
+ overshadows python's list object which messes up the pyi generation for `list.pyi`. As a result, aliases
70
+ should be used for similar cases like this. Note that this logic is employed to fix the pyi generation and alias
71
+ should still be defined or accessible. Check out the __getattr__ logic in `reflex/components/radix/themes/layouts/list.py`
72
+
73
+ ```python
74
+ lazy_loader.attach(
75
+ submodules={"components"},
76
+ submod_attrs={
77
+ "components.radix.themes.layouts": [("list_ns", "list")]
78
+ }
79
+ )
80
+ ```
81
+
82
+ In the example above, you will be able to do `rx.list`
6
83
  """
7
84
 
8
85
  from __future__ import annotations
9
86
 
10
- import importlib
11
- from typing import Type
12
-
13
- from reflex.page import page as page
14
- from reflex.utils import console
15
- from reflex.utils.format import to_snake_case
16
-
17
- _ALL_COMPONENTS = [
18
- # Core
19
- "color",
20
- "cond",
21
- "foreach",
22
- "html",
23
- "match",
24
- "color_mode_cond",
25
- "connection_banner",
26
- "connection_modal",
27
- "debounce_input",
28
- # Base
29
- "fragment",
30
- "Fragment",
31
- "image",
32
- "script",
33
- # Responsive
34
- "desktop_only",
35
- "mobile_and_tablet",
36
- "mobile_only",
37
- "tablet_and_desktop",
38
- "tablet_only",
39
- # Upload
40
- "cancel_upload",
41
- "clear_selected_files",
42
- "get_upload_dir",
43
- "get_upload_url",
44
- "selected_files",
45
- "upload",
46
- # Radix
47
- "accordion",
48
- "alert_dialog",
49
- "aspect_ratio",
50
- "avatar",
51
- "badge",
52
- "blockquote",
53
- "box",
54
- "button",
55
- "callout",
56
- "card",
57
- "center",
58
- "checkbox",
59
- "code",
60
- "container",
61
- "context_menu",
62
- "data_list",
63
- "dialog",
64
- "divider",
65
- "drawer",
66
- "flex",
67
- "form",
68
- "grid",
69
- "heading",
70
- "hover_card",
71
- "hstack",
72
- "icon_button",
73
- "inset",
74
- "input",
75
- "link",
76
- "menu",
77
- "popover",
78
- "progress",
79
- "radio",
80
- "scroll_area",
81
- "section",
82
- "select",
83
- "skeleton",
84
- "slider",
85
- "spacer",
86
- "spinner",
87
- "stack",
88
- "switch",
89
- "table",
90
- "tabs",
91
- "text",
92
- "text_area",
93
- "theme",
94
- "theme_panel",
95
- "tooltip",
96
- "vstack",
97
- # Other
98
- "code_block",
99
- "data_editor",
100
- "data_editor_theme",
101
- "data_table",
102
- "plotly",
103
- "audio",
104
- "video",
105
- "editor",
106
- "EditorButtonList",
107
- "EditorOptions",
108
- "icon",
109
- "markdown",
110
- "list",
111
- "list_item",
112
- "unordered_list",
113
- "ordered_list",
114
- "moment",
115
- "logo",
116
- # Toast is in experimental namespace initially
117
- # "toast",
118
- ]
119
-
120
- _MAPPING = {
121
- "reflex.experimental": ["_x"],
122
- "reflex.admin": ["admin", "AdminDash"],
123
- "reflex.app": ["app", "App", "UploadFile"],
124
- "reflex.base": ["base", "Base"],
125
- "reflex.compiler": ["compiler"],
126
- "reflex.components": _ALL_COMPONENTS,
127
- "reflex.components.component": ["Component", "NoSSRComponent", "memo"],
128
- "reflex.components.chakra": ["chakra"],
129
- "reflex.components.el": ["el"],
130
- "reflex.components.lucide": ["lucide"],
131
- "reflex.components.next": ["next"],
132
- "reflex.components.radix": ["radix", "color_mode"],
133
- "reflex.components.recharts": ["recharts"],
134
- "reflex.components.moment.moment": ["MomentDelta"],
135
- "reflex.config": ["config", "Config", "DBConfig"],
136
- "reflex.constants": ["constants", "Env"],
137
- "reflex.event": [
138
- "event",
87
+ from reflex.utils import lazy_loader
88
+
89
+ # import this here explicitly to avoid returning the page module since page attr has the
90
+ # same name as page module(page.py)
91
+ from .page import page as page
92
+
93
+ RADIX_THEMES_MAPPING: dict = {
94
+ "components.radix.themes.base": ["color_mode", "theme", "theme_panel"],
95
+ "components.radix.themes.color_mode": ["color_mode"],
96
+ }
97
+ RADIX_THEMES_COMPONENTS_MAPPING: dict = {
98
+ **{
99
+ f"components.radix.themes.components.{mod}": [mod]
100
+ for mod in [
101
+ "alert_dialog",
102
+ "aspect_ratio",
103
+ "avatar",
104
+ "badge",
105
+ "button",
106
+ "callout",
107
+ "card",
108
+ "checkbox",
109
+ "context_menu",
110
+ "data_list",
111
+ "dialog",
112
+ "hover_card",
113
+ "icon_button",
114
+ "input",
115
+ "inset",
116
+ "popover",
117
+ "scroll_area",
118
+ "select",
119
+ "skeleton",
120
+ "slider",
121
+ "spinner",
122
+ "switch",
123
+ "table",
124
+ "tabs",
125
+ "text_area",
126
+ "tooltip",
127
+ "segmented_control",
128
+ "radio_cards",
129
+ "checkbox_cards",
130
+ "checkbox_group",
131
+ ]
132
+ },
133
+ "components.radix.themes.components.text_field": ["text_field", "input"],
134
+ "components.radix.themes.components.radio_group": ["radio", "radio_group"],
135
+ "components.radix.themes.components.dropdown_menu": ["menu", "dropdown_menu"],
136
+ "components.radix.themes.components.separator": ["divider", "separator"],
137
+ }
138
+
139
+ RADIX_THEMES_LAYOUT_MAPPING: dict = {
140
+ "components.radix.themes.layout.box": [
141
+ "box",
142
+ ],
143
+ "components.radix.themes.layout.center": [
144
+ "center",
145
+ ],
146
+ "components.radix.themes.layout.container": [
147
+ "container",
148
+ ],
149
+ "components.radix.themes.layout.flex": [
150
+ "flex",
151
+ ],
152
+ "components.radix.themes.layout.grid": [
153
+ "grid",
154
+ ],
155
+ "components.radix.themes.layout.section": [
156
+ "section",
157
+ ],
158
+ "components.radix.themes.layout.spacer": [
159
+ "spacer",
160
+ ],
161
+ "components.radix.themes.layout.stack": [
162
+ "stack",
163
+ "hstack",
164
+ "vstack",
165
+ ],
166
+ "components.radix.themes.layout.list": [
167
+ ("list_ns", "list"),
168
+ "list_item",
169
+ "ordered_list",
170
+ "unordered_list",
171
+ ],
172
+ }
173
+
174
+ RADIX_THEMES_TYPOGRAPHY_MAPPING: dict = {
175
+ "components.radix.themes.typography.blockquote": [
176
+ "blockquote",
177
+ ],
178
+ "components.radix.themes.typography.code": [
179
+ "code",
180
+ ],
181
+ "components.radix.themes.typography.heading": [
182
+ "heading",
183
+ ],
184
+ "components.radix.themes.typography.link": [
185
+ "link",
186
+ ],
187
+ "components.radix.themes.typography.text": [
188
+ "text",
189
+ ],
190
+ }
191
+
192
+ RADIX_PRIMITIVES_MAPPING: dict = {
193
+ "components.radix.primitives.accordion": [
194
+ "accordion",
195
+ ],
196
+ "components.radix.primitives.drawer": [
197
+ "drawer",
198
+ ],
199
+ "components.radix.primitives.form": [
200
+ "form",
201
+ ],
202
+ "components.radix.primitives.progress": ["progress"],
203
+ }
204
+
205
+ COMPONENTS_CORE_MAPPING: dict = {
206
+ "components.core.banner": [
207
+ "connection_banner",
208
+ "connection_modal",
209
+ ],
210
+ "components.core.cond": ["cond", "color_mode_cond"],
211
+ "components.core.foreach": ["foreach"],
212
+ "components.core.debounce": ["debounce_input"],
213
+ "components.core.html": ["html"],
214
+ "components.core.match": ["match"],
215
+ "components.core.colors": ["color"],
216
+ "components.core.responsive": [
217
+ "desktop_only",
218
+ "mobile_and_tablet",
219
+ "mobile_only",
220
+ "tablet_and_desktop",
221
+ "tablet_only",
222
+ ],
223
+ "components.core.upload": [
224
+ "cancel_upload",
225
+ "clear_selected_files",
226
+ "get_upload_dir",
227
+ "get_upload_url",
228
+ "selected_files",
229
+ "upload",
230
+ ],
231
+ }
232
+
233
+ COMPONENTS_BASE_MAPPING: dict = {
234
+ "components.base.fragment": ["fragment", "Fragment"],
235
+ "components.base.script": ["script", "Script"],
236
+ }
237
+
238
+ RADIX_MAPPING: dict = {
239
+ **RADIX_THEMES_MAPPING,
240
+ **RADIX_THEMES_COMPONENTS_MAPPING,
241
+ **RADIX_THEMES_TYPOGRAPHY_MAPPING,
242
+ **RADIX_THEMES_LAYOUT_MAPPING,
243
+ **RADIX_PRIMITIVES_MAPPING,
244
+ }
245
+
246
+ _MAPPING: dict = {
247
+ "experimental": ["_x"],
248
+ "admin": ["AdminDash"],
249
+ "app": ["App", "UploadFile"],
250
+ "base": ["Base"],
251
+ "components.component": ["Component", "NoSSRComponent", "memo"],
252
+ "components.el.elements.media": ["image"],
253
+ "components.lucide": ["icon"],
254
+ **COMPONENTS_BASE_MAPPING,
255
+ "components.suneditor": [
256
+ "editor",
257
+ "EditorButtonList",
258
+ "EditorOptions",
259
+ ],
260
+ "components": ["el", "chakra", "radix", "lucide", "recharts", "next"],
261
+ "components.markdown": ["markdown"],
262
+ **RADIX_MAPPING,
263
+ "components.plotly": ["plotly"],
264
+ "components.react_player": ["audio", "video"],
265
+ **COMPONENTS_CORE_MAPPING,
266
+ "components.datadisplay.code": [
267
+ "code_block",
268
+ ],
269
+ "components.datadisplay.dataeditor": [
270
+ "data_editor",
271
+ "data_editor_theme",
272
+ ],
273
+ "components.datadisplay.logo": ["logo"],
274
+ "components.gridjs": ["data_table"],
275
+ "components.moment": ["MomentDelta", "moment"],
276
+ "config": ["Config", "DBConfig"],
277
+ "constants": ["Env"],
278
+ "event": [
139
279
  "EventChain",
140
280
  "EventHandler",
141
281
  "background",
@@ -155,84 +295,38 @@ _MAPPING = {
155
295
  "upload_files",
156
296
  "window_alert",
157
297
  ],
158
- "reflex.middleware": ["middleware", "Middleware"],
159
- "reflex.model": ["model", "session", "Model"],
160
- "reflex.page": ["page"],
161
- "reflex.route": ["route"],
162
- "reflex.state": [
163
- "state",
298
+ "middleware": ["middleware", "Middleware"],
299
+ "model": ["session", "Model"],
300
+ "state": [
164
301
  "var",
165
302
  "Cookie",
166
303
  "LocalStorage",
167
304
  "ComponentState",
168
305
  "State",
169
306
  ],
170
- "reflex.style": ["style", "toggle_color_mode"],
171
- "reflex.testing": ["testing"],
172
- "reflex.utils": ["utils"],
173
- "reflex.utils.imports": ["ImportVar"],
174
- "reflex.vars": ["vars", "cached_var", "Var"],
307
+ "style": ["Style", "toggle_color_mode"],
308
+ "utils.imports": ["ImportVar"],
309
+ "utils.serializers": ["serializer"],
310
+ "vars": ["cached_var", "Var"],
175
311
  }
176
312
 
177
-
178
- def _reverse_mapping(mapping: dict[str, list]) -> dict[str, str]:
179
- """Reverse the mapping used to lazy loading, and check for conflicting name.
180
-
181
- Args:
182
- mapping: The mapping to reverse.
183
-
184
- Returns:
185
- The reversed mapping.
186
- """
187
- reversed_mapping = {}
188
- for key, values in mapping.items():
189
- for value in values:
190
- if value not in reversed_mapping:
191
- reversed_mapping[value] = key
192
- else:
193
- console.warn(
194
- f"Key {value} is present multiple times in the imports _MAPPING: {key} / {reversed_mapping[value]}"
195
- )
196
- return reversed_mapping
197
-
198
-
199
- # _MAPPING = {value: key for key, values in _MAPPING.items() for value in values}
200
- _MAPPING = _reverse_mapping(_MAPPING)
201
-
202
-
203
- def _removeprefix(text, prefix):
204
- return text[text.startswith(prefix) and len(prefix) :]
205
-
206
-
207
- __all__ = (_removeprefix(mod, "reflex.") for mod in _MAPPING)
208
-
209
-
210
- def __getattr__(name: str) -> Type:
211
- """Lazy load all modules.
212
-
213
- Args:
214
- name: name of the module to load.
215
-
216
- Returns:
217
- The module or the attribute of the module.
218
-
219
- Raises:
220
- AttributeError: If the module or the attribute does not exist.
221
- """
222
- try:
223
- # Check for import of a module that is not in the mapping.
224
- if name not in _MAPPING:
225
- # If the name does not start with reflex, add it.
226
- if not name.startswith("reflex") and name != "__all__":
227
- name = f"reflex.{name}"
228
- return importlib.import_module(name)
229
-
230
- # Import the module.
231
- module = importlib.import_module(_MAPPING[name])
232
-
233
- # Get the attribute from the module if the name is not the module itself.
234
- return (
235
- getattr(module, name) if name != _MAPPING[name].rsplit(".")[-1] else module
236
- )
237
- except ModuleNotFoundError:
238
- raise AttributeError(f"module 'reflex' has no attribute {name}") from None
313
+ _SUBMODULES: set[str] = {
314
+ "components",
315
+ "event",
316
+ "app",
317
+ "style",
318
+ "admin",
319
+ "base",
320
+ "model",
321
+ "testing",
322
+ "utils",
323
+ "vars",
324
+ "config",
325
+ "compiler",
326
+ }
327
+ _SUBMOD_ATTRS: dict = _MAPPING
328
+ __getattr__, __dir__, __all__ = lazy_loader.attach(
329
+ __name__,
330
+ submodules=_SUBMODULES,
331
+ submod_attrs=_SUBMOD_ATTRS,
332
+ )