@octanejs/recharts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +53 -0
- package/src/animation/AnimatedItems.tsrx +82 -0
- package/src/animation/AnimationControllerImpl.js +33 -0
- package/src/animation/AnimationHandle.js +291 -0
- package/src/animation/JavascriptAnimate.tsrx +81 -0
- package/src/animation/easing.js +193 -0
- package/src/animation/matchBy.js +279 -0
- package/src/animation/timeoutController.js +49 -0
- package/src/animation/useAnimationController.ts +22 -0
- package/src/animation/useAnimationStartSnapshot.ts +43 -0
- package/src/animation/util.js +11 -0
- package/src/cartesian/Bar.ts +4 -0
- package/src/cartesian/Bar.tsrx +716 -0
- package/src/cartesian/Bar.tsrx.d.ts +4 -0
- package/src/cartesian/BarStack.tsrx +97 -0
- package/src/cartesian/BarStack.tsrx.d.ts +6 -0
- package/src/cartesian/CartesianAxis.tsrx +413 -0
- package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
- package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
- package/src/cartesian/Line.ts +4 -0
- package/src/cartesian/Line.tsrx +544 -0
- package/src/cartesian/Line.tsrx.d.ts +4 -0
- package/src/cartesian/LineDrawShape.tsrx +106 -0
- package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
- package/src/cartesian/XAxis.tsrx +156 -0
- package/src/cartesian/XAxis.tsrx.d.ts +3 -0
- package/src/cartesian/YAxis.tsrx +183 -0
- package/src/cartesian/YAxis.tsrx.d.ts +3 -0
- package/src/cartesian/getCartesianPosition.js +277 -0
- package/src/cartesian/getEquidistantTicks.js +133 -0
- package/src/cartesian/getTicks.js +280 -0
- package/src/cartesian/useAnimatedLineLength.ts +33 -0
- package/src/chart/BarChart.tsrx +22 -0
- package/src/chart/BarChart.tsrx.d.ts +2 -0
- package/src/chart/CartesianChart.tsrx +76 -0
- package/src/chart/CartesianChart.tsrx.d.ts +10 -0
- package/src/chart/CategoricalChart.tsrx +54 -0
- package/src/chart/LineChart.tsrx +22 -0
- package/src/chart/LineChart.tsrx.d.ts +2 -0
- package/src/chart/RechartsWrapper.tsrx +294 -0
- package/src/component/ActivePoints.tsrx +76 -0
- package/src/component/Cell.ts +37 -0
- package/src/component/Dots.tsrx +74 -0
- package/src/component/Label.tsrx +309 -0
- package/src/component/Label.tsrx.d.ts +12 -0
- package/src/component/LabelList.tsrx +83 -0
- package/src/component/LabelList.tsrx.d.ts +8 -0
- package/src/component/ResponsiveContainer.ts +22 -0
- package/src/component/Text.tsrx +281 -0
- package/src/component/Text.tsrx.d.ts +9 -0
- package/src/component/responsiveContainerUtils.js +111 -0
- package/src/container/ClipPathProvider.tsrx +29 -0
- package/src/container/Layer.tsrx +9 -0
- package/src/container/Layer.tsrx.d.ts +6 -0
- package/src/container/RootSurface.tsrx +76 -0
- package/src/container/Surface.tsrx +23 -0
- package/src/container/Surface.tsrx.d.ts +12 -0
- package/src/context/CellsContext.ts +80 -0
- package/src/context/ErrorBarContext.tsrx +53 -0
- package/src/context/PanoramaContext.ts +10 -0
- package/src/context/RegisterGraphicalItemId.tsrx +19 -0
- package/src/context/accessibilityContext.js +10 -0
- package/src/context/chartDataContext.ts +57 -0
- package/src/context/chartLayoutContext.ts +171 -0
- package/src/context/legendPortalContext.ts +5 -0
- package/src/context/tooltipContext.js +55 -0
- package/src/context/tooltipPortalContext.ts +5 -0
- package/src/hooks.js +509 -0
- package/src/index.ts +64 -0
- package/src/internal.ts +37 -0
- package/src/polar/defaultPolarAngleAxisProps.js +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
- package/src/shape/Cross.tsrx +25 -0
- package/src/shape/Cross.tsrx.d.ts +12 -0
- package/src/shape/Curve.tsrx +132 -0
- package/src/shape/Curve.tsrx.d.ts +42 -0
- package/src/shape/Dot.tsrx +21 -0
- package/src/shape/Dot.tsrx.d.ts +9 -0
- package/src/shape/Polygon.tsrx +95 -0
- package/src/shape/Polygon.tsrx.d.ts +13 -0
- package/src/shape/Rectangle.tsrx +162 -0
- package/src/shape/Rectangle.tsrx.d.ts +31 -0
- package/src/shape/Sector.tsrx +219 -0
- package/src/shape/Sector.tsrx.d.ts +29 -0
- package/src/shape/Symbols.tsrx +95 -0
- package/src/shape/Symbols.tsrx.d.ts +15 -0
- package/src/shape/Trapezoid.tsrx +56 -0
- package/src/shape/Trapezoid.tsrx.d.ts +29 -0
- package/src/state/RechartsReduxContext.ts +7 -0
- package/src/state/RechartsStoreProvider.tsrx +24 -0
- package/src/state/ReportChartProps.ts +13 -0
- package/src/state/ReportEventSettings.ts +15 -0
- package/src/state/ReportMainChartProps.ts +22 -0
- package/src/state/SetGraphicalItem.ts +61 -0
- package/src/state/SetLegendPayload.ts +61 -0
- package/src/state/SetTooltipEntrySettings.ts +40 -0
- package/src/state/brushSlice.js +36 -0
- package/src/state/cartesianAxisSlice.js +256 -0
- package/src/state/chartDataSlice.js +67 -0
- package/src/state/errorBarSlice.js +53 -0
- package/src/state/eventSettingsSlice.js +25 -0
- package/src/state/externalEventsMiddleware.js +127 -0
- package/src/state/graphicalItemsSlice.js +91 -0
- package/src/state/hooks.ts +46 -0
- package/src/state/keyboardEventsMiddleware.js +226 -0
- package/src/state/layoutSlice.js +57 -0
- package/src/state/legendSlice.js +83 -0
- package/src/state/mouseEventsMiddleware.js +130 -0
- package/src/state/optionsSlice.js +45 -0
- package/src/state/polarAxisSlice.js +33 -0
- package/src/state/polarOptionsSlice.js +26 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
- package/src/state/referenceElementsSlice.js +51 -0
- package/src/state/renderedTicksSlice.js +41 -0
- package/src/state/rootPropsSlice.js +48 -0
- package/src/state/selectors/arrayEqualityCheck.js +32 -0
- package/src/state/selectors/axisSelectors.js +2113 -0
- package/src/state/selectors/barSelectors.js +263 -0
- package/src/state/selectors/barStackSelectors.js +65 -0
- package/src/state/selectors/brushSelectors.js +21 -0
- package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
- package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
- package/src/state/selectors/combiners/combineBarPosition.js +17 -0
- package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
- package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
- package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
- package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
- package/src/state/selectors/combiners/combineStackedData.js +22 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
- package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
- package/src/state/selectors/containerSelectors.js +6 -0
- package/src/state/selectors/dataSelectors.js +97 -0
- package/src/state/selectors/graphicalItemSelectors.js +25 -0
- package/src/state/selectors/legendSelectors.js +18 -0
- package/src/state/selectors/lineSelectors.js +106 -0
- package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
- package/src/state/selectors/pickAxisId.js +3 -0
- package/src/state/selectors/pickAxisType.js +3 -0
- package/src/state/selectors/polarAxisSelectors.js +237 -0
- package/src/state/selectors/rootPropsSelectors.js +13 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
- package/src/state/selectors/selectAllAxes.js +15 -0
- package/src/state/selectors/selectChartOffset.js +12 -0
- package/src/state/selectors/selectChartOffsetInternal.js +174 -0
- package/src/state/selectors/selectPlotArea.js +19 -0
- package/src/state/selectors/selectTooltipAxisId.js +3 -0
- package/src/state/selectors/selectTooltipAxisType.js +25 -0
- package/src/state/selectors/selectTooltipEventType.js +27 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
- package/src/state/selectors/selectTooltipSettings.js +3 -0
- package/src/state/selectors/selectTooltipState.js +3 -0
- package/src/state/selectors/selectors.js +222 -0
- package/src/state/selectors/tooltipSelectors.js +471 -0
- package/src/state/selectors/touchSelectors.js +31 -0
- package/src/state/store.js +101 -0
- package/src/state/tooltipSlice.js +237 -0
- package/src/state/touchEventsMiddleware.js +140 -0
- package/src/state/types/StackedGraphicalItem.js +18 -0
- package/src/state/zIndexSlice.js +167 -0
- package/src/synchronisation/syncSelectors.js +5 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
- package/src/util/ActiveShapeUtils.tsrx +62 -0
- package/src/util/BarUtils.tsrx +35 -0
- package/src/util/CartesianUtils.js +66 -0
- package/src/util/ChartUtils.js +630 -0
- package/src/util/Constants.js +42 -0
- package/src/util/DOMUtils.js +180 -0
- package/src/util/DataUtils.js +199 -0
- package/src/util/Events.js +7 -0
- package/src/util/Global.js +13 -0
- package/src/util/LRUCache.js +58 -0
- package/src/util/LogUtils.js +29 -0
- package/src/util/PolarUtils.js +190 -0
- package/src/util/ReactUtils.ts +94 -0
- package/src/util/ReduceCSSCalc.js +260 -0
- package/src/util/TickUtils.js +43 -0
- package/src/util/YAxisUtils.js +43 -0
- package/src/util/axisPropsAreEqual.js +63 -0
- package/src/util/createEventProxy.js +18 -0
- package/src/util/excludeEventProps.js +172 -0
- package/src/util/getActiveCoordinate.js +253 -0
- package/src/util/getAxisTypeBasedOnLayout.js +17 -0
- package/src/util/getClassNameFromUnknown.js +8 -0
- package/src/util/getEveryNth.js +29 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
- package/src/util/getRelativeCoordinate.js +96 -0
- package/src/util/getSliced.js +11 -0
- package/src/util/isDomainSpecifiedByUser.js +255 -0
- package/src/util/isWellBehavedNumber.js +8 -0
- package/src/util/propsAreEqual.js +96 -0
- package/src/util/resolveDefaultProps.js +131 -0
- package/src/util/round.js +39 -0
- package/src/util/scale/RechartsScale.js +68 -0
- package/src/util/scale/createCategoricalInverse.js +77 -0
- package/src/util/scale/getNiceTickValues.js +354 -0
- package/src/util/scale/index.js +3 -0
- package/src/util/scale/util/arithmetic.js +51 -0
- package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
- package/src/util/svgPropertiesAndEvents.ts +29 -0
- package/src/util/svgPropertiesNoEvents.js +383 -0
- package/src/util/types.ts +59 -0
- package/src/util/useAnimationId.ts +14 -0
- package/src/util/useId.ts +13 -0
- package/src/util/usePrefersReducedMotion.ts +30 -0
- package/src/util/useReportScale.ts +26 -0
- package/src/util/useUniqueId.js +34 -0
- package/src/zIndex/DefaultZIndexes.js +75 -0
- package/src/zIndex/ZIndexLayer.tsrx +80 -0
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
- package/src/zIndex/ZIndexPortal.tsrx +43 -0
- package/src/zIndex/getZIndexFromUnknown.js +15 -0
- package/src/zIndex/zIndexSelectors.js +45 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/selectors/touchSelectors.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { createSelector } from 'reselect';
|
|
4
|
+
import { selectTooltipState } from './selectTooltipState';
|
|
5
|
+
var selectAllTooltipPayloadConfiguration = createSelector(
|
|
6
|
+
[selectTooltipState],
|
|
7
|
+
(tooltipState) => tooltipState.tooltipItemPayloads,
|
|
8
|
+
);
|
|
9
|
+
export var selectTooltipCoordinate = createSelector(
|
|
10
|
+
[
|
|
11
|
+
selectAllTooltipPayloadConfiguration,
|
|
12
|
+
(_state, tooltipIndex) => tooltipIndex,
|
|
13
|
+
(_state, _tooltipIndex, graphicalItemId) => graphicalItemId,
|
|
14
|
+
],
|
|
15
|
+
(allTooltipConfigurations, tooltipIndex, graphicalItemId) => {
|
|
16
|
+
if (tooltipIndex == null) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
var mostRelevantTooltipConfiguration = allTooltipConfigurations.find((tooltipConfiguration) => {
|
|
20
|
+
return tooltipConfiguration.settings.graphicalItemId === graphicalItemId;
|
|
21
|
+
});
|
|
22
|
+
if (mostRelevantTooltipConfiguration == null) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
var getPosition = mostRelevantTooltipConfiguration.getPosition;
|
|
26
|
+
if (getPosition == null) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return getPosition(tooltipIndex);
|
|
30
|
+
},
|
|
31
|
+
);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/store.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { autoBatchEnhancer, combineReducers, configureStore } from '@reduxjs/toolkit';
|
|
4
|
+
import { optionsReducer } from './optionsSlice';
|
|
5
|
+
import { tooltipReducer } from './tooltipSlice';
|
|
6
|
+
import { chartDataReducer } from './chartDataSlice';
|
|
7
|
+
import { chartLayoutReducer } from './layoutSlice';
|
|
8
|
+
import { mouseClickMiddleware, mouseMoveMiddleware } from './mouseEventsMiddleware';
|
|
9
|
+
import { reduxDevtoolsJsonStringifyReplacer } from './reduxDevtoolsJsonStringifyReplacer';
|
|
10
|
+
import { cartesianAxisReducer } from './cartesianAxisSlice';
|
|
11
|
+
import { graphicalItemsReducer } from './graphicalItemsSlice';
|
|
12
|
+
import { referenceElementsReducer } from './referenceElementsSlice';
|
|
13
|
+
import { brushReducer } from './brushSlice';
|
|
14
|
+
import { legendReducer } from './legendSlice';
|
|
15
|
+
import { rootPropsReducer } from './rootPropsSlice';
|
|
16
|
+
import { polarAxisReducer } from './polarAxisSlice';
|
|
17
|
+
import { polarOptionsReducer } from './polarOptionsSlice';
|
|
18
|
+
import { keyboardEventsMiddleware } from './keyboardEventsMiddleware';
|
|
19
|
+
import { externalEventsMiddleware } from './externalEventsMiddleware';
|
|
20
|
+
import { touchEventMiddleware } from './touchEventsMiddleware';
|
|
21
|
+
import { errorBarReducer } from './errorBarSlice';
|
|
22
|
+
import { Global } from '../util/Global';
|
|
23
|
+
import { zIndexReducer } from './zIndexSlice';
|
|
24
|
+
import { eventSettingsReducer } from './eventSettingsSlice';
|
|
25
|
+
import { renderedTicksReducer } from './renderedTicksSlice';
|
|
26
|
+
var rootReducer = combineReducers({
|
|
27
|
+
brush: brushReducer,
|
|
28
|
+
cartesianAxis: cartesianAxisReducer,
|
|
29
|
+
chartData: chartDataReducer,
|
|
30
|
+
errorBars: errorBarReducer,
|
|
31
|
+
eventSettings: eventSettingsReducer,
|
|
32
|
+
graphicalItems: graphicalItemsReducer,
|
|
33
|
+
layout: chartLayoutReducer,
|
|
34
|
+
legend: legendReducer,
|
|
35
|
+
options: optionsReducer,
|
|
36
|
+
polarAxis: polarAxisReducer,
|
|
37
|
+
polarOptions: polarOptionsReducer,
|
|
38
|
+
referenceElements: referenceElementsReducer,
|
|
39
|
+
renderedTicks: renderedTicksReducer,
|
|
40
|
+
rootProps: rootPropsReducer,
|
|
41
|
+
tooltip: tooltipReducer,
|
|
42
|
+
zIndex: zIndexReducer,
|
|
43
|
+
});
|
|
44
|
+
export var createRechartsStore = function createRechartsStore(preloadedState) {
|
|
45
|
+
var chartName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Chart';
|
|
46
|
+
return configureStore({
|
|
47
|
+
reducer: rootReducer,
|
|
48
|
+
// redux-toolkit v1 types are unhappy with the preloadedState type. Remove the `as any` when bumping to v2
|
|
49
|
+
preloadedState: preloadedState,
|
|
50
|
+
// @ts-expect-error redux-toolkit v1 types are unhappy with the middleware array. Remove this comment when bumping to v2
|
|
51
|
+
middleware: (getDefaultMiddleware) => {
|
|
52
|
+
var _process$env$NODE_ENV;
|
|
53
|
+
return getDefaultMiddleware({
|
|
54
|
+
serializableCheck: false,
|
|
55
|
+
immutableCheck: !['commonjs', 'es6', 'production'].includes(
|
|
56
|
+
(_process$env$NODE_ENV = 'es6') !== null && _process$env$NODE_ENV !== void 0
|
|
57
|
+
? _process$env$NODE_ENV
|
|
58
|
+
: '',
|
|
59
|
+
),
|
|
60
|
+
}).concat([
|
|
61
|
+
mouseClickMiddleware.middleware,
|
|
62
|
+
mouseMoveMiddleware.middleware,
|
|
63
|
+
keyboardEventsMiddleware.middleware,
|
|
64
|
+
externalEventsMiddleware.middleware,
|
|
65
|
+
touchEventMiddleware.middleware,
|
|
66
|
+
]);
|
|
67
|
+
},
|
|
68
|
+
/*
|
|
69
|
+
* I can't find out how to satisfy typescript here.
|
|
70
|
+
* We return `EnhancerArray<[StoreEnhancer<{}, {}>, StoreEnhancer]>` from this function,
|
|
71
|
+
* but the types say we should return `EnhancerArray<StoreEnhancer<{}, {}>`.
|
|
72
|
+
* Looks like it's badly inferred generics, but it won't allow me to provide the correct type manually either.
|
|
73
|
+
* So let's just ignore the error for now.
|
|
74
|
+
*/
|
|
75
|
+
// @ts-expect-error mismatched generics
|
|
76
|
+
enhancers: (getDefaultEnhancers) => {
|
|
77
|
+
var enhancers = getDefaultEnhancers;
|
|
78
|
+
if (typeof getDefaultEnhancers === 'function') {
|
|
79
|
+
/*
|
|
80
|
+
* In RTK v2 this is always a function, but in v1 it is an array.
|
|
81
|
+
* Because we have @types/redux-toolkit v1 as a dependency, typescript is going to flag this as an error.
|
|
82
|
+
* We support both RTK v1 and v2, so we need to do this check.
|
|
83
|
+
* https://redux-toolkit.js.org/usage/migrating-rtk-2#configurestoreenhancers-must-be-a-callback
|
|
84
|
+
*/
|
|
85
|
+
// @ts-expect-error RTK v2 behaviour on RTK v1 types
|
|
86
|
+
enhancers = getDefaultEnhancers();
|
|
87
|
+
}
|
|
88
|
+
return enhancers.concat(
|
|
89
|
+
autoBatchEnhancer({
|
|
90
|
+
type: 'raf',
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
},
|
|
94
|
+
devTools: Global.devToolsEnabled && {
|
|
95
|
+
serialize: {
|
|
96
|
+
replacer: reduxDevtoolsJsonStringifyReplacer,
|
|
97
|
+
},
|
|
98
|
+
name: 'recharts-'.concat(chartName),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/tooltipSlice.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { createSlice, current, prepareAutoBatched } from '@reduxjs/toolkit';
|
|
4
|
+
import { castDraft } from 'immer';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One Tooltip can display multiple TooltipPayloadEntries at a time.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* So what happens is that the tooltip payload is decided based on the available data, and the dataKey.
|
|
12
|
+
* The dataKey can either be defined on the graphical element (like Line, or Bar)
|
|
13
|
+
* or on the tooltip itself.
|
|
14
|
+
*
|
|
15
|
+
* The data can be defined in the chart element, or in the graphical item.
|
|
16
|
+
*
|
|
17
|
+
* So this type is all the settings, other than the data + dataKey complications.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is what Tooltip renders.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* null means no active index
|
|
26
|
+
* string means: whichever index from the chart data it is.
|
|
27
|
+
* Different charts have different requirements on data shapes,
|
|
28
|
+
* and are also responsible for providing a function that will accept this index
|
|
29
|
+
* and return data.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Different items have different data shapes so the state has no opinion on what the data shape should be;
|
|
34
|
+
* the only requirement is that the chart also provides a searcher function
|
|
35
|
+
* that accepts the data, and a key, and returns whatever the payload in Tooltip should be.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* So this informs the "tooltip event type". Tooltip event type can be either "axis" or "item"
|
|
40
|
+
* and it is used for two things:
|
|
41
|
+
* 1. Sets the active area
|
|
42
|
+
* 2. Sets the background and cursor highlights
|
|
43
|
+
*
|
|
44
|
+
* Some charts only allow to have one type of tooltip event type, some allow both.
|
|
45
|
+
* Those charts that allow both will have one default, and the "shared" prop will be used to switch between them.
|
|
46
|
+
* Undefined means "use the chart default".
|
|
47
|
+
*
|
|
48
|
+
* Charts that only allow one tooltip event type, will ignore the shared prop.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A generic state for user interaction with the chart.
|
|
53
|
+
* User interaction can come through multiple channels: mouse events, keyboard events, or hardcoded in props, or synchronised from other charts.
|
|
54
|
+
*
|
|
55
|
+
* Each of the interaction states is represented as TooltipInteractionState,
|
|
56
|
+
* and then the selectors and Tooltip will decide which of the interaction states to use.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export var noInteraction = {
|
|
60
|
+
active: false,
|
|
61
|
+
index: null,
|
|
62
|
+
dataKey: undefined,
|
|
63
|
+
graphicalItemId: undefined,
|
|
64
|
+
coordinate: undefined,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The tooltip interaction state stores:
|
|
69
|
+
*
|
|
70
|
+
* - Which graphical item is user interacting with at the moment,
|
|
71
|
+
* - which axis (or, which part of chart background) is user interacting with at the moment
|
|
72
|
+
* - The data that individual graphical items wish to be displayed in case the tooltip gets activated
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
export var initialState = {
|
|
76
|
+
itemInteraction: {
|
|
77
|
+
click: noInteraction,
|
|
78
|
+
hover: noInteraction,
|
|
79
|
+
},
|
|
80
|
+
axisInteraction: {
|
|
81
|
+
click: noInteraction,
|
|
82
|
+
hover: noInteraction,
|
|
83
|
+
},
|
|
84
|
+
keyboardInteraction: noInteraction,
|
|
85
|
+
syncInteraction: {
|
|
86
|
+
active: false,
|
|
87
|
+
index: null,
|
|
88
|
+
dataKey: undefined,
|
|
89
|
+
label: undefined,
|
|
90
|
+
coordinate: undefined,
|
|
91
|
+
sourceViewBox: undefined,
|
|
92
|
+
graphicalItemId: undefined,
|
|
93
|
+
},
|
|
94
|
+
tooltipItemPayloads: [],
|
|
95
|
+
settings: {
|
|
96
|
+
shared: undefined,
|
|
97
|
+
trigger: 'hover',
|
|
98
|
+
axisId: 0,
|
|
99
|
+
active: false,
|
|
100
|
+
defaultIndex: undefined,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* This is the event we get when user is interacting with a specific graphical item.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Keyboard interaction payload has no graphical item ID,
|
|
110
|
+
* and no dataKey, because keyboard interaction is always
|
|
111
|
+
* with the whole chart, not with a specific graphical item.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
var tooltipSlice = createSlice({
|
|
115
|
+
name: 'tooltip',
|
|
116
|
+
initialState,
|
|
117
|
+
reducers: {
|
|
118
|
+
addTooltipEntrySettings: {
|
|
119
|
+
reducer(state, action) {
|
|
120
|
+
state.tooltipItemPayloads.push(castDraft(action.payload));
|
|
121
|
+
},
|
|
122
|
+
prepare: prepareAutoBatched(),
|
|
123
|
+
},
|
|
124
|
+
replaceTooltipEntrySettings: {
|
|
125
|
+
reducer(state, action) {
|
|
126
|
+
var _action$payload = action.payload,
|
|
127
|
+
prev = _action$payload.prev,
|
|
128
|
+
next = _action$payload.next;
|
|
129
|
+
var index = current(state).tooltipItemPayloads.indexOf(castDraft(prev));
|
|
130
|
+
if (index > -1) {
|
|
131
|
+
state.tooltipItemPayloads[index] = castDraft(next);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
prepare: prepareAutoBatched(),
|
|
135
|
+
},
|
|
136
|
+
removeTooltipEntrySettings: {
|
|
137
|
+
reducer(state, action) {
|
|
138
|
+
var index = current(state).tooltipItemPayloads.indexOf(castDraft(action.payload));
|
|
139
|
+
if (index > -1) {
|
|
140
|
+
state.tooltipItemPayloads.splice(index, 1);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
prepare: prepareAutoBatched(),
|
|
144
|
+
},
|
|
145
|
+
setTooltipSettingsState(state, action) {
|
|
146
|
+
state.settings = action.payload;
|
|
147
|
+
},
|
|
148
|
+
setActiveMouseOverItemIndex(state, action) {
|
|
149
|
+
state.syncInteraction.active = false;
|
|
150
|
+
state.syncInteraction.sourceViewBox = undefined;
|
|
151
|
+
state.keyboardInteraction.active = false;
|
|
152
|
+
state.itemInteraction.hover.active = true;
|
|
153
|
+
state.itemInteraction.hover.index = action.payload.activeIndex;
|
|
154
|
+
state.itemInteraction.hover.dataKey = action.payload.activeDataKey;
|
|
155
|
+
state.itemInteraction.hover.graphicalItemId = action.payload.activeGraphicalItemId;
|
|
156
|
+
state.itemInteraction.hover.coordinate = action.payload.activeCoordinate;
|
|
157
|
+
},
|
|
158
|
+
mouseLeaveChart(state) {
|
|
159
|
+
/*
|
|
160
|
+
* Clear only the active flags. Why?
|
|
161
|
+
* 1. Keep Coordinate to preserve animation - next time the Tooltip appears, we want to render it from
|
|
162
|
+
* the last place where it was when it disappeared.
|
|
163
|
+
* 2. We want to keep all the properties anyway just in case the tooltip has `active=true` prop
|
|
164
|
+
* and continues being visible even after the mouse has left the chart.
|
|
165
|
+
*/
|
|
166
|
+
state.itemInteraction.hover.active = false;
|
|
167
|
+
state.axisInteraction.hover.active = false;
|
|
168
|
+
},
|
|
169
|
+
mouseLeaveItem(state) {
|
|
170
|
+
state.itemInteraction.hover.active = false;
|
|
171
|
+
},
|
|
172
|
+
setActiveClickItemIndex(state, action) {
|
|
173
|
+
state.syncInteraction.active = false;
|
|
174
|
+
state.syncInteraction.sourceViewBox = undefined;
|
|
175
|
+
state.itemInteraction.click.active = true;
|
|
176
|
+
state.keyboardInteraction.active = false;
|
|
177
|
+
state.itemInteraction.click.index = action.payload.activeIndex;
|
|
178
|
+
state.itemInteraction.click.dataKey = action.payload.activeDataKey;
|
|
179
|
+
state.itemInteraction.click.graphicalItemId = action.payload.activeGraphicalItemId;
|
|
180
|
+
state.itemInteraction.click.coordinate = action.payload.activeCoordinate;
|
|
181
|
+
},
|
|
182
|
+
setMouseOverAxisIndex(state, action) {
|
|
183
|
+
state.syncInteraction.active = false;
|
|
184
|
+
state.syncInteraction.sourceViewBox = undefined;
|
|
185
|
+
state.axisInteraction.hover.active = true;
|
|
186
|
+
state.keyboardInteraction.active = false;
|
|
187
|
+
state.axisInteraction.hover.index = action.payload.activeIndex;
|
|
188
|
+
state.axisInteraction.hover.dataKey = action.payload.activeDataKey;
|
|
189
|
+
state.axisInteraction.hover.coordinate = action.payload.activeCoordinate;
|
|
190
|
+
},
|
|
191
|
+
setMouseClickAxisIndex(state, action) {
|
|
192
|
+
state.syncInteraction.active = false;
|
|
193
|
+
state.syncInteraction.sourceViewBox = undefined;
|
|
194
|
+
state.keyboardInteraction.active = false;
|
|
195
|
+
state.axisInteraction.click.active = true;
|
|
196
|
+
state.axisInteraction.click.index = action.payload.activeIndex;
|
|
197
|
+
state.axisInteraction.click.dataKey = action.payload.activeDataKey;
|
|
198
|
+
state.axisInteraction.click.coordinate = action.payload.activeCoordinate;
|
|
199
|
+
},
|
|
200
|
+
setSyncInteraction(state, action) {
|
|
201
|
+
state.syncInteraction = action.payload;
|
|
202
|
+
},
|
|
203
|
+
setKeyboardInteraction(state, action) {
|
|
204
|
+
state.keyboardInteraction.active = action.payload.active;
|
|
205
|
+
state.keyboardInteraction.index = action.payload.activeIndex;
|
|
206
|
+
state.keyboardInteraction.coordinate = action.payload.activeCoordinate;
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
var _tooltipSlice$actions = tooltipSlice.actions,
|
|
211
|
+
addTooltipEntrySettings = _tooltipSlice$actions.addTooltipEntrySettings,
|
|
212
|
+
replaceTooltipEntrySettings = _tooltipSlice$actions.replaceTooltipEntrySettings,
|
|
213
|
+
removeTooltipEntrySettings = _tooltipSlice$actions.removeTooltipEntrySettings,
|
|
214
|
+
setTooltipSettingsState = _tooltipSlice$actions.setTooltipSettingsState,
|
|
215
|
+
setActiveMouseOverItemIndex = _tooltipSlice$actions.setActiveMouseOverItemIndex,
|
|
216
|
+
mouseLeaveItem = _tooltipSlice$actions.mouseLeaveItem,
|
|
217
|
+
mouseLeaveChart = _tooltipSlice$actions.mouseLeaveChart,
|
|
218
|
+
setActiveClickItemIndex = _tooltipSlice$actions.setActiveClickItemIndex,
|
|
219
|
+
setMouseOverAxisIndex = _tooltipSlice$actions.setMouseOverAxisIndex,
|
|
220
|
+
setMouseClickAxisIndex = _tooltipSlice$actions.setMouseClickAxisIndex,
|
|
221
|
+
setSyncInteraction = _tooltipSlice$actions.setSyncInteraction,
|
|
222
|
+
setKeyboardInteraction = _tooltipSlice$actions.setKeyboardInteraction;
|
|
223
|
+
export {
|
|
224
|
+
addTooltipEntrySettings,
|
|
225
|
+
replaceTooltipEntrySettings,
|
|
226
|
+
removeTooltipEntrySettings,
|
|
227
|
+
setTooltipSettingsState,
|
|
228
|
+
setActiveMouseOverItemIndex,
|
|
229
|
+
mouseLeaveItem,
|
|
230
|
+
mouseLeaveChart,
|
|
231
|
+
setActiveClickItemIndex,
|
|
232
|
+
setMouseOverAxisIndex,
|
|
233
|
+
setMouseClickAxisIndex,
|
|
234
|
+
setSyncInteraction,
|
|
235
|
+
setKeyboardInteraction,
|
|
236
|
+
};
|
|
237
|
+
export var tooltipReducer = tooltipSlice.reducer;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/touchEventsMiddleware.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { createAction, createListenerMiddleware } from '@reduxjs/toolkit';
|
|
4
|
+
import { setActiveMouseOverItemIndex, setMouseOverAxisIndex } from './tooltipSlice';
|
|
5
|
+
import { selectActivePropsFromChartPointer } from './selectors/selectActivePropsFromChartPointer';
|
|
6
|
+
import { getRelativeCoordinate } from '../util/getRelativeCoordinate';
|
|
7
|
+
import { selectTooltipEventType } from './selectors/selectTooltipEventType';
|
|
8
|
+
import {
|
|
9
|
+
DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME,
|
|
10
|
+
DATA_ITEM_INDEX_ATTRIBUTE_NAME,
|
|
11
|
+
} from '../util/Constants';
|
|
12
|
+
import { selectTooltipCoordinate } from './selectors/touchSelectors';
|
|
13
|
+
import { selectAllGraphicalItemsSettings } from './selectors/tooltipSelectors';
|
|
14
|
+
import { createEventProxy } from '../util/createEventProxy';
|
|
15
|
+
export var touchEventAction = createAction('touchMove');
|
|
16
|
+
export var touchEventMiddleware = createListenerMiddleware();
|
|
17
|
+
var rafId = null;
|
|
18
|
+
var timeoutId = null;
|
|
19
|
+
var latestChartPointers = null;
|
|
20
|
+
var latestTouchEvent = null;
|
|
21
|
+
touchEventMiddleware.startListening({
|
|
22
|
+
actionCreator: touchEventAction,
|
|
23
|
+
effect: (action, listenerApi) => {
|
|
24
|
+
var touchEvent = action.payload;
|
|
25
|
+
if (touchEvent.touches == null || touchEvent.touches.length === 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
latestTouchEvent = createEventProxy(touchEvent);
|
|
29
|
+
var state = listenerApi.getState();
|
|
30
|
+
var _state$eventSettings = state.eventSettings,
|
|
31
|
+
throttleDelay = _state$eventSettings.throttleDelay,
|
|
32
|
+
throttledEvents = _state$eventSettings.throttledEvents;
|
|
33
|
+
var isThrottled = throttledEvents === 'all' || throttledEvents.includes('touchmove');
|
|
34
|
+
if (rafId !== null) {
|
|
35
|
+
cancelAnimationFrame(rafId);
|
|
36
|
+
rafId = null;
|
|
37
|
+
}
|
|
38
|
+
if (timeoutId !== null && (typeof throttleDelay !== 'number' || !isThrottled)) {
|
|
39
|
+
clearTimeout(timeoutId);
|
|
40
|
+
timeoutId = null;
|
|
41
|
+
}
|
|
42
|
+
latestChartPointers = Array.from(touchEvent.touches).map((touch) =>
|
|
43
|
+
getRelativeCoordinate({
|
|
44
|
+
clientX: touch.clientX,
|
|
45
|
+
clientY: touch.clientY,
|
|
46
|
+
currentTarget: touchEvent.currentTarget,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
var callback = () => {
|
|
50
|
+
if (latestTouchEvent == null) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
var currentState = listenerApi.getState();
|
|
54
|
+
var tooltipEventType = selectTooltipEventType(
|
|
55
|
+
currentState,
|
|
56
|
+
currentState.tooltip.settings.shared,
|
|
57
|
+
);
|
|
58
|
+
if (tooltipEventType === 'axis') {
|
|
59
|
+
var _latestChartPointers;
|
|
60
|
+
var latestTouchPointer =
|
|
61
|
+
(_latestChartPointers = latestChartPointers) === null || _latestChartPointers === void 0
|
|
62
|
+
? void 0
|
|
63
|
+
: _latestChartPointers[0];
|
|
64
|
+
if (latestTouchPointer == null) {
|
|
65
|
+
rafId = null;
|
|
66
|
+
timeoutId = null;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var activeProps = selectActivePropsFromChartPointer(currentState, latestTouchPointer);
|
|
70
|
+
if (
|
|
71
|
+
(activeProps === null || activeProps === void 0 ? void 0 : activeProps.activeIndex) !=
|
|
72
|
+
null
|
|
73
|
+
) {
|
|
74
|
+
listenerApi.dispatch(
|
|
75
|
+
setMouseOverAxisIndex({
|
|
76
|
+
activeIndex: activeProps.activeIndex,
|
|
77
|
+
activeDataKey: undefined,
|
|
78
|
+
activeCoordinate: activeProps.activeCoordinate,
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
} else if (tooltipEventType === 'item') {
|
|
83
|
+
var _target$getAttribute;
|
|
84
|
+
var touch = latestTouchEvent.touches[0];
|
|
85
|
+
if (document.elementFromPoint == null || touch == null) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
var target = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
89
|
+
if (!target || !target.getAttribute) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var itemIndex = target.getAttribute(DATA_ITEM_INDEX_ATTRIBUTE_NAME);
|
|
93
|
+
var graphicalItemId =
|
|
94
|
+
(_target$getAttribute = target.getAttribute(
|
|
95
|
+
DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME,
|
|
96
|
+
)) !== null && _target$getAttribute !== void 0
|
|
97
|
+
? _target$getAttribute
|
|
98
|
+
: undefined;
|
|
99
|
+
var settings = selectAllGraphicalItemsSettings(currentState).find(
|
|
100
|
+
(item) => item.id === graphicalItemId,
|
|
101
|
+
);
|
|
102
|
+
if (itemIndex == null || settings == null || graphicalItemId == null) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
var dataKey = settings.dataKey;
|
|
106
|
+
var coordinate = selectTooltipCoordinate(currentState, itemIndex, graphicalItemId);
|
|
107
|
+
listenerApi.dispatch(
|
|
108
|
+
setActiveMouseOverItemIndex({
|
|
109
|
+
activeDataKey: dataKey,
|
|
110
|
+
activeIndex: itemIndex,
|
|
111
|
+
activeCoordinate: coordinate,
|
|
112
|
+
activeGraphicalItemId: graphicalItemId,
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
rafId = null;
|
|
117
|
+
timeoutId = null;
|
|
118
|
+
};
|
|
119
|
+
if (!isThrottled) {
|
|
120
|
+
callback();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (throttleDelay === 'raf') {
|
|
124
|
+
rafId = requestAnimationFrame(callback);
|
|
125
|
+
} else if (typeof throttleDelay === 'number') {
|
|
126
|
+
if (timeoutId === null) {
|
|
127
|
+
callback();
|
|
128
|
+
latestTouchEvent = null;
|
|
129
|
+
timeoutId = setTimeout(() => {
|
|
130
|
+
if (latestTouchEvent) {
|
|
131
|
+
callback();
|
|
132
|
+
} else {
|
|
133
|
+
timeoutId = null;
|
|
134
|
+
rafId = null;
|
|
135
|
+
}
|
|
136
|
+
}, throttleDelay);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/types/StackedGraphicalItem.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
/**
|
|
4
|
+
* Some graphical items allow data stacking. The stacks are optional,
|
|
5
|
+
* so all props here are optional too.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Some graphical items allow data stacking.
|
|
10
|
+
* This interface is used to represent the items that are stacked
|
|
11
|
+
* because the user has provided the stackId and dataKey properties.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export function isStacked(graphicalItem) {
|
|
15
|
+
return (
|
|
16
|
+
'stackId' in graphicalItem && graphicalItem.stackId != null && graphicalItem.dataKey != null
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/state/zIndexSlice.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
function ownKeys(e, r) {
|
|
4
|
+
var t = Object.keys(e);
|
|
5
|
+
if (Object.getOwnPropertySymbols) {
|
|
6
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
7
|
+
(r &&
|
|
8
|
+
(o = o.filter(function (r) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
10
|
+
})),
|
|
11
|
+
t.push.apply(t, o));
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
15
|
+
function _objectSpread(e) {
|
|
16
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
17
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
18
|
+
r % 2
|
|
19
|
+
? ownKeys(Object(t), !0).forEach(function (r) {
|
|
20
|
+
_defineProperty(e, r, t[r]);
|
|
21
|
+
})
|
|
22
|
+
: Object.getOwnPropertyDescriptors
|
|
23
|
+
? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))
|
|
24
|
+
: ownKeys(Object(t)).forEach(function (r) {
|
|
25
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
function _defineProperty(e, r, t) {
|
|
31
|
+
return (
|
|
32
|
+
(r = _toPropertyKey(r)) in e
|
|
33
|
+
? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 })
|
|
34
|
+
: (e[r] = t),
|
|
35
|
+
e
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
function _toPropertyKey(t) {
|
|
39
|
+
var i = _toPrimitive(t, 'string');
|
|
40
|
+
return 'symbol' == typeof i ? i : i + '';
|
|
41
|
+
}
|
|
42
|
+
function _toPrimitive(t, r) {
|
|
43
|
+
if ('object' != typeof t || !t) return t;
|
|
44
|
+
var e = t[Symbol.toPrimitive];
|
|
45
|
+
if (void 0 !== e) {
|
|
46
|
+
var i = e.call(t, r || 'default');
|
|
47
|
+
if ('object' != typeof i) return i;
|
|
48
|
+
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
49
|
+
}
|
|
50
|
+
return ('string' === r ? String : Number)(t);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* This slice contains a registry of z-index values for various components.
|
|
54
|
+
* The state is a map from z-index numbers to element references.
|
|
55
|
+
*/
|
|
56
|
+
import { createSlice, prepareAutoBatched } from '@reduxjs/toolkit';
|
|
57
|
+
import { castDraft } from 'immer';
|
|
58
|
+
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
59
|
+
var seed = {};
|
|
60
|
+
var initialState = {
|
|
61
|
+
zIndexMap: Object.values(DefaultZIndexes).reduce(
|
|
62
|
+
(acc, current) =>
|
|
63
|
+
_objectSpread(
|
|
64
|
+
_objectSpread({}, acc),
|
|
65
|
+
{},
|
|
66
|
+
{
|
|
67
|
+
[current]: {
|
|
68
|
+
element: undefined,
|
|
69
|
+
panoramaElement: undefined,
|
|
70
|
+
consumers: 0,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
),
|
|
74
|
+
seed,
|
|
75
|
+
),
|
|
76
|
+
};
|
|
77
|
+
var defaultZIndexSet = new Set(Object.values(DefaultZIndexes));
|
|
78
|
+
function isDefaultZIndex(zIndex) {
|
|
79
|
+
return defaultZIndexSet.has(zIndex);
|
|
80
|
+
}
|
|
81
|
+
var zIndexSlice = createSlice({
|
|
82
|
+
name: 'zIndex',
|
|
83
|
+
initialState,
|
|
84
|
+
reducers: {
|
|
85
|
+
registerZIndexPortal: {
|
|
86
|
+
reducer: (state, action) => {
|
|
87
|
+
var zIndex = action.payload.zIndex;
|
|
88
|
+
if (state.zIndexMap[zIndex]) {
|
|
89
|
+
state.zIndexMap[zIndex].consumers += 1;
|
|
90
|
+
} else {
|
|
91
|
+
state.zIndexMap[zIndex] = {
|
|
92
|
+
consumers: 1,
|
|
93
|
+
element: undefined,
|
|
94
|
+
panoramaElement: undefined,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
prepare: prepareAutoBatched(),
|
|
99
|
+
},
|
|
100
|
+
unregisterZIndexPortal: {
|
|
101
|
+
reducer: (state, action) => {
|
|
102
|
+
var zIndex = action.payload.zIndex;
|
|
103
|
+
if (state.zIndexMap[zIndex]) {
|
|
104
|
+
state.zIndexMap[zIndex].consumers -= 1;
|
|
105
|
+
/*
|
|
106
|
+
* Garbage collect unused z-index entries, except for default z-indexes.
|
|
107
|
+
* Default z-indexes are always rendered, regardless of whether there are consumers or not.
|
|
108
|
+
* And because of that, even if we delete this entry, the ZIndexPortal provider will still be rendered
|
|
109
|
+
* and React is not going to re-create it, and it won't re-register the element ID.
|
|
110
|
+
* So let's not delete default z-index entries.
|
|
111
|
+
*/
|
|
112
|
+
if (state.zIndexMap[zIndex].consumers <= 0 && !isDefaultZIndex(zIndex)) {
|
|
113
|
+
delete state.zIndexMap[zIndex];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
prepare: prepareAutoBatched(),
|
|
118
|
+
},
|
|
119
|
+
registerZIndexPortalElement: {
|
|
120
|
+
reducer: (state, action) => {
|
|
121
|
+
var _action$payload = action.payload,
|
|
122
|
+
zIndex = _action$payload.zIndex,
|
|
123
|
+
element = _action$payload.element,
|
|
124
|
+
isPanorama = _action$payload.isPanorama;
|
|
125
|
+
if (state.zIndexMap[zIndex]) {
|
|
126
|
+
if (isPanorama) {
|
|
127
|
+
state.zIndexMap[zIndex].panoramaElement = castDraft(element);
|
|
128
|
+
} else {
|
|
129
|
+
state.zIndexMap[zIndex].element = castDraft(element);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
state.zIndexMap[zIndex] = {
|
|
133
|
+
consumers: 0,
|
|
134
|
+
element: isPanorama ? undefined : castDraft(element),
|
|
135
|
+
panoramaElement: isPanorama ? castDraft(element) : undefined,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
prepare: prepareAutoBatched(),
|
|
140
|
+
},
|
|
141
|
+
unregisterZIndexPortalElement: {
|
|
142
|
+
reducer: (state, action) => {
|
|
143
|
+
var zIndex = action.payload.zIndex;
|
|
144
|
+
if (state.zIndexMap[zIndex]) {
|
|
145
|
+
if (action.payload.isPanorama) {
|
|
146
|
+
state.zIndexMap[zIndex].panoramaElement = undefined;
|
|
147
|
+
} else {
|
|
148
|
+
state.zIndexMap[zIndex].element = undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
prepare: prepareAutoBatched(),
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
var _zIndexSlice$actions = zIndexSlice.actions,
|
|
157
|
+
registerZIndexPortal = _zIndexSlice$actions.registerZIndexPortal,
|
|
158
|
+
unregisterZIndexPortal = _zIndexSlice$actions.unregisterZIndexPortal,
|
|
159
|
+
registerZIndexPortalElement = _zIndexSlice$actions.registerZIndexPortalElement,
|
|
160
|
+
unregisterZIndexPortalElement = _zIndexSlice$actions.unregisterZIndexPortalElement;
|
|
161
|
+
export {
|
|
162
|
+
registerZIndexPortal,
|
|
163
|
+
unregisterZIndexPortal,
|
|
164
|
+
registerZIndexPortalElement,
|
|
165
|
+
unregisterZIndexPortalElement,
|
|
166
|
+
};
|
|
167
|
+
export var zIndexReducer = zIndexSlice.reducer;
|