AbstractEditor.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * insert text
  68. * @param {string} text
  69. */
  70. insertText(text) {
  71. }
  72. /**
  73. * insert line break to the current position
  74. */
  75. insertLinebreak() {
  76. this.insertText('\n');
  77. }
  78. /**
  79. * dispatch onSave event
  80. */
  81. dispatchSave() {
  82. if (this.props.onSave != null) {
  83. this.props.onSave();
  84. }
  85. }
  86. /**
  87. * dispatch onPasteFiles event
  88. * @param {object} event
  89. */
  90. dispatchPasteFiles(event) {
  91. if (this.props.onPasteFiles != null) {
  92. this.props.onPasteFiles(event);
  93. }
  94. }
  95. /**
  96. * returns items(an array of react elements) in navigation bar for editor
  97. */
  98. getNavbarItems() {
  99. return null;
  100. }
  101. }
  102. AbstractEditor.propTypes = {
  103. value: PropTypes.string,
  104. isGfmMode: PropTypes.bool,
  105. onChange: PropTypes.func,
  106. onScroll: PropTypes.func,
  107. onScrollCursorIntoView: PropTypes.func,
  108. onSave: PropTypes.func,
  109. onPasteFiles: PropTypes.func,
  110. onDragEnter: PropTypes.func,
  111. onCtrlEnter: PropTypes.func,
  112. };
  113. AbstractEditor.defaultProps = {
  114. isGfmMode: true,
  115. };