Skip to content

Commit

Permalink
Fix/suggester compatible node (#157)
Browse files Browse the repository at this point in the history
* fix(suggester): fix sugggester hook compatible for node env

* docs: optimize docs about node env usage

Co-authored-by: humyfred <[email protected]>
  • Loading branch information
humyfred and humyfred authored Mar 1, 2022
1 parent c09dc9f commit 98f4198
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ const cherryInstance = new Cherry({
### Node

```javascript
const { default: Cherry } = require('cherry-markdown');
const cherryInstance = new Cherry({
id: 'markdown-container',
value: '# welcome to cherry editor!',
});
const { default: CherryEngine } = require('cherry-markdown/dist/cherry-markdown.engine.core.common');
const cherryEngineInstance = new CherryEngine();
const htmlContent = cherryEngineInstance.makeHtml('# welcome to cherry editor!');
```

## Lite Version
Expand Down
16 changes: 9 additions & 7 deletions src/core/hooks/Suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
*/
import escapeRegExp from 'lodash/escapeRegExp';
import SyntaxBase from '@/core/SyntaxBase';
import Codemirror from 'codemirror';
import { Pass } from 'codemirror/src/util/misc';
import { isLookbehindSupported } from '@/utils/regexp';
import { replaceLookbehind } from '@/utils/lookbehind-replace';
import { isBrowser } from '@/utils/env';

export default class Suggester extends SyntaxBase {
static HOOK_NAME = 'suggester';

Expand Down Expand Up @@ -79,7 +81,7 @@ export default class Suggester extends SyntaxBase {

makeHtml(str) {
if (!this.RULE.reg) return str;
if (!suggesterPanel.hasEditor()) {
if (!suggesterPanel.hasEditor() && isBrowser()) {
const { editor } = this.$engine.$cherry;
suggesterPanel.setEditor(editor);
suggesterPanel.setSuggester(this.suggester);
Expand Down Expand Up @@ -124,7 +126,7 @@ export default class Suggester extends SyntaxBase {
}

mounted() {
if (!suggesterPanel.hasEditor()) {
if (!suggesterPanel.hasEditor() && isBrowser()) {
const { editor } = this.$engine.$cherry;
suggesterPanel.setEditor(editor);
suggesterPanel.setSuggester(this.suggester);
Expand All @@ -141,7 +143,7 @@ class SuggesterPanel {
this.cursorMove = true;
this.suggesterConfig = {};

if (!this.$suggesterPanel) {
if (!this.$suggesterPanel && isBrowser()) {
document.body.append(this.createDom(SuggesterPanel.panelWrap));
this.$suggesterPanel = document.querySelector('.cherry-suggester-panel');
}
Expand Down Expand Up @@ -187,19 +189,19 @@ class SuggesterPanel {
Up() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Codemirror.Pass;
return Pass;
}
},
Down() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Codemirror.Pass;
return Pass;
}
},
Enter() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Codemirror.Pass;
return Pass;
}
},
});
Expand Down

0 comments on commit 98f4198

Please sign in to comment.