@quintoandar-tokko/wrapped 1.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/index.js +197 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 One Loop
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Wrapped = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _box = require("@quintoandar-tokko/box");
|
|
9
|
+
var _tags = require("@quintoandar-tokko/tags");
|
|
10
|
+
var _excluded = ["items", "fnClose", "widthRestItemsWindow", "printKey", "tagVariant", "clickFn", "idKey"];
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
15
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
16
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
19
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
20
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
21
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
22
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
24
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
25
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
26
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
27
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
28
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
29
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
30
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
31
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable no-unused-expressions */ /* eslint-disable multiline-ternary */
|
|
32
|
+
var wrappedReducer = function wrappedReducer(state, action) {
|
|
33
|
+
switch (action.type) {
|
|
34
|
+
case 'ADD_REST_ITEM':
|
|
35
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
36
|
+
restItems: [].concat(_toConsumableArray(state.restItems), [action.payload])
|
|
37
|
+
});
|
|
38
|
+
case 'DELETE_REST_ITEM':
|
|
39
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
40
|
+
restItems: []
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var Wrapped = exports.Wrapped = function Wrapped(_ref) {
|
|
45
|
+
var items = _ref.items,
|
|
46
|
+
fnClose = _ref.fnClose,
|
|
47
|
+
widthRestItemsWindow = _ref.widthRestItemsWindow,
|
|
48
|
+
printKey = _ref.printKey,
|
|
49
|
+
tagVariant = _ref.tagVariant,
|
|
50
|
+
clickFn = _ref.clickFn,
|
|
51
|
+
_ref$idKey = _ref.idKey,
|
|
52
|
+
idKey = _ref$idKey === void 0 ? 'id' : _ref$idKey,
|
|
53
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
54
|
+
var _useReducer = (0, _react.useReducer)(wrappedReducer, {
|
|
55
|
+
restItems: []
|
|
56
|
+
}),
|
|
57
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
58
|
+
store = _useReducer2[0],
|
|
59
|
+
dispatch = _useReducer2[1];
|
|
60
|
+
var _useState = (0, _react.useState)(false),
|
|
61
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
62
|
+
showRestItem = _useState2[0],
|
|
63
|
+
setShowRestItems = _useState2[1];
|
|
64
|
+
var Ref = (0, _react.useRef)(null);
|
|
65
|
+
var refElements = (0, _react.useRef)([]);
|
|
66
|
+
var RefItemsWindow = (0, _react.useRef)(null);
|
|
67
|
+
var widthWrapper = 0;
|
|
68
|
+
var widthElements = 0;
|
|
69
|
+
var elements = 0;
|
|
70
|
+
(0, _react.useEffect)(function () {
|
|
71
|
+
elements = Ref.current.children;
|
|
72
|
+
widthWrapper = Ref.current.offsetWidth;
|
|
73
|
+
var _loop = function _loop(index) {
|
|
74
|
+
if (!refElements.current.find(function (elem) {
|
|
75
|
+
return elem.id === elements[index].id;
|
|
76
|
+
}) && !elements[index].className.includes('numberTag')) {
|
|
77
|
+
refElements.current.push(_objectSpread(_objectSpread({}, elements[index]), {}, {
|
|
78
|
+
width: elements[index].offsetWidth + 5,
|
|
79
|
+
id: elements[index].id
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
if (!elements[index].className.includes('numberTag')) {
|
|
83
|
+
widthElements = widthElements + refElements.current[index].width;
|
|
84
|
+
}
|
|
85
|
+
if (widthElements > widthWrapper - 30) {
|
|
86
|
+
elements[index].style.display = elements[index].className.includes('numberTag') ? 'inline-flex' : 'none';
|
|
87
|
+
if (!elements[index].className.includes('numberTag')) {
|
|
88
|
+
if (!store.restItems.find(function (elem) {
|
|
89
|
+
return elem[idKey] === items[index][idKey];
|
|
90
|
+
})) {
|
|
91
|
+
dispatch({
|
|
92
|
+
type: 'ADD_REST_ITEM',
|
|
93
|
+
payload: items[index]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
for (var index = 0; index < elements.length; index++) {
|
|
100
|
+
_loop(index);
|
|
101
|
+
}
|
|
102
|
+
}, [items]);
|
|
103
|
+
(0, _react.useEffect)(function () {
|
|
104
|
+
var handleClick = function handleClick(event) {
|
|
105
|
+
var _RefItemsWindow$curre, _event$target$classNa;
|
|
106
|
+
if (!((_RefItemsWindow$curre = RefItemsWindow.current) !== null && _RefItemsWindow$curre !== void 0 && _RefItemsWindow$curre.contains(event.target)) && !((_event$target$classNa = event.target.className) !== null && _event$target$classNa !== void 0 && _event$target$classNa.includes('numberTag'))) {
|
|
107
|
+
setShowRestItems(false);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
document.addEventListener('click', handleClick);
|
|
111
|
+
return function () {
|
|
112
|
+
document.removeEventListener('click', handleClick);
|
|
113
|
+
};
|
|
114
|
+
}, [showRestItem]);
|
|
115
|
+
var handleShowRestItems = function handleShowRestItems() {
|
|
116
|
+
setShowRestItems(!showRestItem);
|
|
117
|
+
};
|
|
118
|
+
var deleteRestItem = function deleteRestItem(item) {
|
|
119
|
+
refElements.current = refElements.current.filter(function (elem) {
|
|
120
|
+
return elem.id !== item[idKey];
|
|
121
|
+
});
|
|
122
|
+
dispatch({
|
|
123
|
+
type: 'DELETE_REST_ITEM'
|
|
124
|
+
});
|
|
125
|
+
fnClose(item);
|
|
126
|
+
};
|
|
127
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({
|
|
128
|
+
__css: {
|
|
129
|
+
display: 'block',
|
|
130
|
+
alignItems: 'center',
|
|
131
|
+
gap: '5px',
|
|
132
|
+
overflow: widthWrapper,
|
|
133
|
+
whiteSpace: 'nowrap'
|
|
134
|
+
}
|
|
135
|
+
}, props, {
|
|
136
|
+
ref: Ref
|
|
137
|
+
}), items.map(function (item, i) {
|
|
138
|
+
return /*#__PURE__*/_react["default"].createElement(_tags.Tags, {
|
|
139
|
+
key: item[idKey] + i,
|
|
140
|
+
id: item[idKey],
|
|
141
|
+
variant: tagVariant,
|
|
142
|
+
closeIcon: fnClose ? function () {
|
|
143
|
+
return deleteRestItem(item);
|
|
144
|
+
} : false,
|
|
145
|
+
style: {
|
|
146
|
+
marginRight: '5px'
|
|
147
|
+
},
|
|
148
|
+
onClick: item[clickFn]
|
|
149
|
+
}, /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
150
|
+
as: "p",
|
|
151
|
+
__css: {
|
|
152
|
+
maxWidth: '250px',
|
|
153
|
+
overflow: 'hidden',
|
|
154
|
+
whiteSpace: 'noWrap',
|
|
155
|
+
textOverflow: 'ellipsis'
|
|
156
|
+
}
|
|
157
|
+
}, item[printKey]));
|
|
158
|
+
}), store.restItems.length > 0 ? /*#__PURE__*/_react["default"].createElement(_tags.Tags, {
|
|
159
|
+
variant: tagVariant,
|
|
160
|
+
className: "numberTag",
|
|
161
|
+
onClick: handleShowRestItems
|
|
162
|
+
}, "+".concat(store.restItems.length)) : ''), showRestItem && /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
163
|
+
ref: RefItemsWindow,
|
|
164
|
+
__css: {
|
|
165
|
+
padding: '12px 14px',
|
|
166
|
+
position: 'absolute',
|
|
167
|
+
top: '30px',
|
|
168
|
+
background: '#FFFFFF',
|
|
169
|
+
boxShadow: '4px 4px 12px rgba(87, 95, 99, 0.1)',
|
|
170
|
+
borderRadius: '8px',
|
|
171
|
+
width: widthRestItemsWindow,
|
|
172
|
+
zIndex: 100
|
|
173
|
+
}
|
|
174
|
+
}, store.restItems.map(function (item, i) {
|
|
175
|
+
return /*#__PURE__*/_react["default"].createElement(_tags.Tags, {
|
|
176
|
+
key: item[idKey] + i,
|
|
177
|
+
id: item[idKey],
|
|
178
|
+
variant: tagVariant,
|
|
179
|
+
closeIcon: fnClose ? function () {
|
|
180
|
+
return deleteRestItem(item);
|
|
181
|
+
} : false,
|
|
182
|
+
style: {
|
|
183
|
+
marginRight: '5px',
|
|
184
|
+
marginBottom: '5px'
|
|
185
|
+
},
|
|
186
|
+
onClick: item[clickFn]
|
|
187
|
+
}, /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
188
|
+
as: "p",
|
|
189
|
+
__css: {
|
|
190
|
+
maxWidth: '250px',
|
|
191
|
+
overflow: 'hidden',
|
|
192
|
+
whiteSpace: 'noWrap',
|
|
193
|
+
textOverflow: 'ellipsis'
|
|
194
|
+
}
|
|
195
|
+
}, item[printKey]));
|
|
196
|
+
})));
|
|
197
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quintoandar-tokko/wrapped",
|
|
3
|
+
"version": "1.0.83",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"module": "src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@quintoandar-tokko/box": "^1.2.286"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": "^16.8.0"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"gitHead": "d33e426a17c29e62c8ea591ae6afa96300d55ad9"
|
|
19
|
+
}
|