reflex 0.4.9a1__py3-none-any.whl → 0.5.0__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 (133) hide show
  1. reflex/.templates/apps/blank/code/blank.py +19 -16
  2. reflex/.templates/apps/demo/code/demo.py +1 -1
  3. reflex/.templates/apps/demo/code/pages/datatable.py +4 -4
  4. reflex/.templates/apps/demo/code/pages/forms.py +2 -2
  5. reflex/.templates/jinja/web/tailwind.config.js.jinja2 +12 -0
  6. reflex/.templates/web/utils/helpers/debounce.js +17 -0
  7. reflex/.templates/web/utils/helpers/throttle.js +22 -0
  8. reflex/.templates/web/utils/state.js +21 -3
  9. reflex/__init__.py +6 -1
  10. reflex/__init__.pyi +4 -1
  11. reflex/app.py +160 -140
  12. reflex/app_module_for_backend.py +1 -1
  13. reflex/base.py +13 -15
  14. reflex/compiler/compiler.py +10 -1
  15. reflex/compiler/utils.py +3 -30
  16. reflex/components/__init__.py +1 -0
  17. reflex/components/chakra/datadisplay/list.py +1 -3
  18. reflex/components/chakra/datadisplay/list.pyi +3 -3
  19. reflex/components/chakra/disclosure/accordion.py +1 -1
  20. reflex/components/chakra/forms/pininput.pyi +1 -1
  21. reflex/components/chakra/media/icon.py +2 -2
  22. reflex/components/component.py +275 -32
  23. reflex/components/core/__init__.py +2 -2
  24. reflex/components/core/cond.py +1 -10
  25. reflex/components/core/debounce.py +5 -2
  26. reflex/components/core/debounce.pyi +4 -2
  27. reflex/components/core/foreach.py +60 -49
  28. reflex/components/core/html.py +6 -0
  29. reflex/components/core/match.py +2 -17
  30. reflex/components/core/upload.py +42 -1
  31. reflex/components/core/upload.pyi +199 -1
  32. reflex/components/datadisplay/code.py +7 -3
  33. reflex/components/datadisplay/code.pyi +3 -1
  34. reflex/components/el/elements/forms.py +1 -1
  35. reflex/components/el/elements/forms.pyi +1 -1
  36. reflex/components/lucide/icon.py +5 -13
  37. reflex/components/lucide/icon.pyi +0 -1
  38. reflex/components/markdown/markdown.py +5 -23
  39. reflex/components/markdown/markdown.pyi +1 -4
  40. reflex/components/radix/primitives/accordion.py +265 -410
  41. reflex/components/radix/primitives/accordion.pyi +390 -36
  42. reflex/components/radix/primitives/form.py +33 -29
  43. reflex/components/radix/primitives/form.pyi +7 -2
  44. reflex/components/radix/primitives/progress.py +17 -9
  45. reflex/components/radix/primitives/progress.pyi +2 -0
  46. reflex/components/radix/primitives/slider.py +30 -18
  47. reflex/components/radix/primitives/slider.pyi +4 -0
  48. reflex/components/radix/themes/base.py +8 -1
  49. reflex/components/radix/themes/base.pyi +79 -1
  50. reflex/components/radix/themes/color_mode.py +88 -20
  51. reflex/components/radix/themes/color_mode.pyi +157 -139
  52. reflex/components/radix/themes/components/__init__.py +17 -0
  53. reflex/components/radix/themes/components/badge.py +2 -1
  54. reflex/components/radix/themes/components/badge.pyi +3 -1
  55. reflex/components/radix/themes/components/button.py +3 -1
  56. reflex/components/radix/themes/components/button.pyi +4 -1
  57. reflex/components/radix/themes/components/checkbox_cards.py +48 -0
  58. reflex/components/radix/themes/components/checkbox_cards.pyi +264 -0
  59. reflex/components/radix/themes/components/checkbox_group.py +42 -0
  60. reflex/components/radix/themes/components/checkbox_group.pyi +253 -0
  61. reflex/components/radix/themes/components/data_list.py +63 -0
  62. reflex/components/radix/themes/components/data_list.pyi +426 -0
  63. reflex/components/radix/themes/components/icon_button.py +20 -17
  64. reflex/components/radix/themes/components/icon_button.pyi +5 -1
  65. reflex/components/radix/themes/components/progress.py +55 -0
  66. reflex/components/radix/themes/components/progress.pyi +180 -0
  67. reflex/components/radix/themes/components/radio.py +31 -0
  68. reflex/components/radix/themes/components/radio.pyi +169 -0
  69. reflex/components/radix/themes/components/radio_cards.py +48 -0
  70. reflex/components/radix/themes/components/radio_cards.pyi +264 -0
  71. reflex/components/radix/themes/components/radio_group.py +2 -4
  72. reflex/components/radix/themes/components/segmented_control.py +48 -0
  73. reflex/components/radix/themes/components/segmented_control.pyi +262 -0
  74. reflex/components/radix/themes/components/skeleton.py +32 -0
  75. reflex/components/radix/themes/components/skeleton.pyi +106 -0
  76. reflex/components/radix/themes/components/spinner.py +26 -0
  77. reflex/components/radix/themes/components/spinner.pyi +101 -0
  78. reflex/components/radix/themes/components/tabs.py +26 -1
  79. reflex/components/radix/themes/components/tabs.pyi +69 -9
  80. reflex/components/radix/themes/components/text_field.py +101 -71
  81. reflex/components/radix/themes/components/text_field.pyi +81 -499
  82. reflex/components/radix/themes/layout/base.py +2 -2
  83. reflex/components/radix/themes/layout/base.pyi +4 -4
  84. reflex/components/radix/themes/layout/center.py +8 -3
  85. reflex/components/radix/themes/layout/center.pyi +2 -1
  86. reflex/components/radix/themes/layout/container.py +30 -2
  87. reflex/components/radix/themes/layout/container.pyi +9 -30
  88. reflex/components/radix/themes/layout/list.py +10 -5
  89. reflex/components/radix/themes/layout/list.pyi +5 -21
  90. reflex/components/radix/themes/layout/spacer.py +8 -3
  91. reflex/components/radix/themes/layout/spacer.pyi +2 -1
  92. reflex/components/radix/themes/layout/stack.py +7 -1
  93. reflex/components/radix/themes/layout/stack.pyi +3 -3
  94. reflex/components/radix/themes/typography/link.py +10 -2
  95. reflex/components/radix/themes/typography/link.pyi +5 -4
  96. reflex/components/sonner/__init__.py +3 -0
  97. reflex/components/sonner/toast.py +267 -0
  98. reflex/components/sonner/toast.pyi +205 -0
  99. reflex/components/tags/iter_tag.py +9 -6
  100. reflex/config.py +30 -54
  101. reflex/constants/__init__.py +0 -2
  102. reflex/constants/base.py +0 -5
  103. reflex/constants/colors.py +2 -0
  104. reflex/constants/installer.py +6 -1
  105. reflex/constants/route.py +4 -0
  106. reflex/custom_components/custom_components.py +24 -2
  107. reflex/event.py +75 -30
  108. reflex/experimental/__init__.py +5 -0
  109. reflex/experimental/layout.py +24 -6
  110. reflex/model.py +2 -1
  111. reflex/page.py +7 -4
  112. reflex/reflex.py +8 -3
  113. reflex/route.py +39 -0
  114. reflex/state.py +128 -131
  115. reflex/style.py +25 -3
  116. reflex/testing.py +10 -6
  117. reflex/utils/console.py +3 -1
  118. reflex/utils/exec.py +20 -7
  119. reflex/utils/format.py +1 -1
  120. reflex/utils/imports.py +3 -1
  121. reflex/utils/prerequisites.py +141 -20
  122. reflex/utils/processes.py +21 -1
  123. reflex/utils/pyi_generator.py +100 -5
  124. reflex/utils/serializers.py +1 -1
  125. reflex/utils/telemetry.py +26 -4
  126. reflex/utils/types.py +62 -18
  127. reflex/vars.py +11 -5
  128. {reflex-0.4.9a1.dist-info → reflex-0.5.0.dist-info}/METADATA +16 -4
  129. {reflex-0.4.9a1.dist-info → reflex-0.5.0.dist-info}/RECORD +132 -110
  130. {reflex-0.4.9a1.dist-info → reflex-0.5.0.dist-info}/WHEEL +1 -1
  131. reflex/app.pyi +0 -149
  132. {reflex-0.4.9a1.dist-info → reflex-0.5.0.dist-info}/LICENSE +0 -0
  133. {reflex-0.4.9a1.dist-info → reflex-0.5.0.dist-info}/entry_points.txt +0 -0
@@ -1,34 +1,37 @@
1
1
  """Welcome to Reflex! This file outlines the steps to create a basic app."""
2
2
 
3
- from rxconfig import config
4
-
5
3
  import reflex as rx
6
4
 
7
- docs_url = "https://reflex.dev/docs/getting-started/introduction/"
8
- filename = f"{config.app_name}/{config.app_name}.py"
5
+ from rxconfig import config
9
6
 
10
7
 
11
8
  class State(rx.State):
12
9
  """The app state."""
13
10
 
11
+ ...
12
+
14
13
 
15
14
  def index() -> rx.Component:
16
- return rx.center(
17
- rx.theme_panel(),
15
+ # Welcome Page (Index)
16
+ return rx.container(
17
+ rx.color_mode.button(position="top-right"),
18
18
  rx.vstack(
19
19
  rx.heading("Welcome to Reflex!", size="9"),
20
- rx.text("Get started by editing ", rx.code(filename)),
21
- rx.button(
22
- "Check out our docs!",
23
- on_click=lambda: rx.redirect(docs_url),
24
- size="4",
20
+ rx.text(
21
+ "Get started by editing ",
22
+ rx.code(f"{config.app_name}/{config.app_name}.py"),
23
+ size="5",
24
+ ),
25
+ rx.link(
26
+ rx.button("Check out our docs!"),
27
+ href="https://reflex.dev/docs/getting-started/introduction/",
28
+ is_external=True,
25
29
  ),
26
- rx.logo(),
27
- align="center",
28
- spacing="7",
29
- font_size="2em",
30
+ spacing="5",
31
+ justify="center",
32
+ min_height="85vh",
30
33
  ),
31
- height="100vh",
34
+ rx.logo(),
32
35
  )
33
36
 
34
37
 
@@ -44,7 +44,7 @@ def template(main_content: Callable[[], rx.Component]) -> rx.Component:
44
44
  ),
45
45
  rx.chakra.menu_item(
46
46
  rx.chakra.link(
47
- "Contact", href="mailto:founders@=reflex.dev", width="100%"
47
+ "Contact", href="mailto:founders@reflex.dev", width="100%"
48
48
  )
49
49
  ),
50
50
  ),
@@ -201,10 +201,10 @@ state_show = """class DataTableState(State):
201
201
  data_show = """[
202
202
  ["1", "Harry James Potter", "31 July 1980", True, "Gryffindor", "11' Holly phoenix feather", "Stag", "Half-blood"],
203
203
  ["2", "Ronald Bilius Weasley", "1 March 1980", True,"Gryffindor", "12' Ash unicorn tail hair", "Jack Russell terrier", "Pure-blood"],
204
- ["3", "Hermione Jean Granger", "19 September, 1979", True, "Gryffindor", "10¾' vine wood dragon heartstring", "Otter", "Muggle-born"],
205
- ["4", "Albus Percival Wulfric Brian Dumbledore", "Late August 1881", True, "Gryffindor", "15' Elder Thestral tail hair core", "Phoenix", "Half-blood"],
206
- ["5", "Rubeus Hagrid", "6 December 1928", False, "Gryffindor", "16' Oak unknown core", "None", "Part-Human (Half-giant)"],
207
- ["6", "Fred Weasley", "1 April, 1978", True, "Gryffindor", "Unknown", "Unknown", "Pure-blood"],
204
+ ["3", "Hermione Jean Granger", "19 September, 1979", True, "Gryffindor", "10¾' vine wood dragon heartstring", "Otter", "Muggle-born"],
205
+ ["4", "Albus Percival Wulfric Brian Dumbledore", "Late August 1881", True, "Gryffindor", "15' Elder Thestral tail hair core", "Phoenix", "Half-blood"],
206
+ ["5", "Rubeus Hagrid", "6 December 1928", False, "Gryffindor", "16' Oak unknown core", "None", "Part-Human (Half-giant)"],
207
+ ["6", "Fred Weasley", "1 April, 1978", True, "Gryffindor", "Unknown", "Unknown", "Pure-blood"],
208
208
  ["7", "George Weasley", "1 April, 1978", True, "Gryffindor", "Unknown", "Unknown", "Pure-blood"],
209
209
  ]"""
210
210
 
@@ -18,8 +18,8 @@ forms_1_code = """rx.chakra.vstack(
18
18
  rx.chakra.checkbox("Checked", id="check"),
19
19
  rx.chakra.switch("Switched", id="switch"),
20
20
  ),
21
- rx.chakra.button("Submit",
22
- type_="submit",
21
+ rx.chakra.button("Submit",
22
+ type_="submit",
23
23
  bg="#ecfdf5",
24
24
  color="#047857",
25
25
  border_radius="lg",
@@ -17,4 +17,16 @@ module.exports = {
17
17
  {% if darkMode is defined %}
18
18
  darkMode: {{darkMode|json_dumps}},
19
19
  {% endif %}
20
+ {% if corePlugins is defined %}
21
+ corePlugins: {{corePlugins|json_dumps}},
22
+ {% endif %}
23
+ {% if important is defined %}
24
+ important: {{important|json_dumps}},
25
+ {% endif %}
26
+ {% if prefix is defined %}
27
+ prefix: {{prefix|json_dumps}},
28
+ {% endif %}
29
+ {% if separator is defined %}
30
+ separator: {{separator|json_dumps}},
31
+ {% endif %}
20
32
  };
@@ -0,0 +1,17 @@
1
+ const debounce_timeout_id = {};
2
+
3
+ /**
4
+ * Generic debounce helper
5
+ *
6
+ * @param {string} name - the name of the event to debounce
7
+ * @param {function} func - the function to call after debouncing
8
+ * @param {number} delay - the time in milliseconds to wait before calling the function
9
+ */
10
+ export default function debounce(name, func, delay) {
11
+ const key = `${name}__${delay}`;
12
+ clearTimeout(debounce_timeout_id[key]);
13
+ debounce_timeout_id[key] = setTimeout(() => {
14
+ func();
15
+ delete debounce_timeout_id[key];
16
+ }, delay);
17
+ }
@@ -0,0 +1,22 @@
1
+ const in_throttle = {};
2
+
3
+ /**
4
+ * Generic throttle helper
5
+ *
6
+ * @param {string} name - the name of the event to throttle
7
+ * @param {number} limit - time in milliseconds between events
8
+ * @returns true if the event is allowed to execute, false if it is throttled
9
+ */
10
+ export default function throttle(name, limit) {
11
+ const key = `${name}__${limit}`;
12
+ if (!in_throttle[key]) {
13
+ in_throttle[key] = true;
14
+
15
+ setTimeout(() => {
16
+ delete in_throttle[key];
17
+ }, limit);
18
+ // function was not throttled, so allow execution
19
+ return true;
20
+ }
21
+ return false;
22
+ }
@@ -12,6 +12,8 @@ import {
12
12
  onLoadInternalEvent,
13
13
  state_name,
14
14
  } from "utils/context.js";
15
+ import debounce from "/utils/helpers/debounce";
16
+ import throttle from "/utils/helpers/throttle";
15
17
 
16
18
  // Endpoint URLs.
17
19
  const EVENTURL = env.EVENT;
@@ -571,7 +573,23 @@ export const useEventLoop = (
571
573
  if (event_actions?.stopPropagation && _e?.stopPropagation) {
572
574
  _e.stopPropagation();
573
575
  }
574
- queueEvents(events, socket);
576
+ const combined_name = events.map((e) => e.name).join("+++");
577
+ if (event_actions?.throttle) {
578
+ // If throttle returns false, the events are not added to the queue.
579
+ if (!throttle(combined_name, event_actions.throttle)) {
580
+ return;
581
+ }
582
+ }
583
+ if (event_actions?.debounce) {
584
+ // If debounce is used, queue the events after some delay
585
+ debounce(
586
+ combined_name,
587
+ () => queueEvents(events, socket),
588
+ event_actions.debounce,
589
+ );
590
+ } else {
591
+ queueEvents(events, socket);
592
+ }
575
593
  };
576
594
 
577
595
  const sentHydrate = useRef(false); // Avoid double-hydrate due to React strict-mode
@@ -691,8 +709,8 @@ export const getRefValue = (ref) => {
691
709
  if (ref.current.type == "checkbox") {
692
710
  return ref.current.checked; // chakra
693
711
  } else if (
694
- ref.current.className?.includes("rt-CheckboxButton") ||
695
- ref.current.className?.includes("rt-SwitchButton")
712
+ ref.current.className?.includes("rt-CheckboxRoot") ||
713
+ ref.current.className?.includes("rt-SwitchRoot")
696
714
  ) {
697
715
  return ref.current.ariaChecked == "true"; // radix
698
716
  } else if (ref.current.className?.includes("rt-SliderRoot")) {
reflex/__init__.py CHANGED
@@ -59,6 +59,7 @@ _ALL_COMPONENTS = [
59
59
  "code",
60
60
  "container",
61
61
  "context_menu",
62
+ "data_list",
62
63
  "dialog",
63
64
  "divider",
64
65
  "drawer",
@@ -79,8 +80,10 @@ _ALL_COMPONENTS = [
79
80
  "scroll_area",
80
81
  "section",
81
82
  "select",
83
+ "skeleton",
82
84
  "slider",
83
85
  "spacer",
86
+ "spinner",
84
87
  "stack",
85
88
  "switch",
86
89
  "table",
@@ -110,6 +113,8 @@ _ALL_COMPONENTS = [
110
113
  "ordered_list",
111
114
  "moment",
112
115
  "logo",
116
+ # Toast is in experimental namespace initially
117
+ # "toast",
113
118
  ]
114
119
 
115
120
  _MAPPING = {
@@ -118,7 +123,6 @@ _MAPPING = {
118
123
  "reflex.app": ["app", "App", "UploadFile"],
119
124
  "reflex.base": ["base", "Base"],
120
125
  "reflex.compiler": ["compiler"],
121
- "reflex.compiler.utils": ["get_asset_path"],
122
126
  "reflex.components": _ALL_COMPONENTS,
123
127
  "reflex.components.component": ["Component", "NoSSRComponent", "memo"],
124
128
  "reflex.components.chakra": ["chakra"],
@@ -166,6 +170,7 @@ _MAPPING = {
166
170
  "reflex.style": ["style", "toggle_color_mode"],
167
171
  "reflex.testing": ["testing"],
168
172
  "reflex.utils": ["utils"],
173
+ "reflex.utils.imports": ["ImportVar"],
169
174
  "reflex.vars": ["vars", "cached_var", "Var"],
170
175
  }
171
176
 
reflex/__init__.pyi CHANGED
@@ -7,7 +7,6 @@ from reflex.app import UploadFile as UploadFile
7
7
  from reflex import base as base
8
8
  from reflex.base import Base as Base
9
9
  from reflex import compiler as compiler
10
- from reflex.compiler.utils import get_asset_path as get_asset_path
11
10
  from reflex.components import color as color
12
11
  from reflex.components import cond as cond
13
12
  from reflex.components import foreach as foreach
@@ -47,6 +46,7 @@ from reflex.components import checkbox as checkbox
47
46
  from reflex.components import code as code
48
47
  from reflex.components import container as container
49
48
  from reflex.components import context_menu as context_menu
49
+ from reflex.components import data_list as data_list
50
50
  from reflex.components import dialog as dialog
51
51
  from reflex.components import divider as divider
52
52
  from reflex.components import drawer as drawer
@@ -67,8 +67,10 @@ from reflex.components import radio as radio
67
67
  from reflex.components import scroll_area as scroll_area
68
68
  from reflex.components import section as section
69
69
  from reflex.components import select as select
70
+ from reflex.components import skeleton as skeleton
70
71
  from reflex.components import slider as slider
71
72
  from reflex.components import spacer as spacer
73
+ from reflex.components import spinner as spinner
72
74
  from reflex.components import stack as stack
73
75
  from reflex.components import switch as switch
74
76
  from reflex.components import table as table
@@ -149,6 +151,7 @@ from reflex import style as style
149
151
  from reflex.style import toggle_color_mode as toggle_color_mode
150
152
  from reflex import testing as testing
151
153
  from reflex import utils as utils
154
+ from reflex.utils.imports import ImportVar as ImportVar
152
155
  from reflex import vars as vars
153
156
  from reflex.vars import cached_var as cached_var
154
157
  from reflex.vars import Var as Var