feat(svelte): make edges selectable

This commit is contained in:
moklick
2023-05-17 13:04:28 +02:00
parent bb847b7a77
commit dd8292ce57
10 changed files with 42 additions and 11 deletions
@@ -45,6 +45,7 @@ export function getEdgesLayouted(store: SvelteFlowStoreState) {
res.push({
...edge,
selectable: edge.selectable || typeof edge.selectable === 'undefined',
type: edgeType,
sourceX,
sourceY,
+16
View File
@@ -251,6 +251,21 @@ export function createStore(params: CreateStoreParams): SvelteFlowStore {
);
}
function addSelectedEdges(ids: string[]) {
if (get(store.multiselectionKeyPressed)) {
// @todo handle multiselection key
}
store.edges.update((edges) =>
edges.map((edge) => {
return {
...edge,
selected: ids.includes(edge.id)
};
})
);
}
function panBy(delta: XYPosition) {
const { zoom: d3Zoom, selection: d3Selection } = get(store.d3);
const transform = get(store.transform);
@@ -335,6 +350,7 @@ export function createStore(params: CreateStoreParams): SvelteFlowStore {
setMaxZoom,
resetSelectedElements,
addSelectedNodes,
addSelectedEdges,
panBy,
updateConnection,
cancelConnection,
+1
View File
@@ -27,6 +27,7 @@ export type SvelteFlowStoreActions = {
updateNodeDimensions: (updates: NodeDimensionUpdate[]) => void;
resetSelectedElements: () => void;
addSelectedNodes: (ids: string[]) => void;
addSelectedEdges: (ids: string[]) => void;
panBy: (delta: XYPosition) => void;
updateConnection: (connection: Partial<ConnectionData>) => void;
cancelConnection: () => void;