|
|
@ -1,4 +1,4 @@
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { marked } from "../labs/marked";
|
|
|
|
import { marked } from "../labs/marked";
|
|
|
|
import Icon from "./Icon";
|
|
|
|
import Icon from "./Icon";
|
|
|
@ -28,10 +28,12 @@ const defaultDisplayConfig: DisplayConfig = {
|
|
|
|
enableExpand: true,
|
|
|
|
enableExpand: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const MAX_MEMO_CONTAINER_HEIGHT = 384;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MemoContent: React.FC<Props> = (props: Props) => {
|
|
|
|
const MemoContent: React.FC<Props> = (props: Props) => {
|
|
|
|
const { className, content, onMemoContentClick, onMemoContentDoubleClick } = props;
|
|
|
|
const { className, content, onMemoContentClick, onMemoContentDoubleClick } = props;
|
|
|
|
|
|
|
|
const foldedContent = useMemo(() => {
|
|
|
|
|
|
|
|
const firstHorizontalRuleIndex = content.search(/^---$|^\*\*\*$|^___$/m);
|
|
|
|
|
|
|
|
return firstHorizontalRuleIndex !== -1 ? content.slice(0, firstHorizontalRuleIndex) : content;
|
|
|
|
|
|
|
|
}, [content]);
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const [isFoldingEnabled] = useLocalStorage(SETTING_IS_FOLDING_ENABLED_KEY, IS_FOLDING_ENABLED_DEFAULT_VALUE);
|
|
|
|
const [isFoldingEnabled] = useLocalStorage(SETTING_IS_FOLDING_ENABLED_KEY, IS_FOLDING_ENABLED_DEFAULT_VALUE);
|
|
|
|
const [state, setState] = useState<State>({
|
|
|
|
const [state, setState] = useState<State>({
|
|
|
@ -49,7 +51,7 @@ const MemoContent: React.FC<Props> = (props: Props) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (displayConfig.enableExpand && isFoldingEnabled) {
|
|
|
|
if (displayConfig.enableExpand && isFoldingEnabled) {
|
|
|
|
if (Number(memoContentContainerRef.current?.clientHeight) > MAX_MEMO_CONTAINER_HEIGHT) {
|
|
|
|
if (foldedContent.length !== content.length) {
|
|
|
|
setState({
|
|
|
|
setState({
|
|
|
|
...state,
|
|
|
|
...state,
|
|
|
|
expandButtonStatus: 0,
|
|
|
|
expandButtonStatus: 0,
|
|
|
@ -84,7 +86,7 @@ const MemoContent: React.FC<Props> = (props: Props) => {
|
|
|
|
className={`memo-content-text ${state.expandButtonStatus === 0 ? "expanded" : ""}`}
|
|
|
|
className={`memo-content-text ${state.expandButtonStatus === 0 ? "expanded" : ""}`}
|
|
|
|
onClick={handleMemoContentClick}
|
|
|
|
onClick={handleMemoContentClick}
|
|
|
|
onDoubleClick={handleMemoContentDoubleClick}
|
|
|
|
onDoubleClick={handleMemoContentDoubleClick}
|
|
|
|
dangerouslySetInnerHTML={{ __html: marked(content) }}
|
|
|
|
dangerouslySetInnerHTML={{ __html: marked(state.expandButtonStatus === 0 ? foldedContent : content) }}
|
|
|
|
></div>
|
|
|
|
></div>
|
|
|
|
{state.expandButtonStatus !== -1 && (
|
|
|
|
{state.expandButtonStatus !== -1 && (
|
|
|
|
<div className="expand-btn-container">
|
|
|
|
<div className="expand-btn-container">
|
|
|
|