| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import accepts from 'attr-accept';
- import markdownListUtil from './MarkdownListUtil';
- class PasteHelper {
- constructor() {
- this.pasteText = this.pasteText.bind(this);
- }
- /**
- * paste text
- * @param {any} editor An editor instance of CodeMirror
- * @param {any} event
- */
- pasteText(editor, event) {
- // get data in clipboard
- const text = event.clipboardData.getData('text/plain');
- if (text.length === 0) {
- return;
- }
- markdownListUtil.pasteText(editor, event, text);
- }
- // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
- /**
- * transplanted from react-dropzone
- * @see https://github.com/react-dropzone/react-dropzone/blob/master/src/utils/index.js
- *
- * @param {*} file
- * @param {*} accept
- */
- isAcceptableType(file, accept) {
- return file.type === 'application/x-moz-file' || accepts(file, accept);
- }
- }
- // singleton pattern
- const instance = new PasteHelper();
- Object.freeze(instance);
- export default instance;
|