| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.touchEventMiddleware = exports.touchEventAction = void 0;
|
|---|
| 7 | var _toolkit = require("@reduxjs/toolkit");
|
|---|
| 8 | var _tooltipSlice = require("./tooltipSlice");
|
|---|
| 9 | var _selectActivePropsFromChartPointer = require("./selectors/selectActivePropsFromChartPointer");
|
|---|
| 10 | var _getChartPointer = require("../util/getChartPointer");
|
|---|
| 11 | var _selectTooltipEventType = require("./selectors/selectTooltipEventType");
|
|---|
| 12 | var _Constants = require("../util/Constants");
|
|---|
| 13 | var _touchSelectors = require("./selectors/touchSelectors");
|
|---|
| 14 | var _tooltipSelectors = require("./selectors/tooltipSelectors");
|
|---|
| 15 | var touchEventAction = exports.touchEventAction = (0, _toolkit.createAction)('touchMove');
|
|---|
| 16 | var touchEventMiddleware = exports.touchEventMiddleware = (0, _toolkit.createListenerMiddleware)();
|
|---|
| 17 | touchEventMiddleware.startListening({
|
|---|
| 18 | actionCreator: touchEventAction,
|
|---|
| 19 | effect: (action, listenerApi) => {
|
|---|
| 20 | var touchEvent = action.payload;
|
|---|
| 21 | if (touchEvent.touches == null || touchEvent.touches.length === 0) {
|
|---|
| 22 | return;
|
|---|
| 23 | }
|
|---|
| 24 | var state = listenerApi.getState();
|
|---|
| 25 | var tooltipEventType = (0, _selectTooltipEventType.selectTooltipEventType)(state, state.tooltip.settings.shared);
|
|---|
| 26 | if (tooltipEventType === 'axis') {
|
|---|
| 27 | var touch = touchEvent.touches[0];
|
|---|
| 28 | if (touch == null) {
|
|---|
| 29 | return;
|
|---|
| 30 | }
|
|---|
| 31 | var activeProps = (0, _selectActivePropsFromChartPointer.selectActivePropsFromChartPointer)(state, (0, _getChartPointer.getChartPointer)({
|
|---|
| 32 | clientX: touch.clientX,
|
|---|
| 33 | clientY: touch.clientY,
|
|---|
| 34 | currentTarget: touchEvent.currentTarget
|
|---|
| 35 | }));
|
|---|
| 36 | if ((activeProps === null || activeProps === void 0 ? void 0 : activeProps.activeIndex) != null) {
|
|---|
| 37 | listenerApi.dispatch((0, _tooltipSlice.setMouseOverAxisIndex)({
|
|---|
| 38 | activeIndex: activeProps.activeIndex,
|
|---|
| 39 | activeDataKey: undefined,
|
|---|
| 40 | activeCoordinate: activeProps.activeCoordinate
|
|---|
| 41 | }));
|
|---|
| 42 | }
|
|---|
| 43 | } else if (tooltipEventType === 'item') {
|
|---|
| 44 | var _target$getAttribute;
|
|---|
| 45 | var _touch = touchEvent.touches[0];
|
|---|
| 46 | if (document.elementFromPoint == null || _touch == null) {
|
|---|
| 47 | return;
|
|---|
| 48 | }
|
|---|
| 49 | var target = document.elementFromPoint(_touch.clientX, _touch.clientY);
|
|---|
| 50 | if (!target || !target.getAttribute) {
|
|---|
| 51 | return;
|
|---|
| 52 | }
|
|---|
| 53 | var itemIndex = target.getAttribute(_Constants.DATA_ITEM_INDEX_ATTRIBUTE_NAME);
|
|---|
| 54 | var graphicalItemId = (_target$getAttribute = target.getAttribute(_Constants.DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME)) !== null && _target$getAttribute !== void 0 ? _target$getAttribute : undefined;
|
|---|
| 55 | var settings = (0, _tooltipSelectors.selectAllGraphicalItemsSettings)(state).find(item => item.id === graphicalItemId);
|
|---|
| 56 | if (itemIndex == null || settings == null || graphicalItemId == null) {
|
|---|
| 57 | return;
|
|---|
| 58 | }
|
|---|
| 59 | var {
|
|---|
| 60 | dataKey
|
|---|
| 61 | } = settings;
|
|---|
| 62 | var coordinate = (0, _touchSelectors.selectTooltipCoordinate)(state, itemIndex, graphicalItemId);
|
|---|
| 63 | listenerApi.dispatch((0, _tooltipSlice.setActiveMouseOverItemIndex)({
|
|---|
| 64 | activeDataKey: dataKey,
|
|---|
| 65 | activeIndex: itemIndex,
|
|---|
| 66 | activeCoordinate: coordinate,
|
|---|
| 67 | activeGraphicalItemId: graphicalItemId
|
|---|
| 68 | }));
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | }); |
|---|