intelicoreact 1.0.22 → 1.0.24
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.
|
@@ -19,6 +19,8 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
19
19
|
|
|
20
20
|
var _react = _interopRequireWildcard(require("react"));
|
|
21
21
|
|
|
22
|
+
var _reactDom = require("react-dom");
|
|
23
|
+
|
|
22
24
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
23
25
|
|
|
24
26
|
var _reactFeather = require("react-feather");
|
|
@@ -29,8 +31,6 @@ require("./Dropdown.scss");
|
|
|
29
31
|
|
|
30
32
|
var _fieldValueFormatters = require("../../../Functions/fieldValueFormatters");
|
|
31
33
|
|
|
32
|
-
var _reactDom = require("react-dom");
|
|
33
|
-
|
|
34
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
35
|
|
|
36
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -78,12 +78,16 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
78
78
|
var dropdownRef = (0, _react.useRef)(null);
|
|
79
79
|
var dropdownListRef = (0, _react.useRef)(null);
|
|
80
80
|
|
|
81
|
-
var _useState5 = (0, _react.useState)(
|
|
81
|
+
var _useState5 = (0, _react.useState)(null),
|
|
82
82
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
initListHeight = _useState6[0],
|
|
84
|
+
setInitListHeight = _useState6[1];
|
|
85
|
+
|
|
86
|
+
var _useState7 = (0, _react.useState)(false),
|
|
87
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
88
|
+
isFocusedByClick = _useState8[0],
|
|
89
|
+
setIsFocusedByClick = _useState8[1];
|
|
85
90
|
|
|
86
|
-
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
87
91
|
if (!options) return null;
|
|
88
92
|
|
|
89
93
|
var moveOtherToEnd = function moveOtherToEnd(options) {
|
|
@@ -271,25 +275,30 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
271
275
|
};
|
|
272
276
|
|
|
273
277
|
var setListContainerStyles = function setListContainerStyles() {
|
|
274
|
-
var _getComputedStyle$mar, _getComputedStyle, _getComputedStyle$mar2,
|
|
278
|
+
var _dropdownRef$current$, _getComputedStyle$mar, _getComputedStyle, _getComputedStyle$mar2, _getComputedStyle$max, _getComputedStyle2, _getComputedStyle2$ma;
|
|
275
279
|
|
|
276
280
|
var lc = getListContainer();
|
|
277
281
|
if (!lc || !isOpen) return false;
|
|
282
|
+
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
278
283
|
|
|
279
|
-
var _dropdownRef$current$ = dropdownRef === null || dropdownRef === void 0 ? void 0 : dropdownRef.current.getBoundingClientRect(),
|
|
280
|
-
width =
|
|
281
|
-
height =
|
|
282
|
-
left =
|
|
283
|
-
top =
|
|
284
|
-
bottom = _dropdownRef$current$.bottom;
|
|
284
|
+
var _ref3 = (_dropdownRef$current$ = dropdownRef === null || dropdownRef === void 0 ? void 0 : dropdownRef.current.getBoundingClientRect()) !== null && _dropdownRef$current$ !== void 0 ? _dropdownRef$current$ : {},
|
|
285
|
+
width = _ref3.width,
|
|
286
|
+
height = _ref3.height,
|
|
287
|
+
left = _ref3.left,
|
|
288
|
+
top = _ref3.top;
|
|
285
289
|
|
|
286
290
|
var sw = lc.getElementsByClassName('dropdown__list')[0];
|
|
287
291
|
var margin = parseInt((_getComputedStyle$mar = (_getComputedStyle = getComputedStyle(sw)) === null || _getComputedStyle === void 0 ? void 0 : (_getComputedStyle$mar2 = _getComputedStyle.marginTop) === null || _getComputedStyle$mar2 === void 0 ? void 0 : _getComputedStyle$mar2.replace('px', '')) !== null && _getComputedStyle$mar !== void 0 ? _getComputedStyle$mar : 0);
|
|
288
|
-
var
|
|
292
|
+
var maxHeight = initListHeight !== null && initListHeight !== void 0 ? initListHeight : parseInt((_getComputedStyle$max = (_getComputedStyle2 = getComputedStyle(sw)) === null || _getComputedStyle2 === void 0 ? void 0 : (_getComputedStyle2$ma = _getComputedStyle2.maxHeight) === null || _getComputedStyle2$ma === void 0 ? void 0 : _getComputedStyle2$ma.replace('px', '')) !== null && _getComputedStyle$max !== void 0 ? _getComputedStyle$max : 0);
|
|
293
|
+
if (initListHeight === null) setInitListHeight(maxHeight);
|
|
294
|
+
var toTop = top - margin;
|
|
295
|
+
var toBottom = windowHeight - top - height - margin * 2;
|
|
296
|
+
var swHeight = toTop >= maxHeight || toBottom >= maxHeight ? maxHeight - 3 * margin : toTop > toBottom ? toTop - 3 * margin : toBottom - 4 * margin;
|
|
297
|
+
var listPos = toTop < toBottom || toBottom >= swHeight ? 'bottom' : 'top';
|
|
289
298
|
lc.style.minWidth = "".concat(width, "px");
|
|
290
299
|
lc.style.left = "".concat(left, "px");
|
|
291
|
-
lc.style.top = "".concat(
|
|
292
|
-
|
|
300
|
+
lc.style.top = "".concat(listPos === 'bottom' ? top + height : top - swHeight - 3 * margin, "px");
|
|
301
|
+
sw.style.maxHeight = "".concat(swHeight, "px");
|
|
293
302
|
};
|
|
294
303
|
|
|
295
304
|
var renderListContainer = function renderListContainer() {
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
&__list {
|
|
57
|
+
box-sizing: border-box;
|
|
57
58
|
position: relative;
|
|
58
59
|
background: #ffffff;
|
|
59
60
|
border: 1px solid #e2e5ec;
|
|
@@ -88,7 +89,6 @@
|
|
|
88
89
|
&-item {
|
|
89
90
|
display: flex;
|
|
90
91
|
align-items: center;
|
|
91
|
-
//justify-content: center;
|
|
92
92
|
border: none;
|
|
93
93
|
background: transparent;
|
|
94
94
|
padding: 0 20px 0 30px;
|
|
@@ -88,15 +88,22 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
88
88
|
|
|
89
89
|
var dropdownRef = (0, _react.useRef)(null);
|
|
90
90
|
var inputRef = (0, _react.useRef)(null);
|
|
91
|
-
|
|
91
|
+
|
|
92
|
+
var _useState5 = (0, _react.useState)(null),
|
|
93
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
94
|
+
initListHeight = _useState6[0],
|
|
95
|
+
setInitListHeight = _useState6[1];
|
|
96
|
+
|
|
92
97
|
var singleLevelOptions = options === null || options === void 0 ? void 0 : options.reduce(function (acc, item) {
|
|
93
98
|
return [].concat((0, _toConsumableArray2.default)(acc), (0, _toConsumableArray2.default)(item.groupName ? item.list : [item]));
|
|
94
99
|
}, []);
|
|
95
100
|
|
|
96
|
-
var handleClickOutside = function handleClickOutside(
|
|
101
|
+
var handleClickOutside = function handleClickOutside(_ref2) {
|
|
97
102
|
var _getListContainer;
|
|
98
103
|
|
|
99
|
-
|
|
104
|
+
var target = _ref2.target;
|
|
105
|
+
|
|
106
|
+
if (!((_getListContainer = getListContainer()) !== null && _getListContainer !== void 0 && _getListContainer.contains(target)) && !isTargetInParent(target)) {
|
|
100
107
|
setIsOpen(false);
|
|
101
108
|
setSearchValue('');
|
|
102
109
|
}
|
|
@@ -167,12 +174,12 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
167
174
|
var selectAllItems = function selectAllItems(e) {
|
|
168
175
|
var _prepareOptions, _prepareOptions$filte;
|
|
169
176
|
|
|
170
|
-
onChange([].concat((0, _toConsumableArray2.default)(chosenOptions), (0, _toConsumableArray2.default)((_prepareOptions = prepareOptions(options)) === null || _prepareOptions === void 0 ? void 0 : (_prepareOptions$filte = _prepareOptions.filter(function (
|
|
171
|
-
var isFreezed =
|
|
172
|
-
value =
|
|
177
|
+
onChange([].concat((0, _toConsumableArray2.default)(chosenOptions), (0, _toConsumableArray2.default)((_prepareOptions = prepareOptions(options)) === null || _prepareOptions === void 0 ? void 0 : (_prepareOptions$filte = _prepareOptions.filter(function (_ref3) {
|
|
178
|
+
var isFreezed = _ref3.isFreezed,
|
|
179
|
+
value = _ref3.value;
|
|
173
180
|
return !isFreezed && !(chosenOptions !== null && chosenOptions !== void 0 && chosenOptions.includes(value));
|
|
174
|
-
})) === null || _prepareOptions$filte === void 0 ? void 0 : _prepareOptions$filte.map(function (
|
|
175
|
-
var value =
|
|
181
|
+
})) === null || _prepareOptions$filte === void 0 ? void 0 : _prepareOptions$filte.map(function (_ref4) {
|
|
182
|
+
var value = _ref4.value;
|
|
176
183
|
return value;
|
|
177
184
|
}))), 'chosenOptions');
|
|
178
185
|
if (closeOnSelect) setIsOpen(false);
|
|
@@ -182,8 +189,8 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
182
189
|
onChange(chosenOptions === null || chosenOptions === void 0 ? void 0 : chosenOptions.filter(function (item) {
|
|
183
190
|
var _prepareOptions2, _prepareOptions2$find;
|
|
184
191
|
|
|
185
|
-
return (_prepareOptions2 = prepareOptions(options)) === null || _prepareOptions2 === void 0 ? void 0 : (_prepareOptions2$find = _prepareOptions2.find(function (
|
|
186
|
-
var value =
|
|
192
|
+
return (_prepareOptions2 = prepareOptions(options)) === null || _prepareOptions2 === void 0 ? void 0 : (_prepareOptions2$find = _prepareOptions2.find(function (_ref5) {
|
|
193
|
+
var value = _ref5.value;
|
|
187
194
|
return value === item;
|
|
188
195
|
})) === null || _prepareOptions2$find === void 0 ? void 0 : _prepareOptions2$find.isFreezed;
|
|
189
196
|
}), 'chosenOptions');
|
|
@@ -208,24 +215,32 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
208
215
|
};
|
|
209
216
|
|
|
210
217
|
var setListContainerStyles = function setListContainerStyles() {
|
|
211
|
-
var _sw$getBoundingClient,
|
|
218
|
+
var _getComputedStyle$mar, _getComputedStyle, _getComputedStyle$mar2, _getComputedStyle$max, _getComputedStyle2, _getComputedStyle2$ma, _sw$getBoundingClient, _dl$getBoundingClient;
|
|
212
219
|
|
|
213
220
|
var lc = getListContainer();
|
|
214
221
|
if (!lc || !isOpen) return false;
|
|
222
|
+
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
215
223
|
|
|
216
224
|
var _dropdownRef$current$ = dropdownRef === null || dropdownRef === void 0 ? void 0 : dropdownRef.current.getBoundingClientRect(),
|
|
217
225
|
width = _dropdownRef$current$.width,
|
|
218
226
|
height = _dropdownRef$current$.height,
|
|
219
227
|
left = _dropdownRef$current$.left,
|
|
220
|
-
top = _dropdownRef$current$.top
|
|
221
|
-
bottom = _dropdownRef$current$.bottom;
|
|
228
|
+
top = _dropdownRef$current$.top;
|
|
222
229
|
|
|
223
230
|
var sw = lc.getElementsByClassName('tags-dropdown__selector-wrapper')[0];
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
231
|
+
var dl = lc.getElementsByClassName('tags-dropdown__list')[0];
|
|
232
|
+
var margin = parseInt((_getComputedStyle$mar = (_getComputedStyle = getComputedStyle(sw)) === null || _getComputedStyle === void 0 ? void 0 : (_getComputedStyle$mar2 = _getComputedStyle.marginTop) === null || _getComputedStyle$mar2 === void 0 ? void 0 : _getComputedStyle$mar2.replace('px', '')) !== null && _getComputedStyle$mar !== void 0 ? _getComputedStyle$mar : 0);
|
|
233
|
+
var maxHeight = initListHeight !== null && initListHeight !== void 0 ? initListHeight : parseInt((_getComputedStyle$max = (_getComputedStyle2 = getComputedStyle(dl)) === null || _getComputedStyle2 === void 0 ? void 0 : (_getComputedStyle2$ma = _getComputedStyle2.maxHeight) === null || _getComputedStyle2$ma === void 0 ? void 0 : _getComputedStyle2$ma.replace('px', '')) !== null && _getComputedStyle$max !== void 0 ? _getComputedStyle$max : 0);
|
|
234
|
+
if (initListHeight === null) setInitListHeight(maxHeight);
|
|
235
|
+
var delta = ((_sw$getBoundingClient = sw.getBoundingClientRect()) === null || _sw$getBoundingClient === void 0 ? void 0 : _sw$getBoundingClient.height) - ((_dl$getBoundingClient = dl.getBoundingClientRect()) === null || _dl$getBoundingClient === void 0 ? void 0 : _dl$getBoundingClient.height);
|
|
236
|
+
var toTop = top - margin;
|
|
237
|
+
var toBottom = windowHeight - top - height - margin * 2;
|
|
238
|
+
var swHeight = toTop >= maxHeight || toBottom >= maxHeight ? maxHeight - 3 * margin : toTop > toBottom ? toTop - 3 * margin : toBottom - 4 * margin;
|
|
239
|
+
var listPos = toTop < toBottom || toBottom >= swHeight ? 'bottom' : 'top';
|
|
240
|
+
lc.style.minWidth = "".concat(width, "px");
|
|
241
|
+
lc.style.left = "".concat(left, "px");
|
|
242
|
+
lc.style.top = "".concat(listPos === 'bottom' ? top + height : top - swHeight - 3 * margin, "px");
|
|
243
|
+
dl.style.maxHeight = "".concat(swHeight - delta, "px");
|
|
229
244
|
};
|
|
230
245
|
|
|
231
246
|
var renderListContainer = function renderListContainer() {
|
|
@@ -234,6 +249,14 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
234
249
|
return /*#__PURE__*/(0, _reactDom.createPortal)(getListMarkUp(), lc);
|
|
235
250
|
};
|
|
236
251
|
|
|
252
|
+
var isTargetInParent = function isTargetInParent(target) {
|
|
253
|
+
var _target$className, _target$className$ind, _target$className2, _target$className2$in;
|
|
254
|
+
|
|
255
|
+
if ((target === null || target === void 0 ? void 0 : target.tagName) === 'svg' && (target === null || target === void 0 ? void 0 : target.parentNodclassName) === 'tag__button' || (target === null || target === void 0 ? void 0 : target.tagName) === 'line') return false;
|
|
256
|
+
if ((target === null || target === void 0 ? void 0 : target.tagName) === 'svg' && (target === null || target === void 0 ? void 0 : target.parentNodclassName) !== 'tag__button' || (target === null || target === void 0 ? void 0 : (_target$className = target.className) === null || _target$className === void 0 ? void 0 : (_target$className$ind = _target$className.indexOf) === null || _target$className$ind === void 0 ? void 0 : _target$className$ind.call(_target$className, 'tag__label')) !== -1 || (target === null || target === void 0 ? void 0 : (_target$className2 = target.className) === null || _target$className2 === void 0 ? void 0 : (_target$className2$in = _target$className2.indexOf) === null || _target$className2$in === void 0 ? void 0 : _target$className2$in.call(_target$className2, 'tag-list_wrapper')) !== -1 || (target === null || target === void 0 ? void 0 : target.className) === "".concat(RC, "__trigger") || (target === null || target === void 0 ? void 0 : target.className) === "tags-dropdown__arrow") return true;
|
|
257
|
+
return false;
|
|
258
|
+
};
|
|
259
|
+
|
|
237
260
|
var getListMarkUp = function getListMarkUp() {
|
|
238
261
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
239
262
|
className: "".concat(RC, "__selector-wrapper")
|
|
@@ -288,7 +311,7 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
288
311
|
return function () {
|
|
289
312
|
return document.removeEventListener('click', handleClickOutside, true);
|
|
290
313
|
};
|
|
291
|
-
});
|
|
314
|
+
}, []);
|
|
292
315
|
(0, _react.useEffect)(function () {
|
|
293
316
|
var _selectAllButtonRef$c, _unselectAllButtonRef;
|
|
294
317
|
|
|
@@ -303,11 +326,13 @@ var TagsDropdown = function TagsDropdown(_ref) {
|
|
|
303
326
|
className: (0, _classnames.default)("".concat(RC, "__trigger"), {
|
|
304
327
|
'tags-dropdown__error': error
|
|
305
328
|
}),
|
|
306
|
-
onClick: function onClick(
|
|
307
|
-
var
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
329
|
+
onClick: function onClick(_ref6) {
|
|
330
|
+
var target = _ref6.target;
|
|
331
|
+
if ((target === null || target === void 0 ? void 0 : target.tagName) === 'INPUT') setIsOpen(true);else if (isTargetInParent(target)) {
|
|
332
|
+
setIsOpen(function (isOpen) {
|
|
333
|
+
return !isOpen;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
311
336
|
}
|
|
312
337
|
}, noTagsWrap ? /*#__PURE__*/_react.default.createElement(_TagList.default, {
|
|
313
338
|
items: chosenOptions === null || chosenOptions === void 0 ? void 0 : chosenOptions.map(function (value, i) {
|