diff --git a/packages/web/src/designer/ColumnLine.svelte b/packages/web/src/designer/ColumnLine.svelte
index 606b9507..61c9f50b 100644
--- a/packages/web/src/designer/ColumnLine.svelte
+++ b/packages/web/src/designer/ColumnLine.svelte
@@ -11,13 +11,55 @@
export let designerId;
export let onChangeColumn;
export let domLine;
+ export let sourceDragColumn$;
+ export let targetDragColumn$;
+ export let onCreateReference;
$: designerColumn = (designer.columns || []).find(
x => x.designerId == designerId && x.columnName == column.columnName
);
-
+
{
+ const dragData = {
+ ...column,
+ designerId,
+ };
+ sourceDragColumn$.set(dragData);
+ e.dataTransfer.setData('designer_column_drag_data', JSON.stringify(dragData));
+ }}
+ on:dragend={e => {
+ sourceDragColumn$.set(null);
+ targetDragColumn$.set(null);
+ }}
+ on:dragover={e => {
+ if ($sourceDragColumn$) {
+ e.preventDefault();
+ targetDragColumn$.set({
+ ...column,
+ designerId,
+ });
+ }
+ }}
+ on:drop={e => {
+ var data = e.dataTransfer.getData('designer_column_drag_data');
+ e.preventDefault();
+ if (!data) return;
+ onCreateReference($sourceDragColumn$, $targetDragColumn$);
+ sourceDragColumn$.set(null);
+ targetDragColumn$.set(null);
+ }}
+ class:isDragSource={$sourceDragColumn$ &&
+ $sourceDragColumn$.designerId == designerId &&
+ $sourceDragColumn$.columnName == column.columnName}
+ class:isDragTarget={$targetDragColumn$ &&
+ $targetDragColumn$.designerId == designerId &&
+ $targetDragColumn$.columnName == column.columnName}
+>
x.designerId == designerId && x.columnName == column.columnName && x.isOutput
@@ -56,3 +98,15 @@
{/if}
+
+
diff --git a/packages/web/src/designer/Designer.svelte b/packages/web/src/designer/Designer.svelte
index 73c3805a..d51727f4 100644
--- a/packages/web/src/designer/Designer.svelte
+++ b/packages/web/src/designer/Designer.svelte
@@ -10,6 +10,8 @@
import _ from 'lodash';
import createRef from '../utility/createRef';
import DesignerReference from './DesignerReference.svelte';
+ import { writable } from 'svelte/store';
+ import { tick } from 'svelte';
export let value;
export let onChange;
@@ -18,6 +20,9 @@
let domCanvas;
+ const sourceDragColumn$ = writable(null);
+ const targetDragColumn$ = writable(null);
+
$: tables = value?.tables as any[];
$: references = value?.references as any[];
@@ -40,15 +45,20 @@
return tables;
}
+ function callChange(changeFunc, skipUndoChain = undefined) {
+ onChange(changeFunc, skipUndoChain);
+ tick().then(recomputeReferencePositions);
+ }
+
const changeTable = table => {
- onChange(current => ({
+ callChange(current => ({
...current,
tables: fixPositions((current.tables || []).map(x => (x.designerId == table.designerId ? table : x))),
}));
};
const bringToFront = table => {
- onChange(
+ callChange(
current => ({
...current,
tables: [...(current.tables || []).filter(x => x.designerId != table.designerId), table],
@@ -58,7 +68,7 @@
};
const removeTable = table => {
- onChange(current => ({
+ callChange(current => ({
...current,
tables: (current.tables || []).filter(x => x.designerId != table.designerId),
references: (current.references || []).filter(
@@ -69,21 +79,21 @@
};
const changeReference = ref => {
- onChange(current => ({
+ callChange(current => ({
...current,
references: (current.references || []).map(x => (x.designerId == ref.designerId ? ref : x)),
}));
};
const removeReference = ref => {
- onChange(current => ({
+ callChange(current => ({
...current,
references: (current.references || []).filter(x => x.designerId != ref.designerId),
}));
};
const handleCreateReference = (source, target) => {
- onChange(current => {
+ callChange(current => {
const existingReference = (current.references || []).find(
x =>
(x.sourceId == source.designerId && x.targetId == target.designerId) ||
@@ -139,7 +149,7 @@
schemaName: foreignKey.refSchemaName,
});
const newTableDesignerId = uuidv1();
- onChange(current => {
+ callChange(current => {
const fromTable = (current.tables || []).find(x => x.designerId == designerId);
if (!fromTable) return;
return {
@@ -171,7 +181,7 @@
};
const handleSelectColumn = column => {
- onChange(
+ callChange(
current => ({
...current,
columns: (current.columns || []).find(
@@ -185,7 +195,7 @@
};
const handleChangeColumn = (column, changeFunc) => {
- onChange(current => {
+ callChange(current => {
const currentColumns = (current || {}).columns || [];
const existing = currentColumns.find(x => x.designerId == column.designerId && x.columnName == column.columnName);
if (existing) {
@@ -214,7 +224,7 @@
json.left = e.clientX - rect.left;
json.top = e.clientY - rect.top;
- onChange(current => {
+ callChange(current => {
const foreignKeys = _.compact([
...(json.foreignKeys || []).map(fk => {
const tables = ((current || {}).tables || []).filter(
@@ -267,9 +277,9 @@
});
};
- function handleMoveReferences() {
- for(const ref of Object.values(referenceRefs) as any[]) {
- ref.recomputePosition();
+ function recomputeReferencePositions() {
+ for (const ref of Object.values(referenceRefs) as any[]) {
+ if (ref) ref.recomputePosition();
}
}
@@ -308,13 +318,15 @@
onSelectColumn={handleSelectColumn}
onChangeColumn={handleChangeColumn}
onAddReferenceByColumn={handleAddReferenceByColumn}
- onMoveReferences={handleMoveReferences}
+ onMoveReferences={recomputeReferencePositions}
{table}
onChangeTable={changeTable}
onBringToFront={bringToFront}
onRemoveTable={removeTable}
{domCanvas}
designer={value}
+ {sourceDragColumn$}
+ {targetDragColumn$}
/>
{/each}
diff --git a/packages/web/src/designer/DesignerReference.svelte b/packages/web/src/designer/DesignerReference.svelte
index 7195b491..4349fadc 100644
--- a/packages/web/src/designer/DesignerReference.svelte
+++ b/packages/web/src/designer/DesignerReference.svelte
@@ -1,5 +1,7 @@
{#if src && dst && minpos}
@@ -88,7 +117,20 @@
`}
/>
{/each}
- >
+
+
+