instaui 0.1.1__py3-none-any.whl → 0.1.3__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.
Files changed (39) hide show
  1. instaui/components/component.py +1 -1
  2. instaui/components/element.py +37 -17
  3. instaui/components/html/checkbox.py +0 -7
  4. instaui/components/html/select.py +1 -1
  5. instaui/components/vfor.py +1 -1
  6. instaui/consts.py +4 -0
  7. instaui/dependencies/component_dependency.py +16 -0
  8. instaui/dependencies/plugin_dependency.py +28 -0
  9. instaui/fastapi_server/debug_mode_router.py +0 -1
  10. instaui/fastapi_server/dependency_router.py +21 -0
  11. instaui/fastapi_server/resource.py +34 -0
  12. instaui/fastapi_server/server.py +147 -95
  13. instaui/html_tools.py +19 -105
  14. instaui/page_info.py +1 -11
  15. instaui/runtime/_app.py +9 -20
  16. instaui/runtime/resource.py +13 -48
  17. instaui/static/insta-ui.esm-browser.prod.js +3663 -3663
  18. instaui/static/insta-ui.ico +0 -0
  19. instaui/static/insta-ui.iife.js +29 -29
  20. instaui/static/templates/debug/sse.html +2 -2
  21. instaui/static/templates/web.html +32 -76
  22. instaui/static/templates/zero.html +48 -32
  23. instaui/systems/file_system.py +3 -14
  24. instaui/template/web_template.py +40 -46
  25. instaui/template/zero_template.py +95 -15
  26. instaui/ui/__init__.py +4 -5
  27. instaui/ui_functions/ui_page.py +3 -18
  28. instaui/vars/path_var.py +2 -1
  29. instaui/zero/func.py +115 -0
  30. instaui/zero/scope.py +12 -1
  31. instaui/zero/test.html +44 -0
  32. {instaui-0.1.1.dist-info → instaui-0.1.3.dist-info}/METADATA +1 -1
  33. {instaui-0.1.1.dist-info → instaui-0.1.3.dist-info}/RECORD +35 -32
  34. instaui/dependencies/__init__.py +0 -15
  35. instaui/dependencies/component_registrar.py +0 -82
  36. instaui/dependencies/installer.py +0 -5
  37. instaui/fastapi_server/config_router.py +0 -60
  38. {instaui-0.1.1.dist-info → instaui-0.1.3.dist-info}/LICENSE +0 -0
  39. {instaui-0.1.1.dist-info → instaui-0.1.3.dist-info}/WHEEL +0 -0
instaui/html_tools.py CHANGED
@@ -1,139 +1,53 @@
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, HtmlResource
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], *, shared: bool = False):
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
- shared: bool = False,
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, *, shared: bool = False):
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 add_js_code(code: str, *, shared: bool = False):
40
- if shared:
41
- HtmlResource.default_script_tag(code)
42
- get_app_slot()._html_resource.add_script_tag(code)
43
-
44
-
45
- def add_vue_app_use(name: str, *, shared: bool = False):
46
- if shared:
47
- HtmlResource.default_vue_app_use(name)
48
- get_app_slot()._html_resource.add_vue_app_use(name)
49
-
50
-
51
- def to_config_data() -> Dict:
52
- return dumps2dict(get_app_slot())
53
-
54
-
55
- def to_json(indent=False):
56
- 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)
28
+ def use_tailwind(value=True):
29
+ get_app_slot()._html_resource.use_tailwind = value
67
30
 
68
- file = Path(file)
69
- system_slot = get_app_slot()
70
- html_resource = system_slot._html_resource
71
31
 
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)
32
+ def use_page_title(title: str):
33
+ get_app_slot()._html_resource.title = title
77
34
 
78
- # register custom components
79
- for component in system_slot._js_components:
80
- if not component.iife:
81
- continue
82
35
 
83
- html_resource.add_js_link(component.iife)
36
+ def use_favicon(favicon: Path):
37
+ get_app_slot()._html_resource.favicon = favicon
84
38
 
85
- if component.css:
86
- for css_link in component.css:
87
- html_resource.add_css_link(css_link)
88
39
 
89
- html_resource.add_vue_app_use(component.name)
40
+ def add_js_code(code: str, *, script_attrs: Optional[Dict[str, Any]] = None):
41
+ get_app_slot()._html_resource.add_script_tag(code, script_attrs=script_attrs)
90
42
 
91
- for plugin in system_slot._plugins:
92
- if not plugin.iife:
93
- continue
94
43
 
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
- }
44
+ def add_vue_app_use(name: str):
45
+ get_app_slot()._html_resource.add_vue_app_use(name)
125
46
 
126
47
 
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
- )
48
+ def to_config_data() -> Dict:
49
+ return dumps2dict(get_app_slot())
131
50
 
132
- for file in files:
133
- content = file.read_text(encoding="utf-8")
134
- html_resource.add_script_tag(content)
135
51
 
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
- ]
52
+ def to_json(indent=False):
53
+ return dumps(get_app_slot(), indent=indent)
instaui/page_info.py CHANGED
@@ -1,23 +1,13 @@
1
1
  from __future__ import annotations
2
- from typing import Callable, Optional, TYPE_CHECKING
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
- from instaui.dependencies import ComponentRegistrationInfo, PluginRegistrationInfo
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._js_components: Set[ComponentRegistrationInfo] = copy(
39
- self._default_js_components
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 register_component(self, component: ComponentRegistrationInfo) -> None:
78
- self._js_components.add(component)
74
+ def use_component_dependency(self, dependency: ComponentDependencyInfo) -> None:
75
+ self._component_dependencies.add(dependency)
79
76
 
80
- def register_plugin(self, plugin: PluginRegistrationInfo) -> None:
81
- self._plugins.add(plugin)
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
@@ -1,30 +1,22 @@
1
1
  from __future__ import annotations
2
2
  from pathlib import Path
3
- from typing import Any, ClassVar, Dict, List, Optional, Set, Union
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
- _default_css_links: ClassVar[Dict[Union[str, Path], Any]] = {}
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
15
- _title: str = ""
8
+ use_tailwind: Optional[bool] = None
9
+ title: Optional[str] = None
10
+ favicon: Optional[Path] = None
16
11
 
17
12
  def __init__(self) -> None:
18
- self._css_links: Dict[Union[str, Path], Any] = self._default_css_links.copy()
19
- self._style_tags: List[str] = self._default_style_tags.copy()
20
- self._js_links: List[JsLink] = self._default_js_links.copy()
21
- self._script_tags: List[str] = self._default_script_tags.copy()
22
- self._vue_app_use: Set[VueAppUse] = self._default_vue_app_use.copy()
23
- self._vue_app_components: Set[VueAppComponent] = (
24
- self._default_vue_app_components.copy()
25
- )
13
+ self._css_links: Dict[Union[str, Path], Any] = {}
14
+ self._style_tags: List[str] = []
15
+ self._js_links: List[JsLink] = []
16
+ self._script_tags: List[str] = []
17
+ self._vue_app_use: Set[VueAppUse] = set()
18
+ self._vue_app_components: Set[VueAppComponent] = set()
26
19
  self._import_maps: Dict[str, str] = {}
27
- self.title: str = self._title
28
20
  self._appConfig = "{}"
29
21
 
30
22
  def add_css_link(self, link: Union[str, Path]):
@@ -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(self, content: str):
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))