reflex 0.5.4a2__py3-none-any.whl → 0.5.5__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/apps/demo/code/demo.py +1 -0
- reflex/.templates/apps/demo/code/pages/__init__.py +1 -0
- reflex/.templates/apps/demo/code/pages/datatable.py +1 -0
- reflex/.templates/apps/demo/code/pages/forms.py +1 -0
- reflex/.templates/apps/demo/code/pages/graphing.py +1 -0
- reflex/.templates/apps/demo/code/pages/home.py +1 -0
- reflex/.templates/apps/demo/code/styles.py +1 -0
- reflex/.templates/apps/demo/code/webui/components/loading_icon.py +1 -8
- reflex/.templates/web/components/reflex/chakra_color_mode_provider.js +27 -12
- reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +19 -5
- reflex/.templates/web/utils/state.js +73 -7
- reflex/__init__.py +3 -0
- reflex/__init__.pyi +3 -0
- reflex/admin.py +1 -0
- reflex/app.py +8 -6
- reflex/app_module_for_backend.py +2 -1
- reflex/base.py +4 -4
- reflex/compiler/compiler.py +4 -3
- reflex/compiler/templates.py +2 -0
- reflex/compiler/utils.py +58 -35
- reflex/components/__init__.py +1 -0
- reflex/components/base/__init__.py +1 -0
- reflex/components/base/app_wrap.py +1 -0
- reflex/components/base/fragment.py +1 -0
- reflex/components/base/link.py +0 -1
- reflex/components/base/script.py +11 -15
- reflex/components/base/script.pyi +1 -2
- reflex/components/chakra/base.py +15 -13
- reflex/components/chakra/base.pyi +3 -1
- reflex/components/chakra/datadisplay/code.py +1 -0
- reflex/components/chakra/datadisplay/divider.py +1 -0
- reflex/components/chakra/datadisplay/table.py +1 -0
- reflex/components/chakra/datadisplay/table.pyi +3 -0
- reflex/components/chakra/datadisplay/tag.py +1 -0
- reflex/components/chakra/disclosure/transition.py +1 -0
- reflex/components/chakra/feedback/circularprogress.py +1 -0
- reflex/components/chakra/forms/button.py +1 -0
- reflex/components/chakra/forms/checkbox.py +4 -13
- reflex/components/chakra/forms/checkbox.pyi +1 -3
- reflex/components/chakra/forms/colormodeswitch.py +1 -0
- reflex/components/chakra/forms/editable.py +13 -16
- reflex/components/chakra/forms/editable.pyi +1 -3
- reflex/components/chakra/forms/form.py +1 -0
- reflex/components/chakra/forms/input.py +22 -21
- reflex/components/chakra/forms/input.pyi +4 -4
- reflex/components/chakra/forms/multiselect.py +1 -0
- reflex/components/chakra/forms/numberinput.py +3 -12
- reflex/components/chakra/forms/numberinput.pyi +1 -3
- reflex/components/chakra/forms/pininput.py +8 -14
- reflex/components/chakra/forms/pininput.pyi +2 -3
- reflex/components/chakra/forms/radio.py +4 -13
- reflex/components/chakra/forms/radio.pyi +2 -3
- reflex/components/chakra/forms/rangeslider.py +10 -13
- reflex/components/chakra/forms/rangeslider.pyi +2 -3
- reflex/components/chakra/forms/select.py +4 -12
- reflex/components/chakra/forms/select.pyi +2 -3
- reflex/components/chakra/forms/slider.py +10 -13
- reflex/components/chakra/forms/slider.pyi +2 -3
- reflex/components/chakra/forms/switch.py +4 -13
- reflex/components/chakra/forms/switch.pyi +1 -3
- reflex/components/chakra/forms/textarea.py +16 -17
- reflex/components/chakra/forms/textarea.pyi +1 -3
- reflex/components/chakra/media/avatar.py +4 -12
- reflex/components/chakra/media/avatar.pyi +1 -2
- reflex/components/chakra/media/icon.py +1 -0
- reflex/components/chakra/media/image.py +7 -11
- reflex/components/chakra/media/image.pyi +2 -2
- reflex/components/chakra/navigation/link.py +8 -4
- reflex/components/chakra/navigation/link.pyi +2 -1
- reflex/components/chakra/overlay/alertdialog.py +12 -14
- reflex/components/chakra/overlay/alertdialog.pyi +1 -2
- reflex/components/chakra/overlay/drawer.py +12 -14
- reflex/components/chakra/overlay/drawer.pyi +1 -2
- reflex/components/chakra/overlay/menu.py +7 -11
- reflex/components/chakra/overlay/menu.pyi +2 -2
- reflex/components/chakra/overlay/modal.py +13 -13
- reflex/components/chakra/overlay/modal.pyi +2 -2
- reflex/components/chakra/overlay/popover.py +6 -12
- reflex/components/chakra/overlay/popover.pyi +1 -2
- reflex/components/chakra/overlay/tooltip.py +7 -13
- reflex/components/chakra/overlay/tooltip.pyi +1 -2
- reflex/components/chakra/typography/heading.py +0 -1
- reflex/components/chakra/typography/span.py +1 -0
- reflex/components/chakra/typography/text.py +1 -0
- reflex/components/component.py +70 -43
- reflex/components/core/__init__.py +1 -0
- reflex/components/core/banner.py +27 -24
- reflex/components/core/banner.pyi +6 -2
- reflex/components/core/client_side_routing.py +1 -0
- reflex/components/core/cond.py +19 -17
- reflex/components/core/debounce.py +4 -11
- reflex/components/core/debounce.pyi +1 -1
- reflex/components/core/foreach.py +1 -0
- reflex/components/core/html.py +1 -0
- reflex/components/core/match.py +9 -6
- reflex/components/core/upload.py +26 -25
- reflex/components/core/upload.pyi +3 -4
- reflex/components/datadisplay/__init__.py +1 -0
- reflex/components/datadisplay/code.py +27 -23
- reflex/components/datadisplay/code.pyi +4 -2
- reflex/components/datadisplay/dataeditor.py +73 -80
- reflex/components/datadisplay/dataeditor.pyi +52 -4
- reflex/components/datadisplay/logo.py +1 -0
- reflex/components/el/__init__.py +1 -0
- reflex/components/el/__init__.pyi +8 -0
- reflex/components/el/element.py +0 -1
- reflex/components/el/elements/__init__.py +5 -0
- reflex/components/el/elements/__init__.pyi +12 -1
- reflex/components/el/elements/base.py +1 -0
- reflex/components/el/elements/forms.py +44 -61
- reflex/components/el/elements/forms.pyi +4 -6
- reflex/components/el/elements/inline.py +1 -0
- reflex/components/el/elements/media.py +53 -0
- reflex/components/el/elements/media.pyi +428 -0
- reflex/components/el/elements/metadata.py +11 -0
- reflex/components/el/elements/metadata.pyi +80 -0
- reflex/components/el/elements/other.py +1 -0
- reflex/components/el/elements/scripts.py +1 -0
- reflex/components/el/elements/tables.py +1 -0
- reflex/components/el/elements/typography.py +1 -0
- reflex/components/gridjs/datatable.py +9 -6
- reflex/components/gridjs/datatable.pyi +4 -1
- reflex/components/markdown/markdown.py +36 -41
- reflex/components/markdown/markdown.pyi +4 -3
- reflex/components/media/icon.py +1 -0
- reflex/components/moment/moment.py +11 -17
- reflex/components/moment/moment.pyi +4 -3
- reflex/components/next/base.py +1 -0
- reflex/components/next/image.py +6 -11
- reflex/components/next/image.pyi +2 -2
- reflex/components/plotly/plotly.py +1 -0
- reflex/components/props.py +1 -0
- reflex/components/radix/__init__.py +1 -0
- reflex/components/radix/primitives/__init__.py +1 -0
- reflex/components/radix/primitives/accordion.py +7 -15
- reflex/components/radix/primitives/accordion.pyi +7 -4
- reflex/components/radix/primitives/base.py +1 -0
- reflex/components/radix/primitives/drawer.py +17 -27
- reflex/components/radix/primitives/drawer.pyi +2 -4
- reflex/components/radix/primitives/form.py +4 -12
- reflex/components/radix/primitives/form.pyi +2 -3
- reflex/components/radix/primitives/slider.py +6 -11
- reflex/components/radix/primitives/slider.pyi +2 -2
- reflex/components/radix/themes/__init__.py +1 -0
- reflex/components/radix/themes/base.py +3 -3
- reflex/components/radix/themes/base.pyi +3 -2
- reflex/components/radix/themes/color_mode.py +31 -2
- reflex/components/radix/themes/color_mode.pyi +10 -1
- reflex/components/radix/themes/components/__init__.py +1 -0
- reflex/components/radix/themes/components/alert_dialog.py +13 -24
- reflex/components/radix/themes/components/alert_dialog.pyi +2 -4
- reflex/components/radix/themes/components/aspect_ratio.py +1 -0
- reflex/components/radix/themes/components/card.py +1 -0
- reflex/components/radix/themes/components/checkbox.py +6 -22
- reflex/components/radix/themes/components/checkbox.pyi +2 -4
- reflex/components/radix/themes/components/checkbox_group.py +15 -3
- reflex/components/radix/themes/components/checkbox_group.pyi +10 -2
- reflex/components/radix/themes/components/context_menu.py +29 -38
- reflex/components/radix/themes/components/context_menu.pyi +2 -5
- reflex/components/radix/themes/components/dialog.py +18 -26
- reflex/components/radix/themes/components/dialog.pyi +2 -4
- reflex/components/radix/themes/components/dropdown_menu.py +32 -57
- reflex/components/radix/themes/components/dropdown_menu.pyi +2 -7
- reflex/components/radix/themes/components/hover_card.py +5 -12
- reflex/components/radix/themes/components/hover_card.pyi +2 -3
- reflex/components/radix/themes/components/icon_button.py +1 -0
- reflex/components/radix/themes/components/icon_button.pyi +1 -0
- reflex/components/radix/themes/components/inset.py +1 -0
- reflex/components/radix/themes/components/popover.py +22 -27
- reflex/components/radix/themes/components/popover.pyi +2 -4
- reflex/components/radix/themes/components/radio_group.py +25 -17
- reflex/components/radix/themes/components/radio_group.pyi +2 -3
- reflex/components/radix/themes/components/scroll_area.py +1 -0
- reflex/components/radix/themes/components/segmented_control.py +18 -5
- reflex/components/radix/themes/components/segmented_control.pyi +16 -7
- reflex/components/radix/themes/components/select.py +13 -23
- reflex/components/radix/themes/components/select.pyi +1 -4
- reflex/components/radix/themes/components/separator.py +1 -0
- reflex/components/radix/themes/components/slider.py +7 -12
- reflex/components/radix/themes/components/slider.pyi +2 -3
- reflex/components/radix/themes/components/switch.py +5 -12
- reflex/components/radix/themes/components/switch.pyi +2 -3
- reflex/components/radix/themes/components/table.py +1 -0
- reflex/components/radix/themes/components/tabs.py +4 -11
- reflex/components/radix/themes/components/tabs.pyi +2 -2
- reflex/components/radix/themes/components/text_area.py +19 -18
- reflex/components/radix/themes/components/text_area.pyi +2 -3
- reflex/components/radix/themes/components/text_field.py +19 -18
- reflex/components/radix/themes/components/text_field.pyi +3 -3
- reflex/components/radix/themes/components/tooltip.py +10 -13
- reflex/components/radix/themes/components/tooltip.pyi +2 -3
- reflex/components/radix/themes/layout/__init__.py +1 -0
- reflex/components/radix/themes/layout/box.py +1 -0
- reflex/components/radix/themes/layout/container.py +1 -0
- reflex/components/radix/themes/layout/list.py +1 -0
- reflex/components/radix/themes/layout/list.pyi +1 -0
- reflex/components/radix/themes/layout/section.py +1 -0
- reflex/components/radix/themes/typography/__init__.py +1 -0
- reflex/components/radix/themes/typography/base.py +1 -0
- reflex/components/radix/themes/typography/blockquote.py +1 -0
- reflex/components/radix/themes/typography/code.py +1 -0
- reflex/components/radix/themes/typography/heading.py +1 -0
- reflex/components/radix/themes/typography/link.py +8 -3
- reflex/components/radix/themes/typography/link.pyi +2 -1
- reflex/components/react_player/audio.py +1 -0
- reflex/components/react_player/audio.pyi +48 -0
- reflex/components/react_player/react_player.py +49 -0
- reflex/components/react_player/react_player.pyi +49 -0
- reflex/components/react_player/video.py +1 -0
- reflex/components/react_player/video.pyi +48 -0
- reflex/components/recharts/__init__.py +1 -0
- reflex/components/recharts/cartesian.py +264 -74
- reflex/components/recharts/cartesian.pyi +573 -58
- reflex/components/recharts/charts.py +68 -78
- reflex/components/recharts/charts.pyi +373 -156
- reflex/components/recharts/general.py +52 -20
- reflex/components/recharts/general.pyi +52 -6
- reflex/components/recharts/polar.py +30 -18
- reflex/components/recharts/polar.pyi +66 -5
- reflex/components/recharts/recharts.py +5 -3
- reflex/components/recharts/recharts.pyi +2 -1
- reflex/components/sonner/toast.py +2 -2
- reflex/components/sonner/toast.pyi +1 -1
- reflex/components/suneditor/editor.py +39 -26
- reflex/components/suneditor/editor.pyi +4 -4
- reflex/components/tags/iter_tag.py +1 -0
- reflex/constants/__init__.py +3 -2
- reflex/constants/base.py +20 -21
- reflex/constants/compiler.py +3 -1
- reflex/constants/config.py +1 -0
- reflex/constants/event.py +1 -0
- reflex/constants/installer.py +3 -2
- reflex/constants/style.py +2 -8
- reflex/event.py +36 -6
- reflex/experimental/assets.py +1 -0
- reflex/experimental/client_state.py +9 -3
- reflex/experimental/hooks.py +1 -0
- reflex/experimental/misc.py +12 -3
- reflex/middleware/hydrate_middleware.py +1 -0
- reflex/middleware/middleware.py +1 -0
- reflex/state.py +38 -1
- reflex/style.py +67 -20
- reflex/testing.py +6 -2
- reflex/utils/build.py +76 -72
- reflex/utils/compat.py +5 -0
- reflex/utils/exec.py +17 -9
- reflex/utils/export.py +13 -9
- reflex/utils/imports.py +34 -5
- reflex/utils/lazy_loader.py +1 -0
- reflex/utils/path_ops.py +39 -33
- reflex/utils/prerequisites.py +38 -29
- reflex/utils/processes.py +1 -1
- reflex/utils/serializers.py +3 -6
- reflex/utils/watch.py +3 -1
- reflex/vars.py +26 -10
- reflex/vars.pyi +3 -3
- {reflex-0.5.4a2.dist-info → reflex-0.5.5.dist-info}/METADATA +3 -3
- {reflex-0.5.4a2.dist-info → reflex-0.5.5.dist-info}/RECORD +261 -261
- {reflex-0.5.4a2.dist-info → reflex-0.5.5.dist-info}/LICENSE +0 -0
- {reflex-0.5.4a2.dist-info → reflex-0.5.5.dist-info}/WHEEL +0 -0
- {reflex-0.5.4a2.dist-info → reflex-0.5.5.dist-info}/entry_points.txt +0 -0
reflex/compiler/utils.py
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
|
+
from pathlib import Path
|
|
6
7
|
from typing import Any, Callable, Dict, Optional, Type, Union
|
|
7
8
|
from urllib.parse import urlparse
|
|
8
9
|
|
|
10
|
+
from reflex.utils.prerequisites import get_web_dir
|
|
11
|
+
|
|
9
12
|
try:
|
|
10
13
|
from pydantic.v1.fields import ModelField
|
|
11
14
|
except ModuleNotFoundError:
|
|
@@ -25,16 +28,17 @@ from reflex.components.base import (
|
|
|
25
28
|
Title,
|
|
26
29
|
)
|
|
27
30
|
from reflex.components.component import Component, ComponentStyle, CustomComponent
|
|
28
|
-
from reflex.state import BaseState, Cookie, LocalStorage
|
|
31
|
+
from reflex.state import BaseState, Cookie, LocalStorage, SessionStorage
|
|
29
32
|
from reflex.style import Style
|
|
30
33
|
from reflex.utils import console, format, imports, path_ops
|
|
34
|
+
from reflex.utils.imports import ImportVar, ParsedImportDict
|
|
31
35
|
from reflex.vars import Var
|
|
32
36
|
|
|
33
37
|
# To re-export this function.
|
|
34
38
|
merge_imports = imports.merge_imports
|
|
35
39
|
|
|
36
40
|
|
|
37
|
-
def compile_import_statement(fields: list[
|
|
41
|
+
def compile_import_statement(fields: list[ImportVar]) -> tuple[str, list[str]]:
|
|
38
42
|
"""Compile an import statement.
|
|
39
43
|
|
|
40
44
|
Args:
|
|
@@ -59,7 +63,7 @@ def compile_import_statement(fields: list[imports.ImportVar]) -> tuple[str, list
|
|
|
59
63
|
return default, list(rest)
|
|
60
64
|
|
|
61
65
|
|
|
62
|
-
def validate_imports(import_dict:
|
|
66
|
+
def validate_imports(import_dict: ParsedImportDict):
|
|
63
67
|
"""Verify that the same Tag is not used in multiple import.
|
|
64
68
|
|
|
65
69
|
Args:
|
|
@@ -82,7 +86,7 @@ def validate_imports(import_dict: imports.ImportDict):
|
|
|
82
86
|
used_tags[import_name] = lib
|
|
83
87
|
|
|
84
88
|
|
|
85
|
-
def compile_imports(import_dict:
|
|
89
|
+
def compile_imports(import_dict: ParsedImportDict) -> list[dict]:
|
|
86
90
|
"""Compile an import dict.
|
|
87
91
|
|
|
88
92
|
Args:
|
|
@@ -91,7 +95,7 @@ def compile_imports(import_dict: imports.ImportDict) -> list[dict]:
|
|
|
91
95
|
Returns:
|
|
92
96
|
The list of import dict.
|
|
93
97
|
"""
|
|
94
|
-
collapsed_import_dict = imports.collapse_imports(import_dict)
|
|
98
|
+
collapsed_import_dict: ParsedImportDict = imports.collapse_imports(import_dict)
|
|
95
99
|
validate_imports(collapsed_import_dict)
|
|
96
100
|
import_dicts = []
|
|
97
101
|
for lib, fields in collapsed_import_dict.items():
|
|
@@ -154,8 +158,11 @@ def compile_state(state: Type[BaseState]) -> dict:
|
|
|
154
158
|
|
|
155
159
|
def _compile_client_storage_field(
|
|
156
160
|
field: ModelField,
|
|
157
|
-
) -> tuple[
|
|
158
|
-
|
|
161
|
+
) -> tuple[
|
|
162
|
+
Type[Cookie] | Type[LocalStorage] | Type[SessionStorage] | None,
|
|
163
|
+
dict[str, Any] | None,
|
|
164
|
+
]:
|
|
165
|
+
"""Compile the given cookie, local_storage or session_storage field.
|
|
159
166
|
|
|
160
167
|
Args:
|
|
161
168
|
field: The possible cookie field to compile.
|
|
@@ -163,7 +170,7 @@ def _compile_client_storage_field(
|
|
|
163
170
|
Returns:
|
|
164
171
|
A dictionary of the compiled cookie or None if the field is not cookie-like.
|
|
165
172
|
"""
|
|
166
|
-
for field_type in (Cookie, LocalStorage):
|
|
173
|
+
for field_type in (Cookie, LocalStorage, SessionStorage):
|
|
167
174
|
if isinstance(field.default, field_type):
|
|
168
175
|
cs_obj = field.default
|
|
169
176
|
elif isinstance(field.type_, type) and issubclass(field.type_, field_type):
|
|
@@ -176,7 +183,7 @@ def _compile_client_storage_field(
|
|
|
176
183
|
|
|
177
184
|
def _compile_client_storage_recursive(
|
|
178
185
|
state: Type[BaseState],
|
|
179
|
-
) -> tuple[dict[str, dict], dict[str, dict[str,
|
|
186
|
+
) -> tuple[dict[str, dict], dict[str, dict], dict[str, dict]]:
|
|
180
187
|
"""Compile the client-side storage for the given state recursively.
|
|
181
188
|
|
|
182
189
|
Args:
|
|
@@ -187,10 +194,12 @@ def _compile_client_storage_recursive(
|
|
|
187
194
|
(
|
|
188
195
|
cookies: dict[str, dict],
|
|
189
196
|
local_storage: dict[str, dict[str, str]]
|
|
190
|
-
|
|
197
|
+
session_storage: dict[str, dict[str, str]]
|
|
198
|
+
).
|
|
191
199
|
"""
|
|
192
200
|
cookies = {}
|
|
193
201
|
local_storage = {}
|
|
202
|
+
session_storage = {}
|
|
194
203
|
state_name = state.get_full_name()
|
|
195
204
|
for name, field in state.__fields__.items():
|
|
196
205
|
if name in state.inherited_vars:
|
|
@@ -202,15 +211,20 @@ def _compile_client_storage_recursive(
|
|
|
202
211
|
cookies[state_key] = options
|
|
203
212
|
elif field_type is LocalStorage:
|
|
204
213
|
local_storage[state_key] = options
|
|
214
|
+
elif field_type is SessionStorage:
|
|
215
|
+
session_storage[state_key] = options
|
|
205
216
|
else:
|
|
206
217
|
continue
|
|
207
218
|
for substate in state.get_substates():
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
219
|
+
(
|
|
220
|
+
substate_cookies,
|
|
221
|
+
substate_local_storage,
|
|
222
|
+
substate_session_storage,
|
|
223
|
+
) = _compile_client_storage_recursive(substate)
|
|
211
224
|
cookies.update(substate_cookies)
|
|
212
225
|
local_storage.update(substate_local_storage)
|
|
213
|
-
|
|
226
|
+
session_storage.update(substate_session_storage)
|
|
227
|
+
return cookies, local_storage, session_storage
|
|
214
228
|
|
|
215
229
|
|
|
216
230
|
def compile_client_storage(state: Type[BaseState]) -> dict[str, dict]:
|
|
@@ -222,16 +236,17 @@ def compile_client_storage(state: Type[BaseState]) -> dict[str, dict]:
|
|
|
222
236
|
Returns:
|
|
223
237
|
A dictionary of the compiled client-side storage info.
|
|
224
238
|
"""
|
|
225
|
-
cookies, local_storage = _compile_client_storage_recursive(state)
|
|
239
|
+
cookies, local_storage, session_storage = _compile_client_storage_recursive(state)
|
|
226
240
|
return {
|
|
227
241
|
constants.COOKIES: cookies,
|
|
228
242
|
constants.LOCAL_STORAGE: local_storage,
|
|
243
|
+
constants.SESSION_STORAGE: session_storage,
|
|
229
244
|
}
|
|
230
245
|
|
|
231
246
|
|
|
232
247
|
def compile_custom_component(
|
|
233
248
|
component: CustomComponent,
|
|
234
|
-
) -> tuple[dict,
|
|
249
|
+
) -> tuple[dict, ParsedImportDict]:
|
|
235
250
|
"""Compile a custom component.
|
|
236
251
|
|
|
237
252
|
Args:
|
|
@@ -244,7 +259,7 @@ def compile_custom_component(
|
|
|
244
259
|
render = component.get_component(component)
|
|
245
260
|
|
|
246
261
|
# Get the imports.
|
|
247
|
-
imports = {
|
|
262
|
+
imports: ParsedImportDict = {
|
|
248
263
|
lib: fields
|
|
249
264
|
for lib, fields in render._get_all_imports().items()
|
|
250
265
|
if lib != component.library
|
|
@@ -329,7 +344,7 @@ def get_page_path(path: str) -> str:
|
|
|
329
344
|
Returns:
|
|
330
345
|
The path of the compiled JS file.
|
|
331
346
|
"""
|
|
332
|
-
return
|
|
347
|
+
return str(get_web_dir() / constants.Dirs.PAGES / (path + constants.Ext.JS))
|
|
333
348
|
|
|
334
349
|
|
|
335
350
|
def get_theme_path() -> str:
|
|
@@ -338,8 +353,10 @@ def get_theme_path() -> str:
|
|
|
338
353
|
Returns:
|
|
339
354
|
The path of the theme style.
|
|
340
355
|
"""
|
|
341
|
-
return
|
|
342
|
-
|
|
356
|
+
return str(
|
|
357
|
+
get_web_dir()
|
|
358
|
+
/ constants.Dirs.UTILS
|
|
359
|
+
/ (constants.PageNames.THEME + constants.Ext.JS)
|
|
343
360
|
)
|
|
344
361
|
|
|
345
362
|
|
|
@@ -349,8 +366,10 @@ def get_root_stylesheet_path() -> str:
|
|
|
349
366
|
Returns:
|
|
350
367
|
The path of the app root file.
|
|
351
368
|
"""
|
|
352
|
-
return
|
|
353
|
-
|
|
369
|
+
return str(
|
|
370
|
+
get_web_dir()
|
|
371
|
+
/ constants.Dirs.STYLES
|
|
372
|
+
/ (constants.PageNames.STYLESHEET_ROOT + constants.Ext.CSS)
|
|
354
373
|
)
|
|
355
374
|
|
|
356
375
|
|
|
@@ -360,9 +379,7 @@ def get_context_path() -> str:
|
|
|
360
379
|
Returns:
|
|
361
380
|
The path of the context module.
|
|
362
381
|
"""
|
|
363
|
-
return
|
|
364
|
-
constants.Dirs.WEB, constants.Dirs.CONTEXTS_PATH + constants.Ext.JS
|
|
365
|
-
)
|
|
382
|
+
return str(get_web_dir() / (constants.Dirs.CONTEXTS_PATH + constants.Ext.JS))
|
|
366
383
|
|
|
367
384
|
|
|
368
385
|
def get_components_path() -> str:
|
|
@@ -371,7 +388,11 @@ def get_components_path() -> str:
|
|
|
371
388
|
Returns:
|
|
372
389
|
The path of the compiled components.
|
|
373
390
|
"""
|
|
374
|
-
return
|
|
391
|
+
return str(
|
|
392
|
+
get_web_dir()
|
|
393
|
+
/ constants.Dirs.UTILS
|
|
394
|
+
/ (constants.PageNames.COMPONENTS + constants.Ext.JS),
|
|
395
|
+
)
|
|
375
396
|
|
|
376
397
|
|
|
377
398
|
def get_stateful_components_path() -> str:
|
|
@@ -380,9 +401,10 @@ def get_stateful_components_path() -> str:
|
|
|
380
401
|
Returns:
|
|
381
402
|
The path of the compiled stateful components.
|
|
382
403
|
"""
|
|
383
|
-
return
|
|
384
|
-
|
|
385
|
-
|
|
404
|
+
return str(
|
|
405
|
+
get_web_dir()
|
|
406
|
+
/ constants.Dirs.UTILS
|
|
407
|
+
/ (constants.PageNames.STATEFUL_COMPONENTS + constants.Ext.JS)
|
|
386
408
|
)
|
|
387
409
|
|
|
388
410
|
|
|
@@ -436,23 +458,24 @@ def write_page(path: str, code: str):
|
|
|
436
458
|
f.write(code)
|
|
437
459
|
|
|
438
460
|
|
|
439
|
-
def empty_dir(path: str, keep_files: list[str] | None = None):
|
|
461
|
+
def empty_dir(path: str | Path, keep_files: list[str] | None = None):
|
|
440
462
|
"""Remove all files and folders in a directory except for the keep_files.
|
|
441
463
|
|
|
442
464
|
Args:
|
|
443
465
|
path: The path to the directory that will be emptied
|
|
444
466
|
keep_files: List of filenames or foldernames that will not be deleted.
|
|
445
467
|
"""
|
|
468
|
+
path = Path(path)
|
|
469
|
+
|
|
446
470
|
# If the directory does not exist, return.
|
|
447
|
-
if not
|
|
471
|
+
if not path.exists():
|
|
448
472
|
return
|
|
449
473
|
|
|
450
474
|
# Remove all files and folders in the directory.
|
|
451
475
|
keep_files = keep_files or []
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
path_ops.rm(os.path.join(path, element))
|
|
476
|
+
for element in path.iterdir():
|
|
477
|
+
if element.name not in keep_files:
|
|
478
|
+
path_ops.rm(element)
|
|
456
479
|
|
|
457
480
|
|
|
458
481
|
def is_valid_url(url) -> bool:
|
reflex/components/__init__.py
CHANGED
reflex/components/base/link.py
CHANGED
reflex/components/base/script.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
https://nextjs.org/docs/app/api-reference/components/script
|
|
4
4
|
"""
|
|
5
|
-
from __future__ import annotations
|
|
6
5
|
|
|
7
|
-
from
|
|
6
|
+
from __future__ import annotations
|
|
8
7
|
|
|
9
8
|
from reflex.components.component import Component
|
|
9
|
+
from reflex.event import EventHandler
|
|
10
10
|
from reflex.vars import Var
|
|
11
11
|
|
|
12
12
|
|
|
@@ -30,6 +30,15 @@ class Script(Component):
|
|
|
30
30
|
# When the script will execute: afterInteractive | beforeInteractive | lazyOnload
|
|
31
31
|
strategy: Var[str] = "afterInteractive" # type: ignore
|
|
32
32
|
|
|
33
|
+
# Triggered when the script is loading
|
|
34
|
+
on_load: EventHandler[lambda: []]
|
|
35
|
+
|
|
36
|
+
# Triggered when the script has loaded
|
|
37
|
+
on_ready: EventHandler[lambda: []]
|
|
38
|
+
|
|
39
|
+
# Triggered when the script has errored
|
|
40
|
+
on_error: EventHandler[lambda: []]
|
|
41
|
+
|
|
33
42
|
@classmethod
|
|
34
43
|
def create(cls, *children, **props) -> Component:
|
|
35
44
|
"""Create an inline or user-defined script.
|
|
@@ -58,18 +67,5 @@ class Script(Component):
|
|
|
58
67
|
raise ValueError("Must provide inline script or `src` prop.")
|
|
59
68
|
return super().create(*children, **props)
|
|
60
69
|
|
|
61
|
-
def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
|
|
62
|
-
"""Get the event triggers for the component.
|
|
63
|
-
|
|
64
|
-
Returns:
|
|
65
|
-
The event triggers.
|
|
66
|
-
"""
|
|
67
|
-
return {
|
|
68
|
-
**super().get_event_triggers(),
|
|
69
|
-
"on_load": lambda: [],
|
|
70
|
-
"on_ready": lambda: [],
|
|
71
|
-
"on_error": lambda: [],
|
|
72
|
-
}
|
|
73
|
-
|
|
74
70
|
|
|
75
71
|
script = Script.create
|
|
@@ -7,8 +7,8 @@ from typing import Any, Dict, Literal, Optional, Union, overload
|
|
|
7
7
|
from reflex.vars import Var, BaseVar, ComputedVar
|
|
8
8
|
from reflex.event import EventChain, EventHandler, EventSpec
|
|
9
9
|
from reflex.style import Style
|
|
10
|
-
from typing import Any, Union
|
|
11
10
|
from reflex.components.component import Component
|
|
11
|
+
from reflex.event import EventHandler
|
|
12
12
|
from reflex.vars import Var
|
|
13
13
|
|
|
14
14
|
class Script(Component):
|
|
@@ -112,6 +112,5 @@ class Script(Component):
|
|
|
112
112
|
ValueError: when neither children nor `src` are specified.
|
|
113
113
|
"""
|
|
114
114
|
...
|
|
115
|
-
def get_event_triggers(self) -> dict[str, Union[Var, Any]]: ...
|
|
116
115
|
|
|
117
116
|
script = Script.create
|
reflex/components/chakra/base.py
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"""Components that are based on Chakra-UI."""
|
|
2
|
+
|
|
2
3
|
from __future__ import annotations
|
|
3
4
|
|
|
4
5
|
from functools import lru_cache
|
|
5
6
|
from typing import List, Literal
|
|
6
7
|
|
|
7
8
|
from reflex.components.component import Component
|
|
8
|
-
from reflex.utils import
|
|
9
|
+
from reflex.utils.imports import ImportDict, ImportVar
|
|
9
10
|
from reflex.vars import Var
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class ChakraComponent(Component):
|
|
13
14
|
"""A component that wraps a Chakra component."""
|
|
14
15
|
|
|
15
|
-
library = "@chakra-ui/react@2.6.1"
|
|
16
|
+
library: str = "@chakra-ui/react@2.6.1" # type: ignore
|
|
16
17
|
lib_dependencies: List[str] = [
|
|
17
18
|
"@chakra-ui/system@2.5.7",
|
|
18
19
|
"framer-motion@10.16.4",
|
|
@@ -35,14 +36,14 @@ class ChakraComponent(Component):
|
|
|
35
36
|
|
|
36
37
|
@classmethod
|
|
37
38
|
@lru_cache(maxsize=None)
|
|
38
|
-
def _get_dependencies_imports(cls) ->
|
|
39
|
+
def _get_dependencies_imports(cls) -> ImportDict:
|
|
39
40
|
"""Get the imports from lib_dependencies for installing.
|
|
40
41
|
|
|
41
42
|
Returns:
|
|
42
43
|
The dependencies imports of the component.
|
|
43
44
|
"""
|
|
44
45
|
return {
|
|
45
|
-
dep: [
|
|
46
|
+
dep: [ImportVar(tag=None, render=False)]
|
|
46
47
|
for dep in [
|
|
47
48
|
"@chakra-ui/system@2.5.7",
|
|
48
49
|
"framer-motion@10.16.4",
|
|
@@ -70,15 +71,16 @@ class ChakraProvider(ChakraComponent):
|
|
|
70
71
|
),
|
|
71
72
|
)
|
|
72
73
|
|
|
73
|
-
def
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
def add_imports(self) -> ImportDict:
|
|
75
|
+
"""Add imports for the ChakraProvider component.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
The import dict for the component.
|
|
79
|
+
"""
|
|
80
|
+
return {
|
|
81
|
+
self.library: ImportVar(tag="extendTheme", is_default=False),
|
|
82
|
+
"/utils/theme.js": ImportVar(tag="theme", is_default=True),
|
|
83
|
+
}
|
|
82
84
|
|
|
83
85
|
@staticmethod
|
|
84
86
|
@lru_cache(maxsize=None)
|
|
@@ -10,7 +10,7 @@ from reflex.style import Style
|
|
|
10
10
|
from functools import lru_cache
|
|
11
11
|
from typing import List, Literal
|
|
12
12
|
from reflex.components.component import Component
|
|
13
|
-
from reflex.utils import
|
|
13
|
+
from reflex.utils.imports import ImportDict, ImportVar
|
|
14
14
|
from reflex.vars import Var
|
|
15
15
|
|
|
16
16
|
class ChakraComponent(Component):
|
|
@@ -156,6 +156,8 @@ class ChakraProvider(ChakraComponent):
|
|
|
156
156
|
"""
|
|
157
157
|
...
|
|
158
158
|
|
|
159
|
+
def add_imports(self) -> ImportDict: ...
|
|
160
|
+
|
|
159
161
|
chakra_provider = ChakraProvider.create()
|
|
160
162
|
|
|
161
163
|
class ChakraColorModeProvider(Component):
|
|
@@ -184,6 +184,7 @@ class Thead(ChakraComponent):
|
|
|
184
184
|
|
|
185
185
|
"""
|
|
186
186
|
...
|
|
187
|
+
|
|
187
188
|
@staticmethod
|
|
188
189
|
def validate_headers(headers): ...
|
|
189
190
|
|
|
@@ -264,6 +265,7 @@ class Tbody(ChakraComponent):
|
|
|
264
265
|
Component: The table body component
|
|
265
266
|
"""
|
|
266
267
|
...
|
|
268
|
+
|
|
267
269
|
@staticmethod
|
|
268
270
|
def validate_rows(rows): ...
|
|
269
271
|
|
|
@@ -344,6 +346,7 @@ class Tfoot(ChakraComponent):
|
|
|
344
346
|
The table footer component.
|
|
345
347
|
"""
|
|
346
348
|
...
|
|
349
|
+
|
|
347
350
|
@staticmethod
|
|
348
351
|
def validate_footers(footers): ...
|
|
349
352
|
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"""A checkbox component."""
|
|
2
|
-
from __future__ import annotations
|
|
3
2
|
|
|
4
|
-
from
|
|
3
|
+
from __future__ import annotations
|
|
5
4
|
|
|
6
5
|
from reflex.components.chakra import (
|
|
7
6
|
ChakraComponent,
|
|
8
7
|
LiteralColorScheme,
|
|
9
8
|
LiteralTagSize,
|
|
10
9
|
)
|
|
11
|
-
from reflex.
|
|
10
|
+
from reflex.event import EventHandler
|
|
12
11
|
from reflex.vars import Var
|
|
13
12
|
|
|
14
13
|
|
|
@@ -56,16 +55,8 @@ class Checkbox(ChakraComponent):
|
|
|
56
55
|
# The spacing between the checkbox and its label text (0.5rem)
|
|
57
56
|
spacing: Var[str]
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
Returns:
|
|
63
|
-
A dict mapping the event trigger to the var that is passed to the handler.
|
|
64
|
-
"""
|
|
65
|
-
return {
|
|
66
|
-
**super().get_event_triggers(),
|
|
67
|
-
EventTriggers.ON_CHANGE: lambda e0: [e0.target.checked],
|
|
68
|
-
}
|
|
58
|
+
# Fired when the checkbox is checked or unchecked
|
|
59
|
+
on_change: EventHandler[lambda e0: [e0.target.checked]]
|
|
69
60
|
|
|
70
61
|
|
|
71
62
|
class CheckboxGroup(ChakraComponent):
|
|
@@ -7,13 +7,11 @@ from typing import Any, Dict, Literal, Optional, Union, overload
|
|
|
7
7
|
from reflex.vars import Var, BaseVar, ComputedVar
|
|
8
8
|
from reflex.event import EventChain, EventHandler, EventSpec
|
|
9
9
|
from reflex.style import Style
|
|
10
|
-
from typing import Any, Union
|
|
11
10
|
from reflex.components.chakra import ChakraComponent, LiteralColorScheme, LiteralTagSize
|
|
12
|
-
from reflex.
|
|
11
|
+
from reflex.event import EventHandler
|
|
13
12
|
from reflex.vars import Var
|
|
14
13
|
|
|
15
14
|
class Checkbox(ChakraComponent):
|
|
16
|
-
def get_event_triggers(self) -> dict[str, Union[Var, Any]]: ...
|
|
17
15
|
@overload
|
|
18
16
|
@classmethod
|
|
19
17
|
def create( # type: ignore
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"""An editable component."""
|
|
2
|
-
from __future__ import annotations
|
|
3
2
|
|
|
4
|
-
from
|
|
3
|
+
from __future__ import annotations
|
|
5
4
|
|
|
6
5
|
from reflex.components.chakra import ChakraComponent
|
|
7
|
-
from reflex.
|
|
6
|
+
from reflex.event import EventHandler
|
|
8
7
|
from reflex.vars import Var
|
|
9
8
|
|
|
10
9
|
|
|
@@ -37,19 +36,17 @@ class Editable(ChakraComponent):
|
|
|
37
36
|
# The initial value of the Editable in both edit and preview mode.
|
|
38
37
|
default_value: Var[str]
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
EventTriggers.ON_CANCEL: lambda e0: [e0],
|
|
52
|
-
}
|
|
39
|
+
# Fired when the Editable is changed.
|
|
40
|
+
on_change: EventHandler[lambda e0: [e0]]
|
|
41
|
+
|
|
42
|
+
# Fired when the Editable is in edit mode.
|
|
43
|
+
on_edit: EventHandler[lambda e0: [e0]]
|
|
44
|
+
|
|
45
|
+
# Fired when the Editable is submitted.
|
|
46
|
+
on_submit: EventHandler[lambda e0: [e0]]
|
|
47
|
+
|
|
48
|
+
# Fired when the Editable is canceled.
|
|
49
|
+
on_cancel: EventHandler[lambda e0: [e0]]
|
|
53
50
|
|
|
54
51
|
|
|
55
52
|
class EditableInput(ChakraComponent):
|
|
@@ -7,13 +7,11 @@ from typing import Any, Dict, Literal, Optional, Union, overload
|
|
|
7
7
|
from reflex.vars import Var, BaseVar, ComputedVar
|
|
8
8
|
from reflex.event import EventChain, EventHandler, EventSpec
|
|
9
9
|
from reflex.style import Style
|
|
10
|
-
from typing import Any, Union
|
|
11
10
|
from reflex.components.chakra import ChakraComponent
|
|
12
|
-
from reflex.
|
|
11
|
+
from reflex.event import EventHandler
|
|
13
12
|
from reflex.vars import Var
|
|
14
13
|
|
|
15
14
|
class Editable(ChakraComponent):
|
|
16
|
-
def get_event_triggers(self) -> dict[str, Union[Var, Any]]: ...
|
|
17
15
|
@overload
|
|
18
16
|
@classmethod
|
|
19
17
|
def create( # type: ignore
|