({ editor, element, attributes, children })
| 39 | } |
| 40 | |
| 41 | const TableComponent: React.FC<TableProps> = ({ editor, element, attributes, children }) => { |
| 42 | const nodeSelected = useNodeSelected() |
| 43 | |
| 44 | const nodeFocused = useNodeFocused() |
| 45 | |
| 46 | const selection = useGridSelection() |
| 47 | |
| 48 | const selected = useGridSelected() |
| 49 | |
| 50 | const tableRef = React.useRef<HTMLTableElement>(null) |
| 51 | |
| 52 | const dragging = useTableDragging() |
| 53 | |
| 54 | /** |
| 55 | * 部分选中表格,让选中部分选中表格的整行 |
| 56 | */ |
| 57 | useIsomorphicLayoutEffect(() => { |
| 58 | const { selection } = editor |
| 59 | if (selection && nodeSelected && !nodeFocused) { |
| 60 | let { anchor, focus } = selection |
| 61 | const isBackward = Range.isBackward(selection) |
| 62 | const [startRow] = Editor.nodes<TableRow>(editor, { |
| 63 | at: anchor.path, |
| 64 | match: n => TableRowEditor.isTableRow(editor, n), |
| 65 | }) |
| 66 | if (startRow) { |
| 67 | const [row, path] = startRow |
| 68 | const { children: cells } = row |
| 69 | const table = Grid.above(editor, path) |
| 70 | if (table) { |
| 71 | if (isBackward) { |
| 72 | const sel = Grid.edges(editor, table, { |
| 73 | start: [0, 0], |
| 74 | end: [path[path.length - 1], cells.length - 1], |
| 75 | }) |
| 76 | anchor = Editor.start(editor, path.slice(0, -1).concat(sel.end)) |
| 77 | } else { |
| 78 | const sel = Grid.edges(editor, table, { |
| 79 | start: [path[path.length - 1], 0], |
| 80 | end: [table[0].children.length - 1, cells.length - 1], |
| 81 | }) |
| 82 | anchor = Editor.start(editor, path.slice(0, -1).concat(sel.start)) |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | const [endRow] = Editor.nodes<TableRow>(editor, { |
| 87 | at: focus.path, |
| 88 | match: n => TableRowEditor.isTableRow(editor, n), |
| 89 | }) |
| 90 | if (endRow) { |
| 91 | const [row, path] = endRow |
| 92 | const { children: cells } = row |
| 93 | const table = Grid.above(editor, path) |
| 94 | if (table) { |
| 95 | if (isBackward) { |
| 96 | const sel = Grid.edges(editor, table, { |
| 97 | start: [table[0].children.length - 1, cells.length - 1], |
| 98 | end: [path[path.length - 1], 0], |
nothing calls this directly
no test coverage detected
searching dependent graphs…