instaui 0.1.3__py3-none-any.whl → 0.1.5__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/content.py +4 -4
- instaui/components/echarts/echarts.js +128 -0
- instaui/components/echarts/echarts.py +194 -0
- instaui/components/echarts/static/echarts.esm.min.js +45 -0
- instaui/components/element.py +103 -13
- instaui/components/html/__init__.py +31 -18
- instaui/components/html/_preset.py +4 -0
- instaui/components/html/heading.py +51 -0
- instaui/components/html/range.py +3 -0
- instaui/components/html/select.py +16 -35
- instaui/components/html/table.py +36 -0
- instaui/components/html/textarea.py +28 -0
- instaui/components/markdown/markdown.js +33 -0
- instaui/components/markdown/markdown.py +41 -0
- instaui/components/markdown/static/github-markdown.css +12 -0
- instaui/components/markdown/static/marked.esm.js +2579 -0
- instaui/components/shiki_code/shiki_code.js +126 -0
- instaui/components/shiki_code/shiki_code.py +99 -0
- instaui/components/shiki_code/static/langs/css.mjs +5 -0
- instaui/components/shiki_code/static/langs/markdown.mjs +5 -0
- instaui/components/shiki_code/static/langs/python.mjs +5 -0
- instaui/components/shiki_code/static/langs/shell.mjs +2 -0
- instaui/components/shiki_code/static/langs/shellscript.mjs +5 -0
- instaui/components/shiki_code/static/shiki-core.js +5784 -0
- instaui/components/shiki_code/static/shiki-style.css +175 -0
- instaui/components/shiki_code/static/shiki-transformers.js +461 -0
- instaui/components/shiki_code/static/themes/vitesse-dark.mjs +2 -0
- instaui/components/shiki_code/static/themes/vitesse-light.mjs +2 -0
- instaui/components/value_element.py +7 -3
- instaui/components/vfor.py +1 -1
- instaui/consts.py +2 -1
- instaui/daisyui/__init__.py +26 -0
- instaui/daisyui/_index.py +20 -0
- instaui/daisyui/button.py +38 -0
- instaui/daisyui/checkbox.py +17 -0
- instaui/daisyui/static/daisyui.css +1 -0
- instaui/daisyui/static/themes.css +1 -0
- instaui/daisyui/table.py +35 -0
- instaui/dependencies/component_dependency.py +11 -5
- instaui/event/js_event.py +1 -0
- instaui/event/web_event.py +6 -7
- instaui/fastapi_server/dependency_router.py +4 -3
- instaui/fastapi_server/resource.py +12 -16
- instaui/fastapi_server/server.py +34 -24
- instaui/handlers/event_handler.py +3 -1
- instaui/handlers/watch_handler.py +4 -0
- instaui/html_tools.py +44 -2
- instaui/inject.py +3 -3
- instaui/runtime/_app.py +43 -4
- instaui/runtime/_link_manager.py +89 -0
- instaui/runtime/resource.py +21 -8
- instaui/shadcn_classless/_index.py +42 -0
- instaui/shadcn_classless/static/shadcn-classless.css +403 -0
- instaui/spa_router/_functions.py +1 -1
- instaui/spa_router/_route_model.py +1 -1
- instaui/static/insta-ui.css +1 -1
- instaui/static/insta-ui.esm-browser.prod.js +1308 -1252
- instaui/static/insta-ui.js.map +1 -1
- instaui/static/instaui-tools-browser.js +511 -0
- instaui/static/templates/webview.html +78 -0
- instaui/systems/module_system.py +30 -0
- instaui/tailwind/__init__.py +6 -0
- instaui/tailwind/_index.py +24 -0
- instaui/{static/tailwindcss.min.js → tailwind/static/tailwindcss-v3.min.js} +62 -62
- instaui/tailwind/static/tailwindcss-v4.min.js +8 -0
- instaui/template/_utils.py +23 -0
- instaui/template/webview_template.py +50 -0
- instaui/template/zero_template.py +18 -17
- instaui/ui/__build_init.py +73 -0
- instaui/ui/__init__.py +74 -58
- instaui/ui/__init__.pyi +135 -0
- instaui/ui/events.py +1 -1
- instaui/ui_functions/server.py +3 -1
- instaui/vars/event_context.py +4 -0
- instaui/vars/web_computed.py +30 -30
- instaui/watch/web_watch.py +5 -6
- instaui/webview/__init__.py +1 -0
- instaui/webview/_utils.py +8 -0
- instaui/webview/api.py +72 -0
- instaui/webview/func.py +114 -0
- instaui/webview/index.py +162 -0
- instaui/webview/resource.py +172 -0
- instaui/zero/func.py +31 -23
- instaui/zero/scope.py +110 -4
- {instaui-0.1.3.dist-info → instaui-0.1.5.dist-info}/METADATA +4 -1
- {instaui-0.1.3.dist-info → instaui-0.1.5.dist-info}/RECORD +88 -44
- instaui/handlers/computed_handler.py +0 -42
- instaui/handlers/config_handler.py +0 -13
- instaui/static/insta-ui.iife.js +0 -29
- instaui/static/insta-ui.iife.js.map +0 -1
- instaui/zero/test.html +0 -44
- {instaui-0.1.3.dist-info → instaui-0.1.5.dist-info}/LICENSE +0 -0
- {instaui-0.1.3.dist-info → instaui-0.1.5.dist-info}/WHEEL +0 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
import typing
|
3
|
+
from pathlib import Path
|
4
|
+
from urllib.parse import quote
|
5
|
+
import base64
|
6
|
+
|
7
|
+
|
8
|
+
_JS_PREFIX = "data:text/javascript;charset=utf-8"
|
9
|
+
_CSS_PREFIX = "data:text/css;charset=utf-8"
|
10
|
+
_ICON_PREFIX = "data:image/x-icon;base64"
|
11
|
+
|
12
|
+
|
13
|
+
def normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
|
14
|
+
if isinstance(path, Path):
|
15
|
+
path = path.read_text(encoding="utf-8")
|
16
|
+
|
17
|
+
return f"{prefix},{quote(path)}"
|
18
|
+
|
19
|
+
|
20
|
+
def normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
|
21
|
+
if path is None:
|
22
|
+
return None
|
23
|
+
return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
import typing
|
3
|
+
from pathlib import Path
|
4
|
+
from dataclasses import dataclass, field
|
5
|
+
from instaui.common.jsonable import dumps
|
6
|
+
from instaui.runtime.dataclass import JsLink
|
7
|
+
from .env import env
|
8
|
+
|
9
|
+
|
10
|
+
_html_template = env.get_template("webview.html")
|
11
|
+
|
12
|
+
|
13
|
+
@dataclass(frozen=True)
|
14
|
+
class WebViewVueAppComponent:
|
15
|
+
name: str
|
16
|
+
url: str
|
17
|
+
|
18
|
+
|
19
|
+
@dataclass
|
20
|
+
class WebViewTemplateModel:
|
21
|
+
vue_js_code: str
|
22
|
+
instaui_js_code: str
|
23
|
+
config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
|
24
|
+
extra_import_maps: typing.Dict[str, str] = field(default_factory=dict)
|
25
|
+
css_links: typing.List[str] = field(default_factory=list)
|
26
|
+
style_tags: typing.List[str] = field(default_factory=list)
|
27
|
+
js_links: typing.List[str] = field(default_factory=list)
|
28
|
+
script_tags: typing.List[str] = field(default_factory=list)
|
29
|
+
vue_app_use: typing.List[str] = field(default_factory=list)
|
30
|
+
vue_app_component: typing.List[WebViewVueAppComponent] = field(default_factory=list)
|
31
|
+
title: typing.Optional[str] = None
|
32
|
+
favicon_url: typing.Optional[str] = None
|
33
|
+
on_app_mounted: typing.Optional[typing.Callable] = None
|
34
|
+
|
35
|
+
def add_extra_import_map(self, name: str, code: str):
|
36
|
+
self.extra_import_maps[name] = code
|
37
|
+
|
38
|
+
@property
|
39
|
+
def import_maps_string(self):
|
40
|
+
data = {
|
41
|
+
**self.extra_import_maps,
|
42
|
+
"vue": self.vue_js_code,
|
43
|
+
"instaui": self.instaui_js_code,
|
44
|
+
}
|
45
|
+
|
46
|
+
return dumps(data)
|
47
|
+
|
48
|
+
|
49
|
+
def render_wbeview_html(model: WebViewTemplateModel) -> str:
|
50
|
+
return _html_template.render(model=model)
|
@@ -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 =
|
56
|
-
self.instaui_js_code =
|
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
|
-
|
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=
|
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:
|
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=
|
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 =
|
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
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
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,76 @@ __all__ = [
|
|
117
61
|
"str_format",
|
118
62
|
"url_location",
|
119
63
|
"on_page_request_lifespan",
|
64
|
+
"webview",
|
65
|
+
"code",
|
66
|
+
"markdown",
|
67
|
+
"echarts",
|
68
|
+
"use_shadcn_classless",
|
120
69
|
]
|
70
|
+
|
71
|
+
# -- static imports
|
72
|
+
from instaui.version import __version__
|
73
|
+
from instaui.vars import TMaybeRef
|
74
|
+
from instaui.vars.ref import ref, TRef
|
75
|
+
|
76
|
+
from instaui.vars.data import ConstData as data, TConstData
|
77
|
+
from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
|
78
|
+
from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
|
79
|
+
from instaui.vars.web_computed import web_computed as computed, TComputed
|
80
|
+
from instaui.vars.state import state, StateModel
|
81
|
+
from instaui.inject import inject_state, provide_state, injection_key
|
82
|
+
from instaui.vars.vfor_item import TVForItem, TVForIndex
|
83
|
+
from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
|
84
|
+
from instaui.html_tools import (
|
85
|
+
to_json,
|
86
|
+
add_css_link,
|
87
|
+
remove_css_link,
|
88
|
+
add_js_link,
|
89
|
+
add_style,
|
90
|
+
add_js_code,
|
91
|
+
add_vue_app_use,
|
92
|
+
to_config_data,
|
93
|
+
use_tailwind,
|
94
|
+
use_page_title,
|
95
|
+
)
|
96
|
+
|
97
|
+
from instaui.components.element import Element as element
|
98
|
+
from instaui.components.row import Row as row
|
99
|
+
from instaui.components.column import Column as column
|
100
|
+
from instaui.components.grid import Grid as grid
|
101
|
+
from instaui.components.directive import Directive as directive
|
102
|
+
from instaui.components.vfor import VFor as vfor
|
103
|
+
from instaui.components.vif import VIf as vif
|
104
|
+
from instaui.components.match import Match as match
|
105
|
+
from instaui.components.content import Content as content
|
106
|
+
|
107
|
+
from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
|
108
|
+
from instaui.event.js_event import js_event
|
109
|
+
from instaui.vars.event_context import EventContext as event_context
|
110
|
+
from instaui.runtime.context import get_context as context
|
111
|
+
|
112
|
+
import instaui.js as js
|
113
|
+
from instaui.watch.web_watch import watch
|
114
|
+
from instaui.watch.vue_watch import VueWatch as vue_watch
|
115
|
+
from instaui.watch.js_watch import js_watch
|
116
|
+
from instaui.handlers.watch_handler import WatchState as TWatchState
|
117
|
+
from instaui.skip import skip_output
|
118
|
+
from instaui.ui_functions.input_slient_data import InputSilentData as slient
|
119
|
+
from instaui.js.js_output import JsOutput as js_output
|
120
|
+
import instaui.experimental as experimental
|
121
|
+
|
122
|
+
from instaui.ui_functions.server import create_server as server
|
123
|
+
from instaui.ui_functions.ui_page import page
|
124
|
+
from instaui.ui_functions.url_location import UrlLocation as url_location
|
125
|
+
from instaui.ui_functions.str_format import str_format
|
126
|
+
from instaui.ui_functions.ui_types import TBindable, is_bindable
|
127
|
+
|
128
|
+
from .events import on_page_request_lifespan
|
129
|
+
|
130
|
+
# -- dynamic imports
|
131
|
+
from instaui.systems.module_system import LazyModule
|
132
|
+
code = LazyModule('instaui.components.shiki_code.shiki_code', 'Code')
|
133
|
+
markdown = LazyModule('instaui.components.markdown.markdown', 'Markdown')
|
134
|
+
webview = LazyModule('instaui.webview', 'WebviewWrapper')
|
135
|
+
echarts = LazyModule('instaui.components.echarts.echarts', 'ECharts')
|
136
|
+
use_shadcn_classless = LazyModule('instaui.shadcn_classless._index', 'use_shadcn_classless')
|
instaui/ui/__init__.pyi
ADDED
@@ -0,0 +1,135 @@
|
|
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
|
+
"webview",
|
65
|
+
"code",
|
66
|
+
"markdown",
|
67
|
+
"echarts",
|
68
|
+
"use_shadcn_classless",
|
69
|
+
]
|
70
|
+
|
71
|
+
# -- static imports
|
72
|
+
from instaui.version import __version__
|
73
|
+
from instaui.vars import TMaybeRef
|
74
|
+
from instaui.vars.ref import ref, TRef
|
75
|
+
|
76
|
+
from instaui.vars.data import ConstData as data, TConstData
|
77
|
+
from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
|
78
|
+
from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
|
79
|
+
from instaui.vars.web_computed import web_computed as computed, TComputed
|
80
|
+
from instaui.vars.state import state, StateModel
|
81
|
+
from instaui.inject import inject_state, provide_state, injection_key
|
82
|
+
from instaui.vars.vfor_item import TVForItem, TVForIndex
|
83
|
+
from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
|
84
|
+
from instaui.html_tools import (
|
85
|
+
to_json,
|
86
|
+
add_css_link,
|
87
|
+
remove_css_link,
|
88
|
+
add_js_link,
|
89
|
+
add_style,
|
90
|
+
add_js_code,
|
91
|
+
add_vue_app_use,
|
92
|
+
to_config_data,
|
93
|
+
use_tailwind,
|
94
|
+
use_page_title,
|
95
|
+
)
|
96
|
+
|
97
|
+
from instaui.components.element import Element as element
|
98
|
+
from instaui.components.row import Row as row
|
99
|
+
from instaui.components.column import Column as column
|
100
|
+
from instaui.components.grid import Grid as grid
|
101
|
+
from instaui.components.directive import Directive as directive
|
102
|
+
from instaui.components.vfor import VFor as vfor
|
103
|
+
from instaui.components.vif import VIf as vif
|
104
|
+
from instaui.components.match import Match as match
|
105
|
+
from instaui.components.content import Content as content
|
106
|
+
|
107
|
+
from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
|
108
|
+
from instaui.event.js_event import js_event
|
109
|
+
from instaui.vars.event_context import EventContext as event_context
|
110
|
+
from instaui.runtime.context import get_context as context
|
111
|
+
|
112
|
+
import instaui.js as js
|
113
|
+
from instaui.watch.web_watch import watch
|
114
|
+
from instaui.watch.vue_watch import VueWatch as vue_watch
|
115
|
+
from instaui.watch.js_watch import js_watch
|
116
|
+
from instaui.handlers.watch_handler import WatchState as TWatchState
|
117
|
+
from instaui.skip import skip_output
|
118
|
+
from instaui.ui_functions.input_slient_data import InputSilentData as slient
|
119
|
+
from instaui.js.js_output import JsOutput as js_output
|
120
|
+
import instaui.experimental as experimental
|
121
|
+
|
122
|
+
from instaui.ui_functions.server import create_server as server
|
123
|
+
from instaui.ui_functions.ui_page import page
|
124
|
+
from instaui.ui_functions.url_location import UrlLocation as url_location
|
125
|
+
from instaui.ui_functions.str_format import str_format
|
126
|
+
from instaui.ui_functions.ui_types import TBindable, is_bindable
|
127
|
+
|
128
|
+
from .events import on_page_request_lifespan
|
129
|
+
|
130
|
+
# -- dynamic imports
|
131
|
+
from instaui.components.shiki_code.shiki_code import Code as code
|
132
|
+
from instaui.components.markdown.markdown import Markdown as markdown
|
133
|
+
from instaui.webview import WebviewWrapper as webview
|
134
|
+
from instaui.components.echarts.echarts import ECharts as echarts
|
135
|
+
from instaui.shadcn_classless._index import use_shadcn_classless
|
instaui/ui/events.py
CHANGED
instaui/ui_functions/server.py
CHANGED
@@ -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
|
15
|
+
return Server(use_gzip=use_gzip)
|
instaui/vars/event_context.py
CHANGED
@@ -30,6 +30,10 @@ class EventContext(Jsonable, CanInputMixin):
|
|
30
30
|
def e():
|
31
31
|
return EventContext(":e => e")
|
32
32
|
|
33
|
+
@staticmethod
|
34
|
+
def target_value():
|
35
|
+
return EventContext(":e => e.target.value")
|
36
|
+
|
33
37
|
|
34
38
|
class DatasetEventContext(Jsonable, CanInputMixin):
|
35
39
|
def __init__(self, event_context: EventContext) -> None:
|
instaui/vars/web_computed.py
CHANGED
@@ -24,6 +24,9 @@ from instaui.vars.mixin_types.observable import ObservableMixin
|
|
24
24
|
from instaui.vars.mixin_types.common_type import TObservableInput
|
25
25
|
from instaui._helper import observable_helper
|
26
26
|
|
27
|
+
_SYNC_TYPE = "sync"
|
28
|
+
_ASYNC_TYPE = "async"
|
29
|
+
|
27
30
|
P = ParamSpec("P")
|
28
31
|
R = TypeVar("R")
|
29
32
|
|
@@ -70,47 +73,44 @@ class WebComputed(
|
|
70
73
|
|
71
74
|
app = get_app_slot()
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
)
|
76
|
+
hkey = watch_handler.create_handler_key(
|
77
|
+
page_path=app.page_path,
|
78
|
+
handler=self._fn,
|
79
|
+
)
|
78
80
|
|
79
|
-
|
81
|
+
watch_handler.register_handler(hkey, self._fn, len(self._outputs) + 1)
|
80
82
|
|
81
|
-
|
82
|
-
watch_handler.ASYNC_URL
|
83
|
-
if inspect.iscoroutinefunction(self._fn)
|
84
|
-
else watch_handler.SYNC_URL
|
85
|
-
)
|
83
|
+
# if app.mode == "web":
|
86
84
|
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
data["id"] = self._id
|
86
|
+
data["sid"] = self._sid
|
87
|
+
data["type"] = self.VAR_TYPE
|
90
88
|
|
91
|
-
|
92
|
-
|
89
|
+
if self._inputs:
|
90
|
+
data["inputs"] = self._inputs
|
93
91
|
|
94
|
-
|
95
|
-
|
92
|
+
if self._outputs:
|
93
|
+
data["outputs"] = self._outputs
|
96
94
|
|
97
|
-
|
98
|
-
|
95
|
+
if sum(self._is_slient_inputs) > 0:
|
96
|
+
data["slient"] = self._is_slient_inputs
|
99
97
|
|
100
|
-
|
101
|
-
|
98
|
+
if sum(self._is_data) > 0:
|
99
|
+
data["data"] = self._is_data
|
102
100
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
101
|
+
data["fType"] = (
|
102
|
+
_ASYNC_TYPE if inspect.iscoroutinefunction(self._fn) else _SYNC_TYPE
|
103
|
+
)
|
104
|
+
data["key"] = hkey
|
105
|
+
if self._init_value is not None:
|
106
|
+
data["init"] = self._init_value
|
107
107
|
|
108
|
-
|
109
|
-
|
108
|
+
if self._evaluating:
|
109
|
+
data["running"] = self._evaluating._to_output_config()
|
110
110
|
|
111
|
-
|
111
|
+
return data
|
112
112
|
|
113
|
-
return {}
|
113
|
+
# return {}
|
114
114
|
|
115
115
|
def __to_binding_config(self):
|
116
116
|
return {
|
instaui/watch/web_watch.py
CHANGED
@@ -13,6 +13,9 @@ from instaui.vars.mixin_types.py_binding import CanOutputMixin
|
|
13
13
|
from instaui.vars.mixin_types.common_type import TObservableInput
|
14
14
|
from instaui._helper import observable_helper
|
15
15
|
|
16
|
+
_SYNC_TYPE = "sync"
|
17
|
+
_ASYNC_TYPE = "async"
|
18
|
+
|
16
19
|
P = ParamSpec("P")
|
17
20
|
R = typing.TypeVar("R")
|
18
21
|
|
@@ -59,13 +62,9 @@ class WebWatch(Jsonable, typing.Generic[P, R]):
|
|
59
62
|
|
60
63
|
watch_handler.register_handler(hkey, self._fn, len(self._outputs))
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
if inspect.iscoroutinefunction(self._fn)
|
65
|
-
else watch_handler.SYNC_URL
|
65
|
+
data["fType"] = (
|
66
|
+
_ASYNC_TYPE if inspect.iscoroutinefunction(self._fn) else _SYNC_TYPE
|
66
67
|
)
|
67
|
-
|
68
|
-
data["url"] = url
|
69
68
|
data["key"] = hkey
|
70
69
|
if self._inputs:
|
71
70
|
data["inputs"] = self._inputs
|
@@ -0,0 +1 @@
|
|
1
|
+
from .index import WebviewWrapper
|