|
|
@@ -15,7 +15,8 @@ import Preview from './Preview';
|
|
|
import AppContainer from '../../services/AppContainer';
|
|
|
import PageContainer from '../../services/PageContainer';
|
|
|
|
|
|
-import PagePathAutoComplete from '../PagePathAutoComplete';
|
|
|
+import SearchTypeahead from '../SearchTypeahead';
|
|
|
+import Linker from '../../models/Linker';
|
|
|
|
|
|
import { withUnstatedContainers } from '../UnstatedUtils';
|
|
|
|
|
|
@@ -28,9 +29,9 @@ class LinkEditModal extends React.PureComponent {
|
|
|
show: false,
|
|
|
isUseRelativePath: false,
|
|
|
isUsePermanentLink: false,
|
|
|
- linkInputValue: '/',
|
|
|
+ linkInputValue: '',
|
|
|
labelInputValue: '',
|
|
|
- linkerType: 'mdLink',
|
|
|
+ linkerType: Linker.types.markdownLink,
|
|
|
markdown: '',
|
|
|
permalink: '',
|
|
|
isEnablePermanentLink: false,
|
|
|
@@ -43,6 +44,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
this.cancel = this.cancel.bind(this);
|
|
|
this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
|
|
|
this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this);
|
|
|
+ this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
|
|
|
this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this);
|
|
|
this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
|
|
|
this.toggleIsUsePamanentLink = this.toggleIsUsePamanentLink.bind(this);
|
|
|
@@ -60,8 +62,23 @@ class LinkEditModal extends React.PureComponent {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- show(defaultLabelInputValue = '') {
|
|
|
- this.setState({ show: true, labelInputValue: defaultLabelInputValue });
|
|
|
+ // defaultMarkdownLink is an instance of Linker
|
|
|
+ show(defaultMarkdownLink = null) {
|
|
|
+ // if defaultMarkdownLink is null, set default value in inputs.
|
|
|
+ const { label = '', link = '' } = defaultMarkdownLink;
|
|
|
+ let { type = Linker.types.markdownLink } = defaultMarkdownLink;
|
|
|
+
|
|
|
+ // if type of defaultMarkdownLink is pukiwikiLink when pukiwikiLikeLinker plugin is disable, change type(not change label and link)
|
|
|
+ if (type === Linker.types.pukiwikiLink && !this.isApplyPukiwikiLikeLinkerPlugin) {
|
|
|
+ type = Linker.types.markdownLink;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setState({
|
|
|
+ show: true,
|
|
|
+ labelInputValue: label,
|
|
|
+ linkInputValue: link,
|
|
|
+ linkerType: type,
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
cancel() {
|
|
|
@@ -75,7 +92,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
}
|
|
|
|
|
|
toggleIsUseRelativePath() {
|
|
|
- if (this.state.linkerType === 'growiLink') {
|
|
|
+ if (this.state.linkerType === Linker.types.growiLink) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -102,16 +119,29 @@ class LinkEditModal extends React.PureComponent {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- handleChangeLinkInput(inputChangeValue) {
|
|
|
- this.setState({ linkInputValue: inputChangeValue, isEnablePermanentLink: false, isUsePermanentLink: false });
|
|
|
+ async setMarkdown(path) {
|
|
|
+ let markdown = '';
|
|
|
+ try {
|
|
|
+ await this.props.appContainer.apiGet('/pages.get', { path }).then((res) => {
|
|
|
+ markdown = res.page.revision.body;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
|
+ }
|
|
|
+ this.setState({ markdown });
|
|
|
}
|
|
|
|
|
|
handleChangeLabelInput(label) {
|
|
|
this.setState({ labelInputValue: label });
|
|
|
}
|
|
|
|
|
|
+ handleChangeLinkInput(link) {
|
|
|
+ this.setState({ linkInputValue: link });
|
|
|
+ }
|
|
|
+
|
|
|
handleSelecteLinkerType(linkerType) {
|
|
|
- if (this.state.isUseRelativePath && linkerType === 'growiLink') {
|
|
|
+ if (this.state.isUseRelativePath && linkerType === Linker.types.growiLink) {
|
|
|
this.toggleIsUseRelativePath();
|
|
|
}
|
|
|
this.setState({ linkerType });
|
|
|
@@ -143,7 +173,6 @@ class LinkEditModal extends React.PureComponent {
|
|
|
this.setState({ markdown, permalink, isEnablePermanentLink });
|
|
|
}
|
|
|
|
|
|
-
|
|
|
generateLink() {
|
|
|
const { pageContainer } = this.props;
|
|
|
const {
|
|
|
@@ -163,13 +192,13 @@ class LinkEditModal extends React.PureComponent {
|
|
|
reshapedLink = this.state.permalink;
|
|
|
}
|
|
|
|
|
|
- if (linkerType === 'pukiwikiLink') {
|
|
|
+ if (linkerType === Linker.types.pukiwikiLink) {
|
|
|
return `[[${labelInputValue}>${reshapedLink}]]`;
|
|
|
}
|
|
|
- if (linkerType === 'growiLink') {
|
|
|
+ if (linkerType === Linker.types.growiLink) {
|
|
|
return `[${reshapedLink}]`;
|
|
|
}
|
|
|
- if (linkerType === 'mdLink') {
|
|
|
+ if (linkerType === Linker.types.markdownLink) {
|
|
|
return `[${labelInputValue}](${reshapedLink})`;
|
|
|
}
|
|
|
}
|
|
|
@@ -188,9 +217,12 @@ class LinkEditModal extends React.PureComponent {
|
|
|
<div className="form-gorup my-3">
|
|
|
<label htmlFor="linkInput">Link</label>
|
|
|
<div className="input-group">
|
|
|
- <PagePathAutoComplete
|
|
|
+ <SearchTypeahead
|
|
|
+ onChange={this.handleChangeTypeahead}
|
|
|
onInputChange={this.handleChangeLinkInput}
|
|
|
- onSubmit={this.getPageWithLinkInputValue}
|
|
|
+ inputName="link"
|
|
|
+ placeholder="Input page path or URL"
|
|
|
+ keywordOnInit={this.state.linkInputValue}
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -206,16 +238,16 @@ class LinkEditModal extends React.PureComponent {
|
|
|
<div className="form-group btn-group d-flex" role="group" aria-label="type">
|
|
|
<button
|
|
|
type="button"
|
|
|
- name="mdLink"
|
|
|
- className={`btn btn-outline-secondary w-100 ${this.state.linkerType === 'mdLink' && 'active'}`}
|
|
|
+ name={Linker.types.markdownLink}
|
|
|
+ className={`btn btn-outline-secondary w-100 ${this.state.linkerType === Linker.types.markdownLink && 'active'}`}
|
|
|
onClick={e => this.handleSelecteLinkerType(e.target.name)}
|
|
|
>
|
|
|
Markdown
|
|
|
</button>
|
|
|
<button
|
|
|
type="button"
|
|
|
- name="growiLink"
|
|
|
- className={`btn btn-outline-secondary w-100 ${this.state.linkerType === 'growiLink' && 'active'}`}
|
|
|
+ name={Linker.types.growiLink}
|
|
|
+ className={`btn btn-outline-secondary w-100 ${this.state.linkerType === Linker.types.growiLink && 'active'}`}
|
|
|
onClick={e => this.handleSelecteLinkerType(e.target.name)}
|
|
|
>
|
|
|
Growi Original
|
|
|
@@ -223,8 +255,8 @@ class LinkEditModal extends React.PureComponent {
|
|
|
{this.isApplyPukiwikiLikeLinkerPlugin && (
|
|
|
<button
|
|
|
type="button"
|
|
|
- name="pukiwikiLink"
|
|
|
- className={`btn btn-outline-secondary w-100 ${this.state.linkerType === 'pukiwikiLink' && 'active'}`}
|
|
|
+ name={Linker.types.pukiwikiLink}
|
|
|
+ className={`btn btn-outline-secondary w-100 ${this.state.linkerType === Linker.types.pukiwikiLink && 'active'}`}
|
|
|
onClick={e => this.handleSelecteLinkerType(e.target.name)}
|
|
|
>
|
|
|
Pukiwiki
|
|
|
@@ -240,7 +272,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
id="label"
|
|
|
value={this.state.labelInputValue}
|
|
|
onChange={e => this.handleChangeLabelInput(e.target.value)}
|
|
|
- disabled={this.state.linkerType === 'growiLink'}
|
|
|
+ disabled={this.state.linkerType === Linker.types.growiLink}
|
|
|
/>
|
|
|
</div>
|
|
|
<div className="form-inline">
|
|
|
@@ -250,7 +282,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
id="relativePath"
|
|
|
type="checkbox"
|
|
|
checked={this.state.isUseRelativePath}
|
|
|
- disabled={this.state.linkerType === 'growiLink'}
|
|
|
+ disabled={this.state.linkerType === Linker.types.growiLink}
|
|
|
/>
|
|
|
<label className="custom-control-label" htmlFor="relativePath" onClick={this.toggleIsUseRelativePath}>
|
|
|
Use relative path
|