kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
69 lines (67 loc) • 9.25 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _reactRedux = require("react-redux");
var _actions = require("@kepler.gl/actions");
var _constants = require("@kepler.gl/constants");
var _utils = require("@kepler.gl/utils");
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
var useDndEffects = function useDndEffects(effects, effectOrder) {
var dispatch = (0, _reactRedux.useDispatch)();
var _useState = (0, _react.useState)(),
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
activeEffect = _useState2[0],
setActiveEffect = _useState2[1];
var onEffectDragStart = (0, _react.useCallback)(function (event) {
var active = event.active;
var newActiveEffect = effects.find(function (effect) {
return effect.id === active.id;
});
if (newActiveEffect) {
setActiveEffect(newActiveEffect);
if (newActiveEffect.isConfigActive) {
dispatch((0, _actions.updateEffect)(newActiveEffect.id, {
isConfigActive: false
}));
}
}
}, [dispatch, effects]);
var onEffectDragEnd = (0, _react.useCallback)(function (event) {
var _over$data;
var active = event.active,
over = event.over;
var activeEffectId = active.id;
var overType = over === null || over === void 0 || (_over$data = over.data) === null || _over$data === void 0 || (_over$data = _over$data.current) === null || _over$data === void 0 ? void 0 : _over$data.type;
if (!overType) {
setActiveEffect(undefined);
return;
}
switch (overType) {
// swaping effects
case _constants.SORTABLE_EFFECT_TYPE:
dispatch((0, _actions.reorderEffect)((0, _utils.reorderEffectOrder)(effectOrder, activeEffectId, over.id)));
break;
// moving effects within side panel
case _constants.SORTABLE_EFFECT_PANEL_TYPE:
// move effect to the end of the list
dispatch((0, _actions.reorderEffect)((0, _utils.reorderEffectOrder)(effectOrder, activeEffectId, effectOrder[effectOrder.length - 1])));
break;
default:
break;
}
setActiveEffect(undefined);
}, [dispatch, effectOrder]);
return {
activeEffect: activeEffect,
onDragStart: onEffectDragStart,
onDragEnd: onEffectDragEnd
};
};
var _default = exports["default"] = useDndEffects;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfcmVhY3QiLCJyZXF1aXJlIiwiX3JlYWN0UmVkdXgiLCJfYWN0aW9ucyIsIl9jb25zdGFudHMiLCJfdXRpbHMiLCJ1c2VEbmRFZmZlY3RzIiwiZWZmZWN0cyIsImVmZmVjdE9yZGVyIiwiZGlzcGF0Y2giLCJ1c2VEaXNwYXRjaCIsIl91c2VTdGF0ZSIsInVzZVN0YXRlIiwiX3VzZVN0YXRlMiIsIl9zbGljZWRUb0FycmF5MiIsImFjdGl2ZUVmZmVjdCIsInNldEFjdGl2ZUVmZmVjdCIsIm9uRWZmZWN0RHJhZ1N0YXJ0IiwidXNlQ2FsbGJhY2siLCJldmVudCIsImFjdGl2ZSIsIm5ld0FjdGl2ZUVmZmVjdCIsImZpbmQiLCJlZmZlY3QiLCJpZCIsImlzQ29uZmlnQWN0aXZlIiwidXBkYXRlRWZmZWN0Iiwib25FZmZlY3REcmFnRW5kIiwiX292ZXIkZGF0YSIsIm92ZXIiLCJhY3RpdmVFZmZlY3RJZCIsIm92ZXJUeXBlIiwiZGF0YSIsImN1cnJlbnQiLCJ0eXBlIiwidW5kZWZpbmVkIiwiU09SVEFCTEVfRUZGRUNUX1RZUEUiLCJyZW9yZGVyRWZmZWN0IiwicmVvcmRlckVmZmVjdE9yZGVyIiwiU09SVEFCTEVfRUZGRUNUX1BBTkVMX1RZUEUiLCJsZW5ndGgiLCJvbkRyYWdTdGFydCIsIm9uRHJhZ0VuZCIsIl9kZWZhdWx0IiwiZXhwb3J0cyJdLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ob29rcy91c2UtZG5kLWVmZmVjdHMudHN4Il0sInNvdXJjZXNDb250ZW50IjpbIi8vIFNQRFgtTGljZW5zZS1JZGVudGlmaWVyOiBNSV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