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
instaui/pre_setup.py ADDED
@@ -0,0 +1,45 @@
1
+ from typing import Dict, Sequence, cast
2
+ from instaui.common.jsonable import Jsonable
3
+ from instaui.vars.mixin_types.py_binding import CanOutputMixin, CanInputMixin
4
+
5
+
6
+ def _check_args(config: Dict):
7
+ for key in config.keys():
8
+ if not isinstance(key, CanOutputMixin):
9
+ raise TypeError(f"key {key} is not a CanOutputMixin")
10
+
11
+
12
+ def convert_config(config: Dict):
13
+ return [
14
+ {
15
+ "target": cast(CanInputMixin, key)._to_input_config(),
16
+ **value._to_json_dict(),
17
+ }
18
+ if isinstance(value, PreSetupAction)
19
+ else {
20
+ "type": "const",
21
+ "target": cast(CanInputMixin, key)._to_input_config(),
22
+ "value": value,
23
+ }
24
+ for key, value in config.items()
25
+ ]
26
+
27
+
28
+ class PreSetupAction(Jsonable):
29
+ def __init__(self, *, inputs: Sequence, code: str, reset: bool = True):
30
+ self.type = "action"
31
+ self._inputs = inputs
32
+ self.code = code
33
+ self.reset = reset
34
+
35
+ def _to_json_dict(self):
36
+ data = super()._to_json_dict()
37
+ if self._inputs:
38
+ data["inputs"] = [
39
+ binding._to_input_config()
40
+ if isinstance(binding, CanInputMixin)
41
+ else binding
42
+ for binding in self._inputs
43
+ ]
44
+
45
+ return data
instaui/response.py ADDED
@@ -0,0 +1,64 @@
1
+ from typing import Any, List, Sequence, TypedDict
2
+ from enum import IntEnum
3
+ from instaui.common.jsonable import Jsonable
4
+ from instaui.skip import is_skip_output
5
+ from instaui.patch_update import PatchSet
6
+
7
+
8
+ class TResponse(TypedDict, total=False):
9
+ values: List[Any]
10
+ types: Sequence[int]
11
+
12
+
13
+ class ValueType(IntEnum):
14
+ VALUE = 0
15
+ SKIP = 1
16
+ Patch = 2
17
+
18
+
19
+ def response_data(outputs_binding_count: int, result: Any):
20
+ data: TResponse = {}
21
+ if outputs_binding_count > 0:
22
+ if not isinstance(result, tuple):
23
+ result = [result]
24
+
25
+ returns_count = len(result)
26
+
27
+ # [(value, 1), (value, 0)]
28
+ result_infos = [
29
+ (_try_get_value_from_jsonable(r), convert_type(r)) for r in result
30
+ ]
31
+
32
+ if returns_count == 1 and result_infos[0][1] == ValueType.SKIP:
33
+ return data
34
+
35
+ # fill missing values with None
36
+ if returns_count < outputs_binding_count:
37
+ result_infos.extend(
38
+ [(None, ValueType.SKIP)] * (outputs_binding_count - returns_count)
39
+ )
40
+
41
+ data["values"] = [
42
+ 0 if info[1] == ValueType.SKIP else info[0] for info in result_infos
43
+ ]
44
+ types = [info[1] for info in result_infos]
45
+
46
+ if sum(types) > 0:
47
+ data["types"] = types
48
+
49
+ return data
50
+
51
+
52
+ def convert_type(value: Any):
53
+ if is_skip_output(value):
54
+ return ValueType.SKIP
55
+ if isinstance(value, PatchSet):
56
+ return ValueType.Patch
57
+ return ValueType.VALUE
58
+
59
+
60
+ def _try_get_value_from_jsonable(value: Any) -> Any:
61
+ if isinstance(value, Jsonable):
62
+ return value._to_json_dict()
63
+
64
+ return value
instaui/runtime/_app.py CHANGED
@@ -30,7 +30,7 @@ class App(Jsonable):
30
30
  self._vfor_id_counter = 0
31
31
  self._slot_id_counter = 0
32
32
  self._js_fn_id_counter = 0
33
- self.mode: _T_App_Mode = mode
33
+ self._mode: _T_App_Mode = mode
34
34
  self.items: List[Component] = []
35
35
  self.meta = meta
36
36
  self._slots_stacks: List[Slot] = []
@@ -49,6 +49,10 @@ class App(Jsonable):
49
49
  self._route_collector: Optional[RouteCollector] = None
50
50
  self._js_fns: List[JsFn] = []
51
51
 
52
+ @property
53
+ def mode(self) -> _T_App_Mode:
54
+ return self._mode
55
+
52
56
  @property
53
57
  def page_path(self) -> str:
54
58
  assert self._page_path is not None, "Page path is not set"
@@ -113,7 +113,7 @@ class _model_utils:
113
113
  if not self.fn_path:
114
114
  return ""
115
115
 
116
- return f"from .{self.fn_path.replace(' ','_')} import main as {self.main_fn_name()}"
116
+ return f"from .{self.fn_path.replace(' ', '_')} import main as {self.main_fn_name()}"
117
117
 
118
118
  def main_fn_name(self):
119
119
  if not self.fn_path: