flet-routing 1.0.0__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.
- flet_routing/__init__.py +28 -0
- flet_routing/builtin/__init__.py +9 -0
- flet_routing/builtin/middlewares/logger.py +16 -0
- flet_routing/builtin/views/not_auth.py +35 -0
- flet_routing/builtin/views/not_found.py +35 -0
- flet_routing/components/__init__.py +7 -0
- flet_routing/components/base_view.py +110 -0
- flet_routing/components/middleware.py +3 -0
- flet_routing/components/middleware_base.py +13 -0
- flet_routing/py.typed +0 -0
- flet_routing/router.py +629 -0
- flet_routing/types/__init__.py +19 -0
- flet_routing/types/types.py +47 -0
- flet_routing-1.0.0.dist-info/METADATA +617 -0
- flet_routing-1.0.0.dist-info/RECORD +17 -0
- flet_routing-1.0.0.dist-info/WHEEL +5 -0
- flet_routing-1.0.0.dist-info/top_level.txt +1 -0
flet_routing/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from .router import FletRouter, FletRouterError
|
|
2
|
+
from .types import (
|
|
3
|
+
AuthChecker,
|
|
4
|
+
Middleware,
|
|
5
|
+
MiddlewareContext,
|
|
6
|
+
Params,
|
|
7
|
+
Route,
|
|
8
|
+
RouteEntry,
|
|
9
|
+
ViewFactory,
|
|
10
|
+
)
|
|
11
|
+
from .components import BaseView, MiddlewareBase
|
|
12
|
+
from .builtin import build_not_auth_view, build_not_found_view
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"FletRouter",
|
|
16
|
+
"FletRouterError",
|
|
17
|
+
"AuthChecker",
|
|
18
|
+
"Middleware",
|
|
19
|
+
"MiddlewareContext",
|
|
20
|
+
"MiddlewareBase",
|
|
21
|
+
"Params",
|
|
22
|
+
"Route",
|
|
23
|
+
"RouteEntry",
|
|
24
|
+
"ViewFactory",
|
|
25
|
+
"BaseView",
|
|
26
|
+
"build_not_auth_view",
|
|
27
|
+
"build_not_found_view",
|
|
28
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ...types.types import MiddlewareContext
|
|
4
|
+
from ...components import MiddlewareBase
|
|
5
|
+
|
|
6
|
+
class LoggerMiddleware(MiddlewareBase):
|
|
7
|
+
def __call__(self, ctx: 'MiddlewareContext'):
|
|
8
|
+
print("-----------------------------------")
|
|
9
|
+
print(f"[LOG]: Route -> {ctx.route}")
|
|
10
|
+
print(f"[LOG]: Private -> {ctx.private}")
|
|
11
|
+
print(f"[LOG]: Path -> {ctx.path}")
|
|
12
|
+
print(f"[LOG]: Params -> {ctx.params}")
|
|
13
|
+
print(f"[LOG]: Full Path -> {ctx.full_path}")
|
|
14
|
+
print(f"[LOG]: Router -> {ctx.router}")
|
|
15
|
+
print("-----------------------------------")
|
|
16
|
+
return True
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from flet import (
|
|
2
|
+
Column,
|
|
3
|
+
Colors,
|
|
4
|
+
Container,
|
|
5
|
+
CrossAxisAlignment,
|
|
6
|
+
FontWeight,
|
|
7
|
+
Icon,
|
|
8
|
+
Icons,
|
|
9
|
+
MainAxisAlignment,
|
|
10
|
+
Text,
|
|
11
|
+
View,
|
|
12
|
+
alignment,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def build_not_auth_view() -> View:
|
|
16
|
+
return View(
|
|
17
|
+
route="/401",
|
|
18
|
+
controls=[
|
|
19
|
+
Container(
|
|
20
|
+
content=Column(
|
|
21
|
+
controls=[
|
|
22
|
+
Icon(Icons.LOCK, size=80, color=Colors.RED_400),
|
|
23
|
+
Text("401 - Unauthorized", size=30, weight=FontWeight.BOLD),
|
|
24
|
+
Text("You don't have permission to access this page.", size=16),
|
|
25
|
+
],
|
|
26
|
+
horizontal_alignment=CrossAxisAlignment.CENTER,
|
|
27
|
+
spacing=20,
|
|
28
|
+
),
|
|
29
|
+
alignment=alignment.center,
|
|
30
|
+
expand=True,
|
|
31
|
+
),
|
|
32
|
+
],
|
|
33
|
+
horizontal_alignment=CrossAxisAlignment.CENTER,
|
|
34
|
+
vertical_alignment=MainAxisAlignment.CENTER,
|
|
35
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from flet import (
|
|
2
|
+
View,
|
|
3
|
+
Container,
|
|
4
|
+
Column,
|
|
5
|
+
Icon,
|
|
6
|
+
Icons,
|
|
7
|
+
Colors,
|
|
8
|
+
Text,
|
|
9
|
+
CrossAxisAlignment,
|
|
10
|
+
FontWeight,
|
|
11
|
+
MainAxisAlignment,
|
|
12
|
+
alignment
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def build_not_found_view() -> View:
|
|
16
|
+
return View(
|
|
17
|
+
route="/404",
|
|
18
|
+
controls=[
|
|
19
|
+
Container(
|
|
20
|
+
content=Column(
|
|
21
|
+
controls=[
|
|
22
|
+
Icon(Icons.ERROR_OUTLINE, size=80, color=Colors.RED_400),
|
|
23
|
+
Text("404 - Page Not Found", size=30, weight=FontWeight.BOLD),
|
|
24
|
+
Text("The page you're looking for doesn't exist.", size=16),
|
|
25
|
+
],
|
|
26
|
+
horizontal_alignment=CrossAxisAlignment.CENTER,
|
|
27
|
+
spacing=20,
|
|
28
|
+
),
|
|
29
|
+
alignment=alignment.center,
|
|
30
|
+
expand=True,
|
|
31
|
+
),
|
|
32
|
+
],
|
|
33
|
+
horizontal_alignment=CrossAxisAlignment.CENTER,
|
|
34
|
+
vertical_alignment=MainAxisAlignment.CENTER,
|
|
35
|
+
)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Sequence
|
|
4
|
+
|
|
5
|
+
from flet import (
|
|
6
|
+
AppBar,
|
|
7
|
+
BottomAppBar,
|
|
8
|
+
ColorValue,
|
|
9
|
+
Colors,
|
|
10
|
+
Control,
|
|
11
|
+
ControlEvent,
|
|
12
|
+
CupertinoAppBar,
|
|
13
|
+
CupertinoNavigationBar,
|
|
14
|
+
FloatingActionButton,
|
|
15
|
+
FloatingActionButtonLocation,
|
|
16
|
+
Icon,
|
|
17
|
+
IconButton,
|
|
18
|
+
Icons,
|
|
19
|
+
MainAxisAlignment,
|
|
20
|
+
NavigationBar,
|
|
21
|
+
NavigationDrawer,
|
|
22
|
+
OffsetValue,
|
|
23
|
+
OptionalControlEventCallable,
|
|
24
|
+
OptionalEventCallable,
|
|
25
|
+
OptionalNumber,
|
|
26
|
+
OnScrollEvent,
|
|
27
|
+
PaddingValue,
|
|
28
|
+
ScrollMode,
|
|
29
|
+
Text,
|
|
30
|
+
View,
|
|
31
|
+
)
|
|
32
|
+
from flet import *
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class BaseView(View):
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
router: Optional['FletRouter'] = None,
|
|
39
|
+
route: str | None = None,
|
|
40
|
+
controls: Sequence[Control] | None = None,
|
|
41
|
+
appbar: AppBar | CupertinoAppBar | None = None,
|
|
42
|
+
bottom_appbar: BottomAppBar | None = None,
|
|
43
|
+
floating_action_button: FloatingActionButton | None = None,
|
|
44
|
+
floating_action_button_location: OffsetValue | FloatingActionButtonLocation = None,
|
|
45
|
+
navigation_bar: NavigationBar | CupertinoNavigationBar | None = None,
|
|
46
|
+
drawer: NavigationDrawer | None = None,
|
|
47
|
+
end_drawer: NavigationDrawer | None = None,
|
|
48
|
+
vertical_alignment: MainAxisAlignment | None = None,
|
|
49
|
+
horizontal_alignment: CrossAxisAlignment | None = None,
|
|
50
|
+
spacing: OptionalNumber = None,
|
|
51
|
+
padding: PaddingValue | None = None,
|
|
52
|
+
bgcolor: ColorValue | None = None,
|
|
53
|
+
decoration: BoxDecoration | None = None,
|
|
54
|
+
foreground_decoration: BoxDecoration | None = None,
|
|
55
|
+
can_pop: bool | None = None,
|
|
56
|
+
on_confirm_pop: OptionalControlEventCallable = None,
|
|
57
|
+
scroll: ScrollMode | None = None,
|
|
58
|
+
auto_scroll: bool | None = None,
|
|
59
|
+
fullscreen_dialog: bool | None = None,
|
|
60
|
+
on_scroll_interval: OptionalNumber = None,
|
|
61
|
+
on_scroll: OptionalEventCallable[OnScrollEvent] = None,
|
|
62
|
+
adaptive: bool | None = None
|
|
63
|
+
):
|
|
64
|
+
super().__init__(
|
|
65
|
+
route=route,
|
|
66
|
+
controls=controls,
|
|
67
|
+
appbar=appbar,
|
|
68
|
+
bottom_appbar=bottom_appbar,
|
|
69
|
+
floating_action_button=floating_action_button,
|
|
70
|
+
floating_action_button_location=floating_action_button_location,
|
|
71
|
+
navigation_bar=navigation_bar,
|
|
72
|
+
drawer=drawer,
|
|
73
|
+
end_drawer=end_drawer,
|
|
74
|
+
vertical_alignment=vertical_alignment,
|
|
75
|
+
horizontal_alignment=horizontal_alignment,
|
|
76
|
+
spacing=spacing,
|
|
77
|
+
padding=padding,
|
|
78
|
+
bgcolor=bgcolor,
|
|
79
|
+
decoration=decoration,
|
|
80
|
+
foreground_decoration=foreground_decoration,
|
|
81
|
+
can_pop=can_pop,
|
|
82
|
+
on_confirm_pop=on_confirm_pop,
|
|
83
|
+
scroll=scroll,
|
|
84
|
+
auto_scroll=auto_scroll,
|
|
85
|
+
fullscreen_dialog=fullscreen_dialog,
|
|
86
|
+
on_scroll_interval=on_scroll_interval,
|
|
87
|
+
on_scroll=on_scroll,
|
|
88
|
+
adaptive=adaptive,
|
|
89
|
+
)
|
|
90
|
+
self.__router = router
|
|
91
|
+
|
|
92
|
+
def build(self):
|
|
93
|
+
if not self.appbar:
|
|
94
|
+
self.appbar = AppBar(
|
|
95
|
+
leading=IconButton(
|
|
96
|
+
icon=Icons.ARROW_BACK,
|
|
97
|
+
on_click=self.pop,
|
|
98
|
+
visible=bool(self.page.views)
|
|
99
|
+
),
|
|
100
|
+
title=Text(self.route.replace("/", "") or "App")
|
|
101
|
+
)
|
|
102
|
+
return super().build()
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def router(self) -> 'FletRouter':
|
|
106
|
+
return self.__router
|
|
107
|
+
|
|
108
|
+
@router.setter
|
|
109
|
+
def router(self, new: 'FletRouter') -> None:
|
|
110
|
+
self.__router = new
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from ..types import MiddlewareContext
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MiddlewareBase:
|
|
5
|
+
"""Base class for class‑based middlewares.
|
|
6
|
+
|
|
7
|
+
Subclass this and implement ``__call__(self, ctx: MiddlewareContext) -> bool``.
|
|
8
|
+
Instances of the subclass can be registered with :meth:`use` just like a
|
|
9
|
+
plain callable middleware.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __call__(self, ctx: 'MiddlewareContext') -> bool: # pragma: no cover
|
|
13
|
+
raise NotImplementedError("MiddlewareBase subclasses must implement __call__")
|
flet_routing/py.typed
ADDED
|
File without changes
|