@mui/x-internals 7.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3987 -0
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/modern/useResizeObserver/index.js +1 -0
- package/modern/useResizeObserver/useResizeObserver.js +36 -0
- package/node/useResizeObserver/index.js +12 -0
- package/node/useResizeObserver/useResizeObserver.js +44 -0
- package/package.json +44 -0
- package/useResizeObserver/index.d.ts +1 -0
- package/useResizeObserver/index.js +1 -0
- package/useResizeObserver/package.json +6 -0
- package/useResizeObserver/useResizeObserver.d.ts +2 -0
- package/useResizeObserver/useResizeObserver.js +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Material-UI SAS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResizeObserver } from './useResizeObserver';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
3
|
+
const isDevEnvironment = process.env.NODE_ENV === 'development';
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
export function useResizeObserver(ref, fn, enabled) {
|
|
6
|
+
const fnRef = React.useRef(null);
|
|
7
|
+
fnRef.current = fn;
|
|
8
|
+
useEnhancedEffect(() => {
|
|
9
|
+
if (enabled === false || typeof ResizeObserver === 'undefined') {
|
|
10
|
+
return noop;
|
|
11
|
+
}
|
|
12
|
+
let frameID = 0;
|
|
13
|
+
const target = ref.current;
|
|
14
|
+
const observer = new ResizeObserver(entries => {
|
|
15
|
+
// See https://github.com/mui/mui-x/issues/8733
|
|
16
|
+
// In dev, we avoid the React warning by moving the task to the next frame.
|
|
17
|
+
// In prod, we want the task to run in the same frame as to avoid tear.
|
|
18
|
+
if (isDevEnvironment) {
|
|
19
|
+
frameID = requestAnimationFrame(() => {
|
|
20
|
+
fnRef.current(entries);
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
fnRef.current(entries);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (target) {
|
|
27
|
+
observer.observe(target);
|
|
28
|
+
}
|
|
29
|
+
return () => {
|
|
30
|
+
if (frameID) {
|
|
31
|
+
cancelAnimationFrame(frameID);
|
|
32
|
+
}
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
};
|
|
35
|
+
}, [ref, enabled]);
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useResizeObserver", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useResizeObserver.useResizeObserver;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _useResizeObserver = require("./useResizeObserver");
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useResizeObserver = useResizeObserver;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _utils = require("@mui/utils");
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
const isDevEnvironment = process.env.NODE_ENV === 'development';
|
|
12
|
+
const noop = () => {};
|
|
13
|
+
function useResizeObserver(ref, fn, enabled) {
|
|
14
|
+
const fnRef = React.useRef(null);
|
|
15
|
+
fnRef.current = fn;
|
|
16
|
+
(0, _utils.unstable_useEnhancedEffect)(() => {
|
|
17
|
+
if (enabled === false || typeof ResizeObserver === 'undefined') {
|
|
18
|
+
return noop;
|
|
19
|
+
}
|
|
20
|
+
let frameID = 0;
|
|
21
|
+
const target = ref.current;
|
|
22
|
+
const observer = new ResizeObserver(entries => {
|
|
23
|
+
// See https://github.com/mui/mui-x/issues/8733
|
|
24
|
+
// In dev, we avoid the React warning by moving the task to the next frame.
|
|
25
|
+
// In prod, we want the task to run in the same frame as to avoid tear.
|
|
26
|
+
if (isDevEnvironment) {
|
|
27
|
+
frameID = requestAnimationFrame(() => {
|
|
28
|
+
fnRef.current(entries);
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
fnRef.current(entries);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (target) {
|
|
35
|
+
observer.observe(target);
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
if (frameID) {
|
|
39
|
+
cancelAnimationFrame(frameID);
|
|
40
|
+
}
|
|
41
|
+
observer.disconnect();
|
|
42
|
+
};
|
|
43
|
+
}, [ref, enabled]);
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mui/x-internals",
|
|
3
|
+
"version": "7.9.0",
|
|
4
|
+
"description": "Utility functions for the MUI X packages (internal use only).",
|
|
5
|
+
"author": "MUI Team",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/mui/mui-x/issues"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://mui.com/x/",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"funding": {
|
|
13
|
+
"type": "opencollective",
|
|
14
|
+
"url": "https://opencollective.com/mui-org"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"directory": "build"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"react",
|
|
22
|
+
"react-component",
|
|
23
|
+
"material-ui",
|
|
24
|
+
"mui",
|
|
25
|
+
"mui-x",
|
|
26
|
+
"utils"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/mui/mui-x.git",
|
|
31
|
+
"directory": "packages/x-internals"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@babel/runtime": "^7.24.7",
|
|
35
|
+
"@mui/utils": "^5.16.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^17.0.0 || ^18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=14.0.0"
|
|
42
|
+
},
|
|
43
|
+
"private": false
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResizeObserver } from './useResizeObserver';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResizeObserver } from './useResizeObserver';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
3
|
+
const isDevEnvironment = process.env.NODE_ENV === 'development';
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
export function useResizeObserver(ref, fn, enabled) {
|
|
6
|
+
const fnRef = React.useRef(null);
|
|
7
|
+
fnRef.current = fn;
|
|
8
|
+
useEnhancedEffect(() => {
|
|
9
|
+
if (enabled === false || typeof ResizeObserver === 'undefined') {
|
|
10
|
+
return noop;
|
|
11
|
+
}
|
|
12
|
+
let frameID = 0;
|
|
13
|
+
const target = ref.current;
|
|
14
|
+
const observer = new ResizeObserver(entries => {
|
|
15
|
+
// See https://github.com/mui/mui-x/issues/8733
|
|
16
|
+
// In dev, we avoid the React warning by moving the task to the next frame.
|
|
17
|
+
// In prod, we want the task to run in the same frame as to avoid tear.
|
|
18
|
+
if (isDevEnvironment) {
|
|
19
|
+
frameID = requestAnimationFrame(() => {
|
|
20
|
+
fnRef.current(entries);
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
fnRef.current(entries);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (target) {
|
|
27
|
+
observer.observe(target);
|
|
28
|
+
}
|
|
29
|
+
return () => {
|
|
30
|
+
if (frameID) {
|
|
31
|
+
cancelAnimationFrame(frameID);
|
|
32
|
+
}
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
};
|
|
35
|
+
}, [ref, enabled]);
|
|
36
|
+
}
|