UNPKG

qwc2-lts

Version:
67 lines (66 loc) 4.27 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Copyright 2017-2024 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import { SET_EDIT_CONTEXT, CLEAR_EDIT_CONTEXT } from '../actions/editing'; var defaultState = { contexts: {}, currentContext: null }; var _nonZeroZCoordinate = function nonZeroZCoordinate(coordinates) { return coordinates.find(function (entry) { return Array.isArray(entry[0]) ? _nonZeroZCoordinate(entry) : entry.length >= 3 && entry[2] !== 0; }); }; var checkGeomReadOnly = function checkGeomReadOnly(oldState, newFeature, fallback) { var _oldState$feature, _ref; // Only recompute if feature id in state changes if (!newFeature) { return false; } else if (newFeature.id !== (oldState === null || oldState === void 0 || (_oldState$feature = oldState.feature) === null || _oldState$feature === void 0 ? void 0 : _oldState$feature.id)) { var _newFeature$geometry; return _nonZeroZCoordinate([((_newFeature$geometry = newFeature.geometry) === null || _newFeature$geometry === void 0 ? void 0 : _newFeature$geometry.coordinates) || []]) !== undefined; } return (_ref = fallback !== null && fallback !== void 0 ? fallback : oldState === null || oldState === void 0 ? void 0 : oldState.geomReadOnly) !== null && _ref !== void 0 ? _ref : false; }; export default function editing() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case SET_EDIT_CONTEXT: { return { contexts: _objectSpread(_objectSpread({}, state.contexts), {}, _defineProperty({}, action.contextId, _objectSpread(_objectSpread(_objectSpread({ action: null, feature: null, geomType: null, changed: false }, state.contexts[action.contextId]), action.editContext), {}, { geomReadOnly: action.editContext.geomReadOnly || checkGeomReadOnly(state.contexts[action.contextId], action.editContext.feature, action.editContext.geomReadOnly), id: action.contextId }))), currentContext: action.contextId }; } case CLEAR_EDIT_CONTEXT: { var newState = { contexts: _objectSpread({}, state.contexts), currentContext: state.currentContext === action.contextId ? action.newActiveContextId : state.currentContext }; delete newState.contexts[action.contextId]; return newState; } default: return state; } }