@megafon/ui-core 9.3.0 → 9.4.0
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/dist/es/components/Modal/Modal.js +27 -3
- package/dist/es/components/Modal/_ModalMobile/ModalMobile.css +1 -1
- package/dist/es/components/Modal/_ModalMobile/ModalMobile.d.ts +1 -0
- package/dist/es/components/Modal/_ModalMobile/ModalMobile.js +9 -4
- package/dist/es/components/Modal/utils/usePreventScroll.d.ts +17 -0
- package/dist/es/components/Modal/utils/usePreventScroll.js +252 -0
- package/dist/es/components/Modal/utils/utils.d.ts +1 -0
- package/dist/es/components/Modal/utils/utils.js +3 -2
- package/dist/es/hooks/useEvent.d.ts +3 -0
- package/dist/es/hooks/useEvent.js +11 -0
- package/dist/es/hooks/useLatest.d.ts +2 -0
- package/dist/es/hooks/useLatest.js +8 -0
- package/dist/es/hooks/useVisualViewport.d.ts +10 -0
- package/dist/es/hooks/useVisualViewport.js +55 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/utils/browser.d.ts +7 -0
- package/dist/es/utils/browser.js +30 -0
- package/dist/es/utils/is.d.ts +19 -0
- package/dist/es/utils/is.js +70 -0
- package/dist/lib/components/Modal/Modal.js +27 -3
- package/dist/lib/components/Modal/_ModalMobile/ModalMobile.css +1 -1
- package/dist/lib/components/Modal/_ModalMobile/ModalMobile.d.ts +1 -0
- package/dist/lib/components/Modal/_ModalMobile/ModalMobile.js +9 -4
- package/dist/lib/components/Modal/utils/usePreventScroll.d.ts +17 -0
- package/dist/lib/components/Modal/utils/usePreventScroll.js +263 -0
- package/dist/lib/components/Modal/utils/utils.d.ts +1 -0
- package/dist/lib/components/Modal/utils/utils.js +3 -2
- package/dist/lib/hooks/useEvent.d.ts +3 -0
- package/dist/lib/hooks/useEvent.js +17 -0
- package/dist/lib/hooks/useLatest.d.ts +2 -0
- package/dist/lib/hooks/useLatest.js +14 -0
- package/dist/lib/hooks/useVisualViewport.d.ts +10 -0
- package/dist/lib/hooks/useVisualViewport.js +62 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/utils/browser.d.ts +7 -0
- package/dist/lib/utils/browser.js +42 -0
- package/dist/lib/utils/is.d.ts +19 -0
- package/dist/lib/utils/is.js +92 -0
- package/package.json +2 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import "core-js/modules/es.array.is-array.js";
|
|
3
|
+
import "core-js/modules/es.date.to-string.js";
|
|
4
|
+
import "core-js/modules/es.number.constructor.js";
|
|
5
|
+
import "core-js/modules/es.number.is-finite.js";
|
|
6
|
+
import "core-js/modules/es.number.is-nan.js";
|
|
7
|
+
import "core-js/modules/es.object.keys.js";
|
|
8
|
+
import "core-js/modules/es.object.to-string.js";
|
|
9
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
10
|
+
import "core-js/modules/es.regexp.test.js";
|
|
11
|
+
import "core-js/modules/es.regexp.to-string.js";
|
|
12
|
+
export function isNumber(value) {
|
|
13
|
+
return typeof value === 'number';
|
|
14
|
+
}
|
|
15
|
+
export function isInteger(v) {
|
|
16
|
+
var value = Number(v);
|
|
17
|
+
return typeof value === 'number' && !Number.isNaN(value) && Number.isFinite(value) && Math.floor(value) === value;
|
|
18
|
+
}
|
|
19
|
+
export function isArray(value) {
|
|
20
|
+
return Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
export function isEmptyArray(value) {
|
|
23
|
+
return isArray(value) && value.length === 0;
|
|
24
|
+
}
|
|
25
|
+
export function isFunction(value) {
|
|
26
|
+
return typeof value === 'function';
|
|
27
|
+
}
|
|
28
|
+
export function isDefined(value) {
|
|
29
|
+
return typeof value !== 'undefined' && value !== undefined;
|
|
30
|
+
}
|
|
31
|
+
export function isUndefined(value) {
|
|
32
|
+
return typeof value === 'undefined' || value === undefined;
|
|
33
|
+
}
|
|
34
|
+
export function isObject(value) {
|
|
35
|
+
var type = _typeof(value);
|
|
36
|
+
return value != null && (type === 'object' || type === 'function') && !isArray(value);
|
|
37
|
+
}
|
|
38
|
+
export function isEmptyObject(value) {
|
|
39
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
40
|
+
}
|
|
41
|
+
export function isNull(value) {
|
|
42
|
+
return value === null;
|
|
43
|
+
}
|
|
44
|
+
export function isString(value) {
|
|
45
|
+
return Object.prototype.toString.call(value) === '[object String]';
|
|
46
|
+
}
|
|
47
|
+
export function isCssVar(value) {
|
|
48
|
+
return /^var\(--.+\)$/.test(value);
|
|
49
|
+
}
|
|
50
|
+
export function isEmpty(value) {
|
|
51
|
+
if (isArray(value)) {
|
|
52
|
+
return isEmptyArray(value);
|
|
53
|
+
}
|
|
54
|
+
if (isObject(value)) {
|
|
55
|
+
return isEmptyObject(value);
|
|
56
|
+
}
|
|
57
|
+
if (value == null || value === '') {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
export var isBoolean = function isBoolean(value) {
|
|
63
|
+
return typeof value === 'boolean';
|
|
64
|
+
};
|
|
65
|
+
export var isTruthy = function isTruthy(value) {
|
|
66
|
+
return Boolean(value);
|
|
67
|
+
};
|
|
68
|
+
export var isHTMLElement = function isHTMLElement(value) {
|
|
69
|
+
return value instanceof HTMLElement;
|
|
70
|
+
};
|
|
@@ -12,10 +12,14 @@ var _uiHelpers = require("@megafon/ui-helpers");
|
|
|
12
12
|
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
13
13
|
var _reactModal = _interopRequireDefault(require("react-modal"));
|
|
14
14
|
var _throttleTime = _interopRequireDefault(require("../../constants/throttleTime"));
|
|
15
|
+
var _useEvent = require("../../hooks/useEvent");
|
|
15
16
|
var _usePrevious = _interopRequireDefault(require("../../hooks/usePrevious"));
|
|
16
17
|
var _useResolution2 = _interopRequireDefault(require("../../hooks/useResolution"));
|
|
18
|
+
var _useVisualViewport2 = _interopRequireDefault(require("../../hooks/useVisualViewport"));
|
|
19
|
+
var _browser = require("../../utils/browser");
|
|
17
20
|
var _ModalDesktop = _interopRequireDefault(require("./_ModalDesktop/ModalDesktop"));
|
|
18
21
|
var _ModalMobile = _interopRequireDefault(require("./_ModalMobile/ModalMobile"));
|
|
22
|
+
var _usePreventScroll = _interopRequireDefault(require("./utils/usePreventScroll"));
|
|
19
23
|
var _utils = require("./utils/utils");
|
|
20
24
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
21
25
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
@@ -106,6 +110,18 @@ var Modal = function Modal(_ref) {
|
|
|
106
110
|
var resizeObserver = React.useRef(null);
|
|
107
111
|
var _useResolution = (0, _useResolution2["default"])(),
|
|
108
112
|
isMobile = _useResolution.isMobile;
|
|
113
|
+
var _useVisualViewport = (0, _useVisualViewport2["default"])({
|
|
114
|
+
enabled: isOpened && (0, _browser.isIOS)(),
|
|
115
|
+
onChange: function onChange(metrics) {
|
|
116
|
+
document.documentElement.style.setProperty('--keyboard-offset', "".concat(metrics.keyboardOffset, "px"));
|
|
117
|
+
document.documentElement.style.setProperty('--viewport-height', "".concat(metrics.viewportHeight, "px"));
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
isKeyboardOpen = _useVisualViewport.isKeyboardOpen,
|
|
121
|
+
viewportHeight = _useVisualViewport.viewportHeight;
|
|
122
|
+
(0, _usePreventScroll["default"])({
|
|
123
|
+
isDisabled: !isOpened
|
|
124
|
+
});
|
|
109
125
|
var isFullScreenView = mobileView === 'fullScreen' && isMobile;
|
|
110
126
|
var isBottomView = mobileView === 'bottom' && isMobile;
|
|
111
127
|
var isBottomTransitionIn = transitionStep !== MODAL_TRANSITIONS_STEPS_ENUM.END_STEP && transitionStep !== MODAL_TRANSITIONS_STEPS_ENUM.MOVE_END_STEP;
|
|
@@ -130,7 +146,7 @@ var Modal = function Modal(_ref) {
|
|
|
130
146
|
overlayRef.current = node;
|
|
131
147
|
getModalOverlayRef === null || getModalOverlayRef === void 0 ? void 0 : getModalOverlayRef(node);
|
|
132
148
|
};
|
|
133
|
-
var handleSetScrollContentMaxHeight =
|
|
149
|
+
var handleSetScrollContentMaxHeight = (0, _useEvent.useEvent)(function () {
|
|
134
150
|
var correctMaxHeight = (0, _utils.getCorrectMaxHeight)({
|
|
135
151
|
refs: {
|
|
136
152
|
overlayNode: overlayRef.current,
|
|
@@ -141,11 +157,12 @@ var Modal = function Modal(_ref) {
|
|
|
141
157
|
props: {
|
|
142
158
|
isStickyFooter: isStickyFooter,
|
|
143
159
|
isBottomView: isBottomView,
|
|
144
|
-
isStickyHeader: isStickyHeader
|
|
160
|
+
isStickyHeader: isStickyHeader,
|
|
161
|
+
availableHeight: isBottomView && (0, _browser.isIOS)() && viewportHeight ? viewportHeight : undefined
|
|
145
162
|
}
|
|
146
163
|
});
|
|
147
164
|
setScrollMaxHeight(correctMaxHeight);
|
|
148
|
-
}
|
|
165
|
+
});
|
|
149
166
|
var handleSetContainerWrapHeight = React.useCallback(function () {
|
|
150
167
|
var containerInnerNode = containerInnerRef.current;
|
|
151
168
|
if (!containerInnerNode) {
|
|
@@ -246,6 +263,12 @@ var Modal = function Modal(_ref) {
|
|
|
246
263
|
}
|
|
247
264
|
handleSetScrollContentMaxHeight();
|
|
248
265
|
}, [isMobile, isChangeMobileView, handleSetScrollContentMaxHeight]);
|
|
266
|
+
React.useEffect(function () {
|
|
267
|
+
if (!isOpened || !isMobile || !isBottomView || !(0, _browser.isIOS)()) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
handleSetScrollContentMaxHeight();
|
|
271
|
+
}, [isOpened, isMobile, isBottomView, viewportHeight, handleSetScrollContentMaxHeight]);
|
|
249
272
|
React.useEffect(function () {
|
|
250
273
|
if (isEnabledNativeScroll || !(isRecalculateHeight && (isHeaderPropsDiff || isFooterPropsDiff))) {
|
|
251
274
|
return;
|
|
@@ -306,6 +329,7 @@ var Modal = function Modal(_ref) {
|
|
|
306
329
|
return /*#__PURE__*/React.createElement(_ModalDesktop["default"], contextProps, children);
|
|
307
330
|
}
|
|
308
331
|
return /*#__PURE__*/React.createElement(_ModalMobile["default"], (0, _extends2["default"])({}, contextProps, {
|
|
332
|
+
isKeyboardOpen: isKeyboardOpen,
|
|
309
333
|
isSwipeDisabled: isSwipeDisabled,
|
|
310
334
|
isFullView: isFullScreenView,
|
|
311
335
|
onChangeTransitionStep: handleChangeTransitionStep,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
h1,h2,h3,h4,h5{margin:0}.mfui-9-modal-mobile{width:100%}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__container-wrap{display:block;height:calc(var(--vh)*100 -
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-9-modal-mobile{--top-offset:72px;width:100%}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__container-wrap{display:block;height:calc(var(--vh, 1vh)*100 - var(--top-offset));width:100%}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__container-inner{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;height:100%}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__container-body{-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1;overflow-y:auto}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__children{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;height:100%}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__children-content{-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1}.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__scroll-content,.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__scroll-init,.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__scroll-root{height:100%}.mfui-9-modal-mobile__container-wrap{bottom:0;display:-webkit-box;display:-ms-flexbox;display:flex;position:fixed;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:end;-ms-flex-pack:end;-webkit-animation:show-popup-from-bottom .3s linear;animation:show-popup-from-bottom .3s linear;height:auto;justify-content:flex-end;max-height:100%;overflow:hidden;-webkit-transition:-webkit-transform .3s;transition:-webkit-transform .3s;transition:transform .3s;transition:transform .3s,-webkit-transform .3s}.mfui-9-modal-mobile__container-wrap:before{content:"";display:block;-ms-flex-item-align:end;align-self:flex-end;background-color:var(--spbSky2);border-radius:10px;height:6px;margin:0 auto 8px;width:40px}.mfui-9-modal-mobile__container-wrap_move{-webkit-transition:none;transition:none}.mfui-9-modal-mobile__container-wrap_transition-end{-webkit-animation:hide-popup-to-bottom .2s linear forwards;animation:hide-popup-to-bottom .2s linear forwards}.mfui-9-modal-mobile__container-inner{-webkit-box-flex:0;-ms-flex-positive:0;border-top-left-radius:32px;border-top-right-radius:32px;flex-grow:0;height:auto;overflow:hidden}.mfui-9-modal-mobile_ios.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__container-wrap,.mfui-9-modal-mobile_ios.mfui-9-modal-mobile_keyboard-open .mfui-9-modal-mobile__container-wrap{bottom:var(--keyboard-offset,0);height:calc(var(--viewport-height) - var(--top-offset))}.mfui-9-modal-mobile_ios.mfui-9-modal-mobile_full-view .mfui-9-modal-mobile__container-wrap:after,.mfui-9-modal-mobile_ios.mfui-9-modal-mobile_keyboard-open .mfui-9-modal-mobile__container-wrap:after{background-color:var(--background);bottom:auto;content:"";display:block;height:200%;left:0;position:fixed;right:0;top:var(--viewport-height)}@-webkit-keyframes show-popup-from-bottom{0%{opacity:0;-webkit-transform:translateY(100%);transform:translateY(100%)}to{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}}@keyframes show-popup-from-bottom{0%{opacity:0;-webkit-transform:translateY(100%);transform:translateY(100%)}to{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}}@-webkit-keyframes hide-popup-to-bottom{0%{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}to{opacity:0;-webkit-transform:translateY(100%);transform:translateY(100%)}}@keyframes hide-popup-to-bottom{0%{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}to{opacity:0;-webkit-transform:translateY(100%);transform:translateY(100%)}}
|
|
@@ -8,6 +8,7 @@ export interface IModalMobileProps extends ModalContextPropsType {
|
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
onChangeTransitionStep: (value: MODAL_TRANSITIONS_STEPS_ENUM) => void;
|
|
10
10
|
onChangeContainerWrapTransform: (value: string) => void;
|
|
11
|
+
isKeyboardOpen: boolean;
|
|
11
12
|
}
|
|
12
13
|
declare const ModalMobile: React.FC<IModalMobileProps>;
|
|
13
14
|
export default ModalMobile;
|
|
@@ -11,6 +11,7 @@ require("core-js/modules/es.symbol.js");
|
|
|
11
11
|
require("core-js/modules/es.array.index-of.js");
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _uiHelpers = require("@megafon/ui-helpers");
|
|
14
|
+
var _browser = require("../../../utils/browser");
|
|
14
15
|
var _ModalContent = _interopRequireDefault(require("../_ModalContent/ModalContent"));
|
|
15
16
|
var _Modal = require("../Modal");
|
|
16
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -43,19 +44,21 @@ var ModalMobile = function ModalMobile(_a) {
|
|
|
43
44
|
scrollContent = _f.scrollContent,
|
|
44
45
|
restClassesScrollBar = __rest(_f, ["root", "init", "scrollContent"]),
|
|
45
46
|
restScrollBarParams = __rest(_d, ["classes"]),
|
|
46
|
-
isSwipeDisabled = _a.isSwipeDisabled,
|
|
47
47
|
_a$isFullView = _a.isFullView,
|
|
48
48
|
isFullView = _a$isFullView === void 0 ? true : _a$isFullView,
|
|
49
49
|
children = _a.children,
|
|
50
50
|
onChangeTransitionStep = _a.onChangeTransitionStep,
|
|
51
51
|
onChangeContainerWrapTransform = _a.onChangeContainerWrapTransform,
|
|
52
|
-
|
|
52
|
+
isKeyboardOpen = _a.isKeyboardOpen,
|
|
53
|
+
restProps = __rest(_a, ["classes", "scrollBarParams", "isFullView", "children", "onChangeTransitionStep", "onChangeContainerWrapTransform", "isKeyboardOpen"]);
|
|
53
54
|
var _restProps$refs = restProps.refs,
|
|
54
55
|
containerWrapRef = _restProps$refs.containerWrapRef,
|
|
55
56
|
containerInnerRef = _restProps$refs.containerInnerRef,
|
|
56
57
|
scrollBarScrollableRef = _restProps$refs.scrollBarScrollableRef,
|
|
57
58
|
isTransitionMoveStep = restProps.isTransitionMoveStep,
|
|
58
|
-
isTransitionEndStep = restProps.isTransitionEndStep
|
|
59
|
+
isTransitionEndStep = restProps.isTransitionEndStep,
|
|
60
|
+
isSwipeDisabledProps = restProps.isSwipeDisabled;
|
|
61
|
+
var isSwipeDisabled = isKeyboardOpen && (0, _browser.isIOS)() || isSwipeDisabledProps;
|
|
59
62
|
var _React$useState = React.useState(null),
|
|
60
63
|
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
|
|
61
64
|
initialTouchPosition = _React$useState2[0],
|
|
@@ -127,7 +130,9 @@ var ModalMobile = function ModalMobile(_a) {
|
|
|
127
130
|
}, [handleWindowTouchEnd, handleWindowTouchMove, isSwipeDisabled]);
|
|
128
131
|
return /*#__PURE__*/React.createElement("div", {
|
|
129
132
|
className: cn({
|
|
130
|
-
'full-view': isFullView
|
|
133
|
+
'full-view': isFullView,
|
|
134
|
+
ios: (0, _browser.isIOS)(),
|
|
135
|
+
'keyboard-open': isKeyboardOpen
|
|
131
136
|
})
|
|
132
137
|
}, /*#__PURE__*/React.createElement(_ModalContent["default"], (0, _extends2["default"])({}, restProps, {
|
|
133
138
|
classes: (0, _extends2["default"])((0, _extends2["default"])({}, restClasses), {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
3
|
+
interface PreventScrollOptions {
|
|
4
|
+
/** Whether the scroll lock is disabled. */
|
|
5
|
+
isDisabled?: boolean;
|
|
6
|
+
focusCallback?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function isScrollable(node: Element): boolean;
|
|
9
|
+
export declare function getScrollParent(node: Element): Element;
|
|
10
|
+
/**
|
|
11
|
+
* Prevents scrolling on the document body on mount, and
|
|
12
|
+
* restores it on unmount. Also ensures that content does not
|
|
13
|
+
* shift due to the scrollbars disappearing.
|
|
14
|
+
*/
|
|
15
|
+
declare function usePreventScroll(options?: PreventScrollOptions): void;
|
|
16
|
+
export declare function isInput(target: Element): boolean;
|
|
17
|
+
export default usePreventScroll;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
exports.getScrollParent = getScrollParent;
|
|
8
|
+
exports.isInput = isInput;
|
|
9
|
+
exports.isScrollable = isScrollable;
|
|
10
|
+
exports.useIsomorphicLayoutEffect = void 0;
|
|
11
|
+
require("core-js/modules/es.array.iterator.js");
|
|
12
|
+
require("core-js/modules/es.object.to-string.js");
|
|
13
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
14
|
+
require("core-js/modules/es.regexp.test.js");
|
|
15
|
+
require("core-js/modules/es.set.js");
|
|
16
|
+
require("core-js/modules/es.string.iterator.js");
|
|
17
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
18
|
+
var _react = require("react");
|
|
19
|
+
var _browser = require("../../../utils/browser");
|
|
20
|
+
// This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts
|
|
21
|
+
/* eslint-disable */
|
|
22
|
+
|
|
23
|
+
var KEYBOARD_BUFFER = 24;
|
|
24
|
+
var useIsomorphicLayoutEffect = exports.useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
|
|
25
|
+
function chain() {
|
|
26
|
+
for (var _len = arguments.length, callbacks = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
27
|
+
callbacks[_key] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
return function () {
|
|
30
|
+
for (var _i = 0, _callbacks = callbacks; _i < _callbacks.length; _i++) {
|
|
31
|
+
var callback = _callbacks[_i];
|
|
32
|
+
if (typeof callback === 'function') {
|
|
33
|
+
callback.apply(void 0, arguments);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
var visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
40
|
+
function isScrollable(node) {
|
|
41
|
+
var style = window.getComputedStyle(node);
|
|
42
|
+
return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
|
|
43
|
+
}
|
|
44
|
+
function getScrollParent(node) {
|
|
45
|
+
if (isScrollable(node)) {
|
|
46
|
+
node = node.parentElement;
|
|
47
|
+
}
|
|
48
|
+
while (node && !isScrollable(node)) {
|
|
49
|
+
node = node.parentElement;
|
|
50
|
+
}
|
|
51
|
+
return node || document.scrollingElement || document.documentElement;
|
|
52
|
+
}
|
|
53
|
+
// HTML input types that do not cause the software keyboard to appear.
|
|
54
|
+
var nonTextInputTypes = new Set(['checkbox', 'radio', 'range', 'color', 'file', 'image', 'button', 'submit', 'reset']);
|
|
55
|
+
// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
|
|
56
|
+
var preventScrollCount = 0;
|
|
57
|
+
var restore;
|
|
58
|
+
/**
|
|
59
|
+
* Prevents scrolling on the document body on mount, and
|
|
60
|
+
* restores it on unmount. Also ensures that content does not
|
|
61
|
+
* shift due to the scrollbars disappearing.
|
|
62
|
+
*/
|
|
63
|
+
function usePreventScroll() {
|
|
64
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
+
var isDisabled = options.isDisabled;
|
|
66
|
+
useIsomorphicLayoutEffect(function () {
|
|
67
|
+
if (isDisabled) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
preventScrollCount++;
|
|
71
|
+
if (preventScrollCount === 1) {
|
|
72
|
+
if ((0, _browser.isIOS)()) {
|
|
73
|
+
restore = preventScrollMobileSafari();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return function () {
|
|
77
|
+
preventScrollCount--;
|
|
78
|
+
if (preventScrollCount === 0) {
|
|
79
|
+
restore === null || restore === void 0 ? void 0 : restore();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}, [isDisabled]);
|
|
83
|
+
}
|
|
84
|
+
// Mobile Safari is a whole different beast. Even with overflow: hidden,
|
|
85
|
+
// it still scrolls the page in many situations:
|
|
86
|
+
//
|
|
87
|
+
// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
|
|
88
|
+
// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
|
|
89
|
+
// it, so it becomes scrollable.
|
|
90
|
+
// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
|
|
91
|
+
// This may cause even fixed position elements to scroll off the screen.
|
|
92
|
+
// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
|
|
93
|
+
// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
|
|
94
|
+
//
|
|
95
|
+
// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
|
|
96
|
+
//
|
|
97
|
+
// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
|
|
98
|
+
// on the window.
|
|
99
|
+
// 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the
|
|
100
|
+
// top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.
|
|
101
|
+
// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
|
|
102
|
+
// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
|
|
103
|
+
// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
|
|
104
|
+
// into view ourselves, without scrolling the whole page.
|
|
105
|
+
// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
|
|
106
|
+
// same visually, but makes the actual scroll position always zero. This is required to make all of the
|
|
107
|
+
// above work or Safari will still try to scroll the page when focusing an input.
|
|
108
|
+
// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
|
|
109
|
+
// to navigate to an input with the next/previous buttons that's outside a modal.
|
|
110
|
+
function preventScrollMobileSafari() {
|
|
111
|
+
var scrollable;
|
|
112
|
+
var lastY = 0;
|
|
113
|
+
var onTouchStart = function onTouchStart(e) {
|
|
114
|
+
// Store the nearest scrollable parent element from the element that the user touched.
|
|
115
|
+
scrollable = getScrollParent(e.target);
|
|
116
|
+
if (scrollable === document.documentElement && scrollable === document.body) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
lastY = e.changedTouches[0].pageY;
|
|
120
|
+
};
|
|
121
|
+
var onTouchMove = function onTouchMove(e) {
|
|
122
|
+
// Prevent scrolling the window.
|
|
123
|
+
if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Prevent scrolling up when at the top and scrolling down when at the bottom
|
|
128
|
+
// of a nested scrollable area, otherwise mobile Safari will start scrolling
|
|
129
|
+
// the window instead. Unfortunately, this disables bounce scrolling when at
|
|
130
|
+
// the top but it's the best we can do.
|
|
131
|
+
var y = e.changedTouches[0].pageY;
|
|
132
|
+
var _scrollable = scrollable,
|
|
133
|
+
scrollTop = _scrollable.scrollTop;
|
|
134
|
+
var bottom = scrollable.scrollHeight - scrollable.clientHeight;
|
|
135
|
+
if (bottom === 0) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
}
|
|
141
|
+
lastY = y;
|
|
142
|
+
};
|
|
143
|
+
var onTouchEnd = function onTouchEnd(e) {
|
|
144
|
+
var target = e.target;
|
|
145
|
+
// Apply this change if we're not already focused on the target element
|
|
146
|
+
if (isInput(target) && target !== document.activeElement) {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
// Apply a transform to trick Safari into thinking the input is at the top of the page
|
|
149
|
+
// so it doesn't try to scroll it into view. When tapping on an input, this needs to
|
|
150
|
+
// be done before the "focus" event, so we have to focus the element ourselves.
|
|
151
|
+
target.style.transform = 'translateY(-2000px)';
|
|
152
|
+
target.focus();
|
|
153
|
+
requestAnimationFrame(function () {
|
|
154
|
+
target.style.transform = '';
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var onFocus = function onFocus(e) {
|
|
159
|
+
var target = e.target;
|
|
160
|
+
if (isInput(target)) {
|
|
161
|
+
// Transform also needs to be applied in the focus event in cases where focus moves
|
|
162
|
+
// other than tapping on an input directly, e.g. the next/previous buttons in the
|
|
163
|
+
// software keyboard. In these cases, it seems applying the transform in the focus event
|
|
164
|
+
// is good enough, whereas when tapping an input, it must be done before the focus event. 🤷♂️
|
|
165
|
+
target.style.transform = 'translateY(-2000px)';
|
|
166
|
+
requestAnimationFrame(function () {
|
|
167
|
+
target.style.transform = '';
|
|
168
|
+
// This will have prevented the browser from scrolling the focused element into view,
|
|
169
|
+
// so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
|
|
170
|
+
if (visualViewport) {
|
|
171
|
+
if (visualViewport.height < window.innerHeight) {
|
|
172
|
+
// If the keyboard is already visible, do this after one additional frame
|
|
173
|
+
// to wait for the transform to be removed.
|
|
174
|
+
requestAnimationFrame(function () {
|
|
175
|
+
scrollIntoView(target);
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
// Otherwise, wait for the visual viewport to resize before scrolling so we can
|
|
179
|
+
// measure the correct position to scroll to.
|
|
180
|
+
visualViewport.addEventListener('resize', function () {
|
|
181
|
+
return scrollIntoView(target);
|
|
182
|
+
}, {
|
|
183
|
+
once: true
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
var onWindowScroll = function onWindowScroll() {
|
|
191
|
+
// Last resort. If the window scrolled, scroll it back to the top.
|
|
192
|
+
// It should always be at the top because the body will have a negative margin (see below).
|
|
193
|
+
window.scrollTo(0, 0);
|
|
194
|
+
};
|
|
195
|
+
// Record the original scroll position so we can restore it.
|
|
196
|
+
// Then apply a negative margin to the body to offset it by the scroll position. This will
|
|
197
|
+
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
198
|
+
var scrollX = window.pageXOffset;
|
|
199
|
+
var scrollY = window.pageYOffset;
|
|
200
|
+
var restoreStyles = chain(setStyle(document.documentElement, 'paddingRight', "".concat(window.innerWidth - document.documentElement.clientWidth, "px")));
|
|
201
|
+
// Scroll to the top. The negative margin on the body will make this appear the same.
|
|
202
|
+
window.scrollTo(0, 0);
|
|
203
|
+
var removeEvents = chain(addEvent(document, 'touchstart', onTouchStart, {
|
|
204
|
+
passive: false,
|
|
205
|
+
capture: true
|
|
206
|
+
}), addEvent(document, 'touchmove', onTouchMove, {
|
|
207
|
+
passive: false,
|
|
208
|
+
capture: true
|
|
209
|
+
}), addEvent(document, 'touchend', onTouchEnd, {
|
|
210
|
+
passive: false,
|
|
211
|
+
capture: true
|
|
212
|
+
}), addEvent(document, 'focus', onFocus, true), addEvent(window, 'scroll', onWindowScroll));
|
|
213
|
+
return function () {
|
|
214
|
+
// Restore styles and scroll the page back to where it was.
|
|
215
|
+
restoreStyles();
|
|
216
|
+
removeEvents();
|
|
217
|
+
window.scrollTo(scrollX, scrollY);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Sets a CSS property on an element, and returns a function to revert it to the previous value.
|
|
221
|
+
function setStyle(element, style, value) {
|
|
222
|
+
// https://github.com/microsoft/TypeScript/issues/17827#issuecomment-391663310
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
var cur = element.style[style];
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
element.style[style] = value;
|
|
227
|
+
return function () {
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
element.style[style] = cur;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Adds an event listener to an element, and returns a function to remove it.
|
|
233
|
+
function addEvent(target, event, handler, options) {
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
target.addEventListener(event, handler, options);
|
|
236
|
+
return function () {
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
target.removeEventListener(event, handler, options);
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function scrollIntoView(target) {
|
|
242
|
+
var root = document.scrollingElement || document.documentElement;
|
|
243
|
+
while (target && target !== root) {
|
|
244
|
+
// Find the parent scrollable element and adjust the scroll position if the target is not already in view.
|
|
245
|
+
var scrollable = getScrollParent(target);
|
|
246
|
+
if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
|
|
247
|
+
var scrollableTop = scrollable.getBoundingClientRect().top;
|
|
248
|
+
var targetTop = target.getBoundingClientRect().top;
|
|
249
|
+
var targetBottom = target.getBoundingClientRect().bottom;
|
|
250
|
+
// Buffer is needed for some edge cases
|
|
251
|
+
var keyboardHeight = scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER;
|
|
252
|
+
if (targetBottom > keyboardHeight) {
|
|
253
|
+
scrollable.scrollTop += targetTop - scrollableTop;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
target = scrollable.parentElement;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function isInput(target) {
|
|
261
|
+
return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
|
|
262
|
+
}
|
|
263
|
+
var _default = exports["default"] = usePreventScroll;
|
|
@@ -37,8 +37,9 @@ var getCorrectMaxHeight = exports.getCorrectMaxHeight = function getCorrectMaxHe
|
|
|
37
37
|
props = _ref.props;
|
|
38
38
|
var isStickyFooter = props.isStickyFooter,
|
|
39
39
|
isStickyHeader = props.isStickyHeader,
|
|
40
|
-
isBottomView = props.isBottomView
|
|
41
|
-
|
|
40
|
+
isBottomView = props.isBottomView,
|
|
41
|
+
availableHeight = props.availableHeight;
|
|
42
|
+
var windowHeight = availableHeight !== null && availableHeight !== void 0 ? availableHeight : window.innerHeight;
|
|
42
43
|
var windowWidth = window.innerWidth;
|
|
43
44
|
var isMobile = windowWidth < _uiHelpers.breakpoints.MOBILE_BIG_START;
|
|
44
45
|
var _getAdditionalSize = getAdditionalSize(refs),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useEvent = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _useLatest = require("./useLatest");
|
|
9
|
+
var useEvent = exports.useEvent = function useEvent(fn) {
|
|
10
|
+
var ref = (0, _useLatest.useLatest)(fn);
|
|
11
|
+
return (0, _react.useMemo)(function () {
|
|
12
|
+
return function () {
|
|
13
|
+
var current = ref.current;
|
|
14
|
+
return current.apply(void 0, arguments);
|
|
15
|
+
};
|
|
16
|
+
}, [ref]);
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useLatest = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var useLatest = exports.useLatest = function useLatest(value) {
|
|
9
|
+
var valueRef = (0, _react.useRef)(value);
|
|
10
|
+
(0, _react.useInsertionEffect)(function () {
|
|
11
|
+
valueRef.current = value;
|
|
12
|
+
}, [value]);
|
|
13
|
+
return valueRef;
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Metrics = {
|
|
2
|
+
keyboardOffset: number;
|
|
3
|
+
viewportHeight: number;
|
|
4
|
+
isKeyboardOpen: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare function useVisualViewport({ enabled, onChange, }: {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
onChange: (metrics: Metrics) => void;
|
|
9
|
+
}): Metrics;
|
|
10
|
+
export default useVisualViewport;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _useEvent = require("./useEvent");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
var getDefaultMetrics = function getDefaultMetrics() {
|
|
12
|
+
return {
|
|
13
|
+
keyboardOffset: 0,
|
|
14
|
+
viewportHeight: window.innerHeight,
|
|
15
|
+
isKeyboardOpen: false
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
var getMetrics = function getMetrics() {
|
|
19
|
+
var viewport = window.visualViewport;
|
|
20
|
+
if (!viewport) {
|
|
21
|
+
return getDefaultMetrics();
|
|
22
|
+
}
|
|
23
|
+
var keyboardOffset = Math.max(0, window.innerHeight - viewport.height - viewport.offsetTop);
|
|
24
|
+
var isKeyboardOpen = viewport.height < window.innerHeight && window.innerHeight - viewport.height > 150;
|
|
25
|
+
return {
|
|
26
|
+
keyboardOffset: keyboardOffset,
|
|
27
|
+
viewportHeight: viewport.height,
|
|
28
|
+
isKeyboardOpen: isKeyboardOpen
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
function useVisualViewport(_ref) {
|
|
32
|
+
var _ref$enabled = _ref.enabled,
|
|
33
|
+
enabled = _ref$enabled === void 0 ? true : _ref$enabled,
|
|
34
|
+
onChange = _ref.onChange;
|
|
35
|
+
var _useState = (0, _react.useState)(function () {
|
|
36
|
+
return getMetrics();
|
|
37
|
+
}),
|
|
38
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
39
|
+
metrics = _useState2[0],
|
|
40
|
+
setMetrics = _useState2[1];
|
|
41
|
+
var onChangeMetrics = (0, _useEvent.useEvent)(onChange);
|
|
42
|
+
(0, _react.useEffect)(function () {
|
|
43
|
+
if (!enabled) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
var updateMetrics = function updateMetrics() {
|
|
47
|
+
var currentMetrics = getMetrics();
|
|
48
|
+
setMetrics(currentMetrics);
|
|
49
|
+
onChangeMetrics(currentMetrics);
|
|
50
|
+
};
|
|
51
|
+
updateMetrics();
|
|
52
|
+
var viewport = window.visualViewport;
|
|
53
|
+
viewport === null || viewport === void 0 ? void 0 : viewport.addEventListener('resize', updateMetrics);
|
|
54
|
+
viewport === null || viewport === void 0 ? void 0 : viewport.addEventListener('scroll', updateMetrics);
|
|
55
|
+
return function () {
|
|
56
|
+
viewport === null || viewport === void 0 ? void 0 : viewport.removeEventListener('resize', updateMetrics);
|
|
57
|
+
viewport === null || viewport === void 0 ? void 0 : viewport.removeEventListener('scroll', updateMetrics);
|
|
58
|
+
};
|
|
59
|
+
}, [enabled, onChangeMetrics]);
|
|
60
|
+
return metrics;
|
|
61
|
+
}
|
|
62
|
+
var _default = exports["default"] = useVisualViewport;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -89,5 +89,6 @@ export { default as UploadFileItemIcon } from './components/UploadForm/UploadFil
|
|
|
89
89
|
export { default as useDragAndDrop } from './components/UploadForm/UploadField/components/useDragAndDrop';
|
|
90
90
|
export { default as useGradient } from './components/Carousel/useGradient';
|
|
91
91
|
export { default as usePagination } from './components/Pagination/usePagination';
|
|
92
|
+
export { default as usePreventScroll } from './components/Modal/utils/usePreventScroll';
|
|
92
93
|
export { default as utils } from './components/Modal/utils/utils';
|
|
93
94
|
export { default as ValueField } from './components/ValueField/ValueField';
|