AbstractEditor.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 new value
  19. */
  20. setValue(newValue) {
  21. }
  22. /**
  23. * set caret position of codemirror
  24. * @param {string} number
  25. */
  26. setCaretLine(line) {
  27. }
  28. /**
  29. * scroll
  30. * @param {number} line
  31. */
  32. setScrollTopByLine(line) {
  33. }
  34. /**
  35. * return strings from BOL(beginning of line) to current position
  36. */
  37. getStrFromBol() {
  38. throw new Error('this method should be impelemented in subclass');
  39. }
  40. /**
  41. * return strings from current position to EOL(end of line)
  42. */
  43. getStrToEol() {
  44. throw new Error('this method should be impelemented in subclass');
  45. }
  46. /**
  47. * replace Beggining Of Line to current position with param 'text'
  48. * @param {string} text
  49. */
  50. replaceBolToCurrentPos(text) {
  51. throw new Error('this method should be impelemented in subclass');
  52. }
  53. /**
  54. * insert text
  55. * @param {string} text
  56. */
  57. insertText(text) {
  58. }
  59. /**
  60. * insert line break to the current position
  61. */
  62. insertLinebreak() {
  63. this.insertText('\n');
  64. }
  65. /**
  66. * dispatch onSave event
  67. */
  68. dispatchSave() {
  69. if (this.props.onSave != null) {
  70. this.props.onSave();
  71. }
  72. }
  73. /**
  74. * dispatch onPasteFiles event
  75. * @param {object} event
  76. */
  77. dispatchPasteFiles(event) {
  78. if (this.props.onPasteFiles != null) {
  79. this.props.onPasteFiles(event);
  80. }
  81. }
  82. }
  83. AbstractEditor.propTypes = {
  84. value: PropTypes.string,
  85. editorOptions: PropTypes.object,
  86. onChange: PropTypes.func,
  87. onScroll: PropTypes.func,
  88. onScrollCursorIntoView: PropTypes.func,
  89. onSave: PropTypes.func,
  90. onPasteFiles: PropTypes.func,
  91. onDragEnter: PropTypes.func,
  92. };