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.
- instaui/arco/components/select.py +2 -1
- instaui/components/component.py +3 -1
- instaui/components/container.py +32 -0
- instaui/components/element.py +1 -4
- instaui/components/heading.py +46 -0
- 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 +11 -8
- 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 +2313 -2361
- instaui/static/insta-ui.js.map +1 -1
- instaui/ui/__init__.py +7 -2
- instaui/ui/__init__.pyi +7 -2
- instaui/ui_functions/input_slient_data.py +4 -0
- instaui/ui_system_var_type.py +6 -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 +40 -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 +15 -6
- {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/METADATA +1 -1
- {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/RECORD +48 -45
- {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/WHEEL +0 -0
- {instaui-0.2.1.dist-info → instaui-0.3.0.dist-info}/licenses/LICENSE +0 -0
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",
|
instaui/runtime/_app.py
CHANGED
@@ -6,7 +6,6 @@ from instaui.common.jsonable import Jsonable
|
|
6
6
|
from .resource import HtmlResource
|
7
7
|
from instaui.consts import _T_App_Mode
|
8
8
|
from contextvars import ContextVar, Token
|
9
|
-
from contextlib import contextmanager
|
10
9
|
from instaui.runtime.scope import Scope, GlobalScope
|
11
10
|
from types import MappingProxyType
|
12
11
|
|
@@ -17,7 +16,6 @@ if TYPE_CHECKING:
|
|
17
16
|
from instaui.dependencies.component_dependency import ComponentDependencyInfo
|
18
17
|
from instaui.dependencies.plugin_dependency import PluginDependencyInfo
|
19
18
|
from instaui.spa_router._route_model import RouteCollector
|
20
|
-
from instaui.js.fn import JsFn
|
21
19
|
|
22
20
|
|
23
21
|
class App(Jsonable):
|
@@ -27,9 +25,6 @@ class App(Jsonable):
|
|
27
25
|
def __init__(self, *, mode: _T_App_Mode, meta: Optional[Dict] = None) -> None:
|
28
26
|
super().__init__()
|
29
27
|
self._scope_id_counter = 0
|
30
|
-
self._vfor_id_counter = 0
|
31
|
-
self._slot_id_counter = 0
|
32
|
-
self._js_fn_id_counter = 0
|
33
28
|
self._mode: _T_App_Mode = mode
|
34
29
|
self.items: List[Component] = []
|
35
30
|
self.meta = meta
|
@@ -38,6 +33,7 @@ class App(Jsonable):
|
|
38
33
|
defalut_scope = self.create_scope()
|
39
34
|
self._scope_stack: List[Scope] = [defalut_scope]
|
40
35
|
self._scopes: List[Scope] = [defalut_scope]
|
36
|
+
self._sid = defalut_scope.id
|
41
37
|
self._html_resource = HtmlResource()
|
42
38
|
self._component_dependencies: Set[ComponentDependencyInfo] = set()
|
43
39
|
self._temp_component_dependencies: Dict[str, ComponentDependencyInfo] = {}
|
@@ -47,12 +43,15 @@ class App(Jsonable):
|
|
47
43
|
self._page_params: Dict[str, Any] = {}
|
48
44
|
self._query_params: Dict[str, Any] = {}
|
49
45
|
self._route_collector: Optional[RouteCollector] = None
|
50
|
-
self._js_fns: List[JsFn] = []
|
51
46
|
|
52
47
|
@property
|
53
48
|
def mode(self) -> _T_App_Mode:
|
54
49
|
return self._mode
|
55
50
|
|
51
|
+
@property
|
52
|
+
def top_scope(self) -> Scope:
|
53
|
+
return self._scope_stack[0]
|
54
|
+
|
56
55
|
@property
|
57
56
|
def page_path(self) -> str:
|
58
57
|
assert self._page_path is not None, "Page path is not set"
|
@@ -71,21 +70,6 @@ class App(Jsonable):
|
|
71
70
|
scope = Scope(str(self._scope_id_counter))
|
72
71
|
return scope
|
73
72
|
|
74
|
-
def generate_vfor_id(self) -> str:
|
75
|
-
self._vfor_id_counter += 1
|
76
|
-
return str(self._vfor_id_counter)
|
77
|
-
|
78
|
-
def generate_slot_id(self) -> str:
|
79
|
-
self._slot_id_counter += 1
|
80
|
-
return str(self._slot_id_counter)
|
81
|
-
|
82
|
-
def generate_js_fn_id(self) -> str:
|
83
|
-
self._js_fn_id_counter += 1
|
84
|
-
return str(self._js_fn_id_counter)
|
85
|
-
|
86
|
-
def register_js_fn(self, fn: JsFn) -> None:
|
87
|
-
self._js_fns.append(fn)
|
88
|
-
|
89
73
|
def reset_html_resource(self):
|
90
74
|
self._html_resource = HtmlResource()
|
91
75
|
|
@@ -130,8 +114,7 @@ class App(Jsonable):
|
|
130
114
|
|
131
115
|
data["url"] = url_info
|
132
116
|
|
133
|
-
data["
|
134
|
-
data["scopes"] = self._scopes
|
117
|
+
# data["scopes"] = self._scopes
|
135
118
|
|
136
119
|
if self._route_collector is not None:
|
137
120
|
data["router"] = self._route_collector.model_dump(
|
@@ -141,8 +124,7 @@ class App(Jsonable):
|
|
141
124
|
if self._web_server_info is not None:
|
142
125
|
data["webInfo"] = self._web_server_info
|
143
126
|
|
144
|
-
|
145
|
-
data["jsFn"] = self._js_fns
|
127
|
+
data["sid"] = self._sid
|
146
128
|
|
147
129
|
return data
|
148
130
|
|
@@ -193,19 +175,45 @@ def get_current_scope():
|
|
193
175
|
return current_scope
|
194
176
|
|
195
177
|
|
196
|
-
|
197
|
-
def
|
198
|
-
|
199
|
-
|
178
|
+
class ready_scope:
|
179
|
+
def __init__(self) -> None:
|
180
|
+
self._scope = None
|
181
|
+
|
182
|
+
@property
|
183
|
+
def used(self) -> bool:
|
184
|
+
return self._scope is not None
|
185
|
+
|
186
|
+
@property
|
187
|
+
def has_vars(self) -> bool:
|
188
|
+
return self._scope.has_var # type: ignore
|
189
|
+
|
190
|
+
@property
|
191
|
+
def scope(self) -> Scope:
|
192
|
+
return self._scope # type: ignore
|
193
|
+
|
194
|
+
@property
|
195
|
+
def scope_id(self) -> str:
|
196
|
+
return self._scope.id # type: ignore
|
197
|
+
|
198
|
+
def __enter__(self):
|
199
|
+
return self.enter()
|
200
|
+
|
201
|
+
def __exit__(self, *_) -> None:
|
202
|
+
self.exit(*_)
|
203
|
+
|
204
|
+
def enter(self):
|
205
|
+
if self._scope is not None:
|
206
|
+
raise ValueError("Scope is already used")
|
200
207
|
|
201
|
-
|
202
|
-
app.
|
208
|
+
app = get_app_slot()
|
209
|
+
self._scope = app.create_scope()
|
210
|
+
app._scopes.append(self._scope)
|
211
|
+
app._scope_stack.append(self._scope)
|
203
212
|
|
204
|
-
|
205
|
-
scope_stack.append(scope)
|
213
|
+
return self._scope
|
206
214
|
|
207
|
-
|
208
|
-
|
215
|
+
def exit(self, *_) -> None:
|
216
|
+
get_app_slot()._scope_stack.pop()
|
209
217
|
|
210
218
|
|
211
219
|
def get_slot_stacks():
|
instaui/runtime/scope.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import TYPE_CHECKING, Callable, List
|
3
|
+
from typing import TYPE_CHECKING, Callable, Dict, List, Optional
|
4
4
|
import functools
|
5
5
|
import weakref
|
6
6
|
from instaui.common.jsonable import Jsonable
|
@@ -17,6 +17,9 @@ if TYPE_CHECKING:
|
|
17
17
|
from instaui.watch.js_watch import JsWatch
|
18
18
|
from instaui.watch.vue_watch import VueWatch
|
19
19
|
from instaui.vars.element_ref import ElementRef
|
20
|
+
from instaui.vars.vfor_item import VForItem, VForIndex, VForItemKey
|
21
|
+
from instaui.components.slot import SlotPropInfo
|
22
|
+
from instaui.js.fn import JsFn
|
20
23
|
|
21
24
|
|
22
25
|
class Scope(Jsonable):
|
@@ -26,33 +29,38 @@ class Scope(Jsonable):
|
|
26
29
|
self._vars_id_counter = 0
|
27
30
|
self._element_ref_id_counter = 0
|
28
31
|
self._refs: List[VarMixin] = []
|
32
|
+
self._element_refs: List[ElementRef] = []
|
29
33
|
self._const_data: List[ConstData] = []
|
30
34
|
self._js_computeds: List[JsComputed] = []
|
31
35
|
self._vue_computeds: List[VueComputed] = []
|
32
36
|
self._web_computeds: List[WebComputed] = []
|
33
|
-
self._element_refs: List[ElementRef] = []
|
34
37
|
self._run_method_records: List = []
|
35
|
-
self.
|
36
|
-
self.
|
37
|
-
self.
|
38
|
+
self._web_watch_configs: List[Dict] = []
|
39
|
+
self._js_watch_configs: List[Dict] = []
|
40
|
+
self._vue_watch_configs: List[Dict] = []
|
41
|
+
self._vfor_item: Optional[VForItem] = None
|
42
|
+
self._vfor_item_key: Optional[VForItemKey] = None
|
43
|
+
self._vfor_index: Optional[VForIndex] = None
|
44
|
+
self._slot_prop_info: Optional[SlotPropInfo] = None
|
45
|
+
self._js_fns: List[JsFn] = []
|
38
46
|
self._query = {}
|
47
|
+
self.__has_registered_task = False
|
48
|
+
|
49
|
+
def _mark_has_registered_task(self):
|
50
|
+
self.__has_registered_task = True
|
39
51
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
52
|
+
@property
|
53
|
+
def has_var(self):
|
54
|
+
return self._vars_id_counter > 0
|
55
|
+
|
56
|
+
@property
|
57
|
+
def has_registered_task(self):
|
58
|
+
return self.__has_registered_task
|
44
59
|
|
45
60
|
def generate_vars_id(self) -> str:
|
46
61
|
self._vars_id_counter += 1
|
47
62
|
return str(self._vars_id_counter)
|
48
63
|
|
49
|
-
def generate_element_ref_id(self) -> str:
|
50
|
-
self._element_ref_id_counter += 1
|
51
|
-
return str(self._element_ref_id_counter)
|
52
|
-
|
53
|
-
def register_element_ref(self, ref: ElementRef):
|
54
|
-
self._element_refs.append(ref)
|
55
|
-
|
56
64
|
def set_query(self, url: str, key: str, on: List[CanInputMixin]) -> None:
|
57
65
|
self._query = {
|
58
66
|
"url": url,
|
@@ -61,13 +69,16 @@ class Scope(Jsonable):
|
|
61
69
|
}
|
62
70
|
|
63
71
|
def register_web_watch(self, watch: WebWatch) -> None:
|
64
|
-
self.
|
72
|
+
self._mark_has_registered_task()
|
73
|
+
self._web_watch_configs.append(watch._to_json_dict())
|
65
74
|
|
66
75
|
def register_js_watch(self, watch: JsWatch) -> None:
|
67
|
-
self.
|
76
|
+
self._mark_has_registered_task()
|
77
|
+
self._js_watch_configs.append(watch._to_json_dict())
|
68
78
|
|
69
79
|
def register_vue_watch(self, watch: VueWatch) -> None:
|
70
|
-
self.
|
80
|
+
self._mark_has_registered_task()
|
81
|
+
self._vue_watch_configs.append(watch._to_json_dict())
|
71
82
|
|
72
83
|
def register_data_task(self, data: ConstData):
|
73
84
|
weak_obj = weakref.ref(data)
|
@@ -76,7 +87,7 @@ class Scope(Jsonable):
|
|
76
87
|
self._const_data.append(weak_obj()) # type: ignore
|
77
88
|
return self.generate_vars_id()
|
78
89
|
|
79
|
-
return
|
90
|
+
return VarRegisterTaskForScope(self, register_fn)
|
80
91
|
|
81
92
|
def register_ref_task(self, ref: VarMixin):
|
82
93
|
weak_obj = weakref.ref(ref)
|
@@ -85,7 +96,52 @@ class Scope(Jsonable):
|
|
85
96
|
self._refs.append(weak_obj()) # type: ignore
|
86
97
|
return self.generate_vars_id()
|
87
98
|
|
88
|
-
return
|
99
|
+
return VarRegisterTaskForScope(self, register_fn)
|
100
|
+
|
101
|
+
def register_element_ref_task(self, target: ElementRef):
|
102
|
+
weak_obj = weakref.ref(target)
|
103
|
+
|
104
|
+
def register_fn():
|
105
|
+
self._element_refs.append(weak_obj()) # type: ignore
|
106
|
+
return self.generate_vars_id()
|
107
|
+
|
108
|
+
return VarRegisterTaskForScope(self, register_fn)
|
109
|
+
|
110
|
+
def register_vfor_item_task(self, vfor_item: VForItem):
|
111
|
+
weak_obj = weakref.ref(vfor_item)
|
112
|
+
|
113
|
+
def register_fn():
|
114
|
+
self._vfor_item = weak_obj()
|
115
|
+
return self.generate_vars_id()
|
116
|
+
|
117
|
+
return VarRegisterTaskForScope(self, register_fn)
|
118
|
+
|
119
|
+
def register_slot_prop_info_task(self, slot_prop_info: SlotPropInfo):
|
120
|
+
weak_obj = weakref.ref(slot_prop_info)
|
121
|
+
|
122
|
+
def register_fn():
|
123
|
+
self._slot_prop_info = weak_obj()
|
124
|
+
return self.generate_vars_id()
|
125
|
+
|
126
|
+
return VarRegisterTaskForScope(self, register_fn)
|
127
|
+
|
128
|
+
def register_vfor_index_task(self, vfor_index: VForIndex):
|
129
|
+
weak_obj = weakref.ref(vfor_index)
|
130
|
+
|
131
|
+
def register_fn():
|
132
|
+
self._vfor_index = weak_obj()
|
133
|
+
return self.generate_vars_id()
|
134
|
+
|
135
|
+
return VarRegisterTaskForScope(self, register_fn)
|
136
|
+
|
137
|
+
def register_vfor_key_task(self, vfor_key: VForItemKey):
|
138
|
+
weak_obj = weakref.ref(vfor_key)
|
139
|
+
|
140
|
+
def register_fn():
|
141
|
+
self._vfor_item_key = weak_obj()
|
142
|
+
return self.generate_vars_id()
|
143
|
+
|
144
|
+
return VarRegisterTaskForScope(self, register_fn)
|
89
145
|
|
90
146
|
def register_js_computed_task(self, computed: JsComputed):
|
91
147
|
weak_obj = weakref.ref(computed)
|
@@ -94,7 +150,7 @@ class Scope(Jsonable):
|
|
94
150
|
self._js_computeds.append(weak_obj()) # type: ignore
|
95
151
|
return self.generate_vars_id()
|
96
152
|
|
97
|
-
return
|
153
|
+
return VarRegisterTaskForScope(self, register_fn)
|
98
154
|
|
99
155
|
def register_computed_task(self, computed: WebComputed):
|
100
156
|
weak_obj = weakref.ref(computed)
|
@@ -103,7 +159,7 @@ class Scope(Jsonable):
|
|
103
159
|
self._web_computeds.append(weak_obj()) # type: ignore
|
104
160
|
return self.generate_vars_id()
|
105
161
|
|
106
|
-
return
|
162
|
+
return VarRegisterTaskForScope(self, register_fn)
|
107
163
|
|
108
164
|
def register_vue_computed_task(self, computed: VueComputed):
|
109
165
|
weak_obj = weakref.ref(computed)
|
@@ -112,7 +168,16 @@ class Scope(Jsonable):
|
|
112
168
|
self._vue_computeds.append(weak_obj()) # type: ignore
|
113
169
|
return self.generate_vars_id()
|
114
170
|
|
115
|
-
return
|
171
|
+
return VarRegisterTaskForScope(self, register_fn)
|
172
|
+
|
173
|
+
def register_js_fn_task(self, fn: JsFn):
|
174
|
+
weak_obj = weakref.ref(fn)
|
175
|
+
|
176
|
+
def register_fn():
|
177
|
+
self._js_fns.append(weak_obj()) # type: ignore
|
178
|
+
return self.generate_vars_id()
|
179
|
+
|
180
|
+
return VarRegisterTaskForScope(self, register_fn)
|
116
181
|
|
117
182
|
def _to_json_dict(self):
|
118
183
|
data = super()._to_json_dict()
|
@@ -120,12 +185,12 @@ class Scope(Jsonable):
|
|
120
185
|
data["refs"] = self._refs
|
121
186
|
if self._query:
|
122
187
|
data["query"] = self._query
|
123
|
-
if self.
|
124
|
-
data["py_watch"] = self.
|
125
|
-
if self.
|
126
|
-
data["js_watch"] = self.
|
127
|
-
if self.
|
128
|
-
data["vue_watch"] = self.
|
188
|
+
if self._web_watch_configs:
|
189
|
+
data["py_watch"] = self._web_watch_configs
|
190
|
+
if self._js_watch_configs:
|
191
|
+
data["js_watch"] = self._js_watch_configs
|
192
|
+
if self._vue_watch_configs:
|
193
|
+
data["vue_watch"] = self._vue_watch_configs
|
129
194
|
if self._element_refs:
|
130
195
|
data["eRefs"] = self._element_refs
|
131
196
|
|
@@ -140,6 +205,24 @@ class Scope(Jsonable):
|
|
140
205
|
if self._const_data:
|
141
206
|
data["data"] = self._const_data
|
142
207
|
|
208
|
+
if self._js_fns:
|
209
|
+
data["jsFn"] = self._js_fns
|
210
|
+
|
211
|
+
# vfor info
|
212
|
+
vfor_dict = {}
|
213
|
+
if self._vfor_item:
|
214
|
+
vfor_dict[self._vfor_item.SCOPE_TYPE] = self._vfor_item
|
215
|
+
if self._vfor_index:
|
216
|
+
vfor_dict[self._vfor_index.SCOPE_TYPE] = self._vfor_index
|
217
|
+
if self._vfor_item_key:
|
218
|
+
vfor_dict[self._vfor_item_key.SCOPE_TYPE] = self._vfor_item_key
|
219
|
+
|
220
|
+
if vfor_dict:
|
221
|
+
data["vfor"] = vfor_dict
|
222
|
+
|
223
|
+
if self._slot_prop_info:
|
224
|
+
data["sp"] = self._slot_prop_info._to_json_dict()
|
225
|
+
|
143
226
|
return data
|
144
227
|
|
145
228
|
|
@@ -169,9 +252,10 @@ class GlobalScope(Scope):
|
|
169
252
|
raise ValueError("Can not register vue_watchs in global scope")
|
170
253
|
|
171
254
|
|
172
|
-
class
|
173
|
-
def __init__(self,
|
174
|
-
|
255
|
+
class VarRegisterTaskForScope:
|
256
|
+
def __init__(self, scope: Scope, register_fn: Callable[[], str]) -> None:
|
257
|
+
scope._mark_has_registered_task()
|
258
|
+
self._scope_id = scope.id
|
175
259
|
self._id_gen_fn = functools.lru_cache(maxsize=1)(register_fn)
|
176
260
|
|
177
261
|
@property
|
instaui/spa_router/_functions.py
CHANGED
@@ -2,7 +2,7 @@ import typing
|
|
2
2
|
from . import _types
|
3
3
|
from instaui.runtime._app import get_app_slot
|
4
4
|
from . import _install
|
5
|
-
from ._router_param_var import
|
5
|
+
from ._router_param_var import RouteParamsVar
|
6
6
|
from ._router_output import RouterOutput, RouterMethod
|
7
7
|
from ._route_model import RouteItem
|
8
8
|
|
@@ -64,15 +64,15 @@ def config_router(
|
|
64
64
|
|
65
65
|
|
66
66
|
def get_params(param_name: str) -> typing.Any:
|
67
|
-
return
|
67
|
+
return RouteParamsVar("params")[param_name]
|
68
68
|
|
69
69
|
|
70
70
|
def get_path():
|
71
|
-
return
|
71
|
+
return RouteParamsVar("path")
|
72
72
|
|
73
73
|
|
74
74
|
def get_full_path():
|
75
|
-
return
|
75
|
+
return RouteParamsVar("fullPath")
|
76
76
|
|
77
77
|
|
78
78
|
def push(
|
@@ -3,7 +3,7 @@ import typing
|
|
3
3
|
from pydantic import BaseModel, Field, ConfigDict, field_serializer, model_serializer
|
4
4
|
|
5
5
|
from instaui.components.html.div import Div
|
6
|
-
from instaui.runtime._app import get_app_slot,
|
6
|
+
from instaui.runtime._app import get_app_slot, get_current_scope
|
7
7
|
from instaui.components.component import Component
|
8
8
|
from instaui.common.jsonable import dumps2dict
|
9
9
|
|
@@ -14,7 +14,7 @@ class RouteItem(BaseModel):
|
|
14
14
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
15
15
|
|
16
16
|
component_fn: typing.Optional[typing.Callable] = Field(exclude=True)
|
17
|
-
|
17
|
+
sid: typing.Optional[str] = None
|
18
18
|
vue_route_item: VueRouteItem = Field(serialization_alias="vueItem")
|
19
19
|
meta: typing.Optional[typing.Dict] = None
|
20
20
|
|
@@ -32,17 +32,16 @@ class RouteItem(BaseModel):
|
|
32
32
|
self.vue_route_item.path = f"/{'' if self.component_fn.__name__ == 'index' else self.component_fn.__name__}"
|
33
33
|
|
34
34
|
app = get_app_slot()
|
35
|
-
with
|
36
|
-
|
37
|
-
|
35
|
+
with Div() as div:
|
36
|
+
self.component_fn()
|
37
|
+
scope_id = get_current_scope().id
|
38
38
|
|
39
39
|
app.items.pop()
|
40
40
|
|
41
|
-
self.scopeId = scope.id
|
42
41
|
self.vue_route_item.component = div._slot_manager.default._children
|
43
42
|
|
44
43
|
return {
|
45
|
-
"
|
44
|
+
"sid": scope_id,
|
46
45
|
"vueItem": self.vue_route_item,
|
47
46
|
}
|
48
47
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from typing import List, Optional
|
2
2
|
from instaui.common.jsonable import Jsonable
|
3
|
+
from instaui.vars._types import OutputSetType
|
3
4
|
from instaui.vars.mixin_types.py_binding import CanOutputMixin
|
4
5
|
from pydantic import BaseModel
|
5
6
|
|
@@ -9,13 +10,16 @@ class RouterOutput(Jsonable, CanOutputMixin):
|
|
9
10
|
self.type = "routeAct"
|
10
11
|
|
11
12
|
def _to_output_config(self):
|
12
|
-
return
|
13
|
+
return {}
|
13
14
|
|
14
15
|
def _to_json_dict(self):
|
15
16
|
data = super()._to_json_dict()
|
16
17
|
|
17
18
|
return data
|
18
19
|
|
20
|
+
def _to_event_output_type(self) -> OutputSetType:
|
21
|
+
return OutputSetType.RouterAction
|
22
|
+
|
19
23
|
|
20
24
|
class RouterMethod(BaseModel):
|
21
25
|
fn: str
|
@@ -10,7 +10,7 @@ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
|
|
10
10
|
from instaui.vars.mixin_types.pathable import CanPathPropMixin
|
11
11
|
|
12
12
|
|
13
|
-
class
|
13
|
+
class RouteParamsVar(
|
14
14
|
Jsonable,
|
15
15
|
PathVar,
|
16
16
|
ObservableMixin,
|
@@ -18,7 +18,7 @@ class RouterParamsVar(
|
|
18
18
|
StrFormatBindingMixin,
|
19
19
|
ElementBindingMixin,
|
20
20
|
):
|
21
|
-
VAR_TYPE = "
|
21
|
+
VAR_TYPE = "rp"
|
22
22
|
|
23
23
|
def __init__(
|
24
24
|
self,
|
@@ -28,7 +28,7 @@ class RouterParamsVar(
|
|
28
28
|
self._prop = prop
|
29
29
|
|
30
30
|
def __to_binding_config(self):
|
31
|
-
return self.
|
31
|
+
return {"type": "rp", "prop": self._prop}
|
32
32
|
|
33
33
|
def _to_pathable_binding_config(self) -> typing.Dict:
|
34
34
|
return self.__to_binding_config()
|
@@ -43,9 +43,4 @@ class RouterParamsVar(
|
|
43
43
|
return self.__to_binding_config()
|
44
44
|
|
45
45
|
def _to_json_dict(self):
|
46
|
-
|
47
|
-
data["type"] = self.VAR_TYPE
|
48
|
-
|
49
|
-
if self._prop != "params":
|
50
|
-
data["prop"] = self._prop
|
51
|
-
return data
|
46
|
+
raise NotImplementedError("RouteParamsVar is not json serializable")
|
instaui/static/insta-ui.css
CHANGED
@@ -1 +1 @@
|
|
1
|
-
:root{color-scheme:light dark}:where(body){--insta-column-gap: 1rem;height:100vh}:where(*){box-sizing:border-box;margin:0;padding:0}:where(#app){height:100%}:where(.app-box,.insta-main){height:100%;overflow-y:auto}:where(.insta-main){--insta-padding: 16px;padding:var(--insta-padding, 16px)}
|
1
|
+
.insta-themes:where([data-scaling="90%"]){--scaling: .9 }.insta-themes:where([data-scaling="95%"]){--scaling: .95 }.insta-themes:where([data-scaling="100%"]){--scaling: 1 }.insta-themes:where([data-scaling="105%"]){--scaling: 1.05 }.insta-themes:where([data-scaling="110%"]){--scaling: 1.1 }.insta-themes{--space-1: calc(4px* var(--scaling));--space-2: calc(8px* var(--scaling));--space-3: calc(12px* var(--scaling));--space-4: calc(16px* var(--scaling));--space-5: calc(24px* var(--scaling));--space-6: calc(32px* var(--scaling));--space-7: calc(40px* var(--scaling));--space-8: calc(48px* var(--scaling));--space-9: calc(64px* var(--scaling));--font-size-1: calc(12px* var(--scaling));--font-size-2: calc(14px* var(--scaling));--font-size-3: calc(16px* var(--scaling));--font-size-4: calc(18px* var(--scaling));--font-size-5: calc(20px* var(--scaling));--font-size-6: calc(24px* var(--scaling));--font-size-7: calc(28px* var(--scaling));--font-size-8: calc(35px* var(--scaling));--font-size-9: calc(60px* var(--scaling));--font-weight-light: 300;--font-weight-regular: 400;--font-weight-medium: 500;--font-weight-bold: 700;--line-height-1: calc(16px* var(--scaling));--line-height-2: calc(20px* var(--scaling));--line-height-3: calc(24px* var(--scaling));--line-height-4: calc(26px* var(--scaling));--line-height-5: calc(28px* var(--scaling));--line-height-6: calc(30px* var(--scaling));--line-height-7: calc(36px* var(--scaling));--line-height-8: calc(40px* var(--scaling));--line-height-9: calc(60px* var(--scaling));--letter-spacing-1: .0025em;--letter-spacing-2: 0em;--letter-spacing-3: 0em;--letter-spacing-4: -.0025em;--letter-spacing-5: -.005em;--letter-spacing-6: -.00625em;--letter-spacing-7: -.0075em;--letter-spacing-8: -.01em;--letter-spacing-9: -.025em;--default-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI (Custom)", Roboto, "Helvetica Neue", "Open Sans (Custom)", system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";--default-font-size: var(--font-size-3);--default-font-style: normal;--default-font-weight: var(--font-weight-regular);--default-line-height: 1.5;--default-letter-spacing: 0em;--default-leading-trim-start: .42em;--default-leading-trim-end: .36em;--heading-font-family: var(--default-font-family);--heading-font-size-adjust: 1;--heading-font-style: normal;--heading-leading-trim-start: var(--default-leading-trim-start);--heading-leading-trim-end: var(--default-leading-trim-end);--heading-letter-spacing: 0em;--heading-line-height-1: calc(16px* var(--scaling));--heading-line-height-2: calc(18px* var(--scaling));--heading-line-height-3: calc(22px* var(--scaling));--heading-line-height-4: calc(24px* var(--scaling));--heading-line-height-5: calc(26px* var(--scaling));--heading-line-height-6: calc(30px* var(--scaling));--heading-line-height-7: calc(36px* var(--scaling));--heading-line-height-8: calc(40px* var(--scaling));--heading-line-height-9: calc(60px* var(--scaling));--strong-font-family: var(--default-font-family);--strong-font-size-adjust: 1;--strong-font-style: inherit;--strong-font-weight: var(--font-weight-bold);--strong-letter-spacing: 0em;--em-font-family: "Times New Roman", "Times", serif;--em-font-size-adjust: 1.18;--em-font-style: italic;--em-font-weight: inherit;--em-letter-spacing: -.025em;overflow-wrap:break-word;font-family:var(--default-font-family);font-size:var(--default-font-size);font-weight:var(--default-font-weight);font-style:var(--default-font-style);line-height:var(--default-line-height);letter-spacing:var(--default-letter-spacing);-webkit-text-size-adjust:none;-moz-text-size-adjust:none;text-size-adjust:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;--container-1: 448px;--container-2: 688px;--container-3: 880px;--container-4: 1136px}.i-weight-light{font-weight:var(--font-weight-light)}.i-weight-regular{font-weight:var(--font-weight-regular)}.i-weight-medium{font-weight:var(--font-weight-medium)}.i-weight-bold{font-weight:var(--font-weight-bold)}.i-text-align-left{text-align:left}.i-text-align-center{text-align:center}.i-text-align-right{text-align:right}.insta-Heading:where(.i-size-1){font-size:calc(var(--font-size-1) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-1);letter-spacing:calc(var(-letter-spacing-1) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-2){font-size:calc(var(--font-size-2) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-2);letter-spacing:calc(var(-letter-spacing-2) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-3){font-size:calc(var(--font-size-3) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-3);letter-spacing:calc(var(-letter-spacing-3) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-4){font-size:calc(var(--font-size-4) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-4);letter-spacing:calc(var(-letter-spacing-4) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-5){font-size:calc(var(--font-size-5) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-5);letter-spacing:calc(var(-letter-spacing-5) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-6){font-size:calc(var(--font-size-6) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-6);letter-spacing:calc(var(-letter-spacing-6) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-7){font-size:calc(var(--font-size-7) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-7);letter-spacing:calc(var(-letter-spacing-7) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-8){font-size:calc(var(--font-size-8) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-8);letter-spacing:calc(var(-letter-spacing-8) + var(--heading-letter-spacing))}.insta-Heading:where(.i-size-9){font-size:calc(var(--font-size-9) * var(--heading-font-size-adjust));--line-height: var(--heading-line-height-9);letter-spacing:calc(var(-letter-spacing-9) + var(--heading-letter-spacing))}:root{color-scheme:light dark}:where(body){--insta-column-gap: 1rem;height:100vh}:where(*){box-sizing:border-box;margin:0;padding:0}:where(#app){height:100%}:where(.app-box,.insta-main){height:100%;overflow-y:auto}:where(.insta-main){--insta-padding: 16px;padding:var(--insta-padding, 16px)}
|