@zohodesk/components 1.0.0-temp-229.1 → 1.0.0-temp-220.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.
- package/.cli/propValidation_report.html +1 -1
- package/README.md +35 -0
- package/assets/Appearance/dark/mode/Component_DarkMode.module.css +15 -11
- package/assets/Appearance/dark/themes/blue/blue_ComponentTheme_DarkTheme.module.css +5 -0
- package/assets/Appearance/dark/themes/green/green_ComponentTheme_DarkTheme.module.css +5 -0
- package/assets/Appearance/dark/themes/orange/orange_ComponentTheme_DarkTheme.module.css +5 -0
- package/assets/Appearance/dark/themes/red/red_ComponentTheme_DarkTheme.module.css +5 -0
- package/assets/Appearance/dark/themes/yellow/yellow_ComponentTheme_DarkTheme.module.css +5 -0
- package/assets/Appearance/light/mode/Component_LightMode.module.css +13 -9
- package/assets/Appearance/light/themes/blue/blue_ComponentTheme_LightTheme.module.css +5 -0
- package/assets/Appearance/light/themes/green/green_ComponentTheme_LightTheme.module.css +5 -0
- package/assets/Appearance/light/themes/orange/orange_ComponentTheme_LightTheme.module.css +5 -0
- package/assets/Appearance/light/themes/red/red_ComponentTheme_LightTheme.module.css +5 -0
- package/assets/Appearance/light/themes/yellow/yellow_ComponentTheme_LightTheme.module.css +5 -0
- package/assets/Appearance/pureDark/mode/Component_PureDarkMode.module.css +15 -11
- package/assets/Appearance/pureDark/themes/blue/blue_ComponentTheme_PureDarkTheme.module.css +5 -0
- package/assets/Appearance/pureDark/themes/green/green_ComponentTheme_PureDarkTheme.module.css +5 -0
- package/assets/Appearance/pureDark/themes/orange/orange_ComponentTheme_PureDarkTheme.module.css +5 -0
- package/assets/Appearance/pureDark/themes/red/red_ComponentTheme_PureDarkTheme.module.css +5 -0
- package/assets/Appearance/pureDark/themes/yellow/yellow_ComponentTheme_PureDarkTheme.module.css +5 -0
- package/es/Button/Button.js +14 -7
- package/es/Button/css/Button.module.css +54 -16
- package/es/Button/css/cssJSLogic.js +6 -1
- package/es/Button/props/propTypes.js +1 -0
- package/es/Card/Card.js +10 -39
- package/es/Card/props/defaultProps.js +1 -2
- package/es/Card/props/propTypes.js +1 -2
- package/es/DropBox/DropBox.js +3 -3
- package/es/ListItem/ListItem.js +11 -2
- package/es/ListItem/ListItem.module.css +9 -0
- package/es/ListItem/__tests__/__snapshots__/ListItem.spec.js.snap +15 -1
- package/es/ListItem/props/propTypes.js +2 -1
- package/es/Modal/Modal.js +35 -14
- package/es/Modal/Portal/Portal.js +33 -0
- package/es/Modal/Portal/__tests__/Portal.spec.js +28 -0
- package/es/Modal/Portal/__tests__/__snapshots__/Portal.spec.js.snap +30 -0
- package/es/Modal/Portal/props/defaultProps.js +3 -0
- package/es/Modal/Portal/props/propTypes.js +5 -0
- package/es/MultiSelect/__tests__/__snapshots__/AdvancedMultiSelect.spec.js.snap +80 -10
- package/es/Popup/Popup.js +239 -107
- package/es/Popup/Registry.js +36 -0
- package/es/Popup/viewPort.js +15 -16
- package/es/Provider/Config.js +4 -1
- package/es/Provider/LibraryContext.js +7 -3
- package/es/RippleEffect/RippleEffect.module.css +3 -2
- package/es/Select/__tests__/__snapshots__/Select.spec.js.snap +512 -64
- package/es/v1/Button/props/propTypes.js +2 -1
- package/es/v1/Switch/useSwitch.js +1 -1
- package/lib/Button/Button.js +12 -5
- package/lib/Button/css/Button.module.css +54 -16
- package/lib/Button/css/cssJSLogic.js +6 -2
- package/lib/Button/props/propTypes.js +1 -0
- package/lib/Card/Card.js +25 -54
- package/lib/Card/props/defaultProps.js +1 -2
- package/lib/Card/props/propTypes.js +1 -2
- package/lib/DropBox/DropBox.js +3 -3
- package/lib/ListItem/ListItem.js +12 -3
- package/lib/ListItem/ListItem.module.css +9 -0
- package/lib/ListItem/__tests__/__snapshots__/ListItem.spec.js.snap +15 -1
- package/lib/ListItem/props/propTypes.js +2 -1
- package/lib/Modal/Modal.js +40 -16
- package/lib/Modal/Portal/Portal.js +46 -0
- package/lib/Modal/Portal/__tests__/Portal.spec.js +37 -0
- package/lib/Modal/Portal/__tests__/__snapshots__/Portal.spec.js.snap +30 -0
- package/lib/Modal/Portal/props/defaultProps.js +10 -0
- package/lib/Modal/Portal/props/propTypes.js +16 -0
- package/lib/MultiSelect/__tests__/__snapshots__/AdvancedMultiSelect.spec.js.snap +80 -10
- package/lib/Popup/Popup.js +316 -162
- package/lib/Popup/Registry.js +46 -0
- package/lib/Popup/viewPort.js +15 -16
- package/lib/Provider/Config.js +4 -1
- package/lib/Provider/LibraryContext.js +7 -3
- package/lib/RippleEffect/RippleEffect.module.css +3 -2
- package/lib/Select/__tests__/__snapshots__/Select.spec.js.snap +512 -64
- package/lib/v1/Button/props/propTypes.js +2 -1
- package/lib/v1/Switch/useSwitch.js +1 -1
- package/package.json +12 -12
- package/result.json +1 -1
package/es/Popup/Popup.js
CHANGED
|
@@ -12,11 +12,10 @@ import { addIntersectionObserver, removeIntersectionObserver } from "./intersect
|
|
|
12
12
|
import { positionMapping } from "../DropBox/DropBoxPositionMapping.js";
|
|
13
13
|
import isMobilePopover from "../DropBox/utils/isMobilePopover.js";
|
|
14
14
|
import selectn from 'selectn';
|
|
15
|
-
|
|
16
|
-
let popups = {};
|
|
15
|
+
import Registry from "./Registry.js";
|
|
17
16
|
|
|
18
17
|
global.closeGroupPopups = function (groupName) {
|
|
19
|
-
const groupPopups = popups[groupName] || [];
|
|
18
|
+
const groupPopups = Registry.popups[groupName] || [];
|
|
20
19
|
groupPopups.forEach(popup => {
|
|
21
20
|
popup.state.isPopupOpen && popup.setState({
|
|
22
21
|
isPopupOpen: false,
|
|
@@ -38,6 +37,51 @@ const defaultState = {
|
|
|
38
37
|
//{height: ‘’, width: ‘’,}
|
|
39
38
|
isAbsolutePositioningNeeded: true
|
|
40
39
|
};
|
|
40
|
+
const SCROLL_BLOCK_EVENTS = Object.freeze([{
|
|
41
|
+
name: 'wheel',
|
|
42
|
+
handlerName: 'handleBlockScroll',
|
|
43
|
+
options: {
|
|
44
|
+
capture: true,
|
|
45
|
+
passive: false
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
name: 'touchmove',
|
|
49
|
+
handlerName: 'handleBlockScroll',
|
|
50
|
+
options: {
|
|
51
|
+
capture: true,
|
|
52
|
+
passive: false
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
name: 'scroll',
|
|
56
|
+
handlerName: 'handlePositionChange',
|
|
57
|
+
options: {
|
|
58
|
+
capture: true,
|
|
59
|
+
passive: false
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
name: 'keydown',
|
|
63
|
+
handlerName: 'preventKeyboardScroll',
|
|
64
|
+
options: {
|
|
65
|
+
capture: true,
|
|
66
|
+
passive: false
|
|
67
|
+
}
|
|
68
|
+
}]);
|
|
69
|
+
const IFRAME_SCROLL_BLOCK_EVENTS = Object.freeze(SCROLL_BLOCK_EVENTS.filter(event => event.name !== 'keydown'));
|
|
70
|
+
const CLICK_EVENTS = Object.freeze([{
|
|
71
|
+
name: 'click',
|
|
72
|
+
handlerName: 'documentClickHandler',
|
|
73
|
+
options: {
|
|
74
|
+
capture: false,
|
|
75
|
+
passive: false
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
name: 'click',
|
|
79
|
+
handlerName: 'documentClickHandler1',
|
|
80
|
+
options: {
|
|
81
|
+
capture: true,
|
|
82
|
+
passive: false
|
|
83
|
+
}
|
|
84
|
+
}]);
|
|
41
85
|
/* eslint-disable react/no-deprecated */
|
|
42
86
|
|
|
43
87
|
/* eslint-disable react/prop-types */
|
|
@@ -99,8 +143,11 @@ const Popup = function (Component) {
|
|
|
99
143
|
this.handleBlockScroll = this.handleBlockScroll.bind(this);
|
|
100
144
|
this.handlePositionChange = this.handlePositionChange.bind(this);
|
|
101
145
|
this.preventKeyboardScroll = this.preventKeyboardScroll.bind(this);
|
|
146
|
+
this.updateListeners = this.updateListeners.bind(this);
|
|
102
147
|
this.addScrollBlockListeners = this.addScrollBlockListeners.bind(this);
|
|
103
148
|
this.removeScrollBlockListeners = this.removeScrollBlockListeners.bind(this);
|
|
149
|
+
this.addScrollToUpdateListeners = this.addScrollToUpdateListeners.bind(this);
|
|
150
|
+
this.removeScrollToUpdateListeners = this.removeScrollToUpdateListeners.bind(this);
|
|
104
151
|
this.handleAddingScrollBlock = this.handleAddingScrollBlock.bind(this);
|
|
105
152
|
this.handleRemovingScrollBlock = this.handleRemovingScrollBlock.bind(this);
|
|
106
153
|
this.handleIntersectionObserver = this.handleIntersectionObserver.bind(this);
|
|
@@ -110,9 +157,15 @@ const Popup = function (Component) {
|
|
|
110
157
|
this.setContainerDynamicPositioning = this.setContainerDynamicPositioning.bind(this);
|
|
111
158
|
this.updatePopupState = this.updatePopupState.bind(this);
|
|
112
159
|
this.handleScrollAndBlockEvents = this.handleScrollAndBlockEvents.bind(this);
|
|
160
|
+
this.handleIframeEventListeners = this.handleIframeEventListeners.bind(this);
|
|
113
161
|
this.handleDropElementStyleUpdate = this.handleDropElementStyleUpdate.bind(this);
|
|
114
162
|
this.positionRef = /*#__PURE__*/React.createRef();
|
|
115
|
-
this.
|
|
163
|
+
this.rootElement = Registry.getRootElement();
|
|
164
|
+
this.popupObserver = new ResizeObserver(this.handlePopupResize);
|
|
165
|
+
this.cancelRaf = this.cancelRaf.bind(this);
|
|
166
|
+
this.cancelPendingAnimationFrames = this.cancelPendingAnimationFrames.bind(this);
|
|
167
|
+
this.setPositionRafId = null;
|
|
168
|
+
this.resizePositionRafId = null; //dropBoxSize
|
|
116
169
|
|
|
117
170
|
this.size = null;
|
|
118
171
|
this.isTargetElementVisible = false;
|
|
@@ -128,18 +181,18 @@ const Popup = function (Component) {
|
|
|
128
181
|
|
|
129
182
|
componentDidMount() {
|
|
130
183
|
const group = this.getGroup();
|
|
131
|
-
const groupPopups = popups[group] || [];
|
|
184
|
+
const groupPopups = Registry.popups[group] || [];
|
|
132
185
|
groupPopups.push(this);
|
|
133
|
-
popups[group] = groupPopups;
|
|
186
|
+
Registry.popups[group] = groupPopups;
|
|
134
187
|
|
|
135
|
-
if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
|
|
136
|
-
|
|
137
|
-
|
|
188
|
+
if (Object.keys(Registry.popups).length === 1 && groupPopups.length === 1 && Registry.listenerPopupRef === undefined) {
|
|
189
|
+
Registry.listenerPopupRef = this;
|
|
190
|
+
Registry.listenerPopupRef.updateListeners(true, CLICK_EVENTS, document);
|
|
191
|
+
document.addEventListener('keyup', Registry.listenerPopupRef.documentKeyupHandler, false); // document.addEventListener('scroll', Registry.listenerPopupRef.handleScroll, true);
|
|
138
192
|
|
|
139
|
-
window.addEventListener('resize',
|
|
140
|
-
document.addEventListener('
|
|
141
|
-
document.addEventListener('
|
|
142
|
-
document.addEventListener('focus', this.handleDocumentFocus, true);
|
|
193
|
+
window.addEventListener('resize', Registry.listenerPopupRef.handleResize);
|
|
194
|
+
document.addEventListener('mousedown', Registry.listenerPopupRef.handleDocumentMouseDown, true);
|
|
195
|
+
document.addEventListener('focus', Registry.listenerPopupRef.handleDocumentFocus, true);
|
|
143
196
|
}
|
|
144
197
|
}
|
|
145
198
|
|
|
@@ -156,8 +209,8 @@ const Popup = function (Component) {
|
|
|
156
209
|
}
|
|
157
210
|
}
|
|
158
211
|
|
|
159
|
-
handleScrollAndBlockEvents(
|
|
160
|
-
if (
|
|
212
|
+
handleScrollAndBlockEvents(shouldAdd) {
|
|
213
|
+
if (shouldAdd) {
|
|
161
214
|
this.handleAddingScrollBlock();
|
|
162
215
|
this.handleAddingScrollToUpdatePosition();
|
|
163
216
|
} else {
|
|
@@ -166,6 +219,16 @@ const Popup = function (Component) {
|
|
|
166
219
|
}
|
|
167
220
|
}
|
|
168
221
|
|
|
222
|
+
handleIframeEventListeners(shouldAdd, eventList) {
|
|
223
|
+
this.rootElement.querySelectorAll('iframe').forEach(frame => {
|
|
224
|
+
const frameDocument = frame.contentDocument;
|
|
225
|
+
|
|
226
|
+
if (frameDocument) {
|
|
227
|
+
this.updateListeners(shouldAdd, eventList, frameDocument);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
169
232
|
componentDidUpdate(prevProps, prevState) {
|
|
170
233
|
const {
|
|
171
234
|
isPopupReady,
|
|
@@ -192,28 +255,45 @@ const Popup = function (Component) {
|
|
|
192
255
|
}
|
|
193
256
|
|
|
194
257
|
if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
|
|
195
|
-
|
|
258
|
+
const shouldAdd = isPopupReady && !isMobile;
|
|
259
|
+
this.handleScrollAndBlockEvents(shouldAdd);
|
|
260
|
+
this.handleIframeEventListeners(shouldAdd, CLICK_EVENTS);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
cancelRaf(refName) {
|
|
265
|
+
const id = this[refName];
|
|
266
|
+
|
|
267
|
+
if (id) {
|
|
268
|
+
cancelAnimationFrame(id);
|
|
269
|
+
this[refName] = null;
|
|
196
270
|
}
|
|
197
271
|
}
|
|
198
272
|
|
|
273
|
+
cancelPendingAnimationFrames() {
|
|
274
|
+
this.cancelRaf('setPositionRafId');
|
|
275
|
+
this.cancelRaf('resizePositionRafId');
|
|
276
|
+
}
|
|
277
|
+
|
|
199
278
|
componentWillUnmount() {
|
|
200
279
|
const group = this.getGroup();
|
|
201
|
-
popups = Object.keys(popups).reduce((res, groupName) => {
|
|
280
|
+
Registry.popups = Object.keys(Registry.popups).reduce((res, groupName) => {
|
|
202
281
|
if (groupName === group) {
|
|
203
|
-
const groupPopups = popups[group];
|
|
282
|
+
const groupPopups = Registry.popups[group];
|
|
204
283
|
const newGroupPopups = groupPopups.filter(popup => popup !== this);
|
|
205
|
-
newGroupPopups.length === 0 && lastOpenedGroup.indexOf(group) >= 0 && lastOpenedGroup.splice(lastOpenedGroup.indexOf(group), 1);
|
|
284
|
+
newGroupPopups.length === 0 && Registry.lastOpenedGroup.indexOf(group) >= 0 && Registry.lastOpenedGroup.splice(Registry.lastOpenedGroup.indexOf(group), 1);
|
|
206
285
|
res[group] = newGroupPopups;
|
|
207
286
|
}
|
|
208
287
|
|
|
209
288
|
return res;
|
|
210
|
-
}, popups);
|
|
289
|
+
}, Registry.popups);
|
|
211
290
|
this.handleRemovingScrollBlock();
|
|
212
291
|
this.handleRemovingScrollToUpdatePosition();
|
|
292
|
+
this.handleIframeEventListeners(false, CLICK_EVENTS);
|
|
213
293
|
let noPopups = true;
|
|
214
294
|
|
|
215
|
-
for (const i in popups) {
|
|
216
|
-
if (popups[i].length >= 1) {
|
|
295
|
+
for (const i in Registry.popups) {
|
|
296
|
+
if (Registry.popups[i].length >= 1) {
|
|
217
297
|
noPopups = false;
|
|
218
298
|
break;
|
|
219
299
|
}
|
|
@@ -223,15 +303,17 @@ const Popup = function (Component) {
|
|
|
223
303
|
this.popupObserver.disconnect();
|
|
224
304
|
}
|
|
225
305
|
|
|
226
|
-
if (noPopups) {
|
|
227
|
-
|
|
228
|
-
document.removeEventListener('keyup',
|
|
306
|
+
if (noPopups && Registry.listenerPopupRef !== undefined) {
|
|
307
|
+
Registry.listenerPopupRef.updateListeners(false, CLICK_EVENTS, document);
|
|
308
|
+
document.removeEventListener('keyup', Registry.listenerPopupRef.documentKeyupHandler); // document.removeEventListener('scroll', Registry.listenerPopupRef.handleScroll);
|
|
229
309
|
|
|
230
|
-
window.removeEventListener('resize',
|
|
231
|
-
document.removeEventListener('
|
|
232
|
-
document.removeEventListener('
|
|
233
|
-
|
|
310
|
+
window.removeEventListener('resize', Registry.listenerPopupRef.handleResize);
|
|
311
|
+
document.removeEventListener('mousedown', Registry.listenerPopupRef.handleDocumentMouseDown, true);
|
|
312
|
+
document.removeEventListener('focus', Registry.listenerPopupRef.handleDocumentFocus, true);
|
|
313
|
+
Registry.listenerPopupRef = undefined;
|
|
234
314
|
}
|
|
315
|
+
|
|
316
|
+
this.cancelPendingAnimationFrames();
|
|
235
317
|
}
|
|
236
318
|
|
|
237
319
|
handleAddingScrollBlock() {
|
|
@@ -260,10 +342,12 @@ const Popup = function (Component) {
|
|
|
260
342
|
|
|
261
343
|
if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
|
|
262
344
|
addIntersectionObserver(this.placeHolderElement, this.updateVisibilityOnIntersection);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
345
|
+
const shouldAddScrollToUpdatePositionListeners = Registry.getOpenedScrollableFixedPopups().length === 1 && Registry.scrollableListenerPopupRef === undefined;
|
|
346
|
+
|
|
347
|
+
if (shouldAddScrollToUpdatePositionListeners) {
|
|
348
|
+
Registry.scrollableListenerPopupRef = this;
|
|
349
|
+
Registry.scrollableListenerPopupRef.addScrollToUpdateListeners();
|
|
350
|
+
}
|
|
267
351
|
}
|
|
268
352
|
}
|
|
269
353
|
|
|
@@ -273,10 +357,12 @@ const Popup = function (Component) {
|
|
|
273
357
|
|
|
274
358
|
if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
|
|
275
359
|
removeIntersectionObserver(this.placeHolderElement, this.updateVisibilityOnIntersection);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
360
|
+
const shouldRemoveScrollToUpdatePositionListeners = Registry.getOpenedScrollableFixedPopups().length === 0 && Registry.scrollableListenerPopupRef !== undefined;
|
|
361
|
+
|
|
362
|
+
if (shouldRemoveScrollToUpdatePositionListeners) {
|
|
363
|
+
Registry.scrollableListenerPopupRef.removeScrollToUpdateListeners();
|
|
364
|
+
Registry.scrollableListenerPopupRef = undefined;
|
|
365
|
+
}
|
|
280
366
|
}
|
|
281
367
|
}
|
|
282
368
|
|
|
@@ -335,83 +421,123 @@ const Popup = function (Component) {
|
|
|
335
421
|
}
|
|
336
422
|
|
|
337
423
|
updatePositionOnScroll(e) {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
424
|
+
const scrollablePopups = Registry.getOpenedScrollableFixedPopups(); // Check if the event target is outside all dropElements
|
|
425
|
+
|
|
426
|
+
scrollablePopups.forEach(_ref2 => {
|
|
427
|
+
let {
|
|
428
|
+
placeHolderElement,
|
|
429
|
+
defaultPosition,
|
|
430
|
+
isTargetElementVisible,
|
|
431
|
+
handlePopupPosition
|
|
432
|
+
} = _ref2;
|
|
433
|
+
|
|
434
|
+
if (e.target.contains(placeHolderElement) && isTargetElementVisible) {
|
|
435
|
+
handlePopupPosition(defaultPosition, true);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
343
439
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
440
|
+
updateListeners() {
|
|
441
|
+
let add = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
442
|
+
let eventList = arguments.length > 1 ? arguments[1] : undefined;
|
|
443
|
+
let element = arguments.length > 2 ? arguments[2] : undefined;
|
|
444
|
+
const method = add ? 'addEventListener' : 'removeEventListener';
|
|
445
|
+
eventList.forEach(_ref3 => {
|
|
446
|
+
let {
|
|
447
|
+
name,
|
|
448
|
+
handlerName,
|
|
449
|
+
options
|
|
450
|
+
} = _ref3;
|
|
451
|
+
const handler = this[handlerName];
|
|
452
|
+
|
|
453
|
+
if (handler) {
|
|
454
|
+
element[method](name, handler, options);
|
|
455
|
+
}
|
|
456
|
+
});
|
|
347
457
|
}
|
|
348
458
|
|
|
349
459
|
addScrollBlockListeners() {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
passive: false
|
|
361
|
-
});
|
|
362
|
-
document.addEventListener('keydown', this.preventKeyboardScroll, {
|
|
363
|
-
capture: true,
|
|
364
|
-
passive: false
|
|
365
|
-
});
|
|
460
|
+
// Only add scroll block listeners if at least one open popup needs outside scroll blocked
|
|
461
|
+
const shouldAddScrollBlockListeners = Registry.getOpenedScrollBlockedFixedPopups().length === 1 && Registry.scrollBlockedListenerPopupRef === undefined;
|
|
462
|
+
|
|
463
|
+
if (shouldAddScrollBlockListeners) {
|
|
464
|
+
Registry.scrollBlockedListenerPopupRef = this; // Main document
|
|
465
|
+
|
|
466
|
+
Registry.scrollBlockedListenerPopupRef.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within rootElement
|
|
467
|
+
|
|
468
|
+
Registry.scrollBlockedListenerPopupRef.handleIframeEventListeners(true, IFRAME_SCROLL_BLOCK_EVENTS);
|
|
469
|
+
}
|
|
366
470
|
}
|
|
367
471
|
|
|
368
472
|
removeScrollBlockListeners() {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
473
|
+
// Only remove scroll block listeners if at least one open popup needs outside scroll blocked
|
|
474
|
+
const shouldRemoveScrollBlockListeners = Registry.getOpenedScrollBlockedFixedPopups().length === 0 && Registry.scrollBlockedListenerPopupRef !== undefined;
|
|
475
|
+
|
|
476
|
+
if (shouldRemoveScrollBlockListeners) {
|
|
477
|
+
Registry.scrollBlockedListenerPopupRef.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
|
|
478
|
+
Registry.scrollBlockedListenerPopupRef.handleIframeEventListeners(false, IFRAME_SCROLL_BLOCK_EVENTS);
|
|
479
|
+
Registry.scrollBlockedListenerPopupRef = undefined;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
addScrollToUpdateListeners() {
|
|
484
|
+
document.addEventListener('scroll', this.updatePositionOnScroll, {
|
|
378
485
|
capture: true,
|
|
379
486
|
passive: false
|
|
380
487
|
});
|
|
381
|
-
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
removeScrollToUpdateListeners() {
|
|
491
|
+
document.removeEventListener('scroll', this.updatePositionOnScroll, {
|
|
382
492
|
capture: true,
|
|
383
493
|
passive: false
|
|
384
494
|
});
|
|
385
495
|
}
|
|
386
496
|
|
|
387
497
|
handleBlockScroll(event) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
498
|
+
const scrollBlockedPopups = Registry.getOpenedScrollBlockedFixedPopups(); // Check if the event target is outside all dropElements
|
|
499
|
+
|
|
500
|
+
const isOutsideAllDropElements = scrollBlockedPopups.every(_ref4 => {
|
|
501
|
+
let {
|
|
502
|
+
dropElement
|
|
503
|
+
} = _ref4;
|
|
504
|
+
return dropElement && dropElement !== event.target && !dropElement.contains(event.target);
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
if (isOutsideAllDropElements) {
|
|
397
508
|
event.preventDefault();
|
|
398
509
|
}
|
|
399
510
|
}
|
|
400
511
|
|
|
401
512
|
handlePositionChange(event) {
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
513
|
+
const scrollBlockedPopups = Registry.getOpenedScrollBlockedFixedPopups();
|
|
514
|
+
scrollBlockedPopups.forEach(_ref5 => {
|
|
515
|
+
let {
|
|
516
|
+
placeHolderElement,
|
|
517
|
+
dropElement,
|
|
518
|
+
handlePopupPosition,
|
|
519
|
+
state
|
|
520
|
+
} = _ref5;
|
|
521
|
+
|
|
522
|
+
if (dropElement && dropElement !== event.target && !dropElement.contains(event.target) && placeHolderElement && placeHolderElement !== event.target && !placeHolderElement.contains(event.target) && event.target.contains(placeHolderElement)) {
|
|
523
|
+
handlePopupPosition(state.position, true);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
408
526
|
}
|
|
409
527
|
|
|
410
528
|
preventKeyboardScroll(event) {
|
|
411
|
-
const containerElement = this.dropElement;
|
|
412
529
|
const keys = [32, 37, 38, 39, 40]; // Space, Arrow keys
|
|
413
530
|
|
|
414
|
-
|
|
531
|
+
const scrollBlockedPopups = Registry.getOpenedScrollBlockedFixedPopups(); // Check if the event target is outside all dropElements
|
|
532
|
+
|
|
533
|
+
const isOutsideAllDropElements = scrollBlockedPopups.every(_ref6 => {
|
|
534
|
+
let {
|
|
535
|
+
dropElement
|
|
536
|
+
} = _ref6;
|
|
537
|
+
return dropElement && dropElement !== event.target && !dropElement.contains(event.target) && keys.includes(event.keyCode);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
if (isOutsideAllDropElements) {
|
|
415
541
|
event.preventDefault();
|
|
416
542
|
}
|
|
417
543
|
}
|
|
@@ -430,10 +556,10 @@ const Popup = function (Component) {
|
|
|
430
556
|
|
|
431
557
|
if (entry.isIntersecting === true) {
|
|
432
558
|
this.isTargetElementVisible = true;
|
|
433
|
-
dropElement.setAttribute('data-visible', 'visible');
|
|
559
|
+
dropElement && dropElement.setAttribute('data-visible', 'visible');
|
|
434
560
|
} else if (entry.intersectionRatio === 0 && entry.isIntersecting === false) {
|
|
435
561
|
this.isTargetElementVisible = false;
|
|
436
|
-
dropElement.setAttribute('data-visible', 'hidden');
|
|
562
|
+
dropElement && dropElement.setAttribute('data-visible', 'hidden');
|
|
437
563
|
}
|
|
438
564
|
}
|
|
439
565
|
|
|
@@ -510,9 +636,9 @@ const Popup = function (Component) {
|
|
|
510
636
|
const {
|
|
511
637
|
isPopupOpen
|
|
512
638
|
} = this.state;
|
|
513
|
-
const groupPopups = popups[group] || [];
|
|
514
|
-
lastOpenedGroup = !isPopupOpen && lastOpenedGroup.indexOf(group) === -1 ? [group, ...lastOpenedGroup] : lastOpenedGroup;
|
|
515
|
-
isPopupOpen && lastOpenedGroup.splice(0, 1);
|
|
639
|
+
const groupPopups = Registry.popups[group] || [];
|
|
640
|
+
Registry.lastOpenedGroup = !isPopupOpen && Registry.lastOpenedGroup.indexOf(group) === -1 ? [group, ...Registry.lastOpenedGroup] : Registry.lastOpenedGroup;
|
|
641
|
+
isPopupOpen && Registry.lastOpenedGroup.splice(0, 1);
|
|
516
642
|
groupPopups.forEach(popup => {
|
|
517
643
|
if (popup !== this && popup.state.isPopupOpen) {
|
|
518
644
|
popup.setState({
|
|
@@ -535,18 +661,18 @@ const Popup = function (Component) {
|
|
|
535
661
|
openPopupOnly(e, defaultPosition) {
|
|
536
662
|
const group = this.getGroup();
|
|
537
663
|
this.removeClose(e);
|
|
538
|
-
lastOpenedGroup = lastOpenedGroup.indexOf(group) === -1 ? [group, ...lastOpenedGroup] : lastOpenedGroup;
|
|
664
|
+
Registry.lastOpenedGroup = Registry.lastOpenedGroup.indexOf(group) === -1 ? [group, ...Registry.lastOpenedGroup] : Registry.lastOpenedGroup;
|
|
539
665
|
this.handlePopupPosition(defaultPosition);
|
|
540
666
|
}
|
|
541
667
|
|
|
542
668
|
closePopupOnly(e) {
|
|
543
669
|
this.removeClose(e);
|
|
544
|
-
lastOpenedGroup.splice(0, 1);
|
|
545
670
|
const {
|
|
546
671
|
isPopupOpen
|
|
547
672
|
} = this.state;
|
|
548
673
|
|
|
549
674
|
if (isPopupOpen) {
|
|
675
|
+
Registry.lastOpenedGroup.splice(0, 1);
|
|
550
676
|
this.setState({
|
|
551
677
|
isPopupOpen: false,
|
|
552
678
|
isPopupReady: false
|
|
@@ -555,8 +681,8 @@ const Popup = function (Component) {
|
|
|
555
681
|
}
|
|
556
682
|
|
|
557
683
|
handleCloseLastOpenedGroup() {
|
|
558
|
-
const groupPopups = lastOpenedGroup.length ? popups[lastOpenedGroup[0]] || [] : [];
|
|
559
|
-
lastOpenedGroup.splice(0, 1);
|
|
684
|
+
const groupPopups = Registry.lastOpenedGroup.length ? Registry.popups[Registry.lastOpenedGroup[0]] || [] : [];
|
|
685
|
+
Registry.lastOpenedGroup.splice(0, 1);
|
|
560
686
|
groupPopups.forEach(popup => {
|
|
561
687
|
popup.state.isPopupOpen && popup.setState({
|
|
562
688
|
isPopupOpen: false,
|
|
@@ -584,11 +710,11 @@ const Popup = function (Component) {
|
|
|
584
710
|
handleGetNeedPrevent(e) {
|
|
585
711
|
let needPrevent = false;
|
|
586
712
|
|
|
587
|
-
if (lastOpenedGroup.length > 1) {
|
|
713
|
+
if (Registry.lastOpenedGroup.length > 1) {
|
|
588
714
|
const {
|
|
589
715
|
target
|
|
590
716
|
} = e;
|
|
591
|
-
const groupPopups = lastOpenedGroup.length ? popups[lastOpenedGroup[0]] : [];
|
|
717
|
+
const groupPopups = Registry.lastOpenedGroup.length ? Registry.popups[Registry.lastOpenedGroup[0]] : [];
|
|
592
718
|
let openedPopup = null; // eslint-disable-next-line guard-for-in
|
|
593
719
|
|
|
594
720
|
for (const i in groupPopups) {
|
|
@@ -634,8 +760,8 @@ const Popup = function (Component) {
|
|
|
634
760
|
|
|
635
761
|
documentClickHandler() {
|
|
636
762
|
try {
|
|
637
|
-
Object.keys(popups).forEach(groupName => {
|
|
638
|
-
const groupPopups = popups[groupName] || [];
|
|
763
|
+
Object.keys(Registry.popups).forEach(groupName => {
|
|
764
|
+
const groupPopups = Registry.popups[groupName] || [];
|
|
639
765
|
groupPopups.forEach(popup => {
|
|
640
766
|
popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !isTextSelected() && popup.setState({
|
|
641
767
|
isPopupOpen: false,
|
|
@@ -643,7 +769,7 @@ const Popup = function (Component) {
|
|
|
643
769
|
});
|
|
644
770
|
});
|
|
645
771
|
});
|
|
646
|
-
lastOpenedGroup = [];
|
|
772
|
+
Registry.lastOpenedGroup = [];
|
|
647
773
|
} catch (e) {// eslint-disable-next-line no-console
|
|
648
774
|
//console.error('popup component not unmounted properly', e);
|
|
649
775
|
}
|
|
@@ -710,7 +836,8 @@ const Popup = function (Component) {
|
|
|
710
836
|
}
|
|
711
837
|
|
|
712
838
|
const setPosition = () => {
|
|
713
|
-
|
|
839
|
+
this.cancelRaf('setPositionRafId');
|
|
840
|
+
this.setPositionRafId = requestAnimationFrame(() => {
|
|
714
841
|
const {
|
|
715
842
|
placeHolderElement,
|
|
716
843
|
dropElement
|
|
@@ -719,7 +846,7 @@ const Popup = function (Component) {
|
|
|
719
846
|
position,
|
|
720
847
|
isPopupReady
|
|
721
848
|
} = this.state;
|
|
722
|
-
const scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
|
|
849
|
+
const scrollContainer = placeHolderElement ? placeHolderElement.closest('[data-scroll=true]') || document.body : document.body;
|
|
723
850
|
const betterPosition = viewPort.betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
|
|
724
851
|
needArrow,
|
|
725
852
|
isAbsolute,
|
|
@@ -748,6 +875,8 @@ const Popup = function (Component) {
|
|
|
748
875
|
this.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
|
|
749
876
|
}
|
|
750
877
|
}
|
|
878
|
+
|
|
879
|
+
this.setPositionRafId = null;
|
|
751
880
|
});
|
|
752
881
|
};
|
|
753
882
|
|
|
@@ -763,8 +892,8 @@ const Popup = function (Component) {
|
|
|
763
892
|
}
|
|
764
893
|
|
|
765
894
|
handleOpenPopupPositionChange() {
|
|
766
|
-
Object.keys(popups).forEach(groupName => {
|
|
767
|
-
const groupPopups = popups[groupName] || [];
|
|
895
|
+
Object.keys(Registry.popups).forEach(groupName => {
|
|
896
|
+
const groupPopups = Registry.popups[groupName] || [];
|
|
768
897
|
groupPopups.forEach(popup => {
|
|
769
898
|
if (popup.state.isPopupOpen) {
|
|
770
899
|
const {
|
|
@@ -779,7 +908,8 @@ const Popup = function (Component) {
|
|
|
779
908
|
|
|
780
909
|
if (placeHolderElement && dropElement) {
|
|
781
910
|
const scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
|
|
782
|
-
|
|
911
|
+
this.cancelRaf('resizePositionRafId');
|
|
912
|
+
this.resizePositionRafId = requestAnimationFrame(() => {
|
|
783
913
|
const needArrow = this.getNeedArrow(popup);
|
|
784
914
|
const isAbsolute = this.getIsAbsolutePopup(popup);
|
|
785
915
|
const customOrder = this.getCustomPositionOrder(popup);
|
|
@@ -836,6 +966,8 @@ const Popup = function (Component) {
|
|
|
836
966
|
// });
|
|
837
967
|
// }
|
|
838
968
|
|
|
969
|
+
|
|
970
|
+
this.resizePositionRafId = null;
|
|
839
971
|
});
|
|
840
972
|
}
|
|
841
973
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getLibraryConfig } from "../Provider/Config.js";
|
|
2
|
+
const Registry = {
|
|
3
|
+
lastOpenedGroup: [],
|
|
4
|
+
popups: {},
|
|
5
|
+
listenerPopupRef: undefined,
|
|
6
|
+
scrollBlockedListenerPopupRef: undefined,
|
|
7
|
+
scrollableListenerPopupRef: undefined,
|
|
8
|
+
|
|
9
|
+
getOpenedPopups() {
|
|
10
|
+
return Object.values(Registry.popups).flat().filter(popup => popup.state.isPopupOpen);
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
getOpenedScrollBlockedFixedPopups() {
|
|
14
|
+
return Registry.getOpenedPopups().filter(popup => popup.getIsOutsideScrollBlocked(popup) && !popup.getIsAbsolutePopup(popup));
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
getOpenedScrollableFixedPopups() {
|
|
18
|
+
return Registry.getOpenedPopups().filter(popup => !popup.getIsOutsideScrollBlocked(popup) && !popup.getIsAbsolutePopup(popup));
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
getRootElement() {
|
|
22
|
+
const getRootElement = getLibraryConfig('getRootElement');
|
|
23
|
+
|
|
24
|
+
if (getRootElement && typeof getRootElement === 'function') {
|
|
25
|
+
const parent = getRootElement();
|
|
26
|
+
|
|
27
|
+
if (parent) {
|
|
28
|
+
return parent;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return document;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
export default Registry;
|
package/es/Popup/viewPort.js
CHANGED
|
@@ -108,24 +108,23 @@ let viewPort = {
|
|
|
108
108
|
let paddingSpace = 5; // space between target and relative element
|
|
109
109
|
|
|
110
110
|
let arrowSize = needArrow ? 10 : 0;
|
|
111
|
-
|
|
112
|
-
rect.width = rect.width + (needArrow ? arrowSize : paddingSpace);
|
|
111
|
+
let padding = needArrow ? arrowSize : paddingSpace;
|
|
113
112
|
let arrowHorizontalBalancePx = !isAbsolute && needArrow ? 30 : 0;
|
|
114
113
|
let arrowVerticalBalancePx = !isAbsolute && needArrow ? 27 : 0;
|
|
115
|
-
let bottomOverFlow = rect.height > relativeBoxGap.bottom;
|
|
116
|
-
let topOverFlow = rect.height > relativeBoxGap.top;
|
|
117
|
-
let rightOverFlow = rect.width > relativeBoxGap.right;
|
|
118
|
-
let leftOverFlow = rect.width > relativeBoxGap.left;
|
|
119
|
-
let horizontalCenterOverFlow = rect.width / 2 > relativeBoxGap.center.right || rect.width / 2 > relativeBoxGap.center.left;
|
|
120
|
-
let verticalCenterOverFlow = rect.height / 2 > relativeBoxGap.center.top || rect.height / 2 > relativeBoxGap.center.bottom;
|
|
121
|
-
let horizontalLeftToRightOverFlow = rect.width > relativeBoxRect.width + relativeBoxGap.right;
|
|
122
|
-
let horizontalCenterToRightOverFlow = rect.width > relativeBoxGap.center.right || arrowHorizontalBalancePx > relativeBoxGap.center.left;
|
|
123
|
-
let horizontalRightToLeft = rect.width > relativeBoxRect.width + relativeBoxGap.left;
|
|
124
|
-
let horizontalCenterToLeft = rect.width > relativeBoxGap.center.left || arrowHorizontalBalancePx > relativeBoxGap.center.right;
|
|
125
|
-
let verticalTopToBottomOverFlow = rect.height > relativeBoxRect.height + relativeBoxGap.bottom;
|
|
126
|
-
let verticalCenterToBottomOverFlow = rect.height > relativeBoxGap.center.bottom || arrowVerticalBalancePx > relativeBoxGap.center.top;
|
|
127
|
-
let verticalBottomToTopOverFlow = rect.height > relativeBoxRect.height + relativeBoxGap.top;
|
|
128
|
-
let verticalCenterToTopOverFlow = rect.height > relativeBoxGap.center.top || arrowVerticalBalancePx > relativeBoxGap.center.bottom;
|
|
114
|
+
let bottomOverFlow = rect.height + padding > relativeBoxGap.bottom;
|
|
115
|
+
let topOverFlow = rect.height + padding > relativeBoxGap.top;
|
|
116
|
+
let rightOverFlow = rect.width + padding > relativeBoxGap.right;
|
|
117
|
+
let leftOverFlow = rect.width + padding > relativeBoxGap.left;
|
|
118
|
+
let horizontalCenterOverFlow = rect.width / 2 + padding > relativeBoxGap.center.right || rect.width / 2 + padding > relativeBoxGap.center.left;
|
|
119
|
+
let verticalCenterOverFlow = rect.height / 2 + padding > relativeBoxGap.center.top || rect.height / 2 + padding > relativeBoxGap.center.bottom;
|
|
120
|
+
let horizontalLeftToRightOverFlow = rect.width + padding > relativeBoxRect.width + relativeBoxGap.right;
|
|
121
|
+
let horizontalCenterToRightOverFlow = rect.width + padding > relativeBoxGap.center.right || arrowHorizontalBalancePx > relativeBoxGap.center.left;
|
|
122
|
+
let horizontalRightToLeft = rect.width + padding > relativeBoxRect.width + relativeBoxGap.left;
|
|
123
|
+
let horizontalCenterToLeft = rect.width + padding > relativeBoxGap.center.left || arrowHorizontalBalancePx > relativeBoxGap.center.right;
|
|
124
|
+
let verticalTopToBottomOverFlow = rect.height + padding > relativeBoxRect.height + relativeBoxGap.bottom;
|
|
125
|
+
let verticalCenterToBottomOverFlow = rect.height + padding > relativeBoxGap.center.bottom || arrowVerticalBalancePx > relativeBoxGap.center.top;
|
|
126
|
+
let verticalBottomToTopOverFlow = rect.height + padding > relativeBoxRect.height + relativeBoxGap.top;
|
|
127
|
+
let verticalCenterToTopOverFlow = rect.height + padding > relativeBoxGap.center.top || arrowVerticalBalancePx > relativeBoxGap.center.bottom;
|
|
129
128
|
let views = {
|
|
130
129
|
bottomCenter: !(bottomOverFlow || horizontalCenterOverFlow),
|
|
131
130
|
bottomLeftToRight: !(bottomOverFlow || horizontalLeftToRightOverFlow),
|