@jetbrains/ring-ui 4.2.7 → 4.2.10
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/components/auth/auth__core.js +5 -0
- package/components/auth/token-validator.js +4 -1
- package/components/pager/pager.js +14 -14
- package/dist/_helpers/_rollupPluginBabelHelpers.js +34 -0
- package/dist/_helpers/anchor.js +33 -0
- package/dist/_helpers/badge.js +3 -0
- package/dist/_helpers/button-group.js +3 -0
- package/dist/_helpers/button-set.js +3 -0
- package/dist/_helpers/button-toolbar.js +3 -0
- package/dist/_helpers/button__classes.js +39 -0
- package/dist/_helpers/card.js +75 -0
- package/dist/_helpers/checkbox.js +3 -0
- package/dist/_helpers/date-picker.js +3 -0
- package/dist/_helpers/dialog__body-scroll-preventer.js +58 -0
- package/dist/_helpers/error-message.js +3 -0
- package/dist/_helpers/footer.js +121 -0
- package/dist/_helpers/grid.js +3 -0
- package/dist/_helpers/group.js +3 -0
- package/dist/_helpers/header.js +3 -0
- package/dist/_helpers/icon.js +3 -0
- package/dist/_helpers/inject-styles.js +22 -0
- package/dist/_helpers/input.js +3 -0
- package/dist/_helpers/island.js +3 -0
- package/dist/_helpers/link.js +3 -0
- package/dist/_helpers/list.js +3 -0
- package/dist/_helpers/loader-screen.js +3 -0
- package/dist/_helpers/panel.js +3 -0
- package/dist/_helpers/query-assist__suggestions.js +95 -0
- package/dist/_helpers/radio.js +3 -0
- package/dist/_helpers/select__filter.js +77 -0
- package/dist/_helpers/services-link.js +40 -0
- package/dist/_helpers/sidebar.js +126 -0
- package/dist/_helpers/table.js +3 -0
- package/dist/_helpers/tabs.js +3 -0
- package/dist/_helpers/title.js +100 -0
- package/dist/alert/alert.js +262 -0
- package/dist/alert/container.js +48 -0
- package/dist/alert-service/alert-service.js +173 -0
- package/dist/analytics/analytics.js +118 -0
- package/dist/analytics/analytics__custom-plugin.js +128 -0
- package/dist/analytics/analytics__fus-plugin.js +102 -0
- package/dist/analytics/analytics__ga-plugin.js +75 -0
- package/dist/analytics/analytics__plugin-utils.js +80 -0
- package/dist/analytics-ng/analytics-ng.js +95 -0
- package/dist/auth/auth.js +96 -0
- package/dist/auth/auth__core.js +1065 -0
- package/dist/auth/background-flow.js +123 -0
- package/dist/auth/down-notification.js +117 -0
- package/dist/auth/iframe-flow.js +153 -0
- package/dist/auth/landing-entry.js +5 -0
- package/dist/auth/landing.js +90 -0
- package/dist/auth/request-builder.js +76 -0
- package/dist/auth/response-parser.js +118 -0
- package/dist/auth/storage.js +283 -0
- package/dist/auth/token-validator.js +180 -0
- package/dist/auth/window-flow.js +134 -0
- package/dist/auth-dialog/auth-dialog.js +180 -0
- package/dist/auth-dialog-service/auth-dialog-service.js +71 -0
- package/dist/auth-ng/auth-ng.js +206 -0
- package/dist/auth-ng/auth-ng.mock.js +33 -0
- package/dist/autofocus-ng/autofocus-ng.js +51 -0
- package/dist/avatar/avatar-example-datauri.js +4 -0
- package/dist/avatar/avatar.js +163 -0
- package/dist/avatar/fallback-avatar.js +142 -0
- package/dist/avatar-editor-ng/avatar-editor-ng.js +167 -0
- package/dist/avatar-editor-ng/avatar-editor-ng__template.js +3 -0
- package/dist/avatar-ng/avatar-ng.js +21 -0
- package/dist/badge/badge.js +51 -0
- package/dist/badge-ng/badge-ng.js +18 -0
- package/dist/breadcrumb-ng/breadcrumb-ng.js +37 -0
- package/dist/button/button.js +125 -0
- package/dist/button/button__classes.js +5 -0
- package/dist/button-group/button-group.js +30 -0
- package/dist/button-group/caption.js +24 -0
- package/dist/button-group-ng/button-group-ng.js +39 -0
- package/dist/button-ng/button-ng.js +217 -0
- package/dist/button-set/button-set.js +26 -0
- package/dist/button-set-ng/button-set-ng.js +19 -0
- package/dist/button-toolbar/button-toolbar.js +29 -0
- package/dist/button-toolbar-ng/button-toolbar-ng.js +24 -0
- package/dist/caret/caret.js +266 -0
- package/dist/checkbox/checkbox.js +110 -0
- package/dist/checkbox-ng/checkbox-ng.js +38 -0
- package/dist/code/code.js +137 -0
- package/dist/compiler-ng/compiler-ng.js +53 -0
- package/dist/confirm/confirm.js +127 -0
- package/dist/confirm-ng/confirm-ng.js +69 -0
- package/dist/confirm-service/confirm-service.js +117 -0
- package/dist/content-layout/content-layout.js +66 -0
- package/dist/content-layout/sidebar.js +7 -0
- package/dist/contenteditable/contenteditable.js +78 -0
- package/dist/data-list/data-list.js +208 -0
- package/dist/data-list/data-list.mock.js +191 -0
- package/dist/data-list/item.js +229 -0
- package/dist/data-list/selection.js +102 -0
- package/dist/data-list/title.js +20 -0
- package/dist/data-list-ng/data-list-ng.js +62 -0
- package/dist/date-picker/consts.js +69 -0
- package/dist/date-picker/date-input.js +175 -0
- package/dist/date-picker/date-picker.js +367 -0
- package/dist/date-picker/date-popup.js +483 -0
- package/dist/date-picker/day.js +120 -0
- package/dist/date-picker/formats.js +3 -0
- package/dist/date-picker/month-names.js +100 -0
- package/dist/date-picker/month-slider.js +84 -0
- package/dist/date-picker/month.js +55 -0
- package/dist/date-picker/months.js +122 -0
- package/dist/date-picker/weekdays.js +32 -0
- package/dist/date-picker/years.js +110 -0
- package/dist/dialog/dialog.js +205 -0
- package/dist/dialog/dialog__body-scroll-preventer.js +3 -0
- package/dist/dialog-ng/dialog-ng.js +604 -0
- package/dist/dialog-ng/dialog-ng__template.js +3 -0
- package/dist/docked-panel-ng/docked-panel-ng.js +171 -0
- package/dist/dropdown/anchor.js +19 -0
- package/dist/dropdown/dropdown.js +236 -0
- package/dist/dropdown-menu/dropdown-menu.js +177 -0
- package/dist/error-bubble/error-bubble.js +59 -0
- package/dist/error-message/error-message.js +57 -0
- package/dist/error-message-ng/error-message-ng.js +35 -0
- package/dist/footer/footer.js +12 -0
- package/dist/footer-ng/footer-ng.js +64 -0
- package/dist/form-ng/form-ng.js +167 -0
- package/dist/global/angular-component-factory.js +84 -0
- package/dist/global/compose.js +9 -0
- package/dist/global/composeRefs.js +15 -0
- package/dist/global/conic-gradient.js +35 -0
- package/dist/global/create-stateful-context.js +55 -0
- package/dist/global/data-tests.js +24 -0
- package/dist/global/dom.js +125 -0
- package/dist/global/focus-sensor-hoc.js +146 -0
- package/dist/global/fuzzy-highlight.js +67 -0
- package/dist/global/get-event-key.js +111 -0
- package/dist/global/get-uid.js +15 -0
- package/dist/global/inject-styles.js +15 -0
- package/dist/global/linear-function.js +17 -0
- package/dist/global/listeners.js +44 -0
- package/dist/global/memoize.js +20 -0
- package/dist/global/normalize-indent.js +30 -0
- package/dist/global/promise-with-timeout.js +17 -0
- package/dist/global/radial-gradient-mask.js +38 -0
- package/dist/global/react-dom-renderer.js +46 -0
- package/dist/global/react-render-adapter.js +41 -0
- package/dist/global/rerender-hoc.js +55 -0
- package/dist/global/ring-angular-component.js +24 -0
- package/dist/global/schedule-raf.js +31 -0
- package/dist/global/sniffer.js +6 -0
- package/dist/global/supports-css.js +22 -0
- package/dist/global/theme.js +54 -0
- package/dist/global/trivial-template-tag.js +17 -0
- package/dist/global/url.js +165 -0
- package/dist/global/variables_dark.js +57 -0
- package/dist/grid/col.js +60 -0
- package/dist/grid/grid.js +33 -0
- package/dist/grid/row.js +64 -0
- package/dist/group/group.js +31 -0
- package/dist/group-ng/group-ng.js +11 -0
- package/dist/header/header.js +150 -0
- package/dist/header/logo.js +40 -0
- package/dist/header/profile.js +219 -0
- package/dist/header/services-link.js +12 -0
- package/dist/header/services.js +138 -0
- package/dist/header/smart-profile.js +233 -0
- package/dist/header/smart-services.js +163 -0
- package/dist/header/tray-icon.js +47 -0
- package/dist/header/tray.js +31 -0
- package/dist/heading/heading.js +73 -0
- package/dist/http/http.js +218 -0
- package/dist/http/http.mock.js +67 -0
- package/dist/hub-source/hub-source.js +130 -0
- package/dist/hub-source/hub-source__user.js +30 -0
- package/dist/hub-source/hub-source__users-groups.js +63 -0
- package/dist/icon/icon.js +105 -0
- package/dist/icon/icon__constants.js +33 -0
- package/dist/icon/icon__svg.js +83 -0
- package/dist/icon/index.js +12 -0
- package/dist/icon-ng/icon-ng.js +91 -0
- package/dist/input/input.js +230 -0
- package/dist/input-ng/input-ng.js +111 -0
- package/dist/island/adaptive-island-hoc.js +48 -0
- package/dist/island/content.js +160 -0
- package/dist/island/header.js +84 -0
- package/dist/island/island.js +51 -0
- package/dist/island-legacy/content-legacy.js +26 -0
- package/dist/island-legacy/header-legacy.js +28 -0
- package/dist/island-legacy/island-legacy.js +28 -0
- package/dist/island-ng/island-content-ng.js +42 -0
- package/dist/island-ng/island-header-ng.js +26 -0
- package/dist/island-ng/island-ng-class-fixer.js +11 -0
- package/dist/island-ng/island-ng.js +25 -0
- package/dist/link/clickableLink.js +64 -0
- package/dist/link/link.js +115 -0
- package/dist/link-ng/link-ng.js +22 -0
- package/dist/list/consts.js +26 -0
- package/dist/list/list.js +822 -0
- package/dist/list/list__custom.js +86 -0
- package/dist/list/list__hint.js +26 -0
- package/dist/list/list__item.js +206 -0
- package/dist/list/list__link.js +65 -0
- package/dist/list/list__separator.js +30 -0
- package/dist/list/list__title.js +39 -0
- package/dist/list/list__users-groups-source.js +130 -0
- package/dist/loader/loader.js +71 -0
- package/dist/loader/loader__core.js +273 -0
- package/dist/loader-inline/inject-styles.js +13 -0
- package/dist/loader-inline/loader-inline.js +58 -0
- package/dist/loader-inline-ng/loader-inline-ng.js +44 -0
- package/dist/loader-ng/loader-ng.js +44 -0
- package/dist/loader-screen/loader-screen.js +44 -0
- package/dist/loader-screen-ng/loader-screen-ng.js +95 -0
- package/dist/login-dialog/login-dialog.js +188 -0
- package/dist/login-dialog/service.js +72 -0
- package/dist/markdown/code.js +31 -0
- package/dist/markdown/heading.js +23 -0
- package/dist/markdown/link.js +31 -0
- package/dist/markdown/markdown.js +74 -0
- package/dist/message/message.js +235 -0
- package/dist/message-bundle-ng/message-bundle-ng.js +111 -0
- package/dist/old-browsers-message/old-browsers-message.js +101 -0
- package/dist/old-browsers-message/old-browsers-message__stop.js +5 -0
- package/dist/old-browsers-message/white-list.js +34 -0
- package/dist/pager/pager.js +365 -0
- package/dist/pager-ng/pager-ng.js +100 -0
- package/dist/panel/panel.js +31 -0
- package/dist/panel-ng/panel-ng.js +17 -0
- package/dist/permissions/permissions.js +200 -0
- package/dist/permissions/permissions__cache.js +272 -0
- package/dist/permissions-ng/permissions-ng.js +277 -0
- package/dist/place-under-ng/place-under-ng.js +158 -0
- package/dist/popup/popup.consts.js +41 -0
- package/dist/popup/popup.js +396 -0
- package/dist/popup/popup.target.js +26 -0
- package/dist/popup/position.js +280 -0
- package/dist/popup-menu/popup-menu.js +117 -0
- package/dist/progress-bar/progress-bar.js +114 -0
- package/dist/progress-bar-ng/progress-bar-ng.js +17 -0
- package/dist/promised-click-ng/promised-click-ng.js +128 -0
- package/dist/proxy-attrs/proxy-attrs.js +21 -0
- package/dist/query-assist/query-assist.js +1096 -0
- package/dist/query-assist/query-assist__suggestions.js +49 -0
- package/dist/query-assist-ng/query-assist-ng.js +86 -0
- package/dist/radio/radio.js +42 -0
- package/dist/radio/radio__item.js +78 -0
- package/dist/radio-ng/radio-ng.js +47 -0
- package/dist/save-field-ng/save-field-ng.js +337 -0
- package/dist/save-field-ng/save-field-ng__template.js +3 -0
- package/dist/select/select.js +1357 -0
- package/dist/select/select__filter.js +56 -0
- package/dist/select/select__popup.js +553 -0
- package/dist/select-ng/select-ng.js +637 -0
- package/dist/select-ng/select-ng__lazy.js +169 -0
- package/dist/select-ng/select-ng__options.js +145 -0
- package/dist/shortcuts/core.js +245 -0
- package/dist/shortcuts/shortcut-title.js +51 -0
- package/dist/shortcuts/shortcuts-hoc.js +42 -0
- package/dist/shortcuts/shortcuts.js +72 -0
- package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +123 -0
- package/dist/shortcuts-hint-ng/shortcuts-hint-ng__template.js +3 -0
- package/dist/shortcuts-ng/shortcuts-ng.js +262 -0
- package/dist/sidebar-ng/sidebar-ng.js +113 -0
- package/dist/sidebar-ng/sidebar-ng__button-template.js +3 -0
- package/dist/sidebar-ng/sidebar-ng__template.js +3 -0
- package/dist/storage/storage.js +59 -0
- package/dist/storage/storage__fallback.js +215 -0
- package/dist/storage/storage__local.js +154 -0
- package/dist/style.css +1 -0
- package/dist/tab-trap/tab-trap.js +177 -0
- package/dist/table/cell.js +26 -0
- package/dist/table/disable-hover-hoc.js +54 -0
- package/dist/table/header-cell.js +92 -0
- package/dist/table/header.js +193 -0
- package/dist/table/multitable.js +141 -0
- package/dist/table/row-with-focus-sensor.js +83 -0
- package/dist/table/row.js +278 -0
- package/dist/table/selection-adapter.js +16 -0
- package/dist/table/selection-shortcuts-hoc.js +215 -0
- package/dist/table/selection.js +223 -0
- package/dist/table/smart-table.js +125 -0
- package/dist/table/table.js +409 -0
- package/dist/table-legacy-ng/table-legacy-ng.js +468 -0
- package/dist/table-legacy-ng/table-legacy-ng__pager.js +120 -0
- package/dist/table-legacy-ng/table-legacy-ng__selection-navigate-actions.js +123 -0
- package/dist/table-legacy-ng/table-legacy-ng__selection.js +179 -0
- package/dist/table-legacy-ng/table-legacy-ng__toolbar.js +57 -0
- package/dist/table-ng/smart-table-ng.js +68 -0
- package/dist/table-ng/table-ng.js +67 -0
- package/dist/tabs/collapsible-more.js +198 -0
- package/dist/tabs/collapsible-tab.js +91 -0
- package/dist/tabs/collapsible-tabs.js +362 -0
- package/dist/tabs/custom-item.js +13 -0
- package/dist/tabs/dumb-tabs.js +164 -0
- package/dist/tabs/smart-tabs.js +106 -0
- package/dist/tabs/tab-link.js +42 -0
- package/dist/tabs/tab.js +33 -0
- package/dist/tabs/tabs.js +71 -0
- package/dist/tabs-ng/tabs-ng.js +194 -0
- package/dist/tabs-ng/tabs-ng__template.js +3 -0
- package/dist/tag/tag.js +197 -0
- package/dist/tags-input/tags-input.js +482 -0
- package/dist/tags-input-ng/tags-input-ng.js +93 -0
- package/dist/tags-list/tags-list.js +95 -0
- package/dist/template-ng/template-ng.js +71 -0
- package/dist/text/text.js +36 -0
- package/dist/theme-ng/theme-ng.js +45 -0
- package/dist/title-ng/title-ng.js +114 -0
- package/dist/toggle/toggle.js +78 -0
- package/dist/toggle-ng/toggle-ng.js +18 -0
- package/dist/tooltip/tooltip.js +209 -0
- package/dist/tooltip-ng/tooltip-ng.js +104 -0
- package/dist/user-agreement/service.js +412 -0
- package/dist/user-agreement/toolbox.eula.js +3 -0
- package/dist/user-agreement/user-agreement.js +169 -0
- package/dist/user-card/card.js +19 -0
- package/dist/user-card/smart-user-card-tooltip.js +114 -0
- package/dist/user-card/tooltip.js +95 -0
- package/dist/user-card/user-card.js +51 -0
- package/dist/user-card-ng/user-card-ng.js +62 -0
- package/package.json +2 -2
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
+
import 'core-js/modules/es.string.replace.js';
|
|
4
|
+
import React, { PureComponent } from 'react';
|
|
5
|
+
import { createPortal } from 'react-dom';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import getUID from '../global/get-uid.js';
|
|
9
|
+
import scheduleRAF from '../global/schedule-raf.js';
|
|
10
|
+
import { Listeners, getStyles } from '../global/dom.js';
|
|
11
|
+
import Shortcuts from '../shortcuts/shortcuts.js';
|
|
12
|
+
import joinDataTestAttributes from '../global/data-tests.js';
|
|
13
|
+
import TabTrap from '../tab-trap/tab-trap.js';
|
|
14
|
+
import position, { positionPropKeys } from './position.js';
|
|
15
|
+
import { Display, DEFAULT_DIRECTIONS, Directions, Dimension, MinWidth, MaxHeight } from './popup.consts.js';
|
|
16
|
+
import { PopupTargetContext, PopupTarget } from './popup.target.js';
|
|
17
|
+
export { PopupTarget, PopupTargetContext } from './popup.target.js';
|
|
18
|
+
import '../shortcuts/core.js';
|
|
19
|
+
import 'combokeys';
|
|
20
|
+
import '../global/sniffer.js';
|
|
21
|
+
import 'sniffr';
|
|
22
|
+
|
|
23
|
+
var modules_2f69e2e2 = {"popup":"popup_rui_7cd4 font_rui_8bff","hidden":"hidden_rui_7cd4","showing":"showing_rui_7cd4","attached":"attached_rui_7cd4"};
|
|
24
|
+
|
|
25
|
+
const stop = e => e.stopPropagation();
|
|
26
|
+
|
|
27
|
+
const getPopupContainer = target => typeof target === 'string' ? document.querySelector("[data-portaltarget=".concat(target, "]")) : target;
|
|
28
|
+
/**
|
|
29
|
+
* @constructor
|
|
30
|
+
* @name Popup
|
|
31
|
+
* @extends {ReactComponent}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
class Popup extends PureComponent {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "state", {
|
|
39
|
+
display: Display.SHOWING
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
_defineProperty(this, "listeners", new Listeners());
|
|
43
|
+
|
|
44
|
+
_defineProperty(this, "redrawScheduler", scheduleRAF(true));
|
|
45
|
+
|
|
46
|
+
_defineProperty(this, "uid", getUID('popup-'));
|
|
47
|
+
|
|
48
|
+
_defineProperty(this, "calculateDisplay", prevState => ({ ...prevState,
|
|
49
|
+
display: this.props.hidden ? Display.SHOWING : Display.SHOWN
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
_defineProperty(this, "portalRef", el => {
|
|
53
|
+
this.node = el;
|
|
54
|
+
this.parent = el && el.parentElement;
|
|
55
|
+
|
|
56
|
+
if (el && this.getContainer()) {
|
|
57
|
+
this._redraw();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
_defineProperty(this, "popupRef", el => {
|
|
62
|
+
this.popup = el;
|
|
63
|
+
|
|
64
|
+
this._redraw();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
_defineProperty(this, "containerRef", el => {
|
|
68
|
+
this.container = el;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
_defineProperty(this, "_updateDirection", newDirection => {
|
|
72
|
+
if (this.state.direction !== newDirection) {
|
|
73
|
+
this.setState({
|
|
74
|
+
direction: newDirection
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (this.props.onDirectionChange) {
|
|
78
|
+
this.props.onDirectionChange(newDirection);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
_defineProperty(this, "_updatePosition", () => {
|
|
84
|
+
if (this.popup) {
|
|
85
|
+
this.popup.style.position = 'absolute';
|
|
86
|
+
|
|
87
|
+
if (this.isVisible()) {
|
|
88
|
+
const {
|
|
89
|
+
styles: style,
|
|
90
|
+
direction
|
|
91
|
+
} = this.position();
|
|
92
|
+
Object.keys(style).forEach(key => {
|
|
93
|
+
const value = style[key];
|
|
94
|
+
|
|
95
|
+
if (typeof value === 'number') {
|
|
96
|
+
this.popup.style[key] = "".concat(value, "px");
|
|
97
|
+
} else {
|
|
98
|
+
this.popup.style[key] = value.toString();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
this._updateDirection(direction);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.setState(this.calculateDisplay);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
_defineProperty(this, "_redraw", () => {
|
|
110
|
+
if (this.isVisible()) {
|
|
111
|
+
this.redrawScheduler(this._updatePosition);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
_defineProperty(this, "_onEscPress", evt => {
|
|
116
|
+
this.props.onEscPress(evt);
|
|
117
|
+
|
|
118
|
+
this._onCloseAttempt(evt, true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
_defineProperty(this, "_onDocumentClick", evt => {
|
|
122
|
+
if (this.container && this.container.contains(evt.target) || !this._listenersEnabled || this.props.dontCloseOnAnchorClick && this._getAnchor() && this._getAnchor().contains(evt.target)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.props.onOutsideClick(evt);
|
|
127
|
+
|
|
128
|
+
this._onCloseAttempt(evt, false);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
_defineProperty(this, "shortcutsScope", this.uid);
|
|
132
|
+
|
|
133
|
+
_defineProperty(this, "shortcutsMap", {
|
|
134
|
+
esc: this._onEscPress
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
componentDidMount() {
|
|
139
|
+
if (!this.props.client) {
|
|
140
|
+
this.setState({
|
|
141
|
+
client: true
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!this.props.hidden) {
|
|
146
|
+
this._setListenersEnabled(true);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
componentDidUpdate(prevProps, prevState) {
|
|
151
|
+
const {
|
|
152
|
+
hidden
|
|
153
|
+
} = this.props;
|
|
154
|
+
|
|
155
|
+
if (this.props !== prevProps) {
|
|
156
|
+
if (prevProps.hidden !== hidden) {
|
|
157
|
+
this._setListenersEnabled(!hidden);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._redraw();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (this.props.onShow && !hidden && this.state.display === Display.SHOWN && (prevProps.hidden || prevState.display !== Display.SHOWN)) {
|
|
164
|
+
this.props.onShow();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
componentWillUnmount() {
|
|
169
|
+
this._setListenersEnabled(false);
|
|
170
|
+
|
|
171
|
+
this.popup = null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
shouldUseShortcuts() {
|
|
175
|
+
const {
|
|
176
|
+
shortcuts,
|
|
177
|
+
hidden
|
|
178
|
+
} = this.props;
|
|
179
|
+
return shortcuts && !hidden;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getContainer() {
|
|
183
|
+
const target = this.props.target || this.ringPopupTarget;
|
|
184
|
+
return target && getPopupContainer(target);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
position() {
|
|
188
|
+
const positionProps = positionPropKeys.reduce((acc, key) => {
|
|
189
|
+
acc[key] = this.props[key];
|
|
190
|
+
return acc;
|
|
191
|
+
}, {});
|
|
192
|
+
const container = this.getContainer();
|
|
193
|
+
return position({
|
|
194
|
+
popup: this.popup,
|
|
195
|
+
container: container && getStyles(container).position !== 'static' ? container : null,
|
|
196
|
+
anchor: this._getAnchor(),
|
|
197
|
+
...positionProps
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_getAnchor() {
|
|
202
|
+
return this.props.anchorElement || this.parent;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @param {boolean} enable
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
_setListenersEnabled(enable) {
|
|
211
|
+
if (enable && !this._listenersEnabled) {
|
|
212
|
+
setTimeout(() => {
|
|
213
|
+
this._listenersEnabled = true;
|
|
214
|
+
this.listeners.add(window, 'resize', this._redraw);
|
|
215
|
+
|
|
216
|
+
if (this.props.autoPositioningOnScroll) {
|
|
217
|
+
this.listeners.add(window, 'scroll', this._redraw);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.listeners.add(document, 'pointerdown', this._onDocumentClick, true);
|
|
221
|
+
|
|
222
|
+
let el = this._getAnchor();
|
|
223
|
+
|
|
224
|
+
while (el) {
|
|
225
|
+
this.listeners.add(el, 'scroll', this._redraw);
|
|
226
|
+
el = el.parentElement;
|
|
227
|
+
}
|
|
228
|
+
}, 0);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!enable && this._listenersEnabled) {
|
|
233
|
+
this.listeners.removeAll();
|
|
234
|
+
this._listenersEnabled = false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns visibility state
|
|
239
|
+
* @return {boolean}
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
isVisible() {
|
|
244
|
+
return !this.props.hidden;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
_onCloseAttempt(evt, isEsc) {
|
|
248
|
+
this.props.onCloseAttempt(evt, isEsc);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
getInternalContent() {
|
|
252
|
+
const {
|
|
253
|
+
trapFocus,
|
|
254
|
+
autoFocusFirst,
|
|
255
|
+
children
|
|
256
|
+
} = this.props;
|
|
257
|
+
return trapFocus ? /*#__PURE__*/React.createElement(TabTrap, {
|
|
258
|
+
autoFocusFirst: autoFocusFirst,
|
|
259
|
+
focusBackOnExit: true
|
|
260
|
+
}, children) : children;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
render() {
|
|
264
|
+
const {
|
|
265
|
+
className,
|
|
266
|
+
style,
|
|
267
|
+
hidden,
|
|
268
|
+
attached,
|
|
269
|
+
keepMounted,
|
|
270
|
+
client,
|
|
271
|
+
onMouseDown,
|
|
272
|
+
onMouseUp,
|
|
273
|
+
onMouseOver,
|
|
274
|
+
onMouseOut,
|
|
275
|
+
onContextMenu,
|
|
276
|
+
'data-test': dataTest
|
|
277
|
+
} = this.props;
|
|
278
|
+
const showing = this.state.display === Display.SHOWING;
|
|
279
|
+
const classes = classNames(className, modules_2f69e2e2.popup, {
|
|
280
|
+
[modules_2f69e2e2.attached]: attached,
|
|
281
|
+
[modules_2f69e2e2.hidden]: hidden,
|
|
282
|
+
[modules_2f69e2e2.showing]: showing
|
|
283
|
+
});
|
|
284
|
+
const direction = (this.state.direction || '').toLowerCase().replace(/[_]/g, '-');
|
|
285
|
+
return /*#__PURE__*/React.createElement(PopupTargetContext.Consumer, null, value => {
|
|
286
|
+
this.ringPopupTarget = value;
|
|
287
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
288
|
+
// prevent bubbling through portal
|
|
289
|
+
onClick: stop // This handler only blocks bubbling through React portal
|
|
290
|
+
,
|
|
291
|
+
role: "presentation",
|
|
292
|
+
ref: this.portalRef
|
|
293
|
+
}, this.shouldUseShortcuts() && /*#__PURE__*/React.createElement(Shortcuts, {
|
|
294
|
+
map: this.shortcutsMap,
|
|
295
|
+
scope: this.shortcutsScope
|
|
296
|
+
}), (client || this.state.client) && (keepMounted || !hidden) && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(PopupTarget, {
|
|
297
|
+
id: this.uid,
|
|
298
|
+
ref: this.containerRef,
|
|
299
|
+
onMouseOver: onMouseOver,
|
|
300
|
+
onFocus: onMouseOver,
|
|
301
|
+
onMouseOut: onMouseOut,
|
|
302
|
+
onBlur: onMouseOut,
|
|
303
|
+
onContextMenu: onContextMenu
|
|
304
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
305
|
+
"data-test": joinDataTestAttributes('ring-popup', dataTest),
|
|
306
|
+
"data-test-shown": !hidden && !showing,
|
|
307
|
+
"data-test-direction": direction,
|
|
308
|
+
ref: this.popupRef,
|
|
309
|
+
className: classes,
|
|
310
|
+
style: style,
|
|
311
|
+
onMouseDown: onMouseDown,
|
|
312
|
+
onMouseUp: onMouseUp // mouse handlers are used to track clicking on inner elements
|
|
313
|
+
,
|
|
314
|
+
role: "presentation"
|
|
315
|
+
}, this.getInternalContent())), this.getContainer() || document.body));
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
_defineProperty(Popup, "propTypes", {
|
|
322
|
+
anchorElement: PropTypes.instanceOf(Node),
|
|
323
|
+
target: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Element)]),
|
|
324
|
+
className: PropTypes.string,
|
|
325
|
+
style: PropTypes.object,
|
|
326
|
+
hidden: PropTypes.bool.isRequired,
|
|
327
|
+
onOutsideClick: PropTypes.func,
|
|
328
|
+
onEscPress: PropTypes.func,
|
|
329
|
+
// onCloseAttempt is a common callback for ESC pressing and outside clicking.
|
|
330
|
+
// Use it if you don't need different behaviors for this cases.
|
|
331
|
+
onCloseAttempt: PropTypes.func,
|
|
332
|
+
children: PropTypes.node.isRequired,
|
|
333
|
+
dontCloseOnAnchorClick: PropTypes.bool,
|
|
334
|
+
shortcuts: PropTypes.bool,
|
|
335
|
+
keepMounted: PropTypes.bool,
|
|
336
|
+
// pass this prop to preserve the popup's DOM state while hidden
|
|
337
|
+
'data-test': PropTypes.string,
|
|
338
|
+
client: PropTypes.bool,
|
|
339
|
+
// true means that it's never used in SSR
|
|
340
|
+
directions: PropTypes.arrayOf(PropTypes.string),
|
|
341
|
+
autoPositioning: PropTypes.bool,
|
|
342
|
+
autoPositioningOnScroll: PropTypes.bool,
|
|
343
|
+
autoCorrectTopOverflow: PropTypes.bool,
|
|
344
|
+
left: PropTypes.number,
|
|
345
|
+
top: PropTypes.number,
|
|
346
|
+
maxHeight: PropTypes.number,
|
|
347
|
+
minWidth: PropTypes.number,
|
|
348
|
+
sidePadding: PropTypes.number,
|
|
349
|
+
attached: PropTypes.bool,
|
|
350
|
+
// Popup adjacent to an input, without upper border and shadow
|
|
351
|
+
onMouseDown: PropTypes.func,
|
|
352
|
+
onMouseUp: PropTypes.func,
|
|
353
|
+
onMouseOver: PropTypes.func,
|
|
354
|
+
onMouseOut: PropTypes.func,
|
|
355
|
+
onContextMenu: PropTypes.func,
|
|
356
|
+
onDirectionChange: PropTypes.func,
|
|
357
|
+
onShow: PropTypes.func,
|
|
358
|
+
// set to true whenever popup contains focusable and scrollable content
|
|
359
|
+
trapFocus: PropTypes.bool,
|
|
360
|
+
autoFocusFirst: PropTypes.bool
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
_defineProperty(Popup, "defaultProps", {
|
|
364
|
+
shortcuts: true,
|
|
365
|
+
hidden: false,
|
|
366
|
+
|
|
367
|
+
onOutsideClick() {},
|
|
368
|
+
|
|
369
|
+
onEscPress() {},
|
|
370
|
+
|
|
371
|
+
onCloseAttempt() {},
|
|
372
|
+
|
|
373
|
+
dontCloseOnAnchorClick: false,
|
|
374
|
+
keepMounted: false,
|
|
375
|
+
directions: DEFAULT_DIRECTIONS,
|
|
376
|
+
autoPositioning: true,
|
|
377
|
+
autoPositioningOnScroll: true,
|
|
378
|
+
autoCorrectTopOverflow: true,
|
|
379
|
+
left: 0,
|
|
380
|
+
top: 0,
|
|
381
|
+
offset: 0,
|
|
382
|
+
sidePadding: 8,
|
|
383
|
+
attached: false,
|
|
384
|
+
trapFocus: false,
|
|
385
|
+
autoFocusFirst: false,
|
|
386
|
+
legacy: false
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
_defineProperty(Popup, "PopupProps", {
|
|
390
|
+
Directions,
|
|
391
|
+
Dimension,
|
|
392
|
+
MinWidth,
|
|
393
|
+
MaxHeight
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
export { Popup as default, getPopupContainer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { a as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React, { createContext, forwardRef } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
const PopupTargetContext = /*#__PURE__*/createContext();
|
|
6
|
+
const PopupTarget = /*#__PURE__*/forwardRef(function PopupTarget(_ref, ref) {
|
|
7
|
+
let {
|
|
8
|
+
id,
|
|
9
|
+
children,
|
|
10
|
+
...restProps
|
|
11
|
+
} = _ref;
|
|
12
|
+
const isFunctionChild = typeof children === 'function';
|
|
13
|
+
const target = /*#__PURE__*/React.createElement("div", _extends({}, restProps, {
|
|
14
|
+
"data-portaltarget": id,
|
|
15
|
+
ref: ref
|
|
16
|
+
}), !isFunctionChild && children);
|
|
17
|
+
return /*#__PURE__*/React.createElement(PopupTargetContext.Provider, {
|
|
18
|
+
value: id
|
|
19
|
+
}, isFunctionChild ? children(target) : target);
|
|
20
|
+
});
|
|
21
|
+
PopupTarget.propTypes = {
|
|
22
|
+
id: PropTypes.string.isRequired,
|
|
23
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { PopupTarget, PopupTargetContext };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { getRect, isMounted, getDocumentScrollTop, getDocumentScrollLeft, getWindowHeight } from '../global/dom.js';
|
|
2
|
+
import { Directions, MaxHeight, Dimension, MinWidth } from './popup.consts.js';
|
|
3
|
+
export { Dimension, Directions, MaxHeight, MinWidth } from './popup.consts.js';
|
|
4
|
+
import '../_helpers/_rollupPluginBabelHelpers.js';
|
|
5
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
6
|
+
|
|
7
|
+
function getScrollingCoordinates(container) {
|
|
8
|
+
if (container !== null) {
|
|
9
|
+
return {
|
|
10
|
+
top: container.scrollTop,
|
|
11
|
+
left: container.scrollLeft
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
top: getDocumentScrollTop(),
|
|
17
|
+
left: getDocumentScrollLeft()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getPositionStyles(popup, anchorRect, anchorLeft, anchorTop, offset) {
|
|
22
|
+
const popupWidth = popup.clientWidth;
|
|
23
|
+
const popupHeight = popup.clientHeight;
|
|
24
|
+
const anchorBottom = anchorTop + anchorRect.height;
|
|
25
|
+
const anchorRight = anchorLeft + anchorRect.width;
|
|
26
|
+
const popupLeft = anchorLeft - popupWidth;
|
|
27
|
+
const popupTop = anchorTop - popupHeight;
|
|
28
|
+
const popupRightToLeft = anchorRight - popupWidth;
|
|
29
|
+
const popupHorizontalCenter = anchorLeft + anchorRect.width / 2 - popupWidth / 2;
|
|
30
|
+
const popupVerticalCenter = anchorTop + anchorRect.height / 2 - popupHeight / 2;
|
|
31
|
+
const popupBottomToTop = anchorBottom - popupHeight;
|
|
32
|
+
return {
|
|
33
|
+
[Directions.BOTTOM_RIGHT]: {
|
|
34
|
+
left: anchorLeft,
|
|
35
|
+
top: anchorBottom + offset
|
|
36
|
+
},
|
|
37
|
+
[Directions.BOTTOM_LEFT]: {
|
|
38
|
+
left: popupRightToLeft,
|
|
39
|
+
top: anchorBottom + offset
|
|
40
|
+
},
|
|
41
|
+
[Directions.BOTTOM_CENTER]: {
|
|
42
|
+
left: popupHorizontalCenter,
|
|
43
|
+
top: anchorBottom + offset
|
|
44
|
+
},
|
|
45
|
+
[Directions.TOP_RIGHT]: {
|
|
46
|
+
left: anchorLeft,
|
|
47
|
+
top: popupTop - offset
|
|
48
|
+
},
|
|
49
|
+
[Directions.TOP_LEFT]: {
|
|
50
|
+
left: popupRightToLeft,
|
|
51
|
+
top: popupTop - offset
|
|
52
|
+
},
|
|
53
|
+
[Directions.TOP_CENTER]: {
|
|
54
|
+
left: popupHorizontalCenter,
|
|
55
|
+
top: popupTop - offset
|
|
56
|
+
},
|
|
57
|
+
[Directions.LEFT_BOTTOM]: {
|
|
58
|
+
left: popupLeft - offset,
|
|
59
|
+
top: anchorTop
|
|
60
|
+
},
|
|
61
|
+
[Directions.LEFT_TOP]: {
|
|
62
|
+
left: popupLeft - offset,
|
|
63
|
+
top: popupBottomToTop
|
|
64
|
+
},
|
|
65
|
+
[Directions.LEFT_CENTER]: {
|
|
66
|
+
left: popupLeft - offset,
|
|
67
|
+
top: popupVerticalCenter
|
|
68
|
+
},
|
|
69
|
+
[Directions.RIGHT_BOTTOM]: {
|
|
70
|
+
left: anchorRight + offset,
|
|
71
|
+
top: anchorTop
|
|
72
|
+
},
|
|
73
|
+
[Directions.RIGHT_TOP]: {
|
|
74
|
+
left: anchorRight + offset,
|
|
75
|
+
top: popupBottomToTop
|
|
76
|
+
},
|
|
77
|
+
[Directions.RIGHT_CENTER]: {
|
|
78
|
+
left: anchorRight + offset,
|
|
79
|
+
top: popupVerticalCenter
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function verticalOverflow(styles, scrollingCoordinates, attrs) {
|
|
85
|
+
const containerHeight = attrs.container !== null ? attrs.container.clientHeight : getWindowHeight();
|
|
86
|
+
const viewportMinX = scrollingCoordinates.top + attrs.sidePadding;
|
|
87
|
+
const viewportMaxX = scrollingCoordinates.top + containerHeight - attrs.sidePadding;
|
|
88
|
+
const topOverflow = Math.max(viewportMinX - styles.top, 0);
|
|
89
|
+
const popupHeight = attrs.popup.clientHeight;
|
|
90
|
+
const verticalDiff = styles.top + popupHeight - viewportMaxX;
|
|
91
|
+
const bottomOverflow = Math.max(verticalDiff, 0);
|
|
92
|
+
return topOverflow + bottomOverflow;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function horizontalOverflow(styles, scrollingCoordinates, attrs) {
|
|
96
|
+
const containerWidth = attrs.container !== null ? attrs.container.clientWidth : window.innerWidth;
|
|
97
|
+
const viewportMinY = scrollingCoordinates.left + attrs.sidePadding;
|
|
98
|
+
const viewportMaxY = scrollingCoordinates.left + containerWidth - attrs.sidePadding;
|
|
99
|
+
const leftOverflow = Math.max(viewportMinY - styles.left, 0);
|
|
100
|
+
const popupWidth = attrs.popup.clientWidth;
|
|
101
|
+
const horizontalDiff = styles.left + popupWidth - viewportMaxY;
|
|
102
|
+
const rightOverflow = Math.max(horizontalDiff, 0);
|
|
103
|
+
return leftOverflow + rightOverflow;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const positionPropKeys = ['directions', 'autoPositioning', 'autoCorrectTopOverflow', 'sidePadding', 'top', 'left', 'offset', 'maxHeight', 'minWidth'];
|
|
107
|
+
const defaultcontainerRect = {
|
|
108
|
+
top: 0,
|
|
109
|
+
left: 0
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function handleTopOffScreen(_ref) {
|
|
113
|
+
let {
|
|
114
|
+
sidePadding,
|
|
115
|
+
styles,
|
|
116
|
+
anchorRect,
|
|
117
|
+
maxHeight,
|
|
118
|
+
popupScrollHeight,
|
|
119
|
+
direction,
|
|
120
|
+
scroll
|
|
121
|
+
} = _ref;
|
|
122
|
+
const BORDER_COMPENSATION = 1;
|
|
123
|
+
const {
|
|
124
|
+
TOP_LEFT,
|
|
125
|
+
TOP_RIGHT,
|
|
126
|
+
TOP_CENTER,
|
|
127
|
+
RIGHT_TOP,
|
|
128
|
+
LEFT_TOP
|
|
129
|
+
} = Directions;
|
|
130
|
+
const openedToTop = [TOP_LEFT, TOP_RIGHT, TOP_CENTER, RIGHT_TOP, LEFT_TOP].includes(direction);
|
|
131
|
+
|
|
132
|
+
if (!openedToTop) {
|
|
133
|
+
return styles;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const isAttachedToAnchorTop = [TOP_LEFT, TOP_CENTER, TOP_RIGHT].includes(direction);
|
|
137
|
+
const attachingPointY = isAttachedToAnchorTop ? anchorRect.top : anchorRect.bottom;
|
|
138
|
+
const effectiveHeight = maxHeight ? Math.min(popupScrollHeight, maxHeight) : popupScrollHeight;
|
|
139
|
+
const hypotheticalTop = attachingPointY - effectiveHeight;
|
|
140
|
+
|
|
141
|
+
if (hypotheticalTop <= sidePadding) {
|
|
142
|
+
styles.top = sidePadding + scroll.top;
|
|
143
|
+
styles.maxHeight = attachingPointY - sidePadding + BORDER_COMPENSATION;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return styles;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function maxHeightForDirection(direction, anchorNode, containerNode) {
|
|
150
|
+
const container = containerNode || document.documentElement;
|
|
151
|
+
const domRect = anchorNode.getBoundingClientRect();
|
|
152
|
+
const containerRect = container.getBoundingClientRect();
|
|
153
|
+
const topMaxHeight = Math.max(domRect.top - containerRect.top, 0);
|
|
154
|
+
const containerHeight = Math.max(containerRect.height, // XXX
|
|
155
|
+
// If container is the document element
|
|
156
|
+
// then we check client height too because we may have situation when
|
|
157
|
+
// "height" from "getBoundingClientRect" less then "clientHeight".
|
|
158
|
+
container === document.documentElement ? container.clientHeight : 0);
|
|
159
|
+
const bottomMaxHeight = Math.max(containerHeight - (topMaxHeight + domRect.height), 0);
|
|
160
|
+
|
|
161
|
+
switch (direction) {
|
|
162
|
+
case Directions.TOP_LEFT:
|
|
163
|
+
case Directions.TOP_CENTER:
|
|
164
|
+
case Directions.TOP_RIGHT:
|
|
165
|
+
return topMaxHeight;
|
|
166
|
+
|
|
167
|
+
case Directions.BOTTOM_LEFT:
|
|
168
|
+
case Directions.BOTTOM_CENTER:
|
|
169
|
+
case Directions.BOTTOM_RIGHT:
|
|
170
|
+
return bottomMaxHeight;
|
|
171
|
+
|
|
172
|
+
case Directions.LEFT_BOTTOM:
|
|
173
|
+
case Directions.RIGHT_BOTTOM:
|
|
174
|
+
return domRect.height + bottomMaxHeight;
|
|
175
|
+
|
|
176
|
+
case Directions.LEFT_TOP:
|
|
177
|
+
case Directions.RIGHT_TOP:
|
|
178
|
+
return domRect.height + topMaxHeight;
|
|
179
|
+
|
|
180
|
+
case Directions.RIGHT_CENTER:
|
|
181
|
+
case Directions.LEFT_CENTER:
|
|
182
|
+
return domRect.height / 2 + Math.min(bottomMaxHeight / 2, topMaxHeight / 2);
|
|
183
|
+
|
|
184
|
+
default:
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function position(attrs) {
|
|
189
|
+
const {
|
|
190
|
+
popup,
|
|
191
|
+
anchor,
|
|
192
|
+
container,
|
|
193
|
+
directions,
|
|
194
|
+
autoPositioning,
|
|
195
|
+
sidePadding,
|
|
196
|
+
top,
|
|
197
|
+
left,
|
|
198
|
+
offset,
|
|
199
|
+
maxHeight,
|
|
200
|
+
minWidth,
|
|
201
|
+
autoCorrectTopOverflow = true
|
|
202
|
+
} = attrs;
|
|
203
|
+
let styles = {
|
|
204
|
+
top: 0,
|
|
205
|
+
left: 0
|
|
206
|
+
};
|
|
207
|
+
let chosenDirection = null;
|
|
208
|
+
const containerRect = container !== null ? getRect(container) : defaultcontainerRect;
|
|
209
|
+
const defaultAnchor = container !== null ? container : document.body;
|
|
210
|
+
const anchorRect = getRect(isMounted(anchor) ? anchor : defaultAnchor);
|
|
211
|
+
const scroll = getScrollingCoordinates(container);
|
|
212
|
+
const anchorLeft = anchorRect.left + scroll.left + left - containerRect.left;
|
|
213
|
+
const anchorTop = anchorRect.top + scroll.top + top - containerRect.top;
|
|
214
|
+
|
|
215
|
+
if (popup) {
|
|
216
|
+
const directionsMatrix = getPositionStyles(popup, anchorRect, anchorLeft, anchorTop, offset);
|
|
217
|
+
|
|
218
|
+
if (!autoPositioning || directions.length === 1) {
|
|
219
|
+
styles = directionsMatrix[directions[0]];
|
|
220
|
+
chosenDirection = directions[0];
|
|
221
|
+
} else {
|
|
222
|
+
const sortedByIncreasingOverflow = directions. // Fall back to the first option
|
|
223
|
+
concat(directions[0]).filter(direction => directionsMatrix[direction]).map(direction => ({
|
|
224
|
+
styles: directionsMatrix[direction],
|
|
225
|
+
direction
|
|
226
|
+
})).sort((_ref2, _ref3) => {
|
|
227
|
+
let {
|
|
228
|
+
styles: stylesA
|
|
229
|
+
} = _ref2;
|
|
230
|
+
let {
|
|
231
|
+
styles: stylesB
|
|
232
|
+
} = _ref3;
|
|
233
|
+
const overflowA = verticalOverflow(stylesA, scroll, attrs) + horizontalOverflow(stylesA, scroll, attrs);
|
|
234
|
+
const overflowB = verticalOverflow(stylesB, scroll, attrs) + horizontalOverflow(stylesB, scroll, attrs);
|
|
235
|
+
return overflowA - overflowB;
|
|
236
|
+
});
|
|
237
|
+
styles = sortedByIncreasingOverflow[0].styles;
|
|
238
|
+
chosenDirection = sortedByIncreasingOverflow[0].direction;
|
|
239
|
+
} // because of the anchor negative margin top and left also may become negative
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
['left', 'top'].forEach(key => {
|
|
243
|
+
if (styles[key] < 0) {
|
|
244
|
+
styles[key] = 0;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (maxHeight === MaxHeight.SCREEN || maxHeight === 'screen') {
|
|
250
|
+
// this feature works properly only when direction is BOTTOM_* or *_BOTTOM
|
|
251
|
+
styles.maxHeight = window.innerHeight + scroll.top - styles.top - Dimension.MARGIN;
|
|
252
|
+
} else if (maxHeight) {
|
|
253
|
+
styles.maxHeight = maxHeight;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (autoCorrectTopOverflow) {
|
|
257
|
+
styles = handleTopOffScreen({
|
|
258
|
+
sidePadding,
|
|
259
|
+
styles,
|
|
260
|
+
anchorRect,
|
|
261
|
+
maxHeight,
|
|
262
|
+
direction: chosenDirection,
|
|
263
|
+
popupScrollHeight: popup.scrollHeight,
|
|
264
|
+
scroll
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (minWidth === MinWidth.TARGET || minWidth === 'target') {
|
|
269
|
+
styles.minWidth = anchorRect.width;
|
|
270
|
+
} else if (minWidth) {
|
|
271
|
+
styles.minWidth = anchorRect.width < minWidth ? minWidth : anchorRect.width;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
styles,
|
|
276
|
+
direction: chosenDirection
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export { position as default, maxHeightForDirection, positionPropKeys };
|