import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import Panel from 'react-bootstrap/es/Panel';
import Tooltip from 'react-bootstrap/es/Tooltip';
import OverlayTrigger from 'react-bootstrap/es/OverlayTrigger';
import { createSubscribedElement } from '../UnstatedUtils';
import AppContainer from '../../services/AppContainer';
import RevisionBody from '../Page/RevisionBody';
class Draft extends React.Component {
constructor(props) {
super(props);
this.state = {
html: '',
isRendered: false,
isPanelExpanded: false,
showCopiedMessage: false,
};
this.growiRenderer = this.props.appContainer.getRenderer('draft');
this.changeToolTipLabel = this.changeToolTipLabel.bind(this);
this.expandPanelHandler = this.expandPanelHandler.bind(this);
this.collapsePanelHandler = this.collapsePanelHandler.bind(this);
this.renderHtml = this.renderHtml.bind(this);
this.renderAccordionTitle = this.renderAccordionTitle.bind(this);
}
changeToolTipLabel() {
this.setState({ showCopiedMessage: true });
setTimeout(() => {
this.setState({ showCopiedMessage: false });
}, 1000);
}
expandPanelHandler() {
this.setState({ isPanelExpanded: true });
if (!this.state.isRendered) {
this.renderHtml();
}
}
collapsePanelHandler() {
this.setState({ isPanelExpanded: false });
}
async renderHtml() {
const context = {
markdown: this.props.markdown,
};
const growiRenderer = this.growiRenderer;
const interceptorManager = this.props.appContainer.interceptorManager;
await interceptorManager.process('prePreProcess', context)
.then(() => {
context.markdown = growiRenderer.preProcess(context.markdown);
})
.then(() => { return interceptorManager.process('postPreProcess', context) })
.then(() => {
const parsedHTML = growiRenderer.process(context.markdown);
context.parsedHTML = parsedHTML;
})
.then(() => { return interceptorManager.process('prePostProcess', context) })
.then(() => {
context.parsedHTML = growiRenderer.postProcess(context.parsedHTML);
})
.then(() => { return interceptorManager.process('postPostProcess', context) })
.then(() => {
this.setState({ html: context.parsedHTML, isRendered: true });
});
}
renderAccordionTitle(isExist) {
const iconClass = this.state.isPanelExpanded ? 'caret-opened' : '';
return (