From ab1dd6f05da0f4d91ebb4dd5fb324f60dccdab28 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Sun, 24 Apr 2022 20:57:24 +0800 Subject: [PATCH] feat: revert table for basic user experience --- .../src/tiptap/extensions/table-cell.tsx | 280 +++++++++--------- .../src/tiptap/extensions/table-header.tsx | 222 +++++++------- .../client/src/tiptap/extensions/table.ts | 58 +--- .../client/src/tiptap/menus/table/bubble.tsx | 4 +- packages/client/src/tiptap/styles/table.scss | 86 ++---- 5 files changed, 270 insertions(+), 380 deletions(-) diff --git a/packages/client/src/tiptap/extensions/table-cell.tsx b/packages/client/src/tiptap/extensions/table-cell.tsx index f0b38c30..1ead13d5 100644 --- a/packages/client/src/tiptap/extensions/table-cell.tsx +++ b/packages/client/src/tiptap/extensions/table-cell.tsx @@ -1,8 +1,8 @@ +import { mergeAttributes } from '@tiptap/core'; +import { TableCell as BuiltInTableCell } from '@tiptap/extension-table-cell'; import ReactDOM from 'react-dom'; import { Button } from '@douyinfe/semi-ui'; import { IconDelete, IconPlus } from '@douyinfe/semi-icons'; -import { mergeAttributes } from '@tiptap/core'; -import { TableCell as BuiltInTableCell } from '@tiptap/extension-table-cell'; import { Tooltip } from 'components/tooltip'; import { Plugin, PluginKey } from 'prosemirror-state'; import { Decoration, DecorationSet } from 'prosemirror-view'; @@ -67,146 +67,146 @@ export const TableCell = BuiltInTableCell.extend({ return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, - addProseMirrorPlugins() { - const extensionThis = this; - let selectedRowIndex = -1; + // addProseMirrorPlugins() { + // const extensionThis = this; + // let selectedRowIndex = -1; - return [ - new Plugin({ - key: new PluginKey(`${this.name}FloatMenu`), - view: () => - new FloatMenuView({ - editor: this.editor, - tippyOptions: { - zIndex: 100, - offset: [-28, 0], - }, - shouldShow: ({ editor }, floatMenuView) => { - if (!editor.isEditable) { - return false; - } - if (isTableSelected(editor.state.selection)) { - return false; - } - const cells = getCellsInColumn(0)(editor.state.selection); - if (selectedRowIndex > -1) { - // 获取当前行的第一个单元格的位置 - const rowCells = getCellsInRow(selectedRowIndex)(editor.state.selection); - if (rowCells && rowCells[0]) { - const node = editor.view.nodeDOM(rowCells[0].pos) as HTMLElement; - if (node) { - const el = node.querySelector('a.grip-row') as HTMLElement; - if (el) { - floatMenuView.parentNode = el; - } - } - } - } - return !!cells?.some((cell, index) => isRowSelected(index)(editor.state.selection)); - }, - init: (dom, editor) => { - dom.classList.add('bubble-memu-table-cell'); - dom.classList.add('row'); - ReactDOM.render( - <> - -