intelicoreact 1.4.40 → 1.4.42

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.
@@ -25,119 +25,186 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
25
25
 
26
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof 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; }
27
27
 
28
- const TagListToDropdown = _ref => {
28
+ const TagList = _ref => {
29
+ var _wrapperRef$current$g, _wrapperRef$current, _wrapperRef$current$g2;
30
+
29
31
  let {
30
- options,
31
- value = [],
32
- dropdownProps = {},
33
- listProps = {},
34
- onChange,
35
- useDropdownCompactMode
32
+ disabled,
33
+ className,
34
+ onTagClick,
35
+ removeItem = null,
36
+ items = [],
37
+ withToggle = true,
38
+ disableShowMore = false,
39
+ shownItemsCount = "auto",
40
+ testId = "test-taglist",
41
+ refProp,
42
+ renderOrder,
43
+ onEditClick,
44
+ onToggleRenderAll
36
45
  } = _ref;
37
- const preparedValue = value.map(_ref2 => {
38
- let {
39
- value
40
- } = _ref2;
41
- return value;
42
- });
43
- const [isEditMode, setIsEditMode] = (0, _react.useState)(false);
44
- const [isRenderAllTags, setIsRenderAllTags] = (0, _react.useState)(false);
45
- const [newValue, setNewValue] = (0, _react.useState)(preparedValue);
46
- const [isValueChanged, setIsValueChanged] = (0, _react.useState)(false);
47
- const [isLoading, setIsLoading] = (0, _react.useState)(false);
48
- const tagListRef = (0, _react.useRef)(null);
49
-
50
- const onConfirmChangesClick = () => {
51
- if (isValueChanged) {
52
- var _Promise;
53
-
54
- setIsLoading(true);
55
- setIsValueChanged(false);
56
- (_Promise = new Promise(r => {
57
- const onChangeResult = onChange(options.filter(_ref3 => {
58
- let {
59
- value
60
- } = _ref3;
61
- return newValue.includes(value);
62
- }));
63
-
64
- if (onChangeResult instanceof Promise) {
65
- onChangeResult.then(data => r(data));
66
- } else {
67
- r();
68
- }
69
- })) === null || _Promise === void 0 ? void 0 : _Promise.finally(() => {
70
- setIsEditMode(false);
71
- setIsLoading(false);
72
- });
73
- } else {
74
- setIsEditMode(false);
75
- }
46
+ const wrapperRef = (0, _react.useRef)(null);
47
+ const [tagList, setTagList] = (0, _react.useState)([]);
48
+ const [staticTagsCount, setStaticTagsCount] = (0, _react.useState)(-1);
49
+ const [renderItemsCount, setRenderItemsCount] = (0, _react.useState)(-1);
50
+ const [renderAll, setRenderAll] = (0, _react.useState)(!withToggle);
51
+ const wrapperWidth = (_wrapperRef$current$g = wrapperRef === null || wrapperRef === void 0 ? void 0 : (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : (_wrapperRef$current$g2 = _wrapperRef$current.getBoundingClientRect()) === null || _wrapperRef$current$g2 === void 0 ? void 0 : _wrapperRef$current$g2.width) !== null && _wrapperRef$current$g !== void 0 ? _wrapperRef$current$g : -1;
52
+
53
+ const setRenderAllInterceptor = v => {
54
+ setRenderAll(v);
55
+ onToggleRenderAll === null || onToggleRenderAll === void 0 ? void 0 : onToggleRenderAll(v);
76
56
  };
77
57
 
78
- (0, _react.useEffect)(() => {
79
- setNewValue(preparedValue); // eslint-disable-next-line react-hooks/exhaustive-deps
80
- }, [isEditMode]);
81
-
82
- const renderTagsDropdown = props => {
83
- return /*#__PURE__*/_react.default.createElement(TagsDropdown, (0, _extends2.default)({}, dropdownProps, {
84
- disabled: isLoading,
85
- options: options,
86
- chosenOptions: newValue,
87
- renderOptionsAsTags: true,
88
- withCreateLogic: true,
89
- isUseLocalOptionsStore: false,
90
- onOptionEdit: dropdownProps === null || dropdownProps === void 0 ? void 0 : dropdownProps.onOptionEdit,
91
- onOptionDelete: dropdownProps === null || dropdownProps === void 0 ? void 0 : dropdownProps.onOptionDelete,
92
- onOptionCreate: dropdownProps === null || dropdownProps === void 0 ? void 0 : dropdownProps.onOptionCreate,
93
- onActionConfirmClick: onConfirmChangesClick,
94
- onActionCancelClick: () => setIsEditMode(v => !v),
95
- onChange: data => {
96
- setNewValue(data);
97
- setIsValueChanged(true);
58
+ const getStaticTagsCount = () => {
59
+ var _window$getComputedSt;
60
+
61
+ if (typeof shownItemsCount === "number") return shownItemsCount;
62
+ const computedWidth = wrapperWidth || parseInt((_window$getComputedSt = window.getComputedStyle(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.width);
63
+ const delta = typeof onEditClick === "function" ? 60 : 32;
64
+ if (isNaN(computedWidth)) return -1;
65
+ const result = tagList.map(_ref2 => {
66
+ let {
67
+ itemRef
68
+ } = _ref2;
69
+ return itemRef;
70
+ }).reduce((result, itemRef) => {
71
+ const itemStyle = window.getComputedStyle(itemRef === null || itemRef === void 0 ? void 0 : itemRef.current);
72
+ const itemWidth = [parseInt(itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.width, 10), parseInt(itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.marginLeft, 10), parseInt(itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.marginRight, 10)].reduce((result, item) => {
73
+ if (!isNaN(item)) result += item;
74
+ return result;
75
+ }, 0);
76
+
77
+ if (!isNaN(itemWidth) && itemWidth > 0 && itemWidth + result.width < wrapperWidth - delta) {
78
+ result = {
79
+ count: result.count + 1,
80
+ width: result.width + itemWidth,
81
+ items: [...result.items, {
82
+ w: itemWidth,
83
+ r: itemRef === null || itemRef === void 0 ? void 0 : itemRef.current
84
+ }]
85
+ };
98
86
  }
99
- }, props, {
100
- isDefaultOpened: isEditMode
101
- }));
87
+
88
+ return result;
89
+ }, {
90
+ count: 0,
91
+ width: 0,
92
+ items: []
93
+ });
94
+ return result === null || result === void 0 ? void 0 : result.count;
102
95
  };
103
96
 
104
- const renderTagsList = props => {
105
- return /*#__PURE__*/_react.default.createElement(TagList, (0, _extends2.default)({
106
- disabled: isLoading,
107
- refProp: tagListRef
108
- }, listProps, {
109
- items: value,
110
- onEditClick: () => setIsEditMode(v => !v)
111
- }, props));
97
+ const cancelDefault = function (e) {
98
+ let cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
99
+ e === null || e === void 0 ? void 0 : e.preventDefault();
100
+ e === null || e === void 0 ? void 0 : e.stopPropagation();
101
+ cb(e);
112
102
  };
113
103
 
114
- const renderCompactMode = () => {
115
- return renderTagsDropdown({
116
- withActions: false,
117
- withSearchInputInList: true,
118
- customTriggerRef: tagListRef,
119
- recalculateListContainerStylesTrigger: isRenderAllTags,
120
- onDropdownListClose: onConfirmChangesClick,
121
- renderCustomTrigger: _ref4 => {
104
+ const renderTags = () => {
105
+ const tagsRenderOrder = renderOrder !== null && renderOrder !== void 0 ? renderOrder : tagList.map(_ref3 => {
106
+ let {
107
+ value,
108
+ id
109
+ } = _ref3;
110
+ return value !== null && value !== void 0 ? value : id;
111
+ });
112
+ return tagsRenderOrder.map((v, i) => {
113
+ var _item$id, _item$id2;
114
+
115
+ const item = tagList.find(_ref4 => {
122
116
  let {
123
- isOpen,
124
- setIsOpen,
125
- inputRef
117
+ value,
118
+ id
126
119
  } = _ref4;
127
- return renderTagsList({
128
- onToggleRenderAll: v => setTimeout(() => setIsRenderAllTags(v), 1),
129
- onEditClick: () => {
130
- setIsOpen(!isEditMode);
131
- if (isEditMode) onConfirmChangesClick();else setIsEditMode(true);
132
- }
133
- });
134
- }
120
+ return (value !== null && value !== void 0 ? value : id) === v;
121
+ });
122
+ if (!item) return null;
123
+ const isHidden = renderItemsCount !== -1 && staticTagsCount !== -1 ? i >= renderItemsCount : false;
124
+ return /*#__PURE__*/_react.default.createElement("div", {
125
+ className: "tag-list_wrapper_item ".concat(isHidden ? "tag-list_wrapper_item--hidden" : ""),
126
+ key: "tag-list-item-".concat((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.value),
127
+ ref: (0, _utils.checkedRef)(item === null || item === void 0 ? void 0 : item.itemRef)
128
+ }, /*#__PURE__*/_react.default.createElement(_Tag.default, (0, _extends2.default)({
129
+ testId: "test-taglist-item-".concat((_item$id2 = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id2 !== void 0 ? _item$id2 : item === null || item === void 0 ? void 0 : item.value)
130
+ }, item, {
131
+ onClick: onTagClick,
132
+ removeItem: removeItem
133
+ })));
134
+ });
135
+ };
136
+
137
+ const renderMoreTags = () => {
138
+ if ((tagList === null || tagList === void 0 ? void 0 : tagList.length) < shownItemsCount || !(tagList !== null && tagList !== void 0 && tagList.length) || disableShowMore) return null;
139
+ const restItems = tagList.length - renderItemsCount;
140
+ if (restItems === 0 || !withToggle || staticTagsCount === -1) return null;
141
+ return /*#__PURE__*/_react.default.createElement(_Tag.default, {
142
+ label: "+".concat(restItems),
143
+ className: "tag-list_wrapper_render-more",
144
+ onClick: disableShowMore ? () => {} : e => cancelDefault(e, () => setRenderAllInterceptor(true))
135
145
  });
136
146
  };
137
147
 
138
- return useDropdownCompactMode ? renderCompactMode() : isEditMode ? renderTagsDropdown({
139
- withActions: true
140
- }) : renderTagsList();
148
+ const renderHideTags = () => {
149
+ if (renderItemsCount !== (tagList === null || tagList === void 0 ? void 0 : tagList.length) || !withToggle || staticTagsCount === -1 || staticTagsCount === (tagList === null || tagList === void 0 ? void 0 : tagList.length)) return null;
150
+ return /*#__PURE__*/_react.default.createElement(_Tag.default, {
151
+ label: "...",
152
+ className: "tag-list_wrapper_hide-more",
153
+ onClick: e => cancelDefault(e, () => setRenderAllInterceptor(false))
154
+ });
155
+ }; // Set TagList Items
156
+
157
+
158
+ (0, _react.useEffect)(() => {
159
+ setStaticTagsCount(-1);
160
+ setRenderItemsCount(-1);
161
+ setRenderAllInterceptor(false);
162
+ setTagList(items.map(item => ({ ...item,
163
+ itemRef: /*#__PURE__*/(0, _react.createRef)()
164
+ })));
165
+ }, [items]); // Count Row Tags
166
+
167
+ (0, _react.useLayoutEffect)(() => {
168
+ if (withToggle && wrapperWidth !== -1 && staticTagsCount === -1) {
169
+ let computedWidth = wrapperWidth;
170
+
171
+ if (computedWidth === 0) {
172
+ var _window$getComputedSt2;
173
+
174
+ computedWidth = parseInt((_window$getComputedSt2 = window.getComputedStyle(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) === null || _window$getComputedSt2 === void 0 ? void 0 : _window$getComputedSt2.width);
175
+ }
176
+
177
+ if (!isNaN(computedWidth)) {
178
+ setStaticTagsCount(getStaticTagsCount());
179
+ }
180
+ }
181
+ }, [tagList, wrapperWidth, wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current]); //
182
+
183
+ (0, _react.useLayoutEffect)(() => {
184
+ setRenderItemsCount(staticTagsCount);
185
+ }, [staticTagsCount]); // Toggle Show/Hide More Tags
186
+
187
+ (0, _react.useEffect)(() => {
188
+ setRenderItemsCount(renderAll ? tagList === null || tagList === void 0 ? void 0 : tagList.length : staticTagsCount);
189
+ }, [renderAll]);
190
+ (0, _react.useEffect)(() => {
191
+ // eslint-disable-next-line react-hooks/exhaustive-deps
192
+ if (wrapperRef !== null && wrapperRef !== void 0 && wrapperRef.current && refProp) refProp.current = wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current;
193
+ }, [wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current]);
194
+ return /*#__PURE__*/_react.default.createElement("div", {
195
+ className: (0, _classnames.default)("tag-list_wrapper", "".concat(renderItemsCount !== (tagList === null || tagList === void 0 ? void 0 : tagList.length) || !withToggle || staticTagsCount === -1 || staticTagsCount === (tagList === null || tagList === void 0 ? void 0 : tagList.length) ? "tag-list_wrapper--only-static-items" : "tag-list_wrapper--all-items"), className, {
196
+ "tag-list_wrapper--disabled": disabled
197
+ }),
198
+ style: {
199
+ visibility: staticTagsCount === -1 ? "hidden" : "visible",
200
+ zIndex: staticTagsCount === -1 ? "-1" : "auto"
201
+ },
202
+ ref: wrapperRef
203
+ }, renderTags(), renderMoreTags(), renderHideTags(), typeof onEditClick === "function" && /*#__PURE__*/_react.default.createElement("div", {
204
+ className: "tag-list__edit-trigger"
205
+ }, /*#__PURE__*/_react.default.createElement(_reactFeather.Edit3, {
206
+ onClick: onEditClick
207
+ })));
141
208
  };
142
209
 
143
210
  var _default = TagList;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.4.40",
3
+ "version": "1.4.42",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [