Are there any plans to add support for using the widgets inside Shadow DOM encapsulated web components?
I have done some experiments with trying to used these widgets inside a framework like Stencil.js. If none of the parent elements use Shadow DOM, everything works well. However, some of the styling of elements is off if you move the style block inside of the shadow root.
Here is the short list of what I would think would help with building modular progressive web applications:
- More modular ES2015 or ES2017 EcmaScript that can be tree shaken using Rollup.js or WebPack.
- More modular styling broken down by widget. Ideally, there would also be Sass or Less versions of this in the deployment.
The idea is to only load the JS and CSS we need for the components we use and only when we use them for the first time. This would allow us to build true progressive Web Applications (PWA) with minimum payload sizes.
It looks like in recent versions, you are moving in this direction, but the deployment seems to only contain the monolithic JS and CSS at this point. I am still evaluating your library and may be wrong about this though. Please forgive me if I am missing something obvious.
If you like, I can build a simple Web component with Shadow DOM to demonstrate some of the styling and modularity problems.
In the long run, it would be great to provide web component versions of these widgets as well, but I would be happy with more modularity for now.
I have added a couple of crude code snippets that demonstrates the problem at
switch: https://snippet.webix.com/n5f3qxj5
datatable: https://snippet.webix.com/3e5jbd17
OK, I have a little additional information this morning. It seems the styling problems on the datatable
are related to the injection of styles into the head section of the document. For example:
<style type="text/css" media="screen,print">
#datatable1540471118828 .webix_cell { height:36px; line-height:36px; }
#datatable1540471118828 .webix_hcell { height:42px; line-height:42px;}
#datatable1540471118971 .webix_cell { height:36px; line-height:36px; }
#datatable1540471118971 .webix_hcell { height:42px; line-height:42px;}
#datatable1540471119014 .webix_cell { height:36px; line-height:36px; }
#datatable1540471119014 .webix_hcell { height:42px; line-height:42px;}</style>
Of course, this would all be ignored by an element in the shadow DOM. Is there a function we can monkey patch to inject these styles into a style block within the shadow root?
As a proof of concept, I modified the datatable snippet to specify these styles within the Shadow DOM.
https://snippet.webix.com/g2lmoxx8
The function that finds the document root currently could use the following code to get the DocumentOrShadowRoot.
const root = container.getRootNode();
See https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode
This would sometimes return the document and sometimes return a shadow root. In the event it returns the document, you could look for the style block in the document.head. In the event it returns the shadow root, you could look for or add the style block directly under it.
Here is a proof of concept that will log the document root and last style block for both Shadow DOM encapsulated elements and elements without shadow DOM: https://snippet.webix.com/0a2r4klk
There are still problems with some widget behavior (switch and checkbox can’t toggle, etc.), but at least this should help on the styling issues.
Chrome, Safari, Firefox 63+ and Opera all support custom elements and Shadow DOM at this point. MS Edge is working on it. And, of course, there are polyfills for the majority of this functionality. It would be great to be able to use Webix widgets in this way.
Thanks,
Neal