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

refactor(admin): host expand read dialog

上级 2f38b3c8
import { Modal } from 'antd'
import ExpandReadDialog from './ExpandReadDialog'
export default function ExpandReadFeatureDialog({ open, onClose, payload, runtime }) {
return <Modal open={open} footer={null} centered destroyOnHidden title="扩展阅读" classNames={{ header: 'editor-header-customer', body: 'editor-body-customer', wrapper: 'editor-wrapper-customer' }} maskClosable={false} onCancel={onClose} width="70%">
<ExpandReadDialog editor={runtime.editor} chapterId={runtime.chapterId} bookId={runtime.bookId} expandInfo={payload} selectionSize={payload.selectionSize || 18} setExpandInfo={() => {}} setExpandVisible={visible => !visible && onClose()} />
</Modal>
}
...@@ -2,6 +2,9 @@ import { defineEditorFeature } from '../../core/define-editor-feature' ...@@ -2,6 +2,9 @@ import { defineEditorFeature } from '../../core/define-editor-feature'
import menu from './menu' import menu from './menu'
import nodeModule from './node' import nodeModule from './node'
import simpleNodeModule from './simple-node' import simpleNodeModule from './simple-node'
import { openEditorDialog } from '../../core/editor-dialog'
import { getSelectionFontSize } from '../../core/selection'
import ExpandReadFeatureDialog from './FeatureDialog'
export default defineEditorFeature({ export default defineEditorFeature({
id: 'expand-read', id: 'expand-read',
...@@ -10,5 +13,6 @@ export default defineEditorFeature({ ...@@ -10,5 +13,6 @@ export default defineEditorFeature({
{ order: 120, types: ['chapterExpandRead'], module: nodeModule }, { order: 120, types: ['chapterExpandRead'], module: nodeModule },
{ order: 130, types: ['chapterExpandReadSimple'], module: simpleNodeModule }, { order: 130, types: ['chapterExpandReadSimple'], module: simpleNodeModule },
], ],
events: [{ name: 'ExpandReadClick', handler: ({ runtime }) => { runtime.captureSelectionFontSize(); runtime.openExpandRead() } }], dialogs: [{ id: 'expand-read.insert', component: ExpandReadFeatureDialog }, { id: 'expand-read.edit', component: ExpandReadFeatureDialog }],
events: [{ name: 'ExpandReadClick', handler: ({ editor }) => openEditorDialog(editor, 'expand-read.insert', { selectionSize: getSelectionFontSize(editor) }) }],
}) })
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
SlateNode, SlateNode,
} from "@wangeditor/editor"; } from "@wangeditor/editor";
import { h } from "snabbdom"; import { h } from "snabbdom";
import { openEditorDialog } from '../../core/editor-dialog'
import iconExpand from "@/assets/images/editor/icon_expand_read.png"; import iconExpand from "@/assets/images/editor/icon_expand_read.png";
import iconClose from "@/assets/images/icon_chapter_close.png"; import iconClose from "@/assets/images/icon_chapter_close.png";
import { findNodeWithParent } from "../../utils/setting"; import { findNodeWithParent } from "../../utils/setting";
...@@ -229,7 +230,7 @@ const renderExpandRead = (elem, children, editor) => { ...@@ -229,7 +230,7 @@ const renderExpandRead = (elem, children, editor) => {
flex, flex,
theme, theme,
}; };
editor.emit("wangeditor-customer:legacy-dialog", { key: "chapterExpand", payload: data }); openEditorDialog(editor, 'expand-read.edit', data)
}, },
}, },
}, },
......
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
SlateNode, SlateNode,
} from "@wangeditor/editor"; } from "@wangeditor/editor";
import { h } from "snabbdom"; import { h } from "snabbdom";
import { openEditorDialog } from '../../core/editor-dialog'
import iconExpand from "@/assets/images/editor/icon_expand_tips.png"; import iconExpand from "@/assets/images/editor/icon_expand_tips.png";
import iconExpandT from "@/assets/images/editor/icon_expand_editor.png"; import iconExpandT from "@/assets/images/editor/icon_expand_editor.png";
...@@ -115,7 +116,7 @@ const renderExpandRead = (elem, children, editor) => { ...@@ -115,7 +116,7 @@ const renderExpandRead = (elem, children, editor) => {
theme, theme,
fontsize, fontsize,
}; };
editor.emit("wangeditor-customer:legacy-dialog", { key: "chapterExpand", payload: data }); openEditorDialog(editor, 'expand-read.edit', data)
}, },
}, },
}, },
......
...@@ -24,7 +24,6 @@ dayjs.extend(relativeTime); ...@@ -24,7 +24,6 @@ dayjs.extend(relativeTime);
import PracticeModal from "../features/practice/PracticeInsertDialog"; import PracticeModal from "../features/practice/PracticeInsertDialog";
import ExpandModal from "../features/expand-read/ExpandReadDialog";
import PracticeSettingModal from "../features/practice/PracticeSettingsDialog"; import PracticeSettingModal from "../features/practice/PracticeSettingsDialog";
...@@ -69,22 +68,16 @@ const WangEditorCustomer = (props, ref) => { ...@@ -69,22 +68,16 @@ const WangEditorCustomer = (props, ref) => {
const [practiceOpenVisible, setPracticeOpenVisible] = useState(false); // 练习 const [practiceOpenVisible, setPracticeOpenVisible] = useState(false); // 练习
const [practiceVisible, setPracticeVisible] = useState(false); // 练习答题设置 const [practiceVisible, setPracticeVisible] = useState(false); // 练习答题设置
const [expandVisible, setExpandVisible] = useState(false); // 扩展阅读
const [expandInfo, setExpandInfo] = useState({}); // 扩展阅读内容
const [priviewVisible, setPreviewVisible] = useState(false); const [priviewVisible, setPreviewVisible] = useState(false);
const [historyVisible, setHistoryVisible] = useState(false); //点击历史 const [historyVisible, setHistoryVisible] = useState(false); //点击历史
const [selectionSize, setSelectionSize] = useState(16); // 当前字号大小
const handleLegacyDialog = ({ key, payload }) => { const handleLegacyDialog = ({ key, payload }) => {
if (key === "practiceNum") { 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);
} else if (key === "chapterExpand") {
setExpandInfo(payload);
setExpandVisible(true);
} }
}; };
...@@ -107,38 +100,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -107,38 +100,6 @@ const WangEditorCustomer = (props, ref) => {
}; };
}); });
const listenNodeStyle = (path) => {
const children = editor.children;
const getNodeFontSize = (targetNode) => {
const element = editor.toDOMNode(targetNode);
const textElement = element.querySelector("[data-slate-string='true']");
const parentNode = editor.getParentNode(targetNode);
const fallbackElement = parentNode ? editor.toDOMNode(parentNode) : element;
return window.getComputedStyle(textElement || fallbackElement).fontSize;
};
let node = null;
if (path[1] === 0) {
node = children[path[0]];
if (node.children.length > 0) {
setSelectionSize(parseInt(getNodeFontSize(node)));
} else {
node = children[path[0]].children[0];
if (node.fontSize) {
setSelectionSize(parseInt(node.fontSize));
} else {
setSelectionSize(parseInt(getNodeFontSize(node)));
}
}
} else {
node = children[path[0]].children[path[1]];
if (node.fontSize) {
setSelectionSize(parseInt(node.fontSize));
} else {
setSelectionSize(parseInt(getNodeFontSize(node)));
}
}
};
// 工具栏配置 // 工具栏配置
const toolbarConfig = { const toolbarConfig = {
toolbarKeys: [ toolbarKeys: [
...@@ -298,10 +259,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -298,10 +259,6 @@ const WangEditorCustomer = (props, ref) => {
const featureRuntime = { const featureRuntime = {
openPractice: () => setPracticeOpenVisible(true), openPractice: () => setPracticeOpenVisible(true),
openExpandRead: () => setExpandVisible(true),
captureSelectionFontSize: () => {
if (editor?.selection) listenNodeStyle(editor.selection.anchor.path)
},
} }
useEditorFeatureEvents({ editor, registry: editorFeatureRegistry, runtime: featureRuntime }) useEditorFeatureEvents({ editor, registry: editorFeatureRegistry, runtime: featureRuntime })
...@@ -410,34 +367,6 @@ const WangEditorCustomer = (props, ref) => { ...@@ -410,34 +367,6 @@ const WangEditorCustomer = (props, ref) => {
/> />
</Modal> </Modal>
{/* 扩展 */}
<Modal
open={expandVisible}
footer={null}
centered
destroyOnHidden
title="扩展阅读"
classNames={{
header: "editor-header-customer",
body: "editor-body-customer",
wrapper: "editor-wrapper-customer",
}}
maskClosable={false}
onCancel={() => setExpandVisible(false)}
width="70%"
>
<ExpandModal
ref={previewRef}
editor={editor}
chapterId={chapterId}
bookId={bookId}
expandInfo={expandInfo}
setExpandInfo={setExpandInfo}
setExpandVisible={setExpandVisible}
selectionSize={selectionSize}
/>
</Modal>
<Modal <Modal
open={practiceVisible} open={practiceVisible}
footer={null} footer={null}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论