precommit fixes

This commit is contained in:
Fabio Pliger
2024-01-31 17:31:11 -06:00
parent ac1cf5fe66
commit cffee1d680
12 changed files with 51 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ import sys
import js as globalThis
from polyscript import js_modules
from pyscript.util import NotSupported
RUNNING_IN_WORKER = not hasattr(globalThis, "document")

View File

@@ -1,4 +1,5 @@
from pyodide.ffi import to_js
from pyscript import window

View File

@@ -1,8 +1,9 @@
from textwrap import dedent
from pyscript import document, when, window
from pyweb import JSProperty, js_property, pydom
from pyscript import document, when, window
class ElementBase(pydom.Element):
tag = "div"
@@ -188,7 +189,7 @@ class div(TextElementBase):
class img(ElementBase):
tag = "img"
src = js_property("src")
# TODO: This should probably go on the ElementBase class since it's a global attribtute
# TODO: This should probably go on the ElementBase class since it's a global attribute
# https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/slot
slot = js_property("slot")

View File

@@ -1,7 +1,8 @@
"""Markdown module to generate web/HTML components from Markdown code"""
from pyscript import document, window
from pyweb.ui.elements import TextElementBase
from pyscript import document, window
class markdown(TextElementBase):
"""Markdown component to render HTML from Markdown code"""

View File

@@ -1,10 +1,11 @@
import string
from textwrap import dedent
from pyscript import document, when, window
from pyweb import JSProperty, js_property, pydom
from pyweb.ui import elements as el
from pyscript import document, when, window
class ShoeBase(pydom.Element):
tag = "div"

View File

@@ -1,7 +1,8 @@
from pyodide.ffi import create_proxy
from pyscript import display, document, when, window
from pyweb import media, pydom
from pyscript import display, document, when, window
devicesSelect = pydom["#devices"][0]
video = pydom["video"][0]
devices = {}

View File

@@ -2,9 +2,10 @@ import random
import time
from datetime import datetime as dt
from pyscript import display, when
from pyweb import pydom
from pyscript import display, when
@when("click", "#just-a-button")
def on_click():

View File

@@ -1,5 +1,6 @@
print("tests starting")
import pytest
from pyscript import window
args = window.location.search.replace("?", "").split("&")

View File

@@ -1,9 +1,10 @@
from unittest import mock
import pytest
from pyscript import document, when
from pyweb import pydom
from pyscript import document, when
class TestDocument:
def test__element(self):

View File

@@ -1,12 +1,13 @@
from textwrap import dedent
import examples
from pyscript import when, window
from pyweb import pydom
from pyweb.ui import elements as el
from pyweb.ui import shoelace
from pyweb.ui.markdown import markdown
from pyscript import when, window
# Style dictionary for code blocks
STYLE_CODE_BLOCK = {"text-align": "left", "background-color": "#eee", "padding": "20px"}
@@ -27,29 +28,37 @@ def create_component_details(component):
"""
# Get the example from the examples catalog
examples_gallery = examples.kits['shoelace']
examples_gallery = examples.kits["shoelace"]
example = examples_gallery[component]["instance"]
details = example.__doc__ or f"Details missing for component {component}"
div = el.div([
# Title and description (description is picked from the class docstring)
el.h1(component),
markdown(details),
# Example section
el.h2("Example:"),
el.div([
example,
shoelace.Details(
el.div(examples_gallery[component]["code"], style=STYLE_CODE_BLOCK),
summary="View Code", style={"background-color": "gainsboro"},
),
],
style={
"border-radius": "3px",
"background-color": "var(--sl-color-neutral-50)",
"margin-bottom": "1.5rem"
}
)], style={"margin": "20px"})
div = el.div(
[
# Title and description (description is picked from the class docstring)
el.h1(component),
markdown(details),
# Example section
el.h2("Example:"),
el.div(
[
example,
shoelace.Details(
el.div(
examples_gallery[component]["code"], style=STYLE_CODE_BLOCK
),
summary="View Code",
style={"background-color": "gainsboro"},
),
],
style={
"border-radius": "3px",
"background-color": "var(--sl-color-neutral-50)",
"margin-bottom": "1.5rem",
},
),
],
style={"margin": "20px"},
)
return div
@@ -68,12 +77,14 @@ def add_component_section(component, parent_div):
el.a(component, href="#"),
style={"display": "block", "text-align": "center", "margin": "auto"},
)
# Create a handler that opens the component details when the link is clicked
@when("click", div)
def _change():
new_main = create_component_details(component)
main_area.html = ""
main_area.append(new_main)
# Add the new link element to the parent div (left panel)
parent_div.append(div)
return div

View File

@@ -1,4 +1,3 @@
from pyscript import when
from pyweb import pydom
from pyweb.ui import elements as el
from pyweb.ui.shoelace import (
@@ -12,6 +11,8 @@ from pyweb.ui.shoelace import (
Rating,
)
from pyscript import when
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
details_code = """
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."

View File

@@ -3,6 +3,7 @@ import js
js.document.body.append("document patch ")
import a
from pyscript import RUNNING_IN_WORKER, display, sync
display("Hello World", target="test", append=True)