@startlibs/components 1.0.4 → 1.0.6
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/lib/BasicBulletList.mjs +9 -0
- package/lib/BasicBulletList.mjs.map +1 -0
- package/lib/Button.mjs +95 -0
- package/lib/Button.mjs.map +1 -0
- package/lib/ContextMenu.mjs +461 -0
- package/lib/ContextMenu.mjs.map +1 -0
- package/lib/Dialog.mjs +232 -0
- package/lib/Dialog.mjs.map +1 -0
- package/lib/Draggable.mjs +880 -0
- package/lib/Draggable.mjs.map +1 -0
- package/lib/ErrorBoundary.mjs +108 -0
- package/lib/ErrorBoundary.mjs.map +1 -0
- package/lib/FillLastLineResizer.mjs +238 -0
- package/lib/FillLastLineResizer.mjs.map +1 -0
- package/lib/Flip.mjs +604 -0
- package/lib/Flip.mjs.map +1 -0
- package/lib/FlipList.mjs +186 -0
- package/lib/FlipList.mjs.map +1 -0
- package/lib/FormatDate.mjs +25 -0
- package/lib/FormatDate.mjs.map +1 -0
- package/lib/Icon.mjs +50 -0
- package/lib/Icon.mjs.map +1 -0
- package/lib/Image.mjs +41 -0
- package/lib/Image.mjs.map +1 -0
- package/lib/Link.mjs +116 -0
- package/lib/Link.mjs.map +1 -0
- package/lib/Loading.mjs +10 -0
- package/lib/Loading.mjs.map +1 -0
- package/lib/LoadingDiv.mjs +83 -0
- package/lib/LoadingDiv.mjs.map +1 -0
- package/lib/Notifications.mjs +63 -0
- package/lib/Notifications.mjs.map +1 -0
- package/lib/PageLoader.mjs +42 -0
- package/lib/PageLoader.mjs.map +1 -0
- package/lib/PersistentNotifications.mjs +130 -0
- package/lib/PersistentNotifications.mjs.map +1 -0
- package/lib/Popup.mjs +49 -0
- package/lib/Popup.mjs.map +1 -0
- package/lib/SplitColumnsContainer.mjs +43 -0
- package/lib/SplitColumnsContainer.mjs.map +1 -0
- package/lib/SwitchDiv.mjs +61 -0
- package/lib/SwitchDiv.mjs.map +1 -0
- package/lib/TextButton.mjs +41 -0
- package/lib/TextButton.mjs.map +1 -0
- package/lib/ToastNotifications.mjs +215 -0
- package/lib/ToastNotifications.mjs.map +1 -0
- package/lib/Tooltip.mjs +160 -0
- package/lib/Tooltip.mjs.map +1 -0
- package/lib/TransitionDiv.mjs +56 -0
- package/lib/TransitionDiv.mjs.map +1 -0
- package/lib/WarningDialog.mjs +84 -0
- package/lib/WarningDialog.mjs.map +1 -0
- package/lib/alt/buttons/OnClickLoadingButton.mjs +36 -0
- package/lib/alt/buttons/OnClickLoadingButton.mjs.map +1 -0
- package/lib/alt/dialogs/DialogWithImageHeader.mjs +14 -0
- package/lib/alt/dialogs/DialogWithImageHeader.mjs.map +1 -0
- package/lib/alt/dialogs/DialogWithSidebar.mjs +106 -0
- package/lib/alt/dialogs/DialogWithSidebar.mjs.map +1 -0
- package/lib/alt/dialogs/MobileBubbleDialog.mjs +49 -0
- package/lib/alt/dialogs/MobileBubbleDialog.mjs.map +1 -0
- package/lib/containers/DialogContainer.mjs +413 -0
- package/lib/containers/DialogContainer.mjs.map +1 -0
- package/lib/containers/Reposition.mjs +35 -0
- package/lib/containers/Reposition.mjs.map +1 -0
- package/lib/containers/usePositioning.mjs +294 -0
- package/lib/containers/usePositioning.mjs.map +1 -0
- package/lib/index.cjs +5009 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.js +20 -5
- package/lib/index.mjs +37 -0
- package/lib/index.mjs.map +1 -0
- package/lib/useDialogWithToggle.mjs +18 -0
- package/lib/useDialogWithToggle.mjs.map +1 -0
- package/lib/willUseIsSticky.mjs +123 -0
- package/lib/willUseIsSticky.mjs.map +1 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1376,6 +1376,9 @@ var usePositioning = function usePositioning(element, _ref, arrowRefOpt) {
|
|
|
1376
1376
|
}, 100);
|
|
1377
1377
|
return;
|
|
1378
1378
|
}
|
|
1379
|
+
// Limpar a largura para medir pode encurtar o conteúdo (itens deixam de quebrar linha)
|
|
1380
|
+
// e o browser corta o scrollTop; guarda para restaurar depois de reaplicar a largura.
|
|
1381
|
+
var previousScrollTop = element.current.scrollTop;
|
|
1379
1382
|
if (keepWidth) {
|
|
1380
1383
|
element.current.style.width = '';
|
|
1381
1384
|
} else {
|
|
@@ -1505,6 +1508,9 @@ var usePositioning = function usePositioning(element, _ref, arrowRefOpt) {
|
|
|
1505
1508
|
if (fixed) {
|
|
1506
1509
|
element.current.style.position = 'fixed';
|
|
1507
1510
|
}
|
|
1511
|
+
if (element.current.scrollTop !== previousScrollTop) {
|
|
1512
|
+
element.current.scrollTop = previousScrollTop;
|
|
1513
|
+
}
|
|
1508
1514
|
};
|
|
1509
1515
|
useLayoutEffect(_setPosition, [on]);
|
|
1510
1516
|
useEffect(function () {
|
|
@@ -3128,8 +3134,8 @@ var fixDoubledLastMarginBottom = function fixDoubledLastMarginBottom(children) {
|
|
|
3128
3134
|
return React.Children.map(children, processChild);
|
|
3129
3135
|
};
|
|
3130
3136
|
|
|
3131
|
-
var _excluded$9 = ["label", "layerIndex", "href", "linkTo", "prefixWith", "subMenu", "icon", "children"],
|
|
3132
|
-
_excluded2$1 = ["emitter", "index", "menuSlot", "keepOpen", "hover", "layerIndex", "hoverCursor", "passTouchThrough", "children", "setCursorOnHover", "onClick", "prefixWith", "linkTo", "icon", "label", "descText", "helpText", "target", "href"],
|
|
3137
|
+
var _excluded$9 = ["label", "layerIndex", "href", "linkTo", "prefixWith", "subMenu", "icon", "children", "scrollOnHover"],
|
|
3138
|
+
_excluded2$1 = ["emitter", "index", "menuSlot", "keepOpen", "hover", "layerIndex", "hoverCursor", "scrollOnHover", "passTouchThrough", "children", "setCursorOnHover", "onClick", "prefixWith", "linkTo", "icon", "label", "descText", "helpText", "target", "href"],
|
|
3133
3139
|
_excluded3$1 = ["children", "sub", "hoverIndex", "autoHover", "menuSlot", "withoutIcons", "onClose", "onHover", "fill", "onClick"],
|
|
3134
3140
|
_excluded4 = ["slot", "sub", "withoutIcons", "children"];
|
|
3135
3141
|
var _templateObject$2, _templateObject2$1, _templateObject3$1, _templateObject4;
|
|
@@ -3246,7 +3252,7 @@ var SimpleLi = /*#__PURE__*/function (_React$Component) {
|
|
|
3246
3252
|
}, {
|
|
3247
3253
|
key: "componentDidUpdate",
|
|
3248
3254
|
value: function componentDidUpdate() {
|
|
3249
|
-
if (this.props.hover) {
|
|
3255
|
+
if (this.props.hover && this.props.scrollOnHover !== false) {
|
|
3250
3256
|
this.scrollToVisibility();
|
|
3251
3257
|
}
|
|
3252
3258
|
}
|
|
@@ -3273,6 +3279,7 @@ var SimpleLi = /*#__PURE__*/function (_React$Component) {
|
|
|
3273
3279
|
_this$props.subMenu;
|
|
3274
3280
|
var icon = _this$props.icon;
|
|
3275
3281
|
_this$props.children;
|
|
3282
|
+
_this$props.scrollOnHover;
|
|
3276
3283
|
var rest = _objectWithoutProperties(_this$props, _excluded$9);
|
|
3277
3284
|
var Tag = linkTo ? Link$1 : 'a';
|
|
3278
3285
|
return /*#__PURE__*/React.createElement(ListItem, _extends({}, rest, {
|
|
@@ -3301,7 +3308,8 @@ var Li = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3301
3308
|
keepOpen = _ref.keepOpen,
|
|
3302
3309
|
hover = _ref.hover;
|
|
3303
3310
|
_ref.layerIndex;
|
|
3304
|
-
var hoverCursor = _ref.hoverCursor
|
|
3311
|
+
var hoverCursor = _ref.hoverCursor,
|
|
3312
|
+
scrollOnHover = _ref.scrollOnHover;
|
|
3305
3313
|
_ref.passTouchThrough;
|
|
3306
3314
|
var children = _ref.children,
|
|
3307
3315
|
setCursorOnHover = _ref.setCursorOnHover,
|
|
@@ -3335,7 +3343,7 @@ var Li = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3335
3343
|
}
|
|
3336
3344
|
};
|
|
3337
3345
|
useEffect(function () {
|
|
3338
|
-
if (hover) {
|
|
3346
|
+
if (hover && scrollOnHover !== false) {
|
|
3339
3347
|
try {
|
|
3340
3348
|
var el = nodeRef.current;
|
|
3341
3349
|
var parent = el.parentElement;
|
|
@@ -3479,6 +3487,9 @@ var ContextMenuComponent = /*#__PURE__*/forwardRef(function (_ref2, unesuredRef)
|
|
|
3479
3487
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3480
3488
|
hoverCursor = _useState2[0],
|
|
3481
3489
|
setHoverCursor = _useState2[1];
|
|
3490
|
+
// Hover vindo do mouse não deve rolar a lista: o Chrome dispara mousemove sintético
|
|
3491
|
+
// ao fim do scroll, e o item cortado sob o cursor puxaria a lista de volta.
|
|
3492
|
+
var hoverFromMouse = useRef(false);
|
|
3482
3493
|
var _useContextMenuShared = useContextMenuSharedState(0),
|
|
3483
3494
|
_useContextMenuShared2 = _slicedToArray(_useContextMenuShared, 2),
|
|
3484
3495
|
layerCursor = _useContextMenuShared2[0],
|
|
@@ -3499,6 +3510,7 @@ var ContextMenuComponent = /*#__PURE__*/forwardRef(function (_ref2, unesuredRef)
|
|
|
3499
3510
|
}, [layerIndex, layerCursor, hoverCursor]);
|
|
3500
3511
|
useEffect(function () {
|
|
3501
3512
|
if (hoverIndex !== undefined) {
|
|
3513
|
+
if (hoverIndex !== hoverCursor) hoverFromMouse.current = false;
|
|
3502
3514
|
setHoverCursor(Math.min(Math.max(hoverIndex, -1), _getTotalKeyboardItems(children) + 1));
|
|
3503
3515
|
}
|
|
3504
3516
|
}, [hoverIndex !== hoverCursor]);
|
|
@@ -3526,6 +3538,7 @@ var ContextMenuComponent = /*#__PURE__*/forwardRef(function (_ref2, unesuredRef)
|
|
|
3526
3538
|
var _direction = e.keyCode - 39;
|
|
3527
3539
|
var max = _getTotalKeyboardItems(children);
|
|
3528
3540
|
var newIndex = (hoverCursor + _direction + max) % max;
|
|
3541
|
+
hoverFromMouse.current = false;
|
|
3529
3542
|
setHoverCursor(newIndex);
|
|
3530
3543
|
onHover(newIndex);
|
|
3531
3544
|
}
|
|
@@ -3545,6 +3558,7 @@ var ContextMenuComponent = /*#__PURE__*/forwardRef(function (_ref2, unesuredRef)
|
|
|
3545
3558
|
return sum;
|
|
3546
3559
|
};
|
|
3547
3560
|
var setCursorOnHover = function setCursorOnHover(index) {
|
|
3561
|
+
hoverFromMouse.current = true;
|
|
3548
3562
|
setLayerCursor(layerIndex);
|
|
3549
3563
|
setHoverCursor(index);
|
|
3550
3564
|
onHover(index);
|
|
@@ -3558,6 +3572,7 @@ var ContextMenuComponent = /*#__PURE__*/forwardRef(function (_ref2, unesuredRef)
|
|
|
3558
3572
|
fixedPosition: props.fixed,
|
|
3559
3573
|
hover: hoverCursor === indexRef.current && layerIndex === layerCursor,
|
|
3560
3574
|
hoverCursor: hoverCursor,
|
|
3575
|
+
scrollOnHover: !hoverFromMouse.current,
|
|
3561
3576
|
index: indexRef.current++,
|
|
3562
3577
|
setCursorOnHover: setCursorOnHover,
|
|
3563
3578
|
emitter: itemsEmitter,
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { Icon } from './Icon.mjs';
|
|
2
|
+
export { Loading } from './Loading.mjs';
|
|
3
|
+
export { Button, DropdownIcon } from './Button.mjs';
|
|
4
|
+
export { OnClickLoadingButton } from './alt/buttons/OnClickLoadingButton.mjs';
|
|
5
|
+
export { TextButton } from './TextButton.mjs';
|
|
6
|
+
export { LoadingDiv } from './LoadingDiv.mjs';
|
|
7
|
+
export { CloseIcon, ConfirmDialog, DefaultConfirmDialog, Dialog, DialogContent, DialogContentWrapper, DialogError, DialogErrorContent, DialogFooter, DialogIcon, DialogTitle, FooterAuxiliaryContainer } from './Dialog.mjs';
|
|
8
|
+
export { useDialog, useDialogWithToggle } from './useDialogWithToggle.mjs';
|
|
9
|
+
export { DefaultWarningDialog, WarningDialog, WarningDialogIcon, WarningDialogTitle, setWarningDialog, useWarningDialog } from './WarningDialog.mjs';
|
|
10
|
+
export { Notifications, setNotification, useNotification, useNotificationRef, willSetNotification } from './Notifications.mjs';
|
|
11
|
+
export { ToastNotifications, createToastNotification, useToastNotificationToggle, useToastNotifications, willShowToastNotification } from './ToastNotifications.mjs';
|
|
12
|
+
export { PersistentNotification, PersistentNotificationActions, PersistentNotificationCloseIcon, PersistentNotificationContent, PersistentNotificationIcon, PersistentNotifications, hidePersistentNotifications, openPersistentNotification, useIsHiddenPersistentNotifications } from './PersistentNotifications.mjs';
|
|
13
|
+
export { DefaultArrow, addPositioningBound, usePositioning } from './containers/usePositioning.mjs';
|
|
14
|
+
export { Reposition } from './containers/Reposition.mjs';
|
|
15
|
+
export { AnimatedModal, DialogContainer, Modal, ModalContainer, dialogFadeInDown, dialogModalIn, dialogModalOut, getDialogLayersSize, isFakeScrolled, preventDialogPop, removeWindowScroll, useDialogLayers, waitForPop } from './containers/DialogContainer.mjs';
|
|
16
|
+
export { DraggableContainer, DraggableItem, DroppableContainer } from './Draggable.mjs';
|
|
17
|
+
export { Popup } from './Popup.mjs';
|
|
18
|
+
export { Tooltip } from './Tooltip.mjs';
|
|
19
|
+
export { SplitColumnsContainer, fixDoubledLastMarginBottom } from './SplitColumnsContainer.mjs';
|
|
20
|
+
export { ContextListMenu, ContextMenu, ContextMenuComponent, Li, ListHeading, ListItem, ListMenu, ListSeparator, SimpleLi, StickyContainer, contextMenuLayersQuantity } from './ContextMenu.mjs';
|
|
21
|
+
export { ErrorBoundary } from './ErrorBoundary.mjs';
|
|
22
|
+
export { LoadingBar, PageLoader, SuspenseLoadingBar } from './PageLoader.mjs';
|
|
23
|
+
export { FillLastLineResizer } from './FillLastLineResizer.mjs';
|
|
24
|
+
export { defaultAnimationMaker, formatAnimation, getClientRectAnimation, morph, toPosition, useFlip, useFlipAnimation, useFlipEnter, useFlipLeave, willUseFlip, willUseFlipSwitch } from './Flip.mjs';
|
|
25
|
+
export { FlipList } from './FlipList.mjs';
|
|
26
|
+
export { AnimationBlockContainer, TransitionDiv } from './TransitionDiv.mjs';
|
|
27
|
+
export { SwitchDiv } from './SwitchDiv.mjs';
|
|
28
|
+
export { willUseIsSticky } from './willUseIsSticky.mjs';
|
|
29
|
+
export { FormatDate } from './FormatDate.mjs';
|
|
30
|
+
export { Image } from './Image.mjs';
|
|
31
|
+
export { DialogWithImageHeader } from './alt/dialogs/DialogWithImageHeader.mjs';
|
|
32
|
+
export { DialogTabMenu, DialogWithSidebar, DialogWithSidebarPresentation, MENU_TAB, SideMenu } from './alt/dialogs/DialogWithSidebar.mjs';
|
|
33
|
+
export { MobileBubbleDialog } from './alt/dialogs/MobileBubbleDialog.mjs';
|
|
34
|
+
export { HistoryLink, Link, Navigate, Route, Router, Routes, useAbsoluteLocation, useAbsolutePath, useLocation, useNavigate, useParams, useSearchParams } from './Link.mjs';
|
|
35
|
+
export { BasicBulletList } from './BasicBulletList.mjs';
|
|
36
|
+
export { useBrowserLocation } from 'wouter/use-browser-location';
|
|
37
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useToggle, useFill } from '@startlibs/core';
|
|
2
|
+
|
|
3
|
+
const useDialog = function (dialog) {
|
|
4
|
+
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
5
|
+
let toggleCallback = arguments.length > 2 ? arguments[2] : undefined;
|
|
6
|
+
const toggle = useToggle(false, toggleCallback);
|
|
7
|
+
useFill("Dialog", toggle.isOpen !== false && dialog(toggle.close), [toggle.isOpen, ...args]);
|
|
8
|
+
return toggle.open;
|
|
9
|
+
};
|
|
10
|
+
const useDialogWithToggle = function (dialog) {
|
|
11
|
+
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
12
|
+
const toggle = useToggle();
|
|
13
|
+
useFill("Dialog", toggle.isOpen !== false && dialog(toggle), [toggle.isOpen, ...args]);
|
|
14
|
+
return toggle;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { useDialog, useDialogWithToggle };
|
|
18
|
+
//# sourceMappingURL=useDialogWithToggle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDialogWithToggle.mjs","sources":["../src/useDialogWithToggle.jsx"],"sourcesContent":["import {useToggle,useFill} from '@startlibs/core'\n\nexport const useDialog = (dialog, args = [], toggleCallback) => {\n const toggle = useToggle(false,toggleCallback)\n useFill(\"Dialog\", toggle.isOpen !== false && dialog(toggle.close), [toggle.isOpen, ...args])\n return toggle.open\n}\nexport const useDialogWithToggle = (dialog, args = []) => {\n const toggle = useToggle()\n useFill(\"Dialog\", toggle.isOpen !== false && dialog(toggle), [toggle.isOpen, ...args])\n return toggle\n}"],"names":["useDialog","dialog","args","arguments","length","undefined","toggleCallback","toggle","useToggle","useFill","isOpen","close","open","useDialogWithToggle"],"mappings":";;MAEaA,SAAS,GAAG,UAACC,MAAM,EAAgC;AAAA,EAAA,IAA9BC,IAAI,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE,CAAA;EAAA,IAAEG,cAAc,GAAAH,SAAA,CAAAC,MAAA,GAAAD,CAAAA,GAAAA,SAAA,MAAAE,SAAA,CAAA;AACzD,EAAA,MAAME,MAAM,GAAGC,SAAS,CAAC,KAAK,EAACF,cAAc,CAAC,CAAA;EAC9CG,OAAO,CAAC,QAAQ,EAAEF,MAAM,CAACG,MAAM,KAAK,KAAK,IAAIT,MAAM,CAACM,MAAM,CAACI,KAAK,CAAC,EAAE,CAACJ,MAAM,CAACG,MAAM,EAAE,GAAGR,IAAI,CAAC,CAAC,CAAA;EAC5F,OAAOK,MAAM,CAACK,IAAI,CAAA;AACpB,EAAC;MACYC,mBAAmB,GAAG,UAACZ,MAAM,EAAgB;AAAA,EAAA,IAAdC,IAAI,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE,CAAA;AACnD,EAAA,MAAMI,MAAM,GAAGC,SAAS,EAAE,CAAA;EAC1BC,OAAO,CAAC,QAAQ,EAAEF,MAAM,CAACG,MAAM,KAAK,KAAK,IAAIT,MAAM,CAACM,MAAM,CAAC,EAAE,CAACA,MAAM,CAACG,MAAM,EAAE,GAAGR,IAAI,CAAC,CAAC,CAAA;AACtF,EAAA,OAAOK,MAAM,CAAA;AACf;;;;"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _without from 'lodash/fp/without';
|
|
3
|
+
import _identity from 'lodash/fp/identity';
|
|
4
|
+
import React, { useState, useEffect } from 'react';
|
|
5
|
+
import { willUseSharedCallback, willUseSharedState, useEnsureRef } from '@startlibs/core';
|
|
6
|
+
import styled from 'styled-components';
|
|
7
|
+
import { callIfFunction } from '@startlibs/utils';
|
|
8
|
+
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
const TOP_TRIGGER = (posInfo, refInfo) => {
|
|
12
|
+
// Started sticking.
|
|
13
|
+
if (posInfo.bottom < refInfo.top) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
// Stopped sticking.
|
|
17
|
+
if (posInfo.bottom >= refInfo.top && posInfo.bottom < refInfo.bottom) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const BOTTOM_TRIGGER = (posInfo, refInfo) => {
|
|
22
|
+
// Started sticking.
|
|
23
|
+
if (posInfo.top > refInfo.bottom) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (posInfo.top <= refInfo.bottom && posInfo.top > refInfo.top) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const SentinelStyle = /*#__PURE__*/styled.div.withConfig({
|
|
31
|
+
displayName: "willUseIsSticky__SentinelStyle",
|
|
32
|
+
componentId: "sc-1nsyca-0"
|
|
33
|
+
})(["position:absolute;visibility:hidden;height:1px;width:1px;", ""], props => props.addCss);
|
|
34
|
+
const willUseIsSticky = function () {
|
|
35
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
36
|
+
const [useRegister, onChange] = willUseSharedCallback();
|
|
37
|
+
const [useSharedIsSticky,, setSharedIsSticky] = willUseSharedState();
|
|
38
|
+
const createObserver = root => window.IntersectionObserver ? new window.IntersectionObserver((records, observer) => {
|
|
39
|
+
for (const record of records) {
|
|
40
|
+
const targetInfo = record.boundingClientRect;
|
|
41
|
+
const rootBoundsInfo = record.rootBounds;
|
|
42
|
+
if (!rootBoundsInfo) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
onChange(targetInfo, rootBoundsInfo, record.target, record.isIntersecting);
|
|
46
|
+
}
|
|
47
|
+
}, _objectSpread({
|
|
48
|
+
root
|
|
49
|
+
}, options)) : {
|
|
50
|
+
observe: _identity,
|
|
51
|
+
unobserve: _identity
|
|
52
|
+
};
|
|
53
|
+
const observerMap = new Map();
|
|
54
|
+
const getObserver = function () {
|
|
55
|
+
let root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
56
|
+
const result = observerMap.get(root);
|
|
57
|
+
if (result) {
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
const observer = createObserver(root);
|
|
61
|
+
observerMap.set(root, observer);
|
|
62
|
+
return observer;
|
|
63
|
+
};
|
|
64
|
+
let activeObserved = [];
|
|
65
|
+
const resetObservers = function () {
|
|
66
|
+
let root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
67
|
+
const observer = getObserver(root);
|
|
68
|
+
activeObserved.forEach(observed => {
|
|
69
|
+
observer.unobserve(observed);
|
|
70
|
+
observer.observe(observed);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const WithIsSticky = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
74
|
+
let {
|
|
75
|
+
className,
|
|
76
|
+
id,
|
|
77
|
+
css,
|
|
78
|
+
children,
|
|
79
|
+
bottom,
|
|
80
|
+
root,
|
|
81
|
+
intersection,
|
|
82
|
+
onChange
|
|
83
|
+
} = _ref;
|
|
84
|
+
const ensuredRef = useEnsureRef(ref);
|
|
85
|
+
const [isSticky, setIsSticky] = useState(false);
|
|
86
|
+
useRegister((posInfo, refInfo, target, isIntersecting) => {
|
|
87
|
+
if (ensuredRef.current === target) {
|
|
88
|
+
const value = intersection ? isIntersecting : bottom ? BOTTOM_TRIGGER(posInfo, refInfo) : TOP_TRIGGER(posInfo, refInfo);
|
|
89
|
+
if (value !== undefined) {
|
|
90
|
+
setIsSticky(value);
|
|
91
|
+
callIfFunction(onChange, value);
|
|
92
|
+
if (!id) {
|
|
93
|
+
setSharedIsSticky(value);
|
|
94
|
+
} else if (value) {
|
|
95
|
+
setSharedIsSticky(id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
setIsSticky(false);
|
|
102
|
+
getObserver(callIfFunction(root)).observe(ensuredRef.current);
|
|
103
|
+
activeObserved = activeObserved.concat(ensuredRef.current);
|
|
104
|
+
return () => {
|
|
105
|
+
// observer.unobserve(ref.current)
|
|
106
|
+
activeObserved = _without([ensuredRef.current], activeObserved);
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
const renderSentinel = function () {
|
|
110
|
+
let css = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
111
|
+
return /*#__PURE__*/React.createElement(SentinelStyle, {
|
|
112
|
+
addCss: css,
|
|
113
|
+
className: className,
|
|
114
|
+
ref: ensuredRef
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
return children ? children(renderSentinel, isSticky) : renderSentinel(css);
|
|
118
|
+
});
|
|
119
|
+
return [WithIsSticky, useSharedIsSticky, resetObservers];
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export { willUseIsSticky };
|
|
123
|
+
//# sourceMappingURL=willUseIsSticky.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"willUseIsSticky.mjs","sources":["../src/willUseIsSticky.jsx"],"sourcesContent":["import React, {useEffect, useState} from 'react'\nimport {useEnsureRef, willUseSharedState, willUseSharedCallback} from '@startlibs/core'\nimport styled from 'styled-components'\nimport _ from 'lodash/fp'\nimport {callIfFunction} from '@startlibs/utils'\n\n\nconst TOP_TRIGGER = (posInfo,refInfo) => {\n // Started sticking.\n if (posInfo.bottom < refInfo.top) {\n return true\n }\n // Stopped sticking.\n if (posInfo.bottom >= refInfo.top &&\n posInfo.bottom < refInfo.bottom) {\n return false\n }\n}\nconst BOTTOM_TRIGGER = (posInfo,refInfo) => {\n // Started sticking.\n if (posInfo.top > refInfo.bottom) {\n return true\n }\n if (posInfo.top <= refInfo.bottom &&\n posInfo.top > refInfo.top) {\n return false\n }\n}\n\nconst SentinelStyle = styled.div`\n position:absolute;\n visibility: hidden;\n height:1px;\n width: 1px;\n ${props => props.addCss}\n`\n\nexport const willUseIsSticky = (options = {}) => {\n\n const [useRegister, onChange] = willUseSharedCallback()\n const [useSharedIsSticky,, setSharedIsSticky] = willUseSharedState()\n\n const createObserver = (root) => window.IntersectionObserver ? new window.IntersectionObserver((records, observer) => {\n for (const record of records) {\n const targetInfo = record.boundingClientRect\n const rootBoundsInfo = record.rootBounds\n if (!rootBoundsInfo) {\n return\n }\n onChange(targetInfo,rootBoundsInfo, record.target, record.isIntersecting)\n }\n },{root,...options}) : {observe:_.identity,unobserve:_.identity}\n\n const observerMap = new Map()\n const getObserver = (root = null) => {\n const result = observerMap.get(root)\n if (result) {\n return result\n }\n const observer = createObserver(root)\n observerMap.set(root,observer)\n return observer\n }\n \n let activeObserved = []\n const resetObservers = (root = null) => {\n const observer = getObserver(root)\n activeObserved.forEach((observed) => {\n observer.unobserve(observed)\n observer.observe(observed)\n })\n }\n\n const WithIsSticky = React.forwardRef(({className, id, css, children,bottom, root, intersection,onChange},ref) => {\n const ensuredRef = useEnsureRef(ref)\n const [isSticky,setIsSticky] = useState(false)\n\n useRegister((posInfo,refInfo,target, isIntersecting) => {\n if (ensuredRef.current === target) {\n const value = intersection ? isIntersecting : (bottom ? BOTTOM_TRIGGER(posInfo,refInfo) : TOP_TRIGGER(posInfo,refInfo))\n if (value!==undefined) {\n setIsSticky(value)\n callIfFunction(onChange,value)\n if (!id) {\n setSharedIsSticky(value)\n } else if (value) {\n setSharedIsSticky(id)\n }\n }\n }\n })\n\n useEffect(() => {\n setIsSticky(false)\n getObserver(callIfFunction(root)).observe(ensuredRef.current)\n activeObserved = activeObserved.concat(ensuredRef.current)\n return () => {\n // observer.unobserve(ref.current)\n activeObserved = _.without([ensuredRef.current],activeObserved)\n }\n },[])\n\n const renderSentinel = (css = \"\") => <SentinelStyle addCss={css} className={className} ref={ensuredRef} />\n\n return children\n ? children(renderSentinel,isSticky)\n : renderSentinel(css)\n\n })\n\n\n return [WithIsSticky, useSharedIsSticky, resetObservers]\n}"],"names":["TOP_TRIGGER","posInfo","refInfo","bottom","top","BOTTOM_TRIGGER","SentinelStyle","styled","div","withConfig","displayName","componentId","props","addCss","willUseIsSticky","options","arguments","length","undefined","useRegister","onChange","willUseSharedCallback","useSharedIsSticky","setSharedIsSticky","willUseSharedState","createObserver","root","window","IntersectionObserver","records","observer","record","targetInfo","boundingClientRect","rootBoundsInfo","rootBounds","target","isIntersecting","_objectSpread","observe","_identity","unobserve","observerMap","Map","getObserver","result","get","set","activeObserved","resetObservers","forEach","observed","WithIsSticky","React","forwardRef","_ref","ref","className","id","css","children","intersection","ensuredRef","useEnsureRef","isSticky","setIsSticky","useState","current","value","callIfFunction","useEffect","concat","_without","renderSentinel","createElement"],"mappings":";;;;;;;;;;AAOA,MAAMA,WAAW,GAAGA,CAACC,OAAO,EAACC,OAAO,KAAK;AACvC;AACA,EAAA,IAAID,OAAO,CAACE,MAAM,GAAGD,OAAO,CAACE,GAAG,EAAE;AAChC,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;AACA;AACA,EAAA,IAAIH,OAAO,CAACE,MAAM,IAAID,OAAO,CAACE,GAAG,IAC/BH,OAAO,CAACE,MAAM,GAAGD,OAAO,CAACC,MAAM,EAAE;AACjC,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AACF,CAAC,CAAA;AACD,MAAME,cAAc,GAAGA,CAACJ,OAAO,EAACC,OAAO,KAAK;AAC1C;AACA,EAAA,IAAID,OAAO,CAACG,GAAG,GAAGF,OAAO,CAACC,MAAM,EAAE;AAChC,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;AACA,EAAA,IAAIF,OAAO,CAACG,GAAG,IAAIF,OAAO,CAACC,MAAM,IACjCF,OAAO,CAACG,GAAG,GAAGF,OAAO,CAACE,GAAG,EAAE;AACzB,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AACF,CAAC,CAAA;AAED,MAAME,aAAa,gBAAGC,MAAM,CAACC,GAAG,CAAAC,UAAA,CAAA;EAAAC,WAAA,EAAA,gCAAA;EAAAC,WAAA,EAAA,aAAA;AAAA,CAAA,CAAA,CAAA,CAAA,2DAAA,EAAA,EAAA,CAAA,EAK5BC,KAAK,IAAIA,KA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