You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 exports
We 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.
Note: the chosen syntax (@) is in line with our suggested @st-import shorthand suggested in PR #936
Example
A component stylesheet exposing some of its internals
/* button.st.css */:vars {
c1: green;
c2: gold;
}
.icon { --c3: purple; }
.text {}
.private {} /* not included in the export below, hence private */@keyframes blink {}
@st-export
c1 as c11,/* rename exports */
c2,
--c3,
icon,
text,
keyframes(blink);
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.
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 variables c1 (aliased to c11) and c2. 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.
The text was updated successfully, but these errors were encountered:
tomrav
changed the title
Allow stylesheets to explicitly define their exported internals
Allow stylesheets to explicitly define their public exports
Nov 10, 2020
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.
The text was updated successfully, but these errors were encountered: