darabos commited on
Commit
fc7156e
·
1 Parent(s): 4767f72

Node search on right click?

Browse files
web/src/App.svelte CHANGED
@@ -11,6 +11,7 @@
11
  type Edge,
12
  } from '@xyflow/svelte';
13
  import LynxKiteNode from './LynxKiteNode.svelte';
 
14
  import '@xyflow/svelte/dist/style.css';
15
 
16
  const nodeTypes: NodeTypes = {
@@ -26,12 +27,6 @@
26
  sourcePosition: Position.Right,
27
  targetPosition: Position.Left,
28
  },
29
- {
30
- id: '2',
31
- // type: 'basic',
32
- data: { label: 'World' },
33
- position: { x: 150, y: 150 },
34
- },
35
  {
36
  id: '3',
37
  type: 'basic',
@@ -43,21 +38,48 @@
43
 
44
  const edges = writable<Edge[]>([
45
  {
46
- id: '1-2',
47
- source: '1',
48
- target: '2',
49
  markerEnd: {
50
- type: MarkerType.Arrow
51
  },
52
  },
53
  ]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  </script>
55
 
56
  <div style:height="100vh">
57
- <SvelteFlow {nodes} {edges} {nodeTypes} fitView>
 
 
 
 
 
58
  <Background />
59
  <Controls />
60
  <Background />
61
  <MiniMap />
 
62
  </SvelteFlow>
63
  </div>
 
11
  type Edge,
12
  } from '@xyflow/svelte';
13
  import LynxKiteNode from './LynxKiteNode.svelte';
14
+ import NodeSearch from './NodeSearch.svelte';
15
  import '@xyflow/svelte/dist/style.css';
16
 
17
  const nodeTypes: NodeTypes = {
 
27
  sourcePosition: Position.Right,
28
  targetPosition: Position.Left,
29
  },
 
 
 
 
 
 
30
  {
31
  id: '3',
32
  type: 'basic',
 
38
 
39
  const edges = writable<Edge[]>([
40
  {
41
+ id: '3-1',
42
+ source: '3',
43
+ target: '1',
44
  markerEnd: {
45
+ type: MarkerType.ArrowClosed,
46
  },
47
  },
48
  ]);
49
+
50
+ function onPaneContextMenu({ detail: { event } }) {
51
+ event.preventDefault();
52
+ const width = 500;
53
+ const height = 200;
54
+ showNodeSearch = {
55
+ top: event.clientY < height - 200 ? event.clientY : undefined,
56
+ left: event.clientX < width - 200 ? event.clientX : undefined,
57
+ right: event.clientX >= width - 200 ? width - event.clientX : undefined,
58
+ bottom: event.clientY >= height - 200 ? height - event.clientY : undefined
59
+ };
60
+ showNodeSearch = {
61
+ top: event.clientY,
62
+ left: event.clientX - 150,
63
+ };
64
+ }
65
+ function addNode(node: Node) {
66
+ nodes.update((n) => [...n, node]);
67
+ }
68
+
69
+ let showNodeSearch;
70
  </script>
71
 
72
  <div style:height="100vh">
73
+ <SvelteFlow {nodes} {edges} {nodeTypes} fitView
74
+ on:nodecontextmenu={onPaneContextMenu}
75
+ on:panecontextmenu={onPaneContextMenu}
76
+ on:paneclick={() => showNodeSearch = undefined}
77
+ on:nodeclick={() => showNodeSearch = undefined}
78
+ >
79
  <Background />
80
  <Controls />
81
  <Background />
82
  <MiniMap />
83
+ {#if showNodeSearch}<NodeSearch on:add={addNode} pos={showNodeSearch} />{/if}
84
  </SvelteFlow>
85
  </div>
web/src/LynxKiteNode.svelte CHANGED
@@ -65,7 +65,7 @@
65
  width: calc(100% - 8px);
66
  }
67
  .node-container {
68
- padding: 5px;
69
  }
70
  .lynxkite-node {
71
  box-shadow: 0px 5px 50px 0px rgba(0, 0, 0, 0.3);
 
65
  width: calc(100% - 8px);
66
  }
67
  .node-container {
68
+ padding: 8px;
69
  }
70
  .lynxkite-node {
71
  box-shadow: 0px 5px 50px 0px rgba(0, 0, 0, 0.3);
web/src/NodeSearch.svelte ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let pos;
3
+ console.log({pos});
4
+ function titleClicked() {
5
+ expanded = !expanded;
6
+ }
7
+ </script>
8
+
9
+ <div class="node-search"
10
+ style="top: {pos.top}px; left: {pos.left}px; right: {pos.right}px; bottom: {pos.bottom}px;">
11
+
12
+ Node Search!
13
+ </div>
14
+
15
+ <style>
16
+ .node-search {
17
+ position: absolute;
18
+ width: 300px;
19
+ z-index: 5;
20
+ padding: 8px;
21
+ border-radius: 4px;
22
+ border: 1px solid #888;
23
+ background-color: white;
24
+ }
25
+ </style>
web/src/app.css CHANGED
@@ -3,3 +3,21 @@
3
  line-height: 1.5;
4
  font-weight: 400;
5
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  line-height: 1.5;
4
  font-weight: 400;
5
  }
6
+ path.svelte-flow__edge-path {
7
+ stroke-width: 2;
8
+ stroke: black;
9
+ }
10
+ .svelte-flow__edge.selected path.svelte-flow__edge-path {
11
+ stroke-width: 5;
12
+ stroke: black;
13
+ }
14
+ .svelte-flow__handle {
15
+ border-color: black;
16
+ background: white;
17
+ width: 10px;
18
+ height: 10px;
19
+ }
20
+ .svelte-flow__arrowhead * {
21
+ stroke: none;
22
+ fill: black;
23
+ }