reflex 0.7.14a6__py3-none-any.whl → 0.8.0a2__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 (211) hide show
  1. reflex/.templates/jinja/app/rxconfig.py.jinja2 +4 -1
  2. reflex/.templates/jinja/web/package.json.jinja2 +1 -1
  3. reflex/.templates/jinja/web/pages/_app.js.jinja2 +16 -10
  4. reflex/.templates/jinja/web/pages/_document.js.jinja2 +1 -1
  5. reflex/.templates/jinja/web/pages/base_page.js.jinja2 +0 -1
  6. reflex/.templates/jinja/web/pages/stateful_component.js.jinja2 +4 -0
  7. reflex/.templates/jinja/web/utils/context.js.jinja2 +25 -8
  8. reflex/.templates/web/app/entry.client.js +8 -0
  9. reflex/.templates/web/app/routes.js +10 -0
  10. reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +12 -37
  11. reflex/.templates/web/postcss.config.js +1 -1
  12. reflex/.templates/web/react-router.config.js +6 -0
  13. reflex/.templates/web/utils/client_side_routing.js +21 -19
  14. reflex/.templates/web/utils/react-theme.js +92 -0
  15. reflex/.templates/web/utils/state.js +160 -67
  16. reflex/.templates/web/vite.config.js +32 -0
  17. reflex/__init__.py +1 -6
  18. reflex/__init__.pyi +0 -4
  19. reflex/app.py +53 -116
  20. reflex/base.py +1 -87
  21. reflex/compiler/compiler.py +41 -8
  22. reflex/compiler/templates.py +3 -3
  23. reflex/compiler/utils.py +73 -33
  24. reflex/components/__init__.py +0 -2
  25. reflex/components/__init__.pyi +0 -3
  26. reflex/components/base/__init__.py +1 -5
  27. reflex/components/base/__init__.pyi +4 -6
  28. reflex/components/base/app_wrap.pyi +5 -4
  29. reflex/components/base/body.pyi +5 -4
  30. reflex/components/base/document.py +18 -14
  31. reflex/components/base/document.pyi +83 -27
  32. reflex/components/base/error_boundary.pyi +5 -4
  33. reflex/components/base/fragment.pyi +5 -4
  34. reflex/components/base/link.pyi +9 -7
  35. reflex/components/base/meta.pyi +17 -13
  36. reflex/components/base/script.py +60 -58
  37. reflex/components/base/script.pyi +246 -31
  38. reflex/components/base/strict_mode.pyi +5 -4
  39. reflex/components/component.py +146 -217
  40. reflex/components/core/__init__.py +1 -0
  41. reflex/components/core/__init__.pyi +1 -0
  42. reflex/components/core/auto_scroll.pyi +5 -4
  43. reflex/components/core/banner.pyi +25 -19
  44. reflex/components/core/client_side_routing.py +7 -6
  45. reflex/components/core/client_side_routing.pyi +6 -56
  46. reflex/components/core/clipboard.pyi +5 -4
  47. reflex/components/core/debounce.py +1 -0
  48. reflex/components/core/debounce.pyi +5 -4
  49. reflex/components/core/foreach.py +3 -2
  50. reflex/components/core/helmet.py +14 -0
  51. reflex/components/{next/base.pyi → core/helmet.pyi} +10 -7
  52. reflex/components/core/html.pyi +5 -4
  53. reflex/components/core/sticky.pyi +17 -13
  54. reflex/components/core/upload.py +2 -1
  55. reflex/components/core/upload.pyi +21 -16
  56. reflex/components/datadisplay/code.py +2 -72
  57. reflex/components/datadisplay/code.pyi +9 -10
  58. reflex/components/datadisplay/dataeditor.pyi +11 -6
  59. reflex/components/datadisplay/shiki_code_block.pyi +13 -10
  60. reflex/components/dynamic.py +5 -5
  61. reflex/components/el/element.pyi +5 -4
  62. reflex/components/el/elements/base.pyi +5 -4
  63. reflex/components/el/elements/forms.pyi +69 -52
  64. reflex/components/el/elements/inline.pyi +113 -85
  65. reflex/components/el/elements/media.pyi +105 -79
  66. reflex/components/el/elements/metadata.pyi +25 -19
  67. reflex/components/el/elements/other.pyi +29 -22
  68. reflex/components/el/elements/scripts.pyi +13 -10
  69. reflex/components/el/elements/sectioning.pyi +61 -46
  70. reflex/components/el/elements/tables.pyi +41 -31
  71. reflex/components/el/elements/typography.pyi +61 -46
  72. reflex/components/field.py +175 -0
  73. reflex/components/gridjs/datatable.py +2 -2
  74. reflex/components/gridjs/datatable.pyi +11 -9
  75. reflex/components/lucide/icon.py +6 -2
  76. reflex/components/lucide/icon.pyi +15 -10
  77. reflex/components/markdown/markdown.pyi +5 -4
  78. reflex/components/moment/moment.pyi +5 -4
  79. reflex/components/plotly/plotly.pyi +19 -10
  80. reflex/components/props.py +376 -27
  81. reflex/components/radix/primitives/accordion.py +8 -1
  82. reflex/components/radix/primitives/accordion.pyi +29 -22
  83. reflex/components/radix/primitives/base.pyi +9 -7
  84. reflex/components/radix/primitives/drawer.pyi +45 -34
  85. reflex/components/radix/primitives/form.pyi +41 -31
  86. reflex/components/radix/primitives/progress.pyi +21 -16
  87. reflex/components/radix/primitives/slider.pyi +21 -16
  88. reflex/components/radix/themes/base.py +3 -3
  89. reflex/components/radix/themes/base.pyi +33 -25
  90. reflex/components/radix/themes/color_mode.pyi +13 -10
  91. reflex/components/radix/themes/components/alert_dialog.pyi +29 -22
  92. reflex/components/radix/themes/components/aspect_ratio.pyi +5 -4
  93. reflex/components/radix/themes/components/avatar.pyi +5 -4
  94. reflex/components/radix/themes/components/badge.pyi +5 -4
  95. reflex/components/radix/themes/components/button.pyi +5 -4
  96. reflex/components/radix/themes/components/callout.pyi +21 -16
  97. reflex/components/radix/themes/components/card.pyi +5 -4
  98. reflex/components/radix/themes/components/checkbox.pyi +13 -10
  99. reflex/components/radix/themes/components/checkbox_cards.pyi +9 -7
  100. reflex/components/radix/themes/components/checkbox_group.pyi +9 -7
  101. reflex/components/radix/themes/components/context_menu.pyi +53 -40
  102. reflex/components/radix/themes/components/data_list.pyi +17 -13
  103. reflex/components/radix/themes/components/dialog.pyi +29 -22
  104. reflex/components/radix/themes/components/dropdown_menu.pyi +33 -25
  105. reflex/components/radix/themes/components/hover_card.pyi +17 -13
  106. reflex/components/radix/themes/components/icon_button.pyi +5 -4
  107. reflex/components/radix/themes/components/inset.pyi +5 -4
  108. reflex/components/radix/themes/components/popover.pyi +17 -13
  109. reflex/components/radix/themes/components/progress.pyi +5 -4
  110. reflex/components/radix/themes/components/radio.pyi +5 -4
  111. reflex/components/radix/themes/components/radio_cards.pyi +9 -7
  112. reflex/components/radix/themes/components/radio_group.pyi +17 -13
  113. reflex/components/radix/themes/components/scroll_area.pyi +5 -4
  114. reflex/components/radix/themes/components/segmented_control.pyi +9 -7
  115. reflex/components/radix/themes/components/select.pyi +37 -28
  116. reflex/components/radix/themes/components/separator.pyi +5 -4
  117. reflex/components/radix/themes/components/skeleton.pyi +5 -4
  118. reflex/components/radix/themes/components/slider.pyi +5 -4
  119. reflex/components/radix/themes/components/spinner.pyi +5 -4
  120. reflex/components/radix/themes/components/switch.pyi +5 -4
  121. reflex/components/radix/themes/components/table.pyi +29 -22
  122. reflex/components/radix/themes/components/tabs.pyi +21 -16
  123. reflex/components/radix/themes/components/text_area.pyi +5 -4
  124. reflex/components/radix/themes/components/text_field.pyi +13 -10
  125. reflex/components/radix/themes/components/tooltip.pyi +5 -4
  126. reflex/components/radix/themes/layout/base.pyi +5 -4
  127. reflex/components/radix/themes/layout/box.pyi +5 -4
  128. reflex/components/radix/themes/layout/center.pyi +5 -4
  129. reflex/components/radix/themes/layout/container.pyi +5 -4
  130. reflex/components/radix/themes/layout/flex.pyi +5 -4
  131. reflex/components/radix/themes/layout/grid.pyi +5 -4
  132. reflex/components/radix/themes/layout/list.pyi +21 -16
  133. reflex/components/radix/themes/layout/section.pyi +5 -4
  134. reflex/components/radix/themes/layout/spacer.pyi +5 -4
  135. reflex/components/radix/themes/layout/stack.pyi +13 -10
  136. reflex/components/radix/themes/typography/blockquote.pyi +5 -4
  137. reflex/components/radix/themes/typography/code.pyi +5 -4
  138. reflex/components/radix/themes/typography/heading.pyi +5 -4
  139. reflex/components/radix/themes/typography/link.py +46 -11
  140. reflex/components/radix/themes/typography/link.pyi +311 -6
  141. reflex/components/radix/themes/typography/text.pyi +29 -22
  142. reflex/components/react_player/audio.pyi +5 -4
  143. reflex/components/react_player/react_player.pyi +5 -4
  144. reflex/components/react_player/video.pyi +5 -4
  145. reflex/components/recharts/cartesian.py +2 -1
  146. reflex/components/recharts/cartesian.pyi +65 -46
  147. reflex/components/recharts/charts.py +4 -2
  148. reflex/components/recharts/charts.pyi +36 -24
  149. reflex/components/recharts/general.pyi +24 -18
  150. reflex/components/recharts/polar.py +8 -4
  151. reflex/components/recharts/polar.pyi +16 -10
  152. reflex/components/recharts/recharts.pyi +9 -7
  153. reflex/components/sonner/toast.py +2 -2
  154. reflex/components/sonner/toast.pyi +10 -8
  155. reflex/config.py +3 -77
  156. reflex/constants/__init__.py +2 -2
  157. reflex/constants/base.py +28 -11
  158. reflex/constants/compiler.py +5 -3
  159. reflex/constants/event.py +1 -0
  160. reflex/constants/installer.py +22 -16
  161. reflex/constants/route.py +19 -7
  162. reflex/constants/state.py +2 -0
  163. reflex/custom_components/custom_components.py +0 -14
  164. reflex/environment.py +1 -1
  165. reflex/event.py +178 -81
  166. reflex/experimental/__init__.py +0 -30
  167. reflex/istate/proxy.py +5 -3
  168. reflex/page.py +0 -27
  169. reflex/plugins/__init__.py +3 -2
  170. reflex/plugins/base.py +5 -1
  171. reflex/plugins/shared_tailwind.py +158 -0
  172. reflex/plugins/sitemap.py +206 -0
  173. reflex/plugins/tailwind_v3.py +13 -106
  174. reflex/plugins/tailwind_v4.py +15 -108
  175. reflex/reflex.py +1 -0
  176. reflex/route.py +15 -21
  177. reflex/state.py +134 -140
  178. reflex/testing.py +58 -10
  179. reflex/utils/build.py +38 -82
  180. reflex/utils/exec.py +59 -161
  181. reflex/utils/export.py +2 -2
  182. reflex/utils/imports.py +0 -4
  183. reflex/utils/misc.py +28 -0
  184. reflex/utils/prerequisites.py +65 -62
  185. reflex/utils/processes.py +8 -7
  186. reflex/utils/pyi_generator.py +21 -9
  187. reflex/utils/serializers.py +14 -1
  188. reflex/utils/types.py +196 -61
  189. reflex/vars/__init__.py +2 -0
  190. reflex/vars/base.py +367 -134
  191. {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/METADATA +12 -5
  192. {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/RECORD +195 -202
  193. reflex/.templates/web/next.config.js +0 -7
  194. reflex/components/base/head.py +0 -20
  195. reflex/components/base/head.pyi +0 -116
  196. reflex/components/next/__init__.py +0 -10
  197. reflex/components/next/base.py +0 -7
  198. reflex/components/next/image.py +0 -117
  199. reflex/components/next/image.pyi +0 -94
  200. reflex/components/next/link.py +0 -20
  201. reflex/components/next/link.pyi +0 -67
  202. reflex/components/next/video.py +0 -38
  203. reflex/components/next/video.pyi +0 -68
  204. reflex/components/suneditor/__init__.py +0 -5
  205. reflex/components/suneditor/editor.py +0 -269
  206. reflex/components/suneditor/editor.pyi +0 -199
  207. reflex/experimental/layout.py +0 -254
  208. reflex/experimental/layout.pyi +0 -814
  209. {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/WHEEL +0 -0
  210. {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/entry_points.txt +0 -0
  211. {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/licenses/LICENSE +0 -0
@@ -1,123 +1,44 @@
1
1
  """Base class for all plugins."""
2
2
 
3
+ import dataclasses
3
4
  from pathlib import Path
4
5
  from types import SimpleNamespace
5
6
 
6
7
  from reflex.constants.base import Dirs
7
8
  from reflex.constants.compiler import Ext, PageNames
8
- from reflex.plugins.base import Plugin as PluginBase
9
- from reflex.utils.decorator import once
9
+ from reflex.plugins.shared_tailwind import (
10
+ TailwindConfig,
11
+ TailwindPlugin,
12
+ tailwind_config_js_template,
13
+ )
10
14
 
11
15
 
12
16
  class Constants(SimpleNamespace):
13
17
  """Tailwind constants."""
14
18
 
15
19
  # The Tailwindcss version
16
- VERSION = "tailwindcss@4.1.7"
20
+ VERSION = "tailwindcss@4.1.8"
17
21
  # The Tailwind config.
18
22
  CONFIG = "tailwind.config.js"
19
23
  # Default Tailwind content paths
20
- CONTENT = ["./pages/**/*.{js,ts,jsx,tsx}", "./utils/**/*.{js,ts,jsx,tsx}"]
24
+ CONTENT = [f"./{Dirs.PAGES}/**/*.{{js,ts,jsx,tsx}}", "./utils/**/*.{js,ts,jsx,tsx}"]
21
25
  # Relative tailwind style path to root stylesheet in Dirs.STYLES.
22
26
  ROOT_STYLE_PATH = "./tailwind.css"
23
27
 
24
28
  # Content of the style content.
25
29
  ROOT_STYLE_CONTENT = """@layer theme, base, components, utilities;
26
- @config "../tailwind.config.js";
27
30
  @import "tailwindcss/theme.css" layer(theme);
28
31
  @import "tailwindcss/preflight.css" layer(base);
29
32
  @import "{radix_url}" layer(components);
30
33
  @import "tailwindcss/utilities.css" layer(utilities);
34
+ @config "../tailwind.config.js";
31
35
  """
32
36
 
33
37
  # The default tailwind css.
34
38
  TAILWIND_CSS = "@import url('./tailwind.css');"
35
39
 
36
40
 
37
- @once
38
- def tailwind_config_js_template():
39
- """Get the Tailwind config template.
40
-
41
- Returns:
42
- The Tailwind config template.
43
- """
44
- from reflex.compiler.templates import from_string
45
-
46
- source = r"""
47
- {# Helper macro to render JS objects and arrays #}
48
- {% macro render_js(val, indent=2, level=0) -%}
49
- {%- set space = ' ' * (indent * level) -%}
50
- {%- set next_space = ' ' * (indent * (level + 1)) -%}
51
-
52
- {%- if val is mapping -%}
53
- {
54
- {%- for k, v in val.items() %}
55
- {{ next_space }}{{ k if k is string and k.isidentifier() else k|tojson }}: {{ render_js(v, indent, level + 1) }}{{ "," if not loop.last }}
56
- {%- endfor %}
57
- {{ space }}}
58
- {%- elif val is iterable and val is not string -%}
59
- [
60
- {%- for item in val %}
61
- {{ next_space }}{{ render_js(item, indent, level + 1) }}{{ "," if not loop.last }}
62
- {%- endfor %}
63
- {{ space }}]
64
- {%- else -%}
65
- {{ val | tojson }}
66
- {%- endif -%}
67
- {%- endmacro %}
68
-
69
- {# Extract destructured imports from plugin dicts only #}
70
- {%- set imports = [] %}
71
- {%- for plugin in plugins if plugin is mapping and plugin.import is defined %}
72
- {%- set _ = imports.append(plugin.import) %}
73
- {%- endfor %}
74
-
75
- /** @type {import('tailwindcss').Config} */
76
- {%- for imp in imports %}
77
- const { {{ imp.name }} } = require({{ imp.from | tojson }});
78
- {%- endfor %}
79
-
80
- module.exports = {
81
- content: {{ render_js(content) }},
82
- theme: {{ render_js(theme) }},
83
- {% if darkMode is defined %}darkMode: {{ darkMode | tojson }},{% endif %}
84
- {% if corePlugins is defined %}corePlugins: {{ render_js(corePlugins) }},{% endif %}
85
- {% if important is defined %}important: {{ important | tojson }},{% endif %}
86
- {% if prefix is defined %}prefix: {{ prefix | tojson }},{% endif %}
87
- {% if separator is defined %}separator: {{ separator | tojson }},{% endif %}
88
- {% if presets is defined %}
89
- presets: [
90
- {% for preset in presets %}
91
- require({{ preset | tojson }}){{ "," if not loop.last }}
92
- {% endfor %}
93
- ],
94
- {% endif %}
95
- plugins: [
96
- {% for plugin in plugins %}
97
- {% if plugin is mapping %}
98
- {% if plugin.call is defined %}
99
- {{ plugin.call }}(
100
- {%- if plugin.args is defined -%}
101
- {{ render_js(plugin.args) }}
102
- {%- endif -%}
103
- ){{ "," if not loop.last }}
104
- {% else %}
105
- require({{ plugin.name | tojson }}){{ "," if not loop.last }}
106
- {% endif %}
107
- {% else %}
108
- require({{ plugin | tojson }}){{ "," if not loop.last }}
109
- {% endif %}
110
- {% endfor %}
111
- ]
112
- };
113
- """
114
-
115
- return from_string(source)
116
-
117
-
118
- def compile_config(
119
- config: dict,
120
- ):
41
+ def compile_config(config: TailwindConfig):
121
42
  """Compile the Tailwind config.
122
43
 
123
44
  Args:
@@ -128,6 +49,7 @@ def compile_config(
128
49
  """
129
50
  return Constants.CONFIG, tailwind_config_js_template().render(
130
51
  **config,
52
+ DEFAULT_CONTENT=Constants.CONTENT,
131
53
  )
132
54
 
133
55
 
@@ -218,7 +140,8 @@ def add_tailwind_to_css_file(css_file_content: str) -> str:
218
140
  )
219
141
 
220
142
 
221
- class Plugin(PluginBase):
143
+ @dataclasses.dataclass
144
+ class TailwindV4Plugin(TailwindPlugin):
222
145
  """Plugin for Tailwind CSS."""
223
146
 
224
147
  def get_frontend_development_dependencies(self, **context) -> list[str]:
@@ -230,12 +153,9 @@ class Plugin(PluginBase):
230
153
  Returns:
231
154
  A list of packages required by the plugin.
232
155
  """
233
- from reflex.config import get_config
234
-
235
- config = get_config()
236
156
  return [
237
157
  plugin if isinstance(plugin, str) else plugin.get("name")
238
- for plugin in (config.tailwind or {}).get("plugins", [])
158
+ for plugin in self.get_config().get("plugins", [])
239
159
  ] + [Constants.VERSION, "@tailwindcss/postcss@4.1.7"]
240
160
 
241
161
  def pre_compile(self, **context):
@@ -244,23 +164,10 @@ class Plugin(PluginBase):
244
164
  Args:
245
165
  context: The context for the plugin.
246
166
  """
247
- from reflex.config import get_config
248
-
249
- config = get_config().tailwind or {}
250
-
251
- config["content"] = config.get("content", Constants.CONTENT)
252
- context["add_save_task"](compile_config, config)
167
+ context["add_save_task"](compile_config, self.get_config())
253
168
  context["add_save_task"](compile_root_style)
254
169
  context["add_modify_task"](Dirs.POSTCSS_JS, add_tailwind_to_postcss_config)
255
170
  context["add_modify_task"](
256
171
  str(Path(Dirs.STYLES) / (PageNames.STYLESHEET_ROOT + Ext.CSS)),
257
172
  add_tailwind_to_css_file,
258
173
  )
259
-
260
- def __repr__(self):
261
- """Return a string representation of the plugin.
262
-
263
- Returns:
264
- A string representation of the plugin.
265
- """
266
- return "TailwindV4Plugin()"
reflex/reflex.py CHANGED
@@ -204,6 +204,7 @@ def _run(
204
204
  args = (frontend,)
205
205
  kwargs = {
206
206
  "check_if_schema_up_to_date": True,
207
+ "prerender_routes": env == constants.Env.PROD,
207
208
  }
208
209
 
209
210
  # Granian fails if the app is already imported.
reflex/route.py CHANGED
@@ -17,14 +17,13 @@ def verify_route_validity(route: str) -> None:
17
17
  ValueError: If the route is invalid.
18
18
  """
19
19
  pattern = catchall_in_route(route)
20
- if pattern and not route.endswith(pattern):
21
- msg = f"Catch-all must be the last part of the URL: {route}"
22
- raise ValueError(msg)
23
- if route == "api" or route.startswith("api/"):
24
- msg = (
25
- f"Cannot have a route prefixed with 'api/': {route} (conflicts with NextJS)"
26
- )
27
- raise ValueError(msg)
20
+ if pattern:
21
+ if pattern != "[[...splat]]":
22
+ msg = f"Catchall pattern `{pattern}` is not valid. Only `[[...splat]]` is allowed."
23
+ raise ValueError(msg)
24
+ if not route.endswith(pattern):
25
+ msg = f"Catchall pattern `{pattern}` must be at the end of the route."
26
+ raise ValueError(msg)
28
27
 
29
28
 
30
29
  def get_route_args(route: str) -> dict[str, str]:
@@ -81,6 +80,14 @@ def get_route_args(route: str) -> dict[str, str]:
81
80
  def catchall_in_route(route: str) -> str:
82
81
  """Extract the catchall part from a route.
83
82
 
83
+ Example:
84
+ >>> catchall_in_route("/posts/[...slug]")
85
+ '[...slug]'
86
+ >>> catchall_in_route("/posts/[[...slug]]")
87
+ '[[...slug]]'
88
+ >>> catchall_in_route("/posts/[slug]")
89
+ ''
90
+
84
91
  Args:
85
92
  route: the route from which to extract
86
93
 
@@ -91,19 +98,6 @@ def catchall_in_route(route: str) -> str:
91
98
  return match_.group() if match_ else ""
92
99
 
93
100
 
94
- def catchall_prefix(route: str) -> str:
95
- """Extract the prefix part from a route that contains a catchall.
96
-
97
- Args:
98
- route: the route from which to extract
99
-
100
- Returns:
101
- str: the prefix part of the URI
102
- """
103
- pattern = catchall_in_route(route)
104
- return route.replace(pattern, "") if pattern else ""
105
-
106
-
107
101
  def replace_brackets_with_keywords(input_string: str) -> str:
108
102
  """Replace brackets and everything inside it in a string with a keyword.
109
103