instaui 0.1.1__py3-none-any.whl → 0.1.2__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.
- instaui/components/component.py +1 -1
- instaui/components/element.py +37 -17
- instaui/components/html/checkbox.py +0 -7
- instaui/components/vfor.py +1 -1
- instaui/dependencies/component_dependency.py +16 -0
- instaui/dependencies/plugin_dependency.py +28 -0
- instaui/fastapi_server/debug_mode_router.py +0 -1
- instaui/fastapi_server/dependency_router.py +21 -0
- instaui/fastapi_server/resource.py +35 -0
- instaui/fastapi_server/server.py +124 -100
- instaui/html_tools.py +12 -106
- instaui/page_info.py +1 -11
- instaui/runtime/_app.py +9 -20
- instaui/runtime/resource.py +11 -46
- instaui/static/insta-ui.esm-browser.prod.js +3663 -3663
- instaui/static/insta-ui.iife.js +29 -29
- instaui/static/templates/web.html +32 -76
- instaui/static/templates/zero.html +48 -32
- instaui/systems/file_system.py +0 -9
- instaui/template/web_template.py +40 -46
- instaui/template/zero_template.py +100 -15
- instaui/ui/__init__.py +2 -5
- instaui/ui_functions/ui_page.py +3 -18
- instaui/vars/path_var.py +2 -1
- instaui/zero/func.py +111 -0
- instaui/zero/scope.py +12 -1
- {instaui-0.1.1.dist-info → instaui-0.1.2.dist-info}/METADATA +1 -1
- {instaui-0.1.1.dist-info → instaui-0.1.2.dist-info}/RECORD +30 -29
- instaui/dependencies/__init__.py +0 -15
- instaui/dependencies/component_registrar.py +0 -82
- instaui/dependencies/installer.py +0 -5
- instaui/fastapi_server/config_router.py +0 -60
- {instaui-0.1.1.dist-info → instaui-0.1.2.dist-info}/LICENSE +0 -0
- {instaui-0.1.1.dist-info → instaui-0.1.2.dist-info}/WHEEL +0 -0
instaui/html_tools.py
CHANGED
@@ -1,50 +1,39 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
from pathlib import Path
|
3
|
-
from typing import Dict, Literal, Optional, Union
|
4
|
-
import instaui.consts as consts
|
3
|
+
from typing import Any, Dict, Literal, Optional, Union
|
5
4
|
from instaui.common.jsonable import dumps, dumps2dict
|
6
|
-
from instaui.runtime import get_app_slot
|
7
|
-
from instaui.template import render_zero_html
|
5
|
+
from instaui.runtime._app import get_app_slot
|
8
6
|
|
9
7
|
|
10
|
-
def add_css_link(href: Union[str, Path]
|
11
|
-
if shared:
|
12
|
-
HtmlResource.default_css_link(href)
|
13
|
-
|
8
|
+
def add_css_link(href: Union[str, Path]):
|
14
9
|
get_app_slot()._html_resource.add_css_link(href)
|
15
10
|
|
16
11
|
|
17
12
|
def add_js_link(
|
18
13
|
link: Union[str, Path],
|
19
14
|
*,
|
20
|
-
|
21
|
-
type: Optional[Literal["module", "importmap"]] = None,
|
15
|
+
type: Optional[Literal["module"]] = None,
|
22
16
|
):
|
23
17
|
attrs = {
|
24
18
|
"type": type,
|
25
19
|
}
|
26
20
|
|
27
|
-
if shared:
|
28
|
-
HtmlResource.default_js_link(link, attrs=attrs)
|
29
|
-
|
30
21
|
get_app_slot()._html_resource.add_js_link(link, attrs=attrs)
|
31
22
|
|
32
23
|
|
33
|
-
def add_style(content: str
|
34
|
-
if shared:
|
35
|
-
HtmlResource.default_style_tag(content)
|
24
|
+
def add_style(content: str):
|
36
25
|
get_app_slot()._html_resource.add_style_tag(content)
|
37
26
|
|
38
27
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
def use_tailwind(value=True):
|
29
|
+
get_app_slot()._html_resource.use_tailwind = value
|
30
|
+
|
31
|
+
|
32
|
+
def add_js_code(code: str, *, script_attrs: Optional[Dict[str, Any]] = None):
|
33
|
+
get_app_slot()._html_resource.add_script_tag(code, script_attrs=script_attrs)
|
43
34
|
|
44
35
|
|
45
|
-
def add_vue_app_use(name: str
|
46
|
-
if shared:
|
47
|
-
HtmlResource.default_vue_app_use(name)
|
36
|
+
def add_vue_app_use(name: str):
|
48
37
|
get_app_slot()._html_resource.add_vue_app_use(name)
|
49
38
|
|
50
39
|
|
@@ -54,86 +43,3 @@ def to_config_data() -> Dict:
|
|
54
43
|
|
55
44
|
def to_json(indent=False):
|
56
45
|
return dumps(get_app_slot(), indent=indent)
|
57
|
-
|
58
|
-
|
59
|
-
def to_html(file: Union[str, Path]):
|
60
|
-
if isinstance(file, str):
|
61
|
-
import inspect
|
62
|
-
|
63
|
-
frame = inspect.currentframe().f_back # type: ignore
|
64
|
-
assert frame is not None
|
65
|
-
script_file = inspect.getfile(frame)
|
66
|
-
file = Path(script_file).parent.joinpath(file)
|
67
|
-
|
68
|
-
file = Path(file)
|
69
|
-
system_slot = get_app_slot()
|
70
|
-
html_resource = system_slot._html_resource
|
71
|
-
|
72
|
-
if html_resource.use_tailwind:
|
73
|
-
html_resource.add_js_link(consts.TAILWIND_JS_PATH, insert_before=0)
|
74
|
-
html_resource.add_js_link(consts.APP_IIFE_JS_PATH, insert_before=0)
|
75
|
-
html_resource.add_js_link(consts.VUE_IIFE_JS_PATH, insert_before=0)
|
76
|
-
html_resource.add_css_link(consts.APP_CSS_PATH)
|
77
|
-
|
78
|
-
# register custom components
|
79
|
-
for component in system_slot._js_components:
|
80
|
-
if not component.iife:
|
81
|
-
continue
|
82
|
-
|
83
|
-
html_resource.add_js_link(component.iife)
|
84
|
-
|
85
|
-
if component.css:
|
86
|
-
for css_link in component.css:
|
87
|
-
html_resource.add_css_link(css_link)
|
88
|
-
|
89
|
-
html_resource.add_vue_app_use(component.name)
|
90
|
-
|
91
|
-
for plugin in system_slot._plugins:
|
92
|
-
if not plugin.iife:
|
93
|
-
continue
|
94
|
-
|
95
|
-
html_resource.add_js_link(plugin.iife)
|
96
|
-
|
97
|
-
if plugin.css:
|
98
|
-
for css_link in plugin.css:
|
99
|
-
html_resource.add_css_link(css_link)
|
100
|
-
|
101
|
-
html_resource.add_vue_app_use(plugin.name)
|
102
|
-
|
103
|
-
_css_file_link_to_style_code(html_resource)
|
104
|
-
_js_file_link_to_script_code(html_resource)
|
105
|
-
|
106
|
-
raw = render_zero_html(to_json())
|
107
|
-
file.write_text(raw, "utf8")
|
108
|
-
|
109
|
-
return file.resolve().absolute()
|
110
|
-
|
111
|
-
|
112
|
-
def _css_file_link_to_style_code(html_resource: HtmlResource):
|
113
|
-
files = [link for link in html_resource._css_links.keys() if isinstance(link, Path)]
|
114
|
-
|
115
|
-
for file in files:
|
116
|
-
content = file.read_text(encoding="utf-8")
|
117
|
-
html_resource.add_style_tag(content)
|
118
|
-
|
119
|
-
# remove file links
|
120
|
-
html_resource._css_links = {
|
121
|
-
link: None
|
122
|
-
for link in html_resource._css_links.keys()
|
123
|
-
if not isinstance(link, Path)
|
124
|
-
}
|
125
|
-
|
126
|
-
|
127
|
-
def _js_file_link_to_script_code(html_resource: HtmlResource):
|
128
|
-
files = (
|
129
|
-
info.link for info in html_resource._js_links if isinstance(info.link, Path)
|
130
|
-
)
|
131
|
-
|
132
|
-
for file in files:
|
133
|
-
content = file.read_text(encoding="utf-8")
|
134
|
-
html_resource.add_script_tag(content)
|
135
|
-
|
136
|
-
# remove file links
|
137
|
-
html_resource._js_links = [
|
138
|
-
info for info in html_resource._js_links if not isinstance(info.link, Path)
|
139
|
-
]
|
instaui/page_info.py
CHANGED
@@ -1,23 +1,13 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
from typing import Callable
|
2
|
+
from typing import Callable
|
3
3
|
from dataclasses import dataclass
|
4
4
|
from urllib.parse import quote
|
5
5
|
|
6
6
|
|
7
|
-
if TYPE_CHECKING:
|
8
|
-
from instaui.runtime.resource import HtmlResource
|
9
|
-
|
10
|
-
|
11
7
|
@dataclass
|
12
8
|
class PageInfo:
|
13
9
|
path: str
|
14
10
|
func: Callable
|
15
|
-
page_loading: Optional[Callable] = None
|
16
|
-
use_tailwind: Optional[bool] = None
|
17
11
|
|
18
12
|
def create_key(self) -> str:
|
19
13
|
return quote(self.path)
|
20
|
-
|
21
|
-
def apply_settings(self, html_resource: HtmlResource):
|
22
|
-
if self.use_tailwind is not None:
|
23
|
-
html_resource.use_tailwind = self.use_tailwind
|
instaui/runtime/_app.py
CHANGED
@@ -5,7 +5,6 @@ from instaui.common.jsonable import Jsonable
|
|
5
5
|
from .resource import HtmlResource
|
6
6
|
from instaui.consts import _T_App_Mode
|
7
7
|
from contextvars import ContextVar, Token
|
8
|
-
from copy import copy
|
9
8
|
from contextlib import contextmanager
|
10
9
|
from instaui.runtime.scope import Scope, GlobalScope
|
11
10
|
from types import MappingProxyType
|
@@ -13,14 +12,14 @@ from types import MappingProxyType
|
|
13
12
|
if TYPE_CHECKING:
|
14
13
|
from instaui.components.component import Component
|
15
14
|
from instaui.components.slot import Slot
|
16
|
-
|
15
|
+
|
16
|
+
from instaui.dependencies.component_dependency import ComponentDependencyInfo
|
17
|
+
from instaui.dependencies.plugin_dependency import PluginDependencyInfo
|
17
18
|
from instaui.spa_router._route_model import RouteCollector
|
18
19
|
|
19
20
|
|
20
21
|
class App(Jsonable):
|
21
22
|
_default_app_slot: ClassVar[Optional[App]] = None
|
22
|
-
_default_js_components: ClassVar[Set[ComponentRegistrationInfo]] = set()
|
23
|
-
_default_plugins: ClassVar[Set[PluginRegistrationInfo]] = set()
|
24
23
|
|
25
24
|
def __init__(self, *, mode: _T_App_Mode) -> None:
|
26
25
|
super().__init__()
|
@@ -35,11 +34,9 @@ class App(Jsonable):
|
|
35
34
|
self._scope_stack: List[Scope] = [defalut_scope]
|
36
35
|
self._scopes: List[Scope] = [defalut_scope]
|
37
36
|
self._html_resource = HtmlResource()
|
38
|
-
self.
|
39
|
-
|
40
|
-
)
|
37
|
+
self._component_dependencies: Set[ComponentDependencyInfo] = set()
|
38
|
+
self._plugin_dependencies: Set[PluginDependencyInfo] = set()
|
41
39
|
|
42
|
-
self._plugins: Set[PluginRegistrationInfo] = copy(self._default_plugins)
|
43
40
|
self._page_path: Optional[str] = None
|
44
41
|
self._page_params: Dict[str, Any] = {}
|
45
42
|
self._query_params: Dict[str, Any] = {}
|
@@ -74,11 +71,11 @@ class App(Jsonable):
|
|
74
71
|
def reset_html_resource(self):
|
75
72
|
self._html_resource = HtmlResource()
|
76
73
|
|
77
|
-
def
|
78
|
-
self.
|
74
|
+
def use_component_dependency(self, dependency: ComponentDependencyInfo) -> None:
|
75
|
+
self._component_dependencies.add(dependency)
|
79
76
|
|
80
|
-
def
|
81
|
-
self.
|
77
|
+
def use_plugin_dependency(self, dependency: PluginDependencyInfo) -> None:
|
78
|
+
self._plugin_dependencies.add(dependency)
|
82
79
|
|
83
80
|
def register_router(self, collector: RouteCollector) -> None:
|
84
81
|
self._route_collector = collector
|
@@ -115,14 +112,6 @@ class App(Jsonable):
|
|
115
112
|
cls._default_app_slot = DefaultApp(mode="web")
|
116
113
|
return cls._default_app_slot
|
117
114
|
|
118
|
-
@classmethod
|
119
|
-
def default_js_components(cls, component: ComponentRegistrationInfo):
|
120
|
-
cls._default_js_components.add(component)
|
121
|
-
|
122
|
-
@classmethod
|
123
|
-
def default_plugins(cls, plugin: PluginRegistrationInfo):
|
124
|
-
cls._default_plugins.add(plugin)
|
125
|
-
|
126
115
|
|
127
116
|
class DefaultApp(App):
|
128
117
|
_instance = None
|
instaui/runtime/resource.py
CHANGED
@@ -1,28 +1,20 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
from pathlib import Path
|
3
|
-
from typing import Any,
|
3
|
+
from typing import Any, Dict, List, Optional, Set, Union
|
4
4
|
from .dataclass import JsLink, VueAppUse, VueAppComponent
|
5
5
|
|
6
6
|
|
7
7
|
class HtmlResource:
|
8
|
-
|
9
|
-
_default_style_tags: ClassVar[List[str]] = []
|
10
|
-
_default_js_links: ClassVar[List[JsLink]] = []
|
11
|
-
_default_script_tags: ClassVar[List[str]] = []
|
12
|
-
_default_vue_app_use: ClassVar[Set[VueAppUse]] = set()
|
13
|
-
_default_vue_app_components: ClassVar[Set[VueAppComponent]] = set()
|
14
|
-
use_tailwind: bool = False
|
8
|
+
use_tailwind: Optional[bool] = None
|
15
9
|
_title: str = ""
|
16
10
|
|
17
11
|
def __init__(self) -> None:
|
18
|
-
self._css_links: Dict[Union[str, Path], Any] =
|
19
|
-
self._style_tags: List[str] =
|
20
|
-
self._js_links: List[JsLink] =
|
21
|
-
self._script_tags: List[str] =
|
22
|
-
self._vue_app_use: Set[VueAppUse] =
|
23
|
-
self._vue_app_components: Set[VueAppComponent] = (
|
24
|
-
self._default_vue_app_components.copy()
|
25
|
-
)
|
12
|
+
self._css_links: Dict[Union[str, Path], Any] = {}
|
13
|
+
self._style_tags: List[str] = []
|
14
|
+
self._js_links: List[JsLink] = []
|
15
|
+
self._script_tags: List[str] = []
|
16
|
+
self._vue_app_use: Set[VueAppUse] = set()
|
17
|
+
self._vue_app_components: Set[VueAppComponent] = set()
|
26
18
|
self._import_maps: Dict[str, str] = {}
|
27
19
|
self.title: str = self._title
|
28
20
|
self._appConfig = "{}"
|
@@ -45,7 +37,9 @@ class HtmlResource:
|
|
45
37
|
return
|
46
38
|
self._js_links.insert(insert_before, JsLink(link, attrs or {}))
|
47
39
|
|
48
|
-
def add_script_tag(
|
40
|
+
def add_script_tag(
|
41
|
+
self, content: str, script_attrs: Optional[Dict[str, Any]] = None
|
42
|
+
):
|
49
43
|
self._script_tags.append(content)
|
50
44
|
|
51
45
|
def add_vue_app_use(self, name: str):
|
@@ -56,32 +50,3 @@ class HtmlResource:
|
|
56
50
|
|
57
51
|
def add_import_map(self, name: str, link: str):
|
58
52
|
self._import_maps[name] = link
|
59
|
-
|
60
|
-
@classmethod
|
61
|
-
def default_css_link(cls, link: Union[str, Path]):
|
62
|
-
cls._default_css_links[link] = None
|
63
|
-
|
64
|
-
@classmethod
|
65
|
-
def default_style_tag(cls, content: str):
|
66
|
-
cls._default_style_tags.append(content)
|
67
|
-
|
68
|
-
@classmethod
|
69
|
-
def default_js_link(
|
70
|
-
cls,
|
71
|
-
link: Union[str, Path],
|
72
|
-
*,
|
73
|
-
attrs: Optional[Dict[str, Any]] = None,
|
74
|
-
insert_before: int = -1,
|
75
|
-
):
|
76
|
-
if insert_before == -1:
|
77
|
-
cls._default_js_links.append(JsLink(link, attrs or {}))
|
78
|
-
return
|
79
|
-
cls._default_js_links.insert(insert_before, JsLink(link, attrs or {}))
|
80
|
-
|
81
|
-
@classmethod
|
82
|
-
def default_script_tag(cls, content: str):
|
83
|
-
cls._default_script_tags.append(content)
|
84
|
-
|
85
|
-
@classmethod
|
86
|
-
def default_vue_app_use(cls, name: str):
|
87
|
-
cls._default_vue_app_use.add(VueAppUse(name))
|