instaui 0.1.3__py3-none-any.whl → 0.1.4__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 (58) hide show
  1. instaui/components/content.py +4 -4
  2. instaui/components/element.py +56 -12
  3. instaui/components/highlight_code/code.js +63 -0
  4. instaui/components/highlight_code/code.py +117 -0
  5. instaui/components/highlight_code/static/core.min.js +307 -0
  6. instaui/components/highlight_code/static/languages/css.min.js +31 -0
  7. instaui/components/highlight_code/static/languages/javascript.min.js +81 -0
  8. instaui/components/highlight_code/static/languages/json.min.js +8 -0
  9. instaui/components/highlight_code/static/languages/python-repl.min.js +5 -0
  10. instaui/components/highlight_code/static/languages/python.min.js +42 -0
  11. instaui/components/highlight_code/static/languages/shell.min.js +5 -0
  12. instaui/components/highlight_code/static/styles/default.min.css +9 -0
  13. instaui/components/highlight_code/static/styles/github-dark-dimmed.min.css +9 -0
  14. instaui/components/highlight_code/static/styles/github-dark.min.css +10 -0
  15. instaui/components/highlight_code/static/styles/github.min.css +10 -0
  16. instaui/components/html/__init__.py +2 -0
  17. instaui/components/html/select.py +6 -7
  18. instaui/components/html/textarea.py +28 -0
  19. instaui/components/markdown/markdown.js +33 -0
  20. instaui/components/markdown/markdown.py +41 -0
  21. instaui/components/markdown/static/github-markdown.css +12 -0
  22. instaui/components/markdown/static/marked.esm.js +2580 -0
  23. instaui/components/vfor.py +1 -1
  24. instaui/daisyui/__init__.py +20 -0
  25. instaui/daisyui/_index.py +15 -0
  26. instaui/daisyui/button.py +38 -0
  27. instaui/daisyui/checkbox.py +17 -0
  28. instaui/daisyui/static/daisyui.css +1 -0
  29. instaui/daisyui/static/themes.css +1 -0
  30. instaui/dependencies/component_dependency.py +11 -5
  31. instaui/fastapi_server/dependency_router.py +4 -3
  32. instaui/fastapi_server/resource.py +12 -16
  33. instaui/fastapi_server/server.py +30 -12
  34. instaui/html_tools.py +4 -0
  35. instaui/inject.py +3 -3
  36. instaui/runtime/_app.py +6 -1
  37. instaui/runtime/resource.py +3 -0
  38. instaui/spa_router/_functions.py +1 -1
  39. instaui/spa_router/_route_model.py +1 -1
  40. instaui/static/insta-ui.css +1 -1
  41. instaui/static/insta-ui.esm-browser.prod.js +106 -111
  42. instaui/static/insta-ui.js.map +1 -1
  43. instaui/systems/module_system.py +30 -0
  44. instaui/template/zero_template.py +18 -17
  45. instaui/ui/__build_init.py +73 -0
  46. instaui/ui/__init__.py +68 -58
  47. instaui/ui/__init__.pyi +129 -0
  48. instaui/ui/events.py +1 -1
  49. instaui/ui_functions/server.py +3 -1
  50. instaui/zero/func.py +12 -11
  51. instaui/zero/scope.py +89 -1
  52. {instaui-0.1.3.dist-info → instaui-0.1.4.dist-info}/METADATA +1 -1
  53. {instaui-0.1.3.dist-info → instaui-0.1.4.dist-info}/RECORD +55 -31
  54. instaui/static/insta-ui.iife.js +0 -29
  55. instaui/static/insta-ui.iife.js.map +0 -1
  56. instaui/zero/test.html +0 -44
  57. {instaui-0.1.3.dist-info → instaui-0.1.4.dist-info}/LICENSE +0 -0
  58. {instaui-0.1.3.dist-info → instaui-0.1.4.dist-info}/WHEEL +0 -0
@@ -0,0 +1,30 @@
1
+ from importlib import import_module
2
+ from types import ModuleType
3
+ from typing import Any, List
4
+
5
+
6
+ class LazyModule(ModuleType):
7
+ def __init__(self, name: str, member: str):
8
+ super().__init__(name)
9
+ self._name = name
10
+ self._mod = None
11
+ self._member_obj = None
12
+ self._member = member
13
+
14
+ def __getattr__(self, attr: str) -> Any:
15
+ self.__try_import()
16
+ return getattr(self._member_obj, attr)
17
+
18
+ def __call__(self, *args: Any, **kwds: Any) -> Any:
19
+ self.__try_import()
20
+ return self._member_obj(*args, **kwds) # type: ignore
21
+
22
+ def __dir__(self) -> List[str]:
23
+ if self._mod is None:
24
+ self._mod = import_module(self._name)
25
+ return dir(self._mod)
26
+
27
+ def __try_import(self):
28
+ if self._mod is None:
29
+ self._mod = import_module(self._name)
30
+ self._member_obj = getattr(self._mod, self._member)
@@ -52,51 +52,52 @@ class ZeroTemplateModel:
52
52
  return dumps(data)
53
53
 
54
54
  def normalize_path_with_self(self):
55
- self.vue_js_code = self._normalize_path_to_dataurl(self.vue_js_code, _JS_PREFIX)
56
- self.instaui_js_code = self._normalize_path_to_dataurl(
55
+ self.vue_js_code = _normalize_path_to_dataurl(self.vue_js_code, _JS_PREFIX)
56
+ self.instaui_js_code = _normalize_path_to_dataurl(
57
57
  self.instaui_js_code, _JS_PREFIX
58
58
  )
59
59
 
60
60
  self.css_links = [
61
- self._normalize_path_to_dataurl(link, _CSS_PREFIX)
61
+ _normalize_path_to_dataurl(link, _CSS_PREFIX)
62
62
  for link in self.css_links
63
+ if isinstance(link, str) or (isinstance(link, Path) and link.is_file())
63
64
  ]
64
65
 
65
66
  self.js_links = [
66
67
  JsLink(
67
- link=self._normalize_path_to_dataurl(link.link, _JS_PREFIX),
68
+ link=_normalize_path_to_dataurl(link.link, _JS_PREFIX),
68
69
  attrs=link.attrs,
69
70
  )
70
71
  for link in self.js_links
71
72
  ]
72
73
 
73
74
  self.extra_import_maps = {
74
- k: self._normalize_path_to_dataurl(v, _JS_PREFIX)
75
+ k: _normalize_path_to_dataurl(v, _JS_PREFIX)
75
76
  for k, v in self.extra_import_maps.items()
76
77
  }
77
78
 
78
79
  self.vue_app_component = [
79
80
  ZeroVueAppComponent(
80
81
  name=component.name,
81
- url=self._normalize_path_to_dataurl(component.url, _JS_PREFIX),
82
+ url=_normalize_path_to_dataurl(component.url, _JS_PREFIX),
82
83
  )
83
84
  for component in self.vue_app_component
84
85
  ]
85
86
 
86
- self.favicon = self._normalize_path_to_base64_url(self.favicon, _ICON_PREFIX)
87
+ self.favicon = _normalize_path_to_base64_url(self.favicon, _ICON_PREFIX) # type: ignore
87
88
 
88
- @staticmethod
89
- def _normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
90
- if isinstance(path, Path):
91
- path = path.read_text(encoding="utf-8")
92
89
 
93
- return f"{prefix},{quote(path)}"
90
+ def _normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
91
+ if isinstance(path, Path):
92
+ path = path.read_text(encoding="utf-8")
94
93
 
95
- @staticmethod
96
- def _normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
97
- if path is None:
98
- return None
99
- return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
94
+ return f"{prefix},{quote(path)}"
95
+
96
+
97
+ def _normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
98
+ if path is None:
99
+ return None
100
+ return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
100
101
 
101
102
 
102
103
  def render_zero_html(model: ZeroTemplateModel) -> str:
@@ -0,0 +1,73 @@
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+
5
+ PYI_FILE = Path(__file__).parent / "__init__.pyi"
6
+ INIT_FILE = Path(__file__).parent / "__init__.py"
7
+
8
+ MARK_ALL = "# -- __all__"
9
+ MARK_STATIC_IMPORTS = "# -- static imports"
10
+ MARK_DYNAMIC_IMPORTS = "# -- dynamic imports"
11
+
12
+ LAZY_MODULE_IMPORT = "from instaui.systems.module_system import LazyModule"
13
+
14
+
15
+ def create_init_file():
16
+ all_part_lines, static_lines, dynamic_lines = _split_by_marks(
17
+ PYI_FILE, [MARK_ALL, MARK_STATIC_IMPORTS, MARK_DYNAMIC_IMPORTS]
18
+ )
19
+
20
+ # first line is comment, skip it
21
+ dynamic_lines = [
22
+ _conver_dynamic(line) for line in dynamic_lines[1:] if line.strip()
23
+ ]
24
+
25
+ with open(INIT_FILE, "w", encoding="utf-8") as f:
26
+ f.writelines("\n".join(all_part_lines))
27
+ f.write("\n")
28
+ f.writelines("\n".join(static_lines))
29
+ f.write("\n")
30
+
31
+ f.writelines(
32
+ "\n".join([MARK_DYNAMIC_IMPORTS, LAZY_MODULE_IMPORT, *dynamic_lines])
33
+ )
34
+
35
+ print(f"Create {INIT_FILE} success.")
36
+
37
+
38
+ def _split_by_marks(file: Path, marks: List[str]):
39
+ with open(file, "r", encoding="utf-8") as f:
40
+ lines = f.read().splitlines()
41
+
42
+ marks_index = [lines.index(mark) for mark in marks]
43
+ marks_index.append(len(lines))
44
+
45
+ return [
46
+ lines[marks_index[i] : marks_index[i + 1]] for i in range(len(marks_index) - 1)
47
+ ]
48
+
49
+
50
+ def _conver_dynamic(dynamic_code: str):
51
+ # "from instaui.components.highlight_code.code import Code as code" convert to "code = LazyModule('instaui.components.highlight_code.code', 'Code')"
52
+
53
+ # instaui.components.highlight_code.code
54
+ from_part = dynamic_code.split("import")[0][5:].strip()
55
+
56
+ # Code as code
57
+ import_part = dynamic_code.split("import")[1].strip()
58
+ has_as = " as " in import_part
59
+
60
+ member_name = ""
61
+ alias_name = ""
62
+
63
+ if has_as:
64
+ member_name, alias_name = import_part.split(" as ")
65
+ else:
66
+ member_name = import_part
67
+ alias_name = member_name
68
+
69
+ return f"{alias_name} = LazyModule('{from_part}', '{member_name}')"
70
+
71
+
72
+ if __name__ == "__main__":
73
+ create_init_file()
instaui/ui/__init__.py CHANGED
@@ -1,61 +1,4 @@
1
- from instaui.version import __version__
2
- from instaui.vars import TMaybeRef
3
- from instaui.vars.ref import ref, TRef
4
-
5
- from instaui.vars.data import ConstData as data, TConstData
6
- from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
7
- from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
8
- from instaui.vars.web_computed import web_computed as computed, TComputed
9
- from instaui.vars.state import state, StateModel
10
- from instaui.inject import inject_state, provide_state, injection_key
11
- from instaui.vars.vfor_item import TVForItem, TVForIndex
12
- from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
13
- from instaui.html_tools import (
14
- to_json,
15
- add_css_link,
16
- add_js_link,
17
- add_style,
18
- add_js_code,
19
- add_vue_app_use,
20
- to_config_data,
21
- use_tailwind,
22
- use_page_title,
23
- )
24
-
25
- from instaui.components.element import Element as element
26
- from instaui.components.row import Row as row
27
- from instaui.components.column import Column as column
28
- from instaui.components.grid import Grid as grid
29
- from instaui.components.directive import Directive as directive
30
- from instaui.components.vfor import VFor as vfor
31
- from instaui.components.vif import VIf as vif
32
- from instaui.components.match import Match as match
33
- from instaui.components.content import Content as content
34
-
35
- from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
36
- from instaui.event.js_event import js_event
37
- from instaui.vars.event_context import EventContext as event_context
38
- from instaui.runtime.context import get_context as context
39
-
40
- import instaui.js as js
41
- from instaui.watch.web_watch import watch
42
- from instaui.watch.vue_watch import VueWatch as vue_watch
43
- from instaui.watch.js_watch import js_watch
44
- from instaui.handlers.watch_handler import WatchState as TWatchState
45
- from instaui.skip import skip_output
46
- from instaui.ui_functions.input_slient_data import InputSilentData as slient
47
- from instaui.js.js_output import JsOutput as js_output
48
- import instaui.experimental as experimental
49
-
50
-
51
- from instaui.ui_functions.server import create_server as server
52
- from instaui.ui_functions.ui_page import page
53
- from instaui.ui_functions.url_location import UrlLocation as url_location
54
- from instaui.ui_functions.str_format import str_format
55
- from instaui.ui_functions.ui_types import TBindable, is_bindable
56
-
57
- from .events import on_page_request_lifespan
58
-
1
+ # -- __all__
59
2
  __all__ = [
60
3
  "__version__",
61
4
  "TMaybeRef",
@@ -88,6 +31,7 @@ __all__ = [
88
31
  "content",
89
32
  "add_style",
90
33
  "add_css_link",
34
+ "remove_css_link",
91
35
  "add_js_code",
92
36
  "add_js_link",
93
37
  "add_vue_app_use",
@@ -117,4 +61,70 @@ __all__ = [
117
61
  "str_format",
118
62
  "url_location",
119
63
  "on_page_request_lifespan",
64
+ "code",
65
+ "markdown",
120
66
  ]
67
+
68
+ # -- static imports
69
+ from instaui.version import __version__
70
+ from instaui.vars import TMaybeRef
71
+ from instaui.vars.ref import ref, TRef
72
+
73
+ from instaui.vars.data import ConstData as data, TConstData
74
+ from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
75
+ from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
76
+ from instaui.vars.web_computed import web_computed as computed, TComputed
77
+ from instaui.vars.state import state, StateModel
78
+ from instaui.inject import inject_state, provide_state, injection_key
79
+ from instaui.vars.vfor_item import TVForItem, TVForIndex
80
+ from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
81
+ from instaui.html_tools import (
82
+ to_json,
83
+ add_css_link,
84
+ remove_css_link,
85
+ add_js_link,
86
+ add_style,
87
+ add_js_code,
88
+ add_vue_app_use,
89
+ to_config_data,
90
+ use_tailwind,
91
+ use_page_title,
92
+ )
93
+
94
+ from instaui.components.element import Element as element
95
+ from instaui.components.row import Row as row
96
+ from instaui.components.column import Column as column
97
+ from instaui.components.grid import Grid as grid
98
+ from instaui.components.directive import Directive as directive
99
+ from instaui.components.vfor import VFor as vfor
100
+ from instaui.components.vif import VIf as vif
101
+ from instaui.components.match import Match as match
102
+ from instaui.components.content import Content as content
103
+
104
+ from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
105
+ from instaui.event.js_event import js_event
106
+ from instaui.vars.event_context import EventContext as event_context
107
+ from instaui.runtime.context import get_context as context
108
+
109
+ import instaui.js as js
110
+ from instaui.watch.web_watch import watch
111
+ from instaui.watch.vue_watch import VueWatch as vue_watch
112
+ from instaui.watch.js_watch import js_watch
113
+ from instaui.handlers.watch_handler import WatchState as TWatchState
114
+ from instaui.skip import skip_output
115
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
116
+ from instaui.js.js_output import JsOutput as js_output
117
+ import instaui.experimental as experimental
118
+
119
+ from instaui.ui_functions.server import create_server as server
120
+ from instaui.ui_functions.ui_page import page
121
+ from instaui.ui_functions.url_location import UrlLocation as url_location
122
+ from instaui.ui_functions.str_format import str_format
123
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
124
+
125
+ from .events import on_page_request_lifespan
126
+
127
+ # -- dynamic imports
128
+ from instaui.systems.module_system import LazyModule
129
+ code = LazyModule('instaui.components.highlight_code.code', 'Code')
130
+ markdown = LazyModule('instaui.components.markdown.markdown', 'Markdown')
@@ -0,0 +1,129 @@
1
+ # -- __all__
2
+ __all__ = [
3
+ "__version__",
4
+ "TMaybeRef",
5
+ "TBindable",
6
+ "is_bindable",
7
+ "ref",
8
+ "slient",
9
+ "data",
10
+ "TConstData",
11
+ "TRef",
12
+ "vue_computed",
13
+ "TVueComputed",
14
+ "js_computed",
15
+ "TJsComputed",
16
+ "computed",
17
+ "TComputed",
18
+ "state",
19
+ "StateModel",
20
+ "inject_state",
21
+ "provide_state",
22
+ "injection_key",
23
+ "TVForItem",
24
+ "TVForIndex",
25
+ "element_ref",
26
+ "run_element_method",
27
+ "to_json",
28
+ "to_config_data",
29
+ "element",
30
+ "vfor",
31
+ "content",
32
+ "add_style",
33
+ "add_css_link",
34
+ "remove_css_link",
35
+ "add_js_code",
36
+ "add_js_link",
37
+ "add_vue_app_use",
38
+ "use_tailwind",
39
+ "use_page_title",
40
+ "directive",
41
+ "vif",
42
+ "page",
43
+ "event",
44
+ "js_event",
45
+ "event_context",
46
+ "TEventFn",
47
+ "server",
48
+ "context",
49
+ "row",
50
+ "grid",
51
+ "js",
52
+ "watch",
53
+ "vue_watch",
54
+ "js_watch",
55
+ "TWatchState",
56
+ "match",
57
+ "column",
58
+ "experimental",
59
+ "skip_output",
60
+ "js_output",
61
+ "str_format",
62
+ "url_location",
63
+ "on_page_request_lifespan",
64
+ "code",
65
+ "markdown",
66
+ ]
67
+
68
+ # -- static imports
69
+ from instaui.version import __version__
70
+ from instaui.vars import TMaybeRef
71
+ from instaui.vars.ref import ref, TRef
72
+
73
+ from instaui.vars.data import ConstData as data, TConstData
74
+ from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
75
+ from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
76
+ from instaui.vars.web_computed import web_computed as computed, TComputed
77
+ from instaui.vars.state import state, StateModel
78
+ from instaui.inject import inject_state, provide_state, injection_key
79
+ from instaui.vars.vfor_item import TVForItem, TVForIndex
80
+ from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
81
+ from instaui.html_tools import (
82
+ to_json,
83
+ add_css_link,
84
+ remove_css_link,
85
+ add_js_link,
86
+ add_style,
87
+ add_js_code,
88
+ add_vue_app_use,
89
+ to_config_data,
90
+ use_tailwind,
91
+ use_page_title,
92
+ )
93
+
94
+ from instaui.components.element import Element as element
95
+ from instaui.components.row import Row as row
96
+ from instaui.components.column import Column as column
97
+ from instaui.components.grid import Grid as grid
98
+ from instaui.components.directive import Directive as directive
99
+ from instaui.components.vfor import VFor as vfor
100
+ from instaui.components.vif import VIf as vif
101
+ from instaui.components.match import Match as match
102
+ from instaui.components.content import Content as content
103
+
104
+ from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
105
+ from instaui.event.js_event import js_event
106
+ from instaui.vars.event_context import EventContext as event_context
107
+ from instaui.runtime.context import get_context as context
108
+
109
+ import instaui.js as js
110
+ from instaui.watch.web_watch import watch
111
+ from instaui.watch.vue_watch import VueWatch as vue_watch
112
+ from instaui.watch.js_watch import js_watch
113
+ from instaui.handlers.watch_handler import WatchState as TWatchState
114
+ from instaui.skip import skip_output
115
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
116
+ from instaui.js.js_output import JsOutput as js_output
117
+ import instaui.experimental as experimental
118
+
119
+ from instaui.ui_functions.server import create_server as server
120
+ from instaui.ui_functions.ui_page import page
121
+ from instaui.ui_functions.url_location import UrlLocation as url_location
122
+ from instaui.ui_functions.str_format import str_format
123
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
124
+
125
+ from .events import on_page_request_lifespan
126
+
127
+ # -- dynamic imports
128
+ from instaui.components.highlight_code.code import Code as code
129
+ from instaui.components.markdown.markdown import Markdown as markdown
instaui/ui/events.py CHANGED
@@ -8,7 +8,7 @@ def on_page_request_lifespan(fn: Callable):
8
8
  Args:
9
9
  fn (Callable): A function to be called on each page request.
10
10
 
11
- Example:
11
+ Examples:
12
12
  .. code-block:: python
13
13
  @ui.on_page_request_lifespan
14
14
  def _():
@@ -1,8 +1,10 @@
1
+ from typing import Union
1
2
  from instaui.runtime.context import get_context
2
3
 
3
4
 
4
5
  def create_server(
5
6
  debug: bool = True,
7
+ use_gzip: Union[int, bool] = True,
6
8
  ):
7
9
  from instaui.fastapi_server.server import Server
8
10
 
@@ -10,4 +12,4 @@ def create_server(
10
12
  context._app_mode = "web"
11
13
  context._debug_mode = debug
12
14
 
13
- return Server.get_instance()
15
+ return Server(use_gzip=use_gzip)
instaui/zero/func.py CHANGED
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
  import itertools
3
3
  from pathlib import Path
4
- from typing import Union
5
4
  import instaui.consts as consts
6
5
  from instaui.runtime._app import get_app_slot, get_default_app_slot
7
6
  from instaui.template import render_zero_html
@@ -10,15 +9,7 @@ from instaui.html_tools import to_config_data
10
9
  from instaui.runtime.dataclass import JsLink
11
10
 
12
11
 
13
- def to_html(file: Union[str, Path]):
14
- if isinstance(file, str):
15
- import inspect
16
-
17
- frame = inspect.currentframe().f_back # type: ignore
18
- assert frame is not None
19
- script_file = inspect.getfile(frame)
20
- file = Path(script_file).parent.joinpath(file)
21
-
12
+ def to_html(file: Path):
22
13
  file = Path(file)
23
14
 
24
15
  raw = to_html_str()
@@ -27,7 +18,7 @@ def to_html(file: Union[str, Path]):
27
18
  return file.resolve().absolute()
28
19
 
29
20
 
30
- def to_html_str():
21
+ def get_template_model():
31
22
  system_slot = get_app_slot()
32
23
  default_app_slot = get_default_app_slot()
33
24
  html_resource = system_slot._html_resource
@@ -71,6 +62,11 @@ def to_html_str():
71
62
  for css_link in component.css:
72
63
  model.css_links.append(css_link)
73
64
 
65
+ if component.externals:
66
+ for name, url in component.externals.items():
67
+ if url.is_file():
68
+ model.add_extra_import_map(name, url)
69
+
74
70
  # register custom plugins
75
71
  for plugin in set(
76
72
  itertools.chain(
@@ -112,4 +108,9 @@ def to_html_str():
112
108
  ):
113
109
  model.style_tags.append(sylte_code)
114
110
 
111
+ return model
112
+
113
+
114
+ def to_html_str():
115
+ model = get_template_model()
115
116
  return render_zero_html(model)
instaui/zero/scope.py CHANGED
@@ -2,7 +2,8 @@ from pathlib import Path
2
2
  from typing import Union
3
3
  from instaui.runtime import new_app_slot, reset_app_slot
4
4
  from contextlib import contextmanager
5
- from .func import to_html, to_html_str
5
+ from .func import to_html, to_html_str, get_template_model
6
+ from instaui.template.zero_template import ZeroTemplateModel
6
7
 
7
8
 
8
9
  @contextmanager
@@ -14,7 +15,94 @@ def scope():
14
15
 
15
16
  class Wrapper:
16
17
  def to_html(self, file: Union[str, Path]):
18
+ file = self._get_caller_path(file)
17
19
  return to_html(file)
18
20
 
19
21
  def to_html_str(self):
20
22
  return to_html_str()
23
+
24
+ def to_debug_report(self, file: Union[str, Path]):
25
+ file = self._get_caller_path(file)
26
+
27
+ # Custom component dependencies must be recorded only during actual execution
28
+ to_html_str()
29
+ model = get_template_model()
30
+ with scope() as s:
31
+ _create_debug_report(model)
32
+ s.to_html(file.resolve().absolute())
33
+
34
+ @staticmethod
35
+ def _get_caller_path(file: Union[str, Path]) -> Path:
36
+ if isinstance(file, str):
37
+ import inspect
38
+
39
+ frame = inspect.currentframe().f_back.f_back # type: ignore
40
+ assert frame is not None
41
+ script_file = inspect.getfile(frame)
42
+ file = Path(script_file).parent.joinpath(file)
43
+
44
+ return file
45
+
46
+
47
+ def _create_debug_report(model: ZeroTemplateModel):
48
+ from instaui import ui, html
49
+
50
+ no_exists_path_class = "ex-no-exists-path"
51
+
52
+ def _path_exists_class(path: Path):
53
+ return "" if path.exists() else no_exists_path_class
54
+
55
+ ui.use_tailwind()
56
+ ui.add_style(rf".{no_exists_path_class} {{background-color: red;color: white;}}")
57
+
58
+ with ui.column().classes("gap-2"):
59
+ # import maps
60
+ html.paragraph("import maps")
61
+ with ui.grid(columns="auto 1fr").classes(
62
+ "gap-4 border-2 border-gray-200 p-4 place-center"
63
+ ):
64
+ html.span("name")
65
+ html.span("path")
66
+
67
+ html.span("vue")
68
+ html.span(str(model.vue_js_code))
69
+
70
+ html.span("instaui")
71
+ html.span(str(model.instaui_js_code))
72
+
73
+ for name, url in model.extra_import_maps.items():
74
+ if isinstance(url, Path) and url.is_file():
75
+ html.span(name)
76
+ html.span(str(url.resolve().absolute())).classes(
77
+ _path_exists_class(url)
78
+ )
79
+
80
+ # css links
81
+ html.paragraph("css links")
82
+ with ui.column().classes("gap-4 border-2 border-gray-200 p-4 place-center"):
83
+ for link in model.css_links:
84
+ if isinstance(link, Path) and link.is_file():
85
+ html.span(str(link)).classes(_path_exists_class(link))
86
+
87
+ # js links
88
+ html.paragraph("js links")
89
+ with ui.column().classes("gap-4 border-2 border-gray-200 p-4 place-center"):
90
+ for info in model.js_links:
91
+ if isinstance(info.link, Path) and info.link.is_file():
92
+ html.span(str(info.link)).classes(_path_exists_class(info.link))
93
+
94
+ # custom components
95
+ html.paragraph("custom components")
96
+ with ui.grid(columns="auto 1fr").classes(
97
+ "gap-4 border-2 border-gray-200 p-4 place-center"
98
+ ):
99
+ html.span("name")
100
+ html.span("js file path")
101
+
102
+ for info in model.vue_app_component:
103
+ html.span(info.name)
104
+
105
+ if isinstance(info.url, Path) and info.url.is_file():
106
+ html.span(str(info.url)).classes(_path_exists_class(info.url))
107
+ else:
108
+ html.span("not file")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: instaui
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: insta-ui is a Python-based UI library for rapidly building user interfaces.
5
5
  License: MIT
6
6
  Author: CrystalWindSnake