remove unrelated code style improvements
This commit is contained in:
parent
f93aa34105
commit
e401f7ef9b
@ -5,13 +5,8 @@ import { EditorState } from 'prosemirror-state';
|
|||||||
import { EditorView } from 'prosemirror-view';
|
import { EditorView } from 'prosemirror-view';
|
||||||
import history from 'prosemirror-history';
|
import history from 'prosemirror-history';
|
||||||
import {
|
import {
|
||||||
blockQuoteRule,
|
blockQuoteRule, orderedListRule, bulletListRule, codeBlockRule, headingRule,
|
||||||
orderedListRule,
|
inputRules, allInputRules,
|
||||||
bulletListRule,
|
|
||||||
codeBlockRule,
|
|
||||||
headingRule,
|
|
||||||
inputRules,
|
|
||||||
allInputRules,
|
|
||||||
} from 'prosemirror-inputrules';
|
} from 'prosemirror-inputrules';
|
||||||
import { keymap } from 'prosemirror-keymap';
|
import { keymap } from 'prosemirror-keymap';
|
||||||
import { schema as markdownSchema, defaultMarkdownSerializer } from 'prosemirror-markdown';
|
import { schema as markdownSchema, defaultMarkdownSerializer } from 'prosemirror-markdown';
|
||||||
@ -67,20 +62,14 @@ function schemaWithPlugins(schema, plugins) {
|
|||||||
nodeSpec = nodeSpec.addToEnd(`plugin_${ plugin.get('id') }`, {
|
nodeSpec = nodeSpec.addToEnd(`plugin_${ plugin.get('id') }`, {
|
||||||
attrs,
|
attrs,
|
||||||
group: 'block',
|
group: 'block',
|
||||||
parseDOM: [
|
parseDOM: [{
|
||||||
{
|
|
||||||
tag: 'div[data-plugin]',
|
tag: 'div[data-plugin]',
|
||||||
getAttrs(dom) {
|
getAttrs(dom) {
|
||||||
return JSON.parse(dom.getAttribute('data-plugin'));
|
return JSON.parse(dom.getAttribute('data-plugin'));
|
||||||
},
|
},
|
||||||
},
|
}],
|
||||||
],
|
|
||||||
toDOM(node) {
|
toDOM(node) {
|
||||||
return [
|
return ['div', { 'data-plugin': JSON.stringify(node.attrs) }, plugin.get('label')];
|
||||||
'div',
|
|
||||||
{ 'data-plugin': JSON.stringify(node.attrs) },
|
|
||||||
plugin.get('label'),
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -170,28 +159,16 @@ export default class Editor extends Component {
|
|||||||
const { schema, selection } = state;
|
const { schema, selection } = state;
|
||||||
if (selection.from === selection.to) {
|
if (selection.from === selection.to) {
|
||||||
const { $from } = selection;
|
const { $from } = selection;
|
||||||
if (
|
if ($from.parent && $from.parent.type === schema.nodes.paragraph && $from.parent.textContent === '') {
|
||||||
$from.parent &&
|
|
||||||
$from.parent.type === schema.nodes.paragraph &&
|
|
||||||
$from.parent.textContent === ''
|
|
||||||
) {
|
|
||||||
const pos = this.view.coordsAtPos(selection.from);
|
const pos = this.view.coordsAtPos(selection.from);
|
||||||
const editorPos = this.view.content.getBoundingClientRect();
|
const editorPos = this.view.content.getBoundingClientRect();
|
||||||
const selectionPosition = {
|
const selectionPosition = { top: pos.top - editorPos.top, left: pos.left - editorPos.left };
|
||||||
top: pos.top - editorPos.top,
|
|
||||||
left: pos.left - editorPos.left,
|
|
||||||
};
|
|
||||||
this.setState({ selectionPosition });
|
this.setState({ selectionPosition });
|
||||||
} else {
|
|
||||||
this.setState({ showToolbar: false, showBlockMenu: false });
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const pos = this.view.coordsAtPos(selection.from);
|
const pos = this.view.coordsAtPos(selection.from);
|
||||||
const editorPos = this.view.content.getBoundingClientRect();
|
const editorPos = this.view.content.getBoundingClientRect();
|
||||||
const selectionPosition = {
|
const selectionPosition = { top: pos.top - editorPos.top, left: pos.left - editorPos.left };
|
||||||
top: pos.top - editorPos.top,
|
|
||||||
left: pos.left - editorPos.left,
|
|
||||||
};
|
|
||||||
this.setState({ selectionPosition });
|
this.setState({ selectionPosition });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -200,7 +177,7 @@ export default class Editor extends Component {
|
|||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
handleHeader = level =>
|
handleHeader = level => (
|
||||||
() => {
|
() => {
|
||||||
const { schema } = this.state;
|
const { schema } = this.state;
|
||||||
const state = this.view.state;
|
const state = this.view.state;
|
||||||
@ -218,7 +195,8 @@ export default class Editor extends Component {
|
|||||||
|
|
||||||
const command = setBlockType(nodeType, { level });
|
const command = setBlockType(nodeType, { level });
|
||||||
command(state, this.handleAction);
|
command(state, this.handleAction);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
handleBold = () => {
|
handleBold = () => {
|
||||||
const command = toggleMark(this.state.schema.marks.strong);
|
const command = toggleMark(this.state.schema.marks.strong);
|
||||||
@ -235,20 +213,14 @@ export default class Editor extends Component {
|
|||||||
if (!markActive(this.view.state, this.state.schema.marks.link)) {
|
if (!markActive(this.view.state, this.state.schema.marks.link)) {
|
||||||
url = prompt('Link URL:'); // eslint-disable-line no-alert
|
url = prompt('Link URL:'); // eslint-disable-line no-alert
|
||||||
}
|
}
|
||||||
const command = toggleMark(this.state.schema.marks.link, {
|
const command = toggleMark(this.state.schema.marks.link, { href: url ? processUrl(url) : null });
|
||||||
href: url ? processUrl(url) : null,
|
|
||||||
});
|
|
||||||
command(this.view.state, this.handleAction);
|
command(this.view.state, this.handleAction);
|
||||||
};
|
};
|
||||||
|
|
||||||
handlePluginSubmit = (plugin, data) => {
|
handlePluginSubmit = (plugin, data) => {
|
||||||
const { schema } = this.state;
|
const { schema } = this.state;
|
||||||
const nodeType = schema.nodes[`plugin_${ plugin.get('id') }`];
|
const nodeType = schema.nodes[`plugin_${ plugin.get('id') }`];
|
||||||
this.view.props.onAction(
|
this.view.props.onAction(this.view.state.tr.replaceSelectionWith(nodeType.create(data.toJS())).action());
|
||||||
this.view.state.tr
|
|
||||||
.replaceSelectionWith(nodeType.create(data.toJS()))
|
|
||||||
.action()
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDragEnter = (e) => {
|
handleDragEnter = (e) => {
|
||||||
@ -276,35 +248,26 @@ export default class Editor extends Component {
|
|||||||
|
|
||||||
if (e.dataTransfer.files && e.dataTransfer.files.length) {
|
if (e.dataTransfer.files && e.dataTransfer.files.length) {
|
||||||
Array.from(e.dataTransfer.files).forEach((file) => {
|
Array.from(e.dataTransfer.files).forEach((file) => {
|
||||||
createAssetProxy(file.name, file).then((assetProxy) => {
|
createAssetProxy(file.name, file)
|
||||||
|
.then((assetProxy) => {
|
||||||
this.props.onAddAsset(assetProxy);
|
this.props.onAddAsset(assetProxy);
|
||||||
if (file.type.split('/')[0] === 'image') {
|
if (file.type.split('/')[0] === 'image') {
|
||||||
nodes.push(
|
nodes.push(
|
||||||
schema.nodes.image.create({
|
schema.nodes.image.create({ src: assetProxy.public_path, alt: file.name })
|
||||||
src: assetProxy.public_path,
|
|
||||||
alt: file.name,
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
nodes.push(
|
nodes.push(
|
||||||
schema.marks.link.create({
|
schema.marks.link.create({ href: assetProxy.public_path, title: file.name })
|
||||||
href: assetProxy.public_path,
|
|
||||||
title: file.name,
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
nodes.push(
|
nodes.push(schema.nodes.paragraph.create({}, e.dataTransfer.getData('text/plain')));
|
||||||
schema.nodes.paragraph.create({}, e.dataTransfer.getData('text/plain'))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.forEach((node) => {
|
nodes.forEach((node) => {
|
||||||
this.view.props.onAction(
|
this.view.props.onAction(this.view.state.tr.replaceSelectionWith(node).action());
|
||||||
this.view.state.tr.replaceSelectionWith(node).action()
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -320,8 +283,7 @@ export default class Editor extends Component {
|
|||||||
classNames.push(styles.dragging);
|
classNames.push(styles.dragging);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (<div
|
||||||
<div
|
|
||||||
className={classNames.join(' ')}
|
className={classNames.join(' ')}
|
||||||
onDragEnter={this.handleDragEnter}
|
onDragEnter={this.handleDragEnter}
|
||||||
onDragLeave={this.handleDragLeave}
|
onDragLeave={this.handleDragLeave}
|
||||||
@ -350,8 +312,7 @@ export default class Editor extends Component {
|
|||||||
</Sticky>
|
</Sticky>
|
||||||
<div ref={this.handleRef} />
|
<div ref={this.handleRef} />
|
||||||
<div className={styles.shim} />
|
<div className={styles.shim} />
|
||||||
</div>
|
</div>);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user