Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export all babel-compiled src/modules to fix #110 #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
node_modules
coverage
_book
lib
129 changes: 129 additions & 0 deletions lib/CSSPropertyOperations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* CSS Property Operations
*/

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.setStyle = setStyle;
exports.removeStyle = removeStyle;
exports.patchStyle = patchStyle;

function setStyle(elemStyle, styles) {
for (var styleName in styles) {
if (styles.hasOwnProperty(styleName)) {
setStyleValue(elemStyle, styleName, styles[styleName]);
}
}
}

function removeStyle(elemStyle, styles) {
for (var styleName in styles) {
if (styles.hasOwnProperty(styleName)) {
elemStyle[styleName] = '';
}
}
}

function patchStyle(elemStyle, style, newStyle) {
if (style === newStyle) {
return;
}
if (!newStyle && style) {
removeStyle(elemStyle, style);
return;
} else if (newStyle && !style) {
setStyle(elemStyle, newStyle);
return;
}

for (var key in style) {
if (newStyle.hasOwnProperty(key)) {
if (newStyle[key] !== style[key]) {
setStyleValue(elemStyle, key, newStyle[key]);
}
} else {
elemStyle[key] = '';
}
}
for (var key in newStyle) {
if (!style.hasOwnProperty(key)) {
setStyleValue(elemStyle, key, newStyle[key]);
}
}
}

/**
* CSS properties which accept numbers but are not in units of "px".
*/
var isUnitlessNumber = {
animationIterationCount: 1,
borderImageOutset: 1,
borderImageSlice: 1,
borderImageWidth: 1,
boxFlex: 1,
boxFlexGroup: 1,
boxOrdinalGroup: 1,
columnCount: 1,
flex: 1,
flexGrow: 1,
flexPositive: 1,
flexShrink: 1,
flexNegative: 1,
flexOrder: 1,
gridRow: 1,
gridColumn: 1,
fontWeight: 1,
lineClamp: 1,
lineHeight: 1,
opacity: 1,
order: 1,
orphans: 1,
tabSize: 1,
widows: 1,
zIndex: 1,
zoom: 1,

// SVG-related properties
fillOpacity: 1,
floodOpacity: 1,
stopOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeMiterlimit: 1,
strokeOpacity: 1,
strokeWidth: 1
};

function prefixKey(prefix, key) {
return prefix + key.charAt(0).toUpperCase() + key.substring(1);
}

var prefixes = ['Webkit', 'ms', 'Moz', 'O'];

Object.keys(isUnitlessNumber).forEach(function (prop) {
prefixes.forEach(function (prefix) {
isUnitlessNumber[prefixKey(prefix, prop)] = 1;
});
});

var RE_NUMBER = /^-?\d+(\.\d+)?$/;
function setStyleValue(elemStyle, styleName, styleValue) {

if (!isUnitlessNumber[styleName] && RE_NUMBER.test(styleValue)) {
elemStyle[styleName] = styleValue + 'px';
return;
}

if (styleName === 'float') {
styleName = 'cssFloat';
}

if (styleValue == null || typeof styleValue === 'boolean') {
styleValue = '';
}

elemStyle[styleName] = styleValue;
}
124 changes: 124 additions & 0 deletions lib/Children.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.only = only;
exports.forEach = forEach;
exports.map = map;
exports.count = count;
exports.toArray = toArray;

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

var _util = require('./util');

var _ = _interopRequireWildcard(_util);

var _createElement = require('./createElement');

function only(children) {
if ((0, _createElement.isValidElement)(children)) {
return children;
}
throw new Error('expect only one child');
}

function forEach(children, iteratee, context) {
if (children == null) {
return children;
}
var index = 0;
if (_.isArr(children)) {
_.flatEach(children, function (child) {
// from traverseAllChildrenImpl in react
var type = typeof child;
if (type === 'undefined' || type === 'boolean') {
// All of the above are perceived as null.
child = null;
}

iteratee.call(context, child, index++);
});
} else {
// from traverseAllChildrenImpl in react
var type = typeof children;
if (type === 'undefined' || type === 'boolean') {
// All of the above are perceived as null.
children = null;
}
iteratee.call(context, children, index);
}
}

function map(children, iteratee, context) {
if (children == null) {
return children;
}
var store = [];
var keyMap = {};
forEach(children, function (child, index) {
var data = {};
data.child = iteratee.call(context, child, index) || child;
data.isEqual = data.child === child;
var key = data.key = getKey(child, index);
if (keyMap.hasOwnProperty(key)) {
keyMap[key] += 1;
} else {
keyMap[key] = 0;
}
data.index = keyMap[key];
_.addItem(store, data);
});
var result = [];
store.forEach(function (_ref) {
var child = _ref.child;
var key = _ref.key;
var index = _ref.index;
var isEqual = _ref.isEqual;

if (child == null || typeof child === 'boolean') {
return;
}
if (!(0, _createElement.isValidElement)(child) || key == null) {
_.addItem(result, child);
return;
}
if (keyMap[key] !== 0) {
key += ':' + index;
}
if (!isEqual) {
key = escapeUserProvidedKey(child.key || '') + '/' + key;
}
child = (0, _createElement.cloneElement)(child, { key: key });
_.addItem(result, child);
});
return result;
}

function count(children) {
var count = 0;
forEach(children, function () {
count++;
});
return count;
}

function toArray(children) {
return map(children, _.identity) || [];
}

function getKey(child, index) {
var key = undefined;
if ((0, _createElement.isValidElement)(child) && typeof child.key === 'string') {
key = '.$' + child.key;
} else {
key = '.' + index.toString(36);
}
return key;
}

var userProvidedKeyEscapeRegex = /\/(?!\/)/g;
function escapeUserProvidedKey(text) {
return ('' + text).replace(userProvidedKeyEscapeRegex, '//');
}
Loading