({
editor,
table,
left,
top,
height,
width,
index,
})
| 148 | } |
| 149 | // split action |
| 150 | const SplitActionDefault: React.FC<TableActionProps> = ({ |
| 151 | editor, |
| 152 | table, |
| 153 | left, |
| 154 | top, |
| 155 | height, |
| 156 | width, |
| 157 | index, |
| 158 | }) => { |
| 159 | if (height !== undefined) { |
| 160 | height += 8 |
| 161 | } |
| 162 | if (width !== undefined) { |
| 163 | width += 8 |
| 164 | } |
| 165 | // 宽/高度为3,所以得减1居中 |
| 166 | if (left !== undefined) { |
| 167 | left -= 1 |
| 168 | } |
| 169 | if (top !== undefined) { |
| 170 | top -= 1 |
| 171 | } |
| 172 | const type = left !== undefined ? TYPE_COL : TYPE_ROW |
| 173 | |
| 174 | const dragRef = React.useRef<TableDragSplitOptions | null>(null) |
| 175 | const { minColWidth = defaultTableMinColWidth, minRowHeight = defaultTableMinRowHeight } = |
| 176 | useTableOptions(editor) |
| 177 | const [isHover, setHover] = React.useState(false) |
| 178 | const isDrag = React.useRef(false) |
| 179 | |
| 180 | const handleDragSplitMove = React.useCallback( |
| 181 | (e: MouseEvent) => { |
| 182 | if (!dragRef.current) return |
| 183 | const { type, x, y, start } = dragRef.current |
| 184 | const path = Editable.findPath(editor, table) |
| 185 | if (type === TYPE_COL) { |
| 186 | const { colsWidth } = table |
| 187 | if (!colsWidth) return |
| 188 | const cX = e.clientX |
| 189 | const val = cX - x |
| 190 | const newColsWidth = colsWidth.concat() |
| 191 | let width = newColsWidth[start] + val |
| 192 | width = Math.max(width, minColWidth) |
| 193 | if (start < newColsWidth.length - 1) { |
| 194 | width = Math.min(newColsWidth[start] + newColsWidth[start + 1] - minColWidth, width) |
| 195 | let nextW = newColsWidth[start + 1] - val |
| 196 | nextW = Math.max(nextW, minColWidth) |
| 197 | nextW = Math.min(newColsWidth[start] + newColsWidth[start + 1] - minColWidth, nextW) |
| 198 | newColsWidth[start + 1] = nextW |
| 199 | } |
| 200 | newColsWidth[start] = width |
| 201 | Transforms.setNodes<Grid>(editor, { colsWidth: newColsWidth }, { at: path }) |
| 202 | } else if (type === TYPE_ROW) { |
| 203 | const row = table.children[start] |
| 204 | const { height, children: cells } = row |
| 205 | if (height) { |
| 206 | const ch = RowStore.getContentHeight(row) |
| 207 | const cY = e.clientY |
nothing calls this directly
no test coverage detected
searching dependent graphs…