Skip to content

Commit da85174

Browse files
committed
changes for table offset
1 parent da0f084 commit da85174

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/context/DiagramContext.jsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@ export default function DiagramContextProvider({ children }) {
1818

1919
const addTable = (data, addToHistory = true) => {
2020
const id = nanoid();
21+
22+
// Calculate position for new table with offset to avoid overlap
23+
let newPosition = { x: transform.pan.x, y: transform.pan.y };
24+
25+
if (!data && tables.length > 0) {
26+
const lastTable = tables[tables.length - 1];
27+
// Offset by 50px diagonally from the last table
28+
newPosition = {
29+
x: lastTable.x + 50,
30+
y: lastTable.y + 50,
31+
};
32+
}
33+
2134
const newTable = {
2235
id,
2336
name: `table_${id}`,
24-
x: transform.pan.x,
25-
y: transform.pan.y,
37+
x: newPosition.x,
38+
y: newPosition.y,
2639
locked: false,
2740
fields: [
2841
{

0 commit comments

Comments
 (0)