qwc2
Version:
QGIS Web Client
8 lines • 3.99 kB
JavaScript
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 checkNonZeroZ=function checkNonZeroZ(oldState,newState,fallback){var _oldState$feature;// Only recompute if feature id in state changes
if(!newState.feature){return false}else if(newState.feature.id!==(oldState===null||oldState===void 0||(_oldState$feature=oldState.feature)===null||_oldState$feature===void 0?void 0:_oldState$feature.id)){var _newState$feature$geo;return _nonZeroZCoordinate([((_newState$feature$geo=newState.feature.geometry)===null||_newState$feature$geo===void 0?void 0:_newState$feature$geo.coordinates)||[]])!==undefined}return(oldState===null||oldState===void 0?void 0:oldState.geomNonZeroZ)||false};var checkGeomReadOnly=function checkGeomReadOnly(geomType){return(geomType!==null&&geomType!==void 0?geomType:null)!==null&&!["Point","LineString","Polygon"].includes((geomType||"").replace(/^Multi/,"").replace(/Z$/,""))};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:{var _action$editContext$g,_state$contexts$actio;return{contexts:_objectSpread(_objectSpread({},state.contexts),{},_defineProperty({},action.contextId,_objectSpread(_objectSpread(_objectSpread({action:null,feature:null,geomType:null,changed:false,permissions:{}},state.contexts[action.contextId]),action.editContext),{},{geomNonZeroZ:checkNonZeroZ(state.contexts[action.contextId],action.editContext),geomReadOnly:checkGeomReadOnly((_action$editContext$g=action.editContext.geomType)!==null&&_action$editContext$g!==void 0?_action$editContext$g:(_state$contexts$actio=state.contexts[action.contextId])===null||_state$contexts$actio===void 0?void 0:_state$contexts$actio.geomType),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}}