instaui 0.1.15__py2.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/__init__.py +9 -0
- instaui/_helper/observable_helper.py +45 -0
- instaui/arco/__init__.py +191 -0
- instaui/arco/_settings.py +25 -0
- instaui/arco/_use_tools/locale.py +50 -0
- instaui/arco/component_types.py +1019 -0
- instaui/arco/components/_utils.py +22 -0
- instaui/arco/components/affix.py +29 -0
- instaui/arco/components/alert.py +42 -0
- instaui/arco/components/anchor.py +42 -0
- instaui/arco/components/auto_complete.py +96 -0
- instaui/arco/components/avatar.py +55 -0
- instaui/arco/components/back_top.py +14 -0
- instaui/arco/components/badge.py +14 -0
- instaui/arco/components/breadcrumb.py +14 -0
- instaui/arco/components/button.py +43 -0
- instaui/arco/components/calendar.py +47 -0
- instaui/arco/components/card.py +14 -0
- instaui/arco/components/carousel.py +33 -0
- instaui/arco/components/cascader.py +111 -0
- instaui/arco/components/checkbox.py +32 -0
- instaui/arco/components/collapse.py +31 -0
- instaui/arco/components/color_picker.py +45 -0
- instaui/arco/components/comment.py +14 -0
- instaui/arco/components/config_provider.py +13 -0
- instaui/arco/components/date_picker.py +111 -0
- instaui/arco/components/descriptions.py +14 -0
- instaui/arco/components/divider.py +13 -0
- instaui/arco/components/drawer.py +98 -0
- instaui/arco/components/dropdown.py +45 -0
- instaui/arco/components/empty.py +14 -0
- instaui/arco/components/form.py +55 -0
- instaui/arco/components/icon.py +17 -0
- instaui/arco/components/image.py +33 -0
- instaui/arco/components/input.py +102 -0
- instaui/arco/components/input_number.py +97 -0
- instaui/arco/components/input_password.py +38 -0
- instaui/arco/components/input_search.py +37 -0
- instaui/arco/components/input_tag.py +110 -0
- instaui/arco/components/layout.py +13 -0
- instaui/arco/components/layout_content.py +6 -0
- instaui/arco/components/layout_footer.py +6 -0
- instaui/arco/components/layout_header.py +6 -0
- instaui/arco/components/layout_sider.py +53 -0
- instaui/arco/components/link.py +36 -0
- instaui/arco/components/list.py +68 -0
- instaui/arco/components/mention.py +97 -0
- instaui/arco/components/menu.py +88 -0
- instaui/arco/components/modal.py +97 -0
- instaui/arco/components/overflow_list.py +29 -0
- instaui/arco/components/page_header.py +29 -0
- instaui/arco/components/pagination.py +45 -0
- instaui/arco/components/pop_confirm.py +58 -0
- instaui/arco/components/popover.py +32 -0
- instaui/arco/components/progress.py +14 -0
- instaui/arco/components/radio.py +40 -0
- instaui/arco/components/radio_group.py +42 -0
- instaui/arco/components/rate.py +45 -0
- instaui/arco/components/resize_box.py +62 -0
- instaui/arco/components/result.py +14 -0
- instaui/arco/components/select.py +182 -0
- instaui/arco/components/skeleton.py +14 -0
- instaui/arco/components/slider.py +38 -0
- instaui/arco/components/space.py +14 -0
- instaui/arco/components/spin.py +14 -0
- instaui/arco/components/split.py +76 -0
- instaui/arco/components/statistic.py +14 -0
- instaui/arco/components/steps.py +32 -0
- instaui/arco/components/switch.py +57 -0
- instaui/arco/components/tab_pane.py +12 -0
- instaui/arco/components/table.py +276 -0
- instaui/arco/components/tabs.py +101 -0
- instaui/arco/components/tag.py +42 -0
- instaui/arco/components/textarea.py +84 -0
- instaui/arco/components/time_picker.py +76 -0
- instaui/arco/components/timeline.py +14 -0
- instaui/arco/components/tooltip.py +29 -0
- instaui/arco/components/transfer.py +58 -0
- instaui/arco/components/tree.py +120 -0
- instaui/arco/components/tree_select.py +86 -0
- instaui/arco/components/trigger.py +58 -0
- instaui/arco/components/typography.py +142 -0
- instaui/arco/components/upload.py +71 -0
- instaui/arco/components/verification_code.py +58 -0
- instaui/arco/components/watermark.py +14 -0
- instaui/arco/locales/__init__.py +4 -0
- instaui/arco/locales/_index.py +31 -0
- instaui/arco/locales/en_us.py +227 -0
- instaui/arco/locales/zh_cn.py +224 -0
- instaui/arco/setup.py +36 -0
- instaui/arco/static/instaui-arco.css +1 -0
- instaui/arco/static/instaui-arco.js +55771 -0
- instaui/arco/types.py +24 -0
- instaui/boot_info.py +43 -0
- instaui/common/jsonable.py +37 -0
- instaui/components/__init__.py +0 -0
- instaui/components/column.py +26 -0
- instaui/components/component.py +47 -0
- instaui/components/content.py +34 -0
- instaui/components/directive.py +55 -0
- instaui/components/element.py +573 -0
- instaui/components/grid.py +213 -0
- instaui/components/html/__init__.py +49 -0
- instaui/components/html/_mixins.py +34 -0
- instaui/components/html/_preset.py +4 -0
- instaui/components/html/button.py +38 -0
- instaui/components/html/checkbox.py +35 -0
- instaui/components/html/date.py +28 -0
- instaui/components/html/div.py +7 -0
- instaui/components/html/form.py +7 -0
- instaui/components/html/heading.py +51 -0
- instaui/components/html/input.py +28 -0
- instaui/components/html/label.py +21 -0
- instaui/components/html/li.py +17 -0
- instaui/components/html/link.py +31 -0
- instaui/components/html/number.py +34 -0
- instaui/components/html/paragraph.py +29 -0
- instaui/components/html/range.py +48 -0
- instaui/components/html/select.py +69 -0
- instaui/components/html/span.py +19 -0
- instaui/components/html/table.py +36 -0
- instaui/components/html/textarea.py +28 -0
- instaui/components/html/ul.py +20 -0
- instaui/components/label.py +5 -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/match.py +108 -0
- instaui/components/row.py +17 -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 +179 -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/slot.py +81 -0
- instaui/components/transition_group.py +9 -0
- instaui/components/value_element.py +52 -0
- instaui/components/vfor.py +142 -0
- instaui/components/vif.py +42 -0
- instaui/consts.py +23 -0
- instaui/dependencies/component_dependency.py +22 -0
- instaui/dependencies/plugin_dependency.py +28 -0
- instaui/event/event_mixin.py +12 -0
- instaui/event/js_event.py +82 -0
- instaui/event/vue_event.py +66 -0
- instaui/event/web_event.py +123 -0
- instaui/experimental/__init__.py +3 -0
- instaui/experimental/debug.py +48 -0
- instaui/extra_libs/_echarts.py +3 -0
- instaui/extra_libs/_import_error.py +9 -0
- instaui/extra_libs/_mermaid.py +3 -0
- instaui/extra_libs/_shiki_code.py +3 -0
- instaui/fastapi_server/_utils.py +42 -0
- instaui/fastapi_server/_uvicorn.py +37 -0
- instaui/fastapi_server/debug_mode_router.py +60 -0
- instaui/fastapi_server/dependency_router.py +28 -0
- instaui/fastapi_server/event_router.py +58 -0
- instaui/fastapi_server/middlewares.py +19 -0
- instaui/fastapi_server/request_context.py +19 -0
- instaui/fastapi_server/resource.py +30 -0
- instaui/fastapi_server/server.py +308 -0
- instaui/fastapi_server/watch_router.py +53 -0
- instaui/handlers/_utils.py +88 -0
- instaui/handlers/event_handler.py +60 -0
- instaui/handlers/watch_handler.py +61 -0
- instaui/html_tools.py +94 -0
- instaui/inject.py +33 -0
- instaui/js/__init__.py +4 -0
- instaui/js/js_output.py +15 -0
- instaui/js/lambda_func.py +35 -0
- instaui/launch_collector.py +52 -0
- instaui/page_info.py +13 -0
- instaui/runtime/__init__.py +29 -0
- instaui/runtime/_app.py +234 -0
- instaui/runtime/_inner_helper.py +9 -0
- instaui/runtime/_link_manager.py +89 -0
- instaui/runtime/context.py +47 -0
- instaui/runtime/dataclass.py +30 -0
- instaui/runtime/resource.py +65 -0
- instaui/runtime/scope.py +133 -0
- instaui/runtime/ui_state_scope.py +15 -0
- instaui/settings/__init__.py +4 -0
- instaui/settings/__settings.py +13 -0
- instaui/shadcn_classless/_index.py +42 -0
- instaui/shadcn_classless/static/shadcn-classless.css +403 -0
- instaui/skip.py +12 -0
- instaui/spa_router/__init__.py +26 -0
- instaui/spa_router/_components.py +35 -0
- instaui/spa_router/_file_base_utils.py +273 -0
- instaui/spa_router/_functions.py +122 -0
- instaui/spa_router/_install.py +11 -0
- instaui/spa_router/_route_model.py +117 -0
- instaui/spa_router/_router_box.py +40 -0
- instaui/spa_router/_router_output.py +22 -0
- instaui/spa_router/_router_param_var.py +51 -0
- instaui/spa_router/_types.py +4 -0
- instaui/spa_router/templates/page_routes +60 -0
- instaui/static/insta-ui.css +1 -0
- instaui/static/insta-ui.esm-browser.prod.js +3717 -0
- instaui/static/insta-ui.ico +0 -0
- instaui/static/insta-ui.js.map +1 -0
- instaui/static/instaui-tools-browser.js +511 -0
- instaui/static/templates/debug/sse.html +117 -0
- instaui/static/templates/web.html +74 -0
- instaui/static/templates/webview.html +78 -0
- instaui/static/templates/zero.html +71 -0
- instaui/static/vue.esm-browser.prod.js +9 -0
- instaui/static/vue.global.prod.js +9 -0
- instaui/static/vue.runtime.esm-browser.prod.js +5 -0
- instaui/systems/file_system.py +6 -0
- instaui/systems/func_system.py +119 -0
- instaui/systems/js_system.py +22 -0
- instaui/systems/module_system.py +46 -0
- instaui/systems/pydantic_system.py +27 -0
- instaui/systems/string_system.py +10 -0
- instaui/tailwind/__init__.py +6 -0
- instaui/tailwind/_index.py +24 -0
- instaui/tailwind/static/tailwindcss-v3.min.js +62 -0
- instaui/tailwind/static/tailwindcss-v4.min.js +8 -0
- instaui/template/__init__.py +4 -0
- instaui/template/_utils.py +23 -0
- instaui/template/env.py +7 -0
- instaui/template/web_template.py +49 -0
- instaui/template/webview_template.py +48 -0
- instaui/template/zero_template.py +105 -0
- instaui/ui/__init__.py +144 -0
- instaui/ui/__init__.pyi +149 -0
- instaui/ui/events.py +25 -0
- instaui/ui_functions/input_slient_data.py +16 -0
- instaui/ui_functions/server.py +15 -0
- instaui/ui_functions/str_format.py +36 -0
- instaui/ui_functions/ui_page.py +16 -0
- instaui/ui_functions/ui_types.py +13 -0
- instaui/ui_functions/url_location.py +33 -0
- instaui/vars/_types.py +8 -0
- instaui/vars/data.py +68 -0
- instaui/vars/element_ref.py +40 -0
- instaui/vars/event_context.py +49 -0
- instaui/vars/event_extend.py +0 -0
- instaui/vars/js_computed.py +117 -0
- instaui/vars/mixin_types/common_type.py +5 -0
- instaui/vars/mixin_types/element_binding.py +16 -0
- instaui/vars/mixin_types/observable.py +7 -0
- instaui/vars/mixin_types/pathable.py +14 -0
- instaui/vars/mixin_types/py_binding.py +13 -0
- instaui/vars/mixin_types/str_format_binding.py +8 -0
- instaui/vars/mixin_types/var_type.py +5 -0
- instaui/vars/path_var.py +90 -0
- instaui/vars/ref.py +103 -0
- instaui/vars/slot_prop.py +46 -0
- instaui/vars/state.py +97 -0
- instaui/vars/types.py +24 -0
- instaui/vars/vfor_item.py +204 -0
- instaui/vars/vue_computed.py +81 -0
- instaui/vars/web_computed.py +209 -0
- instaui/vars/web_view_computed.py +1 -0
- instaui/version.py +3 -0
- instaui/watch/_types.py +4 -0
- instaui/watch/_utils.py +3 -0
- instaui/watch/js_watch.py +110 -0
- instaui/watch/vue_watch.py +77 -0
- instaui/watch/web_watch.py +181 -0
- instaui/webview/__init__.py +2 -0
- instaui/webview/_utils.py +8 -0
- instaui/webview/api.py +72 -0
- instaui/webview/func.py +114 -0
- instaui/webview/index.py +161 -0
- instaui/webview/resource.py +172 -0
- instaui/zero/__init__.py +3 -0
- instaui/zero/func.py +123 -0
- instaui/zero/scope.py +109 -0
- instaui-0.1.15.dist-info/METADATA +152 -0
- instaui-0.1.15.dist-info/RECORD +283 -0
- instaui-0.1.15.dist-info/WHEEL +5 -0
- instaui-0.1.15.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
from urllib.parse import quote_plus
|
2
|
+
|
3
|
+
|
4
|
+
class UrlLocation:
|
5
|
+
@staticmethod
|
6
|
+
def goto(url: str, **params):
|
7
|
+
url = _url_with_params(url, **params)
|
8
|
+
return f'window.location.href = "{url}"'
|
9
|
+
|
10
|
+
@staticmethod
|
11
|
+
def replace(url: str, **params):
|
12
|
+
url = _url_with_params(url, **params)
|
13
|
+
return f'window.location.replace("{url}")'
|
14
|
+
|
15
|
+
@staticmethod
|
16
|
+
def back():
|
17
|
+
return "window.history.back()"
|
18
|
+
|
19
|
+
@staticmethod
|
20
|
+
def forward():
|
21
|
+
return "window.history.forward()"
|
22
|
+
|
23
|
+
@staticmethod
|
24
|
+
def reload():
|
25
|
+
return "window.history.go(0)"
|
26
|
+
|
27
|
+
|
28
|
+
def _url_with_params(url: str, **params):
|
29
|
+
url_params = "&".join([f"{k}={v}" for k, v in params.items()])
|
30
|
+
if url_params:
|
31
|
+
url += f"?{url_params}"
|
32
|
+
|
33
|
+
return quote_plus(url, safe=":/?=&")
|
instaui/vars/_types.py
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import Literal, TypeVar
|
3
|
+
|
4
|
+
|
5
|
+
_T_Value = TypeVar("_T_Value")
|
6
|
+
_T_Output_Value = TypeVar("_T_Output_Value", covariant=True)
|
7
|
+
_T_VAR_TYPE = Literal["ref", "computed", "webComputed"]
|
8
|
+
_T_Bindable_Type = Literal["ref", "computed", "js", "webComputed", "vforItem"]
|
instaui/vars/data.py
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import (
|
3
|
+
Any,
|
4
|
+
Dict,
|
5
|
+
)
|
6
|
+
|
7
|
+
from instaui.common.jsonable import Jsonable
|
8
|
+
from instaui.runtime._app import get_current_scope
|
9
|
+
from instaui.vars.path_var import PathVar
|
10
|
+
|
11
|
+
from .mixin_types.var_type import VarMixin
|
12
|
+
from .mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
13
|
+
from .mixin_types.element_binding import ElementBindingMixin
|
14
|
+
from .mixin_types.pathable import CanPathPropMixin
|
15
|
+
from .mixin_types.str_format_binding import StrFormatBindingMixin
|
16
|
+
|
17
|
+
|
18
|
+
class ConstData(
|
19
|
+
Jsonable,
|
20
|
+
PathVar,
|
21
|
+
VarMixin,
|
22
|
+
CanInputMixin,
|
23
|
+
CanOutputMixin,
|
24
|
+
CanPathPropMixin,
|
25
|
+
StrFormatBindingMixin,
|
26
|
+
ElementBindingMixin,
|
27
|
+
):
|
28
|
+
BIND_TYPE = "var"
|
29
|
+
|
30
|
+
def __init__(self, value: Any = None) -> None:
|
31
|
+
self.value = value # type: ignore
|
32
|
+
|
33
|
+
scope = get_current_scope()
|
34
|
+
scope.register_data(self)
|
35
|
+
self._sid = scope.id
|
36
|
+
self._id = scope.generate_vars_id()
|
37
|
+
|
38
|
+
def __to_binding_config(self):
|
39
|
+
return {
|
40
|
+
"type": self.BIND_TYPE,
|
41
|
+
"id": self._id,
|
42
|
+
"sid": self._sid,
|
43
|
+
}
|
44
|
+
|
45
|
+
def _to_pathable_binding_config(self) -> Dict:
|
46
|
+
return self.__to_binding_config()
|
47
|
+
|
48
|
+
def _to_path_prop_binding_config(self) -> Dict:
|
49
|
+
return self.__to_binding_config()
|
50
|
+
|
51
|
+
def _to_input_config(self):
|
52
|
+
return self.__to_binding_config()
|
53
|
+
|
54
|
+
def _to_output_config(self):
|
55
|
+
return self.__to_binding_config()
|
56
|
+
|
57
|
+
def _to_element_binding_config(self):
|
58
|
+
return self.__to_binding_config()
|
59
|
+
|
60
|
+
def _to_json_dict(self):
|
61
|
+
data = super()._to_json_dict()
|
62
|
+
data["sid"] = self._sid
|
63
|
+
data["id"] = self._id
|
64
|
+
|
65
|
+
return data
|
66
|
+
|
67
|
+
|
68
|
+
TConstData = ConstData
|
@@ -0,0 +1,40 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from instaui.common.jsonable import Jsonable
|
3
|
+
from instaui.runtime._app import get_current_scope
|
4
|
+
from instaui.vars.mixin_types.py_binding import CanOutputMixin
|
5
|
+
|
6
|
+
|
7
|
+
class ElementRef(Jsonable, CanOutputMixin):
|
8
|
+
def __init__(self) -> None:
|
9
|
+
scope = get_current_scope()
|
10
|
+
self._id = scope.generate_element_ref_id()
|
11
|
+
self.__sid = get_current_scope().id
|
12
|
+
|
13
|
+
def __to_binding_config(
|
14
|
+
self,
|
15
|
+
):
|
16
|
+
return {
|
17
|
+
"type": "ele_ref",
|
18
|
+
"id": self._id,
|
19
|
+
"sid": self.__sid,
|
20
|
+
}
|
21
|
+
|
22
|
+
def _to_output_config(self):
|
23
|
+
return self.__to_binding_config()
|
24
|
+
|
25
|
+
def _to_json_dict(self):
|
26
|
+
data = super()._to_json_dict()
|
27
|
+
data["id"] = self._id
|
28
|
+
data["sid"] = self.__sid
|
29
|
+
|
30
|
+
return data
|
31
|
+
|
32
|
+
def _to_element_config(self):
|
33
|
+
return {"id": self._id, "sid": self.__sid}
|
34
|
+
|
35
|
+
|
36
|
+
def run_element_method(method_name: str, *args, **kwargs):
|
37
|
+
return {
|
38
|
+
"method": method_name,
|
39
|
+
"args": args,
|
40
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from typing import Dict
|
2
|
+
from instaui.common.jsonable import Jsonable
|
3
|
+
from instaui.vars.mixin_types.py_binding import CanInputMixin
|
4
|
+
|
5
|
+
|
6
|
+
class EventContext(Jsonable, CanInputMixin):
|
7
|
+
_TYPE = "event"
|
8
|
+
|
9
|
+
def __init__(self, path: str):
|
10
|
+
self.path = path
|
11
|
+
|
12
|
+
def _to_input_config(self):
|
13
|
+
return self._to_binding_config()
|
14
|
+
|
15
|
+
def _to_binding_config(self) -> Dict:
|
16
|
+
return {
|
17
|
+
"type": self._TYPE,
|
18
|
+
"path": self.path,
|
19
|
+
}
|
20
|
+
|
21
|
+
@staticmethod
|
22
|
+
def dataset(name="eventData"):
|
23
|
+
return DatasetEventContext(EventContext(f":e=> e.target.dataset.{name}"))
|
24
|
+
|
25
|
+
@staticmethod
|
26
|
+
def args():
|
27
|
+
return EventContext(":(...e)=> e")
|
28
|
+
|
29
|
+
@staticmethod
|
30
|
+
def e():
|
31
|
+
return EventContext(":e => e")
|
32
|
+
|
33
|
+
@staticmethod
|
34
|
+
def target_value():
|
35
|
+
return EventContext(":e => e.target.value")
|
36
|
+
|
37
|
+
|
38
|
+
class DatasetEventContext(Jsonable, CanInputMixin):
|
39
|
+
def __init__(self, event_context: EventContext) -> None:
|
40
|
+
self._event_context = event_context
|
41
|
+
|
42
|
+
def _to_input_config(self):
|
43
|
+
return self._to_binding_config()
|
44
|
+
|
45
|
+
def _to_binding_config(self) -> Dict:
|
46
|
+
return self._event_context._to_binding_config()
|
47
|
+
|
48
|
+
def _to_json_dict(self):
|
49
|
+
return self._event_context._to_json_dict()
|
File without changes
|
@@ -0,0 +1,117 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
import typing
|
3
|
+
|
4
|
+
from instaui.common.jsonable import Jsonable
|
5
|
+
|
6
|
+
from instaui.runtime._app import get_current_scope
|
7
|
+
from instaui.vars.path_var import PathVar
|
8
|
+
from instaui.vars.mixin_types.var_type import VarMixin
|
9
|
+
from instaui.vars.mixin_types.element_binding import ElementBindingMixin
|
10
|
+
from instaui.vars.mixin_types.py_binding import CanInputMixin
|
11
|
+
from instaui.vars.mixin_types.pathable import CanPathPropMixin
|
12
|
+
from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
|
13
|
+
from instaui.vars.mixin_types.observable import ObservableMixin
|
14
|
+
from instaui.vars.mixin_types.common_type import TObservableInput
|
15
|
+
from instaui._helper import observable_helper
|
16
|
+
|
17
|
+
|
18
|
+
class JsComputed(
|
19
|
+
Jsonable,
|
20
|
+
PathVar,
|
21
|
+
VarMixin,
|
22
|
+
ObservableMixin,
|
23
|
+
CanInputMixin,
|
24
|
+
CanPathPropMixin,
|
25
|
+
StrFormatBindingMixin,
|
26
|
+
ElementBindingMixin,
|
27
|
+
):
|
28
|
+
"""
|
29
|
+
A client-side computed property that evaluates JavaScript code to derive reactive values.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
inputs (typing.Optional[typing.Sequence[TObservableInput]], optional): Reactive data sources to monitor.
|
33
|
+
Changes to these values trigger re-computation.
|
34
|
+
code (str): JavaScript code to execute for computing the value.
|
35
|
+
async_init_value (typing.Optional[typing.Any], optional): Initial value to use before first successful async evaluation.
|
36
|
+
|
37
|
+
# Example:
|
38
|
+
.. code-block:: python
|
39
|
+
a = ui.state(0)
|
40
|
+
|
41
|
+
plus_one = ui.js_computed(inputs=[a], code="a=> a+1")
|
42
|
+
|
43
|
+
html.number(a)
|
44
|
+
ui.label(plus_one)
|
45
|
+
"""
|
46
|
+
|
47
|
+
BIND_TYPE = "var"
|
48
|
+
|
49
|
+
def __init__(
|
50
|
+
self,
|
51
|
+
*,
|
52
|
+
inputs: typing.Optional[typing.Sequence[TObservableInput]] = None,
|
53
|
+
code: str,
|
54
|
+
async_init_value: typing.Optional[typing.Any] = None,
|
55
|
+
deep_compare_on_input: bool = False,
|
56
|
+
) -> None:
|
57
|
+
self.code = code
|
58
|
+
|
59
|
+
scope = get_current_scope()
|
60
|
+
scope.register_js_computed(self)
|
61
|
+
self._sid = scope.id
|
62
|
+
self._id = scope.generate_vars_id()
|
63
|
+
|
64
|
+
self._inputs, self._is_slient_inputs, self._is_data = (
|
65
|
+
observable_helper.analyze_observable_inputs(list(inputs or []))
|
66
|
+
)
|
67
|
+
|
68
|
+
self._async_init_value = async_init_value
|
69
|
+
self._deep_compare_on_input = deep_compare_on_input
|
70
|
+
|
71
|
+
def __to_binding_config(self):
|
72
|
+
return {
|
73
|
+
"type": self.BIND_TYPE,
|
74
|
+
"id": self._id,
|
75
|
+
"sid": self._sid,
|
76
|
+
}
|
77
|
+
|
78
|
+
def _to_input_config(self):
|
79
|
+
return self.__to_binding_config()
|
80
|
+
|
81
|
+
def _to_path_prop_binding_config(self) -> typing.Dict:
|
82
|
+
return self.__to_binding_config()
|
83
|
+
|
84
|
+
def _to_element_binding_config(self):
|
85
|
+
return self.__to_binding_config()
|
86
|
+
|
87
|
+
def _to_pathable_binding_config(self) -> typing.Dict:
|
88
|
+
return self.__to_binding_config()
|
89
|
+
|
90
|
+
def _to_observable_config(self):
|
91
|
+
return self.__to_binding_config()
|
92
|
+
|
93
|
+
def _to_json_dict(self):
|
94
|
+
data = super()._to_json_dict()
|
95
|
+
|
96
|
+
data["sid"] = self._sid
|
97
|
+
data["id"] = self._id
|
98
|
+
|
99
|
+
if self._inputs:
|
100
|
+
data["inputs"] = self._inputs
|
101
|
+
|
102
|
+
if sum(self._is_slient_inputs) > 0:
|
103
|
+
data["slient"] = self._is_slient_inputs
|
104
|
+
|
105
|
+
if sum(self._is_data) > 0:
|
106
|
+
data["data"] = self._is_data
|
107
|
+
|
108
|
+
if self._async_init_value is not None:
|
109
|
+
data["asyncInit"] = self._async_init_value
|
110
|
+
|
111
|
+
if self._deep_compare_on_input is not False:
|
112
|
+
data["deepEqOnInput"] = 1
|
113
|
+
|
114
|
+
return data
|
115
|
+
|
116
|
+
|
117
|
+
TJsComputed = JsComputed
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from typing import Dict, Generic, TypeVar
|
2
|
+
from abc import ABC, abstractmethod
|
3
|
+
|
4
|
+
T = TypeVar("T")
|
5
|
+
|
6
|
+
|
7
|
+
class ElementBindingMixin(ABC, Generic[T]):
|
8
|
+
@abstractmethod
|
9
|
+
def _to_element_binding_config(self) -> Dict:
|
10
|
+
pass
|
11
|
+
|
12
|
+
def _mark_used(self):
|
13
|
+
pass
|
14
|
+
|
15
|
+
def _is_used(self):
|
16
|
+
return True
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from typing import Dict
|
2
|
+
from abc import ABC, abstractmethod
|
3
|
+
|
4
|
+
|
5
|
+
class PathableMixin(ABC):
|
6
|
+
@abstractmethod
|
7
|
+
def _to_pathable_binding_config(self) -> Dict:
|
8
|
+
pass
|
9
|
+
|
10
|
+
|
11
|
+
class CanPathPropMixin(ABC):
|
12
|
+
@abstractmethod
|
13
|
+
def _to_path_prop_binding_config(self) -> Dict:
|
14
|
+
pass
|
instaui/vars/path_var.py
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from abc import abstractmethod
|
3
|
+
from typing import List, Optional, Union
|
4
|
+
from typing_extensions import Self
|
5
|
+
from instaui.vars.mixin_types.pathable import PathableMixin, CanPathPropMixin
|
6
|
+
from instaui.vars.mixin_types.element_binding import ElementBindingMixin
|
7
|
+
from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
8
|
+
from instaui.vars.mixin_types.observable import ObservableMixin
|
9
|
+
from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
|
10
|
+
|
11
|
+
|
12
|
+
class PathVar(PathableMixin):
|
13
|
+
def __getitem__(self, item: Union[str, int, CanPathPropMixin]):
|
14
|
+
return PathTrackerBindable(self)[item]
|
15
|
+
|
16
|
+
def inverse(self):
|
17
|
+
return PathTrackerBindable(self).inverse()
|
18
|
+
|
19
|
+
def __add__(self, other: str):
|
20
|
+
return PathTrackerBindable(self) + other
|
21
|
+
|
22
|
+
def __radd__(self, other: str):
|
23
|
+
return other + PathTrackerBindable(self)
|
24
|
+
|
25
|
+
|
26
|
+
class PathTracker:
|
27
|
+
def __init__(self, paths: Optional[List[Union[str, List[str]]]] = None):
|
28
|
+
self.paths = paths or []
|
29
|
+
|
30
|
+
def __getitem__(self, key) -> Self:
|
31
|
+
return self.__new_self__([*self.paths, key])
|
32
|
+
|
33
|
+
def __getattr__(self, key) -> Self:
|
34
|
+
return self.__new_self__([*self.paths, key])
|
35
|
+
|
36
|
+
def inverse(self) -> Self:
|
37
|
+
return self.__new_self__([*self.paths, ["!"]])
|
38
|
+
|
39
|
+
def __add__(self, other: str) -> Self:
|
40
|
+
return self.__new_self__([*self.paths, ["+", other]])
|
41
|
+
|
42
|
+
def __radd__(self, other: str) -> Self:
|
43
|
+
return self.__new_self__([*self.paths, ["~+", other]])
|
44
|
+
|
45
|
+
@abstractmethod
|
46
|
+
def __new_self__(self, paths: List[Union[str, List[str]]]) -> Self:
|
47
|
+
pass
|
48
|
+
|
49
|
+
|
50
|
+
class PathTrackerBindable(
|
51
|
+
PathTracker,
|
52
|
+
CanInputMixin,
|
53
|
+
ObservableMixin,
|
54
|
+
CanOutputMixin,
|
55
|
+
ElementBindingMixin,
|
56
|
+
StrFormatBindingMixin,
|
57
|
+
):
|
58
|
+
def __init__(self, source: PathableMixin):
|
59
|
+
super().__init__()
|
60
|
+
self.__source = source
|
61
|
+
|
62
|
+
def __new_self__(self, paths: List[Union[str, List[str]]]) -> PathTrackerBindable:
|
63
|
+
obj = PathTrackerBindable(self.__source)
|
64
|
+
obj.paths = paths
|
65
|
+
return obj
|
66
|
+
|
67
|
+
def _to_element_binding_config(self):
|
68
|
+
return self._to_json_dict()
|
69
|
+
|
70
|
+
def _to_input_config(self):
|
71
|
+
return self._to_json_dict()
|
72
|
+
|
73
|
+
def _to_output_config(self):
|
74
|
+
return self._to_json_dict()
|
75
|
+
|
76
|
+
def _to_observable_config(self):
|
77
|
+
return self._to_json_dict()
|
78
|
+
|
79
|
+
def _to_json_dict(self):
|
80
|
+
data = self.__source._to_pathable_binding_config()
|
81
|
+
|
82
|
+
if self.paths:
|
83
|
+
data["path"] = [
|
84
|
+
["bind", path._to_path_prop_binding_config()]
|
85
|
+
if isinstance(path, CanPathPropMixin)
|
86
|
+
else path
|
87
|
+
for path in self.paths
|
88
|
+
]
|
89
|
+
|
90
|
+
return data
|
instaui/vars/ref.py
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import (
|
3
|
+
Dict,
|
4
|
+
Generic,
|
5
|
+
Optional,
|
6
|
+
TypeVar,
|
7
|
+
Union,
|
8
|
+
overload,
|
9
|
+
)
|
10
|
+
|
11
|
+
from instaui.common.jsonable import Jsonable
|
12
|
+
from instaui.runtime._app import get_current_scope
|
13
|
+
from instaui.vars.path_var import PathVar
|
14
|
+
|
15
|
+
from .mixin_types.var_type import VarMixin
|
16
|
+
from .mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
17
|
+
from .mixin_types.observable import ObservableMixin
|
18
|
+
from .mixin_types.element_binding import ElementBindingMixin
|
19
|
+
from .mixin_types.pathable import CanPathPropMixin
|
20
|
+
from .mixin_types.str_format_binding import StrFormatBindingMixin
|
21
|
+
|
22
|
+
|
23
|
+
_T_Value = TypeVar("_T_Value")
|
24
|
+
|
25
|
+
|
26
|
+
class Ref(
|
27
|
+
Jsonable,
|
28
|
+
PathVar,
|
29
|
+
VarMixin,
|
30
|
+
ObservableMixin,
|
31
|
+
CanInputMixin,
|
32
|
+
CanOutputMixin,
|
33
|
+
CanPathPropMixin,
|
34
|
+
StrFormatBindingMixin,
|
35
|
+
ElementBindingMixin[_T_Value],
|
36
|
+
Generic[_T_Value],
|
37
|
+
):
|
38
|
+
VAR_TYPE = "var"
|
39
|
+
|
40
|
+
def __init__(self, value: Optional[_T_Value] = None) -> None:
|
41
|
+
self.value = value # type: ignore
|
42
|
+
scope = get_current_scope()
|
43
|
+
scope.register_ref(self)
|
44
|
+
|
45
|
+
self._sid = scope.id
|
46
|
+
self._id = scope.generate_vars_id()
|
47
|
+
self._debounced = None
|
48
|
+
|
49
|
+
def debounced(self, secounds: float):
|
50
|
+
self._debounced = secounds
|
51
|
+
return self
|
52
|
+
|
53
|
+
def __to_binding_config(self):
|
54
|
+
return {
|
55
|
+
"type": self.VAR_TYPE,
|
56
|
+
"id": self._id,
|
57
|
+
"sid": self._sid,
|
58
|
+
}
|
59
|
+
|
60
|
+
def _to_pathable_binding_config(self) -> Dict:
|
61
|
+
return self.__to_binding_config()
|
62
|
+
|
63
|
+
def _to_path_prop_binding_config(self) -> Dict:
|
64
|
+
return self.__to_binding_config()
|
65
|
+
|
66
|
+
def _to_observable_config(self):
|
67
|
+
return self.__to_binding_config()
|
68
|
+
|
69
|
+
def _to_input_config(self):
|
70
|
+
return self.__to_binding_config()
|
71
|
+
|
72
|
+
def _to_output_config(self):
|
73
|
+
return self.__to_binding_config()
|
74
|
+
|
75
|
+
def _to_element_binding_config(self):
|
76
|
+
return self.__to_binding_config()
|
77
|
+
|
78
|
+
def _to_json_dict(self):
|
79
|
+
data = super()._to_json_dict()
|
80
|
+
data["sid"] = self._sid
|
81
|
+
data["id"] = self._id
|
82
|
+
|
83
|
+
if self._debounced is not None:
|
84
|
+
data["debounced"] = self._debounced
|
85
|
+
|
86
|
+
return data
|
87
|
+
|
88
|
+
|
89
|
+
TRef = Ref
|
90
|
+
|
91
|
+
|
92
|
+
@overload
|
93
|
+
def ref(value: Ref[_T_Value]) -> Ref[_T_Value]: ...
|
94
|
+
|
95
|
+
|
96
|
+
@overload
|
97
|
+
def ref(value: Optional[_T_Value] = None) -> Ref[_T_Value]: ...
|
98
|
+
|
99
|
+
|
100
|
+
def ref(value: Union[Ref[_T_Value], _T_Value, None] = None):
|
101
|
+
if isinstance(value, Ref):
|
102
|
+
return value
|
103
|
+
return Ref(value)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import (
|
3
|
+
Dict,
|
4
|
+
)
|
5
|
+
from instaui.common.jsonable import Jsonable
|
6
|
+
|
7
|
+
from instaui.vars.path_var import PathVar
|
8
|
+
|
9
|
+
from .mixin_types.py_binding import CanInputMixin
|
10
|
+
from .mixin_types.element_binding import ElementBindingMixin
|
11
|
+
from .mixin_types.pathable import CanPathPropMixin
|
12
|
+
|
13
|
+
|
14
|
+
class BindingSlotPropItem(
|
15
|
+
Jsonable,
|
16
|
+
PathVar,
|
17
|
+
ElementBindingMixin,
|
18
|
+
CanInputMixin,
|
19
|
+
CanPathPropMixin,
|
20
|
+
):
|
21
|
+
def __init__(self, slot_id: str, name: str) -> None:
|
22
|
+
super().__init__()
|
23
|
+
self.name = name
|
24
|
+
self._id = slot_id
|
25
|
+
|
26
|
+
def _to_element_binding_config(self):
|
27
|
+
return self._to_binding_config()
|
28
|
+
|
29
|
+
def _to_input_config(self):
|
30
|
+
return self._to_binding_config()
|
31
|
+
|
32
|
+
def _to_path_prop_binding_config(self) -> Dict:
|
33
|
+
return self._to_binding_config()
|
34
|
+
|
35
|
+
def _to_pathable_binding_config(self) -> Dict:
|
36
|
+
return self._to_binding_config()
|
37
|
+
|
38
|
+
def _to_json_dict(self):
|
39
|
+
data = super()._to_json_dict()
|
40
|
+
data["type"] = "sp"
|
41
|
+
data["id"] = self._id
|
42
|
+
|
43
|
+
return data
|
44
|
+
|
45
|
+
def _to_binding_config(self) -> Dict:
|
46
|
+
return self._to_json_dict()
|