stash
This commit is contained in:
@ -4,13 +4,17 @@ import styled from 'styled-components';
|
|||||||
import { Text } from 'slate';
|
import { Text } from 'slate';
|
||||||
import RichMarkdownEditor, { Placeholder } from 'rich-markdown-editor';
|
import RichMarkdownEditor, { Placeholder } from 'rich-markdown-editor';
|
||||||
import ClickablePadding from 'components/ClickablePadding';
|
import ClickablePadding from 'components/ClickablePadding';
|
||||||
import schema from '../schema';
|
import { uploadFile } from 'utils/uploadFile';
|
||||||
|
import isInternalUrl from 'utils/isInternalUrl';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
titlePlaceholder?: string,
|
titlePlaceholder?: string,
|
||||||
bodyPlaceholder?: string,
|
bodyPlaceholder?: string,
|
||||||
defaultValue?: string,
|
defaultValue?: string,
|
||||||
readOnly: boolean,
|
readOnly?: boolean,
|
||||||
|
expandToFit?: boolean,
|
||||||
|
history: *,
|
||||||
|
ui: *,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Editor extends React.Component<Props> {
|
class Editor extends React.Component<Props> {
|
||||||
@ -34,6 +38,42 @@ class Editor extends React.Component<Props> {
|
|||||||
if (this.editor) this.editor.focusAtEnd();
|
if (this.editor) this.editor.focusAtEnd();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onUploadImage = async (file: File) => {
|
||||||
|
const result = await uploadFile(file);
|
||||||
|
return result.url;
|
||||||
|
};
|
||||||
|
|
||||||
|
onClickLink = (href: string) => {
|
||||||
|
// on page hash
|
||||||
|
if (href[0] === '#') {
|
||||||
|
window.location.href = href;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInternalUrl(href)) {
|
||||||
|
// relative
|
||||||
|
let navigateTo = href;
|
||||||
|
|
||||||
|
// probably absolute
|
||||||
|
if (href[0] !== '/') {
|
||||||
|
try {
|
||||||
|
const url = new URL(href);
|
||||||
|
navigateTo = url.pathname + url.hash;
|
||||||
|
} catch (err) {
|
||||||
|
navigateTo = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.history.push(navigateTo);
|
||||||
|
} else {
|
||||||
|
window.open(href, '_blank');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onShowToast = (message: string) => {
|
||||||
|
this.props.ui.showToast(message, 'success');
|
||||||
|
};
|
||||||
|
|
||||||
renderPlaceholder = (props: *) => {
|
renderPlaceholder = (props: *) => {
|
||||||
const { editor, node } = props;
|
const { editor, node } = props;
|
||||||
|
|
||||||
@ -52,20 +92,24 @@ class Editor extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { readOnly } = this.props;
|
const { readOnly, expandToFit } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<StyledEditor
|
<StyledEditor
|
||||||
ref={this.setEditorRef}
|
ref={this.setEditorRef}
|
||||||
renderPlaceholder={this.renderPlaceholder}
|
renderPlaceholder={this.renderPlaceholder}
|
||||||
schema={schema}
|
uploadImage={this.onUploadImage}
|
||||||
|
onClickLink={this.onClickLink}
|
||||||
|
onShowToast={this.onShowToast}
|
||||||
{...this.props}
|
{...this.props}
|
||||||
/>
|
/>
|
||||||
<ClickablePadding
|
{expandToFit && (
|
||||||
onClick={!readOnly ? this.focusAtEnd : undefined}
|
<ClickablePadding
|
||||||
grow
|
onClick={!readOnly ? this.focusAtEnd : undefined}
|
||||||
/>
|
grow
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -1,29 +1,46 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { observable } from 'mobx';
|
||||||
|
import { observer, inject } from 'mobx-react';
|
||||||
|
import { withRouter } from 'react-router-dom';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import RichMarkdownEditor from 'rich-markdown-editor';
|
|
||||||
import { LabelText, Outline } from 'components/Input';
|
import { LabelText, Outline } from 'components/Input';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
label: string,
|
label: string,
|
||||||
minHeight?: number,
|
minHeight?: number,
|
||||||
maxHeight?: number,
|
maxHeight?: number,
|
||||||
|
readOnly?: boolean,
|
||||||
|
history: *,
|
||||||
|
ui: *,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function InputRich({
|
@observer
|
||||||
label,
|
class InputRich extends React.Component<Props> {
|
||||||
minHeight,
|
@observable editorComponent;
|
||||||
maxHeight,
|
|
||||||
...rest
|
componentDidMount() {
|
||||||
}: Props) {
|
this.loadEditor();
|
||||||
return (
|
}
|
||||||
<React.Fragment>
|
|
||||||
<LabelText>{label}</LabelText>
|
loadEditor = async () => {
|
||||||
<StyledOutline maxHeight={maxHeight} minHeight={minHeight}>
|
const EditorImport = await import('./Editor');
|
||||||
<RichMarkdownEditor {...rest} />
|
this.editorComponent = EditorImport.default;
|
||||||
</StyledOutline>
|
};
|
||||||
</React.Fragment>
|
|
||||||
);
|
render() {
|
||||||
|
const { label, minHeight, maxHeight, ...rest } = this.props;
|
||||||
|
const Editor = this.editorComponent;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<LabelText>{label}</LabelText>
|
||||||
|
<StyledOutline maxHeight={maxHeight} minHeight={minHeight}>
|
||||||
|
{Editor && <Editor {...rest} />}
|
||||||
|
</StyledOutline>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const StyledOutline = styled(Outline)`
|
const StyledOutline = styled(Outline)`
|
||||||
@ -36,3 +53,5 @@ const StyledOutline = styled(Outline)`
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export default inject('ui')(withRouter(InputRich));
|
||||||
|
@ -65,7 +65,7 @@ class CollectionEdit extends React.Component<Props> {
|
|||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<HelpText>
|
<HelpText>
|
||||||
You can edit a collection’s details at any time, however doing so
|
You can edit a collection’s details at any time, however doing so
|
||||||
might confuse your team mates.
|
often might confuse your team mates.
|
||||||
</HelpText>
|
</HelpText>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
|
@ -17,9 +17,7 @@ import {
|
|||||||
documentEditUrl,
|
documentEditUrl,
|
||||||
matchDocumentEdit,
|
matchDocumentEdit,
|
||||||
} from 'utils/routeHelpers';
|
} from 'utils/routeHelpers';
|
||||||
import { uploadFile } from 'utils/uploadFile';
|
|
||||||
import { emojiToUrl } from 'utils/emoji';
|
import { emojiToUrl } from 'utils/emoji';
|
||||||
import isInternalUrl from 'utils/isInternalUrl';
|
|
||||||
import type { Revision } from 'types';
|
import type { Revision } from 'types';
|
||||||
|
|
||||||
import Document from 'models/Document';
|
import Document from 'models/Document';
|
||||||
@ -39,6 +37,7 @@ import UiStore from 'stores/UiStore';
|
|||||||
import AuthStore from 'stores/AuthStore';
|
import AuthStore from 'stores/AuthStore';
|
||||||
import DocumentsStore from 'stores/DocumentsStore';
|
import DocumentsStore from 'stores/DocumentsStore';
|
||||||
import RevisionsStore from 'stores/RevisionsStore';
|
import RevisionsStore from 'stores/RevisionsStore';
|
||||||
|
import schema from './schema';
|
||||||
|
|
||||||
const AUTOSAVE_DELAY = 3000;
|
const AUTOSAVE_DELAY = 3000;
|
||||||
const IS_DIRTY_DELAY = 500;
|
const IS_DIRTY_DELAY = 500;
|
||||||
@ -173,7 +172,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
loadEditor = async () => {
|
loadEditor = async () => {
|
||||||
const EditorImport = await import('./components/Editor');
|
const EditorImport = await import('components/Editor');
|
||||||
this.editorComponent = EditorImport.default;
|
this.editorComponent = EditorImport.default;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -259,11 +258,6 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
onUploadImage = async (file: File) => {
|
|
||||||
const result = await uploadFile(file);
|
|
||||||
return result.url;
|
|
||||||
};
|
|
||||||
|
|
||||||
onSearchLink = async (term: string) => {
|
onSearchLink = async (term: string) => {
|
||||||
const results = await this.props.documents.search(term);
|
const results = await this.props.documents.search(term);
|
||||||
|
|
||||||
@ -273,37 +267,6 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
onClickLink = (href: string) => {
|
|
||||||
// on page hash
|
|
||||||
if (href[0] === '#') {
|
|
||||||
window.location.href = href;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInternalUrl(href)) {
|
|
||||||
// relative
|
|
||||||
let navigateTo = href;
|
|
||||||
|
|
||||||
// probably absolute
|
|
||||||
if (href[0] !== '/') {
|
|
||||||
try {
|
|
||||||
const url = new URL(href);
|
|
||||||
navigateTo = url.pathname + url.hash;
|
|
||||||
} catch (err) {
|
|
||||||
navigateTo = href;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.props.history.push(navigateTo);
|
|
||||||
} else {
|
|
||||||
window.open(href, '_blank');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onShowToast = (message: string) => {
|
|
||||||
this.props.ui.showToast(message, 'success');
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { location, match } = this.props;
|
const { location, match } = this.props;
|
||||||
const Editor = this.editorComponent;
|
const Editor = this.editorComponent;
|
||||||
@ -386,17 +349,18 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
bodyPlaceholder="…the rest is your canvas"
|
bodyPlaceholder="…the rest is your canvas"
|
||||||
defaultValue={revision ? revision.text : document.text}
|
defaultValue={revision ? revision.text : document.text}
|
||||||
pretitle={document.emoji}
|
pretitle={document.emoji}
|
||||||
uploadImage={this.onUploadImage}
|
|
||||||
onImageUploadStart={this.onImageUploadStart}
|
onImageUploadStart={this.onImageUploadStart}
|
||||||
onImageUploadStop={this.onImageUploadStop}
|
onImageUploadStop={this.onImageUploadStop}
|
||||||
onSearchLink={this.onSearchLink}
|
onSearchLink={this.onSearchLink}
|
||||||
onClickLink={this.onClickLink}
|
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onSave={this.onSave}
|
onSave={this.onSave}
|
||||||
onCancel={this.onDiscard}
|
onCancel={this.onDiscard}
|
||||||
onShowToast={this.onShowToast}
|
|
||||||
readOnly={!this.isEditing}
|
readOnly={!this.isEditing}
|
||||||
toc={!revision}
|
toc={!revision}
|
||||||
|
history={this.props.history}
|
||||||
|
ui={this.props.ui}
|
||||||
|
schema={schema}
|
||||||
|
expandToFit
|
||||||
/>
|
/>
|
||||||
</MaxWidth>
|
</MaxWidth>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -109,7 +109,7 @@ Team.prototype.provisionSubdomain = async function(subdomain) {
|
|||||||
Team.prototype.provisionFirstCollection = async function(userId) {
|
Team.prototype.provisionFirstCollection = async function(userId) {
|
||||||
return await Collection.create({
|
return await Collection.create({
|
||||||
name: 'General',
|
name: 'General',
|
||||||
description: 'Your first Collection',
|
description: '',
|
||||||
type: 'atlas',
|
type: 'atlas',
|
||||||
teamId: this.id,
|
teamId: this.id,
|
||||||
creatorId: userId,
|
creatorId: userId,
|
||||||
|
Reference in New Issue
Block a user