@zohodesk/components 1.2.9 → 1.2.11

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.
Files changed (83) hide show
  1. package/.cli/PropLessFiles.html +1 -1
  2. package/.cli/PropValidationExcludeFilesArray.js +7 -10
  3. package/.cli/propValidation_report.html +1 -1
  4. package/README.md +14 -0
  5. package/coverage/Button/Button.js.html +1 -1
  6. package/coverage/Button/css/Button.module.css.html +1 -1
  7. package/coverage/Button/css/cssJSLogic.js.html +1 -1
  8. package/coverage/Button/css/index.html +1 -1
  9. package/coverage/Button/index.html +1 -1
  10. package/coverage/Button/props/defaultProps.js.html +1 -1
  11. package/coverage/Button/props/index.html +1 -1
  12. package/coverage/Button/props/propTypes.js.html +1 -1
  13. package/coverage/Buttongroup/Buttongroup.js.html +1 -1
  14. package/coverage/Buttongroup/Buttongroup.module.css.html +1 -1
  15. package/coverage/Buttongroup/index.html +1 -1
  16. package/coverage/Buttongroup/props/defaultProps.js.html +1 -1
  17. package/coverage/Buttongroup/props/index.html +1 -1
  18. package/coverage/Buttongroup/props/propTypes.js.html +1 -1
  19. package/coverage/coverage-final.json +10 -10
  20. package/coverage/coverage-summary.json +10 -10
  21. package/coverage/index.html +1 -1
  22. package/coverage/utils/dummyFunction.js.html +1 -1
  23. package/coverage/utils/index.html +1 -1
  24. package/es/DateTime/dateFormatUtils/dayChange.js +2 -1
  25. package/es/DateTime/dateFormatUtils/index.js +1 -1
  26. package/es/DateTime/dateFormatUtils/monthChange.js +2 -1
  27. package/es/DateTime/dateFormatUtils/timeChange.js +4 -4
  28. package/es/DateTime/dateFormatUtils/yearChange.js +2 -1
  29. package/es/MultiSelect/props/propTypes.js +140 -138
  30. package/es/Select/GroupSelect.js +2 -5
  31. package/es/Select/Select.js +2 -5
  32. package/es/Select/props/propTypes.js +3 -1
  33. package/es/utils/Common.js +3 -0
  34. package/es/v1/Accordion/Accordion.js +3 -2
  35. package/es/v1/AppContainer/AppContainer.js +75 -92
  36. package/es/v1/Avatar/Avatar.js +84 -134
  37. package/es/v1/Card/Card.js +143 -177
  38. package/es/v1/MultiSelect/MultiSelect.js +1 -0
  39. package/es/v1/MultiSelect/MultiSelectWithAvatar.js +1 -0
  40. package/es/v1/PopOver/PopOver.js +125 -160
  41. package/es/v1/Popup/Popup.js +1 -1
  42. package/es/v1/Provider/AvatarSize.js +13 -0
  43. package/es/v1/Provider/Config.js +18 -0
  44. package/es/v1/Provider/CssProvider.js +16 -0
  45. package/es/v1/Provider/IdProvider.js +66 -0
  46. package/es/v1/Provider/LibraryContext.js +37 -0
  47. package/es/v1/Provider/LibraryContextInit.js +3 -0
  48. package/es/v1/Provider/NumberGenerator/NumberGenerator.js +136 -0
  49. package/es/v1/Provider/ZindexProvider.js +57 -0
  50. package/es/v1/Provider/index.js +4 -0
  51. package/es/v1/Select/GroupSelect.js +2 -5
  52. package/es/v1/Select/Select.js +2 -5
  53. package/lib/DateTime/dateFormatUtils/dayChange.js +3 -1
  54. package/lib/DateTime/dateFormatUtils/index.js +1 -1
  55. package/lib/DateTime/dateFormatUtils/monthChange.js +3 -1
  56. package/lib/DateTime/dateFormatUtils/timeChange.js +3 -3
  57. package/lib/DateTime/dateFormatUtils/yearChange.js +3 -1
  58. package/lib/MultiSelect/props/propTypes.js +146 -141
  59. package/lib/Select/GroupSelect.js +1 -2
  60. package/lib/Select/Select.js +1 -2
  61. package/lib/Select/props/propTypes.js +12 -2
  62. package/lib/utils/Common.js +5 -0
  63. package/lib/v1/Accordion/Accordion.js +3 -1
  64. package/lib/v1/AppContainer/AppContainer.js +87 -138
  65. package/lib/v1/Avatar/Avatar.js +130 -186
  66. package/lib/v1/Card/Card.js +190 -286
  67. package/lib/v1/MultiSelect/MultiSelect.js +3 -1
  68. package/lib/v1/MultiSelect/MultiSelectWithAvatar.js +3 -1
  69. package/lib/v1/PopOver/PopOver.js +160 -256
  70. package/lib/v1/Popup/Popup.js +1 -1
  71. package/lib/v1/Provider/AvatarSize.js +24 -0
  72. package/lib/v1/Provider/Config.js +27 -0
  73. package/lib/v1/Provider/CssProvider.js +27 -0
  74. package/lib/v1/Provider/IdProvider.js +79 -0
  75. package/lib/v1/Provider/LibraryContext.js +76 -0
  76. package/lib/v1/Provider/LibraryContextInit.js +15 -0
  77. package/lib/v1/Provider/NumberGenerator/NumberGenerator.js +174 -0
  78. package/lib/v1/Provider/ZindexProvider.js +69 -0
  79. package/lib/v1/Provider/index.js +81 -0
  80. package/lib/v1/Select/GroupSelect.js +1 -2
  81. package/lib/v1/Select/Select.js +1 -2
  82. package/package.json +4 -4
  83. package/result.json +1 -1
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import React, { useRef } from 'react';
2
+ import { useEffectCallOnlyAfterState } from '@zohodesk/hooks';
2
3
  import { PopOver_defaultProps, PopOverContainer_defaultProps } from '../../PopOver/props/defaultProps';
3
4
  import { PopOver_propTypes, PopOverTarget_propTypes, PopOverContainer_propTypes } from '../../PopOver/props/propTypes';
4
5
  import Popup from '../Popup/Popup';
@@ -6,55 +7,60 @@ import { Box } from '../Layout';
6
7
  import ResponsiveDropBox from '../ResponsiveDropBox/ResponsiveDropBox';
7
8
  import style from '../../PopOver/PopOver.module.css';
8
9
 
9
- class PopOver extends React.Component {
10
- constructor(props) {
11
- super(props);
12
- this.popOverTargetRef = this.popOverTargetRef.bind(this);
13
- this.popOverContainerRef = this.popOverContainerRef.bind(this);
14
- this.togglePopup = this.togglePopup.bind(this);
15
- }
16
-
17
- componentDidUpdate(prevProps) {
18
- let {
19
- isPopupOpen,
20
- onPopupOpen,
21
- onPopupClose
22
- } = this.props;
23
-
24
- if (prevProps.isPopupOpen !== isPopupOpen) {
25
- isPopupOpen && onPopupOpen && onPopupOpen();
26
- !isPopupOpen && onPopupClose && onPopupClose();
27
- }
28
- }
29
-
30
- popOverTargetRef(el) {
31
- this.popOverTarget = el;
32
- let {
33
- getTargetRef
34
- } = this.props;
10
+ function PopOver(props) {
11
+ let {
12
+ children,
13
+ isPopupOpen,
14
+ removeClose,
15
+ right,
16
+ left,
17
+ top,
18
+ bottom,
19
+ arrowRight,
20
+ arrowLeft,
21
+ arrowTop,
22
+ arrowBottom,
23
+ isAnimate,
24
+ isArrow,
25
+ arrowPosition,
26
+ position,
27
+ size,
28
+ onClick,
29
+ isPopupReady,
30
+ getTargetRef,
31
+ getContainerRef,
32
+ boxPosition,
33
+ onPopupOpen,
34
+ onPopupClose
35
+ } = props;
36
+ const popOverTarget = useRef(null);
37
+ const popOverContainer = useRef(null);
38
+
39
+ const popOverTargetRef = el => {
40
+ popOverTarget.current = el;
35
41
  getTargetRef(el);
36
- }
42
+ };
37
43
 
38
- popOverContainerRef(el) {
39
- this.popOverContainer = el;
40
- let {
41
- getContainerRef
42
- } = this.props;
44
+ const popOverContainerRef = el => {
45
+ popOverContainer.current = el;
43
46
  getContainerRef(el);
44
- }
47
+ };
45
48
 
46
- togglePopup(e) {
49
+ const togglePopup = e => {
47
50
  let {
48
- togglePopup,
49
- boxPosition
50
- } = this.props;
51
+ togglePopup
52
+ } = props;
51
53
  togglePopup(e, boxPosition);
52
- }
53
-
54
- render() {
55
- let {
56
- children,
54
+ };
55
+
56
+ useEffectCallOnlyAfterState(() => {
57
+ isPopupOpen && onPopupOpen && onPopupOpen();
58
+ !isPopupOpen && onPopupClose && onPopupClose();
59
+ }, [isPopupOpen]);
60
+ let childrens = React.Children.map(children, (child, index) => {
61
+ let element = index === 1 ? /*#__PURE__*/React.cloneElement(child, {
57
62
  isPopupOpen,
63
+ togglePopup: togglePopup,
58
64
  removeClose,
59
65
  right,
60
66
  left,
@@ -64,148 +70,107 @@ class PopOver extends React.Component {
64
70
  arrowLeft,
65
71
  arrowTop,
66
72
  arrowBottom,
73
+ boxPosition: position,
67
74
  isAnimate,
68
75
  isArrow,
69
76
  arrowPosition,
70
- position,
71
77
  size,
72
78
  onClick,
79
+ getRef: popOverContainerRef,
73
80
  isPopupReady
74
- } = this.props;
75
- let childrens = React.Children.map(children, (child, index) => {
76
- let element = index === 1 ? /*#__PURE__*/React.cloneElement(child, {
77
- isPopupOpen,
78
- togglePopup: this.togglePopup,
79
- removeClose,
80
- right,
81
- left,
82
- top,
83
- bottom,
84
- arrowRight,
85
- arrowLeft,
86
- arrowTop,
87
- arrowBottom,
88
- boxPosition: position,
89
- isAnimate,
90
- isArrow,
91
- arrowPosition,
92
- size,
93
- onClick,
94
- getRef: this.popOverContainerRef,
95
- isPopupReady
96
- }) : /*#__PURE__*/React.cloneElement(child, {
97
- isPopupOpen,
98
- togglePopup: this.togglePopup,
99
- removeClose,
100
- getRef: this.popOverTargetRef
101
- });
102
- return element;
81
+ }) : /*#__PURE__*/React.cloneElement(child, {
82
+ isPopupOpen,
83
+ togglePopup: togglePopup,
84
+ removeClose,
85
+ getRef: popOverTargetRef
103
86
  });
104
- return /*#__PURE__*/React.createElement("div", {
105
- className: style.popup
106
- }, childrens);
107
- }
108
-
87
+ return element;
88
+ });
89
+ return /*#__PURE__*/React.createElement("div", {
90
+ className: style.popup
91
+ }, childrens);
109
92
  }
110
93
 
111
94
  PopOver.defaultProps = PopOver_defaultProps;
112
95
  PopOver.propTypes = PopOver_propTypes;
113
96
  export default Popup(PopOver);
114
- export class PopOverTarget extends React.Component {
115
- constructor(props) {
116
- super(props);
117
- this.getRef = this.getRef.bind(this);
118
- }
97
+ export function PopOverTarget(props) {
98
+ let {
99
+ children,
100
+ togglePopup
101
+ } = props;
119
102
 
120
- getRef(el) {
103
+ const getRef = el => {
121
104
  let {
122
105
  getRef
123
- } = this.props;
106
+ } = props;
124
107
  getRef(el);
125
- }
126
-
127
- render() {
128
- let {
129
- children,
130
- togglePopup
131
- } = this.props;
132
- return /*#__PURE__*/React.createElement("div", {
133
- className: style.target,
134
- onClick: togglePopup,
135
- ref: this.getRef
136
- }, children);
137
- }
108
+ };
138
109
 
110
+ return /*#__PURE__*/React.createElement("div", {
111
+ className: style.target,
112
+ onClick: togglePopup,
113
+ ref: getRef
114
+ }, children);
139
115
  }
140
116
  PopOverTarget.propTypes = PopOverTarget_propTypes;
141
- export class PopOverContainer extends React.Component {
142
- constructor(props) {
143
- super(props);
144
- this.handleClick = this.handleClick.bind(this);
145
- this.getRef = this.getRef.bind(this);
146
- }
147
-
148
- getRef(el) {
117
+ export function PopOverContainer(props) {
118
+ let {
119
+ children,
120
+ isPopupOpen,
121
+ isAnimate,
122
+ isArrow,
123
+ size,
124
+ arrowPosition,
125
+ boxPosition,
126
+ right,
127
+ left,
128
+ top,
129
+ bottom,
130
+ arrowRight,
131
+ arrowLeft,
132
+ arrowTop,
133
+ arrowBottom,
134
+ animationStyle,
135
+ onClick,
136
+ removeClose
137
+ } = props;
138
+
139
+ const getRef = el => {
149
140
  let {
150
141
  getRef
151
- } = this.props;
142
+ } = props;
152
143
  getRef && getRef(el);
153
- }
144
+ };
154
145
 
155
- handleClick(e) {
156
- let {
157
- onClick,
158
- removeClose
159
- } = this.props;
146
+ const handleClick = e => {
160
147
  removeClose && removeClose(e);
161
148
  onClick && onClick();
162
- }
163
-
164
- render() {
165
- let {
166
- children,
167
- isPopupOpen,
168
- isAnimate,
169
- isArrow,
170
- size,
171
- arrowPosition,
172
- boxPosition,
173
- right,
174
- left,
175
- top,
176
- bottom,
177
- arrowRight,
178
- arrowLeft,
179
- arrowTop,
180
- arrowBottom,
181
- animationStyle,
182
- getRef
183
- } = this.props;
184
- return /*#__PURE__*/React.createElement(ResponsiveDropBox, {
185
- animationStyle: animationStyle,
186
- arrowBottom: arrowBottom,
187
- arrowLeft: arrowLeft,
188
- arrowPosition: arrowPosition,
189
- arrowRight: arrowRight,
190
- arrowTop: arrowTop,
191
- bottom: bottom,
192
- boxPosition: boxPosition,
193
- getRef: getRef,
194
- isActive: isPopupOpen,
195
- isAnimate: isAnimate,
196
- isArrow: isArrow,
197
- left: left,
198
- right: right,
199
- size: size,
200
- top: top,
201
- alignBox: "row"
202
- }, /*#__PURE__*/React.createElement(Box, {
203
- flexible: true,
204
- shrink: true,
205
- scroll: "vertical"
206
- }, children));
207
- }
208
-
149
+ };
150
+
151
+ return /*#__PURE__*/React.createElement(ResponsiveDropBox, {
152
+ animationStyle: animationStyle,
153
+ arrowBottom: arrowBottom,
154
+ arrowLeft: arrowLeft,
155
+ arrowPosition: arrowPosition,
156
+ arrowRight: arrowRight,
157
+ arrowTop: arrowTop,
158
+ bottom: bottom,
159
+ boxPosition: boxPosition,
160
+ getRef: getRef,
161
+ isActive: isPopupOpen,
162
+ isAnimate: isAnimate,
163
+ isArrow: isArrow,
164
+ left: left,
165
+ right: right,
166
+ size: size,
167
+ top: top,
168
+ alignBox: "row"
169
+ }, /*#__PURE__*/React.createElement(Box, {
170
+ flexible: true,
171
+ shrink: true,
172
+ scroll: "vertical"
173
+ }, children));
209
174
  }
210
175
  PopOverContainer.defaultProps = PopOverContainer_defaultProps;
211
176
  PopOverContainer.propTypes = PopOverContainer_propTypes;
@@ -7,7 +7,7 @@ import hoistStatics from 'hoist-non-react-statics';
7
7
  /**** Methods ****/
8
8
 
9
9
  import { debounce, isDescendant, isTextSelected, cancelBubblingEffect } from '../../utils/Common.js';
10
- import viewPort from './viewPort';
10
+ import viewPort from '../../Popup/viewPort';
11
11
  import { absolutePositionMapping, rtlAbsolutePositionMapping, rtlFixedPositionMapping } from '../../Popup/PositionMapping.json';
12
12
  import ResizeObserver from '@zohodesk/virtualizer/lib/commons/ResizeObserver.js';
13
13
  let lastOpenedGroup = [];
@@ -0,0 +1,13 @@
1
+ import style from '../../common/avatarsizes.module.css';
2
+ let styleList = {
3
+ small: style.small,
4
+ xsmall: style.xsmall,
5
+ xxsmall: style.xxsmall,
6
+ medium: style.medium,
7
+ xmedium: style.xmedium,
8
+ large: style.large,
9
+ xlarge: style.xlarge
10
+ };
11
+ export default function CssProvider(name) {
12
+ return styleList[name] || '';
13
+ }
@@ -0,0 +1,18 @@
1
+ let id = {
2
+ mobileWidth: 640,
3
+ zindexCounter: 3,
4
+ idCounter: 0,
5
+ idPrefix: 'ZD',
6
+ scrollFetchLimit: 80,
7
+ isReducedMotion: false,
8
+ direction: 'ltr',
9
+ tooltipDebounce: 175,
10
+ getTooltipContainer: () => {},
11
+ autoComplete: false
12
+ };
13
+ export function getLibraryConfig(key) {
14
+ return id[key];
15
+ }
16
+ export function setLibraryConfig(configObj) {
17
+ id = Object.assign({}, id, configObj);
18
+ }
@@ -0,0 +1,16 @@
1
+ import style from '../common/common.module.css';
2
+ let styleList = {
3
+ hide: style.hide,
4
+ isDisabled: style.disabled,
5
+ isDisable: style.disable,
6
+ isBlock: style.blockEvent,
7
+ isFlexible: style.flexgrow,
8
+ dotted: style.dotted,
9
+ vMiddle: style.yMiddle,
10
+ hMiddle: style.xMiddle,
11
+ smooth: style.ftsmooth,
12
+ clamp: style.clamp
13
+ };
14
+ export default function CssProvider(name) {
15
+ return styleList[name] || '';
16
+ }
@@ -0,0 +1,66 @@
1
+ import { useNumberGenerator, getNumberGenerators } from './NumberGenerator/NumberGenerator';
2
+ import { getLibraryConfig } from './Config';
3
+ let globalId = getLibraryConfig('idCounter'),
4
+ deletedIndexes = [],
5
+ globalPrefix;
6
+ export function setGlobalIdPrefix(value) {
7
+ globalPrefix = value;
8
+ }
9
+ export function removeGlobalIdPrefix() {
10
+ globalPrefix = undefined;
11
+ }
12
+
13
+ function getGlobalIdPrefix() {
14
+ return globalPrefix;
15
+ }
16
+
17
+ function setGlobalId(id) {
18
+ globalId = id;
19
+ }
20
+
21
+ function getGlobalId() {
22
+ return globalId;
23
+ }
24
+
25
+ function setDeletedIndexes(array) {
26
+ deletedIndexes = array;
27
+ }
28
+
29
+ function getDeletedIndexes() {
30
+ return deletedIndexes;
31
+ }
32
+
33
+ function callback(_ref) {
34
+ let {
35
+ globalId,
36
+ deletedIndexes
37
+ } = _ref;
38
+ setGlobalId(globalId);
39
+ setDeletedIndexes(deletedIndexes);
40
+ }
41
+
42
+ export function useUniqueId(prefix) {
43
+ return useNumberGenerator({
44
+ getGlobalId,
45
+ prefix,
46
+ getGlobalPrefix: getGlobalIdPrefix,
47
+ getDeletedIndexes,
48
+ callback
49
+ });
50
+ }
51
+ export function getUniqueId(Component, prefix) {
52
+ return getNumberGenerators({
53
+ Component,
54
+ prefix,
55
+ getGlobalPrefix: getGlobalIdPrefix,
56
+ getGlobalId,
57
+ getDeletedIndexes,
58
+ callback
59
+ });
60
+ } // let Provider = {
61
+ // docs: {
62
+ // componentGroup: 'Provider',
63
+ // folderName: 'Functions'
64
+ // }
65
+ // };
66
+ // export { Provider };
@@ -0,0 +1,37 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import LibraryContextInit from './LibraryContextInit';
4
+ import { getLibraryConfig } from './Config';
5
+
6
+ const LibraryContextProvider = _ref => {
7
+ let {
8
+ isReducedMotion = getLibraryConfig('isReducedMotion'),
9
+ direction = getLibraryConfig('direction'),
10
+ children
11
+ } = _ref;
12
+ const [value, setValue] = useState({
13
+ isReducedMotion,
14
+ direction
15
+ });
16
+
17
+ function setGlobalContext(key, data) {
18
+ if (value[key] != data) {
19
+ setValue({ ...value,
20
+ [key]: data
21
+ });
22
+ }
23
+ }
24
+
25
+ return /*#__PURE__*/React.createElement(LibraryContextInit.Provider, {
26
+ value: { ...value,
27
+ setGlobalContext
28
+ }
29
+ }, children);
30
+ };
31
+
32
+ LibraryContextProvider.propTypes = {
33
+ children: PropTypes.node.isRequired,
34
+ isReducedMotion: PropTypes.bool,
35
+ direction: PropTypes.string
36
+ };
37
+ export default LibraryContextProvider;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ const LibraryContext = /*#__PURE__*/React.createContext();
3
+ export default LibraryContext;
@@ -0,0 +1,136 @@
1
+ import React, { useRef, useEffect } from 'react';
2
+ export function addGlobalId(globalId) {
3
+ if (Number.isSafeInteger(Number(globalId)) && Number.isSafeInteger(Number(globalId) + 1)) {
4
+ globalId = Number(globalId) + 1;
5
+ } else {
6
+ globalId = `${globalId}1`;
7
+ }
8
+
9
+ return globalId;
10
+ }
11
+
12
+ function decreaseGlobalId(number, globalId) {
13
+ if (`${number}` == `${globalId}`) {
14
+ if (Number.isSafeInteger(Number(globalId)) && Number.isSafeInteger(Number(globalId) - 1)) {
15
+ globalId = Number(globalId) - 1;
16
+ } else {
17
+ globalId = `${globalId}`;
18
+ globalId = globalId.substring(0, globalId.length - 1);
19
+ }
20
+
21
+ return {
22
+ isDeleted: true,
23
+ globalId
24
+ };
25
+ }
26
+
27
+ return {
28
+ isDeleted: false,
29
+ globalId
30
+ };
31
+ }
32
+
33
+ export function decreaseGlobalIds(numbers, deletedIndexes, globalId) {
34
+ deletedIndexes = [...deletedIndexes];
35
+ [...numbers].reverse().map(number => {
36
+ let result = decreaseGlobalId(number, globalId);
37
+ globalId = result.globalId;
38
+ !result.isDeleted && deletedIndexes.push(number);
39
+ });
40
+
41
+ for (; deletedIndexes.indexOf(globalId) != -1;) {
42
+ let presentHighValue = globalId;
43
+ let result = decreaseGlobalId(globalId, globalId);
44
+ globalId = result.globalId;
45
+ deletedIndexes = deletedIndexes.filter(ele => `${ele}` != `${presentHighValue}`);
46
+ }
47
+
48
+ return {
49
+ globalId,
50
+ deletedIndexes
51
+ };
52
+ }
53
+ export function useNumberGenerator(_ref) {
54
+ let {
55
+ getGlobalId,
56
+ prefix,
57
+ getGlobalPrefix,
58
+ getDeletedIndexes,
59
+ callback
60
+ } = _ref;
61
+ let presentValues = useRef([]),
62
+ presentIndex = useRef(0);
63
+ prefix = typeof prefix === 'undefined' ? '' : `${prefix}_`;
64
+ let globalPrefix = typeof getGlobalPrefix() === 'undefined' ? '' : `${getGlobalPrefix()}_`;
65
+
66
+ function getNextId() {
67
+ presentIndex.current = presentIndex.current + 1;
68
+ let currentIndex = presentIndex.current;
69
+ let isValuePresent = typeof presentValues.current[currentIndex] !== 'undefined';
70
+ let result = isValuePresent ? presentValues.current[currentIndex] : presentValues.current[currentIndex] = addGlobalId(getGlobalId());
71
+ !isValuePresent && callback({
72
+ globalId: result,
73
+ deletedIndexes: getDeletedIndexes()
74
+ });
75
+ return `${globalPrefix}${prefix}${presentValues.current[currentIndex]}`;
76
+ }
77
+
78
+ useEffect(() => {
79
+ presentValues.current = presentValues.current.filter((value, index) => index <= presentIndex.current);
80
+ });
81
+ useEffect(() => () => {
82
+ callback(decreaseGlobalIds(presentValues.current, getDeletedIndexes(), getGlobalId()));
83
+ }, []);
84
+ presentIndex.current = -1;
85
+ return getNextId;
86
+ }
87
+ export function getNumberGenerators(_ref2) {
88
+ let {
89
+ Component,
90
+ prefix,
91
+ getGlobalPrefix,
92
+ getGlobalId,
93
+ getDeletedIndexes,
94
+ callback
95
+ } = _ref2;
96
+ let presentIndex = 0,
97
+ presentValues = [],
98
+ {
99
+ name
100
+ } = Component.props;
101
+ let didUpdateRef = Component.componentDidUpdate ? Component.componentDidUpdate.bind(Component) : undefined,
102
+ renderRef = Component.render.bind(Component),
103
+ willUnMountRef = Component.componentWillUnmount ? Component.componentWillUnmount.bind(Component) : undefined;
104
+ prefix = typeof prefix !== 'undefined' ? `${prefix}_` : '';
105
+
106
+ Component.componentDidUpdate = function () {
107
+ didUpdateRef && didUpdateRef(...arguments);
108
+ presentValues = presentValues.filter((value, index) => index <= presentIndex);
109
+ };
110
+
111
+ Component.componentWillUnmount = function () {
112
+ callback(decreaseGlobalIds(presentValues, getDeletedIndexes(), getGlobalId()));
113
+ willUnMountRef && willUnMountRef();
114
+ didUpdateRef = null, renderRef = null, willUnMountRef = null;
115
+ };
116
+
117
+ Component.render = function () {
118
+ presentIndex = -1;
119
+ return renderRef();
120
+ };
121
+
122
+ function getNextId() {
123
+ presentIndex += 1;
124
+ let isValuePresent = typeof presentValues[presentIndex] !== 'undefined';
125
+ let result = isValuePresent ? presentValues[presentIndex] : presentValues[presentIndex] = addGlobalId(getGlobalId(getGlobalId()));
126
+ let globalPrefix = getGlobalPrefix();
127
+ globalPrefix = typeof globalPrefix === 'undefined' ? '' : `${globalPrefix}_`;
128
+ !isValuePresent && callback({
129
+ globalId: result,
130
+ deletedIndexes: getDeletedIndexes()
131
+ });
132
+ return `${globalPrefix}${prefix}${result}`;
133
+ }
134
+
135
+ return getNextId;
136
+ }
@@ -0,0 +1,57 @@
1
+ import { useNumberGenerator, getNumberGenerators } from './NumberGenerator/NumberGenerator';
2
+ import { getLibraryConfig } from './Config';
3
+ let globalId = getLibraryConfig('zindexCounter'),
4
+ deletedIndexes = [],
5
+ globalPrefix;
6
+ export function removeGlobalZIndexPrefix() {
7
+ globalPrefix = undefined;
8
+ }
9
+
10
+ function getGlobalZIndexPrefix() {
11
+ return globalPrefix;
12
+ }
13
+
14
+ export function setInitialZIndex(id) {
15
+ globalId = id;
16
+ }
17
+
18
+ function getGlobalId() {
19
+ return globalId;
20
+ }
21
+
22
+ function setDeletedIndexes(array) {
23
+ deletedIndexes = array;
24
+ }
25
+
26
+ function getDeletedIndexes() {
27
+ return deletedIndexes;
28
+ }
29
+
30
+ function callback(_ref) {
31
+ let {
32
+ globalId,
33
+ deletedIndexes
34
+ } = _ref;
35
+ setInitialZIndex(globalId);
36
+ setDeletedIndexes(deletedIndexes);
37
+ }
38
+
39
+ export function useZIndex(prefix) {
40
+ return useNumberGenerator({
41
+ getGlobalId,
42
+ prefix,
43
+ getGlobalPrefix: getGlobalZIndexPrefix,
44
+ getDeletedIndexes,
45
+ callback
46
+ });
47
+ }
48
+ export function getZIndex(Component, prefix) {
49
+ return getNumberGenerators({
50
+ Component,
51
+ prefix,
52
+ getGlobalPrefix: getGlobalZIndexPrefix,
53
+ getGlobalId,
54
+ getDeletedIndexes,
55
+ callback
56
+ });
57
+ }