diff --git a/.gitignore b/.gitignore index d7b30f1..c356ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ .pyc __pycache__/ *.egg-info +build +dist diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ff46f77 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include inst * diff --git a/pyproject.toml b/pyproject.toml index 1126387..bbc5e57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,20 @@ [project] -name = "shiny-router" -version = "0.1.0" +name = "shiny_router" +version = "0.1.3" description = "Add your description here" readme = "README.md" requires-python = ">=3.12" dependencies = [ "pandas", "shiny", + "shiny-router", ] + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.package-data] +"shiny_router" = ["www/*"] + +[tool.uv.sources] +shiny-router = { workspace = true } diff --git a/src/shiny_router/__init__.py b/src/shiny_router/__init__.py index b1cd8c2..52ba3ea 100644 --- a/src/shiny_router/__init__.py +++ b/src/shiny_router/__init__.py @@ -1,4 +1,4 @@ from .router import route_link, router_ui, route, router_server def hello() -> str: - return "Hello from shiny-router!" + return "Hello from shiny_router!" diff --git a/src/shiny_router/router.py b/src/shiny_router/router.py index 2e7ee4b..fff116b 100644 --- a/src/shiny_router/router.py +++ b/src/shiny_router/router.py @@ -1,6 +1,7 @@ from shiny import ui, reactive from htmltools import HTMLDependency from pathlib import PurePath +from urllib.parse import urlparse, parse_qs log_msg = print PAGE_404_ROUTE = "404" @@ -36,15 +37,22 @@ def router_callback(input, output, session=None, **kwargs): query = None, unparsed = root )) + @reactive.effect @reactive.event(input._clientdata_url_hash) def _(): requested_path = input._clientdata_url_hash() - clean_path = requested_path[3:] if requested_path.startswith("#!/") else requested_path - # TODO: Below simplifies and is incorrect: + parsed_url = urlparse(requested_path) + fragment_path = urlparse(parsed_url.fragment) + clean_path = fragment_path.path.lstrip("!").lstrip("/") + query_params = parse_qs(fragment_path.query) + + print("Path:", clean_path) + print("Query Parameters:", query_params) + input.shiny_router_page.set(dict( - path = clean_path if clean_path else root, - query = None, + path = clean_path, + query = query_params, unparsed = requested_path, )) @@ -109,7 +117,7 @@ def router_ui_internal(router): pkg_dependency = HTMLDependency("shiny_router", "0.0.1", source={ "package": "shiny_router", - "subdir": str(PurePath(__file__).parent.parent.parent / "inst" / "www"), + "subdir": str(PurePath(__file__).parent / "www"), }, script={"src": js_file, "type": "module"}, stylesheet={"href": css_file} diff --git a/src/shiny_router/www b/src/shiny_router/www new file mode 120000 index 0000000..620a902 --- /dev/null +++ b/src/shiny_router/www @@ -0,0 +1 @@ +../../inst/www \ No newline at end of file diff --git a/uv.lock b/uv.lock index 1b1bd25..ceb8609 100644 --- a/uv.lock +++ b/uv.lock @@ -339,7 +339,7 @@ wheels = [ [[distribution]] name = "shiny-router" -version = "0.1.0" +version = "0.1.2" source = { editable = "." } dependencies = [ { name = "pandas" },