AbstractEditor.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. * return strings from BOL(beginning of line) to current position
  48. */
  49. getStrFromBolToSelectedUpperPos() {
  50. throw new Error('this method should be impelemented in subclass');
  51. }
  52. /**
  53. * replace Beggining Of Line to current position with param 'text'
  54. * @param {string} text
  55. */
  56. replaceBolToCurrentPos(text) {
  57. throw new Error('this method should be impelemented in subclass');
  58. }
  59. /**
  60. * insert text
  61. * @param {string} text
  62. */
  63. insertText(text) {
  64. }
  65. /**
  66. * insert line break to the current position
  67. */
  68. insertLinebreak() {
  69. this.insertText('\n');
  70. }
  71. /**
  72. * dispatch onSave event
  73. */
  74. dispatchSave() {
  75. if (this.props.onSave != null) {
  76. this.props.onSave();
  77. }
  78. }
  79. /**
  80. * dispatch onPasteFiles event
  81. * @param {object} event
  82. */
  83. dispatchPasteFiles(event) {
  84. if (this.props.onPasteFiles != null) {
  85. this.props.onPasteFiles(event);
  86. }
  87. }
  88. }
  89. AbstractEditor.propTypes = {
  90. value: PropTypes.string,
  91. editorOptions: PropTypes.object,
  92. onChange: PropTypes.func,
  93. onScroll: PropTypes.func,
  94. onScrollCursorIntoView: PropTypes.func,
  95. onSave: PropTypes.func,
  96. onPasteFiles: PropTypes.func,
  97. onDragEnter: PropTypes.func,
  98. };