reflex 0.6.0a4__py3-none-any.whl → 0.6.1a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of reflex might be problematic. Click here for more details.
- reflex/.templates/jinja/web/pages/_app.js.jinja2 +14 -0
- reflex/.templates/web/utils/state.js +67 -40
- reflex/app.py +9 -5
- reflex/app_mixins/lifespan.py +24 -6
- reflex/base.py +7 -13
- reflex/compiler/utils.py +17 -8
- reflex/components/base/bare.py +3 -1
- reflex/components/base/meta.py +5 -3
- reflex/components/component.py +19 -19
- reflex/components/core/cond.py +4 -4
- reflex/components/datadisplay/__init__.py +0 -1
- reflex/components/datadisplay/__init__.pyi +0 -1
- reflex/components/datadisplay/code.py +93 -106
- reflex/components/datadisplay/code.pyi +710 -53
- reflex/components/datadisplay/logo.py +22 -20
- reflex/components/dynamic.py +157 -0
- reflex/components/el/elements/forms.py +4 -1
- reflex/components/gridjs/datatable.py +2 -1
- reflex/components/markdown/markdown.py +10 -6
- reflex/components/markdown/markdown.pyi +3 -0
- reflex/components/radix/themes/components/progress.py +22 -0
- reflex/components/radix/themes/components/progress.pyi +2 -0
- reflex/components/radix/themes/components/segmented_control.py +3 -0
- reflex/components/radix/themes/components/segmented_control.pyi +2 -0
- reflex/components/radix/themes/layout/stack.py +1 -1
- reflex/components/recharts/cartesian.py +1 -1
- reflex/components/tags/iter_tag.py +5 -1
- reflex/config.py +2 -2
- reflex/constants/base.py +4 -1
- reflex/constants/installer.py +8 -1
- reflex/event.py +61 -20
- reflex/experimental/assets.py +3 -1
- reflex/experimental/client_state.py +5 -1
- reflex/experimental/misc.py +5 -3
- reflex/middleware/hydrate_middleware.py +1 -2
- reflex/page.py +10 -3
- reflex/reflex.py +20 -3
- reflex/state.py +105 -43
- reflex/style.py +12 -2
- reflex/testing.py +8 -4
- reflex/utils/console.py +1 -1
- reflex/utils/exceptions.py +4 -0
- reflex/utils/exec.py +170 -18
- reflex/utils/format.py +6 -44
- reflex/utils/path_ops.py +36 -1
- reflex/utils/prerequisites.py +42 -14
- reflex/utils/serializers.py +7 -46
- reflex/utils/types.py +17 -2
- reflex/vars/base.py +303 -43
- reflex/vars/number.py +3 -0
- reflex/vars/sequence.py +43 -0
- {reflex-0.6.0a4.dist-info → reflex-0.6.1a1.dist-info}/METADATA +2 -3
- {reflex-0.6.0a4.dist-info → reflex-0.6.1a1.dist-info}/RECORD +56 -55
- {reflex-0.6.0a4.dist-info → reflex-0.6.1a1.dist-info}/LICENSE +0 -0
- {reflex-0.6.0a4.dist-info → reflex-0.6.1a1.dist-info}/WHEEL +0 -0
- {reflex-0.6.0a4.dist-info → reflex-0.6.1a1.dist-info}/entry_points.txt +0 -0
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import dataclasses
|
|
6
|
+
from typing import ClassVar, Dict, Literal, Optional, Union
|
|
6
7
|
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
from reflex.components.component import Component
|
|
8
|
+
from reflex.components.component import Component, ComponentNamespace
|
|
10
9
|
from reflex.components.core.cond import color_mode_cond
|
|
11
10
|
from reflex.components.lucide.icon import Icon
|
|
12
11
|
from reflex.components.radix.themes.components.button import Button
|
|
@@ -14,58 +13,9 @@ from reflex.components.radix.themes.layout.box import Box
|
|
|
14
13
|
from reflex.constants.colors import Color
|
|
15
14
|
from reflex.event import set_clipboard
|
|
16
15
|
from reflex.style import Style
|
|
17
|
-
from reflex.utils import format
|
|
16
|
+
from reflex.utils import console, format
|
|
18
17
|
from reflex.utils.imports import ImportDict, ImportVar
|
|
19
|
-
from reflex.vars.base import LiteralVar, Var
|
|
20
|
-
|
|
21
|
-
LiteralCodeBlockTheme = Literal[
|
|
22
|
-
"a11y-dark",
|
|
23
|
-
"atom-dark",
|
|
24
|
-
"cb",
|
|
25
|
-
"coldark-cold",
|
|
26
|
-
"coldark-dark",
|
|
27
|
-
"coy",
|
|
28
|
-
"coy-without-shadows",
|
|
29
|
-
"darcula",
|
|
30
|
-
"dark",
|
|
31
|
-
"dracula",
|
|
32
|
-
"duotone-dark",
|
|
33
|
-
"duotone-earth",
|
|
34
|
-
"duotone-forest",
|
|
35
|
-
"duotone-light",
|
|
36
|
-
"duotone-sea",
|
|
37
|
-
"duotone-space",
|
|
38
|
-
"funky",
|
|
39
|
-
"ghcolors",
|
|
40
|
-
"gruvbox-dark",
|
|
41
|
-
"gruvbox-light",
|
|
42
|
-
"holi-theme",
|
|
43
|
-
"hopscotch",
|
|
44
|
-
"light", # not present in react-syntax-highlighter styles
|
|
45
|
-
"lucario",
|
|
46
|
-
"material-dark",
|
|
47
|
-
"material-light",
|
|
48
|
-
"material-oceanic",
|
|
49
|
-
"night-owl",
|
|
50
|
-
"nord",
|
|
51
|
-
"okaidia",
|
|
52
|
-
"one-dark",
|
|
53
|
-
"one-light",
|
|
54
|
-
"pojoaque",
|
|
55
|
-
"prism",
|
|
56
|
-
"shades-of-purple",
|
|
57
|
-
"solarized-dark-atom",
|
|
58
|
-
"solarizedlight",
|
|
59
|
-
"synthwave84",
|
|
60
|
-
"tomorrow",
|
|
61
|
-
"twilight",
|
|
62
|
-
"vs",
|
|
63
|
-
"vs-dark",
|
|
64
|
-
"vsc-dark-plus",
|
|
65
|
-
"xonokai",
|
|
66
|
-
"z-touch",
|
|
67
|
-
]
|
|
68
|
-
|
|
18
|
+
from reflex.vars.base import LiteralVar, Var, VarData
|
|
69
19
|
|
|
70
20
|
LiteralCodeLanguage = Literal[
|
|
71
21
|
"abap",
|
|
@@ -350,18 +300,82 @@ LiteralCodeLanguage = Literal[
|
|
|
350
300
|
]
|
|
351
301
|
|
|
352
302
|
|
|
353
|
-
def
|
|
354
|
-
"""
|
|
303
|
+
def construct_theme_var(theme: str) -> Var[Theme]:
|
|
304
|
+
"""Construct a theme var.
|
|
355
305
|
|
|
356
306
|
Args:
|
|
357
|
-
|
|
307
|
+
theme: The theme to construct.
|
|
358
308
|
|
|
359
309
|
Returns:
|
|
360
|
-
|
|
310
|
+
The constructed theme var.
|
|
361
311
|
"""
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
312
|
+
return Var(
|
|
313
|
+
theme,
|
|
314
|
+
_var_data=VarData(
|
|
315
|
+
imports={
|
|
316
|
+
f"react-syntax-highlighter/dist/cjs/styles/prism/{format.to_kebab_case(theme)}": [
|
|
317
|
+
ImportVar(tag=theme, is_default=True, install=False)
|
|
318
|
+
]
|
|
319
|
+
}
|
|
320
|
+
),
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
@dataclasses.dataclass(init=False)
|
|
325
|
+
class Theme:
|
|
326
|
+
"""Themes for the CodeBlock component."""
|
|
327
|
+
|
|
328
|
+
a11y_dark: ClassVar[Var[Theme]] = construct_theme_var("a11yDark")
|
|
329
|
+
atom_dark: ClassVar[Var[Theme]] = construct_theme_var("atomDark")
|
|
330
|
+
cb: ClassVar[Var[Theme]] = construct_theme_var("cb")
|
|
331
|
+
coldark_cold: ClassVar[Var[Theme]] = construct_theme_var("coldarkCold")
|
|
332
|
+
coldark_dark: ClassVar[Var[Theme]] = construct_theme_var("coldarkDark")
|
|
333
|
+
coy: ClassVar[Var[Theme]] = construct_theme_var("coy")
|
|
334
|
+
coy_without_shadows: ClassVar[Var[Theme]] = construct_theme_var("coyWithoutShadows")
|
|
335
|
+
darcula: ClassVar[Var[Theme]] = construct_theme_var("darcula")
|
|
336
|
+
dark: ClassVar[Var[Theme]] = construct_theme_var("oneDark")
|
|
337
|
+
dracula: ClassVar[Var[Theme]] = construct_theme_var("dracula")
|
|
338
|
+
duotone_dark: ClassVar[Var[Theme]] = construct_theme_var("duotoneDark")
|
|
339
|
+
duotone_earth: ClassVar[Var[Theme]] = construct_theme_var("duotoneEarth")
|
|
340
|
+
duotone_forest: ClassVar[Var[Theme]] = construct_theme_var("duotoneForest")
|
|
341
|
+
duotone_light: ClassVar[Var[Theme]] = construct_theme_var("duotoneLight")
|
|
342
|
+
duotone_sea: ClassVar[Var[Theme]] = construct_theme_var("duotoneSea")
|
|
343
|
+
duotone_space: ClassVar[Var[Theme]] = construct_theme_var("duotoneSpace")
|
|
344
|
+
funky: ClassVar[Var[Theme]] = construct_theme_var("funky")
|
|
345
|
+
ghcolors: ClassVar[Var[Theme]] = construct_theme_var("ghcolors")
|
|
346
|
+
gruvbox_dark: ClassVar[Var[Theme]] = construct_theme_var("gruvboxDark")
|
|
347
|
+
gruvbox_light: ClassVar[Var[Theme]] = construct_theme_var("gruvboxLight")
|
|
348
|
+
holi_theme: ClassVar[Var[Theme]] = construct_theme_var("holiTheme")
|
|
349
|
+
hopscotch: ClassVar[Var[Theme]] = construct_theme_var("hopscotch")
|
|
350
|
+
light: ClassVar[Var[Theme]] = construct_theme_var("oneLight")
|
|
351
|
+
lucario: ClassVar[Var[Theme]] = construct_theme_var("lucario")
|
|
352
|
+
material_dark: ClassVar[Var[Theme]] = construct_theme_var("materialDark")
|
|
353
|
+
material_light: ClassVar[Var[Theme]] = construct_theme_var("materialLight")
|
|
354
|
+
material_oceanic: ClassVar[Var[Theme]] = construct_theme_var("materialOceanic")
|
|
355
|
+
night_owl: ClassVar[Var[Theme]] = construct_theme_var("nightOwl")
|
|
356
|
+
nord: ClassVar[Var[Theme]] = construct_theme_var("nord")
|
|
357
|
+
okaidia: ClassVar[Var[Theme]] = construct_theme_var("okaidia")
|
|
358
|
+
one_dark: ClassVar[Var[Theme]] = construct_theme_var("oneDark")
|
|
359
|
+
one_light: ClassVar[Var[Theme]] = construct_theme_var("oneLight")
|
|
360
|
+
pojoaque: ClassVar[Var[Theme]] = construct_theme_var("pojoaque")
|
|
361
|
+
prism: ClassVar[Var[Theme]] = construct_theme_var("prism")
|
|
362
|
+
shades_of_purple: ClassVar[Var[Theme]] = construct_theme_var("shadesOfPurple")
|
|
363
|
+
solarized_dark_atom: ClassVar[Var[Theme]] = construct_theme_var("solarizedDarkAtom")
|
|
364
|
+
solarizedlight: ClassVar[Var[Theme]] = construct_theme_var("solarizedlight")
|
|
365
|
+
synthwave84: ClassVar[Var[Theme]] = construct_theme_var("synthwave84")
|
|
366
|
+
tomorrow: ClassVar[Var[Theme]] = construct_theme_var("tomorrow")
|
|
367
|
+
twilight: ClassVar[Var[Theme]] = construct_theme_var("twilight")
|
|
368
|
+
vs: ClassVar[Var[Theme]] = construct_theme_var("vs")
|
|
369
|
+
vs_dark: ClassVar[Var[Theme]] = construct_theme_var("vsDark")
|
|
370
|
+
vsc_dark_plus: ClassVar[Var[Theme]] = construct_theme_var("vscDarkPlus")
|
|
371
|
+
xonokai: ClassVar[Var[Theme]] = construct_theme_var("xonokai")
|
|
372
|
+
z_touch: ClassVar[Var[Theme]] = construct_theme_var("zTouch")
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
for theme_name in dir(Theme):
|
|
376
|
+
if theme_name.startswith("_"):
|
|
377
|
+
continue
|
|
378
|
+
setattr(Theme, theme_name, getattr(Theme, theme_name)._replace(_var_type=Theme))
|
|
365
379
|
|
|
366
380
|
|
|
367
381
|
class CodeBlock(Component):
|
|
@@ -374,7 +388,7 @@ class CodeBlock(Component):
|
|
|
374
388
|
alias = "SyntaxHighlighter"
|
|
375
389
|
|
|
376
390
|
# The theme to use ("light" or "dark").
|
|
377
|
-
theme: Var[
|
|
391
|
+
theme: Var[Union[Theme, str]] = Theme.one_light
|
|
378
392
|
|
|
379
393
|
# The language to use.
|
|
380
394
|
language: Var[LiteralCodeLanguage] = "python" # type: ignore
|
|
@@ -405,31 +419,6 @@ class CodeBlock(Component):
|
|
|
405
419
|
"""
|
|
406
420
|
imports_: ImportDict = {}
|
|
407
421
|
|
|
408
|
-
themeString = str(self.theme)
|
|
409
|
-
|
|
410
|
-
selected_themes = []
|
|
411
|
-
|
|
412
|
-
for possibleTheme in get_args(LiteralCodeBlockTheme):
|
|
413
|
-
if format.to_camel_case(possibleTheme) in themeString:
|
|
414
|
-
selected_themes.append(possibleTheme)
|
|
415
|
-
if possibleTheme in themeString:
|
|
416
|
-
selected_themes.append(possibleTheme)
|
|
417
|
-
|
|
418
|
-
selected_themes = sorted(set(map(self.convert_theme_name, selected_themes)))
|
|
419
|
-
|
|
420
|
-
imports_.update(
|
|
421
|
-
{
|
|
422
|
-
f"react-syntax-highlighter/dist/cjs/styles/prism/{theme}": [
|
|
423
|
-
ImportVar(
|
|
424
|
-
tag=format.to_camel_case(theme),
|
|
425
|
-
is_default=True,
|
|
426
|
-
install=False,
|
|
427
|
-
)
|
|
428
|
-
]
|
|
429
|
-
for theme in selected_themes
|
|
430
|
-
}
|
|
431
|
-
)
|
|
432
|
-
|
|
433
422
|
if (
|
|
434
423
|
self.language is not None
|
|
435
424
|
and (language_without_quotes := str(self.language).replace('"', ""))
|
|
@@ -480,14 +469,20 @@ class CodeBlock(Component):
|
|
|
480
469
|
if "theme" not in props:
|
|
481
470
|
# Default color scheme responds to global color mode.
|
|
482
471
|
props["theme"] = color_mode_cond(
|
|
483
|
-
light=
|
|
484
|
-
dark=
|
|
472
|
+
light=Theme.one_light,
|
|
473
|
+
dark=Theme.one_dark,
|
|
485
474
|
)
|
|
486
475
|
|
|
487
476
|
# react-syntax-highlighter doesnt have an explicit "light" or "dark" theme so we use one-light and one-dark
|
|
488
477
|
# themes respectively to ensure code compatibility.
|
|
489
478
|
if "theme" in props and not isinstance(props["theme"], Var):
|
|
490
|
-
props["theme"] =
|
|
479
|
+
props["theme"] = getattr(Theme, format.to_snake_case(props["theme"])) # type: ignore
|
|
480
|
+
console.deprecate(
|
|
481
|
+
feature_name="theme prop as string",
|
|
482
|
+
reason="Use code_block.themes instead.",
|
|
483
|
+
deprecation_version="0.6.0",
|
|
484
|
+
removal_version="0.7.0",
|
|
485
|
+
)
|
|
491
486
|
|
|
492
487
|
if can_copy:
|
|
493
488
|
code = children[0]
|
|
@@ -533,9 +528,7 @@ class CodeBlock(Component):
|
|
|
533
528
|
def _render(self):
|
|
534
529
|
out = super()._render()
|
|
535
530
|
|
|
536
|
-
theme = self.theme
|
|
537
|
-
_js_expr=replace_quotes_with_camel_case(str(self.theme))
|
|
538
|
-
)
|
|
531
|
+
theme = self.theme
|
|
539
532
|
|
|
540
533
|
out.add_props(style=theme).remove_props("theme", "code").add_props(
|
|
541
534
|
children=self.code
|
|
@@ -543,19 +536,13 @@ class CodeBlock(Component):
|
|
|
543
536
|
|
|
544
537
|
return out
|
|
545
538
|
|
|
546
|
-
@staticmethod
|
|
547
|
-
def convert_theme_name(theme) -> str:
|
|
548
|
-
"""Convert theme names to appropriate names.
|
|
549
539
|
|
|
550
|
-
|
|
551
|
-
|
|
540
|
+
class CodeblockNamespace(ComponentNamespace):
|
|
541
|
+
"""Namespace for the CodeBlock component."""
|
|
552
542
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if theme in ["light", "dark"]:
|
|
557
|
-
return f"one-{theme}"
|
|
558
|
-
return theme
|
|
543
|
+
themes = Theme
|
|
544
|
+
|
|
545
|
+
__call__ = CodeBlock.create
|
|
559
546
|
|
|
560
547
|
|
|
561
|
-
code_block =
|
|
548
|
+
code_block = CodeblockNamespace()
|