Skip to content

Commit f33f157

Browse files
committed
Fixed extend button positions not updating when dragging in some cases
1 parent 5543c56 commit f33f157

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

packages/react/src/components/TableHandles/TableHandlesController.tsx

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,20 @@ export const TableHandlesController = <
4545

4646
const state = useExtensionState(TableHandlesExtension);
4747

48-
const references = useMemo<
49-
| {
50-
tableReference: undefined;
51-
cellReference: undefined;
52-
rowReference: undefined;
53-
columnReference: undefined;
54-
}
55-
| {
56-
tableReference: GenericPopoverReference;
57-
cellReference: GenericPopoverReference;
58-
rowReference: GenericPopoverReference;
59-
columnReference: GenericPopoverReference;
60-
}
61-
>(() => {
62-
if (
63-
state === undefined ||
64-
state.rowIndex === undefined ||
65-
state.colIndex === undefined
66-
) {
48+
const references = useMemo<{
49+
tableReference?: GenericPopoverReference;
50+
cellReference?: GenericPopoverReference;
51+
rowReference?: GenericPopoverReference;
52+
columnReference?: GenericPopoverReference;
53+
}>(() => {
54+
const references: {
55+
tableReference?: GenericPopoverReference;
56+
cellReference?: GenericPopoverReference;
57+
rowReference?: GenericPopoverReference;
58+
columnReference?: GenericPopoverReference;
59+
} = {};
60+
61+
if (state === undefined) {
6762
return {};
6863
}
6964

@@ -85,7 +80,11 @@ export const TableHandlesController = <
8580
return {};
8681
}
8782

88-
const tableReference = { element: tableElement };
83+
references.tableReference = { element: tableElement };
84+
85+
if (state.rowIndex === undefined || state.colIndex === undefined) {
86+
return references;
87+
}
8988

9089
const rowBeforePos = editor.prosemirrorState.doc
9190
.resolve(tableBeforePos + 1)
@@ -99,9 +98,8 @@ export const TableHandlesController = <
9998
return {};
10099
}
101100

102-
const cellReference = { element: cellElement };
103-
104-
const rowReference = {
101+
references.cellReference = { element: cellElement };
102+
references.rowReference = {
105103
element: tableElement,
106104
getBoundingClientRect: () => {
107105
const tableBoundingRect = tableElement.getBoundingClientRect();
@@ -118,7 +116,7 @@ export const TableHandlesController = <
118116
);
119117
},
120118
};
121-
const columnReference = {
119+
references.columnReference = {
122120
element: tableElement,
123121
getBoundingClientRect: () => {
124122
const tableBoundingRect = tableElement.getBoundingClientRect();
@@ -136,12 +134,7 @@ export const TableHandlesController = <
136134
},
137135
};
138136

139-
return {
140-
tableReference,
141-
cellReference,
142-
rowReference,
143-
columnReference,
144-
};
137+
return references;
145138
}, [editor, state]);
146139

147140
const floatingUIOptions = useMemo<

0 commit comments

Comments
 (0)