forked from 77media/video-flow
Merge branch 'dev' of https://git.qikongjian.com/77media/video-flow into dev
This commit is contained in:
commit
2dd926d0a1
@ -312,6 +312,7 @@ export class TextToShotAdapter {
|
|||||||
public static fromRoleToText(paragraphs: Paragraph[]): string {
|
public static fromRoleToText(paragraphs: Paragraph[]): string {
|
||||||
let text = '';
|
let text = '';
|
||||||
paragraphs.forEach(paragraph => {
|
paragraphs.forEach(paragraph => {
|
||||||
|
if (paragraph?.content) {
|
||||||
paragraph.content.forEach(node => {
|
paragraph.content.forEach(node => {
|
||||||
if (node.type === 'highlightText') {
|
if (node.type === 'highlightText') {
|
||||||
text += node.attrs.text;
|
text += node.attrs.text;
|
||||||
@ -321,6 +322,7 @@ export class TextToShotAdapter {
|
|||||||
text += node.attrs.name;
|
text += node.attrs.name;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,9 +117,6 @@ const [pendingSwitchTabId, setPendingSwitchTabId] = useState<string | null>(null
|
|||||||
// 切换前 检查是否更新
|
// 切换前 检查是否更新
|
||||||
const isUpdate = checkUpdate(tabId);
|
const isUpdate = checkUpdate(tabId);
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
// setPendingSwitchTabId(tabId); // 记录要切换到的目标tab
|
|
||||||
// setRemindFallbackText('You must click Apply button to save the current changes.');
|
|
||||||
// setIsRemindFallbackOpen(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setActiveTab(tabId);
|
setActiveTab(tabId);
|
||||||
@ -129,8 +126,12 @@ const [pendingSwitchTabId, setPendingSwitchTabId] = useState<string | null>(null
|
|||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
console.log('handleSave');
|
console.log('handleSave');
|
||||||
// setIsRemindFallbackOpen(true);
|
// setIsRemindFallbackOpen(true);
|
||||||
if (activeTab === '1') {
|
if (activeTab === '0') {
|
||||||
|
scriptTabContentRef.current.saveBefore();
|
||||||
|
} else if (activeTab === '1') {
|
||||||
characterTabContentRef.current.saveBefore();
|
characterTabContentRef.current.saveBefore();
|
||||||
|
} else if (activeTab === '3') {
|
||||||
|
handleConfirmGotoFallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,35 +13,84 @@ export default function MainEditor({ content, onChangeContent }: MainEditorProps
|
|||||||
const [renderContent, setRenderContent] = useState<any[]>(content);
|
const [renderContent, setRenderContent] = useState<any[]>(content);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onChangeContent?.(renderContent);;
|
onChangeContent?.(renderContent);
|
||||||
}, [renderContent]);
|
}, [renderContent]);
|
||||||
|
|
||||||
const editor = useEditor({
|
const editor = useEditor({
|
||||||
extensions: [
|
extensions: [
|
||||||
StarterKit,
|
StarterKit.configure({
|
||||||
|
paragraph: {
|
||||||
|
HTMLAttributes: {
|
||||||
|
class: 'paragraph'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
HighlightTextExtension,
|
HighlightTextExtension,
|
||||||
],
|
],
|
||||||
content: { type: 'doc', content: renderContent },
|
content: {
|
||||||
|
type: 'doc',
|
||||||
|
content: renderContent.length === 0 ? [{ type: 'paragraph', content: [] }] : renderContent
|
||||||
|
},
|
||||||
editorProps: {
|
editorProps: {
|
||||||
attributes: {
|
attributes: {
|
||||||
class: 'prose prose-invert max-w-none focus:outline-none'
|
class: 'prose prose-invert max-w-none focus:outline-none'
|
||||||
|
},
|
||||||
|
handleDOMEvents: {
|
||||||
|
keydown: (view, event) => {
|
||||||
|
// 如果内容为空且按下删除键或退格键,阻止默认行为
|
||||||
|
if (
|
||||||
|
(event.key === 'Backspace' || event.key === 'Delete') &&
|
||||||
|
editor?.isEmpty
|
||||||
|
) {
|
||||||
|
event.preventDefault();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
immediatelyRender: false,
|
|
||||||
onCreate: ({ editor }) => {
|
onCreate: ({ editor }) => {
|
||||||
editor.setOptions({ editable: true })
|
editor.setOptions({ editable: true });
|
||||||
},
|
},
|
||||||
onUpdate: ({ editor }) => {
|
onUpdate: ({ editor }) => {
|
||||||
|
try {
|
||||||
const json = editor.getJSON();
|
const json = editor.getJSON();
|
||||||
|
// 确保至少有一个空段落
|
||||||
|
const safeContent = json.content.length === 0
|
||||||
|
? [{ type: 'paragraph', content: [] }]
|
||||||
|
: json.content;
|
||||||
|
|
||||||
flushSync(() => {
|
flushSync(() => {
|
||||||
setRenderContent(json.content);
|
setRenderContent(safeContent);
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Editor update error:', error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
immediatelyRender: false, // 解决 SSR 水合问题
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!editor) {
|
// 监听编辑器内容变化,确保始终有一个段落
|
||||||
return null
|
useEffect(() => {
|
||||||
|
const handleEmpty = () => {
|
||||||
|
if (editor?.isEmpty) {
|
||||||
|
editor.commands.setContent([{
|
||||||
|
type: 'paragraph',
|
||||||
|
content: []
|
||||||
|
}]);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
editor?.on('update', handleEmpty);
|
||||||
|
return () => {
|
||||||
|
editor?.off('update', handleEmpty);
|
||||||
|
};
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
if (!editor) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditorContent editor={editor} />
|
<EditorContent editor={editor} />
|
||||||
);
|
);
|
||||||
|
|||||||
@ -15,7 +15,7 @@ interface ScriptTabContentProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ScriptTabContent = forwardRef<
|
export const ScriptTabContent = forwardRef<
|
||||||
{ switchBefore: (tabId: string) => boolean },
|
{ switchBefore: (tabId: string) => boolean, saveBefore: () => void },
|
||||||
ScriptTabContentProps
|
ScriptTabContentProps
|
||||||
>((props, ref) => {
|
>((props, ref) => {
|
||||||
const { setIsPauseWorkFlow, isPauseWorkFlow, originalText, onApply, setActiveTab } = props;
|
const { setIsPauseWorkFlow, isPauseWorkFlow, originalText, onApply, setActiveTab } = props;
|
||||||
@ -39,6 +39,12 @@ export const ScriptTabContent = forwardRef<
|
|||||||
}
|
}
|
||||||
return isUpdate;
|
return isUpdate;
|
||||||
},
|
},
|
||||||
|
saveBefore: () => {
|
||||||
|
console.log('saveBefore');
|
||||||
|
if (isUpdate) {
|
||||||
|
onApply();
|
||||||
|
}
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const handleApply = () => {
|
const handleApply = () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user