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
@@ -0,0 +1,89 @@
1
+ from __future__ import annotations
2
+ from abc import abstractmethod
3
+ from typing import List, Optional, Union, Self
4
+ from instaui.vars.mixin_types.pathable import PathableMixin, CanPathPropMixin
5
+ from instaui.vars.mixin_types.element_binding import ElementBindingMixin
6
+ from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
7
+ from instaui.vars.mixin_types.observable import ObservableMixin
8
+ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
9
+
10
+
11
+ class PathVar(PathableMixin):
12
+ def __getitem__(self, item: Union[str, int, CanPathPropMixin]):
13
+ return PathTrackerBindable(self)[item]
14
+
15
+ def inverse(self):
16
+ return PathTrackerBindable(self).inverse()
17
+
18
+ def __add__(self, other: str):
19
+ return PathTrackerBindable(self) + other
20
+
21
+ def __radd__(self, other: str):
22
+ return other + PathTrackerBindable(self)
23
+
24
+
25
+ class PathTracker:
26
+ def __init__(self, paths: Optional[List[Union[str, List[str]]]] = None):
27
+ self.paths = paths or []
28
+
29
+ def __getitem__(self, key) -> Self:
30
+ return self.__new_self__([*self.paths, key])
31
+
32
+ def __getattr__(self, key) -> Self:
33
+ return self.__new_self__([*self.paths, key])
34
+
35
+ def inverse(self) -> Self:
36
+ return self.__new_self__([*self.paths, ["!"]])
37
+
38
+ def __add__(self, other: str) -> Self:
39
+ return self.__new_self__([*self.paths, ["+", other]])
40
+
41
+ def __radd__(self, other: str) -> Self:
42
+ return self.__new_self__([*self.paths, ["~+", other]])
43
+
44
+ @abstractmethod
45
+ def __new_self__(self, paths: List[Union[str, List[str]]]) -> Self:
46
+ pass
47
+
48
+
49
+ class PathTrackerBindable(
50
+ PathTracker,
51
+ CanInputMixin,
52
+ ObservableMixin,
53
+ CanOutputMixin,
54
+ ElementBindingMixin,
55
+ StrFormatBindingMixin,
56
+ ):
57
+ def __init__(self, source: PathableMixin):
58
+ super().__init__()
59
+ self.__source = source
60
+
61
+ def __new_self__(self, paths: List[Union[str, List[str]]]) -> PathTrackerBindable:
62
+ obj = PathTrackerBindable(self.__source)
63
+ obj.paths = paths
64
+ return obj
65
+
66
+ def _to_element_binding_config(self):
67
+ return self._to_json_dict()
68
+
69
+ def _to_input_config(self):
70
+ return self._to_json_dict()
71
+
72
+ def _to_output_config(self):
73
+ return self._to_json_dict()
74
+
75
+ def _to_observable_config(self):
76
+ return self._to_json_dict()
77
+
78
+ def _to_json_dict(self):
79
+ data = self.__source._to_pathable_binding_config()
80
+
81
+ if self.paths:
82
+ data["path"] = [
83
+ ["bind", path._to_path_prop_binding_config()]
84
+ if isinstance(path, CanPathPropMixin)
85
+ else path
86
+ for path in self.paths
87
+ ]
88
+
89
+ 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.vars.path_var import PathVar
13
+
14
+ from .mixin_types.var_type import VarMixin
15
+ from .mixin_types.py_binding import CanInputMixin, CanOutputMixin
16
+ from .mixin_types.observable import ObservableMixin
17
+ from .mixin_types.element_binding import ElementBindingMixin
18
+ from .mixin_types.pathable import CanPathPropMixin
19
+ from .mixin_types.str_format_binding import StrFormatBindingMixin
20
+ from . import _utils
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 = "ref"
39
+
40
+ def __init__(self, value: Optional[_T_Value] = None) -> None:
41
+ self.value = value # type: ignore
42
+
43
+ sid, id = _utils.register_var(self)
44
+ self._sid = sid
45
+ self._id = id
46
+ self._debounced = None
47
+
48
+ def debounced(self, secounds: float):
49
+ self._debounced = secounds
50
+ return self
51
+
52
+ def __to_binding_config(self):
53
+ return {
54
+ "type": self.VAR_TYPE,
55
+ "id": self._id,
56
+ "sid": self._sid,
57
+ }
58
+
59
+ def _to_pathable_binding_config(self) -> Dict:
60
+ return self.__to_binding_config()
61
+
62
+ def _to_path_prop_binding_config(self) -> Dict:
63
+ return self.__to_binding_config()
64
+
65
+ def _to_observable_config(self):
66
+ return self.__to_binding_config()
67
+
68
+ def _to_input_config(self):
69
+ return self.__to_binding_config()
70
+
71
+ def _to_output_config(self):
72
+ return self.__to_binding_config()
73
+
74
+ def _to_element_binding_config(self):
75
+ return self.__to_binding_config()
76
+
77
+ def _to_json_dict(self):
78
+ data = super()._to_json_dict()
79
+ data["sid"] = self._sid
80
+ data["id"] = self._id
81
+ data["type"] = self.VAR_TYPE
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()
instaui/vars/state.py ADDED
@@ -0,0 +1,82 @@
1
+ from typing import Dict, Tuple, TypeVar
2
+
3
+ from instaui import ui
4
+ from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
5
+ from instaui.vars.mixin_types.observable import ObservableMixin
6
+ from instaui.vars.mixin_types.element_binding import ElementBindingMixin
7
+ from instaui.vars.mixin_types.pathable import CanPathPropMixin
8
+ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
9
+ from instaui.common.jsonable import Jsonable
10
+
11
+ from pydantic import BaseModel, RootModel
12
+
13
+ _T = TypeVar("_T")
14
+
15
+
16
+ _ProxyModel = RootModel
17
+
18
+
19
+ class RefProxy(
20
+ CanInputMixin,
21
+ ObservableMixin,
22
+ CanOutputMixin,
23
+ CanPathPropMixin,
24
+ StrFormatBindingMixin,
25
+ ElementBindingMixin,
26
+ Jsonable,
27
+ ):
28
+ def __init__(self, instance: BaseModel) -> None:
29
+ data = instance.model_dump()
30
+ self._ref_ = ui.ref(data)
31
+ self._prop_names_ = set(data.keys()) if isinstance(data, dict) else set()
32
+
33
+ def __getattribute__(self, name):
34
+ if name not in super().__getattribute__("_prop_names_"):
35
+ return super().__getattribute__(name)
36
+
37
+ return super().__getattribute__("_ref_")[name]
38
+
39
+ def __getitem__(self, name):
40
+ return super().__getattribute__("_ref_")[name]
41
+
42
+ def inverse(self):
43
+ return super().__getattribute__("_ref_").inverse()
44
+
45
+ def __add__(self, other: str):
46
+ return super().__getattribute__("_ref_") + other
47
+
48
+ def __radd__(self, other: str):
49
+ return other + super().__getattribute__("_ref_")
50
+
51
+ def _to_element_binding_config(self) -> Dict:
52
+ return super().__getattribute__("_ref_")._to_element_binding_config()
53
+
54
+ def _to_input_config(self):
55
+ return super().__getattribute__("_ref_")._to_input_config()
56
+
57
+ def _to_observable_config(self):
58
+ return super().__getattribute__("_ref_")._to_observable_config()
59
+
60
+ def _to_path_prop_binding_config(self) -> Dict:
61
+ return super().__getattribute__("_ref_")._to_path_prop_binding_config()
62
+
63
+ def _to_output_config(self):
64
+ return super().__getattribute__("_ref_")._to_output_config()
65
+
66
+ def _to_str_format_binding(self, order: int) -> Tuple[str, str]:
67
+ return super().__getattribute__("_ref_")._to_str_format_binding(order)
68
+
69
+ def _to_json_dict(self):
70
+ return super().__getattribute__("_ref_")._to_json_dict()
71
+
72
+
73
+ class StateModel(BaseModel, Jsonable):
74
+ pass
75
+
76
+ def _to_json_dict(self):
77
+ return self.model_dump()
78
+
79
+
80
+ def state(value: _T) -> _T:
81
+ obj = RefProxy(_ProxyModel(value)) # type: ignore
82
+ return obj # type: ignore
instaui/vars/types.py ADDED
@@ -0,0 +1,24 @@
1
+ from typing import Any, Union
2
+ from .ref import Ref
3
+ from .js_computed import JsComputed
4
+ from .vue_computed import VueComputed
5
+ from .web_computed import WebComputed
6
+
7
+
8
+ from ._types import _T_Value
9
+ from .mixin_types.element_binding import ElementBindingMixin
10
+
11
+
12
+ TRefOrComputed = Union[
13
+ Ref[_T_Value],
14
+ VueComputed,
15
+ JsComputed,
16
+ WebComputed[Any, _T_Value],
17
+ ]
18
+ TMaybeRef = Union[
19
+ ElementBindingMixin[_T_Value],
20
+ WebComputed,
21
+ VueComputed,
22
+ JsComputed,
23
+ _T_Value,
24
+ ]
@@ -0,0 +1,204 @@
1
+ from __future__ import annotations
2
+ from typing import Dict, Generic, Tuple, TypeVar, TYPE_CHECKING, Union, cast
3
+ from contextlib import contextmanager
4
+
5
+ from instaui.common.jsonable import Jsonable
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.pathable import CanPathPropMixin
9
+ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
10
+ from instaui.vars.mixin_types.observable import ObservableMixin
11
+ from instaui.vars.path_var import PathVar
12
+
13
+ if TYPE_CHECKING:
14
+ from instaui.components.vfor import VFor
15
+
16
+ _T = TypeVar("_T")
17
+
18
+
19
+ class VForItemProxy(
20
+ PathVar,
21
+ CanInputMixin,
22
+ ObservableMixin,
23
+ CanOutputMixin,
24
+ CanPathPropMixin,
25
+ StrFormatBindingMixin,
26
+ ElementBindingMixin,
27
+ Jsonable,
28
+ Generic[_T],
29
+ ):
30
+ def __init__(self, vfor_item: VForItem[_T]):
31
+ self._vfor_item = vfor_item
32
+
33
+ def __getattr__(self, name: str):
34
+ return self._vfor_item[name]
35
+
36
+ def __getitem__(self, name):
37
+ return super().__getattribute__("_vfor_item")[name]
38
+
39
+ def _to_element_binding_config(self) -> Dict:
40
+ return super().__getattribute__("_vfor_item")._to_element_binding_config()
41
+
42
+ def _to_input_config(self):
43
+ return super().__getattribute__("_vfor_item")._to_input_config()
44
+
45
+ def _to_path_prop_binding_config(self) -> Dict:
46
+ return super().__getattribute__("_vfor_item")._to_path_prop_binding_config()
47
+
48
+ def _to_output_config(self):
49
+ return super().__getattribute__("_vfor_item")._to_output_config()
50
+
51
+ def _to_str_format_binding(self, order: int) -> Tuple[str, str]:
52
+ return super().__getattribute__("_vfor_item")._to_str_format_binding(order)
53
+
54
+ def _to_pathable_binding_config(self) -> Dict:
55
+ return super().__getattribute__("_vfor_item")._to_pathable_binding_config()
56
+
57
+ def _to_observable_config(self):
58
+ return super().__getattribute__("_vfor_item")._to_observable_config()
59
+
60
+ def _to_json_dict(self):
61
+ return super().__getattribute__("_vfor_item")._to_json_dict()
62
+
63
+
64
+ class VForItem(
65
+ PathVar,
66
+ CanInputMixin,
67
+ ObservableMixin,
68
+ CanOutputMixin,
69
+ CanPathPropMixin,
70
+ ElementBindingMixin[_T],
71
+ StrFormatBindingMixin,
72
+ Generic[_T],
73
+ ):
74
+ VAR_Type = "vf"
75
+
76
+ def __init__(self, vfor: VFor):
77
+ super().__init__()
78
+ self._vfor = vfor
79
+
80
+ @property
81
+ def dict_key(self):
82
+ return self._vfor.current[1]
83
+
84
+ @property
85
+ def dict_value(self):
86
+ return self._vfor.current[0]
87
+
88
+ @property
89
+ def proxy(self):
90
+ return cast(_T, VForItemProxy(self))
91
+
92
+ def _to_binding_config(self) -> Union[Jsonable, Dict]:
93
+ return self._to_json_dict()
94
+
95
+ def _to_element_binding_config(self):
96
+ return self._to_json_dict()
97
+
98
+ def _to_input_config(self):
99
+ return self._to_json_dict()
100
+
101
+ def _to_output_config(self):
102
+ return self._to_json_dict()
103
+
104
+ def _to_path_prop_binding_config(self) -> Dict:
105
+ return self._to_json_dict()
106
+
107
+ def _to_pathable_binding_config(self) -> Dict:
108
+ return self._to_json_dict()
109
+
110
+ def _to_observable_config(self):
111
+ return self._to_json_dict()
112
+
113
+ def _to_json_dict(self):
114
+ data: Dict = {
115
+ "type": self.VAR_Type,
116
+ "fid": self._vfor._fid,
117
+ }
118
+
119
+ return data
120
+
121
+
122
+ class VForIndex(
123
+ CanInputMixin,
124
+ CanPathPropMixin,
125
+ ElementBindingMixin,
126
+ StrFormatBindingMixin,
127
+ ):
128
+ def __init__(self, vfor: VFor):
129
+ super().__init__()
130
+ self._vfor = vfor
131
+
132
+ def _to_element_binding_config(self):
133
+ return self._to_json_dict()
134
+
135
+ def _to_input_config(self):
136
+ return self._to_json_dict()
137
+
138
+ def _to_path_prop_binding_config(self) -> Dict:
139
+ return self._to_json_dict()
140
+
141
+ def _to_json_dict(self):
142
+ return {
143
+ "type": "vf-i",
144
+ "fid": self._vfor._fid,
145
+ }
146
+
147
+
148
+ class VForDict(
149
+ CanInputMixin,
150
+ CanOutputMixin,
151
+ StrFormatBindingMixin,
152
+ ElementBindingMixin,
153
+ Jsonable,
154
+ ):
155
+ def __init__(self, vfor: VFor):
156
+ self._vfor = vfor
157
+
158
+ @property
159
+ def dict_key(self):
160
+ return self._vfor.current[1]
161
+
162
+ @property
163
+ def dict_value(self):
164
+ return self._vfor.current[0]
165
+
166
+ @contextmanager
167
+ def with_index(self):
168
+ self.__enter__()
169
+ yield self, cast(int, VForIndex(self._vfor))
170
+
171
+ def __enter__(self):
172
+ self._vfor.__enter__()
173
+ return self
174
+
175
+ def __exit__(self, *_) -> None:
176
+ return self._vfor.__exit__(*_)
177
+
178
+ def _to_element_binding_config(self) -> Dict:
179
+ return self.dict_value._to_element_binding_config()
180
+
181
+ def _to_input_config(self):
182
+ return self.dict_value._to_input_config()
183
+
184
+ def _to_output_config(self):
185
+ return self.dict_value._to_output_config()
186
+
187
+ def _to_json_dict(self):
188
+ return self.dict_value._to_json_dict()
189
+
190
+
191
+ class VForWithIndex(Generic[_T]):
192
+ def __init__(self, vfor: VFor[_T]):
193
+ self._vfor = vfor
194
+
195
+ def __enter__(self):
196
+ self._vfor.__enter__()
197
+ return cast(_T, self._vfor.current.proxy), cast(int, VForIndex(self._vfor))
198
+
199
+ def __exit__(self, *_) -> None:
200
+ return self._vfor.__exit__(*_)
201
+
202
+
203
+ TVForItem = VForItem
204
+ TVForIndex = VForIndex
@@ -0,0 +1,82 @@
1
+ from __future__ import annotations
2
+ from typing import Any, Dict, Mapping, Optional, Union
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 . import _utils
14
+
15
+
16
+ class VueComputed(
17
+ Jsonable,
18
+ PathVar,
19
+ VarMixin,
20
+ CanInputMixin,
21
+ ObservableMixin,
22
+ CanPathPropMixin,
23
+ StrFormatBindingMixin,
24
+ ElementBindingMixin,
25
+ ):
26
+ VAR_TYPE = "vComputed"
27
+ BIND_TYPE = "computed"
28
+
29
+ def __init__(
30
+ self,
31
+ fn_code: str,
32
+ bindings: Optional[Mapping[str, Union[ElementBindingMixin, Any]]] = None,
33
+ ) -> None:
34
+ self.code = fn_code
35
+
36
+ sid, id = _utils.register_var(self)
37
+ self._sid = sid
38
+ self._id = id
39
+
40
+ if bindings:
41
+ const_bind = []
42
+ self.bind = {}
43
+
44
+ for k, v in bindings.items():
45
+ is_binding = isinstance(v, ElementBindingMixin)
46
+ self.bind[k] = v._to_element_binding_config() if is_binding else v
47
+ const_bind.append(int(not is_binding))
48
+
49
+ if any(i == 1 for i in const_bind):
50
+ self.const = const_bind
51
+
52
+ def __to_binding_config(self):
53
+ return {
54
+ "type": self.BIND_TYPE,
55
+ "id": self._id,
56
+ "sid": self._sid,
57
+ }
58
+
59
+ def _to_input_config(self):
60
+ return self.__to_binding_config()
61
+
62
+ def _to_path_prop_binding_config(self) -> Dict:
63
+ return self.__to_binding_config()
64
+
65
+ def _to_element_binding_config(self):
66
+ return self.__to_binding_config()
67
+
68
+ def _to_pathable_binding_config(self) -> Dict:
69
+ return self.__to_binding_config()
70
+
71
+ def _to_observable_config(self):
72
+ return self.__to_binding_config()
73
+
74
+ def _to_json_dict(self):
75
+ data = super()._to_json_dict()
76
+ data["sid"] = self._sid
77
+ data["id"] = self._id
78
+ data["type"] = self.VAR_TYPE
79
+ return data
80
+
81
+
82
+ TVueComputed = VueComputed