|
25 | 25 | from django.db.models.query import QuerySet
|
26 | 26 | from django.http import HttpRequest, HttpResponse
|
27 | 27 | from django.template import engines
|
| 28 | +from django.templatetags.static import static |
28 | 29 | from django.utils.encoding import smart_str
|
29 | 30 | from django.views import View
|
30 | 31 | from reactpy import vdom_to_html
|
|
62 | 63 | PYSCRIPT_LAYOUT_HANDLER = (
|
63 | 64 | Path(__file__).parent / "pyscript" / "layout_handler.py"
|
64 | 65 | ).read_text(encoding="utf-8")
|
65 |
| -PYSCRIPT_DEFAULT_CONFIG = { |
66 |
| - "packages": [ |
67 |
| - f"reactpy=={reactpy.__version__}", |
68 |
| - f"jsonpointer=={jsonpointer.__version__}", |
69 |
| - "ssl", |
70 |
| - ] |
71 |
| -} |
| 66 | +PYSCRIPT_DEFAULT_CONFIG: dict[str, Any] = {} |
72 | 67 |
|
73 | 68 |
|
74 | 69 | async def render_view(
|
@@ -503,6 +498,22 @@ def render_pyscript_template(file_paths: Sequence[str], uuid: str, root: str):
|
503 | 498 |
|
504 | 499 | def extend_pyscript_config(config: dict | str, extra_packages: Sequence) -> str:
|
505 | 500 | """Extends ReactPy's default PyScript config with user provided values."""
|
| 501 | + if not PYSCRIPT_DEFAULT_CONFIG: |
| 502 | + # Need to perform this lazily in order to wait for static files to be available |
| 503 | + PYSCRIPT_DEFAULT_CONFIG.update( |
| 504 | + { |
| 505 | + "packages": [ |
| 506 | + f"reactpy=={reactpy.__version__}", |
| 507 | + f"jsonpointer=={jsonpointer.__version__}", |
| 508 | + "ssl", |
| 509 | + ], |
| 510 | + "js_modules": { |
| 511 | + "main": { |
| 512 | + static("reactpy_django/morphdom/morphdom-esm.js"): "morphdom" |
| 513 | + } |
| 514 | + }, |
| 515 | + } |
| 516 | + ) |
506 | 517 | pyscript_config = deepcopy(PYSCRIPT_DEFAULT_CONFIG)
|
507 | 518 | pyscript_config["packages"].extend(extra_packages)
|
508 | 519 | if config and isinstance(config, str):
|
|
0 commit comments