reflex 0.6.0__py3-none-any.whl → 0.6.0a1__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/custom_components/pyproject.toml.jinja2 +2 -2
- reflex/.templates/jinja/web/pages/_app.js.jinja2 +1 -1
- reflex/.templates/jinja/web/pages/utils.js.jinja2 +2 -2
- reflex/.templates/web/components/reflex/chakra_color_mode_provider.js +36 -0
- reflex/.templates/web/utils/state.js +1 -3
- reflex/__init__.py +2 -8
- reflex/__init__.pyi +1 -2
- reflex/app.py +2 -4
- reflex/app_module_for_backend.py +1 -1
- reflex/base.py +1 -1
- reflex/compiler/compiler.py +2 -2
- reflex/compiler/utils.py +3 -3
- reflex/components/base/app_wrap.py +2 -2
- reflex/components/base/app_wrap.pyi +27 -17
- reflex/components/base/bare.py +5 -4
- reflex/components/base/body.pyi +27 -17
- reflex/components/base/document.pyi +131 -81
- reflex/components/base/error_boundary.py +7 -6
- reflex/components/base/error_boundary.pyi +33 -20
- reflex/components/base/fragment.pyi +27 -17
- reflex/components/base/head.pyi +53 -33
- reflex/components/base/link.py +1 -1
- reflex/components/base/link.pyi +54 -33
- reflex/components/base/meta.pyi +105 -65
- reflex/components/base/script.py +2 -1
- reflex/components/base/script.pyi +38 -21
- reflex/components/component.py +47 -53
- reflex/components/core/banner.py +27 -23
- reflex/components/core/banner.pyi +171 -134
- reflex/components/core/client_side_routing.py +3 -2
- reflex/components/core/client_side_routing.pyi +54 -33
- reflex/components/core/clipboard.py +1 -2
- reflex/components/core/clipboard.pyi +33 -20
- reflex/components/core/cond.py +5 -5
- reflex/components/core/debounce.py +5 -5
- reflex/components/core/debounce.pyi +33 -20
- reflex/components/core/foreach.py +4 -3
- reflex/components/core/html.py +1 -1
- reflex/components/core/html.pyi +46 -35
- reflex/components/core/match.py +17 -17
- reflex/components/core/upload.py +23 -17
- reflex/components/core/upload.pyi +124 -78
- reflex/components/datadisplay/code.py +10 -9
- reflex/components/datadisplay/code.pyi +409 -299
- reflex/components/datadisplay/dataeditor.py +10 -8
- reflex/components/datadisplay/dataeditor.pyi +53 -40
- reflex/components/el/element.pyi +27 -17
- reflex/components/el/elements/base.py +1 -1
- reflex/components/el/elements/base.pyi +45 -34
- reflex/components/el/elements/forms.py +16 -16
- reflex/components/el/elements/forms.pyi +707 -554
- reflex/components/el/elements/inline.py +1 -1
- reflex/components/el/elements/inline.pyi +1218 -937
- reflex/components/el/elements/media.py +1 -1
- reflex/components/el/elements/media.pyi +997 -786
- reflex/components/el/elements/metadata.py +6 -3
- reflex/components/el/elements/metadata.pyi +242 -181
- reflex/components/el/elements/other.py +1 -1
- reflex/components/el/elements/other.pyi +306 -235
- reflex/components/el/elements/scripts.py +1 -1
- reflex/components/el/elements/scripts.pyi +140 -109
- reflex/components/el/elements/sectioning.py +2 -0
- reflex/components/el/elements/sectioning.pyi +647 -496
- reflex/components/el/elements/tables.py +1 -1
- reflex/components/el/elements/tables.pyi +452 -351
- reflex/components/el/elements/typography.py +1 -1
- reflex/components/el/elements/typography.pyi +657 -506
- reflex/components/gridjs/datatable.py +9 -6
- reflex/components/gridjs/datatable.pyi +56 -35
- reflex/components/lucide/icon.py +1 -1
- reflex/components/lucide/icon.pyi +54 -33
- reflex/components/markdown/markdown.py +31 -26
- reflex/components/markdown/markdown.pyi +37 -27
- reflex/components/moment/moment.py +12 -13
- reflex/components/moment/moment.pyi +35 -23
- reflex/components/next/base.pyi +27 -17
- reflex/components/next/image.py +1 -1
- reflex/components/next/image.pyi +37 -22
- reflex/components/next/link.py +1 -1
- reflex/components/next/link.pyi +28 -17
- reflex/components/next/video.py +1 -1
- reflex/components/next/video.pyi +28 -17
- reflex/components/plotly/plotly.py +13 -12
- reflex/components/plotly/plotly.pyi +54 -39
- reflex/components/props.py +1 -1
- reflex/components/radix/__init__.pyi +0 -1
- reflex/components/radix/primitives/__init__.pyi +0 -1
- reflex/components/radix/primitives/accordion.py +4 -4
- reflex/components/radix/primitives/accordion.pyi +495 -424
- reflex/components/radix/primitives/base.py +1 -1
- reflex/components/radix/primitives/base.pyi +54 -33
- reflex/components/radix/primitives/drawer.py +1 -1
- reflex/components/radix/primitives/drawer.pyi +273 -172
- reflex/components/radix/primitives/form.py +1 -1
- reflex/components/radix/primitives/form.pyi +364 -257
- reflex/components/radix/primitives/progress.py +1 -1
- reflex/components/radix/primitives/progress.pyi +282 -231
- reflex/components/radix/primitives/slider.py +1 -1
- reflex/components/radix/primitives/slider.pyi +138 -87
- reflex/components/radix/themes/base.py +24 -3
- reflex/components/radix/themes/base.pyi +250 -178
- reflex/components/radix/themes/color_mode.py +5 -5
- reflex/components/radix/themes/color_mode.pyi +220 -187
- reflex/components/radix/themes/components/alert_dialog.py +1 -1
- reflex/components/radix/themes/components/alert_dialog.pyi +207 -136
- reflex/components/radix/themes/components/aspect_ratio.py +1 -1
- reflex/components/radix/themes/components/aspect_ratio.pyi +28 -17
- reflex/components/radix/themes/components/avatar.py +1 -1
- reflex/components/radix/themes/components/avatar.pyi +81 -70
- reflex/components/radix/themes/components/badge.py +1 -1
- reflex/components/radix/themes/components/badge.pyi +99 -88
- reflex/components/radix/themes/components/button.py +1 -1
- reflex/components/radix/themes/components/button.pyi +109 -98
- reflex/components/radix/themes/components/callout.py +1 -1
- reflex/components/radix/themes/components/callout.pyi +373 -322
- reflex/components/radix/themes/components/card.py +1 -1
- reflex/components/radix/themes/components/card.pyi +49 -38
- reflex/components/radix/themes/components/checkbox.py +2 -1
- reflex/components/radix/themes/components/checkbox.pyi +245 -208
- reflex/components/radix/themes/components/checkbox_cards.py +1 -1
- reflex/components/radix/themes/components/checkbox_cards.pyi +115 -94
- reflex/components/radix/themes/components/checkbox_group.py +1 -1
- reflex/components/radix/themes/components/checkbox_group.pyi +107 -86
- reflex/components/radix/themes/components/context_menu.py +1 -1
- reflex/components/radix/themes/components/context_menu.pyi +319 -238
- reflex/components/radix/themes/components/data_list.py +1 -1
- reflex/components/radix/themes/components/data_list.pyi +171 -130
- reflex/components/radix/themes/components/dialog.py +1 -1
- reflex/components/radix/themes/components/dialog.pyi +210 -139
- reflex/components/radix/themes/components/dropdown_menu.py +1 -1
- reflex/components/radix/themes/components/dropdown_menu.pyi +332 -249
- reflex/components/radix/themes/components/hover_card.py +1 -1
- reflex/components/radix/themes/components/hover_card.pyi +131 -90
- reflex/components/radix/themes/components/icon_button.py +3 -2
- reflex/components/radix/themes/components/icon_button.pyi +109 -98
- reflex/components/radix/themes/components/inset.py +1 -1
- reflex/components/radix/themes/components/inset.pyi +58 -47
- reflex/components/radix/themes/components/popover.py +1 -1
- reflex/components/radix/themes/components/popover.pyi +136 -95
- reflex/components/radix/themes/components/progress.py +1 -1
- reflex/components/radix/themes/components/progress.pyi +82 -71
- reflex/components/radix/themes/components/radio.py +1 -1
- reflex/components/radix/themes/components/radio.pyi +80 -69
- reflex/components/radix/themes/components/radio_cards.py +1 -1
- reflex/components/radix/themes/components/radio_cards.pyi +119 -98
- reflex/components/radix/themes/components/radio_group.py +11 -8
- reflex/components/radix/themes/components/radio_group.pyi +271 -228
- reflex/components/radix/themes/components/scroll_area.py +1 -1
- reflex/components/radix/themes/components/scroll_area.pyi +32 -21
- reflex/components/radix/themes/components/segmented_control.py +1 -1
- reflex/components/radix/themes/components/segmented_control.pyi +113 -90
- reflex/components/radix/themes/components/select.py +3 -2
- reflex/components/radix/themes/components/select.pyi +471 -374
- reflex/components/radix/themes/components/separator.py +2 -1
- reflex/components/radix/themes/components/separator.pyi +80 -69
- reflex/components/radix/themes/components/skeleton.py +1 -1
- reflex/components/radix/themes/components/skeleton.pyi +34 -23
- reflex/components/radix/themes/components/slider.py +3 -2
- reflex/components/radix/themes/components/slider.pyi +88 -75
- reflex/components/radix/themes/components/spinner.py +1 -1
- reflex/components/radix/themes/components/spinner.pyi +30 -19
- reflex/components/radix/themes/components/switch.py +1 -1
- reflex/components/radix/themes/components/switch.pyi +84 -71
- reflex/components/radix/themes/components/table.py +1 -1
- reflex/components/radix/themes/components/table.pyi +332 -261
- reflex/components/radix/themes/components/tabs.py +1 -1
- reflex/components/radix/themes/components/tabs.pyi +194 -139
- reflex/components/radix/themes/components/text_area.py +1 -1
- reflex/components/radix/themes/components/text_area.pyi +111 -96
- reflex/components/radix/themes/components/text_field.py +1 -1
- reflex/components/radix/themes/components/text_field.pyi +286 -247
- reflex/components/radix/themes/components/tooltip.py +1 -1
- reflex/components/radix/themes/components/tooltip.pyi +37 -26
- reflex/components/radix/themes/layout/__init__.pyi +0 -1
- reflex/components/radix/themes/layout/base.py +1 -1
- reflex/components/radix/themes/layout/base.pyi +67 -56
- reflex/components/radix/themes/layout/box.pyi +45 -34
- reflex/components/radix/themes/layout/center.pyi +67 -56
- reflex/components/radix/themes/layout/container.py +2 -1
- reflex/components/radix/themes/layout/container.pyi +47 -36
- reflex/components/radix/themes/layout/flex.py +1 -1
- reflex/components/radix/themes/layout/flex.pyi +67 -56
- reflex/components/radix/themes/layout/grid.py +1 -1
- reflex/components/radix/themes/layout/grid.pyi +75 -64
- reflex/components/radix/themes/layout/list.py +6 -5
- reflex/components/radix/themes/layout/list.pyi +244 -193
- reflex/components/radix/themes/layout/section.py +2 -1
- reflex/components/radix/themes/layout/section.pyi +47 -36
- reflex/components/radix/themes/layout/spacer.pyi +67 -56
- reflex/components/radix/themes/layout/stack.py +1 -1
- reflex/components/radix/themes/layout/stack.pyi +159 -128
- reflex/components/radix/themes/typography/blockquote.py +1 -1
- reflex/components/radix/themes/typography/blockquote.pyi +100 -89
- reflex/components/radix/themes/typography/code.py +1 -1
- reflex/components/radix/themes/typography/code.pyi +101 -90
- reflex/components/radix/themes/typography/heading.py +1 -1
- reflex/components/radix/themes/typography/heading.pyi +107 -96
- reflex/components/radix/themes/typography/link.py +1 -1
- reflex/components/radix/themes/typography/link.pyi +113 -102
- reflex/components/radix/themes/typography/text.py +1 -1
- reflex/components/radix/themes/typography/text.pyi +572 -501
- reflex/components/react_player/audio.pyi +60 -33
- reflex/components/react_player/react_player.py +1 -1
- reflex/components/react_player/react_player.pyi +60 -33
- reflex/components/react_player/video.pyi +60 -33
- reflex/components/recharts/cartesian.py +3 -2
- reflex/components/recharts/cartesian.pyi +861 -678
- reflex/components/recharts/charts.py +5 -4
- reflex/components/recharts/charts.pyi +357 -252
- reflex/components/recharts/general.py +2 -1
- reflex/components/recharts/general.pyi +231 -180
- reflex/components/recharts/polar.py +5 -4
- reflex/components/recharts/polar.pyi +181 -144
- reflex/components/recharts/recharts.pyi +53 -33
- reflex/components/sonner/toast.py +17 -16
- reflex/components/sonner/toast.pyi +47 -36
- reflex/components/suneditor/editor.py +3 -2
- reflex/components/suneditor/editor.pyi +78 -55
- reflex/components/tags/cond_tag.py +4 -6
- reflex/components/tags/iter_tag.py +16 -28
- reflex/components/tags/match_tag.py +4 -6
- reflex/components/tags/tag.py +23 -40
- reflex/custom_components/custom_components.py +1 -3
- reflex/event.py +65 -113
- reflex/experimental/client_state.py +24 -25
- reflex/experimental/hooks.py +16 -16
- reflex/experimental/layout.py +5 -5
- reflex/experimental/layout.pyi +187 -136
- reflex/{vars → ivars}/__init__.py +2 -6
- reflex/{vars → ivars}/base.py +216 -599
- reflex/{vars → ivars}/function.py +19 -15
- reflex/{vars → ivars}/number.py +20 -41
- reflex/{vars → ivars}/object.py +30 -28
- reflex/{vars → ivars}/sequence.py +50 -53
- reflex/middleware/hydrate_middleware.py +0 -2
- reflex/middleware/middleware.py +3 -3
- reflex/state.py +82 -148
- reflex/style.py +22 -21
- reflex/utils/exceptions.py +0 -20
- reflex/utils/format.py +34 -54
- reflex/utils/imports.py +73 -16
- reflex/utils/prerequisites.py +15 -35
- reflex/utils/pyi_generator.py +8 -13
- reflex/utils/serializers.py +22 -12
- reflex/utils/telemetry.py +2 -3
- reflex/utils/types.py +5 -10
- reflex/vars.py +501 -0
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/METADATA +5 -4
- reflex-0.6.0a1.dist-info/RECORD +384 -0
- reflex-0.6.0.dist-info/RECORD +0 -382
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/LICENSE +0 -0
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/WHEEL +0 -0
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/entry_points.txt +0 -0
|
@@ -7,9 +7,10 @@ from typing import Any, Callable, Dict, List, Optional, Union, overload
|
|
|
7
7
|
|
|
8
8
|
from reflex.components.base.fragment import Fragment
|
|
9
9
|
from reflex.event import EventHandler, EventSpec
|
|
10
|
+
from reflex.ivars.base import ImmutableVar
|
|
10
11
|
from reflex.style import Style
|
|
11
12
|
from reflex.utils.imports import ImportVar
|
|
12
|
-
from reflex.vars
|
|
13
|
+
from reflex.vars import Var
|
|
13
14
|
|
|
14
15
|
class Clipboard(Fragment):
|
|
15
16
|
@overload
|
|
@@ -17,51 +18,63 @@ class Clipboard(Fragment):
|
|
|
17
18
|
def create( # type: ignore
|
|
18
19
|
cls,
|
|
19
20
|
*children,
|
|
20
|
-
targets: Optional[Union[List[str],
|
|
21
|
+
targets: Optional[Union[Var[List[str]], List[str]]] = None,
|
|
21
22
|
on_paste_event_actions: Optional[
|
|
22
|
-
Union[Dict[str, Union[bool, int]],
|
|
23
|
+
Union[Var[Dict[str, Union[bool, int]]], Dict[str, Union[bool, int]]]
|
|
23
24
|
] = None,
|
|
24
25
|
style: Optional[Style] = None,
|
|
25
26
|
key: Optional[Any] = None,
|
|
26
27
|
id: Optional[Any] = None,
|
|
27
28
|
class_name: Optional[Any] = None,
|
|
28
29
|
autofocus: Optional[bool] = None,
|
|
29
|
-
custom_attrs: Optional[Dict[str, Union[
|
|
30
|
-
on_blur: Optional[
|
|
31
|
-
|
|
30
|
+
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
|
|
31
|
+
on_blur: Optional[
|
|
32
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
33
|
+
] = None,
|
|
34
|
+
on_click: Optional[
|
|
35
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
36
|
+
] = None,
|
|
32
37
|
on_context_menu: Optional[
|
|
33
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
38
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
34
39
|
] = None,
|
|
35
40
|
on_double_click: Optional[
|
|
36
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
41
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
42
|
+
] = None,
|
|
43
|
+
on_focus: Optional[
|
|
44
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
45
|
+
] = None,
|
|
46
|
+
on_mount: Optional[
|
|
47
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
37
48
|
] = None,
|
|
38
|
-
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
39
|
-
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
40
49
|
on_mouse_down: Optional[
|
|
41
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
50
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
42
51
|
] = None,
|
|
43
52
|
on_mouse_enter: Optional[
|
|
44
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
53
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
45
54
|
] = None,
|
|
46
55
|
on_mouse_leave: Optional[
|
|
47
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
56
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
48
57
|
] = None,
|
|
49
58
|
on_mouse_move: Optional[
|
|
50
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
59
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
51
60
|
] = None,
|
|
52
61
|
on_mouse_out: Optional[
|
|
53
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
62
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
54
63
|
] = None,
|
|
55
64
|
on_mouse_over: Optional[
|
|
56
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
65
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
57
66
|
] = None,
|
|
58
67
|
on_mouse_up: Optional[
|
|
59
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
68
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
69
|
+
] = None,
|
|
70
|
+
on_paste: Optional[
|
|
71
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
72
|
+
] = None,
|
|
73
|
+
on_scroll: Optional[
|
|
74
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
60
75
|
] = None,
|
|
61
|
-
on_paste: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
62
|
-
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
63
76
|
on_unmount: Optional[
|
|
64
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
77
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
65
78
|
] = None,
|
|
66
79
|
**props,
|
|
67
80
|
) -> "Clipboard":
|
reflex/components/core/cond.py
CHANGED
|
@@ -8,11 +8,11 @@ from reflex.components.base.fragment import Fragment
|
|
|
8
8
|
from reflex.components.component import BaseComponent, Component, MemoizationLeaf
|
|
9
9
|
from reflex.components.tags import CondTag, Tag
|
|
10
10
|
from reflex.constants import Dirs
|
|
11
|
+
from reflex.ivars.base import ImmutableVar, LiteralVar
|
|
12
|
+
from reflex.ivars.number import ternary_operation
|
|
11
13
|
from reflex.style import LIGHT_COLOR_MODE, resolved_color_mode
|
|
12
14
|
from reflex.utils.imports import ImportDict, ImportVar
|
|
13
|
-
from reflex.vars import VarData
|
|
14
|
-
from reflex.vars.base import LiteralVar, Var
|
|
15
|
-
from reflex.vars.number import ternary_operation
|
|
15
|
+
from reflex.vars import Var, VarData
|
|
16
16
|
|
|
17
17
|
_IS_TRUE_IMPORT: ImportDict = {
|
|
18
18
|
f"/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
|
|
@@ -119,10 +119,10 @@ def cond(condition: Any, c1: Component) -> Component: ...
|
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
@overload
|
|
122
|
-
def cond(condition: Any, c1: Any, c2: Any) ->
|
|
122
|
+
def cond(condition: Any, c1: Any, c2: Any) -> ImmutableVar: ...
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def cond(condition: Any, c1: Any, c2: Any = None) -> Component |
|
|
125
|
+
def cond(condition: Any, c1: Any, c2: Any = None) -> Component | ImmutableVar:
|
|
126
126
|
"""Create a conditional component or Prop.
|
|
127
127
|
|
|
128
128
|
Args:
|
|
@@ -7,8 +7,8 @@ from typing import Any, Type, Union
|
|
|
7
7
|
from reflex.components.component import Component
|
|
8
8
|
from reflex.constants import EventTriggers
|
|
9
9
|
from reflex.event import EventHandler
|
|
10
|
-
from reflex.
|
|
11
|
-
from reflex.vars
|
|
10
|
+
from reflex.ivars.base import ImmutableVar
|
|
11
|
+
from reflex.vars import Var, VarData
|
|
12
12
|
|
|
13
13
|
DEFAULT_DEBOUNCE_TIMEOUT = 300
|
|
14
14
|
|
|
@@ -107,14 +107,14 @@ class DebounceInput(Component):
|
|
|
107
107
|
props[field] = getattr(child, field)
|
|
108
108
|
child_ref = child.get_ref()
|
|
109
109
|
if props.get("input_ref") is None and child_ref:
|
|
110
|
-
props["input_ref"] =
|
|
110
|
+
props["input_ref"] = ImmutableVar.create_safe(child_ref)
|
|
111
111
|
props["id"] = child.id
|
|
112
112
|
|
|
113
113
|
# Set the child element to wrap, including any imports/hooks from the child.
|
|
114
114
|
props.setdefault(
|
|
115
115
|
"element",
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
ImmutableVar(
|
|
117
|
+
_var_name=str(child.alias or child.tag),
|
|
118
118
|
_var_type=Type[Component],
|
|
119
119
|
_var_data=VarData(
|
|
120
120
|
imports=child._get_imports(),
|
|
@@ -7,8 +7,9 @@ from typing import Any, Callable, Dict, Optional, Type, Union, overload
|
|
|
7
7
|
|
|
8
8
|
from reflex.components.component import Component
|
|
9
9
|
from reflex.event import EventHandler, EventSpec
|
|
10
|
+
from reflex.ivars.base import ImmutableVar
|
|
10
11
|
from reflex.style import Style
|
|
11
|
-
from reflex.vars
|
|
12
|
+
from reflex.vars import Var
|
|
12
13
|
|
|
13
14
|
DEFAULT_DEBOUNCE_TIMEOUT = 300
|
|
14
15
|
|
|
@@ -22,50 +23,62 @@ class DebounceInput(Component):
|
|
|
22
23
|
debounce_timeout: Optional[Union[Var[int], int]] = None,
|
|
23
24
|
force_notify_by_enter: Optional[Union[Var[bool], bool]] = None,
|
|
24
25
|
force_notify_on_blur: Optional[Union[Var[bool], bool]] = None,
|
|
25
|
-
value: Optional[Union[Var[Union[float, int, str]],
|
|
26
|
+
value: Optional[Union[Var[Union[float, int, str]], str, int, float]] = None,
|
|
26
27
|
input_ref: Optional[Union[Var[str], str]] = None,
|
|
27
|
-
element: Optional[Union[Type[Component],
|
|
28
|
+
element: Optional[Union[Var[Type[Component]], Type[Component]]] = None,
|
|
28
29
|
style: Optional[Style] = None,
|
|
29
30
|
key: Optional[Any] = None,
|
|
30
31
|
id: Optional[Any] = None,
|
|
31
32
|
class_name: Optional[Any] = None,
|
|
32
33
|
autofocus: Optional[bool] = None,
|
|
33
|
-
custom_attrs: Optional[Dict[str, Union[
|
|
34
|
-
on_blur: Optional[
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
|
|
35
|
+
on_blur: Optional[
|
|
36
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
37
|
+
] = None,
|
|
38
|
+
on_change: Optional[
|
|
39
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
40
|
+
] = None,
|
|
41
|
+
on_click: Optional[
|
|
42
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
43
|
+
] = None,
|
|
37
44
|
on_context_menu: Optional[
|
|
38
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
45
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
39
46
|
] = None,
|
|
40
47
|
on_double_click: Optional[
|
|
41
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
48
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
49
|
+
] = None,
|
|
50
|
+
on_focus: Optional[
|
|
51
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
52
|
+
] = None,
|
|
53
|
+
on_mount: Optional[
|
|
54
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
42
55
|
] = None,
|
|
43
|
-
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
44
|
-
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
45
56
|
on_mouse_down: Optional[
|
|
46
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
57
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
47
58
|
] = None,
|
|
48
59
|
on_mouse_enter: Optional[
|
|
49
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
60
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
50
61
|
] = None,
|
|
51
62
|
on_mouse_leave: Optional[
|
|
52
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
63
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
53
64
|
] = None,
|
|
54
65
|
on_mouse_move: Optional[
|
|
55
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
66
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
56
67
|
] = None,
|
|
57
68
|
on_mouse_out: Optional[
|
|
58
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
69
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
59
70
|
] = None,
|
|
60
71
|
on_mouse_over: Optional[
|
|
61
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
72
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
62
73
|
] = None,
|
|
63
74
|
on_mouse_up: Optional[
|
|
64
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
75
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
76
|
+
] = None,
|
|
77
|
+
on_scroll: Optional[
|
|
78
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
65
79
|
] = None,
|
|
66
|
-
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
67
80
|
on_unmount: Optional[
|
|
68
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
81
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
69
82
|
] = None,
|
|
70
83
|
**props,
|
|
71
84
|
) -> "DebounceInput":
|
|
@@ -9,8 +9,9 @@ from reflex.components.base.fragment import Fragment
|
|
|
9
9
|
from reflex.components.component import Component
|
|
10
10
|
from reflex.components.tags import IterTag
|
|
11
11
|
from reflex.constants import MemoizationMode
|
|
12
|
+
from reflex.ivars.base import ImmutableVar
|
|
12
13
|
from reflex.state import ComponentState
|
|
13
|
-
from reflex.vars
|
|
14
|
+
from reflex.vars import Var
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class ForeachVarError(TypeError):
|
|
@@ -51,7 +52,7 @@ class Foreach(Component):
|
|
|
51
52
|
ForeachVarError: If the iterable is of type Any.
|
|
52
53
|
TypeError: If the render function is a ComponentState.
|
|
53
54
|
"""
|
|
54
|
-
iterable =
|
|
55
|
+
iterable = ImmutableVar.create_safe(iterable)
|
|
55
56
|
if iterable._var_type == Any:
|
|
56
57
|
raise ForeachVarError(
|
|
57
58
|
f"Could not foreach over var `{str(iterable)}` of type Any. "
|
|
@@ -129,7 +130,7 @@ class Foreach(Component):
|
|
|
129
130
|
iterable_state=str(tag.iterable),
|
|
130
131
|
arg_name=tag.arg_var_name,
|
|
131
132
|
arg_index=tag.get_index_var_arg(),
|
|
132
|
-
iterable_type=tag.iterable._var_type.mro()[0].__name__,
|
|
133
|
+
iterable_type=tag.iterable.upcast()._var_type.mro()[0].__name__,
|
|
133
134
|
)
|
|
134
135
|
|
|
135
136
|
|
reflex/components/core/html.py
CHANGED
reflex/components/core/html.pyi
CHANGED
|
@@ -7,8 +7,9 @@ from typing import Any, Callable, Dict, Optional, Union, overload
|
|
|
7
7
|
|
|
8
8
|
from reflex.components.el.elements.typography import Div
|
|
9
9
|
from reflex.event import EventHandler, EventSpec
|
|
10
|
+
from reflex.ivars.base import ImmutableVar
|
|
10
11
|
from reflex.style import Style
|
|
11
|
-
from reflex.vars
|
|
12
|
+
from reflex.vars import Var
|
|
12
13
|
|
|
13
14
|
class Html(Div):
|
|
14
15
|
@overload
|
|
@@ -17,72 +18,82 @@ class Html(Div):
|
|
|
17
18
|
cls,
|
|
18
19
|
*children,
|
|
19
20
|
dangerouslySetInnerHTML: Optional[
|
|
20
|
-
Union[Dict[str, str],
|
|
21
|
+
Union[Var[Dict[str, str]], Dict[str, str]]
|
|
21
22
|
] = None,
|
|
22
|
-
access_key: Optional[Union[Var[Union[bool, int, str]],
|
|
23
|
+
access_key: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
23
24
|
auto_capitalize: Optional[
|
|
24
|
-
Union[Var[Union[bool, int, str]],
|
|
25
|
+
Union[Var[Union[bool, int, str]], str, int, bool]
|
|
25
26
|
] = None,
|
|
26
27
|
content_editable: Optional[
|
|
27
|
-
Union[Var[Union[bool, int, str]],
|
|
28
|
+
Union[Var[Union[bool, int, str]], str, int, bool]
|
|
28
29
|
] = None,
|
|
29
30
|
context_menu: Optional[
|
|
30
|
-
Union[Var[Union[bool, int, str]],
|
|
31
|
+
Union[Var[Union[bool, int, str]], str, int, bool]
|
|
31
32
|
] = None,
|
|
32
|
-
dir: Optional[Union[Var[Union[bool, int, str]],
|
|
33
|
-
draggable: Optional[Union[Var[Union[bool, int, str]],
|
|
33
|
+
dir: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
34
|
+
draggable: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
34
35
|
enter_key_hint: Optional[
|
|
35
|
-
Union[Var[Union[bool, int, str]],
|
|
36
|
-
] = None,
|
|
37
|
-
hidden: Optional[Union[Var[Union[bool, int, str]],
|
|
38
|
-
input_mode: Optional[Union[Var[Union[bool, int, str]],
|
|
39
|
-
item_prop: Optional[Union[Var[Union[bool, int, str]],
|
|
40
|
-
lang: Optional[Union[Var[Union[bool, int, str]],
|
|
41
|
-
role: Optional[Union[Var[Union[bool, int, str]],
|
|
42
|
-
slot: Optional[Union[Var[Union[bool, int, str]],
|
|
43
|
-
spell_check: Optional[Union[Var[Union[bool, int, str]],
|
|
44
|
-
tab_index: Optional[Union[Var[Union[bool, int, str]],
|
|
45
|
-
title: Optional[Union[Var[Union[bool, int, str]],
|
|
36
|
+
Union[Var[Union[bool, int, str]], str, int, bool]
|
|
37
|
+
] = None,
|
|
38
|
+
hidden: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
39
|
+
input_mode: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
40
|
+
item_prop: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
41
|
+
lang: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
42
|
+
role: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
43
|
+
slot: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
44
|
+
spell_check: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
45
|
+
tab_index: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
46
|
+
title: Optional[Union[Var[Union[bool, int, str]], str, int, bool]] = None,
|
|
46
47
|
style: Optional[Style] = None,
|
|
47
48
|
key: Optional[Any] = None,
|
|
48
49
|
id: Optional[Any] = None,
|
|
49
50
|
class_name: Optional[Any] = None,
|
|
50
51
|
autofocus: Optional[bool] = None,
|
|
51
|
-
custom_attrs: Optional[Dict[str, Union[
|
|
52
|
-
on_blur: Optional[
|
|
53
|
-
|
|
52
|
+
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
|
|
53
|
+
on_blur: Optional[
|
|
54
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
55
|
+
] = None,
|
|
56
|
+
on_click: Optional[
|
|
57
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
58
|
+
] = None,
|
|
54
59
|
on_context_menu: Optional[
|
|
55
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
60
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
56
61
|
] = None,
|
|
57
62
|
on_double_click: Optional[
|
|
58
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
63
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
64
|
+
] = None,
|
|
65
|
+
on_focus: Optional[
|
|
66
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
67
|
+
] = None,
|
|
68
|
+
on_mount: Optional[
|
|
69
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
59
70
|
] = None,
|
|
60
|
-
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
61
|
-
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
62
71
|
on_mouse_down: Optional[
|
|
63
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
72
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
64
73
|
] = None,
|
|
65
74
|
on_mouse_enter: Optional[
|
|
66
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
75
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
67
76
|
] = None,
|
|
68
77
|
on_mouse_leave: Optional[
|
|
69
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
78
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
70
79
|
] = None,
|
|
71
80
|
on_mouse_move: Optional[
|
|
72
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
81
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
73
82
|
] = None,
|
|
74
83
|
on_mouse_out: Optional[
|
|
75
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
84
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
76
85
|
] = None,
|
|
77
86
|
on_mouse_over: Optional[
|
|
78
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
87
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
79
88
|
] = None,
|
|
80
89
|
on_mouse_up: Optional[
|
|
81
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
90
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
91
|
+
] = None,
|
|
92
|
+
on_scroll: Optional[
|
|
93
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
82
94
|
] = None,
|
|
83
|
-
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
|
|
84
95
|
on_unmount: Optional[
|
|
85
|
-
Union[EventHandler, EventSpec, list, Callable,
|
|
96
|
+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
|
|
86
97
|
] = None,
|
|
87
98
|
**props,
|
|
88
99
|
) -> "Html":
|
reflex/components/core/match.py
CHANGED
|
@@ -6,12 +6,12 @@ from typing import Any, Dict, List, Optional, Tuple, Union
|
|
|
6
6
|
from reflex.components.base import Fragment
|
|
7
7
|
from reflex.components.component import BaseComponent, Component, MemoizationLeaf
|
|
8
8
|
from reflex.components.tags import MatchTag, Tag
|
|
9
|
+
from reflex.ivars.base import ImmutableVar, LiteralVar
|
|
9
10
|
from reflex.style import Style
|
|
10
11
|
from reflex.utils import format, types
|
|
11
12
|
from reflex.utils.exceptions import MatchTypeError
|
|
12
13
|
from reflex.utils.imports import ImportDict
|
|
13
|
-
from reflex.vars import VarData
|
|
14
|
-
from reflex.vars.base import LiteralVar, Var
|
|
14
|
+
from reflex.vars import Var, VarData
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class Match(MemoizationLeaf):
|
|
@@ -27,7 +27,7 @@ class Match(MemoizationLeaf):
|
|
|
27
27
|
default: Any
|
|
28
28
|
|
|
29
29
|
@classmethod
|
|
30
|
-
def create(cls, cond: Any, *cases) -> Union[Component,
|
|
30
|
+
def create(cls, cond: Any, *cases) -> Union[Component, ImmutableVar]:
|
|
31
31
|
"""Create a Match Component.
|
|
32
32
|
|
|
33
33
|
Args:
|
|
@@ -56,7 +56,7 @@ class Match(MemoizationLeaf):
|
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
@classmethod
|
|
59
|
-
def _create_condition_var(cls, cond: Any) ->
|
|
59
|
+
def _create_condition_var(cls, cond: Any) -> ImmutableVar:
|
|
60
60
|
"""Convert the condition to a Var.
|
|
61
61
|
|
|
62
62
|
Args:
|
|
@@ -77,7 +77,7 @@ class Match(MemoizationLeaf):
|
|
|
77
77
|
@classmethod
|
|
78
78
|
def _process_cases(
|
|
79
79
|
cls, cases: List
|
|
80
|
-
) -> Tuple[List, Optional[Union[
|
|
80
|
+
) -> Tuple[List, Optional[Union[ImmutableVar, BaseComponent]]]:
|
|
81
81
|
"""Process the list of match cases and the catchall default case.
|
|
82
82
|
|
|
83
83
|
Args:
|
|
@@ -125,7 +125,7 @@ class Match(MemoizationLeaf):
|
|
|
125
125
|
return case_element
|
|
126
126
|
|
|
127
127
|
@classmethod
|
|
128
|
-
def _process_match_cases(cls, cases: List) -> List[List[
|
|
128
|
+
def _process_match_cases(cls, cases: List) -> List[List[ImmutableVar]]:
|
|
129
129
|
"""Process the individual match cases.
|
|
130
130
|
|
|
131
131
|
Args:
|
|
@@ -157,7 +157,7 @@ class Match(MemoizationLeaf):
|
|
|
157
157
|
if not isinstance(element, BaseComponent)
|
|
158
158
|
else element
|
|
159
159
|
)
|
|
160
|
-
if not isinstance(el, (
|
|
160
|
+
if not isinstance(el, (ImmutableVar, BaseComponent)):
|
|
161
161
|
raise ValueError("Case element must be a var or component")
|
|
162
162
|
case_list.append(el)
|
|
163
163
|
|
|
@@ -166,7 +166,7 @@ class Match(MemoizationLeaf):
|
|
|
166
166
|
return match_cases
|
|
167
167
|
|
|
168
168
|
@classmethod
|
|
169
|
-
def _validate_return_types(cls, match_cases: List[List[
|
|
169
|
+
def _validate_return_types(cls, match_cases: List[List[ImmutableVar]]) -> None:
|
|
170
170
|
"""Validate that match cases have the same return types.
|
|
171
171
|
|
|
172
172
|
Args:
|
|
@@ -180,24 +180,24 @@ class Match(MemoizationLeaf):
|
|
|
180
180
|
|
|
181
181
|
if types._isinstance(first_case_return, BaseComponent):
|
|
182
182
|
return_type = BaseComponent
|
|
183
|
-
elif types._isinstance(first_case_return,
|
|
184
|
-
return_type =
|
|
183
|
+
elif types._isinstance(first_case_return, ImmutableVar):
|
|
184
|
+
return_type = ImmutableVar
|
|
185
185
|
|
|
186
186
|
for index, case in enumerate(match_cases):
|
|
187
187
|
if not types._issubclass(type(case[-1]), return_type):
|
|
188
188
|
raise MatchTypeError(
|
|
189
189
|
f"Match cases should have the same return types. Case {index} with return "
|
|
190
|
-
f"value `{case[-1].
|
|
190
|
+
f"value `{case[-1]._var_name if isinstance(case[-1], ImmutableVar) else textwrap.shorten(str(case[-1]), width=250)}`"
|
|
191
191
|
f" of type {type(case[-1])!r} is not {return_type}"
|
|
192
192
|
)
|
|
193
193
|
|
|
194
194
|
@classmethod
|
|
195
195
|
def _create_match_cond_var_or_component(
|
|
196
196
|
cls,
|
|
197
|
-
match_cond_var:
|
|
198
|
-
match_cases: List[List[
|
|
199
|
-
default: Optional[Union[
|
|
200
|
-
) -> Union[Component,
|
|
197
|
+
match_cond_var: ImmutableVar,
|
|
198
|
+
match_cases: List[List[ImmutableVar]],
|
|
199
|
+
default: Optional[Union[ImmutableVar, BaseComponent]],
|
|
200
|
+
) -> Union[Component, ImmutableVar]:
|
|
201
201
|
"""Create and return the match condition var or component.
|
|
202
202
|
|
|
203
203
|
Args:
|
|
@@ -232,8 +232,8 @@ class Match(MemoizationLeaf):
|
|
|
232
232
|
) or not types._isinstance(default, Var):
|
|
233
233
|
raise ValueError("Return types of match cases should be Vars.")
|
|
234
234
|
|
|
235
|
-
return
|
|
236
|
-
|
|
235
|
+
return ImmutableVar(
|
|
236
|
+
_var_name=format.format_match(
|
|
237
237
|
cond=str(match_cond_var),
|
|
238
238
|
match_cases=match_cases,
|
|
239
239
|
default=default, # type: ignore
|
reflex/components/core/upload.py
CHANGED
|
@@ -19,10 +19,10 @@ from reflex.event import (
|
|
|
19
19
|
call_script,
|
|
20
20
|
parse_args_spec,
|
|
21
21
|
)
|
|
22
|
+
from reflex.ivars.base import ImmutableCallableVar, ImmutableVar, LiteralVar
|
|
23
|
+
from reflex.ivars.sequence import LiteralStringVar
|
|
22
24
|
from reflex.utils.imports import ImportVar
|
|
23
|
-
from reflex.vars import VarData
|
|
24
|
-
from reflex.vars.base import CallableVar, LiteralVar, Var
|
|
25
|
-
from reflex.vars.sequence import LiteralStringVar
|
|
25
|
+
from reflex.vars import Var, VarData
|
|
26
26
|
|
|
27
27
|
DEFAULT_UPLOAD_ID: str = "default"
|
|
28
28
|
|
|
@@ -37,8 +37,8 @@ upload_files_context_var_data: VarData = VarData(
|
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
@
|
|
41
|
-
def upload_file(id_: str = DEFAULT_UPLOAD_ID) ->
|
|
40
|
+
@ImmutableCallableVar
|
|
41
|
+
def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> ImmutableVar:
|
|
42
42
|
"""Get the file upload drop trigger.
|
|
43
43
|
|
|
44
44
|
This var is passed to the dropzone component to update the file list when a
|
|
@@ -58,8 +58,8 @@ def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
58
58
|
}})
|
|
59
59
|
"""
|
|
60
60
|
|
|
61
|
-
return
|
|
62
|
-
|
|
61
|
+
return ImmutableVar(
|
|
62
|
+
_var_name=var_name,
|
|
63
63
|
_var_type=EventChain,
|
|
64
64
|
_var_data=VarData.merge(
|
|
65
65
|
upload_files_context_var_data, id_var._get_all_var_data()
|
|
@@ -67,8 +67,8 @@ def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
67
67
|
)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
@
|
|
71
|
-
def selected_files(id_: str = DEFAULT_UPLOAD_ID) ->
|
|
70
|
+
@ImmutableCallableVar
|
|
71
|
+
def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> ImmutableVar:
|
|
72
72
|
"""Get the list of selected files.
|
|
73
73
|
|
|
74
74
|
Args:
|
|
@@ -78,8 +78,8 @@ def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
78
78
|
A var referencing the list of selected file paths.
|
|
79
79
|
"""
|
|
80
80
|
id_var = LiteralStringVar.create(id_)
|
|
81
|
-
return
|
|
82
|
-
|
|
81
|
+
return ImmutableVar(
|
|
82
|
+
_var_name=f"(filesById[{str(id_var)}] ? filesById[{str(id_var)}].map((f) => (f.path || f.name)) : [])",
|
|
83
83
|
_var_type=List[str],
|
|
84
84
|
_var_data=VarData.merge(
|
|
85
85
|
upload_files_context_var_data, id_var._get_all_var_data()
|
|
@@ -132,8 +132,8 @@ def get_upload_dir() -> Path:
|
|
|
132
132
|
return uploaded_files_dir
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
uploaded_files_url_prefix =
|
|
136
|
-
|
|
135
|
+
uploaded_files_url_prefix = ImmutableVar(
|
|
136
|
+
_var_name="getBackendURL(env.UPLOAD)",
|
|
137
137
|
_var_data=VarData(
|
|
138
138
|
imports={
|
|
139
139
|
f"/{Dirs.STATE_PATH}": "getBackendURL",
|
|
@@ -247,7 +247,9 @@ class Upload(MemoizationLeaf):
|
|
|
247
247
|
}
|
|
248
248
|
# The file input to use.
|
|
249
249
|
upload = Input.create(type="file")
|
|
250
|
-
upload.special_props =
|
|
250
|
+
upload.special_props = {
|
|
251
|
+
ImmutableVar(_var_name="{...getInputProps()}", _var_type=None)
|
|
252
|
+
}
|
|
251
253
|
|
|
252
254
|
# The dropzone to use.
|
|
253
255
|
zone = Box.create(
|
|
@@ -255,7 +257,9 @@ class Upload(MemoizationLeaf):
|
|
|
255
257
|
*children,
|
|
256
258
|
**{k: v for k, v in props.items() if k not in supported_props},
|
|
257
259
|
)
|
|
258
|
-
zone.special_props =
|
|
260
|
+
zone.special_props = {
|
|
261
|
+
ImmutableVar(_var_name="{...getRootProps()}", _var_type=None)
|
|
262
|
+
}
|
|
259
263
|
|
|
260
264
|
# Create the component.
|
|
261
265
|
upload_props["id"] = props.get("id", DEFAULT_UPLOAD_ID)
|
|
@@ -283,7 +287,9 @@ class Upload(MemoizationLeaf):
|
|
|
283
287
|
)
|
|
284
288
|
|
|
285
289
|
@classmethod
|
|
286
|
-
def _update_arg_tuple_for_on_drop(
|
|
290
|
+
def _update_arg_tuple_for_on_drop(
|
|
291
|
+
cls, arg_value: tuple[ImmutableVar, ImmutableVar]
|
|
292
|
+
):
|
|
287
293
|
"""Helper to update caller-provided EventSpec args for direct use with on_drop.
|
|
288
294
|
|
|
289
295
|
Args:
|
|
@@ -292,7 +298,7 @@ class Upload(MemoizationLeaf):
|
|
|
292
298
|
Returns:
|
|
293
299
|
The updated arg_value tuple when arg is "files", otherwise the original arg_value.
|
|
294
300
|
"""
|
|
295
|
-
if arg_value[0].
|
|
301
|
+
if arg_value[0]._var_name == "files":
|
|
296
302
|
placeholder = parse_args_spec(_on_drop_spec)[0]
|
|
297
303
|
return (arg_value[0], placeholder)
|
|
298
304
|
return arg_value
|