emoji-mart-lazyload/dist/emoji-picker.js

3998 lines
683 KiB
JavaScript
Raw Normal View History

2016-07-06 14:32:52 +00:00
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
2016-07-11 19:21:13 +00:00
module.exports = factory(require("React"));
2016-07-06 14:32:52 +00:00
else if(typeof define === 'function' && define.amd)
2016-07-11 19:21:13 +00:00
define(["React"], factory);
2016-07-06 14:32:52 +00:00
else if(typeof exports === 'object')
2016-07-11 19:21:13 +00:00
exports["EmojiPicker"] = factory(require("React"));
2016-07-06 14:32:52 +00:00
else
2016-07-11 19:21:13 +00:00
root["EmojiPicker"] = factory(root["React"]);
2016-07-06 14:32:52 +00:00
})(this, function(__WEBPACK_EXTERNAL_MODULE_3__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // Flag the module as loaded
/******/ module.loaded = true;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _components = __webpack_require__(1);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Picker', {
enumerable: true,
get: function get() {
return _components.Picker;
}
});
Object.defineProperty(exports, 'Emoji', {
enumerable: true,
get: function get() {
return _components.Emoji;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _utils = __webpack_require__(16);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, 'emojiIndex', {
enumerable: true,
get: function get() {
return _utils.emojiIndex;
}
});
2016-07-06 14:32:52 +00:00
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _anchors = __webpack_require__(2);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Anchors', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_anchors).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _category = __webpack_require__(15);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Category', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_category).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _emoji = __webpack_require__(22);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Emoji', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_emoji).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _picker = __webpack_require__(23);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Picker', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_picker).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _preview = __webpack_require__(25);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Preview', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_preview).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _search = __webpack_require__(26);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Search', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_search).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _skins = __webpack_require__(27);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Skins', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_skins).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _svgInlineReact = __webpack_require__(4);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _svgInlineReact2 = _interopRequireDefault(_svgInlineReact);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _svgs = __webpack_require__(5);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var SVGs = _interopRequireWildcard(_svgs);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; } }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var Anchors = function (_React$Component) {
_inherits(Anchors, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function Anchors(props) {
_classCallCheck(this, Anchors);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Anchors).call(this, props));
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var defaultCategory = props.categories[0];
if (defaultCategory.anchor) {
defaultCategory = defaultCategory.anchor;
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_this.state = {
2016-07-11 18:22:39 +00:00
selected: defaultCategory.name
2016-07-06 14:32:52 +00:00
};
return _this;
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_createClass(Anchors, [{
key: 'render',
value: function render() {
var _props = this.props;
var categories = _props.categories;
var onAnchorClick = _props.onAnchorClick;
var selected = this.state.selected;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _react2.default.createElement(
'div',
{ className: 'emoji-picker-anchors' },
categories.map(function (category, i) {
var name = category.name;
2016-07-11 18:22:39 +00:00
var anchor = category.anchor;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (anchor) {
return null;
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _react2.default.createElement(
'span',
{
key: name,
title: name,
onClick: function onClick() {
return onAnchorClick(category, i);
},
className: 'emoji-picker-anchor ' + (name == selected ? 'emoji-picker-anchor-selected' : '')
},
_react2.default.createElement(_svgInlineReact2.default, { src: SVGs[name] }),
_react2.default.createElement('span', { className: 'emoji-picker-anchor-bar' })
);
})
);
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return Anchors;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
exports.default = Anchors;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Anchors.propTypes = {
categories: _react2.default.PropTypes.array,
onAnchorClick: _react2.default.PropTypes.func
};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Anchors.defaultProps = {
categories: [],
onAnchorClick: function onAnchorClick() {}
};
/***/ },
/* 3 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, '__esModule', {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; };
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; }; })();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var DOMParser = typeof window !== 'undefined' && window.DOMParser;
var process = process || {};
process.env = process.env || {};
var parserAvailable = typeof DOMParser !== 'undefined' && DOMParser.prototype != null && DOMParser.prototype.parseFromString != null;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if ("production" !== process.env.NODE_ENV && !parserAvailable) {
console.info('<InlineSVG />: `raw` prop works only when `window.DOMParser` exists.');
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function isParsable(src) {
// kinda naive but meh, ain't gonna use full-blown parser for this
return parserAvailable && typeof src === 'string' && src.trim().substr(0, 4) === '<svg';
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
// parse SVG string using `DOMParser`
function parseFromSVGString(src) {
var parser = new DOMParser();
return parser.parseFromString(src, "image/svg+xml");
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
// Transform DOM prop/attr names applicable to `<svg>` element but react-limited
function switchSVGAttrToReactProp(propName) {
switch (propName) {
case 'class':
return 'className';
default:
return propName;
}
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var InlineSVG = (function (_React$Component) {
_inherits(InlineSVG, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_createClass(InlineSVG, null, [{
key: 'defaultProps',
value: {
element: 'i',
raw: false,
src: ''
},
enumerable: true
}, {
key: 'propTypes',
value: {
src: _react2['default'].PropTypes.string.isRequired,
element: _react2['default'].PropTypes.string,
raw: _react2['default'].PropTypes.bool
},
enumerable: true
}]);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function InlineSVG(props) {
_classCallCheck(this, InlineSVG);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_get(Object.getPrototypeOf(InlineSVG.prototype), 'constructor', this).call(this, props);
this._extractSVGProps = this._extractSVGProps.bind(this);
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
// Serialize `Attr` objects in `NamedNodeMap`
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_createClass(InlineSVG, [{
key: '_serializeAttrs',
value: function _serializeAttrs(map) {
var ret = {};
var prop = undefined;
for (var i = 0; i < map.length; i++) {
prop = switchSVGAttrToReactProp(map[i].name);
ret[prop] = map[i].value;
}
return ret;
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
// get <svg /> element props
}, {
key: '_extractSVGProps',
value: function _extractSVGProps(src) {
var map = parseFromSVGString(src).documentElement.attributes;
return map.length > 0 ? this._serializeAttrs(map) : null;
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
// get content inside <svg> element.
}, {
key: '_stripSVG',
value: function _stripSVG(src) {
return parseFromSVGString(src).documentElement.innerHTML;
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(_ref) {
var children = _ref.children;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if ("production" !== process.env.NODE_ENV && children != null) {
console.info('<InlineSVG />: `children` prop will be ignored.');
}
}
}, {
key: 'render',
value: function render() {
var Element = undefined,
__html = undefined,
svgProps = undefined;
var _props = this.props;
var element = _props.element;
var raw = _props.raw;
var src = _props.src;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if (raw === true && isParsable(src)) {
Element = 'svg';
svgProps = this._extractSVGProps(src);
__html = this._stripSVG(src);
}
__html = __html || src;
Element = Element || element;
svgProps = svgProps || {};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _react2['default'].createElement(Element, _extends({}, svgProps, this.props, { src: null, children: null,
dangerouslySetInnerHTML: { __html: __html } }));
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return InlineSVG;
})(_react2['default'].Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
exports['default'] = InlineSVG;
module.exports = exports['default'];
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _activity = __webpack_require__(6);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Activity', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_activity).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _flags = __webpack_require__(7);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Flags', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_flags).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _foods = __webpack_require__(8);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Foods', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_foods).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _nature = __webpack_require__(9);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Nature', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_nature).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _objects = __webpack_require__(10);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Objects', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_objects).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _people = __webpack_require__(11);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'People', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_people).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _places = __webpack_require__(12);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Places', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_places).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _recent = __webpack_require__(13);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Recent', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_recent).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _symbols = __webpack_require__(14);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, 'Symbols', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_symbols).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/***/ },
/* 6 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 0C5.373 0 0 5.372 0 12c0 6.627 5.373 12 12 12 6.628 0 12-5.373 12-12 0-6.628-5.372-12-12-12m9.949 11H17.05c.224-2.527 1.232-4.773 1.968-6.113A9.966 9.966 0 0 1 21.949 11M13 11V2.051a9.945 9.945 0 0 1 4.432 1.564c-.858 1.491-2.156 4.22-2.392 7.385H13zm-2 0H8.961c-.238-3.165-1.536-5.894-2.393-7.385A9.95 9.95 0 0 1 11 2.051V11zm0 2v8.949a9.937 9.937 0 0 1-4.432-1.564c.857-1.492 2.155-4.221 2.393-7.385H11zm4.04 0c.236 3.164 1.534 5.893 2.392 7.385A9.92 9.92 0 0 1 13 21.949V13h2.04zM4.982 4.887C5.718 6.227 6.726 8.473 6.951 11h-4.9a9.977 9.977 0 0 1 2.931-6.113M2.051 13h4.9c-.226 2.527-1.233 4.771-1.969 6.113A9.972 9.972 0 0 1 2.051 13m16.967 6.113c-.735-1.342-1.744-3.586-1.968-6.113h4.899a9.961 9.961 0 0 1-2.931 6.113\"></path></svg>"
/***/ },
/* 7 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M0 0l6.084 24H8L1.916 0zM21 5h-4l-1-4H4l3 12h3l1 4h13L21 5zM6.563 3h7.875l2 8H8.563l-2-8zm8.832 10l-2.856 1.904L12.063 13h3.332zM19 13l-1.5-6h1.938l2 8H16l3-2z\"></path></svg>"
/***/ },
/* 8 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M17 4.978c-1.838 0-2.876.396-3.68.934.513-1.172 1.768-2.934 4.68-2.934a1 1 0 0 0 0-2c-2.921 0-4.629 1.365-5.547 2.512-.064.078-.119.162-.18.244C11.73 1.838 10.798.023 9.207.023 8.579.022 7.85.306 7 .978 5.027 2.54 5.329 3.902 6.492 4.999 3.609 5.222 0 7.352 0 12.969c0 4.582 4.961 11.009 9 11.009 1.975 0 2.371-.486 3-1 .629.514 1.025 1 3 1 4.039 0 9-6.418 9-11 0-5.953-4.055-8-7-8M8.242 2.546c.641-.508.943-.523.965-.523.426.169.975 1.405 1.357 3.055-1.527-.629-2.741-1.352-2.98-1.846.059-.112.241-.356.658-.686M15 21.978c-1.08 0-1.21-.109-1.559-.402l-.176-.146c-.367-.302-.816-.452-1.266-.452s-.898.15-1.266.452l-.176.146c-.347.292-.477.402-1.557.402-2.813 0-7-5.389-7-9.009 0-5.823 4.488-5.991 5-5.991 1.939 0 2.484.471 3.387 1.251l.323.276a1.995 1.995 0 0 0 2.58 0l.323-.276c.902-.78 1.447-1.251 3.387-1.251.512 0 5 .168 5 6 0 3.617-4.187 9-7 9\"></path></svg>"
/***/ },
/* 9 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M15.5 8a1.5 1.5 0 1 0 .001 3.001A1.5 1.5 0 0 0 15.5 8M8.5 8a1.5 1.5 0 1 0 .001 3.001A1.5 1.5 0 0 0 8.5 8\"></path><path d=\"M18.933 0h-.027c-.97 0-2.138.787-3.018 1.497-1.274-.374-2.612-.51-3.887-.51-1.285 0-2.616.133-3.874.517C7.245.79 6.069 0 5.093 0h-.027C3.352 0 .07 2.67.002 7.026c-.039 2.479.276 4.238 1.04 5.013.254.258.882.677 1.295.882.191 3.177.922 5.238 2.536 6.38.897.637 2.187.949 3.2 1.102C8.04 20.6 8 20.795 8 21c0 1.773 2.35 3 4 3 1.648 0 4-1.227 4-3 0-.201-.038-.393-.072-.586 2.573-.385 5.435-1.877 5.925-7.587.396-.22.887-.568 1.104-.788.763-.774 1.079-2.534 1.04-5.013C23.929 2.67 20.646 0 18.933 0M3.223 9.135c-.237.281-.837 1.155-.884 1.238-.15-.41-.368-1.349-.337-3.291.051-3.281 2.478-4.972 3.091-5.031.256.015.731.27 1.265.646-1.11 1.171-2.275 2.915-2.352 5.125-.133.546-.398.858-.783 1.313M12 22c-.901 0-1.954-.693-2-1 0-.654.475-1.236 1-1.602V20a1 1 0 1 0 2 0v-.602c.524.365 1 .947 1 1.602-.046.307-1.099 1-2 1m3-3.48v.02a4.752 4.752 0 0 0-1.262-1.02c1.092-.516 2.239-1.334 2.239-2.217 0-1.842-1.781-2.195-3.977-2.195-2.196 0-3.978.354-3.978 2.195 0 .883 1.148 1.701 2.238 2.217A4.8 4.8 0 0 0 9 18.539v-.025c-1-.076-2.182-.281-2.973-.842-1.301-.92-1.838-3.045-1.853-6.478l.023-.041c.496-.826 1.49-1.45 1.804-3.102 0-2.047 1.357-3.631 2.362-4.522C9.37 3.178 10.555 3 11.948 3c1.447 0 2.685.192 3.733.57 1 .9 2.316 2.465 2.316 4.48.313 1.651 1.307 2.275 1.803 3.102.035.058.068.117.102.178-.059 5.967-1.949 7.01-4.902 7.19m6.628-8.202c-.037-.065-.074-.13-.113-.195a7.587 7.587 0 0 0-.739-.987c-.385-.455-.648-.768-.782-1.313-.076-2.209-1.241-3.954-2.353-5.124.531-.376 1.004-.63 1.261-.647.636.071 3.044 1.764 3.096 5.031.027 1.81-.347 3.218-.37 3.235\"></path></svg>"
/***/ },
/* 10 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 0a9 9 0 0 0-5 16.482V21s2.035 3 5 3 5-3 5-3v-4.518A9 9 0 0 0 12 0zm0 2c3.86 0 7 3.141 7 7s-3.14 7-7 7-7-3.141-7-7 3.14-7 7-7zM9 17.477c.94.332 1.946.523 3 .523s2.06-.19 3-.523v.834c-.91.436-1.925.689-3 .689a6.924 6.924 0 0 1-3-.69v-.833zm.236 3.07A8.854 8.854 0 0 0 12 21c.965 0 1.888-.167 2.758-.451C14.155 21.173 13.153 22 12 22c-1.102 0-2.117-.789-2.764-1.453z\"></path><path d=\"M14.745 12.449h-.004c-.852-.024-1.188-.858-1.577-1.824-.421-1.061-.703-1.561-1.182-1.566h-.009c-.481 0-.783.497-1.235 1.537-.436.982-.801 1.811-1.636 1.791l-.276-.043c-.565-.171-.853-.691-1.284-1.794-.125-.313-.202-.632-.27-.913-.051-.213-.127-.53-.195-.634C7.067 9.004 7.039 9 6.99 9A1 1 0 0 1 7 7h.01c1.662.017 2.015 1.373 2.198 2.134.486-.981 1.304-2.058 2.797-2.075 1.531.018 2.28 1.153 2.731 2.141l.002-.008C14.944 8.424 15.327 7 16.979 7h.032A1 1 0 1 1 17 9h-.011c-.149.076-.256.474-.319.709a6.484 6.484 0 0 1-.311.951c-.429.973-.79 1.789-1.614 1.789\"></path></svg>"
/***/ },
/* 11 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0m0 22C6.486 22 2 17.514 2 12S6.486 2 12 2s10 4.486 10 10-4.486 10-10 10\"></path><path d=\"M8 7a2 2 0 1 0-.001 3.999A2 2 0 0 0 8 7M16 7a2 2 0 1 0-.001 3.999A2 2 0 0 0 16 7M15.232 15c-.693 1.195-1.87 2-3.349 2-1.477 0-2.655-.805-3.347-2H15m3-2H6a6 6 0 1 0 12 0\"></path></svg>"
/***/ },
/* 12 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M6.5 12C5.122 12 4 13.121 4 14.5S5.122 17 6.5 17 9 15.879 9 14.5 7.878 12 6.5 12m0 3c-.275 0-.5-.225-.5-.5s.225-.5.5-.5.5.225.5.5-.225.5-.5.5M17.5 12c-1.378 0-2.5 1.121-2.5 2.5s1.122 2.5 2.5 2.5 2.5-1.121 2.5-2.5-1.122-2.5-2.5-2.5m0 3c-.275 0-.5-.225-.5-.5s.225-.5.5-.5.5.225.5.5-.225.5-.5.5\"></path><path d=\"M22.482 9.494l-1.039-.346L21.4 9h.6c.552 0 1-.439 1-.992 0-.006-.003-.008-.003-.008H23c0-1-.889-2-1.984-2h-.642l-.731-1.717C19.262 3.012 18.091 2 16.764 2H7.236C5.909 2 4.738 3.012 4.357 4.283L3.626 6h-.642C1.889 6 1 7 1 8h.003S1 8.002 1 8.008C1 8.561 1.448 9 2 9h.6l-.043.148-1.039.346a2.001 2.001 0 0 0-1.359 2.097l.751 7.508a1 1 0 0 0 .994.901H3v1c0 1.103.896 2 2 2h2c1.104 0 2-.897 2-2v-1h6v1c0 1.103.896 2 2 2h2c1.104 0 2-.897 2-2v-1h1.096a.999.999 0 0 0 .994-.901l.751-7.508a2.001 2.001 0 0 0-1.359-2.097M6.273 4.857C6.402 4.43 6.788 4 7.236 4h9.527c.448 0 .834.43.963.857L19.313 9H4.688l1.585-4.143zM7 21H5v-1h2v1zm12 0h-2v-1h2v1zm2.189-3H2.811l-.662-6.607L3 11h18l.852.393L21.189 18z\"></path></svg>"
/***/ },
/* 13 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M13 4h-2l-.001 7H9v2h2v2h2v-2h4v-2h-4z\"></path><path d=\"M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0m0 22C6.486 22 2 17.514 2 12S6.486 2 12 2s10 4.486 10 10-4.486 10-10 10\"></path></svg>"
/***/ },
/* 14 */
/***/ function(module, exports) {
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M0 0h11v2H0zM4 11h3V6h4V4H0v2h4zM15.5 17c1.381 0 2.5-1.116 2.5-2.493s-1.119-2.493-2.5-2.493S13 13.13 13 14.507 14.119 17 15.5 17m0-2.986c.276 0 .5.222.5.493 0 .272-.224.493-.5.493s-.5-.221-.5-.493.224-.493.5-.493M21.5 19.014c-1.381 0-2.5 1.116-2.5 2.493S20.119 24 21.5 24s2.5-1.116 2.5-2.493-1.119-2.493-2.5-2.493m0 2.986a.497.497 0 0 1-.5-.493c0-.271.224-.493.5-.493s.5.222.5.493a.497.497 0 0 1-.5.493M22 13l-9 9 1.513 1.5 8.99-9.009zM17 11c2.209 0 4-1.119 4-2.5V2s.985-.161 1.498.949C23.01 4.055 23 6 23 6s1-1.119 1-3.135C24-.02 21 0 21 0h-2v6.347A5.853 5.853 0 0 0 17 6c-2.209 0-4 1.119-4 2.5s1.791 2.5 4 2.5M10.297 20.482l-1.475-1.585a47.54 47.54 0 0 1-1.442 1.129c-.307-.288-.989-1.016-2.045-2.183.902-.836 1.479-1.466 1.729-1.892s.376-.871.376-1.336c0-.592-.273-1.178-.818-1.759-.546-.581-1.329-.871-2.349-.871-1.008 0-1.79.293-2.344.879-.556.587-.832 1.181-.832 1.784 0 .813.419 1.748 1.256 2.805-.847.614-1.444 1.208-1.794 1.784a3.465 3.465 0 0 0-.523 1.833c0 .857.308 1.56.924 2.107.616.549 1.423.823 2.42.823 1.173 0 2.444-.379 3.813-1.137L8.235 24h2.819l-2.09-2.383 1.333-1.135zm-6.736-6.389a1.02 1.02 0 0 1 .73-.286c.31 0 .559.085.747.254a.849.849 0 0 1 .283.659c0 .518-.419 1.112-1.257 1.784-.536-.651-.805-1.231-.805-1.742a.901.901 0 0 1 .302-.669M3.74 22c-.427 0-.778-.116-1.057-.349-.279-.232-.418-.487-.418-.766 0-.594.509-1.288 1.527-2.083.968 1.134 1.717 1.946 2.248 2.438-.921.507-1.686.76-2.3.76\"></path></svg>"
/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; };
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _utils = __webpack_require__(16);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _ = __webpack_require__(1);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var LABELS = {
'Search': 'Search Results',
'Recent': 'Frequently Used',
'People': 'Smileys & People',
'Nature': 'Animals & Nature',
'Foods': 'Food & Drink',
'Activity': 'Activity',
'Places': 'Travel & Places',
'Objects': 'Objects',
'Symbols': 'Symbols',
'Flags': 'Flags'
};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var Category = function (_React$Component) {
_inherits(Category, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function Category() {
_classCallCheck(this, Category);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _possibleConstructorReturn(this, Object.getPrototypeOf(Category).apply(this, arguments));
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_createClass(Category, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.container = this.refs.container;
this.label = this.refs.label;
this.parent = this.container.parentNode;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
this.margin = 0;
this.minMargin = 0;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
this.memoizeSize();
}
}, {
2016-07-11 18:22:39 +00:00
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState) {
var _props = this.props;
var name = _props.name;
var perLine = _props.perLine;
var emojis = _props.emojis;
var emojiProps = _props.emojiProps;
var skin = emojiProps.skin;
var size = emojiProps.size;
var sheetURL = emojiProps.sheetURL;
var nextPerLine = nextProps.perLine;
var nextEmojis = nextProps.emojis;
var nextEmojiProps = nextProps.emojiProps;
var nextSkin = nextEmojiProps.skin;
var nextSize = nextEmojiProps.size;
var nextSheetURL = nextEmojiProps.sheetURL;
var shouldUpdate = false;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (name == 'Recent' && perLine != nextPerLine) {
shouldUpdate = true;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (name == 'Search') {
shouldUpdate = !(emojis == nextEmojis);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (skin != nextSkin || size != nextSize || sheetURL != nextSheetURL) {
shouldUpdate = true;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return shouldUpdate;
2016-07-06 14:32:52 +00:00
}
}, {
key: 'memoizeSize',
value: function memoizeSize() {
var _container$getBoundin = this.container.getBoundingClientRect();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var top = _container$getBoundin.top;
var height = _container$getBoundin.height;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _parent$getBoundingCl = this.parent.getBoundingClientRect();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var parentTop = _parent$getBoundingCl.top;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _label$getBoundingCli = this.label.getBoundingClientRect();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var labelHeight = _label$getBoundingCli.height;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
this.top = top - parentTop + this.parent.scrollTop;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (height == 0) {
this.maxMargin = 0;
2016-07-06 14:32:52 +00:00
} else {
2016-07-11 18:22:39 +00:00
this.maxMargin = height - labelHeight;
2016-07-06 14:32:52 +00:00
}
}
}, {
key: 'handleScroll',
value: function handleScroll(scrollTop) {
var margin = scrollTop - this.top;
margin = margin < this.minMargin ? this.minMargin : margin;
margin = margin > this.maxMargin ? this.maxMargin : margin;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if (margin == this.margin) return;
var name = this.props.name;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if (!this.props.hasStickyPosition) {
this.label.style.top = margin + 'px';
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
this.margin = margin;
return true;
}
2016-07-11 18:22:39 +00:00
}, {
key: 'getEmojis',
value: function getEmojis() {
var _props2 = this.props;
var name = _props2.name;
var emojis = _props2.emojis;
var perLine = _props2.perLine;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (name == 'Recent') {
var frequentlyUsed = _utils.frequently.get(perLine * 4);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (frequentlyUsed.length) {
emojis = frequentlyUsed;
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (emojis) {
emojis = emojis.slice(0);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return emojis;
}
}, {
key: 'updateDisplay',
value: function updateDisplay(display) {
var emojis = this.getEmojis();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!display && !emojis) {
return;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.container.style.display = display;
}
2016-07-06 14:32:52 +00:00
}, {
key: 'render',
value: function render() {
2016-07-11 18:22:39 +00:00
var _props3 = this.props;
var name = _props3.name;
var hasStickyPosition = _props3.hasStickyPosition;
var emojiProps = _props3.emojiProps;
var emojis = this.getEmojis();
2016-07-06 14:32:52 +00:00
var labelStyles = {};
var labelSpanStyles = {};
var containerStyles = {};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!emojis) {
containerStyles = {
display: 'none'
};
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if (!hasStickyPosition) {
labelStyles = {
height: 28
};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
labelSpanStyles = {
position: 'absolute'
};
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _react2.default.createElement(
'div',
{ ref: 'container', className: 'emoji-picker-category', style: containerStyles },
_react2.default.createElement(
'div',
{ style: labelStyles, 'data-name': name, className: 'emoji-picker-category-label' },
_react2.default.createElement(
'span',
{ style: labelSpanStyles, ref: 'label' },
2016-07-11 18:22:39 +00:00
LABELS[name]
2016-07-06 14:32:52 +00:00
)
),
emojis && emojis.map(function (emoji) {
return _react2.default.createElement(_.Emoji, _extends({
key: emoji,
emoji: emoji
}, emojiProps));
}),
emojis && !emojis.length && _react2.default.createElement(
'div',
{ className: 'emoji-picker-no-results' },
_react2.default.createElement(_.Emoji, _extends({}, emojiProps, {
size: 22,
emoji: 'sleuth_or_spy'
})),
_react2.default.createElement(
'span',
{ className: 'emoji-picker-no-results-label' },
'No emoji found'
)
)
);
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return Category;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
exports.default = Category;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Category.propTypes = {
emojis: _react2.default.PropTypes.array,
hasStickyPosition: _react2.default.PropTypes.bool,
name: _react2.default.PropTypes.string.isRequired,
2016-07-11 18:22:39 +00:00
perLine: _react2.default.PropTypes.number.isRequired,
2016-07-06 14:32:52 +00:00
emojiProps: _react2.default.PropTypes.object.isRequired
};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Category.defaultProps = {
emojis: [],
hasStickyPosition: true
};
/***/ },
/* 16 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _store = __webpack_require__(17);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, 'store', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_store).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _emojiIndex = __webpack_require__(18);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, 'emojiIndex', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_emojiIndex).default;
}
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _frequently = __webpack_require__(21);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, 'frequently', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_frequently).default;
}
});
2016-07-06 14:32:52 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 18:22:39 +00:00
/***/ },
/* 17 */
/***/ function(module, exports) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
var NAMESPACE = 'emoji-picker';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function update(state) {
for (var key in state) {
var value = state[key];
set(key, value);
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function set(key, value) {
if (!('localStorage' in window)) return;
window.localStorage[NAMESPACE + '.' + key] = JSON.stringify(value);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function get(key) {
if (!('localStorage' in window)) return;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var value = window.localStorage[NAMESPACE + '.' + key];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (value) {
return JSON.parse(value);
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = { update: update, set: set, get: get };
/***/ },
/* 18 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _lunr = __webpack_require__(19);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _lunr2 = _interopRequireDefault(_lunr);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _data = __webpack_require__(20);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _data2 = _interopRequireDefault(_data);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var index = (0, _lunr2.default)(function () {
this.pipeline.reset();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.field('short_name', { boost: 2 });
this.field('emoticons');
this.field('name');
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.ref('id');
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var emoji in _data2.default.emojis) {
var emojiData = _data2.default.emojis[emoji];
var short_name = emojiData.short_name;
var name = emojiData.name;
var emoticons = emojiData.emoticons;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
index.add({
id: short_name,
emoticons: emoticons,
short_name: tokenize(short_name),
name: tokenize(name)
});
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function search(value) {
var maxResults = arguments.length <= 1 || arguments[1] === undefined ? 75 : arguments[1];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var results = null;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (value.length) {
results = index.search(tokenize(value)).map(function (result) {
return result.ref;
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
results = results.slice(0, maxResults);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return results;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function tokenize(string) {
if (['-', '-1', '+', '+1'].indexOf(string) == 0) {
return string.split('');
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (/(:|;|=)-/.test(string)) {
return [string];
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return string.split(/[-|_|\s]+/);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = { search: search };
2016-07-06 14:32:52 +00:00
/***/ },
2016-07-11 18:22:39 +00:00
/* 19 */
/***/ function(module, exports, __webpack_require__) {
2016-07-06 14:32:52 +00:00
2016-07-11 18:22:39 +00:00
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.7.1
* Copyright (C) 2016 Oliver Nightingale
* @license MIT
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
;(function(){
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Convenience function for instantiating a new lunr index and configuring it
* with the default pipeline functions and the passed config function.
*
* When using this convenience function a new index will be created with the
* following functions already in the pipeline:
*
* lunr.StopWordFilter - filters out any stop words before they enter the
* index
*
* lunr.stemmer - stems the tokens before entering the index.
*
* Example:
*
* var idx = lunr(function () {
* this.field('title', 10)
* this.field('tags', 100)
* this.field('body')
*
* this.ref('cid')
*
* this.pipeline.add(function () {
* // some custom pipeline function
* })
*
* })
*
* @param {Function} config A function that will be called with the new instance
* of the lunr.Index as both its context and first parameter. It can be used to
* customize the instance of new lunr.Index.
* @namespace
* @module
* @returns {lunr.Index}
*
*/
var lunr = function (config) {
var idx = new lunr.Index
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
idx.pipeline.add(
lunr.trimmer,
lunr.stopWordFilter,
lunr.stemmer
)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (config) config.call(idx, idx)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return idx
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.version = "0.7.1"
/*!
* lunr.utils
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* A namespace containing utils for the rest of the lunr library
*/
lunr.utils = {}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Print a warning message to the console.
*
* @param {String} message The message to be printed.
* @memberOf Utils
*/
lunr.utils.warn = (function (global) {
return function (message) {
if (global.console && console.warn) {
console.warn(message)
}
}
})(this)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Convert an object to a string.
*
* In the case of `null` and `undefined` the function returns
* the empty string, in all other cases the result of calling
* `toString` on the passed object is returned.
*
* @param {Any} obj The object to convert to a string.
* @return {String} string representation of the passed object.
* @memberOf Utils
*/
lunr.utils.asString = function (obj) {
if (obj === void 0 || obj === null) {
return ""
} else {
return obj.toString()
}
}
/*!
* lunr.EventEmitter
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* lunr.EventEmitter is an event emitter for lunr. It manages adding and removing event handlers and triggering events and their handlers.
*
* @constructor
*/
lunr.EventEmitter = function () {
this.events = {}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Binds a handler function to a specific event(s).
*
* Can bind a single function to many different events in one call.
*
* @param {String} [eventName] The name(s) of events to bind this function to.
* @param {Function} fn The function to call when an event is fired.
* @memberOf EventEmitter
*/
lunr.EventEmitter.prototype.addListener = function () {
var args = Array.prototype.slice.call(arguments),
fn = args.pop(),
names = args
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (typeof fn !== "function") throw new TypeError ("last argument must be a function")
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
names.forEach(function (name) {
if (!this.hasHandler(name)) this.events[name] = []
this.events[name].push(fn)
}, this)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Removes a handler function from a specific event.
*
* @param {String} eventName The name of the event to remove this function from.
* @param {Function} fn The function to remove from an event.
* @memberOf EventEmitter
*/
lunr.EventEmitter.prototype.removeListener = function (name, fn) {
if (!this.hasHandler(name)) return
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var fnIndex = this.events[name].indexOf(fn)
this.events[name].splice(fnIndex, 1)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!this.events[name].length) delete this.events[name]
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Calls all functions bound to the given event.
*
* Additional data can be passed to the event handler as arguments to `emit`
* after the event name.
*
* @param {String} eventName The name of the event to emit.
* @memberOf EventEmitter
*/
lunr.EventEmitter.prototype.emit = function (name) {
if (!this.hasHandler(name)) return
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var args = Array.prototype.slice.call(arguments, 1)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.events[name].forEach(function (fn) {
fn.apply(undefined, args)
})
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Checks whether a handler has ever been stored against an event.
*
* @param {String} eventName The name of the event to check.
* @private
* @memberOf EventEmitter
*/
lunr.EventEmitter.prototype.hasHandler = function (name) {
return name in this.events
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/*!
* lunr.tokenizer
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* A function for splitting a string into tokens ready to be inserted into
* the search index. Uses `lunr.tokenizer.seperator` to split strings, change
* the value of this property to change how strings are split into tokens.
*
* @module
* @param {String} obj The string to convert into tokens
* @see lunr.tokenizer.seperator
* @returns {Array}
*/
lunr.tokenizer = function (obj) {
if (!arguments.length || obj == null || obj == undefined) return []
if (Array.isArray(obj)) return obj.map(function (t) { return lunr.utils.asString(t).toLowerCase() })
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return obj.toString().trim().toLowerCase().split(lunr.tokenizer.seperator)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* The sperator used to split a string into tokens. Override this property to change the behaviour of
* `lunr.tokenizer` behaviour when tokenizing strings. By default this splits on whitespace and hyphens.
*
* @static
* @see lunr.tokenizer
*/
lunr.tokenizer.seperator = /[\s\-]+/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Loads a previously serialised tokenizer.
*
* A tokenizer function to be loaded must already be registered with lunr.tokenizer.
* If the serialised tokenizer has not been registered then an error will be thrown.
*
* @param {String} label The label of the serialised tokenizer.
* @returns {Function}
* @memberOf tokenizer
*/
lunr.tokenizer.load = function (label) {
var fn = this.registeredFunctions[label]
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!fn) {
throw new Error('Cannot load un-registered function: ' + label)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return fn
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.tokenizer.label = 'default'
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.tokenizer.registeredFunctions = {
'default': lunr.tokenizer
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Register a tokenizer function.
*
* Functions that are used as tokenizers should be registered if they are to be used with a serialised index.
*
* Registering a function does not add it to an index, functions must still be associated with a specific index for them to be used when indexing and searching documents.
*
* @param {Function} fn The function to register.
* @param {String} label The label to register this function with
* @memberOf tokenizer
*/
lunr.tokenizer.registerFunction = function (fn, label) {
if (label in this.registeredFunctions) {
lunr.utils.warn('Overwriting existing tokenizer: ' + label)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
fn.label = label
this.registeredFunctions[label] = fn
}
/*!
* lunr.Pipeline
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* lunr.Pipelines maintain an ordered list of functions to be applied to all
* tokens in documents entering the search index and queries being ran against
* the index.
*
* An instance of lunr.Index created with the lunr shortcut will contain a
* pipeline with a stop word filter and an English language stemmer. Extra
* functions can be added before or after either of these functions or these
* default functions can be removed.
*
* When run the pipeline will call each function in turn, passing a token, the
* index of that token in the original list of all tokens and finally a list of
* all the original tokens.
*
* The output of functions in the pipeline will be passed to the next function
* in the pipeline. To exclude a token from entering the index the function
* should return undefined, the rest of the pipeline will not be called with
* this token.
*
* For serialisation of pipelines to work, all functions used in an instance of
* a pipeline should be registered with lunr.Pipeline. Registered functions can
* then be loaded. If trying to load a serialised pipeline that uses functions
* that are not registered an error will be thrown.
*
* If not planning on serialising the pipeline then registering pipeline functions
* is not necessary.
*
* @constructor
*/
lunr.Pipeline = function () {
this._stack = []
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.Pipeline.registeredFunctions = {}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Register a function with the pipeline.
*
* Functions that are used in the pipeline should be registered if the pipeline
* needs to be serialised, or a serialised pipeline needs to be loaded.
*
* Registering a function does not add it to a pipeline, functions must still be
* added to instances of the pipeline for them to be used when running a pipeline.
*
* @param {Function} fn The function to check for.
* @param {String} label The label to register this function with
* @memberOf Pipeline
*/
lunr.Pipeline.registerFunction = function (fn, label) {
if (label in this.registeredFunctions) {
lunr.utils.warn('Overwriting existing registered function: ' + label)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
fn.label = label
lunr.Pipeline.registeredFunctions[fn.label] = fn
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Warns if the function is not registered as a Pipeline function.
*
* @param {Function} fn The function to check for.
* @private
* @memberOf Pipeline
*/
lunr.Pipeline.warnIfFunctionNotRegistered = function (fn) {
var isRegistered = fn.label && (fn.label in this.registeredFunctions)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!isRegistered) {
lunr.utils.warn('Function is not registered with pipeline. This may cause problems when serialising the index.\n', fn)
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Loads a previously serialised pipeline.
*
* All functions to be loaded must already be registered with lunr.Pipeline.
* If any function from the serialised data has not been registered then an
* error will be thrown.
*
* @param {Object} serialised The serialised pipeline to load.
* @returns {lunr.Pipeline}
* @memberOf Pipeline
*/
lunr.Pipeline.load = function (serialised) {
var pipeline = new lunr.Pipeline
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
serialised.forEach(function (fnName) {
var fn = lunr.Pipeline.registeredFunctions[fnName]
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (fn) {
pipeline.add(fn)
} else {
throw new Error('Cannot load un-registered function: ' + fnName)
}
})
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return pipeline
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Adds new functions to the end of the pipeline.
*
* Logs a warning if the function has not been registered.
*
* @param {Function} functions Any number of functions to add to the pipeline.
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.add = function () {
var fns = Array.prototype.slice.call(arguments)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
fns.forEach(function (fn) {
lunr.Pipeline.warnIfFunctionNotRegistered(fn)
this._stack.push(fn)
}, this)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Adds a single function after a function that already exists in the
* pipeline.
*
* Logs a warning if the function has not been registered.
*
* @param {Function} existingFn A function that already exists in the pipeline.
* @param {Function} newFn The new function to add to the pipeline.
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.after = function (existingFn, newFn) {
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var pos = this._stack.indexOf(existingFn)
if (pos == -1) {
throw new Error('Cannot find existingFn')
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
pos = pos + 1
this._stack.splice(pos, 0, newFn)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Adds a single function before a function that already exists in the
* pipeline.
*
* Logs a warning if the function has not been registered.
*
* @param {Function} existingFn A function that already exists in the pipeline.
* @param {Function} newFn The new function to add to the pipeline.
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.before = function (existingFn, newFn) {
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var pos = this._stack.indexOf(existingFn)
if (pos == -1) {
throw new Error('Cannot find existingFn')
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this._stack.splice(pos, 0, newFn)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Removes a function from the pipeline.
*
* @param {Function} fn The function to remove from the pipeline.
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.remove = function (fn) {
var pos = this._stack.indexOf(fn)
if (pos == -1) {
return
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this._stack.splice(pos, 1)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Runs the current list of functions that make up the pipeline against the
* passed tokens.
*
* @param {Array} tokens The tokens to run through the pipeline.
* @returns {Array}
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.run = function (tokens) {
var out = [],
tokenLength = tokens.length,
stackLength = this._stack.length
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < tokenLength; i++) {
var token = tokens[i]
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var j = 0; j < stackLength; j++) {
token = this._stack[j](token, i, tokens)
if (token === void 0 || token === '') break
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (token !== void 0 && token !== '') out.push(token)
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return out
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Resets the pipeline by removing any existing processors.
*
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.reset = function () {
this._stack = []
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Returns a representation of the pipeline ready for serialisation.
*
* Logs a warning if the function has not been registered.
*
* @returns {Array}
* @memberOf Pipeline
*/
lunr.Pipeline.prototype.toJSON = function () {
return this._stack.map(function (fn) {
lunr.Pipeline.warnIfFunctionNotRegistered(fn)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return fn.label
})
}
/*!
* lunr.Vector
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* lunr.Vectors implement vector related operations for
* a series of elements.
*
* @constructor
*/
lunr.Vector = function () {
this._magnitude = null
this.list = undefined
this.length = 0
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* lunr.Vector.Node is a simple struct for each node
* in a lunr.Vector.
*
* @private
* @param {Number} The index of the node in the vector.
* @param {Object} The data at this node in the vector.
* @param {lunr.Vector.Node} The node directly after this node in the vector.
* @constructor
* @memberOf Vector
*/
lunr.Vector.Node = function (idx, val, next) {
this.idx = idx
this.val = val
this.next = next
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Inserts a new value at a position in a vector.
*
* @param {Number} The index at which to insert a value.
* @param {Object} The object to insert in the vector.
* @memberOf Vector.
*/
lunr.Vector.prototype.insert = function (idx, val) {
this._magnitude = undefined;
var list = this.list
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!list) {
this.list = new lunr.Vector.Node (idx, val, list)
return this.length++
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (idx < list.idx) {
this.list = new lunr.Vector.Node (idx, val, list)
return this.length++
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var prev = list,
next = list.next
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
while (next != undefined) {
if (idx < next.idx) {
prev.next = new lunr.Vector.Node (idx, val, next)
return this.length++
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
prev = next, next = next.next
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
prev.next = new lunr.Vector.Node (idx, val, next)
return this.length++
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Calculates the magnitude of this vector.
*
* @returns {Number}
* @memberOf Vector
*/
lunr.Vector.prototype.magnitude = function () {
if (this._magnitude) return this._magnitude
var node = this.list,
sumOfSquares = 0,
val
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
while (node) {
val = node.val
sumOfSquares += val * val
node = node.next
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return this._magnitude = Math.sqrt(sumOfSquares)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Calculates the dot product of this vector and another vector.
*
* @param {lunr.Vector} otherVector The vector to compute the dot product with.
* @returns {Number}
* @memberOf Vector
*/
lunr.Vector.prototype.dot = function (otherVector) {
var node = this.list,
otherNode = otherVector.list,
dotProduct = 0
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
while (node && otherNode) {
if (node.idx < otherNode.idx) {
node = node.next
} else if (node.idx > otherNode.idx) {
otherNode = otherNode.next
} else {
dotProduct += node.val * otherNode.val
node = node.next
otherNode = otherNode.next
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return dotProduct
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Calculates the cosine similarity between this vector and another
* vector.
*
* @param {lunr.Vector} otherVector The other vector to calculate the
* similarity with.
* @returns {Number}
* @memberOf Vector
*/
lunr.Vector.prototype.similarity = function (otherVector) {
return this.dot(otherVector) / (this.magnitude() * otherVector.magnitude())
}
/*!
* lunr.SortedSet
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* lunr.SortedSets are used to maintain an array of uniq values in a sorted
* order.
*
* @constructor
*/
lunr.SortedSet = function () {
this.length = 0
this.elements = []
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Loads a previously serialised sorted set.
*
* @param {Array} serialisedData The serialised set to load.
* @returns {lunr.SortedSet}
* @memberOf SortedSet
*/
lunr.SortedSet.load = function (serialisedData) {
var set = new this
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
set.elements = serialisedData
set.length = serialisedData.length
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return set
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Inserts new items into the set in the correct position to maintain the
* order.
*
* @param {Object} The objects to add to this set.
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.add = function () {
var i, element
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (i = 0; i < arguments.length; i++) {
element = arguments[i]
if (~this.indexOf(element)) continue
this.elements.splice(this.locationFor(element), 0, element)
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.length = this.elements.length
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Converts this sorted set into an array.
*
* @returns {Array}
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.toArray = function () {
return this.elements.slice()
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Creates a new array with the results of calling a provided function on every
* element in this sorted set.
*
* Delegates to Array.prototype.map and has the same signature.
*
* @param {Function} fn The function that is called on each element of the
* set.
* @param {Object} ctx An optional object that can be used as the context
* for the function fn.
* @returns {Array}
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.map = function (fn, ctx) {
return this.elements.map(fn, ctx)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Executes a provided function once per sorted set element.
*
* Delegates to Array.prototype.forEach and has the same signature.
*
* @param {Function} fn The function that is called on each element of the
* set.
* @param {Object} ctx An optional object that can be used as the context
* @memberOf SortedSet
* for the function fn.
*/
lunr.SortedSet.prototype.forEach = function (fn, ctx) {
return this.elements.forEach(fn, ctx)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Returns the index at which a given element can be found in the
* sorted set, or -1 if it is not present.
*
* @param {Object} elem The object to locate in the sorted set.
* @returns {Number}
* @memberOf SortedSet
*/
lunr.SortedSet.prototype.indexOf = function (elem) {
var start = 0,
end = this.elements.length,
sectionLength = end - start,
pivot = start + Math.floor(sectionLength / 2),
pivotElem = this.elements[pivot]
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
while (sectionLength > 1) {
if (pivotElem === elem) return pivot
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (pivotElem < elem) start = pivot
if (pivotElem > elem) end = pivot
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
sectionLength = end - start
pivot = start + Math.floor(sectionLength / 2)
pivotElem = this.elements[pivot]
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (pivotElem === elem) return pivot
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return -1
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Returns the position within the sorted set that an element should be
* inserted at to maintain the current order of the set.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* This function assumes that the element to search for does not already exist
* in the sorted set.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} elem The elem to find the position for in the set
* @returns {Number}
* @memberOf SortedSet
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.SortedSet.prototype.locationFor = function (elem) {
var start = 0,
end = this.elements.length,
sectionLength = end - start,
pivot = start + Math.floor(sectionLength / 2),
pivotElem = this.elements[pivot]
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
while (sectionLength > 1) {
if (pivotElem < elem) start = pivot
if (pivotElem > elem) end = pivot
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
sectionLength = end - start
pivot = start + Math.floor(sectionLength / 2)
pivotElem = this.elements[pivot]
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (pivotElem > elem) return pivot
if (pivotElem < elem) return pivot + 1
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* Creates a new lunr.SortedSet that contains the elements in the intersection
* of this set and the passed set.
*
* @param {lunr.SortedSet} otherSet The set to intersect with this set.
* @returns {lunr.SortedSet}
* @memberOf SortedSet
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.SortedSet.prototype.intersect = function (otherSet) {
var intersectSet = new lunr.SortedSet,
i = 0, j = 0,
a_len = this.length, b_len = otherSet.length,
a = this.elements, b = otherSet.elements
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
while (true) {
if (i > a_len - 1 || j > b_len - 1) break
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (a[i] === b[j]) {
intersectSet.add(a[i])
i++, j++
continue
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (a[i] < b[j]) {
i++
continue
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (a[i] > b[j]) {
j++
continue
}
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return intersectSet
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Makes a copy of this set
*
* @returns {lunr.SortedSet}
* @memberOf SortedSet
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.SortedSet.prototype.clone = function () {
var clone = new lunr.SortedSet
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
clone.elements = this.toArray()
clone.length = clone.elements.length
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return clone
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Creates a new lunr.SortedSet that contains the elements in the union
* of this set and the passed set.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {lunr.SortedSet} otherSet The set to union with this set.
* @returns {lunr.SortedSet}
* @memberOf SortedSet
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.SortedSet.prototype.union = function (otherSet) {
var longSet, shortSet, unionSet
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (this.length >= otherSet.length) {
longSet = this, shortSet = otherSet
} else {
longSet = otherSet, shortSet = this
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
unionSet = longSet.clone()
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for(var i = 0, shortSetElements = shortSet.toArray(); i < shortSetElements.length; i++){
unionSet.add(shortSetElements[i])
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return unionSet
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Returns a representation of the sorted set ready for serialisation.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @returns {Array}
* @memberOf SortedSet
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.SortedSet.prototype.toJSON = function () {
return this.toArray()
2016-07-06 14:32:52 +00:00
}
/*!
2016-07-11 18:22:39 +00:00
* lunr.Index
2016-07-06 14:32:52 +00:00
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* lunr.Index is object that manages a search index. It contains the indexes
* and stores all the tokens and document lookups. It also provides the main
* user facing API for the library.
2016-07-06 14:32:52 +00:00
*
* @constructor
*/
2016-07-11 18:22:39 +00:00
lunr.Index = function () {
this._fields = []
this._ref = 'id'
this.pipeline = new lunr.Pipeline
this.documentStore = new lunr.Store
this.tokenStore = new lunr.TokenStore
this.corpusTokens = new lunr.SortedSet
this.eventEmitter = new lunr.EventEmitter
this.tokenizerFn = lunr.tokenizer
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this._idfCache = {}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.on('add', 'remove', 'update', (function () {
this._idfCache = {}
}).bind(this))
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Bind a handler to events being emitted by the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* The handler can be bound to many events at the same time.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} [eventName] The name(s) of events to bind the function to.
* @param {Function} fn The serialised set to load.
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.on = function () {
var args = Array.prototype.slice.call(arguments)
return this.eventEmitter.addListener.apply(this.eventEmitter, args)
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Removes a handler from an event being emitted by the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} eventName The name of events to remove the function from.
* @param {Function} fn The serialised set to load.
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.off = function (name, fn) {
return this.eventEmitter.removeListener(name, fn)
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Loads a previously serialised index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* Issues a warning if the index being imported was serialised
* by a different version of lunr.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} serialisedData The serialised set to load.
* @returns {lunr.Index}
* @memberOf Index
*/
lunr.Index.load = function (serialisedData) {
if (serialisedData.version !== lunr.version) {
lunr.utils.warn('version mismatch: current ' + lunr.version + ' importing ' + serialisedData.version)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var idx = new this
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
idx._fields = serialisedData.fields
idx._ref = serialisedData.ref
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
idx.tokenizer = lunr.tokenizer.load(serialisedData.tokenizer)
idx.documentStore = lunr.Store.load(serialisedData.documentStore)
idx.tokenStore = lunr.TokenStore.load(serialisedData.tokenStore)
idx.corpusTokens = lunr.SortedSet.load(serialisedData.corpusTokens)
idx.pipeline = lunr.Pipeline.load(serialisedData.pipeline)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return idx
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Adds a field to the list of fields that will be searchable within documents
* in the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* An optional boost param can be passed to affect how much tokens in this field
* rank in search results, by default the boost value is 1.
*
* Fields should be added before any documents are added to the index, fields
* that are added after documents are added to the index will only apply to new
* documents added to the index.
*
* @param {String} fieldName The name of the field within the document that
* should be indexed
* @param {Number} boost An optional boost that can be applied to terms in this
* field.
* @returns {lunr.Index}
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.field = function (fieldName, opts) {
var opts = opts || {},
field = { name: fieldName, boost: opts.boost || 1 }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this._fields.push(field)
return this
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Sets the property used to uniquely identify documents added to the index,
* by default this property is 'id'.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* This should only be changed before adding documents to the index, changing
* the ref property without resetting the index can lead to unexpected results.
*
* The value of ref can be of any type but it _must_ be stably comparable and
* orderable.
*
* @param {String} refName The property to use to uniquely identify the
* documents in the index.
* @param {Boolean} emitEvent Whether to emit add events, defaults to true
* @returns {lunr.Index}
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.ref = function (refName) {
this._ref = refName
return this
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Sets the tokenizer used for this index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* By default the index will use the default tokenizer, lunr.tokenizer. The tokenizer
* should only be changed before adding documents to the index. Changing the tokenizer
* without re-building the index can lead to unexpected results.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Function} fn The function to use as a tokenizer.
* @returns {lunr.Index}
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.tokenizer = function (fn) {
var isRegistered = fn.label && (fn.label in lunr.tokenizer.registeredFunctions)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!isRegistered) {
lunr.utils.warn('Function is not a registered tokenizer. This may cause problems when serialising the index')
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.tokenizerFn = fn
return this
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Add a document to the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* This is the way new documents enter the index, this function will run the
* fields from the document through the index's pipeline and then add it to
* the index, it will then show up in search results.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* An 'add' event is emitted with the document that has been added and the index
* the document has been added to. This event can be silenced by passing false
* as the second argument to add.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} doc The document to add to the index.
* @param {Boolean} emitEvent Whether or not to emit events, default true.
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.add = function (doc, emitEvent) {
var docTokens = {},
allDocumentTokens = new lunr.SortedSet,
docRef = doc[this._ref],
emitEvent = emitEvent === undefined ? true : emitEvent
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this._fields.forEach(function (field) {
var fieldTokens = this.pipeline.run(this.tokenizerFn(doc[field.name]))
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
docTokens[field.name] = fieldTokens
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < fieldTokens.length; i++) {
var token = fieldTokens[i]
allDocumentTokens.add(token)
this.corpusTokens.add(token)
}
}, this)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.documentStore.set(docRef, allDocumentTokens)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < allDocumentTokens.length; i++) {
var token = allDocumentTokens.elements[i]
var tf = 0;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var j = 0; j < this._fields.length; j++){
var field = this._fields[j]
var fieldTokens = docTokens[field.name]
var fieldLength = fieldTokens.length
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!fieldLength) continue
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var tokenCount = 0
for (var k = 0; k < fieldLength; k++){
if (fieldTokens[k] === token){
tokenCount++
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
tf += (tokenCount / fieldLength * field.boost)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.tokenStore.add(token, { ref: docRef, tf: tf })
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (emitEvent) this.eventEmitter.emit('add', doc, this)
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Removes a document from the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* To make sure documents no longer show up in search results they can be
* removed from the index using this method.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* The document passed only needs to have the same ref property value as the
* document that was added to the index, they could be completely different
* objects.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* A 'remove' event is emitted with the document that has been removed and the index
* the document has been removed from. This event can be silenced by passing false
* as the second argument to remove.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} doc The document to remove from the index.
* @param {Boolean} emitEvent Whether to emit remove events, defaults to true
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.remove = function (doc, emitEvent) {
var docRef = doc[this._ref],
emitEvent = emitEvent === undefined ? true : emitEvent
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!this.documentStore.has(docRef)) return
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var docTokens = this.documentStore.get(docRef)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.documentStore.remove(docRef)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
docTokens.forEach(function (token) {
this.tokenStore.remove(token, docRef)
}, this)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (emitEvent) this.eventEmitter.emit('remove', doc, this)
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Updates a document in the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* When a document contained within the index gets updated, fields changed,
* added or removed, to make sure it correctly matched against search queries,
* it should be updated in the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* This method is just a wrapper around `remove` and `add`
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* An 'update' event is emitted with the document that has been updated and the index.
* This event can be silenced by passing false as the second argument to update. Only
* an update event will be fired, the 'add' and 'remove' events of the underlying calls
* are silenced.
*
* @param {Object} doc The document to update in the index.
* @param {Boolean} emitEvent Whether to emit update events, defaults to true
* @see Index.prototype.remove
* @see Index.prototype.add
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.update = function (doc, emitEvent) {
var emitEvent = emitEvent === undefined ? true : emitEvent
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.remove(doc, false)
this.add(doc, false)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (emitEvent) this.eventEmitter.emit('update', doc, this)
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Calculates the inverse document frequency for a token within the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} token The token to calculate the idf of.
* @see Index.prototype.idf
2016-07-06 14:32:52 +00:00
* @private
2016-07-11 18:22:39 +00:00
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.idf = function (term) {
var cacheKey = "@" + term
if (Object.prototype.hasOwnProperty.call(this._idfCache, cacheKey)) return this._idfCache[cacheKey]
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var documentFrequency = this.tokenStore.count(term),
idf = 1
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (documentFrequency > 0) {
idf = 1 + Math.log(this.documentStore.length / documentFrequency)
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return this._idfCache[cacheKey] = idf
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Searches the index using the passed query.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* Queries should be a string, multiple words are allowed and will lead to an
* AND based query, e.g. `idx.search('foo bar')` will run a search for
* documents containing both 'foo' and 'bar'.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* All query tokens are passed through the same pipeline that document tokens
* are passed through, so any language processing involved will be run on every
* query term.
*
* Each query term is expanded, so that the term 'he' might be expanded to
* 'hello' and 'help' if those terms were already included in the index.
*
* Matching documents are returned as an array of objects, each object contains
* the matching document ref, as set for this index, and the similarity score
* for this document against the query.
*
* @param {String} query The query to search the index with.
* @returns {Object}
* @see Index.prototype.idf
* @see Index.prototype.documentVector
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.search = function (query) {
var queryTokens = this.pipeline.run(this.tokenizerFn(query)),
queryVector = new lunr.Vector,
documentSets = [],
fieldBoosts = this._fields.reduce(function (memo, f) { return memo + f.boost }, 0)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var hasSomeToken = queryTokens.some(function (token) {
return this.tokenStore.has(token)
}, this)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!hasSomeToken) return []
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
queryTokens
.forEach(function (token, i, tokens) {
var tf = 1 / tokens.length * this._fields.length * fieldBoosts,
self = this
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var set = this.tokenStore.expand(token).reduce(function (memo, key) {
var pos = self.corpusTokens.indexOf(key),
idf = self.idf(key),
similarityBoost = 1,
set = new lunr.SortedSet
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// if the expanded key is not an exact match to the token then
// penalise the score for this key by how different the key is
// to the token.
if (key !== token) {
var diff = Math.max(3, key.length - token.length)
similarityBoost = 1 / Math.log(diff)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// calculate the query tf-idf score for this token
// applying an similarityBoost to ensure exact matches
// these rank higher than expanded terms
if (pos > -1) queryVector.insert(pos, tf * idf * similarityBoost)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// add all the documents that have this key into a set
// ensuring that the type of key is preserved
var matchingDocuments = self.tokenStore.get(key),
refs = Object.keys(matchingDocuments),
refsLen = refs.length
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < refsLen; i++) {
set.add(matchingDocuments[refs[i]].ref)
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return memo.union(set)
}, new lunr.SortedSet)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
documentSets.push(set)
}, this)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var documentSet = documentSets.reduce(function (memo, set) {
return memo.intersect(set)
2016-07-06 14:32:52 +00:00
})
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return documentSet
.map(function (ref) {
return { ref: ref, score: queryVector.similarity(this.documentVector(ref)) }
}, this)
.sort(function (a, b) {
return b.score - a.score
})
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Generates a vector containing all the tokens in the document matching the
* passed documentRef.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* The vector contains the tf-idf score for each token contained in the
* document with the passed documentRef. The vector will contain an element
* for every token in the indexes corpus, if the document does not contain that
* token the element will be 0.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} documentRef The ref to find the document with.
* @returns {lunr.Vector}
* @private
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.documentVector = function (documentRef) {
var documentTokens = this.documentStore.get(documentRef),
documentTokensLength = documentTokens.length,
documentVector = new lunr.Vector
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < documentTokensLength; i++) {
var token = documentTokens.elements[i],
tf = this.tokenStore.get(token)[documentRef].tf,
idf = this.idf(token)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
documentVector.insert(this.corpusTokens.indexOf(token), tf * idf)
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return documentVector
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Returns a representation of the index ready for serialisation.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @returns {Object}
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.toJSON = function () {
return {
version: lunr.version,
fields: this._fields,
ref: this._ref,
tokenizer: this.tokenizerFn.label,
documentStore: this.documentStore.toJSON(),
tokenStore: this.tokenStore.toJSON(),
corpusTokens: this.corpusTokens.toJSON(),
pipeline: this.pipeline.toJSON()
2016-07-06 14:32:52 +00:00
}
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Applies a plugin to the current index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* A plugin is a function that is called with the index as its context.
* Plugins can be used to customise or extend the behaviour the index
* in some way. A plugin is just a function, that encapsulated the custom
* behaviour that should be applied to the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* The plugin function will be called with the index as its argument, additional
* arguments can also be passed when calling use. The function will be called
* with the index as its context.
*
* Example:
*
* var myPlugin = function (idx, arg1, arg2) {
* // `this` is the index to be extended
* // apply any extensions etc here.
* }
*
* var idx = lunr(function () {
* this.use(myPlugin, 'arg1', 'arg2')
* })
*
* @param {Function} plugin The plugin to apply.
* @memberOf Index
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Index.prototype.use = function (plugin) {
var args = Array.prototype.slice.call(arguments, 1)
args.unshift(this)
plugin.apply(this, args)
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
/*!
* lunr.Store
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* lunr.Store is a simple key-value store used for storing sets of tokens for
* documents stored in index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @constructor
* @module
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store = function () {
this.store = {}
this.length = 0
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Loads a previously serialised store
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} serialisedData The serialised store to load.
* @returns {lunr.Store}
* @memberOf Store
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store.load = function (serialisedData) {
var store = new this
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
store.length = serialisedData.length
store.store = Object.keys(serialisedData.store).reduce(function (memo, key) {
memo[key] = lunr.SortedSet.load(serialisedData.store[key])
return memo
}, {})
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return store
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Stores the given tokens in the store against the given id.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} id The key used to store the tokens against.
* @param {Object} tokens The tokens to store against the key.
* @memberOf Store
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store.prototype.set = function (id, tokens) {
if (!this.has(id)) this.length++
this.store[id] = tokens
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Retrieves the tokens from the store for a given key.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} id The key to lookup and retrieve from the store.
* @returns {Object}
* @memberOf Store
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store.prototype.get = function (id) {
return this.store[id]
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Checks whether the store contains a key.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} id The id to look up in the store.
* @returns {Boolean}
* @memberOf Store
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store.prototype.has = function (id) {
return id in this.store
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Removes the value for a key in the store.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} id The id to remove from the store.
* @memberOf Store
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store.prototype.remove = function (id) {
if (!this.has(id)) return
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
delete this.store[id]
this.length--
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Returns a representation of the store ready for serialisation.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @returns {Object}
* @memberOf Store
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.Store.prototype.toJSON = function () {
return {
store: this.store,
length: this.length
2016-07-06 14:32:52 +00:00
}
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/*!
2016-07-11 18:22:39 +00:00
* lunr.stemmer
2016-07-06 14:32:52 +00:00
* Copyright (C) 2016 Oliver Nightingale
2016-07-11 18:22:39 +00:00
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
2016-07-06 14:32:52 +00:00
*/
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* lunr.stemmer is an english language stemmer, this is a JavaScript
* implementation of the PorterStemmer taken from http://tartarus.org/~martin
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @module
* @param {String} str The string to stem
* @returns {String}
* @see lunr.Pipeline
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.stemmer = (function(){
var step2list = {
"ational" : "ate",
"tional" : "tion",
"enci" : "ence",
"anci" : "ance",
"izer" : "ize",
"bli" : "ble",
"alli" : "al",
"entli" : "ent",
"eli" : "e",
"ousli" : "ous",
"ization" : "ize",
"ation" : "ate",
"ator" : "ate",
"alism" : "al",
"iveness" : "ive",
"fulness" : "ful",
"ousness" : "ous",
"aliti" : "al",
"iviti" : "ive",
"biliti" : "ble",
"logi" : "log"
},
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
step3list = {
"icate" : "ic",
"ative" : "",
"alize" : "al",
"iciti" : "ic",
"ical" : "ic",
"ful" : "",
"ness" : ""
},
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
c = "[^aeiou]", // consonant
v = "[aeiouy]", // vowel
C = c + "[^aeiouy]*", // consonant sequence
V = v + "[aeiou]*", // vowel sequence
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
mgr0 = "^(" + C + ")?" + V + C, // [C]VC... is m>0
meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$", // [C]VC[V] is m=1
mgr1 = "^(" + C + ")?" + V + C + V + C, // [C]VCVC... is m>1
s_v = "^(" + C + ")?" + v; // vowel in stem
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var re_mgr0 = new RegExp(mgr0);
var re_mgr1 = new RegExp(mgr1);
var re_meq1 = new RegExp(meq1);
var re_s_v = new RegExp(s_v);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var re_1a = /^(.+?)(ss|i)es$/;
var re2_1a = /^(.+?)([^s])s$/;
var re_1b = /^(.+?)eed$/;
var re2_1b = /^(.+?)(ed|ing)$/;
var re_1b_2 = /.$/;
var re2_1b_2 = /(at|bl|iz)$/;
var re3_1b_2 = new RegExp("([^aeiouylsz])\\1$");
var re4_1b_2 = new RegExp("^" + C + v + "[^aeiouwxy]$");
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var re_1c = /^(.+?[^aeiou])y$/;
var re_2 = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var re_3 = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var re_4 = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
var re2_4 = /^(.+?)(s|t)(ion)$/;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var re_5 = /^(.+?)e$/;
var re_5_1 = /ll$/;
var re3_5 = new RegExp("^" + C + v + "[^aeiouwxy]$");
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var porterStemmer = function porterStemmer(w) {
var stem,
suffix,
firstch,
re,
re2,
re3,
re4;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (w.length < 3) { return w; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
firstch = w.substr(0,1);
if (firstch == "y") {
w = firstch.toUpperCase() + w.substr(1);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 1a
re = re_1a
re2 = re2_1a;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (re.test(w)) { w = w.replace(re,"$1$2"); }
else if (re2.test(w)) { w = w.replace(re2,"$1$2"); }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 1b
re = re_1b;
re2 = re2_1b;
if (re.test(w)) {
var fp = re.exec(w);
re = re_mgr0;
if (re.test(fp[1])) {
re = re_1b_2;
w = w.replace(re,"");
}
} else if (re2.test(w)) {
var fp = re2.exec(w);
stem = fp[1];
re2 = re_s_v;
if (re2.test(stem)) {
w = stem;
re2 = re2_1b_2;
re3 = re3_1b_2;
re4 = re4_1b_2;
if (re2.test(w)) { w = w + "e"; }
else if (re3.test(w)) { re = re_1b_2; w = w.replace(re,""); }
else if (re4.test(w)) { w = w + "e"; }
}
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 1c - replace suffix y or Y by i if preceded by a non-vowel which is not the first letter of the word (so cry -> cri, by -> by, say -> say)
re = re_1c;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
w = stem + "i";
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 2
re = re_2;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
suffix = fp[2];
re = re_mgr0;
if (re.test(stem)) {
w = stem + step2list[suffix];
}
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 3
re = re_3;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
suffix = fp[2];
re = re_mgr0;
if (re.test(stem)) {
w = stem + step3list[suffix];
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 4
re = re_4;
re2 = re2_4;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
re = re_mgr1;
if (re.test(stem)) {
w = stem;
}
} else if (re2.test(w)) {
var fp = re2.exec(w);
stem = fp[1] + fp[2];
re2 = re_mgr1;
if (re2.test(stem)) {
w = stem;
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// Step 5
re = re_5;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
re = re_mgr1;
re2 = re_meq1;
re3 = re3_5;
if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) {
w = stem;
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
re = re_5_1;
re2 = re_mgr1;
if (re.test(w) && re2.test(w)) {
re = re_1b_2;
w = w.replace(re,"");
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// and turn initial Y back to y
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (firstch == "y") {
w = firstch.toLowerCase() + w.substr(1);
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return w;
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return porterStemmer;
})();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
2016-07-06 14:32:52 +00:00
/*!
2016-07-11 18:22:39 +00:00
* lunr.stopWordFilter
2016-07-06 14:32:52 +00:00
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* lunr.generateStopWordFilter builds a stopWordFilter function from the provided
* list of stop words.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* The built in lunr.stopWordFilter is built using this generator and can be used
* to generate custom stopWordFilters for applications or non English languages.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @module
* @param {Array} token The token to pass through the filter
* @returns {Function}
* @see lunr.Pipeline
* @see lunr.stopWordFilter
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.generateStopWordFilter = function (stopWords) {
var words = stopWords.reduce(function (memo, stopWord) {
memo[stopWord] = stopWord
return memo
}, {})
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return function (token) {
if (token && words[token] !== token) return token
2016-07-06 14:32:52 +00:00
}
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* lunr.stopWordFilter is an English language stop word list filter, any words
* contained in the list will not be passed through the filter.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* This is intended to be used in the Pipeline. If the token does not pass the
* filter then undefined will be returned.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @module
* @param {String} token The token to pass through the filter
* @returns {String}
* @see lunr.Pipeline
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.stopWordFilter = lunr.generateStopWordFilter([
'a',
'able',
'about',
'across',
'after',
'all',
'almost',
'also',
'am',
'among',
'an',
'and',
'any',
'are',
'as',
'at',
'be',
'because',
'been',
'but',
'by',
'can',
'cannot',
'could',
'dear',
'did',
'do',
'does',
'either',
'else',
'ever',
'every',
'for',
'from',
'get',
'got',
'had',
'has',
'have',
'he',
'her',
'hers',
'him',
'his',
'how',
'however',
'i',
'if',
'in',
'into',
'is',
'it',
'its',
'just',
'least',
'let',
'like',
'likely',
'may',
'me',
'might',
'most',
'must',
'my',
'neither',
'no',
'nor',
'not',
'of',
'off',
'often',
'on',
'only',
'or',
'other',
'our',
'own',
'rather',
'said',
'say',
'says',
'she',
'should',
'since',
'so',
'some',
'than',
'that',
'the',
'their',
'them',
'then',
'there',
'these',
'they',
'this',
'tis',
'to',
'too',
'twas',
'us',
'wants',
'was',
'we',
'were',
'what',
'when',
'where',
'which',
'while',
'who',
'whom',
'why',
'will',
'with',
'would',
'yet',
'you',
'your'
])
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
/*!
* lunr.trimmer
* Copyright (C) 2016 Oliver Nightingale
*/
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* lunr.trimmer is a pipeline function for trimming non word
* characters from the begining and end of tokens before they
* enter the index.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* This implementation may not work correctly for non latin
* characters and should either be removed or adapted for use
* with languages with non-latin characters.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @module
* @param {String} token The token to pass through the filter
* @returns {String}
* @see lunr.Pipeline
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.trimmer = function (token) {
return token.replace(/^\W+/, '').replace(/\W+$/, '')
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
/*!
* lunr.stemmer
* Copyright (C) 2016 Oliver Nightingale
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
*/
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* lunr.TokenStore is used for efficient storing and lookup of the reverse
* index of token to document ref.
*
* @constructor
*/
lunr.TokenStore = function () {
this.root = { docs: {} }
this.length = 0
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Loads a previously serialised token store
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {Object} serialisedData The serialised token store to load.
* @returns {lunr.TokenStore}
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.load = function (serialisedData) {
var store = new this
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
store.root = serialisedData.root
store.length = serialisedData.length
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return store
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Adds a new token doc pair to the store.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* By default this function starts at the root of the current store, however
* it can start at any node of any token store if required.
*
* @param {String} token The token to store the doc under
* @param {Object} doc The doc to store against the token
* @param {Object} root An optional node at which to start looking for the
* correct place to enter the doc, by default the root of this lunr.TokenStore
* is used.
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.add = function (token, doc, root) {
var root = root || this.root,
key = token.charAt(0),
rest = token.slice(1)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!(key in root)) root[key] = {docs: {}}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (rest.length === 0) {
root[key].docs[doc.ref] = doc
this.length += 1
return
} else {
return this.add(rest, doc, root[key])
2016-07-06 14:32:52 +00:00
}
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Checks whether this key is contained within this lunr.TokenStore.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* By default this function starts at the root of the current store, however
* it can start at any node of any token store if required.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} token The token to check for
* @param {Object} root An optional node at which to start
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.has = function (token) {
if (!token) return false
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var node = this.root
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < token.length; i++) {
if (!node[token.charAt(i)]) return false
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
node = node[token.charAt(i)]
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return true
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Retrieve a node from the token store for a given token.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* By default this function starts at the root of the current store, however
* it can start at any node of any token store if required.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} token The token to get the node for.
* @param {Object} root An optional node at which to start.
* @returns {Object}
* @see TokenStore.prototype.get
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.getNode = function (token) {
if (!token) return {}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var node = this.root
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < token.length; i++) {
if (!node[token.charAt(i)]) return {}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
node = node[token.charAt(i)]
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return node
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Retrieve the documents for a node for the given token.
*
* By default this function starts at the root of the current store, however
* it can start at any node of any token store if required.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} token The token to get the documents for.
* @param {Object} root An optional node at which to start.
2016-07-06 14:32:52 +00:00
* @returns {Object}
2016-07-11 18:22:39 +00:00
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.get = function (token, root) {
return this.getNode(token, root).docs || {}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.count = function (token, root) {
return Object.keys(this.get(token, root)).length
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Remove the document identified by ref from the token in the store.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* By default this function starts at the root of the current store, however
* it can start at any node of any token store if required.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} token The token to get the documents for.
* @param {String} ref The ref of the document to remove from this token.
* @param {Object} root An optional node at which to start.
* @returns {Object}
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.remove = function (token, ref) {
if (!token) return
var node = this.root
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0; i < token.length; i++) {
if (!(token.charAt(i) in node)) return
node = node[token.charAt(i)]
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
delete node.docs[ref]
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Find all the possible suffixes of the passed token using tokens
* currently in the store.
2016-07-06 14:32:52 +00:00
*
2016-07-11 18:22:39 +00:00
* @param {String} token The token to expand.
* @returns {Array}
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.expand = function (token, memo) {
var root = this.getNode(token),
docs = root.docs || {},
memo = memo || []
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (Object.keys(docs).length) memo.push(token)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.keys(root)
.forEach(function (key) {
if (key === 'docs') return
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
memo.concat(this.expand(token + key, memo))
}, this)
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return memo
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
/**
2016-07-11 18:22:39 +00:00
* Returns a representation of the token store ready for serialisation.
2016-07-06 14:32:52 +00:00
*
* @returns {Object}
2016-07-11 18:22:39 +00:00
* @memberOf TokenStore
2016-07-06 14:32:52 +00:00
*/
2016-07-11 18:22:39 +00:00
lunr.TokenStore.prototype.toJSON = function () {
return {
root: this.root,
length: this.length
}
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
/**
* export the module via AMD, CommonJS or as a browser global
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
*/
;(function (root, factory) {
if (true) {
// AMD. Register as an anonymous module.
!(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))
} else if (typeof exports === 'object') {
/**
* Node. Does not work with strict CommonJS, but
* only CommonJS-like enviroments that support module.exports,
* like Node.
*/
module.exports = factory()
} else {
// Browser globals (root is window)
root.lunr = factory()
}
}(this, function () {
/**
* Just return a value to define the module export.
* This example returns an object, but the module
* can return a function as the exported value.
*/
return lunr
}))
})();
/***/ },
/* 20 */
/***/ function(module, exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default={"categories":[{"name":"People","emojis":["grinning","grimacing","grin","joy","smiley","smile","sweat_smile","laughing","innocent","wink","blush","slightly_smiling_face","upside_down_face","relaxed","yum","relieved","heart_eyes","kissing_heart","kissing","kissing_smiling_eyes","kissing_closed_eyes","stuck_out_tongue_winking_eye","stuck_out_tongue_closed_eyes","stuck_out_tongue","money_mouth_face","nerd_face","sunglasses","hugging_face","smirk","no_mouth","neutral_face","expressionless","unamused","face_with_rolling_eyes","thinking_face","flushed","disappointed","worried","angry","rage","pensive","confused","slightly_frowning_face","white_frowning_face","persevere","confounded","tired_face","weary","triumph","open_mouth","scream","fearful","cold_sweat","hushed","frowning","anguished","cry","disappointed_relieved","sleepy","sweat","sob","dizzy_face","astonished","zipper_mouth_face","mask","face_with_thermometer","face_with_head_bandage","sleeping","zzz","hankey","smiling_imp","imp","japanese_ogre","japanese_goblin","skull","ghost","alien","robot_face","smiley_cat","smile_cat","joy_cat","heart_eyes_cat","smirk_cat","kissing_cat","scream_cat","crying_cat_face","pouting_cat","raised_hands","clap","wave","+1","-1","facepunch","fist","v","ok_hand","hand","open_hands","muscle","pray","point_up","point_up_2","point_down","point_left","point_right","middle_finger","raised_hand_with_fingers_splayed","the_horns","spock-hand","writing_hand","nail_care","lips","tongue","ear","nose","eye","eyes","bust_in_silhouette","busts_in_silhouette","speaking_head_in_silhouette","baby","boy","girl","man","woman","person_with_blond_hair","older_man","older_woman","man_with_gua_pi_mao","man_with_turban","cop","construction_worker","guardsman","sleuth_or_spy","santa","angel","princess","bride_with_veil","walking","runner","dancer","dancers","couple","two_men_holding_hands","two_women_holding_hands","bow","information_desk_person","no_good","ok_woman","raising_hand","person_with_pouting_face","person_frowning","haircut","massage","couple_with_heart","woman-heart-woman","man-heart-man","couplekiss","woman-kiss-woman","man-kiss-man","family","man-woman-girl","man-woman-girl-boy","man-woman-boy-boy","man-woman-girl-girl","woman-woman-boy","woman-woman-girl","woman-woman-girl-boy","woman-woman-boy-boy","woman-woman-girl-girl","man-man-boy","man-man-girl","man-man-girl-boy","man-man-boy-boy","man-man-girl-girl","womans_clothes","shirt","jeans","necktie","dress","bikini","kimono","lipstick","kiss","footprints","high_heel","sandal","boot","mans_shoe","athletic_shoe","womans_hat","tophat","helmet_with_white_cross","mortar_board","crown","school_satchel","pouch","purse","handbag","briefcase","eyeglasses","dark_sunglasses","ring","closed_umbrella"]},{"name":"Nature","emojis":["dog","cat","mouse","hamster","rabbit","bear","panda_face","koala","tiger","lion_face","cow","pig","pig_nose","frog","octopus","monkey_face","see_no_evil","hear_no_evil","speak_no_evil","monkey","chicken","penguin","bird","baby_chick","hatching_chick","hatched_chick","wolf","boar","horse","unicorn_face","bee","bug","snail","beetle","ant","spider","scorpion","crab","snake","turtle","tropical_fish","fish","blowfish","dolphin","whale","whale2","crocodile","leopard","tiger2","water_buffalo","ox","cow2","dromedary_camel","camel","elephant","goat","ram","sheep","racehorse","pig2","rat","mouse2","rooster","turkey","dove_of_peace","dog2","poodle","cat2","rabbit2","chipmunk","feet","dragon","dragon_face","cactus","christmas_tree","evergreen_tree","deciduous_tree","palm_tree","seedling","herb","shamrock","four_leaf_clover","bamboo","tanabata_tree","leaves","fallen_leaf","maple_leaf","ear_of_rice","hibiscus","sunflower","rose","tulip","blossom","cherry_blossom","bouquet","mushroom","chestnut","jack_o_lantern","shell","spider_web","earth_americas","earth_africa","earth_asia","full_moon","waning_gibbous_moon","last_quarter_moon","waning_crescent_moon","new_moon","waxing_crescent_moon","first_quarter_moon","moon","ne
/***/ },
/* 21 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _ = __webpack_require__(16);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var frequently = _.store.get('frequently') || {};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function add(emoji) {
var id = emoji.id;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
frequently[id] || (frequently[id] = 0);
frequently[id] += 1;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_.store.set('last', id);
_.store.set('frequently', frequently);
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function get(quantity) {
var sorted = Object.keys(frequently).sort(function (a, b) {
return frequently[a] - frequently[b];
}).reverse(),
sliced = sorted.slice(0, quantity),
last = _.store.get('last');
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (last && sliced.indexOf(last) == -1) {
sliced.pop();
sliced.push(last);
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return sliced;
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = { add: add, get: get };
/***/ },
/* 22 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _data = __webpack_require__(20);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _data2 = _interopRequireDefault(_data);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _toConsumableArray(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); } }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var SHEET_COLUMNS = 41;
var SKINS = ['1F3FA', '1F3FB', '1F3FC', '1F3FD', '1F3FE', '1F3FF'];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var Emoji = function (_React$Component) {
_inherits(Emoji, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function Emoji(props) {
_classCallCheck(this, Emoji);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Emoji).call(this, props));
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var emojiData = _this.getEmojiData();
_this.hasSkinVariations = !!emojiData.skin_variations;
return _this;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_createClass(Emoji, [{
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps) {
return this.hasSkinVariations && nextProps.skin != this.props.skin || nextProps.size != this.props.size || nextProps.sheetURL != this.props.sheetURL;
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
}, {
key: 'getEmojiData',
value: function getEmojiData() {
var _props = this.props;
var emoji = _props.emoji;
var skin = _props.skin;
var sheetURL = _props.sheetURL;
var emojiData = emoji;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (typeof emoji == 'string') {
emojiData = _data2.default.emojis[emoji];
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (this.hasSkinVariations && skin > 1) {
emojiData = JSON.parse(JSON.stringify(_data2.default.emojis[emoji]));
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var skinKey = SKINS[skin - 1],
variationKey = emojiData.unified + '-' + skinKey,
variationData = emojiData.skin_variations[variationKey],
kitMatches = sheetURL.match(/(apple|google|twitter|emojione)/),
kit = kitMatches[0];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (variationData['has_img_' + kit]) {
emojiData.skin_tone = skin;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var k in variationData) {
var v = variationData[k];
emojiData[k] = v;
}
}
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return emojiData;
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
}, {
key: 'getPosition',
value: function getPosition(emojiData) {
var sheet_x = emojiData.sheet_x;
var sheet_y = emojiData.sheet_y;
var multiply = 100 / (SHEET_COLUMNS - 1);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return multiply * sheet_x + '% ' + multiply * sheet_y + '%';
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
}, {
key: 'getNative',
value: function getNative(emojiData) {
var unified = emojiData.unified;
var unicodes = unified.split('-');
var codePoints = unicodes.map(function (u) {
return '0x' + u;
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return String.fromCodePoint.apply(String, _toConsumableArray(codePoints));
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
}, {
key: 'handleClick',
value: function handleClick(emojiData) {
var onClick = this.props.onClick;
var name = emojiData.name;
var short_names = emojiData.short_names;
var skin_tone = emojiData.skin_tone;
var emoticons = emojiData.emoticons;
var unified = emojiData.unified;
var id = short_names[0];
var colons = ':' + id + ':';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (skin_tone) {
colons += ':skin-tone-' + skin_tone + ':';
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
onClick({
id: id,
name: name,
colons: colons,
emoticons: emoticons,
skin: skin_tone || 1,
native: this.getNative(emojiData)
});
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
}, {
key: 'render',
value: function render() {
var _this2 = this;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _props2 = this.props;
var sheetURL = _props2.sheetURL;
var size = _props2.size;
var onOver = _props2.onOver;
var onLeave = _props2.onLeave;
var emojiData = this.getEmojiData();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return _react2.default.createElement(
'span',
{
onClick: function onClick() {
return _this2.handleClick(emojiData);
},
onMouseEnter: function onMouseEnter() {
return onOver(emojiData);
},
onMouseLeave: function onMouseLeave() {
return onLeave(emojiData);
},
className: 'emoji-picker-emoji' },
_react2.default.createElement('span', { style: {
width: size,
height: size,
display: 'inline-block',
backgroundImage: 'url(' + sheetURL + ')',
backgroundSize: 100 * SHEET_COLUMNS + '%',
backgroundPosition: this.getPosition(emojiData)
} })
);
2016-07-06 14:32:52 +00:00
}
2016-07-11 18:22:39 +00:00
}]);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return Emoji;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = Emoji;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Emoji.propTypes = {
skin: _react2.default.PropTypes.number,
onOver: _react2.default.PropTypes.func,
onLeave: _react2.default.PropTypes.func,
onClick: _react2.default.PropTypes.func,
size: _react2.default.PropTypes.number.isRequired,
sheetURL: _react2.default.PropTypes.string.isRequired,
emoji: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.object]).isRequired
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Emoji.defaultProps = {
skin: 1,
onOver: function onOver() {},
onLeave: function onLeave() {},
onClick: function onClick() {}
};
/***/ },
/* 23 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
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; };
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
__webpack_require__(24);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _data = __webpack_require__(20);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _data2 = _interopRequireDefault(_data);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _utils = __webpack_require__(16);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _ = __webpack_require__(1);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var RECENT_CATEGORY = { name: 'Recent', emojis: null };
var SEARCH_CATEGORY = { name: 'Search', emojis: null, anchor: RECENT_CATEGORY };
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var CATEGORIES = [SEARCH_CATEGORY, RECENT_CATEGORY].concat(_data2.default.categories);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var Picker = function (_React$Component) {
_inherits(Picker, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function Picker(props) {
_classCallCheck(this, Picker);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Picker).call(this, props));
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_this.testStickyPosition();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_this.state = {
skin: _utils.store.get('skin') || props.skin
};
return _this;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_createClass(Picker, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(props) {
if (props.skin && !_utils.store.get('skin')) {
this.setState({ skin: props.skin });
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
this.updateCategoriesSize();
this.handleScroll();
}
}, {
key: 'testStickyPosition',
value: function testStickyPosition() {
var stickyTestElement = document.createElement('div');
var _arr = ['', '-webkit-', '-ms-', '-moz-', '-o-'];
for (var _i = 0; _i < _arr.length; _i++) {
var prefix = _arr[_i];
stickyTestElement.style.position = prefix + 'sticky';
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.hasStickyPosition = !!stickyTestElement.style.position.length;
}
}, {
key: 'handleEmojiOver',
value: function handleEmojiOver(emoji) {
var preview = this.refs.preview;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
preview.setState({ emoji: emoji });
clearTimeout(this.leaveTimeout);
}
}, {
key: 'handleEmojiLeave',
value: function handleEmojiLeave(emoji) {
var _this2 = this;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.leaveTimeout = setTimeout(function () {
var preview = _this2.refs.preview;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
preview.setState({ emoji: null });
}, 16);
}
}, {
key: 'handleEmojiClick',
value: function handleEmojiClick(emoji) {
var _this3 = this;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.props.onClick(emoji);
_utils.frequently.add(emoji);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var component = this.refs['category-1'];
if (component) {
(function () {
var maxMargin = component.maxMargin;
component.forceUpdate();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
window.requestAnimationFrame(function () {
component.memoizeSize();
if (maxMargin == component.maxMargin) return;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_this3.updateCategoriesSize();
_this3.handleScrollPaint();
});
})();
}
}
}, {
key: 'handleScroll',
value: function handleScroll() {
if (!this.waitingForPaint) {
this.waitingForPaint = true;
window.requestAnimationFrame(this.handleScrollPaint.bind(this));
}
}
}, {
key: 'handleScrollPaint',
value: function handleScrollPaint() {
this.waitingForPaint = false;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var target = this.refs.scroll,
scrollTop = target.scrollTop,
scrollingDown = scrollTop > (this.scrollTop || 0),
activeCategory = null,
minTop = 0;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0, l = CATEGORIES.length; i < l; i++) {
var ii = scrollingDown ? CATEGORIES.length - 1 - i : i,
category = CATEGORIES[ii],
component = this.refs['category-' + ii];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!minTop || component.top < minTop) {
if (component.top > 0) {
minTop = component.top;
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (component) {
var active = component.handleScroll(scrollTop);
if (active && !activeCategory) {
if (category.anchor) category = category.anchor;
activeCategory = category;
}
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (scrollTop < minTop) {
activeCategory = RECENT_CATEGORY;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (activeCategory) {
var anchors = this.refs.anchors;
var _activeCategory = activeCategory;
var categoryName = _activeCategory.name;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (anchors.state.selected != categoryName) {
anchors.setState({ selected: categoryName });
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.scrollTop = scrollTop;
}
}, {
key: 'handleSearch',
value: function handleSearch(emojis) {
SEARCH_CATEGORY.emojis = emojis;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
for (var i = 0, l = CATEGORIES.length; i < l; i++) {
var component = this.refs['category-' + i];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (component && component.props.name != 'Search') {
var display = emojis ? 'none' : null;
component.updateDisplay(display);
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.forceUpdate();
}
}, {
key: 'handleAnchorClick',
value: function handleAnchorClick(category, i) {
var component = this.refs['category-' + i];
var _refs = this.refs;
var scroll = _refs.scroll;
var anchors = _refs.anchors;
var scrollToComponent = null;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
scrollToComponent = function scrollToComponent() {
if (component) {
var top = component.top;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (category.name == 'Recent') {
top = 0;
} else {
top += 1;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
scroll.scrollTop = top;
}
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (SEARCH_CATEGORY.emojis) {
this.handleSearch(null);
this.refs.search.clear();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
window.requestAnimationFrame(scrollToComponent);
} else {
scrollToComponent();
}
}
}, {
key: 'handleSkinChange',
value: function handleSkinChange(skin) {
var newState = { skin: skin };
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.setState(newState);
_utils.store.update(newState);
}
}, {
key: 'updateCategoriesSize',
value: function updateCategoriesSize() {
for (var i = 0, l = CATEGORIES.length; i < l; i++) {
var component = this.refs['category-' + i];
if (component) component.memoizeSize();
}
}
}, {
key: 'render',
value: function render() {
var _this4 = this;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _props = this.props;
var perLine = _props.perLine;
var emojiSize = _props.emojiSize;
var sheetURL = _props.sheetURL;
var style = _props.style;
var skin = this.state.skin;
var width = perLine * (emojiSize + 12) + 12 + 2;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return _react2.default.createElement(
'div',
{ style: _extends({}, style, { width: width }), className: 'emoji-picker' },
_react2.default.createElement(
'div',
{ className: 'emoji-picker-bar' },
_react2.default.createElement(_.Anchors, {
ref: 'anchors',
categories: CATEGORIES,
onAnchorClick: this.handleAnchorClick.bind(this)
})
),
_react2.default.createElement(
'div',
{ ref: 'scroll', className: 'emoji-picker-scroll', onScroll: this.handleScroll.bind(this) },
_react2.default.createElement(_.Search, {
ref: 'search',
onSearch: this.handleSearch.bind(this)
}),
CATEGORIES.map(function (category, i) {
return _react2.default.createElement(_.Category, {
ref: 'category-' + i,
key: category.name,
name: category.name,
emojis: category.emojis,
perLine: perLine,
hasStickyPosition: _this4.hasStickyPosition,
emojiProps: {
skin: skin,
size: emojiSize,
sheetURL: sheetURL,
onOver: _this4.handleEmojiOver.bind(_this4),
onLeave: _this4.handleEmojiLeave.bind(_this4),
onClick: _this4.handleEmojiClick.bind(_this4)
}
});
})
),
_react2.default.createElement(
'div',
{ className: 'emoji-picker-bar' },
_react2.default.createElement(_.Preview, {
ref: 'preview',
emojiProps: {
size: 38,
sheetURL: sheetURL
},
skinsProps: {
skin: skin,
onChange: this.handleSkinChange.bind(this)
}
})
)
);
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return Picker;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = Picker;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Picker.propTypes = {
onClick: _react2.default.PropTypes.func,
skin: _react2.default.PropTypes.number,
perLine: _react2.default.PropTypes.number,
emojiSize: _react2.default.PropTypes.number,
style: _react2.default.PropTypes.object,
sheetURL: _react2.default.PropTypes.string.isRequired
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Picker.defaultProps = {
onClick: function onClick() {},
emojiSize: 24,
perLine: 9,
style: {},
skin: 1
};
/***/ },
/* 24 */
/***/ function(module, exports) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
// MIT license
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
(function () {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!window.requestAnimationFrame) window.requestAnimationFrame = function (callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function () {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
})();
/***/ },
/* 25 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
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; };
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _ = __webpack_require__(1);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var Preview = function (_React$Component) {
_inherits(Preview, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function Preview(props) {
_classCallCheck(this, Preview);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Preview).call(this, props));
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_this.state = { emoji: null };
return _this;
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_createClass(Preview, [{
key: 'render',
value: function render() {
var emoji = this.state.emoji;
var _props = this.props;
var emojiProps = _props.emojiProps;
var skinsProps = _props.skinsProps;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (emoji) {
var emoticons = emoji.emoticons;
var knownEmoticons = [];
var listedEmoticons = [];
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
try {
for (var _iterator = emoticons[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var emoticon = _step.value;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
if (knownEmoticons.indexOf(emoticon.toLowerCase()) == -1) {
knownEmoticons.push(emoticon.toLowerCase());
listedEmoticons.push(emoticon);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return _react2.default.createElement(
'div',
{ className: 'emoji-picker-preview' },
_react2.default.createElement(
'div',
{ className: 'emoji-picker-preview-emoji' },
_react2.default.createElement(_.Emoji, _extends({
key: emoji.short_name || emoji,
emoji: emoji
}, emojiProps))
),
_react2.default.createElement(
'div',
{ className: 'emoji-picker-preview-data' },
_react2.default.createElement(
'span',
{ className: 'emoji-picker-preview-name' },
emoji.name
),
_react2.default.createElement('br', null),
_react2.default.createElement(
'span',
{ className: 'emoji-picker-preview-shortnames' },
emoji.short_names.map(function (short_name) {
return _react2.default.createElement(
'span',
{ key: short_name, className: 'emoji-picker-preview-shortname' },
':',
short_name,
':'
);
}),
_react2.default.createElement('br', null),
listedEmoticons.map(function (emoticon) {
return _react2.default.createElement(
'span',
{ key: emoticon, className: 'emoji-picker-preview-emoticon' },
emoticon
);
})
)
)
);
} else {
return _react2.default.createElement(
'div',
{ className: 'emoji-picker-preview' },
_react2.default.createElement(
'div',
{ className: 'emoji-picker-preview-emoji' },
_react2.default.createElement(_.Emoji, _extends({
emoji: 'tophat'
}, emojiProps))
),
_react2.default.createElement(
'div',
{ className: 'emoji-picker-preview-data' },
_react2.default.createElement(
'span',
{ className: 'emoji-picker-title-label' },
'EmojiPicker'
)
),
_react2.default.createElement(
'div',
{ className: 'emoji-picker-preview-skins' },
_react2.default.createElement(_.Skins, skinsProps)
)
);
}
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return Preview;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = Preview;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Preview.propTypes = {
emojiProps: _react2.default.PropTypes.object.isRequired,
skinsProps: _react2.default.PropTypes.object.isRequired
};
/***/ },
/* 26 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var _utils = __webpack_require__(16);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
var Search = function (_React$Component) {
_inherits(Search, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
function Search() {
_classCallCheck(this, Search);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return _possibleConstructorReturn(this, Object.getPrototypeOf(Search).apply(this, arguments));
2016-07-06 14:32:52 +00:00
}
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
_createClass(Search, [{
key: 'handleChange',
value: function handleChange() {
var input = this.refs.input;
var value = input.value;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
this.props.onSearch(_utils.emojiIndex.search(value));
}
}, {
key: 'clear',
value: function clear() {
this.refs.input.value = '';
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement('input', {
ref: 'input',
type: 'text',
onChange: this.handleChange.bind(this),
placeholder: 'Search',
className: 'emoji-picker-search'
});
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
return Search;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
exports.default = Search;
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Search.propTypes = {
onSearch: _react2.default.PropTypes.func,
maxResults: _react2.default.PropTypes.number
};
2016-07-11 19:04:58 +00:00
2016-07-11 18:22:39 +00:00
Search.defaultProps = {
onSearch: function onSearch() {},
maxResults: 75
};
2016-07-06 14:32:52 +00:00
/***/ },
2016-07-11 18:22:39 +00:00
/* 27 */
2016-07-06 14:32:52 +00:00
/***/ function(module, exports, __webpack_require__) {
'use strict';
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
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; }; }();
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react = __webpack_require__(3);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _react2 = _interopRequireDefault(_react);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var Skins = function (_React$Component) {
_inherits(Skins, _React$Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
function Skins(props) {
_classCallCheck(this, Skins);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Skins).call(this, props));
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_this.state = {
opened: false
};
return _this;
}
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
_createClass(Skins, [{
key: 'handleClick',
value: function handleClick(skin) {
var onChange = this.props.onChange;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
if (!this.state.opened) {
this.setState({ opened: true });
} else {
onChange(skin);
this.setState({ opened: false });
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
var skin = this.props.skin;
var opened = this.state.opened;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(
'div',
{ className: 'emoji-picker-skin-swatches ' + (opened ? 'emoji-picker-skin-swatches-opened' : '') },
Array(6).fill().map(function (_, i) {
var skinTone = i + 1,
selected = skinTone == skin;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return _react2.default.createElement(
'span',
{ key: 'skin-tone-' + skinTone, className: 'emoji-picker-skin-swatch ' + (selected ? 'emoji-picker-skin-swatch-selected' : '') },
_react2.default.createElement('span', {
onClick: function onClick() {
return _this2.handleClick(skinTone);
},
className: 'emoji-picker-skin emoji-picker-skin-tone-' + skinTone })
);
})
)
);
}
}]);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
return Skins;
}(_react2.default.Component);
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
exports.default = Skins;
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Skins.propTypes = {
onChange: _react2.default.PropTypes.func,
skin: _react2.default.PropTypes.number.isRequired
};
2016-07-11 19:04:58 +00:00
2016-07-06 14:32:52 +00:00
Skins.defaultProps = {
onChange: function onChange() {}
};
/***/ }
/******/ ])
});
2016-07-11 19:04:58 +00:00
;