Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v2-web components based widgets and get rid of iframes in operators. #534

Merged
merged 31 commits into from
Mar 7, 2024

Conversation

oxixes
Copy link
Contributor

@oxixes oxixes commented Nov 21, 2023

Proposed changes

This PR adds v2 widgets and operators, wich will work with web components now. v1 widgets (that work with iframes) will still work well. v2 widgets are not directly compatible due to the impossibility of isolating javascript without iframes, but they are very similar to their v1 counterparts.

The idea is that widgets (and operators) will now define a class in one of their script files in the window object, which will be instantiated for each widget. Each class will receive the MashupPlatform object as a parameter, which is tailored to the specific widget (just like the iframe) as well as any extra objects (such as StyledElements, NGSI...). They will also receive a reference to a shadowDOM that will contain all of the HTML and CSS of the widget, so that they can work in their isolated frame.

Operators not only won't use iframes, but not even web components, as they are pure javascript, which will be instantiated for each operator by adding their corresponding scripts without further DOM modifications.

For this to work, a new fieldhas been added into the Mashable Application Components Description Language, named entrypoint for both widgets and operators, which contains the name of the class that is instantiated for every widget and/or operator. Also, widgets now accept scripts, which are loaded into the main DOM, instead of the shadowDOM (altough they'll work the same way).

To differentiate between old, v1 widgets and operators (which will still work well), the macversion number has been increased to 2 for the new type of MACs, and 1 is left for the old ones. For this reason, this PR depends on #533 (includes #533 commits, so this can be merged and #533 closed).

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (Except for SOME japanese docs)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Other alternatives considered where to use just a shadowDOM. Unfortunately, javascript and only javascript is not isolated, and since the way things were working right now required modifying the window object, it was impossible to get rid of iframes (which is the only way to isolate javascript without creating a javascript sandbox). This can cause some problems sometimes, such as 2 different widgets using different versions of the same library, as conflicts can occur. This PR can be further expanded to create new fields in the MACs configuration files that allow to specify which libraries have been used and what version, in order to Wirecloud to handle conflicts to an extent, as well as warn the user about the conficts.

This PR is still in development, and while the main functionality has been made, there may be bugs left to fix. Moreover, documentation and testing is still missing, which is why this is still a draft. Already finished.

@oxixes
Copy link
Contributor Author

oxixes commented Nov 28, 2023

This PR is now reviewable.

Copy link
Contributor

github-actions bot commented Dec 28, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@coveralls
Copy link

coveralls commented Jan 18, 2024

Coverage Status

coverage: 88.99% (+0.07%) from 88.923%
when pulling f3b24df on oxixes:mac-v2
into 28fec83 on Wirecloud:develop.

@aarranz aarranz merged commit 01e171a into Wirecloud:develop Mar 7, 2024
36 checks passed
@aarranz
Copy link
Member

aarranz commented Mar 7, 2024

Thank you very much for your great work!

@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2024
@oxixes oxixes deleted the mac-v2 branch March 10, 2024 12:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants