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/sequence.py CHANGED
@@ -11,7 +11,6 @@ import typing
11
11
  from typing import (
12
12
  TYPE_CHECKING,
13
13
  Any,
14
- ClassVar,
15
14
  Dict,
16
15
  List,
17
16
  Literal,
@@ -19,27 +18,28 @@ from typing import (
19
18
  Set,
20
19
  Tuple,
21
20
  Type,
22
- TypeVar,
23
21
  Union,
24
22
  overload,
25
23
  )
26
24
 
25
+ from typing_extensions import TypeVar
26
+
27
27
  from reflex import constants
28
28
  from reflex.constants.base import REFLEX_VAR_OPENING_TAG
29
+ from reflex.constants.colors import Color
29
30
  from reflex.utils.exceptions import VarTypeError
30
31
  from reflex.utils.types import GenericType, get_origin
31
32
 
32
33
  from .base import (
33
34
  CachedVarOperation,
34
35
  CustomVarOperationReturn,
35
- LiteralNoneVar,
36
36
  LiteralVar,
37
- ToOperation,
38
37
  Var,
39
38
  VarData,
40
39
  _global_vars,
41
40
  cached_property_no_lock,
42
41
  figure_out_type,
42
+ get_python_literal,
43
43
  get_unique_variable_name,
44
44
  unionize,
45
45
  var_operation,
@@ -50,13 +50,16 @@ from .number import (
50
50
  LiteralNumberVar,
51
51
  NumberVar,
52
52
  raise_unsupported_operand_types,
53
+ ternary_operation,
53
54
  )
54
55
 
55
56
  if TYPE_CHECKING:
56
57
  from .object import ObjectVar
57
58
 
59
+ STRING_TYPE = TypeVar("STRING_TYPE", default=str)
60
+
58
61
 
59
- class StringVar(Var[str]):
62
+ class StringVar(Var[STRING_TYPE], python_types=str):
60
63
  """Base class for immutable string vars."""
61
64
 
62
65
  @overload
@@ -350,7 +353,7 @@ class StringVar(Var[str]):
350
353
 
351
354
 
352
355
  @var_operation
353
- def string_lt_operation(lhs: StringVar | str, rhs: StringVar | str):
356
+ def string_lt_operation(lhs: StringVar[Any] | str, rhs: StringVar[Any] | str):
354
357
  """Check if a string is less than another string.
355
358
 
356
359
  Args:
@@ -364,7 +367,7 @@ def string_lt_operation(lhs: StringVar | str, rhs: StringVar | str):
364
367
 
365
368
 
366
369
  @var_operation
367
- def string_gt_operation(lhs: StringVar | str, rhs: StringVar | str):
370
+ def string_gt_operation(lhs: StringVar[Any] | str, rhs: StringVar[Any] | str):
368
371
  """Check if a string is greater than another string.
369
372
 
370
373
  Args:
@@ -378,7 +381,7 @@ def string_gt_operation(lhs: StringVar | str, rhs: StringVar | str):
378
381
 
379
382
 
380
383
  @var_operation
381
- def string_le_operation(lhs: StringVar | str, rhs: StringVar | str):
384
+ def string_le_operation(lhs: StringVar[Any] | str, rhs: StringVar[Any] | str):
382
385
  """Check if a string is less than or equal to another string.
383
386
 
384
387
  Args:
@@ -392,7 +395,7 @@ def string_le_operation(lhs: StringVar | str, rhs: StringVar | str):
392
395
 
393
396
 
394
397
  @var_operation
395
- def string_ge_operation(lhs: StringVar | str, rhs: StringVar | str):
398
+ def string_ge_operation(lhs: StringVar[Any] | str, rhs: StringVar[Any] | str):
396
399
  """Check if a string is greater than or equal to another string.
397
400
 
398
401
  Args:
@@ -406,7 +409,7 @@ def string_ge_operation(lhs: StringVar | str, rhs: StringVar | str):
406
409
 
407
410
 
408
411
  @var_operation
409
- def string_lower_operation(string: StringVar):
412
+ def string_lower_operation(string: StringVar[Any]):
410
413
  """Convert a string to lowercase.
411
414
 
412
415
  Args:
@@ -419,7 +422,7 @@ def string_lower_operation(string: StringVar):
419
422
 
420
423
 
421
424
  @var_operation
422
- def string_upper_operation(string: StringVar):
425
+ def string_upper_operation(string: StringVar[Any]):
423
426
  """Convert a string to uppercase.
424
427
 
425
428
  Args:
@@ -432,7 +435,7 @@ def string_upper_operation(string: StringVar):
432
435
 
433
436
 
434
437
  @var_operation
435
- def string_strip_operation(string: StringVar):
438
+ def string_strip_operation(string: StringVar[Any]):
436
439
  """Strip a string.
437
440
 
438
441
  Args:
@@ -446,7 +449,7 @@ def string_strip_operation(string: StringVar):
446
449
 
447
450
  @var_operation
448
451
  def string_contains_field_operation(
449
- haystack: StringVar, needle: StringVar | str, field: StringVar | str
452
+ haystack: StringVar[Any], needle: StringVar[Any] | str, field: StringVar[Any] | str
450
453
  ):
451
454
  """Check if a string contains another string.
452
455
 
@@ -465,7 +468,7 @@ def string_contains_field_operation(
465
468
 
466
469
 
467
470
  @var_operation
468
- def string_contains_operation(haystack: StringVar, needle: StringVar | str):
471
+ def string_contains_operation(haystack: StringVar[Any], needle: StringVar[Any] | str):
469
472
  """Check if a string contains another string.
470
473
 
471
474
  Args:
@@ -481,7 +484,9 @@ def string_contains_operation(haystack: StringVar, needle: StringVar | str):
481
484
 
482
485
 
483
486
  @var_operation
484
- def string_starts_with_operation(full_string: StringVar, prefix: StringVar | str):
487
+ def string_starts_with_operation(
488
+ full_string: StringVar[Any], prefix: StringVar[Any] | str
489
+ ):
485
490
  """Check if a string starts with a prefix.
486
491
 
487
492
  Args:
@@ -497,7 +502,7 @@ def string_starts_with_operation(full_string: StringVar, prefix: StringVar | str
497
502
 
498
503
 
499
504
  @var_operation
500
- def string_item_operation(string: StringVar, index: NumberVar | int):
505
+ def string_item_operation(string: StringVar[Any], index: NumberVar | int):
501
506
  """Get an item from a string.
502
507
 
503
508
  Args:
@@ -511,7 +516,7 @@ def string_item_operation(string: StringVar, index: NumberVar | int):
511
516
 
512
517
 
513
518
  @var_operation
514
- def array_join_operation(array: ArrayVar, sep: StringVar | str = ""):
519
+ def array_join_operation(array: ArrayVar, sep: StringVar[Any] | str = ""):
515
520
  """Join the elements of an array.
516
521
 
517
522
  Args:
@@ -524,6 +529,26 @@ def array_join_operation(array: ArrayVar, sep: StringVar | str = ""):
524
529
  return var_operation_return(js_expression=f"{array}.join({sep})", var_type=str)
525
530
 
526
531
 
532
+ @var_operation
533
+ def string_replace_operation(
534
+ string: StringVar, search_value: StringVar | str, new_value: StringVar | str
535
+ ):
536
+ """Replace a string with a value.
537
+
538
+ Args:
539
+ string: The string.
540
+ search_value: The string to search.
541
+ new_value: The value to be replaced with.
542
+
543
+ Returns:
544
+ The string replace operation.
545
+ """
546
+ return var_operation_return(
547
+ js_expression=f"{string}.replace({search_value}, {new_value})",
548
+ var_type=str,
549
+ )
550
+
551
+
527
552
  # Compile regex for finding reflex var tags.
528
553
  _decode_var_pattern_re = (
529
554
  rf"{constants.REFLEX_VAR_OPENING_TAG}(.*?){constants.REFLEX_VAR_CLOSING_TAG}"
@@ -536,7 +561,7 @@ _decode_var_pattern = re.compile(_decode_var_pattern_re, flags=re.DOTALL)
536
561
  frozen=True,
537
562
  **{"slots": True} if sys.version_info >= (3, 10) else {},
538
563
  )
539
- class LiteralStringVar(LiteralVar, StringVar):
564
+ class LiteralStringVar(LiteralVar, StringVar[str]):
540
565
  """Base class for immutable literal string vars."""
541
566
 
542
567
  _var_value: str = dataclasses.field(default="")
@@ -658,7 +683,7 @@ class LiteralStringVar(LiteralVar, StringVar):
658
683
  frozen=True,
659
684
  **{"slots": True} if sys.version_info >= (3, 10) else {},
660
685
  )
661
- class ConcatVarOperation(CachedVarOperation, StringVar):
686
+ class ConcatVarOperation(CachedVarOperation, StringVar[str]):
662
687
  """Representing a concatenation of literal string vars."""
663
688
 
664
689
  _var_value: Tuple[Var, ...] = dataclasses.field(default_factory=tuple)
@@ -742,7 +767,7 @@ KEY_TYPE = TypeVar("KEY_TYPE")
742
767
  VALUE_TYPE = TypeVar("VALUE_TYPE")
743
768
 
744
769
 
745
- class ArrayVar(Var[ARRAY_VAR_TYPE]):
770
+ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
746
771
  """Base class for immutable array vars."""
747
772
 
748
773
  @overload
@@ -1275,7 +1300,7 @@ class LiteralArrayVar(CachedVarOperation, LiteralVar, ArrayVar[ARRAY_VAR_TYPE]):
1275
1300
 
1276
1301
 
1277
1302
  @var_operation
1278
- def string_split_operation(string: StringVar, sep: StringVar | str = ""):
1303
+ def string_split_operation(string: StringVar[Any], sep: StringVar | str = ""):
1279
1304
  """Split a string.
1280
1305
 
1281
1306
  Args:
@@ -1572,32 +1597,6 @@ def array_contains_operation(haystack: ArrayVar, needle: Any | Var):
1572
1597
  )
1573
1598
 
1574
1599
 
1575
- @dataclasses.dataclass(
1576
- eq=False,
1577
- frozen=True,
1578
- **{"slots": True} if sys.version_info >= (3, 10) else {},
1579
- )
1580
- class ToStringOperation(ToOperation, StringVar):
1581
- """Base class for immutable string vars that are the result of a to string operation."""
1582
-
1583
- _original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())
1584
-
1585
- _default_var_type: ClassVar[Type] = str
1586
-
1587
-
1588
- @dataclasses.dataclass(
1589
- eq=False,
1590
- frozen=True,
1591
- **{"slots": True} if sys.version_info >= (3, 10) else {},
1592
- )
1593
- class ToArrayOperation(ToOperation, ArrayVar):
1594
- """Base class for immutable array vars that are the result of a to array operation."""
1595
-
1596
- _original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())
1597
-
1598
- _default_var_type: ClassVar[Type] = List[Any]
1599
-
1600
-
1601
1600
  @var_operation
1602
1601
  def repeat_array_operation(
1603
1602
  array: ArrayVar[ARRAY_VAR_TYPE], count: NumberVar | int
@@ -1657,3 +1656,134 @@ def array_concat_operation(
1657
1656
  js_expression=f"[...{lhs}, ...{rhs}]",
1658
1657
  var_type=Union[lhs._var_type, rhs._var_type],
1659
1658
  )
1659
+
1660
+
1661
+ class ColorVar(StringVar[Color], python_types=Color):
1662
+ """Base class for immutable color vars."""
1663
+
1664
+
1665
+ @dataclasses.dataclass(
1666
+ eq=False,
1667
+ frozen=True,
1668
+ **{"slots": True} if sys.version_info >= (3, 10) else {},
1669
+ )
1670
+ class LiteralColorVar(CachedVarOperation, LiteralVar, ColorVar):
1671
+ """Base class for immutable literal color vars."""
1672
+
1673
+ _var_value: Color = dataclasses.field(default_factory=lambda: Color(color="black"))
1674
+
1675
+ @classmethod
1676
+ def create(
1677
+ cls,
1678
+ value: Color,
1679
+ _var_type: Type[Color] | None = None,
1680
+ _var_data: VarData | None = None,
1681
+ ) -> ColorVar:
1682
+ """Create a var from a string value.
1683
+
1684
+ Args:
1685
+ value: The value to create the var from.
1686
+ _var_type: The type of the var.
1687
+ _var_data: Additional hooks and imports associated with the Var.
1688
+
1689
+ Returns:
1690
+ The var.
1691
+ """
1692
+ return cls(
1693
+ _js_expr="",
1694
+ _var_type=_var_type or Color,
1695
+ _var_data=_var_data,
1696
+ _var_value=value,
1697
+ )
1698
+
1699
+ def __hash__(self) -> int:
1700
+ """Get the hash of the var.
1701
+
1702
+ Returns:
1703
+ The hash of the var.
1704
+ """
1705
+ return hash(
1706
+ (
1707
+ self.__class__.__name__,
1708
+ self._var_value.color,
1709
+ self._var_value.alpha,
1710
+ self._var_value.shade,
1711
+ )
1712
+ )
1713
+
1714
+ @cached_property_no_lock
1715
+ def _cached_var_name(self) -> str:
1716
+ """The name of the var.
1717
+
1718
+ Returns:
1719
+ The name of the var.
1720
+ """
1721
+ alpha = self._var_value.alpha
1722
+ alpha = (
1723
+ ternary_operation(
1724
+ alpha,
1725
+ LiteralStringVar.create("a"),
1726
+ LiteralStringVar.create(""),
1727
+ )
1728
+ if isinstance(alpha, Var)
1729
+ else LiteralStringVar.create("a" if alpha else "")
1730
+ )
1731
+
1732
+ shade = self._var_value.shade
1733
+ shade = (
1734
+ shade.to_string(use_json=False)
1735
+ if isinstance(shade, Var)
1736
+ else LiteralStringVar.create(str(shade))
1737
+ )
1738
+ return str(
1739
+ ConcatVarOperation.create(
1740
+ LiteralStringVar.create("var(--"),
1741
+ self._var_value.color,
1742
+ LiteralStringVar.create("-"),
1743
+ alpha,
1744
+ shade,
1745
+ LiteralStringVar.create(")"),
1746
+ )
1747
+ )
1748
+
1749
+ @cached_property_no_lock
1750
+ def _cached_get_all_var_data(self) -> VarData | None:
1751
+ """Get all the var data.
1752
+
1753
+ Returns:
1754
+ The var data.
1755
+ """
1756
+ return VarData.merge(
1757
+ *[
1758
+ LiteralVar.create(var)._get_all_var_data()
1759
+ for var in (
1760
+ self._var_value.color,
1761
+ self._var_value.alpha,
1762
+ self._var_value.shade,
1763
+ )
1764
+ ],
1765
+ self._var_data,
1766
+ )
1767
+
1768
+ def json(self) -> str:
1769
+ """Get the JSON representation of the var.
1770
+
1771
+ Returns:
1772
+ The JSON representation of the var.
1773
+
1774
+ Raises:
1775
+ TypeError: If the color is not a valid color.
1776
+ """
1777
+ color, alpha, shade = map(
1778
+ get_python_literal,
1779
+ (self._var_value.color, self._var_value.alpha, self._var_value.shade),
1780
+ )
1781
+ if color is None or alpha is None or shade is None:
1782
+ raise TypeError("Cannot serialize color that contains non-literal vars.")
1783
+ if (
1784
+ not isinstance(color, str)
1785
+ or not isinstance(alpha, bool)
1786
+ or not isinstance(shade, int)
1787
+ ):
1788
+ raise TypeError("Color is not a valid color.")
1789
+ return f"var(--{color}-{'a' if alpha else ''}{shade})"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: reflex
3
- Version: 0.6.3a4
3
+ Version: 0.6.4
4
4
  Summary: Web apps in pure Python.
5
5
  Home-page: https://reflex.dev
6
6
  License: Apache-2.0