@mui/x-data-grid-pro
Version:
The Pro plan edition of the MUI X Data Grid components.
41 lines (40 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GridMultiSelectCache = void 0;
var _fastArrayCompare = require("@mui/x-internals/fastArrayCompare");
/**
* Holds the grid-level `+N` overflow chip metrics. Written by the single `GridMultiSelectMeasurer`
* and read by every multiSelect chip cell via `useSyncExternalStore`.
*/
class GridMultiSelectCache {
overflowMetrics = null;
metricsSubscribers = new Set();
notifyMetrics = metrics => {
this.metricsSubscribers.forEach(cb => cb(metrics));
};
getOverflowMetrics = () => {
return this.overflowMetrics;
};
setOverflowMetrics = next => {
// Skip no-op updates so subscribed cells don't re-render on every measurer ResizeObserver tick.
const prev = this.overflowMetrics;
if (prev && prev.gap === next.gap && (0, _fastArrayCompare.fastArrayCompare)(prev.overflowChipWidths, next.overflowChipWidths)) {
return;
}
this.overflowMetrics = next;
this.notifyMetrics(next);
};
subscribeOverflowMetrics = callback => {
this.metricsSubscribers.add(callback);
return () => {
this.metricsSubscribers.delete(callback);
};
};
teardown = () => {
this.metricsSubscribers.clear();
this.overflowMetrics = null;
};
}
exports.GridMultiSelectCache = GridMultiSelectCache;