|
@@ -1,6 +1,7 @@
|
|
|
import { useCallback, useState } from 'react';
|
|
import { useCallback, useState } from 'react';
|
|
|
|
|
|
|
|
import { Collapse } from 'reactstrap';
|
|
import { Collapse } from 'reactstrap';
|
|
|
|
|
+import type SimpleBar from 'simplebar-react';
|
|
|
|
|
|
|
|
import type { GlobalCodeMirrorEditorKey } from '../../../../consts';
|
|
import type { GlobalCodeMirrorEditorKey } from '../../../../consts';
|
|
|
import { useCodeMirrorEditorIsolated } from '../../../stores/codemirror-editor';
|
|
import { useCodeMirrorEditorIsolated } from '../../../stores/codemirror-editor';
|
|
@@ -9,7 +10,6 @@ import styles from './TextFormatTools.module.scss';
|
|
|
|
|
|
|
|
const btnTextFormatToolsTogglerClass = styles['btn-text-format-tools-toggler'];
|
|
const btnTextFormatToolsTogglerClass = styles['btn-text-format-tools-toggler'];
|
|
|
|
|
|
|
|
-
|
|
|
|
|
type TogglarProps = {
|
|
type TogglarProps = {
|
|
|
isOpen: boolean,
|
|
isOpen: boolean,
|
|
|
onClick?: () => void,
|
|
onClick?: () => void,
|
|
@@ -34,10 +34,11 @@ const TextFormatToolsToggler = (props: TogglarProps): JSX.Element => {
|
|
|
|
|
|
|
|
type TextFormatToolsType = {
|
|
type TextFormatToolsType = {
|
|
|
editorKey: string | GlobalCodeMirrorEditorKey,
|
|
editorKey: string | GlobalCodeMirrorEditorKey,
|
|
|
|
|
+ simpleBarRef: React.RefObject<SimpleBar>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
|
|
export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
|
|
|
- const { editorKey } = props;
|
|
|
|
|
|
|
+ const { editorKey, simpleBarRef } = props;
|
|
|
const [isOpen, setOpen] = useState(false);
|
|
const [isOpen, setOpen] = useState(false);
|
|
|
const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(editorKey);
|
|
const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(editorKey);
|
|
|
|
|
|
|
@@ -45,6 +46,12 @@ export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
|
|
|
setOpen(bool => !bool);
|
|
setOpen(bool => !bool);
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
+ const recalculateSimpleBar = useCallback(() => {
|
|
|
|
|
+ if (simpleBarRef.current) {
|
|
|
|
|
+ simpleBarRef.current.recalculate();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [simpleBarRef]);
|
|
|
|
|
+
|
|
|
const onClickInsertMarkdownElements = (prefix: string, suffix: string) => {
|
|
const onClickInsertMarkdownElements = (prefix: string, suffix: string) => {
|
|
|
codeMirrorEditor?.insertMarkdownElements(prefix, suffix);
|
|
codeMirrorEditor?.insertMarkdownElements(prefix, suffix);
|
|
|
};
|
|
};
|
|
@@ -57,7 +64,7 @@ export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
|
|
|
<div className="d-flex">
|
|
<div className="d-flex">
|
|
|
<TextFormatToolsToggler isOpen={isOpen} onClick={toggle} />
|
|
<TextFormatToolsToggler isOpen={isOpen} onClick={toggle} />
|
|
|
|
|
|
|
|
- <Collapse isOpen={isOpen} horizontal>
|
|
|
|
|
|
|
+ <Collapse isOpen={isOpen} horizontal onEntered={recalculateSimpleBar} onExited={recalculateSimpleBar}>
|
|
|
<div className="d-flex px-1 gap-1" style={{ width: '220px' }}>
|
|
<div className="d-flex px-1 gap-1" style={{ width: '220px' }}>
|
|
|
<button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertMarkdownElements('**', '**')}>
|
|
<button type="button" className="btn btn-toolbar-button" onClick={() => onClickInsertMarkdownElements('**', '**')}>
|
|
|
<span className="material-symbols-outlined fs-5">format_bold</span>
|
|
<span className="material-symbols-outlined fs-5">format_bold</span>
|