instaui 0.2.2__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.
- instaui/arco/components/select.py +2 -1
- instaui/components/component.py +3 -1
- instaui/components/element.py +1 -4
- instaui/components/match.py +20 -84
- instaui/components/slot.py +53 -19
- instaui/components/vfor.py +39 -44
- instaui/components/vif.py +10 -22
- instaui/event/js_event.py +10 -8
- instaui/event/vue_event.py +14 -16
- instaui/event/web_event.py +4 -7
- instaui/html_tools.py +8 -2
- instaui/js/fn.py +13 -10
- instaui/runtime/__init__.py +2 -2
- instaui/runtime/_app.py +43 -35
- instaui/runtime/scope.py +117 -33
- instaui/spa_router/_functions.py +4 -4
- instaui/spa_router/_route_model.py +6 -7
- instaui/spa_router/_router_output.py +5 -1
- instaui/spa_router/_router_param_var.py +4 -9
- instaui/static/insta-ui.css +1 -1
- instaui/static/insta-ui.esm-browser.prod.js +2245 -2329
- instaui/static/insta-ui.js.map +1 -1
- instaui/ui/__init__.py +3 -2
- instaui/ui/__init__.pyi +3 -2
- instaui/ui_functions/input_slient_data.py +4 -0
- instaui/vars/_types.py +14 -0
- instaui/vars/data.py +7 -4
- instaui/vars/element_ref.py +13 -10
- instaui/vars/event_context.py +7 -3
- instaui/vars/js_computed.py +4 -4
- instaui/vars/mixin_types/py_binding.py +33 -0
- instaui/vars/path_var.py +7 -0
- instaui/vars/ref.py +7 -2
- instaui/vars/slot_prop.py +22 -14
- instaui/vars/state.py +23 -12
- instaui/vars/vfor_item.py +170 -72
- instaui/vars/vue_computed.py +4 -4
- instaui/vars/web_computed.py +10 -6
- instaui/watch/js_watch.py +6 -6
- instaui/watch/vue_watch.py +25 -2
- instaui/watch/web_watch.py +6 -5
- {instaui-0.2.2.dist-info → instaui-0.3.0.dist-info}/METADATA +1 -1
- {instaui-0.2.2.dist-info → instaui-0.3.0.dist-info}/RECORD +45 -45
- {instaui-0.2.2.dist-info → instaui-0.3.0.dist-info}/WHEEL +0 -0
- {instaui-0.2.2.dist-info → instaui-0.3.0.dist-info}/licenses/LICENSE +0 -0
@@ -45,7 +45,8 @@ class Select(Element):
|
|
45
45
|
)
|
46
46
|
|
47
47
|
with self.add_slot("default"):
|
48
|
-
with ui.vfor
|
48
|
+
with ui.vfor(options) as item:
|
49
|
+
item = ui.iter_info(item)
|
49
50
|
Select.Option(item.dict_value).props(
|
50
51
|
{"value": item.dict_key, "label": item.dict_value}
|
51
52
|
)
|
instaui/components/component.py
CHANGED
instaui/components/element.py
CHANGED
@@ -23,7 +23,6 @@ from typing import (
|
|
23
23
|
from typing_extensions import Self
|
24
24
|
from collections import defaultdict
|
25
25
|
from instaui.runtime._app import get_app_slot
|
26
|
-
from instaui.runtime._app import get_current_scope
|
27
26
|
from instaui.vars.element_ref import ElementRef
|
28
27
|
from instaui.vars.vfor_item import VForItem
|
29
28
|
from instaui.components.directive import Directive
|
@@ -468,9 +467,7 @@ class Element(Component):
|
|
468
467
|
)
|
469
468
|
|
470
469
|
if self.__element_ref:
|
471
|
-
|
472
|
-
data["eRef"] = self.__element_ref._to_element_config()
|
473
|
-
scope.register_element_ref(self.__element_ref)
|
470
|
+
data["eRef"] = self.__element_ref._to_element_binding_config()
|
474
471
|
|
475
472
|
return data
|
476
473
|
|
instaui/components/match.py
CHANGED
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import typing
|
4
4
|
from instaui.components.component import Component
|
5
|
-
from instaui.runtime._app import new_scope
|
6
5
|
|
7
6
|
from instaui.vars.mixin_types.element_binding import ElementBindingProtocol
|
8
7
|
|
@@ -11,96 +10,33 @@ class Match(Component):
|
|
11
10
|
def __init__(self, on: ElementBindingProtocol):
|
12
11
|
super().__init__("match")
|
13
12
|
self._on = on
|
14
|
-
self.
|
13
|
+
self.cass_id_count = -1
|
14
|
+
self._case_values = []
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
props: typing.Dict = data["props"]
|
22
|
-
|
23
|
-
props["case"] = [
|
24
|
-
item
|
25
|
-
for item in self._slot_manager.default._children
|
26
|
-
if isinstance(item, Case)
|
27
|
-
]
|
28
|
-
|
29
|
-
if self._default_case:
|
30
|
-
props["default"] = self._default_case
|
31
|
-
|
32
|
-
data.pop("slots", None)
|
33
|
-
|
34
|
-
return data
|
35
|
-
|
36
|
-
def case(self, value: typing.Any) -> Case:
|
37
|
-
with self:
|
38
|
-
case = Case(value)
|
39
|
-
|
40
|
-
return case
|
41
|
-
|
42
|
-
def default(self) -> DefaultCase:
|
43
|
-
with self:
|
44
|
-
self._default_case = DefaultCase()
|
45
|
-
|
46
|
-
return self._default_case
|
47
|
-
|
48
|
-
|
49
|
-
class Case(Component):
|
50
|
-
def __init__(self, value: typing.Any):
|
51
|
-
super().__init__("case")
|
52
|
-
self._value = value
|
53
|
-
self.__scope_manager = new_scope()
|
54
|
-
self.__scope = None
|
16
|
+
def case(self, value: typing.Any):
|
17
|
+
self.cass_id_count += 1
|
18
|
+
self._case_values.append(value)
|
19
|
+
return self._slot_manager.get_slot(str(self.cass_id_count))
|
55
20
|
|
56
|
-
def
|
57
|
-
|
58
|
-
return super().__enter__()
|
59
|
-
|
60
|
-
def __exit__(self, *_) -> None:
|
61
|
-
self.__scope_manager.__exit__(*_)
|
62
|
-
return super().__exit__(*_)
|
21
|
+
def default(self):
|
22
|
+
return self._slot_manager.get_slot(":default")
|
63
23
|
|
64
24
|
def _to_json_dict(self):
|
65
25
|
data = super()._to_json_dict()
|
66
|
-
data["
|
67
|
-
|
68
|
-
}
|
69
|
-
props = data["props"]
|
70
|
-
|
71
|
-
props["scopeId"] = self.__scope.id # type: ignore
|
72
|
-
|
73
|
-
if self._slot_manager.has_slot():
|
74
|
-
props["items"] = self._slot_manager
|
75
|
-
|
76
|
-
data.pop("slots", None)
|
77
|
-
return data
|
78
|
-
|
26
|
+
data["on"] = self._on._to_element_binding_config()
|
27
|
+
data["caseValues"] = self._case_values
|
79
28
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
self.__scope = None
|
86
|
-
|
87
|
-
def __enter__(self):
|
88
|
-
self.__scope = self.__scope_manager.__enter__()
|
89
|
-
return super().__enter__()
|
90
|
-
|
91
|
-
def __exit__(self, *_) -> None:
|
92
|
-
self.__scope_manager.__exit__(*_)
|
93
|
-
return super().__exit__(*_)
|
94
|
-
|
95
|
-
def _to_json_dict(self):
|
96
|
-
data = super()._to_json_dict()
|
97
|
-
data["props"] = {}
|
98
|
-
props = data["props"]
|
29
|
+
data["slots"] = {
|
30
|
+
name: slot
|
31
|
+
for name, slot in self._slot_manager._slots.items()
|
32
|
+
if name != ":"
|
33
|
+
}
|
99
34
|
|
100
|
-
|
35
|
+
default_slot = self._slot_manager.get_slot(
|
36
|
+
"default"
|
37
|
+
)._to_items_container_config()
|
101
38
|
|
102
|
-
if
|
103
|
-
|
39
|
+
if "sid" in default_slot:
|
40
|
+
data["sid"] = default_slot["sid"]
|
104
41
|
|
105
|
-
data.pop("slots", None)
|
106
42
|
return data
|
instaui/components/slot.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import TYPE_CHECKING, Dict, List, Optional
|
3
|
+
from typing import TYPE_CHECKING, Dict, List, Optional
|
4
4
|
from instaui.common.jsonable import Jsonable
|
5
5
|
from instaui.runtime import get_slot_stacks, pop_slot
|
6
|
-
from instaui.runtime._app import
|
6
|
+
from instaui.runtime._app import ready_scope
|
7
7
|
from instaui.vars.slot_prop import BindingSlotPropItem
|
8
8
|
|
9
9
|
if TYPE_CHECKING:
|
@@ -30,13 +30,6 @@ class SlotManager(Jsonable):
|
|
30
30
|
return self.get_slot(_DEFAULT_SLOT_NAME)
|
31
31
|
|
32
32
|
def _to_json_dict(self):
|
33
|
-
if (
|
34
|
-
len(self._slots) == 1
|
35
|
-
and _DEFAULT_SLOT_NAME in self._slots
|
36
|
-
and (not self._slots[_DEFAULT_SLOT_NAME]._has_props_use())
|
37
|
-
):
|
38
|
-
return self._slots[_DEFAULT_SLOT_NAME]._children
|
39
|
-
|
40
33
|
return {name: slot._to_json_dict() for name, slot in self._slots.items()}
|
41
34
|
|
42
35
|
def has_slot(self) -> bool:
|
@@ -50,23 +43,28 @@ class Slot(Jsonable):
|
|
50
43
|
self._id: Optional[str] = None
|
51
44
|
self._name = name
|
52
45
|
self._children: List[Component] = []
|
53
|
-
self.
|
54
|
-
|
55
|
-
|
56
|
-
return len(self._props_use_name) > 0
|
46
|
+
self._use_slot_props: bool = False
|
47
|
+
self._scope_wrapper = ready_scope()
|
48
|
+
self._slot_prop_info = SlotPropInfo(self._scope_wrapper)
|
57
49
|
|
58
50
|
def props(self, name: str):
|
59
|
-
|
60
|
-
|
51
|
+
self._use_slot_props = True
|
52
|
+
self._slot_prop_info.setup()
|
53
|
+
|
54
|
+
item = BindingSlotPropItem(
|
55
|
+
name, self._slot_prop_info.sid, self._slot_prop_info.var_id
|
56
|
+
)
|
61
57
|
|
62
|
-
|
63
|
-
return BindingSlotPropItem(self._id, name)
|
58
|
+
return item[name]
|
64
59
|
|
65
60
|
def __enter__(self):
|
66
61
|
get_slot_stacks().append(self)
|
62
|
+
self._scope_wrapper.enter()
|
63
|
+
|
67
64
|
return self
|
68
65
|
|
69
66
|
def __exit__(self, *_):
|
67
|
+
self._scope_wrapper.exit()
|
70
68
|
pop_slot()
|
71
69
|
|
72
70
|
def _to_json_dict(self):
|
@@ -75,7 +73,43 @@ class Slot(Jsonable):
|
|
75
73
|
if self._children:
|
76
74
|
data["items"] = self._children
|
77
75
|
|
78
|
-
if self.
|
79
|
-
data["
|
76
|
+
if self._use_slot_props:
|
77
|
+
data["use_prop"] = 1
|
78
|
+
|
79
|
+
if self._scope_wrapper.used and self._scope_wrapper.scope.has_registered_task:
|
80
|
+
data["sid"] = self._scope_wrapper.scope_id
|
80
81
|
|
81
82
|
return data
|
83
|
+
|
84
|
+
def _to_items_container_config(self) -> Dict:
|
85
|
+
data = self._to_json_dict()
|
86
|
+
|
87
|
+
return {k: v for k, v in data.items() if k in ("items", "sid")}
|
88
|
+
|
89
|
+
|
90
|
+
class SlotPropInfo(Jsonable):
|
91
|
+
def __init__(self, scope_wrapper: ready_scope):
|
92
|
+
pass
|
93
|
+
|
94
|
+
self._scope_wrapper = scope_wrapper
|
95
|
+
self.__register_info = None
|
96
|
+
|
97
|
+
def setup(self):
|
98
|
+
if self.__register_info is not None:
|
99
|
+
return
|
100
|
+
scope = self._scope_wrapper.scope
|
101
|
+
self.__register_info = scope.register_slot_prop_info_task(self)
|
102
|
+
|
103
|
+
@property
|
104
|
+
def sid(self) -> str:
|
105
|
+
return self.__register_info.scope_id # type: ignore
|
106
|
+
|
107
|
+
@property
|
108
|
+
def var_id(self) -> str:
|
109
|
+
return self.__register_info.var_id # type: ignore
|
110
|
+
|
111
|
+
def _to_json_dict(self):
|
112
|
+
return {
|
113
|
+
"sid": self.sid,
|
114
|
+
"id": self.var_id,
|
115
|
+
}
|
instaui/components/vfor.py
CHANGED
@@ -2,19 +2,18 @@ from __future__ import annotations
|
|
2
2
|
from typing import (
|
3
3
|
Dict,
|
4
4
|
Literal,
|
5
|
-
Mapping,
|
6
5
|
Optional,
|
7
6
|
Union,
|
8
7
|
Sequence,
|
9
8
|
Generic,
|
10
9
|
TypeVar,
|
10
|
+
cast,
|
11
11
|
overload,
|
12
12
|
)
|
13
|
-
import
|
13
|
+
from enum import Enum
|
14
14
|
|
15
15
|
from instaui.components.component import Component
|
16
|
-
from instaui.vars.vfor_item import VForItem
|
17
|
-
from instaui.runtime._app import get_app_slot, new_scope
|
16
|
+
from instaui.vars.vfor_item import VForItem
|
18
17
|
|
19
18
|
from instaui.vars.mixin_types.element_binding import (
|
20
19
|
ElementBindingMixin,
|
@@ -24,10 +23,16 @@ from instaui.vars.mixin_types.element_binding import (
|
|
24
23
|
_T = TypeVar("_T")
|
25
24
|
|
26
25
|
|
26
|
+
class VForArrayTypeEnum(Enum):
|
27
|
+
CONST = "c"
|
28
|
+
REF = "r"
|
29
|
+
RANGE = "n"
|
30
|
+
|
31
|
+
|
27
32
|
class VFor(Component, Generic[_T]):
|
28
33
|
def __init__(
|
29
34
|
self,
|
30
|
-
data: Union[Sequence[_T], ElementBindingProtocol],
|
35
|
+
data: Union[Sequence[_T], ElementBindingProtocol, Dict[str, _T], _T],
|
31
36
|
*,
|
32
37
|
key: Union[Literal["item", "index"], str] = "index",
|
33
38
|
):
|
@@ -53,20 +58,12 @@ class VFor(Component, Generic[_T]):
|
|
53
58
|
super().__init__("vfor")
|
54
59
|
self._data = data
|
55
60
|
self._key = key
|
56
|
-
self._fid = get_app_slot().generate_vfor_id()
|
57
|
-
self.__scope_manager = new_scope()
|
58
|
-
self.__scope = None
|
59
61
|
self._num = None
|
60
62
|
self._transition_group_setting = None
|
61
63
|
|
62
64
|
def __enter__(self) -> _T:
|
63
|
-
self.__scope = self.__scope_manager.__enter__()
|
64
65
|
super().__enter__()
|
65
|
-
return VForItem(
|
66
|
-
|
67
|
-
def __exit__(self, *_) -> None:
|
68
|
-
self.__scope_manager.__exit__(*_)
|
69
|
-
return super().__exit__(*_)
|
66
|
+
return cast(_T, VForItem())
|
70
67
|
|
71
68
|
def _set_num(self, num):
|
72
69
|
self._num = num
|
@@ -75,41 +72,41 @@ class VFor(Component, Generic[_T]):
|
|
75
72
|
self._transition_group_setting = {"name": name, "tag": tag}
|
76
73
|
return self
|
77
74
|
|
78
|
-
@property
|
79
|
-
def current(self):
|
80
|
-
return VForItem(self)
|
81
|
-
|
82
|
-
def with_index(self):
|
83
|
-
return VForWithIndex(self)
|
84
|
-
|
85
75
|
def _to_json_dict(self):
|
86
76
|
data = super()._to_json_dict()
|
87
|
-
data["props"] = {"fid": self._fid}
|
88
77
|
|
89
|
-
props: Dict = data["props"]
|
90
78
|
if self._key is not None and self._key != "index":
|
91
|
-
|
92
|
-
|
93
|
-
if self._data is not None:
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
79
|
+
data["fkey"] = self._key
|
80
|
+
|
81
|
+
if self._data is not None or self._num is not None:
|
82
|
+
array_type = (
|
83
|
+
VForArrayTypeEnum.REF
|
84
|
+
if isinstance(self._data, ElementBindingMixin)
|
85
|
+
else VForArrayTypeEnum.RANGE
|
86
|
+
if self._num is not None
|
87
|
+
else VForArrayTypeEnum.CONST
|
88
|
+
)
|
89
|
+
|
90
|
+
array_value = (
|
91
|
+
self._data._to_element_binding_config()
|
92
|
+
if isinstance(self._data, ElementBindingMixin)
|
93
|
+
else self._num
|
94
|
+
if self._num is not None
|
95
|
+
else self._data
|
96
|
+
)
|
97
|
+
|
98
|
+
data["array"] = {"type": array_type, "value": array_value}
|
101
99
|
|
102
100
|
if self._transition_group_setting is not None:
|
103
|
-
|
101
|
+
data["tsGroup"] = {
|
104
102
|
k: v for k, v in self._transition_group_setting.items() if v is not None
|
105
103
|
}
|
106
104
|
|
107
|
-
props["scopeId"] = self.__scope.id # type: ignore
|
108
|
-
|
109
105
|
if self._slot_manager.has_slot():
|
110
|
-
|
111
|
-
|
112
|
-
|
106
|
+
slot_data = self._slot_manager.get_slot(
|
107
|
+
"default"
|
108
|
+
)._to_items_container_config()
|
109
|
+
data.update(slot_data)
|
113
110
|
|
114
111
|
return data
|
115
112
|
|
@@ -135,8 +132,6 @@ class VFor(Component, Generic[_T]):
|
|
135
132
|
|
136
133
|
return obj # type: ignore
|
137
134
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
):
|
142
|
-
return VForDict(VFor(data)) # type: ignore
|
135
|
+
|
136
|
+
def iter_info(item: _T) -> VForItem[_T]:
|
137
|
+
return cast(VForItem[_T], item)
|
instaui/components/vif.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
from typing import
|
2
|
+
from typing import cast
|
3
3
|
from instaui.components.component import Component
|
4
|
-
from instaui.runtime._app import new_scope
|
5
4
|
from instaui.vars.mixin_types.element_binding import ElementBindingMixin
|
6
5
|
from instaui.vars.types import TMaybeRef
|
7
6
|
|
@@ -10,31 +9,20 @@ class VIf(Component):
|
|
10
9
|
def __init__(self, on: TMaybeRef[bool]):
|
11
10
|
super().__init__("vif")
|
12
11
|
self._on = cast(ElementBindingMixin, on)
|
13
|
-
self.__scope_manager = new_scope()
|
14
|
-
self.__scope = None
|
15
|
-
|
16
|
-
def __enter__(self):
|
17
|
-
self.__scope = self.__scope_manager.__enter__()
|
18
|
-
return super().__enter__()
|
19
|
-
|
20
|
-
def __exit__(self, *_) -> None:
|
21
|
-
self.__scope_manager.__exit__(*_)
|
22
|
-
return super().__exit__(*_)
|
23
12
|
|
24
13
|
def _to_json_dict(self):
|
25
14
|
data = super()._to_json_dict()
|
26
|
-
data["props"] = {
|
27
|
-
"on": self._on
|
28
|
-
if isinstance(self._on, bool)
|
29
|
-
else self._on._to_element_binding_config(),
|
30
|
-
}
|
31
|
-
props: Dict = data["props"]
|
32
15
|
|
33
|
-
|
16
|
+
data["on"] = (
|
17
|
+
self._on
|
18
|
+
if isinstance(self._on, bool)
|
19
|
+
else self._on._to_element_binding_config()
|
20
|
+
)
|
34
21
|
|
35
22
|
if self._slot_manager.has_slot():
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
slot_data = self._slot_manager.get_slot(
|
24
|
+
"default"
|
25
|
+
)._to_items_container_config()
|
26
|
+
data.update(slot_data)
|
39
27
|
|
40
28
|
return data
|
instaui/event/js_event.py
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
import typing
|
2
|
-
from instaui.vars.mixin_types.py_binding import
|
2
|
+
from instaui.vars.mixin_types.py_binding import (
|
3
|
+
CanInputMixin,
|
4
|
+
CanOutputMixin,
|
5
|
+
inputs_to_config,
|
6
|
+
outputs_to_config,
|
7
|
+
)
|
3
8
|
from instaui.common.jsonable import Jsonable
|
4
9
|
from .event_mixin import EventMixin
|
5
10
|
|
@@ -16,11 +21,8 @@ class JsEvent(Jsonable, EventMixin):
|
|
16
21
|
]
|
17
22
|
self._org_inputs = list(inputs or [])
|
18
23
|
self._org_outputs = list(outputs or [])
|
19
|
-
self._inputs = [
|
20
|
-
|
21
|
-
for input in inputs or []
|
22
|
-
]
|
23
|
-
self._outputs = [output._to_output_config() for output in outputs or []]
|
24
|
+
self._inputs = inputs or []
|
25
|
+
self._outputs = outputs or []
|
24
26
|
self.code = code
|
25
27
|
|
26
28
|
def _to_json_dict(self):
|
@@ -28,10 +30,10 @@ class JsEvent(Jsonable, EventMixin):
|
|
28
30
|
data["type"] = self.event_type()
|
29
31
|
|
30
32
|
if self._inputs:
|
31
|
-
data["inputs"] = self._inputs
|
33
|
+
data["inputs"] = inputs_to_config(self._inputs)
|
32
34
|
|
33
35
|
if self._outputs:
|
34
|
-
data["
|
36
|
+
data["sets"] = outputs_to_config(self._outputs)
|
35
37
|
|
36
38
|
if sum(self._is_const_data) > 0:
|
37
39
|
data["data"] = self._is_const_data
|
instaui/event/vue_event.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import typing
|
2
2
|
from instaui.common.jsonable import Jsonable
|
3
|
-
from instaui.vars.mixin_types.
|
3
|
+
from instaui.vars.mixin_types.py_binding import CanInputMixin
|
4
|
+
from instaui.vars._types import InputBindingType
|
4
5
|
from .event_mixin import EventMixin
|
5
6
|
|
6
7
|
|
@@ -36,21 +37,6 @@ class VueEvent(Jsonable, EventMixin):
|
|
36
37
|
self.code = code
|
37
38
|
self._bindings = bindings
|
38
39
|
|
39
|
-
if bindings:
|
40
|
-
bindData = [
|
41
|
-
int(not isinstance(v, ObservableMixin)) for v in bindings.values()
|
42
|
-
]
|
43
|
-
|
44
|
-
if sum(bindData) > 0:
|
45
|
-
self.bindData = bindData
|
46
|
-
|
47
|
-
self.bind = {
|
48
|
-
k: typing.cast(ObservableMixin, v)._to_observable_config()
|
49
|
-
if isinstance(v, ObservableMixin)
|
50
|
-
else v
|
51
|
-
for k, v in bindings.items()
|
52
|
-
}
|
53
|
-
|
54
40
|
def copy_with_extends(self, extends: typing.Dict):
|
55
41
|
raise NotImplementedError("VueEvent does not support extends")
|
56
42
|
|
@@ -60,6 +46,18 @@ class VueEvent(Jsonable, EventMixin):
|
|
60
46
|
def _to_json_dict(self):
|
61
47
|
data = super()._to_json_dict()
|
62
48
|
data["type"] = self.event_type()
|
49
|
+
if self._bindings:
|
50
|
+
data["inputs"] = {
|
51
|
+
name: {
|
52
|
+
"value": v._to_input_config()
|
53
|
+
if isinstance(v, CanInputMixin)
|
54
|
+
else v,
|
55
|
+
"type": v._to_event_input_type().value
|
56
|
+
if isinstance(v, CanInputMixin)
|
57
|
+
else InputBindingType.Data,
|
58
|
+
}
|
59
|
+
for name, v in self._bindings.items()
|
60
|
+
}
|
63
61
|
return data
|
64
62
|
|
65
63
|
|
instaui/event/web_event.py
CHANGED
@@ -7,6 +7,8 @@ from instaui.vars.mixin_types.py_binding import (
|
|
7
7
|
CanInputMixin,
|
8
8
|
CanOutputMixin,
|
9
9
|
_assert_outputs_be_can_output_mixin,
|
10
|
+
inputs_to_config,
|
11
|
+
outputs_to_config,
|
10
12
|
)
|
11
13
|
from instaui.handlers import event_handler
|
12
14
|
from instaui import pre_setup as _pre_setup
|
@@ -74,15 +76,10 @@ class WebEvent(Jsonable, EventMixin, typing.Generic[P, R]):
|
|
74
76
|
data["sid"] = self._sid
|
75
77
|
|
76
78
|
if self._inputs:
|
77
|
-
data["
|
78
|
-
binding._to_input_config()
|
79
|
-
if isinstance(binding, CanInputMixin)
|
80
|
-
else binding
|
81
|
-
for binding in self._inputs
|
82
|
-
]
|
79
|
+
data["inputs"] = inputs_to_config(self._inputs)
|
83
80
|
|
84
81
|
if self._outputs:
|
85
|
-
data["
|
82
|
+
data["sets"] = outputs_to_config(self._outputs)
|
86
83
|
|
87
84
|
if self._pre_setup:
|
88
85
|
data["preSetup"] = _pre_setup.convert_config(self._pre_setup)
|
instaui/html_tools.py
CHANGED
@@ -87,8 +87,14 @@ def add_vue_app_use(name: str):
|
|
87
87
|
|
88
88
|
|
89
89
|
def to_config_data() -> Dict:
|
90
|
-
|
90
|
+
app = get_app_slot()
|
91
|
+
data = dumps2dict(app)
|
92
|
+
|
93
|
+
# Exclude scopes that contain only the id field.
|
94
|
+
scopes = [s for s in dumps2dict(app._scopes) if len(s) > 1]
|
95
|
+
data["scopes"] = scopes
|
96
|
+
return data
|
91
97
|
|
92
98
|
|
93
99
|
def to_json(indent=False):
|
94
|
-
return dumps(
|
100
|
+
return dumps(to_config_data(), indent=indent)
|
instaui/js/fn.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
from instaui.common.jsonable import Jsonable
|
2
|
+
from instaui.vars._types import InputBindingType
|
2
3
|
from instaui.vars.mixin_types.py_binding import CanInputMixin
|
3
|
-
from instaui.runtime._app import get_app_slot
|
4
|
+
from instaui.runtime._app import get_app_slot, get_current_scope
|
4
5
|
|
5
6
|
|
6
7
|
class JsFn(Jsonable, CanInputMixin):
|
@@ -21,26 +22,28 @@ class JsFn(Jsonable, CanInputMixin):
|
|
21
22
|
ui.label(result)
|
22
23
|
"""
|
23
24
|
|
24
|
-
def __init__(self, code: str, *, execute_immediately=False):
|
25
|
+
def __init__(self, code: str, *, execute_immediately=False, global_scope=False):
|
25
26
|
self.code = code
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
|
28
|
+
scope = get_app_slot().top_scope if global_scope else get_current_scope()
|
29
|
+
self.__register_info = scope.register_js_fn_task(self)
|
30
|
+
|
30
31
|
self._execute_immediately = execute_immediately
|
31
32
|
|
32
33
|
def _to_input_config(self):
|
33
34
|
return {
|
34
|
-
"
|
35
|
-
"id": self.
|
35
|
+
"sid": self.__register_info.scope_id,
|
36
|
+
"id": self.__register_info.var_id,
|
36
37
|
}
|
37
38
|
|
38
39
|
def _to_json_dict(self):
|
39
40
|
data = super()._to_json_dict()
|
40
|
-
data["
|
41
|
-
data["id"] = self.__id
|
41
|
+
data["id"] = self.__register_info.var_id
|
42
42
|
|
43
43
|
if self._execute_immediately is True:
|
44
44
|
data["immediately"] = 1
|
45
45
|
|
46
46
|
return data
|
47
|
+
|
48
|
+
def _to_event_input_type(self) -> InputBindingType:
|
49
|
+
return InputBindingType.JsFn
|
instaui/runtime/__init__.py
CHANGED
@@ -6,7 +6,7 @@ from ._app import (
|
|
6
6
|
get_slot_stacks,
|
7
7
|
pop_slot,
|
8
8
|
get_current_scope,
|
9
|
-
|
9
|
+
ready_scope,
|
10
10
|
check_default_app_slot_or_error,
|
11
11
|
in_default_app_slot,
|
12
12
|
)
|
@@ -15,7 +15,7 @@ from .resource import HtmlResource
|
|
15
15
|
|
16
16
|
__all__ = [
|
17
17
|
"get_slot_stacks",
|
18
|
-
"
|
18
|
+
"ready_scope",
|
19
19
|
"get_current_scope",
|
20
20
|
"get_app_slot",
|
21
21
|
"reset_app_slot",
|