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.
- instaui/__init__.py +9 -0
- instaui/_helper/observable_helper.py +35 -0
- instaui/boot_info.py +43 -0
- instaui/common/jsonable.py +37 -0
- instaui/components/__init__.py +0 -0
- instaui/components/column.py +18 -0
- instaui/components/component.py +47 -0
- instaui/components/content.py +34 -0
- instaui/components/directive.py +55 -0
- instaui/components/element.py +462 -0
- instaui/components/grid.py +80 -0
- instaui/components/html/__init__.py +36 -0
- instaui/components/html/_mixins.py +34 -0
- instaui/components/html/button.py +38 -0
- instaui/components/html/checkbox.py +42 -0
- instaui/components/html/date.py +28 -0
- instaui/components/html/div.py +7 -0
- instaui/components/html/form.py +7 -0
- instaui/components/html/input.py +28 -0
- instaui/components/html/label.py +21 -0
- instaui/components/html/li.py +17 -0
- instaui/components/html/link.py +31 -0
- instaui/components/html/number.py +34 -0
- instaui/components/html/paragraph.py +19 -0
- instaui/components/html/range.py +45 -0
- instaui/components/html/select.py +93 -0
- instaui/components/html/span.py +19 -0
- instaui/components/html/ul.py +20 -0
- instaui/components/match.py +106 -0
- instaui/components/row.py +19 -0
- instaui/components/slot.py +82 -0
- instaui/components/transition_group.py +9 -0
- instaui/components/value_element.py +48 -0
- instaui/components/vfor.py +140 -0
- instaui/components/vif.py +38 -0
- instaui/consts.py +18 -0
- instaui/dependencies/__init__.py +15 -0
- instaui/dependencies/component_registrar.py +82 -0
- instaui/dependencies/installer.py +5 -0
- instaui/event/event_mixin.py +12 -0
- instaui/event/js_event.py +57 -0
- instaui/event/web_event.py +108 -0
- instaui/experimental/__init__.py +4 -0
- instaui/experimental/debug.py +48 -0
- instaui/fastapi_server/_utils.py +42 -0
- instaui/fastapi_server/_uvicorn.py +37 -0
- instaui/fastapi_server/config_router.py +60 -0
- instaui/fastapi_server/debug_mode_router.py +61 -0
- instaui/fastapi_server/event_router.py +58 -0
- instaui/fastapi_server/middlewares.py +19 -0
- instaui/fastapi_server/request_context.py +19 -0
- instaui/fastapi_server/server.py +246 -0
- instaui/fastapi_server/watch_router.py +53 -0
- instaui/handlers/_utils.py +66 -0
- instaui/handlers/computed_handler.py +42 -0
- instaui/handlers/config_handler.py +13 -0
- instaui/handlers/event_handler.py +58 -0
- instaui/handlers/watch_handler.py +57 -0
- instaui/html_tools.py +139 -0
- instaui/inject.py +33 -0
- instaui/js/__init__.py +4 -0
- instaui/js/js_output.py +15 -0
- instaui/js/lambda_func.py +35 -0
- instaui/launch_collector.py +52 -0
- instaui/page_info.py +23 -0
- instaui/runtime/__init__.py +29 -0
- instaui/runtime/_app.py +206 -0
- instaui/runtime/_inner_helper.py +9 -0
- instaui/runtime/context.py +47 -0
- instaui/runtime/dataclass.py +30 -0
- instaui/runtime/resource.py +87 -0
- instaui/runtime/scope.py +107 -0
- instaui/runtime/ui_state_scope.py +15 -0
- instaui/settings/__init__.py +4 -0
- instaui/settings/__settings.py +13 -0
- instaui/skip.py +12 -0
- instaui/spa_router/__init__.py +26 -0
- instaui/spa_router/_components.py +35 -0
- instaui/spa_router/_file_base_utils.py +264 -0
- instaui/spa_router/_functions.py +122 -0
- instaui/spa_router/_install.py +11 -0
- instaui/spa_router/_route_model.py +139 -0
- instaui/spa_router/_router_box.py +40 -0
- instaui/spa_router/_router_output.py +22 -0
- instaui/spa_router/_router_param_var.py +51 -0
- instaui/spa_router/_types.py +4 -0
- instaui/spa_router/templates/page_routes +59 -0
- instaui/static/insta-ui.css +1 -0
- instaui/static/insta-ui.esm-browser.prod.js +3663 -0
- instaui/static/insta-ui.iife.js +29 -0
- instaui/static/insta-ui.iife.js.map +1 -0
- instaui/static/insta-ui.js.map +1 -0
- instaui/static/tailwindcss.min.js +62 -0
- instaui/static/templates/debug/sse.html +117 -0
- instaui/static/templates/web.html +118 -0
- instaui/static/templates/zero.html +55 -0
- instaui/static/vue.esm-browser.prod.js +9 -0
- instaui/static/vue.global.prod.js +9 -0
- instaui/static/vue.runtime.esm-browser.prod.js +5 -0
- instaui/systems/file_system.py +17 -0
- instaui/systems/func_system.py +104 -0
- instaui/systems/js_system.py +22 -0
- instaui/systems/pydantic_system.py +27 -0
- instaui/systems/string_system.py +10 -0
- instaui/template/__init__.py +4 -0
- instaui/template/env.py +7 -0
- instaui/template/web_template.py +55 -0
- instaui/template/zero_template.py +24 -0
- instaui/ui/__init__.py +121 -0
- instaui/ui/events.py +25 -0
- instaui/ui_functions/input_slient_data.py +16 -0
- instaui/ui_functions/server.py +13 -0
- instaui/ui_functions/str_format.py +36 -0
- instaui/ui_functions/ui_page.py +31 -0
- instaui/ui_functions/ui_types.py +13 -0
- instaui/ui_functions/url_location.py +33 -0
- instaui/vars/__init__.py +13 -0
- instaui/vars/_types.py +8 -0
- instaui/vars/_utils.py +12 -0
- instaui/vars/data.py +68 -0
- instaui/vars/element_ref.py +42 -0
- instaui/vars/event_context.py +45 -0
- instaui/vars/event_extend.py +0 -0
- instaui/vars/js_computed.py +95 -0
- instaui/vars/mixin_types/common_type.py +5 -0
- instaui/vars/mixin_types/element_binding.py +10 -0
- instaui/vars/mixin_types/observable.py +7 -0
- instaui/vars/mixin_types/pathable.py +14 -0
- instaui/vars/mixin_types/py_binding.py +13 -0
- instaui/vars/mixin_types/str_format_binding.py +8 -0
- instaui/vars/mixin_types/var_type.py +5 -0
- instaui/vars/path_var.py +89 -0
- instaui/vars/ref.py +103 -0
- instaui/vars/slot_prop.py +46 -0
- instaui/vars/state.py +82 -0
- instaui/vars/types.py +24 -0
- instaui/vars/vfor_item.py +204 -0
- instaui/vars/vue_computed.py +82 -0
- instaui/vars/web_computed.py +157 -0
- instaui/vars/web_view_computed.py +1 -0
- instaui/version.py +3 -0
- instaui/watch/_types.py +4 -0
- instaui/watch/_utils.py +3 -0
- instaui/watch/js_watch.py +74 -0
- instaui/watch/vue_watch.py +61 -0
- instaui/watch/web_watch.py +123 -0
- instaui/zero/__init__.py +3 -0
- instaui/zero/scope.py +9 -0
- instaui-0.1.0.dist-info/LICENSE +21 -0
- instaui-0.1.0.dist-info/METADATA +154 -0
- instaui-0.1.0.dist-info/RECORD +152 -0
- instaui-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
import typing
|
3
|
+
from pydantic import BaseModel, Field, ConfigDict, field_serializer, model_serializer
|
4
|
+
|
5
|
+
from instaui.components.html.div import Div
|
6
|
+
from instaui.runtime._app import get_app_slot, new_scope
|
7
|
+
from instaui.components.component import Component
|
8
|
+
from instaui.runtime.scope import Scope
|
9
|
+
from instaui.common.jsonable import dumps2dict
|
10
|
+
|
11
|
+
from . import _types
|
12
|
+
|
13
|
+
|
14
|
+
class RouteItem(BaseModel):
|
15
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
16
|
+
|
17
|
+
component_fn: typing.Optional[typing.Callable] = Field(exclude=True)
|
18
|
+
scope: typing.Optional[Scope] = None
|
19
|
+
vue_route_item: VueRouteItem = Field(serialization_alias="vueItem")
|
20
|
+
|
21
|
+
# def model_post_init(self, __context: typing.Any) -> None:
|
22
|
+
# if self.component_fn is None and (not self.vue_route_item.path):
|
23
|
+
# raise ValueError("Either component_fn or vue_route_item.path must be set")
|
24
|
+
|
25
|
+
# if self.component_fn is None:
|
26
|
+
# return None
|
27
|
+
|
28
|
+
# if self.vue_route_item.path is None:
|
29
|
+
# self.vue_route_item.path = f"/{'' if self.component_fn.__name__=='index' else self.component_fn.__name__}"
|
30
|
+
|
31
|
+
# app = get_app_slot()
|
32
|
+
|
33
|
+
# with new_scope(append_to_app=False) as scope:
|
34
|
+
# with Div() as div:
|
35
|
+
# self.component_fn()
|
36
|
+
|
37
|
+
# app.items.pop()
|
38
|
+
|
39
|
+
# self.scope = scope
|
40
|
+
# self.vue_route_item.component = div._slot_manager.default._children
|
41
|
+
|
42
|
+
# @field_serializer("scope")
|
43
|
+
# def serialize_scope(self, value: Scope):
|
44
|
+
# return dumps2dict(value)
|
45
|
+
|
46
|
+
@model_serializer
|
47
|
+
def model_ser(self):
|
48
|
+
if self.component_fn is None and (not self.vue_route_item.path):
|
49
|
+
raise ValueError("Either component_fn or vue_route_item.path must be set")
|
50
|
+
|
51
|
+
if self.component_fn is None:
|
52
|
+
return {
|
53
|
+
"vueItem": self.vue_route_item,
|
54
|
+
}
|
55
|
+
|
56
|
+
if self.vue_route_item.path is None:
|
57
|
+
self.vue_route_item.path = f"/{'' if self.component_fn.__name__=='index' else self.component_fn.__name__}"
|
58
|
+
|
59
|
+
app = get_app_slot()
|
60
|
+
with new_scope(append_to_app=False) as scope:
|
61
|
+
with Div() as div:
|
62
|
+
self.component_fn()
|
63
|
+
|
64
|
+
app.items.pop()
|
65
|
+
|
66
|
+
self.scope = scope
|
67
|
+
self.vue_route_item.component = div._slot_manager.default._children
|
68
|
+
|
69
|
+
return {
|
70
|
+
"scope": dumps2dict(scope),
|
71
|
+
"vueItem": self.vue_route_item,
|
72
|
+
}
|
73
|
+
|
74
|
+
@classmethod
|
75
|
+
def create(
|
76
|
+
cls,
|
77
|
+
*,
|
78
|
+
component_fn: typing.Optional[typing.Callable] = None,
|
79
|
+
path: typing.Optional[str] = None,
|
80
|
+
name: typing.Optional[str] = None,
|
81
|
+
params: typing.Optional[typing.Dict[str, str]] = None,
|
82
|
+
children: typing.Optional[typing.List[RouteItem]] = None,
|
83
|
+
):
|
84
|
+
"""Create a new RouteItem
|
85
|
+
|
86
|
+
Example:
|
87
|
+
.. code-block:: python
|
88
|
+
routes = [
|
89
|
+
spa_router.RouteItem.create(path='/',component_fn=home),
|
90
|
+
spa_router.RouteItem.create(path='/user',component_fn=user_home),
|
91
|
+
]
|
92
|
+
|
93
|
+
spa_router.config_router(routes=routes)
|
94
|
+
|
95
|
+
Args:
|
96
|
+
component_fn (typing.Callable): function that returns a component to be rendered.
|
97
|
+
path (typing.Optional[str], optional): route path. Defaults to None.
|
98
|
+
name (typing.Optional[str], optional): route name. Defaults to None.
|
99
|
+
params (typing.Optional[typing.Dict[str, str]], optional): route params. Defaults to None.
|
100
|
+
children (typing.Optional[typing.List[RouteItem]], optional): child routes. Defaults to None.
|
101
|
+
|
102
|
+
"""
|
103
|
+
|
104
|
+
return cls(
|
105
|
+
component_fn=component_fn,
|
106
|
+
vue_route_item=VueRouteItem(
|
107
|
+
path=path,
|
108
|
+
name=name,
|
109
|
+
params=params,
|
110
|
+
component=[],
|
111
|
+
children=children,
|
112
|
+
),
|
113
|
+
)
|
114
|
+
|
115
|
+
|
116
|
+
class VueRouteItem(BaseModel):
|
117
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
118
|
+
|
119
|
+
path: typing.Optional[str] = None
|
120
|
+
params: typing.Optional[typing.Dict[str, str]] = None
|
121
|
+
name: typing.Optional[str] = None
|
122
|
+
component: typing.Optional[typing.List[Component]] = []
|
123
|
+
children: typing.Optional[typing.List[RouteItem]] = None
|
124
|
+
|
125
|
+
@field_serializer("component")
|
126
|
+
def serialize_component(self, value: typing.List[Component]):
|
127
|
+
if not value:
|
128
|
+
return []
|
129
|
+
return dumps2dict(value)
|
130
|
+
|
131
|
+
|
132
|
+
class RouteCollector(BaseModel):
|
133
|
+
mode: _types.TRouterHistoryMode = "hash"
|
134
|
+
keep_alive: bool = Field(default=False, serialization_alias="kAlive")
|
135
|
+
routes: typing.List[RouteItem] = []
|
136
|
+
|
137
|
+
def add_route(self, item: RouteItem):
|
138
|
+
self.routes.append(item)
|
139
|
+
return self
|
@@ -0,0 +1,40 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import Dict, List
|
3
|
+
from instaui.common.jsonable import Jsonable
|
4
|
+
from instaui.components.component import Component
|
5
|
+
from instaui.runtime.scope import Scope
|
6
|
+
|
7
|
+
from . import _types
|
8
|
+
from ._route_model import RouteCollector
|
9
|
+
|
10
|
+
|
11
|
+
class RouterBox_(Jsonable):
|
12
|
+
def __init__(self):
|
13
|
+
self._mode: _types.TRouterHistoryMode = "web"
|
14
|
+
self._keep_alive: bool = False
|
15
|
+
self._component_map: Dict[str, Dict] = {}
|
16
|
+
self._route_collector: RouteCollector = RouteCollector()
|
17
|
+
|
18
|
+
def add_component(
|
19
|
+
self,
|
20
|
+
path: str,
|
21
|
+
components: List[Component],
|
22
|
+
scope: Scope,
|
23
|
+
lazy_loading: bool = False,
|
24
|
+
):
|
25
|
+
config = {"items": components, "scope": scope}
|
26
|
+
if lazy_loading:
|
27
|
+
config["lazy"] = True
|
28
|
+
|
29
|
+
self._component_map[path] = config
|
30
|
+
|
31
|
+
def _to_json_dict(self):
|
32
|
+
data = {}
|
33
|
+
|
34
|
+
data["routes"] = self._route_collector.model_dump(exclude_none=True)["routes"]
|
35
|
+
data["mode"] = self._mode
|
36
|
+
|
37
|
+
if self._keep_alive is not False:
|
38
|
+
data["kAlive"] = self._keep_alive
|
39
|
+
|
40
|
+
return data
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from typing import List, Optional
|
2
|
+
from instaui.common.jsonable import Jsonable
|
3
|
+
from instaui.vars.mixin_types.py_binding import CanOutputMixin
|
4
|
+
from pydantic import BaseModel
|
5
|
+
|
6
|
+
|
7
|
+
class RouterOutput(Jsonable, CanOutputMixin):
|
8
|
+
def __init__(self):
|
9
|
+
self.type = "routeAct"
|
10
|
+
|
11
|
+
def _to_output_config(self):
|
12
|
+
return self._to_json_dict()
|
13
|
+
|
14
|
+
def _to_json_dict(self):
|
15
|
+
data = super()._to_json_dict()
|
16
|
+
|
17
|
+
return data
|
18
|
+
|
19
|
+
|
20
|
+
class RouterMethod(BaseModel):
|
21
|
+
fn: str
|
22
|
+
args: Optional[List]
|
@@ -0,0 +1,51 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
import typing
|
3
|
+
|
4
|
+
from instaui.common.jsonable import Jsonable
|
5
|
+
from instaui.vars.path_var import PathVar
|
6
|
+
|
7
|
+
from instaui.vars.mixin_types.element_binding import ElementBindingMixin
|
8
|
+
from instaui.vars.mixin_types.observable import ObservableMixin
|
9
|
+
from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
|
10
|
+
from instaui.vars.mixin_types.pathable import CanPathPropMixin
|
11
|
+
|
12
|
+
|
13
|
+
class RouterParamsVar(
|
14
|
+
Jsonable,
|
15
|
+
PathVar,
|
16
|
+
ObservableMixin,
|
17
|
+
CanPathPropMixin,
|
18
|
+
StrFormatBindingMixin,
|
19
|
+
ElementBindingMixin,
|
20
|
+
):
|
21
|
+
VAR_TYPE = "routePar"
|
22
|
+
|
23
|
+
def __init__(
|
24
|
+
self,
|
25
|
+
prop: typing.Literal["params", "path", "fullPath"] = "params",
|
26
|
+
) -> None:
|
27
|
+
super().__init__()
|
28
|
+
self._prop = prop
|
29
|
+
|
30
|
+
def __to_binding_config(self):
|
31
|
+
return self._to_json_dict()
|
32
|
+
|
33
|
+
def _to_pathable_binding_config(self) -> typing.Dict:
|
34
|
+
return self.__to_binding_config()
|
35
|
+
|
36
|
+
def _to_path_prop_binding_config(self) -> typing.Dict:
|
37
|
+
return self.__to_binding_config()
|
38
|
+
|
39
|
+
def _to_observable_config(self):
|
40
|
+
return self.__to_binding_config()
|
41
|
+
|
42
|
+
def _to_element_binding_config(self):
|
43
|
+
return self.__to_binding_config()
|
44
|
+
|
45
|
+
def _to_json_dict(self):
|
46
|
+
data = super()._to_json_dict()
|
47
|
+
data["type"] = self.VAR_TYPE
|
48
|
+
|
49
|
+
if self._prop != "params":
|
50
|
+
data["prop"] = self._prop
|
51
|
+
return data
|
@@ -0,0 +1,59 @@
|
|
1
|
+
{% macro render_fn_arg(main_fn_name) -%}
|
2
|
+
{% if main_fn_name -%}
|
3
|
+
component_fn={{main_fn_name}},
|
4
|
+
{% endif -%}
|
5
|
+
{% endmacro -%}
|
6
|
+
|
7
|
+
{% macro render_children_arg(children) -%}
|
8
|
+
{% if children -%}
|
9
|
+
children=[
|
10
|
+
{{render_routes(children)}}],
|
11
|
+
{% endif -%}
|
12
|
+
{% endmacro -%}
|
13
|
+
|
14
|
+
|
15
|
+
{% macro render_routes(routes) -%}
|
16
|
+
|
17
|
+
{% if not routes -%}
|
18
|
+
|
19
|
+
{% else -%}
|
20
|
+
{% for route in routes -%}
|
21
|
+
router.RouteItem.create(
|
22
|
+
path="{{route.path}}",
|
23
|
+
name="{{route.name}}",
|
24
|
+
{{ render_fn_arg(route.main_fn_name()) |trim}}
|
25
|
+
{{ render_children_arg(route.children) |trim}}
|
26
|
+
),
|
27
|
+
{% endfor -%}
|
28
|
+
|
29
|
+
{% endif -%}
|
30
|
+
|
31
|
+
{% endmacro -%}
|
32
|
+
|
33
|
+
"""
|
34
|
+
This file is automatically generated by InstaUI. Do not modify it manually.
|
35
|
+
|
36
|
+
update: {{model.update_time}}
|
37
|
+
"""
|
38
|
+
|
39
|
+
import typing
|
40
|
+
from instaui import spa_router as router
|
41
|
+
|
42
|
+
TNames = typing.Literal{{model.route_names}}
|
43
|
+
|
44
|
+
def link(text: str, name: TNames, params: typing.Optional[typing.Dict] = None):
|
45
|
+
return router.link.by_name(text, name=name, params=params)
|
46
|
+
|
47
|
+
def get_routes():
|
48
|
+
try:
|
49
|
+
{% for code in model.get_all_main_import() -%}
|
50
|
+
{{code}}
|
51
|
+
{% endfor -%}
|
52
|
+
|
53
|
+
return [
|
54
|
+
{{render_routes(model.routes)}}
|
55
|
+
]
|
56
|
+
except Exception as e:
|
57
|
+
print(f"router error: {e}")
|
58
|
+
|
59
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
:where(body){--insta-column-gap: 1rem;height:100vh}:where(#app){height:100%}:where(*){box-sizing:border-box;margin:0;padding:0}:where(.app-box[data-v-687dcc1a],.insta-main[data-v-687dcc1a]){height:100%}:where(.insta-main[data-v-687dcc1a]){--insta-padding: 16px;padding:var(--insta-padding, 16px)}
|