mirror of
https://github.com/muerwre/markdown-home-tab.git
synced 2025-04-25 00:46:41 +07:00
added empty editor view and rich editor switch
This commit is contained in:
parent
3f81f6d3b3
commit
a08ebe2cbc
6 changed files with 82 additions and 17 deletions
25
src/modules/editor/components/EmptyViewer/index.tsx
Normal file
25
src/modules/editor/components/EmptyViewer/index.tsx
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { FC } from "react";
|
||||||
|
import styles from "./styles.module.scss";
|
||||||
|
import { useContainerPaddings } from "~/modules/theme/hooks/useContainerPaddings";
|
||||||
|
|
||||||
|
interface EmptyViewerProps {
|
||||||
|
startEditing?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EmptyViewer: FC<EmptyViewerProps> = ({ startEditing }) => {
|
||||||
|
const style = useContainerPaddings();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.empty} style={style}>
|
||||||
|
<div className={styles.title}>Nothing's here</div>
|
||||||
|
<div>
|
||||||
|
<small>
|
||||||
|
<a href="javascript:void();" onClick={startEditing}>
|
||||||
|
start editing
|
||||||
|
</a>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export { EmptyViewer };
|
19
src/modules/editor/components/EmptyViewer/styles.module.scss
Normal file
19
src/modules/editor/components/EmptyViewer/styles.module.scss
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
.empty {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.25s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
|
@ -1,35 +1,50 @@
|
||||||
import { FC } from "react";
|
import { FC, Suspense, lazy } from "react";
|
||||||
import { ReactMarkdownEditor } from "../../components/ReactMarkdownEditor";
|
import { ReactMarkdownEditor } from "../../components/ReactMarkdownEditor";
|
||||||
import { ReactMarkdownViewer } from "../../components/ReactMarkdownViewer";
|
import { ReactMarkdownViewer } from "../../components/ReactMarkdownViewer";
|
||||||
import { usePersistedValue } from "./hooks/usePersistedValue";
|
import { usePersistedValue } from "./hooks/usePersistedValue";
|
||||||
import styles from "./styles.module.scss";
|
import styles from "./styles.module.scss";
|
||||||
|
import { useSettings } from "~/modules/settings/context/SettingsContext";
|
||||||
|
import { EmptyViewer } from "../../components/EmptyViewer";
|
||||||
|
|
||||||
interface MarkdownEditorContainerProps {
|
interface MarkdownEditorContainerProps {
|
||||||
id: string;
|
id: string;
|
||||||
locked: boolean;
|
locked: boolean;
|
||||||
|
startEditing: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RichEditor = lazy(() =>
|
||||||
|
import("../../components/RemirrorEditor").then((module) => ({
|
||||||
|
default: module.RemirrorEditor,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
export const MarkdownEditorContainer: FC<MarkdownEditorContainerProps> = ({
|
export const MarkdownEditorContainer: FC<MarkdownEditorContainerProps> = ({
|
||||||
id,
|
id,
|
||||||
locked,
|
locked,
|
||||||
|
startEditing,
|
||||||
}) => {
|
}) => {
|
||||||
|
const {
|
||||||
|
settings: { richEditorEnabled },
|
||||||
|
} = useSettings();
|
||||||
|
|
||||||
const [value, setValue] = usePersistedValue(id, "MarkdownEditorContainer");
|
const [value, setValue] = usePersistedValue(id, "MarkdownEditorContainer");
|
||||||
|
|
||||||
|
const empty = !value.trim();
|
||||||
|
|
||||||
|
const viewer = empty ? (
|
||||||
|
<EmptyViewer startEditing={startEditing} />
|
||||||
|
) : (
|
||||||
|
<ReactMarkdownViewer value={value} />
|
||||||
|
);
|
||||||
|
|
||||||
|
const editor = richEditorEnabled ? (
|
||||||
|
<RichEditor value={value} onChange={setValue} locked={locked} />
|
||||||
|
) : (
|
||||||
|
<ReactMarkdownEditor value={value} onChange={setValue} />
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div className={styles.editor}>
|
<div className={styles.editor}>
|
||||||
{/*
|
<Suspense>{locked ? viewer : editor}</Suspense>
|
||||||
locked ? (
|
|
||||||
<ReactMarkdownViewer value={value} />
|
|
||||||
) : (
|
|
||||||
<ReactMarkdownEditor value={value} onChange={setValue} />
|
|
||||||
)
|
|
||||||
*/}
|
|
||||||
{locked ? (
|
|
||||||
<ReactMarkdownViewer value={value} />
|
|
||||||
) : (
|
|
||||||
<ReactMarkdownEditor value={value} onChange={setValue} />
|
|
||||||
// <RemirrorEditor value={value} onChange={setValue} locked={locked} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,6 +63,7 @@ const DefaultLayout = ({
|
||||||
id: panelProps.api.id,
|
id: panelProps.api.id,
|
||||||
title: panelProps.params.title,
|
title: panelProps.params.title,
|
||||||
locked,
|
locked,
|
||||||
|
startEditing: lock,
|
||||||
})}
|
})}
|
||||||
</GridLayoutItemWrapper>
|
</GridLayoutItemWrapper>
|
||||||
);
|
);
|
||||||
|
@ -81,7 +82,7 @@ export const GridLayout: FC<GridLayoutProps> = ({ component }) => {
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
[component]
|
[component, persistLayout]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -2,4 +2,5 @@ export interface GridLayoutComponentProps {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
locked: boolean;
|
locked: boolean;
|
||||||
|
startEditing: () => void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
export type SettingsValue = Record<string, never>;
|
export type SettingsValue = {
|
||||||
export const defaultSettings: SettingsValue = {};
|
richEditorEnabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultSettings: SettingsValue = { richEditorEnabled: false };
|
||||||
|
|
||||||
export const SettingsContext = createContext({
|
export const SettingsContext = createContext({
|
||||||
settings: defaultSettings,
|
settings: defaultSettings,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue