reflex 0.6.3.post1__py3-none-any.whl → 0.6.4a1__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.
- reflex/.templates/jinja/web/pages/_app.js.jinja2 +2 -2
- reflex/.templates/jinja/web/utils/context.js.jinja2 +3 -1
- reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +3 -3
- reflex/.templates/web/components/shiki/code.js +29 -0
- reflex/.templates/web/jsconfig.json +2 -1
- reflex/.templates/web/utils/state.js +6 -4
- reflex/__init__.py +6 -3
- reflex/__init__.pyi +4 -3
- reflex/app.py +6 -5
- reflex/compiler/compiler.py +6 -7
- reflex/compiler/utils.py +8 -1
- reflex/components/base/error_boundary.py +37 -24
- reflex/components/base/error_boundary.pyi +8 -7
- reflex/components/component.py +8 -3
- reflex/components/core/banner.py +2 -2
- reflex/components/core/client_side_routing.py +1 -1
- reflex/components/core/clipboard.py +1 -1
- reflex/components/core/clipboard.pyi +1 -1
- reflex/components/core/cond.py +1 -1
- reflex/components/core/debounce.py +5 -1
- reflex/components/core/upload.py +7 -9
- reflex/components/core/upload.pyi +2 -2
- reflex/components/datadisplay/code.py +1 -1
- reflex/components/datadisplay/dataeditor.py +83 -18
- reflex/components/datadisplay/dataeditor.pyi +67 -15
- reflex/components/datadisplay/shiki_code_block.py +813 -0
- reflex/components/datadisplay/shiki_code_block.pyi +2211 -0
- reflex/components/dynamic.py +3 -3
- reflex/components/el/elements/forms.py +37 -23
- reflex/components/el/elements/forms.pyi +7 -4
- reflex/components/markdown/markdown.py +12 -1
- reflex/components/moment/moment.pyi +1 -1
- reflex/components/radix/primitives/drawer.pyi +2 -2
- reflex/components/radix/themes/base.py +2 -2
- reflex/components/radix/themes/color_mode.pyi +1 -1
- reflex/components/radix/themes/components/alert_dialog.pyi +1 -1
- reflex/components/radix/themes/components/checkbox.pyi +3 -3
- reflex/components/radix/themes/components/context_menu.pyi +1 -1
- reflex/components/radix/themes/components/dialog.pyi +2 -2
- reflex/components/radix/themes/components/dropdown_menu.pyi +2 -2
- reflex/components/radix/themes/components/hover_card.pyi +2 -2
- reflex/components/radix/themes/components/popover.pyi +1 -1
- reflex/components/radix/themes/components/radio_cards.pyi +1 -1
- reflex/components/radix/themes/components/radio_group.pyi +1 -1
- reflex/components/radix/themes/components/select.pyi +6 -6
- reflex/components/radix/themes/components/switch.pyi +1 -1
- reflex/components/radix/themes/components/tabs.pyi +2 -2
- reflex/components/radix/themes/components/tooltip.pyi +4 -2
- reflex/components/react_player/__init__.py +1 -0
- reflex/components/react_player/audio.pyi +6 -3
- reflex/components/react_player/react_player.py +12 -1
- reflex/components/react_player/react_player.pyi +11 -3
- reflex/components/react_player/video.pyi +6 -3
- reflex/components/recharts/recharts.py +2 -2
- reflex/components/sonner/toast.py +1 -1
- reflex/components/suneditor/editor.py +40 -16
- reflex/components/suneditor/editor.pyi +15 -11
- reflex/config.py +236 -20
- reflex/constants/__init__.py +2 -0
- reflex/constants/base.py +53 -31
- reflex/constants/compiler.py +2 -12
- reflex/constants/config.py +1 -2
- reflex/constants/installer.py +88 -32
- reflex/constants/style.py +1 -1
- reflex/constants/utils.py +32 -0
- reflex/custom_components/custom_components.py +3 -3
- reflex/event.py +147 -84
- reflex/experimental/__init__.py +2 -0
- reflex/experimental/client_state.py +1 -1
- reflex/experimental/layout.pyi +1 -1
- reflex/istate/storage.py +144 -0
- reflex/model.py +8 -11
- reflex/reflex.py +18 -17
- reflex/state.py +83 -149
- reflex/style.py +1 -1
- reflex/testing.py +2 -1
- reflex/utils/build.py +0 -12
- reflex/utils/exceptions.py +8 -0
- reflex/utils/exec.py +22 -4
- reflex/utils/imports.py +6 -0
- reflex/utils/net.py +2 -4
- reflex/utils/path_ops.py +7 -21
- reflex/utils/prerequisites.py +11 -17
- reflex/utils/pyi_generator.py +91 -3
- reflex/utils/registry.py +2 -6
- reflex/utils/types.py +14 -0
- reflex/vars/base.py +453 -424
- reflex/vars/function.py +6 -16
- reflex/vars/number.py +46 -67
- reflex/vars/object.py +1 -31
- reflex/vars/sequence.py +177 -47
- {reflex-0.6.3.post1.dist-info → reflex-0.6.4a1.dist-info}/METADATA +1 -1
- {reflex-0.6.3.post1.dist-info → reflex-0.6.4a1.dist-info}/RECORD +96 -91
- {reflex-0.6.3.post1.dist-info → reflex-0.6.4a1.dist-info}/LICENSE +0 -0
- {reflex-0.6.3.post1.dist-info → reflex-0.6.4a1.dist-info}/WHEEL +0 -0
- {reflex-0.6.3.post1.dist-info → reflex-0.6.4a1.dist-info}/entry_points.txt +0 -0
reflex/constants/installer.py
CHANGED
|
@@ -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
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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 = "
|
|
121
|
+
VERSION = "22.10.0"
|
|
84
122
|
# The minimum required node version.
|
|
85
123
|
MIN_VERSION = "18.17.0"
|
|
86
124
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
187
|
+
"universal-cookie": "7.2.1",
|
|
132
188
|
}
|
|
133
189
|
DEV_DEPENDENCIES = {
|
|
134
190
|
"autoprefixer": "10.4.20",
|
reflex/constants/style.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
471
520
|
|
|
472
521
|
|
|
473
|
-
|
|
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]]]: ...
|
|
526
|
+
|
|
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
|
-
|
|
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(
|
|
484
|
-
return
|
|
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
|
-
"
|
|
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=
|
|
557
|
+
return_annotation=return_annotation,
|
|
495
558
|
)
|
|
496
|
-
|
|
497
|
-
|
|
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,73 @@ 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
|
|
1443
|
-
self: EventCallback[[V], T],
|
|
1444
|
-
) ->
|
|
1493
|
+
def __call__(
|
|
1494
|
+
self: EventCallback[Concatenate[V, Q], T], value: V | Var[V]
|
|
1495
|
+
) -> EventCallback[Q, T]: ...
|
|
1445
1496
|
|
|
1446
1497
|
@overload
|
|
1447
|
-
def
|
|
1448
|
-
self: EventCallback[[V, V2], T],
|
|
1449
|
-
|
|
1498
|
+
def __call__(
|
|
1499
|
+
self: EventCallback[Concatenate[V, V2, Q], T],
|
|
1500
|
+
value: V | Var[V],
|
|
1501
|
+
value2: V2 | Var[V2],
|
|
1502
|
+
) -> EventCallback[Q, T]: ...
|
|
1450
1503
|
|
|
1451
1504
|
@overload
|
|
1452
|
-
def
|
|
1453
|
-
self: EventCallback[[V, V2, V3], T],
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
]: ...
|
|
1505
|
+
def __call__(
|
|
1506
|
+
self: EventCallback[Concatenate[V, V2, V3, Q], T],
|
|
1507
|
+
value: V | Var[V],
|
|
1508
|
+
value2: V2 | Var[V2],
|
|
1509
|
+
value3: V3 | Var[V3],
|
|
1510
|
+
) -> EventCallback[Q, T]: ...
|
|
1458
1511
|
|
|
1459
1512
|
@overload
|
|
1460
|
-
def
|
|
1461
|
-
self: EventCallback[[V, V2, V3, V4], T],
|
|
1462
|
-
|
|
1463
|
-
[
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1513
|
+
def __call__(
|
|
1514
|
+
self: EventCallback[Concatenate[V, V2, V3, V4, Q], T],
|
|
1515
|
+
value: V | Var[V],
|
|
1516
|
+
value2: V2 | Var[V2],
|
|
1517
|
+
value3: V3 | Var[V3],
|
|
1518
|
+
value4: V4 | Var[V4],
|
|
1519
|
+
) -> EventCallback[Q, T]: ...
|
|
1520
|
+
|
|
1521
|
+
def __call__(self, *values) -> EventCallback: # type: ignore
|
|
1522
|
+
"""Call the function with the values.
|
|
1523
|
+
|
|
1524
|
+
Args:
|
|
1525
|
+
*values: The values to call the function with.
|
|
1526
|
+
|
|
1527
|
+
Returns:
|
|
1528
|
+
The function with the values.
|
|
1529
|
+
"""
|
|
1530
|
+
return self.func(*values) # type: ignore
|
|
1471
1531
|
|
|
1472
1532
|
@overload
|
|
1473
1533
|
def __get__(
|
|
1474
|
-
self: EventCallback[
|
|
1475
|
-
) ->
|
|
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
|
-
]: ...
|
|
1534
|
+
self: EventCallback[P, T], instance: None, owner
|
|
1535
|
+
) -> EventCallback[P, T]: ...
|
|
1485
1536
|
|
|
1486
1537
|
@overload
|
|
1487
1538
|
def __get__(self, instance, owner) -> Callable[P, T]: ...
|
|
1488
1539
|
|
|
1489
|
-
def __get__(self, instance, owner) -> Callable:
|
|
1540
|
+
def __get__(self, instance, owner) -> Callable: # type: ignore
|
|
1490
1541
|
"""Get the function with the instance bound to it.
|
|
1491
1542
|
|
|
1492
1543
|
Args:
|
|
@@ -1513,6 +1564,9 @@ if sys.version_info >= (3, 10):
|
|
|
1513
1564
|
return func # type: ignore
|
|
1514
1565
|
else:
|
|
1515
1566
|
|
|
1567
|
+
class EventCallback(Generic[P, T]):
|
|
1568
|
+
"""A descriptor that wraps a function to be used as an event."""
|
|
1569
|
+
|
|
1516
1570
|
def event_handler(func: Callable[P, T]) -> Callable[P, T]:
|
|
1517
1571
|
"""Wrap a function to be used as an event.
|
|
1518
1572
|
|
|
@@ -1525,6 +1579,17 @@ else:
|
|
|
1525
1579
|
return func
|
|
1526
1580
|
|
|
1527
1581
|
|
|
1582
|
+
G = ParamSpec("G")
|
|
1583
|
+
|
|
1584
|
+
IndividualEventType = Union[
|
|
1585
|
+
EventSpec, EventHandler, Callable[G, Any], EventCallback[G, Any], Var[Any]
|
|
1586
|
+
]
|
|
1587
|
+
|
|
1588
|
+
ItemOrList = Union[V, List[V]]
|
|
1589
|
+
|
|
1590
|
+
EventType = ItemOrList[IndividualEventType[G]]
|
|
1591
|
+
|
|
1592
|
+
|
|
1528
1593
|
class EventNamespace(types.SimpleNamespace):
|
|
1529
1594
|
"""A namespace for event related classes."""
|
|
1530
1595
|
|
|
@@ -1537,8 +1602,6 @@ class EventNamespace(types.SimpleNamespace):
|
|
|
1537
1602
|
LiteralEventVar = LiteralEventVar
|
|
1538
1603
|
EventChainVar = EventChainVar
|
|
1539
1604
|
LiteralEventChainVar = LiteralEventChainVar
|
|
1540
|
-
ToEventVarOperation = ToEventVarOperation
|
|
1541
|
-
ToEventChainVarOperation = ToEventChainVarOperation
|
|
1542
1605
|
EventType = EventType
|
|
1543
1606
|
|
|
1544
1607
|
__call__ = staticmethod(event_handler)
|
reflex/experimental/__init__.py
CHANGED
|
@@ -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
|
)
|
reflex/experimental/layout.pyi
CHANGED
|
@@ -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,
|