instaui 0.1.19__py2.py3-none-any.whl → 0.2.1__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 (53) hide show
  1. instaui/arco/component_types.py +389 -182
  2. instaui/arco/components/input.py +1 -1
  3. instaui/arco/components/typography.py +1 -1
  4. instaui/boot_info.py +2 -2
  5. instaui/components/component.py +9 -7
  6. instaui/components/element.py +11 -8
  7. instaui/components/html/button.py +2 -2
  8. instaui/components/html/input.py +2 -2
  9. instaui/components/html/range.py +2 -2
  10. instaui/components/html/select.py +3 -2
  11. instaui/components/html/textarea.py +2 -2
  12. instaui/components/html/ul.py +2 -2
  13. instaui/components/match.py +2 -2
  14. instaui/components/mixins.py +16 -0
  15. instaui/components/vfor.py +8 -6
  16. instaui/event/web_event.py +25 -2
  17. instaui/fastapi_server/_utils.py +5 -21
  18. instaui/fastapi_server/dependency_router.py +5 -1
  19. instaui/fastapi_server/event_router.py +5 -5
  20. instaui/fastapi_server/middlewares.py +12 -0
  21. instaui/fastapi_server/request_context.py +5 -4
  22. instaui/fastapi_server/server.py +5 -1
  23. instaui/fastapi_server/watch_router.py +2 -2
  24. instaui/js/fn.py +5 -1
  25. instaui/patch_update.py +54 -0
  26. instaui/pre_setup.py +45 -0
  27. instaui/response.py +64 -0
  28. instaui/runtime/_app.py +5 -1
  29. instaui/spa_router/_file_base_utils.py +1 -1
  30. instaui/static/insta-ui.esm-browser.prod.js +1400 -1391
  31. instaui/static/insta-ui.js.map +1 -1
  32. instaui/static/templates/web.html +5 -3
  33. instaui/static/templates/webview.html +4 -2
  34. instaui/static/templates/zero.html +4 -2
  35. instaui/template/web_template.py +1 -0
  36. instaui/template/webview_template.py +1 -0
  37. instaui/template/zero_template.py +1 -0
  38. instaui/ui/__init__.py +31 -6
  39. instaui/ui/__init__.pyi +4 -0
  40. instaui/ui_functions/server.py +10 -1
  41. instaui/ui_functions/ui_types.py +6 -2
  42. instaui/vars/mixin_types/element_binding.py +5 -1
  43. instaui/vars/mixin_types/observable.py +1 -1
  44. instaui/vars/vue_computed.py +5 -2
  45. instaui/watch/web_watch.py +11 -0
  46. instaui/webview/api.py +2 -23
  47. instaui/webview/resource.py +2 -0
  48. instaui/zero/func.py +2 -0
  49. {instaui-0.1.19.dist-info → instaui-0.2.1.dist-info}/METADATA +4 -3
  50. {instaui-0.1.19.dist-info → instaui-0.2.1.dist-info}/RECORD +52 -49
  51. instaui/webview/func.py +0 -114
  52. {instaui-0.1.19.dist-info → instaui-0.2.1.dist-info}/WHEEL +0 -0
  53. {instaui-0.1.19.dist-info → instaui-0.2.1.dist-info}/licenses/LICENSE +0 -0
@@ -24,8 +24,8 @@
24
24
  <body>
25
25
  {{ sse_html(model.is_debug) }}
26
26
 
27
- <div id="app">
28
- <insta-ui :config="config"></insta-ui>
27
+ <div id="app">
28
+ <insta-ui :config="config" :meta="meta"></insta-ui>
29
29
  </div>
30
30
 
31
31
  <script type="importmap">
@@ -52,11 +52,13 @@
52
52
  const None = undefined;
53
53
 
54
54
  const appConfig = {{model.config_dict | safe}};
55
+ const meta = {mode: 'web',version:'{{model.version | safe}}',debug:{{model.is_debug}}}
55
56
 
56
57
  const app = createApp({
57
58
  setup() {
58
59
  return {
59
- config:appConfig
60
+ config:appConfig,
61
+ meta,
60
62
  }
61
63
  }
62
64
  })
@@ -23,7 +23,7 @@
23
23
  <body>
24
24
 
25
25
  <div id="app">
26
- <insta-ui :config="config"></insta-ui>
26
+ <insta-ui :config="config" :meta="meta"></insta-ui>
27
27
  </div>
28
28
 
29
29
  <script type="importmap">
@@ -49,6 +49,7 @@
49
49
  const None = undefined;
50
50
 
51
51
  const appConfig = {{model.config_dict | safe}};
52
+ const meta = {mode: 'webview',version:'{{model.version | safe}}'}
52
53
 
53
54
  window.addEventListener('pywebviewready',async () => {
54
55
  const app = createApp({
@@ -59,7 +60,8 @@
59
60
  {% endif %}
60
61
  setup() {
61
62
  return {
62
- config:appConfig
63
+ config:appConfig,
64
+ meta,
63
65
  }
64
66
  }
65
67
  })
@@ -23,7 +23,7 @@
23
23
  <body>
24
24
 
25
25
  <div id="app">
26
- <insta-ui :config="config"></insta-ui>
26
+ <insta-ui :config="config" :meta="meta"></insta-ui>
27
27
  </div>
28
28
 
29
29
  <script type="importmap">
@@ -49,11 +49,13 @@
49
49
  const None = undefined;
50
50
 
51
51
  const appConfig = {{model.config_dict | safe}};
52
+ const meta = {mode: 'zero',version:'{{model.version | safe}}',debug:true}
52
53
 
53
54
  const app = createApp({
54
55
  setup() {
55
56
  return {
56
- config:appConfig
57
+ config:appConfig,
58
+ meta,
57
59
  }
58
60
  }
59
61
  })
@@ -12,6 +12,7 @@ _html_template = env.get_template("web.html")
12
12
 
13
13
  @dataclass
14
14
  class WebTemplateModel:
15
+ version: str
15
16
  vue_js_link: str
16
17
  instaui_js_link: str
17
18
  config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
@@ -16,6 +16,7 @@ class WebViewVueAppComponent:
16
16
 
17
17
  @dataclass
18
18
  class WebViewTemplateModel:
19
+ version: str
19
20
  vue_js_code: str
20
21
  instaui_js_code: str
21
22
  config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
@@ -24,6 +24,7 @@ class ZeroVueAppComponent:
24
24
 
25
25
  @dataclass
26
26
  class ZeroTemplateModel:
27
+ version: str
27
28
  vue_js_code: _TCodeOrPath
28
29
  instaui_js_code: _TCodeOrPath
29
30
  config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
instaui/ui/__init__.py CHANGED
@@ -61,6 +61,8 @@ __all__ = [
61
61
  "experimental",
62
62
  "skip_output",
63
63
  "str_format",
64
+ "pre_setup_action",
65
+ "patch_set",
64
66
  "on_page_request_lifespan",
65
67
  "webview",
66
68
  "code",
@@ -132,13 +134,36 @@ from instaui.ui_functions.ui_types import TBindable, is_bindable
132
134
  from .events import on_page_request_lifespan
133
135
  from instaui.extra_libs._import_error import show_error # noqa: E402, F401
134
136
  from instaui.js.fn import JsFn as js_fn
137
+ from instaui.pre_setup import PreSetupAction as pre_setup_action
138
+ from instaui.patch_update import patch_set
135
139
 
136
140
  # -- dynamic imports
137
141
  from instaui.systems.module_system import LazyModule as _LazyModule
138
- markdown = _LazyModule('instaui.components.markdown.markdown', 'Markdown')
139
- webview = _LazyModule('instaui.webview', 'WebviewWrapper')
140
- use_shadcn_classless = _LazyModule('instaui.shadcn_classless._index', 'use_shadcn_classless')
142
+
143
+ markdown = _LazyModule("instaui.components.markdown.markdown", "Markdown")
144
+ webview = _LazyModule("instaui.webview", "WebviewWrapper")
145
+ use_shadcn_classless = _LazyModule(
146
+ "instaui.shadcn_classless._index", "use_shadcn_classless"
147
+ )
141
148
  # -- extra libs
142
- mermaid = _LazyModule('instaui.extra_libs._mermaid', 'mermaid', import_error_callback=show_error('Mermaid is not installed. Please run "pip install instaui-mermaid" to install it.'),)
143
- code = _LazyModule('instaui.extra_libs._shiki_code', 'code', import_error_callback=show_error('Shiki is not installed. Please run "pip install instaui-shiki" to install it.'),)
144
- echarts = _LazyModule('instaui.extra_libs._echarts', 'echarts', import_error_callback=show_error('Echarts is not installed. Please run "pip install instaui-echarts" to install it.'),)
149
+ mermaid = _LazyModule(
150
+ "instaui.extra_libs._mermaid",
151
+ "mermaid",
152
+ import_error_callback=show_error(
153
+ 'Mermaid is not installed. Please run "pip install instaui-mermaid" to install it.'
154
+ ),
155
+ )
156
+ code = _LazyModule(
157
+ "instaui.extra_libs._shiki_code",
158
+ "code",
159
+ import_error_callback=show_error(
160
+ 'Shiki is not installed. Please run "pip install instaui-shiki" to install it.'
161
+ ),
162
+ )
163
+ echarts = _LazyModule(
164
+ "instaui.extra_libs._echarts",
165
+ "echarts",
166
+ import_error_callback=show_error(
167
+ 'Echarts is not installed. Please run "pip install instaui-echarts" to install it.'
168
+ ),
169
+ )
instaui/ui/__init__.pyi CHANGED
@@ -61,6 +61,8 @@ __all__ = [
61
61
  "experimental",
62
62
  "skip_output",
63
63
  "str_format",
64
+ "pre_setup_action",
65
+ "patch_set",
64
66
  "on_page_request_lifespan",
65
67
  "webview",
66
68
  "code",
@@ -132,6 +134,8 @@ from instaui.ui_functions.ui_types import TBindable, is_bindable
132
134
  from .events import on_page_request_lifespan
133
135
  from instaui.extra_libs._import_error import show_error # noqa: E402, F401
134
136
  from instaui.js.fn import JsFn as js_fn
137
+ from instaui.pre_setup import PreSetupAction as pre_setup_action
138
+ from instaui.patch_update import patch_set
135
139
 
136
140
  # -- dynamic imports
137
141
  from instaui.components.markdown.markdown import Markdown as markdown
@@ -3,9 +3,18 @@ from instaui.runtime.context import get_context
3
3
 
4
4
 
5
5
  def create_server(
6
- debug: bool = True,
6
+ debug: bool = False,
7
7
  use_gzip: Union[int, bool] = True,
8
8
  ):
9
+ """
10
+ Create a new server instance.
11
+
12
+ Note: When deploy to production, you need to set `debug=False`
13
+
14
+ Args:
15
+ debug (bool): Whether to run in debug mode. In debug mode, it has the development hot-reload feature. Defaults to False.
16
+ use_gzip (Union[int, bool], optional): Whether to use gzip compression. If an integer is provided, it will be used as the minimum response size for compression. If True, the default minimum size of 500 bytes will be used. If False, compression will not be used. Defaults to True.
17
+ """
9
18
  from instaui.fastapi_server.server import Server
10
19
 
11
20
  context = get_context()
@@ -7,7 +7,11 @@ _T = TypeVar("_T")
7
7
 
8
8
 
9
9
  def is_bindable(obj: Any):
10
- return isinstance(obj, (CanInputMixin, CanOutputMixin,ObservableMixin, ElementBindingMixin))
10
+ return isinstance(
11
+ obj, (CanInputMixin, CanOutputMixin, ObservableMixin, ElementBindingMixin)
12
+ )
11
13
 
12
14
 
13
- TBindable = Union[CanInputMixin, CanOutputMixin,ObservableMixin, ElementBindingMixin[_T]]
15
+ TBindable = Union[
16
+ CanInputMixin, CanOutputMixin, ObservableMixin, ElementBindingMixin[_T]
17
+ ]
@@ -1,4 +1,4 @@
1
- from typing import Dict, Generic, TypeVar
1
+ from typing import Dict, Generic, TypeVar, Protocol
2
2
  from abc import ABC, abstractmethod
3
3
 
4
4
  T = TypeVar("T")
@@ -8,3 +8,7 @@ class ElementBindingMixin(ABC, Generic[T]):
8
8
  @abstractmethod
9
9
  def _to_element_binding_config(self) -> Dict:
10
10
  pass
11
+
12
+
13
+ class ElementBindingProtocol(Protocol):
14
+ def _to_element_binding_config(self) -> Dict: ...
@@ -4,4 +4,4 @@ from abc import ABC, abstractmethod
4
4
  class ObservableMixin(ABC):
5
5
  @abstractmethod
6
6
  def _to_observable_config(self):
7
- pass
7
+ pass
@@ -6,7 +6,10 @@ from instaui.common.jsonable import Jsonable
6
6
  from instaui.runtime._app import get_current_scope
7
7
  from instaui.vars.path_var import PathVar
8
8
  from instaui.vars.mixin_types.var_type import VarMixin
9
- from instaui.vars.mixin_types.element_binding import ElementBindingMixin
9
+ from instaui.vars.mixin_types.element_binding import (
10
+ ElementBindingMixin,
11
+ ElementBindingProtocol,
12
+ )
10
13
  from instaui.vars.mixin_types.py_binding import CanInputMixin
11
14
  from instaui.vars.mixin_types.pathable import CanPathPropMixin
12
15
  from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
@@ -28,7 +31,7 @@ class VueComputed(
28
31
  def __init__(
29
32
  self,
30
33
  fn_code: str,
31
- bindings: Optional[Mapping[str, Union[ElementBindingMixin, Any]]] = None,
34
+ bindings: Optional[Mapping[str, Union[ElementBindingProtocol, Any]]] = None,
32
35
  ) -> None:
33
36
  self.code = fn_code
34
37
  self._bindings = bindings
@@ -12,6 +12,7 @@ from instaui.handlers import watch_handler
12
12
  from instaui.vars.mixin_types.py_binding import CanOutputMixin
13
13
  from instaui.vars.mixin_types.common_type import TObservableInput
14
14
  from instaui._helper import observable_helper
15
+ from instaui import pre_setup as _pre_setup
15
16
 
16
17
  _SYNC_TYPE = "sync"
17
18
  _ASYNC_TYPE = "async"
@@ -30,8 +31,11 @@ class WebWatch(Jsonable, typing.Generic[P, R]):
30
31
  deep: typing.Union[bool, int] = True,
31
32
  once: bool = False,
32
33
  flush: typing.Optional[_types.TFlush] = None,
34
+ pre_setup: typing.Optional[typing.Dict] = None,
33
35
  _debug: typing.Optional[typing.Any] = None,
34
36
  ) -> None:
37
+ if pre_setup:
38
+ _pre_setup._check_args(pre_setup)
35
39
  inputs = observable_helper.auto_made_inputs_to_slient(inputs, outputs)
36
40
 
37
41
  get_current_scope().register_web_watch(self)
@@ -47,6 +51,7 @@ class WebWatch(Jsonable, typing.Generic[P, R]):
47
51
  self._once = once
48
52
  self._flush = flush
49
53
  self._debug = _debug
54
+ self._pre_setup = pre_setup
50
55
 
51
56
  def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
52
57
  return self._fn(*args, **kwargs)
@@ -93,6 +98,8 @@ class WebWatch(Jsonable, typing.Generic[P, R]):
93
98
  data["once"] = self._once
94
99
  if self._flush is not None:
95
100
  data["flush"] = self._flush
101
+ if self._pre_setup:
102
+ data["preSetup"] = _pre_setup.convert_config(self._pre_setup)
96
103
 
97
104
  return data
98
105
 
@@ -107,6 +114,7 @@ def watch(
107
114
  deep: typing.Union[bool, int] = True,
108
115
  once: bool = False,
109
116
  flush: typing.Optional[_types.TFlush] = None,
117
+ pre_setup: typing.Optional[typing.Dict] = None,
110
118
  _debug: typing.Optional[typing.Any] = None,
111
119
  ):
112
120
  """
@@ -128,6 +136,8 @@ def watch(
128
136
  - 'sync': Execute immediately on change
129
137
  - 'post': Batch updates and execute after current tick
130
138
  - 'pre': Execute before render phase (if applicable)
139
+ pre_setup (typing.Optional[typing.Dict], optional): A dictionary of pre-setup actions to be executed before the event executes.
140
+
131
141
 
132
142
  # Example:
133
143
  .. code-block:: python
@@ -169,6 +179,7 @@ def watch(
169
179
  deep=deep,
170
180
  once=once,
171
181
  flush=flush,
182
+ pre_setup=pre_setup,
172
183
  _debug=_debug,
173
184
  )
174
185
 
instaui/webview/api.py CHANGED
@@ -1,10 +1,10 @@
1
- from typing import Any, Dict
1
+ from typing import Dict
2
2
 
3
3
 
4
4
  from instaui.runtime._app import get_app_slot
5
5
  from instaui.handlers import watch_handler
6
6
  from instaui.handlers import event_handler
7
- from instaui.skip import is_skip_output
7
+ from instaui.response import response_data
8
8
 
9
9
 
10
10
  class Api:
@@ -28,7 +28,6 @@ class Api:
28
28
 
29
29
  update_app_page_info(data)
30
30
 
31
-
32
31
  args = [bind for bind in data.get("bind", [])]
33
32
 
34
33
  result = handler.fn(*handler.get_handler_args(args))
@@ -50,23 +49,3 @@ def update_app_page_info(data: Dict):
50
49
 
51
50
  def _get_binds_from_data(data: Dict):
52
51
  return data.get("input", [])
53
-
54
-
55
- def response_data(outputs_binding_count: int, result: Any):
56
- data = {}
57
- if outputs_binding_count > 0:
58
- if not isinstance(result, tuple):
59
- result = [result]
60
-
61
- result_infos = [(r, int(is_skip_output(r))) for r in result]
62
-
63
- if len(result_infos) == 1 and result_infos[0][1] == 1:
64
- return data
65
-
66
- data["values"] = [0 if info[1] == 1 else info[0] for info in result_infos]
67
- skips = [info[1] for info in result_infos]
68
-
69
- if sum(skips) > 0:
70
- data["skips"] = skips
71
-
72
- return data
@@ -5,6 +5,7 @@ import shutil
5
5
  from typing import Callable, Optional
6
6
  from urllib.parse import quote
7
7
 
8
+ from instaui.version import __version__ as _INSTAUI_VERSION
8
9
  from instaui.html_tools import to_config_data
9
10
  from instaui.runtime._app import get_app_slot, get_default_app_slot
10
11
  from instaui.systems import file_system
@@ -48,6 +49,7 @@ def resource_to_assets(
48
49
  favicon_url = file_to_assets(consts.FAVICON_PATH)
49
50
 
50
51
  model = webview_template.WebViewTemplateModel(
52
+ version=_INSTAUI_VERSION,
51
53
  vue_js_code=file_to_assets(consts.VUE_ES_JS_PATH),
52
54
  instaui_js_code=file_to_assets(consts.APP_ES_JS_PATH),
53
55
  css_links=[
instaui/zero/func.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
  import itertools
3
3
  from pathlib import Path
4
+ from instaui.version import __version__ as _INSTA_VERSION
4
5
  import instaui.consts as consts
5
6
  from instaui.runtime._app import get_app_slot, get_default_app_slot
6
7
  from instaui.template import render_zero_html
@@ -37,6 +38,7 @@ def get_template_model():
37
38
  config_data = to_config_data()
38
39
 
39
40
  model = zero_template.ZeroTemplateModel(
41
+ version=_INSTA_VERSION,
40
42
  vue_js_code=consts.VUE_ES_JS_PATH,
41
43
  instaui_js_code=consts.APP_ES_JS_PATH,
42
44
  css_links=[
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: instaui
3
- Version: 0.1.19
3
+ Version: 0.2.1
4
4
  Summary: insta-ui is a Python-based UI library for rapidly building user interfaces.
5
5
  Author-email: CrystalWindSnake <568166495@qq.com>
6
6
  License-Expression: MIT
@@ -91,7 +91,8 @@ def home():
91
91
  ui.label("=")
92
92
  ui.label(result).style({"color": text_color})
93
93
 
94
- ui.server().run()
94
+ # when you deploy your web application, you need to set debug=False.
95
+ ui.server(debug=True).run()
95
96
  ```
96
97
 
97
98
  Replace `ui.server().run()` with `ui.webview().run()` to switch to Web View mode:
@@ -99,7 +100,7 @@ Replace `ui.server().run()` with `ui.webview().run()` to switch to Web View mode
99
100
  ```python
100
101
  ...
101
102
 
102
- # ui.server().run()
103
+ # ui.server(debug=True).run()
103
104
  ui.webview().run()
104
105
  ```
105
106