reflex 0.6.3.post1__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 +83 -149
  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.3.post1.dist-info → reflex-0.6.4.dist-info}/METADATA +1 -1
  93. {reflex-0.6.3.post1.dist-info → reflex-0.6.4.dist-info}/RECORD +96 -91
  94. {reflex-0.6.3.post1.dist-info → reflex-0.6.4.dist-info}/LICENSE +0 -0
  95. {reflex-0.6.3.post1.dist-info → reflex-0.6.4.dist-info}/WHEEL +0 -0
  96. {reflex-0.6.3.post1.dist-info → reflex-0.6.4.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,5 @@
1
1
  """Config constants."""
2
2
 
3
- import os
4
3
  from pathlib import Path
5
4
  from types import SimpleNamespace
6
5
 
@@ -9,7 +8,7 @@ from reflex.constants.base import Dirs, Reflex
9
8
  from .compiler import Ext
10
9
 
11
10
  # Alembic migrations
12
- ALEMBIC_CONFIG = os.environ.get("ALEMBIC_CONFIG", "alembic.ini")
11
+ ALEMBIC_CONFIG = "alembic.ini"
13
12
 
14
13
 
15
14
  class Config(SimpleNamespace):
@@ -3,9 +3,11 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import platform
6
+ from pathlib import Path
6
7
  from types import SimpleNamespace
7
8
 
8
- from .base import IS_WINDOWS, Reflex
9
+ from .base import IS_WINDOWS
10
+ from .utils import classproperty
9
11
 
10
12
 
11
13
  def get_fnm_name() -> str | None:
@@ -36,12 +38,9 @@ class Bun(SimpleNamespace):
36
38
 
37
39
  # The Bun version.
38
40
  VERSION = "1.1.29"
41
+
39
42
  # Min Bun Version
40
43
  MIN_VERSION = "0.7.0"
41
- # The directory to store the bun.
42
- ROOT_PATH = Reflex.DIR / "bun"
43
- # Default bun path.
44
- DEFAULT_PATH = ROOT_PATH / "bin" / ("bun" if not IS_WINDOWS else "bun.exe")
45
44
 
46
45
  # URL to bun install script.
47
46
  INSTALL_URL = "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/bun_install.sh"
@@ -50,11 +49,31 @@ class Bun(SimpleNamespace):
50
49
  WINDOWS_INSTALL_URL = (
51
50
  "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/install.ps1"
52
51
  )
52
+
53
53
  # Path of the bunfig file
54
54
  CONFIG_PATH = "bunfig.toml"
55
55
 
56
- # The environment variable to use the system installed bun.
57
- USE_SYSTEM_VAR = "REFLEX_USE_SYSTEM_BUN"
56
+ @classproperty
57
+ @classmethod
58
+ def ROOT_PATH(cls):
59
+ """The directory to store the bun.
60
+
61
+ Returns:
62
+ The directory to store the bun.
63
+ """
64
+ from reflex.config import environment
65
+
66
+ return environment.REFLEX_DIR / "bun"
67
+
68
+ @classproperty
69
+ @classmethod
70
+ def DEFAULT_PATH(cls):
71
+ """Default bun path.
72
+
73
+ Returns:
74
+ The default bun path.
75
+ """
76
+ return cls.ROOT_PATH / "bin" / ("bun" if not IS_WINDOWS else "bun.exe")
58
77
 
59
78
 
60
79
  # FNM config.
@@ -63,44 +82,81 @@ class Fnm(SimpleNamespace):
63
82
 
64
83
  # The FNM version.
65
84
  VERSION = "1.35.1"
66
- # The directory to store fnm.
67
- DIR = Reflex.DIR / "fnm"
85
+
68
86
  FILENAME = get_fnm_name()
69
- # The fnm executable binary.
70
- EXE = DIR / ("fnm.exe" if IS_WINDOWS else "fnm")
71
87
 
72
88
  # The URL to the fnm release binary
73
89
  INSTALL_URL = (
74
90
  f"https://github.com/Schniz/fnm/releases/download/v{VERSION}/{FILENAME}.zip"
75
91
  )
76
92
 
93
+ @classproperty
94
+ @classmethod
95
+ def DIR(cls) -> Path:
96
+ """The directory to store fnm.
97
+
98
+ Returns:
99
+ The directory to store fnm.
100
+ """
101
+ from reflex.config import environment
102
+
103
+ return environment.REFLEX_DIR / "fnm"
104
+
105
+ @classproperty
106
+ @classmethod
107
+ def EXE(cls):
108
+ """The fnm executable binary.
109
+
110
+ Returns:
111
+ The fnm executable binary.
112
+ """
113
+ return cls.DIR / ("fnm.exe" if IS_WINDOWS else "fnm")
114
+
77
115
 
78
116
  # Node / NPM config
79
117
  class Node(SimpleNamespace):
80
118
  """Node/ NPM constants."""
81
119
 
82
120
  # The Node version.
83
- VERSION = "20.18.0"
121
+ VERSION = "22.10.0"
84
122
  # The minimum required node version.
85
123
  MIN_VERSION = "18.17.0"
86
124
 
87
- # The node bin path.
88
- BIN_PATH = (
89
- Fnm.DIR
90
- / "node-versions"
91
- / f"v{VERSION}"
92
- / "installation"
93
- / ("bin" if not IS_WINDOWS else "")
94
- )
95
-
96
- # The default path where node is installed.
97
- PATH = BIN_PATH / ("node.exe" if IS_WINDOWS else "node")
98
-
99
- # The default path where npm is installed.
100
- NPM_PATH = BIN_PATH / "npm"
101
-
102
- # The environment variable to use the system installed node.
103
- USE_SYSTEM_VAR = "REFLEX_USE_SYSTEM_NODE"
125
+ @classproperty
126
+ @classmethod
127
+ def BIN_PATH(cls):
128
+ """The node bin path.
129
+
130
+ Returns:
131
+ The node bin path.
132
+ """
133
+ return (
134
+ Fnm.DIR
135
+ / "node-versions"
136
+ / f"v{cls.VERSION}"
137
+ / "installation"
138
+ / ("bin" if not IS_WINDOWS else "")
139
+ )
140
+
141
+ @classproperty
142
+ @classmethod
143
+ def PATH(cls):
144
+ """The default path where node is installed.
145
+
146
+ Returns:
147
+ The default path where node is installed.
148
+ """
149
+ return cls.BIN_PATH / ("node.exe" if IS_WINDOWS else "node")
150
+
151
+ @classproperty
152
+ @classmethod
153
+ def NPM_PATH(cls):
154
+ """The default path where npm is installed.
155
+
156
+ Returns:
157
+ The default path where npm is installed.
158
+ """
159
+ return cls.BIN_PATH / "npm"
104
160
 
105
161
 
106
162
  class PackageJson(SimpleNamespace):
@@ -117,18 +173,18 @@ class PackageJson(SimpleNamespace):
117
173
  PATH = "package.json"
118
174
 
119
175
  DEPENDENCIES = {
120
- "@babel/standalone": "7.25.7",
176
+ "@babel/standalone": "7.25.8",
121
177
  "@emotion/react": "11.13.3",
122
178
  "axios": "1.7.7",
123
179
  "json5": "2.2.3",
124
- "next": "14.2.14",
180
+ "next": "14.2.15",
125
181
  "next-sitemap": "4.2.3",
126
182
  "next-themes": "0.3.0",
127
183
  "react": "18.3.1",
128
184
  "react-dom": "18.3.1",
129
185
  "react-focus-lock": "2.13.2",
130
186
  "socket.io-client": "4.8.0",
131
- "universal-cookie": "7.2.0",
187
+ "universal-cookie": "7.2.1",
132
188
  }
133
189
  DEV_DEPENDENCIES = {
134
190
  "autoprefixer": "10.4.20",
reflex/constants/style.py CHANGED
@@ -7,7 +7,7 @@ class Tailwind(SimpleNamespace):
7
7
  """Tailwind constants."""
8
8
 
9
9
  # The Tailwindcss version
10
- VERSION = "tailwindcss@3.4.13"
10
+ VERSION = "tailwindcss@3.4.14"
11
11
  # The Tailwind config.
12
12
  CONFIG = "tailwind.config.js"
13
13
  # Default Tailwind content paths
@@ -0,0 +1,32 @@
1
+ """Utility functions for constants."""
2
+
3
+ from typing import Any, Callable, Generic, Type
4
+
5
+ from typing_extensions import TypeVar
6
+
7
+ T = TypeVar("T")
8
+ V = TypeVar("V")
9
+
10
+
11
+ class classproperty(Generic[T, V]):
12
+ """A class property decorator."""
13
+
14
+ def __init__(self, getter: Callable[[Type[T]], V]) -> None:
15
+ """Initialize the class property.
16
+
17
+ Args:
18
+ getter: The getter function.
19
+ """
20
+ self.getter = getattr(getter, "__func__", getter)
21
+
22
+ def __get__(self, instance: Any, owner: Type[T]) -> V:
23
+ """Get the value of the class property.
24
+
25
+ Args:
26
+ instance: The instance of the class.
27
+ owner: The class itself.
28
+
29
+ Returns:
30
+ The value of the class property.
31
+ """
32
+ return self.getter(owner)
@@ -17,7 +17,7 @@ import typer
17
17
  from tomlkit.exceptions import TOMLKitError
18
18
 
19
19
  from reflex import constants
20
- from reflex.config import get_config
20
+ from reflex.config import environment, get_config
21
21
  from reflex.constants import CustomComponents
22
22
  from reflex.utils import console
23
23
 
@@ -609,14 +609,14 @@ def publish(
609
609
  help="The API token to use for authentication on python package repository. If token is provided, no username/password should be provided at the same time",
610
610
  ),
611
611
  username: Optional[str] = typer.Option(
612
- os.getenv("TWINE_USERNAME"),
612
+ environment.TWINE_USERNAME,
613
613
  "-u",
614
614
  "--username",
615
615
  show_default="TWINE_USERNAME environment variable value if set",
616
616
  help="The username to use for authentication on python package repository. Username and password must both be provided.",
617
617
  ),
618
618
  password: Optional[str] = typer.Option(
619
- os.getenv("TWINE_PASSWORD"),
619
+ environment.TWINE_PASSWORD,
620
620
  "-p",
621
621
  "--password",
622
622
  show_default="TWINE_PASSWORD environment variable value if set",
reflex/event.py CHANGED
@@ -12,11 +12,11 @@ from functools import partial
12
12
  from typing import (
13
13
  Any,
14
14
  Callable,
15
- ClassVar,
16
15
  Dict,
17
16
  Generic,
18
17
  List,
19
18
  Optional,
19
+ Sequence,
20
20
  Tuple,
21
21
  Type,
22
22
  TypeVar,
@@ -25,7 +25,7 @@ from typing import (
25
25
  overload,
26
26
  )
27
27
 
28
- from typing_extensions import ParamSpec, get_args, get_origin
28
+ from typing_extensions import ParamSpec, Protocol, get_args, get_origin
29
29
 
30
30
  from reflex import constants
31
31
  from reflex.utils import console, format
@@ -33,9 +33,7 @@ from reflex.utils.exceptions import EventFnArgMismatch, EventHandlerArgMismatch
33
33
  from reflex.utils.types import ArgsSpec, GenericType
34
34
  from reflex.vars import VarData
35
35
  from reflex.vars.base import (
36
- LiteralNoneVar,
37
36
  LiteralVar,
38
- ToOperation,
39
37
  Var,
40
38
  )
41
39
  from reflex.vars.function import (
@@ -392,7 +390,9 @@ class CallableEventSpec(EventSpec):
392
390
  class EventChain(EventActionsMixin):
393
391
  """Container for a chain of events that will be executed in order."""
394
392
 
395
- events: List[Union[EventSpec, EventVar]] = dataclasses.field(default_factory=list)
393
+ events: Sequence[Union[EventSpec, EventVar, EventCallback]] = dataclasses.field(
394
+ default_factory=list
395
+ )
396
396
 
397
397
  args_spec: Optional[Callable] = dataclasses.field(default=None)
398
398
 
@@ -468,33 +468,97 @@ prevent_default = EventChain(events=[], args_spec=empty_event).prevent_default
468
468
 
469
469
 
470
470
  T = TypeVar("T")
471
+ U = TypeVar("U")
472
+
473
+
474
+ # def identity_event(event_type: Type[T]) -> Callable[[Var[T]], Tuple[Var[T]]]:
475
+ # """A helper function that returns the input event as output.
476
+
477
+ # Args:
478
+ # event_type: The type of the event.
479
+
480
+ # Returns:
481
+ # A function that returns the input event as output.
482
+ # """
483
+
484
+ # def inner(ev: Var[T]) -> Tuple[Var[T]]:
485
+ # return (ev,)
486
+
487
+ # inner.__signature__ = inspect.signature(inner).replace( # type: ignore
488
+ # parameters=[
489
+ # inspect.Parameter(
490
+ # "ev",
491
+ # kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
492
+ # annotation=Var[event_type],
493
+ # )
494
+ # ],
495
+ # return_annotation=Tuple[Var[event_type]],
496
+ # )
497
+ # inner.__annotations__["ev"] = Var[event_type]
498
+ # inner.__annotations__["return"] = Tuple[Var[event_type]]
499
+
500
+ # return inner
501
+
502
+
503
+ class IdentityEventReturn(Generic[T], Protocol):
504
+ """Protocol for an identity event return."""
505
+
506
+ def __call__(self, *values: Var[T]) -> Tuple[Var[T], ...]:
507
+ """Return the input values.
508
+
509
+ Args:
510
+ *values: The values to return.
511
+
512
+ Returns:
513
+ The input values.
514
+ """
515
+ return values
516
+
517
+
518
+ @overload
519
+ def identity_event(event_type: Type[T], /) -> Callable[[Var[T]], Tuple[Var[T]]]: ... # type: ignore
520
+
471
521
 
522
+ @overload
523
+ def identity_event(
524
+ event_type_1: Type[T], event_type2: Type[U], /
525
+ ) -> Callable[[Var[T], Var[U]], Tuple[Var[T], Var[U]]]: ...
472
526
 
473
- def identity_event(event_type: Type[T]) -> Callable[[Var[T]], Tuple[Var[T]]]:
527
+
528
+ @overload
529
+ def identity_event(*event_types: Type[T]) -> IdentityEventReturn[T]: ...
530
+
531
+
532
+ def identity_event(*event_types: Type[T]) -> IdentityEventReturn[T]: # type: ignore
474
533
  """A helper function that returns the input event as output.
475
534
 
476
535
  Args:
477
- event_type: The type of the event.
536
+ *event_types: The types of the events.
478
537
 
479
538
  Returns:
480
539
  A function that returns the input event as output.
481
540
  """
482
541
 
483
- def inner(ev: Var[T]) -> Tuple[Var[T]]:
484
- return (ev,)
542
+ def inner(*values: Var[T]) -> Tuple[Var[T], ...]:
543
+ return values
544
+
545
+ inner_type = tuple(Var[event_type] for event_type in event_types)
546
+ return_annotation = Tuple[inner_type] # type: ignore
485
547
 
486
548
  inner.__signature__ = inspect.signature(inner).replace( # type: ignore
487
549
  parameters=[
488
550
  inspect.Parameter(
489
- "ev",
551
+ f"ev_{i}",
490
552
  kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
491
553
  annotation=Var[event_type],
492
554
  )
555
+ for i, event_type in enumerate(event_types)
493
556
  ],
494
- return_annotation=Tuple[Var[event_type]],
557
+ return_annotation=return_annotation,
495
558
  )
496
- inner.__annotations__["ev"] = Var[event_type]
497
- inner.__annotations__["return"] = Tuple[Var[event_type]]
559
+ for i, event_type in enumerate(event_types):
560
+ inner.__annotations__[f"ev_{i}"] = Var[event_type]
561
+ inner.__annotations__["return"] = return_annotation
498
562
 
499
563
  return inner
500
564
 
@@ -1254,7 +1318,7 @@ def get_fn_signature(fn: Callable) -> inspect.Signature:
1254
1318
  return signature.replace(parameters=(new_param, *signature.parameters.values()))
1255
1319
 
1256
1320
 
1257
- class EventVar(ObjectVar):
1321
+ class EventVar(ObjectVar, python_types=EventSpec):
1258
1322
  """Base class for event vars."""
1259
1323
 
1260
1324
 
@@ -1315,7 +1379,7 @@ class LiteralEventVar(VarOperationCall, LiteralVar, EventVar):
1315
1379
  )
1316
1380
 
1317
1381
 
1318
- class EventChainVar(FunctionVar):
1382
+ class EventChainVar(FunctionVar, python_types=EventChain):
1319
1383
  """Base class for event chain vars."""
1320
1384
 
1321
1385
 
@@ -1384,39 +1448,8 @@ class LiteralEventChainVar(ArgsFunctionOperation, LiteralVar, EventChainVar):
1384
1448
  )
1385
1449
 
1386
1450
 
1387
- @dataclasses.dataclass(
1388
- eq=False,
1389
- frozen=True,
1390
- **{"slots": True} if sys.version_info >= (3, 10) else {},
1391
- )
1392
- class ToEventVarOperation(ToOperation, EventVar):
1393
- """Result of a cast to an event var."""
1394
-
1395
- _original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())
1396
-
1397
- _default_var_type: ClassVar[Type] = EventSpec
1398
-
1399
-
1400
- @dataclasses.dataclass(
1401
- eq=False,
1402
- frozen=True,
1403
- **{"slots": True} if sys.version_info >= (3, 10) else {},
1404
- )
1405
- class ToEventChainVarOperation(ToOperation, EventChainVar):
1406
- """Result of a cast to an event chain var."""
1407
-
1408
- _original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())
1409
-
1410
- _default_var_type: ClassVar[Type] = EventChain
1411
-
1412
-
1413
- G = ParamSpec("G")
1414
-
1415
- IndividualEventType = Union[EventSpec, EventHandler, Callable[G, Any], Var[Any]]
1416
-
1417
- EventType = Union[IndividualEventType[G], List[IndividualEventType[G]]]
1418
-
1419
1451
  P = ParamSpec("P")
1452
+ Q = ParamSpec("Q")
1420
1453
  T = TypeVar("T")
1421
1454
  V = TypeVar("V")
1422
1455
  V2 = TypeVar("V2")
@@ -1438,55 +1471,78 @@ if sys.version_info >= (3, 10):
1438
1471
  """
1439
1472
  self.func = func
1440
1473
 
1474
+ @property
1475
+ def prevent_default(self):
1476
+ """Prevent default behavior.
1477
+
1478
+ Returns:
1479
+ The event callback with prevent default behavior.
1480
+ """
1481
+ return self
1482
+
1483
+ @property
1484
+ def stop_propagation(self):
1485
+ """Stop event propagation.
1486
+
1487
+ Returns:
1488
+ The event callback with stop propagation behavior.
1489
+ """
1490
+ return self
1491
+
1441
1492
  @overload
1442
- def __get__(
1443
- self: EventCallback[[V], T], instance: None, owner
1444
- ) -> Callable[[Union[Var[V], V]], EventSpec]: ...
1493
+ def __call__(
1494
+ self: EventCallback[Q, T],
1495
+ ) -> EventCallback[Q, T]: ...
1445
1496
 
1446
1497
  @overload
1447
- def __get__(
1448
- self: EventCallback[[V, V2], T], instance: None, owner
1449
- ) -> Callable[[Union[Var[V], V], Union[Var[V2], V2]], EventSpec]: ...
1498
+ def __call__(
1499
+ self: EventCallback[Concatenate[V, Q], T], value: V | Var[V]
1500
+ ) -> EventCallback[Q, T]: ...
1450
1501
 
1451
1502
  @overload
1452
- def __get__(
1453
- self: EventCallback[[V, V2, V3], T], instance: None, owner
1454
- ) -> Callable[
1455
- [Union[Var[V], V], Union[Var[V2], V2], Union[Var[V3], V3]],
1456
- EventSpec,
1457
- ]: ...
1503
+ def __call__(
1504
+ self: EventCallback[Concatenate[V, V2, Q], T],
1505
+ value: V | Var[V],
1506
+ value2: V2 | Var[V2],
1507
+ ) -> EventCallback[Q, T]: ...
1458
1508
 
1459
1509
  @overload
1460
- def __get__(
1461
- self: EventCallback[[V, V2, V3, V4], T], instance: None, owner
1462
- ) -> Callable[
1463
- [
1464
- Union[Var[V], V],
1465
- Union[Var[V2], V2],
1466
- Union[Var[V3], V3],
1467
- Union[Var[V4], V4],
1468
- ],
1469
- EventSpec,
1470
- ]: ...
1510
+ def __call__(
1511
+ self: EventCallback[Concatenate[V, V2, V3, Q], T],
1512
+ value: V | Var[V],
1513
+ value2: V2 | Var[V2],
1514
+ value3: V3 | Var[V3],
1515
+ ) -> EventCallback[Q, T]: ...
1516
+
1517
+ @overload
1518
+ def __call__(
1519
+ self: EventCallback[Concatenate[V, V2, V3, V4, Q], T],
1520
+ value: V | Var[V],
1521
+ value2: V2 | Var[V2],
1522
+ value3: V3 | Var[V3],
1523
+ value4: V4 | Var[V4],
1524
+ ) -> EventCallback[Q, T]: ...
1525
+
1526
+ def __call__(self, *values) -> EventCallback: # type: ignore
1527
+ """Call the function with the values.
1528
+
1529
+ Args:
1530
+ *values: The values to call the function with.
1531
+
1532
+ Returns:
1533
+ The function with the values.
1534
+ """
1535
+ return self.func(*values) # type: ignore
1471
1536
 
1472
1537
  @overload
1473
1538
  def __get__(
1474
- self: EventCallback[[V, V2, V3, V4, V5], T], instance: None, owner
1475
- ) -> Callable[
1476
- [
1477
- Union[Var[V], V],
1478
- Union[Var[V2], V2],
1479
- Union[Var[V3], V3],
1480
- Union[Var[V4], V4],
1481
- Union[Var[V5], V5],
1482
- ],
1483
- EventSpec,
1484
- ]: ...
1539
+ self: EventCallback[P, T], instance: None, owner
1540
+ ) -> EventCallback[P, T]: ...
1485
1541
 
1486
1542
  @overload
1487
1543
  def __get__(self, instance, owner) -> Callable[P, T]: ...
1488
1544
 
1489
- def __get__(self, instance, owner) -> Callable:
1545
+ def __get__(self, instance, owner) -> Callable: # type: ignore
1490
1546
  """Get the function with the instance bound to it.
1491
1547
 
1492
1548
  Args:
@@ -1513,6 +1569,9 @@ if sys.version_info >= (3, 10):
1513
1569
  return func # type: ignore
1514
1570
  else:
1515
1571
 
1572
+ class EventCallback(Generic[P, T]):
1573
+ """A descriptor that wraps a function to be used as an event."""
1574
+
1516
1575
  def event_handler(func: Callable[P, T]) -> Callable[P, T]:
1517
1576
  """Wrap a function to be used as an event.
1518
1577
 
@@ -1525,6 +1584,17 @@ else:
1525
1584
  return func
1526
1585
 
1527
1586
 
1587
+ G = ParamSpec("G")
1588
+
1589
+ IndividualEventType = Union[
1590
+ EventSpec, EventHandler, Callable[G, Any], EventCallback[G, Any], Var[Any]
1591
+ ]
1592
+
1593
+ ItemOrList = Union[V, List[V]]
1594
+
1595
+ EventType = ItemOrList[IndividualEventType[G]]
1596
+
1597
+
1528
1598
  class EventNamespace(types.SimpleNamespace):
1529
1599
  """A namespace for event related classes."""
1530
1600
 
@@ -1537,8 +1607,6 @@ class EventNamespace(types.SimpleNamespace):
1537
1607
  LiteralEventVar = LiteralEventVar
1538
1608
  EventChainVar = EventChainVar
1539
1609
  LiteralEventChainVar = LiteralEventChainVar
1540
- ToEventVarOperation = ToEventVarOperation
1541
- ToEventChainVarOperation = ToEventChainVarOperation
1542
1610
  EventType = EventType
1543
1611
 
1544
1612
  __call__ = staticmethod(event_handler)
@@ -2,6 +2,7 @@
2
2
 
3
3
  from types import SimpleNamespace
4
4
 
5
+ from reflex.components.datadisplay.shiki_code_block import code_block as code_block
5
6
  from reflex.components.props import PropsBase
6
7
  from reflex.components.radix.themes.components.progress import progress as progress
7
8
  from reflex.components.sonner.toast import toast as toast
@@ -67,4 +68,5 @@ _x = ExperimentalNamespace(
67
68
  layout=layout,
68
69
  PropsBase=PropsBase,
69
70
  run_in_thread=run_in_thread,
71
+ code_block=code_block,
70
72
  )
@@ -21,7 +21,7 @@ NoValue = object()
21
21
 
22
22
 
23
23
  _refs_import = {
24
- f"/{constants.Dirs.STATE_PATH}": [ImportVar(tag="refs")],
24
+ f"$/{constants.Dirs.STATE_PATH}": [ImportVar(tag="refs")],
25
25
  }
26
26
 
27
27
 
@@ -129,7 +129,7 @@ class DrawerSidebar(DrawerRoot):
129
129
  on_mouse_out: Optional[EventType[[]]] = None,
130
130
  on_mouse_over: Optional[EventType[[]]] = None,
131
131
  on_mouse_up: Optional[EventType[[]]] = None,
132
- on_open_change: Optional[EventType] = None,
132
+ on_open_change: Optional[EventType[bool]] = None,
133
133
  on_scroll: Optional[EventType[[]]] = None,
134
134
  on_unmount: Optional[EventType[[]]] = None,
135
135
  **props,