AbstractEditor.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* eslint-disable react/no-unused-prop-types */
  2. import React from 'react';
  3. import PropTypes from 'prop-types';
  4. export default class AbstractEditor extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.forceToFocus = this.forceToFocus.bind(this);
  8. this.setCaretLine = this.setCaretLine.bind(this);
  9. this.setScrollTopByLine = this.setScrollTopByLine.bind(this);
  10. this.getStrFromBol = this.getStrFromBol.bind(this);
  11. this.getStrToEol = this.getStrToEol.bind(this);
  12. this.insertText = this.insertText.bind(this);
  13. this.insertLinebreak = this.insertLinebreak.bind(this);
  14. this.dispatchSave = this.dispatchSave.bind(this);
  15. }
  16. forceToFocus() {
  17. }
  18. /**
  19. * set new value
  20. */
  21. setValue(newValue) {
  22. }
  23. /**
  24. * Enable/Disable GFM mode
  25. * @param {bool} bool
  26. */
  27. setGfmMode(bool) {
  28. }
  29. /**
  30. * set caret position of codemirror
  31. * @param {string} number
  32. */
  33. setCaretLine(line) {
  34. }
  35. /**
  36. * scroll
  37. * @param {number} line
  38. */
  39. setScrollTopByLine(line) {
  40. }
  41. /**
  42. * return strings from BOL(beginning of line) to current position
  43. */
  44. getStrFromBol() {
  45. throw new Error('this method should be impelemented in subclass');
  46. }
  47. /**
  48. * return strings from current position to EOL(end of line)
  49. */
  50. getStrToEol() {
  51. throw new Error('this method should be impelemented in subclass');
  52. }
  53. /**
  54. * return strings from BOL(beginning of line) to current position
  55. */
  56. getStrFromBolToSelectedUpperPos() {
  57. throw new Error('this method should be impelemented in subclass');
  58. }
  59. /**
  60. * replace Beggining Of Line to current position with param 'text'
  61. * @param {string} text
  62. */
  63. replaceBolToCurrentPos(text) {
  64. throw new Error('this method should be impelemented in subclass');
  65. }
  66. /**
  67. * replace the current line with param 'text'
  68. * @param {string} text
  69. */
  70. replaceLine(text) {
  71. throw new Error('this method should be impelemented in subclass');
  72. }
  73. /**
  74. * insert text
  75. * @param {string} text
  76. */
  77. insertText(text) {
  78. }
  79. /**
  80. * insert line break to the current position
  81. */
  82. insertLinebreak() {
  83. this.insertText('\n');
  84. }
  85. /**
  86. * dispatch onSave event
  87. */
  88. dispatchSave() {
  89. if (this.props.onSave != null) {
  90. this.props.onSave();
  91. }
  92. }
  93. /**
  94. * dispatch onPasteFiles event
  95. * @param {object} event
  96. */
  97. dispatchPasteFiles(event) {
  98. if (this.props.onPasteFiles != null) {
  99. this.props.onPasteFiles(event);
  100. }
  101. }
  102. /**
  103. * returns items(an array of react elements) in navigation bar for editor
  104. */
  105. getNavbarItems() {
  106. return null;
  107. }
  108. }
  109. AbstractEditor.propTypes = {
  110. value: PropTypes.string,
  111. isGfmMode: PropTypes.bool,
  112. onChange: PropTypes.func,
  113. onScroll: PropTypes.func,
  114. onScrollCursorIntoView: PropTypes.func,
  115. onSave: PropTypes.func,
  116. onPasteFiles: PropTypes.func,
  117. onDragEnter: PropTypes.func,
  118. onCtrlEnter: PropTypes.func,
  119. };
  120. AbstractEditor.defaultProps = {
  121. isGfmMode: true,
  122. };