reflex 0.8.0a4__py3-none-any.whl → 0.8.0a6__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 (163) hide show
  1. reflex/.templates/jinja/web/pages/_app.js.jinja2 +1 -1
  2. reflex/.templates/jinja/web/styles/styles.css.jinja2 +1 -0
  3. reflex/.templates/web/app/routes.js +3 -3
  4. reflex/.templates/web/utils/client_side_routing.js +1 -1
  5. reflex/.templates/web/utils/state.js +110 -52
  6. reflex/__init__.pyi +327 -188
  7. reflex/app.py +50 -48
  8. reflex/compiler/compiler.py +6 -2
  9. reflex/compiler/utils.py +32 -14
  10. reflex/components/__init__.pyi +34 -15
  11. reflex/components/base/__init__.pyi +30 -19
  12. reflex/components/base/app_wrap.pyi +2 -3
  13. reflex/components/base/body.pyi +2 -3
  14. reflex/components/base/document.pyi +7 -13
  15. reflex/components/base/error_boundary.pyi +2 -3
  16. reflex/components/base/fragment.pyi +2 -3
  17. reflex/components/base/link.pyi +3 -5
  18. reflex/components/base/meta.py +4 -15
  19. reflex/components/base/meta.pyi +14 -18
  20. reflex/components/base/script.pyi +2 -3
  21. reflex/components/base/strict_mode.pyi +2 -3
  22. reflex/components/core/__init__.pyi +77 -38
  23. reflex/components/core/auto_scroll.pyi +2 -3
  24. reflex/components/core/banner.pyi +8 -14
  25. reflex/components/core/client_side_routing.pyi +2 -3
  26. reflex/components/core/clipboard.pyi +2 -3
  27. reflex/components/core/debounce.pyi +2 -3
  28. reflex/components/core/foreach.py +2 -2
  29. reflex/components/core/helmet.pyi +2 -3
  30. reflex/components/core/html.pyi +2 -3
  31. reflex/components/core/match.py +3 -3
  32. reflex/components/core/sticky.pyi +4 -7
  33. reflex/components/core/upload.py +2 -1
  34. reflex/components/core/upload.pyi +5 -9
  35. reflex/components/datadisplay/__init__.pyi +13 -7
  36. reflex/components/datadisplay/code.py +12 -7
  37. reflex/components/datadisplay/code.pyi +2 -3
  38. reflex/components/datadisplay/dataeditor.pyi +33 -11
  39. reflex/components/datadisplay/shiki_code_block.py +5 -3
  40. reflex/components/datadisplay/shiki_code_block.pyi +3 -5
  41. reflex/components/el/__init__.pyi +506 -246
  42. reflex/components/el/element.pyi +2 -3
  43. reflex/components/el/elements/__init__.pyi +504 -245
  44. reflex/components/el/elements/base.pyi +2 -3
  45. reflex/components/el/elements/forms.pyi +77 -49
  46. reflex/components/el/elements/inline.pyi +29 -57
  47. reflex/components/el/elements/media.pyi +26 -51
  48. reflex/components/el/elements/metadata.pyi +7 -13
  49. reflex/components/el/elements/other.pyi +8 -15
  50. reflex/components/el/elements/scripts.pyi +4 -7
  51. reflex/components/el/elements/sectioning.pyi +16 -31
  52. reflex/components/el/elements/tables.pyi +11 -21
  53. reflex/components/el/elements/typography.pyi +16 -31
  54. reflex/components/gridjs/datatable.pyi +3 -5
  55. reflex/components/lucide/icon.pyi +4 -7
  56. reflex/components/markdown/markdown.py +5 -3
  57. reflex/components/markdown/markdown.pyi +2 -3
  58. reflex/components/moment/moment.py +1 -1
  59. reflex/components/moment/moment.pyi +2 -3
  60. reflex/components/plotly/plotly.py +12 -6
  61. reflex/components/plotly/plotly.pyi +31 -39
  62. reflex/components/radix/__init__.pyi +123 -65
  63. reflex/components/radix/primitives/__init__.pyi +6 -4
  64. reflex/components/radix/primitives/accordion.pyi +8 -15
  65. reflex/components/radix/primitives/base.pyi +3 -5
  66. reflex/components/radix/primitives/drawer.pyi +11 -21
  67. reflex/components/radix/primitives/form.pyi +22 -22
  68. reflex/components/radix/primitives/progress.pyi +5 -9
  69. reflex/components/radix/primitives/slider.pyi +6 -11
  70. reflex/components/radix/themes/__init__.pyi +5 -6
  71. reflex/components/radix/themes/base.pyi +9 -17
  72. reflex/components/radix/themes/color_mode.py +5 -6
  73. reflex/components/radix/themes/color_mode.pyi +4 -7
  74. reflex/components/radix/themes/components/__init__.pyi +75 -38
  75. reflex/components/radix/themes/components/alert_dialog.pyi +8 -15
  76. reflex/components/radix/themes/components/aspect_ratio.pyi +2 -3
  77. reflex/components/radix/themes/components/avatar.pyi +2 -3
  78. reflex/components/radix/themes/components/badge.pyi +2 -3
  79. reflex/components/radix/themes/components/button.pyi +2 -3
  80. reflex/components/radix/themes/components/callout.pyi +5 -9
  81. reflex/components/radix/themes/components/card.pyi +2 -3
  82. reflex/components/radix/themes/components/checkbox.pyi +3 -5
  83. reflex/components/radix/themes/components/checkbox_cards.pyi +3 -5
  84. reflex/components/radix/themes/components/checkbox_group.pyi +3 -5
  85. reflex/components/radix/themes/components/context_menu.pyi +14 -27
  86. reflex/components/radix/themes/components/data_list.pyi +5 -9
  87. reflex/components/radix/themes/components/dialog.pyi +7 -13
  88. reflex/components/radix/themes/components/dropdown_menu.pyi +9 -17
  89. reflex/components/radix/themes/components/hover_card.pyi +4 -7
  90. reflex/components/radix/themes/components/icon_button.pyi +2 -3
  91. reflex/components/radix/themes/components/inset.pyi +2 -3
  92. reflex/components/radix/themes/components/popover.pyi +5 -9
  93. reflex/components/radix/themes/components/progress.pyi +2 -3
  94. reflex/components/radix/themes/components/radio.pyi +2 -3
  95. reflex/components/radix/themes/components/radio_cards.pyi +3 -5
  96. reflex/components/radix/themes/components/radio_group.pyi +4 -7
  97. reflex/components/radix/themes/components/scroll_area.pyi +2 -3
  98. reflex/components/radix/themes/components/segmented_control.pyi +3 -5
  99. reflex/components/radix/themes/components/select.pyi +9 -17
  100. reflex/components/radix/themes/components/separator.pyi +2 -3
  101. reflex/components/radix/themes/components/skeleton.pyi +2 -3
  102. reflex/components/radix/themes/components/slider.pyi +12 -5
  103. reflex/components/radix/themes/components/spinner.pyi +2 -3
  104. reflex/components/radix/themes/components/switch.pyi +2 -3
  105. reflex/components/radix/themes/components/table.pyi +8 -15
  106. reflex/components/radix/themes/components/tabs.pyi +5 -9
  107. reflex/components/radix/themes/components/text_area.pyi +10 -5
  108. reflex/components/radix/themes/components/text_field.pyi +19 -9
  109. reflex/components/radix/themes/components/tooltip.pyi +2 -3
  110. reflex/components/radix/themes/layout/__init__.pyi +27 -14
  111. reflex/components/radix/themes/layout/base.pyi +2 -3
  112. reflex/components/radix/themes/layout/box.pyi +2 -3
  113. reflex/components/radix/themes/layout/center.pyi +2 -3
  114. reflex/components/radix/themes/layout/container.pyi +2 -3
  115. reflex/components/radix/themes/layout/flex.pyi +2 -3
  116. reflex/components/radix/themes/layout/grid.pyi +2 -3
  117. reflex/components/radix/themes/layout/list.pyi +5 -9
  118. reflex/components/radix/themes/layout/section.pyi +2 -3
  119. reflex/components/radix/themes/layout/spacer.pyi +2 -3
  120. reflex/components/radix/themes/layout/stack.pyi +4 -7
  121. reflex/components/radix/themes/typography/__init__.pyi +7 -5
  122. reflex/components/radix/themes/typography/blockquote.pyi +2 -3
  123. reflex/components/radix/themes/typography/code.pyi +2 -3
  124. reflex/components/radix/themes/typography/heading.pyi +2 -3
  125. reflex/components/radix/themes/typography/link.pyi +3 -5
  126. reflex/components/radix/themes/typography/text.pyi +7 -13
  127. reflex/components/react_player/audio.pyi +5 -4
  128. reflex/components/react_player/react_player.pyi +2 -3
  129. reflex/components/react_player/video.pyi +5 -4
  130. reflex/components/recharts/__init__.pyi +208 -100
  131. reflex/components/recharts/cartesian.py +8 -7
  132. reflex/components/recharts/cartesian.pyi +25 -48
  133. reflex/components/recharts/charts.pyi +13 -25
  134. reflex/components/recharts/general.pyi +7 -13
  135. reflex/components/recharts/polar.pyi +7 -13
  136. reflex/components/recharts/recharts.py +2 -2
  137. reflex/components/recharts/recharts.pyi +3 -5
  138. reflex/components/sonner/toast.py +1 -1
  139. reflex/components/sonner/toast.pyi +2 -3
  140. reflex/constants/installer.py +7 -8
  141. reflex/constants/route.py +13 -6
  142. reflex/istate/__init__.py +69 -0
  143. reflex/istate/manager.py +1 -0
  144. reflex/plugins/shared_tailwind.py +58 -1
  145. reflex/plugins/tailwind_v3.py +4 -4
  146. reflex/plugins/tailwind_v4.py +6 -5
  147. reflex/route.py +159 -71
  148. reflex/state.py +38 -16
  149. reflex/testing.py +2 -1
  150. reflex/utils/exec.py +18 -13
  151. reflex/utils/format.py +1 -5
  152. reflex/utils/imports.py +5 -12
  153. reflex/utils/misc.py +40 -0
  154. reflex/utils/prerequisites.py +7 -12
  155. reflex/utils/processes.py +8 -41
  156. reflex/utils/pyi_generator.py +23 -40
  157. reflex/utils/telemetry.py +0 -15
  158. reflex/utils/types.py +1 -1
  159. {reflex-0.8.0a4.dist-info → reflex-0.8.0a6.dist-info}/METADATA +3 -3
  160. {reflex-0.8.0a4.dist-info → reflex-0.8.0a6.dist-info}/RECORD +163 -163
  161. {reflex-0.8.0a4.dist-info → reflex-0.8.0a6.dist-info}/WHEEL +0 -0
  162. {reflex-0.8.0a4.dist-info → reflex-0.8.0a6.dist-info}/entry_points.txt +0 -0
  163. {reflex-0.8.0a4.dist-info → reflex-0.8.0a6.dist-info}/licenses/LICENSE +0 -0
@@ -34,7 +34,7 @@ function AppWrap({children}) {
34
34
 
35
35
 
36
36
  export function Layout({children}) {
37
- React.useEffect(() => {
37
+ useEffect(() => {
38
38
  // Make contexts and state objects available globally for dynamic eval'd components
39
39
  let windowImports = {
40
40
  {% for library_alias, library_path in window_libraries %}
@@ -1,4 +1,5 @@
1
1
  {%- block imports_styles %}
2
+ @layer __reflex_base;
2
3
  {% for sheet_name in stylesheets %}
3
4
  {{- "@import url('" + sheet_name + "'); " }}
4
5
  {% endfor %}
@@ -2,9 +2,9 @@ import { route } from "@react-router/dev/routes";
2
2
  import { flatRoutes } from "@react-router/fs-routes";
3
3
 
4
4
  export default [
5
- route("404", "routes/[404]_._index.jsx", { id: "404" }),
5
+ route("404", "routes/[404]._index.jsx", { id: "404" }),
6
6
  ...(await flatRoutes({
7
- ignoredRouteFiles: ["routes/\\[404\\]_._index.jsx"],
7
+ ignoredRouteFiles: ["routes/\\[404\\]._index.jsx"],
8
8
  })),
9
- route("*", "routes/[404]_._index.jsx"),
9
+ route("*", "routes/[404]._index.jsx"),
10
10
  ];
@@ -25,7 +25,7 @@ export const useClientSideRouting = () => {
25
25
  const search = window.location.search;
26
26
 
27
27
  // Use navigate instead of replace
28
- navigate(path + search, { replace: true })
28
+ navigate(path + search, { replace: true, state: { fromNotFound: true } })
29
29
  .then(() => {
30
30
  // Check if we're still on a NotFound route
31
31
  // Note: This depends on how your routes are set up
@@ -1,11 +1,10 @@
1
1
  // State management for Reflex web apps.
2
- import axios from "axios";
3
2
  import io from "socket.io-client";
4
3
  import JSON5 from "json5";
5
4
  import env from "$/env.json";
6
5
  import reflexEnvironment from "$/reflex.json";
7
6
  import Cookies from "universal-cookie";
8
- import { useEffect, useRef, useState } from "react";
7
+ import { useCallback, useEffect, useRef, useState } from "react";
9
8
  import {
10
9
  useLocation,
11
10
  useNavigate,
@@ -655,17 +654,6 @@ export const uploadFiles = async (
655
654
  };
656
655
 
657
656
  const controller = new AbortController();
658
- const config = {
659
- headers: {
660
- "Reflex-Client-Token": getToken(),
661
- "Reflex-Event-Handler": handler,
662
- },
663
- signal: controller.signal,
664
- onDownloadProgress: eventHandler,
665
- };
666
- if (on_upload_progress) {
667
- config["onUploadProgress"] = on_upload_progress;
668
- }
669
657
  const formdata = new FormData();
670
658
 
671
659
  // Add the token and handler to the file name.
@@ -676,26 +664,85 @@ export const uploadFiles = async (
676
664
  // Send the file to the server.
677
665
  refs[upload_ref_name] = controller;
678
666
 
679
- try {
680
- return await axios.post(getBackendURL(UPLOADURL), formdata, config);
681
- } catch (error) {
682
- if (error.response) {
683
- // The request was made and the server responded with a status code
684
- // that falls out of the range of 2xx
685
- console.log(error.response.data);
686
- } else if (error.request) {
687
- // The request was made but no response was received
688
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
689
- // http.ClientRequest in node.js
690
- console.log(error.request);
691
- } else {
692
- // Something happened in setting up the request that triggered an Error
693
- console.log(error.message);
667
+ return new Promise((resolve, reject) => {
668
+ const xhr = new XMLHttpRequest();
669
+
670
+ // Set up event handlers
671
+ xhr.onload = function () {
672
+ if (xhr.status >= 200 && xhr.status < 300) {
673
+ resolve({
674
+ data: xhr.responseText,
675
+ status: xhr.status,
676
+ statusText: xhr.statusText,
677
+ headers: {
678
+ get: (name) => xhr.getResponseHeader(name),
679
+ },
680
+ });
681
+ } else {
682
+ reject(new Error(`HTTP error! status: ${xhr.status}`));
683
+ }
684
+ };
685
+
686
+ xhr.onerror = function () {
687
+ reject(new Error("Network error"));
688
+ };
689
+
690
+ xhr.onabort = function () {
691
+ reject(new Error("Upload aborted"));
692
+ };
693
+
694
+ // Handle upload progress
695
+ if (on_upload_progress) {
696
+ xhr.upload.onprogress = function (event) {
697
+ if (event.lengthComputable) {
698
+ const progressEvent = {
699
+ loaded: event.loaded,
700
+ total: event.total,
701
+ progress: event.loaded / event.total,
702
+ };
703
+ on_upload_progress(progressEvent);
704
+ }
705
+ };
694
706
  }
695
- return false;
696
- } finally {
697
- delete refs[upload_ref_name];
698
- }
707
+
708
+ // Handle download progress with streaming response parsing
709
+ xhr.onprogress = function (event) {
710
+ if (eventHandler) {
711
+ const progressEvent = {
712
+ event: {
713
+ target: {
714
+ responseText: xhr.responseText,
715
+ },
716
+ },
717
+ progress: event.lengthComputable ? event.loaded / event.total : 0,
718
+ };
719
+ eventHandler(progressEvent);
720
+ }
721
+ };
722
+
723
+ // Handle abort controller
724
+ controller.signal.addEventListener("abort", () => {
725
+ xhr.abort();
726
+ });
727
+
728
+ // Configure and send request
729
+ xhr.open("POST", getBackendURL(UPLOADURL));
730
+ xhr.setRequestHeader("Reflex-Client-Token", getToken());
731
+ xhr.setRequestHeader("Reflex-Event-Handler", handler);
732
+
733
+ try {
734
+ xhr.send(formdata);
735
+ } catch (error) {
736
+ reject(error);
737
+ }
738
+ })
739
+ .catch((error) => {
740
+ console.log("Upload error:", error.message);
741
+ return false;
742
+ })
743
+ .finally(() => {
744
+ delete refs[upload_ref_name];
745
+ });
699
746
  };
700
747
 
701
748
  /**
@@ -851,7 +898,7 @@ export const useEventLoop = (
851
898
  }, [paramsR]);
852
899
 
853
900
  // Function to add new events to the event queue.
854
- const addEvents = (events, args, event_actions) => {
901
+ const addEvents = useCallback((events, args, event_actions) => {
855
902
  const _events = events.filter((e) => e !== undefined && e !== null);
856
903
 
857
904
  if (!(args instanceof Array)) {
@@ -894,7 +941,7 @@ export const useEventLoop = (
894
941
  } else {
895
942
  queueEvents(_events, socket, false, navigate, () => params.current);
896
943
  }
897
- };
944
+ }, []);
898
945
 
899
946
  const sentHydrate = useRef(false); // Avoid double-hydrate due to React strict-mode
900
947
  useEffect(() => {
@@ -1020,31 +1067,42 @@ export const useEventLoop = (
1020
1067
  return () => window.removeEventListener("storage", handleStorage);
1021
1068
  });
1022
1069
 
1070
+ const handleNavigationEvents = useRef(false);
1023
1071
  // Route after the initial page hydration
1024
1072
  useEffect(() => {
1073
+ // The first time this effect runs is initial load, so don't handle
1074
+ // any navigation events.
1075
+ if (!handleNavigationEvents.current) {
1076
+ handleNavigationEvents.current = true;
1077
+ return;
1078
+ }
1079
+ if (location.state?.fromNotFound) {
1080
+ // If the redirect is from a 404 page, we skip onLoadInternalEvent,
1081
+ // since it was already run when the 404 page was first rendered.
1082
+ return;
1083
+ }
1025
1084
  // This will run when the location changes
1026
1085
  if (
1027
- location.pathname + location.search + location.hash !==
1028
- prevLocationRef.current.pathname +
1029
- prevLocationRef.current.search +
1030
- prevLocationRef.current.hash
1086
+ location.pathname + location.search ===
1087
+ prevLocationRef.current.pathname + prevLocationRef.current.search
1031
1088
  ) {
1032
- // Equivalent to routeChangeStart - runs when navigation begins
1033
- const change_start = () => {
1034
- const main_state_dispatch = dispatch["reflex___state____state"];
1035
- if (main_state_dispatch !== undefined) {
1036
- main_state_dispatch({ is_hydrated_rx_state_: false });
1037
- }
1038
- };
1039
- change_start();
1040
-
1041
- // Equivalent to routeChangeComplete - runs after navigation completes
1042
- const change_complete = () => addEvents(onLoadInternalEvent());
1043
- change_complete();
1089
+ if (location.hash) {
1090
+ // If the hash is the same, we don't need to do anything.
1091
+ return;
1092
+ }
1093
+ }
1044
1094
 
1045
- // Update the ref
1046
- prevLocationRef.current = location;
1095
+ // Equivalent to routeChangeStart - runs when navigation begins
1096
+ const main_state_dispatch = dispatch["reflex___state____state"];
1097
+ if (main_state_dispatch !== undefined) {
1098
+ main_state_dispatch({ is_hydrated_rx_state_: false });
1047
1099
  }
1100
+
1101
+ // Equivalent to routeChangeComplete - runs after navigation completes
1102
+ addEvents(onLoadInternalEvent());
1103
+
1104
+ // Update the ref
1105
+ prevLocationRef.current = location;
1048
1106
  }, [location, dispatch, onLoadInternalEvent, addEvents]);
1049
1107
 
1050
1108
  return [addEvents, connectErrors];