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

Upgrade to Babel 7 and Rollup 1.0 and generate updated build. #213

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["env", "react", "stage-3"]
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
230 changes: 129 additions & 101 deletions index.es.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,111 @@
import { icon, parse } from '@fortawesome/fontawesome-svg-core';
import { parse, icon } from '@fortawesome/fontawesome-svg-core';
import PropTypes from 'prop-types';
import React from 'react';

function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}

return _typeof(obj);
}

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}

return obj;
}

function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);

if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}

ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}

return target;
}

function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;

for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}

return target;
}

function _objectWithoutProperties(source, excluded) {
if (source == null) return {};

var target = _objectWithoutPropertiesLoose(source, excluded);

var key, i;

if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);

for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}

return target;
}

function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}

function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];

return arr2;
}
}

function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}

var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function createCommonjsModule(fn, module) {
Expand Down Expand Up @@ -140,63 +244,6 @@ var humps = createCommonjsModule(function (module) {
})(commonjsGlobal);
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};

var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}

return obj;
};

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 objectWithoutProperties = function (obj, keys) {
var target = {};

for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}

return target;
};

var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];

return arr2;
} else {
return Array.from(arr);
}
};

function capitalize(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
}
Expand All @@ -210,9 +257,7 @@ function styleToObject(style) {
var i = pair.indexOf(':');
var prop = humps.camelize(pair.slice(0, i));
var value = pair.slice(i + 1).trim();

prop.startsWith('webkit') ? acc[capitalize(prop)] = value : acc[prop] = value;

return acc;
}, {});
}
Expand All @@ -223,8 +268,8 @@ function convert(createElement, element) {
if (typeof element === 'string') {
return element;
}
var children = (element.children || []).map(convert.bind(null, createElement));

var children = (element.children || []).map(convert.bind(null, createElement));
var mixins = Object.keys(element.attributes || {}).reduce(function (acc, key) {
var val = element.attributes[key];

Expand All @@ -233,28 +278,31 @@ function convert(createElement, element) {
acc.attrs['className'] = val;
delete element.attributes['class'];
break;

case 'style':
acc.attrs['style'] = styleToObject(val);
break;

default:
if (key.indexOf('aria-') === 0 || key.indexOf('data-') === 0) {
acc.attrs[key.toLowerCase()] = val;
} else {
acc.attrs[humps.camelize(key)] = val;
}

}

return acc;
}, { attrs: {} });
}, {
attrs: {}
});

var _extraProps$style = extraProps.style,
existingStyle = _extraProps$style === undefined ? {} : _extraProps$style,
remaining = objectWithoutProperties(extraProps, ['style']);
existingStyle = _extraProps$style === void 0 ? {} : _extraProps$style,
remaining = _objectWithoutProperties(extraProps, ["style"]);


mixins.attrs['style'] = _extends({}, mixins.attrs['style'], existingStyle);

return createElement.apply(undefined, [element.tag, _extends({}, mixins.attrs, remaining)].concat(toConsumableArray(children)));
mixins.attrs['style'] = _objectSpread({}, mixins.attrs['style'], existingStyle);
return createElement.apply(void 0, [element.tag, _objectSpread({}, mixins.attrs, remaining)].concat(_toConsumableArray(children)));
}

var PRODUCTION = false;
Expand All @@ -272,7 +320,7 @@ function log () {
}

function objectWithKey(key, value) {
return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? defineProperty({}, key, value) : {};
return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty({}, key, value) : {};
}

function classList(props) {
Expand All @@ -287,8 +335,7 @@ function classList(props) {
'fa-li': props.listItem,
'fa-flip-horizontal': props.flip === 'horizontal' || props.flip === 'both',
'fa-flip-vertical': props.flip === 'vertical' || props.flip === 'both'
}, defineProperty(_classes, 'fa-' + props.size, props.size !== null), defineProperty(_classes, 'fa-rotate-' + props.rotation, props.rotation !== null), defineProperty(_classes, 'fa-pull-' + props.pull, props.pull !== null), _classes);

}, _defineProperty(_classes, "fa-".concat(props.size), props.size !== null), _defineProperty(_classes, "fa-rotate-".concat(props.rotation), props.rotation !== null), _defineProperty(_classes, "fa-pull-".concat(props.pull), props.pull !== null), _classes);
return Object.keys(classes).map(function (key) {
return classes[key] ? key : null;
}).filter(function (key) {
Expand All @@ -301,16 +348,22 @@ function normalizeIconArgs(icon$$1) {
return null;
}

if ((typeof icon$$1 === 'undefined' ? 'undefined' : _typeof(icon$$1)) === 'object' && icon$$1.prefix && icon$$1.iconName) {
if (_typeof(icon$$1) === 'object' && icon$$1.prefix && icon$$1.iconName) {
return icon$$1;
}

if (Array.isArray(icon$$1) && icon$$1.length === 2) {
return { prefix: icon$$1[0], iconName: icon$$1[1] };
return {
prefix: icon$$1[0],
iconName: icon$$1[1]
};
}

if (typeof icon$$1 === 'string') {
return { prefix: 'fas', iconName: icon$$1 };
return {
prefix: 'fas',
iconName: icon$$1
};
}
}

Expand All @@ -320,14 +373,11 @@ function FontAwesomeIcon(props) {
symbol = props.symbol,
className = props.className,
title = props.title;


var iconLookup = normalizeIconArgs(iconArgs);
var classes = objectWithKey('classes', [].concat(toConsumableArray(classList(props)), toConsumableArray(className.split(' '))));
var classes = objectWithKey('classes', [].concat(_toConsumableArray(classList(props)), _toConsumableArray(className.split(' '))));
var transform = objectWithKey('transform', typeof props.transform === 'string' ? parse.transform(props.transform) : props.transform);
var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));

var renderedIcon = icon(iconLookup, _extends({}, classes, transform, mask, {
var renderedIcon = icon(iconLookup, _objectSpread({}, classes, transform, mask, {
symbol: symbol,
title: title
}));
Expand All @@ -338,54 +388,33 @@ function FontAwesomeIcon(props) {
}

var abstract = renderedIcon.abstract;

var extraProps = {};

Object.keys(props).forEach(function (key) {
if (!FontAwesomeIcon.defaultProps.hasOwnProperty(key)) {
extraProps[key] = props[key];
}
});

return convertCurry(abstract[0], extraProps);
}

FontAwesomeIcon.displayName = 'FontAwesomeIcon';

FontAwesomeIcon.propTypes = {
border: PropTypes.bool,

className: PropTypes.string,

mask: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string]),

fixedWidth: PropTypes.bool,

inverse: PropTypes.bool,

flip: PropTypes.oneOf(['horizontal', 'vertical', 'both']),

icon: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string]),

listItem: PropTypes.bool,

pull: PropTypes.oneOf(['right', 'left']),

pulse: PropTypes.bool,

rotation: PropTypes.oneOf([90, 180, 270]),

size: PropTypes.oneOf(['lg', 'xs', 'sm', '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', '10x']),

spin: PropTypes.bool,

symbol: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),

title: PropTypes.string,

transform: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
};

FontAwesomeIcon.defaultProps = {
border: false,
className: '',
Expand All @@ -404,7 +433,6 @@ FontAwesomeIcon.defaultProps = {
title: '',
transform: null
};

var convertCurry = convert.bind(null, React.createElement);

export { FontAwesomeIcon };