reflex 0.8.8a2__py3-none-any.whl → 0.8.9a2__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/app.py +15 -5
- reflex/compiler/templates.py +19 -3
- reflex/compiler/utils.py +7 -4
- reflex/components/component.py +68 -79
- reflex/components/core/sticky.pyi +3 -0
- reflex/components/el/elements/media.py +518 -0
- reflex/components/el/elements/media.pyi +5869 -5
- reflex/components/lucide/icon.py +3 -0
- reflex/components/lucide/icon.pyi +3 -0
- reflex/components/radix/primitives/drawer.pyi +4 -0
- reflex/config.py +34 -7
- reflex/constants/installer.py +4 -4
- reflex/environment.py +8 -3
- reflex/istate/data.py +15 -0
- reflex/plugins/sitemap.py +3 -6
- reflex/reflex.py +8 -2
- reflex/state.py +46 -6
- reflex/testing.py +1 -1
- reflex/utils/console.py +67 -7
- reflex/utils/frontend_skeleton.py +6 -1
- reflex/utils/imports.py +1 -1
- reflex/utils/prerequisites.py +3 -1
- reflex/utils/pyi_generator.py +2 -2
- reflex/utils/serializers.py +4 -4
- reflex/utils/types.py +11 -10
- reflex/vars/base.py +24 -17
- reflex/vars/object.py +4 -2
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a2.dist-info}/METADATA +1 -1
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a2.dist-info}/RECORD +32 -32
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a2.dist-info}/WHEEL +0 -0
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a2.dist-info}/entry_points.txt +0 -0
- {reflex-0.8.8a2.dist-info → reflex-0.8.9a2.dist-info}/licenses/LICENSE +0 -0
reflex/app.py
CHANGED
|
@@ -1100,12 +1100,18 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1100
1100
|
for substate in state.class_subclasses:
|
|
1101
1101
|
self._validate_var_dependencies(substate)
|
|
1102
1102
|
|
|
1103
|
-
def _compile(
|
|
1103
|
+
def _compile(
|
|
1104
|
+
self,
|
|
1105
|
+
prerender_routes: bool = False,
|
|
1106
|
+
dry_run: bool = False,
|
|
1107
|
+
use_rich: bool = True,
|
|
1108
|
+
):
|
|
1104
1109
|
"""Compile the app and output it to the pages folder.
|
|
1105
1110
|
|
|
1106
1111
|
Args:
|
|
1107
1112
|
prerender_routes: Whether to prerender the routes.
|
|
1108
1113
|
dry_run: Whether to compile the app without saving it.
|
|
1114
|
+
use_rich: Whether to use rich progress bars.
|
|
1109
1115
|
|
|
1110
1116
|
Raises:
|
|
1111
1117
|
ReflexRuntimeError: When any page uses state, but no rx.State subclass is defined.
|
|
@@ -1171,10 +1177,14 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1171
1177
|
return
|
|
1172
1178
|
|
|
1173
1179
|
# Create a progress bar.
|
|
1174
|
-
progress =
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1180
|
+
progress = (
|
|
1181
|
+
Progress(
|
|
1182
|
+
*Progress.get_default_columns()[:-1],
|
|
1183
|
+
MofNCompleteColumn(),
|
|
1184
|
+
TimeElapsedColumn(),
|
|
1185
|
+
)
|
|
1186
|
+
if use_rich
|
|
1187
|
+
else console.PoorProgress()
|
|
1178
1188
|
)
|
|
1179
1189
|
|
|
1180
1190
|
# try to be somewhat accurate - but still not 100%
|
reflex/compiler/templates.py
CHANGED
|
@@ -362,7 +362,7 @@ export const UploadFilesContext = createContext(null);
|
|
|
362
362
|
export const DispatchContext = createContext(null);
|
|
363
363
|
export const StateContexts = {{{state_contexts_str}}};
|
|
364
364
|
export const EventLoopContext = createContext(null);
|
|
365
|
-
export const clientStorage = {"{}" if client_storage is None else
|
|
365
|
+
export const clientStorage = {"{}" if client_storage is None else json.dumps(client_storage)}
|
|
366
366
|
|
|
367
367
|
{state_str}
|
|
368
368
|
|
|
@@ -502,11 +502,13 @@ def package_json_template(
|
|
|
502
502
|
)
|
|
503
503
|
|
|
504
504
|
|
|
505
|
-
def vite_config_template(base: str):
|
|
505
|
+
def vite_config_template(base: str, hmr: bool, force_full_reload: bool):
|
|
506
506
|
"""Template for vite.config.js.
|
|
507
507
|
|
|
508
508
|
Args:
|
|
509
509
|
base: The base path for the Vite config.
|
|
510
|
+
hmr: Whether to enable hot module replacement.
|
|
511
|
+
force_full_reload: Whether to force a full reload on changes.
|
|
510
512
|
|
|
511
513
|
Returns:
|
|
512
514
|
Rendered vite.config.js content as string.
|
|
@@ -537,12 +539,25 @@ function alwaysUseReactDomServerNode() {{
|
|
|
537
539
|
}};
|
|
538
540
|
}}
|
|
539
541
|
|
|
542
|
+
function fullReload() {{
|
|
543
|
+
return {{
|
|
544
|
+
name: "full-reload",
|
|
545
|
+
enforce: "pre",
|
|
546
|
+
handleHotUpdate({{ server }}) {{
|
|
547
|
+
server.ws.send({{
|
|
548
|
+
type: "full-reload",
|
|
549
|
+
}});
|
|
550
|
+
return [];
|
|
551
|
+
}}
|
|
552
|
+
}};
|
|
553
|
+
}}
|
|
554
|
+
|
|
540
555
|
export default defineConfig((config) => ({{
|
|
541
556
|
plugins: [
|
|
542
557
|
alwaysUseReactDomServerNode(),
|
|
543
558
|
reactRouter(),
|
|
544
559
|
safariCacheBustPlugin(),
|
|
545
|
-
],
|
|
560
|
+
].concat({"[fullReload()]" if force_full_reload else "[]"}),
|
|
546
561
|
build: {{
|
|
547
562
|
assetsDir: "{base}assets".slice(1),
|
|
548
563
|
rollupOptions: {{
|
|
@@ -564,6 +579,7 @@ export default defineConfig((config) => ({{
|
|
|
564
579
|
}},
|
|
565
580
|
server: {{
|
|
566
581
|
port: process.env.PORT,
|
|
582
|
+
hmr: {"true" if hmr else "false"},
|
|
567
583
|
watch: {{
|
|
568
584
|
ignored: [
|
|
569
585
|
"**/.web/backend/**",
|
reflex/compiler/utils.py
CHANGED
|
@@ -220,10 +220,13 @@ def compile_state(state: type[BaseState]) -> dict:
|
|
|
220
220
|
|
|
221
221
|
def _compile_client_storage_field(
|
|
222
222
|
field: Field,
|
|
223
|
-
) ->
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
]
|
|
223
|
+
) -> (
|
|
224
|
+
tuple[
|
|
225
|
+
type[Cookie] | type[LocalStorage] | type[SessionStorage],
|
|
226
|
+
dict[str, Any],
|
|
227
|
+
]
|
|
228
|
+
| tuple[None, None]
|
|
229
|
+
):
|
|
227
230
|
"""Compile the given cookie, local_storage or session_storage field.
|
|
228
231
|
|
|
229
232
|
Args:
|
reflex/components/component.py
CHANGED
|
@@ -419,7 +419,6 @@ def evaluate_style_namespaces(style: ComponentStyle) -> dict:
|
|
|
419
419
|
|
|
420
420
|
# Map from component to styling.
|
|
421
421
|
ComponentStyle = dict[str | type[BaseComponent] | Callable | ComponentNamespace, Any]
|
|
422
|
-
ComponentChild = types.PrimitiveType | Var | BaseComponent
|
|
423
422
|
ComponentChildTypes = (*types.PrimitiveTypes, Var, BaseComponent, type(None))
|
|
424
423
|
|
|
425
424
|
|
|
@@ -480,7 +479,21 @@ def _components_from(
|
|
|
480
479
|
return ()
|
|
481
480
|
|
|
482
481
|
|
|
483
|
-
def
|
|
482
|
+
def _hash_str(value: str) -> str:
|
|
483
|
+
return md5(f'"{value}"'.encode(), usedforsecurity=False).hexdigest()
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _hash_sequence(value: Sequence) -> str:
|
|
487
|
+
return _hash_str(str([_deterministic_hash(v) for v in value]))
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _hash_dict(value: dict) -> str:
|
|
491
|
+
return _hash_sequence(
|
|
492
|
+
sorted([(k, _deterministic_hash(v)) for k, v in value.items()])
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def _deterministic_hash(value: object) -> str:
|
|
484
497
|
"""Hash a rendered dictionary.
|
|
485
498
|
|
|
486
499
|
Args:
|
|
@@ -492,37 +505,28 @@ def _deterministic_hash(value: object) -> int:
|
|
|
492
505
|
Raises:
|
|
493
506
|
TypeError: If the value is not hashable.
|
|
494
507
|
"""
|
|
495
|
-
if
|
|
496
|
-
#
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if isinstance(value, Var):
|
|
500
|
-
return _deterministic_hash((value._js_expr, value._get_all_var_data()))
|
|
501
|
-
if isinstance(value, VarData):
|
|
502
|
-
return _deterministic_hash(dataclasses.asdict(value))
|
|
503
|
-
if isinstance(value, dict):
|
|
504
|
-
# Sort the dictionary to ensure consistent hashing.
|
|
505
|
-
return _deterministic_hash(
|
|
506
|
-
tuple(sorted((k, _deterministic_hash(v)) for k, v in value.items()))
|
|
507
|
-
)
|
|
508
|
-
if isinstance(value, int):
|
|
508
|
+
if value is None:
|
|
509
|
+
# Hash None as a special case.
|
|
510
|
+
return "None"
|
|
511
|
+
if isinstance(value, (int, float, enum.Enum)):
|
|
509
512
|
# Hash numbers and booleans directly.
|
|
510
|
-
return
|
|
511
|
-
if isinstance(value, float):
|
|
512
|
-
return _deterministic_hash(str(value))
|
|
513
|
+
return str(value)
|
|
513
514
|
if isinstance(value, str):
|
|
514
|
-
return
|
|
515
|
+
return _hash_str(value)
|
|
516
|
+
if isinstance(value, dict):
|
|
517
|
+
return _hash_dict(value)
|
|
515
518
|
if isinstance(value, (tuple, list)):
|
|
516
519
|
# Hash tuples by hashing each element.
|
|
517
|
-
return
|
|
518
|
-
|
|
520
|
+
return _hash_sequence(value)
|
|
521
|
+
if isinstance(value, Var):
|
|
522
|
+
return _hash_str(
|
|
523
|
+
str((value._js_expr, _deterministic_hash(value._get_all_var_data())))
|
|
519
524
|
)
|
|
520
|
-
if isinstance(value,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return _deterministic_hash("None")
|
|
525
|
+
if isinstance(value, VarData):
|
|
526
|
+
return _hash_dict(dataclasses.asdict(value))
|
|
527
|
+
if isinstance(value, BaseComponent):
|
|
528
|
+
# If the value is a component, hash its rendered code.
|
|
529
|
+
return _hash_dict(value.render())
|
|
526
530
|
|
|
527
531
|
msg = (
|
|
528
532
|
f"Cannot hash value `{value}` of type `{type(value).__name__}`. "
|
|
@@ -1017,44 +1021,8 @@ class Component(BaseComponent, ABC):
|
|
|
1017
1021
|
"""
|
|
1018
1022
|
return set()
|
|
1019
1023
|
|
|
1020
|
-
@
|
|
1021
|
-
def
|
|
1022
|
-
"""Check if all fields are known at compile time. True for most components.
|
|
1023
|
-
|
|
1024
|
-
Returns:
|
|
1025
|
-
Whether all fields are known at compile time.
|
|
1026
|
-
"""
|
|
1027
|
-
return True
|
|
1028
|
-
|
|
1029
|
-
@classmethod
|
|
1030
|
-
@functools.cache
|
|
1031
|
-
def _get_component_prop_names(cls) -> set[str]:
|
|
1032
|
-
"""Get the names of the component props. NOTE: This assumes all fields are known.
|
|
1033
|
-
|
|
1034
|
-
Returns:
|
|
1035
|
-
The names of the component props.
|
|
1036
|
-
"""
|
|
1037
|
-
return {
|
|
1038
|
-
name
|
|
1039
|
-
for name in cls.get_fields()
|
|
1040
|
-
if name in cls.get_props()
|
|
1041
|
-
and types._issubclass(
|
|
1042
|
-
types.value_inside_optional(types.get_field_type(cls, name)), Component
|
|
1043
|
-
)
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
def _get_components_in_props(self) -> Sequence[BaseComponent]:
|
|
1047
|
-
"""Get the components in the props.
|
|
1048
|
-
|
|
1049
|
-
Returns:
|
|
1050
|
-
The components in the props
|
|
1051
|
-
"""
|
|
1052
|
-
if self._are_fields_known():
|
|
1053
|
-
return [
|
|
1054
|
-
component
|
|
1055
|
-
for name in self._get_component_prop_names()
|
|
1056
|
-
for component in _components_from(getattr(self, name))
|
|
1057
|
-
]
|
|
1024
|
+
@functools.cached_property
|
|
1025
|
+
def _get_component_prop_property(self) -> Sequence[BaseComponent]:
|
|
1058
1026
|
return [
|
|
1059
1027
|
component
|
|
1060
1028
|
for prop in self.get_props()
|
|
@@ -1063,6 +1031,14 @@ class Component(BaseComponent, ABC):
|
|
|
1063
1031
|
for component in _components_from(value)
|
|
1064
1032
|
]
|
|
1065
1033
|
|
|
1034
|
+
def _get_components_in_props(self) -> Sequence[BaseComponent]:
|
|
1035
|
+
"""Get the components in the props.
|
|
1036
|
+
|
|
1037
|
+
Returns:
|
|
1038
|
+
The components in the props
|
|
1039
|
+
"""
|
|
1040
|
+
return self._get_component_prop_property
|
|
1041
|
+
|
|
1066
1042
|
@classmethod
|
|
1067
1043
|
def _validate_children(cls, children: tuple | list):
|
|
1068
1044
|
from reflex.utils.exceptions import ChildrenTypeError
|
|
@@ -1508,8 +1484,9 @@ class Component(BaseComponent, ABC):
|
|
|
1508
1484
|
Returns:
|
|
1509
1485
|
A sequence of parent classes that define the method (differently than the base).
|
|
1510
1486
|
"""
|
|
1487
|
+
current_class_method = getattr(Component, method, None)
|
|
1511
1488
|
seen_methods = (
|
|
1512
|
-
{
|
|
1489
|
+
{current_class_method} if current_class_method is not None else set()
|
|
1513
1490
|
)
|
|
1514
1491
|
clzs: list[type[Component]] = []
|
|
1515
1492
|
for clz in cls.mro():
|
|
@@ -1807,7 +1784,7 @@ class Component(BaseComponent, ABC):
|
|
|
1807
1784
|
|
|
1808
1785
|
# Add the hook code from add_hooks for each parent class (this is reversed to preserve
|
|
1809
1786
|
# the order of the hooks in the final output)
|
|
1810
|
-
for clz in reversed(
|
|
1787
|
+
for clz in reversed(self._iter_parent_classes_with_method("add_hooks")):
|
|
1811
1788
|
for hook in clz.add_hooks(self):
|
|
1812
1789
|
if isinstance(hook, Var):
|
|
1813
1790
|
extract_var_hooks(hook)
|
|
@@ -2051,15 +2028,6 @@ class CustomComponent(Component):
|
|
|
2051
2028
|
self.props[camel_cased_key] = value
|
|
2052
2029
|
setattr(self, camel_cased_key, value)
|
|
2053
2030
|
|
|
2054
|
-
@classmethod
|
|
2055
|
-
def _are_fields_known(cls) -> bool:
|
|
2056
|
-
"""Check if the fields are known.
|
|
2057
|
-
|
|
2058
|
-
Returns:
|
|
2059
|
-
Whether the fields are known.
|
|
2060
|
-
"""
|
|
2061
|
-
return False
|
|
2062
|
-
|
|
2063
2031
|
def __eq__(self, other: Any) -> bool:
|
|
2064
2032
|
"""Check if the component is equal to another.
|
|
2065
2033
|
|
|
@@ -2190,6 +2158,9 @@ def _register_custom_component(
|
|
|
2190
2158
|
Args:
|
|
2191
2159
|
component_fn: The function that creates the component.
|
|
2192
2160
|
|
|
2161
|
+
Returns:
|
|
2162
|
+
The custom component.
|
|
2163
|
+
|
|
2193
2164
|
Raises:
|
|
2194
2165
|
TypeError: If the tag name cannot be determined.
|
|
2195
2166
|
"""
|
|
@@ -2214,6 +2185,7 @@ def _register_custom_component(
|
|
|
2214
2185
|
msg = f"Could not determine the tag name for {component_fn!r}"
|
|
2215
2186
|
raise TypeError(msg)
|
|
2216
2187
|
CUSTOM_COMPONENTS[dummy_component.tag] = dummy_component
|
|
2188
|
+
return dummy_component
|
|
2217
2189
|
|
|
2218
2190
|
|
|
2219
2191
|
def custom_component(
|
|
@@ -2237,7 +2209,24 @@ def custom_component(
|
|
|
2237
2209
|
)
|
|
2238
2210
|
|
|
2239
2211
|
# Register this component so it can be compiled.
|
|
2240
|
-
_register_custom_component(component_fn)
|
|
2212
|
+
dummy_component = _register_custom_component(component_fn)
|
|
2213
|
+
if tag := dummy_component.tag:
|
|
2214
|
+
object.__setattr__(
|
|
2215
|
+
wrapper,
|
|
2216
|
+
"_as_var",
|
|
2217
|
+
lambda: Var(
|
|
2218
|
+
tag,
|
|
2219
|
+
_var_type=type[Component],
|
|
2220
|
+
_var_data=VarData(
|
|
2221
|
+
imports={
|
|
2222
|
+
f"$/{constants.Dirs.UTILS}/components": [ImportVar(tag=tag)],
|
|
2223
|
+
"@emotion/react": [
|
|
2224
|
+
ImportVar(tag="jsx"),
|
|
2225
|
+
],
|
|
2226
|
+
}
|
|
2227
|
+
),
|
|
2228
|
+
),
|
|
2229
|
+
)
|
|
2241
2230
|
|
|
2242
2231
|
return wrapper
|
|
2243
2232
|
|
|
@@ -2457,7 +2446,7 @@ class StatefulComponent(BaseComponent):
|
|
|
2457
2446
|
return None
|
|
2458
2447
|
|
|
2459
2448
|
# Compute the hash based on the rendered code.
|
|
2460
|
-
code_hash = _deterministic_hash(rendered_code)
|
|
2449
|
+
code_hash = _hash_str(_deterministic_hash(rendered_code))
|
|
2461
2450
|
|
|
2462
2451
|
# Format the tag name including the hash.
|
|
2463
2452
|
return format.format_state_name(
|
|
@@ -22,6 +22,9 @@ class StickyLogo(Svg):
|
|
|
22
22
|
width: Var[int | str] | int | str | None = None,
|
|
23
23
|
height: Var[int | str] | int | str | None = None,
|
|
24
24
|
xmlns: Var[str] | str | None = None,
|
|
25
|
+
view_box: Var[str] | str | None = None,
|
|
26
|
+
preserve_aspect_ratio: Var[str] | str | None = None,
|
|
27
|
+
transform: Var[str] | str | None = None,
|
|
25
28
|
access_key: Var[str] | str | None = None,
|
|
26
29
|
auto_capitalize: Literal[
|
|
27
30
|
"characters", "none", "off", "on", "sentences", "words"
|