feat: refactor tinymce editor to sharedComponents (#255)
This commit is contained in:
27
src/editors/sharedComponents/SourceCodeModal/hooks.js
Normal file
27
src/editors/sharedComponents/SourceCodeModal/hooks.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { useRef } from 'react';
|
||||
import * as module from './hooks';
|
||||
|
||||
export const getSaveBtnProps = ({ editorRef, ref, close }) => ({
|
||||
onClick: () => {
|
||||
if (editorRef && editorRef.current && ref && ref.current) {
|
||||
const content = ref.current.state.doc.toString();
|
||||
editorRef.current.setContent(content);
|
||||
close();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const prepareSourceCodeModal = ({ editorRef, close }) => {
|
||||
const ref = useRef();
|
||||
const saveBtnProps = module.getSaveBtnProps({ editorRef, ref, close });
|
||||
|
||||
if (editorRef && editorRef.current && typeof editorRef.current.getContent === 'function') {
|
||||
const value = editorRef?.current?.getContent();
|
||||
return { saveBtnProps, value, ref };
|
||||
}
|
||||
return { saveBtnProps, value: null, ref };
|
||||
};
|
||||
|
||||
export default {
|
||||
prepareSourceCodeModal,
|
||||
};
|
||||
Reference in New Issue
Block a user