Open tomrav opened 4 years ago
Random thought. Everything written above talks about managing exports as a way of limiting the public interface.
Does this relate to the issue raised in #294? Should @st-export
also limit use through pseudo-element syntax?
/* button.st.css */
.root {}
.icon {}
.text {}
@st-export icon;
/* user-code.st.css */
:import {
-st-from: './button.st.css';
-st-default: Button;
-st-named: icon /* exists */,
text; /* doesn't exist */
}
Button::icon {} /* exists */
Button::text {} /* doesn't exist? */
@st-export also limit use through pseudo-element syntax?
If this would change the way pseudo elements are exposed then it be in conflict with @custom-selector.
I would prefer a directive to control access to pseudo-elements. Suggested it a while ago: #294
Stylable allows multiple types of symbols to be imported across stylesheets:
Button
.part
:vars { myVar: green; }
--myVar
@keyframes blink {}
All of these parts are automatically exposed as a public interface for every stylesheet.
This means that a user that wishes to limit the scope of their exposed style API cannot do so.
Furthermore, once we implement the feature suggested in issue #1484 it becomes even easier for anyone consuming a project to access any part of any stylesheet "legitimately".
Suggested feature - add
@st-exports
to explicitly manage exportsWe can introduce a new feature to Stylable that would allow a user to specify which parts of every stylesheet they wish to expose for external use. Any symbol not mentioned will count as a private member and will not be exposed for import across stylesheets.
If no
@st-export
definition exists in the stylesheet, the current behavior of everything being public is maintained.Example
A component stylesheet exposing some of its internals
An index file exposing the desired parts of its API. This in conjunction with the feature in #1484 cover both ends of the import/export relationship.
A user consuming the 3rd-party exports either through a
default
import or a `named one.Possible variation
We can consider using the same sort of destructuring syntax introduced in #1484 in the
@st-exports
directive as well to narrow down the export to specific parts of a stylesheet root.This example exposes three items,
Button
the component root, and two variablesc1
(aliased toc11
) andc2
. Any imports passing through this export see only those items. This allows managing the entire project exports through a single outward-facing file.In concept, this is similar to our CLI generated index file, but within the project source code (instead of dist), and more specific about which parts it exposes.