* Minor cleanups: move all Element classes to bottom of module.
* Commenting.
* Commenting.
* Commenting.
* Group dunder methods.
* Don't cache the element's parent.
* Remove style type check until we decide whether or not to add for classes too.
* Add ability to register/unregister element classes.
* Implement __iter__ for container elements.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Minor renaming to make it clear when we have an Element instance vs an actual DOM element.
* remove duplication: added Element.get_tag_name
* Commenting.
* Allow Element.append to 1) use *args, 2) accept iterables
* Remove iterable check - inteferes with js proxies.
* Don't use *args, so it quacks more like a list ;)
* Element.append take 2 :)
* Remove unused code.
* Move to web.py with a page object!
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Added 'page.title' too :)
* Add __getitem__ as a shortcut for page.find
* Add Element.__getitem__ to be consistent
* Make __getitem__ consistent for Page, Element and ElementCollection.
* Docstringing.
* Docstringing.
* Docstringing/commenting.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix select.add (revert InnerHTML->html)
* Commenting.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Hand-edit some of the AI :)
* Rename ElementCollection.children -> ElementCollection.elements
* Remove unnecessary guard.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* change pydom example to use new pyscript.web namespace
* change tests to use new pyscript.web namespace
* create new pyscript.web package and move pydom to pyscript.web.dom
* add __init__ to pyscript.web and expose the dom instance instead of the pyscript.web.dom module
* move elements from pyweb.ui to pyscript.web and temp fix pydom import
* moved of elements file completed
* moved media from pyweb to pyscript.web
* RIP pyweb
* move JSProperty from pyscript.web.dom to pyscript.web.elements
* move element classes from pyscript.web.dom to pyscript.web.elements
* first round of fixes while running tests
* fix test typo
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* restore right type type returned for Element.parent. ALL TESTS PASS LOCALLY NOW
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean up dom.py from dead commented code and osbolete comments
* bugfix: dom shouldn't return None when it can't find any element for a specific selector so it now returns an empty collection
* additional cleanup in tests
* lint
* initial cleaning up of unused modules
* change element.append to not consider types anymore and add tests for appending elements.Element or a JsProxy object
* add Element.append tests for append JS elements directly and appending nodeList as well
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Tag and create the correct subclass of Element.
* Move: Element.snap -> video.snap
* Move: Element.download and draw to canvas.download and draw.
* Minor cleanups.
* Commenting.
* Allow css classes to be passed to Element constructor.
* Commenting.
* Typo fix.
* Make html, id and text JSProperties.
* Commenting.
* Remove unnecessary selected attribute on BaseElement.
* Extract: BaseElement.from_js -> element_from_js
* Pass *args and **kwargs to element_from_js and remove BaseElement.create
* Move value attribute to specific Element subclasses.
* fix: wrapping of existing js elements.
* Add body and head elements so parent and children work everywhere.
* Revert order of HasOptions mixin for the select element.
* Comment out tests that are no longer relevant (see comment).
* Use correct super args in mixin.
* Have to use element_from_js when returning options from OptionsProxy.
* rename: StyleProxy -> Style, OptionsProxy -> Options and added Classes.
* Remove cached_property.
* Remove list-y methods from Classes collection.
* Allow explicit children or *args for containers.
* controversial: fix tests to use find rather than dom
* Add html element so (say) body.parent does what is expected.
* Collapse Element class hierarchy.
* rename: js_element -> dom_element
* rename: element_from_js -> element_from_dom
* replace: JS with DOM
* rename: _js -> _dom_element
* fix dom tests.
* Complete element list with void elements derived from Element.
* Added attributes to the newly added Element subclasses.
* remove dom module, replace with instance.
Also, remove media :)
* fix: typo in test for 'b' element.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove dom and media modules.
* fix up ts definitions.
* Added missing import (used in content property).
* Added TODO :)
* wip: Add ClassesCollection
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Attempt to ask black to leave class list alone.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add classes attribute to ElementCollection
* wip: work on classes collection
* Extract code to get set of all class names in ClassesCollection.
* Update elements.py
* Polishing.
* Make children return an ElementCollection
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* wip: Add the ability to set multiple properties.
* Add __getitem__ back to the dom object.
* Put validation when setting DOM properties back in.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* All tests green.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove unnecessary comment.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Martin <martin.chilvers@gmail.com>
* change pydom example to use new pyscript.web namespace
* change tests to use new pyscript.web namespace
* create new pyscript.web package and move pydom to pyscript.web.dom
* add __init__ to pyscript.web and expose the dom instance instead of the pyscript.web.dom module
* move elements from pyweb.ui to pyscript.web and temp fix pydom import
* moved of elements file completed
* moved media from pyweb to pyscript.web
* RIP pyweb
* move JSProperty from pyscript.web.dom to pyscript.web.elements
* move element classes from pyscript.web.dom to pyscript.web.elements
* first round of fixes while running tests
* fix test typo
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* restore right type type returned for Element.parent. ALL TESTS PASS LOCALLY NOW
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean up dom.py from dead commented code and osbolete comments
* bugfix: dom shouldn't return None when it can't find any element for a specific selector so it now returns an empty collection
* additional cleanup in tests
* lint
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* add JSProperty to pydom so it can be used to create descriptors mapping to specific JS attributes
* add pyweb.ui
* fix pyweb imports
* fix link and a elements and add a script element
* fix imports and add initialization to load resources to shoelace module
* new pyweb.ui test folder
* remove comments
* add Icon to shoelace components
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* use html property rather than accessing _js directly
* add markdown suppport
* move examples section out of stdlib pyweb to examples.py in the demo itself
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* simplify demo code
* improve docstrings
* precommit fixes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* simplify code for main page
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add load_resources to markdown
* add showlace extra style dynamically
* precommit
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add gallery files
* add global attributes and dynamic property assignment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add shoelace radio component (#1961)
* add shoelace radio component
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* fix type that lead using the the JSDescriptor directly instead of the factory method
* add missing marked dependency
* refactor gallary to simplify codebase
* precommig lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add text attribute to pydom Elements
* add global JS attributes to elements and improve demos
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix image instantiation on card since the API has changed
* add attributes to all classes in elements
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* change example creation functions to take the label and the object directly
* fix input name clashing with input keyword
* refactor examples to better simplify and automate
* fix div clashing names
* fix demo left menu width
* simplify base elements demo by moving all the examples to the examples module
* rename Grid to grid to align to other elements
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reorg classes order in elements.py and add missing elements to examples
* fix issue related to now importing div from pyweb.ui
* improve demo
* link and fix spelling typo
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add a bunch more elements (#1966)
* Add copy button
* Add skeleton and spinner
* Add Switch
* Add text area
* Add more elements
* More styling to each component
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabio Pliger <fpliger@users.noreply.github.com>
* Add radio group (#1963)
* add radio group
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabio Pliger <fpliger@users.noreply.github.com>
* Small tweaks to main demo page (#1962)
* Small tweaks to main demo page
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabio Pliger <fpliger@users.noreply.github.com>
* fix post merge issues
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixed issues with renaming Grid to grid, after we merged
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add multple HTML elements in alphabetical order from abbr to em
* fix attributes of some of the elements added in the previous commit and add embed
* fix embed attributes and add fieldset
* add figcation, figure and form. Also fix ordering of definitoin of img and input_
* add style and lint
* wrap up adding all major html elements
* fix test failing due to different error message from fake server compared to a real test server
* change default docstring associated with all classes dynamically patched
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add pyweb tests
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add global attributes and change abbr test
* fix abbr to inherit from TextElementBase
* add address test and improve error messaging when ElementBase gets a bad input as style
* change test helper function to be more flexible on attributes and manage content vs non content based elements. Also adds area tests
* add test for more elements up to caption
* fix canvas and caption as elements that have content and fix name typo on figcaption
* fix another typo on figcaption
* minor fixes and complete tests for all elements
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* adapt shoelace to latest upates in ui.elements
* fix issue with example code not showing created button
* move global attributes to base class
* replace all the calls to _add_js_properties with defining attributes directly in the classes
* finish moving all properties manually on each class
* remove _add_js_properties
* replace JSProperty with js_property
* replace JSProperty with js_property
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixed merge conflicts
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* remove js_property and just use JSProperty with name and allow_nones as arguments
* fix bug around Element not being able to map global attributes in subclasses
* remove js_property and fix references
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* precommit
* precommit again
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* enable pyweb on micropython
* switch examples to micropython
* fix pydom issue with micropython, created by the monkeypatch around JsProxy
* print micropython version on micropython pydom example
* lint and remove of textwrap in stdlib for micropython compatibility
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* added msising attributes on the option Element. Tests are all passing now
* fix tests
* lint
* temp ugly fix for micropython, using the when decorator with a function without arguments
* small fixes and improvements to examples
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix examples and broken link from the removal of markdown and shoelace from stdlib
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* dynamically change the server address in tests
* use the right element in test_a
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* skipping test_audio in CI due to different behavior of fake_server vs a real server, that runs in local tests
* add conditional expected_missing_file_errors property to manage different behaviour between local tests and CI (due to fake_server)
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Askat <aaskat@users.noreply.github.com>
Co-authored-by: Fábio Rosado <hello@fabiorosado.dev>
Co-authored-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
* fix pydom example
* fix the pydom test example to use a python syntax that works with MicroPython by replacing datetime
* add note about capturing errors importing when
* patch event_handler to handle compat with micropython
* turn pyweb into a package and remove hack to make pydom a sort of module with an ugly hack
* add pydom example using micropython
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix select element test
* change pydom test page to let pytest tests load it properly
* add missing folders to test dev server so it can run examples in the manual tests folder
* add pydom tests to the test suite as integration tests
* lint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* improve fixes in event_handling
* change when decorator to actually dynamically fail in micropython and support handlers with or without arguments
* simplify when decorator code
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add type declaration back for the MP use case
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* removed code to access pydom get index as I can't think of any proper use case
* remove old commented hack to replace pydom module with class
* fix examples title
* precommit checks
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This MR shows errors and exit in these conditions:
* multiple `<py-config>` or `<mpy-config>` found on the page
* both `<py-config>` and `<script type="py" config="file.toml">` found on main
* different `<script type="py" config="a.toml">` and `<script type="py" config="b.toml">` configs found on main
* add tests to verify if we show an error banner when users load from latest
* add deprecation manager to take care of showing a notification in case script src is being loaded from latest
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* make sure deprecation warning also register onWorker
* restore tests for banner in worker
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* add a wait selector when testing banner since worker seems to take too long to render in CI
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix test_deprecate_loading_scripts_from_latest: I think that the
previous failure was because we actually TRIED to execute the js from
latest/core.js and it conflicted with our local copy.
But to trigger the warning is enough to have a script pointing to
pyscript.net/latest, there is no need to execute it: modify it with
type="ignore-me" and an URL which doesn't exist.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
pre-commit.ci has been disabled for a while.
This PR ensures that all the files has been validated/formatted by pre-commit, to avoid spurious diffs in subsequent PRs.
During the process, ruff broke the code because it removed an "unused" import which was actually used.
A linter which breaks my code is a linter which I cannot trust, so I just removed it. I re-enabled isort instead.
* blacked
* More robust code for display, with tests
Display now includes more robust controls when checking
the input target parameters, with appropriate exception raised
(i.e. ValueError or TypeError) whether target is either
an empty string, or a not-string, not-None type, respectively.
The TypeError aligns with other similar behaviour with other Pyton
functions (e.g. str.split with integer separator).
Also, now display raises a ValueError whether the target element
is not found or not existing.
All changes are supported by tests.
* traceback lines in check_py_error & removed clones
check_py_error function now automatically includes
check of the traceback in console errors.
This way tests in basic and display have been refactored,
and lots of duplicated code removed.
* removed useless console check lines.
If check_py_errors function is running, those
console log lines are useless to check.
This re-enables CI tests on every PR 🎉.
This uses make test-integration, which runs tests sequentially.
In theory, we also have test-integration-parallel but it seems to be very flaky: many tests randomly timeout. I didn't spend too much time investigating this, it's probably worth its own investigation in a separate PR, but for now it's important to re-enable CI tests, even if they are a bit slower.
This PR re-enables tests on `worker`s. Highlights:
* by default, each test is run twice: the main thread version uses `<script type="py">`, the worker version automatically turn the tags into `<script type="py" worker>`
* you can tweak the settings per-class by using the `@with_execution_thread` decorator. In particular, `@with_execution_thread(None)` is for those tests which don't care about it (e.g., `test_py_config.py`)
* inside each class, there might be some test which should be run only in the main thread (because it doesn't make sense to test it in a worker). For those, I introduced the `@only_main` decorator
* we might introduce `@only_worker` in the future, if needed
* `@skip_worker` is for those tests which currently pass on main but not on workers. These are meant to be temporary, and eventually they should all be fixed
During the process, I tweaked/improved/fixed/deleted some of the existing tests. Some of them were at risk of being flaky and I made them more robust, others depended on some very precise implementation detail, and I made them more generic (for example, `test_image_renders_correctly` relied on pillow to render an image with a very specific string of bytes, and it broke due to the recent upgrade to pyodide 0.24.1)
I also renamed all the skip messages to start with `NEXT`, so that they are easier to grep.
Clean up a bit the testsuite and integration tests.
Highlights:
- Some of the @skipped tests just worked -- I unskipped them
- some worked after some small tweak to adapt to the new pyscript next
- some are still skipped, but I tweaked the skip message to be more precise and descriptive
- Moreover, I killed/removed the ones which no longer make sense in the context of pyscript next; in particular, I removed all the ones which tested Element (which is now gone) and the one which tested py-config features which are no longer needed (e.g., multiple interpreters).
The testsuite passes locally.
* move integration tests pyscriptjs/tests/integration ->pyscript.core/tests/integration
* add information in regards to how to run integration tests to README
* fix fake server build paths
* fix paths to build and run tests. The change of path before integration tests is a glitch maybe due to pytest cache?
* remove test files created by mistake
* update readme with latest changes
---------
Co-authored-by: Fabio Pliger <fpliger@anaconda.com>