instaui 0.1.15__py2.py3-none-any.whl → 0.1.17__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/action/__init__.py +10 -0
- instaui/action/cookie.py +25 -0
- instaui/arco/components/radio.py +19 -6
- instaui/arco/components/radio_group.py +2 -3
- instaui/components/component.py +2 -0
- instaui/components/html/__init__.py +2 -0
- instaui/components/html/label.py +9 -7
- instaui/components/html/radio.py +37 -0
- instaui/components/timer/timer.js +48 -0
- instaui/components/timer/timer.py +94 -0
- instaui/event/js_event.py +2 -0
- instaui/event/vue_event.py +3 -0
- instaui/event/web_event.py +2 -4
- instaui/runtime/scope.py +11 -2
- instaui/static/insta-ui.esm-browser.prod.js +131 -130
- instaui/static/insta-ui.js.map +1 -1
- instaui/ui/__init__.py +2 -2
- instaui/ui/__init__.pyi +2 -2
- instaui/vars/js_computed.py +16 -1
- instaui/vars/mixin_types/element_binding.py +7 -1
- instaui/vars/path_var.py +3 -3
- instaui/vars/ref.py +15 -5
- instaui/vars/state.py +4 -4
- instaui/vars/vue_computed.py +17 -1
- instaui/vars/web_computed.py +5 -4
- instaui/watch/js_watch.py +2 -0
- instaui/watch/web_watch.py +2 -6
- {instaui-0.1.15.dist-info → instaui-0.1.17.dist-info}/METADATA +1 -1
- {instaui-0.1.15.dist-info → instaui-0.1.17.dist-info}/RECORD +32 -27
- /instaui/{ui_functions → action}/url_location.py +0 -0
- {instaui-0.1.15.dist-info → instaui-0.1.17.dist-info}/WHEEL +0 -0
- {instaui-0.1.15.dist-info → instaui-0.1.17.dist-info}/licenses/LICENSE +0 -0
instaui/action/cookie.py
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
from typing import Optional, Union
|
3
|
+
from instaui.runtime.context import get_context
|
4
|
+
|
5
|
+
|
6
|
+
def cookie_output():
|
7
|
+
if not get_context().app_mode == "web":
|
8
|
+
raise ValueError("cookie_output can only be used in web mode")
|
9
|
+
|
10
|
+
|
11
|
+
def cookie_input():
|
12
|
+
pass
|
13
|
+
|
14
|
+
|
15
|
+
def set_cookie(
|
16
|
+
key: str,
|
17
|
+
value: str,
|
18
|
+
*,
|
19
|
+
max_age: Optional[int] = None,
|
20
|
+
expires: Optional[Union[int, datetime]] = None,
|
21
|
+
secure: bool = False,
|
22
|
+
httponly: bool = False,
|
23
|
+
samesite: Optional[str] = None,
|
24
|
+
):
|
25
|
+
pass
|
instaui/arco/components/radio.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
import typing
|
2
3
|
from typing_extensions import Unpack
|
3
4
|
import pydantic
|
@@ -6,13 +7,16 @@ from instaui.vars.types import TMaybeRef
|
|
6
7
|
from instaui.vars.state import StateModel
|
7
8
|
from instaui.arco import component_types
|
8
9
|
from instaui.event.event_mixin import EventMixin
|
9
|
-
from ._utils import handle_props
|
10
|
+
from ._utils import handle_props
|
11
|
+
from .radio_group import RadioGroup
|
12
|
+
|
13
|
+
_TValue = typing.Union[str, float]
|
10
14
|
|
11
15
|
|
12
16
|
class Radio(Element):
|
13
17
|
def __init__(
|
14
18
|
self,
|
15
|
-
value: typing.Optional[TMaybeRef[
|
19
|
+
value: typing.Optional[TMaybeRef[_TValue]] = None,
|
16
20
|
**kwargs: Unpack[component_types.TRadio],
|
17
21
|
):
|
18
22
|
super().__init__("a-radio")
|
@@ -33,8 +37,17 @@ class Radio(Element):
|
|
33
37
|
)
|
34
38
|
return self
|
35
39
|
|
40
|
+
@staticmethod
|
41
|
+
def from_list(options: TMaybeRef[typing.List[_TValue]], value: TMaybeRef[_TValue]):
|
42
|
+
return RadioGroup(value=value, options=options) # type: ignore
|
43
|
+
|
44
|
+
@staticmethod
|
45
|
+
def from_options(
|
46
|
+
options: TMaybeRef[typing.List[RadioOption]], value: TMaybeRef[_TValue]
|
47
|
+
):
|
48
|
+
return RadioGroup(value=value, options=options) # type: ignore
|
36
49
|
|
37
|
-
class RadioOption(StateModel):
|
38
|
-
|
39
|
-
|
40
|
-
|
50
|
+
class RadioOption(StateModel):
|
51
|
+
label: str
|
52
|
+
value: typing.Union[str, int]
|
53
|
+
disabled: bool = pydantic.Field(default=False)
|
@@ -4,7 +4,6 @@ from instaui.components.element import Element
|
|
4
4
|
from instaui.vars.types import TMaybeRef
|
5
5
|
from instaui.event.event_mixin import EventMixin
|
6
6
|
from ._utils import handle_props, try_setup_vmodel
|
7
|
-
from .radio import RadioOption
|
8
7
|
|
9
8
|
|
10
9
|
class TRadioGroup(TypedDict, total=False):
|
@@ -12,7 +11,7 @@ class TRadioGroup(TypedDict, total=False):
|
|
12
11
|
default_value: typing.Union[str, int, bool]
|
13
12
|
type: typing.Literal["radio", "button"]
|
14
13
|
size: typing.Literal["mini", "small", "medium", "large"]
|
15
|
-
options: typing.List[typing.Union[str, int
|
14
|
+
options: typing.List[typing.Union[str, int]]
|
16
15
|
direction: typing.Literal["horizontal", "vertical"]
|
17
16
|
disabled: bool
|
18
17
|
|
@@ -20,7 +19,7 @@ class TRadioGroup(TypedDict, total=False):
|
|
20
19
|
class RadioGroup(Element):
|
21
20
|
def __init__(
|
22
21
|
self,
|
23
|
-
value: typing.Optional[TMaybeRef[typing.Union[str,
|
22
|
+
value: typing.Optional[TMaybeRef[typing.Union[str, float]]] = None,
|
24
23
|
**kwargs: Unpack[TRadioGroup],
|
25
24
|
):
|
26
25
|
super().__init__("a-radio-group")
|
instaui/components/component.py
CHANGED
@@ -6,6 +6,7 @@ __all__ = [
|
|
6
6
|
"number",
|
7
7
|
"button",
|
8
8
|
"checkbox",
|
9
|
+
"radio",
|
9
10
|
"form",
|
10
11
|
"select",
|
11
12
|
"option",
|
@@ -32,6 +33,7 @@ from .input import Input as input
|
|
32
33
|
from .number import Number as number
|
33
34
|
from .button import Button as button
|
34
35
|
from .checkbox import Checkbox as checkbox
|
36
|
+
from .radio import Radio as radio
|
35
37
|
from .form import Form as form
|
36
38
|
from .select import Select as select
|
37
39
|
from .ul import Ul as ul
|
instaui/components/html/label.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
from typing import TYPE_CHECKING, Any, Union
|
2
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
3
3
|
from instaui.components.element import Element
|
4
4
|
|
5
5
|
if TYPE_CHECKING:
|
@@ -10,12 +10,14 @@ class Label(Element):
|
|
10
10
|
def __init__(
|
11
11
|
self,
|
12
12
|
text: Union[Any, TMaybeRef[Any], None] = None,
|
13
|
+
*,
|
14
|
+
for_: Optional[TMaybeRef[str]] = None,
|
13
15
|
):
|
14
16
|
super().__init__("label")
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
self.props(
|
19
|
+
{
|
20
|
+
"innerText": text,
|
21
|
+
"for": for_,
|
22
|
+
}
|
23
|
+
)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import TYPE_CHECKING, Optional
|
3
|
+
from instaui.components.element import Element
|
4
|
+
from instaui.components.value_element import ValueElement
|
5
|
+
from ._mixins import InputEventMixin
|
6
|
+
|
7
|
+
if TYPE_CHECKING:
|
8
|
+
from instaui.vars.types import TMaybeRef
|
9
|
+
|
10
|
+
|
11
|
+
_T_value = str
|
12
|
+
|
13
|
+
|
14
|
+
class Radio(InputEventMixin, ValueElement[_T_value]):
|
15
|
+
def __init__(
|
16
|
+
self,
|
17
|
+
value: Optional[TMaybeRef[_T_value]] = None,
|
18
|
+
*,
|
19
|
+
model_value: Optional[_T_value] = None,
|
20
|
+
id: Optional[TMaybeRef[str]] = None,
|
21
|
+
name: Optional[TMaybeRef[str]] = None,
|
22
|
+
):
|
23
|
+
super().__init__("input", value, is_html_component=True)
|
24
|
+
self.props({"type": "radio"})
|
25
|
+
|
26
|
+
self.props(
|
27
|
+
{
|
28
|
+
"id": id,
|
29
|
+
"name": name,
|
30
|
+
}
|
31
|
+
)
|
32
|
+
|
33
|
+
if model_value is not None:
|
34
|
+
self.props({"value": model_value})
|
35
|
+
|
36
|
+
def _input_event_mixin_element(self) -> Element:
|
37
|
+
return self
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { ref, watch, onMounted, onUnmounted, toRef } from 'vue'
|
2
|
+
|
3
|
+
|
4
|
+
export default {
|
5
|
+
props: ['intervalSeconds', 'active', 'once', 'immediate'],
|
6
|
+
setup(props, { emit }) {
|
7
|
+
const { intervalSeconds, once = false, immediate = true } = props
|
8
|
+
const intervalId = ref(null)
|
9
|
+
const isActive = toRef(() => props.active ?? true)
|
10
|
+
const emitTick = once ? () => { emit('tick'); stopInterval() } : () => emit('tick')
|
11
|
+
|
12
|
+
if (once === false) {
|
13
|
+
watch(isActive, (value) => {
|
14
|
+
if (value) {
|
15
|
+
startInterval()
|
16
|
+
} else {
|
17
|
+
stopInterval()
|
18
|
+
}
|
19
|
+
})
|
20
|
+
}
|
21
|
+
|
22
|
+
const startInterval = () => {
|
23
|
+
if (immediate) {
|
24
|
+
emitTick()
|
25
|
+
}
|
26
|
+
|
27
|
+
intervalId.value = setInterval(() => {
|
28
|
+
emitTick()
|
29
|
+
}, intervalSeconds * 1000)
|
30
|
+
}
|
31
|
+
|
32
|
+
const stopInterval = () => {
|
33
|
+
clearInterval(intervalId.value)
|
34
|
+
emit('stop')
|
35
|
+
}
|
36
|
+
|
37
|
+
onMounted(() => {
|
38
|
+
if (isActive.value) {
|
39
|
+
startInterval()
|
40
|
+
}
|
41
|
+
})
|
42
|
+
|
43
|
+
onUnmounted(() => {
|
44
|
+
stopInterval()
|
45
|
+
})
|
46
|
+
}
|
47
|
+
|
48
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import List, Optional
|
3
|
+
from instaui.components.element import Element
|
4
|
+
from instaui.vars.types import TMaybeRef
|
5
|
+
from instaui.event.event_mixin import EventMixin
|
6
|
+
|
7
|
+
|
8
|
+
class Timer(Element, esm="./timer.js"):
|
9
|
+
"""
|
10
|
+
A timer component that triggers events at specified intervals.
|
11
|
+
|
12
|
+
Args:
|
13
|
+
interval_seconds (float): Time in seconds between repeated events.
|
14
|
+
active (Optional[TMaybeRef[bool]], optional): If True, starts the timer immediately.
|
15
|
+
Accepts reactive values (e.g., state references) for dynamic control. Defaults to None (equivalent to True).
|
16
|
+
immediate (Optional[bool], optional): If True, triggers the first event immediately. Defaults to None (equivalent to True).
|
17
|
+
|
18
|
+
Example:
|
19
|
+
.. code-block:: python
|
20
|
+
from instaui import ui, html
|
21
|
+
|
22
|
+
@ui.page('/')
|
23
|
+
def index():
|
24
|
+
x = ui.state(0)
|
25
|
+
active = ui.state(True)
|
26
|
+
|
27
|
+
@ui.event(inputs=[x], outputs=[x])
|
28
|
+
def on_tick(x):
|
29
|
+
return x + 1
|
30
|
+
|
31
|
+
ui.timer(1, active=active).on_tick(on_tick)
|
32
|
+
|
33
|
+
html.checkbox(active)
|
34
|
+
html.span(x)
|
35
|
+
"""
|
36
|
+
|
37
|
+
def __init__(
|
38
|
+
self,
|
39
|
+
interval_seconds: float,
|
40
|
+
*,
|
41
|
+
active: Optional[TMaybeRef[bool]] = None,
|
42
|
+
immediate: Optional[bool] = None,
|
43
|
+
):
|
44
|
+
super().__init__("template")
|
45
|
+
|
46
|
+
self.props(
|
47
|
+
{
|
48
|
+
"intervalSeconds": interval_seconds,
|
49
|
+
"active": active,
|
50
|
+
"immediate": immediate,
|
51
|
+
}
|
52
|
+
)
|
53
|
+
|
54
|
+
def on_tick(
|
55
|
+
self,
|
56
|
+
handler: EventMixin,
|
57
|
+
*,
|
58
|
+
extends: Optional[List] = None,
|
59
|
+
):
|
60
|
+
"""
|
61
|
+
Registers an event handler for the "tick" event.
|
62
|
+
"""
|
63
|
+
return self.on("tick", handler, extends=extends)
|
64
|
+
|
65
|
+
def on_stop(
|
66
|
+
self,
|
67
|
+
handler: EventMixin,
|
68
|
+
*,
|
69
|
+
extends: Optional[List] = None,
|
70
|
+
):
|
71
|
+
"""
|
72
|
+
Registers an event handler for the "stop" event.
|
73
|
+
"""
|
74
|
+
|
75
|
+
return self.on("stop", handler, extends=extends)
|
76
|
+
|
77
|
+
@classmethod
|
78
|
+
def once(cls, delay_seconds: float):
|
79
|
+
"""
|
80
|
+
Creates a timer that triggers only once.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
delay_seconds (float): Time in seconds before the timer triggers.
|
84
|
+
|
85
|
+
Example:
|
86
|
+
.. code-block:: python
|
87
|
+
msg = ui.state('')
|
88
|
+
on_done = ui.js_event(outputs=[msg],code="()=> 'Done!'")
|
89
|
+
|
90
|
+
ui.timer.once(1).on_tick(on_done)
|
91
|
+
html.span(msg) # will show "Done!" after 1 second
|
92
|
+
|
93
|
+
"""
|
94
|
+
return cls(delay_seconds, immediate=False).props({"once": True})
|
instaui/event/js_event.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import typing
|
2
2
|
from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
3
|
+
from instaui.vars.mixin_types.element_binding import _try_mark_inputs_used
|
3
4
|
from instaui.common.jsonable import Jsonable
|
4
5
|
from .event_mixin import EventMixin
|
5
6
|
|
@@ -26,6 +27,7 @@ class JsEvent(Jsonable, EventMixin):
|
|
26
27
|
def _to_json_dict(self):
|
27
28
|
data = super()._to_json_dict()
|
28
29
|
data["type"] = self.event_type()
|
30
|
+
_try_mark_inputs_used(self._org_inputs)
|
29
31
|
|
30
32
|
if self._inputs:
|
31
33
|
data["inputs"] = self._inputs
|
instaui/event/vue_event.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import typing
|
2
2
|
from instaui.common.jsonable import Jsonable
|
3
3
|
from instaui.vars.mixin_types.observable import ObservableMixin
|
4
|
+
from instaui.vars.mixin_types.element_binding import _try_mark_inputs_used
|
4
5
|
from .event_mixin import EventMixin
|
5
6
|
|
6
7
|
|
@@ -59,6 +60,8 @@ class VueEvent(Jsonable, EventMixin):
|
|
59
60
|
|
60
61
|
def _to_json_dict(self):
|
61
62
|
data = super()._to_json_dict()
|
63
|
+
|
64
|
+
_try_mark_inputs_used((self._bindings or {}).values())
|
62
65
|
data["type"] = self.event_type()
|
63
66
|
return data
|
64
67
|
|
instaui/event/web_event.py
CHANGED
@@ -4,7 +4,7 @@ from typing_extensions import ParamSpec
|
|
4
4
|
from instaui.common.jsonable import Jsonable
|
5
5
|
from instaui.runtime._app import get_current_scope, get_app_slot
|
6
6
|
from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
|
7
|
-
from instaui.vars.mixin_types.element_binding import
|
7
|
+
from instaui.vars.mixin_types.element_binding import _try_mark_inputs_used
|
8
8
|
from instaui.handlers import event_handler
|
9
9
|
from .event_mixin import EventMixin
|
10
10
|
|
@@ -47,9 +47,7 @@ class WebEvent(Jsonable, EventMixin, typing.Generic[P, R]):
|
|
47
47
|
def _to_json_dict(self):
|
48
48
|
app = get_app_slot()
|
49
49
|
|
50
|
-
|
51
|
-
if isinstance(_input, ElementBindingMixin):
|
52
|
-
_input._mark_used()
|
50
|
+
_try_mark_inputs_used(self._inputs)
|
53
51
|
|
54
52
|
hkey = event_handler.create_handler_key(
|
55
53
|
page_path=app.page_path, handler=self._fn
|
instaui/runtime/scope.py
CHANGED
@@ -97,14 +97,23 @@ class Scope(Jsonable):
|
|
97
97
|
if self._element_refs:
|
98
98
|
data["eRefs"] = self._element_refs
|
99
99
|
|
100
|
+
# web computeds
|
100
101
|
_web_computeds = [
|
101
102
|
computed for computed in self._web_computeds if computed._is_used()
|
102
103
|
]
|
103
104
|
|
104
105
|
if _web_computeds:
|
105
106
|
data["web_computed"] = _web_computeds
|
106
|
-
|
107
|
-
|
107
|
+
|
108
|
+
# js computeds
|
109
|
+
_js_computeds = [
|
110
|
+
computed for computed in self._js_computeds if computed._is_used()
|
111
|
+
]
|
112
|
+
|
113
|
+
if _js_computeds:
|
114
|
+
data["js_computed"] = _js_computeds
|
115
|
+
|
116
|
+
# vue computeds
|
108
117
|
if self._vue_computeds:
|
109
118
|
data["vue_computed"] = self._vue_computeds
|
110
119
|
if self._const_data:
|