overlayscrollbars-react 0.5.5 → 0.5.7
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/CHANGELOG.md +12 -0
- package/README.md +146 -146
- package/overlayscrollbars-react.cjs +1 -1
- package/overlayscrollbars-react.cjs.js +1 -1
- package/overlayscrollbars-react.cjs.js.map +1 -1
- package/overlayscrollbars-react.cjs.map +1 -1
- package/overlayscrollbars-react.esm.js +43 -38
- package/overlayscrollbars-react.esm.js.map +1 -1
- package/overlayscrollbars-react.mjs +43 -38
- package/overlayscrollbars-react.mjs.map +1 -1
- package/overlayscrollbars-react.umd.cjs +2 -0
- package/overlayscrollbars-react.umd.cjs.map +1 -0
- package/package.json +1 -1
- package/types/OverlayScrollbarsComponent.d.ts +5 -7
- package/overlayscrollbars-react.umd.js +0 -2
- package/overlayscrollbars-react.umd.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.7
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Use `ComponentRef<T>` instead of `ElementRef<T>`. ([#760](https://github.com/KingSora/OverlayScrollbars/issues/760))
|
|
8
|
+
|
|
9
|
+
## 0.5.6
|
|
10
|
+
|
|
11
|
+
### Improvements
|
|
12
|
+
|
|
13
|
+
- The `OverlayScrollbarsComponent` now properly supports `'body'` as its element tag.
|
|
14
|
+
|
|
3
15
|
## 0.5.5
|
|
4
16
|
|
|
5
17
|
### Improvements
|
package/README.md
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<a href="https://kingsora.github.io/OverlayScrollbars"><img src="https://raw.githubusercontent.com/KingSora/OverlayScrollbars/master/logo/logo.png" width="160" height="160" alt="OverlayScrollbars"></a>
|
|
3
|
-
<a href="https://reactjs.org"><img src="https://raw.githubusercontent.com/KingSora/OverlayScrollbars/master/packages/overlayscrollbars-react/logo.svg" width="160" height="160" alt="React"></a>
|
|
4
|
-
</div>
|
|
5
|
-
<br />
|
|
6
|
-
<div align="center">
|
|
7
|
-
|
|
8
|
-
[](https://github.com/KingSora/OverlayScrollbars)
|
|
9
|
-
[](https://github.com/facebook/react/)
|
|
10
|
-
[](https://www.npmjs.com/package/overlayscrollbars-react)
|
|
11
|
-
[](https://www.npmjs.com/package/overlayscrollbars-react)
|
|
12
|
-
[](#)
|
|
13
|
-
|
|
14
|
-
</div>
|
|
15
|
-
<h3 align="center">
|
|
16
|
-
<a href="https://kingsora.github.io/OverlayScrollbars">Website</a>
|
|
17
|
-
•
|
|
18
|
-
<a href="https://kingsora.github.io/OverlayScrollbars/examples">Examples</a>
|
|
19
|
-
</h3>
|
|
20
|
-
|
|
21
|
-
# OverlayScrollbars for React
|
|
22
|
-
|
|
23
|
-
This is the official OverlayScrollbars React wrapper.
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
npm install overlayscrollbars-react
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Peer Dependencies
|
|
32
|
-
|
|
33
|
-
OverlayScrollbars for React has the following **peer dependencies**:
|
|
34
|
-
|
|
35
|
-
- The vanilla JavaScript library: [overlayscrollbars](https://www.npmjs.com/package/overlayscrollbars)
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
npm install overlayscrollbars
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
- The React framework: [react](https://www.npmjs.com/package/react)
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
npm install react
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Usage
|
|
48
|
-
|
|
49
|
-
The first step is to import the CSS file into your app:
|
|
50
|
-
```ts
|
|
51
|
-
import 'overlayscrollbars/overlayscrollbars.css';
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
> __Note__: If the path `'overlayscrollbars/overlayscrollbars.css'` is not working use `'overlayscrollbars/styles/overlayscrollbars.css'` as the import path for the CSS file.
|
|
55
|
-
|
|
56
|
-
## Component
|
|
57
|
-
|
|
58
|
-
The main entry point is the `OverlayScrollbarsComponent` which can be used in your application as a component:
|
|
59
|
-
|
|
60
|
-
```jsx
|
|
61
|
-
import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
|
|
62
|
-
|
|
63
|
-
// ...
|
|
64
|
-
|
|
65
|
-
<OverlayScrollbarsComponent defer>
|
|
66
|
-
example content
|
|
67
|
-
</OverlayScrollbarsComponent>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Properties
|
|
71
|
-
|
|
72
|
-
The component accepts all properties of regular elements such as `div` and `span`.
|
|
73
|
-
Additionally it has custom optional properties:
|
|
74
|
-
|
|
75
|
-
- `element`: accepts a `string` which represents the tag of the root element.
|
|
76
|
-
- `options`: accepts an `object` which represents the OverlayScrollbars options.
|
|
77
|
-
- `events`: accepts an `object` which represents the OverlayScrollbars events.
|
|
78
|
-
- `defer`: accepts an `boolean` or `object`. Defers the initialization to a point in time when the browser is idle.
|
|
79
|
-
|
|
80
|
-
> __Note__: None of the properties has to be memoized.
|
|
81
|
-
|
|
82
|
-
> __Note__: Its **highly recommended** to use the `defer` option whenever possible to defer the initialization to a browser's idle period.
|
|
83
|
-
|
|
84
|
-
```jsx
|
|
85
|
-
// example usage
|
|
86
|
-
<OverlayScrollbarsComponent
|
|
87
|
-
element="span"
|
|
88
|
-
options={{ scrollbars: { autoHide: 'scroll' } }}
|
|
89
|
-
events={{ scroll: () => { /* ... */ } }}
|
|
90
|
-
defer
|
|
91
|
-
/>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Ref
|
|
95
|
-
|
|
96
|
-
The `ref` of the `OverlayScrollbarsComponent` will give you an object with which you can access the OverlayScrollbars `instance` and the root `element` of the component.
|
|
97
|
-
The ref object has two properties:
|
|
98
|
-
|
|
99
|
-
- `osInstance`: a function which returns the OverlayScrollbars instance.
|
|
100
|
-
- `getElement`: a function which returns the root element.
|
|
101
|
-
|
|
102
|
-
## Hook
|
|
103
|
-
|
|
104
|
-
In case the `OverlayScrollbarsComponent` is not enough, you can also use the `useOverlayScrollbars` hook:
|
|
105
|
-
|
|
106
|
-
```jsx
|
|
107
|
-
import { useOverlayScrollbars } from "overlayscrollbars-react";
|
|
108
|
-
|
|
109
|
-
// example usage
|
|
110
|
-
const Component = () => {
|
|
111
|
-
const ref = useRef();
|
|
112
|
-
const [initialize, instance] = useOverlayScrollbars({ options, events, defer });
|
|
113
|
-
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
initialize(ref.current);
|
|
116
|
-
}, [initialize]);
|
|
117
|
-
|
|
118
|
-
return <div ref={ref} />
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
The hook is for advanced usage and lets you control the whole initialization process. This is useful if you want to integrate it with other plugins such as `react-window` or `react-virtualized`.
|
|
123
|
-
|
|
124
|
-
The hook will destroy the instance automatically if the component unmounts.
|
|
125
|
-
|
|
126
|
-
### Parameters
|
|
127
|
-
|
|
128
|
-
Parameters are optional and similar to the `OverlayScrollbarsComponent`.
|
|
129
|
-
Its an `object` with optional properties:
|
|
130
|
-
|
|
131
|
-
- `options`: accepts an `object` which represents the OverlayScrollbars options.
|
|
132
|
-
- `events`: accepts an `object` which represents the OverlayScrollbars events.
|
|
133
|
-
- `defer`: accepts an `boolean` or `object`. Defers the initialization to a point in time when the browser is idle.
|
|
134
|
-
|
|
135
|
-
### Return
|
|
136
|
-
|
|
137
|
-
The `useOverlayScrollbars` hook returns a `tuple` with two values:
|
|
138
|
-
|
|
139
|
-
- The first value is the `initialization` function, it takes one argument which is the `InitializationTarget`.
|
|
140
|
-
- The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.
|
|
141
|
-
|
|
142
|
-
> __Note__: The identity of both functions is stable and won't change, thus they can safely be used in any dependency array.
|
|
143
|
-
|
|
144
|
-
## License
|
|
145
|
-
|
|
146
|
-
MIT
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://kingsora.github.io/OverlayScrollbars"><img src="https://raw.githubusercontent.com/KingSora/OverlayScrollbars/master/logo/logo.png" width="160" height="160" alt="OverlayScrollbars"></a>
|
|
3
|
+
<a href="https://reactjs.org"><img src="https://raw.githubusercontent.com/KingSora/OverlayScrollbars/master/packages/overlayscrollbars-react/logo.svg" width="160" height="160" alt="React"></a>
|
|
4
|
+
</div>
|
|
5
|
+
<br />
|
|
6
|
+
<div align="center">
|
|
7
|
+
|
|
8
|
+
[](https://github.com/KingSora/OverlayScrollbars)
|
|
9
|
+
[](https://github.com/facebook/react/)
|
|
10
|
+
[](https://www.npmjs.com/package/overlayscrollbars-react)
|
|
11
|
+
[](https://www.npmjs.com/package/overlayscrollbars-react)
|
|
12
|
+
[](#)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
<h3 align="center">
|
|
16
|
+
<a href="https://kingsora.github.io/OverlayScrollbars">Website</a>
|
|
17
|
+
•
|
|
18
|
+
<a href="https://kingsora.github.io/OverlayScrollbars/examples">Examples</a>
|
|
19
|
+
</h3>
|
|
20
|
+
|
|
21
|
+
# OverlayScrollbars for React
|
|
22
|
+
|
|
23
|
+
This is the official OverlayScrollbars React wrapper.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
npm install overlayscrollbars-react
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Peer Dependencies
|
|
32
|
+
|
|
33
|
+
OverlayScrollbars for React has the following **peer dependencies**:
|
|
34
|
+
|
|
35
|
+
- The vanilla JavaScript library: [overlayscrollbars](https://www.npmjs.com/package/overlayscrollbars)
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
npm install overlayscrollbars
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- The React framework: [react](https://www.npmjs.com/package/react)
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
npm install react
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
The first step is to import the CSS file into your app:
|
|
50
|
+
```ts
|
|
51
|
+
import 'overlayscrollbars/overlayscrollbars.css';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
> __Note__: If the path `'overlayscrollbars/overlayscrollbars.css'` is not working use `'overlayscrollbars/styles/overlayscrollbars.css'` as the import path for the CSS file.
|
|
55
|
+
|
|
56
|
+
## Component
|
|
57
|
+
|
|
58
|
+
The main entry point is the `OverlayScrollbarsComponent` which can be used in your application as a component:
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
|
|
62
|
+
|
|
63
|
+
// ...
|
|
64
|
+
|
|
65
|
+
<OverlayScrollbarsComponent defer>
|
|
66
|
+
example content
|
|
67
|
+
</OverlayScrollbarsComponent>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Properties
|
|
71
|
+
|
|
72
|
+
The component accepts all properties of regular elements such as `div` and `span`.
|
|
73
|
+
Additionally it has custom optional properties:
|
|
74
|
+
|
|
75
|
+
- `element`: accepts a `string` which represents the tag of the root element.
|
|
76
|
+
- `options`: accepts an `object` which represents the OverlayScrollbars options.
|
|
77
|
+
- `events`: accepts an `object` which represents the OverlayScrollbars events.
|
|
78
|
+
- `defer`: accepts an `boolean` or `object`. Defers the initialization to a point in time when the browser is idle.
|
|
79
|
+
|
|
80
|
+
> __Note__: None of the properties has to be memoized.
|
|
81
|
+
|
|
82
|
+
> __Note__: Its **highly recommended** to use the `defer` option whenever possible to defer the initialization to a browser's idle period.
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
// example usage
|
|
86
|
+
<OverlayScrollbarsComponent
|
|
87
|
+
element="span"
|
|
88
|
+
options={{ scrollbars: { autoHide: 'scroll' } }}
|
|
89
|
+
events={{ scroll: () => { /* ... */ } }}
|
|
90
|
+
defer
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Ref
|
|
95
|
+
|
|
96
|
+
The `ref` of the `OverlayScrollbarsComponent` will give you an object with which you can access the OverlayScrollbars `instance` and the root `element` of the component.
|
|
97
|
+
The ref object has two properties:
|
|
98
|
+
|
|
99
|
+
- `osInstance`: a function which returns the OverlayScrollbars instance.
|
|
100
|
+
- `getElement`: a function which returns the root element.
|
|
101
|
+
|
|
102
|
+
## Hook
|
|
103
|
+
|
|
104
|
+
In case the `OverlayScrollbarsComponent` is not enough, you can also use the `useOverlayScrollbars` hook:
|
|
105
|
+
|
|
106
|
+
```jsx
|
|
107
|
+
import { useOverlayScrollbars } from "overlayscrollbars-react";
|
|
108
|
+
|
|
109
|
+
// example usage
|
|
110
|
+
const Component = () => {
|
|
111
|
+
const ref = useRef();
|
|
112
|
+
const [initialize, instance] = useOverlayScrollbars({ options, events, defer });
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
initialize(ref.current);
|
|
116
|
+
}, [initialize]);
|
|
117
|
+
|
|
118
|
+
return <div ref={ref} />
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The hook is for advanced usage and lets you control the whole initialization process. This is useful if you want to integrate it with other plugins such as `react-window` or `react-virtualized`.
|
|
123
|
+
|
|
124
|
+
The hook will destroy the instance automatically if the component unmounts.
|
|
125
|
+
|
|
126
|
+
### Parameters
|
|
127
|
+
|
|
128
|
+
Parameters are optional and similar to the `OverlayScrollbarsComponent`.
|
|
129
|
+
Its an `object` with optional properties:
|
|
130
|
+
|
|
131
|
+
- `options`: accepts an `object` which represents the OverlayScrollbars options.
|
|
132
|
+
- `events`: accepts an `object` which represents the OverlayScrollbars events.
|
|
133
|
+
- `defer`: accepts an `boolean` or `object`. Defers the initialization to a point in time when the browser is idle.
|
|
134
|
+
|
|
135
|
+
### Return
|
|
136
|
+
|
|
137
|
+
The `useOverlayScrollbars` hook returns a `tuple` with two values:
|
|
138
|
+
|
|
139
|
+
- The first value is the `initialization` function, it takes one argument which is the `InitializationTarget`.
|
|
140
|
+
- The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.
|
|
141
|
+
|
|
142
|
+
> __Note__: The identity of both functions is stable and won't change, thus they can safely be used in any dependency array.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),p=require("overlayscrollbars"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),p=require("overlayscrollbars"),O=()=>{if(typeof window>"u"){const n=()=>{};return[n,n]}let a,o;const t=window,s=typeof t.requestIdleCallback=="function",u=t.requestAnimationFrame,i=t.cancelAnimationFrame,c=s?t.requestIdleCallback:u,f=s?t.cancelIdleCallback:i,l=()=>{f(a),i(o)};return[(n,r)=>{l(),a=c(s?()=>{l(),o=u(n)}:n,typeof r=="object"?r:{timeout:2233})},l]},S=a=>{const{options:o,events:t,defer:s}=a||{},[u,i]=e.useMemo(O,[]),c=e.useRef(null),f=e.useRef(s),l=e.useRef(o),n=e.useRef(t);return e.useEffect(()=>{f.current=s},[s]),e.useEffect(()=>{const{current:r}=c;l.current=o,p.OverlayScrollbars.valid(r)&&r.options(o||{},!0)},[o]),e.useEffect(()=>{const{current:r}=c;n.current=t,p.OverlayScrollbars.valid(r)&&r.on(t||{},!0)},[t]),e.useEffect(()=>()=>{var r;i(),(r=c.current)==null||r.destroy()},[]),e.useMemo(()=>[r=>{const b=c.current;if(p.OverlayScrollbars.valid(b))return;const d=l.current,m=n.current,v=f.current,y=()=>c.current=p.OverlayScrollbars(r,d||{},m||{});v?u(y,v):y()},()=>c.current],[])},E=(a,o)=>{const{element:t="div",options:s,events:u,defer:i,children:c,...f}=a,l=t,n=e.useRef(null),r=e.useRef(null),[b,d]=S({options:s,events:u,defer:i});return e.useEffect(()=>{const{current:m}=n,{current:v}=r;if(!m)return;const y=m;return b(t==="body"?{target:y,cancel:{body:null}}:{target:y,elements:{viewport:v,content:v}}),()=>{var R;return(R=d())==null?void 0:R.destroy()}},[b,d,t]),e.useImperativeHandle(o,()=>({osInstance:d,getElement:()=>n.current}),[d]),e.createElement(l,{"data-overlayscrollbars-initialize":"",ref:n,...f},t==="body"?c:e.createElement("div",{"data-overlayscrollbars-contents":"",ref:r},c))},I=e.forwardRef(E);exports.OverlayScrollbarsComponent=I;exports.useOverlayScrollbars=S;
|
|
2
2
|
//# sourceMappingURL=overlayscrollbars-react.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),p=require("overlayscrollbars"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),p=require("overlayscrollbars"),O=()=>{if(typeof window>"u"){const n=()=>{};return[n,n]}let a,o;const t=window,s=typeof t.requestIdleCallback=="function",u=t.requestAnimationFrame,i=t.cancelAnimationFrame,c=s?t.requestIdleCallback:u,f=s?t.cancelIdleCallback:i,l=()=>{f(a),i(o)};return[(n,r)=>{l(),a=c(s?()=>{l(),o=u(n)}:n,typeof r=="object"?r:{timeout:2233})},l]},S=a=>{const{options:o,events:t,defer:s}=a||{},[u,i]=e.useMemo(O,[]),c=e.useRef(null),f=e.useRef(s),l=e.useRef(o),n=e.useRef(t);return e.useEffect(()=>{f.current=s},[s]),e.useEffect(()=>{const{current:r}=c;l.current=o,p.OverlayScrollbars.valid(r)&&r.options(o||{},!0)},[o]),e.useEffect(()=>{const{current:r}=c;n.current=t,p.OverlayScrollbars.valid(r)&&r.on(t||{},!0)},[t]),e.useEffect(()=>()=>{var r;i(),(r=c.current)==null||r.destroy()},[]),e.useMemo(()=>[r=>{const b=c.current;if(p.OverlayScrollbars.valid(b))return;const d=l.current,m=n.current,v=f.current,y=()=>c.current=p.OverlayScrollbars(r,d||{},m||{});v?u(y,v):y()},()=>c.current],[])},E=(a,o)=>{const{element:t="div",options:s,events:u,defer:i,children:c,...f}=a,l=t,n=e.useRef(null),r=e.useRef(null),[b,d]=S({options:s,events:u,defer:i});return e.useEffect(()=>{const{current:m}=n,{current:v}=r;if(!m)return;const y=m;return b(t==="body"?{target:y,cancel:{body:null}}:{target:y,elements:{viewport:v,content:v}}),()=>{var R;return(R=d())==null?void 0:R.destroy()}},[b,d,t]),e.useImperativeHandle(o,()=>({osInstance:d,getElement:()=>n.current}),[d]),e.createElement(l,{"data-overlayscrollbars-initialize":"",ref:n,...f},t==="body"?c:e.createElement("div",{"data-overlayscrollbars-contents":"",ref:r},c))},I=e.forwardRef(E);exports.OverlayScrollbarsComponent=I;exports.useOverlayScrollbars=S;
|
|
2
2
|
//# sourceMappingURL=overlayscrollbars-react.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlayscrollbars-react.cjs.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ElementRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: OverlayScrollbarsComponentBaseProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div'\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":"wIA6BMA,EAAc,IAAa,CAE3B,GAAA,OAAO,OAAW,IAAa,CAGjC,MAAMC,EAAO,IAAM,CAAA,EACZ,MAAA,CAACA,EAAMA,CAAI,CACpB,CAGI,IAAAC,EACAC,EACJ,MAAMC,EAAM,OACNC,EAAgB,OAAOD,EAAI,qBAAwB,WACnDE,EAAMF,EAAI,sBACVG,EAAMH,EAAI,qBACVI,EAAQH,EAAgBD,EAAI,oBAAsBE,EAClDG,EAAQJ,EAAgBD,EAAI,mBAAqBG,EACjDG,EAAQ,IAAM,CAClBD,EAAMP,CAAM,EACZK,EAAIJ,CAAK,CAAA,EAGJ,MAAA,CACL,CAACQ,EAAUC,IAAY,CACfF,IACGR,EAAAM,EACPH,EACI,IAAM,CACEK,IAENP,EAAQG,EAAIK,CAAQ,CAAA,EAEtBA,EACJ,OAAOC,GAAY,SAAWA,EAAU,CAAE,QAAS,IAAK,CAAA,CAE5D,EACAF,CAAA,CAEJ,EASaG,EACXC,GACuE,CACvE,KAAM,CAAE,QAAAF,EAAS,OAAAG,EAAQ,MAAAC,CAAM,EAAIF,GAAU,CAAA,EACvC,CAACG,EAAcC,CAAW,EAAIC,EAAAA,QAAenB,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EAAarB,SAAsB,IAAI,EACvCsB,EAActB,SAAuB,IAAI,EACzC,CAACuB,EAAYC,CAAU,EAAIhC,EAAqB,CAAE,QAAAD,EAAS,OAAAG,EAAQ,MAAAC,CAAA,CAAO,EAEhFS,OAAAA,EAAAA,UAAU,IAAM,CACR,KAAA,CAAE,QAASqB,CAAQ,EAAAJ,EACnB,CAAE,QAASK,CAAgB,EAAAJ,EACjC,OAAIG,GAAOC,GACEH,EAAA,CACT,OAAQE,EACR,SAAU,CACR,SAAUC,EACV,QAASA,CACX,CAAA,CACD,EAEI,IAAM,OAAA,OAAAnB,EAAAiB,MAAA,YAAAjB,EAAc,UAAQ,EAClC,CAACgB,EAAYN,CAAO,CAAC,EAExBU,EAAA,oBACEX,EACA,KACS,CACL,WAAAQ,EACA,WAAY,IAAMH,EAAW,OAAA,GAGjC,CAAC,CAAA,EAKAO,EAAA,cAAAR,EAAA,CAAI,oCAAkC,GAAG,IAAKC,EAAa,GAAGF,CAC7D,EAAAS,EAAA,cAAC,OAAI,kCAAgC,GAAG,IAAKN,GAC1CJ,CACH,CACF,CAEJ,EAEMW,EAAyCC,aAAWhB,CAA0B"}
|
|
1
|
+
{"version":3,"file":"overlayscrollbars-react.cjs.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\ntype Defer = [\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void,\r\n];\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currOptions = optionsRef.current;\r\n const currEvents = eventsRef.current;\r\n const currDefer = deferRef.current;\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions || {}, currEvents || {}));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// keep React in the scope to not break users which aren't using react-jsx runtime (react pre v17)\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars, PartialOptions, EventListeners } from 'overlayscrollbars';\r\n\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ComponentRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ComponentRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: T extends ElementType ? OverlayScrollbarsComponentBaseProps<T> : never,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ComponentRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: contentsElm } = childrenRef;\r\n\r\n /* c8 ignore start */\r\n if (!elm) {\r\n return;\r\n }\r\n /* c8 ignore end */\r\n\r\n const target = elm as unknown as HTMLElement;\r\n\r\n initialize(\r\n element === 'body'\r\n ? {\r\n target,\r\n cancel: {\r\n body: null,\r\n },\r\n }\r\n : {\r\n target,\r\n elements: {\r\n viewport: contentsElm,\r\n content: contentsElm,\r\n },\r\n }\r\n );\r\n\r\n return () => osInstance()?.destroy();\r\n }, [initialize, osInstance, element]);\r\n\r\n useImperativeHandle(ref, () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n }, [osInstance]);\r\n\r\n return (\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n {element === 'body' ? (\r\n children\r\n ) : (\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n )}\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div',\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currOptions","currEvents","currDefer","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","contentsElm","useImperativeHandle","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":"wIA6BMA,EAAc,IAAa,CAE3B,GAAA,OAAO,OAAW,IAAa,CAGjC,MAAMC,EAAO,IAAM,CAAC,EACb,MAAA,CAACA,EAAMA,CAAI,CAAA,CAIhB,IAAAC,EACAC,EACJ,MAAMC,EAAM,OACNC,EAAgB,OAAOD,EAAI,qBAAwB,WACnDE,EAAMF,EAAI,sBACVG,EAAMH,EAAI,qBACVI,EAAQH,EAAgBD,EAAI,oBAAsBE,EAClDG,EAAQJ,EAAgBD,EAAI,mBAAqBG,EACjDG,EAAQ,IAAM,CAClBD,EAAMP,CAAM,EACZK,EAAIJ,CAAK,CACX,EAEO,MAAA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"file":"overlayscrollbars-react.cjs","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ElementRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: OverlayScrollbarsComponentBaseProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div'\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":"wIA6BMA,EAAc,IAAa,CAE3B,GAAA,OAAO,OAAW,IAAa,CAGjC,MAAMC,EA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kC,GAAG,IAAKC,EAAa,GAAGF,CAC7D,EAAAS,EAAA,cAAC,OAAI,kCAAgC,GAAG,IAAKN,GAC1CJ,CACH,CACF,CAEJ,EAEMW,EAAyCC,aAAWhB,CAA0B"}
|
|
1
|
+
{"version":3,"file":"overlayscrollbars-react.cjs","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\ntype Defer = [\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void,\r\n];\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currOptions = optionsRef.current;\r\n const currEvents = eventsRef.current;\r\n const currDefer = deferRef.current;\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions || {}, currEvents || {}));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// keep React in the scope to not break users which aren't using react-jsx runtime (react pre v17)\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars, PartialOptions, EventListeners } from 'overlayscrollbars';\r\n\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ComponentRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ComponentRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: T extends ElementType ? OverlayScrollbarsComponentBaseProps<T> : never,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ComponentRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: contentsElm } = childrenRef;\r\n\r\n /* c8 ignore start */\r\n if (!elm) {\r\n return;\r\n }\r\n /* c8 ignore end */\r\n\r\n const target = elm as unknown as HTMLElement;\r\n\r\n initialize(\r\n element === 'body'\r\n ? {\r\n target,\r\n cancel: {\r\n body: null,\r\n },\r\n }\r\n : {\r\n target,\r\n elements: {\r\n viewport: contentsElm,\r\n content: contentsElm,\r\n },\r\n }\r\n );\r\n\r\n return () => osInstance()?.destroy();\r\n }, [initialize, osInstance, element]);\r\n\r\n useImperativeHandle(ref, () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n }, [osInstance]);\r\n\r\n return (\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n {element === 'body' ? (\r\n children\r\n ) : (\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n )}\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div',\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currOptions","currEvents","currDefer","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","contentsElm","useImperativeHandle","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":"wIA6BMA,EAAc,IAAa,CAE3B,GAAA,OAAO,OAAW,IAAa,CAGjC,MAAMC,EAAO,IAAM,CAAC,EACb,MAAA,CAACA,EAAMA,CAAI,CAAA,CAIhB,IAAAC,EACAC,EACJ,MAAMC,EAAM,OACNC,EAAgB,OAAOD,EAAI,qBAAwB,WACnDE,EAAMF,EAAI,sBACVG,EAAMH,EAAI,qBACVI,EAAQH,EAAgBD,EAAI,oBAAsBE,EAClDG,EAAQJ,EAAgBD,EAAI,mBAAqBG,EACjDG,EAAQ,IAAM,CAClBD,EAAMP,CAAM,EACZK,EAAIJ,CAAK,CACX,EAEO,MAAA,CACL,CAACQ,EAAUC,IAAY,CACfF,EAAA,EACGR,EAAAM,EACPH,EACI,IAAM,CACEK,EAAA,EAENP,EAAQG,EAAIK,CAAQ,CAAA,EAEtBA,EACJ,OAAOC,GAAY,SAAWA,EAAU,CAAE,QAAS,IAAK,CAC1D,CACF,EACAF,CACF,CACF,EASaG,EACXC,GACuE,CACvE,KAAM,CAAE,QAAAF,EAAS,OAAAG,EAAQ,MAAAC,CAAM,EAAIF,GAAU,CAAC,EACxC,CAACG,EAAcC,CAAW,EAAIC,EAAAA,QAAenB,EAAa,CAAA,CAAE,EAC5DoB,EAAcC,SAAiD,IAAI,EACnEC,EAAWD,SAAOL,CAAK,EACvBO,EAAaF,SAAOT,CAAO,EAC3BY,EAAYH,SAAON,CAAM,EAE/BU,OAAAA,EAAAA,UAAU,IAAM,CACdH,EAAS,QAAUN,CAAA,EAClB,CAACA,CAAK,CAAC,EAEVS,EAAAA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nB,CAAE,QAASK,CAAA,EAAgBJ,EAGjC,GAAI,CAACG,EACH,OAIF,MAAMjB,EAASiB,EAEf,OAAAF,EACEN,IAAY,OACR,CACE,OAAAT,EACA,OAAQ,CACN,KAAM,IAAA,CACR,EAEF,CACE,OAAAA,EACA,SAAU,CACR,SAAUkB,EACV,QAASA,CAAA,CACX,CAER,EAEO,IAAM,OAAA,OAAAnB,EAAAiB,EAAW,IAAX,YAAAjB,EAAc,UAC1B,EAAA,CAACgB,EAAYC,EAAYP,CAAO,CAAC,EAEpCU,EAAA,oBAAoBX,EAAK,KAChB,CACL,WAAAQ,EACA,WAAY,IAAMH,EAAW,OAC/B,GACC,CAACG,CAAU,CAAC,kBAGZJ,EAAI,CAAA,oCAAkC,GAAG,IAAKC,EAAa,GAAGF,CAC5D,EAAAF,IAAY,OACXC,kBAEC,MAAI,CAAA,kCAAgC,GAAG,IAAKI,GAC1CJ,CACH,CAEJ,CAEJ,EAEMU,EAAyCC,aAAWf,CAA0B"}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import w, { useMemo as C, useRef as f, useEffect as v, forwardRef as E, useImperativeHandle as O } from "react";
|
|
2
2
|
import { OverlayScrollbars as I } from "overlayscrollbars";
|
|
3
|
-
const
|
|
3
|
+
const S = () => {
|
|
4
4
|
if (typeof window > "u") {
|
|
5
5
|
const n = () => {
|
|
6
6
|
};
|
|
7
7
|
return [n, n];
|
|
8
8
|
}
|
|
9
|
-
let l,
|
|
10
|
-
const t = window,
|
|
11
|
-
u(l), i(
|
|
9
|
+
let l, o;
|
|
10
|
+
const t = window, c = typeof t.requestIdleCallback == "function", a = t.requestAnimationFrame, i = t.cancelAnimationFrame, r = c ? t.requestIdleCallback : a, u = c ? t.cancelIdleCallback : i, s = () => {
|
|
11
|
+
u(l), i(o);
|
|
12
12
|
};
|
|
13
13
|
return [
|
|
14
14
|
(n, e) => {
|
|
15
15
|
s(), l = r(
|
|
16
|
-
|
|
17
|
-
s(),
|
|
16
|
+
c ? () => {
|
|
17
|
+
s(), o = a(n);
|
|
18
18
|
} : n,
|
|
19
19
|
typeof e == "object" ? e : { timeout: 2233 }
|
|
20
20
|
);
|
|
21
21
|
},
|
|
22
22
|
s
|
|
23
23
|
];
|
|
24
|
-
},
|
|
25
|
-
const { options:
|
|
24
|
+
}, F = (l) => {
|
|
25
|
+
const { options: o, events: t, defer: c } = l || {}, [a, i] = C(S, []), r = f(null), u = f(c), s = f(o), n = f(t);
|
|
26
26
|
return v(() => {
|
|
27
|
-
u.current =
|
|
28
|
-
}, [o]), v(() => {
|
|
29
|
-
const { current: e } = r;
|
|
30
|
-
s.current = c, I.valid(e) && e.options(c || {}, !0);
|
|
27
|
+
u.current = c;
|
|
31
28
|
}, [c]), v(() => {
|
|
29
|
+
const { current: e } = r;
|
|
30
|
+
s.current = o, I.valid(e) && e.options(o || {}, !0);
|
|
31
|
+
}, [o]), v(() => {
|
|
32
32
|
const { current: e } = r;
|
|
33
33
|
n.current = t, I.valid(e) && e.on(t || {}, !0);
|
|
34
34
|
}, [t]), v(
|
|
@@ -37,45 +37,50 @@ const O = () => {
|
|
|
37
37
|
i(), (e = r.current) == null || e.destroy();
|
|
38
38
|
},
|
|
39
39
|
[]
|
|
40
|
-
),
|
|
40
|
+
), C(
|
|
41
41
|
() => [
|
|
42
42
|
(e) => {
|
|
43
43
|
const y = r.current;
|
|
44
44
|
if (I.valid(y))
|
|
45
45
|
return;
|
|
46
|
-
const d =
|
|
47
|
-
|
|
46
|
+
const d = s.current, b = n.current, m = u.current, p = () => r.current = I(e, d || {}, b || {});
|
|
47
|
+
m ? a(p, m) : p();
|
|
48
48
|
},
|
|
49
49
|
() => r.current
|
|
50
50
|
],
|
|
51
51
|
[]
|
|
52
52
|
);
|
|
53
|
-
},
|
|
54
|
-
const { element: t = "div", options:
|
|
53
|
+
}, q = (l, o) => {
|
|
54
|
+
const { element: t = "div", options: c, events: a, defer: i, children: r, ...u } = l, s = t, n = f(null), e = f(null), [y, d] = F({ options: c, events: a, defer: i });
|
|
55
55
|
return v(() => {
|
|
56
56
|
const { current: b } = n, { current: m } = e;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
if (!b)
|
|
58
|
+
return;
|
|
59
|
+
const p = b;
|
|
60
|
+
return y(
|
|
61
|
+
t === "body" ? {
|
|
62
|
+
target: p,
|
|
63
|
+
cancel: {
|
|
64
|
+
body: null
|
|
65
|
+
}
|
|
66
|
+
} : {
|
|
67
|
+
target: p,
|
|
68
|
+
elements: {
|
|
69
|
+
viewport: m,
|
|
70
|
+
content: m
|
|
71
|
+
}
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
return (
|
|
73
|
+
), () => {
|
|
74
|
+
var R;
|
|
75
|
+
return (R = d()) == null ? void 0 : R.destroy();
|
|
66
76
|
};
|
|
67
|
-
}, [y, t]),
|
|
68
|
-
|
|
69
|
-
() =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}),
|
|
73
|
-
[]
|
|
74
|
-
), // @ts-ignore
|
|
75
|
-
/* @__PURE__ */ R.createElement(s, { "data-overlayscrollbars-initialize": "", ref: n, ...u }, /* @__PURE__ */ R.createElement("div", { "data-overlayscrollbars-contents": "", ref: e }, r));
|
|
76
|
-
}, A = C(F);
|
|
77
|
+
}, [y, d, t]), O(o, () => ({
|
|
78
|
+
osInstance: d,
|
|
79
|
+
getElement: () => n.current
|
|
80
|
+
}), [d]), /* @__PURE__ */ w.createElement(s, { "data-overlayscrollbars-initialize": "", ref: n, ...u }, t === "body" ? r : /* @__PURE__ */ w.createElement("div", { "data-overlayscrollbars-contents": "", ref: e }, r));
|
|
81
|
+
}, g = E(q);
|
|
77
82
|
export {
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
g as OverlayScrollbarsComponent,
|
|
84
|
+
F as useOverlayScrollbars
|
|
80
85
|
};
|
|
81
86
|
//# sourceMappingURL=overlayscrollbars-react.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlayscrollbars-react.esm.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ElementRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: OverlayScrollbarsComponentBaseProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div'\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":";;AA6BA,MAAMA,IAAc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,MAAM;;AAAA,cAAAnB,IAAAiB,QAAA,gBAAAjB,EAAc;AAAA;AAAA,EAAQ,GAClC,CAACgB,GAAYN,CAAO,CAAC,GAExBU;AAAA,IACEX;AAAA,IACA,OACS;AAAA,MACL,YAAAQ;AAAA,MACA,YAAY,MAAMH,EAAW;AAAA,IAAA;AAAA,IAGjC,CAAC;AAAA,EAAA;AAAA,EAKA,gBAAAO,EAAA,cAAAR,GAAA,EAAI,qCAAkC,IAAG,KAAKC,GAAa,GAAGF,EAC7D,GAAA,gBAAAS,EAAA,cAAC,SAAI,mCAAgC,IAAG,KAAKN,KAC1CJ,CACH,CACF;AAEJ,GAEMW,IAAyCC,EAAWhB,CAA0B;"}
|
|
1
|
+
{"version":3,"file":"overlayscrollbars-react.esm.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\ntype Defer = [\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void,\r\n];\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currOptions = optionsRef.current;\r\n const currEvents = eventsRef.current;\r\n const currDefer = deferRef.current;\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions || {}, currEvents || {}));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// keep React in the scope to not break users which aren't using react-jsx runtime (react pre v17)\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars, PartialOptions, EventListeners } from 'overlayscrollbars';\r\n\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ComponentRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ComponentRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: T extends ElementType ? OverlayScrollbarsComponentBaseProps<T> : never,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ComponentRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: contentsElm } = childrenRef;\r\n\r\n /* c8 ignore start */\r\n if (!elm) {\r\n return;\r\n }\r\n /* c8 ignore end */\r\n\r\n const target = elm as unknown as HTMLElement;\r\n\r\n initialize(\r\n element === 'body'\r\n ? {\r\n target,\r\n cancel: {\r\n body: null,\r\n },\r\n }\r\n : {\r\n target,\r\n elements: {\r\n viewport: contentsElm,\r\n content: contentsElm,\r\n },\r\n }\r\n );\r\n\r\n return () => osInstance()?.destroy();\r\n }, [initialize, osInstance, element]);\r\n\r\n useImperativeHandle(ref, () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n }, [osInstance]);\r\n\r\n return (\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n {element === 'body' ? (\r\n children\r\n ) : (\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n )}\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div',\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currOptions","currEvents","currDefer","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","contentsElm","useImperativeHandle","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":";;AA6BA,MAAMA,IAAc,MAAa;AAE3B,MAAA,OAAO,SAAW,KAAa;AAGjC,UAAMC,IAAO,MAAM;AAAA,IAAC;AACb,WAAA,CAACA,GAAMA,CAAI;AAAA,EAAA;AAIhB,MAAAC,GACAC;AACJ,QAAMC,IAAM,QACNC,IAAgB,OAAOD,EAAI,uBAAwB,YACnDE,IAAMF,EAAI,uBACVG,IAAMH,EAAI,sBACVI,IAAQH,IAAgBD,EAAI,sBAAsBE,GAClDG,IAAQJ,IAAgBD,EAAI,qBAAqBG,GACjDG,IAAQ,MAAM;AAClB,IAAAD,EAAMP,CAAM,GACZK,EAAIJ,CAAK;AAAA,EACX;AAEO,SAAA;AAAA,IACL,CAACQ,GAAUC,MAAY;AACf,MAAAF,EAAA,GACGR,IAAAM;AAAA,QACPH,IACI,MAAM;AACE,UAAAK,EAAA,GAENP,IAAQG,EAAIK,CAAQ;AAAA,QAAA,IAEtBA;AAAA,QACJ,OAAOC,KAAY,WAAWA,IAAU,EAAE,SAAS,KAAK;AAAA,MAC1D;AAAA,IACF;AAAA,IACAF;AAAA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ffect as v, forwardRef as E, useImperativeHandle as O } from "react";
|
|
2
2
|
import { OverlayScrollbars as I } from "overlayscrollbars";
|
|
3
|
-
const
|
|
3
|
+
const S = () => {
|
|
4
4
|
if (typeof window > "u") {
|
|
5
5
|
const n = () => {
|
|
6
6
|
};
|
|
7
7
|
return [n, n];
|
|
8
8
|
}
|
|
9
|
-
let l,
|
|
10
|
-
const t = window,
|
|
11
|
-
u(l), i(
|
|
9
|
+
let l, o;
|
|
10
|
+
const t = window, c = typeof t.requestIdleCallback == "function", a = t.requestAnimationFrame, i = t.cancelAnimationFrame, r = c ? t.requestIdleCallback : a, u = c ? t.cancelIdleCallback : i, s = () => {
|
|
11
|
+
u(l), i(o);
|
|
12
12
|
};
|
|
13
13
|
return [
|
|
14
14
|
(n, e) => {
|
|
15
15
|
s(), l = r(
|
|
16
|
-
|
|
17
|
-
s(),
|
|
16
|
+
c ? () => {
|
|
17
|
+
s(), o = a(n);
|
|
18
18
|
} : n,
|
|
19
19
|
typeof e == "object" ? e : { timeout: 2233 }
|
|
20
20
|
);
|
|
21
21
|
},
|
|
22
22
|
s
|
|
23
23
|
];
|
|
24
|
-
},
|
|
25
|
-
const { options:
|
|
24
|
+
}, F = (l) => {
|
|
25
|
+
const { options: o, events: t, defer: c } = l || {}, [a, i] = C(S, []), r = f(null), u = f(c), s = f(o), n = f(t);
|
|
26
26
|
return v(() => {
|
|
27
|
-
u.current =
|
|
28
|
-
}, [o]), v(() => {
|
|
29
|
-
const { current: e } = r;
|
|
30
|
-
s.current = c, I.valid(e) && e.options(c || {}, !0);
|
|
27
|
+
u.current = c;
|
|
31
28
|
}, [c]), v(() => {
|
|
29
|
+
const { current: e } = r;
|
|
30
|
+
s.current = o, I.valid(e) && e.options(o || {}, !0);
|
|
31
|
+
}, [o]), v(() => {
|
|
32
32
|
const { current: e } = r;
|
|
33
33
|
n.current = t, I.valid(e) && e.on(t || {}, !0);
|
|
34
34
|
}, [t]), v(
|
|
@@ -37,45 +37,50 @@ const O = () => {
|
|
|
37
37
|
i(), (e = r.current) == null || e.destroy();
|
|
38
38
|
},
|
|
39
39
|
[]
|
|
40
|
-
),
|
|
40
|
+
), C(
|
|
41
41
|
() => [
|
|
42
42
|
(e) => {
|
|
43
43
|
const y = r.current;
|
|
44
44
|
if (I.valid(y))
|
|
45
45
|
return;
|
|
46
|
-
const d =
|
|
47
|
-
|
|
46
|
+
const d = s.current, b = n.current, m = u.current, p = () => r.current = I(e, d || {}, b || {});
|
|
47
|
+
m ? a(p, m) : p();
|
|
48
48
|
},
|
|
49
49
|
() => r.current
|
|
50
50
|
],
|
|
51
51
|
[]
|
|
52
52
|
);
|
|
53
|
-
},
|
|
54
|
-
const { element: t = "div", options:
|
|
53
|
+
}, q = (l, o) => {
|
|
54
|
+
const { element: t = "div", options: c, events: a, defer: i, children: r, ...u } = l, s = t, n = f(null), e = f(null), [y, d] = F({ options: c, events: a, defer: i });
|
|
55
55
|
return v(() => {
|
|
56
56
|
const { current: b } = n, { current: m } = e;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
if (!b)
|
|
58
|
+
return;
|
|
59
|
+
const p = b;
|
|
60
|
+
return y(
|
|
61
|
+
t === "body" ? {
|
|
62
|
+
target: p,
|
|
63
|
+
cancel: {
|
|
64
|
+
body: null
|
|
65
|
+
}
|
|
66
|
+
} : {
|
|
67
|
+
target: p,
|
|
68
|
+
elements: {
|
|
69
|
+
viewport: m,
|
|
70
|
+
content: m
|
|
71
|
+
}
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
return (
|
|
73
|
+
), () => {
|
|
74
|
+
var R;
|
|
75
|
+
return (R = d()) == null ? void 0 : R.destroy();
|
|
66
76
|
};
|
|
67
|
-
}, [y, t]),
|
|
68
|
-
|
|
69
|
-
() =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}),
|
|
73
|
-
[]
|
|
74
|
-
), // @ts-ignore
|
|
75
|
-
/* @__PURE__ */ R.createElement(s, { "data-overlayscrollbars-initialize": "", ref: n, ...u }, /* @__PURE__ */ R.createElement("div", { "data-overlayscrollbars-contents": "", ref: e }, r));
|
|
76
|
-
}, A = C(F);
|
|
77
|
+
}, [y, d, t]), O(o, () => ({
|
|
78
|
+
osInstance: d,
|
|
79
|
+
getElement: () => n.current
|
|
80
|
+
}), [d]), /* @__PURE__ */ w.createElement(s, { "data-overlayscrollbars-initialize": "", ref: n, ...u }, t === "body" ? r : /* @__PURE__ */ w.createElement("div", { "data-overlayscrollbars-contents": "", ref: e }, r));
|
|
81
|
+
}, g = E(q);
|
|
77
82
|
export {
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
g as OverlayScrollbarsComponent,
|
|
84
|
+
F as useOverlayScrollbars
|
|
80
85
|
};
|
|
81
86
|
//# sourceMappingURL=overlayscrollbars-react.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlayscrollbars-react.mjs","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ElementRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: OverlayScrollbarsComponentBaseProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div'\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":";;AA6BA,MAAMA,IAAc,MAAa;AAE3B,MAAA,OAAO,SAAW,KAAa;AAGjC,UAAMC,IAAO,MAAM;AAAA,IAAA;AACZ,WAAA,CAACA,GAAMA,CAAI;AAAA,EACpB;AAGI,MAAAC,GACAC;AACJ,QAAMC,IAAM,QACNC,IAAgB,OAAOD,EAAI,uBAAwB,YACnDE,IAAMF,EAAI,uBACVG,IAAMH,EAAI,sBACVI,IAAQH,IAAgBD,EAAI,sBAAsBE,GAClDG,IAAQJ,IAAgBD,EAAI,qBAAqBG,GACjDG,IAAQ,MAAM;AAClB,IAAAD,EAAMP,CAAM,GACZK,EAAIJ,CAAK;AAAA,EAAA;AAGJ,SAAA;AAAA,IACL,CAACQ,GAAUC,MAAY;AACf,MAAAF,KACGR,IAAAM;AAAA,QACPH,IACI,MAAM;AACE,UAAAK,KAENP,IAAQG,EAAIK,CAAQ;AAAA,QAAA,IAEtBA;AAAA,QACJ,OAAOC,KAAY,WAAWA,IAAU,EAAE,SAAS,KAAK;AAAA,MAAA;AAAA,IAE5D;AAAA,IACAF;AAAA,EAAA;AAEJ,GASaG,IAAuB,CAClCC,MACuE;AACvE,QAAM,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B,CACjCC,GACAC,MACwB;AAClB,QAAA,EAAE,SAAAC,IAAU,OAAO,SAAA1B,GAAS,QAAAG,GAAQ,OAAAC,GAAO,UAAAuB,GAAU,GAAGC,EAAU,IAAAJ,GAClEK,IAAMH,GACNI,IAAarB,EAAsB,IAAI,GACvCsB,IAActB,EAAuB,IAAI,GACzC,CAACuB,GAAYC,CAAU,IAAIhC,EAAqB,EAAE,SAAAD,GAAS,QAAAG,GAAQ,OAAAC,EAAA,CAAO;AAEhF,SAAAS,EAAU,MAAM;AACR,UAAA,EAAE,SAASqB,EAAQ,IAAAJ,GACnB,EAAE,SAASK,EAAgB,IAAAJ;AACjC,WAAIG,KAAOC,KACEH,EAAA;AAAA,MACT,QAAQE;AAAA,MACR,UAAU;AAAA,QACR,UAAUC;AAAA,QACV,SAASA;AAAA,MACX;AAAA,IAAA,CACD,GAEI,MAAM;;AAAA,cAAAnB,IAAAiB,QAAA,gBAAAjB,EAAc;AAAA;AAAA,EAAQ,GAClC,CAACgB,GAAYN,CAAO,CAAC,GAExBU;AAAA,IACEX;AAAA,IACA,OACS;AAAA,MACL,YAAAQ;AAAA,MACA,YAAY,MAAMH,EAAW;AAAA,IAAA;AAAA,IAGjC,CAAC;AAAA,EAAA;AAAA,EAKA,gBAAAO,EAAA,cAAAR,GAAA,EAAI,qCAAkC,IAAG,KAAKC,GAAa,GAAGF,EAC7D,GAAA,gBAAAS,EAAA,cAAC,SAAI,mCAAgC,IAAG,KAAKN,KAC1CJ,CACH,CACF;AAEJ,GAEMW,IAAyCC,EAAWhB,CAA0B;"}
|
|
1
|
+
{"version":3,"file":"overlayscrollbars-react.mjs","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\ntype Defer = [\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void,\r\n];\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currOptions = optionsRef.current;\r\n const currEvents = eventsRef.current;\r\n const currDefer = deferRef.current;\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions || {}, currEvents || {}));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// keep React in the scope to not break users which aren't using react-jsx runtime (react pre v17)\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars, PartialOptions, EventListeners } from 'overlayscrollbars';\r\n\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ComponentRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ComponentRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: T extends ElementType ? OverlayScrollbarsComponentBaseProps<T> : never,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ComponentRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: contentsElm } = childrenRef;\r\n\r\n /* c8 ignore start */\r\n if (!elm) {\r\n return;\r\n }\r\n /* c8 ignore end */\r\n\r\n const target = elm as unknown as HTMLElement;\r\n\r\n initialize(\r\n element === 'body'\r\n ? {\r\n target,\r\n cancel: {\r\n body: null,\r\n },\r\n }\r\n : {\r\n target,\r\n elements: {\r\n viewport: contentsElm,\r\n content: contentsElm,\r\n },\r\n }\r\n );\r\n\r\n return () => osInstance()?.destroy();\r\n }, [initialize, osInstance, element]);\r\n\r\n useImperativeHandle(ref, () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n }, [osInstance]);\r\n\r\n return (\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n {element === 'body' ? (\r\n children\r\n ) : (\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n )}\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div',\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currOptions","currEvents","currDefer","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","contentsElm","useImperativeHandle","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":";;AA6BA,MAAMA,IAAc,MAAa;AAE3B,MAAA,OAAO,SAAW,KAAa;AAGjC,UAAMC,IAAO,MAAM;AAAA,IAAC;AACb,WAAA,CAACA,GAAMA,CAAI;AAAA,EAAA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;AAAA,QAAA;AAAA,MACX;AAAA,IAER,GAEO,MAAM;;AAAA,cAAAnB,IAAAiB,EAAW,MAAX,gBAAAjB,EAAc;AAAA;AAAA,EAC1B,GAAA,CAACgB,GAAYC,GAAYP,CAAO,CAAC,GAEpCU,EAAoBX,GAAK,OAChB;AAAA,IACL,YAAAQ;AAAA,IACA,YAAY,MAAMH,EAAW;AAAA,EAC/B,IACC,CAACG,CAAU,CAAC,mCAGZJ,GAAI,EAAA,qCAAkC,IAAG,KAAKC,GAAa,GAAGF,EAC5D,GAAAF,MAAY,SACXC,oCAEC,OAAI,EAAA,mCAAgC,IAAG,KAAKI,KAC1CJ,CACH,CAEJ;AAEJ,GAEMU,IAAyCC,EAAWf,CAA0B;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(s,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("overlayscrollbars")):typeof define=="function"&&define.amd?define(["exports","react","overlayscrollbars"],e):(s=typeof globalThis<"u"?globalThis:s||self,e(s.OverlayScrollbarsReact={},s.React,s.OverlayScrollbarsGlobal))})(this,function(s,e,p){"use strict";const I=()=>{if(typeof window>"u"){const t=()=>{};return[t,t]}let i,c;const r=window,l=typeof r.requestIdleCallback=="function",f=r.requestAnimationFrame,a=r.cancelAnimationFrame,o=l?r.requestIdleCallback:f,d=l?r.cancelIdleCallback:a,u=()=>{d(i),a(c)};return[(t,n)=>{u(),i=o(l?()=>{u(),c=f(t)}:t,typeof n=="object"?n:{timeout:2233})},u]},O=i=>{const{options:c,events:r,defer:l}=i||{},[f,a]=e.useMemo(I,[]),o=e.useRef(null),d=e.useRef(l),u=e.useRef(c),t=e.useRef(r);return e.useEffect(()=>{d.current=l},[l]),e.useEffect(()=>{const{current:n}=o;u.current=c,p.OverlayScrollbars.valid(n)&&n.options(c||{},!0)},[c]),e.useEffect(()=>{const{current:n}=o;t.current=r,p.OverlayScrollbars.valid(n)&&n.on(r||{},!0)},[r]),e.useEffect(()=>()=>{var n;a(),(n=o.current)==null||n.destroy()},[]),e.useMemo(()=>[n=>{const b=o.current;if(p.OverlayScrollbars.valid(b))return;const v=u.current,S=t.current,y=d.current,m=()=>o.current=p.OverlayScrollbars(n,v||{},S||{});y?f(m,y):m()},()=>o.current],[])},w=(i,c)=>{const{element:r="div",options:l,events:f,defer:a,children:o,...d}=i,u=r,t=e.useRef(null),n=e.useRef(null),[b,v]=O({options:l,events:f,defer:a});return e.useEffect(()=>{const{current:S}=t,{current:y}=n;if(!S)return;const m=S;return b(r==="body"?{target:m,cancel:{body:null}}:{target:m,elements:{viewport:y,content:y}}),()=>{var E;return(E=v())==null?void 0:E.destroy()}},[b,v,r]),e.useImperativeHandle(c,()=>({osInstance:v,getElement:()=>t.current}),[v]),e.createElement(u,{"data-overlayscrollbars-initialize":"",ref:t,...d},r==="body"?o:e.createElement("div",{"data-overlayscrollbars-contents":"",ref:n},o))},h=e.forwardRef(w);s.OverlayScrollbarsComponent=h,s.useOverlayScrollbars=O,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
+
//# sourceMappingURL=overlayscrollbars-react.umd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlayscrollbars-react.umd.cjs","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\ntype Defer = [\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void,\r\n];\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currOptions = optionsRef.current;\r\n const currEvents = eventsRef.current;\r\n const currDefer = deferRef.current;\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions || {}, currEvents || {}));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// keep React in the scope to not break users which aren't using react-jsx runtime (react pre v17)\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars, PartialOptions, EventListeners } from 'overlayscrollbars';\r\n\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ComponentRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ComponentRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: T extends ElementType ? OverlayScrollbarsComponentBaseProps<T> : never,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ComponentRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: contentsElm } = childrenRef;\r\n\r\n /* c8 ignore start */\r\n if (!elm) {\r\n return;\r\n }\r\n /* c8 ignore end */\r\n\r\n const target = elm as unknown as HTMLElement;\r\n\r\n initialize(\r\n element === 'body'\r\n ? {\r\n target,\r\n cancel: {\r\n body: null,\r\n },\r\n }\r\n : {\r\n target,\r\n elements: {\r\n viewport: contentsElm,\r\n content: contentsElm,\r\n },\r\n }\r\n );\r\n\r\n return () => osInstance()?.destroy();\r\n }, [initialize, osInstance, element]);\r\n\r\n useImperativeHandle(ref, () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n }, [osInstance]);\r\n\r\n return (\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n {element === 'body' ? (\r\n children\r\n ) : (\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n )}\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div',\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currOptions","currEvents","currDefer","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","contentsElm","useImperativeHandle","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":"8VA6BA,MAAMA,EAAc,IAAa,CAE3B,GAAA,OAAO,OAAW,IAAa,CAGjC,MAAMC,EAAO,IAAM,CAAC,EACb,MAAA,CAACA,EAAMA,CAAI,CAAA,CAIhB,IAAAC,EACAC,EACJ,MAAMC,EAAM,OACNC,EAAgB,OAAOD,EAAI,qBAAwB,WACnDE,EAAMF,EAAI,sBACVG,EAAMH,EAAI,qBACVI,EAAQH,EAAgBD,EAAI,oBAAsBE,EAClDG,EAAQJ,EAAgBD,EAAI,mBAAqBG,EACjDG,EAAQ,IAAM,CAClBD,EAAMP,CAAM,EACZK,EAAIJ,CAAK,CAC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 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import type { PartialOptions, EventListeners } from 'overlayscrollbars';
|
|
4
|
-
import type { ComponentPropsWithoutRef, ElementRef, ElementType, ForwardedRef, ReactElement } from 'react';
|
|
1
|
+
import type { OverlayScrollbars, PartialOptions, EventListeners } from 'overlayscrollbars';
|
|
2
|
+
import type { ComponentPropsWithoutRef, ComponentRef, ElementType, ForwardedRef, ReactElement } from 'react';
|
|
5
3
|
type OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> = ComponentPropsWithoutRef<T> & {
|
|
6
4
|
/** Tag of the root element. */
|
|
7
5
|
element?: T;
|
|
@@ -19,8 +17,8 @@ export interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {
|
|
|
19
17
|
/** Returns the OverlayScrollbars instance or null if not initialized. */
|
|
20
18
|
osInstance(): OverlayScrollbars | null;
|
|
21
19
|
/** Returns the root element. */
|
|
22
|
-
getElement():
|
|
20
|
+
getElement(): ComponentRef<T> | null;
|
|
23
21
|
}
|
|
24
|
-
declare const OverlayScrollbarsComponent: <T extends
|
|
25
|
-
declare const OverlayScrollbarsComponentForwardedRef: <T extends
|
|
22
|
+
declare const OverlayScrollbarsComponent: <T extends ElementType = "div">(props: T extends ElementType ? OverlayScrollbarsComponentBaseProps<T> : never, ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>) => ReactElement | null;
|
|
23
|
+
declare const OverlayScrollbarsComponentForwardedRef: <T extends ElementType = "div">(props: OverlayScrollbarsComponentProps<T>) => ReturnType<typeof OverlayScrollbarsComponent>;
|
|
26
24
|
export { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
(function(s,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("overlayscrollbars")):typeof define=="function"&&define.amd?define(["exports","react","overlayscrollbars"],e):(s=typeof globalThis<"u"?globalThis:s||self,e(s.OverlayScrollbarsReact={},s.React,s.OverlayScrollbarsGlobal))})(this,function(s,e,y){"use strict";const E=()=>{if(typeof window>"u"){const t=()=>{};return[t,t]}let i,c;const n=window,l=typeof n.requestIdleCallback=="function",f=n.requestAnimationFrame,a=n.cancelAnimationFrame,o=l?n.requestIdleCallback:f,d=l?n.cancelIdleCallback:a,u=()=>{d(i),a(c)};return[(t,r)=>{u(),i=o(l?()=>{u(),c=f(t)}:t,typeof r=="object"?r:{timeout:2233})},u]},O=i=>{const{options:c,events:n,defer:l}=i||{},[f,a]=e.useMemo(E,[]),o=e.useRef(null),d=e.useRef(l),u=e.useRef(c),t=e.useRef(n);return e.useEffect(()=>{d.current=l},[l]),e.useEffect(()=>{const{current:r}=o;u.current=c,y.OverlayScrollbars.valid(r)&&r.options(c||{},!0)},[c]),e.useEffect(()=>{const{current:r}=o;t.current=n,y.OverlayScrollbars.valid(r)&&r.on(n||{},!0)},[n]),e.useEffect(()=>()=>{var r;a(),(r=o.current)==null||r.destroy()},[]),e.useMemo(()=>[r=>{const b=o.current;if(y.OverlayScrollbars.valid(b))return;const v=d.current,S=u.current||{},m=t.current||{},p=()=>o.current=y.OverlayScrollbars(r,S,m);v?f(p,v):p()},()=>o.current],[])},I=(i,c)=>{const{element:n="div",options:l,events:f,defer:a,children:o,...d}=i,u=n,t=e.useRef(null),r=e.useRef(null),[b,v]=O({options:l,events:f,defer:a});return e.useEffect(()=>{const{current:S}=t,{current:m}=r;return S&&m&&b({target:S,elements:{viewport:m,content:m}}),()=>{var p;return(p=v())==null?void 0:p.destroy()}},[b,n]),e.useImperativeHandle(c,()=>({osInstance:v,getElement:()=>t.current}),[]),e.createElement(u,{"data-overlayscrollbars-initialize":"",ref:t,...d},e.createElement("div",{"data-overlayscrollbars-contents":"",ref:r},o))},w=e.forwardRef(I);s.OverlayScrollbarsComponent=w,s.useOverlayScrollbars=O,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
-
//# sourceMappingURL=overlayscrollbars-react.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"overlayscrollbars-react.umd.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nimport React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type {\r\n ComponentPropsWithoutRef,\r\n ElementRef,\r\n ElementType,\r\n ForwardedRef,\r\n ReactElement,\r\n} from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\ntype OverlayScrollbarsComponentBaseProps<T extends ElementType = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends ElementType = 'div'> =\r\n OverlayScrollbarsComponentBaseProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends ElementType = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends ElementType = 'div'>(\r\n props: OverlayScrollbarsComponentBaseProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n): ReactElement | null => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div data-overlayscrollbars-contents=\"\" ref={childrenRef}>\r\n {children}\r\n </div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends ElementType = 'div'\r\n>(\r\n props: OverlayScrollbarsComponentProps<T>\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":"8VA6BA,MAAMA,EAAc,IAAa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