diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0dc2182..2673841 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 hooks: - # - id: no-commit-to-branch + - id: no-commit-to-branch - id: check-yaml args: ['--unsafe'] - id: check-toml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..286f4f1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 to present Samuel Colvin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d29303f --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# FastUI + +WIP diff --git a/demo/server/main.py b/demo/server.py similarity index 83% rename from demo/server/main.py rename to demo/server.py index 287ba12..63b7dd1 100644 --- a/demo/server/main.py +++ b/demo/server.py @@ -3,20 +3,15 @@ from __future__ import annotations as _annotations from datetime import date from fastapi import FastAPI -from pydantic import RootModel, BaseModel, Field +from pydantic import BaseModel, Field -import components as c -from components import AnyComponent -from components.events import PageEvent, GoToEvent +from fastui import components as c +from fastui import FastUI app = FastAPI() -class FastUi(RootModel): - root: AnyComponent - - -@app.get('/api/', response_model=FastUi, response_model_exclude_none=True) +@app.get('/api/', response_model=FastUI, response_model_exclude_none=True) def read_root() -> AnyComponent: return c.Page( children=[ @@ -44,7 +39,7 @@ class MyTableRow(BaseModel): enabled: bool | None = None -@app.get('/api/table', response_model=FastUi, response_model_exclude_none=True) +@app.get('/api/table', response_model=FastUI, response_model_exclude_none=True) def read_foo() -> AnyComponent: return c.Page( children=[ diff --git a/demo/tsconfig.json b/demo/tsconfig.json index 2ff3191..170a281 100644 --- a/demo/tsconfig.json +++ b/demo/tsconfig.json @@ -20,7 +20,7 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "paths": { - "fastui": ["../frontend/fastui"] + "fastui": ["../react/fastui"] } }, "include": ["src"], diff --git a/demo/vite.config.ts b/demo/vite.config.ts index 3be1061..da1827c 100644 --- a/demo/vite.config.ts +++ b/demo/vite.config.ts @@ -17,7 +17,7 @@ export default () => { resolve: { alias: { '@': path.resolve(__dirname, './src'), - fastui: path.resolve(__dirname, '../frontend/fastui'), + fastui: path.resolve(__dirname, '../react/fastui'), }, }, server: serverConfig, diff --git a/package.json b/package.json index 5eed218..cf779fc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "typecheck": "tsc --noEmit", "build": "tsc", "typewatch": "tsc --noEmit --watch", - "lint": "eslint frontend --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0", + "lint": "eslint react --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0", "lint-fix": "npm run lint -- --fix", "prettier": "prettier --write", "format": "npm run prettier -- . && npm run lint-fix" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..33118b7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,49 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.sdist] +include = ["python"] + +[tool.hatch.build.targets.wheel] +packages = ["python/fastui"] + +[tool.hatch.version] +path = "python/fastui/__init__.py" + +[project] +name = "fastui" +description = "Build UIs fast." +authors = [{ name = "Samuel Colvin", email = "s@muelcolvin.com" }] +license = "MIT" +readme = "README.md" +classifiers = [ + "Development Status :: 4 - Beta", + "Topic :: Internet", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + 'Programming Language :: Python :: 3 :: Only', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", +] +requires-python = ">=3.8" +dependencies = [ + "pydantic>=2.5.0b1", + "fastapi>=0.104.0", +] +dynamic = ["version"] + +[project.urls] +Homepage = "https://github.com/samuelcolvin/fastui" + + +[tool.ruff] +line-length = 120 +extend-select = ["Q", "RUF100", "UP", "I"] +flake8-quotes = {inline-quotes = "single", multiline-quotes = "double"} +target-version = "py38" diff --git a/python/fastui/__init__.py b/python/fastui/__init__.py new file mode 100644 index 0000000..a1e2ec0 --- /dev/null +++ b/python/fastui/__init__.py @@ -0,0 +1,8 @@ +__version__ = '0.0.1' + +from pydantic import RootModel +from .components import AnyComponent + + +class FastUI(RootModel): + root: AnyComponent diff --git a/demo/server/components/__init__.py b/python/fastui/components/__init__.py similarity index 100% rename from demo/server/components/__init__.py rename to python/fastui/components/__init__.py diff --git a/demo/server/components/events.py b/python/fastui/components/events.py similarity index 100% rename from demo/server/components/events.py rename to python/fastui/components/events.py diff --git a/demo/server/components/extra.py b/python/fastui/components/extra.py similarity index 100% rename from demo/server/components/extra.py rename to python/fastui/components/extra.py diff --git a/demo/server/components/table.py b/python/fastui/components/table.py similarity index 100% rename from demo/server/components/table.py rename to python/fastui/components/table.py diff --git a/frontend/fastui/DefaultLoading.tsx b/react/fastui/DefaultLoading.tsx similarity index 100% rename from frontend/fastui/DefaultLoading.tsx rename to react/fastui/DefaultLoading.tsx diff --git a/frontend/fastui/components/FormField.tsx b/react/fastui/components/FormField.tsx similarity index 100% rename from frontend/fastui/components/FormField.tsx rename to react/fastui/components/FormField.tsx diff --git a/frontend/fastui/components/Json.tsx b/react/fastui/components/Json.tsx similarity index 100% rename from frontend/fastui/components/Json.tsx rename to react/fastui/components/Json.tsx diff --git a/frontend/fastui/components/button.tsx b/react/fastui/components/button.tsx similarity index 100% rename from frontend/fastui/components/button.tsx rename to react/fastui/components/button.tsx diff --git a/frontend/fastui/components/display.tsx b/react/fastui/components/display.tsx similarity index 100% rename from frontend/fastui/components/display.tsx rename to react/fastui/components/display.tsx diff --git a/frontend/fastui/components/div.tsx b/react/fastui/components/div.tsx similarity index 100% rename from frontend/fastui/components/div.tsx rename to react/fastui/components/div.tsx diff --git a/frontend/fastui/components/heading.tsx b/react/fastui/components/heading.tsx similarity index 100% rename from frontend/fastui/components/heading.tsx rename to react/fastui/components/heading.tsx diff --git a/frontend/fastui/components/index.tsx b/react/fastui/components/index.tsx similarity index 100% rename from frontend/fastui/components/index.tsx rename to react/fastui/components/index.tsx diff --git a/frontend/fastui/components/link.tsx b/react/fastui/components/link.tsx similarity index 100% rename from frontend/fastui/components/link.tsx rename to react/fastui/components/link.tsx diff --git a/frontend/fastui/components/modal.css b/react/fastui/components/modal.css similarity index 100% rename from frontend/fastui/components/modal.css rename to react/fastui/components/modal.css diff --git a/frontend/fastui/components/modal.tsx b/react/fastui/components/modal.tsx similarity index 100% rename from frontend/fastui/components/modal.tsx rename to react/fastui/components/modal.tsx diff --git a/frontend/fastui/components/table.tsx b/react/fastui/components/table.tsx similarity index 100% rename from frontend/fastui/components/table.tsx rename to react/fastui/components/table.tsx diff --git a/frontend/fastui/components/text.tsx b/react/fastui/components/text.tsx similarity index 100% rename from frontend/fastui/components/text.tsx rename to react/fastui/components/text.tsx diff --git a/frontend/fastui/controller.tsx b/react/fastui/controller.tsx similarity index 100% rename from frontend/fastui/controller.tsx rename to react/fastui/controller.tsx diff --git a/frontend/fastui/display.ts b/react/fastui/display.ts similarity index 100% rename from frontend/fastui/display.ts rename to react/fastui/display.ts diff --git a/frontend/fastui/hooks/className.ts b/react/fastui/hooks/className.ts similarity index 100% rename from frontend/fastui/hooks/className.ts rename to react/fastui/hooks/className.ts diff --git a/frontend/fastui/hooks/customRender.ts b/react/fastui/hooks/customRender.ts similarity index 100% rename from frontend/fastui/hooks/customRender.ts rename to react/fastui/hooks/customRender.ts diff --git a/frontend/fastui/hooks/error.tsx b/react/fastui/hooks/error.tsx similarity index 100% rename from frontend/fastui/hooks/error.tsx rename to react/fastui/hooks/error.tsx diff --git a/frontend/fastui/hooks/event.ts b/react/fastui/hooks/event.ts similarity index 100% rename from frontend/fastui/hooks/event.ts rename to react/fastui/hooks/event.ts diff --git a/frontend/fastui/hooks/locationContext.tsx b/react/fastui/hooks/locationContext.tsx similarity index 100% rename from frontend/fastui/hooks/locationContext.tsx rename to react/fastui/hooks/locationContext.tsx diff --git a/frontend/fastui/index.tsx b/react/fastui/index.tsx similarity index 100% rename from frontend/fastui/index.tsx rename to react/fastui/index.tsx diff --git a/tsconfig.json b/tsconfig.json index 58064ef..daece3b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "outDir": "./frontend-dist", + "outDir": "./react-dist", "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], @@ -20,5 +20,5 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["frontend"] + "include": ["react"] }