Skip to content

Commit 4ef4c98

Browse files
author
jfusco
committed
Refactoring build process and adding more build scripts to package.json file. Adding config.json to make it easy to config file names
1 parent 12b6ac2 commit 4ef4c98

File tree

15 files changed

+419
-84
lines changed

15 files changed

+419
-84
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# react-tagging-input
22

33
[![Build Status][build-image]][build-url]
4-
[![Coverage Status](https://coveralls.io/repos/github/JFusco/react-tagging-input/badge.svg?branch=master)](https://coveralls.io/github/JFusco/react-tagging-input?branch=master)
54

65
[![peerDependency Status][peer-dep-image]][peer-dep-url]
76
[![devDependency Status][dev-dep-image]][dev-dep-url]
@@ -220,6 +219,6 @@ npm test
220219
[npm-version-image]: https://img.shields.io/npm/v/npm.svg?maxAge=2592000
221220
[npm-url]: https://www.npmjs.com/package/react-tagging-input
222221
[dev-dep-image]: https://david-dm.org/JFusco/react-tagging-input/dev-status.svg
223-
[dev-dep-url]: https://david-dm.org/JFusco/react-tagging-input#info=devDependencies
222+
[dev-dep-url]: https://david-dm.org/JFusco/react-tagging-input?type=dev
224223
[peer-dep-image]: https://david-dm.org/JFusco/react-tagging-input/peer-status.svg
225-
[peer-dep-url]: https://david-dm.org/JFusco/react-tagging-input#info=peerDependencies
224+
[peer-dep-url]: https://david-dm.org/JFusco/react-tagging-input?type=peer

config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"css": {
3+
"fileName": "react-tags"
4+
},
5+
"scripts": {
6+
"fileName": "react-tags",
7+
"entry": "Tags",
8+
"library": "Tags"
9+
}
10+
}

dist/react-tags.js

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
(function webpackUniversalModuleDefinition(root, factory) {
2+
if(typeof exports === 'object' && typeof module === 'object')
3+
module.exports = factory(require("React"), require("update"));
4+
else if(typeof define === 'function' && define.amd)
5+
define(["React", "update"], factory);
6+
else if(typeof exports === 'object')
7+
exports["Tags"] = factory(require("React"), require("update"));
8+
else
9+
root["Tags"] = factory(root["React"], root["update"]);
10+
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) {
11+
return /******/ (function(modules) { // webpackBootstrap
12+
/******/ // The module cache
13+
/******/ var installedModules = {};
14+
15+
/******/ // The require function
16+
/******/ function __webpack_require__(moduleId) {
17+
18+
/******/ // Check if module is in cache
19+
/******/ if(installedModules[moduleId])
20+
/******/ return installedModules[moduleId].exports;
21+
22+
/******/ // Create a new module (and put it into the cache)
23+
/******/ var module = installedModules[moduleId] = {
24+
/******/ exports: {},
25+
/******/ id: moduleId,
26+
/******/ loaded: false
27+
/******/ };
28+
29+
/******/ // Execute the module function
30+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31+
32+
/******/ // Flag the module as loaded
33+
/******/ module.loaded = true;
34+
35+
/******/ // Return the exports of the module
36+
/******/ return module.exports;
37+
/******/ }
38+
39+
40+
/******/ // expose the modules object (__webpack_modules__)
41+
/******/ __webpack_require__.m = modules;
42+
43+
/******/ // expose the module cache
44+
/******/ __webpack_require__.c = installedModules;
45+
46+
/******/ // __webpack_public_path__
47+
/******/ __webpack_require__.p = "/";
48+
49+
/******/ // Load entry module and return exports
50+
/******/ return __webpack_require__(0);
51+
/******/ })
52+
/************************************************************************/
53+
/******/ ([
54+
/* 0 */
55+
/***/ function(module, exports, __webpack_require__) {
56+
57+
'use strict';
58+
59+
Object.defineProperty(exports, "__esModule", {
60+
value: true
61+
});
62+
63+
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; }; }();
64+
65+
var _react = __webpack_require__(1);
66+
67+
var _react2 = _interopRequireDefault(_react);
68+
69+
var _reactAddonsUpdate = __webpack_require__(2);
70+
71+
var _reactAddonsUpdate2 = _interopRequireDefault(_reactAddonsUpdate);
72+
73+
var _Tag = __webpack_require__(3);
74+
75+
var _Tag2 = _interopRequireDefault(_Tag);
76+
77+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
78+
79+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
80+
81+
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; }
82+
83+
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; }
84+
85+
var Tags = function (_Component) {
86+
_inherits(Tags, _Component);
87+
88+
function Tags(props) {
89+
_classCallCheck(this, Tags);
90+
91+
var _this = _possibleConstructorReturn(this, (Tags.__proto__ || Object.getPrototypeOf(Tags)).call(this, props));
92+
93+
_this.state = {
94+
tags: _this.props.initialTags,
95+
value: ''
96+
};
97+
return _this;
98+
}
99+
100+
_createClass(Tags, [{
101+
key: 'addTag',
102+
value: function addTag() {
103+
var _this2 = this;
104+
105+
if (this.props.maxTags >= 0) {
106+
if (this.state.tags.length >= this.props.maxTags) return;
107+
}
108+
109+
var _props = this.props;
110+
var uniqueTags = _props.uniqueTags;
111+
var onChange = _props.onChange;
112+
var onAdded = _props.onAdded;
113+
114+
115+
var value = this.input.value.trim();
116+
117+
if (uniqueTags) {
118+
if (this.state.tags.indexOf(value) >= 0) return;
119+
}
120+
121+
this.setState({
122+
tags: (0, _reactAddonsUpdate2.default)(this.state.tags, { $push: [value] })
123+
}, function () {
124+
if (typeof onChange !== 'undefined') {
125+
onChange(_this2.state.tags);
126+
}
127+
128+
if (typeof onAdded !== 'undefined') {
129+
onAdded(value);
130+
}
131+
132+
_this2.input.value = '';
133+
});
134+
}
135+
}, {
136+
key: 'removeTag',
137+
value: function removeTag(index) {
138+
var _this3 = this;
139+
140+
var _props2 = this.props;
141+
var onChange = _props2.onChange;
142+
var onRemoved = _props2.onRemoved;
143+
144+
var value = this.state.tags[index];
145+
146+
this.setState({
147+
tags: (0, _reactAddonsUpdate2.default)(this.state.tags, { $splice: [[index, 1]] })
148+
}, function () {
149+
if (typeof onChange !== 'undefined') {
150+
onChange(_this3.state.tags);
151+
}
152+
153+
if (typeof onRemoved !== 'undefined') {
154+
onRemoved(value);
155+
}
156+
});
157+
}
158+
}, {
159+
key: 'onInputKey',
160+
value: function onInputKey(e) {
161+
switch (e.keyCode) {
162+
case Tags.KEYS.backspace:
163+
if (this.state.tags.length === 0) return;
164+
165+
if (this.input.value === '') {
166+
this.removeTag(this.state.tags.length - 1);
167+
}
168+
169+
break;
170+
171+
default:
172+
if (this.input.value === '') return;
173+
174+
if (this.props.addKeys.indexOf(e.keyCode) !== -1) {
175+
if (Tags.KEYS.enter !== e.keyCode) {
176+
e.preventDefault();
177+
}
178+
179+
this.addTag();
180+
}
181+
182+
break;
183+
}
184+
}
185+
}, {
186+
key: 'onInputChange',
187+
value: function onInputChange(e) {
188+
var value = e.target.value.trim();
189+
190+
if (typeof this.props.onInputChange !== 'undefined') {
191+
this.props.onInputChange(value);
192+
}
193+
194+
this.setState({
195+
value: value
196+
});
197+
}
198+
}, {
199+
key: 'render',
200+
value: function render() {
201+
var _this4 = this;
202+
203+
var _props3 = this.props;
204+
var readOnly = _props3.readOnly;
205+
var removeTagIcon = _props3.removeTagIcon;
206+
var placeholder = _props3.placeholder;
207+
var id = _props3.id;
208+
209+
210+
var tagItems = this.state.tags.map(function (tag, v) {
211+
return _react2.default.createElement(_Tag2.default, {
212+
key: v,
213+
name: tag,
214+
readOnly: readOnly,
215+
removeTagIcon: removeTagIcon,
216+
onRemoveTag: _this4.removeTag.bind(_this4, v) });
217+
});
218+
219+
var tagInput = !this.props.readOnly ? _react2.default.createElement('input', {
220+
type: 'text',
221+
role: 'textbox',
222+
'aria-label': placeholder,
223+
placeholder: placeholder,
224+
onChange: this.onInputChange.bind(this),
225+
onKeyDown: this.onInputKey.bind(this),
226+
ref: function ref(el) {
227+
return _this4.input = el;
228+
} }) : null;
229+
230+
var classNames = readOnly ? 'tags-container readonly' : 'tags-container';
231+
232+
return _react2.default.createElement(
233+
'div',
234+
{ className: 'react-tags', id: id },
235+
_react2.default.createElement(
236+
'ul',
237+
{ className: classNames },
238+
tagItems
239+
),
240+
tagInput
241+
);
242+
}
243+
}]);
244+
245+
return Tags;
246+
}(_react.Component);
247+
248+
Tags.KEYS = {
249+
enter: 13,
250+
tab: 9,
251+
spacebar: 32,
252+
backspace: 8,
253+
left: 37,
254+
right: 39
255+
};
256+
Tags.propTypes = {
257+
initialTags: _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.string),
258+
onChange: _react2.default.PropTypes.func,
259+
onAdded: _react2.default.PropTypes.func,
260+
onRemoved: _react2.default.PropTypes.func,
261+
onInputChange: _react2.default.PropTypes.func,
262+
maxTags: _react2.default.PropTypes.number,
263+
placeholder: _react2.default.PropTypes.string,
264+
addKeys: _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.number),
265+
id: _react2.default.PropTypes.string,
266+
readOnly: _react2.default.PropTypes.bool,
267+
uniqueTags: _react2.default.PropTypes.bool,
268+
removeTagIcon: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.element])
269+
};
270+
Tags.defaultProps = {
271+
initialTags: [],
272+
maxTags: -1,
273+
placeholder: 'Add a tag',
274+
addKeys: [Tags.KEYS.enter, Tags.KEYS.tab, Tags.KEYS.spacebar],
275+
uniqueTags: false,
276+
readOnly: false
277+
};
278+
exports.default = Tags;
279+
280+
/***/ },
281+
/* 1 */
282+
/***/ function(module, exports) {
283+
284+
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
285+
286+
/***/ },
287+
/* 2 */
288+
/***/ function(module, exports) {
289+
290+
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
291+
292+
/***/ },
293+
/* 3 */
294+
/***/ function(module, exports, __webpack_require__) {
295+
296+
'use strict';
297+
298+
Object.defineProperty(exports, "__esModule", {
299+
value: true
300+
});
301+
302+
var _react = __webpack_require__(1);
303+
304+
var _react2 = _interopRequireDefault(_react);
305+
306+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
307+
308+
var Tag = function Tag(props) {
309+
var onRemoveClick = function onRemoveClick(e) {
310+
e.preventDefault();
311+
312+
props.onRemoveTag(e);
313+
};
314+
315+
var removeIcon = !props.readOnly ? _react2.default.createElement(
316+
'a',
317+
{ onClick: onRemoveClick },
318+
props.removeTagIcon || String.fromCharCode(215)
319+
) : null;
320+
321+
return _react2.default.createElement(
322+
'li',
323+
null,
324+
props.name,
325+
removeIcon
326+
);
327+
};
328+
329+
exports.default = Tag;
330+
331+
332+
Tag.propTypes = {
333+
name: _react2.default.PropTypes.string.isRequired,
334+
onRemoveTag: _react2.default.PropTypes.func,
335+
selectedTag: _react2.default.PropTypes.bool,
336+
readOnly: _react2.default.PropTypes.bool,
337+
removeTagIcon: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.element])
338+
};
339+
340+
/***/ }
341+
/******/ ])
342+
});
343+
;

0 commit comments

Comments
 (0)