instaui 0.1.4__py3-none-any.whl → 0.1.6__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 (198) hide show
  1. instaui/arco/__init__.py +191 -0
  2. instaui/arco/_settings.py +25 -0
  3. instaui/arco/_use_tools/locale.py +50 -0
  4. instaui/arco/component_types.py +1019 -0
  5. instaui/arco/components/_utils.py +22 -0
  6. instaui/arco/components/affix.py +29 -0
  7. instaui/arco/components/alert.py +42 -0
  8. instaui/arco/components/anchor.py +42 -0
  9. instaui/arco/components/auto_complete.py +96 -0
  10. instaui/arco/components/avatar.py +55 -0
  11. instaui/arco/components/back_top.py +14 -0
  12. instaui/arco/components/badge.py +14 -0
  13. instaui/arco/components/breadcrumb.py +14 -0
  14. instaui/arco/components/button.py +43 -0
  15. instaui/arco/components/calendar.py +47 -0
  16. instaui/arco/components/card.py +14 -0
  17. instaui/arco/components/carousel.py +33 -0
  18. instaui/arco/components/cascader.py +111 -0
  19. instaui/arco/components/checkbox.py +32 -0
  20. instaui/arco/components/collapse.py +31 -0
  21. instaui/arco/components/color_picker.py +45 -0
  22. instaui/arco/components/comment.py +14 -0
  23. instaui/arco/components/config_provider.py +13 -0
  24. instaui/arco/components/date_picker.py +111 -0
  25. instaui/arco/components/descriptions.py +14 -0
  26. instaui/arco/components/divider.py +13 -0
  27. instaui/arco/components/drawer.py +98 -0
  28. instaui/arco/components/dropdown.py +45 -0
  29. instaui/arco/components/empty.py +14 -0
  30. instaui/arco/components/form.py +55 -0
  31. instaui/arco/components/icon.py +17 -0
  32. instaui/arco/components/image.py +33 -0
  33. instaui/arco/components/input.py +102 -0
  34. instaui/arco/components/input_number.py +97 -0
  35. instaui/arco/components/input_password.py +38 -0
  36. instaui/arco/components/input_search.py +37 -0
  37. instaui/arco/components/input_tag.py +110 -0
  38. instaui/arco/components/layout.py +13 -0
  39. instaui/arco/components/layout_content.py +6 -0
  40. instaui/arco/components/layout_footer.py +6 -0
  41. instaui/arco/components/layout_header.py +6 -0
  42. instaui/arco/components/layout_sider.py +53 -0
  43. instaui/arco/components/link.py +36 -0
  44. instaui/arco/components/list.py +68 -0
  45. instaui/arco/components/mention.py +97 -0
  46. instaui/arco/components/menu.py +88 -0
  47. instaui/arco/components/modal.py +97 -0
  48. instaui/arco/components/overflow_list.py +29 -0
  49. instaui/arco/components/page_header.py +29 -0
  50. instaui/arco/components/pagination.py +45 -0
  51. instaui/arco/components/pop_confirm.py +58 -0
  52. instaui/arco/components/popover.py +32 -0
  53. instaui/arco/components/progress.py +14 -0
  54. instaui/arco/components/radio.py +40 -0
  55. instaui/arco/components/radio_group.py +42 -0
  56. instaui/arco/components/rate.py +45 -0
  57. instaui/arco/components/resize_box.py +62 -0
  58. instaui/arco/components/result.py +14 -0
  59. instaui/arco/components/select.py +179 -0
  60. instaui/arco/components/skeleton.py +14 -0
  61. instaui/arco/components/slider.py +38 -0
  62. instaui/arco/components/space.py +14 -0
  63. instaui/arco/components/spin.py +14 -0
  64. instaui/arco/components/split.py +76 -0
  65. instaui/arco/components/statistic.py +14 -0
  66. instaui/arco/components/steps.py +32 -0
  67. instaui/arco/components/switch.py +57 -0
  68. instaui/arco/components/tab_pane.py +12 -0
  69. instaui/arco/components/table.py +276 -0
  70. instaui/arco/components/tabs.py +101 -0
  71. instaui/arco/components/tag.py +42 -0
  72. instaui/arco/components/textarea.py +84 -0
  73. instaui/arco/components/time_picker.py +76 -0
  74. instaui/arco/components/timeline.py +14 -0
  75. instaui/arco/components/tooltip.py +29 -0
  76. instaui/arco/components/transfer.py +58 -0
  77. instaui/arco/components/tree.py +120 -0
  78. instaui/arco/components/tree_select.py +86 -0
  79. instaui/arco/components/trigger.py +58 -0
  80. instaui/arco/components/typography.py +142 -0
  81. instaui/arco/components/upload.py +71 -0
  82. instaui/arco/components/verification_code.py +58 -0
  83. instaui/arco/components/watermark.py +14 -0
  84. instaui/arco/locales/__init__.py +4 -0
  85. instaui/arco/locales/_index.py +31 -0
  86. instaui/arco/locales/en_us.py +227 -0
  87. instaui/arco/locales/zh_cn.py +224 -0
  88. instaui/arco/setup.py +36 -0
  89. instaui/arco/static/instaui-arco.css +1 -0
  90. instaui/arco/static/instaui-arco.js +55771 -0
  91. instaui/arco/types.py +24 -0
  92. instaui/components/column.py +10 -2
  93. instaui/components/echarts/echarts.js +128 -0
  94. instaui/components/echarts/echarts.py +194 -0
  95. instaui/components/echarts/static/echarts.esm.min.js +45 -0
  96. instaui/components/element.py +50 -6
  97. instaui/components/grid.py +81 -0
  98. instaui/components/html/__init__.py +30 -19
  99. instaui/components/html/_preset.py +4 -0
  100. instaui/components/html/heading.py +51 -0
  101. instaui/components/html/range.py +3 -0
  102. instaui/components/html/select.py +13 -31
  103. instaui/components/html/table.py +36 -0
  104. instaui/components/markdown/static/github-markdown.css +1 -1
  105. instaui/components/markdown/static/marked.esm.js +0 -1
  106. instaui/components/row.py +8 -7
  107. instaui/components/shiki_code/shiki_code.js +126 -0
  108. instaui/components/shiki_code/shiki_code.py +99 -0
  109. instaui/components/shiki_code/static/langs/css.mjs +5 -0
  110. instaui/components/shiki_code/static/langs/markdown.mjs +5 -0
  111. instaui/components/shiki_code/static/langs/python.mjs +5 -0
  112. instaui/components/shiki_code/static/langs/shell.mjs +2 -0
  113. instaui/components/shiki_code/static/langs/shellscript.mjs +5 -0
  114. instaui/components/shiki_code/static/shiki-core.js +5784 -0
  115. instaui/components/shiki_code/static/shiki-style.css +179 -0
  116. instaui/components/shiki_code/static/shiki-transformers.js +461 -0
  117. instaui/components/shiki_code/static/themes/vitesse-dark.mjs +2 -0
  118. instaui/components/shiki_code/static/themes/vitesse-light.mjs +2 -0
  119. instaui/components/value_element.py +7 -3
  120. instaui/consts.py +2 -1
  121. instaui/event/js_event.py +1 -0
  122. instaui/event/web_event.py +6 -7
  123. instaui/experimental/link_sql/__init__.py +3 -0
  124. instaui/experimental/link_sql/_base.py +23 -0
  125. instaui/experimental/link_sql/_duckdb.py +221 -0
  126. instaui/experimental/link_sql/_types.py +15 -0
  127. instaui/experimental/link_sql/data_source.js +50 -0
  128. instaui/fastapi_server/debug_mode_router.py +1 -1
  129. instaui/fastapi_server/server.py +4 -12
  130. instaui/handlers/event_handler.py +3 -1
  131. instaui/handlers/watch_handler.py +4 -0
  132. instaui/html_tools.py +41 -4
  133. instaui/runtime/_app.py +37 -3
  134. instaui/runtime/_link_manager.py +89 -0
  135. instaui/runtime/resource.py +19 -9
  136. instaui/runtime/scope.py +28 -7
  137. instaui/shadcn_classless/_index.py +42 -0
  138. instaui/shadcn_classless/static/shadcn-classless.css +403 -0
  139. instaui/static/insta-ui.css +1 -1
  140. instaui/static/insta-ui.esm-browser.prod.js +3663 -3658
  141. instaui/static/insta-ui.js.map +1 -1
  142. instaui/static/instaui-tools-browser.js +511 -0
  143. instaui/static/templates/debug/sse.html +1 -1
  144. instaui/static/templates/webview.html +78 -0
  145. instaui/tailwind/__init__.py +6 -0
  146. instaui/tailwind/_index.py +24 -0
  147. instaui/{static/tailwindcss.min.js → tailwind/static/tailwindcss-v3.min.js} +62 -62
  148. instaui/tailwind/static/tailwindcss-v4.min.js +8 -0
  149. instaui/template/_utils.py +23 -0
  150. instaui/template/webview_template.py +50 -0
  151. instaui/ui/__init__.py +8 -2
  152. instaui/ui/__init__.pyi +7 -1
  153. instaui/ui_functions/ui_page.py +1 -1
  154. instaui/vars/data.py +7 -7
  155. instaui/vars/element_ref.py +2 -4
  156. instaui/vars/event_context.py +4 -0
  157. instaui/vars/js_computed.py +6 -8
  158. instaui/vars/ref.py +6 -6
  159. instaui/vars/vue_computed.py +6 -7
  160. instaui/vars/web_computed.py +31 -32
  161. instaui/watch/vue_watch.py +23 -7
  162. instaui/watch/web_watch.py +5 -6
  163. instaui/webview/__init__.py +1 -0
  164. instaui/webview/_utils.py +8 -0
  165. instaui/webview/api.py +72 -0
  166. instaui/webview/func.py +114 -0
  167. instaui/webview/index.py +162 -0
  168. instaui/webview/resource.py +172 -0
  169. instaui/zero/func.py +19 -12
  170. instaui/zero/scope.py +29 -28
  171. {instaui-0.1.4.dist-info → instaui-0.1.6.dist-info}/METADATA +6 -2
  172. instaui-0.1.6.dist-info/RECORD +286 -0
  173. instaui/components/highlight_code/code.js +0 -63
  174. instaui/components/highlight_code/code.py +0 -117
  175. instaui/components/highlight_code/static/core.min.js +0 -307
  176. instaui/components/highlight_code/static/languages/css.min.js +0 -31
  177. instaui/components/highlight_code/static/languages/javascript.min.js +0 -81
  178. instaui/components/highlight_code/static/languages/json.min.js +0 -8
  179. instaui/components/highlight_code/static/languages/python-repl.min.js +0 -5
  180. instaui/components/highlight_code/static/languages/python.min.js +0 -42
  181. instaui/components/highlight_code/static/languages/shell.min.js +0 -5
  182. instaui/components/highlight_code/static/styles/default.min.css +0 -9
  183. instaui/components/highlight_code/static/styles/github-dark-dimmed.min.css +0 -9
  184. instaui/components/highlight_code/static/styles/github-dark.min.css +0 -10
  185. instaui/components/highlight_code/static/styles/github.min.css +0 -10
  186. instaui/daisyui/__init__.py +0 -20
  187. instaui/daisyui/_index.py +0 -15
  188. instaui/daisyui/button.py +0 -38
  189. instaui/daisyui/checkbox.py +0 -17
  190. instaui/daisyui/static/daisyui.css +0 -1
  191. instaui/daisyui/static/themes.css +0 -1
  192. instaui/handlers/computed_handler.py +0 -42
  193. instaui/handlers/config_handler.py +0 -13
  194. instaui/ui/__build_init.py +0 -73
  195. instaui/vars/_utils.py +0 -12
  196. instaui-0.1.4.dist-info/RECORD +0 -179
  197. {instaui-0.1.4.dist-info → instaui-0.1.6.dist-info}/LICENSE +0 -0
  198. {instaui-0.1.4.dist-info → instaui-0.1.6.dist-info}/WHEEL +0 -0
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+ import typing
3
+ from pathlib import Path
4
+ from urllib.parse import quote
5
+ import base64
6
+
7
+
8
+ _JS_PREFIX = "data:text/javascript;charset=utf-8"
9
+ _CSS_PREFIX = "data:text/css;charset=utf-8"
10
+ _ICON_PREFIX = "data:image/x-icon;base64"
11
+
12
+
13
+ def normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
14
+ if isinstance(path, Path):
15
+ path = path.read_text(encoding="utf-8")
16
+
17
+ return f"{prefix},{quote(path)}"
18
+
19
+
20
+ def normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
21
+ if path is None:
22
+ return None
23
+ return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
@@ -0,0 +1,50 @@
1
+ from __future__ import annotations
2
+ import typing
3
+ from pathlib import Path
4
+ from dataclasses import dataclass, field
5
+ from instaui.common.jsonable import dumps
6
+ from instaui.runtime.dataclass import JsLink
7
+ from .env import env
8
+
9
+
10
+ _html_template = env.get_template("webview.html")
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class WebViewVueAppComponent:
15
+ name: str
16
+ url: str
17
+
18
+
19
+ @dataclass
20
+ class WebViewTemplateModel:
21
+ vue_js_code: str
22
+ instaui_js_code: str
23
+ config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
24
+ extra_import_maps: typing.Dict[str, str] = field(default_factory=dict)
25
+ css_links: typing.List[str] = field(default_factory=list)
26
+ style_tags: typing.List[str] = field(default_factory=list)
27
+ js_links: typing.List[str] = field(default_factory=list)
28
+ script_tags: typing.List[str] = field(default_factory=list)
29
+ vue_app_use: typing.List[str] = field(default_factory=list)
30
+ vue_app_component: typing.List[WebViewVueAppComponent] = field(default_factory=list)
31
+ title: typing.Optional[str] = None
32
+ favicon_url: typing.Optional[str] = None
33
+ on_app_mounted: typing.Optional[typing.Callable] = None
34
+
35
+ def add_extra_import_map(self, name: str, code: str):
36
+ self.extra_import_maps[name] = code
37
+
38
+ @property
39
+ def import_maps_string(self):
40
+ data = {
41
+ **self.extra_import_maps,
42
+ "vue": self.vue_js_code,
43
+ "instaui": self.instaui_js_code,
44
+ }
45
+
46
+ return dumps(data)
47
+
48
+
49
+ def render_wbeview_html(model: WebViewTemplateModel) -> str:
50
+ return _html_template.render(model=model)
instaui/ui/__init__.py CHANGED
@@ -61,8 +61,11 @@ __all__ = [
61
61
  "str_format",
62
62
  "url_location",
63
63
  "on_page_request_lifespan",
64
+ "webview",
64
65
  "code",
65
66
  "markdown",
67
+ "echarts",
68
+ "use_shadcn_classless",
66
69
  ]
67
70
 
68
71
  # -- static imports
@@ -126,5 +129,8 @@ from .events import on_page_request_lifespan
126
129
 
127
130
  # -- dynamic imports
128
131
  from instaui.systems.module_system import LazyModule
129
- code = LazyModule('instaui.components.highlight_code.code', 'Code')
130
- markdown = LazyModule('instaui.components.markdown.markdown', 'Markdown')
132
+ code = LazyModule('instaui.components.shiki_code.shiki_code', 'Code')
133
+ markdown = LazyModule('instaui.components.markdown.markdown', 'Markdown')
134
+ webview = LazyModule('instaui.webview', 'WebviewWrapper')
135
+ echarts = LazyModule('instaui.components.echarts.echarts', 'ECharts')
136
+ use_shadcn_classless = LazyModule('instaui.shadcn_classless._index', 'use_shadcn_classless')
instaui/ui/__init__.pyi CHANGED
@@ -61,8 +61,11 @@ __all__ = [
61
61
  "str_format",
62
62
  "url_location",
63
63
  "on_page_request_lifespan",
64
+ "webview",
64
65
  "code",
65
66
  "markdown",
67
+ "echarts",
68
+ "use_shadcn_classless",
66
69
  ]
67
70
 
68
71
  # -- static imports
@@ -125,5 +128,8 @@ from instaui.ui_functions.ui_types import TBindable, is_bindable
125
128
  from .events import on_page_request_lifespan
126
129
 
127
130
  # -- dynamic imports
128
- from instaui.components.highlight_code.code import Code as code
131
+ from instaui.components.shiki_code.shiki_code import Code as code
129
132
  from instaui.components.markdown.markdown import Markdown as markdown
133
+ from instaui.webview import WebviewWrapper as webview
134
+ from instaui.components.echarts.echarts import ECharts as echarts
135
+ from instaui.shadcn_classless._index import use_shadcn_classless
@@ -2,7 +2,7 @@ from typing import Callable
2
2
  from instaui.launch_collector import get_launch_collector, PageInfo
3
3
 
4
4
 
5
- def page(url: str):
5
+ def page(url: str = "/"):
6
6
  """Register a page route.
7
7
 
8
8
  Args:
instaui/vars/data.py CHANGED
@@ -5,6 +5,7 @@ from typing import (
5
5
  )
6
6
 
7
7
  from instaui.common.jsonable import Jsonable
8
+ from instaui.runtime._app import get_current_scope
8
9
  from instaui.vars.path_var import PathVar
9
10
 
10
11
  from .mixin_types.var_type import VarMixin
@@ -12,7 +13,6 @@ from .mixin_types.py_binding import CanInputMixin, CanOutputMixin
12
13
  from .mixin_types.element_binding import ElementBindingMixin
13
14
  from .mixin_types.pathable import CanPathPropMixin
14
15
  from .mixin_types.str_format_binding import StrFormatBindingMixin
15
- from . import _utils
16
16
 
17
17
 
18
18
  class ConstData(
@@ -25,18 +25,19 @@ class ConstData(
25
25
  StrFormatBindingMixin,
26
26
  ElementBindingMixin,
27
27
  ):
28
- VAR_TYPE = "data"
28
+ BIND_TYPE = "var"
29
29
 
30
30
  def __init__(self, value: Any = None) -> None:
31
31
  self.value = value # type: ignore
32
32
 
33
- sid, id = _utils.register_var(self)
34
- self._sid = sid
35
- self._id = id
33
+ scope = get_current_scope()
34
+ scope.register_data(self)
35
+ self._sid = scope.id
36
+ self._id = scope.generate_vars_id()
36
37
 
37
38
  def __to_binding_config(self):
38
39
  return {
39
- "type": self.VAR_TYPE,
40
+ "type": self.BIND_TYPE,
40
41
  "id": self._id,
41
42
  "sid": self._sid,
42
43
  }
@@ -60,7 +61,6 @@ class ConstData(
60
61
  data = super()._to_json_dict()
61
62
  data["sid"] = self._sid
62
63
  data["id"] = self._id
63
- data["type"] = self.VAR_TYPE
64
64
 
65
65
  return data
66
66
 
@@ -6,12 +6,10 @@ from instaui.vars.mixin_types.py_binding import CanOutputMixin
6
6
 
7
7
  class ElementRef(Jsonable, CanOutputMixin):
8
8
  def __init__(self) -> None:
9
- self._id = None
9
+ scope = get_current_scope()
10
+ self._id = scope.generate_element_ref_id()
10
11
  self.__sid = get_current_scope().id
11
12
 
12
- def _set_id(self, id: str):
13
- self._id = id
14
-
15
13
  def __to_binding_config(
16
14
  self,
17
15
  ):
@@ -30,6 +30,10 @@ class EventContext(Jsonable, CanInputMixin):
30
30
  def e():
31
31
  return EventContext(":e => e")
32
32
 
33
+ @staticmethod
34
+ def target_value():
35
+ return EventContext(":e => e.target.value")
36
+
33
37
 
34
38
  class DatasetEventContext(Jsonable, CanInputMixin):
35
39
  def __init__(self, event_context: EventContext) -> None:
@@ -3,6 +3,7 @@ import typing
3
3
 
4
4
  from instaui.common.jsonable import Jsonable
5
5
 
6
+ from instaui.runtime._app import get_current_scope
6
7
  from instaui.vars.path_var import PathVar
7
8
  from instaui.vars.mixin_types.var_type import VarMixin
8
9
  from instaui.vars.mixin_types.element_binding import ElementBindingMixin
@@ -13,8 +14,6 @@ from instaui.vars.mixin_types.observable import ObservableMixin
13
14
  from instaui.vars.mixin_types.common_type import TObservableInput
14
15
  from instaui._helper import observable_helper
15
16
 
16
- from . import _utils
17
-
18
17
 
19
18
  class JsComputed(
20
19
  Jsonable,
@@ -26,8 +25,7 @@ class JsComputed(
26
25
  StrFormatBindingMixin,
27
26
  ElementBindingMixin,
28
27
  ):
29
- VAR_TYPE = "jsComputed"
30
- BIND_TYPE = "computed"
28
+ BIND_TYPE = "var"
31
29
 
32
30
  def __init__(
33
31
  self,
@@ -38,9 +36,10 @@ class JsComputed(
38
36
  ) -> None:
39
37
  self.code = code
40
38
 
41
- sid, id = _utils.register_var(self)
42
- self._sid = sid
43
- self._id = id
39
+ scope = get_current_scope()
40
+ scope.register_js_computed(self)
41
+ self._sid = scope.id
42
+ self._id = scope.generate_vars_id()
44
43
 
45
44
  self._inputs, self._is_slient_inputs, self._is_data = (
46
45
  observable_helper.analyze_observable_inputs(list(inputs or []))
@@ -75,7 +74,6 @@ class JsComputed(
75
74
 
76
75
  data["sid"] = self._sid
77
76
  data["id"] = self._id
78
- data["type"] = self.VAR_TYPE
79
77
 
80
78
  if self._inputs:
81
79
  data["inputs"] = self._inputs
instaui/vars/ref.py CHANGED
@@ -9,6 +9,7 @@ from typing import (
9
9
  )
10
10
 
11
11
  from instaui.common.jsonable import Jsonable
12
+ from instaui.runtime._app import get_current_scope
12
13
  from instaui.vars.path_var import PathVar
13
14
 
14
15
  from .mixin_types.var_type import VarMixin
@@ -17,7 +18,6 @@ from .mixin_types.observable import ObservableMixin
17
18
  from .mixin_types.element_binding import ElementBindingMixin
18
19
  from .mixin_types.pathable import CanPathPropMixin
19
20
  from .mixin_types.str_format_binding import StrFormatBindingMixin
20
- from . import _utils
21
21
 
22
22
 
23
23
  _T_Value = TypeVar("_T_Value")
@@ -35,14 +35,15 @@ class Ref(
35
35
  ElementBindingMixin[_T_Value],
36
36
  Generic[_T_Value],
37
37
  ):
38
- VAR_TYPE = "ref"
38
+ VAR_TYPE = "var"
39
39
 
40
40
  def __init__(self, value: Optional[_T_Value] = None) -> None:
41
41
  self.value = value # type: ignore
42
+ scope = get_current_scope()
43
+ scope.register_ref(self)
42
44
 
43
- sid, id = _utils.register_var(self)
44
- self._sid = sid
45
- self._id = id
45
+ self._sid = scope.id
46
+ self._id = scope.generate_vars_id()
46
47
  self._debounced = None
47
48
 
48
49
  def debounced(self, secounds: float):
@@ -78,7 +79,6 @@ class Ref(
78
79
  data = super()._to_json_dict()
79
80
  data["sid"] = self._sid
80
81
  data["id"] = self._id
81
- data["type"] = self.VAR_TYPE
82
82
 
83
83
  if self._debounced is not None:
84
84
  data["debounced"] = self._debounced
@@ -3,6 +3,7 @@ from typing import Any, Dict, Mapping, Optional, Union
3
3
 
4
4
  from instaui.common.jsonable import Jsonable
5
5
 
6
+ from instaui.runtime._app import get_current_scope
6
7
  from instaui.vars.path_var import PathVar
7
8
  from instaui.vars.mixin_types.var_type import VarMixin
8
9
  from instaui.vars.mixin_types.element_binding import ElementBindingMixin
@@ -10,7 +11,6 @@ from instaui.vars.mixin_types.py_binding import CanInputMixin
10
11
  from instaui.vars.mixin_types.pathable import CanPathPropMixin
11
12
  from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
12
13
  from instaui.vars.mixin_types.observable import ObservableMixin
13
- from . import _utils
14
14
 
15
15
 
16
16
  class VueComputed(
@@ -23,8 +23,7 @@ class VueComputed(
23
23
  StrFormatBindingMixin,
24
24
  ElementBindingMixin,
25
25
  ):
26
- VAR_TYPE = "vComputed"
27
- BIND_TYPE = "computed"
26
+ BIND_TYPE = "var"
28
27
 
29
28
  def __init__(
30
29
  self,
@@ -32,10 +31,11 @@ class VueComputed(
32
31
  bindings: Optional[Mapping[str, Union[ElementBindingMixin, Any]]] = None,
33
32
  ) -> None:
34
33
  self.code = fn_code
34
+ scope = get_current_scope()
35
+ scope.register_vue_computed(self)
35
36
 
36
- sid, id = _utils.register_var(self)
37
- self._sid = sid
38
- self._id = id
37
+ self._sid = scope.id
38
+ self._id = scope.generate_vars_id()
39
39
 
40
40
  if bindings:
41
41
  const_bind = []
@@ -75,7 +75,6 @@ class VueComputed(
75
75
  data = super()._to_json_dict()
76
76
  data["sid"] = self._sid
77
77
  data["id"] = self._id
78
- data["type"] = self.VAR_TYPE
79
78
  return data
80
79
 
81
80
 
@@ -24,6 +24,9 @@ from instaui.vars.mixin_types.observable import ObservableMixin
24
24
  from instaui.vars.mixin_types.common_type import TObservableInput
25
25
  from instaui._helper import observable_helper
26
26
 
27
+ _SYNC_TYPE = "sync"
28
+ _ASYNC_TYPE = "async"
29
+
27
30
  P = ParamSpec("P")
28
31
  R = TypeVar("R")
29
32
 
@@ -38,7 +41,7 @@ class WebComputed(
38
41
  ElementBindingMixin[R],
39
42
  Generic[P, R],
40
43
  ):
41
- VAR_TYPE = "webComputed"
44
+ BIND_TYPE = "var"
42
45
 
43
46
  def __init__(
44
47
  self,
@@ -70,51 +73,47 @@ class WebComputed(
70
73
 
71
74
  app = get_app_slot()
72
75
 
73
- if app.mode == "web":
74
- hkey = watch_handler.create_handler_key(
75
- page_path=app.page_path,
76
- handler=self._fn,
77
- )
76
+ hkey = watch_handler.create_handler_key(
77
+ page_path=app.page_path,
78
+ handler=self._fn,
79
+ )
78
80
 
79
- watch_handler.register_handler(hkey, self._fn, len(self._outputs) + 1)
81
+ watch_handler.register_handler(hkey, self._fn, len(self._outputs) + 1)
80
82
 
81
- url = (
82
- watch_handler.ASYNC_URL
83
- if inspect.iscoroutinefunction(self._fn)
84
- else watch_handler.SYNC_URL
85
- )
83
+ # if app.mode == "web":
86
84
 
87
- data["id"] = self._id
88
- data["sid"] = self._sid
89
- data["type"] = self.VAR_TYPE
85
+ data["id"] = self._id
86
+ data["sid"] = self._sid
90
87
 
91
- if self._inputs:
92
- data["inputs"] = self._inputs
88
+ if self._inputs:
89
+ data["inputs"] = self._inputs
93
90
 
94
- if self._outputs:
95
- data["outputs"] = self._outputs
91
+ if self._outputs:
92
+ data["outputs"] = self._outputs
96
93
 
97
- if sum(self._is_slient_inputs) > 0:
98
- data["slient"] = self._is_slient_inputs
94
+ if sum(self._is_slient_inputs) > 0:
95
+ data["slient"] = self._is_slient_inputs
99
96
 
100
- if sum(self._is_data) > 0:
101
- data["data"] = self._is_data
97
+ if sum(self._is_data) > 0:
98
+ data["data"] = self._is_data
102
99
 
103
- data["url"] = url
104
- data["key"] = hkey
105
- if self._init_value is not None:
106
- data["init"] = self._init_value
100
+ data["fType"] = (
101
+ _ASYNC_TYPE if inspect.iscoroutinefunction(self._fn) else _SYNC_TYPE
102
+ )
103
+ data["key"] = hkey
104
+ if self._init_value is not None:
105
+ data["init"] = self._init_value
107
106
 
108
- if self._evaluating:
109
- data["running"] = self._evaluating._to_output_config()
107
+ if self._evaluating:
108
+ data["running"] = self._evaluating._to_output_config()
110
109
 
111
- return data
110
+ return data
112
111
 
113
- return {}
112
+ # return {}
114
113
 
115
114
  def __to_binding_config(self):
116
115
  return {
117
- "type": self.VAR_TYPE,
116
+ "type": self.BIND_TYPE,
118
117
  "id": self._id,
119
118
  "sid": self._sid,
120
119
  }
@@ -33,17 +33,33 @@ class VueWatch(Jsonable):
33
33
 
34
34
  self.code = callback
35
35
 
36
- if isinstance(sources, Sequence):
37
- self.on = [
38
- cast(ObservableMixin, varObj)._to_observable_config()
39
- for varObj in sources
40
- ]
41
- else:
42
- self.on = cast(ObservableMixin, sources)._to_observable_config()
36
+ if not isinstance(sources, Sequence):
37
+ sources = [sources]
38
+
39
+ onData = [int(not isinstance(varObj, ObservableMixin)) for varObj in sources]
40
+
41
+ if sum(onData) > 0:
42
+ self.onData = onData
43
+
44
+ self.on = [
45
+ cast(ObservableMixin, varObj)._to_observable_config()
46
+ if isinstance(varObj, ObservableMixin)
47
+ else varObj
48
+ for varObj in sources
49
+ ]
43
50
 
44
51
  if bindings:
52
+ bindData = [
53
+ int(not isinstance(v, ObservableMixin)) for v in bindings.values()
54
+ ]
55
+
56
+ if sum(bindData) > 0:
57
+ self.bindData = bindData
58
+
45
59
  self.bind = {
46
60
  k: cast(ObservableMixin, v)._to_observable_config()
61
+ if isinstance(v, ObservableMixin)
62
+ else v
47
63
  for k, v in bindings.items()
48
64
  }
49
65
 
@@ -13,6 +13,9 @@ 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
15
 
16
+ _SYNC_TYPE = "sync"
17
+ _ASYNC_TYPE = "async"
18
+
16
19
  P = ParamSpec("P")
17
20
  R = typing.TypeVar("R")
18
21
 
@@ -59,13 +62,9 @@ class WebWatch(Jsonable, typing.Generic[P, R]):
59
62
 
60
63
  watch_handler.register_handler(hkey, self._fn, len(self._outputs))
61
64
 
62
- url = (
63
- watch_handler.ASYNC_URL
64
- if inspect.iscoroutinefunction(self._fn)
65
- else watch_handler.SYNC_URL
65
+ data["fType"] = (
66
+ _ASYNC_TYPE if inspect.iscoroutinefunction(self._fn) else _SYNC_TYPE
66
67
  )
67
-
68
- data["url"] = url
69
68
  data["key"] = hkey
70
69
  if self._inputs:
71
70
  data["inputs"] = self._inputs
@@ -0,0 +1 @@
1
+ from .index import WebviewWrapper
@@ -0,0 +1,8 @@
1
+ from pathlib import Path
2
+ import shutil
3
+
4
+
5
+ def reset_dir(dir_path: Path):
6
+ if dir_path.exists():
7
+ shutil.rmtree(dir_path)
8
+ dir_path.mkdir(exist_ok=True)
instaui/webview/api.py ADDED
@@ -0,0 +1,72 @@
1
+ from typing import Any, Dict
2
+
3
+
4
+ from instaui.runtime._app import get_app_slot
5
+ from instaui.handlers import watch_handler
6
+ from instaui.handlers import event_handler
7
+ from instaui.skip import is_skip_output
8
+
9
+
10
+ class Api:
11
+ def watch_call(self, data: Dict):
12
+ hkey = data.pop("key")
13
+ handler_info = watch_handler.get_handler_info(hkey)
14
+ if handler_info is None:
15
+ return {"error": "watch handler not found"}
16
+
17
+ update_app_page_info(data)
18
+
19
+ result = handler_info.fn(
20
+ *handler_info.get_handler_args(_get_binds_from_data(data))
21
+ )
22
+ return response_data(handler_info.outputs_binding_count, result)
23
+
24
+ def event_call(self, data: Dict):
25
+ handler = event_handler.get_handler(data["hKey"])
26
+ if handler is None:
27
+ raise ValueError("event handler not found")
28
+
29
+ update_app_page_info(data)
30
+
31
+
32
+ args = [bind for bind in data.get("bind", [])]
33
+
34
+ result = handler.fn(*handler.get_handler_args(args))
35
+ return response_data(handler.outputs_binding_count, result)
36
+
37
+
38
+ def update_app_page_info(data: Dict):
39
+ app = get_app_slot()
40
+
41
+ page_info = data.get("page", {})
42
+ app._page_path = page_info["path"]
43
+
44
+ if "params" in page_info:
45
+ app._page_params = page_info["params"]
46
+
47
+ if "queryParams" in page_info:
48
+ app._query_params = page_info["queryParams"]
49
+
50
+
51
+ def _get_binds_from_data(data: Dict):
52
+ 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