reflex 0.6.6.post2__py3-none-any.whl → 0.6.7__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/stateful_component.js.jinja2 +5 -1
- reflex/.templates/web/utils/state.js +36 -28
- reflex/__init__.py +1 -1
- reflex/__init__.pyi +1 -0
- reflex/app.py +41 -16
- reflex/assets.py +2 -2
- reflex/base.py +8 -7
- reflex/compiler/templates.py +1 -0
- reflex/compiler/utils.py +2 -3
- reflex/components/base/bare.py +2 -2
- reflex/components/component.py +54 -29
- reflex/components/core/banner.py +2 -2
- reflex/components/core/banner.pyi +1 -1
- reflex/components/core/client_side_routing.py +2 -2
- reflex/components/core/client_side_routing.pyi +1 -1
- reflex/components/core/clipboard.py +11 -9
- reflex/components/core/clipboard.pyi +1 -1
- reflex/components/core/cond.py +3 -3
- reflex/components/core/foreach.py +1 -1
- reflex/components/core/html.pyi +1 -1
- reflex/components/core/upload.py +8 -8
- reflex/components/datadisplay/code.py +5 -5
- reflex/components/datadisplay/dataeditor.py +8 -28
- reflex/components/datadisplay/dataeditor.pyi +1 -1
- reflex/components/datadisplay/shiki_code_block.py +7 -7
- reflex/components/dynamic.py +2 -2
- reflex/components/el/elements/__init__.py +1 -1
- reflex/components/el/elements/__init__.pyi +1 -1
- reflex/components/el/elements/base.py +2 -2
- reflex/components/el/elements/base.pyi +1 -1
- reflex/components/el/elements/forms.py +40 -10
- reflex/components/el/elements/forms.pyi +17 -15
- reflex/components/el/elements/inline.py +1 -1
- reflex/components/el/elements/inline.pyi +28 -28
- reflex/components/el/elements/media.py +1 -4
- reflex/components/el/elements/media.pyi +25 -26
- reflex/components/el/elements/metadata.py +6 -6
- reflex/components/el/elements/metadata.pyi +4 -4
- reflex/components/el/elements/other.py +17 -9
- reflex/components/el/elements/other.pyi +7 -7
- reflex/components/el/elements/scripts.py +1 -2
- reflex/components/el/elements/scripts.pyi +3 -3
- reflex/components/el/elements/sectioning.py +16 -16
- reflex/components/el/elements/sectioning.pyi +15 -15
- reflex/components/el/elements/tables.py +1 -1
- reflex/components/el/elements/tables.pyi +10 -10
- reflex/components/el/elements/typography.py +1 -1
- reflex/components/el/elements/typography.pyi +15 -15
- reflex/components/markdown/markdown.py +3 -3
- reflex/components/next/image.py +1 -1
- reflex/components/next/image.pyi +1 -1
- reflex/components/plotly/plotly.py +2 -2
- reflex/components/radix/primitives/accordion.py +2 -1
- reflex/components/radix/primitives/form.pyi +3 -3
- reflex/components/radix/primitives/slider.py +1 -1
- reflex/components/radix/themes/base.py +4 -10
- reflex/components/radix/themes/color_mode.pyi +2 -2
- reflex/components/radix/themes/components/alert_dialog.pyi +1 -1
- reflex/components/radix/themes/components/badge.pyi +1 -1
- reflex/components/radix/themes/components/button.pyi +1 -1
- reflex/components/radix/themes/components/callout.pyi +5 -5
- reflex/components/radix/themes/components/card.pyi +1 -1
- reflex/components/radix/themes/components/checkbox.pyi +3 -3
- reflex/components/radix/themes/components/context_menu.py +11 -0
- reflex/components/radix/themes/components/context_menu.pyi +155 -0
- reflex/components/radix/themes/components/dialog.pyi +1 -1
- reflex/components/radix/themes/components/hover_card.pyi +1 -1
- reflex/components/radix/themes/components/icon_button.py +1 -1
- reflex/components/radix/themes/components/icon_button.pyi +1 -1
- reflex/components/radix/themes/components/inset.pyi +1 -1
- reflex/components/radix/themes/components/popover.pyi +1 -1
- reflex/components/radix/themes/components/radio_group.py +2 -4
- reflex/components/radix/themes/components/radio_group.pyi +1 -1
- reflex/components/radix/themes/components/select.pyi +3 -3
- reflex/components/radix/themes/components/slider.pyi +1 -1
- reflex/components/radix/themes/components/switch.pyi +1 -1
- reflex/components/radix/themes/components/table.pyi +7 -7
- reflex/components/radix/themes/components/tabs.pyi +2 -2
- reflex/components/radix/themes/components/text_area.py +3 -0
- reflex/components/radix/themes/components/text_area.pyi +3 -1
- reflex/components/radix/themes/components/text_field.py +16 -1
- reflex/components/radix/themes/components/text_field.pyi +105 -17
- reflex/components/radix/themes/layout/box.pyi +1 -1
- reflex/components/radix/themes/layout/center.pyi +1 -1
- reflex/components/radix/themes/layout/flex.pyi +1 -1
- reflex/components/radix/themes/layout/grid.pyi +1 -1
- reflex/components/radix/themes/layout/list.py +0 -4
- reflex/components/radix/themes/layout/list.pyi +3 -8
- reflex/components/radix/themes/layout/section.pyi +1 -1
- reflex/components/radix/themes/layout/spacer.pyi +1 -1
- reflex/components/radix/themes/layout/stack.pyi +3 -3
- reflex/components/radix/themes/typography/blockquote.pyi +1 -1
- reflex/components/radix/themes/typography/code.pyi +1 -1
- reflex/components/radix/themes/typography/heading.pyi +1 -1
- reflex/components/radix/themes/typography/link.py +5 -1
- reflex/components/radix/themes/typography/link.pyi +1 -1
- reflex/components/radix/themes/typography/text.pyi +7 -7
- reflex/components/recharts/cartesian.py +1 -1
- reflex/components/recharts/charts.py +4 -4
- reflex/components/recharts/polar.py +1 -1
- reflex/components/recharts/polar.pyi +1 -1
- reflex/components/sonner/toast.py +4 -7
- reflex/components/suneditor/editor.py +6 -6
- reflex/components/suneditor/editor.pyi +6 -6
- reflex/config.py +25 -10
- reflex/constants/compiler.py +6 -0
- reflex/constants/config.py +2 -0
- reflex/constants/custom_components.py +1 -1
- reflex/constants/route.py +1 -1
- reflex/custom_components/custom_components.py +21 -21
- reflex/event.py +57 -22
- reflex/experimental/client_state.py +2 -1
- reflex/experimental/layout.py +0 -6
- reflex/model.py +125 -9
- reflex/reflex.py +12 -8
- reflex/state.py +200 -88
- reflex/style.py +1 -4
- reflex/testing.py +10 -11
- reflex/utils/build.py +1 -1
- reflex/utils/console.py +75 -6
- reflex/utils/exceptions.py +12 -0
- reflex/utils/exec.py +10 -10
- reflex/utils/export.py +1 -2
- reflex/utils/format.py +11 -8
- reflex/utils/path_ops.py +2 -2
- reflex/utils/prerequisites.py +31 -28
- reflex/utils/processes.py +4 -4
- reflex/utils/pyi_generator.py +12 -11
- reflex/utils/types.py +6 -3
- reflex/vars/__init__.py +1 -0
- reflex/vars/base.py +75 -38
- reflex/vars/datetime.py +222 -0
- reflex/vars/function.py +3 -3
- reflex/vars/number.py +3 -3
- reflex/vars/object.py +5 -5
- reflex/vars/sequence.py +7 -7
- {reflex-0.6.6.post2.dist-info → reflex-0.6.7.dist-info}/METADATA +2 -2
- {reflex-0.6.6.post2.dist-info → reflex-0.6.7.dist-info}/RECORD +141 -140
- {reflex-0.6.6.post2.dist-info → reflex-0.6.7.dist-info}/LICENSE +0 -0
- {reflex-0.6.6.post2.dist-info → reflex-0.6.7.dist-info}/WHEEL +0 -0
- {reflex-0.6.6.post2.dist-info → reflex-0.6.7.dist-info}/entry_points.txt +0 -0
|
@@ -6,11 +6,12 @@ from typing import Dict, List, Tuple, Union
|
|
|
6
6
|
|
|
7
7
|
from reflex.components.base.fragment import Fragment
|
|
8
8
|
from reflex.components.tags.tag import Tag
|
|
9
|
+
from reflex.constants.compiler import Hooks
|
|
9
10
|
from reflex.event import EventChain, EventHandler, passthrough_event_spec
|
|
10
11
|
from reflex.utils.format import format_prop, wrap
|
|
11
12
|
from reflex.utils.imports import ImportVar
|
|
12
13
|
from reflex.vars import get_unique_variable_name
|
|
13
|
-
from reflex.vars.base import Var
|
|
14
|
+
from reflex.vars.base import Var, VarData
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class Clipboard(Fragment):
|
|
@@ -51,7 +52,7 @@ class Clipboard(Fragment):
|
|
|
51
52
|
return super().create(*children, **props)
|
|
52
53
|
|
|
53
54
|
def _exclude_props(self) -> list[str]:
|
|
54
|
-
return super()._exclude_props()
|
|
55
|
+
return [*super()._exclude_props(), "on_paste", "on_paste_event_actions"]
|
|
55
56
|
|
|
56
57
|
def _render(self) -> Tag:
|
|
57
58
|
tag = super()._render()
|
|
@@ -72,7 +73,7 @@ class Clipboard(Fragment):
|
|
|
72
73
|
),
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
def add_hooks(self) -> list[str]:
|
|
76
|
+
def add_hooks(self) -> list[str | Var[str]]:
|
|
76
77
|
"""Add hook to register paste event listener.
|
|
77
78
|
|
|
78
79
|
Returns:
|
|
@@ -83,13 +84,14 @@ class Clipboard(Fragment):
|
|
|
83
84
|
return []
|
|
84
85
|
if isinstance(on_paste, EventChain):
|
|
85
86
|
on_paste = wrap(str(format_prop(on_paste)).strip("{}"), "(")
|
|
87
|
+
hook_expr = f"usePasteHandler({self.targets!s}, {self.on_paste_event_actions!s}, {on_paste!s})"
|
|
88
|
+
|
|
86
89
|
return [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
str
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
90
|
+
Var(
|
|
91
|
+
hook_expr,
|
|
92
|
+
_var_type="str",
|
|
93
|
+
_var_data=VarData(position=Hooks.HookPosition.POST_TRIGGER),
|
|
94
|
+
),
|
|
93
95
|
]
|
|
94
96
|
|
|
95
97
|
|
reflex/components/core/cond.py
CHANGED
|
@@ -49,9 +49,9 @@ class Cond(MemoizationLeaf):
|
|
|
49
49
|
The conditional component.
|
|
50
50
|
"""
|
|
51
51
|
# Wrap everything in fragments.
|
|
52
|
-
if comp1.
|
|
52
|
+
if type(comp1).__name__ != "Fragment":
|
|
53
53
|
comp1 = Fragment.create(comp1)
|
|
54
|
-
if comp2 is None or comp2.
|
|
54
|
+
if comp2 is None or type(comp2).__name__ != "Fragment":
|
|
55
55
|
comp2 = Fragment.create(comp2) if comp2 else Fragment.create()
|
|
56
56
|
return Fragment.create(
|
|
57
57
|
cls(
|
|
@@ -94,7 +94,7 @@ class Cond(MemoizationLeaf):
|
|
|
94
94
|
).set(
|
|
95
95
|
props=tag.format_props(),
|
|
96
96
|
),
|
|
97
|
-
cond_state=f"isTrue({
|
|
97
|
+
cond_state=f"isTrue({self.cond!s})",
|
|
98
98
|
)
|
|
99
99
|
|
|
100
100
|
def add_imports(self) -> ImportDict:
|
|
@@ -54,7 +54,7 @@ class Foreach(Component):
|
|
|
54
54
|
iterable = LiteralVar.create(iterable)
|
|
55
55
|
if iterable._var_type == Any:
|
|
56
56
|
raise ForeachVarError(
|
|
57
|
-
f"Could not foreach over var `{
|
|
57
|
+
f"Could not foreach over var `{iterable!s}` of type Any. "
|
|
58
58
|
"(If you are trying to foreach over a state var, add a type annotation to the var). "
|
|
59
59
|
"See https://reflex.dev/docs/library/dynamic-rendering/foreach/"
|
|
60
60
|
)
|
reflex/components/core/html.pyi
CHANGED
|
@@ -71,7 +71,7 @@ class Html(Div):
|
|
|
71
71
|
Args:
|
|
72
72
|
*children: The children of the component.
|
|
73
73
|
dangerouslySetInnerHTML: The HTML to render.
|
|
74
|
-
access_key:
|
|
74
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
75
75
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
76
76
|
content_editable: Indicates whether the element's content is editable.
|
|
77
77
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
reflex/components/core/upload.py
CHANGED
|
@@ -29,7 +29,7 @@ from reflex.event import (
|
|
|
29
29
|
from reflex.utils import format
|
|
30
30
|
from reflex.utils.imports import ImportVar
|
|
31
31
|
from reflex.vars import VarData
|
|
32
|
-
from reflex.vars.base import CallableVar,
|
|
32
|
+
from reflex.vars.base import CallableVar, Var, get_unique_variable_name
|
|
33
33
|
from reflex.vars.sequence import LiteralStringVar
|
|
34
34
|
|
|
35
35
|
DEFAULT_UPLOAD_ID: str = "default"
|
|
@@ -61,7 +61,7 @@ def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
61
61
|
id_var = LiteralStringVar.create(id_)
|
|
62
62
|
var_name = f"""e => setFilesById(filesById => {{
|
|
63
63
|
const updatedFilesById = Object.assign({{}}, filesById);
|
|
64
|
-
updatedFilesById[{
|
|
64
|
+
updatedFilesById[{id_var!s}] = e;
|
|
65
65
|
return updatedFilesById;
|
|
66
66
|
}})
|
|
67
67
|
"""
|
|
@@ -87,7 +87,7 @@ def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
87
87
|
"""
|
|
88
88
|
id_var = LiteralStringVar.create(id_)
|
|
89
89
|
return Var(
|
|
90
|
-
_js_expr=f"(filesById[{
|
|
90
|
+
_js_expr=f"(filesById[{id_var!s}] ? filesById[{id_var!s}].map((f) => (f.path || f.name)) : [])",
|
|
91
91
|
_var_type=List[str],
|
|
92
92
|
_var_data=VarData.merge(
|
|
93
93
|
upload_files_context_var_data, id_var._get_all_var_data()
|
|
@@ -108,7 +108,8 @@ def clear_selected_files(id_: str = DEFAULT_UPLOAD_ID) -> EventSpec:
|
|
|
108
108
|
# UploadFilesProvider assigns a special function to clear selected files
|
|
109
109
|
# into the shared global refs object to make it accessible outside a React
|
|
110
110
|
# component via `run_script` (otherwise backend could never clear files).
|
|
111
|
-
|
|
111
|
+
func = Var("__clear_selected_files")._as_ref()
|
|
112
|
+
return run_script(f"{func}({id_!r})")
|
|
112
113
|
|
|
113
114
|
|
|
114
115
|
def cancel_upload(upload_id: str) -> EventSpec:
|
|
@@ -120,9 +121,8 @@ def cancel_upload(upload_id: str) -> EventSpec:
|
|
|
120
121
|
Returns:
|
|
121
122
|
An event spec that cancels the upload when triggered.
|
|
122
123
|
"""
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
124
|
+
controller = Var(f"__upload_controllers_{upload_id}")._as_ref()
|
|
125
|
+
return run_script(f"{controller}?.abort()")
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
def get_upload_dir() -> Path:
|
|
@@ -301,7 +301,7 @@ class Upload(MemoizationLeaf):
|
|
|
301
301
|
)
|
|
302
302
|
|
|
303
303
|
left_side = f"const {{getRootProps: {root_props_unique_name}, getInputProps: {input_props_unique_name}}} "
|
|
304
|
-
right_side = f"useDropzone({
|
|
304
|
+
right_side = f"useDropzone({use_dropzone_arguments!s})"
|
|
305
305
|
|
|
306
306
|
var_data = VarData.merge(
|
|
307
307
|
VarData(
|
|
@@ -519,13 +519,13 @@ class CodeBlock(Component, MarkdownComponentMap):
|
|
|
519
519
|
The hook to register the language.
|
|
520
520
|
"""
|
|
521
521
|
return f"""
|
|
522
|
-
if ({
|
|
522
|
+
if ({_LANGUAGE!s}) {{
|
|
523
523
|
(async () => {{
|
|
524
524
|
try {{
|
|
525
|
-
const module = await import(`react-syntax-highlighter/dist/cjs/languages/prism/${{{
|
|
526
|
-
SyntaxHighlighter.registerLanguage({
|
|
525
|
+
const module = await import(`react-syntax-highlighter/dist/cjs/languages/prism/${{{_LANGUAGE!s}}}`);
|
|
526
|
+
SyntaxHighlighter.registerLanguage({_LANGUAGE!s}, module.default);
|
|
527
527
|
}} catch (error) {{
|
|
528
|
-
console.error(`Error importing language module for ${{{
|
|
528
|
+
console.error(`Error importing language module for ${{{_LANGUAGE!s}}}:`, error);
|
|
529
529
|
}}
|
|
530
530
|
}})();
|
|
531
531
|
}}
|
|
@@ -547,7 +547,7 @@ class CodeBlock(Component, MarkdownComponentMap):
|
|
|
547
547
|
The hooks for the component.
|
|
548
548
|
"""
|
|
549
549
|
return [
|
|
550
|
-
f"const {
|
|
550
|
+
f"const {_LANGUAGE!s} = {self.language!s}",
|
|
551
551
|
self._get_language_registration_hook(),
|
|
552
552
|
]
|
|
553
553
|
|
|
@@ -51,27 +51,6 @@ class GridColumnIcons(Enum):
|
|
|
51
51
|
VideoUri = "video_uri"
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
# @serializer
|
|
55
|
-
# def serialize_gridcolumn_icon(icon: GridColumnIcons) -> str:
|
|
56
|
-
# """Serialize grid column icon.
|
|
57
|
-
|
|
58
|
-
# Args:
|
|
59
|
-
# icon: the Icon to serialize.
|
|
60
|
-
|
|
61
|
-
# Returns:
|
|
62
|
-
# The serialized value.
|
|
63
|
-
# """
|
|
64
|
-
# return "prefix" + str(icon)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# class DataEditorColumn(Base):
|
|
68
|
-
# """Column."""
|
|
69
|
-
|
|
70
|
-
# title: str
|
|
71
|
-
# id: Optional[str] = None
|
|
72
|
-
# type_: str = "str"
|
|
73
|
-
|
|
74
|
-
|
|
75
54
|
class DataEditorTheme(Base):
|
|
76
55
|
"""The theme for the DataEditor component."""
|
|
77
56
|
|
|
@@ -229,7 +208,7 @@ class DataEditor(NoSSRComponent):
|
|
|
229
208
|
header_height: Var[int]
|
|
230
209
|
|
|
231
210
|
# Additional header icons:
|
|
232
|
-
# header_icons: Var[Any] # (TODO: must be a map of name: svg)
|
|
211
|
+
# header_icons: Var[Any] # (TODO: must be a map of name: svg) #noqa: ERA001
|
|
233
212
|
|
|
234
213
|
# The maximum width a column can be automatically sized to.
|
|
235
214
|
max_column_auto_width: Var[int]
|
|
@@ -360,8 +339,11 @@ class DataEditor(NoSSRComponent):
|
|
|
360
339
|
editor_id = get_unique_variable_name()
|
|
361
340
|
|
|
362
341
|
# Define the name of the getData callback associated with this component and assign to get_cell_content.
|
|
363
|
-
|
|
364
|
-
|
|
342
|
+
if self.get_cell_content is not None:
|
|
343
|
+
data_callback = self.get_cell_content._js_expr
|
|
344
|
+
else:
|
|
345
|
+
data_callback = f"getData_{editor_id}"
|
|
346
|
+
self.get_cell_content = Var(_js_expr=data_callback) # type: ignore
|
|
365
347
|
|
|
366
348
|
code = [f"function {data_callback}([col, row])" "{"]
|
|
367
349
|
|
|
@@ -406,10 +388,8 @@ class DataEditor(NoSSRComponent):
|
|
|
406
388
|
props["rows"] = data.length() if isinstance(data, Var) else len(data)
|
|
407
389
|
|
|
408
390
|
if not isinstance(columns, Var) and len(columns):
|
|
409
|
-
if (
|
|
410
|
-
types.is_dataframe(
|
|
411
|
-
or isinstance(data, Var)
|
|
412
|
-
and types.is_dataframe(data._var_type)
|
|
391
|
+
if types.is_dataframe(type(data)) or (
|
|
392
|
+
isinstance(data, Var) and types.is_dataframe(data._var_type)
|
|
413
393
|
):
|
|
414
394
|
raise ValueError(
|
|
415
395
|
"Cannot pass in both a pandas dataframe and columns to the data_editor component."
|
|
@@ -288,7 +288,7 @@ class DataEditor(NoSSRComponent):
|
|
|
288
288
|
freeze_columns: The number of columns which should remain in place when scrolling horizontally. Doesn't include rowMarkers.
|
|
289
289
|
group_header_height: Controls the header of the group header row.
|
|
290
290
|
header_height: Controls the height of the header row.
|
|
291
|
-
max_column_auto_width:
|
|
291
|
+
max_column_auto_width: The maximum width a column can be automatically sized to.
|
|
292
292
|
max_column_width: The maximum width a column can be resized to.
|
|
293
293
|
min_column_width: The minimum width a column can be resized to.
|
|
294
294
|
row_height: Determins the height of each row.
|
|
@@ -490,17 +490,17 @@ class ShikiJsTransformer(ShikiBaseTransformers):
|
|
|
490
490
|
},
|
|
491
491
|
# White Space
|
|
492
492
|
# ".tab, .space": {
|
|
493
|
-
# "position": "relative",
|
|
493
|
+
# "position": "relative", # noqa: ERA001
|
|
494
494
|
# },
|
|
495
495
|
# ".tab::before": {
|
|
496
|
-
# "content": "'⇥'",
|
|
497
|
-
# "position": "absolute",
|
|
498
|
-
# "opacity": "0.3"
|
|
496
|
+
# "content": "'⇥'", # noqa: ERA001
|
|
497
|
+
# "position": "absolute", # noqa: ERA001
|
|
498
|
+
# "opacity": "0.3",# noqa: ERA001
|
|
499
499
|
# },
|
|
500
500
|
# ".space::before": {
|
|
501
|
-
# "content": "'·'",
|
|
502
|
-
# "position": "absolute",
|
|
503
|
-
# "opacity": "0.3",
|
|
501
|
+
# "content": "'·'", # noqa: ERA001
|
|
502
|
+
# "position": "absolute", # noqa: ERA001
|
|
503
|
+
# "opacity": "0.3", # noqa: ERA001
|
|
504
504
|
# },
|
|
505
505
|
}
|
|
506
506
|
)
|
reflex/components/dynamic.py
CHANGED
|
@@ -173,7 +173,7 @@ def load_dynamic_serializer():
|
|
|
173
173
|
f"const [{unique_var_name}, set_{unique_var_name}] = useState(null);": None,
|
|
174
174
|
"useEffect(() => {"
|
|
175
175
|
"let isMounted = true;"
|
|
176
|
-
f"evalReactComponent({
|
|
176
|
+
f"evalReactComponent({js_string!s})"
|
|
177
177
|
".then((component) => {"
|
|
178
178
|
"if (isMounted) {"
|
|
179
179
|
f"set_{unique_var_name}(component);"
|
|
@@ -183,7 +183,7 @@ def load_dynamic_serializer():
|
|
|
183
183
|
"isMounted = false;"
|
|
184
184
|
"};"
|
|
185
185
|
"}"
|
|
186
|
-
f", [{
|
|
186
|
+
f", [{js_string!s}]);": None,
|
|
187
187
|
},
|
|
188
188
|
),
|
|
189
189
|
),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Base classes."""
|
|
2
2
|
|
|
3
3
|
from typing import Union
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ from reflex.vars.base import Var
|
|
|
9
9
|
class BaseHTML(Element):
|
|
10
10
|
"""Base class for common attributes."""
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# Provides a hint for generating a keyboard shortcut for the current element.
|
|
13
13
|
access_key: Var[Union[str, int, bool]]
|
|
14
14
|
|
|
15
15
|
# Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
@@ -67,7 +67,7 @@ class BaseHTML(Element):
|
|
|
67
67
|
|
|
68
68
|
Args:
|
|
69
69
|
*children: The children of the component.
|
|
70
|
-
access_key:
|
|
70
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
71
71
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
72
72
|
content_editable: Indicates whether the element's content is editable.
|
|
73
73
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Forms classes."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -18,6 +18,7 @@ from reflex.event import (
|
|
|
18
18
|
prevent_default,
|
|
19
19
|
)
|
|
20
20
|
from reflex.utils.imports import ImportDict
|
|
21
|
+
from reflex.utils.types import is_optional
|
|
21
22
|
from reflex.vars import VarData
|
|
22
23
|
from reflex.vars.base import LiteralVar, Var
|
|
23
24
|
|
|
@@ -84,7 +85,6 @@ class Datalist(BaseHTML):
|
|
|
84
85
|
"""Display the datalist element."""
|
|
85
86
|
|
|
86
87
|
tag = "datalist"
|
|
87
|
-
# No unique attributes, only common ones are inherited
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
class Fieldset(Element):
|
|
@@ -241,16 +241,15 @@ class Form(BaseHTML):
|
|
|
241
241
|
if ref.startswith("refs_"):
|
|
242
242
|
ref_var = Var(_js_expr=ref[:-3])._as_ref()
|
|
243
243
|
form_refs[ref[len("refs_") : -3]] = Var(
|
|
244
|
-
_js_expr=f"getRefValues({
|
|
244
|
+
_js_expr=f"getRefValues({ref_var!s})",
|
|
245
245
|
_var_data=VarData.merge(ref_var._get_all_var_data()),
|
|
246
246
|
)
|
|
247
247
|
else:
|
|
248
248
|
ref_var = Var(_js_expr=ref)._as_ref()
|
|
249
249
|
form_refs[ref[4:]] = Var(
|
|
250
|
-
_js_expr=f"getRefValue({
|
|
250
|
+
_js_expr=f"getRefValue({ref_var!s})",
|
|
251
251
|
_var_data=VarData.merge(ref_var._get_all_var_data()),
|
|
252
252
|
)
|
|
253
|
-
# print(repr(form_refs))
|
|
254
253
|
return form_refs
|
|
255
254
|
|
|
256
255
|
def _get_vars(self, include_children: bool = True) -> Iterator[Var]:
|
|
@@ -258,7 +257,8 @@ class Form(BaseHTML):
|
|
|
258
257
|
yield from self._get_form_refs().values()
|
|
259
258
|
|
|
260
259
|
def _exclude_props(self) -> list[str]:
|
|
261
|
-
return
|
|
260
|
+
return [
|
|
261
|
+
*super()._exclude_props(),
|
|
262
262
|
"reset_on_submit",
|
|
263
263
|
"handle_submit_unique_name",
|
|
264
264
|
]
|
|
@@ -383,6 +383,33 @@ class Input(BaseHTML):
|
|
|
383
383
|
# Fired when a key is released
|
|
384
384
|
on_key_up: EventHandler[key_event]
|
|
385
385
|
|
|
386
|
+
@classmethod
|
|
387
|
+
def create(cls, *children, **props):
|
|
388
|
+
"""Create an Input component.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
*children: The children of the component.
|
|
392
|
+
**props: The properties of the component.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
The component.
|
|
396
|
+
"""
|
|
397
|
+
from reflex.vars.number import ternary_operation
|
|
398
|
+
|
|
399
|
+
value = props.get("value")
|
|
400
|
+
|
|
401
|
+
# React expects an empty string(instead of null) for controlled inputs.
|
|
402
|
+
if value is not None and is_optional(
|
|
403
|
+
(value_var := Var.create(value))._var_type
|
|
404
|
+
):
|
|
405
|
+
props["value"] = ternary_operation(
|
|
406
|
+
(value_var != Var.create(None)) # pyright: ignore [reportGeneralTypeIssues]
|
|
407
|
+
& (value_var != Var(_js_expr="undefined")),
|
|
408
|
+
value,
|
|
409
|
+
Var.create(""),
|
|
410
|
+
)
|
|
411
|
+
return super().create(*children, **props)
|
|
412
|
+
|
|
386
413
|
|
|
387
414
|
class Label(BaseHTML):
|
|
388
415
|
"""Display the label element."""
|
|
@@ -400,7 +427,6 @@ class Legend(BaseHTML):
|
|
|
400
427
|
"""Display the legend element."""
|
|
401
428
|
|
|
402
429
|
tag = "legend"
|
|
403
|
-
# No unique attributes, only common ones are inherited
|
|
404
430
|
|
|
405
431
|
|
|
406
432
|
class Meter(BaseHTML):
|
|
@@ -570,6 +596,9 @@ class Textarea(BaseHTML):
|
|
|
570
596
|
# Visible width of the text control, in average character widths
|
|
571
597
|
cols: Var[Union[str, int, bool]]
|
|
572
598
|
|
|
599
|
+
# The default value of the textarea when initially rendered
|
|
600
|
+
default_value: Var[str]
|
|
601
|
+
|
|
573
602
|
# Name part of the textarea to submit in 'dir' and 'name' pair when form is submitted
|
|
574
603
|
dirname: Var[Union[str, int, bool]]
|
|
575
604
|
|
|
@@ -649,19 +678,20 @@ class Textarea(BaseHTML):
|
|
|
649
678
|
"Cannot combine `enter_key_submit` with `on_key_down`.",
|
|
650
679
|
)
|
|
651
680
|
custom_attrs["on_key_down"] = Var(
|
|
652
|
-
_js_expr=f"(e) => enterKeySubmitOnKeyDown(e, {
|
|
681
|
+
_js_expr=f"(e) => enterKeySubmitOnKeyDown(e, {enter_key_submit!s})",
|
|
653
682
|
_var_data=VarData.merge(enter_key_submit._get_all_var_data()),
|
|
654
683
|
)
|
|
655
684
|
if auto_height is not None:
|
|
656
685
|
auto_height = Var.create(auto_height)
|
|
657
686
|
custom_attrs["on_input"] = Var(
|
|
658
|
-
_js_expr=f"(e) => autoHeightOnInput(e, {
|
|
687
|
+
_js_expr=f"(e) => autoHeightOnInput(e, {auto_height!s})",
|
|
659
688
|
_var_data=VarData.merge(auto_height._get_all_var_data()),
|
|
660
689
|
)
|
|
661
690
|
return super().create(*children, **props)
|
|
662
691
|
|
|
663
692
|
def _exclude_props(self) -> list[str]:
|
|
664
|
-
return
|
|
693
|
+
return [
|
|
694
|
+
*super()._exclude_props(),
|
|
665
695
|
"auto_height",
|
|
666
696
|
"enter_key_submit",
|
|
667
697
|
]
|
|
@@ -103,7 +103,7 @@ class Button(BaseHTML):
|
|
|
103
103
|
name: Name of the button, used when sending form data
|
|
104
104
|
type: Type of the button (submit, reset, or button)
|
|
105
105
|
value: Value of the button, used when sending form data
|
|
106
|
-
access_key:
|
|
106
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
107
107
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
108
108
|
content_editable: Indicates whether the element's content is editable.
|
|
109
109
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -189,7 +189,7 @@ class Datalist(BaseHTML):
|
|
|
189
189
|
|
|
190
190
|
Args:
|
|
191
191
|
*children: The children of the component.
|
|
192
|
-
access_key:
|
|
192
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
193
193
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
194
194
|
content_editable: Indicates whether the element's content is editable.
|
|
195
195
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -367,7 +367,7 @@ class Form(BaseHTML):
|
|
|
367
367
|
reset_on_submit: If true, the form will be cleared after submit.
|
|
368
368
|
handle_submit_unique_name: The name used to make this form's submit handler function unique.
|
|
369
369
|
on_submit: Fired when the form is submitted
|
|
370
|
-
access_key:
|
|
370
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
371
371
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
372
372
|
content_editable: Indicates whether the element's content is editable.
|
|
373
373
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -512,7 +512,7 @@ class Input(BaseHTML):
|
|
|
512
512
|
on_unmount: Optional[EventType[[], BASE_STATE]] = None,
|
|
513
513
|
**props,
|
|
514
514
|
) -> "Input":
|
|
515
|
-
"""Create
|
|
515
|
+
"""Create an Input component.
|
|
516
516
|
|
|
517
517
|
Args:
|
|
518
518
|
*children: The children of the component.
|
|
@@ -554,7 +554,7 @@ class Input(BaseHTML):
|
|
|
554
554
|
on_blur: Fired when the input loses focus
|
|
555
555
|
on_key_down: Fired when a key is pressed down
|
|
556
556
|
on_key_up: Fired when a key is released
|
|
557
|
-
access_key:
|
|
557
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
558
558
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
559
559
|
content_editable: Indicates whether the element's content is editable.
|
|
560
560
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -576,7 +576,7 @@ class Input(BaseHTML):
|
|
|
576
576
|
class_name: The class name for the component.
|
|
577
577
|
autofocus: Whether the component should take the focus once the page is loaded
|
|
578
578
|
custom_attrs: custom attribute
|
|
579
|
-
**props: The
|
|
579
|
+
**props: The properties of the component.
|
|
580
580
|
|
|
581
581
|
Returns:
|
|
582
582
|
The component.
|
|
@@ -644,7 +644,7 @@ class Label(BaseHTML):
|
|
|
644
644
|
*children: The children of the component.
|
|
645
645
|
html_for: ID of a form control with which the label is associated
|
|
646
646
|
form: Associates the label with a form (by id)
|
|
647
|
-
access_key:
|
|
647
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
648
648
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
649
649
|
content_editable: Indicates whether the element's content is editable.
|
|
650
650
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -730,7 +730,7 @@ class Legend(BaseHTML):
|
|
|
730
730
|
|
|
731
731
|
Args:
|
|
732
732
|
*children: The children of the component.
|
|
733
|
-
access_key:
|
|
733
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
734
734
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
735
735
|
content_editable: Indicates whether the element's content is editable.
|
|
736
736
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -830,7 +830,7 @@ class Meter(BaseHTML):
|
|
|
830
830
|
min: Minimum value of the range
|
|
831
831
|
optimum: Optimum value in the range
|
|
832
832
|
value: Current value of the meter
|
|
833
|
-
access_key:
|
|
833
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
834
834
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
835
835
|
content_editable: Indicates whether the element's content is editable.
|
|
836
836
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -920,7 +920,7 @@ class Optgroup(BaseHTML):
|
|
|
920
920
|
*children: The children of the component.
|
|
921
921
|
disabled: Disables the optgroup
|
|
922
922
|
label: Label for the optgroup
|
|
923
|
-
access_key:
|
|
923
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
924
924
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
925
925
|
content_editable: Indicates whether the element's content is editable.
|
|
926
926
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -1014,7 +1014,7 @@ class Option(BaseHTML):
|
|
|
1014
1014
|
label: Label for the option, if the text is not the label
|
|
1015
1015
|
selected: Indicates that the option is initially selected
|
|
1016
1016
|
value: Value to be sent as form data
|
|
1017
|
-
access_key:
|
|
1017
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
1018
1018
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
1019
1019
|
content_editable: Indicates whether the element's content is editable.
|
|
1020
1020
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -1106,7 +1106,7 @@ class Output(BaseHTML):
|
|
|
1106
1106
|
html_for: Associates the output with one or more elements (by their IDs)
|
|
1107
1107
|
form: Associates the output with a form (by id)
|
|
1108
1108
|
name: Name of the output element for form submission
|
|
1109
|
-
access_key:
|
|
1109
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
1110
1110
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
1111
1111
|
content_editable: Indicates whether the element's content is editable.
|
|
1112
1112
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -1198,7 +1198,7 @@ class Progress(BaseHTML):
|
|
|
1198
1198
|
form: Associates the progress element with a form (by id)
|
|
1199
1199
|
max: Maximum value of the progress indicator
|
|
1200
1200
|
value: Current value of the progress indicator
|
|
1201
|
-
access_key:
|
|
1201
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
1202
1202
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
1203
1203
|
content_editable: Indicates whether the element's content is editable.
|
|
1204
1204
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -1306,7 +1306,7 @@ class Select(BaseHTML):
|
|
|
1306
1306
|
required: Indicates that the select control must have a selected option
|
|
1307
1307
|
size: Number of visible options in a drop-down list
|
|
1308
1308
|
on_change: Fired when the select value changes
|
|
1309
|
-
access_key:
|
|
1309
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
1310
1310
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
1311
1311
|
content_editable: Indicates whether the element's content is editable.
|
|
1312
1312
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
@@ -1350,6 +1350,7 @@ class Textarea(BaseHTML):
|
|
|
1350
1350
|
auto_focus: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
|
|
1351
1351
|
auto_height: Optional[Union[Var[bool], bool]] = None,
|
|
1352
1352
|
cols: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
|
|
1353
|
+
default_value: Optional[Union[Var[str], str]] = None,
|
|
1353
1354
|
dirname: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
|
|
1354
1355
|
disabled: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
|
|
1355
1356
|
enter_key_submit: Optional[Union[Var[bool], bool]] = None,
|
|
@@ -1439,6 +1440,7 @@ class Textarea(BaseHTML):
|
|
|
1439
1440
|
auto_focus: Automatically focuses the textarea when the page loads
|
|
1440
1441
|
auto_height: Automatically fit the content height to the text (use min-height with this prop)
|
|
1441
1442
|
cols: Visible width of the text control, in average character widths
|
|
1443
|
+
default_value: The default value of the textarea when initially rendered
|
|
1442
1444
|
dirname: Name part of the textarea to submit in 'dir' and 'name' pair when form is submitted
|
|
1443
1445
|
disabled: Disables the textarea
|
|
1444
1446
|
enter_key_submit: Enter key submits form (shift-enter adds new line)
|
|
@@ -1457,7 +1459,7 @@ class Textarea(BaseHTML):
|
|
|
1457
1459
|
on_blur: Fired when the input loses focus
|
|
1458
1460
|
on_key_down: Fired when a key is pressed down
|
|
1459
1461
|
on_key_up: Fired when a key is released
|
|
1460
|
-
access_key:
|
|
1462
|
+
access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
1461
1463
|
auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
1462
1464
|
content_editable: Indicates whether the element's content is editable.
|
|
1463
1465
|
context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|