qwc2
Version:
QGIS Web Client
209 lines (208 loc) • 11.2 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 _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, 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 2016-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 React from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'react-redux';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { setCurrentTask } from '../actions/task';
import Icon from './Icon';
import { MapContainerPortalContext } from './PluginsContainer';
import { Swipeable } from './Swipeable';
import './style/SideBar.css';
var SideBar = /*#__PURE__*/function (_React$Component) {
function SideBar(props) {
var _this;
_classCallCheck(this, SideBar);
_this = _callSuper(this, SideBar, [props]);
_defineProperty(_this, "state", {
render: false
});
_defineProperty(_this, "closeClicked", function () {
if (_this.props.currentTask.id === _this.props.id) {
_this.props.setCurrentTask(null);
}
});
_defineProperty(_this, "renderRole", function (role) {
var children = typeof _this.props.children === "function" ? _this.props.children() : React.Children.toArray(_this.props.children).reduce(function (res, child) {
return _objectSpread(_objectSpread({}, res), {}, _defineProperty({}, child.props.role, child));
}, {});
return children[role];
});
_defineProperty(_this, "setRef", function (el) {
_this.sidebar = el;
});
_defineProperty(_this, "startSidebarResize", function (ev) {
var startWidth = _this.sidebar.offsetWidth;
var startMouseX = ev.clientX;
var sign = _this.props.side === 'left' ? -1 : 1;
var resizeSidebar = function resizeSidebar(event) {
_this.sidebar.style.width = startWidth + sign * (startMouseX - event.clientX) + 'px';
};
ev.view.document.body.style.userSelect = 'none';
ev.view.addEventListener("pointermove", resizeSidebar);
ev.view.addEventListener("pointerup", function () {
ev.view.document.body.style.userSelect = '';
ev.view.removeEventListener("pointermove", resizeSidebar);
}, {
once: true
});
});
_defineProperty(_this, "startSidebarBottomResize", function (ev) {
var startHeight = _this.sidebar.offsetHeight;
var startMouseY = ev.clientY;
var resizeSidebar = function resizeSidebar(event) {
_this.sidebar.style.height = Math.max(64, startHeight + (event.clientY - startMouseY)) + 'px';
};
ev.view.document.body.style.userSelect = 'none';
ev.view.addEventListener("pointermove", resizeSidebar);
ev.view.addEventListener("pointerup", function () {
ev.view.document.body.style.userSelect = '';
ev.view.removeEventListener("pointermove", resizeSidebar);
}, {
once: true
});
});
_this.state.render = props.currentTask && props.currentTask.id === props.id;
_this.sidebar = null;
return _this;
}
_inherits(SideBar, _React$Component);
return _createClass(SideBar, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
var _this2 = this;
var newVisible = this.props.currentTask && this.props.currentTask.id === this.props.id;
var oldVisible = prevProps.currentTask && prevProps.currentTask.id === prevProps.id;
if (newVisible && (!oldVisible || this.props.currentTask.mode !== prevProps.currentTask.mode)) {
this.setState({
render: true
});
this.props.onShow(this.props.currentTask.mode);
} else if (!newVisible && oldVisible) {
this.props.onHide();
// Hide the element after the transition period (see SideBar.css)
setTimeout(function () {
_this2.setState({
render: false
});
}, 300);
}
if (!this.props.heightResizeable && prevProps.heightResizeable) {
this.sidebar.style.height = '';
}
}
}, {
key: "render",
value: function render() {
var visible = this.props.currentTask.id === this.props.id;
var render = visible || this.state.render;
var style = {
width: this.props.width,
minWidth: this.props.minWidth,
zIndex: visible ? 5 : 4
};
var isLeftSide = this.props.side === "left";
var classes = classnames({
"sidebar": true,
"sidebar-open": visible,
"sidebar-left": isLeftSide,
"sidebar-right": !isLeftSide
});
var closeIcon = isLeftSide ? "chevron-left" : "chevron-right";
var body = null;
var extra = null;
if (render) {
body = this.renderRole("body");
extra = this.renderRole("extra");
}
return /*#__PURE__*/ReactDOM.createPortal(/*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Swipeable, {
delta: 30,
onSwipedRight: this.closeClicked
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(classes, " ").concat(this.props.extraClasses),
id: this.props.id,
ref: this.setRef,
style: style
}, /*#__PURE__*/React.createElement("div", {
className: "sidebar-resize-handle sidebar-resize-handle-" + this.props.side,
onPointerDown: this.startSidebarResize
}), /*#__PURE__*/React.createElement("div", {
className: "sidebar-titlebar"
}, this.state.render ? this.props.extraBeforeContent : null, /*#__PURE__*/React.createElement(Icon, {
className: "sidebar-titlebar-icon",
icon: this.props.icon,
size: "large"
}), /*#__PURE__*/React.createElement("span", {
className: "sidebar-titlebar-title"
}, this.props.title), this.state.render ? this.props.extraTitlebarContent : null, /*#__PURE__*/React.createElement("span", {
className: "sidebar-titlebar-spacer"
}), /*#__PURE__*/React.createElement(Icon, {
className: "sidebar-titlebar-closeicon",
icon: closeIcon,
onClick: this.closeClicked
})), /*#__PURE__*/React.createElement("div", {
className: "sidebar-body"
}, body), this.props.heightResizeable ? /*#__PURE__*/React.createElement("div", {
className: "sidebar-resize-handle-bottom",
onPointerDown: this.startSidebarBottomResize
}) : null)), extra), this.context);
}
}]);
}(React.Component);
_defineProperty(SideBar, "contextType", MapContainerPortalContext);
_defineProperty(SideBar, "propTypes", {
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
currentTask: PropTypes.object,
extraBeforeContent: PropTypes.object,
extraClasses: PropTypes.string,
extraTitlebarContent: PropTypes.object,
heightResizeable: PropTypes.bool,
icon: PropTypes.string,
id: PropTypes.string.isRequired,
minWidth: PropTypes.string,
onHide: PropTypes.func,
onShow: PropTypes.func,
setCurrentTask: PropTypes.func,
side: PropTypes.string,
title: PropTypes.string,
width: PropTypes.string
});
_defineProperty(SideBar, "defaultProps", {
extraClasses: '',
onShow: function onShow() {},
onHide: function onHide() {},
width: '15em',
minWidth: '15em',
// allowed values are 'left' and 'right'
side: 'right'
});
export default connect(function (state) {
return {
currentTask: state.task
};
}, {
setCurrentTask: setCurrentTask
})(SideBar);