diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..356385d78 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 +end_of_line = lf + +[*.py] +indent_size = 4 +max_line_length = 120 + +[*.md] +indent_size = 4 + +[*.html] +max_line_length = off + +[*.js] +max_line_length = off + +[*.css] +indent_size = 4 +max_line_length = off + +# Tests can violate line width restrictions in the interest of clarity. +[**/test_*.py] +max_line_length = off diff --git a/src/js/app/package.json b/src/js/app/package.json index cecc15083..f3b7a1cf7 100644 --- a/src/js/app/package.json +++ b/src/js/app/package.json @@ -3,9 +3,9 @@ "license": "MIT", "main": "src/dist/index.js", "types": "src/dist/index.d.ts", - "description": "A client application for ReactPy implemented in React", + "description": "Main entry point for ReactPy.", "dependencies": { - "@reactpy/client": "^0.2.0", + "@reactpy/client": "file:../packages/@reactpy/client", "preact": "^10.7.0" }, "devDependencies": { diff --git a/src/js/package-lock.json b/src/js/package-lock.json index 83d0d5c08..924f59171 100644 --- a/src/js/package-lock.json +++ b/src/js/package-lock.json @@ -21,7 +21,7 @@ "app": { "license": "MIT", "dependencies": { - "@reactpy/client": "^0.2.0", + "@reactpy/client": "file:../packages/@reactpy/client", "preact": "^10.7.0" }, "devDependencies": { @@ -31,19 +31,6 @@ "vite": "^3.2.11" } }, - "app/node_modules/@reactpy/client": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@reactpy/client/-/client-0.2.1.tgz", - "integrity": "sha512-9sgGH+pJ2BpLT+QSVe7FQLS2VQ9acHgPlO8X3qiTumGw43O0X82sm8pzya8H8dAew463SeGza/pZc0mpUBHmqA==", - "dependencies": { - "event-to-object": "^0.1.2", - "json-pointer": "^0.6.2" - }, - "peerDependencies": { - "react": ">=16 <18", - "react-dom": ">=16 <18" - } - }, "app/node_modules/typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", @@ -3507,10 +3494,10 @@ } }, "packages/@reactpy/client": { - "version": "0.3.1", + "version": "0.3.2", "license": "MIT", "dependencies": { - "event-to-object": "^0.1.2", + "event-to-object": "file:../event-to-object", "json-pointer": "^0.6.2" }, "devDependencies": { @@ -3524,6 +3511,10 @@ "react-dom": ">=16 <18" } }, + "packages/@reactpy/client/node_modules/event-to-object": { + "resolved": "packages/@reactpy/event-to-object", + "link": true + }, "packages/@reactpy/client/node_modules/typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", @@ -3537,6 +3528,7 @@ "node": ">=4.2.0" } }, + "packages/@reactpy/event-to-object": {}, "packages/app": { "name": "@reactpy/app", "extraneous": true, @@ -3727,11 +3719,14 @@ "@types/json-pointer": "^1.0.31", "@types/react": "^17.0", "@types/react-dom": "^17.0", - "event-to-object": "^0.1.2", + "event-to-object": "file:../event-to-object", "json-pointer": "^0.6.2", "typescript": "^4.9.5" }, "dependencies": { + "event-to-object": { + "version": "file:packages/@reactpy/event-to-object" + }, "typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", @@ -3950,7 +3945,7 @@ "app": { "version": "file:app", "requires": { - "@reactpy/client": "^0.2.0", + "@reactpy/client": "file:../packages/@reactpy/client", "@types/react": "^17.0", "@types/react-dom": "^17.0", "preact": "^10.7.0", @@ -3958,15 +3953,6 @@ "vite": "^3.2.11" }, "dependencies": { - "@reactpy/client": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@reactpy/client/-/client-0.2.1.tgz", - "integrity": "sha512-9sgGH+pJ2BpLT+QSVe7FQLS2VQ9acHgPlO8X3qiTumGw43O0X82sm8pzya8H8dAew463SeGza/pZc0mpUBHmqA==", - "requires": { - "event-to-object": "^0.1.2", - "json-pointer": "^0.6.2" - } - }, "typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", diff --git a/src/js/packages/@reactpy/client/package.json b/src/js/packages/@reactpy/client/package.json index ab4bd34ad..d399f7b91 100644 --- a/src/js/packages/@reactpy/client/package.json +++ b/src/js/packages/@reactpy/client/package.json @@ -6,9 +6,9 @@ "license": "MIT", "name": "@reactpy/client", "type": "module", - "version": "0.3.1", + "version": "0.3.2", "dependencies": { - "event-to-object": "^0.1.2", + "event-to-object": "file:../event-to-object", "json-pointer": "^0.6.2" }, "devDependencies": { diff --git a/src/py/reactpy/.temp.py b/src/py/reactpy/.temp.py deleted file mode 100644 index d8881ad1e..000000000 --- a/src/py/reactpy/.temp.py +++ /dev/null @@ -1,28 +0,0 @@ -from reactpy import component, html, run, use_state -from reactpy.core.types import State - - -@component -def Item(item: str, all_items: State[list[str]]): - color = use_state(None) - - def deleteme(event): - all_items.set_value([i for i in all_items.value if (i != item)]) - - def colorize(event): - color.set_value("blue" if not color.value else None) - - return html.div( - {"id": item, "style": {"background_color": color.value}}, - html.button({"on_click": colorize}, f"Color {item}"), - html.button({"on_click": deleteme}, f"Delete {item}"), - ) - - -@component -def App(): - items = use_state(["A", "B", "C"]) - return html._([Item(item, items, key=item) for item in items.value]) - - -run(App) diff --git a/src/py/reactpy/pyproject.toml b/src/py/reactpy/pyproject.toml index 05d35c8e1..56ad6a7c5 100644 --- a/src/py/reactpy/pyproject.toml +++ b/src/py/reactpy/pyproject.toml @@ -105,18 +105,18 @@ all = ["types"] [tool.hatch.build.targets.sdist] artifacts = ["_static"] +exclude = ["scripts/", "tests/"] [tool.hatch.build.targets.wheel] artifacts = ["_static"] +exclude = ["scripts/", "tests/"] [[tool.hatch.build.hooks.build-scripts.scripts]] -out_dir = "reactpy/_static" commands = [ - # link the js directory if it doesn't exist - use Python to avoid platform differences - "python -c \"import pathlib as p;js=p.Path('js');js.unlink(missing_ok=True);js.symlink_to(p.Path('..','..','js').resolve(),target_is_directory=True);\"", - "cd js && npm ci && npm run build", + "cd .. && cd .. && cd js && npm install && npm run build", + "cd scripts && python copy_js_output.py", ] -artifacts = ["js/app/dist/"] +artifacts = [] # --- Pytest --------------------------------------------------------------------------- diff --git a/src/py/reactpy/reactpy/backend/_common.py b/src/py/reactpy/reactpy/backend/_common.py index 77c9a7ae0..0b7179092 100644 --- a/src/py/reactpy/reactpy/backend/_common.py +++ b/src/py/reactpy/reactpy/backend/_common.py @@ -21,7 +21,7 @@ MODULES_PATH = PATH_PREFIX / "modules" ASSETS_PATH = PATH_PREFIX / "assets" STREAM_PATH = PATH_PREFIX / "stream" -CLIENT_BUILD_DIR = Path(_reactpy_file_path).parent / "_static" / "js" / "app" / "dist" +CLIENT_BUILD_DIR = Path(_reactpy_file_path).parent / "_static" async def serve_with_uvicorn( diff --git a/src/py/reactpy/scripts/copy_js_output.py b/src/py/reactpy/scripts/copy_js_output.py new file mode 100644 index 000000000..5844bbad9 --- /dev/null +++ b/src/py/reactpy/scripts/copy_js_output.py @@ -0,0 +1,8 @@ +from pathlib import Path +from shutil import copytree, rmtree + +output_dir = Path(__file__).parent.parent / "reactpy" / "_static" +source_dir = Path(__file__).parent.parent.parent.parent / "js" / "app" / "dist" +rmtree(output_dir, ignore_errors=True) +copytree(source_dir, output_dir) +print("JavaScript output copied to reactpy/_static") # noqa: T201