2017-05-18 02:36:31 +00:00
|
|
|
// @flow
|
2017-12-06 16:15:06 +00:00
|
|
|
import InsertImages from '@tommoor/slate-drop-or-paste-images';
|
2017-05-18 02:36:31 +00:00
|
|
|
import PasteLinkify from 'slate-paste-linkify';
|
|
|
|
import CollapseOnEscape from 'slate-collapse-on-escape';
|
|
|
|
import TrailingBlock from 'slate-trailing-block';
|
2018-03-07 05:00:44 +00:00
|
|
|
import EditCode from 'slate-edit-code';
|
2017-05-18 02:36:31 +00:00
|
|
|
import Prism from 'slate-prism';
|
2017-10-18 03:22:20 +00:00
|
|
|
import EditList from './plugins/EditList';
|
2017-05-18 02:36:31 +00:00
|
|
|
import KeyboardShortcuts from './plugins/KeyboardShortcuts';
|
|
|
|
import MarkdownShortcuts from './plugins/MarkdownShortcuts';
|
2017-12-04 03:59:54 +00:00
|
|
|
import { insertImageFile } from './changes';
|
2017-05-18 02:36:31 +00:00
|
|
|
|
2017-06-26 00:21:33 +00:00
|
|
|
type Options = {
|
2017-12-06 04:05:43 +00:00
|
|
|
onImageUploadStart: () => void,
|
|
|
|
onImageUploadStop: () => void,
|
2017-05-26 19:56:10 +00:00
|
|
|
};
|
|
|
|
|
2017-08-27 16:03:05 +00:00
|
|
|
const createPlugins = ({ onImageUploadStart, onImageUploadStop }: Options) => {
|
2017-05-18 02:36:31 +00:00
|
|
|
return [
|
|
|
|
PasteLinkify({
|
|
|
|
type: 'link',
|
|
|
|
collapseTo: 'end',
|
|
|
|
}),
|
2017-12-04 03:59:54 +00:00
|
|
|
InsertImages({
|
2017-12-06 07:25:09 +00:00
|
|
|
extensions: ['png', 'jpg', 'gif', 'webp'],
|
2017-12-06 16:15:06 +00:00
|
|
|
insertImage: async (change, file, editor) => {
|
2017-12-04 03:59:54 +00:00
|
|
|
return change.call(
|
|
|
|
insertImageFile,
|
|
|
|
file,
|
2017-12-06 16:15:06 +00:00
|
|
|
editor,
|
2017-12-04 03:59:54 +00:00
|
|
|
onImageUploadStart,
|
|
|
|
onImageUploadStop
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}),
|
2017-10-18 03:22:20 +00:00
|
|
|
EditList,
|
2017-05-18 02:36:31 +00:00
|
|
|
EditCode({
|
|
|
|
containerType: 'code',
|
|
|
|
lineType: 'code-line',
|
|
|
|
exitBlocktype: 'paragraph',
|
2018-02-04 20:30:22 +00:00
|
|
|
allowMarks: false,
|
2017-05-18 02:36:31 +00:00
|
|
|
selectAll: true,
|
|
|
|
}),
|
|
|
|
Prism({
|
2018-02-04 20:30:22 +00:00
|
|
|
onlyIn: node => node.type === 'code',
|
2017-05-18 02:36:31 +00:00
|
|
|
getSyntax: node => 'javascript',
|
|
|
|
}),
|
|
|
|
CollapseOnEscape({ toEdge: 'end' }),
|
|
|
|
TrailingBlock({ type: 'paragraph' }),
|
|
|
|
KeyboardShortcuts(),
|
|
|
|
MarkdownShortcuts(),
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
export default createPlugins;
|