wip:milestone 0 fixes
Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped

This commit is contained in:
2026-03-15 12:35:42 +02:00
parent 6708cf28a7
commit cffdf8af86
61266 changed files with 4511646 additions and 1938 deletions

View File

@@ -0,0 +1,6 @@
export * from './useGridApiEventHandler';
export * from './useGridApiMethod';
export * from './useGridLogger';
export { useGridSelector } from './useGridSelector';
export * from './useGridNativeEventListener';
export * from './useFirstRender';

View File

@@ -0,0 +1,8 @@
import * as React from 'react';
export var useFirstRender = function useFirstRender(callback) {
var isFirstRender = React.useRef(true);
if (isFirstRender.current) {
isFirstRender.current = false;
callback();
}
};

View File

@@ -0,0 +1,9 @@
import * as React from 'react';
import { GridApiContext } from '../../components/GridApiContext';
export function useGridApiContext() {
var apiRef = React.useContext(GridApiContext);
if (apiRef === undefined) {
throw new Error(['MUI: Could not find the data grid context.', 'It looks like you rendered your component outside of a DataGrid, DataGridPro or DataGridPremium parent component.', 'This can also happen if you are bundling multiple versions of the data grid.'].join('\n'));
}
return apiRef;
}

View File

@@ -0,0 +1,105 @@
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import * as React from 'react';
import { TimerBasedCleanupTracking } from '../../utils/cleanupTracking/TimerBasedCleanupTracking';
import { FinalizationRegistryBasedCleanupTracking } from '../../utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking';
/**
* Signal to the underlying logic what version of the public component API
* of the data grid is exposed.
*/
var GridSignature = /*#__PURE__*/function (GridSignature) {
GridSignature["DataGrid"] = "DataGrid";
GridSignature["DataGridPro"] = "DataGridPro";
return GridSignature;
}(GridSignature || {});
// We use class to make it easier to detect in heap snapshots by name
var ObjectToBeRetainedByReact = /*#__PURE__*/_createClass(function ObjectToBeRetainedByReact() {
_classCallCheck(this, ObjectToBeRetainedByReact);
}); // Based on https://github.com/Bnaya/use-dispose-uncommitted/blob/main/src/finalization-registry-based-impl.ts
// Check https://github.com/facebook/react/issues/15317 to get more information
export function createUseGridApiEventHandler(registryContainer) {
var cleanupTokensCounter = 0;
return function useGridApiEventHandler(apiRef, eventName, handler, options) {
if (registryContainer.registry === null) {
registryContainer.registry = typeof FinalizationRegistry !== 'undefined' ? new FinalizationRegistryBasedCleanupTracking() : new TimerBasedCleanupTracking();
}
var _React$useState = React.useState(new ObjectToBeRetainedByReact()),
_React$useState2 = _slicedToArray(_React$useState, 1),
objectRetainedByReact = _React$useState2[0];
var subscription = React.useRef(null);
var handlerRef = React.useRef();
handlerRef.current = handler;
var cleanupTokenRef = React.useRef(null);
if (!subscription.current && handlerRef.current) {
var enhancedHandler = function enhancedHandler(params, event, details) {
if (!event.defaultMuiPrevented) {
var _handlerRef$current;
(_handlerRef$current = handlerRef.current) == null || _handlerRef$current.call(handlerRef, params, event, details);
}
};
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
cleanupTokensCounter += 1;
cleanupTokenRef.current = {
cleanupToken: cleanupTokensCounter
};
registryContainer.registry.register(objectRetainedByReact,
// The callback below will be called once this reference stops being retained
function () {
var _subscription$current;
(_subscription$current = subscription.current) == null || _subscription$current.call(subscription);
subscription.current = null;
cleanupTokenRef.current = null;
}, cleanupTokenRef.current);
} else if (!handlerRef.current && subscription.current) {
subscription.current();
subscription.current = null;
if (cleanupTokenRef.current) {
registryContainer.registry.unregister(cleanupTokenRef.current);
cleanupTokenRef.current = null;
}
}
React.useEffect(function () {
if (!subscription.current && handlerRef.current) {
var _enhancedHandler = function _enhancedHandler(params, event, details) {
if (!event.defaultMuiPrevented) {
var _handlerRef$current2;
(_handlerRef$current2 = handlerRef.current) == null || _handlerRef$current2.call(handlerRef, params, event, details);
}
};
subscription.current = apiRef.current.subscribeEvent(eventName, _enhancedHandler, options);
}
if (cleanupTokenRef.current && registryContainer.registry) {
// If the effect was called, it means that this render was committed
// so we can trust the cleanup function to remove the listener.
registryContainer.registry.unregister(cleanupTokenRef.current);
cleanupTokenRef.current = null;
}
return function () {
var _subscription$current2;
(_subscription$current2 = subscription.current) == null || _subscription$current2.call(subscription);
subscription.current = null;
};
}, [apiRef, eventName, options]);
};
}
var registryContainer = {
registry: null
};
// TODO: move to @mui/x-data-grid/internals
// eslint-disable-next-line @typescript-eslint/naming-convention
export var unstable_resetCleanupTracking = function unstable_resetCleanupTracking() {
var _registryContainer$re;
(_registryContainer$re = registryContainer.registry) == null || _registryContainer$re.reset();
registryContainer.registry = null;
};
export var useGridApiEventHandler = createUseGridApiEventHandler(registryContainer);
var optionsSubscriberOptions = {
isFirst: true
};
export function useGridApiOptionHandler(apiRef, eventName, handler) {
// Validate that only one per event name?
useGridApiEventHandler(apiRef, eventName, handler, optionsSubscriberOptions);
}
export { GridSignature };

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
export function useGridApiMethod(privateApiRef, apiMethods, visibility) {
var isFirstRender = React.useRef(true);
React.useEffect(function () {
isFirstRender.current = false;
privateApiRef.current.register(visibility, apiMethods);
}, [privateApiRef, visibility, apiMethods]);
if (isFirstRender.current) {
privateApiRef.current.register(visibility, apiMethods);
}
}

View File

@@ -0,0 +1,7 @@
import * as React from 'react';
/**
* Hook that instantiate a [[GridApiRef]].
*/
export var useGridApiRef = function useGridApiRef() {
return React.useRef({});
};

View File

@@ -0,0 +1,25 @@
import { gridVisibleColumnDefinitionsSelector } from '../features/columns/gridColumnsSelector';
import { useGridSelector } from './useGridSelector';
import { useGridRootProps } from './useGridRootProps';
import { gridColumnGroupsHeaderMaxDepthSelector } from '../features/columnGrouping/gridColumnGroupsSelector';
import { gridPinnedRowsCountSelector, gridRowCountSelector } from '../features/rows/gridRowsSelector';
import { useGridPrivateApiContext } from './useGridPrivateApiContext';
export var useGridAriaAttributes = function useGridAriaAttributes() {
var _rootProps$experiment;
var apiRef = useGridPrivateApiContext();
var rootProps = useGridRootProps();
var visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
var totalRowCount = useGridSelector(apiRef, gridRowCountSelector);
var headerGroupingMaxDepth = useGridSelector(apiRef, gridColumnGroupsHeaderMaxDepthSelector);
var pinnedRowsCount = useGridSelector(apiRef, gridPinnedRowsCountSelector);
var role = 'grid';
if ((_rootProps$experiment = rootProps.experimentalFeatures) != null && _rootProps$experiment.ariaV7 && rootProps.treeData) {
role = 'treegrid';
}
return {
role: role,
'aria-colcount': visibleColumns.length,
'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + totalRowCount,
'aria-multiselectable': !rootProps.disableMultipleRowSelection
};
};

View File

@@ -0,0 +1,8 @@
import * as React from 'react';
export var useGridInitializeState = function useGridInitializeState(initializer, privateApiRef, props) {
var isInitialized = React.useRef(false);
if (!isInitialized.current) {
privateApiRef.current.state = initializer(privateApiRef.current.state, props, privateApiRef);
isInitialized.current = true;
}
};

View File

@@ -0,0 +1,10 @@
import * as React from 'react';
export function useGridLogger(privateApiRef, name) {
var logger = React.useRef(null);
if (logger.current) {
return logger.current;
}
var newLogger = privateApiRef.current.getLogger(name);
logger.current = newLogger;
return newLogger;
}

View File

@@ -0,0 +1,37 @@
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import * as React from 'react';
import { isFunction } from '../../utils/utils';
import { useGridLogger } from './useGridLogger';
export var useGridNativeEventListener = function useGridNativeEventListener(apiRef, ref, eventName, handler, options) {
var logger = useGridLogger(apiRef, 'useNativeEventListener');
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
added = _React$useState2[0],
setAdded = _React$useState2[1];
var handlerRef = React.useRef(handler);
var wrapHandler = React.useCallback(function (event) {
return handlerRef.current && handlerRef.current(event);
}, []);
React.useEffect(function () {
handlerRef.current = handler;
}, [handler]);
React.useEffect(function () {
var targetElement;
if (isFunction(ref)) {
targetElement = ref();
} else {
targetElement = ref && ref.current ? ref.current : null;
}
if (targetElement && eventName && !added) {
logger.debug("Binding native ".concat(eventName, " event"));
targetElement.addEventListener(eventName, wrapHandler, options);
var boundElem = targetElement;
setAdded(true);
var unsubscribe = function unsubscribe() {
logger.debug("Clearing native ".concat(eventName, " event"));
boundElem.removeEventListener(eventName, wrapHandler, options);
};
apiRef.current.subscribeEvent('unmount', unsubscribe);
}
}, [ref, wrapHandler, eventName, added, logger, options, apiRef]);
};

View File

@@ -0,0 +1,12 @@
import * as React from 'react';
export var GridPrivateApiContext = /*#__PURE__*/React.createContext(undefined);
if (process.env.NODE_ENV !== 'production') {
GridPrivateApiContext.displayName = 'GridPrivateApiContext';
}
export function useGridPrivateApiContext() {
var privateApiRef = React.useContext(GridPrivateApiContext);
if (privateApiRef === undefined) {
throw new Error(['MUI: Could not find the data grid private context.', 'It looks like you rendered your component outside of a DataGrid, DataGridPro or DataGridPremium parent component.', 'This can also happen if you are bundling multiple versions of the data grid.'].join('\n'));
}
return privateApiRef;
}

View File

@@ -0,0 +1,9 @@
import * as React from 'react';
import { GridRootPropsContext } from '../../context/GridRootPropsContext';
export var useGridRootProps = function useGridRootProps() {
var contextValue = React.useContext(GridRootPropsContext);
if (!contextValue) {
throw new Error('MUI: useGridRootProps should only be used inside the DataGrid, DataGridPro or DataGridPremium component.');
}
return contextValue;
};

View File

@@ -0,0 +1,54 @@
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import * as React from 'react';
import { useLazyRef } from './useLazyRef';
import { useOnMount } from './useOnMount';
import { buildWarning } from '../../utils/warning';
import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
var stateNotInitializedWarning = buildWarning(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
function isOutputSelector(selector) {
return selector.acceptsApiRef;
}
function applySelector(apiRef, selector) {
if (isOutputSelector(selector)) {
return selector(apiRef);
}
return selector(apiRef.current.state);
}
var defaultCompare = Object.is;
export var objectShallowCompare = fastObjectShallowCompare;
var createRefs = function createRefs() {
return {
state: null,
equals: null,
selector: null
};
};
export var useGridSelector = function useGridSelector(apiRef, selector) {
var equals = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCompare;
if (process.env.NODE_ENV !== 'production') {
if (!apiRef.current.state) {
stateNotInitializedWarning();
}
}
var refs = useLazyRef(createRefs);
var didInit = refs.current.selector !== null;
var _React$useState = React.useState(
// We don't use an initialization function to avoid allocations
didInit ? null : applySelector(apiRef, selector)),
_React$useState2 = _slicedToArray(_React$useState, 2),
state = _React$useState2[0],
setState = _React$useState2[1];
refs.current.state = state;
refs.current.equals = equals;
refs.current.selector = selector;
useOnMount(function () {
return apiRef.current.store.subscribe(function () {
var newState = applySelector(apiRef, refs.current.selector);
if (!refs.current.equals(refs.current.state, newState)) {
refs.current.state = newState;
setState(newState);
}
});
});
return state;
};

View File

@@ -0,0 +1,42 @@
import * as React from 'react';
import { gridPaginationRowRangeSelector, gridPaginatedVisibleSortedGridRowEntriesSelector } from '../features/pagination/gridPaginationSelector';
import { gridExpandedSortedRowEntriesSelector } from '../features/filter/gridFilterSelector';
export var getVisibleRows = function getVisibleRows(apiRef, props) {
var rows;
var range;
if (props.pagination && props.paginationMode === 'client') {
range = gridPaginationRowRangeSelector(apiRef);
rows = gridPaginatedVisibleSortedGridRowEntriesSelector(apiRef);
} else {
rows = gridExpandedSortedRowEntriesSelector(apiRef);
if (rows.length === 0) {
range = null;
} else {
range = {
firstRowIndex: 0,
lastRowIndex: rows.length - 1
};
}
}
return {
rows: rows,
range: range
};
};
/**
* Computes the list of rows that are reachable by scroll.
* Depending on whether pagination is enabled, it will return the rows in the current page.
* - If the pagination is disabled or in server mode, it equals all the visible rows.
* - If the row tree has several layers, it contains up to `state.pageSize` top level rows and all their descendants.
* - If the row tree is flat, it only contains up to `state.pageSize` rows.
*/
export var useGridVisibleRows = function useGridVisibleRows(apiRef, props) {
var response = getVisibleRows(apiRef, props);
return React.useMemo(function () {
return {
rows: response.rows,
range: response.range
};
}, [response.rows, response.range]);
};

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
var UNINITIALIZED = {};
// See https://github.com/facebook/react/issues/14490 for when to use this.
export function useLazyRef(init, initArg) {
var ref = React.useRef(UNINITIALIZED);
if (ref.current === UNINITIALIZED) {
ref.current = init(initArg);
}
return ref;
}

View File

@@ -0,0 +1,7 @@
import * as React from 'react';
var EMPTY = [];
export function useOnMount(fn) {
/* eslint-disable react-hooks/exhaustive-deps */
React.useEffect(fn, EMPTY);
/* eslint-enable react-hooks/exhaustive-deps */
}

View File

@@ -0,0 +1,38 @@
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import { useLazyRef } from './useLazyRef';
import { useOnMount } from './useOnMount';
var Timeout = /*#__PURE__*/function () {
function Timeout() {
var _this = this;
_classCallCheck(this, Timeout);
this.currentId = 0;
this.clear = function () {
if (_this.currentId !== 0) {
clearTimeout(_this.currentId);
_this.currentId = 0;
}
};
this.disposeEffect = function () {
return _this.clear;
};
}
_createClass(Timeout, [{
key: "start",
value: function start(delay, fn) {
this.clear();
this.currentId = setTimeout(fn, delay);
}
}], [{
key: "create",
value: function create() {
return new Timeout();
}
}]);
return Timeout;
}();
export function useTimeout() {
var timeout = useLazyRef(Timeout.create).current;
useOnMount(timeout.disposeEffect);
return timeout;
}