Open DmitrySharabin opened 5 months ago
Name | Link |
---|---|
Latest commit | dafcb659b0745a18fedb6a9bb36f5c539677b929 |
Latest deploy log | https://app.netlify.com/sites/color-elements/deploys/665f42ef6d21f10008963f37 |
Deploy Preview | https://deploy-preview-83--color-elements.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
I wonder if instead of jumping through all these hoops it may be easier to DIY it. A lot of the stuff that we need to expose in the CEM is already declarative, all we'd need to do is read each component and extract the relevant definitions. We wouldn't have descriptions, but perhaps we can deal with that later.
At the moment, we need to manually write docs for color elements (reference tables for slots, parts, props, events, etc.), even though most of the info can be inferred from their source code or JSDocs.
There is a package called
@custom-elements-manifest/analyzer
that allows us to build a custom element manifest file from the custom element source code. We can use the information in this file to automate the generation of docs (in some way).But there are some steps we need to perform to get the most out of the mentioned package:
@slot
tag@part
tag@cssproperty
tag@type
tag, or it will be inferred from the prop's spec (for simple cases; for more complex ones, it's much easier to provide a@type
tag)@default
tag, or it will be inferred from the prop's spec (unlessdefault
is a function)reflect
property is also (mostly—see note below) supported, so we automatically get the corresponding attributes from the spec.events
property:@type
attribute can be used to specify the event's typeUnfortunately, the
@custom-elements-manifest/analyzer
package supports only the first step out of the box. For example, it doesn't consider JSDocs for object properties (so there is no way to documentevents
andprops
). However, the package supports plugins, and I wrote a couple to support the features we need. Under the hood, it analyzes the AST built from a color element's source code by the TypeScript compiler (provided by the package).The corresponding manifest file might look like this (for
<color-picker>
for brevity):As you can see, it includes all the info we need to generate docs. Getters are also be there: in the manifest file, they are class members with the
readonly
property:Issues
There is one more thing to consider. All our color elements now export the
Self
constant instead of the class itself. I get what benefits we have from this. However, tools like@custom-elements-manifest/analyzer
orTypeDoc
don't go beyond the default export and don't see the class itself. As a result, we face issues like this one: https://github.com/nudeui/element/issues/12. In our case, we might end up with the following manifest file (for<color-slider>
for brevity):This is definitely not what we want. So, I wonder if there are any strong objections to switching back to
export default class ...
instead of usingSelf
.ToDos
Right now, in this (draft) PR, I addressed the first part of docs generation—I added and configured the tool to build the (correct) manifest file for our color elements.
Notes
reflect
is supported mainly because it doesn't support thereflect.to
case, and I'm still unsure how to distinguish attributes and properties with one directional reflection in the manifest file. I will research it more.