Conversation
- move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that
| // TODO make it more robust | ||
| this.name = key.substr(this.type.length + 2) | ||
| const fakeRule: Rule = ({key: this.name}: any) | ||
| this.id = options.jss.generateClassName(fakeRule, options.sheet) |
There was a problem hiding this comment.
this is not very nice, I actually want id generation to be outside of a rule and passed to it
There was a problem hiding this comment.
We could rename generateClassName to generateUniqueId?
|
Thought about this too as well as about a new interface. The problem here
is that key in this rule unusable for id, so I had to create a fake rule.
Alternatively the key can be changed to something usable for id, then
interface can stay.
…On Sat, Oct 13, 2018, 16:22 Henri ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/jss/src/rules/KeyframesRule.js
<#888 (comment)>:
> @@ -20,6 +28,10 @@ export default class KeyframesRule implements ContainerRule {
constructor(key: string, frames: Object, options: RuleOptions) {
this.key = key
+ // TODO make it more robust
+ this.name = key.substr(this.type.length + 2)
+ const fakeRule: Rule = ({key: this.name}: any)
+ this.id = options.jss.generateClassName(fakeRule, options.sheet)
We could rename generateClassName to generateUniqueId?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#888 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADOWMMY3AX7-6s8hzw5eq7s61O6_NoFks5ukfc4gaJpZM4Xal7d>
.
|
| }) | ||
|
|
||
| // Animation name ref replacer. | ||
| plugins.push({ |
There was a problem hiding this comment.
Not a fan of this. I think we should rename all of the Rules to StylePlugin etc. and move this functionality to the KeyframesPlugin.
There was a problem hiding this comment.
yeah, that would be cleaner, but also more hooks and more code, not sure its worth it
| if (rule.type !== 'style' || !sheet) return style | ||
|
|
||
| // We need to support camel case here, because this plugin runs before the camelization plugin. | ||
| const prop = 'animationName' in style ? 'animationName' : 'animation-name' |
There was a problem hiding this comment.
I think we also need to support animation: { name: 'fadeIn' }
There was a problem hiding this comment.
and also the animation: $keyframeId 150ms shortcut
There was a problem hiding this comment.
thought about it an decided to limit it for now, because it goes into difficult directions, adds more code and slows down.
In the first case you would introduce the knowledge from jss-expand plugin about new syntax, in the second case, you would have to always run a regex or indexOf on the animation property.
We already had to introduce camel case support in the core, which is suboptimal. In theory we could make this refs replacement a separate plugin, but then its not very logical that one can't reference keyframes from the same sheet without plugins.
There was a problem hiding this comment.
Making it a separate plugin and running after jss-expand and jss-camel-case, would allow to just support "animation-name" property and rely on the animation: {name} and animationName being converted to animation-name
There was a problem hiding this comment.
Another thought I had a while ago: what if we extract all core rules into separate packages and plugins? Most people use preset anyways. A few people can also setup by themselves all the plugins. This would give us the flexibility with above mentioned plugin.
There was a problem hiding this comment.
Additional benefit: someone who doesn't need all the rules, doesn't have to include them. For e.g. we got a request to include @page rule and there are some more rarely used rules. Why not make them all separate packages, but included in default preset.
There was a problem hiding this comment.
Yeah, let's maybe make all of the rules plugins for now and then move them out maybe.
We could do a KeyframeRulePlugin and a KeyframeReferencePlugin then. I think this would be the best solution.
This should allow us to support all of the mentioned case above without needing to introduce anything.
There was a problem hiding this comment.
by "make all of the rules plugins" you mean just jss/src/plugins or making them separate packages each?
There was a problem hiding this comment.
lets do this in a separate PR after the other PRs are merged, too many conflicts otherwise
There was a problem hiding this comment.
Okay, I think we need to apply the rule plugins last so that the keyframes name replace works on every possibility.
Changed the key to a form where it can be used directly as-is for id generation, so we don't have to fake the rule when using generateClassName
onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added
Separate registries? This could work now, but not sure if it won't be a problem later, if we want to expose the registry for some reason. |
|
Also PluginsRegistry is called from many places, I would have to make 2 maps inside PluginsRegistry, but thats exactly what I did. |
|
I can sort on .use() call though, this allows to have one registry. Sorting on .use() call is possible because its not a hot call. |
TODO - Rethink BaseStyleRule - Evtl move generateClassName to the rule models - Evtl rename generateClassName to generateId
|
Ok, I think we can do the final CR and merge it. |
…t/add-markdown-lint * origin/feat/add-markdown-lint: Scoped keyframes (#888)
* origin/add-ts-typings: Scoped keyframes (#888) Update readme.md (#897) Use CSSTOM in default unit plugin (#893) Added .nvmrc (#896) [WIP] DONT MERGE Fix ci (#895) Update ci (#894) Support plugins processing for observables by default (#892) Typed CSSOM values support (#887) Dynamic values full syntax (#878) [jss-plugin-cache] Use WeakMap for cache plugin (#890)
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for cssinjs#796, as part of cssinjs#682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * scoped keyframes * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * use "keyframes-{name}" as a key in KeyFramesRule Changed the key to a form where it can be used directly as-is for id generation, so we don't have to fake the rule when using generateClassName * keyframes name parser with validation * wip keyframes inside of global * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope * changelog * update tests with key keyframes name * Update changelog.md * Update docs/json-api.md * Update changelog.md * process: true always * support multiple whitespaces after keyframes identifier * move keyframe name generation to outside * call external plugins first we need to separate internal and external queues, queue 0 is external, 1 is internal and 1 is executed always after 0 * move keyframes rule to plugins * move StyleRule to a plugin Additionally stop rendering StyleRule when user passes a bad/unknown at-rule * move viewport rule to plugins * move simple rule to plugins * move FontFace rule * rename plugins to {rule}Rule schema * beter types for queue * Add support for animation property * optimize perf, handle arrays * fix tests, add more tests * Fix * Support arrays * remove array support * use global instead of window * always run stylerule plugin first, to avoid regexes of the at rules * ensure to always use style rule as a first rule in plugins flow started to complain with "Unused suppression comment." so I removed them * fix cache plugin * test raw rule registration order * rewrite internal plugins queue * better logic in plugins.use() * better types * better types * fix types * keyframe inside of global TODO - Rethink BaseStyleRule - Evtl move generateClassName to the rule models - Evtl rename generateClassName to generateId * default export in plugins * move id generator to models * update snapshots * fix circular deps * use CSSKeyframeRule * generateClassName -> generateId * added exampls with keyframes to global plugin * docs, small syntactic changes
#346