reflex 0.6.3a4__py3-none-any.whl → 0.6.4__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 (96) hide show
  1. reflex/.templates/jinja/web/pages/_app.js.jinja2 +2 -2
  2. reflex/.templates/jinja/web/utils/context.js.jinja2 +3 -1
  3. reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +3 -3
  4. reflex/.templates/web/components/shiki/code.js +29 -0
  5. reflex/.templates/web/jsconfig.json +2 -1
  6. reflex/.templates/web/utils/state.js +6 -4
  7. reflex/__init__.py +6 -3
  8. reflex/__init__.pyi +4 -3
  9. reflex/app.py +6 -5
  10. reflex/compiler/compiler.py +6 -7
  11. reflex/compiler/utils.py +8 -1
  12. reflex/components/base/error_boundary.py +37 -24
  13. reflex/components/base/error_boundary.pyi +8 -7
  14. reflex/components/component.py +9 -4
  15. reflex/components/core/banner.py +2 -2
  16. reflex/components/core/client_side_routing.py +1 -1
  17. reflex/components/core/clipboard.py +1 -1
  18. reflex/components/core/clipboard.pyi +1 -1
  19. reflex/components/core/cond.py +1 -1
  20. reflex/components/core/debounce.py +5 -1
  21. reflex/components/core/upload.py +7 -9
  22. reflex/components/core/upload.pyi +2 -2
  23. reflex/components/datadisplay/code.py +1 -1
  24. reflex/components/datadisplay/dataeditor.py +83 -18
  25. reflex/components/datadisplay/dataeditor.pyi +67 -15
  26. reflex/components/datadisplay/shiki_code_block.py +813 -0
  27. reflex/components/datadisplay/shiki_code_block.pyi +2211 -0
  28. reflex/components/dynamic.py +3 -3
  29. reflex/components/el/elements/forms.py +37 -23
  30. reflex/components/el/elements/forms.pyi +7 -4
  31. reflex/components/markdown/markdown.py +12 -1
  32. reflex/components/moment/moment.pyi +1 -1
  33. reflex/components/radix/primitives/drawer.pyi +2 -2
  34. reflex/components/radix/themes/base.py +2 -2
  35. reflex/components/radix/themes/color_mode.pyi +1 -1
  36. reflex/components/radix/themes/components/alert_dialog.pyi +1 -1
  37. reflex/components/radix/themes/components/checkbox.pyi +3 -3
  38. reflex/components/radix/themes/components/context_menu.pyi +1 -1
  39. reflex/components/radix/themes/components/dialog.pyi +2 -2
  40. reflex/components/radix/themes/components/dropdown_menu.pyi +2 -2
  41. reflex/components/radix/themes/components/hover_card.pyi +2 -2
  42. reflex/components/radix/themes/components/popover.pyi +1 -1
  43. reflex/components/radix/themes/components/radio_cards.pyi +1 -1
  44. reflex/components/radix/themes/components/radio_group.pyi +1 -1
  45. reflex/components/radix/themes/components/select.pyi +6 -6
  46. reflex/components/radix/themes/components/switch.pyi +1 -1
  47. reflex/components/radix/themes/components/tabs.pyi +2 -2
  48. reflex/components/radix/themes/components/tooltip.pyi +4 -2
  49. reflex/components/react_player/__init__.py +1 -0
  50. reflex/components/react_player/audio.pyi +6 -3
  51. reflex/components/react_player/react_player.py +12 -1
  52. reflex/components/react_player/react_player.pyi +11 -3
  53. reflex/components/react_player/video.pyi +6 -3
  54. reflex/components/recharts/recharts.py +2 -2
  55. reflex/components/sonner/toast.py +1 -1
  56. reflex/components/suneditor/editor.py +40 -16
  57. reflex/components/suneditor/editor.pyi +15 -11
  58. reflex/config.py +284 -20
  59. reflex/constants/__init__.py +2 -0
  60. reflex/constants/base.py +53 -31
  61. reflex/constants/compiler.py +2 -12
  62. reflex/constants/config.py +1 -2
  63. reflex/constants/installer.py +88 -32
  64. reflex/constants/style.py +1 -1
  65. reflex/constants/utils.py +32 -0
  66. reflex/custom_components/custom_components.py +3 -3
  67. reflex/event.py +152 -84
  68. reflex/experimental/__init__.py +2 -0
  69. reflex/experimental/client_state.py +1 -1
  70. reflex/experimental/layout.pyi +1 -1
  71. reflex/istate/storage.py +144 -0
  72. reflex/model.py +8 -11
  73. reflex/reflex.py +18 -17
  74. reflex/state.py +89 -151
  75. reflex/style.py +1 -1
  76. reflex/testing.py +2 -1
  77. reflex/utils/build.py +0 -12
  78. reflex/utils/exceptions.py +8 -0
  79. reflex/utils/exec.py +22 -4
  80. reflex/utils/imports.py +6 -0
  81. reflex/utils/net.py +2 -4
  82. reflex/utils/path_ops.py +7 -21
  83. reflex/utils/prerequisites.py +11 -17
  84. reflex/utils/pyi_generator.py +91 -3
  85. reflex/utils/registry.py +2 -6
  86. reflex/utils/types.py +14 -0
  87. reflex/vars/base.py +453 -424
  88. reflex/vars/function.py +6 -16
  89. reflex/vars/number.py +46 -67
  90. reflex/vars/object.py +1 -31
  91. reflex/vars/sequence.py +177 -47
  92. {reflex-0.6.3a4.dist-info → reflex-0.6.4.dist-info}/METADATA +1 -1
  93. {reflex-0.6.3a4.dist-info → reflex-0.6.4.dist-info}/RECORD +96 -91
  94. {reflex-0.6.3a4.dist-info → reflex-0.6.4.dist-info}/LICENSE +0 -0
  95. {reflex-0.6.3a4.dist-info → reflex-0.6.4.dist-info}/WHEEL +0 -0
  96. {reflex-0.6.3a4.dist-info → reflex-0.6.4.dist-info}/entry_points.txt +0 -0
reflex/vars/function.py CHANGED
@@ -4,21 +4,20 @@ from __future__ import annotations
4
4
 
5
5
  import dataclasses
6
6
  import sys
7
- from typing import Any, Callable, ClassVar, Optional, Tuple, Type, Union
7
+ from typing import Any, Callable, Optional, Tuple, Type, Union
8
8
 
9
9
  from reflex.utils.types import GenericType
10
10
 
11
11
  from .base import (
12
12
  CachedVarOperation,
13
13
  LiteralVar,
14
- ToOperation,
15
14
  Var,
16
15
  VarData,
17
16
  cached_property_no_lock,
18
17
  )
19
18
 
20
19
 
21
- class FunctionVar(Var[Callable]):
20
+ class FunctionVar(Var[Callable], python_types=Callable):
22
21
  """Base class for immutable function vars."""
23
22
 
24
23
  def __call__(self, *args: Var | Any) -> ArgsFunctionOperation:
@@ -180,17 +179,8 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar):
180
179
  )
181
180
 
182
181
 
183
- @dataclasses.dataclass(
184
- eq=False,
185
- frozen=True,
186
- **{"slots": True} if sys.version_info >= (3, 10) else {},
187
- )
188
- class ToFunctionOperation(ToOperation, FunctionVar):
189
- """Base class of converting a var to a function."""
190
-
191
- _original: Var = dataclasses.field(default_factory=lambda: LiteralVar.create(None))
192
-
193
- _default_var_type: ClassVar[GenericType] = Callable
194
-
195
-
196
182
  JSON_STRINGIFY = FunctionStringVar.create("JSON.stringify")
183
+ ARRAY_ISARRAY = FunctionStringVar.create("Array.isArray")
184
+ PROTOTYPE_TO_STRING = FunctionStringVar.create(
185
+ "((__to_string) => __to_string.toString())"
186
+ )
reflex/vars/number.py CHANGED
@@ -10,7 +10,6 @@ from typing import (
10
10
  TYPE_CHECKING,
11
11
  Any,
12
12
  Callable,
13
- ClassVar,
14
13
  NoReturn,
15
14
  Type,
16
15
  TypeVar,
@@ -25,9 +24,7 @@ from reflex.utils.types import is_optional
25
24
 
26
25
  from .base import (
27
26
  CustomVarOperationReturn,
28
- LiteralNoneVar,
29
27
  LiteralVar,
30
- ToOperation,
31
28
  Var,
32
29
  VarData,
33
30
  unionize,
@@ -58,7 +55,7 @@ def raise_unsupported_operand_types(
58
55
  )
59
56
 
60
57
 
61
- class NumberVar(Var[NUMBER_T]):
58
+ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
62
59
  """Base class for immutable number vars."""
63
60
 
64
61
  @overload
@@ -760,7 +757,7 @@ def number_trunc_operation(value: NumberVar):
760
757
  return var_operation_return(js_expression=f"Math.trunc({value})", var_type=int)
761
758
 
762
759
 
763
- class BooleanVar(NumberVar[bool]):
760
+ class BooleanVar(NumberVar[bool], python_types=bool):
764
761
  """Base class for immutable boolean vars."""
765
762
 
766
763
  def __invert__(self):
@@ -989,18 +986,25 @@ def boolean_not_operation(value: BooleanVar):
989
986
  frozen=True,
990
987
  **{"slots": True} if sys.version_info >= (3, 10) else {},
991
988
  )
992
- class LiteralBooleanVar(LiteralVar, BooleanVar):
993
- """Base class for immutable literal boolean vars."""
989
+ class LiteralNumberVar(LiteralVar, NumberVar):
990
+ """Base class for immutable literal number vars."""
994
991
 
995
- _var_value: bool = dataclasses.field(default=False)
992
+ _var_value: float | int = dataclasses.field(default=0)
996
993
 
997
994
  def json(self) -> str:
998
995
  """Get the JSON representation of the var.
999
996
 
1000
997
  Returns:
1001
998
  The JSON representation of the var.
999
+
1000
+ Raises:
1001
+ PrimitiveUnserializableToJSON: If the var is unserializable to JSON.
1002
1002
  """
1003
- return "true" if self._var_value else "false"
1003
+ if math.isinf(self._var_value) or math.isnan(self._var_value):
1004
+ raise PrimitiveUnserializableToJSON(
1005
+ f"No valid JSON representation for {self}"
1006
+ )
1007
+ return json.dumps(self._var_value)
1004
1008
 
1005
1009
  def __hash__(self) -> int:
1006
1010
  """Calculate the hash value of the object.
@@ -1011,19 +1015,26 @@ class LiteralBooleanVar(LiteralVar, BooleanVar):
1011
1015
  return hash((self.__class__.__name__, self._var_value))
1012
1016
 
1013
1017
  @classmethod
1014
- def create(cls, value: bool, _var_data: VarData | None = None):
1015
- """Create the boolean var.
1018
+ def create(cls, value: float | int, _var_data: VarData | None = None):
1019
+ """Create the number var.
1016
1020
 
1017
1021
  Args:
1018
1022
  value: The value of the var.
1019
1023
  _var_data: Additional hooks and imports associated with the Var.
1020
1024
 
1021
1025
  Returns:
1022
- The boolean var.
1026
+ The number var.
1023
1027
  """
1028
+ if math.isinf(value):
1029
+ js_expr = "Infinity" if value > 0 else "-Infinity"
1030
+ elif math.isnan(value):
1031
+ js_expr = "NaN"
1032
+ else:
1033
+ js_expr = str(value)
1034
+
1024
1035
  return cls(
1025
- _js_expr="true" if value else "false",
1026
- _var_type=bool,
1036
+ _js_expr=js_expr,
1037
+ _var_type=type(value),
1027
1038
  _var_data=_var_data,
1028
1039
  _var_value=value,
1029
1040
  )
@@ -1034,25 +1045,18 @@ class LiteralBooleanVar(LiteralVar, BooleanVar):
1034
1045
  frozen=True,
1035
1046
  **{"slots": True} if sys.version_info >= (3, 10) else {},
1036
1047
  )
1037
- class LiteralNumberVar(LiteralVar, NumberVar):
1038
- """Base class for immutable literal number vars."""
1048
+ class LiteralBooleanVar(LiteralVar, BooleanVar):
1049
+ """Base class for immutable literal boolean vars."""
1039
1050
 
1040
- _var_value: float | int = dataclasses.field(default=0)
1051
+ _var_value: bool = dataclasses.field(default=False)
1041
1052
 
1042
1053
  def json(self) -> str:
1043
1054
  """Get the JSON representation of the var.
1044
1055
 
1045
1056
  Returns:
1046
1057
  The JSON representation of the var.
1047
-
1048
- Raises:
1049
- PrimitiveUnserializableToJSON: If the var is unserializable to JSON.
1050
1058
  """
1051
- if math.isinf(self._var_value) or math.isnan(self._var_value):
1052
- raise PrimitiveUnserializableToJSON(
1053
- f"No valid JSON representation for {self}"
1054
- )
1055
- return json.dumps(self._var_value)
1059
+ return "true" if self._var_value else "false"
1056
1060
 
1057
1061
  def __hash__(self) -> int:
1058
1062
  """Calculate the hash value of the object.
@@ -1063,26 +1067,19 @@ class LiteralNumberVar(LiteralVar, NumberVar):
1063
1067
  return hash((self.__class__.__name__, self._var_value))
1064
1068
 
1065
1069
  @classmethod
1066
- def create(cls, value: float | int, _var_data: VarData | None = None):
1067
- """Create the number var.
1070
+ def create(cls, value: bool, _var_data: VarData | None = None):
1071
+ """Create the boolean var.
1068
1072
 
1069
1073
  Args:
1070
1074
  value: The value of the var.
1071
1075
  _var_data: Additional hooks and imports associated with the Var.
1072
1076
 
1073
1077
  Returns:
1074
- The number var.
1078
+ The boolean var.
1075
1079
  """
1076
- if math.isinf(value):
1077
- js_expr = "Infinity" if value > 0 else "-Infinity"
1078
- elif math.isnan(value):
1079
- js_expr = "NaN"
1080
- else:
1081
- js_expr = str(value)
1082
-
1083
1080
  return cls(
1084
- _js_expr=js_expr,
1085
- _var_type=type(value),
1081
+ _js_expr="true" if value else "false",
1082
+ _var_type=bool,
1086
1083
  _var_data=_var_data,
1087
1084
  _var_value=value,
1088
1085
  )
@@ -1092,34 +1089,8 @@ number_types = Union[NumberVar, int, float]
1092
1089
  boolean_types = Union[BooleanVar, bool]
1093
1090
 
1094
1091
 
1095
- @dataclasses.dataclass(
1096
- eq=False,
1097
- frozen=True,
1098
- **{"slots": True} if sys.version_info >= (3, 10) else {},
1099
- )
1100
- class ToNumberVarOperation(ToOperation, NumberVar):
1101
- """Base class for immutable number vars that are the result of a number operation."""
1102
-
1103
- _original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())
1104
-
1105
- _default_var_type: ClassVar[Type] = float
1106
-
1107
-
1108
- @dataclasses.dataclass(
1109
- eq=False,
1110
- frozen=True,
1111
- **{"slots": True} if sys.version_info >= (3, 10) else {},
1112
- )
1113
- class ToBooleanVarOperation(ToOperation, BooleanVar):
1114
- """Base class for immutable boolean vars that are the result of a boolean operation."""
1115
-
1116
- _original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())
1117
-
1118
- _default_var_type: ClassVar[Type] = bool
1119
-
1120
-
1121
1092
  _IS_TRUE_IMPORT: ImportDict = {
1122
- f"/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
1093
+ f"$/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
1123
1094
  }
1124
1095
 
1125
1096
 
@@ -1140,8 +1111,12 @@ def boolify(value: Var):
1140
1111
  )
1141
1112
 
1142
1113
 
1114
+ T = TypeVar("T")
1115
+ U = TypeVar("U")
1116
+
1117
+
1143
1118
  @var_operation
1144
- def ternary_operation(condition: BooleanVar, if_true: Var, if_false: Var):
1119
+ def ternary_operation(condition: BooleanVar, if_true: Var[T], if_false: Var[U]):
1145
1120
  """Create a ternary operation.
1146
1121
 
1147
1122
  Args:
@@ -1152,10 +1127,14 @@ def ternary_operation(condition: BooleanVar, if_true: Var, if_false: Var):
1152
1127
  Returns:
1153
1128
  The ternary operation.
1154
1129
  """
1155
- return var_operation_return(
1130
+ type_value: Union[Type[T], Type[U]] = unionize(
1131
+ if_true._var_type, if_false._var_type
1132
+ )
1133
+ value: CustomVarOperationReturn[Union[T, U]] = var_operation_return(
1156
1134
  js_expression=f"({condition} ? {if_true} : {if_false})",
1157
- var_type=unionize(if_true._var_type, if_false._var_type),
1135
+ var_type=type_value,
1158
1136
  )
1137
+ return value
1159
1138
 
1160
1139
 
1161
1140
  NUMBER_TYPES = (int, float, NumberVar)
reflex/vars/object.py CHANGED
@@ -8,7 +8,6 @@ import typing
8
8
  from inspect import isclass
9
9
  from typing import (
10
10
  Any,
11
- ClassVar,
12
11
  Dict,
13
12
  List,
14
13
  NoReturn,
@@ -27,7 +26,6 @@ from reflex.utils.types import GenericType, get_attribute_access_type, get_origi
27
26
  from .base import (
28
27
  CachedVarOperation,
29
28
  LiteralVar,
30
- ToOperation,
31
29
  Var,
32
30
  VarData,
33
31
  cached_property_no_lock,
@@ -48,7 +46,7 @@ ARRAY_INNER_TYPE = TypeVar("ARRAY_INNER_TYPE")
48
46
  OTHER_KEY_TYPE = TypeVar("OTHER_KEY_TYPE")
49
47
 
50
48
 
51
- class ObjectVar(Var[OBJECT_TYPE]):
49
+ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
52
50
  """Base class for immutable object vars."""
53
51
 
54
52
  def _key_type(self) -> Type:
@@ -521,34 +519,6 @@ class ObjectItemOperation(CachedVarOperation, Var):
521
519
  )
522
520
 
523
521
 
524
- @dataclasses.dataclass(
525
- eq=False,
526
- frozen=True,
527
- **{"slots": True} if sys.version_info >= (3, 10) else {},
528
- )
529
- class ToObjectOperation(ToOperation, ObjectVar):
530
- """Operation to convert a var to an object."""
531
-
532
- _original: Var = dataclasses.field(
533
- default_factory=lambda: LiteralObjectVar.create({})
534
- )
535
-
536
- _default_var_type: ClassVar[GenericType] = dict
537
-
538
- def __getattr__(self, name: str) -> Any:
539
- """Get an attribute of the var.
540
-
541
- Args:
542
- name: The name of the attribute.
543
-
544
- Returns:
545
- The attribute of the var.
546
- """
547
- if name == "_js_expr":
548
- return self._original._js_expr
549
- return ObjectVar.__getattr__(self, name)
550
-
551
-
552
522
  @var_operation
553
523
  def object_has_own_property_operation(object: ObjectVar, key: Var):
554
524
  """Check if an object has a key.