PasteHelper.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import accepts from 'attr-accept';
  2. import markdownListUtil from './MarkdownListUtil';
  3. class PasteHelper {
  4. constructor() {
  5. this.pasteText = this.pasteText.bind(this);
  6. }
  7. /**
  8. * paste text
  9. * @param {any} editor An editor instance of CodeMirror
  10. * @param {any} event
  11. */
  12. pasteText(editor, event) {
  13. // get data in clipboard
  14. const text = event.clipboardData.getData('text/plain');
  15. if (text.length === 0) {
  16. return;
  17. }
  18. markdownListUtil.pasteText(editor, event, text);
  19. }
  20. // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
  21. /**
  22. * transplanted from react-dropzone
  23. * @see https://github.com/react-dropzone/react-dropzone/blob/master/src/utils/index.js
  24. *
  25. * @param {*} file
  26. * @param {*} accept
  27. */
  28. isAcceptableType(file, accept) {
  29. return file.type === 'application/x-moz-file' || accepts(file, accept);
  30. }
  31. }
  32. // singleton pattern
  33. const instance = new PasteHelper();
  34. Object.freeze(instance);
  35. export default instance;