|
@@ -2,20 +2,18 @@ import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import path from 'path';
|
|
import path from 'path';
|
|
|
-
|
|
|
|
|
import {
|
|
import {
|
|
|
Modal,
|
|
Modal,
|
|
|
ModalHeader,
|
|
ModalHeader,
|
|
|
ModalBody,
|
|
ModalBody,
|
|
|
ModalFooter,
|
|
ModalFooter,
|
|
|
} from 'reactstrap';
|
|
} from 'reactstrap';
|
|
|
-
|
|
|
|
|
-import PageContainer from '../../services/PageContainer';
|
|
|
|
|
-import AppContainer from '../../services/AppContainer';
|
|
|
|
|
-
|
|
|
|
|
import Preview from './Preview';
|
|
import Preview from './Preview';
|
|
|
import PagePathAutoComplete from '../PagePathAutoComplete';
|
|
import PagePathAutoComplete from '../PagePathAutoComplete';
|
|
|
|
|
|
|
|
|
|
+import AppContainer from '../../services/AppContainer';
|
|
|
|
|
+import PageContainer from '../../services/PageContainer';
|
|
|
|
|
+
|
|
|
import { withUnstatedContainers } from '../UnstatedUtils';
|
|
import { withUnstatedContainers } from '../UnstatedUtils';
|
|
|
|
|
|
|
|
class LinkEditModal extends React.PureComponent {
|
|
class LinkEditModal extends React.PureComponent {
|
|
@@ -27,7 +25,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
show: false,
|
|
show: false,
|
|
|
isUseRelativePath: false,
|
|
isUseRelativePath: false,
|
|
|
isUsePermanentLink: false,
|
|
isUsePermanentLink: false,
|
|
|
- linkInputValue: '',
|
|
|
|
|
|
|
+ linkInputValue: '/',
|
|
|
labelInputValue: '',
|
|
labelInputValue: '',
|
|
|
linkerType: 'mdLink',
|
|
linkerType: 'mdLink',
|
|
|
markdown: '',
|
|
markdown: '',
|
|
@@ -40,7 +38,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
this.show = this.show.bind(this);
|
|
this.show = this.show.bind(this);
|
|
|
this.hide = this.hide.bind(this);
|
|
this.hide = this.hide.bind(this);
|
|
|
this.cancel = this.cancel.bind(this);
|
|
this.cancel = this.cancel.bind(this);
|
|
|
- this.inputChangeHandler = this.inputChangeHandler.bind(this);
|
|
|
|
|
|
|
+ this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
|
|
|
this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this);
|
|
this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this);
|
|
|
this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this);
|
|
this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this);
|
|
|
this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
|
|
this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
|
|
@@ -51,6 +49,14 @@ class LinkEditModal extends React.PureComponent {
|
|
|
this.renderPreview = this.renderPreview.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(defaultLabelInputValue = '') {
|
|
show(defaultLabelInputValue = '') {
|
|
|
this.setState({ show: true, labelInputValue: defaultLabelInputValue });
|
|
this.setState({ show: true, labelInputValue: defaultLabelInputValue });
|
|
|
}
|
|
}
|
|
@@ -69,18 +75,18 @@ class LinkEditModal extends React.PureComponent {
|
|
|
if (this.state.linkerType === 'growiLink') {
|
|
if (this.state.linkerType === 'growiLink') {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- this.setState({ isUseRelativePath: !this.state.isUseRelativePath });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // User can't use both relativePath and permalink at the same time
|
|
|
|
|
+ this.setState({ isUseRelativePath: !this.state.isUseRelativePath, isUsePermanentLink: false });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
toggleIsUsePamanentLink() {
|
|
toggleIsUsePamanentLink() {
|
|
|
if (!this.state.isEnablePermanentLink) {
|
|
if (!this.state.isEnablePermanentLink) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (!this.state.isUsePermanentLink) {
|
|
|
|
|
- this.setState({ linkInputValue: this.state.permalink });
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- this.setState({ isUsePermanentLink: !this.state.isUsePermanentLink });
|
|
|
|
|
|
|
+ // User can't use both relativePath and permalink at the same time
|
|
|
|
|
+ this.setState({ isUsePermanentLink: !this.state.isUsePermanentLink, isUseRelativePath: false });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderPreview() {
|
|
renderPreview() {
|
|
@@ -94,20 +100,8 @@ class LinkEditModal extends React.PureComponent {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async getPageWithLinkInputValue() {
|
|
|
|
|
- let markdown = '';
|
|
|
|
|
- let permalink = '';
|
|
|
|
|
- let isEnablePermanentLink = false;
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await this.props.appContainer.apiGet('/pages.get', { path: this.state.linkInputValue });
|
|
|
|
|
- markdown = res.page.revision.body;
|
|
|
|
|
- permalink = `${window.location.origin}/${res.page.id}`;
|
|
|
|
|
- isEnablePermanentLink = true;
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
|
|
|
- }
|
|
|
|
|
- this.setState({ markdown, permalink, isEnablePermanentLink });
|
|
|
|
|
|
|
+ handleChangeLinkInput(inputChangeValue) {
|
|
|
|
|
+ this.setState({ linkInputValue: inputChangeValue, isEnablePermanentLink: false, isUsePermanentLink: false });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
handleChangeLabelInput(label) {
|
|
handleChangeLabelInput(label) {
|
|
@@ -131,10 +125,23 @@ class LinkEditModal extends React.PureComponent {
|
|
|
this.hide();
|
|
this.hide();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inputChangeHandler(inputChangeValue) {
|
|
|
|
|
- this.setState({ linkInputValue: inputChangeValue, isEnablePermanentLink: false, isUsePermanentLink: false });
|
|
|
|
|
|
|
+ async getPageWithLinkInputValue(path) {
|
|
|
|
|
+ let markdown = '';
|
|
|
|
|
+ let permalink = '';
|
|
|
|
|
+ let isEnablePermanentLink = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await this.props.appContainer.apiGet('/pages.get', { path });
|
|
|
|
|
+ markdown = res.page.revision.body;
|
|
|
|
|
+ permalink = `${window.location.origin}/${res.page.id}`;
|
|
|
|
|
+ isEnablePermanentLink = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setState({ markdown, permalink, isEnablePermanentLink });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
generateLink() {
|
|
generateLink() {
|
|
|
const { pageContainer } = this.props;
|
|
const { pageContainer } = this.props;
|
|
|
const {
|
|
const {
|
|
@@ -142,6 +149,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
labelInputValue,
|
|
labelInputValue,
|
|
|
linkerType,
|
|
linkerType,
|
|
|
isUseRelativePath,
|
|
isUseRelativePath,
|
|
|
|
|
+ isUsePermanentLink,
|
|
|
} = this.state;
|
|
} = this.state;
|
|
|
|
|
|
|
|
let reshapedLink = linkInputValue;
|
|
let reshapedLink = linkInputValue;
|
|
@@ -149,6 +157,9 @@ class LinkEditModal extends React.PureComponent {
|
|
|
if (isUseRelativePath && linkInputValue.match(/^\//)) {
|
|
if (isUseRelativePath && linkInputValue.match(/^\//)) {
|
|
|
reshapedLink = path.relative(pageContainer.state.path, linkInputValue);
|
|
reshapedLink = path.relative(pageContainer.state.path, linkInputValue);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (isUsePermanentLink) {
|
|
|
|
|
+ reshapedLink = this.state.permalink;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (linkerType === 'pukiwikiLink') {
|
|
if (linkerType === 'pukiwikiLink') {
|
|
|
return `[[${labelInputValue}>${reshapedLink}]]`;
|
|
return `[[${labelInputValue}>${reshapedLink}]]`;
|
|
@@ -169,17 +180,19 @@ class LinkEditModal extends React.PureComponent {
|
|
|
</ModalHeader>
|
|
</ModalHeader>
|
|
|
|
|
|
|
|
<ModalBody className="container">
|
|
<ModalBody className="container">
|
|
|
- <div className="row h-100">
|
|
|
|
|
|
|
+ <div className="row">
|
|
|
<div className="col-12 col-lg-6">
|
|
<div className="col-12 col-lg-6">
|
|
|
- <div className="form-gorup my-3">
|
|
|
|
|
- <label htmlFor="linkInput">Link</label>
|
|
|
|
|
- <div className="input-group">
|
|
|
|
|
- <PagePathAutoComplete
|
|
|
|
|
- onInputChange={this.inputChangeHandler}
|
|
|
|
|
- onSubmit={this.getPageWithLinkInputValue}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <form className="form-group">
|
|
|
|
|
+ <div className="form-gorup my-3">
|
|
|
|
|
+ <label htmlFor="linkInput">Link</label>
|
|
|
|
|
+ <div className="input-group">
|
|
|
|
|
+ <PagePathAutoComplete
|
|
|
|
|
+ onInputChange={this.handleChangeLinkInput}
|
|
|
|
|
+ onSubmit={this.getPageWithLinkInputValue}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
- </div>
|
|
|
|
|
|
|
+ </form>
|
|
|
|
|
|
|
|
<div className="card">
|
|
<div className="card">
|
|
|
<div className="card-body">
|
|
<div className="card-body">
|
|
@@ -257,14 +270,8 @@ class LinkEditModal extends React.PureComponent {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div className="col-12 col-lg-6">
|
|
<div className="col-12 col-lg-6">
|
|
|
- <div className="d-block">
|
|
|
|
|
- <div className="linkedit-preview">
|
|
|
|
|
- <Preview
|
|
|
|
|
- markdown={this.state.markdown}
|
|
|
|
|
- inputRef={() => {}}
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
- render preview
|
|
|
|
|
|
|
+ <div className="d-block mb-3">
|
|
|
|
|
+ {this.renderPreview()}
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|