AbstractEditor.js 2.6 KB

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