-
-
Notifications
You must be signed in to change notification settings - Fork 389
Scoped keyframes #888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scoped keyframes #888
Changes from 1 commit
b90fe69
2989e27
dfbb767
2296958
bdd1ddf
421d42b
901ae2f
79228d2
3583f32
9a6a1e0
49cc07f
7e5eca9
abfafa8
c5fdf05
a70b3e2
54f2b7f
220bb42
d5b2794
2c10b42
171902b
0e53702
31ecf79
938b48b
eda061d
efede57
59f5ccc
b17c63d
7a32f09
5f5c1ef
4f3f549
3ce4648
890cecf
6bb5bbd
59fa73d
2c04dd7
91858a0
ccf0473
c1ca50f
7770877
79813c1
f0148a6
ac5a8a4
c91ec88
b9e2f0c
3e63bbf
98778f8
575a6df
e23927e
fbeb4e0
924a7ac
ad39a97
7a71754
621e6da
7c43edb
35d07f9
f47365b
4a9cb4c
1a517df
089edaf
dcd0a8f
d8a25a0
0e0d049
d20b9dd
0a5b84c
5dfd336
a2b3c43
0b652e6
a1e4e0d
a885d32
ba59e1c
6fdd38c
0edcbc3
fff8026
a4243ff
4ce3b61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /* @flow */ | ||
| import warning from 'warning' | ||
| import SimpleRule from '../rules/SimpleRule' | ||
| import KeyframesRule from '../rules/KeyframesRule' | ||
| import ConditionalRule from '../rules/ConditionalRule' | ||
|
|
@@ -21,7 +22,7 @@ const classes = { | |
| /** | ||
| * Generate plugins which will register all rules. | ||
| */ | ||
| const plugins: $ReadOnlyArray<Plugin> = Object.keys(classes).map((key: string) => { | ||
| const plugins: Array<Plugin> = Object.keys(classes).map((key: string) => { | ||
| // https://jsperf.com/indexof-vs-substr-vs-regex-at-the-beginning-3 | ||
| const re = new RegExp(`^${key}`) | ||
| const RuleClass = classes[key] | ||
|
|
@@ -30,4 +31,27 @@ const plugins: $ReadOnlyArray<Plugin> = Object.keys(classes).map((key: string) = | |
| return {onCreateRule} | ||
| }) | ||
|
|
||
| // Animation name ref replacer. | ||
| plugins.push({ | ||
| onProcessStyle: (style, rule, sheet) => { | ||
| 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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also need to support
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's maybe make all of the rules plugins for now and then move them out maybe. We could do a This should allow us to support all of the mentioned case above without needing to introduce anything.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by "make all of the rules plugins" you mean just jss/src/plugins or making them separate packages each?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets do this in a separate PR after the other PRs are merged, too many conflicts otherwise
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I think we need to apply the rule plugins last so that the keyframes name replace works on every possibility. |
||
| const ref = style[prop] | ||
| const isRef = ref && ref[0] === '$' | ||
| if (!isRef) return style | ||
|
|
||
| // We need to remove $ from $ref. | ||
| const name = ref.substr(1) | ||
|
|
||
| if (name in sheet.keyframes) { | ||
| style[prop] = sheet.keyframes[name] | ||
| } else { | ||
| warning(false, '[JSS] Referenced keyframes rule "%s" is not defined.', name) | ||
| } | ||
| return style | ||
| } | ||
| }) | ||
|
|
||
| export default plugins | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that would be cleaner, but also more hooks and more code, not sure its worth it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth it.