terriajs
Version:
Geospatial data visualization platform.
117 lines • 5.87 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import classNames from "classnames";
import { observer } from "mobx-react";
import { Component } from "react";
import { withTranslation } from "react-i18next";
import Box from "../../../../Styled/Box";
import Spacing from "../../../../Styled/Spacing";
import Text from "../../../../Styled/Text";
import { canShorten } from "./BuildShareLink";
import Styles from "./share-panel.scss";
import { SharePanelContent } from "./SharePanelContent";
import { ShareUrl } from "./ShareUrl";
import MenuPanel from "../../../StandardUserInterface/customizable/MenuPanel";
import StorySharePanel from "./StorySharePanel";
let SharePanel = class SharePanel extends Component {
static displayName = "SharePanel";
constructor(props) {
super(props);
this.changeOpenState = this.changeOpenState.bind(this);
this.closePanel = this.closePanel.bind(this);
this.state = {
isOpen: false
};
}
changeOpenState(open) {
this.setState({
isOpen: open
});
if (open) {
if (this.props.catalogShare || this.props.storyShare) {
this.props.viewState.shareModalIsVisible = true;
}
}
}
closePanel() {
this.setState({
isOpen: false
});
}
renderContent() {
const { terria, viewState, t } = this.props;
if (this.props.catalogShare) {
return (_jsxs(Box, { fullWidth: true, column: true, paddedRatio: 3, children: [_jsx(Text, { medium: true, children: t("clipboard.shareURL") }), _jsx(Spacing, { bottom: 1 }), _jsx(ShareUrl, { terria: terria, viewState: viewState, includeStories: true, shouldShorten: shouldShorten(terria) })] }));
}
else if (this.props.storyShare) {
return (_jsxs(Box, { fullWidth: true, column: true, paddedRatio: 3, children: [_jsx(Text, { medium: true, children: t("share.shareStoryLink") }), _jsx(Spacing, { bottom: 1 }), _jsx(ShareUrl, { terria: terria, viewState: viewState, includeStories: true, shouldShorten: shouldShorten(terria) })] }));
}
else {
return (_jsx(SharePanelContent, { terria: terria, viewState: viewState, closePanel: this.closePanel }));
}
}
render() {
const { t } = this.props;
const { catalogShare, storyShare, catalogShareWithoutText, modalWidth } = this.props;
const dropdownTheme = {
btn: classNames({
[Styles.btnCatalogShare]: catalogShare,
[Styles.btnWithoutText]: catalogShareWithoutText
}),
outer: classNames(Styles.sharePanel, {
[Styles.catalogShare]: catalogShare,
[Styles.storyShare]: storyShare
}),
inner: classNames(Styles.dropdownInner, {
[Styles.storyShareInner]: storyShare
}),
icon: "share"
};
const btnText = catalogShare
? t("share.btnCatalogShareText")
: storyShare
? t("share.btnStoryShareText")
: t("share.btnMapShareText");
const btnTitle = catalogShare
? t("share.btnCatalogShareTitle")
: storyShare
? t("share.btnStoryShareTitle")
: t("share.btnMapShareTitle");
return !storyShare ? (
//@ts-expect-error - not yet ready to tackle tsfying MenuPanel
_jsx(MenuPanel, { theme: dropdownTheme, btnText: catalogShareWithoutText ? null : btnText, viewState: this.props.viewState, btnTitle: btnTitle, isOpen: this.state.isOpen, onOpenChanged: this.changeOpenState, showDropdownAsModal: catalogShare, modalWidth: modalWidth, smallScreen: this.props.viewState.useSmallScreenInterface, onDismissed: () => {
if (catalogShare)
this.props.viewState.shareModalIsVisible = false;
}, onUserClick: this.props.onUserClick, disableCloseOnFocusLoss: this.props.viewState.retainSharePanel, children: this.state.isOpen && this.renderContent() })) : (_jsx(StorySharePanel, { btnText: catalogShareWithoutText ? null : btnText, viewState: this.props.viewState, btnTitle: btnTitle, isOpen: this.state.isOpen,
//@ts-expect-error - not yet ready to tackle tsfying StorySharePanel
onOpenChanged: this.changeOpenState, showDropdownAsModal: storyShare, modalWidth: modalWidth, smallScreen: this.props.viewState.useSmallScreenInterface, btnDisabled: this.props.btnDisabled, onDismissed: () => {
if (storyShare)
this.props.viewState.shareModalIsVisible = false;
}, onUserClick: this.props.onUserClick, children: this.state.isOpen && this.renderContent() }));
}
};
SharePanel = __decorate([
observer
], SharePanel);
export default withTranslation()(SharePanel);
export function shouldShorten(terria) {
return (stringToBool(terria.getLocalProperty("shortenShareUrls")) ??
!!canShorten(terria));
}
function stringToBool(s) {
if (s === true)
return true;
if (s === false)
return false;
if (s === "true")
return true;
if (s === "false")
return false;
return undefined;
}
//# sourceMappingURL=SharePanel.js.map