instaui 0.1.0__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 (152) hide show
  1. instaui/__init__.py +9 -0
  2. instaui/_helper/observable_helper.py +35 -0
  3. instaui/boot_info.py +43 -0
  4. instaui/common/jsonable.py +37 -0
  5. instaui/components/__init__.py +0 -0
  6. instaui/components/column.py +18 -0
  7. instaui/components/component.py +47 -0
  8. instaui/components/content.py +34 -0
  9. instaui/components/directive.py +55 -0
  10. instaui/components/element.py +462 -0
  11. instaui/components/grid.py +80 -0
  12. instaui/components/html/__init__.py +36 -0
  13. instaui/components/html/_mixins.py +34 -0
  14. instaui/components/html/button.py +38 -0
  15. instaui/components/html/checkbox.py +42 -0
  16. instaui/components/html/date.py +28 -0
  17. instaui/components/html/div.py +7 -0
  18. instaui/components/html/form.py +7 -0
  19. instaui/components/html/input.py +28 -0
  20. instaui/components/html/label.py +21 -0
  21. instaui/components/html/li.py +17 -0
  22. instaui/components/html/link.py +31 -0
  23. instaui/components/html/number.py +34 -0
  24. instaui/components/html/paragraph.py +19 -0
  25. instaui/components/html/range.py +45 -0
  26. instaui/components/html/select.py +93 -0
  27. instaui/components/html/span.py +19 -0
  28. instaui/components/html/ul.py +20 -0
  29. instaui/components/match.py +106 -0
  30. instaui/components/row.py +19 -0
  31. instaui/components/slot.py +82 -0
  32. instaui/components/transition_group.py +9 -0
  33. instaui/components/value_element.py +48 -0
  34. instaui/components/vfor.py +140 -0
  35. instaui/components/vif.py +38 -0
  36. instaui/consts.py +18 -0
  37. instaui/dependencies/__init__.py +15 -0
  38. instaui/dependencies/component_registrar.py +82 -0
  39. instaui/dependencies/installer.py +5 -0
  40. instaui/event/event_mixin.py +12 -0
  41. instaui/event/js_event.py +57 -0
  42. instaui/event/web_event.py +108 -0
  43. instaui/experimental/__init__.py +4 -0
  44. instaui/experimental/debug.py +48 -0
  45. instaui/fastapi_server/_utils.py +42 -0
  46. instaui/fastapi_server/_uvicorn.py +37 -0
  47. instaui/fastapi_server/config_router.py +60 -0
  48. instaui/fastapi_server/debug_mode_router.py +61 -0
  49. instaui/fastapi_server/event_router.py +58 -0
  50. instaui/fastapi_server/middlewares.py +19 -0
  51. instaui/fastapi_server/request_context.py +19 -0
  52. instaui/fastapi_server/server.py +246 -0
  53. instaui/fastapi_server/watch_router.py +53 -0
  54. instaui/handlers/_utils.py +66 -0
  55. instaui/handlers/computed_handler.py +42 -0
  56. instaui/handlers/config_handler.py +13 -0
  57. instaui/handlers/event_handler.py +58 -0
  58. instaui/handlers/watch_handler.py +57 -0
  59. instaui/html_tools.py +139 -0
  60. instaui/inject.py +33 -0
  61. instaui/js/__init__.py +4 -0
  62. instaui/js/js_output.py +15 -0
  63. instaui/js/lambda_func.py +35 -0
  64. instaui/launch_collector.py +52 -0
  65. instaui/page_info.py +23 -0
  66. instaui/runtime/__init__.py +29 -0
  67. instaui/runtime/_app.py +206 -0
  68. instaui/runtime/_inner_helper.py +9 -0
  69. instaui/runtime/context.py +47 -0
  70. instaui/runtime/dataclass.py +30 -0
  71. instaui/runtime/resource.py +87 -0
  72. instaui/runtime/scope.py +107 -0
  73. instaui/runtime/ui_state_scope.py +15 -0
  74. instaui/settings/__init__.py +4 -0
  75. instaui/settings/__settings.py +13 -0
  76. instaui/skip.py +12 -0
  77. instaui/spa_router/__init__.py +26 -0
  78. instaui/spa_router/_components.py +35 -0
  79. instaui/spa_router/_file_base_utils.py +264 -0
  80. instaui/spa_router/_functions.py +122 -0
  81. instaui/spa_router/_install.py +11 -0
  82. instaui/spa_router/_route_model.py +139 -0
  83. instaui/spa_router/_router_box.py +40 -0
  84. instaui/spa_router/_router_output.py +22 -0
  85. instaui/spa_router/_router_param_var.py +51 -0
  86. instaui/spa_router/_types.py +4 -0
  87. instaui/spa_router/templates/page_routes +59 -0
  88. instaui/static/insta-ui.css +1 -0
  89. instaui/static/insta-ui.esm-browser.prod.js +3663 -0
  90. instaui/static/insta-ui.iife.js +29 -0
  91. instaui/static/insta-ui.iife.js.map +1 -0
  92. instaui/static/insta-ui.js.map +1 -0
  93. instaui/static/tailwindcss.min.js +62 -0
  94. instaui/static/templates/debug/sse.html +117 -0
  95. instaui/static/templates/web.html +118 -0
  96. instaui/static/templates/zero.html +55 -0
  97. instaui/static/vue.esm-browser.prod.js +9 -0
  98. instaui/static/vue.global.prod.js +9 -0
  99. instaui/static/vue.runtime.esm-browser.prod.js +5 -0
  100. instaui/systems/file_system.py +17 -0
  101. instaui/systems/func_system.py +104 -0
  102. instaui/systems/js_system.py +22 -0
  103. instaui/systems/pydantic_system.py +27 -0
  104. instaui/systems/string_system.py +10 -0
  105. instaui/template/__init__.py +4 -0
  106. instaui/template/env.py +7 -0
  107. instaui/template/web_template.py +55 -0
  108. instaui/template/zero_template.py +24 -0
  109. instaui/ui/__init__.py +121 -0
  110. instaui/ui/events.py +25 -0
  111. instaui/ui_functions/input_slient_data.py +16 -0
  112. instaui/ui_functions/server.py +13 -0
  113. instaui/ui_functions/str_format.py +36 -0
  114. instaui/ui_functions/ui_page.py +31 -0
  115. instaui/ui_functions/ui_types.py +13 -0
  116. instaui/ui_functions/url_location.py +33 -0
  117. instaui/vars/__init__.py +13 -0
  118. instaui/vars/_types.py +8 -0
  119. instaui/vars/_utils.py +12 -0
  120. instaui/vars/data.py +68 -0
  121. instaui/vars/element_ref.py +42 -0
  122. instaui/vars/event_context.py +45 -0
  123. instaui/vars/event_extend.py +0 -0
  124. instaui/vars/js_computed.py +95 -0
  125. instaui/vars/mixin_types/common_type.py +5 -0
  126. instaui/vars/mixin_types/element_binding.py +10 -0
  127. instaui/vars/mixin_types/observable.py +7 -0
  128. instaui/vars/mixin_types/pathable.py +14 -0
  129. instaui/vars/mixin_types/py_binding.py +13 -0
  130. instaui/vars/mixin_types/str_format_binding.py +8 -0
  131. instaui/vars/mixin_types/var_type.py +5 -0
  132. instaui/vars/path_var.py +89 -0
  133. instaui/vars/ref.py +103 -0
  134. instaui/vars/slot_prop.py +46 -0
  135. instaui/vars/state.py +82 -0
  136. instaui/vars/types.py +24 -0
  137. instaui/vars/vfor_item.py +204 -0
  138. instaui/vars/vue_computed.py +82 -0
  139. instaui/vars/web_computed.py +157 -0
  140. instaui/vars/web_view_computed.py +1 -0
  141. instaui/version.py +3 -0
  142. instaui/watch/_types.py +4 -0
  143. instaui/watch/_utils.py +3 -0
  144. instaui/watch/js_watch.py +74 -0
  145. instaui/watch/vue_watch.py +61 -0
  146. instaui/watch/web_watch.py +123 -0
  147. instaui/zero/__init__.py +3 -0
  148. instaui/zero/scope.py +9 -0
  149. instaui-0.1.0.dist-info/LICENSE +21 -0
  150. instaui-0.1.0.dist-info/METADATA +154 -0
  151. instaui-0.1.0.dist-info/RECORD +152 -0
  152. instaui-0.1.0.dist-info/WHEEL +4 -0
instaui/ui/__init__.py ADDED
@@ -0,0 +1,121 @@
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
+ to_html,
16
+ add_css_link,
17
+ add_js_link,
18
+ add_style,
19
+ add_js_code,
20
+ add_vue_app_use,
21
+ to_config_data,
22
+ )
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
+ from instaui.dependencies import install_component
35
+
36
+ from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
37
+ from instaui.event.js_event import js_event
38
+ from instaui.vars.event_context import EventContext as event_context
39
+ from instaui.runtime.context import get_context as context
40
+
41
+ import instaui.js as js
42
+ from instaui.watch.web_watch import watch
43
+ from instaui.watch.vue_watch import VueWatch as vue_watch
44
+ from instaui.watch.js_watch import js_watch
45
+ from instaui.handlers.watch_handler import WatchState as TWatchState
46
+ from instaui.skip import skip_output
47
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
48
+ from instaui.js.js_output import JsOutput as js_output
49
+ import instaui.experimental as experimental
50
+
51
+
52
+ from instaui.ui_functions.server import create_server as server
53
+ from instaui.ui_functions.ui_page import page
54
+ from instaui.ui_functions.url_location import UrlLocation as url_location
55
+ from instaui.ui_functions.str_format import str_format
56
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
57
+
58
+ from .events import on_page_request_lifespan
59
+
60
+ __all__ = [
61
+ "__version__",
62
+ "TMaybeRef",
63
+ "TBindable",
64
+ "is_bindable",
65
+ "ref",
66
+ "slient",
67
+ "data",
68
+ "TConstData",
69
+ "TRef",
70
+ "vue_computed",
71
+ "TVueComputed",
72
+ "js_computed",
73
+ "TJsComputed",
74
+ "computed",
75
+ "TComputed",
76
+ "state",
77
+ "StateModel",
78
+ "inject_state",
79
+ "provide_state",
80
+ "injection_key",
81
+ "TVForItem",
82
+ "TVForIndex",
83
+ "element_ref",
84
+ "run_element_method",
85
+ "to_json",
86
+ "to_html",
87
+ "to_config_data",
88
+ "element",
89
+ "vfor",
90
+ "content",
91
+ "add_style",
92
+ "add_css_link",
93
+ "add_js_code",
94
+ "add_js_link",
95
+ "add_vue_app_use",
96
+ "install_component",
97
+ "directive",
98
+ "vif",
99
+ "page",
100
+ "event",
101
+ "js_event",
102
+ "event_context",
103
+ "TEventFn",
104
+ "server",
105
+ "context",
106
+ "row",
107
+ "grid",
108
+ "js",
109
+ "watch",
110
+ "vue_watch",
111
+ "js_watch",
112
+ "TWatchState",
113
+ "match",
114
+ "column",
115
+ "experimental",
116
+ "skip_output",
117
+ "js_output",
118
+ "str_format",
119
+ "url_location",
120
+ "on_page_request_lifespan",
121
+ ]
instaui/ui/events.py ADDED
@@ -0,0 +1,25 @@
1
+ from typing import Callable
2
+ from instaui.launch_collector import get_launch_collector
3
+
4
+
5
+ def on_page_request_lifespan(fn: Callable):
6
+ """Register a function to be called on each page request.
7
+
8
+ Args:
9
+ fn (Callable): A function to be called on each page request.
10
+
11
+ Example:
12
+ .. code-block:: python
13
+ @ui.on_page_request_lifespan
14
+ def _():
15
+ print("page request start")
16
+ yield
17
+ print("page request end")
18
+
19
+ # can stop the lifespan by calling the returned function
20
+ stop_lifespan = ui.on_page_request_lifespan(lambda: None)
21
+ stop_lifespan()
22
+ """
23
+
24
+ remove_key = get_launch_collector().add_page_request_lifespan(fn)
25
+ return lambda: get_launch_collector().remove_page_request_lifespan(remove_key)
@@ -0,0 +1,16 @@
1
+ import typing
2
+ from instaui.vars.mixin_types.py_binding import CanInputMixin
3
+
4
+
5
+ class InputSilentData(CanInputMixin):
6
+ def __init__(self, value: typing.Union[CanInputMixin, typing.Any]) -> None:
7
+ self.value = value
8
+
9
+ def is_const_value(self) -> bool:
10
+ return not isinstance(self.value, CanInputMixin)
11
+
12
+ def _to_input_config(self):
13
+ if isinstance(self.value, CanInputMixin):
14
+ return self.value._to_input_config()
15
+ else:
16
+ return self.value
@@ -0,0 +1,13 @@
1
+ from instaui.runtime.context import get_context
2
+
3
+
4
+ def create_server(
5
+ debug: bool = True,
6
+ ):
7
+ from instaui.fastapi_server.server import Server
8
+
9
+ context = get_context()
10
+ context._app_mode = "web"
11
+ context._debug_mode = debug
12
+
13
+ return Server.get_instance()
@@ -0,0 +1,36 @@
1
+ from typing import cast
2
+ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
3
+ from instaui.vars.vue_computed import VueComputed
4
+
5
+
6
+ def str_format(template: str, *args, **kwargs):
7
+ bindings = {}
8
+
9
+ tran_args = []
10
+
11
+ for idx, arg in enumerate(args):
12
+ is_mixin = isinstance(arg, StrFormatBindingMixin)
13
+ value = (
14
+ cast(StrFormatBindingMixin, arg)._to_str_format_binding(idx)
15
+ if is_mixin
16
+ else arg
17
+ )
18
+ tran_args.append(value[-1] if is_mixin else value)
19
+ if is_mixin:
20
+ bindings[value[0]] = arg
21
+
22
+ tran_kwargs = {}
23
+
24
+ for idx, (k, v) in enumerate(kwargs.items()):
25
+ is_mixin = isinstance(v, StrFormatBindingMixin)
26
+ value = (
27
+ cast(StrFormatBindingMixin, v)._to_str_format_binding(idx)
28
+ if is_mixin
29
+ else v
30
+ )
31
+ tran_kwargs[k] = value[-1] if is_mixin else value
32
+ if is_mixin:
33
+ bindings[value[0]] = v
34
+
35
+ code = "()=>`" + template.format(*tran_args, **tran_kwargs) + "`"
36
+ return VueComputed(code, bindings=bindings)
@@ -0,0 +1,31 @@
1
+ import inspect
2
+ from typing import Callable, Optional
3
+ from instaui.launch_collector import get_launch_collector, PageInfo
4
+
5
+
6
+ def page(
7
+ url: str,
8
+ *,
9
+ page_loading: Optional[Callable] = None,
10
+ use_tailwind: Optional[bool] = None,
11
+ ):
12
+ """Register a page route.
13
+
14
+ Args:
15
+ url (str): The route URL.
16
+ page_loading (Optional[Callable], optional): Function to display a preload interface for the page. Defaults to None.
17
+ use_tailwind (Optional[bool], optional): Whether to use tailwind or not. Defaults to None(not use tailwind).
18
+
19
+ Raises:
20
+ ValueError: if page_loading_fn is a coroutine function
21
+ """
22
+ if page_loading is not None and inspect.iscoroutinefunction(page_loading):
23
+ raise ValueError("page_loading_fn must be a synchronous function")
24
+
25
+ def wrapper(func: Callable):
26
+ get_launch_collector().register_page(
27
+ PageInfo(url, func, page_loading, use_tailwind=use_tailwind)
28
+ )
29
+ return func
30
+
31
+ return wrapper
@@ -0,0 +1,13 @@
1
+ from typing import Any, TypeVar, Union
2
+ from instaui.vars.mixin_types.observable import ObservableMixin
3
+ from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
4
+ from instaui.vars.mixin_types.element_binding import ElementBindingMixin
5
+
6
+ _T = TypeVar("_T")
7
+
8
+
9
+ def is_bindable(obj: Any):
10
+ return isinstance(obj, (CanInputMixin, CanOutputMixin,ObservableMixin, ElementBindingMixin))
11
+
12
+
13
+ TBindable = Union[CanInputMixin, CanOutputMixin,ObservableMixin, ElementBindingMixin[_T]]
@@ -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=":/?=&")
@@ -0,0 +1,13 @@
1
+ from .ref import Ref
2
+ from .web_computed import WebComputed
3
+ from .vfor_item import VForItem
4
+ from .types import TRefOrComputed, TMaybeRef
5
+
6
+
7
+ __all__ = [
8
+ "Ref",
9
+ "WebComputed",
10
+ "TRefOrComputed",
11
+ "TMaybeRef",
12
+ "VForItem",
13
+ ]
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/_utils.py ADDED
@@ -0,0 +1,12 @@
1
+ from instaui.runtime._app import get_current_scope
2
+ from instaui.vars.mixin_types.var_type import VarMixin
3
+
4
+
5
+ def register_var(object: VarMixin):
6
+ """
7
+ sid,id = register_var(object)
8
+ """
9
+ scope = get_current_scope()
10
+ scope.register_var(object)
11
+
12
+ return scope.id, scope.generate_vars_id()
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.vars.path_var import PathVar
9
+
10
+ from .mixin_types.var_type import VarMixin
11
+ from .mixin_types.py_binding import CanInputMixin, CanOutputMixin
12
+ from .mixin_types.element_binding import ElementBindingMixin
13
+ from .mixin_types.pathable import CanPathPropMixin
14
+ from .mixin_types.str_format_binding import StrFormatBindingMixin
15
+ from . import _utils
16
+
17
+
18
+ class ConstData(
19
+ Jsonable,
20
+ PathVar,
21
+ VarMixin,
22
+ CanInputMixin,
23
+ CanOutputMixin,
24
+ CanPathPropMixin,
25
+ StrFormatBindingMixin,
26
+ ElementBindingMixin,
27
+ ):
28
+ VAR_TYPE = "data"
29
+
30
+ def __init__(self, value: Any = None) -> None:
31
+ self.value = value # type: ignore
32
+
33
+ sid, id = _utils.register_var(self)
34
+ self._sid = sid
35
+ self._id = id
36
+
37
+ def __to_binding_config(self):
38
+ return {
39
+ "type": self.VAR_TYPE,
40
+ "id": self._id,
41
+ "sid": self._sid,
42
+ }
43
+
44
+ def _to_pathable_binding_config(self) -> Dict:
45
+ return self.__to_binding_config()
46
+
47
+ def _to_path_prop_binding_config(self) -> Dict:
48
+ return self.__to_binding_config()
49
+
50
+ def _to_input_config(self):
51
+ return self.__to_binding_config()
52
+
53
+ def _to_output_config(self):
54
+ return self.__to_binding_config()
55
+
56
+ def _to_element_binding_config(self):
57
+ return self.__to_binding_config()
58
+
59
+ def _to_json_dict(self):
60
+ data = super()._to_json_dict()
61
+ data["sid"] = self._sid
62
+ data["id"] = self._id
63
+ data["type"] = self.VAR_TYPE
64
+
65
+ return data
66
+
67
+
68
+ TConstData = ConstData
@@ -0,0 +1,42 @@
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
+ self._id = None
10
+ self.__sid = get_current_scope().id
11
+
12
+ def _set_id(self, id: str):
13
+ self._id = id
14
+
15
+ def __to_binding_config(
16
+ self,
17
+ ):
18
+ return {
19
+ "type": "ele_ref",
20
+ "id": self._id,
21
+ "sid": self.__sid,
22
+ }
23
+
24
+ def _to_output_config(self):
25
+ return self.__to_binding_config()
26
+
27
+ def _to_json_dict(self):
28
+ data = super()._to_json_dict()
29
+ data["id"] = self._id
30
+ data["sid"] = self.__sid
31
+
32
+ return data
33
+
34
+ def _to_element_config(self):
35
+ return {"id": self._id, "sid": self.__sid}
36
+
37
+
38
+ def run_element_method(method_name: str, *args, **kwargs):
39
+ return {
40
+ "method": method_name,
41
+ "args": args,
42
+ }
@@ -0,0 +1,45 @@
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
+
34
+ class DatasetEventContext(Jsonable, CanInputMixin):
35
+ def __init__(self, event_context: EventContext) -> None:
36
+ self._event_context = event_context
37
+
38
+ def _to_input_config(self):
39
+ return self._to_binding_config()
40
+
41
+ def _to_binding_config(self) -> Dict:
42
+ return self._event_context._to_binding_config()
43
+
44
+ def _to_json_dict(self):
45
+ return self._event_context._to_json_dict()
File without changes
@@ -0,0 +1,95 @@
1
+ from __future__ import annotations
2
+ import typing
3
+
4
+ from instaui.common.jsonable import Jsonable
5
+
6
+ from instaui.vars.path_var import PathVar
7
+ from instaui.vars.mixin_types.var_type import VarMixin
8
+ from instaui.vars.mixin_types.element_binding import ElementBindingMixin
9
+ from instaui.vars.mixin_types.py_binding import CanInputMixin
10
+ from instaui.vars.mixin_types.pathable import CanPathPropMixin
11
+ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
12
+ from instaui.vars.mixin_types.observable import ObservableMixin
13
+ from instaui.vars.mixin_types.common_type import TObservableInput
14
+ from instaui._helper import observable_helper
15
+
16
+ from . import _utils
17
+
18
+
19
+ class JsComputed(
20
+ Jsonable,
21
+ PathVar,
22
+ VarMixin,
23
+ ObservableMixin,
24
+ CanInputMixin,
25
+ CanPathPropMixin,
26
+ StrFormatBindingMixin,
27
+ ElementBindingMixin,
28
+ ):
29
+ VAR_TYPE = "jsComputed"
30
+ BIND_TYPE = "computed"
31
+
32
+ def __init__(
33
+ self,
34
+ *,
35
+ inputs: typing.Optional[typing.Sequence[TObservableInput]] = None,
36
+ code: str = "",
37
+ async_init_value: typing.Optional[typing.Any] = None,
38
+ ) -> None:
39
+ self.code = code
40
+
41
+ sid, id = _utils.register_var(self)
42
+ self._sid = sid
43
+ self._id = id
44
+
45
+ self._inputs, self._is_slient_inputs, self._is_data = (
46
+ observable_helper.analyze_observable_inputs(list(inputs or []))
47
+ )
48
+
49
+ self._async_init_value = async_init_value
50
+
51
+ def __to_binding_config(self):
52
+ return {
53
+ "type": self.BIND_TYPE,
54
+ "id": self._id,
55
+ "sid": self._sid,
56
+ }
57
+
58
+ def _to_input_config(self):
59
+ return self.__to_binding_config()
60
+
61
+ def _to_path_prop_binding_config(self) -> typing.Dict:
62
+ return self.__to_binding_config()
63
+
64
+ def _to_element_binding_config(self):
65
+ return self.__to_binding_config()
66
+
67
+ def _to_pathable_binding_config(self) -> typing.Dict:
68
+ return self.__to_binding_config()
69
+
70
+ def _to_observable_config(self):
71
+ return self.__to_binding_config()
72
+
73
+ def _to_json_dict(self):
74
+ data = super()._to_json_dict()
75
+
76
+ data["sid"] = self._sid
77
+ data["id"] = self._id
78
+ data["type"] = self.VAR_TYPE
79
+
80
+ if self._inputs:
81
+ data["inputs"] = self._inputs
82
+
83
+ if sum(self._is_slient_inputs) > 0:
84
+ data["slient"] = self._is_slient_inputs
85
+
86
+ if sum(self._is_data) > 0:
87
+ data["data"] = self._is_data
88
+
89
+ if self._async_init_value is not None:
90
+ data["asyncInit"] = self._async_init_value
91
+
92
+ return data
93
+
94
+
95
+ TJsComputed = JsComputed
@@ -0,0 +1,5 @@
1
+ from typing import Union, Any
2
+ from .observable import ObservableMixin
3
+ from .py_binding import CanInputMixin
4
+
5
+ TObservableInput = Union[ObservableMixin, CanInputMixin, Any]
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,7 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class ObservableMixin(ABC):
5
+ @abstractmethod
6
+ def _to_observable_config(self):
7
+ pass
@@ -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
@@ -0,0 +1,13 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class CanInputMixin(ABC):
5
+ @abstractmethod
6
+ def _to_input_config(self):
7
+ pass
8
+
9
+
10
+ class CanOutputMixin(ABC):
11
+ @abstractmethod
12
+ def _to_output_config(self):
13
+ pass
@@ -0,0 +1,8 @@
1
+ from typing import Tuple
2
+ from abc import ABC
3
+
4
+
5
+ class StrFormatBindingMixin(ABC):
6
+ def _to_str_format_binding(self, order: int) -> Tuple[str, str]:
7
+ var_name = f"___ref_var{order}"
8
+ return var_name, f"${{__Vue.toValue({var_name})}}"
@@ -0,0 +1,5 @@
1
+ from abc import ABC
2
+
3
+
4
+ class VarMixin(ABC):
5
+ pass