instaui 0.1.18__py2.py3-none-any.whl → 0.1.19__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/components/component.py +0 -2
- instaui/components/element.py +0 -16
- instaui/components/match.py +4 -6
- instaui/components/vfor.py +2 -4
- instaui/components/vif.py +2 -4
- instaui/event/js_event.py +0 -2
- instaui/event/vue_event.py +0 -3
- instaui/event/web_event.py +0 -3
- instaui/runtime/_app.py +2 -2
- instaui/runtime/scope.py +74 -33
- instaui/spa_router/_route_model.py +5 -6
- instaui/static/insta-ui.esm-browser.prod.js +1010 -984
- instaui/static/insta-ui.js.map +1 -1
- instaui/vars/data.py +5 -7
- instaui/vars/js_computed.py +6 -22
- instaui/vars/mixin_types/element_binding.py +1 -13
- instaui/vars/ref.py +5 -7
- instaui/vars/vue_computed.py +6 -21
- instaui/vars/web_computed.py +6 -23
- instaui/watch/js_watch.py +0 -2
- instaui/watch/web_watch.py +0 -2
- {instaui-0.1.18.dist-info → instaui-0.1.19.dist-info}/METADATA +1 -1
- {instaui-0.1.18.dist-info → instaui-0.1.19.dist-info}/RECORD +25 -25
- {instaui-0.1.18.dist-info → instaui-0.1.19.dist-info}/WHEEL +0 -0
- {instaui-0.1.18.dist-info → instaui-0.1.19.dist-info}/licenses/LICENSE +0 -0
instaui/components/component.py
CHANGED
instaui/components/element.py
CHANGED
@@ -271,28 +271,18 @@ class Element(Component):
|
|
271
271
|
|
272
272
|
if isinstance(add, dict):
|
273
273
|
self._dict_classes.update(**add) # type: ignore
|
274
|
-
for value in (
|
275
|
-
v for v in add.values() if isinstance(v, ElementBindingMixin)
|
276
|
-
):
|
277
|
-
value._mark_used()
|
278
274
|
|
279
275
|
if isinstance(add, ElementBindingMixin):
|
280
276
|
self._bind_str_classes.append(add) # type: ignore
|
281
|
-
add._mark_used()
|
282
277
|
|
283
278
|
return self
|
284
279
|
|
285
280
|
def style(self, add: Union[str, Dict[str, Any], TMaybeRef[str]]) -> Self:
|
286
281
|
if isinstance(add, dict):
|
287
282
|
add = {key: value for key, value in add.items()}
|
288
|
-
for value in (
|
289
|
-
v for v in add.values() if isinstance(v, ElementBindingMixin)
|
290
|
-
):
|
291
|
-
value._mark_used()
|
292
283
|
|
293
284
|
if isinstance(add, ElementBindingMixin):
|
294
285
|
self._style_str_binds.append(add)
|
295
|
-
add._mark_used()
|
296
286
|
return self
|
297
287
|
|
298
288
|
new_style = self._parse_style(add)
|
@@ -302,17 +292,11 @@ class Element(Component):
|
|
302
292
|
def props(self, add: Union[str, Dict[str, Any], TMaybeRef]) -> Self:
|
303
293
|
if isinstance(add, ElementBindingMixin):
|
304
294
|
self._proxy_props.append(add)
|
305
|
-
add._mark_used()
|
306
295
|
return self
|
307
296
|
|
308
297
|
if isinstance(add, dict):
|
309
298
|
add = {key: value for key, value in add.items() if value is not None}
|
310
299
|
|
311
|
-
for value in (
|
312
|
-
v for v in add.values() if isinstance(v, ElementBindingMixin)
|
313
|
-
):
|
314
|
-
value._mark_used()
|
315
|
-
|
316
300
|
new_props = self._parse_props(add)
|
317
301
|
self._props.update(new_props)
|
318
302
|
return self
|
instaui/components/match.py
CHANGED
@@ -11,8 +11,6 @@ class Match(Component):
|
|
11
11
|
def __init__(self, on: ElementBindingMixin):
|
12
12
|
super().__init__("match")
|
13
13
|
self._on = on
|
14
|
-
if isinstance(on, ElementBindingMixin):
|
15
|
-
on._mark_used()
|
16
14
|
self._default_case = None
|
17
15
|
|
18
16
|
def _to_json_dict(self):
|
@@ -52,7 +50,7 @@ class Case(Component):
|
|
52
50
|
def __init__(self, value: typing.Any):
|
53
51
|
super().__init__("case")
|
54
52
|
self._value = value
|
55
|
-
self.__scope_manager = new_scope(
|
53
|
+
self.__scope_manager = new_scope()
|
56
54
|
self.__scope = None
|
57
55
|
|
58
56
|
def __enter__(self):
|
@@ -70,7 +68,7 @@ class Case(Component):
|
|
70
68
|
}
|
71
69
|
props = data["props"]
|
72
70
|
|
73
|
-
props["
|
71
|
+
props["scopeId"] = self.__scope.id # type: ignore
|
74
72
|
|
75
73
|
if self._slot_manager.has_slot():
|
76
74
|
props["items"] = self._slot_manager
|
@@ -83,7 +81,7 @@ class DefaultCase(Component):
|
|
83
81
|
def __init__(self):
|
84
82
|
super().__init__("default-case")
|
85
83
|
|
86
|
-
self.__scope_manager = new_scope(
|
84
|
+
self.__scope_manager = new_scope()
|
87
85
|
self.__scope = None
|
88
86
|
|
89
87
|
def __enter__(self):
|
@@ -99,7 +97,7 @@ class DefaultCase(Component):
|
|
99
97
|
data["props"] = {}
|
100
98
|
props = data["props"]
|
101
99
|
|
102
|
-
props["
|
100
|
+
props["scopeId"] = self.__scope.id # type: ignore
|
103
101
|
|
104
102
|
if self._slot_manager.has_slot():
|
105
103
|
props["items"] = self._slot_manager
|
instaui/components/vfor.py
CHANGED
@@ -50,11 +50,9 @@ class VFor(Component, Generic[_T]):
|
|
50
50
|
|
51
51
|
super().__init__("vfor")
|
52
52
|
self._data = data
|
53
|
-
if isinstance(self._data, ElementBindingMixin):
|
54
|
-
self._data._mark_used()
|
55
53
|
self._key = key
|
56
54
|
self._fid = get_app_slot().generate_vfor_id()
|
57
|
-
self.__scope_manager = new_scope(
|
55
|
+
self.__scope_manager = new_scope()
|
58
56
|
self.__scope = None
|
59
57
|
self._num = None
|
60
58
|
self._transition_group_setting = None
|
@@ -104,7 +102,7 @@ class VFor(Component, Generic[_T]):
|
|
104
102
|
k: v for k, v in self._transition_group_setting.items() if v is not None
|
105
103
|
}
|
106
104
|
|
107
|
-
props["
|
105
|
+
props["scopeId"] = self.__scope.id # type: ignore
|
108
106
|
|
109
107
|
if self._slot_manager.has_slot():
|
110
108
|
props["items"] = self._slot_manager
|
instaui/components/vif.py
CHANGED
@@ -10,9 +10,7 @@ class VIf(Component):
|
|
10
10
|
def __init__(self, on: TMaybeRef[bool]):
|
11
11
|
super().__init__("vif")
|
12
12
|
self._on = cast(ElementBindingMixin, on)
|
13
|
-
|
14
|
-
on._mark_used()
|
15
|
-
self.__scope_manager = new_scope(append_to_app=False)
|
13
|
+
self.__scope_manager = new_scope()
|
16
14
|
self.__scope = None
|
17
15
|
|
18
16
|
def __enter__(self):
|
@@ -32,7 +30,7 @@ class VIf(Component):
|
|
32
30
|
}
|
33
31
|
props: Dict = data["props"]
|
34
32
|
|
35
|
-
props["
|
33
|
+
props["scopeId"] = self.__scope.id # type: ignore
|
36
34
|
|
37
35
|
if self._slot_manager.has_slot():
|
38
36
|
props["items"] = self._slot_manager
|
instaui/event/js_event.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import typing
|
2
2
|
from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
3
|
-
from instaui.vars.mixin_types.element_binding import _try_mark_inputs_used
|
4
3
|
from instaui.common.jsonable import Jsonable
|
5
4
|
from .event_mixin import EventMixin
|
6
5
|
|
@@ -27,7 +26,6 @@ class JsEvent(Jsonable, EventMixin):
|
|
27
26
|
def _to_json_dict(self):
|
28
27
|
data = super()._to_json_dict()
|
29
28
|
data["type"] = self.event_type()
|
30
|
-
_try_mark_inputs_used(self._org_inputs)
|
31
29
|
|
32
30
|
if self._inputs:
|
33
31
|
data["inputs"] = self._inputs
|
instaui/event/vue_event.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import typing
|
2
2
|
from instaui.common.jsonable import Jsonable
|
3
3
|
from instaui.vars.mixin_types.observable import ObservableMixin
|
4
|
-
from instaui.vars.mixin_types.element_binding import _try_mark_inputs_used
|
5
4
|
from .event_mixin import EventMixin
|
6
5
|
|
7
6
|
|
@@ -60,8 +59,6 @@ class VueEvent(Jsonable, EventMixin):
|
|
60
59
|
|
61
60
|
def _to_json_dict(self):
|
62
61
|
data = super()._to_json_dict()
|
63
|
-
|
64
|
-
_try_mark_inputs_used((self._bindings or {}).values())
|
65
62
|
data["type"] = self.event_type()
|
66
63
|
return data
|
67
64
|
|
instaui/event/web_event.py
CHANGED
@@ -4,7 +4,6 @@ from typing_extensions import ParamSpec
|
|
4
4
|
from instaui.common.jsonable import Jsonable
|
5
5
|
from instaui.runtime._app import get_current_scope, get_app_slot
|
6
6
|
from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
7
|
-
from instaui.vars.mixin_types.element_binding import _try_mark_inputs_used
|
8
7
|
from instaui.handlers import event_handler
|
9
8
|
from .event_mixin import EventMixin
|
10
9
|
|
@@ -47,8 +46,6 @@ class WebEvent(Jsonable, EventMixin, typing.Generic[P, R]):
|
|
47
46
|
def _to_json_dict(self):
|
48
47
|
app = get_app_slot()
|
49
48
|
|
50
|
-
_try_mark_inputs_used(self._inputs)
|
51
|
-
|
52
49
|
hkey = event_handler.create_handler_key(
|
53
50
|
page_path=app.page_path, handler=self._fn
|
54
51
|
)
|
instaui/runtime/_app.py
CHANGED
@@ -126,8 +126,8 @@ class App(Jsonable):
|
|
126
126
|
|
127
127
|
data["url"] = url_info
|
128
128
|
|
129
|
-
|
130
|
-
data["
|
129
|
+
data["scopeId"] = self._scopes[0].id
|
130
|
+
data["scopes"] = self._scopes
|
131
131
|
|
132
132
|
if self._route_collector is not None:
|
133
133
|
data["router"] = self._route_collector.model_dump(
|
instaui/runtime/scope.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import TYPE_CHECKING, List
|
3
|
+
from typing import TYPE_CHECKING, Callable, List
|
4
|
+
import functools
|
5
|
+
import weakref
|
4
6
|
from instaui.common.jsonable import Jsonable
|
5
7
|
|
6
8
|
|
@@ -58,21 +60,6 @@ class Scope(Jsonable):
|
|
58
60
|
"on": [v._to_input_config() for v in on],
|
59
61
|
}
|
60
62
|
|
61
|
-
def register_ref(self, var: VarMixin) -> None:
|
62
|
-
self._refs.append(var)
|
63
|
-
|
64
|
-
def register_data(self, data: ConstData) -> None:
|
65
|
-
self._const_data.append(data)
|
66
|
-
|
67
|
-
def register_js_computed(self, computed: JsComputed) -> None:
|
68
|
-
self._js_computeds.append(computed)
|
69
|
-
|
70
|
-
def register_vue_computed(self, computed: VueComputed) -> None:
|
71
|
-
self._vue_computeds.append(computed)
|
72
|
-
|
73
|
-
def register_web_computed(self, computed: WebComputed) -> None:
|
74
|
-
self._web_computeds.append(computed)
|
75
|
-
|
76
63
|
def register_web_watch(self, watch: WebWatch) -> None:
|
77
64
|
self._web_watchs.append(watch)
|
78
65
|
|
@@ -82,6 +69,51 @@ class Scope(Jsonable):
|
|
82
69
|
def register_vue_watch(self, watch: VueWatch) -> None:
|
83
70
|
self._vue_watchs.append(watch)
|
84
71
|
|
72
|
+
def register_data_task(self, data: ConstData):
|
73
|
+
weak_obj = weakref.ref(data)
|
74
|
+
|
75
|
+
def register_fn():
|
76
|
+
self._const_data.append(weak_obj()) # type: ignore
|
77
|
+
return self.generate_vars_id()
|
78
|
+
|
79
|
+
return VarRegisterTask(self.id, register_fn)
|
80
|
+
|
81
|
+
def register_ref_task(self, ref: VarMixin):
|
82
|
+
weak_obj = weakref.ref(ref)
|
83
|
+
|
84
|
+
def register_fn():
|
85
|
+
self._refs.append(weak_obj()) # type: ignore
|
86
|
+
return self.generate_vars_id()
|
87
|
+
|
88
|
+
return VarRegisterTask(self.id, register_fn)
|
89
|
+
|
90
|
+
def register_js_computed_task(self, computed: JsComputed):
|
91
|
+
weak_obj = weakref.ref(computed)
|
92
|
+
|
93
|
+
def register_fn():
|
94
|
+
self._js_computeds.append(weak_obj()) # type: ignore
|
95
|
+
return self.generate_vars_id()
|
96
|
+
|
97
|
+
return VarRegisterTask(self.id, register_fn)
|
98
|
+
|
99
|
+
def register_computed_task(self, computed: WebComputed):
|
100
|
+
weak_obj = weakref.ref(computed)
|
101
|
+
|
102
|
+
def register_fn():
|
103
|
+
self._web_computeds.append(weak_obj()) # type: ignore
|
104
|
+
return self.generate_vars_id()
|
105
|
+
|
106
|
+
return VarRegisterTask(self.id, register_fn)
|
107
|
+
|
108
|
+
def register_vue_computed_task(self, computed: VueComputed):
|
109
|
+
weak_obj = weakref.ref(computed)
|
110
|
+
|
111
|
+
def register_fn():
|
112
|
+
self._vue_computeds.append(weak_obj()) # type: ignore
|
113
|
+
return self.generate_vars_id()
|
114
|
+
|
115
|
+
return VarRegisterTask(self.id, register_fn)
|
116
|
+
|
85
117
|
def _to_json_dict(self):
|
86
118
|
data = super()._to_json_dict()
|
87
119
|
if self._refs:
|
@@ -97,23 +129,12 @@ class Scope(Jsonable):
|
|
97
129
|
if self._element_refs:
|
98
130
|
data["eRefs"] = self._element_refs
|
99
131
|
|
100
|
-
|
101
|
-
|
102
|
-
computed for computed in self._web_computeds if computed._is_used()
|
103
|
-
]
|
104
|
-
|
105
|
-
if _web_computeds:
|
106
|
-
data["web_computed"] = _web_computeds
|
132
|
+
if self._web_computeds:
|
133
|
+
data["web_computed"] = self._web_computeds
|
107
134
|
|
108
|
-
|
109
|
-
|
110
|
-
computed for computed in self._js_computeds if computed._is_used()
|
111
|
-
]
|
135
|
+
if self._js_computeds:
|
136
|
+
data["js_computed"] = self._js_computeds
|
112
137
|
|
113
|
-
if _js_computeds:
|
114
|
-
data["js_computed"] = _js_computeds
|
115
|
-
|
116
|
-
# vue computeds
|
117
138
|
if self._vue_computeds:
|
118
139
|
data["vue_computed"] = self._vue_computeds
|
119
140
|
if self._const_data:
|
@@ -126,12 +147,18 @@ class GlobalScope(Scope):
|
|
126
147
|
def __init__(self, id: str) -> None:
|
127
148
|
super().__init__(id)
|
128
149
|
|
129
|
-
def
|
150
|
+
def register_ref_task(self, var: VarMixin) -> None:
|
130
151
|
raise ValueError("Can not register ref in global scope")
|
131
152
|
|
132
|
-
def
|
153
|
+
def register_computed_task(self, computed: WebComputed) -> None:
|
133
154
|
raise ValueError("Can not register web_computeds in global scope")
|
134
155
|
|
156
|
+
def register_js_computed_task(self, computed: JsComputed):
|
157
|
+
raise ValueError("Can not register js_computeds in global scope")
|
158
|
+
|
159
|
+
def register_vue_computed_task(self, computed: VueComputed):
|
160
|
+
raise ValueError("Can not register vue_computeds in global scope")
|
161
|
+
|
135
162
|
def register_web_watch(self, watch: WebWatch) -> None:
|
136
163
|
raise ValueError("Can not register web_watchs in global scope")
|
137
164
|
|
@@ -140,3 +167,17 @@ class GlobalScope(Scope):
|
|
140
167
|
|
141
168
|
def register_vue_watch(self, watch: VueWatch) -> None:
|
142
169
|
raise ValueError("Can not register vue_watchs in global scope")
|
170
|
+
|
171
|
+
|
172
|
+
class VarRegisterTask:
|
173
|
+
def __init__(self, scope_id: str, register_fn: Callable[[], str]) -> None:
|
174
|
+
self._scope_id = scope_id
|
175
|
+
self._id_gen_fn = functools.lru_cache(maxsize=1)(register_fn)
|
176
|
+
|
177
|
+
@property
|
178
|
+
def scope_id(self) -> str:
|
179
|
+
return self._scope_id
|
180
|
+
|
181
|
+
@property
|
182
|
+
def var_id(self) -> str:
|
183
|
+
return self._id_gen_fn()
|
@@ -5,7 +5,6 @@ from pydantic import BaseModel, Field, ConfigDict, field_serializer, model_seria
|
|
5
5
|
from instaui.components.html.div import Div
|
6
6
|
from instaui.runtime._app import get_app_slot, new_scope
|
7
7
|
from instaui.components.component import Component
|
8
|
-
from instaui.runtime.scope import Scope
|
9
8
|
from instaui.common.jsonable import dumps2dict
|
10
9
|
|
11
10
|
from . import _types
|
@@ -15,7 +14,7 @@ class RouteItem(BaseModel):
|
|
15
14
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
16
15
|
|
17
16
|
component_fn: typing.Optional[typing.Callable] = Field(exclude=True)
|
18
|
-
|
17
|
+
scopeId: typing.Optional[str] = None
|
19
18
|
vue_route_item: VueRouteItem = Field(serialization_alias="vueItem")
|
20
19
|
meta: typing.Optional[typing.Dict] = None
|
21
20
|
|
@@ -30,20 +29,20 @@ class RouteItem(BaseModel):
|
|
30
29
|
}
|
31
30
|
|
32
31
|
if self.vue_route_item.path is None:
|
33
|
-
self.vue_route_item.path = f"/{'' if self.component_fn.__name__=='index' else self.component_fn.__name__}"
|
32
|
+
self.vue_route_item.path = f"/{'' if self.component_fn.__name__ == 'index' else self.component_fn.__name__}"
|
34
33
|
|
35
34
|
app = get_app_slot()
|
36
|
-
with new_scope(
|
35
|
+
with new_scope() as scope:
|
37
36
|
with Div() as div:
|
38
37
|
self.component_fn()
|
39
38
|
|
40
39
|
app.items.pop()
|
41
40
|
|
42
|
-
self.
|
41
|
+
self.scopeId = scope.id
|
43
42
|
self.vue_route_item.component = div._slot_manager.default._children
|
44
43
|
|
45
44
|
return {
|
46
|
-
"
|
45
|
+
"scopeId": scope.id,
|
47
46
|
"vueItem": self.vue_route_item,
|
48
47
|
}
|
49
48
|
|