Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
b90fe69
added fallbacks test to fn rules
kof Sep 18, 2018
2989e27
only call onChangeValue if plugins: true
kof Sep 18, 2018
dfbb767
enable removing props from fn rules
kof Sep 18, 2018
2296958
shorter syntax with coercion
kof Sep 18, 2018
bdd1ddf
Merge branch 'master' into dynamic-values-full-syntax
kof Sep 26, 2018
421d42b
wip full syntax support
kof Oct 9, 2018
901ae2f
Merge branch 'master' into dynamic-values-full-syntax
kof Oct 9, 2018
79228d2
restore browsers.json
kof Oct 9, 2018
3583f32
changelog
kof Oct 9, 2018
9a6a1e0
move hook call to the core
kof Oct 10, 2018
49cc07f
isProcessed flag explanation
kof Oct 10, 2018
7e5eca9
added tests to fn rules
kof Oct 10, 2018
abfafa8
remove media rule as a function test case
kof Oct 11, 2018
c5fdf05
added a test for #796, as part of #682
kof Oct 11, 2018
a70b3e2
tests for compose plugin
kof Oct 11, 2018
54f2b7f
observables
kof Oct 11, 2018
220bb42
move fn values docs
kof Oct 11, 2018
d5b2794
wording
kof Oct 11, 2018
2c10b42
scoped keyframes
kof Oct 13, 2018
171902b
Added tests for using jss-plugin-syntax-expand with function rules an…
Oct 13, 2018
0e53702
Skip fn values with jss-expand for now
Oct 13, 2018
31ecf79
use "keyframes-{name}" as a key in KeyFramesRule
kof Oct 13, 2018
938b48b
keyframes name parser with validation
kof Oct 13, 2018
eda061d
wip keyframes inside of global
kof Oct 14, 2018
efede57
move container rules update to the core
kof Oct 14, 2018
59f5ccc
optimize onProcessStyle
kof Oct 14, 2018
b17c63d
put variables in the right scope
kof Oct 14, 2018
7a32f09
changelog
kof Oct 14, 2018
5f5c1ef
Merge branch 'master' into scoped-keyframes
kof Oct 14, 2018
4f3f549
update tests with key keyframes name
kof Oct 15, 2018
3ce4648
Update changelog.md
kof Oct 15, 2018
890cecf
Update docs/json-api.md
kof Oct 15, 2018
6bb5bbd
Merge branch 'master' into dynamic-values-full-syntax
kof Oct 15, 2018
59fa73d
Update changelog.md
kof Oct 15, 2018
2c04dd7
process: true always
kof Oct 15, 2018
91858a0
Merge branch 'dynamic-values-full-syntax' into scoped-keyframes
kof Oct 15, 2018
ccf0473
support multiple whitespaces after keyframes identifier
kof Oct 15, 2018
c1ca50f
move keyframe name generation to outside
kof Oct 15, 2018
7770877
call external plugins first
kof Oct 15, 2018
79813c1
move keyframes rule to plugins
kof Oct 15, 2018
f0148a6
move StyleRule to a plugin
kof Oct 15, 2018
ac5a8a4
move viewport rule to plugins
kof Oct 15, 2018
c91ec88
move simple rule to plugins
kof Oct 16, 2018
b9e2f0c
move FontFace rule
kof Oct 16, 2018
3e63bbf
rename plugins to {rule}Rule schema
kof Oct 16, 2018
98778f8
Merge branch 'master' into scoped-keyframes
kof Oct 16, 2018
575a6df
beter types for queue
kof Oct 16, 2018
e23927e
Add support for animation property
Oct 16, 2018
fbeb4e0
optimize perf, handle arrays
kof Oct 16, 2018
924a7ac
fix tests, add more tests
kof Oct 16, 2018
ad39a97
Fix
Oct 16, 2018
7a71754
Merge remote-tracking branch 'origin/scoped-keyframes' into scoped-ke…
Oct 16, 2018
621e6da
Support arrays
Oct 17, 2018
7c43edb
remove array support
kof Oct 17, 2018
35d07f9
use global instead of window
kof Oct 17, 2018
f47365b
Merge branch 'master' into scoped-keyframes
kof Oct 17, 2018
4a9cb4c
always run stylerule plugin first, to avoid regexes of the at rules
kof Oct 17, 2018
1a517df
ensure to always use style rule as a first rule in plugins
kof Oct 17, 2018
089edaf
fix cache plugin
kof Oct 17, 2018
dcd0a8f
test raw rule registration order
kof Oct 17, 2018
d8a25a0
Merge branch 'master' into scoped-keyframes
Oct 17, 2018
0e0d049
rewrite internal plugins queue
kof Oct 18, 2018
d20b9dd
better logic in plugins.use()
kof Oct 18, 2018
0a5b84c
better types
kof Oct 18, 2018
5dfd336
better types
kof Oct 18, 2018
a2b3c43
fix types
kof Oct 21, 2018
0b652e6
keyframe inside of global
kof Oct 21, 2018
a1e4e0d
default export in plugins
kof Oct 21, 2018
a885d32
move id generator to models
kof Oct 21, 2018
ba59e1c
update snapshots
kof Oct 21, 2018
6fdd38c
fix circular deps
kof Oct 21, 2018
0edcbc3
use CSSKeyframeRule
kof Oct 21, 2018
fff8026
generateClassName -> generateId
kof Oct 21, 2018
a4243ff
added exampls with keyframes to global plugin
kof Oct 21, 2018
4ce3b61
docs, small syntactic changes
kof Oct 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/jss-plugin-isolate/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/jss-plugin-isolate.js": {
"bundled": 14372,
"minified": 9394,
"gzipped": 2667
"bundled": 14368,
"minified": 9404,
"gzipped": 2670
},
"dist/jss-plugin-isolate.min.js": {
"bundled": 14372,
"minified": 9394,
"gzipped": 2667
"bundled": 14368,
"minified": 9404,
"gzipped": 2670
},
"dist/jss-plugin-isolate.cjs.js": {
"bundled": 3922,
"minified": 1604,
"gzipped": 746
"bundled": 3920,
"minified": 1614,
"gzipped": 750
},
"dist/jss-plugin-isolate.esm.js": {
"bundled": 3668,
"minified": 1410,
"gzipped": 678,
"bundled": 3666,
"minified": 1420,
"gzipped": 681,
"treeshaked": {
"rollup": {
"code": 99,
Expand Down
8 changes: 4 additions & 4 deletions packages/jss-plugin-syntax-expand/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"dist/jss-plugin-syntax-expand.js": {
"bundled": 10991,
"bundled": 11087,
"minified": 4112,
"gzipped": 1450
},
"dist/jss-plugin-syntax-expand.min.js": {
"bundled": 10991,
"bundled": 11087,
"minified": 4112,
"gzipped": 1450
},
"dist/jss-plugin-syntax-expand.cjs.js": {
"bundled": 10010,
"bundled": 10102,
"minified": 4283,
"gzipped": 1451
},
"dist/jss-plugin-syntax-expand.esm.js": {
"bundled": 9928,
"bundled": 10020,
"minified": 4214,
"gzipped": 1406,
"treeshaked": {
Expand Down
8 changes: 4 additions & 4 deletions packages/jss-plugin-syntax-extend/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"dist/jss-plugin-syntax-extend.js": {
"bundled": 5220,
"bundled": 5265,
"minified": 1801,
"gzipped": 912
},
"dist/jss-plugin-syntax-extend.min.js": {
"bundled": 4104,
"bundled": 4149,
"minified": 1281,
"gzipped": 630
},
"dist/jss-plugin-syntax-extend.cjs.js": {
"bundled": 3404,
"bundled": 3447,
"minified": 1384,
"gzipped": 620
},
"dist/jss-plugin-syntax-extend.esm.js": {
"bundled": 3186,
"bundled": 3229,
"minified": 1216,
"gzipped": 551,
"treeshaked": {
Expand Down
16 changes: 8 additions & 8 deletions packages/jss-plugin-syntax-nested/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/jss-plugin-syntax-nested.js": {
"bundled": 5743,
"bundled": 5777,
"minified": 1944,
"gzipped": 1048
"gzipped": 1050
},
"dist/jss-plugin-syntax-nested.min.js": {
"bundled": 4627,
"bundled": 4661,
"minified": 1424,
"gzipped": 781
"gzipped": 782
},
"dist/jss-plugin-syntax-nested.cjs.js": {
"bundled": 3612,
"bundled": 3646,
"minified": 1347,
"gzipped": 720
"gzipped": 722
},
"dist/jss-plugin-syntax-nested.esm.js": {
"bundled": 3378,
"bundled": 3412,
"minified": 1168,
"gzipped": 640,
"gzipped": 642,
"treeshaked": {
"rollup": {
"code": 59,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/jss-plugin-syntax-rule-value-function.js": {
"bundled": 2073,
"minified": 827,
"gzipped": 472
"bundled": 2141,
"minified": 824,
"gzipped": 469
},
"dist/jss-plugin-syntax-rule-value-function.min.js": {
"bundled": 2073,
"minified": 827,
"gzipped": 472
"bundled": 2141,
"minified": 824,
"gzipped": 469
},
"dist/jss-plugin-syntax-rule-value-function.cjs.js": {
"bundled": 1672,
"minified": 737,
"gzipped": 411
"bundled": 1742,
"minified": 734,
"gzipped": 408
},
"dist/jss-plugin-syntax-rule-value-function.esm.js": {
"bundled": 1600,
"minified": 678,
"gzipped": 363,
"bundled": 1670,
"minified": 675,
"gzipped": 360,
"treeshaked": {
"rollup": {
"code": 12,
Expand Down
10 changes: 5 additions & 5 deletions packages/jss-preset-default/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dist/jss-preset-default.js": {
"bundled": 66952,
"minified": 23591,
"gzipped": 6992
"bundled": 67196,
"minified": 23588,
"gzipped": 6993
},
"dist/jss-preset-default.min.js": {
"bundled": 65836,
"minified": 23071,
"bundled": 66080,
"minified": 23068,
"gzipped": 6733
},
"dist/jss-preset-default.cjs.js": {
Expand Down
28 changes: 14 additions & 14 deletions packages/jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"dist/jss.js": {
"bundled": 51522,
"minified": 19353,
"gzipped": 5840
"bundled": 51612,
"minified": 19375,
"gzipped": 5843
},
"dist/jss.min.js": {
"bundled": 50646,
"minified": 18740,
"gzipped": 5521
"bundled": 50736,
"minified": 18762,
"gzipped": 5526
},
"dist/jss.cjs.js": {
"bundled": 45381,
"minified": 19718,
"gzipped": 5556
"bundled": 45471,
"minified": 19747,
"gzipped": 5564
},
"dist/jss.esm.js": {
"bundled": 44924,
"minified": 19346,
"gzipped": 5465,
"bundled": 45014,
"minified": 19375,
"gzipped": 5471,
"treeshaked": {
"rollup": {
"code": 16518,
"code": 16540,
"import_statements": 189
},
"webpack": {
"code": 17856
"code": 17880
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/jss/src/Jss.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export default class Jss {
return this.createRule(undefined, name, style)
}

// Cast from RuleFactoryOptions to RuleOptions
// https://stackoverflow.com/questions/41328728/force-casting-in-flow
const ruleOptions: RuleOptions = {...options, jss: this, Renderer: this.options.Renderer}

if (!ruleOptions.generateClassName) ruleOptions.generateClassName = this.generateClassName
Expand Down
18 changes: 17 additions & 1 deletion packages/jss/src/RuleList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/* @flow */
import createRule from './utils/createRule'
import StyleRule from './rules/StyleRule'
import type {RuleListOptions, ToCssOptions, Rule, RuleOptions, JssStyle, Classes} from './types'
import KeyframesRule from './rules/KeyframesRule'
import type {
RuleListOptions,
ToCssOptions,
Rule,
RuleOptions,
JssStyle,
Classes,
KeyframesMap
} from './types'
import escape from './utils/escape'

type Update = ((name: string, data?: Object) => void) & ((data?: Object) => void)
Expand All @@ -25,9 +34,12 @@ export default class RuleList {

classes: Classes

keyframes: KeyframesMap

constructor(options: RuleListOptions) {
this.options = options
this.classes = options.classes
this.keyframes = options.keyframes
}

/**
Expand Down Expand Up @@ -110,6 +122,8 @@ export default class RuleList {
if (rule instanceof StyleRule) {
this.map[rule.selector] = rule
if (className) this.classes[rule.key] = className
} else if (rule instanceof KeyframesRule) {
this.keyframes[rule.name] = rule.id
}
}

Expand All @@ -121,6 +135,8 @@ export default class RuleList {
if (rule instanceof StyleRule) {
delete this.map[rule.selector]
delete this.classes[rule.key]
} else if (rule instanceof KeyframesRule) {
delete this.keyframes[rule.name]
}
}

Expand Down
9 changes: 7 additions & 2 deletions packages/jss/src/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
RuleOptions,
StyleSheetOptions,
JssStyle,
Classes
Classes,
KeyframesMap
} from './types'

/* eslint-disable-next-line no-use-before-define */
Expand All @@ -26,17 +27,21 @@ export default class StyleSheet {

classes: Classes

keyframes: KeyframesMap

queue: ?Array<Rule>

constructor(styles: Object, options: StyleSheetOptions) {
this.attached = false
this.deployed = false
this.classes = {}
this.keyframes = {}
this.options = {
...options,
sheet: this,
parent: this,
classes: this.classes
classes: this.classes,
keyframes: this.keyframes
}
this.renderer = new options.Renderer(this)
this.rules = new RuleList(this.options)
Expand Down
26 changes: 25 additions & 1 deletion packages/jss/src/plugins/rules.js
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'
Expand All @@ -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]
Expand All @@ -30,4 +31,27 @@ const plugins: $ReadOnlyArray<Plugin> = Object.keys(classes).map((key: string) =
return {onCreateRule}
})

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

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

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
6 changes: 3 additions & 3 deletions packages/jss/src/renderers/DomRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,16 @@ export default class DomRenderer {
const {sheet} = this.element

if (rule.type === 'conditional' || rule.type === 'keyframes') {
const containerRule = ((rule: any): ContainerRule)
const cssRule = insertRule(sheet, `${containerRule.key} {}`, index)
const containerRule: ContainerRule = (rule: any)
// We need to render the container without children first.
const cssRule = insertRule(sheet, containerRule.toString({children: false}), index)
if (cssRule === false) {
return false
}
containerRule.rules.index.forEach((childRule, childIndex) => {
const cssChildRule = insertRule(cssRule, childRule.toString(), childIndex)
if (cssChildRule !== false) childRule.renderable = cssChildRule
})

return cssRule
}

Expand Down
14 changes: 11 additions & 3 deletions packages/jss/src/rules/ConditionalRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import RuleList from '../RuleList'
import type {CSSMediaRule, Rule, RuleOptions, ToCssOptions, JssStyle, ContainerRule} from '../types'

const defaultToStringOptions = {
indent: 1,
children: true
}

/**
* Conditional rule for @media, @supports
*/
Expand Down Expand Up @@ -56,8 +61,11 @@ export default class ConditionalRule implements ContainerRule {
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions = {indent: 1}): string {
const inner = this.rules.toString(options)
return inner ? `${this.key} {\n${inner}\n}` : ''
toString(options?: ToCssOptions = defaultToStringOptions): string {
if (options.children === false) {
return `${this.key} {}`
}
const children = this.rules.toString(options)
return children ? `${this.key} {\n${children}\n}` : ''
}
}
Loading