@koine/react 2.0.0-beta.10 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/Alert/Alert.js +0 -33
- package/Alert/Alert.stories.js +0 -39
- package/Alert/index.js +0 -6
- package/Animations/Reveal.js +0 -53
- package/Animations/Underline.js +0 -26
- package/Animations/index.js +0 -8
- package/Animations/useReveal.js +0 -83
- package/Autocomplete/AutocompleteDownshift.js +0 -167
- package/Autocomplete/AutocompleteDownshiftMultiselect.js +0 -362
- package/Autocomplete/AutocompleteMui.js +0 -183
- package/Autocomplete/AutocompleteReach.js +0 -121
- package/Autocomplete/components.js +0 -132
- package/Autocomplete/helpers.js +0 -34
- package/Autocomplete/index.js +0 -15
- package/Bg/BgColor.js +0 -64
- package/Bg/BgPhoto.js +0 -82
- package/Bg/BgSvg.js +0 -31
- package/Bg/index.js +0 -8
- package/Breadcrumbs/Breadcrumbs.js +0 -103
- package/Breadcrumbs/index.js +0 -6
- package/Buttons/Button.js +0 -106
- package/Buttons/ButtonComposite.js +0 -116
- package/Buttons/ButtonFab.js +0 -27
- package/Buttons/ButtonLink.js +0 -29
- package/Buttons/IconButton.js +0 -41
- package/Buttons/index.js +0 -10
- package/Calendar/CalendarDaygridCell.js +0 -105
- package/Calendar/CalendarDaygridNav.js +0 -63
- package/Calendar/CalendarDaygridTable.js +0 -126
- package/Calendar/CalendarLegend.js +0 -39
- package/Calendar/calendar-api-google.js +0 -110
- package/Calendar/index.js +0 -11
- package/Calendar/types.js +0 -4
- package/Calendar/useCalendar.js +0 -235
- package/Calendar/utils.js +0 -252
- package/Carousel/Carousel.js +0 -387
- package/Carousel/CarouselCss.js +0 -64
- package/Carousel/index.js +0 -6
- package/Collapsable/Collapsable.js +0 -11
- package/Collapsable/CollapsableReach.js +0 -251
- package/Collapsable/index.js +0 -7
- package/Debug/Debug.js +0 -34
- package/Debug/index.js +0 -6
- package/Details/Details.js +0 -117
- package/Details/Details.stories.js +0 -39
- package/Details/index.js +0 -6
- package/Dialog/DialogMui.js +0 -143
- package/Dialog/DialogMui.stories.js +0 -38
- package/Dialog/css/bare.js +0 -55
- package/Dialog/css/index.stories.js +0 -93
- package/Dialog/index.js +0 -11
- package/Dialog/m/bare.js +0 -125
- package/Dialog/m/basic.js +0 -50
- package/Dialog/m/index.js +0 -14
- package/Dialog/sc/bare.js +0 -83
- package/Dialog/sc/framer.js +0 -26
- package/Dialog/sc/framerMaterial.js +0 -26
- package/Dialog/sc/index.stories.js +0 -75
- package/Dialog/sc/material.js +0 -78
- package/Dialog/tw/bare.js +0 -55
- package/Dialog/tw/elegant.js +0 -54
- package/Dialog/tw/framer.js +0 -26
- package/Dialog/tw/framerMaterial.js +0 -26
- package/Dialog/tw/index.stories.js +0 -113
- package/Dialog/tw/material.js +0 -54
- package/Editor/Editor--tiptap.js +0 -72
- package/Editor/components.js +0 -59
- package/Editor/index.js +0 -6
- package/FaviconTags.js +0 -73
- package/Form/Form.js +0 -130
- package/Form/index.js +0 -6
- package/Form/sc/bare.js +0 -55
- package/Forms/Checkbox/Checkbox.js +0 -62
- package/Forms/Checkbox/index.js +0 -6
- package/Forms/Feedback/Feedback.js +0 -25
- package/Forms/Feedback/index.js +0 -6
- package/Forms/Field/Field.js +0 -75
- package/Forms/Field/FieldControl.js +0 -69
- package/Forms/Field/FieldHint.js +0 -17
- package/Forms/Field/index.js +0 -7
- package/Forms/Input/Input.js +0 -67
- package/Forms/Input/index.js +0 -6
- package/Forms/InputGroup/InputGroup.js +0 -85
- package/Forms/InputGroup/index.js +0 -6
- package/Forms/Label/Label.js +0 -46
- package/Forms/Label/index.js +0 -6
- package/Forms/Password/Password.js +0 -72
- package/Forms/Password/index.js +0 -6
- package/Forms/Radio/Radio.js +0 -68
- package/Forms/Radio/index.js +0 -6
- package/Forms/Switch/Switch.js +0 -80
- package/Forms/Switch/index.js +0 -6
- package/Forms/Textarea/Textarea.js +0 -45
- package/Forms/Textarea/TextareaRich.js +0 -58
- package/Forms/Textarea/index.js +0 -7
- package/Forms/Toggle/Toggle-tailwind.js +0 -99
- package/Forms/Toggle/Toggle.js +0 -175
- package/Forms/Toggle/index.js +0 -6
- package/Forms/Toggle/useToggle-tailwind.js +0 -202
- package/Forms/Toggle/useToggle.js +0 -145
- package/Forms/antispam.js +0 -59
- package/Forms/helpers.js +0 -72
- package/Forms/index.js +0 -19
- package/Forms/styles.js +0 -94
- package/Gauge/Gauge.js +0 -111
- package/Grid/Grid.js +0 -106
- package/Grid/index.js +0 -6
- package/Hamburger/Hamburger.js +0 -90
- package/Hamburger/index.js +0 -6
- package/Header/index.js +0 -6
- package/Header/useHeader.js +0 -54
- package/Hidden/Hidden.js +0 -21
- package/Hidden/index.js +0 -6
- package/Img/index.js +0 -6
- package/Img/sc/bare.js +0 -43
- package/Img/types.js +0 -6
- package/Link/Link.js +0 -13
- package/Link/LinkBlank.js +0 -52
- package/Link/index.js +0 -7
- package/Menu/Menu.js +0 -22
- package/Menu/MenuMui.js +0 -165
- package/Menu/index.js +0 -6
- package/MenuItem/MenuItem.js +0 -31
- package/MenuItem/MenuItemMui.js +0 -32
- package/MenuItem/index.js +0 -6
- package/MenuItem/useMenuItem.js +0 -96
- package/Meta/Meta.js +0 -26
- package/Meta/index.js +0 -12
- package/NoJs/NoJs.js +0 -28
- package/NoJs/index.js +0 -12
- package/Pagination/PaginationNav.js +0 -126
- package/Pagination/PaginationResults.js +0 -45
- package/Pagination/index.js +0 -7
- package/Pill/Pill.js +0 -62
- package/Pill/index.js +0 -6
- package/Progress/ProgressCircular.js +0 -62
- package/Progress/ProgressLinear.js +0 -53
- package/Progress/ProgressOverlay.js +0 -75
- package/Progress/index.js +0 -8
- package/Rating/Rating.js +0 -188
- package/Rating/index.js +0 -85
- package/Select/SelectDownshift.js +0 -47
- package/Select/components.js +0 -44
- package/Select/index.js +0 -13
- package/Sidebar/Sidebar.js +0 -74
- package/Sidebar/index.js +0 -6
- package/Spacing/Spacing.js +0 -55
- package/Spacing/index.js +0 -6
- package/Sticky/Sticky.js +0 -228
- package/Sticky/StickyCss.js +0 -20
- package/Sticky/index.js +0 -19
- package/Tabs/TabsMui.js +0 -91
- package/Tabs/TabsMui.stories.js +0 -38
- package/Tabs/index.js +0 -6
- package/Tabs/sc/bare.js +0 -86
- package/Tabs/sc/index.stories.js +0 -1
- package/Tabs/tw/bare.js +0 -45
- package/Tabs/tw/index.stories.js +0 -46
- package/Tabs/tw/material.js +0 -44
- package/Tabs/useTabs.js +0 -66
- package/Typography/CopyPasteVisible.js +0 -17
- package/Typography/Native.js +0 -90
- package/Typography/ReadMore.js +0 -125
- package/Typography/TextLoop.js +0 -108
- package/Typography/TypeStairs.js +0 -71
- package/Typography/index.js +0 -10
- package/css/index.js +0 -33
- package/helpers/classed.js +0 -66
- package/helpers/classed.stories.js +0 -140
- package/helpers/createUseMediaQueryWidth.js +0 -193
- package/helpers/extend-component.js +0 -32
- package/helpers/index.js +0 -9
- package/helpers/mergeRefs.js +0 -30
- package/hooks/index.js +0 -92
- package/hooks/types.js +0 -6
- package/hooks/useAsyncFn.js +0 -56
- package/hooks/useDateLocale.js +0 -51
- package/hooks/useFirstMountState.js +0 -28
- package/hooks/useFixedOffset.js +0 -67
- package/hooks/useFocus.js +0 -30
- package/hooks/useInterval.js +0 -44
- package/hooks/useIsomorphicLayoutEffect.js +0 -23
- package/hooks/useKeyUp.js +0 -40
- package/hooks/useMeasure.js +0 -189
- package/hooks/useMountedState.js +0 -31
- package/hooks/useNavigateAway.js +0 -69
- package/hooks/usePrevious.js +0 -33
- package/hooks/usePreviousRef.js +0 -27
- package/hooks/useScrollPosition.js +0 -83
- package/hooks/useScrollThreshold.js +0 -52
- package/hooks/useScrollTo.js +0 -39
- package/hooks/useSmoothScroll.js +0 -49
- package/hooks/useSpinDelay.js +0 -59
- package/hooks/useTraceUpdate.js +0 -39
- package/hooks/useUpdateEffect.js +0 -30
- package/hooks/useWindowSize.js +0 -43
- package/index.js +0 -10
- package/m/MotionProvider.js +0 -27
- package/m/index.js +0 -10
- package/m/lite.js +0 -12
- package/m/max.js +0 -12
- package/sc/index.js +0 -49
- package/scm/index.js +0 -40
- package/shared/index.js +0 -13
- package/styles/Body.js +0 -28
- package/styles/Global.js +0 -55
- package/styles/index.js +0 -142
- package/styles/media.js +0 -139
- package/styles/spacing.js +0 -70
- package/styles/styled.js +0 -58
- package/styles/theme--vanilla.js +0 -82
- package/styles/theme.js +0 -49
- package/tw/index.js +0 -33
- package/twm/index.js +0 -33
- package/types.js +0 -4
package/hooks/useFixedOffset.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useFixedOffset: function() {
|
|
13
|
-
return useFixedOffset;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _debounce = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/debounce"));
|
|
22
|
-
const _$each = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/$each"));
|
|
23
|
-
const _calculateFixedOffset = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/calculateFixedOffset"));
|
|
24
|
-
const _injectCss = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/injectCss"));
|
|
25
|
-
const _listenResizeDebounced = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/listenResizeDebounced"));
|
|
26
|
-
const _useIsomorphicLayoutEffect = /*#__PURE__*/ _interop_require_default._(require("./useIsomorphicLayoutEffect"));
|
|
27
|
-
const inject = (value)=>{
|
|
28
|
-
(0, _injectCss.default)("useFixedOffset", `html{scroll-padding-top: ${value}px}`);
|
|
29
|
-
};
|
|
30
|
-
function useFixedOffset(selector) {
|
|
31
|
-
const fixedOffset = (0, _react.useRef)(0);
|
|
32
|
-
(0, _useIsomorphicLayoutEffect.default)(()=>{
|
|
33
|
-
const update = ()=>{
|
|
34
|
-
const newFixedOffset = (0, _calculateFixedOffset.default)();
|
|
35
|
-
fixedOffset.current = newFixedOffset;
|
|
36
|
-
// inject this CSS make the hashed deeplinks position the scroll at the
|
|
37
|
-
// right offset
|
|
38
|
-
inject(newFixedOffset);
|
|
39
|
-
};
|
|
40
|
-
update();
|
|
41
|
-
if (ResizeObserver) {
|
|
42
|
-
// const elements = $$("[data-fixed]");
|
|
43
|
-
const observer = new ResizeObserver((entries)=>{
|
|
44
|
-
let newFixedOffset = 0;
|
|
45
|
-
entries.forEach((entry)=>{
|
|
46
|
-
newFixedOffset += entry.contentRect.height;
|
|
47
|
-
});
|
|
48
|
-
fixedOffset.current = newFixedOffset;
|
|
49
|
-
const updateOnResize = (0, _debounce.default)(()=>inject(newFixedOffset), 400, true);
|
|
50
|
-
updateOnResize();
|
|
51
|
-
});
|
|
52
|
-
(0, _$each.default)(selector || "[data-fixed]", ($el)=>{
|
|
53
|
-
if (observer) observer.observe($el);
|
|
54
|
-
});
|
|
55
|
-
return ()=>{
|
|
56
|
-
observer?.disconnect();
|
|
57
|
-
};
|
|
58
|
-
} else {
|
|
59
|
-
const listener = (0, _listenResizeDebounced.default)(0, update);
|
|
60
|
-
return listener;
|
|
61
|
-
}
|
|
62
|
-
}, [
|
|
63
|
-
selector
|
|
64
|
-
]);
|
|
65
|
-
return fixedOffset;
|
|
66
|
-
}
|
|
67
|
-
const _default = useFixedOffset;
|
package/hooks/useFocus.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useFocus: function() {
|
|
13
|
-
return useFocus;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _react = require("react");
|
|
20
|
-
const useFocus = ()=>{
|
|
21
|
-
const elementRef = (0, _react.useRef)(null);
|
|
22
|
-
const setFocus = ()=>{
|
|
23
|
-
elementRef.current && elementRef.current.focus();
|
|
24
|
-
};
|
|
25
|
-
return [
|
|
26
|
-
elementRef,
|
|
27
|
-
setFocus
|
|
28
|
-
];
|
|
29
|
-
};
|
|
30
|
-
const _default = useFocus;
|
package/hooks/useInterval.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useInterval: function() {
|
|
13
|
-
return useInterval;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _noop = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/noop"));
|
|
22
|
-
function useInterval(callback, delay, deps = []) {
|
|
23
|
-
const savedCallback = (0, _react.useRef)();
|
|
24
|
-
(0, _react.useEffect)(()=>{
|
|
25
|
-
savedCallback.current = callback;
|
|
26
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
-
}, [
|
|
28
|
-
callback,
|
|
29
|
-
...deps
|
|
30
|
-
]);
|
|
31
|
-
(0, _react.useEffect)(()=>{
|
|
32
|
-
function tick() {
|
|
33
|
-
if (savedCallback.current) savedCallback.current();
|
|
34
|
-
}
|
|
35
|
-
if (delay !== null) {
|
|
36
|
-
const id = setInterval(tick, delay);
|
|
37
|
-
return ()=>clearInterval(id);
|
|
38
|
-
}
|
|
39
|
-
return _noop.default;
|
|
40
|
-
}, [
|
|
41
|
-
delay
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
const _default = useInterval;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useIsomorphicLayoutEffect: function() {
|
|
13
|
-
return useIsomorphicLayoutEffect;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _isBrowser = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isBrowser"));
|
|
22
|
-
const useIsomorphicLayoutEffect = _isBrowser.default ? _react.useLayoutEffect : _react.useEffect;
|
|
23
|
-
const _default = useIsomorphicLayoutEffect;
|
package/hooks/useKeyUp.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useKeyUp: function() {
|
|
13
|
-
return useKeyUp;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _on = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/on"));
|
|
22
|
-
function useKeyUp(callback, deps = []) {
|
|
23
|
-
(0, _react.useEffect)(()=>{
|
|
24
|
-
const listener = (0, _on.default)(window, "keyup", (event)=>{
|
|
25
|
-
// const { key } = event;
|
|
26
|
-
// be sure we do not intercept keys combinations maybe used for other
|
|
27
|
-
// actions like native browser navigation shortcuts
|
|
28
|
-
// @see https://stackoverflow.com/a/37559790/1938970
|
|
29
|
-
if (!event.ctrlKey && !event.altKey && !event.shiftKey && !event.metaKey) {
|
|
30
|
-
callback(event);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return listener;
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
}, [
|
|
36
|
-
callback,
|
|
37
|
-
...deps
|
|
38
|
-
]);
|
|
39
|
-
}
|
|
40
|
-
const _default = useKeyUp;
|
package/hooks/useMeasure.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useMeasure: function() {
|
|
13
|
-
return useMeasure;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _debounce = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/debounce"));
|
|
22
|
-
const _noop = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/noop"));
|
|
23
|
-
const _listenResizeDebounced = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/listenResizeDebounced"));
|
|
24
|
-
const _listenScrollDebounced = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/listenScrollDebounced"));
|
|
25
|
-
const _off = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/off"));
|
|
26
|
-
const _on = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/on"));
|
|
27
|
-
let observer;
|
|
28
|
-
// Returns a list of scroll offsets
|
|
29
|
-
function findScrollContainers(element) {
|
|
30
|
-
const result = [];
|
|
31
|
-
if (!element || element === document.body) return result;
|
|
32
|
-
const { overflow, overflowX, overflowY } = window.getComputedStyle(element);
|
|
33
|
-
if ([
|
|
34
|
-
overflow,
|
|
35
|
-
overflowX,
|
|
36
|
-
overflowY
|
|
37
|
-
].some((prop)=>prop === "auto" || prop === "scroll")) result.push(element);
|
|
38
|
-
return [
|
|
39
|
-
...result,
|
|
40
|
-
...findScrollContainers(element.parentElement)
|
|
41
|
-
];
|
|
42
|
-
}
|
|
43
|
-
const keys = [
|
|
44
|
-
"x",
|
|
45
|
-
"y",
|
|
46
|
-
"top",
|
|
47
|
-
"bottom",
|
|
48
|
-
"left",
|
|
49
|
-
"right",
|
|
50
|
-
"width",
|
|
51
|
-
"height"
|
|
52
|
-
];
|
|
53
|
-
const areBoundsEqual = (a, b)=>keys.every((key)=>a[key] === b[key]);
|
|
54
|
-
function useMeasure(options) {
|
|
55
|
-
const { scroll = false } = options || {};
|
|
56
|
-
const [bounds, setBounds] = (0, _react.useState)({
|
|
57
|
-
left: 0,
|
|
58
|
-
top: 0,
|
|
59
|
-
width: 0,
|
|
60
|
-
height: 0,
|
|
61
|
-
bottom: 0,
|
|
62
|
-
right: 0,
|
|
63
|
-
x: 0,
|
|
64
|
-
y: 0
|
|
65
|
-
});
|
|
66
|
-
// keep all state in a ref
|
|
67
|
-
const state = (0, _react.useRef)([
|
|
68
|
-
// element
|
|
69
|
-
null,
|
|
70
|
-
// scrollContainers
|
|
71
|
-
null,
|
|
72
|
-
// resizeObserver
|
|
73
|
-
null,
|
|
74
|
-
// lastBounds
|
|
75
|
-
bounds
|
|
76
|
-
]);
|
|
77
|
-
// make sure to update state only as long as the component is truly mounted
|
|
78
|
-
const mounted = (0, _react.useRef)(false);
|
|
79
|
-
(0, _react.useEffect)(()=>{
|
|
80
|
-
mounted.current = true;
|
|
81
|
-
return ()=>void (mounted.current = false);
|
|
82
|
-
}, []);
|
|
83
|
-
// memoize handlers, so event-listeners know when they should update
|
|
84
|
-
const [forceRefresh /* resizeChange */ , , scrollChange] = (0, _react.useMemo)(()=>{
|
|
85
|
-
const callback = (..._args)=>{
|
|
86
|
-
const [element, , , lastBounds] = state.current;
|
|
87
|
-
if (!element) return;
|
|
88
|
-
const size = element.getBoundingClientRect();
|
|
89
|
-
// if (element instanceof HTMLElement && offsetSize) {
|
|
90
|
-
// size.height = element.offsetHeight;
|
|
91
|
-
// size.width = element.offsetWidth;
|
|
92
|
-
// }
|
|
93
|
-
Object.freeze(size);
|
|
94
|
-
if (mounted.current && !areBoundsEqual(lastBounds, size)) {
|
|
95
|
-
state.current[3] = size;
|
|
96
|
-
setBounds(size);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const debouncedCallback = (0, _debounce.default)(callback);
|
|
100
|
-
return [
|
|
101
|
-
callback,
|
|
102
|
-
debouncedCallback,
|
|
103
|
-
debouncedCallback
|
|
104
|
-
];
|
|
105
|
-
}, [
|
|
106
|
-
setBounds /* , offsetSize */
|
|
107
|
-
]);
|
|
108
|
-
// cleanup current scroll-listeners / observers
|
|
109
|
-
function removeListeners() {
|
|
110
|
-
const [, scrollContainers, resizeObserver] = state.current;
|
|
111
|
-
if (scrollContainers) {
|
|
112
|
-
scrollContainers.forEach((element)=>(0, _off.default)(element, "scroll", scrollChange));
|
|
113
|
-
state.current[1] = null;
|
|
114
|
-
}
|
|
115
|
-
if (resizeObserver) {
|
|
116
|
-
resizeObserver.disconnect();
|
|
117
|
-
state.current[2] = null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// add scroll-listeners / observers
|
|
121
|
-
function addListeners() {
|
|
122
|
-
const [element, scrollContainers] = state.current;
|
|
123
|
-
if (!element) return;
|
|
124
|
-
if (!observer && ResizeObserver) {
|
|
125
|
-
observer = new ResizeObserver(scrollChange);
|
|
126
|
-
state.current[2] = observer;
|
|
127
|
-
observer.observe(element);
|
|
128
|
-
if (scroll && scrollContainers) {
|
|
129
|
-
scrollContainers.forEach((scrollContainer)=>(0, _on.default)(scrollContainer, "scroll", scrollChange, {
|
|
130
|
-
capture: true,
|
|
131
|
-
passive: true
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// the ref we expose to the user
|
|
137
|
-
const ref = (node)=>{
|
|
138
|
-
if (!node || node === state.current[0]) return;
|
|
139
|
-
removeListeners();
|
|
140
|
-
state.current[0] = node;
|
|
141
|
-
state.current[1] = findScrollContainers(node);
|
|
142
|
-
addListeners();
|
|
143
|
-
};
|
|
144
|
-
// add general event listeners
|
|
145
|
-
// useOnWindowScroll(forceRefresh, Boolean(scroll));
|
|
146
|
-
// useOnWindowResize(() => {
|
|
147
|
-
// debugger;
|
|
148
|
-
// forceRefresh();
|
|
149
|
-
// });
|
|
150
|
-
(0, _react.useEffect)(()=>{
|
|
151
|
-
if (scroll) {
|
|
152
|
-
const listener = (0, _listenScrollDebounced.default)(0, forceRefresh, 100);
|
|
153
|
-
return listener;
|
|
154
|
-
}
|
|
155
|
-
return _noop.default;
|
|
156
|
-
}, [
|
|
157
|
-
scroll,
|
|
158
|
-
forceRefresh
|
|
159
|
-
]);
|
|
160
|
-
(0, _react.useEffect)(()=>{
|
|
161
|
-
// const listener = listenResizeDebounced(onWindowResize);
|
|
162
|
-
// return listener;
|
|
163
|
-
const listener = (0, _listenResizeDebounced.default)(0, forceRefresh, 100);
|
|
164
|
-
return listener;
|
|
165
|
-
}, [
|
|
166
|
-
forceRefresh
|
|
167
|
-
]);
|
|
168
|
-
// respond to changes that are relevant for the listeners
|
|
169
|
-
(0, _react.useEffect)(()=>{
|
|
170
|
-
removeListeners();
|
|
171
|
-
addListeners();
|
|
172
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
-
}, [
|
|
174
|
-
scroll /* , scrollChange, resizeChange */
|
|
175
|
-
]);
|
|
176
|
-
(0, _react.useEffect)(()=>{
|
|
177
|
-
// operate on mount, @kuus on the original version there is no call on mount?
|
|
178
|
-
forceRefresh();
|
|
179
|
-
// remove all listeners when the components unmounts
|
|
180
|
-
return removeListeners;
|
|
181
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
182
|
-
}, []);
|
|
183
|
-
return [
|
|
184
|
-
ref,
|
|
185
|
-
bounds,
|
|
186
|
-
forceRefresh
|
|
187
|
-
];
|
|
188
|
-
}
|
|
189
|
-
const _default = useMeasure;
|
package/hooks/useMountedState.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useMountedState: function() {
|
|
13
|
-
return useMountedState;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _react = require("react");
|
|
20
|
-
function useMountedState() {
|
|
21
|
-
const mountedRef = (0, _react.useRef)(false);
|
|
22
|
-
const get = (0, _react.useCallback)(()=>mountedRef.current, []);
|
|
23
|
-
(0, _react.useEffect)(()=>{
|
|
24
|
-
mountedRef.current = true;
|
|
25
|
-
return ()=>{
|
|
26
|
-
mountedRef.current = false;
|
|
27
|
-
};
|
|
28
|
-
}, []);
|
|
29
|
-
return get;
|
|
30
|
-
}
|
|
31
|
-
const _default = useMountedState;
|
package/hooks/useNavigateAway.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useNavigateAway: function() {
|
|
13
|
-
return useNavigateAway;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _on = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/on"));
|
|
22
|
-
const useNavigateAway = (handler)=>{
|
|
23
|
-
const beforeUnloadHandlerRef = (0, _react.useRef)();
|
|
24
|
-
// const pagehideHandlerRef = useRef<UseNavigateAwayPagehideHandler | undefined>();
|
|
25
|
-
(0, _react.useEffect)(()=>{
|
|
26
|
-
beforeUnloadHandlerRef.current = (event)=>{
|
|
27
|
-
const customMessageOrCondition = handler(event);
|
|
28
|
-
if (customMessageOrCondition) {
|
|
29
|
-
event.preventDefault();
|
|
30
|
-
}
|
|
31
|
-
// Handle legacy `event.returnValue` property
|
|
32
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
|
|
33
|
-
if (typeof customMessageOrCondition === "string") {
|
|
34
|
-
return event.returnValue = customMessageOrCondition;
|
|
35
|
-
}
|
|
36
|
-
// Chrome doesn't support `event.preventDefault()` on `BeforeUnloadEvent`,
|
|
37
|
-
// instead it requires `event.returnValue` to be set
|
|
38
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#browser_compatibility
|
|
39
|
-
if (event.defaultPrevented) {
|
|
40
|
-
return event.returnValue = "";
|
|
41
|
-
}
|
|
42
|
-
return;
|
|
43
|
-
};
|
|
44
|
-
// pagehideHandlerRef.current = (event) => {
|
|
45
|
-
// const returnValue = handler?.(event);
|
|
46
|
-
// if (event.persisted) {
|
|
47
|
-
// // If the event's persisted property is `true` the page is about
|
|
48
|
-
// // to enter the Back-Forward Cache, which is also in the frozen state.
|
|
49
|
-
// } else {
|
|
50
|
-
// // If the event's persisted property is not `true` the page is
|
|
51
|
-
// // about to be unloaded.
|
|
52
|
-
// }
|
|
53
|
-
// };
|
|
54
|
-
}, [
|
|
55
|
-
handler
|
|
56
|
-
]);
|
|
57
|
-
(0, _react.useEffect)(()=>{
|
|
58
|
-
const listenerBeforeunload = (0, _on.default)(window, "beforeunload", (event)=>beforeUnloadHandlerRef.current?.(event));
|
|
59
|
-
// const listenerPagehide = on(window, "pagehide", (event) =>
|
|
60
|
-
// pagehideHandlerRef.current?.(event)
|
|
61
|
-
// );
|
|
62
|
-
return listenerBeforeunload;
|
|
63
|
-
// return () => {
|
|
64
|
-
// listenerBeforeunload();
|
|
65
|
-
// // listenerPagehide();
|
|
66
|
-
// };
|
|
67
|
-
}, []);
|
|
68
|
-
};
|
|
69
|
-
const _default = useNavigateAway;
|
package/hooks/usePrevious.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
usePrevious: function() {
|
|
13
|
-
return usePrevious;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _react = require("react");
|
|
20
|
-
function usePrevious(state, defaulValue) {
|
|
21
|
-
const [tuple, setTuple] = (0, _react.useState)([
|
|
22
|
-
state,
|
|
23
|
-
defaulValue
|
|
24
|
-
]);
|
|
25
|
-
if (tuple[1] !== state) {
|
|
26
|
-
setTuple([
|
|
27
|
-
tuple[1],
|
|
28
|
-
state
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
return tuple[0];
|
|
32
|
-
}
|
|
33
|
-
const _default = usePrevious;
|
package/hooks/usePreviousRef.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
usePreviousRef: function() {
|
|
13
|
-
return usePreviousRef;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _react = require("react");
|
|
20
|
-
function usePreviousRef(value) {
|
|
21
|
-
const ref = (0, _react.useRef)();
|
|
22
|
-
(0, _react.useEffect)(()=>{
|
|
23
|
-
ref.current = value;
|
|
24
|
-
});
|
|
25
|
-
return ref.current;
|
|
26
|
-
}
|
|
27
|
-
const _default = usePreviousRef;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
useScrollPosition: function() {
|
|
13
|
-
return useScrollPosition;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _react = require("react");
|
|
21
|
-
const _isBrowser = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isBrowser"));
|
|
22
|
-
const _listenScroll = /*#__PURE__*/ _interop_require_default._(require("@koine/dom/listenScroll"));
|
|
23
|
-
const _useIsomorphicLayoutEffect = /*#__PURE__*/ _interop_require_default._(require("./useIsomorphicLayoutEffect"));
|
|
24
|
-
const zeroPosition = {
|
|
25
|
-
x: 0,
|
|
26
|
-
y: 0
|
|
27
|
-
};
|
|
28
|
-
const getClientRect = (element)=>element?.getBoundingClientRect();
|
|
29
|
-
const getScrollPosition = (element, boundingElement)=>{
|
|
30
|
-
if (!_isBrowser.default) {
|
|
31
|
-
return zeroPosition;
|
|
32
|
-
}
|
|
33
|
-
if (!boundingElement) {
|
|
34
|
-
return {
|
|
35
|
-
x: window.scrollX,
|
|
36
|
-
y: window.scrollY
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const targetPosition = getClientRect(element?.current || document.body);
|
|
40
|
-
const containerPosition = getClientRect(boundingElement.current);
|
|
41
|
-
if (!targetPosition) {
|
|
42
|
-
return zeroPosition;
|
|
43
|
-
}
|
|
44
|
-
return containerPosition ? {
|
|
45
|
-
x: (containerPosition.x || 0) - (targetPosition.x || 0),
|
|
46
|
-
y: (containerPosition.y || 0) - (targetPosition.y || 0)
|
|
47
|
-
} : {
|
|
48
|
-
x: targetPosition.left,
|
|
49
|
-
y: targetPosition.top
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
const useScrollPosition = (effect, deps = [], element, boundingElement, wait)=>{
|
|
53
|
-
const position = (0, _react.useRef)(getScrollPosition(null, boundingElement));
|
|
54
|
-
let throttleTimeout = null;
|
|
55
|
-
const callBack = ()=>{
|
|
56
|
-
const current = getScrollPosition(element, boundingElement);
|
|
57
|
-
effect(current, position.current);
|
|
58
|
-
position.current = current;
|
|
59
|
-
throttleTimeout = null;
|
|
60
|
-
};
|
|
61
|
-
(0, _useIsomorphicLayoutEffect.default)(()=>{
|
|
62
|
-
if (!_isBrowser.default) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
const handleScroll = ()=>{
|
|
66
|
-
if (wait) {
|
|
67
|
-
if (throttleTimeout === null) {
|
|
68
|
-
throttleTimeout = window.setTimeout(callBack, wait);
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
callBack();
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const listener = (0, _listenScroll.default)(handleScroll, boundingElement?.current);
|
|
75
|
-
return ()=>{
|
|
76
|
-
listener();
|
|
77
|
-
if (throttleTimeout) {
|
|
78
|
-
clearTimeout(throttleTimeout);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}, deps);
|
|
82
|
-
};
|
|
83
|
-
const _default = useScrollPosition;
|