Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,7 @@
{
"presets": ["es2015", "stage-0"],
"plugins": [
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}

View File

@@ -0,0 +1,4 @@
{
"parser": "babel-eslint",
"extends": "eslint-config-jss"
}

View File

@@ -0,0 +1,3 @@
src
coverage
tmp

View File

@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2016 - present Oleg Slobodskoi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,33 @@
## 2.0.0 / 2017-06-20
- Support JSS 8
## 1.0.1 / 2017-04-18
- Use latest jss-nested in devDeps
## 1.0.0 / 2017-04-10
- Support JSS 7.0
## 0.4.1 / 2017-01-14
- Fixed comma separated scoped selectors (cssinjs/jss#400)
## 0.4.0 / 2016-12-23
- Update JSS to 6.0.2
- Fixed nested nesting (cssinjs/jss#380)
- Fixed @media and (cssinjs/jss#387)
## 0.3.0 / 2016-12-09
- Add docs
## 0.2.0 / 2016-12-03
- Changed hook api to onCreateRule and onProcessRule
## 0.1.0 / 2016-12-03
- First release

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
const webpackConfig = require('./webpack.config')
module.exports = (config) => {
config.set({
browsers: ['Chrome'],
frameworks: ['mocha'],
files: ['tests.webpack.js'],
preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap']
},
webpack: Object.assign(webpackConfig, {
devtool: 'inline-source-map'
}),
webpackServer: {
noInfo: true
},
reporters: ['mocha']
})
}

View File

@@ -0,0 +1,191 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports['default'] = jssGlobal;
var _jss = require('jss');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var propKey = '@global';
var prefixKey = '@global ';
var GlobalContainerRule = function () {
function GlobalContainerRule(key, styles, options) {
_classCallCheck(this, GlobalContainerRule);
this.type = 'global';
this.key = key;
this.options = options;
this.rules = new _jss.RuleList(_extends({}, options, {
parent: this
}));
for (var selector in styles) {
this.rules.add(selector, styles[selector], { selector: selector });
}
this.rules.process();
}
/**
* Get a rule.
*/
_createClass(GlobalContainerRule, [{
key: 'getRule',
value: function getRule(name) {
return this.rules.get(name);
}
/**
* Create and register rule, run plugins.
*/
}, {
key: 'addRule',
value: function addRule(name, style, options) {
var rule = this.rules.add(name, style, options);
this.options.jss.plugins.onProcessRule(rule);
return rule;
}
/**
* Get index of a rule.
*/
}, {
key: 'indexOf',
value: function indexOf(rule) {
return this.rules.indexOf(rule);
}
/**
* Generates a CSS string.
*/
}, {
key: 'toString',
value: function toString() {
return this.rules.toString();
}
}]);
return GlobalContainerRule;
}();
var GlobalPrefixedRule = function () {
function GlobalPrefixedRule(name, style, options) {
_classCallCheck(this, GlobalPrefixedRule);
this.name = name;
this.options = options;
var selector = name.substr(prefixKey.length);
this.rule = options.jss.createRule(selector, style, _extends({}, options, {
parent: this,
selector: selector
}));
}
_createClass(GlobalPrefixedRule, [{
key: 'toString',
value: function toString(options) {
return this.rule.toString(options);
}
}]);
return GlobalPrefixedRule;
}();
var separatorRegExp = /\s*,\s*/g;
function addScope(selector, scope) {
var parts = selector.split(separatorRegExp);
var scoped = '';
for (var i = 0; i < parts.length; i++) {
scoped += scope + ' ' + parts[i].trim();
if (parts[i + 1]) scoped += ', ';
}
return scoped;
}
function handleNestedGlobalContainerRule(rule) {
var options = rule.options,
style = rule.style;
var rules = style[propKey];
if (!rules) return;
for (var name in rules) {
options.sheet.addRule(name, rules[name], _extends({}, options, {
selector: addScope(name, rule.selector)
}));
}
delete style[propKey];
}
function handlePrefixedGlobalRule(rule) {
var options = rule.options,
style = rule.style;
for (var prop in style) {
if (prop.substr(0, propKey.length) !== propKey) continue;
var selector = addScope(prop.substr(propKey.length), rule.selector);
options.sheet.addRule(selector, style[prop], _extends({}, options, {
selector: selector
}));
delete style[prop];
}
}
/**
* Convert nested rules to separate, remove them from original styles.
*
* @param {Rule} rule
* @api public
*/
function jssGlobal() {
function onCreateRule(name, styles, options) {
if (name === propKey) {
return new GlobalContainerRule(name, styles, options);
}
if (name[0] === '@' && name.substr(0, prefixKey.length) === prefixKey) {
return new GlobalPrefixedRule(name, styles, options);
}
var parent = options.parent;
if (parent) {
if (parent.type === 'global' || parent.options.parent.type === 'global') {
options.global = true;
}
}
if (options.global) options.selector = name;
return null;
}
function onProcessRule(rule) {
if (rule.type !== 'style') return;
handleNestedGlobalContainerRule(rule);
handlePrefixedGlobalRule(rule);
}
return { onCreateRule: onCreateRule, onProcessRule: onProcessRule };
}

View File

@@ -0,0 +1,257 @@
'use strict';
var _expect = require('expect.js');
var _expect2 = _interopRequireDefault(_expect);
var _jss = require('jss');
var _jssNested = require('jss-nested');
var _jssNested2 = _interopRequireDefault(_jssNested);
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var settings = {
createGenerateClassName: function createGenerateClassName() {
return function (rule) {
return rule.key + '-id';
};
}
};
describe('jss-global', function () {
var jss = void 0;
beforeEach(function () {
jss = (0, _jss.create)(settings).use((0, _index2['default'])());
});
describe('@global root container', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
'@global': {
a: { color: 'red' },
body: { color: 'green' }
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('@global')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('a')).to.be(undefined);
(0, _expect2['default'])(sheet.getRule('body')).to.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('a {\n' + ' color: red;\n' + '}\n' + 'body {\n' + ' color: green;\n' + '}');
});
});
describe('@global root prefix', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
'@global body': {
color: 'red'
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('body')).to.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('body {\n' + ' color: red;\n' + '}');
});
});
describe('@global scoped container', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global': {
span: { color: 'red' }
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id span')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id span {\n' + ' color: red;\n' + '}');
});
});
describe('@global scoped container with comma separate selectors', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global': {
'a, b': { color: 'red' }
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id a, .button-id b')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id a, .button-id b {\n' + ' color: red;\n' + '}');
});
});
describe('@global prefixed scoped rule', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global span': {
color: 'red'
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id span')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id span {\n' + ' color: red;\n' + '}');
});
});
describe('@global prefixed scoped rule with comma separate selectors', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global a, b': {
color: 'red'
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id a, .button-id b')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id a, .button-id b {\n' + ' color: red;\n' + '}');
});
});
describe('@global with nested rules inside', function () {
var jss2 = void 0;
beforeEach(function () {
jss2 = (0, _jss.create)({ plugins: [(0, _index2['default'])(), (0, _jssNested2['default'])()] });
});
it('should handle regular nested rules', function () {
var sheet = jss2.createStyleSheet({
'@global': {
button: {
color: 'red',
'& span': {
color: 'green'
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('button {\n' + ' color: red;\n' + '}\n' + 'button span {\n' + ' color: green;\n' + '}');
});
it('should handle nested rules inside of a rule with comma separated selector', function () {
var sheet = jss2.createStyleSheet({
'@global': {
'button, a': {
color: 'red',
'& span': {
color: 'green'
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('button, a {\n' + ' color: red;\n' + '}\n' + 'button span, a span {\n' + ' color: green;\n' + '}');
});
it('should handle regular deep nested rules', function () {
var sheet = jss2.createStyleSheet({
'@global': {
button: {
color: 'red',
'& span': {
color: 'green',
'& b': {
color: 'blue'
}
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('button {\n' + ' color: red;\n' + '}\n' + 'button span {\n' + ' color: green;\n' + '}\n' + 'button span b {\n' + ' color: blue;\n' + '}');
});
it('should handle nested conditional rules', function () {
var sheet = jss2.createStyleSheet({
'@global': {
html: {
color: 'red',
'@media (max-width: 767px)': {
color: 'green'
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('html {\n' + ' color: red;\n' + '}\n' + '@media (max-width: 767px) {\n' + ' html {\n' + ' color: green;\n' + ' }\n' + '}');
});
it('should handle conditionals with nesting inside', function () {
var sheet = jss2.createStyleSheet({
'@global': {
'@media (max-width: 767px)': {
html: {
color: 'red',
'& button': {
color: 'green'
}
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('@media (max-width: 767px) {\n' + ' html {\n' + ' color: red;\n' + ' }\n' + ' html button {\n' + ' color: green;\n' + ' }\n' + '}');
});
});
});

View File

@@ -0,0 +1,117 @@
{
"_args": [
[
"jss-global@2.0.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "jss-global@2.0.0",
"_id": "jss-global@2.0.0",
"_inBundle": false,
"_integrity": "sha512-/FSOMp4lF/vg47T/w8kKvL9tu7ka9am8N4izS63W81Qlay9hAq6xe9RxrPxygLpnn4KEb8LNbkKRoUv4SJfQsQ==",
"_location": "/material-ui/jss-global",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "jss-global@2.0.0",
"name": "jss-global",
"escapedName": "jss-global",
"rawSpec": "2.0.0",
"saveSpec": null,
"fetchSpec": "2.0.0"
},
"_requiredBy": [
"/material-ui/jss-preset-default"
],
"_resolved": "https://registry.npmjs.org/jss-global/-/jss-global-2.0.0.tgz",
"_spec": "2.0.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Oleg Slobodskoi",
"email": "oleg008@gmail.com"
},
"bugs": {
"url": "https://github.com/cssinjs/jss/issues/new?title=[jss-global]"
},
"description": "Global styles for JSS",
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.9.1",
"babel-eslint": "^7.0.0",
"babel-loader": "^6.2.5",
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
"babel-plugin-transform-es3-property-literals": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"cross-env": "^3.0.0",
"es5-shim": "^4.5.9",
"eslint": "^3.6.0",
"eslint-config-airbnb": "^12.0.0",
"eslint-config-jss": "^2.3.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"expect.js": "^0.3.1",
"jss": "8.0.0",
"jss-nested": "^5.0.0",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.2.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"lint-staged": "^3.0.3",
"mocha": "^3.0.2",
"pre-commit": "^1.1.3",
"rimraf": "^2.5.4",
"webpack": "^1.13.1"
},
"homepage": "https://github.com/cssinjs/jss-global",
"keywords": [
"cssinjs",
"css-in-js",
"css in js",
"jss",
"plugin",
"global",
"unscoped"
],
"license": "MIT",
"lint-staged": {
"./src/*.js": [
"eslint",
"git add"
]
},
"main": "lib/index.js",
"name": "jss-global",
"peerDependencies": {
"jss": "^8.0.0"
},
"pre-commit": "lint:staged",
"repository": {
"type": "git",
"url": "git+https://github.com/cssinjs/jss-global.git"
},
"scripts": {
"all": "npm run lint && npm run test && npm run build",
"build": "npm run clean && npm run build:lib && npm run build:tests && npm run build:dist",
"build:dist": "npm run build:dist:max && npm run build:dist:min",
"build:dist:max": "cross-env NODE_ENV=development webpack src/index.js dist/jss-global.js",
"build:dist:min": "cross-env NODE_ENV=production webpack src/index.js dist/jss-global.min.js",
"build:lib": "babel src --out-dir lib",
"build:tests": "npm run build:tests:lib && npm run build:tests:local",
"build:tests:lib": "cross-env NODE_ENV=test babel src --out-dir tests",
"build:tests:local": "cross-env NODE_ENV=test webpack src/index.test.js tmp/tests.js",
"clean": "rimraf {lib,dist,tests,tmp}/*",
"lint": "eslint ./src",
"lint:staged": "lint-staged",
"prepublishOnly": "npm run all",
"test": "cross-env NODE_ENV=test karma start --single-run ",
"test:watch": "cross-env NODE_ENV=test karma start"
},
"version": "2.0.0"
}

View File

@@ -0,0 +1,69 @@
# Global Styles for JSS
If you want to write regular globally scoped CSS with JSS, this plugin is for you. Don't use it if you can avoid it.
[![Gitter](https://badges.gitter.im/JoinChat.svg)](https://gitter.im/cssinjs/lobby)
## Top level global declarations block
```javascript
const styles = {
'@global': {
body: {
color: 'green'
},
a: {
textDecoration: 'underline'
}
}
}
```
## Top level global prefix
```javascript
const styles = {
'@global body': {
color: 'green'
}
}
```
## Nested global declarations block
```javascript
const styles = {
button: {
float: 'left',
'@global': {
span: {color: 'red'}
}
}
}
```
## Nested global prefix
```javascript
const styles = {
button: {
float: 'left',
'@global span': {color: 'red'}
}
}
```
## Issues
File a bug against [cssinjs/jss prefixed with \[jss-global\]](https://github.com/cssinjs/jss/issues/new?title=[jss-global]%20).
## Run tests
```bash
npm i
npm run test
```
## License
MIT

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>JSS Tests</title>
<link href="./node_modules/mocha/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="./node_modules/es5-shim/es5-shim.js"></script>
<script src="./node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="tmp/tests.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>

View File

@@ -0,0 +1,2 @@
var context = require.context('./src', true, /\.test\.js$/)
context.keys().forEach(context)

View File

@@ -0,0 +1,191 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports['default'] = jssGlobal;
var _jss = require('jss');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var propKey = '@global';
var prefixKey = '@global ';
var GlobalContainerRule = function () {
function GlobalContainerRule(key, styles, options) {
_classCallCheck(this, GlobalContainerRule);
this.type = 'global';
this.key = key;
this.options = options;
this.rules = new _jss.RuleList(_extends({}, options, {
parent: this
}));
for (var selector in styles) {
this.rules.add(selector, styles[selector], { selector: selector });
}
this.rules.process();
}
/**
* Get a rule.
*/
_createClass(GlobalContainerRule, [{
key: 'getRule',
value: function getRule(name) {
return this.rules.get(name);
}
/**
* Create and register rule, run plugins.
*/
}, {
key: 'addRule',
value: function addRule(name, style, options) {
var rule = this.rules.add(name, style, options);
this.options.jss.plugins.onProcessRule(rule);
return rule;
}
/**
* Get index of a rule.
*/
}, {
key: 'indexOf',
value: function indexOf(rule) {
return this.rules.indexOf(rule);
}
/**
* Generates a CSS string.
*/
}, {
key: 'toString',
value: function toString() {
return this.rules.toString();
}
}]);
return GlobalContainerRule;
}();
var GlobalPrefixedRule = function () {
function GlobalPrefixedRule(name, style, options) {
_classCallCheck(this, GlobalPrefixedRule);
this.name = name;
this.options = options;
var selector = name.substr(prefixKey.length);
this.rule = options.jss.createRule(selector, style, _extends({}, options, {
parent: this,
selector: selector
}));
}
_createClass(GlobalPrefixedRule, [{
key: 'toString',
value: function toString(options) {
return this.rule.toString(options);
}
}]);
return GlobalPrefixedRule;
}();
var separatorRegExp = /\s*,\s*/g;
function addScope(selector, scope) {
var parts = selector.split(separatorRegExp);
var scoped = '';
for (var i = 0; i < parts.length; i++) {
scoped += scope + ' ' + parts[i].trim();
if (parts[i + 1]) scoped += ', ';
}
return scoped;
}
function handleNestedGlobalContainerRule(rule) {
var options = rule.options,
style = rule.style;
var rules = style[propKey];
if (!rules) return;
for (var name in rules) {
options.sheet.addRule(name, rules[name], _extends({}, options, {
selector: addScope(name, rule.selector)
}));
}
delete style[propKey];
}
function handlePrefixedGlobalRule(rule) {
var options = rule.options,
style = rule.style;
for (var prop in style) {
if (prop.substr(0, propKey.length) !== propKey) continue;
var selector = addScope(prop.substr(propKey.length), rule.selector);
options.sheet.addRule(selector, style[prop], _extends({}, options, {
selector: selector
}));
delete style[prop];
}
}
/**
* Convert nested rules to separate, remove them from original styles.
*
* @param {Rule} rule
* @api public
*/
function jssGlobal() {
function onCreateRule(name, styles, options) {
if (name === propKey) {
return new GlobalContainerRule(name, styles, options);
}
if (name[0] === '@' && name.substr(0, prefixKey.length) === prefixKey) {
return new GlobalPrefixedRule(name, styles, options);
}
var parent = options.parent;
if (parent) {
if (parent.type === 'global' || parent.options.parent.type === 'global') {
options.global = true;
}
}
if (options.global) options.selector = name;
return null;
}
function onProcessRule(rule) {
if (rule.type !== 'style') return;
handleNestedGlobalContainerRule(rule);
handlePrefixedGlobalRule(rule);
}
return { onCreateRule: onCreateRule, onProcessRule: onProcessRule };
}

View File

@@ -0,0 +1,257 @@
'use strict';
var _expect = require('expect.js');
var _expect2 = _interopRequireDefault(_expect);
var _jss = require('jss');
var _jssNested = require('jss-nested');
var _jssNested2 = _interopRequireDefault(_jssNested);
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var settings = {
createGenerateClassName: function createGenerateClassName() {
return function (rule) {
return rule.key + '-id';
};
}
};
describe('jss-global', function () {
var jss = void 0;
beforeEach(function () {
jss = (0, _jss.create)(settings).use((0, _index2['default'])());
});
describe('@global root container', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
'@global': {
a: { color: 'red' },
body: { color: 'green' }
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('@global')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('a')).to.be(undefined);
(0, _expect2['default'])(sheet.getRule('body')).to.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('a {\n' + ' color: red;\n' + '}\n' + 'body {\n' + ' color: green;\n' + '}');
});
});
describe('@global root prefix', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
'@global body': {
color: 'red'
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('body')).to.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('body {\n' + ' color: red;\n' + '}');
});
});
describe('@global scoped container', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global': {
span: { color: 'red' }
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id span')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id span {\n' + ' color: red;\n' + '}');
});
});
describe('@global scoped container with comma separate selectors', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global': {
'a, b': { color: 'red' }
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id a, .button-id b')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id a, .button-id b {\n' + ' color: red;\n' + '}');
});
});
describe('@global prefixed scoped rule', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global span': {
color: 'red'
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id span')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id span {\n' + ' color: red;\n' + '}');
});
});
describe('@global prefixed scoped rule with comma separate selectors', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
button: {
float: 'left',
'@global a, b': {
color: 'red'
}
}
});
});
it('should add rules', function () {
(0, _expect2['default'])(sheet.getRule('button')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('.button-id a, .button-id b')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.button-id {\n' + ' float: left;\n' + '}\n' + '.button-id a, .button-id b {\n' + ' color: red;\n' + '}');
});
});
describe('@global with nested rules inside', function () {
var jss2 = void 0;
beforeEach(function () {
jss2 = (0, _jss.create)({ plugins: [(0, _index2['default'])(), (0, _jssNested2['default'])()] });
});
it('should handle regular nested rules', function () {
var sheet = jss2.createStyleSheet({
'@global': {
button: {
color: 'red',
'& span': {
color: 'green'
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('button {\n' + ' color: red;\n' + '}\n' + 'button span {\n' + ' color: green;\n' + '}');
});
it('should handle nested rules inside of a rule with comma separated selector', function () {
var sheet = jss2.createStyleSheet({
'@global': {
'button, a': {
color: 'red',
'& span': {
color: 'green'
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('button, a {\n' + ' color: red;\n' + '}\n' + 'button span, a span {\n' + ' color: green;\n' + '}');
});
it('should handle regular deep nested rules', function () {
var sheet = jss2.createStyleSheet({
'@global': {
button: {
color: 'red',
'& span': {
color: 'green',
'& b': {
color: 'blue'
}
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('button {\n' + ' color: red;\n' + '}\n' + 'button span {\n' + ' color: green;\n' + '}\n' + 'button span b {\n' + ' color: blue;\n' + '}');
});
it('should handle nested conditional rules', function () {
var sheet = jss2.createStyleSheet({
'@global': {
html: {
color: 'red',
'@media (max-width: 767px)': {
color: 'green'
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('html {\n' + ' color: red;\n' + '}\n' + '@media (max-width: 767px) {\n' + ' html {\n' + ' color: green;\n' + ' }\n' + '}');
});
it('should handle conditionals with nesting inside', function () {
var sheet = jss2.createStyleSheet({
'@global': {
'@media (max-width: 767px)': {
html: {
color: 'red',
'& button': {
color: 'green'
}
}
}
}
});
(0, _expect2['default'])(sheet.toString()).to.be('@media (max-width: 767px) {\n' + ' html {\n' + ' color: red;\n' + ' }\n' + ' html button {\n' + ' color: green;\n' + ' }\n' + '}');
});
});
});

View File

@@ -0,0 +1,42 @@
'use strict'
const webpack = require('webpack')
const env = process.env.NODE_ENV
const isDev = env === 'development'
const isTest = env === 'test'
const isProd = env === 'production'
const plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
__DEV__: isDev,
__TEST__: isTest
})
]
if (isProd) {
plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}))
}
module.exports = {
output: {
library: 'jssGlobal',
libraryTarget: 'umd'
},
plugins,
module: {
loaders: [
{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
}
]
},
devtool: 'source-map'
}