import React from 'react'; import PropTypes from 'prop-types'; import path from 'path'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import Preview from './Preview'; import AppContainer from '../../services/AppContainer'; import PageContainer from '../../services/PageContainer'; import SearchTypeahead from '../SearchTypeahead'; import { withUnstatedContainers } from '../UnstatedUtils'; class LinkEditModal extends React.PureComponent { constructor(props) { super(props); this.state = { show: false, isUseRelativePath: false, isUsePermanentLink: false, linkInputValue: 'ss', labelInputValue: '', linkerType: 'mdLink', markdown: '', permalink: '', isEnablePermanentLink: false, }; this.isApplyPukiwikiLikeLinkerPlugin = window.growiRenderer.preProcessors.some(process => process.constructor.name === 'PukiwikiLikeLinker'); this.show = this.show.bind(this); this.hide = this.hide.bind(this); this.cancel = this.cancel.bind(this); this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this); this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this); this.handleChangeTypeahead = this.handleChangeTypeahead.bind(this); this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this); this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this); this.toggleIsUsePamanentLink = this.toggleIsUsePamanentLink.bind(this); this.save = this.save.bind(this); this.generateLink = this.generateLink.bind(this); this.getPageWithLinkInputValue = this.getPageWithLinkInputValue.bind(this); this.renderPreview = this.renderPreview.bind(this); } componentDidUpdate(prevState) { const { linkInputValue: prevLinkInputValue } = prevState; const { linkInputValue } = this.state; if (linkInputValue !== prevLinkInputValue) { this.getPageWithLinkInputValue(linkInputValue); } } show(defaultMarkdownLink = '') { let labelInputValue = defaultMarkdownLink; let linkInputValue = ''; let linkerType = 'mdLink'; if (defaultMarkdownLink.match(/^\[\[.*\]\]$/) && this.isApplyPukiwikiLikeLinkerPlugin) { linkerType = 'pukiwikiLink'; labelInputValue = 'pukilabel'; linkInputValue = 'pukilink'; } else if (defaultMarkdownLink.match(/^\[\/.*\]$/)) { linkerType = 'growiLink'; labelInputValue = 'growilabel'; linkInputValue = 'growilink'; } else if (defaultMarkdownLink.match(/^\[.*\]\(.*\)$/)) { labelInputValue = 'mdlabel'; linkInputValue = 'mdlink'; } this.setState({ show: true, labelInputValue, linkInputValue, linkerType, }); } cancel() { this.hide(); } hide() { this.setState({ show: false, }); } toggleIsUseRelativePath() { if (this.state.linkerType === 'growiLink') { return; } // User can't use both relativePath and permalink at the same time this.setState({ isUseRelativePath: !this.state.isUseRelativePath, isUsePermanentLink: false }); } toggleIsUsePamanentLink() { if (!this.state.isEnablePermanentLink) { return; } // User can't use both relativePath and permalink at the same time this.setState({ isUsePermanentLink: !this.state.isUsePermanentLink, isUseRelativePath: false }); } renderPreview() { return (