Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

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

View File

@@ -1,3 +1,7 @@
## 3.0.0 / 2017-09-30
- Support JSS 9
## 2.0.0 / 2017-06-20
- Support JSS 8

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

@@ -1,50 +1,41 @@
{
"name": "jss-global",
"version": "2.0.0",
"description": "Global styles for JSS",
"main": "lib/index.js",
"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: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",
"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",
"clean": "rimraf {lib,dist,tests,tmp}/*",
"lint": "eslint ./src",
"lint:staged": "lint-staged",
"test": "cross-env NODE_ENV=test karma start --single-run ",
"test:watch": "cross-env NODE_ENV=test karma start",
"prepublishOnly": "npm run all"
},
"repository": {
"type": "git",
"url": "https://github.com/cssinjs/jss-global.git"
},
"keywords": [
"cssinjs",
"css-in-js",
"css in js",
"jss",
"plugin",
"global",
"unscoped"
"_args": [
[
"jss-global@3.0.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
]
],
"_from": "jss-global@3.0.0",
"_id": "jss-global@3.0.0",
"_inBundle": false,
"_integrity": "sha512-wxYn7vL+TImyQYGAfdplg7yaxnPQ9RaXY/cIA8hawaVnmmWxDHzBK32u1y+RAvWboa3lW83ya3nVZ/C+jyjZ5Q==",
"_location": "/material-ui/jss-global",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "jss-global@3.0.0",
"name": "jss-global",
"escapedName": "jss-global",
"rawSpec": "3.0.0",
"saveSpec": null,
"fetchSpec": "3.0.0"
},
"_requiredBy": [
"/material-ui",
"/material-ui/jss-preset-default"
],
"_resolved": "https://registry.npmjs.org/jss-global/-/jss-global-3.0.0.tgz",
"_spec": "3.0.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
"author": {
"name": "Oleg Slobodskoi",
"email": "oleg008@gmail.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/cssinjs/jss/issues/new?title=[jss-global]"
},
"homepage": "https://github.com/cssinjs/jss-global",
"peerDependencies": {
"jss": "^8.0.0"
},
"description": "Global styles for JSS",
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.9.1",
@@ -64,8 +55,8 @@
"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",
"jss": "^9.0.0",
"jss-nested": "^6.0.0",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
@@ -79,11 +70,49 @@
"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"
]
},
"pre-commit": "lint:staged"
"main": "lib/index.js",
"name": "jss-global",
"peerDependencies": {
"jss": "^9.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": "3.0.0"
}

View File

@@ -1,191 +0,0 @@
'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

@@ -1,257 +0,0 @@
'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' + '}');
});
});
});