instaui 0.2.1__py2.py3-none-any.whl → 0.3.0__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.
Files changed (48) hide show
  1. instaui/arco/components/select.py +2 -1
  2. instaui/components/component.py +3 -1
  3. instaui/components/container.py +32 -0
  4. instaui/components/element.py +1 -4
  5. instaui/components/heading.py +46 -0
  6. instaui/components/match.py +20 -84
  7. instaui/components/slot.py +53 -19
  8. instaui/components/vfor.py +39 -44
  9. instaui/components/vif.py +10 -22
  10. instaui/event/js_event.py +10 -8
  11. instaui/event/vue_event.py +14 -16
  12. instaui/event/web_event.py +11 -8
  13. instaui/html_tools.py +8 -2
  14. instaui/js/fn.py +13 -10
  15. instaui/runtime/__init__.py +2 -2
  16. instaui/runtime/_app.py +43 -35
  17. instaui/runtime/scope.py +117 -33
  18. instaui/spa_router/_functions.py +4 -4
  19. instaui/spa_router/_route_model.py +6 -7
  20. instaui/spa_router/_router_output.py +5 -1
  21. instaui/spa_router/_router_param_var.py +4 -9
  22. instaui/static/insta-ui.css +1 -1
  23. instaui/static/insta-ui.esm-browser.prod.js +2313 -2361
  24. instaui/static/insta-ui.js.map +1 -1
  25. instaui/ui/__init__.py +7 -2
  26. instaui/ui/__init__.pyi +7 -2
  27. instaui/ui_functions/input_slient_data.py +4 -0
  28. instaui/ui_system_var_type.py +6 -0
  29. instaui/vars/_types.py +14 -0
  30. instaui/vars/data.py +7 -4
  31. instaui/vars/element_ref.py +13 -10
  32. instaui/vars/event_context.py +7 -3
  33. instaui/vars/js_computed.py +4 -4
  34. instaui/vars/mixin_types/py_binding.py +40 -0
  35. instaui/vars/path_var.py +7 -0
  36. instaui/vars/ref.py +7 -2
  37. instaui/vars/slot_prop.py +22 -14
  38. instaui/vars/state.py +23 -12
  39. instaui/vars/vfor_item.py +170 -72
  40. instaui/vars/vue_computed.py +4 -4
  41. instaui/vars/web_computed.py +10 -6
  42. instaui/watch/js_watch.py +6 -6
  43. instaui/watch/vue_watch.py +25 -2
  44. instaui/watch/web_watch.py +15 -6
  45. {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/METADATA +1 -1
  46. {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/RECORD +48 -45
  47. {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/WHEEL +0 -0
  48. {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/licenses/LICENSE +0 -0
instaui/ui/__init__.py CHANGED
@@ -28,6 +28,7 @@ __all__ = [
28
28
  "to_config_data",
29
29
  "element",
30
30
  "vfor",
31
+ "iter_info",
31
32
  "content",
32
33
  "label",
33
34
  "add_style",
@@ -50,6 +51,8 @@ __all__ = [
50
51
  "context",
51
52
  "row",
52
53
  "grid",
54
+ "container",
55
+ "heading",
53
56
  "js",
54
57
  "watch",
55
58
  "vue_watch",
@@ -103,8 +106,10 @@ from instaui.components.element import Element as element
103
106
  from instaui.components.row import Row as row
104
107
  from instaui.components.column import Column as column
105
108
  from instaui.components.grid import Grid as grid
109
+ from instaui.components.container import Container as container
110
+ from instaui.components.heading import Heading as heading
106
111
  from instaui.components.directive import Directive as directive
107
- from instaui.components.vfor import VFor as vfor
112
+ from instaui.components.vfor import VFor as vfor, iter_info
108
113
  from instaui.components.vif import VIf as vif
109
114
  from instaui.components.match import Match as match
110
115
  from instaui.components.content import Content as content
@@ -119,7 +124,7 @@ from instaui.runtime.context import get_context as context
119
124
 
120
125
  import instaui.js as js
121
126
  from instaui.watch.web_watch import watch
122
- from instaui.watch.vue_watch import VueWatch as vue_watch
127
+ from instaui.watch.vue_watch import vue_watch
123
128
  from instaui.watch.js_watch import js_watch
124
129
  from instaui.handlers.watch_handler import WatchState as TWatchState
125
130
  from instaui.skip import skip_output
instaui/ui/__init__.pyi CHANGED
@@ -28,6 +28,7 @@ __all__ = [
28
28
  "to_config_data",
29
29
  "element",
30
30
  "vfor",
31
+ "iter_info",
31
32
  "content",
32
33
  "label",
33
34
  "add_style",
@@ -50,6 +51,8 @@ __all__ = [
50
51
  "context",
51
52
  "row",
52
53
  "grid",
54
+ "container",
55
+ "heading",
53
56
  "js",
54
57
  "watch",
55
58
  "vue_watch",
@@ -103,8 +106,10 @@ from instaui.components.element import Element as element
103
106
  from instaui.components.row import Row as row
104
107
  from instaui.components.column import Column as column
105
108
  from instaui.components.grid import Grid as grid
109
+ from instaui.components.container import Container as container
110
+ from instaui.components.heading import Heading as heading
106
111
  from instaui.components.directive import Directive as directive
107
- from instaui.components.vfor import VFor as vfor
112
+ from instaui.components.vfor import VFor as vfor, iter_info
108
113
  from instaui.components.vif import VIf as vif
109
114
  from instaui.components.match import Match as match
110
115
  from instaui.components.content import Content as content
@@ -119,7 +124,7 @@ from instaui.runtime.context import get_context as context
119
124
 
120
125
  import instaui.js as js
121
126
  from instaui.watch.web_watch import watch
122
- from instaui.watch.vue_watch import VueWatch as vue_watch
127
+ from instaui.watch.vue_watch import vue_watch
123
128
  from instaui.watch.js_watch import js_watch
124
129
  from instaui.handlers.watch_handler import WatchState as TWatchState
125
130
  from instaui.skip import skip_output
@@ -1,4 +1,5 @@
1
1
  import typing
2
+ from instaui.vars._types import InputBindingType
2
3
  from instaui.vars.mixin_types.py_binding import CanInputMixin
3
4
 
4
5
 
@@ -14,3 +15,6 @@ class InputSilentData(CanInputMixin):
14
15
  return self.value._to_input_config()
15
16
  else:
16
17
  return self.value
18
+
19
+ def _to_event_input_type(self) -> InputBindingType:
20
+ return InputBindingType.Ref
@@ -0,0 +1,6 @@
1
+ from typing import Literal
2
+
3
+
4
+ TSize = Literal["1", "2", "3", "4", "5", "6", "7", "8", "9"]
5
+ TWeight = Literal["light", "regular", "medium", "bold"]
6
+ TAlign = Literal["left", "center", "right"]
instaui/vars/_types.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from __future__ import annotations
2
+ from enum import IntEnum
2
3
  from typing import Literal, TypeVar
3
4
 
4
5
 
@@ -6,3 +7,16 @@ _T_Value = TypeVar("_T_Value")
6
7
  _T_Output_Value = TypeVar("_T_Output_Value", covariant=True)
7
8
  _T_VAR_TYPE = Literal["ref", "computed", "webComputed"]
8
9
  _T_Bindable_Type = Literal["ref", "computed", "js", "webComputed", "vforItem"]
10
+
11
+
12
+ class InputBindingType(IntEnum):
13
+ Ref = 0
14
+ EventContext = 1
15
+ Data = 2
16
+ JsFn = 3
17
+
18
+
19
+ class OutputSetType(IntEnum):
20
+ Ref = 0
21
+ RouterAction = 1
22
+ ElementRefAction = 2
instaui/vars/data.py CHANGED
@@ -6,6 +6,7 @@ from typing import (
6
6
 
7
7
  from instaui.common.jsonable import Jsonable
8
8
  from instaui.runtime._app import get_current_scope
9
+ from instaui.vars._types import InputBindingType, OutputSetType
9
10
  from instaui.vars.path_var import PathVar
10
11
 
11
12
  from .mixin_types.var_type import VarMixin
@@ -25,8 +26,6 @@ class ConstData(
25
26
  StrFormatBindingMixin,
26
27
  ElementBindingMixin,
27
28
  ):
28
- BIND_TYPE = "var"
29
-
30
29
  def __init__(self, value: Any = None) -> None:
31
30
  self.value = value # type: ignore
32
31
 
@@ -35,7 +34,6 @@ class ConstData(
35
34
 
36
35
  def __to_binding_config(self):
37
36
  return {
38
- "type": self.BIND_TYPE,
39
37
  "id": self.__register_info.var_id,
40
38
  "sid": self.__register_info.scope_id,
41
39
  }
@@ -57,10 +55,15 @@ class ConstData(
57
55
 
58
56
  def _to_json_dict(self):
59
57
  data = super()._to_json_dict()
60
- data["sid"] = self.__register_info.scope_id
61
58
  data["id"] = self.__register_info.var_id
62
59
 
63
60
  return data
64
61
 
62
+ def _to_event_output_type(self) -> OutputSetType:
63
+ raise TypeError("ConstData cannot be used as an output")
64
+
65
+ def _to_event_input_type(self) -> InputBindingType:
66
+ return InputBindingType.Data
67
+
65
68
 
66
69
  TConstData = ConstData
@@ -1,22 +1,23 @@
1
1
  from __future__ import annotations
2
+ from typing import Dict
2
3
  from instaui.common.jsonable import Jsonable
3
4
  from instaui.runtime._app import get_current_scope
5
+ from instaui.vars._types import OutputSetType
4
6
  from instaui.vars.mixin_types.py_binding import CanOutputMixin
7
+ from instaui.vars.mixin_types.element_binding import ElementBindingMixin
5
8
 
6
9
 
7
- class ElementRef(Jsonable, CanOutputMixin):
10
+ class ElementRef(Jsonable, CanOutputMixin, ElementBindingMixin):
8
11
  def __init__(self) -> None:
9
12
  scope = get_current_scope()
10
- self._id = scope.generate_element_ref_id()
11
- self.__sid = get_current_scope().id
13
+ self.__register_info = scope.register_element_ref_task(self)
12
14
 
13
15
  def __to_binding_config(
14
16
  self,
15
17
  ):
16
18
  return {
17
- "type": "ele_ref",
18
- "id": self._id,
19
- "sid": self.__sid,
19
+ "id": self.__register_info.var_id,
20
+ "sid": self.__register_info.scope_id,
20
21
  }
21
22
 
22
23
  def _to_output_config(self):
@@ -24,13 +25,15 @@ class ElementRef(Jsonable, CanOutputMixin):
24
25
 
25
26
  def _to_json_dict(self):
26
27
  data = super()._to_json_dict()
27
- data["id"] = self._id
28
- data["sid"] = self.__sid
28
+ data["id"] = self.__register_info.var_id
29
29
 
30
30
  return data
31
31
 
32
- def _to_element_config(self):
33
- return {"id": self._id, "sid": self.__sid}
32
+ def _to_element_binding_config(self) -> Dict:
33
+ return self.__to_binding_config()
34
+
35
+ def _to_event_output_type(self) -> OutputSetType:
36
+ return OutputSetType.ElementRefAction
34
37
 
35
38
 
36
39
  def run_element_method(method_name: str, *args, **kwargs):
@@ -1,11 +1,10 @@
1
1
  from typing import Dict
2
2
  from instaui.common.jsonable import Jsonable
3
+ from instaui.vars._types import InputBindingType
3
4
  from instaui.vars.mixin_types.py_binding import CanInputMixin
4
5
 
5
6
 
6
7
  class EventContext(Jsonable, CanInputMixin):
7
- _TYPE = "event"
8
-
9
8
  def __init__(self, path: str):
10
9
  self.path = path
11
10
 
@@ -14,7 +13,6 @@ class EventContext(Jsonable, CanInputMixin):
14
13
 
15
14
  def _to_binding_config(self) -> Dict:
16
15
  return {
17
- "type": self._TYPE,
18
16
  "path": self.path,
19
17
  }
20
18
 
@@ -34,6 +32,9 @@ class EventContext(Jsonable, CanInputMixin):
34
32
  def target_value():
35
33
  return EventContext(":e => e.target.value")
36
34
 
35
+ def _to_event_input_type(self) -> InputBindingType:
36
+ return InputBindingType.EventContext
37
+
37
38
 
38
39
  class DatasetEventContext(Jsonable, CanInputMixin):
39
40
  def __init__(self, event_context: EventContext) -> None:
@@ -47,3 +48,6 @@ class DatasetEventContext(Jsonable, CanInputMixin):
47
48
 
48
49
  def _to_json_dict(self):
49
50
  return self._event_context._to_json_dict()
51
+
52
+ def _to_event_input_type(self) -> InputBindingType:
53
+ return InputBindingType.EventContext
@@ -4,6 +4,7 @@ import typing
4
4
  from instaui.common.jsonable import Jsonable
5
5
 
6
6
  from instaui.runtime._app import get_current_scope
7
+ from instaui.vars._types import InputBindingType
7
8
  from instaui.vars.path_var import PathVar
8
9
  from instaui.vars.mixin_types.var_type import VarMixin
9
10
  from instaui.vars.mixin_types.element_binding import ElementBindingMixin
@@ -44,8 +45,6 @@ class JsComputed(
44
45
  ui.label(plus_one)
45
46
  """
46
47
 
47
- BIND_TYPE = "var"
48
-
49
48
  def __init__(
50
49
  self,
51
50
  *,
@@ -69,7 +68,6 @@ class JsComputed(
69
68
 
70
69
  def __to_binding_config(self):
71
70
  return {
72
- "type": self.BIND_TYPE,
73
71
  "id": self.__register_info.var_id,
74
72
  "sid": self.__register_info.scope_id,
75
73
  }
@@ -92,7 +90,6 @@ class JsComputed(
92
90
  def _to_json_dict(self):
93
91
  data = super()._to_json_dict()
94
92
 
95
- data["sid"] = self.__register_info.scope_id
96
93
  data["id"] = self.__register_info.var_id
97
94
 
98
95
  if self._inputs:
@@ -112,5 +109,8 @@ class JsComputed(
112
109
 
113
110
  return data
114
111
 
112
+ def _to_event_input_type(self) -> InputBindingType:
113
+ return InputBindingType.Ref
114
+
115
115
 
116
116
  TJsComputed = JsComputed
@@ -1,4 +1,6 @@
1
1
  from abc import ABC, abstractmethod
2
+ from typing import Sequence
3
+ from instaui.vars._types import InputBindingType, OutputSetType
2
4
 
3
5
 
4
6
  class CanInputMixin(ABC):
@@ -6,8 +8,46 @@ class CanInputMixin(ABC):
6
8
  def _to_input_config(self):
7
9
  pass
8
10
 
11
+ @abstractmethod
12
+ def _to_event_input_type(self) -> InputBindingType:
13
+ pass
14
+
9
15
 
10
16
  class CanOutputMixin(ABC):
11
17
  @abstractmethod
12
18
  def _to_output_config(self):
13
19
  pass
20
+
21
+ @abstractmethod
22
+ def _to_event_output_type(self) -> OutputSetType:
23
+ pass
24
+
25
+
26
+ def inputs_to_config(inputs: Sequence[CanInputMixin]):
27
+ return [
28
+ {
29
+ "value": input._to_input_config()
30
+ if isinstance(input, CanInputMixin)
31
+ else input,
32
+ "type": input._to_event_input_type().value
33
+ if isinstance(input, CanInputMixin)
34
+ else InputBindingType.Data.value,
35
+ }
36
+ for input in inputs
37
+ ]
38
+
39
+
40
+ def outputs_to_config(outputs: Sequence[CanOutputMixin]):
41
+ return [
42
+ {
43
+ "ref": ref._to_output_config(),
44
+ "type": ref._to_event_output_type().value,
45
+ }
46
+ for ref in outputs
47
+ ]
48
+
49
+
50
+ def _assert_outputs_be_can_output_mixin(outputs: Sequence):
51
+ for output in outputs:
52
+ if not isinstance(output, CanOutputMixin):
53
+ raise TypeError("The outputs parameter must be a `ui.state`")
instaui/vars/path_var.py CHANGED
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
  from abc import abstractmethod
3
3
  from typing import List, Optional, Union
4
4
  from typing_extensions import Self
5
+ from instaui.vars._types import InputBindingType, OutputSetType
5
6
  from instaui.vars.mixin_types.pathable import PathableMixin, CanPathPropMixin
6
7
  from instaui.vars.mixin_types.element_binding import ElementBindingMixin
7
8
  from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
@@ -88,3 +89,9 @@ class PathTrackerBindable(
88
89
  ]
89
90
 
90
91
  return data
92
+
93
+ def _to_event_input_type(self) -> InputBindingType:
94
+ return InputBindingType.Ref
95
+
96
+ def _to_event_output_type(self) -> OutputSetType:
97
+ return OutputSetType.Ref
instaui/vars/ref.py CHANGED
@@ -10,6 +10,7 @@ from typing import (
10
10
 
11
11
  from instaui.common.jsonable import Jsonable
12
12
  from instaui.runtime._app import get_current_scope
13
+ from instaui.vars._types import InputBindingType, OutputSetType
13
14
  from instaui.vars.path_var import PathVar
14
15
 
15
16
  from .mixin_types.var_type import VarMixin
@@ -53,7 +54,6 @@ class Ref(
53
54
 
54
55
  def __to_binding_config(self):
55
56
  return {
56
- "type": self.VAR_TYPE,
57
57
  "id": self.__register_info.var_id,
58
58
  "sid": self.__register_info.scope_id,
59
59
  }
@@ -78,7 +78,6 @@ class Ref(
78
78
 
79
79
  def _to_json_dict(self):
80
80
  data = super()._to_json_dict()
81
- data["sid"] = self.__register_info.scope_id
82
81
  data["id"] = self.__register_info.var_id
83
82
 
84
83
  if self._debounced is not None:
@@ -89,6 +88,12 @@ class Ref(
89
88
 
90
89
  return data
91
90
 
91
+ def _to_event_input_type(self) -> InputBindingType:
92
+ return InputBindingType.Ref
93
+
94
+ def _to_event_output_type(self) -> OutputSetType:
95
+ return OutputSetType.Ref
96
+
92
97
 
93
98
  TRef = Ref
94
99
 
instaui/vars/slot_prop.py CHANGED
@@ -3,9 +3,8 @@ from typing import (
3
3
  Dict,
4
4
  )
5
5
  from instaui.common.jsonable import Jsonable
6
-
6
+ from instaui.vars._types import InputBindingType
7
7
  from instaui.vars.path_var import PathVar
8
-
9
8
  from .mixin_types.py_binding import CanInputMixin
10
9
  from .mixin_types.element_binding import ElementBindingMixin
11
10
  from .mixin_types.pathable import CanPathPropMixin
@@ -18,29 +17,38 @@ class BindingSlotPropItem(
18
17
  CanInputMixin,
19
18
  CanPathPropMixin,
20
19
  ):
21
- def __init__(self, slot_id: str, name: str) -> None:
20
+ def __init__(self, name: str, sid: str, var_id: str) -> None:
22
21
  super().__init__()
23
- self.name = name
24
- self._id = slot_id
22
+ self._name = name
23
+ self._sid = sid
24
+ self._id = var_id
25
+
26
+ def __to_binding_config(self):
27
+ data: Dict = {
28
+ "sid": self._sid,
29
+ "id": self._id,
30
+ }
31
+
32
+ return data
25
33
 
26
34
  def _to_element_binding_config(self):
27
- return self._to_binding_config()
35
+ return self.__to_binding_config()
28
36
 
29
37
  def _to_input_config(self):
30
- return self._to_binding_config()
38
+ return self.__to_binding_config()
31
39
 
32
40
  def _to_path_prop_binding_config(self) -> Dict:
33
- return self._to_binding_config()
41
+ return self.__to_binding_config()
34
42
 
35
43
  def _to_pathable_binding_config(self) -> Dict:
36
- return self._to_binding_config()
44
+ return self.__to_binding_config()
37
45
 
38
46
  def _to_json_dict(self):
39
- data = super()._to_json_dict()
40
- data["type"] = "sp"
41
- data["id"] = self._id
47
+ data: Dict = {
48
+ "id": self._id,
49
+ }
42
50
 
43
51
  return data
44
52
 
45
- def _to_binding_config(self) -> Dict:
46
- return self._to_json_dict()
53
+ def _to_event_input_type(self) -> InputBindingType:
54
+ return InputBindingType.Ref
instaui/vars/state.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from typing import Dict, Tuple, TypeVar
2
2
 
3
3
  from instaui import ui
4
+ from instaui.vars._types import InputBindingType, OutputSetType
4
5
  from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
5
6
  from instaui.vars.mixin_types.observable import ObservableMixin
6
7
  from instaui.vars.mixin_types.element_binding import ElementBindingMixin
@@ -30,44 +31,54 @@ class RefProxy(
30
31
  self._ref_ = ui.ref(data, deep_compare=deep_compare)
31
32
  self._prop_names_ = set(data.keys()) if isinstance(data, dict) else set()
32
33
 
34
+ @property
35
+ def __ref_(self):
36
+ return super().__getattribute__("_ref_")
37
+
33
38
  def __getattribute__(self, name):
34
39
  if name not in super().__getattribute__("_prop_names_"):
35
40
  return super().__getattribute__(name)
36
41
 
37
- return super().__getattribute__("_ref_")[name]
42
+ return self.__ref_[name]
38
43
 
39
44
  def __getitem__(self, name):
40
- return super().__getattribute__("_ref_")[name]
45
+ return self.__ref_[name]
41
46
 
42
47
  def inverse(self):
43
- return super().__getattribute__("_ref_").inverse()
48
+ return self.__ref_.inverse()
44
49
 
45
50
  def __add__(self, other: str):
46
- return super().__getattribute__("_ref_") + other
51
+ return self.__ref_ + other
47
52
 
48
53
  def __radd__(self, other: str):
49
- return other + super().__getattribute__("_ref_")
54
+ return other + self.__ref_
50
55
 
51
56
  def _to_element_binding_config(self) -> Dict:
52
- return super().__getattribute__("_ref_")._to_element_binding_config()
57
+ return self.__ref_._to_element_binding_config()
53
58
 
54
59
  def _to_input_config(self):
55
- return super().__getattribute__("_ref_")._to_input_config()
60
+ return self.__ref_._to_input_config()
56
61
 
57
62
  def _to_observable_config(self):
58
- return super().__getattribute__("_ref_")._to_observable_config()
63
+ return self.__ref_._to_observable_config()
59
64
 
60
65
  def _to_path_prop_binding_config(self) -> Dict:
61
- return super().__getattribute__("_ref_")._to_path_prop_binding_config()
66
+ return self.__ref_._to_path_prop_binding_config()
62
67
 
63
68
  def _to_output_config(self):
64
- return super().__getattribute__("_ref_")._to_output_config()
69
+ return self.__ref_._to_output_config()
65
70
 
66
71
  def _to_str_format_binding(self, order: int) -> Tuple[str, str]:
67
- return super().__getattribute__("_ref_")._to_str_format_binding(order)
72
+ return self.__ref_._to_str_format_binding(order)
68
73
 
69
74
  def _to_json_dict(self):
70
- return super().__getattribute__("_ref_")._to_json_dict()
75
+ return self.__ref_._to_json_dict()
76
+
77
+ def _to_event_output_type(self) -> OutputSetType:
78
+ return self.__ref_._to_event_output_type()
79
+
80
+ def _to_event_input_type(self) -> InputBindingType:
81
+ return self.__ref_._to_event_input_type()
71
82
 
72
83
 
73
84
  class StateModel(BaseModel, Jsonable):