diff --git a/packages/builder/src/components/backend/RoleEditor/RoleEdge.svelte b/packages/builder/src/components/backend/RoleEditor/RoleEdge.svelte new file mode 100644 index 0000000000..b4076e2281 --- /dev/null +++ b/packages/builder/src/components/backend/RoleEditor/RoleEdge.svelte @@ -0,0 +1,114 @@ + + + + + + + +
(labelHovered = true)} + on:mouseout={() => (labelHovered = false)} + > + +
+
+ + diff --git a/packages/builder/src/components/backend/RoleEditor/RoleEditor.svelte b/packages/builder/src/components/backend/RoleEditor/RoleEditor.svelte index 783dc5a108..d24810f468 100644 --- a/packages/builder/src/components/backend/RoleEditor/RoleEditor.svelte +++ b/packages/builder/src/components/backend/RoleEditor/RoleEditor.svelte @@ -4,14 +4,16 @@ import { SvelteFlow, Background, BackgroundVariant } from "@xyflow/svelte" import "@xyflow/svelte/dist/style.css" import RoleNode from "./RoleNode.svelte" + import RoleEdge from "./RoleEdge.svelte" import { rolesToNodes, autoLayout } from "./layout" import { onMount, setContext } from "svelte" import Controls from "./Controls.svelte" const nodes = writable([]) const edges = writable([]) + const dragging = writable(false) - setContext("flow", { nodes, edges }) + setContext("flow", { nodes, edges, dragging }) onMount(() => { const layout = autoLayout(rolesToNodes()) @@ -33,9 +35,12 @@ {edges} snapGrid={[25, 25]} nodeTypes={{ role: RoleNode }} + edgeTypes={{ role: RoleEdge }} proOptions={{ hideAttribution: true }} fitViewOptions={{ maxZoom: 1 }} - defaultEdgeOptions={{ type: "bezier", animated: true }} + defaultEdgeOptions={{ type: "role", animated: true, selectable: false }} + onconnectstart={() => dragging.set(true)} + onconnectend={() => dragging.set(false)} > @@ -81,6 +86,6 @@ /* Edges */ --xy-edge-stroke: var(--edge-color); - --xy-edge-stroke-selected: var(--selected-color); + --xy-edge-stroke-selected: var(--edge-color); } diff --git a/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte b/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte index e07ab70ff6..2614d609f6 100644 --- a/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte +++ b/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte @@ -16,10 +16,9 @@ import { roles } from "stores/builder" export let data - export let isConnectable export let id - const { nodes, edges } = getContext("flow") + const { nodes, edges, dragging } = getContext("flow") const flow = useSvelteFlow() let anchor @@ -31,6 +30,7 @@ $: nameError = validateName(tempDisplayName, $roles) $: descriptionError = validateDescription(tempDescription) $: invalid = nameError || descriptionError + $: targetClasses = `target${$dragging ? "" : " hidden"}` const validateName = (name, roles) => { if (!name?.length) { @@ -109,10 +109,15 @@ {/if} {#if id !== Roles.BASIC} - + {/if} {#if id !== Roles.ADMIN} - + {/if} @@ -207,4 +212,11 @@ .node:hover .buttons { display: flex; } + .node :global(.svelte-flow__handle.target) { + background: var(--background-color); + } + .node :global(.svelte-flow__handle.hidden) { + opacity: 0; + pointer-events: none; + } diff --git a/packages/builder/src/components/backend/RoleEditor/layout.js b/packages/builder/src/components/backend/RoleEditor/layout.js index 5dae9a3b5c..d721549d48 100644 --- a/packages/builder/src/components/backend/RoleEditor/layout.js +++ b/packages/builder/src/components/backend/RoleEditor/layout.js @@ -62,7 +62,6 @@ export const rolesToNodes = () => { id: `${sourceRole}-${role._id}`, source: sourceRole, target: role._id, - animated: true, }) } } @@ -79,7 +78,7 @@ const dagreLayout = ({ nodes, edges }) => { dagreGraph.setDefaultEdgeLabel(() => ({})) dagreGraph.setGraph({ rankdir: "LR", - ranksep: 100, + ranksep: 200, nodesep: 100, }) nodes.forEach(node => { @@ -122,7 +121,6 @@ const sanitiseLayout = ({ nodes, edges }) => { id: Helpers.uuid(), source: node.id, target: Roles.ADMIN, - animated: true, }) } }