soumaeda 2 лет назад
Родитель
Сommit
ac8896e9de

+ 1 - 1
apps/app/src/components/PageEditor/HandsontableModal.tsx

@@ -102,7 +102,7 @@ export const HandsontableModal = (): JSX.Element => {
   const debouncedHandleWindowExpandedChange = debounce(100, handleWindowExpandedChange);
 
   const handleModalOpen = () => {
-    const initTableInstance = table == null ? defaultMarkdownTable : table;
+    const initTableInstance = table == null ? defaultMarkdownTable : table.clone();
     setMarkdownTable(table ?? defaultMarkdownTable);
     setMarkdownTableOnInit(initTableInstance);
     debouncedHandleWindowExpandedChange();

+ 1 - 1
apps/app/src/components/PageEditor/MarkdownTableUtil.js

@@ -91,7 +91,7 @@ class MarkdownTableUtil {
    */
   getMarkdownTable(editor) {
     if (!this.isInTable(editor)) {
-      return null;
+      return;
     }
 
     const strFromBotToEot = editor.state.sliceDoc(this.getBot(editor), this.getEot(editor));

+ 2 - 5
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -187,13 +187,10 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
 
   const openTableModalHandler = useCallback(() => {
-    const editor = codeMirrorEditor?.view;
+    const editor = codeMirrorEditor.view;
     const markdownTable = mtu.getMarkdownTable(editor);
-    if (markdownTable == null) {
-      return;
-    }
     openHandsontableModal(markdownTable, editor);
-  }, [openHandsontableModal]);
+  }, [codeMirrorEditor.view, openHandsontableModal]);
 
 
   const checkIsConflict = useCallback((data) => {

+ 1 - 1
apps/app/src/stores/modal.tsx

@@ -516,7 +516,7 @@ type HandsontableModalStatus = {
 
 type HandsontableModalStatusUtils = {
   open(
-    table: MarkdownTable,
+    table?: MarkdownTable,
     editor?: any,
     autoFormatMarkdownTable?: boolean,
     onSave?: HandsonTableModalSaveHandler

+ 4 - 1
packages/editor/src/components/CodeMirrorEditor/Toolbar/TableButton.tsx

@@ -4,8 +4,11 @@ type TableButtonProps = {
 
 export const TableButton = (props: TableButtonProps): JSX.Element => {
   const { openTabelModal } = props;
+  const openTabelModalHandler = () => {
+    openTabelModal();
+  };
   return (
-    <button type="button" className="btn btn-toolbar-button" onClick={openTabelModal}>
+    <button type="button" className="btn btn-toolbar-button" onClick={openTabelModalHandler}>
       <span className="material-symbols-outlined fs-5">table_chart</span>
     </button>
   );