From b7897eaf9263d774783a9e66d610d1d39e1fa7dc Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Mon, 1 Jul 2024 11:17:02 +0200 Subject: [PATCH] [core] Create a new package to share utils across X packages (#13528) --- .codesandbox/ci.json | 6 +- babel.config.js | 1 + docs/package.json | 2 +- docs/pages/_app.js | 1 + .../eslint-plugin-material-ui/package.json | 2 +- packages/x-charts-pro/package.json | 2 +- packages/x-data-grid-premium/package.json | 1 + .../x-data-grid-premium/tsconfig.build.json | 3 +- packages/x-data-grid-pro/package.json | 1 + .../src/components/GridDetailPanel.tsx | 2 +- packages/x-data-grid-pro/tsconfig.build.json | 3 +- packages/x-data-grid/package.json | 1 + .../virtualization/useGridVirtualScroller.tsx | 2 +- packages/x-data-grid/src/hooks/utils/index.ts | 1 - packages/x-data-grid/tsconfig.build.json | 1 + packages/x-internals/LICENSE | 21 +++++++ packages/x-internals/README.md | 4 ++ packages/x-internals/package.json | 57 +++++++++++++++++++ .../src/useResizeObserver/index.ts | 1 + .../useResizeObserver}/useResizeObserver.ts | 0 packages/x-internals/tsconfig.build.json | 16 ++++++ packages/x-internals/tsconfig.json | 7 +++ pnpm-lock.yaml | 29 ++++++++++ scripts/x-data-grid-premium.exports.json | 1 - scripts/x-data-grid-pro.exports.json | 1 - scripts/x-data-grid.exports.json | 1 - test/package.json | 2 +- tsconfig.json | 2 + webpackBaseConfig.js | 1 + 29 files changed, 158 insertions(+), 14 deletions(-) create mode 100644 packages/x-internals/LICENSE create mode 100644 packages/x-internals/README.md create mode 100644 packages/x-internals/package.json create mode 100644 packages/x-internals/src/useResizeObserver/index.ts rename packages/{x-data-grid/src/hooks/utils => x-internals/src/useResizeObserver}/useResizeObserver.ts (100%) create mode 100644 packages/x-internals/tsconfig.build.json create mode 100644 packages/x-internals/tsconfig.json diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json index 37d8d1c44544..2bcfb7926690 100644 --- a/.codesandbox/ci.json +++ b/.codesandbox/ci.json @@ -11,7 +11,8 @@ "packages/x-date-pickers", "packages/x-date-pickers-pro", "packages/x-charts", - "packages/x-tree-view" + "packages/x-tree-view", + "packages/x-internals" ], "publishDirectory": { "@mui/x-license": "packages/x-license/build", @@ -24,7 +25,8 @@ "@mui/x-charts": "packages/x-charts/build", "@mui/x-charts-pro": "packages/x-charts-pro/build", "@mui/x-tree-view": "packages/x-tree-view/build", - "@mui/x-tree-view-pro": "packages/x-tree-view-pro/build" + "@mui/x-tree-view-pro": "packages/x-tree-view-pro/build", + "@mui/x-internals": "packages/x-internals/build" }, "sandboxes": ["/bug-reproductions/x-data-grid"], "silent": true diff --git a/babel.config.js b/babel.config.js index e10b6c313097..9e2bc852d0ed 100644 --- a/babel.config.js +++ b/babel.config.js @@ -18,6 +18,7 @@ const defaultAlias = { '@mui/x-charts-pro': resolveAliasPath('./packages/x-charts-pro/src'), '@mui/x-tree-view': resolveAliasPath('./packages/x-tree-view/src'), '@mui/x-tree-view-pro': resolveAliasPath('./packages/x-tree-view-pro/src'), + '@mui/x-internals': resolveAliasPath('./packages/x-internals/src'), '@mui/material-nextjs': '@mui/monorepo/packages/mui-material-nextjs/src', '@mui-internal/api-docs-builder': resolveAliasPath( './node_modules/@mui/monorepo/packages/api-docs-builder', diff --git a/docs/package.json b/docs/package.json index 2a79a4926a03..81b54044ab3f 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "name": "docs", - "version": "6.7.0", + "version": "7.7.1", "private": true, "author": "MUI Team", "license": "MIT", diff --git a/docs/pages/_app.js b/docs/pages/_app.js index 0a2f998cd9b6..08a025daad50 100644 --- a/docs/pages/_app.js +++ b/docs/pages/_app.js @@ -65,6 +65,7 @@ ponyfillGlobal.muiDocConfig = { '@mui/x-charts-pro': getMuiPackageVersion('x-charts-pro', muiCommitRef), '@mui/x-tree-view': getMuiPackageVersion('x-tree-view', muiCommitRef), '@mui/x-tree-view-pro': getMuiPackageVersion('x-tree-view-pro', muiCommitRef), + '@mui/x-internals': getMuiPackageVersion('x-internals', muiCommitRef), exceljs: 'latest', }; return output; diff --git a/packages/eslint-plugin-material-ui/package.json b/packages/eslint-plugin-material-ui/package.json index 347ccb8ca25d..612a420f472e 100644 --- a/packages/eslint-plugin-material-ui/package.json +++ b/packages/eslint-plugin-material-ui/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-material-ui", - "version": "6.3.0", + "version": "7.7.1", "private": true, "description": "Custom eslint rules for MUI X.", "main": "src/index.js", diff --git a/packages/x-charts-pro/package.json b/packages/x-charts-pro/package.json index 945293d1ce0b..38076efb9dd4 100644 --- a/packages/x-charts-pro/package.json +++ b/packages/x-charts-pro/package.json @@ -2,7 +2,7 @@ "name": "@mui/x-charts-pro", "version": "7.7.0", "private": true, - "description": "The community edition of the Charts components (MUI X).", + "description": "The Pro plan edition of the Charts components (MUI X).", "author": "MUI Team", "main": "./src/index.ts", "license": "SEE LICENSE IN LICENSE", diff --git a/packages/x-data-grid-premium/package.json b/packages/x-data-grid-premium/package.json index 9ff5984bf643..508b7e6c43c8 100644 --- a/packages/x-data-grid-premium/package.json +++ b/packages/x-data-grid-premium/package.json @@ -48,6 +48,7 @@ "@mui/utils": "^5.15.20", "@mui/x-data-grid": "workspace:*", "@mui/x-data-grid-pro": "workspace:*", + "@mui/x-internals": "workspace:*", "@mui/x-license": "workspace:*", "@types/format-util": "^1.0.4", "clsx": "^2.1.1", diff --git a/packages/x-data-grid-premium/tsconfig.build.json b/packages/x-data-grid-premium/tsconfig.build.json index 3f1870534100..35dae5af1b78 100644 --- a/packages/x-data-grid-premium/tsconfig.build.json +++ b/packages/x-data-grid-premium/tsconfig.build.json @@ -14,7 +14,8 @@ "references": [ { "path": "../x-data-grid/tsconfig.build.json" }, { "path": "../x-data-grid-pro/tsconfig.build.json" }, - { "path": "../x-license/tsconfig.build.json" } + { "path": "../x-license/tsconfig.build.json" }, + { "path": "../x-internals/tsconfig.build.json" } ], "include": ["src/**/*.ts*"], "exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"] diff --git a/packages/x-data-grid-pro/package.json b/packages/x-data-grid-pro/package.json index c69cd8ae0ad4..b52644da14ec 100644 --- a/packages/x-data-grid-pro/package.json +++ b/packages/x-data-grid-pro/package.json @@ -48,6 +48,7 @@ "@mui/utils": "^5.15.20", "@mui/x-data-grid": "workspace:*", "@mui/x-license": "workspace:*", + "@mui/x-internals": "workspace:*", "@types/format-util": "^1.0.4", "clsx": "^2.1.1", "prop-types": "^15.8.1", diff --git a/packages/x-data-grid-pro/src/components/GridDetailPanel.tsx b/packages/x-data-grid-pro/src/components/GridDetailPanel.tsx index 82577308cb75..a37b3e4bc807 100644 --- a/packages/x-data-grid-pro/src/components/GridDetailPanel.tsx +++ b/packages/x-data-grid-pro/src/components/GridDetailPanel.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { styled } from '@mui/material/styles'; import { GridRowId } from '@mui/x-data-grid'; -import { useResizeObserver } from '@mui/x-data-grid/internals'; +import { useResizeObserver } from '@mui/x-internals/useResizeObserver'; import { useGridRootProps } from '../hooks/utils/useGridRootProps'; import { useGridPrivateApiContext } from '../hooks/utils/useGridPrivateApiContext'; import { DataGridProProcessedProps } from '../models/dataGridProProps'; diff --git a/packages/x-data-grid-pro/tsconfig.build.json b/packages/x-data-grid-pro/tsconfig.build.json index 3649d7b11677..c5eab772f678 100644 --- a/packages/x-data-grid-pro/tsconfig.build.json +++ b/packages/x-data-grid-pro/tsconfig.build.json @@ -13,7 +13,8 @@ }, "references": [ { "path": "../x-data-grid/tsconfig.build.json" }, - { "path": "../x-license/tsconfig.build.json" } + { "path": "../x-license/tsconfig.build.json" }, + { "path": "../x-internals/tsconfig.build.json" } ], "include": ["src/**/*.ts*"], "exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"] diff --git a/packages/x-data-grid/package.json b/packages/x-data-grid/package.json index dea5d0de8017..ee7c95fe792b 100644 --- a/packages/x-data-grid/package.json +++ b/packages/x-data-grid/package.json @@ -50,6 +50,7 @@ "@babel/runtime": "^7.24.7", "@mui/system": "^5.15.20", "@mui/utils": "^5.15.20", + "@mui/x-internals": "workspace:*", "clsx": "^2.1.1", "prop-types": "^15.8.1", "reselect": "^4.1.8" diff --git a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx index a68ba9bae8e1..0aaa03f8760c 100644 --- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx +++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx @@ -6,12 +6,12 @@ import { } from '@mui/utils'; import useLazyRef from '@mui/utils/useLazyRef'; import useTimeout from '@mui/utils/useTimeout'; +import { useResizeObserver } from '@mui/x-internals/useResizeObserver'; import { useTheme, Theme } from '@mui/material/styles'; import type { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity'; import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext'; import { useGridRootProps } from '../../utils/useGridRootProps'; import { useGridSelector } from '../../utils/useGridSelector'; -import { useResizeObserver } from '../../utils/useResizeObserver'; import { useRunOnce } from '../../utils/useRunOnce'; import { gridVisibleColumnDefinitionsSelector, diff --git a/packages/x-data-grid/src/hooks/utils/index.ts b/packages/x-data-grid/src/hooks/utils/index.ts index e609ea5fb0fd..642c9db07366 100644 --- a/packages/x-data-grid/src/hooks/utils/index.ts +++ b/packages/x-data-grid/src/hooks/utils/index.ts @@ -5,5 +5,4 @@ export { useGridSelector } from './useGridSelector'; export * from './useGridNativeEventListener'; export * from './useFirstRender'; export * from './useOnMount'; -export * from './useResizeObserver'; export * from './useRunOnce'; diff --git a/packages/x-data-grid/tsconfig.build.json b/packages/x-data-grid/tsconfig.build.json index a287257ec3c0..be862bc37b1b 100644 --- a/packages/x-data-grid/tsconfig.build.json +++ b/packages/x-data-grid/tsconfig.build.json @@ -11,6 +11,7 @@ "rootDir": "./src", "types": ["node", "@mui/material/themeCssVarsAugmentation", "@emotion/styled", "@mui/types"] }, + "references": [{ "path": "../x-internals/tsconfig.build.json" }], "include": ["src/**/*.ts*"], "exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"] } diff --git a/packages/x-internals/LICENSE b/packages/x-internals/LICENSE new file mode 100644 index 000000000000..126bc57eaa23 --- /dev/null +++ b/packages/x-internals/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Material-UI SAS + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/x-internals/README.md b/packages/x-internals/README.md new file mode 100644 index 000000000000..e4389f60af4d --- /dev/null +++ b/packages/x-internals/README.md @@ -0,0 +1,4 @@ +# @mui/x-internals + +Shared utilities used by MUI X packages. +This package should never be installed or used directly. diff --git a/packages/x-internals/package.json b/packages/x-internals/package.json new file mode 100644 index 000000000000..466d728c0111 --- /dev/null +++ b/packages/x-internals/package.json @@ -0,0 +1,57 @@ +{ + "name": "@mui/x-internals", + "version": "7.7.1", + "description": "Utility functions for the MUI X packages (internal use only).", + "author": "MUI Team", + "license": "MIT", + "bugs": { + "url": "https://github.com/mui/mui-x/issues" + }, + "homepage": "https://mui.com/x/", + "sideEffects": false, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "publishConfig": { + "access": "public", + "directory": "build" + }, + "keywords": [ + "react", + "react-component", + "material-ui", + "mui", + "mui-x", + "utils" + ], + "scripts": { + "typescript": "tsc -p tsconfig.json", + "build": "pnpm build:modern && pnpm build:node && pnpm build:stable && pnpm build:types && pnpm build:copy-files ", + "build:modern": "node ../../scripts/build.mjs modern", + "build:node": "node ../../scripts/build.mjs node", + "build:stable": "node ../../scripts/build.mjs stable", + "build:copy-files": "node ../../scripts/copyFiles.mjs", + "build:types": "node ../../scripts/buildTypes.mjs", + "prebuild": "rimraf build tsconfig.build.tsbuildinfo" + }, + "repository": { + "type": "git", + "url": "https://github.com/mui/mui-x.git", + "directory": "packages/x-internals" + }, + "dependencies": { + "@babel/runtime": "^7.24.7", + "@mui/utils": "^5.15.20" + }, + "peerDependencies": { + "react": "^17.0.0 || ^18.0.0" + }, + "devDependencies": { + "@mui/internal-test-utils": "^1.0.2", + "rimraf": "^5.0.7" + }, + "engines": { + "node": ">=14.0.0" + } +} diff --git a/packages/x-internals/src/useResizeObserver/index.ts b/packages/x-internals/src/useResizeObserver/index.ts new file mode 100644 index 000000000000..327eacb9a95d --- /dev/null +++ b/packages/x-internals/src/useResizeObserver/index.ts @@ -0,0 +1 @@ +export { useResizeObserver } from './useResizeObserver'; diff --git a/packages/x-data-grid/src/hooks/utils/useResizeObserver.ts b/packages/x-internals/src/useResizeObserver/useResizeObserver.ts similarity index 100% rename from packages/x-data-grid/src/hooks/utils/useResizeObserver.ts rename to packages/x-internals/src/useResizeObserver/useResizeObserver.ts diff --git a/packages/x-internals/tsconfig.build.json b/packages/x-internals/tsconfig.build.json new file mode 100644 index 000000000000..1bd81f499e5c --- /dev/null +++ b/packages/x-internals/tsconfig.build.json @@ -0,0 +1,16 @@ +{ + // This config is for emitting declarations (.d.ts) only + // Actual .ts source files are transpiled via babel + "extends": "./tsconfig.json", + "compilerOptions": { + "composite": true, + "declaration": true, + "noEmit": false, + "emitDeclarationOnly": true, + "outDir": "build", + "rootDir": "./src", + "types": ["node"] + }, + "include": ["src/**/*.ts*"], + "exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"] +} diff --git a/packages/x-internals/tsconfig.json b/packages/x-internals/tsconfig.json new file mode 100644 index 000000000000..359e742ef933 --- /dev/null +++ b/packages/x-internals/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "types": ["node", "@mui/internal-test-utils/initMatchers", "chai-dom", "mocha"] + }, + "include": ["src/**/*"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47df358bd0f6..0e72c1400d64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -930,6 +930,9 @@ importers: '@mui/utils': specifier: ^5.15.20 version: 5.15.20(@types/react@18.3.3)(react@18.3.1) + '@mui/x-internals': + specifier: workspace:* + version: link:../x-internals/build clsx: specifier: ^2.1.1 version: 2.1.1 @@ -1024,6 +1027,9 @@ importers: '@mui/x-data-grid-pro': specifier: workspace:* version: link:../x-data-grid-pro/build + '@mui/x-internals': + specifier: workspace:* + version: link:../x-internals/build '@mui/x-license': specifier: workspace:* version: link:../x-license/build @@ -1080,6 +1086,9 @@ importers: '@mui/x-data-grid': specifier: workspace:* version: link:../x-data-grid/build + '@mui/x-internals': + specifier: workspace:* + version: link:../x-internals/build '@mui/x-license': specifier: workspace:* version: link:../x-license/build @@ -1279,6 +1288,26 @@ importers: version: 5.0.7 publishDirectory: build + packages/x-internals: + dependencies: + '@babel/runtime': + specifier: ^7.24.7 + version: 7.24.7 + '@mui/utils': + specifier: ^5.15.20 + version: 5.15.20(@types/react@18.3.3)(react@18.3.1) + react: + specifier: ^17.0.0 || ^18.0.0 + version: 18.3.1 + devDependencies: + '@mui/internal-test-utils': + specifier: ^1.0.2 + version: 1.0.2(@babel/core@7.24.7)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + rimraf: + specifier: ^5.0.7 + version: 5.0.7 + publishDirectory: build + packages/x-license: dependencies: '@babel/runtime': diff --git a/scripts/x-data-grid-premium.exports.json b/scripts/x-data-grid-premium.exports.json index 367da6389ce3..12f86b8d6196 100644 --- a/scripts/x-data-grid-premium.exports.json +++ b/scripts/x-data-grid-premium.exports.json @@ -663,7 +663,6 @@ { "name": "useGridVirtualization", "kind": "Function" }, { "name": "useKeepGroupedColumnsHidden", "kind": "Variable" }, { "name": "useOnMount", "kind": "Function" }, - { "name": "useResizeObserver", "kind": "Function" }, { "name": "useRunOnce", "kind": "Variable" }, { "name": "ValueOptions", "kind": "TypeAlias" }, { "name": "virtualizationStateInitializer", "kind": "Variable" } diff --git a/scripts/x-data-grid-pro.exports.json b/scripts/x-data-grid-pro.exports.json index 3007e027bd29..22f8ca72e6d0 100644 --- a/scripts/x-data-grid-pro.exports.json +++ b/scripts/x-data-grid-pro.exports.json @@ -613,7 +613,6 @@ { "name": "useGridSelector", "kind": "Variable" }, { "name": "useGridVirtualization", "kind": "Function" }, { "name": "useOnMount", "kind": "Function" }, - { "name": "useResizeObserver", "kind": "Function" }, { "name": "useRunOnce", "kind": "Variable" }, { "name": "ValueOptions", "kind": "TypeAlias" }, { "name": "virtualizationStateInitializer", "kind": "Variable" } diff --git a/scripts/x-data-grid.exports.json b/scripts/x-data-grid.exports.json index cf7cbd8a558f..ec3c2edb53e8 100644 --- a/scripts/x-data-grid.exports.json +++ b/scripts/x-data-grid.exports.json @@ -562,7 +562,6 @@ { "name": "useGridSelector", "kind": "Variable" }, { "name": "useGridVirtualization", "kind": "Function" }, { "name": "useOnMount", "kind": "Function" }, - { "name": "useResizeObserver", "kind": "Function" }, { "name": "useRunOnce", "kind": "Variable" }, { "name": "ValueOptions", "kind": "TypeAlias" }, { "name": "virtualizationStateInitializer", "kind": "Variable" } diff --git a/test/package.json b/test/package.json index 03fbb2a7deb3..402241f2b115 100644 --- a/test/package.json +++ b/test/package.json @@ -1,6 +1,6 @@ { "name": "@mui-x-internal/test", - "version": "7.2.0", + "version": "7.7.1", "private": true, "scripts": { "typescript": "tsc -p tsconfig.json" diff --git a/tsconfig.json b/tsconfig.json index a94255b6f09c..6a9b26ef2fdf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -31,6 +31,8 @@ "@mui/x-tree-view-pro/*": ["./packages/x-tree-view-pro/src/*"], "@mui/x-license": ["./packages/x-license/src"], "@mui/x-license/*": ["./packages/x-license/src/*"], + "@mui/x-internals": ["./packages/x-internals/src"], + "@mui/x-internals/*": ["./packages/x-internals/src/*"], "@mui/docs": ["./node_modules/@mui/monorepo/packages/mui-docs/src"], "@mui/docs/*": ["./node_modules/@mui/monorepo/packages/mui-docs/src/*"], "@mui-internal/api-docs-builder": ["./node_modules/@mui/monorepo/packages/api-docs-builder"], diff --git a/webpackBaseConfig.js b/webpackBaseConfig.js index ab1b0fe068fd..22dddfcfed4f 100644 --- a/webpackBaseConfig.js +++ b/webpackBaseConfig.js @@ -19,6 +19,7 @@ module.exports = { '@mui/x-tree-view': path.resolve(__dirname, './packages/x-tree-view/src'), '@mui/x-tree-view-pro': path.resolve(__dirname, './packages/x-tree-view-pro/src'), '@mui/x-license': path.resolve(__dirname, './packages/x-license/src'), + '@mui/x-internals': path.resolve(__dirname, './packages/x-internals/src'), '@mui/material-nextjs': path.resolve( __dirname, './node_modules/@mui/monorepo/packages/mui-material-nextjs/src',