refactor: move create state to editorHelper

This commit is contained in:
Shivam Mishra
2024-05-09 17:20:14 +05:30
parent eff24c0d71
commit 55b6e5fbf6
2 changed files with 25 additions and 23 deletions
@@ -47,11 +47,9 @@
<script>
import {
messageSchema,
buildEditor,
EditorView,
MessageMarkdownTransformer,
MessageMarkdownSerializer,
EditorState,
Selection,
} from '@chatwoot/prosemirror-schema';
import {
@@ -70,6 +68,7 @@ import {
scrollCursorIntoView,
findNodeToInsertImage,
setURLWithQueryAndSize,
createState,
} from 'dashboard/helper/editorHelper';
const TYPING_INDICATOR_IDLE_TIME = 4000;
@@ -95,27 +94,6 @@ import {
MESSAGE_EDITOR_IMAGE_RESIZES,
} from 'dashboard/constants/editor';
const createState = (
content,
placeholder,
// eslint-disable-next-line default-param-last
plugins = [],
// eslint-disable-next-line default-param-last
methods = {},
enabledMenuOptions
) => {
return EditorState.create({
doc: new MessageMarkdownTransformer(messageSchema).parse(content),
plugins: buildEditor({
schema: messageSchema,
placeholder,
methods,
plugins,
enabledMenuOptions,
}),
});
};
export default {
name: 'WootMessageEditor',
components: { TagAgents, CannedResponse, VariableList },
@@ -2,7 +2,10 @@ import {
messageSchema,
MessageMarkdownTransformer,
MessageMarkdownSerializer,
buildEditor,
EditorState,
} from '@chatwoot/prosemirror-schema';
import * as Sentry from '@sentry/browser';
/**
@@ -281,3 +284,24 @@ export function setURLWithQueryAndSize(selectedImageNode, size, editorView) {
}
}
}
export const createState = (
content,
placeholder,
// eslint-disable-next-line default-param-last
plugins = [],
// eslint-disable-next-line default-param-last
methods = {},
enabledMenuOptions
) => {
return EditorState.create({
doc: new MessageMarkdownTransformer(messageSchema).parse(content),
plugins: buildEditor({
schema: messageSchema,
placeholder,
methods,
plugins,
enabledMenuOptions,
}),
});
};