This commit is contained in:
Fabio Pliger
2024-02-12 14:47:36 -06:00
parent ae3c36b5dd
commit 83d17a75ba
13 changed files with 74 additions and 22 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
# Global attributes that all elements have (this list is a subset of the official one)
# and tries to capture the most used ones
GLOBAL_ATTRIBUTES = [
@@ -28,19 +29,47 @@ GLOBAL_ATTRIBUTES = [
# class and style are different ones that are handled by pydom.element directly
CUSTOM_ATTRIBUTES = {
'a': ['download', 'href', 'referrerpolicy', 'rel', 'target', 'type'],
'td': ['colspan', 'headers', 'rowspan'],
'template': ['shadowrootmode'],
'textarea': ['autocapitalize', 'autocomplete', 'autofocus', 'cols', 'dirname', 'disabled',
'form', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly',
'required', 'rows', 'spellcheck', 'wrap'],
'tr': ['abbr', 'colspan', 'headers', 'rowspan', 'scope'],
'time': ['datetime'],
'video': ['autoplay', 'controls', 'crossorigin', 'disablepictureinpicture',
'disableremoteplayback', 'height', 'loop', 'muted', 'playsinline',
'poster', 'preload', 'src', 'width'],
"a": ["download", "href", "referrerpolicy", "rel", "target", "type"],
"td": ["colspan", "headers", "rowspan"],
"template": ["shadowrootmode"],
"textarea": [
"autocapitalize",
"autocomplete",
"autofocus",
"cols",
"dirname",
"disabled",
"form",
"maxlength",
"minlength",
"name",
"placeholder",
"readonly",
"required",
"rows",
"spellcheck",
"wrap",
],
"tr": ["abbr", "colspan", "headers", "rowspan", "scope"],
"time": ["datetime"],
"video": [
"autoplay",
"controls",
"crossorigin",
"disablepictureinpicture",
"disableremoteplayback",
"height",
"loop",
"muted",
"playsinline",
"poster",
"preload",
"src",
"width",
],
}
class ElementBase(pydom.Element):
tag = "div"
@@ -491,8 +520,19 @@ class iframe(TextElementBase):
# code tags only have the global attributes ones
_add_js_properties(iframe, "allow", "allowfullscreen", "height", "loading", "name",
"referrerpolicy", "sandbox", "src", "srcdoc", "width")
_add_js_properties(
iframe,
"allow",
"allowfullscreen",
"height",
"loading",
"name",
"referrerpolicy",
"sandbox",
"src",
"srcdoc",
"width",
)
class img(ElementBase):

View File

@@ -1,8 +1,9 @@
"""Markdown module to generate web/HTML components from Markdown code"""
from pyscript import document, window
from pyweb import pydom
from pyweb.ui.elements import TextElementBase, script
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

@@ -2,13 +2,14 @@ from textwrap import dedent
import examples
import styles
from pyscript import when, window
from pyweb import pydom
from pyweb.ui import elements as el
from pyweb.ui import shoelace
from pyweb.ui.elements import a, button, div, grid, h1, h2, h3, input_
from pyweb.ui.markdown import markdown
from pyscript import when, window
MAIN_PAGE_MARKDOWN = dedent(
"""
## What is pyweb.ui?

View File

@@ -1,4 +1,3 @@
from pyscript import when, window
from pyweb import pydom
from pyweb.ui.elements import (
a,
@@ -41,6 +40,8 @@ from pyweb.ui.shoelace import (
Textarea,
)
from pyscript import when, window
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,12 +3,13 @@ from textwrap import dedent
import styles
import tictactoe
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
MAIN_PAGE_MARKDOWN = dedent(
"""
This gallery is a collection of demos using the PyWeb.UI library. There are meant

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)