Skip to content

Scoped keyframes#888

Merged
kof merged 75 commits intomasterfrom
scoped-keyframes
Oct 22, 2018
Merged

Scoped keyframes#888
kof merged 75 commits intomasterfrom
scoped-keyframes

Conversation

@kof
Copy link
Copy Markdown
Member

@kof kof commented Oct 13, 2018

Comment thread packages/jss/src/rules/KeyframesRule.js Outdated
// 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)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not very nice, I actually want id generation to be outside of a rule and passed to it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rename generateClassName to generateUniqueId?

@kof
Copy link
Copy Markdown
Member Author

kof commented Oct 13, 2018 via email

Comment thread packages/jss/src/plugins/rules.js Outdated
})

// Animation name ref replacer.
plugins.push({
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member

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.

Comment thread packages/jss/src/plugins/rules.js Outdated
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'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to support animation: { name: 'fadeIn' }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also the animation: $keyframeId 150ms shortcut

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

@kof kof Oct 13, 2018

Choose a reason for hiding this comment

The 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 animation: {name} and animationName being converted to animation-name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 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.

Copy link
Copy Markdown
Member Author

@kof kof Oct 14, 2018

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

kof added 6 commits October 13, 2018 23:48
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
@kof
Copy link
Copy Markdown
Member Author

kof commented Oct 18, 2018

Yeah, or a default plugins registry maybe? This registry would be private, and those hooks would be called by the public registry.

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.

@kof
Copy link
Copy Markdown
Member Author

kof commented Oct 18, 2018

Also PluginsRegistry is called from many places, I would have to make 2 maps inside PluginsRegistry, but thats exactly what I did.

@kof
Copy link
Copy Markdown
Member Author

kof commented Oct 18, 2018

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.

@kof kof force-pushed the scoped-keyframes branch from a17cfae to a2b3c43 Compare October 21, 2018 10:45
@kof
Copy link
Copy Markdown
Member Author

kof commented Oct 21, 2018

Ok, I think we can do the final CR and merge it.

@kof kof changed the title [WIP] scoped keyframes Scoped keyframes Oct 21, 2018
@kof kof merged commit fc3773f into master Oct 22, 2018
@kof kof deleted the scoped-keyframes branch October 22, 2018 12:39
@HenriBeck HenriBeck mentioned this pull request Oct 22, 2018
9 tasks
HenriBeck pushed a commit that referenced this pull request Oct 22, 2018
…t/add-markdown-lint

* origin/feat/add-markdown-lint:
  Scoped keyframes (#888)
HenriBeck pushed a commit that referenced this pull request Oct 22, 2018
* 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)
bhupinderbola pushed a commit to bhupinderbola/jss that referenced this pull request Sep 17, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants