Skip to content

Commit 43098b3

Browse files
authored
fix table issues (#10207)
Signed-off-by: Alexander Onnikov <[email protected]>
1 parent 9b7be34 commit 43098b3

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

packages/theme/styles/prose.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ table.proseTable {
2323
--table-handle-size: 0.875rem;
2424
--table-handle-indent: calc(var(--table-handle-size) * -1 - 1px);
2525
--table-handle-col-indent: calc(var(--table-handle-size) * -0.5);
26-
--table-handle-row-indent: calc(var(--table-handle-size) * -1 - 0.75rem);
26+
--table-handle-row-indent: calc(var(--table-handle-size) * -1);
2727
--table-insert-marker-indent: calc(-1.25rem - 1px);
2828

2929
--table-selection-z-index: 100;

plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
editor = new Editor({
424424
extensions: [kit],
425425
element,
426-
editable: false,
426+
editable: !readonly,
427427
editorProps: {
428428
attributes: mergeAttributes(defaultEditorAttributes, editorAttributes, { class: 'flex-grow' })
429429
},

plugins/text-editor-resources/src/components/extension/table/TableNodeView.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
&__col {
196196
right: calc(var(--table-offscreen-spacing) - 1.5rem);
197197
top: 0;
198-
bottom: 0;
198+
bottom: 1rem;
199199
margin: 1.5rem 0;
200200
201201
.table-button {
@@ -204,7 +204,7 @@
204204
}
205205
206206
&__row {
207-
bottom: -0.25rem;
207+
bottom: 1rem;
208208
left: var(--table-offscreen-spacing);
209209
right: var(--table-offscreen-spacing);
210210

plugins/text-editor-resources/src/components/extension/table/decorations/columnHandlerDecoration.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,24 @@ class ColumnHandler {
194194
const dropMarker = getDropMarker()
195195
const dragMarker = getColDragMarker()
196196

197+
const handleMove = (event: MouseEvent): void => {
198+
if (dropMarker !== null && dragMarker !== null) {
199+
const currentLeft = startLeft + event.clientX - startX
200+
dropIndex = calculateColumnDropIndex(col, columns, currentLeft)
201+
202+
const dragMarkerWidthPx = columns[col].widthPx
203+
const dragMarkerLeftPx = Math.max(0, Math.min(currentLeft, tableWidthPx - dragMarkerWidthPx))
204+
const dropMarkerLeftPx =
205+
dropIndex <= col ? columns[dropIndex].leftPx : columns[dropIndex].leftPx + columns[dropIndex].widthPx
206+
207+
updateColDropMarker(dropMarker, dropMarkerLeftPx - Math.floor(dropMarkerWidthPx / 2) - 1, dropMarkerWidthPx)
208+
updateColDragMarker(dragMarker, dragMarkerLeftPx, dragMarkerWidthPx)
209+
}
210+
}
211+
197212
const handleFinish = (): void => {
213+
window.removeEventListener('mousemove', handleMove)
214+
198215
if (dropMarker !== null) hideDropMarker(dropMarker)
199216
if (dragMarker !== null) hideDragMarker(dragMarker)
200217

@@ -211,21 +228,6 @@ class ColumnHandler {
211228
}
212229
}
213230

214-
const handleMove = (event: MouseEvent): void => {
215-
if (dropMarker !== null && dragMarker !== null) {
216-
const currentLeft = startLeft + event.clientX - startX
217-
dropIndex = calculateColumnDropIndex(col, columns, currentLeft)
218-
219-
const dragMarkerWidthPx = columns[col].widthPx
220-
const dragMarkerLeftPx = Math.max(0, Math.min(currentLeft, tableWidthPx - dragMarkerWidthPx))
221-
const dropMarkerLeftPx =
222-
dropIndex <= col ? columns[dropIndex].leftPx : columns[dropIndex].leftPx + columns[dropIndex].widthPx
223-
224-
updateColDropMarker(dropMarker, dropMarkerLeftPx - Math.floor(dropMarkerWidthPx / 2) - 1, dropMarkerWidthPx)
225-
updateColDragMarker(dragMarker, dragMarkerLeftPx, dragMarkerWidthPx)
226-
}
227-
}
228-
229231
window.addEventListener('mouseup', handleFinish, { once: true })
230232
window.addEventListener('mousemove', handleMove)
231233
})

plugins/text-editor-resources/src/components/extension/table/decorations/rowHandlerDecoration.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,24 @@ class RowHandler {
194194
const dropMarker = getDropMarker()
195195
const dragMarker = getRowDragMarker()
196196

197+
const handleMove = (event: MouseEvent): void => {
198+
if (dropMarker !== null && dragMarker !== null) {
199+
const cursorTop = startTop + event.clientY - startY
200+
dropIndex = calculateRowDropIndex(row, rows, cursorTop)
201+
202+
const dragMarkerHeightPx = rows[row].heightPx
203+
const dragMarkerTopPx = Math.max(0, Math.min(cursorTop, tableHeightPx - dragMarkerHeightPx))
204+
const dropMarkerTopPx =
205+
dropIndex <= row ? rows[dropIndex].topPx : rows[dropIndex].topPx + rows[dropIndex].heightPx
206+
207+
updateRowDropMarker(dropMarker, dropMarkerTopPx - dropMarkerWidthPx / 2, dropMarkerWidthPx)
208+
updateRowDragMarker(dragMarker, dragMarkerTopPx, dragMarkerHeightPx)
209+
}
210+
}
211+
197212
const handleFinish = (): void => {
213+
window.removeEventListener('mousemove', handleMove)
214+
198215
if (dropMarker !== null) hideDropMarker(dropMarker)
199216
if (dragMarker !== null) hideDragMarker(dragMarker)
200217

@@ -211,21 +228,6 @@ class RowHandler {
211228
}
212229
}
213230

214-
const handleMove = (event: MouseEvent): void => {
215-
if (dropMarker !== null && dragMarker !== null) {
216-
const cursorTop = startTop + event.clientY - startY
217-
dropIndex = calculateRowDropIndex(row, rows, cursorTop)
218-
219-
const dragMarkerHeightPx = rows[row].heightPx
220-
const dragMarkerTopPx = Math.max(0, Math.min(cursorTop, tableHeightPx - dragMarkerHeightPx))
221-
const dropMarkerTopPx =
222-
dropIndex <= row ? rows[dropIndex].topPx : rows[dropIndex].topPx + rows[dropIndex].heightPx
223-
224-
updateRowDropMarker(dropMarker, dropMarkerTopPx - dropMarkerWidthPx / 2, dropMarkerWidthPx)
225-
updateRowDragMarker(dragMarker, dragMarkerTopPx, dragMarkerHeightPx)
226-
}
227-
}
228-
229231
window.addEventListener('mouseup', handleFinish, { once: true })
230232
window.addEventListener('mousemove', handleMove)
231233
})

0 commit comments

Comments
 (0)