reflex 0.3.2__py3-none-any.whl → 0.3.3a1__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.

Files changed (48) hide show
  1. reflex/.templates/jinja/web/pages/custom_component.js.jinja2 +20 -3
  2. reflex/.templates/web/next.config.js +1 -0
  3. reflex/.templates/web/utils/helpers/range.js +43 -0
  4. reflex/.templates/web/utils/state.js +10 -6
  5. reflex/__init__.py +312 -40
  6. reflex/__init__.pyi +477 -0
  7. reflex/compiler/compiler.py +3 -0
  8. reflex/components/__init__.py +138 -138
  9. reflex/components/component.py +29 -22
  10. reflex/components/datadisplay/__init__.py +3 -1
  11. reflex/components/datadisplay/code.py +388 -14
  12. reflex/components/datadisplay/code.pyi +1146 -10
  13. reflex/components/forms/button.py +3 -0
  14. reflex/components/forms/checkbox.py +3 -0
  15. reflex/components/forms/form.py +90 -27
  16. reflex/components/forms/input.py +3 -0
  17. reflex/components/forms/numberinput.py +3 -0
  18. reflex/components/forms/pininput.py +77 -21
  19. reflex/components/forms/radio.py +3 -0
  20. reflex/components/forms/rangeslider.py +3 -0
  21. reflex/components/forms/select.py +3 -0
  22. reflex/components/forms/slider.py +3 -0
  23. reflex/components/forms/switch.py +3 -0
  24. reflex/components/forms/textarea.py +3 -0
  25. reflex/components/libs/chakra.py +2 -0
  26. reflex/components/libs/chakra.pyi +323 -24
  27. reflex/components/tags/tag.py +3 -2
  28. reflex/components/typography/markdown.py +10 -0
  29. reflex/constants/installer.py +4 -4
  30. reflex/event.py +4 -0
  31. reflex/page.py +3 -4
  32. reflex/page.pyi +17 -0
  33. reflex/reflex.py +3 -0
  34. reflex/state.py +31 -12
  35. reflex/testing.py +1 -1
  36. reflex/utils/build.py +24 -19
  37. reflex/utils/console.py +5 -1
  38. reflex/utils/format.py +26 -9
  39. reflex/utils/prerequisites.py +27 -28
  40. reflex/utils/processes.py +5 -4
  41. reflex/vars.py +80 -12
  42. reflex/vars.pyi +7 -0
  43. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/METADATA +3 -2
  44. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/RECORD +47 -45
  45. reflex/.templates/web/styles/code/prism.js +0 -1015
  46. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/LICENSE +0 -0
  47. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/WHEEL +0 -0
  48. {reflex-0.3.2.dist-info → reflex-0.3.3a1.dist-info}/entry_points.txt +0 -0
@@ -1,19 +1,349 @@
1
1
  """A code component."""
2
2
 
3
- from typing import Dict, Optional, Union
3
+ from typing import Dict, Literal, Optional, Union
4
4
 
5
5
  from reflex.components.component import Component
6
6
  from reflex.components.forms import Button
7
7
  from reflex.components.layout import Box
8
- from reflex.components.libs.chakra import ChakraComponent, LiteralTheme
8
+ from reflex.components.libs.chakra import (
9
+ ChakraComponent,
10
+ )
9
11
  from reflex.components.media import Icon
10
12
  from reflex.event import set_clipboard
11
13
  from reflex.style import Style
12
- from reflex.utils import imports
14
+ from reflex.utils import format, imports
13
15
  from reflex.vars import ImportVar, Var
14
16
 
15
- # Path to the prism styles.
16
- PRISM_STYLES_PATH: str = "/styles/code/prism"
17
+ LiteralCodeBlockTheme = Literal[
18
+ "a11y-dark",
19
+ "atom-dark",
20
+ "cb",
21
+ "coldark-cold",
22
+ "coldark-dark",
23
+ "coy",
24
+ "coy-without-shadows",
25
+ "darcula",
26
+ "dark",
27
+ "dracula",
28
+ "duotone-dark",
29
+ "duotone-earth",
30
+ "duotone-forest",
31
+ "duotone-light",
32
+ "duotone-sea",
33
+ "duotone-space",
34
+ "funky",
35
+ "ghcolors",
36
+ "gruvbox-dark",
37
+ "gruvbox-light",
38
+ "holi-theme",
39
+ "hopscotch",
40
+ "light", # not present in react-syntax-highlighter styles
41
+ "lucario",
42
+ "material-dark",
43
+ "material-light",
44
+ "material-oceanic",
45
+ "night-owl",
46
+ "nord",
47
+ "okaidia",
48
+ "one-dark",
49
+ "one-light",
50
+ "pojoaque",
51
+ "prism",
52
+ "shades-of-purple",
53
+ "solarized-dark-atom",
54
+ "solarizedlight",
55
+ "synthwave84",
56
+ "tomorrow",
57
+ "twilight",
58
+ "vs",
59
+ "vs-dark",
60
+ "vsc-dark-plus",
61
+ "xonokai",
62
+ "z-touch",
63
+ ]
64
+
65
+
66
+ LiteralCodeLanguage = Literal[
67
+ "abap",
68
+ "abnf",
69
+ "actionscript",
70
+ "ada",
71
+ "agda",
72
+ "al",
73
+ "antlr4",
74
+ "apacheconf",
75
+ "apex",
76
+ "apl",
77
+ "applescript",
78
+ "aql",
79
+ "arduino",
80
+ "arff",
81
+ "asciidoc",
82
+ "asm6502",
83
+ "asmatmel",
84
+ "aspnet",
85
+ "autohotkey",
86
+ "autoit",
87
+ "avisynth",
88
+ "avro-idl",
89
+ "bash",
90
+ "basic",
91
+ "batch",
92
+ "bbcode",
93
+ "bicep",
94
+ "birb",
95
+ "bison",
96
+ "bnf",
97
+ "brainfuck",
98
+ "brightscript",
99
+ "bro",
100
+ "bsl",
101
+ "c",
102
+ "cfscript",
103
+ "chaiscript",
104
+ "cil",
105
+ "clike",
106
+ "clojure",
107
+ "cmake",
108
+ "cobol",
109
+ "coffeescript",
110
+ "concurnas",
111
+ "coq",
112
+ "core",
113
+ "cpp",
114
+ "crystal",
115
+ "csharp",
116
+ "cshtml",
117
+ "csp",
118
+ "css",
119
+ "css-extras",
120
+ "csv",
121
+ "cypher",
122
+ "d",
123
+ "dart",
124
+ "dataweave",
125
+ "dax",
126
+ "dhall",
127
+ "diff",
128
+ "django",
129
+ "dns-zone-file",
130
+ "docker",
131
+ "dot",
132
+ "ebnf",
133
+ "editorconfig",
134
+ "eiffel",
135
+ "ejs",
136
+ "elixir",
137
+ "elm",
138
+ "erb",
139
+ "erlang",
140
+ "etlua",
141
+ "excel-formula",
142
+ "factor",
143
+ "false",
144
+ "firestore-security-rules",
145
+ "flow",
146
+ "fortran",
147
+ "fsharp",
148
+ "ftl",
149
+ "gap",
150
+ "gcode",
151
+ "gdscript",
152
+ "gedcom",
153
+ "gherkin",
154
+ "git",
155
+ "glsl",
156
+ "gml",
157
+ "gn",
158
+ "go",
159
+ "go-module",
160
+ "graphql",
161
+ "groovy",
162
+ "haml",
163
+ "handlebars",
164
+ "haskell",
165
+ "haxe",
166
+ "hcl",
167
+ "hlsl",
168
+ "hoon",
169
+ "hpkp",
170
+ "hsts",
171
+ "http",
172
+ "ichigojam",
173
+ "icon",
174
+ "icu-message-format",
175
+ "idris",
176
+ "iecst",
177
+ "ignore",
178
+ "index",
179
+ "inform7",
180
+ "ini",
181
+ "io",
182
+ "j",
183
+ "java",
184
+ "javadoc",
185
+ "javadoclike",
186
+ "javascript",
187
+ "javastacktrace",
188
+ "jexl",
189
+ "jolie",
190
+ "jq",
191
+ "js-extras",
192
+ "js-templates",
193
+ "jsdoc",
194
+ "json",
195
+ "json5",
196
+ "jsonp",
197
+ "jsstacktrace",
198
+ "jsx",
199
+ "julia",
200
+ "keepalived",
201
+ "keyman",
202
+ "kotlin",
203
+ "kumir",
204
+ "kusto",
205
+ "latex",
206
+ "latte",
207
+ "less",
208
+ "lilypond",
209
+ "liquid",
210
+ "lisp",
211
+ "livescript",
212
+ "llvm",
213
+ "log",
214
+ "lolcode",
215
+ "lua",
216
+ "magma",
217
+ "makefile",
218
+ "markdown",
219
+ "markup",
220
+ "markup-templating",
221
+ "matlab",
222
+ "maxscript",
223
+ "mel",
224
+ "mermaid",
225
+ "mizar",
226
+ "mongodb",
227
+ "monkey",
228
+ "moonscript",
229
+ "n1ql",
230
+ "n4js",
231
+ "nand2tetris-hdl",
232
+ "naniscript",
233
+ "nasm",
234
+ "neon",
235
+ "nevod",
236
+ "nginx",
237
+ "nim",
238
+ "nix",
239
+ "nsis",
240
+ "objectivec",
241
+ "ocaml",
242
+ "opencl",
243
+ "openqasm",
244
+ "oz",
245
+ "parigp",
246
+ "parser",
247
+ "pascal",
248
+ "pascaligo",
249
+ "pcaxis",
250
+ "peoplecode",
251
+ "perl",
252
+ "php",
253
+ "php-extras",
254
+ "phpdoc",
255
+ "plsql",
256
+ "powerquery",
257
+ "powershell",
258
+ "processing",
259
+ "prolog",
260
+ "promql",
261
+ "properties",
262
+ "protobuf",
263
+ "psl",
264
+ "pug",
265
+ "puppet",
266
+ "pure",
267
+ "purebasic",
268
+ "purescript",
269
+ "python",
270
+ "q",
271
+ "qml",
272
+ "qore",
273
+ "qsharp",
274
+ "r",
275
+ "racket",
276
+ "reason",
277
+ "regex",
278
+ "rego",
279
+ "renpy",
280
+ "rest",
281
+ "rip",
282
+ "roboconf",
283
+ "robotframework",
284
+ "ruby",
285
+ "rust",
286
+ "sas",
287
+ "sass",
288
+ "scala",
289
+ "scheme",
290
+ "scss",
291
+ "shell-session",
292
+ "smali",
293
+ "smalltalk",
294
+ "smarty",
295
+ "sml",
296
+ "solidity",
297
+ "solution-file",
298
+ "soy",
299
+ "sparql",
300
+ "splunk-spl",
301
+ "sqf",
302
+ "sql",
303
+ "squirrel",
304
+ "stan",
305
+ "stylus",
306
+ "swift",
307
+ "systemd",
308
+ "t4-cs",
309
+ "t4-templating",
310
+ "t4-vb",
311
+ "tap",
312
+ "tcl",
313
+ "textile",
314
+ "toml",
315
+ "tremor",
316
+ "tsx",
317
+ "tt2",
318
+ "turtle",
319
+ "twig",
320
+ "typescript",
321
+ "typoscript",
322
+ "unrealscript",
323
+ "uorazor",
324
+ "uri",
325
+ "v",
326
+ "vala",
327
+ "vbnet",
328
+ "velocity",
329
+ "verilog",
330
+ "vhdl",
331
+ "vim",
332
+ "visual-basic",
333
+ "warpscript",
334
+ "wasm",
335
+ "web-idl",
336
+ "wiki",
337
+ "wolfram",
338
+ "wren",
339
+ "xeora",
340
+ "xml-doc",
341
+ "xojo",
342
+ "xquery",
343
+ "yaml",
344
+ "yang",
345
+ "zig",
346
+ ]
17
347
 
18
348
 
19
349
  class CodeBlock(Component):
@@ -21,13 +351,15 @@ class CodeBlock(Component):
21
351
 
22
352
  library = "react-syntax-highlighter@15.5.0"
23
353
 
24
- tag = "Prism"
354
+ tag = "PrismAsyncLight"
355
+
356
+ alias = "SyntaxHighlighter"
25
357
 
26
358
  # The theme to use ("light" or "dark").
27
- theme: Var[LiteralTheme]
359
+ theme: Var[LiteralCodeBlockTheme] = "one-light" # type: ignore
28
360
 
29
361
  # The language to use.
30
- language: Var[str]
362
+ language: Var[LiteralCodeLanguage] = "python" # type: ignore
31
363
 
32
364
  # If this is enabled line numbers will be shown next to the code block.
33
365
  show_line_numbers: Var[bool]
@@ -46,13 +378,43 @@ class CodeBlock(Component):
46
378
 
47
379
  def _get_imports(self) -> imports.ImportDict:
48
380
  merged_imports = super()._get_imports()
49
- if self.theme is not None:
381
+ merged_imports = imports.merge_imports(
382
+ merged_imports,
383
+ {
384
+ f"react-syntax-highlighter/dist/cjs/styles/prism/{self.theme._var_name}": {
385
+ ImportVar(
386
+ tag=format.to_camel_case(self.theme._var_name),
387
+ is_default=True,
388
+ install=False,
389
+ )
390
+ }
391
+ },
392
+ )
393
+ if (
394
+ self.language is not None
395
+ and self.language._var_name in LiteralCodeLanguage.__args__ # type: ignore
396
+ ):
50
397
  merged_imports = imports.merge_imports(
51
398
  merged_imports,
52
- {PRISM_STYLES_PATH: {ImportVar(tag=self.theme._var_name)}},
399
+ {
400
+ f"react-syntax-highlighter/dist/cjs/languages/prism/{self.language._var_name}": {
401
+ ImportVar(
402
+ tag=format.to_camel_case(self.language._var_name),
403
+ is_default=True,
404
+ install=False,
405
+ )
406
+ }
407
+ },
53
408
  )
54
409
  return merged_imports
55
410
 
411
+ def _get_custom_code(self) -> Optional[str]:
412
+ if (
413
+ self.language is not None
414
+ and self.language._var_name in LiteralCodeLanguage.__args__ # type: ignore
415
+ ):
416
+ return f"{self.alias}.registerLanguage('{self.language._var_name}', {format.to_camel_case(self.language._var_name)})"
417
+
56
418
  @classmethod
57
419
  def create(
58
420
  cls,
@@ -75,6 +437,17 @@ class CodeBlock(Component):
75
437
  # This component handles style in a special prop.
76
438
  custom_style = props.pop("custom_style", {})
77
439
 
440
+ # react-syntax-highlighter doesnt have an explicit "light" or "dark" theme so we use one-light and one-dark
441
+ # themes respectively to ensure code compatibility.
442
+ if "theme" in props:
443
+ props["theme"] = (
444
+ "one-light"
445
+ if props["theme"] == "light"
446
+ else "one-dark"
447
+ if props["theme"] == "dark"
448
+ else props["theme"]
449
+ )
450
+
78
451
  if can_copy:
79
452
  code = children[0]
80
453
  copy_button = ( # type: ignore
@@ -112,10 +485,11 @@ class CodeBlock(Component):
112
485
 
113
486
  def _render(self):
114
487
  out = super()._render()
115
- if self.theme is not None:
116
- out.add_props(
117
- style=Var.create(self.theme._var_name, _var_is_local=False)
118
- ).remove_props("theme")
488
+ out.add_props(
489
+ style=Var.create(
490
+ format.to_camel_case(self.theme._var_name), _var_is_local=False
491
+ )
492
+ ).remove_props("theme")
119
493
  return out
120
494
 
121
495