AbstractEditor.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class AbstractEditor extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.forceToFocus = this.forceToFocus.bind(this);
  7. this.setCaretLine = this.setCaretLine.bind(this);
  8. this.setScrollTopByLine = this.setScrollTopByLine.bind(this);
  9. this.getStrFromBol = this.getStrFromBol.bind(this);
  10. this.getStrToEol = this.getStrToEol.bind(this);
  11. this.insertText = this.insertText.bind(this);
  12. this.insertLinebreak = this.insertLinebreak.bind(this);
  13. this.dispatchSave = this.dispatchSave.bind(this);
  14. }
  15. forceToFocus() {
  16. }
  17. /**
  18. * set caret position of codemirror
  19. * @param {string} number
  20. */
  21. setCaretLine(line) {
  22. }
  23. /**
  24. * scroll
  25. * @param {number} line
  26. */
  27. setScrollTopByLine(line) {
  28. }
  29. /**
  30. * return strings from BOL(beginning of line) to current position
  31. */
  32. getStrFromBol() {
  33. throw new Error('this method should be impelemented in subclass');
  34. }
  35. /**
  36. * return strings from current position to EOL(end of line)
  37. */
  38. getStrToEol() {
  39. throw new Error('this method should be impelemented in subclass');
  40. }
  41. /**
  42. * replace Beggining Of Line to current position with param 'text'
  43. * @param {string} text
  44. */
  45. replaceBolToCurrentPos(text) {
  46. throw new Error('this method should be impelemented in subclass');
  47. }
  48. /**
  49. * insert text
  50. * @param {string} text
  51. */
  52. insertText(text) {
  53. }
  54. /**
  55. * insert line break to the current position
  56. */
  57. insertLinebreak() {
  58. this.insertText('\n');
  59. }
  60. /**
  61. * dispatch onSave event
  62. */
  63. dispatchSave() {
  64. if (this.props.onSave != null) {
  65. this.props.onSave();
  66. }
  67. }
  68. /**
  69. * dispatch onPasteFiles event
  70. * @param {object} event
  71. */
  72. dispatchPasteFiles(event) {
  73. if (this.props.onPasteFiles != null) {
  74. this.props.onPasteFiles(event);
  75. }
  76. }
  77. }
  78. AbstractEditor.propTypes = {
  79. value: PropTypes.string,
  80. editorOptions: PropTypes.object,
  81. onChange: PropTypes.func,
  82. onScroll: PropTypes.func,
  83. onScrollCursorIntoView: PropTypes.func,
  84. onSave: PropTypes.func,
  85. onPasteFiles: PropTypes.func,
  86. onDragEnter: PropTypes.func,
  87. };