Component style will not pollute the child component

This commit is contained in:
dntzhang 2018-05-09 15:51:47 +08:00
parent 25a5cfb5fc
commit b471681c07
16 changed files with 1395 additions and 1391 deletions

View File

@ -257,8 +257,8 @@ npm i omi
或从 CDN 获取:
* [https://unpkg.com/omi@3.0.0/dist/omi.min.js](https://unpkg.com/omi@3.0.0/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.0/dist/omi.js](https://unpkg.com/omi@3.0.0/dist/omi.js)
* [https://unpkg.com/omi@3.0.1/dist/omi.min.js](https://unpkg.com/omi@3.0.1/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.1/dist/omi.js](https://unpkg.com/omi@3.0.1/dist/omi.js)
## Official Plugins

View File

@ -256,8 +256,8 @@ npm i omi
or get it from CDN:
* [https://unpkg.com/omi@3.0.0/dist/omi.min.js](https://unpkg.com/omi@3.0.0/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.0/dist/omi.js](https://unpkg.com/omi@3.0.0/dist/omi.js)
* [https://unpkg.com/omi@3.0.1/dist/omi.min.js](https://unpkg.com/omi@3.0.1/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.1/dist/omi.js](https://unpkg.com/omi@3.0.1/dist/omi.js)
## Official Plugins

3
change-log.md Normal file
View File

@ -0,0 +1,3 @@
# omi 3.0.1
Solve component style scope. Component style will not pollute the child component.

18
dist/omi.dev.js vendored
View File

@ -1,5 +1,5 @@
/**
* omi v3.0.0 http://omijs.org
* omi v3.0.1 http://omijs.org
* Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.
* By dntzhang https://github.com/dntzhang
* Github: https://github.com/AlloyTeam/omi
@ -50,8 +50,6 @@
var EMPTY_CHILDREN = [];
var isH5 = options.isWeb;
var map = {
'br': 'view',
'hr': 'view',
@ -255,9 +253,9 @@
}
var p = new VNode();
p.nodeName = isH5 ? nodeName : map[nodeName];
p.nodeName = options.isWeb ? nodeName : map[nodeName];
p.attributes = attributes == null ? undefined : attributes;
if (children && typeof children[0] === 'string' && !isH5) {
if (children && typeof children[0] === 'string' && !options.isWeb) {
if (p.attributes) {
p.attributes.value = children[0];
} else {
@ -447,8 +445,6 @@
}return style;
}
var isH5$1 = options.isWeb;
/** Remove a child node from its parent if attached.
* @param {Element} node The node to remove
*/
@ -477,7 +473,7 @@
} else if (name === 'class' && !isSvg) {
node.className = value || '';
} else if (name === 'style') {
if (isH5$1) {
if (options.isWeb) {
if (!value || typeof value === 'string' || typeof old === 'string') {
node.style.cssText = value || '';
}
@ -932,8 +928,10 @@
}
var appendClass = g1.replace(/(\s*)$/, '') + prefix + g2;
var prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + ',' + prependClass + g3;
//let prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + g3;
//return appendClass + ',' + prependClass + g3;
});
return css;

2
dist/omi.dev.js.map vendored

File diff suppressed because one or more lines are too long

18
dist/omi.esm.js vendored
View File

@ -1,5 +1,5 @@
/**
* omi v3.0.0 http://omijs.org
* omi v3.0.1 http://omijs.org
* Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.
* By dntzhang https://github.com/dntzhang
* Github: https://github.com/AlloyTeam/omi
@ -47,8 +47,6 @@ var stack = [];
var EMPTY_CHILDREN = [];
var isH5 = options.isWeb;
var map = {
'br': 'view',
'hr': 'view',
@ -252,9 +250,9 @@ function h(nodeName, attributes) {
}
var p = new VNode();
p.nodeName = isH5 ? nodeName : map[nodeName];
p.nodeName = options.isWeb ? nodeName : map[nodeName];
p.attributes = attributes == null ? undefined : attributes;
if (children && typeof children[0] === 'string' && !isH5) {
if (children && typeof children[0] === 'string' && !options.isWeb) {
if (p.attributes) {
p.attributes.value = children[0];
} else {
@ -444,8 +442,6 @@ function parseCSSText(cssText) {
}return style;
}
var isH5$1 = options.isWeb;
/** Remove a child node from its parent if attached.
* @param {Element} node The node to remove
*/
@ -474,7 +470,7 @@ function setAccessor(node, name, old, value, isSvg) {
} else if (name === 'class' && !isSvg) {
node.className = value || '';
} else if (name === 'style') {
if (isH5$1) {
if (options.isWeb) {
if (!value || typeof value === 'string' || typeof old === 'string') {
node.style.cssText = value || '';
}
@ -929,8 +925,10 @@ function scoper(css, prefix) {
}
var appendClass = g1.replace(/(\s*)$/, '') + prefix + g2;
var prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + ',' + prependClass + g3;
//let prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + g3;
//return appendClass + ',' + prependClass + g3;
});
return css;

2
dist/omi.esm.js.map vendored

File diff suppressed because one or more lines are too long

11
dist/omi.js vendored
View File

@ -15,9 +15,9 @@
lastSimple = simple;
}
var p = new VNode();
p.nodeName = isH5 ? nodeName : map[nodeName];
p.nodeName = options.isWeb ? nodeName : map[nodeName];
p.attributes = null == attributes ? void 0 : attributes;
if (children && 'string' == typeof children[0] && !isH5) if (p.attributes) p.attributes.value = children[0]; else p.attributes = {
if (children && 'string' == typeof children[0] && !options.isWeb) if (p.attributes) p.attributes.value = children[0]; else p.attributes = {
value: children[0]
}; else p.children = children;
p.key = null == attributes ? void 0 : attributes.key;
@ -101,7 +101,7 @@
if ('key' === name) ; else if ('ref' === name) {
if (old) old(null);
if (value) value(node);
} else if ('class' === name && !isSvg) node.className = value || ''; else if ('style' === name) if (isH5$1) {
} else if ('class' === name && !isSvg) node.className = value || ''; else if ('style' === name) if (options.isWeb) {
if (!value || 'string' == typeof value || 'string' == typeof old) node.style.cssText = value || '';
if (value && 'object' == typeof value) {
if ('string' != typeof old) for (var i in old) if (!(i in value)) node.style[i] = '';
@ -297,8 +297,7 @@
if (void 0 === g2) g2 = '';
if (g1.match(/^\s*(@media|\d+%?|@-webkit-keyframes|@keyframes|to|from|@font-face)/)) return g1 + g2 + g3;
var appendClass = g1.replace(/(\s*)$/, '') + prefix + g2;
var prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + ',' + prependClass + g3;
return appendClass + g3;
});
return css;
}
@ -525,7 +524,6 @@
};
var stack = [];
var EMPTY_CHILDREN = [];
var isH5 = options.isWeb;
var map = {
br: 'view',
hr: 'view',
@ -655,7 +653,6 @@
var defer = usePromise ? Promise.resolve().then.bind(Promise.resolve()) : setTimeout;
var IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
var items = [];
var isH5$1 = options.isWeb;
var mounts = [];
var diffLevel = 0;
var isSvgMode = !1;

2
dist/omi.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/omi.min.js vendored

File diff suppressed because one or more lines are too long

2
dist/omi.min.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
import { render, Component } from '../../dist/omi.esm';
import { render, Component } from '../../src/omi';
class Hello extends Component {
render() {
return <div> {this.props.name}</div>
return <h3> {this.props.name}</h3>
}
}
@ -19,15 +19,15 @@ class App extends Component {
style() {
return `h3{
cursor:pointer;
color: ${Math.random() > 0.5 ? 'red' :'green'};
}`
cursor:pointer;
color: ${Math.random() > 0.5 ? 'red' :'green'};
}`
}
staticStyle() {
return `div{
font-size:20px;
}`
font-size:20px;
}`
}
render() {

View File

@ -1,6 +1,6 @@
{
"name": "omi",
"version": "3.0.0",
"version": "3.0.1",
"description": "Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.",
"main": "dist/omi.js",
"jsnext:main": "dist/omi.esm.js",

View File

@ -27,8 +27,10 @@ export function scoper(css, prefix) {
}
let appendClass = g1.replace(/(\s*)$/, '') + prefix + g2;
let prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + ',' + prependClass + g3;
//let prependClass = prefix + ' ' + g1.trim() + g2;
return appendClass + g3;
//return appendClass + ',' + prependClass + g3;
});
return css;