提交 a24389d3 authored 作者: 王鹏飞's avatar 王鹏飞

refactor(admin): host chapter structure dialogs

上级 3a33655a
import { Modal } from 'antd'
import TitleDialog from './TitleDialog'
import SectionDialog from './SectionDialog'
const classNames = { header: 'editor-header-customer', body: 'editor-body-customer', wrapper: 'editor-wrapper-customer' }
export function ChapterTitleFeatureDialog({ open, onClose, payload, runtime }) {
return <Modal open={open} footer={null} centered destroyOnHidden title="插入章头" classNames={classNames} maskClosable={false} onCancel={onClose}>
<TitleDialog editor={runtime.editor} titleInfo={payload} setTitleInfo={() => {}} setTitleVisible={visible => !visible && onClose()} />
</Modal>
}
export function ChapterSectionFeatureDialog({ open, onClose, payload, runtime }) {
return <Modal open={open} footer={null} centered destroyOnHidden title="插入节头" classNames={classNames} maskClosable={false} onCancel={onClose}>
<SectionDialog editor={runtime.editor} sectionInfo={payload} setSectionInfo={() => {}} setSectionVisible={visible => !visible && onClose()} />
</Modal>
}
...@@ -3,6 +3,8 @@ import itemMenu from './section-menu' ...@@ -3,6 +3,8 @@ import itemMenu from './section-menu'
import titleMenu from './title-menu' import titleMenu from './title-menu'
import sectionNodeModule from './section-node' import sectionNodeModule from './section-node'
import headerNodeModule from './title-node' import headerNodeModule from './title-node'
import { openEditorDialog } from '../../core/editor-dialog'
import { ChapterTitleFeatureDialog, ChapterSectionFeatureDialog } from './FeatureDialogs'
export default defineEditorFeature({ export default defineEditorFeature({
id: 'chapter-structure', id: 'chapter-structure',
...@@ -11,8 +13,12 @@ export default defineEditorFeature({ ...@@ -11,8 +13,12 @@ export default defineEditorFeature({
{ order: 10, types: ['chapterSection'], module: sectionNodeModule }, { order: 10, types: ['chapterSection'], module: sectionNodeModule },
{ order: 20, types: ['chapterHeader'], module: headerNodeModule }, { order: 20, types: ['chapterHeader'], module: headerNodeModule },
], ],
dialogs: [
{ id: 'chapter-structure.title', component: ChapterTitleFeatureDialog },
{ id: 'chapter-structure.section', component: ChapterSectionFeatureDialog },
],
events: [ events: [
{ name: 'ChapterItemMenuClick', handler: ({ runtime }) => runtime.openSection() }, { name: 'ChapterItemMenuClick', handler: ({ editor }) => openEditorDialog(editor, 'chapter-structure.section') },
{ name: 'ChapterTitleClick', handler: ({ runtime }) => runtime.openTitle() }, { name: 'ChapterTitleClick', handler: ({ editor }) => openEditorDialog(editor, 'chapter-structure.title') },
], ],
}) })
import { DomEditor, SlateTransforms } from "@wangeditor/editor"; import { DomEditor, SlateTransforms } from "@wangeditor/editor";
import iconClose from "@/assets/images/icon_chapter_close.png"; import iconClose from "@/assets/images/icon_chapter_close.png";
import { h } from "snabbdom"; import { h } from "snabbdom";
import { openEditorDialog } from '../../core/editor-dialog'
import { findNodeWithParent } from "../../utils/setting"; import { findNodeWithParent } from "../../utils/setting";
const withChapterSectionNode = (editor) => { const withChapterSectionNode = (editor) => {
...@@ -117,7 +118,7 @@ const renderChapterSection = (elem, children, editor) => { ...@@ -117,7 +118,7 @@ const renderChapterSection = (elem, children, editor) => {
size: size, size: size,
family: family, family: family,
}; };
editor.emit("wangeditor-customer:legacy-dialog", { key: "chapterItemNum", payload: data }); openEditorDialog(editor, 'chapter-structure.section', data)
callback && callback(data); callback && callback(data);
} /* 其他... */, } /* 其他... */,
}, },
......
import { DomEditor, SlateTransforms } from "@wangeditor/editor"; import { DomEditor, SlateTransforms } from "@wangeditor/editor";
import iconClose from "@/assets/images/icon_chapter_close.png"; import iconClose from "@/assets/images/icon_chapter_close.png";
import { h } from "snabbdom"; import { h } from "snabbdom";
import { openEditorDialog } from '../../core/editor-dialog'
import { findNodeWithParent } from "../../utils/setting"; import { findNodeWithParent } from "../../utils/setting";
const withChapterHeaderNode = (editor) => { const withChapterHeaderNode = (editor) => {
...@@ -123,7 +124,7 @@ const renderChapterHeader = (elem, children, editor) => { ...@@ -123,7 +124,7 @@ const renderChapterHeader = (elem, children, editor) => {
size: size, size: size,
family: family, family: family,
}; };
editor.emit("wangeditor-customer:legacy-dialog", { key: "chapterTitleNum", payload: data }); openEditorDialog(editor, 'chapter-structure.title', data)
callback && callback(data); callback && callback(data);
} /* 其他... */, } /* 其他... */,
}, },
......
...@@ -23,8 +23,6 @@ import relativeTime from "dayjs/plugin/relativeTime"; ...@@ -23,8 +23,6 @@ import relativeTime from "dayjs/plugin/relativeTime";
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
import ChapterTitleModal from "../features/chapter-structure/TitleDialog";
import ChapterItemModal from "../features/chapter-structure/SectionDialog";
import PracticeModal from "../features/practice/PracticeInsertDialog"; import PracticeModal from "../features/practice/PracticeInsertDialog";
import TooltipModal from "../features/tooltip/TooltipDialog"; import TooltipModal from "../features/tooltip/TooltipDialog";
import LinkModal from "../features/link/LinkDialog"; import LinkModal from "../features/link/LinkDialog";
...@@ -71,10 +69,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -71,10 +69,6 @@ const WangEditorCustomer = (props, ref) => {
const [content, setContent] = useState(html); const [content, setContent] = useState(html);
const saveRef = useRef(); const saveRef = useRef();
const [titleVisible, setTitleVisible] = useState(false); // 章头
const [titleInfo, setTitleInfo] = useState({});
const [sectionVisible, setSectionVisible] = useState(false);
const [sectionInfo, setSectionInfo] = useState({}); // 节头
const [practiceOpenVisible, setPracticeOpenVisible] = useState(false); // 练习 const [practiceOpenVisible, setPracticeOpenVisible] = useState(false); // 练习
const [practiceVisible, setPracticeVisible] = useState(false); // 练习答题设置 const [practiceVisible, setPracticeVisible] = useState(false); // 练习答题设置
const [tooltipVisible, setTooltipVisible] = useState(false); // 气泡框 const [tooltipVisible, setTooltipVisible] = useState(false); // 气泡框
...@@ -90,13 +84,7 @@ const WangEditorCustomer = (props, ref) => { ...@@ -90,13 +84,7 @@ const WangEditorCustomer = (props, ref) => {
const [selectionSize, setSelectionSize] = useState(16); // 当前字号大小 const [selectionSize, setSelectionSize] = useState(16); // 当前字号大小
const handleLegacyDialog = ({ key, payload }) => { const handleLegacyDialog = ({ key, payload }) => {
if (key === "chapterTitleNum") { if (key === "practiceNum") {
setTitleInfo(payload);
setTitleVisible(true);
} else if (key === "chapterItemNum") {
setSectionInfo(payload);
setSectionVisible(true);
} else if (key === "practiceNum") {
const { practiceNum, title, theme } = payload; const { practiceNum, title, theme } = payload;
dispatch(setPracticeRandom({ practiceNum, practiceTitle: title, practiceTheme: theme })); dispatch(setPracticeRandom({ practiceNum, practiceTitle: title, practiceTheme: theme }));
setPracticeVisible(true); setPracticeVisible(true);
...@@ -235,8 +223,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -235,8 +223,6 @@ const WangEditorCustomer = (props, ref) => {
}; };
const tooltipRef = useRef(); const tooltipRef = useRef();
const chapterTitleRef = useRef();
const chapterItemRef = useRef();
const practiceRef = useRef(); const practiceRef = useRef();
const practiceSettingRef = useRef(); const practiceSettingRef = useRef();
const previewRef = useRef(); const previewRef = useRef();
...@@ -324,8 +310,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -324,8 +310,6 @@ const WangEditorCustomer = (props, ref) => {
}; };
const featureRuntime = { const featureRuntime = {
openTitle: () => setTitleVisible(true),
openSection: () => setSectionVisible(true),
openPractice: () => setPracticeOpenVisible(true), openPractice: () => setPracticeOpenVisible(true),
openTooltip: () => setTooltipVisible(true), openTooltip: () => setTooltipVisible(true),
openLink: () => setLinkVisible(true), openLink: () => setLinkVisible(true),
...@@ -417,52 +401,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -417,52 +401,6 @@ const WangEditorCustomer = (props, ref) => {
/> />
</div> </div>
{!isView && <EditorSidebar editor={editor} toolbarConfig={toolbarConfig} toolbarRef={toolbarRef} tabKey={tabKey} onTabChange={tabKeyChange} colorList={colorList} onApplyColor={setColor} />} {!isView && <EditorSidebar editor={editor} toolbarConfig={toolbarConfig} toolbarRef={toolbarRef} tabKey={tabKey} onTabChange={tabKeyChange} colorList={colorList} onApplyColor={setColor} />}
<Modal
open={titleVisible}
footer={null}
centered
destroyOnHidden
title="插入章头"
classNames={{
header: "editor-header-customer",
body: "editor-body-customer",
wrapper: "editor-wrapper-customer",
}}
maskClosable={false}
onCancel={() => setTitleVisible(false)}
>
<ChapterTitleModal
ref={chapterTitleRef}
editor={editor}
setTitleVisible={setTitleVisible}
titleInfo={titleInfo}
setTitleInfo={setTitleInfo}
/>
</Modal>
<Modal
open={sectionVisible}
footer={null}
centered
destroyOnHidden
title="插入节头"
classNames={{
header: "editor-header-customer",
body: "editor-body-customer",
wrapper: "editor-wrapper-customer",
}}
maskClosable={false}
onCancel={() => setSectionVisible(false)}
>
<ChapterItemModal
ref={chapterItemRef}
editor={editor}
setSectionVisible={setSectionVisible}
sectionInfo={sectionInfo}
setSectionInfo={setSectionInfo}
/>
</Modal>
{/* 插入练习 */} {/* 插入练习 */}
<Modal <Modal
open={practiceOpenVisible} open={practiceOpenVisible}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论