pyjs 0.0.1__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.
- pyjs/__init__.py +6 -0
- pyjs/__main__.py +6 -0
- pyjs/cli.py +816 -0
- pyjs/decorators.py +170 -0
- pyjs/docs/__init__.py +6 -0
- pyjs/docs/builder.py +351 -0
- pyjs/docs/cli.py +55 -0
- pyjs/docs/config.py +45 -0
- pyjs/docs/favicon.svg +18 -0
- pyjs/docs/markdown.py +61 -0
- pyjs/docs/models.py +38 -0
- pyjs/docs/navigation.py +61 -0
- pyjs/docs/style.css +901 -0
- pyjs/docs/ui.py +349 -0
- pyjs/nativescript/__init__.py +77 -0
- pyjs/scaffolding/__init__.py +418 -0
- pyjs/scaffolding/templates/app/README.md.template +33 -0
- pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__PYJS_PACKAGE__.py.template +81 -0
- pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__init__.py.template +0 -0
- pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__main__.py.template +5 -0
- pyjs/scaffolding/templates/app/tests/test_app.py.template +22 -0
- pyjs/scaffolding/templates/app/tests/test_browser_app.py.template +19 -0
- pyjs/scaffolding/templates/app_test.py.template +8 -0
- pyjs/server.py +468 -0
- pyjs/skills/pyjs/SKILL.md +161 -0
- pyjs/state.py +101 -0
- pyjs/testing/__init__.py +3 -0
- pyjs/testing/android.py +248 -0
- pyjs/testing/artifacts.py +37 -0
- pyjs/testing/assertion_rewriter.py +125 -0
- pyjs/testing/builder.py +191 -0
- pyjs/testing/capture.py +133 -0
- pyjs/testing/client/__init__.py +1 -0
- pyjs/testing/client/app.py +718 -0
- pyjs/testing/client/assertions.py +49 -0
- pyjs/testing/client/runtime.py +123 -0
- pyjs/testing/client/sidebar.py +377 -0
- pyjs/testing/client/state.py +107 -0
- pyjs/testing/client/viewer.py +361 -0
- pyjs/testing/daemon.py +641 -0
- pyjs/testing/helpers.py +155 -0
- pyjs/testing/protocol.py +56 -0
- pyjs/testing/pytest_plugin.py +797 -0
- pyjs/testing/web.py +97 -0
- pyjs/testing/webgpu.py +27 -0
- pyjs/tooling/__init__.py +4 -0
- pyjs/tooling/android.py +138 -0
- pyjs/tooling/browser.py +676 -0
- pyjs/tooling/command.py +75 -0
- pyjs/tooling/nativescript.py +156 -0
- pyjs/tooling/node.py +170 -0
- pyjs/tooling/perf.py +163 -0
- pyjs/transpiler/__init__.py +23 -0
- pyjs/transpiler/_builtins.py +485 -0
- pyjs/transpiler/analyzer.py +1495 -0
- pyjs/transpiler/objects.py +1015 -0
- pyjs/transpiler/source.py +189 -0
- pyjs/transpiler/transpiler.py +748 -0
- pyjs/transpiler/utils.py +150 -0
- pyjs/web/__init__.py +5 -0
- pyjs/web/console.py +16 -0
- pyjs/web/dom.py +1529 -0
- pyjs/web/domx.py +474 -0
- pyjs/web/dragdrop.py +102 -0
- pyjs/web/events.py +1306 -0
- pyjs/web/files.py +203 -0
- pyjs/web/geometry.py +475 -0
- pyjs/web/html.py +927 -0
- pyjs/web/indexeddb.py +410 -0
- pyjs/web/javascript.py +112 -0
- pyjs/web/network.py +193 -0
- pyjs/web/ssr.py +70 -0
- pyjs/web/streams.py +17 -0
- pyjs/web/svg.py +684 -0
- pyjs/web/timers.py +29 -0
- pyjs/web/ui/__init__.py +18 -0
- pyjs/web/ui/accordion.py +166 -0
- pyjs/web/ui/alert.py +52 -0
- pyjs/web/ui/alert_dialog.py +102 -0
- pyjs/web/ui/aspect_ratio.py +12 -0
- pyjs/web/ui/attachment.py +80 -0
- pyjs/web/ui/avatar.py +105 -0
- pyjs/web/ui/badge.py +48 -0
- pyjs/web/ui/breadcrumb.py +85 -0
- pyjs/web/ui/bubble.py +38 -0
- pyjs/web/ui/button.py +86 -0
- pyjs/web/ui/calendar.py +124 -0
- pyjs/web/ui/card.py +58 -0
- pyjs/web/ui/carousel.py +99 -0
- pyjs/web/ui/chart.py +56 -0
- pyjs/web/ui/checkbox.py +31 -0
- pyjs/web/ui/collapsible.py +71 -0
- pyjs/web/ui/combobox.py +36 -0
- pyjs/web/ui/command.py +118 -0
- pyjs/web/ui/context_menu.py +65 -0
- pyjs/web/ui/date_picker.py +24 -0
- pyjs/web/ui/dialog.py +289 -0
- pyjs/web/ui/direction.py +9 -0
- pyjs/web/ui/drawer.py +72 -0
- pyjs/web/ui/dropdown_menu.py +239 -0
- pyjs/web/ui/empty.py +69 -0
- pyjs/web/ui/field.py +96 -0
- pyjs/web/ui/floating.py +90 -0
- pyjs/web/ui/hover_card.py +128 -0
- pyjs/web/ui/input.py +48 -0
- pyjs/web/ui/input_group.py +77 -0
- pyjs/web/ui/input_otp.py +76 -0
- pyjs/web/ui/item.py +78 -0
- pyjs/web/ui/kbd.py +26 -0
- pyjs/web/ui/label.py +14 -0
- pyjs/web/ui/marker.py +29 -0
- pyjs/web/ui/menubar.py +52 -0
- pyjs/web/ui/message.py +57 -0
- pyjs/web/ui/message_scroller.py +45 -0
- pyjs/web/ui/native_select.py +47 -0
- pyjs/web/ui/navigation_menu.py +110 -0
- pyjs/web/ui/pagination.py +63 -0
- pyjs/web/ui/popover.py +217 -0
- pyjs/web/ui/progress.py +44 -0
- pyjs/web/ui/radio_group.py +129 -0
- pyjs/web/ui/resizable.py +194 -0
- pyjs/web/ui/scroll_area.py +29 -0
- pyjs/web/ui/select.py +83 -0
- pyjs/web/ui/separator.py +24 -0
- pyjs/web/ui/sheet.py +77 -0
- pyjs/web/ui/sidebar.py +162 -0
- pyjs/web/ui/skeleton.py +15 -0
- pyjs/web/ui/slider.py +46 -0
- pyjs/web/ui/sonner.py +70 -0
- pyjs/web/ui/spinner.py +14 -0
- pyjs/web/ui/switch.py +35 -0
- pyjs/web/ui/table.py +84 -0
- pyjs/web/ui/tabs.py +167 -0
- pyjs/web/ui/text.py +15 -0
- pyjs/web/ui/textarea.py +28 -0
- pyjs/web/ui/toggle.py +109 -0
- pyjs/web/ui/tooltip.py +164 -0
- pyjs/web/ui/typography.py +79 -0
- pyjs/web/url.py +76 -0
- pyjs/web/webgpu.py +496 -0
- pyjs-0.0.1.dist-info/METADATA +441 -0
- pyjs-0.0.1.dist-info/RECORD +146 -0
- pyjs-0.0.1.dist-info/WHEEL +5 -0
- pyjs-0.0.1.dist-info/entry_points.txt +5 -0
- pyjs-0.0.1.dist-info/licenses/LICENSE +28 -0
- pyjs-0.0.1.dist-info/top_level.txt +1 -0
pyjs/web/ui/tabs.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.dom import Element
|
|
3
|
+
from pyjs.web.domx import tag, tw
|
|
4
|
+
from pyjs.web.events import Event, KeyboardEvent
|
|
5
|
+
from pyjs.web.html import HTMLElement
|
|
6
|
+
from pyjs.web.ui import Widget
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@js
|
|
10
|
+
class Tab:
|
|
11
|
+
def __init__(self, value: str, label: str, *children):
|
|
12
|
+
self.value = value
|
|
13
|
+
self.trigger = tag(
|
|
14
|
+
"button",
|
|
15
|
+
tw(
|
|
16
|
+
"inline-flex h-8 flex-1 items-center justify-center rounded-md border "
|
|
17
|
+
"border-transparent px-3 text-sm font-medium text-slate-500 transition-all "
|
|
18
|
+
"hover:text-slate-950 focus-visible:outline-none focus-visible:ring-2 "
|
|
19
|
+
"focus-visible:ring-slate-400 data-[state=active]:bg-white "
|
|
20
|
+
"data-[state=active]:text-slate-950 data-[state=active]:shadow-sm"
|
|
21
|
+
),
|
|
22
|
+
{
|
|
23
|
+
"data-slot": "tabs-trigger",
|
|
24
|
+
"data-value": value,
|
|
25
|
+
"role": "tab",
|
|
26
|
+
"type": "button",
|
|
27
|
+
},
|
|
28
|
+
label,
|
|
29
|
+
)
|
|
30
|
+
self.content = tag(
|
|
31
|
+
"div",
|
|
32
|
+
tw(
|
|
33
|
+
"mt-3 rounded-md border border-slate-200 bg-white p-4 text-sm text-slate-700"
|
|
34
|
+
),
|
|
35
|
+
{"data-slot": "tabs-content", "data-value": value, "role": "tabpanel"},
|
|
36
|
+
*children,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def link(self, id_prefix: str):
|
|
40
|
+
trigger_id = id_prefix + "-trigger"
|
|
41
|
+
content_id = id_prefix + "-content"
|
|
42
|
+
self.trigger.setAttribute("id", trigger_id)
|
|
43
|
+
self.trigger.setAttribute("aria-controls", content_id)
|
|
44
|
+
self.content.setAttribute("id", content_id)
|
|
45
|
+
self.content.setAttribute("aria-labelledby", trigger_id)
|
|
46
|
+
|
|
47
|
+
def set_active(self, active: bool):
|
|
48
|
+
if active:
|
|
49
|
+
self.trigger.setAttribute("aria-selected", "true")
|
|
50
|
+
self.trigger.setAttribute("data-state", "active")
|
|
51
|
+
self.trigger.setAttribute("tabindex", "0")
|
|
52
|
+
self.content.setAttribute("data-state", "active")
|
|
53
|
+
self.content.setAttribute("style", "display: block")
|
|
54
|
+
else:
|
|
55
|
+
self.trigger.setAttribute("aria-selected", "false")
|
|
56
|
+
self.trigger.setAttribute("data-state", "inactive")
|
|
57
|
+
self.trigger.setAttribute("tabindex", "-1")
|
|
58
|
+
self.content.setAttribute("data-state", "inactive")
|
|
59
|
+
self.content.setAttribute("style", "display: none")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@js
|
|
63
|
+
class TabGroup(Widget):
|
|
64
|
+
def __init__(self, *tabs: Tab, default_value: str):
|
|
65
|
+
super().__init__()
|
|
66
|
+
tab_list = tag(
|
|
67
|
+
"div",
|
|
68
|
+
tw("inline-flex h-9 w-fit items-center rounded-lg bg-slate-100 p-1"),
|
|
69
|
+
{
|
|
70
|
+
"aria-orientation": "horizontal",
|
|
71
|
+
"data-slot": "tabs-list",
|
|
72
|
+
"role": "tablist",
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
contents: list[HTMLElement] = []
|
|
76
|
+
group_id = self.get_component_id()
|
|
77
|
+
tab_index = 0
|
|
78
|
+
for tab in tabs:
|
|
79
|
+
tab.link(group_id + "-tab-" + str(tab_index))
|
|
80
|
+
tab.set_active(tab.value == default_value)
|
|
81
|
+
tab_list.append(tab.trigger)
|
|
82
|
+
contents.append(tab.content)
|
|
83
|
+
tab_index += 1
|
|
84
|
+
self.add(
|
|
85
|
+
tw("block w-full"),
|
|
86
|
+
{"data-slot": "tabs", "value": default_value},
|
|
87
|
+
tab_list,
|
|
88
|
+
*contents,
|
|
89
|
+
)
|
|
90
|
+
self.addEventListener("click", self.clicked)
|
|
91
|
+
self.addEventListener("keydown", self.keydown)
|
|
92
|
+
|
|
93
|
+
def current_value(self) -> str:
|
|
94
|
+
value = self.getAttribute("value")
|
|
95
|
+
if value is None:
|
|
96
|
+
return ""
|
|
97
|
+
return value
|
|
98
|
+
|
|
99
|
+
def select(self, value: str, focus: bool = False):
|
|
100
|
+
triggers: list[HTMLElement] = self.querySelectorAll("[data-slot=tabs-trigger]")
|
|
101
|
+
contents = self.querySelectorAll("[data-slot=tabs-content]")
|
|
102
|
+
for trigger in triggers:
|
|
103
|
+
active = trigger.getAttribute("data-value") == value
|
|
104
|
+
trigger.setAttribute("aria-selected", "true" if active else "false")
|
|
105
|
+
trigger.setAttribute("data-state", "active" if active else "inactive")
|
|
106
|
+
trigger.setAttribute("tabindex", "0" if active else "-1")
|
|
107
|
+
if active and focus:
|
|
108
|
+
trigger.focus()
|
|
109
|
+
for content in contents:
|
|
110
|
+
active = content.getAttribute("data-value") == value
|
|
111
|
+
content.setAttribute("data-state", "active" if active else "inactive")
|
|
112
|
+
content.setAttribute("style", "display: block" if active else "display: none")
|
|
113
|
+
self.setAttribute("value", value)
|
|
114
|
+
|
|
115
|
+
def clicked(self, event: Event):
|
|
116
|
+
target: Element = event.target
|
|
117
|
+
trigger = target.closest("[data-slot=tabs-trigger]")
|
|
118
|
+
if trigger is not None:
|
|
119
|
+
value = trigger.getAttribute("data-value")
|
|
120
|
+
if value is not None:
|
|
121
|
+
self.select(value)
|
|
122
|
+
|
|
123
|
+
def keydown(self, event: KeyboardEvent):
|
|
124
|
+
if (
|
|
125
|
+
event.key != "ArrowLeft"
|
|
126
|
+
and event.key != "ArrowRight"
|
|
127
|
+
and event.key != "Home"
|
|
128
|
+
and event.key != "End"
|
|
129
|
+
):
|
|
130
|
+
return
|
|
131
|
+
target: Element = event.target
|
|
132
|
+
trigger = target.closest("[data-slot=tabs-trigger]")
|
|
133
|
+
if trigger is None:
|
|
134
|
+
return
|
|
135
|
+
triggers: list[HTMLElement] = self.querySelectorAll("[data-slot=tabs-trigger]")
|
|
136
|
+
first_trigger: HTMLElement | None = None
|
|
137
|
+
last_trigger: HTMLElement | None = None
|
|
138
|
+
previous_trigger: HTMLElement | None = None
|
|
139
|
+
following_trigger: HTMLElement | None = None
|
|
140
|
+
found_current = False
|
|
141
|
+
for item in triggers:
|
|
142
|
+
if first_trigger is None:
|
|
143
|
+
first_trigger = item
|
|
144
|
+
if item is trigger:
|
|
145
|
+
found_current = True
|
|
146
|
+
previous_trigger = last_trigger
|
|
147
|
+
elif found_current and following_trigger is None:
|
|
148
|
+
following_trigger = item
|
|
149
|
+
last_trigger = item
|
|
150
|
+
next_trigger: HTMLElement | None = None
|
|
151
|
+
if event.key == "Home":
|
|
152
|
+
next_trigger = first_trigger
|
|
153
|
+
elif event.key == "End":
|
|
154
|
+
next_trigger = last_trigger
|
|
155
|
+
elif event.key == "ArrowLeft":
|
|
156
|
+
next_trigger = previous_trigger
|
|
157
|
+
if next_trigger is None:
|
|
158
|
+
next_trigger = last_trigger
|
|
159
|
+
else:
|
|
160
|
+
next_trigger = following_trigger
|
|
161
|
+
if next_trigger is None:
|
|
162
|
+
next_trigger = first_trigger
|
|
163
|
+
event.preventDefault()
|
|
164
|
+
if next_trigger is not None:
|
|
165
|
+
value = next_trigger.getAttribute("data-value")
|
|
166
|
+
if value is not None:
|
|
167
|
+
self.select(value, focus=True)
|
pyjs/web/ui/text.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import ProxyElement, span
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
class Text(ProxyElement):
|
|
7
|
+
def __init__(self, text: str):
|
|
8
|
+
self.element = span(text)
|
|
9
|
+
|
|
10
|
+
def get_content(self) -> str:
|
|
11
|
+
return self.element.textContent.strip()
|
|
12
|
+
|
|
13
|
+
def set_content(self, text: str) -> str:
|
|
14
|
+
self.element.textContent = text
|
|
15
|
+
return text
|
pyjs/web/ui/textarea.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import ProxyElement, textarea, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
class Textarea(ProxyElement):
|
|
7
|
+
def __init__(self, placeholder: str = "", name: str = ""):
|
|
8
|
+
self.element = textarea(
|
|
9
|
+
tw(
|
|
10
|
+
"flex min-h-24 w-full rounded-md border border-slate-300 bg-white px-3 py-2 "
|
|
11
|
+
"text-sm text-slate-950 shadow-sm outline-none placeholder:text-slate-400 "
|
|
12
|
+
"focus:border-slate-500 focus:ring-2 focus:ring-slate-200 disabled:cursor-not-allowed "
|
|
13
|
+
"disabled:opacity-50 aria-invalid:border-red-500 aria-invalid:ring-red-100"
|
|
14
|
+
),
|
|
15
|
+
{"data-slot": "textarea", "name": name, "placeholder": placeholder},
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def get_value(self) -> str:
|
|
19
|
+
return self.element.value
|
|
20
|
+
|
|
21
|
+
def set_value(self, value: str):
|
|
22
|
+
self.element.value = value
|
|
23
|
+
|
|
24
|
+
def set_invalid(self, invalid: bool):
|
|
25
|
+
self.element.setAttribute("aria-invalid", "true" if invalid else "false")
|
|
26
|
+
|
|
27
|
+
def on_input(self, callback: callable):
|
|
28
|
+
self.element.addEventListener("input", callback)
|
pyjs/web/ui/toggle.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.dom import Element
|
|
3
|
+
from pyjs.web.domx import ProxyElement, button, tw
|
|
4
|
+
from pyjs.web.events import Event
|
|
5
|
+
from pyjs.web.html import HTMLElement
|
|
6
|
+
from pyjs.web.ui import Widget
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@js
|
|
10
|
+
class Toggle(ProxyElement):
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
*children: object,
|
|
14
|
+
value: str | None = None,
|
|
15
|
+
pressed: bool = False,
|
|
16
|
+
variant: str = "default",
|
|
17
|
+
size: str = "default",
|
|
18
|
+
):
|
|
19
|
+
self.element = button(
|
|
20
|
+
tw(
|
|
21
|
+
"inline-flex h-9 items-center justify-center rounded-md px-3 text-sm font-medium "
|
|
22
|
+
"text-slate-700 outline-none transition-colors hover:bg-slate-100 "
|
|
23
|
+
"focus-visible:ring-2 focus-visible:ring-slate-400 disabled:opacity-50 "
|
|
24
|
+
"data-[state=on]:bg-slate-200 data-[state=on]:text-slate-950 "
|
|
25
|
+
"data-[variant=outline]:border data-[variant=outline]:border-slate-300 "
|
|
26
|
+
"data-[variant=outline]:bg-white data-[size=sm]:h-8 data-[size=sm]:px-2.5 "
|
|
27
|
+
"data-[size=lg]:h-10 data-[size=lg]:px-4"
|
|
28
|
+
),
|
|
29
|
+
{
|
|
30
|
+
"data-size": size,
|
|
31
|
+
"data-slot": "toggle",
|
|
32
|
+
"data-variant": variant,
|
|
33
|
+
"type": "button",
|
|
34
|
+
},
|
|
35
|
+
*children,
|
|
36
|
+
)
|
|
37
|
+
if value is not None:
|
|
38
|
+
self.element.setAttribute("data-value", value)
|
|
39
|
+
self.set_pressed(pressed)
|
|
40
|
+
self.element.addEventListener("click", self.clicked)
|
|
41
|
+
|
|
42
|
+
def is_pressed(self) -> bool:
|
|
43
|
+
return self.element.getAttribute("aria-pressed") == "true"
|
|
44
|
+
|
|
45
|
+
def set_pressed(self, pressed: bool):
|
|
46
|
+
self.element.setAttribute("aria-pressed", "true" if pressed else "false")
|
|
47
|
+
self.element.setAttribute("data-state", "on" if pressed else "off")
|
|
48
|
+
|
|
49
|
+
def clicked(self, event: Event):
|
|
50
|
+
self.set_pressed(not self.is_pressed())
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@js
|
|
54
|
+
class ToggleGroup(Widget):
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*items: Toggle,
|
|
58
|
+
multiple: bool = False,
|
|
59
|
+
orientation: str = "horizontal",
|
|
60
|
+
):
|
|
61
|
+
super().__init__()
|
|
62
|
+
current_value = ""
|
|
63
|
+
for item in items:
|
|
64
|
+
value = item.getAttribute("data-value")
|
|
65
|
+
if value is None:
|
|
66
|
+
raise ValueError("ToggleGroup items must define a value")
|
|
67
|
+
if item.is_pressed():
|
|
68
|
+
current_value = value
|
|
69
|
+
self.add(
|
|
70
|
+
tw(
|
|
71
|
+
"flex w-fit items-center gap-1 data-[orientation=vertical]:flex-col "
|
|
72
|
+
"data-[orientation=vertical]:items-stretch"
|
|
73
|
+
),
|
|
74
|
+
{
|
|
75
|
+
"data-multiple": "true" if multiple else "false",
|
|
76
|
+
"data-orientation": orientation,
|
|
77
|
+
"data-slot": "toggle-group",
|
|
78
|
+
"data-value": current_value,
|
|
79
|
+
"role": "group",
|
|
80
|
+
},
|
|
81
|
+
*items,
|
|
82
|
+
)
|
|
83
|
+
self.addEventListener("click", self.clicked)
|
|
84
|
+
|
|
85
|
+
def allows_multiple(self) -> bool:
|
|
86
|
+
return self.getAttribute("data-multiple") == "true"
|
|
87
|
+
|
|
88
|
+
def current_value(self) -> str:
|
|
89
|
+
value = self.getAttribute("data-value")
|
|
90
|
+
if value is None:
|
|
91
|
+
return ""
|
|
92
|
+
return value
|
|
93
|
+
|
|
94
|
+
def clicked(self, event: Event):
|
|
95
|
+
target: Element = event.target
|
|
96
|
+
selected = target.closest("[data-slot=toggle]")
|
|
97
|
+
if selected is None or self.allows_multiple():
|
|
98
|
+
return
|
|
99
|
+
if selected.getAttribute("aria-pressed") != "true":
|
|
100
|
+
self.setAttribute("data-value", "")
|
|
101
|
+
return
|
|
102
|
+
value = selected.getAttribute("data-value")
|
|
103
|
+
if value is not None:
|
|
104
|
+
self.setAttribute("data-value", value)
|
|
105
|
+
items: list[HTMLElement] = self.querySelectorAll("[data-slot=toggle]")
|
|
106
|
+
for item in items:
|
|
107
|
+
if item is not selected:
|
|
108
|
+
item.setAttribute("aria-pressed", "false")
|
|
109
|
+
item.setAttribute("data-state", "off")
|
pyjs/web/ui/tooltip.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.dom import document
|
|
3
|
+
from pyjs.web.domx import ProxyElement, button, ref, tw
|
|
4
|
+
from pyjs.web.events import Event, KeyboardEvent
|
|
5
|
+
from pyjs.web.ui import Widget
|
|
6
|
+
from pyjs.web.ui.floating import FloatingPanel, FloatingPosition
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@js
|
|
10
|
+
class TooltipTrigger(ProxyElement):
|
|
11
|
+
def __init__(self, *children):
|
|
12
|
+
self.element = button(
|
|
13
|
+
tw(
|
|
14
|
+
"inline-flex size-9 items-center justify-center rounded-md border "
|
|
15
|
+
"border-slate-300 bg-white text-sm font-medium text-slate-950 shadow-sm "
|
|
16
|
+
"hover:bg-slate-100 focus-visible:outline-none focus-visible:ring-2 "
|
|
17
|
+
"focus-visible:ring-slate-400"
|
|
18
|
+
),
|
|
19
|
+
{"data-slot": "tooltip-trigger", "type": "button"},
|
|
20
|
+
*children,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@js
|
|
25
|
+
class TooltipContent(FloatingPanel):
|
|
26
|
+
def __init__(self, *children):
|
|
27
|
+
super().__init__(
|
|
28
|
+
tw(
|
|
29
|
+
"pointer-events-none max-w-64 rounded-md bg-slate-950 px-3 py-1.5 "
|
|
30
|
+
"text-xs text-white shadow-md"
|
|
31
|
+
),
|
|
32
|
+
{"data-slot": "tooltip-content", "role": "tooltip"},
|
|
33
|
+
*children,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@js
|
|
38
|
+
class TooltipKeyListener:
|
|
39
|
+
def __init__(self, tooltip: Tooltip):
|
|
40
|
+
self.tooltip = tooltip
|
|
41
|
+
|
|
42
|
+
@js(include=True)
|
|
43
|
+
def handleEvent(self, event: KeyboardEvent):
|
|
44
|
+
if event.key == "Escape":
|
|
45
|
+
self.tooltip.close()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@js
|
|
49
|
+
class Tooltip(Widget):
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
trigger: TooltipTrigger,
|
|
53
|
+
content: TooltipContent,
|
|
54
|
+
*,
|
|
55
|
+
side: str = "top",
|
|
56
|
+
align: str = "center",
|
|
57
|
+
side_offset: int = 4,
|
|
58
|
+
):
|
|
59
|
+
super().__init__()
|
|
60
|
+
self.trigger = ref(trigger)
|
|
61
|
+
self.content = ref(content)
|
|
62
|
+
self.setAttribute("data-side", side)
|
|
63
|
+
self.setAttribute("data-align", align)
|
|
64
|
+
self.setAttribute("data-side-offset", str(side_offset))
|
|
65
|
+
|
|
66
|
+
self.link_content()
|
|
67
|
+
self.trigger.element.addEventListener("mouseenter", self.mouse_entered)
|
|
68
|
+
self.trigger.element.addEventListener("mouseleave", self.mouse_left)
|
|
69
|
+
self.trigger.element.addEventListener("focus", self.focused)
|
|
70
|
+
self.trigger.element.addEventListener("blur", self.blurred)
|
|
71
|
+
self.trigger.element.addEventListener("click", self.clicked)
|
|
72
|
+
self.add(
|
|
73
|
+
tw("inline-block"),
|
|
74
|
+
{"data-slot": "tooltip", "data-state": "closed"},
|
|
75
|
+
self.trigger,
|
|
76
|
+
self.content,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def link_content(self):
|
|
80
|
+
content_id = self.content.get_component_id() + "-content"
|
|
81
|
+
self.content.setAttribute("id", content_id)
|
|
82
|
+
described_by = self.trigger.getAttribute("aria-describedby")
|
|
83
|
+
if described_by is None:
|
|
84
|
+
self.trigger.setAttribute("aria-describedby", content_id)
|
|
85
|
+
return
|
|
86
|
+
ids = ""
|
|
87
|
+
for existing_id in described_by.split():
|
|
88
|
+
if existing_id != content_id:
|
|
89
|
+
duplicate = False
|
|
90
|
+
for added_id in ids.split():
|
|
91
|
+
if added_id == existing_id:
|
|
92
|
+
duplicate = True
|
|
93
|
+
if not duplicate:
|
|
94
|
+
if ids != "":
|
|
95
|
+
ids += " "
|
|
96
|
+
ids += existing_id
|
|
97
|
+
if ids != "":
|
|
98
|
+
ids += " "
|
|
99
|
+
self.trigger.setAttribute("aria-describedby", ids + content_id)
|
|
100
|
+
|
|
101
|
+
def initialize(self):
|
|
102
|
+
self.is_open = False
|
|
103
|
+
self.is_hovered = False
|
|
104
|
+
self.has_focus = False
|
|
105
|
+
self.key_listener = TooltipKeyListener(self)
|
|
106
|
+
|
|
107
|
+
def open(self) -> FloatingPosition:
|
|
108
|
+
side = self.getAttribute("data-side")
|
|
109
|
+
align = self.getAttribute("data-align")
|
|
110
|
+
side_offset = self.getAttribute("data-side-offset")
|
|
111
|
+
resolved_side = "top"
|
|
112
|
+
resolved_align = "center"
|
|
113
|
+
resolved_side_offset = 4
|
|
114
|
+
if side is not None:
|
|
115
|
+
resolved_side = side
|
|
116
|
+
if align is not None:
|
|
117
|
+
resolved_align = align
|
|
118
|
+
if side_offset is not None:
|
|
119
|
+
resolved_side_offset = int(side_offset)
|
|
120
|
+
position = self.content.open(
|
|
121
|
+
self.trigger.element,
|
|
122
|
+
side=resolved_side,
|
|
123
|
+
align=resolved_align,
|
|
124
|
+
side_offset=resolved_side_offset,
|
|
125
|
+
)
|
|
126
|
+
self.is_open = True
|
|
127
|
+
self.setAttribute("data-state", "open")
|
|
128
|
+
document.addEventListener("keydown", self.key_listener)
|
|
129
|
+
return position
|
|
130
|
+
|
|
131
|
+
def close(self):
|
|
132
|
+
if not self.is_open:
|
|
133
|
+
return
|
|
134
|
+
document.removeEventListener("keydown", self.key_listener)
|
|
135
|
+
self.content.close()
|
|
136
|
+
self.is_open = False
|
|
137
|
+
self.setAttribute("data-state", "closed")
|
|
138
|
+
|
|
139
|
+
def mouse_entered(self, event: Event):
|
|
140
|
+
self.is_hovered = True
|
|
141
|
+
if not self.is_open:
|
|
142
|
+
self.open()
|
|
143
|
+
|
|
144
|
+
def mouse_left(self, event: Event):
|
|
145
|
+
self.is_hovered = False
|
|
146
|
+
if not self.has_focus:
|
|
147
|
+
self.close()
|
|
148
|
+
|
|
149
|
+
def focused(self, event: Event):
|
|
150
|
+
self.has_focus = True
|
|
151
|
+
if not self.is_open:
|
|
152
|
+
self.open()
|
|
153
|
+
|
|
154
|
+
def blurred(self, event: Event):
|
|
155
|
+
self.has_focus = False
|
|
156
|
+
if not self.is_hovered:
|
|
157
|
+
self.close()
|
|
158
|
+
|
|
159
|
+
def clicked(self, event: Event):
|
|
160
|
+
self.close()
|
|
161
|
+
|
|
162
|
+
@js(include=True)
|
|
163
|
+
def disconnectedCallback(self):
|
|
164
|
+
self.close()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import a, p, tag, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
def TypographyH1(*children):
|
|
7
|
+
return tag("h1", tw("scroll-m-20 text-4xl font-extrabold tracking-tight"), *children)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@js
|
|
11
|
+
def TypographyH2(*children):
|
|
12
|
+
return tag(
|
|
13
|
+
"h2",
|
|
14
|
+
tw(
|
|
15
|
+
"scroll-m-20 border-b border-slate-200 pb-2 text-3xl font-semibold tracking-tight"
|
|
16
|
+
),
|
|
17
|
+
*children,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@js
|
|
22
|
+
def TypographyH3(*children):
|
|
23
|
+
return tag("h3", tw("scroll-m-20 text-2xl font-semibold tracking-tight"), *children)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@js
|
|
27
|
+
def TypographyH4(*children):
|
|
28
|
+
return tag("h4", tw("scroll-m-20 text-xl font-semibold tracking-tight"), *children)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@js
|
|
32
|
+
def TypographyP(*children):
|
|
33
|
+
return p(tw("leading-7 [&:not(:first-child)]:mt-6"), *children)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@js
|
|
37
|
+
def TypographyBlockquote(*children):
|
|
38
|
+
return tag(
|
|
39
|
+
"blockquote", tw("mt-6 border-l-2 border-slate-300 pl-6 italic"), *children
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@js
|
|
44
|
+
def TypographyList(*children):
|
|
45
|
+
return tag("ul", tw("my-6 ml-6 list-disc [&>li]:mt-2"), *children)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@js
|
|
49
|
+
def TypographyInlineCode(*children):
|
|
50
|
+
return tag(
|
|
51
|
+
"code",
|
|
52
|
+
tw("rounded bg-slate-100 px-1.5 py-1 font-mono text-sm font-semibold"),
|
|
53
|
+
*children,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@js
|
|
58
|
+
def TypographyLead(*children):
|
|
59
|
+
return p(tw("text-xl text-slate-500"), *children)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@js
|
|
63
|
+
def TypographyLarge(*children):
|
|
64
|
+
return tag("div", tw("text-lg font-semibold"), *children)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@js
|
|
68
|
+
def TypographySmall(*children):
|
|
69
|
+
return tag("small", tw("text-sm font-medium leading-none"), *children)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@js
|
|
73
|
+
def TypographyMuted(*children):
|
|
74
|
+
return p(tw("text-sm text-slate-500"), *children)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@js
|
|
78
|
+
def TypographyLink(href: str, *children):
|
|
79
|
+
return a(tw("font-medium underline underline-offset-4"), {"href": href}, *children)
|
pyjs/web/url.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.files import Blob
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js(builtin=True)
|
|
6
|
+
class MediaSource:
|
|
7
|
+
"""WebIDL source: @webref/idl/media-source.idl
|
|
8
|
+
|
|
9
|
+
MDN: https://developer.mozilla.org/docs/Web/API/MediaSource
|
|
10
|
+
|
|
11
|
+
Browser support: Chrome 31, Safari 8"""
|
|
12
|
+
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@js(builtin=True)
|
|
17
|
+
class URL:
|
|
18
|
+
"""WebIDL source: @webref/idl/url.idl
|
|
19
|
+
|
|
20
|
+
MDN: https://developer.mozilla.org/docs/Web/API/URL
|
|
21
|
+
|
|
22
|
+
Browser support: Chrome 32, Safari 7"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, url: str, base: str | None = None):
|
|
25
|
+
self.hash: str = ""
|
|
26
|
+
self.host: str = ""
|
|
27
|
+
self.hostname: str = ""
|
|
28
|
+
self.href: str = ""
|
|
29
|
+
self.origin: str = ""
|
|
30
|
+
self.password: str = ""
|
|
31
|
+
self.pathname: str = ""
|
|
32
|
+
self.port: str = ""
|
|
33
|
+
self.protocol: str = ""
|
|
34
|
+
self.search: str = ""
|
|
35
|
+
self.searchParams: URLSearchParams = None
|
|
36
|
+
self.username: str = ""
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def canParse(url: str, base: str | None = None) -> bool: ...
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def createObjectURL(obj: Blob | MediaSource) -> str: ...
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def parse(url: str, base: str | None = None) -> URL | None: ...
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def revokeObjectURL(url: str) -> None: ...
|
|
49
|
+
|
|
50
|
+
def toJSON(self) -> str: ...
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@js(builtin=True)
|
|
54
|
+
class URLSearchParams:
|
|
55
|
+
"""WebIDL source: @webref/idl/url.idl
|
|
56
|
+
|
|
57
|
+
MDN: https://developer.mozilla.org/docs/Web/API/URLSearchParams
|
|
58
|
+
|
|
59
|
+
Browser support: Chrome 49, Safari 10.1"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, init: list[list[str]] | dict[str, str] | str = ""):
|
|
62
|
+
self.size: int = 0
|
|
63
|
+
|
|
64
|
+
def append(self, name: str, value: str) -> None: ...
|
|
65
|
+
|
|
66
|
+
def delete(self, name: str, value: str | None = None) -> None: ...
|
|
67
|
+
|
|
68
|
+
def get(self, name: str) -> str | None: ...
|
|
69
|
+
|
|
70
|
+
def getAll(self, name: str) -> list[str]: ...
|
|
71
|
+
|
|
72
|
+
def has(self, name: str, value: str | None = None) -> bool: ...
|
|
73
|
+
|
|
74
|
+
def set(self, name: str, value: str) -> None: ...
|
|
75
|
+
|
|
76
|
+
def sort(self) -> None: ...
|