neue Homepage auf react basis

This commit is contained in:
2026-08-07 21:39:30 +02:00
parent 164bdd19ad
commit ee89442c04
52191 changed files with 1230242 additions and 58 deletions
+10
View File
@@ -0,0 +1,10 @@
export * from '@mui/x-internals/useRunOnce';
export { useGridEvent, useGridEventPriority, unstable_resetCleanupTracking } from "./useGridEvent.mjs";
export * from "./useGridApiMethod.mjs";
export * from "./useGridLogger.mjs";
export { useGridSelector } from "./useGridSelector.mjs";
export * from "./useGridNativeEventListener.mjs";
export * from "./useFirstRender.mjs";
export * from "./useOnMount.mjs";
export * from "./useRunOncePerLoop.mjs";
export type { RenderProp } from '@mui/x-internals/useComponentRenderer';
+10
View File
@@ -0,0 +1,10 @@
export * from '@mui/x-internals/useRunOnce';
export { useGridEvent, useGridEventPriority, unstable_resetCleanupTracking } from "./useGridEvent.js";
export * from "./useGridApiMethod.js";
export * from "./useGridLogger.js";
export { useGridSelector } from "./useGridSelector.js";
export * from "./useGridNativeEventListener.js";
export * from "./useFirstRender.js";
export * from "./useOnMount.js";
export * from "./useRunOncePerLoop.js";
export type { RenderProp } from '@mui/x-internals/useComponentRenderer';
+121
View File
@@ -0,0 +1,121 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
useGridEvent: true,
useGridEventPriority: true,
unstable_resetCleanupTracking: true,
useGridSelector: true
};
Object.defineProperty(exports, "unstable_resetCleanupTracking", {
enumerable: true,
get: function () {
return _useGridEvent.unstable_resetCleanupTracking;
}
});
Object.defineProperty(exports, "useGridEvent", {
enumerable: true,
get: function () {
return _useGridEvent.useGridEvent;
}
});
Object.defineProperty(exports, "useGridEventPriority", {
enumerable: true,
get: function () {
return _useGridEvent.useGridEventPriority;
}
});
Object.defineProperty(exports, "useGridSelector", {
enumerable: true,
get: function () {
return _useGridSelector.useGridSelector;
}
});
var _useRunOnce = require("@mui/x-internals/useRunOnce");
Object.keys(_useRunOnce).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useRunOnce[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useRunOnce[key];
}
});
});
var _useGridEvent = require("./useGridEvent");
var _useGridApiMethod = require("./useGridApiMethod");
Object.keys(_useGridApiMethod).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useGridApiMethod[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useGridApiMethod[key];
}
});
});
var _useGridLogger = require("./useGridLogger");
Object.keys(_useGridLogger).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useGridLogger[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useGridLogger[key];
}
});
});
var _useGridSelector = require("./useGridSelector");
var _useGridNativeEventListener = require("./useGridNativeEventListener");
Object.keys(_useGridNativeEventListener).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useGridNativeEventListener[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useGridNativeEventListener[key];
}
});
});
var _useFirstRender = require("./useFirstRender");
Object.keys(_useFirstRender).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useFirstRender[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useFirstRender[key];
}
});
});
var _useOnMount = require("./useOnMount");
Object.keys(_useOnMount).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useOnMount[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useOnMount[key];
}
});
});
var _useRunOncePerLoop = require("./useRunOncePerLoop");
Object.keys(_useRunOncePerLoop).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useRunOncePerLoop[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useRunOncePerLoop[key];
}
});
});
+9
View File
@@ -0,0 +1,9 @@
export * from '@mui/x-internals/useRunOnce';
export { useGridEvent, useGridEventPriority, unstable_resetCleanupTracking } from "./useGridEvent.mjs";
export * from "./useGridApiMethod.mjs";
export * from "./useGridLogger.mjs";
export { useGridSelector } from "./useGridSelector.mjs";
export * from "./useGridNativeEventListener.mjs";
export * from "./useFirstRender.mjs";
export * from "./useOnMount.mjs";
export * from "./useRunOncePerLoop.mjs";
@@ -0,0 +1 @@
export * from '@mui/x-internals/useFirstRender';
@@ -0,0 +1 @@
export * from '@mui/x-internals/useFirstRender';
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _useFirstRender = require("@mui/x-internals/useFirstRender");
Object.keys(_useFirstRender).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _useFirstRender[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _useFirstRender[key];
}
});
});
+1
View File
@@ -0,0 +1 @@
export * from '@mui/x-internals/useFirstRender';
@@ -0,0 +1,4 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridApiCommon } from "../../models/api/gridApiCommon.mjs";
import type { GridApiCommunity } from "../../models/api/gridApiCommunity.mjs";
export declare function useGridApiContext<Api extends GridApiCommon = GridApiCommunity>(): RefObject<Api>;
@@ -0,0 +1,4 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridApiCommon } from "../../models/api/gridApiCommon.js";
import type { GridApiCommunity } from "../../models/api/gridApiCommunity.js";
export declare function useGridApiContext<Api extends GridApiCommon = GridApiCommunity>(): RefObject<Api>;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridApiContext = useGridApiContext;
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
var React = _interopRequireWildcard(require("react"));
var _GridApiContext = require("../../components/GridApiContext");
function useGridApiContext() {
const apiRef = React.useContext(_GridApiContext.GridApiContext);
if (apiRef === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: Could not find the Data Grid context. ' + 'This happens when a component is rendered outside of a DataGrid, DataGridPro, or DataGridPremium parent component. ' + 'Ensure your component is a child of a Data Grid component. ' + 'This can also happen if you are bundling multiple versions of the Data Grid.' : (0, _formatErrorMessage2.default)(67));
}
return apiRef;
}
@@ -0,0 +1,12 @@
'use client';
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
import * as React from 'react';
import { GridApiContext } from "../../components/GridApiContext.mjs";
export function useGridApiContext() {
const apiRef = React.useContext(GridApiContext);
if (apiRef === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: Could not find the Data Grid context. ' + 'This happens when a component is rendered outside of a DataGrid, DataGridPro, or DataGridPremium parent component. ' + 'Ensure your component is a child of a Data Grid component. ' + 'This can also happen if you are bundling multiple versions of the Data Grid.' : _formatErrorMessage(67));
}
return apiRef;
}
@@ -0,0 +1,7 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.mjs";
type GetPublicApiType<PrivateApi> = PrivateApi extends {
getPublicApi: () => infer PublicApi;
} ? PublicApi : never;
export declare function useGridApiMethod<PrivateApi extends GridPrivateApiCommon, PublicApi extends GetPublicApiType<PrivateApi>, PrivateOnlyApi extends Omit<PrivateApi, keyof PublicApi>, V extends 'public' | 'private', T extends (V extends 'public' ? Partial<PublicApi> : Partial<PrivateOnlyApi>)>(privateApiRef: RefObject<PrivateApi>, apiMethods: T, visibility: V): void;
export {};
@@ -0,0 +1,7 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
type GetPublicApiType<PrivateApi> = PrivateApi extends {
getPublicApi: () => infer PublicApi;
} ? PublicApi : never;
export declare function useGridApiMethod<PrivateApi extends GridPrivateApiCommon, PublicApi extends GetPublicApiType<PrivateApi>, PrivateOnlyApi extends Omit<PrivateApi, keyof PublicApi>, V extends 'public' | 'private', T extends (V extends 'public' ? Partial<PublicApi> : Partial<PrivateOnlyApi>)>(privateApiRef: RefObject<PrivateApi>, apiMethods: T, visibility: V): void;
export {};
+21
View File
@@ -0,0 +1,21 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridApiMethod = useGridApiMethod;
var React = _interopRequireWildcard(require("react"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
function useGridApiMethod(privateApiRef, apiMethods, visibility) {
const isFirstRender = React.useRef(true);
(0, _useEnhancedEffect.default)(() => {
isFirstRender.current = false;
privateApiRef.current.register(visibility, apiMethods);
}, [privateApiRef, visibility, apiMethods]);
if (isFirstRender.current) {
privateApiRef.current.register(visibility, apiMethods);
}
}
+14
View File
@@ -0,0 +1,14 @@
'use client';
import * as React from 'react';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
export function useGridApiMethod(privateApiRef, apiMethods, visibility) {
const isFirstRender = React.useRef(true);
useEnhancedEffect(() => {
isFirstRender.current = false;
privateApiRef.current.register(visibility, apiMethods);
}, [privateApiRef, visibility, apiMethods]);
if (isFirstRender.current) {
privateApiRef.current.register(visibility, apiMethods);
}
}
@@ -0,0 +1,6 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridApiCommunity } from "../../models/api/gridApiCommunity.mjs";
/**
* Hook that instantiate a [[GridApiRef]].
*/
export declare const useGridApiRef: () => RefObject<GridApiCommunity | null>;
+6
View File
@@ -0,0 +1,6 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridApiCommunity } from "../../models/api/gridApiCommunity.js";
/**
* Hook that instantiate a [[GridApiRef]].
*/
export declare const useGridApiRef: () => RefObject<GridApiCommunity | null>;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridApiRef = void 0;
var React = _interopRequireWildcard(require("react"));
/**
* Hook that instantiate a [[GridApiRef]].
*/
const useGridApiRef = () => React.useRef(null);
exports.useGridApiRef = useGridApiRef;
+7
View File
@@ -0,0 +1,7 @@
'use client';
import * as React from 'react';
/**
* Hook that instantiate a [[GridApiRef]].
*/
export const useGridApiRef = () => React.useRef(null);
@@ -0,0 +1,2 @@
import type * as React from 'react';
export declare const useGridAriaAttributes: () => React.HTMLAttributes<HTMLElement>;
@@ -0,0 +1,2 @@
import type * as React from 'react';
export declare const useGridAriaAttributes: () => React.HTMLAttributes<HTMLElement>;
@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridAriaAttributes = void 0;
var _gridColumnsSelector = require("../features/columns/gridColumnsSelector");
var _useGridSelector = require("./useGridSelector");
var _useGridRootProps = require("./useGridRootProps");
var _gridColumnGroupsSelector = require("../features/columnGrouping/gridColumnGroupsSelector");
var _gridRowsSelector = require("../features/rows/gridRowsSelector");
var _useGridPrivateApiContext = require("./useGridPrivateApiContext");
var _utils = require("../features/rowSelection/utils");
var _gridFilterSelector = require("../features/filter/gridFilterSelector");
const useGridAriaAttributes = () => {
const apiRef = (0, _useGridPrivateApiContext.useGridPrivateApiContext)();
const rootProps = (0, _useGridRootProps.useGridRootProps)();
const visibleColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector);
const accessibleRowCount = (0, _useGridSelector.useGridSelector)(apiRef, _gridFilterSelector.gridExpandedRowCountSelector);
const headerGroupingMaxDepth = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnGroupsSelector.gridColumnGroupsHeaderMaxDepthSelector);
const pinnedRowsCount = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsCountSelector);
const ariaLabel = rootProps['aria-label'];
const ariaLabelledby = rootProps['aria-labelledby'];
// `aria-label` and `aria-labelledby` should take precedence over `label`
const shouldUseLabelAsAriaLabel = !ariaLabel && !ariaLabelledby && rootProps.label;
return {
role: 'grid',
'aria-label': shouldUseLabelAsAriaLabel ? rootProps.label : ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-colcount': visibleColumns.length,
'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + accessibleRowCount,
'aria-multiselectable': (0, _utils.isMultipleRowSelectionEnabled)(rootProps)
};
};
exports.useGridAriaAttributes = useGridAriaAttributes;
@@ -0,0 +1,28 @@
import { gridVisibleColumnDefinitionsSelector } from "../features/columns/gridColumnsSelector.mjs";
import { useGridSelector } from "./useGridSelector.mjs";
import { useGridRootProps } from "./useGridRootProps.mjs";
import { gridColumnGroupsHeaderMaxDepthSelector } from "../features/columnGrouping/gridColumnGroupsSelector.mjs";
import { gridPinnedRowsCountSelector } from "../features/rows/gridRowsSelector.mjs";
import { useGridPrivateApiContext } from "./useGridPrivateApiContext.mjs";
import { isMultipleRowSelectionEnabled } from "../features/rowSelection/utils.mjs";
import { gridExpandedRowCountSelector } from "../features/filter/gridFilterSelector.mjs";
export const useGridAriaAttributes = () => {
const apiRef = useGridPrivateApiContext();
const rootProps = useGridRootProps();
const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
const accessibleRowCount = useGridSelector(apiRef, gridExpandedRowCountSelector);
const headerGroupingMaxDepth = useGridSelector(apiRef, gridColumnGroupsHeaderMaxDepthSelector);
const pinnedRowsCount = useGridSelector(apiRef, gridPinnedRowsCountSelector);
const ariaLabel = rootProps['aria-label'];
const ariaLabelledby = rootProps['aria-labelledby'];
// `aria-label` and `aria-labelledby` should take precedence over `label`
const shouldUseLabelAsAriaLabel = !ariaLabel && !ariaLabelledby && rootProps.label;
return {
role: 'grid',
'aria-label': shouldUseLabelAsAriaLabel ? rootProps.label : ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-colcount': visibleColumns.length,
'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + accessibleRowCount,
'aria-multiselectable': isMultipleRowSelectionEnabled(rootProps)
};
};
@@ -0,0 +1,4 @@
import type { GridConfiguration } from "../../models/configuration/gridConfiguration.mjs";
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.mjs";
import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.mjs";
export declare const useGridConfiguration: <Api extends GridPrivateApiCommon = GridPrivateApiCommunity>() => GridConfiguration<Api>;
@@ -0,0 +1,4 @@
import type { GridConfiguration } from "../../models/configuration/gridConfiguration.js";
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
export declare const useGridConfiguration: <Api extends GridPrivateApiCommon = GridPrivateApiCommunity>() => GridConfiguration<Api>;
@@ -0,0 +1,20 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridConfiguration = void 0;
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
var React = _interopRequireWildcard(require("react"));
var _GridConfigurationContext = require("../../components/GridConfigurationContext");
const useGridConfiguration = () => {
const configuration = React.useContext(_GridConfigurationContext.GridConfigurationContext);
if (configuration === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: Could not find the Data Grid configuration context. ' + 'This happens when a component is rendered outside of a DataGrid, DataGridPro, or DataGridPremium parent component. ' + 'Ensure your component is a child of a Data Grid component. ' + 'This can also happen if you are bundling multiple versions of the Data Grid.' : (0, _formatErrorMessage2.default)(68));
}
return configuration;
};
exports.useGridConfiguration = useGridConfiguration;
@@ -0,0 +1,12 @@
'use client';
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
import * as React from 'react';
import { GridConfigurationContext } from "../../components/GridConfigurationContext.mjs";
export const useGridConfiguration = () => {
const configuration = React.useContext(GridConfigurationContext);
if (configuration === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: Could not find the Data Grid configuration context. ' + 'This happens when a component is rendered outside of a DataGrid, DataGridPro, or DataGridPremium parent component. ' + 'Ensure your component is a child of a Data Grid component. ' + 'This can also happen if you are bundling multiple versions of the Data Grid.' : _formatErrorMessage(68));
}
return configuration;
};
+12
View File
@@ -0,0 +1,12 @@
import type { RefObject } from '@mui/x-internals/types';
import type { EventListenerOptions } from '@mui/x-internals/EventManager';
import type { GridEventListener, GridEvents } from "../../models/events/index.mjs";
import { TimerBasedCleanupTracking } from "../../utils/cleanupTracking/TimerBasedCleanupTracking.mjs";
import { FinalizationRegistryBasedCleanupTracking } from "../../utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.mjs";
import type { GridApiCommon } from "../../models/index.mjs";
export declare function useGridEvent<Api extends GridApiCommon, E extends GridEvents>(apiRef: RefObject<Api>, eventName: E, handler?: GridEventListener<E>, options?: EventListenerOptions): void;
export declare function useGridEventPriority<Api extends GridApiCommon, E extends GridEvents>(apiRef: RefObject<Api>, eventName: E, handler?: GridEventListener<E>): void;
export declare function unstable_resetCleanupTracking(): void;
export declare const internal_registryContainer: {
current: FinalizationRegistryBasedCleanupTracking | TimerBasedCleanupTracking;
};
+12
View File
@@ -0,0 +1,12 @@
import type { RefObject } from '@mui/x-internals/types';
import type { EventListenerOptions } from '@mui/x-internals/EventManager';
import type { GridEventListener, GridEvents } from "../../models/events/index.js";
import { TimerBasedCleanupTracking } from "../../utils/cleanupTracking/TimerBasedCleanupTracking.js";
import { FinalizationRegistryBasedCleanupTracking } from "../../utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js";
import type { GridApiCommon } from "../../models/index.js";
export declare function useGridEvent<Api extends GridApiCommon, E extends GridEvents>(apiRef: RefObject<Api>, eventName: E, handler?: GridEventListener<E>, options?: EventListenerOptions): void;
export declare function useGridEventPriority<Api extends GridApiCommon, E extends GridEvents>(apiRef: RefObject<Api>, eventName: E, handler?: GridEventListener<E>): void;
export declare function unstable_resetCleanupTracking(): void;
export declare const internal_registryContainer: {
current: FinalizationRegistryBasedCleanupTracking | TimerBasedCleanupTracking;
};
+103
View File
@@ -0,0 +1,103 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.internal_registryContainer = void 0;
exports.unstable_resetCleanupTracking = unstable_resetCleanupTracking;
exports.useGridEvent = useGridEvent;
exports.useGridEventPriority = useGridEventPriority;
var React = _interopRequireWildcard(require("react"));
var _TimerBasedCleanupTracking = require("../../utils/cleanupTracking/TimerBasedCleanupTracking");
var _FinalizationRegistryBasedCleanupTracking = require("../../utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking");
// Based on https://github.com/Bnaya/use-dispose-uncommitted/blob/main/src/finalization-registry-based-impl.ts
// Check https://github.com/react/react/issues/15317 to get more information
// We use class to make it easier to detect in heap snapshots by name
class ObjectToBeRetainedByReact {
static create() {
return new ObjectToBeRetainedByReact();
}
}
const registryContainer = {
current: createRegistry()
};
let cleanupTokensCounter = 0;
function useGridEvent(apiRef, eventName, handler, options) {
const objectRetainedByReact = React.useState(ObjectToBeRetainedByReact.create)[0];
const subscription = React.useRef(null);
const handlerRef = React.useRef(null);
handlerRef.current = handler;
const cleanupTokenRef = React.useRef(null);
if (!subscription.current && handlerRef.current) {
const enhancedHandler = (params, event, details) => {
// Check for the existence of the event once more to avoid Safari 26 issue
// https://github.com/mui/mui-x/issues/20159
if (event && !event.defaultMuiPrevented) {
handlerRef.current?.(params, event, details);
}
};
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
cleanupTokensCounter += 1;
cleanupTokenRef.current = {
cleanupToken: cleanupTokensCounter
};
registryContainer.current.register(objectRetainedByReact,
// The callback below will be called once this reference stops being retained
() => {
subscription.current?.();
subscription.current = null;
cleanupTokenRef.current = null;
}, cleanupTokenRef.current);
} else if (!handlerRef.current && subscription.current) {
subscription.current();
subscription.current = null;
if (cleanupTokenRef.current) {
registryContainer.current.unregister(cleanupTokenRef.current);
cleanupTokenRef.current = null;
}
}
React.useEffect(() => {
if (!subscription.current && handlerRef.current) {
const enhancedHandler = (params, event, details) => {
// Check for the existence of the event once more to avoid Safari 26 issue
// https://github.com/mui/mui-x/issues/20159
if (event && !event.defaultMuiPrevented) {
handlerRef.current?.(params, event, details);
}
};
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
}
if (cleanupTokenRef.current && registryContainer.current) {
// If the effect was called, it means that this render was committed
// so we can trust the cleanup function to remove the listener.
registryContainer.current.unregister(cleanupTokenRef.current);
cleanupTokenRef.current = null;
}
return () => {
subscription.current?.();
subscription.current = null;
};
}, [apiRef, eventName, options]);
}
const OPTIONS_IS_FIRST = {
isFirst: true
};
function useGridEventPriority(apiRef, eventName, handler) {
useGridEvent(apiRef, eventName, handler, OPTIONS_IS_FIRST);
}
// TODO: move to @mui/x-data-grid/internals
// eslint-disable-next-line @typescript-eslint/naming-convention
function unstable_resetCleanupTracking() {
registryContainer.current?.reset();
registryContainer.current = createRegistry();
}
// eslint-disable-next-line @typescript-eslint/naming-convention
const internal_registryContainer = exports.internal_registryContainer = registryContainer;
function createRegistry() {
return typeof FinalizationRegistry !== 'undefined' ? new _FinalizationRegistryBasedCleanupTracking.FinalizationRegistryBasedCleanupTracking() : new _TimerBasedCleanupTracking.TimerBasedCleanupTracking();
}
+94
View File
@@ -0,0 +1,94 @@
'use client';
import * as React from 'react';
import { TimerBasedCleanupTracking } from "../../utils/cleanupTracking/TimerBasedCleanupTracking.mjs";
import { FinalizationRegistryBasedCleanupTracking } from "../../utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.mjs";
// Based on https://github.com/Bnaya/use-dispose-uncommitted/blob/main/src/finalization-registry-based-impl.ts
// Check https://github.com/react/react/issues/15317 to get more information
// We use class to make it easier to detect in heap snapshots by name
class ObjectToBeRetainedByReact {
static create() {
return new ObjectToBeRetainedByReact();
}
}
const registryContainer = {
current: createRegistry()
};
let cleanupTokensCounter = 0;
export function useGridEvent(apiRef, eventName, handler, options) {
const objectRetainedByReact = React.useState(ObjectToBeRetainedByReact.create)[0];
const subscription = React.useRef(null);
const handlerRef = React.useRef(null);
handlerRef.current = handler;
const cleanupTokenRef = React.useRef(null);
if (!subscription.current && handlerRef.current) {
const enhancedHandler = (params, event, details) => {
// Check for the existence of the event once more to avoid Safari 26 issue
// https://github.com/mui/mui-x/issues/20159
if (event && !event.defaultMuiPrevented) {
handlerRef.current?.(params, event, details);
}
};
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
cleanupTokensCounter += 1;
cleanupTokenRef.current = {
cleanupToken: cleanupTokensCounter
};
registryContainer.current.register(objectRetainedByReact,
// The callback below will be called once this reference stops being retained
() => {
subscription.current?.();
subscription.current = null;
cleanupTokenRef.current = null;
}, cleanupTokenRef.current);
} else if (!handlerRef.current && subscription.current) {
subscription.current();
subscription.current = null;
if (cleanupTokenRef.current) {
registryContainer.current.unregister(cleanupTokenRef.current);
cleanupTokenRef.current = null;
}
}
React.useEffect(() => {
if (!subscription.current && handlerRef.current) {
const enhancedHandler = (params, event, details) => {
// Check for the existence of the event once more to avoid Safari 26 issue
// https://github.com/mui/mui-x/issues/20159
if (event && !event.defaultMuiPrevented) {
handlerRef.current?.(params, event, details);
}
};
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
}
if (cleanupTokenRef.current && registryContainer.current) {
// If the effect was called, it means that this render was committed
// so we can trust the cleanup function to remove the listener.
registryContainer.current.unregister(cleanupTokenRef.current);
cleanupTokenRef.current = null;
}
return () => {
subscription.current?.();
subscription.current = null;
};
}, [apiRef, eventName, options]);
}
const OPTIONS_IS_FIRST = {
isFirst: true
};
export function useGridEventPriority(apiRef, eventName, handler) {
useGridEvent(apiRef, eventName, handler, OPTIONS_IS_FIRST);
}
// TODO: move to @mui/x-data-grid/internals
// eslint-disable-next-line @typescript-eslint/naming-convention
export function unstable_resetCleanupTracking() {
registryContainer.current?.reset();
registryContainer.current = createRegistry();
}
// eslint-disable-next-line @typescript-eslint/naming-convention
export const internal_registryContainer = registryContainer;
function createRegistry() {
return typeof FinalizationRegistry !== 'undefined' ? new FinalizationRegistryBasedCleanupTracking() : new TimerBasedCleanupTracking();
}
@@ -0,0 +1,8 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.mjs";
import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.mjs";
import type { DataGridProcessedProps } from "../../models/props/DataGridProps.mjs";
type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> };
export type GridStateInitializer<P extends Partial<DataGridProcessedProps> = DataGridProcessedProps, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity> = (state: DeepPartial<PrivateApi['state']>, props: P, privateApiRef: RefObject<PrivateApi>) => DeepPartial<PrivateApi['state']>;
export declare const useGridInitializeState: <P extends Partial<DataGridProcessedProps>, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity>(initializer: GridStateInitializer<P, PrivateApi>, privateApiRef: RefObject<PrivateApi>, props: P, key?: string) => void;
export {};
@@ -0,0 +1,8 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
import type { DataGridProcessedProps } from "../../models/props/DataGridProps.js";
type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> };
export type GridStateInitializer<P extends Partial<DataGridProcessedProps> = DataGridProcessedProps, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity> = (state: DeepPartial<PrivateApi['state']>, props: P, privateApiRef: RefObject<PrivateApi>) => DeepPartial<PrivateApi['state']>;
export declare const useGridInitializeState: <P extends Partial<DataGridProcessedProps>, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity>(initializer: GridStateInitializer<P, PrivateApi>, privateApiRef: RefObject<PrivateApi>, props: P, key?: string) => void;
export {};
@@ -0,0 +1,22 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridInitializeState = void 0;
var React = _interopRequireWildcard(require("react"));
const useGridInitializeState = (initializer, privateApiRef, props, key) => {
const previousKey = React.useRef(key);
const isInitialized = React.useRef(false);
if (key !== previousKey.current) {
isInitialized.current = false;
previousKey.current = key;
}
if (!isInitialized.current) {
privateApiRef.current.state = initializer(privateApiRef.current.state, props, privateApiRef);
isInitialized.current = true;
}
};
exports.useGridInitializeState = useGridInitializeState;
@@ -0,0 +1,15 @@
'use client';
import * as React from 'react';
export const useGridInitializeState = (initializer, privateApiRef, props, key) => {
const previousKey = React.useRef(key);
const isInitialized = React.useRef(false);
if (key !== previousKey.current) {
isInitialized.current = false;
previousKey.current = key;
}
if (!isInitialized.current) {
privateApiRef.current.state = initializer(privateApiRef.current.state, props, privateApiRef);
isInitialized.current = true;
}
};
@@ -0,0 +1,4 @@
import type { RefObject } from '@mui/x-internals/types';
import type { Logger } from "../../models/logger.mjs";
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.mjs";
export declare function useGridLogger<PrivateApi extends GridPrivateApiCommon>(privateApiRef: RefObject<PrivateApi>, name: string): Logger;
+4
View File
@@ -0,0 +1,4 @@
import type { RefObject } from '@mui/x-internals/types';
import type { Logger } from "../../models/logger.js";
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
export declare function useGridLogger<PrivateApi extends GridPrivateApiCommon>(privateApiRef: RefObject<PrivateApi>, name: string): Logger;
+18
View File
@@ -0,0 +1,18 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridLogger = useGridLogger;
var React = _interopRequireWildcard(require("react"));
function useGridLogger(privateApiRef, name) {
const logger = React.useRef(null);
if (logger.current) {
return logger.current;
}
const newLogger = privateApiRef.current.getLogger(name);
logger.current = newLogger;
return newLogger;
}
+12
View File
@@ -0,0 +1,12 @@
'use client';
import * as React from 'react';
export function useGridLogger(privateApiRef, name) {
const logger = React.useRef(null);
if (logger.current) {
return logger.current;
}
const newLogger = privateApiRef.current.getLogger(name);
logger.current = newLogger;
return newLogger;
}
@@ -0,0 +1,3 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.mjs";
export declare const useGridNativeEventListener: <PrivateApi extends GridPrivateApiCommon, K extends keyof HTMLElementEventMap>(apiRef: RefObject<PrivateApi>, ref: () => HTMLElement | undefined | null, eventName: K, handler: (event: HTMLElementEventMap[K]) => any, options?: AddEventListenerOptions) => void;
@@ -0,0 +1,3 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
export declare const useGridNativeEventListener: <PrivateApi extends GridPrivateApiCommon, K extends keyof HTMLElementEventMap>(apiRef: RefObject<PrivateApi>, ref: () => HTMLElement | undefined | null, eventName: K, handler: (event: HTMLElementEventMap[K]) => any, options?: AddEventListenerOptions) => void;
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridNativeEventListener = void 0;
var _useGridLogger = require("./useGridLogger");
var _useGridEvent = require("./useGridEvent");
const useGridNativeEventListener = (apiRef, ref, eventName, handler, options) => {
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useNativeEventListener');
(0, _useGridEvent.useGridEventPriority)(apiRef, 'rootMount', () => {
const targetElement = ref();
if (!targetElement || !eventName) {
return undefined;
}
logger.debug(`Binding native ${eventName} event`);
targetElement.addEventListener(eventName, handler, options);
return () => {
logger.debug(`Clearing native ${eventName} event`);
targetElement.removeEventListener(eventName, handler, options);
};
});
};
exports.useGridNativeEventListener = useGridNativeEventListener;
@@ -0,0 +1,17 @@
import { useGridLogger } from "./useGridLogger.mjs";
import { useGridEventPriority } from "./useGridEvent.mjs";
export const useGridNativeEventListener = (apiRef, ref, eventName, handler, options) => {
const logger = useGridLogger(apiRef, 'useNativeEventListener');
useGridEventPriority(apiRef, 'rootMount', () => {
const targetElement = ref();
if (!targetElement || !eventName) {
return undefined;
}
logger.debug(`Binding native ${eventName} event`);
targetElement.addEventListener(eventName, handler, options);
return () => {
logger.debug(`Clearing native ${eventName} event`);
targetElement.removeEventListener(eventName, handler, options);
};
});
};
@@ -0,0 +1,6 @@
import * as React from 'react';
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.mjs";
import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.mjs";
export declare const GridPrivateApiContext: React.Context<unknown>;
export declare function useGridPrivateApiContext<PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity>(): RefObject<PrivateApi>;
@@ -0,0 +1,6 @@
import * as React from 'react';
import type { RefObject } from '@mui/x-internals/types';
import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
export declare const GridPrivateApiContext: React.Context<unknown>;
export declare function useGridPrivateApiContext<PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity>(): RefObject<PrivateApi>;
@@ -0,0 +1,21 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridPrivateApiContext = void 0;
exports.useGridPrivateApiContext = useGridPrivateApiContext;
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
var React = _interopRequireWildcard(require("react"));
const GridPrivateApiContext = exports.GridPrivateApiContext = /*#__PURE__*/React.createContext(undefined);
if (process.env.NODE_ENV !== "production") GridPrivateApiContext.displayName = "GridPrivateApiContext";
function useGridPrivateApiContext() {
const privateApiRef = React.useContext(GridPrivateApiContext);
if (privateApiRef === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: Could not find the Data Grid private context. ' + 'This happens when a component is rendered outside of a DataGrid, DataGridPro, or DataGridPremium parent component. ' + 'Ensure your component is a child of a Data Grid component. ' + 'This can also happen if you are bundling multiple versions of the Data Grid.' : (0, _formatErrorMessage2.default)(69));
}
return privateApiRef;
}
@@ -0,0 +1,13 @@
'use client';
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
import * as React from 'react';
export const GridPrivateApiContext = /*#__PURE__*/React.createContext(undefined);
if (process.env.NODE_ENV !== "production") GridPrivateApiContext.displayName = "GridPrivateApiContext";
export function useGridPrivateApiContext() {
const privateApiRef = React.useContext(GridPrivateApiContext);
if (privateApiRef === undefined) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: Could not find the Data Grid private context. ' + 'This happens when a component is rendered outside of a DataGrid, DataGridPro, or DataGridPremium parent component. ' + 'Ensure your component is a child of a Data Grid component. ' + 'This can also happen if you are bundling multiple versions of the Data Grid.' : _formatErrorMessage(69));
}
return privateApiRef;
}
@@ -0,0 +1,2 @@
import type { DataGridProcessedProps } from "../../models/props/DataGridProps.mjs";
export declare const useGridRootProps: () => DataGridProcessedProps;
@@ -0,0 +1,2 @@
import type { DataGridProcessedProps } from "../../models/props/DataGridProps.js";
export declare const useGridRootProps: () => DataGridProcessedProps;
+20
View File
@@ -0,0 +1,20 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridRootProps = void 0;
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
var React = _interopRequireWildcard(require("react"));
var _GridRootPropsContext = require("../../context/GridRootPropsContext");
const useGridRootProps = () => {
const contextValue = React.useContext(_GridRootPropsContext.GridRootPropsContext);
if (!contextValue) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: useGridRootProps should only be used inside a Data Grid component. ' + 'The component must be a child of DataGrid, DataGridPro, or DataGridPremium. ' + 'Ensure your component is properly nested within a Data Grid.' : (0, _formatErrorMessage2.default)(70));
}
return contextValue;
};
exports.useGridRootProps = useGridRootProps;
+12
View File
@@ -0,0 +1,12 @@
'use client';
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
import * as React from 'react';
import { GridRootPropsContext } from "../../context/GridRootPropsContext.mjs";
export const useGridRootProps = () => {
const contextValue = React.useContext(GridRootPropsContext);
if (!contextValue) {
throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Data Grid: useGridRootProps should only be used inside a Data Grid component. ' + 'The component must be a child of DataGrid, DataGridPro, or DataGridPremium. ' + 'Ensure your component is properly nested within a Data Grid.' : _formatErrorMessage(70));
}
return contextValue;
};
@@ -0,0 +1,5 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridApiCommon } from "../../models/api/gridApiCommon.mjs";
export declare const objectShallowCompare: (a: unknown, b: unknown) => boolean;
export declare function useGridSelector<Api extends GridApiCommon, T>(apiRef: RefObject<Api>, selector: (apiRef: RefObject<Api>) => T, args?: undefined, equals?: <U = T>(a: U, b: U) => boolean): T;
export declare function useGridSelector<Api extends GridApiCommon, T, Args>(apiRef: RefObject<Api>, selector: (apiRef: RefObject<Api>, a1: Args) => T, args: Args, equals?: <U = T>(a: U, b: U) => boolean): T;
@@ -0,0 +1,5 @@
import type { RefObject } from '@mui/x-internals/types';
import type { GridApiCommon } from "../../models/api/gridApiCommon.js";
export declare const objectShallowCompare: (a: unknown, b: unknown) => boolean;
export declare function useGridSelector<Api extends GridApiCommon, T>(apiRef: RefObject<Api>, selector: (apiRef: RefObject<Api>) => T, args?: undefined, equals?: <U = T>(a: U, b: U) => boolean): T;
export declare function useGridSelector<Api extends GridApiCommon, T, Args>(apiRef: RefObject<Api>, selector: (apiRef: RefObject<Api>, a1: Args) => T, args: Args, equals?: <U = T>(a: U, b: U) => boolean): T;
+94
View File
@@ -0,0 +1,94 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.objectShallowCompare = void 0;
exports.useGridSelector = useGridSelector;
var React = _interopRequireWildcard(require("react"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _fastObjectShallowCompare = require("@mui/x-internals/fastObjectShallowCompare");
var _warning = require("@mui/x-internals/warning");
var _useLazyRef = require("./useLazyRef");
const defaultCompare = Object.is;
const objectShallowCompare = exports.objectShallowCompare = _fastObjectShallowCompare.fastObjectShallowCompare;
const arrayShallowCompare = (a, b) => {
if (a === b) {
return true;
}
return a.length === b.length && a.every((v, i) => v === b[i]);
};
const argsEqual = (prev, curr) => {
let fn = Object.is;
if (curr instanceof Array) {
fn = arrayShallowCompare;
} else if (curr instanceof Object) {
fn = objectShallowCompare;
}
return fn(prev, curr);
};
const createRefs = () => ({
state: null,
equals: null,
selector: null,
args: undefined,
storeState: null
});
const EMPTY = [];
function useGridSelector(apiRef, selector, args = undefined, equals = defaultCompare) {
if (process.env.NODE_ENV !== 'production' && !apiRef.current.state) {
(0, _warning.warnOnce)(['MUI X: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
}
const refs = (0, _useLazyRef.useLazyRef)(createRefs);
const didInit = refs.current.selector !== null;
const [state, setState] = React.useState(
// We don't use an initialization function to avoid allocations
didInit ? null : selector(apiRef, args));
refs.current.state = state;
if (!didInit) {
refs.current.storeState = apiRef.current.store.state;
}
refs.current.equals = equals;
refs.current.selector = selector;
const prevArgs = refs.current.args;
refs.current.args = args;
if (didInit && !argsEqual(prevArgs, args)) {
const newState = refs.current.selector(apiRef, refs.current.args);
if (!refs.current.equals(refs.current.state, newState)) {
refs.current.state = newState;
setState(newState);
}
refs.current.storeState = apiRef.current.store.state;
}
const updateState = React.useCallback(() => {
const storeState = apiRef.current.store.state;
if (refs.current.storeState !== storeState) {
const newState = refs.current.selector(apiRef, refs.current.args);
refs.current.storeState = storeState;
if (!refs.current.equals(refs.current.state, newState)) {
refs.current.state = newState;
setState(newState);
}
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo
EMPTY);
// Why subscribe in an effect instead of during render: a component can render without
// ever mounting (e.g. when it suspends during hydration). If it subscribed during render,
// it could receive a store update and call `setState` before being mounted (#17077).
// Effects only run for mounted components, so subscribing here is safe.
//
// Using a layout effect because the store may already have changed
// between render and mount (e.g. from a child's ref callback or layout effect).
// `updateState()` picks up such changes, so the corrected value is shown right away instead of in a second frame.
(0, _useEnhancedEffect.default)(() => {
updateState();
return apiRef.current.store.subscribe(updateState);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, EMPTY);
return state;
}
+86
View File
@@ -0,0 +1,86 @@
'use client';
import * as React from 'react';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
import { warnOnce } from '@mui/x-internals/warning';
import { useLazyRef } from "./useLazyRef.mjs";
const defaultCompare = Object.is;
export const objectShallowCompare = fastObjectShallowCompare;
const arrayShallowCompare = (a, b) => {
if (a === b) {
return true;
}
return a.length === b.length && a.every((v, i) => v === b[i]);
};
const argsEqual = (prev, curr) => {
let fn = Object.is;
if (curr instanceof Array) {
fn = arrayShallowCompare;
} else if (curr instanceof Object) {
fn = objectShallowCompare;
}
return fn(prev, curr);
};
const createRefs = () => ({
state: null,
equals: null,
selector: null,
args: undefined,
storeState: null
});
const EMPTY = [];
export function useGridSelector(apiRef, selector, args = undefined, equals = defaultCompare) {
if (process.env.NODE_ENV !== 'production' && !apiRef.current.state) {
warnOnce(['MUI X: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
}
const refs = useLazyRef(createRefs);
const didInit = refs.current.selector !== null;
const [state, setState] = React.useState(
// We don't use an initialization function to avoid allocations
didInit ? null : selector(apiRef, args));
refs.current.state = state;
if (!didInit) {
refs.current.storeState = apiRef.current.store.state;
}
refs.current.equals = equals;
refs.current.selector = selector;
const prevArgs = refs.current.args;
refs.current.args = args;
if (didInit && !argsEqual(prevArgs, args)) {
const newState = refs.current.selector(apiRef, refs.current.args);
if (!refs.current.equals(refs.current.state, newState)) {
refs.current.state = newState;
setState(newState);
}
refs.current.storeState = apiRef.current.store.state;
}
const updateState = React.useCallback(() => {
const storeState = apiRef.current.store.state;
if (refs.current.storeState !== storeState) {
const newState = refs.current.selector(apiRef, refs.current.args);
refs.current.storeState = storeState;
if (!refs.current.equals(refs.current.state, newState)) {
refs.current.state = newState;
setState(newState);
}
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo
EMPTY);
// Why subscribe in an effect instead of during render: a component can render without
// ever mounting (e.g. when it suspends during hydration). If it subscribed during render,
// it could receive a store update and call `setState` before being mounted (#17077).
// Effects only run for mounted components, so subscribing here is safe.
//
// Using a layout effect because the store may already have changed
// between render and mount (e.g. from a child's ref callback or layout effect).
// `updateState()` picks up such changes, so the corrected value is shown right away instead of in a second frame.
useEnhancedEffect(() => {
updateState();
return apiRef.current.store.subscribe(updateState);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, EMPTY);
return state;
}
@@ -0,0 +1,26 @@
import type { RefObject } from '@mui/x-internals/types';
import type { DataGridProcessedProps } from "../../models/props/DataGridProps.mjs";
import type { GridApiCommon } from "../../models/index.mjs";
export declare const getVisibleRows: <Api extends GridApiCommon>(apiRef: RefObject<Api>, props?: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => {
rows: import("@mui/x-data-grid").GridRowEntry<import("@mui/x-data-grid").GridValidRowModel>[];
range: {
firstRowIndex: number;
lastRowIndex: number;
} | null;
rowIdToIndexMap: Map<import("@mui/x-data-grid").GridRowId, number>;
};
/**
* 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 declare const useGridVisibleRows: <Api extends GridApiCommon>(apiRef: RefObject<Api>, props?: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => {
rows: import("@mui/x-data-grid").GridRowEntry<import("@mui/x-data-grid").GridValidRowModel>[];
range: {
firstRowIndex: number;
lastRowIndex: number;
} | null;
rowIdToIndexMap: Map<import("@mui/x-data-grid").GridRowId, number>;
};
@@ -0,0 +1,26 @@
import type { RefObject } from '@mui/x-internals/types';
import type { DataGridProcessedProps } from "../../models/props/DataGridProps.js";
import type { GridApiCommon } from "../../models/index.js";
export declare const getVisibleRows: <Api extends GridApiCommon>(apiRef: RefObject<Api>, props?: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => {
rows: import("@mui/x-data-grid").GridRowEntry<import("@mui/x-data-grid").GridValidRowModel>[];
range: {
firstRowIndex: number;
lastRowIndex: number;
} | null;
rowIdToIndexMap: Map<import("@mui/x-data-grid").GridRowId, number>;
};
/**
* 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 declare const useGridVisibleRows: <Api extends GridApiCommon>(apiRef: RefObject<Api>, props?: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => {
rows: import("@mui/x-data-grid").GridRowEntry<import("@mui/x-data-grid").GridValidRowModel>[];
range: {
firstRowIndex: number;
lastRowIndex: number;
} | null;
rowIdToIndexMap: Map<import("@mui/x-data-grid").GridRowId, number>;
};
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridVisibleRows = exports.getVisibleRows = void 0;
var _gridPaginationSelector = require("../features/pagination/gridPaginationSelector");
var _ = require(".");
const getVisibleRows = (apiRef, props) => {
return (0, _gridPaginationSelector.gridVisibleRowsSelector)(apiRef);
};
/**
* 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.
*/
exports.getVisibleRows = getVisibleRows;
const useGridVisibleRows = (apiRef, props) => {
return (0, _.useGridSelector)(apiRef, _gridPaginationSelector.gridVisibleRowsSelector);
};
exports.useGridVisibleRows = useGridVisibleRows;
@@ -0,0 +1,17 @@
import { gridVisibleRowsSelector } from "../features/pagination/gridPaginationSelector.mjs";
import { useGridSelector } from "./index.mjs";
export const getVisibleRows = (apiRef, props) => {
return gridVisibleRowsSelector(apiRef);
};
/**
* 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 const useGridVisibleRows = (apiRef, props) => {
return useGridSelector(apiRef, gridVisibleRowsSelector);
};
+1
View File
@@ -0,0 +1 @@
export declare const useIsSSR: () => boolean;
+1
View File
@@ -0,0 +1 @@
export declare const useIsSSR: () => boolean;
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useIsSSR = void 0;
var _shim = require("use-sync-external-store/shim");
const emptySubscribe = () => () => {};
const clientSnapshot = () => false;
const serverSnapshot = () => true;
const useIsSSR = () => (0, _shim.useSyncExternalStore)(emptySubscribe, clientSnapshot, serverSnapshot);
exports.useIsSSR = useIsSSR;
+5
View File
@@ -0,0 +1,5 @@
import { useSyncExternalStore } from 'use-sync-external-store/shim';
const emptySubscribe = () => () => {};
const clientSnapshot = () => false;
const serverSnapshot = () => true;
export const useIsSSR = () => useSyncExternalStore(emptySubscribe, clientSnapshot, serverSnapshot);
+1
View File
@@ -0,0 +1 @@
export { default as useLazyRef } from '@mui/utils/useLazyRef';
+1
View File
@@ -0,0 +1 @@
export { default as useLazyRef } from '@mui/utils/useLazyRef';
+13
View File
@@ -0,0 +1,13 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useLazyRef", {
enumerable: true,
get: function () {
return _useLazyRef.default;
}
});
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
+1
View File
@@ -0,0 +1 @@
export { default as useLazyRef } from '@mui/utils/useLazyRef';
+1
View File
@@ -0,0 +1 @@
export { default as useOnMount } from '@mui/utils/useOnMount';
+1
View File
@@ -0,0 +1 @@
export { default as useOnMount } from '@mui/utils/useOnMount';
+13
View File
@@ -0,0 +1,13 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useOnMount", {
enumerable: true,
get: function () {
return _useOnMount.default;
}
});
var _useOnMount = _interopRequireDefault(require("@mui/utils/useOnMount"));
+1
View File
@@ -0,0 +1 @@
export { default as useOnMount } from '@mui/utils/useOnMount';
@@ -0,0 +1,3 @@
import { PinnedColumnPosition } from "../../internals/constants.mjs";
import type { useGridPrivateApiContext } from "./useGridPrivateApiContext.mjs";
export declare function usePinnedScrollOffset(apiRef: ReturnType<typeof useGridPrivateApiContext>, pinnedPosition?: PinnedColumnPosition): number;
@@ -0,0 +1,3 @@
import { PinnedColumnPosition } from "../../internals/constants.js";
import type { useGridPrivateApiContext } from "./useGridPrivateApiContext.js";
export declare function usePinnedScrollOffset(apiRef: ReturnType<typeof useGridPrivateApiContext>, pinnedPosition?: PinnedColumnPosition): number;
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.usePinnedScrollOffset = usePinnedScrollOffset;
var _xVirtualizer = require("@mui/x-virtualizer");
var _constants = require("../../internals/constants");
function usePinnedScrollOffset(apiRef, pinnedPosition) {
const store = apiRef.current.virtualizer.store;
// SAFETY: For performance reasons, we only add store selectors for pinned cells in controlled
// mode. Both pinnedPosition and layoutMode are stable (never change for a given instance),
// so the hook call order is consistent across renders.
if (pinnedPosition !== undefined) {
const layoutMode = store.use(_xVirtualizer.Virtualization.selectors.layoutMode);
if (layoutMode === 'controlled') {
if (pinnedPosition === _constants.PinnedColumnPosition.LEFT) {
return store.use(_xVirtualizer.Virtualization.selectors.pinnedLeftOffsetSelector);
}
if (pinnedPosition === _constants.PinnedColumnPosition.RIGHT) {
return store.use(_xVirtualizer.Virtualization.selectors.pinnedRightOffsetSelector);
}
}
}
return 0;
}
@@ -0,0 +1,21 @@
import { Virtualization } from '@mui/x-virtualizer';
import { PinnedColumnPosition } from "../../internals/constants.mjs";
export function usePinnedScrollOffset(apiRef, pinnedPosition) {
const store = apiRef.current.virtualizer.store;
// SAFETY: For performance reasons, we only add store selectors for pinned cells in controlled
// mode. Both pinnedPosition and layoutMode are stable (never change for a given instance),
// so the hook call order is consistent across renders.
if (pinnedPosition !== undefined) {
const layoutMode = store.use(Virtualization.selectors.layoutMode);
if (layoutMode === 'controlled') {
if (pinnedPosition === PinnedColumnPosition.LEFT) {
return store.use(Virtualization.selectors.pinnedLeftOffsetSelector);
}
if (pinnedPosition === PinnedColumnPosition.RIGHT) {
return store.use(Virtualization.selectors.pinnedRightOffsetSelector);
}
}
}
return 0;
}
@@ -0,0 +1,4 @@
export declare function useRunOncePerLoop<T extends (...args: any[]) => void>(callback: T): {
schedule: (...args: Parameters<T>) => void;
cancel: () => boolean;
};
@@ -0,0 +1,4 @@
export declare function useRunOncePerLoop<T extends (...args: any[]) => void>(callback: T): {
schedule: (...args: Parameters<T>) => void;
cancel: () => boolean;
};
+42
View File
@@ -0,0 +1,42 @@
"use strict";
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useRunOncePerLoop = useRunOncePerLoop;
var React = _interopRequireWildcard(require("react"));
function useRunOncePerLoop(callback) {
const scheduledCallbackRef = React.useRef(null);
const schedule = React.useCallback((...args) => {
// for robustness, a fallback in case we don't react to state updates and layoutEffect is not run
// if we react to state updates, layoutEffect will run before microtasks
if (!scheduledCallbackRef.current) {
queueMicrotask(() => {
if (scheduledCallbackRef.current) {
scheduledCallbackRef.current();
}
});
}
scheduledCallbackRef.current = () => {
scheduledCallbackRef.current = null;
callback(...args);
};
}, [callback]);
React.useLayoutEffect(() => {
if (scheduledCallbackRef.current) {
scheduledCallbackRef.current();
}
});
return {
schedule,
cancel: () => {
if (scheduledCallbackRef.current) {
scheduledCallbackRef.current = null;
return true;
}
return false;
}
};
}
@@ -0,0 +1,36 @@
'use client';
import * as React from 'react';
export function useRunOncePerLoop(callback) {
const scheduledCallbackRef = React.useRef(null);
const schedule = React.useCallback((...args) => {
// for robustness, a fallback in case we don't react to state updates and layoutEffect is not run
// if we react to state updates, layoutEffect will run before microtasks
if (!scheduledCallbackRef.current) {
queueMicrotask(() => {
if (scheduledCallbackRef.current) {
scheduledCallbackRef.current();
}
});
}
scheduledCallbackRef.current = () => {
scheduledCallbackRef.current = null;
callback(...args);
};
}, [callback]);
React.useLayoutEffect(() => {
if (scheduledCallbackRef.current) {
scheduledCallbackRef.current();
}
});
return {
schedule,
cancel: () => {
if (scheduledCallbackRef.current) {
scheduledCallbackRef.current = null;
return true;
}
return false;
}
};
}
+1
View File
@@ -0,0 +1 @@
export { default as useTimeout } from '@mui/utils/useTimeout';
+1
View File
@@ -0,0 +1 @@
export { default as useTimeout } from '@mui/utils/useTimeout';
+13
View File
@@ -0,0 +1,13 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useTimeout", {
enumerable: true,
get: function () {
return _useTimeout.default;
}
});
var _useTimeout = _interopRequireDefault(require("@mui/utils/useTimeout"));
+1
View File
@@ -0,0 +1 @@
export { default as useTimeout } from '@mui/utils/useTimeout';