|
|
@@ -2,6 +2,8 @@ import { useCallback, useState } from 'react';
|
|
|
|
|
|
import { Collapse } from 'reactstrap';
|
|
|
|
|
|
+import type { GlobalCodeMirrorEditorKey } from '../../../consts';
|
|
|
+import { useCodeMirrorEditorIsolated } from '../../../stores';
|
|
|
|
|
|
import styles from './TextFormatTools.module.scss';
|
|
|
|
|
|
@@ -30,44 +32,58 @@ const TextFormatToolsToggler = (props: TogglarProps): JSX.Element => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-export const TextFormatTools = (): JSX.Element => {
|
|
|
+type TextFormatToolsType = {
|
|
|
+ editorKey: string | GlobalCodeMirrorEditorKey,
|
|
|
+}
|
|
|
+
|
|
|
+export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
|
|
|
+ const { editorKey } = props;
|
|
|
const [isOpen, setOpen] = useState(false);
|
|
|
+ const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(editorKey);
|
|
|
|
|
|
const toggle = useCallback(() => {
|
|
|
setOpen(bool => !bool);
|
|
|
}, []);
|
|
|
|
|
|
+ const onClickInsertMarkdownElements = (prefix: string, suffix: string) => {
|
|
|
+ codeMirrorEditor?.insertMarkdownElements(prefix, suffix);
|
|
|
+ };
|
|
|
+
|
|
|
+ const onClickInsertPrefix = (prefix: string, noSpaceIfPrefixExists?: boolean) => {
|
|
|
+ codeMirrorEditor?.insertPrefix(prefix, noSpaceIfPrefixExists);
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<div className="d-flex">
|
|
|
<TextFormatToolsToggler isOpen={isOpen} onClick={toggle} />
|
|
|
|
|
|
<Collapse isOpen={isOpen} horizontal>
|
|
|
<div className="d-flex px-1 gap-1" style={{ width: '220px' }}>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertMarkdownElements('**', '**')}>
|
|
|
<span className="material-symbols-outlined fs-5">format_bold</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertMarkdownElements('*', '*')}>
|
|
|
<span className="material-symbols-outlined fs-5">format_italic</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertMarkdownElements('~', '~')}>
|
|
|
<span className="material-symbols-outlined fs-5">format_strikethrough</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertPrefix('#', true)}>
|
|
|
<span className="material-symbols-outlined fs-5">block</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertMarkdownElements('`', '`')}>
|
|
|
<span className="material-symbols-outlined fs-5">code</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertPrefix('-')}>
|
|
|
<span className="material-symbols-outlined fs-5">format_list_bulleted</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertPrefix('1.')}>
|
|
|
<span className="material-symbols-outlined fs-5">format_list_numbered</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertPrefix('>')}>
|
|
|
<span className="material-symbols-outlined fs-5">block</span>
|
|
|
</button>
|
|
|
- <button type="button" className="btn btn-toolbar-button">
|
|
|
+ <button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertPrefix('- [ ]')}>
|
|
|
<span className="material-symbols-outlined fs-5">checklist</span>
|
|
|
</button>
|
|
|
</div>
|