Skip to content

Commit 16faafb

Browse files
authored
Merge pull request #105 from Jcparkyn/dev
Update to v1.3.0
2 parents c83848b + 9271df2 commit 16faafb

39 files changed

+609
-367
lines changed

Nodexr.Tests/FakeNodeOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FakeNodeOutput : INodeOutput
1313

1414
public event EventHandler OutputChanged;
1515

16-
public Vector2L OutputPos => throw new NotImplementedException();
16+
public Vector2 OutputPos => throw new NotImplementedException();
1717

1818
public string CssName => throw new NotImplementedException();
1919

Nodexr/Nodexr.csproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0" PrivateAssets="all" />
2828
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0" PrivateAssets="all" />
2929
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
30+
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="3.9.7">
31+
<PrivateAssets>all</PrivateAssets>
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33+
</PackageReference>
3034
<PackageReference Include="Pidgin" Version="2.4.0" />
3135
<PackageReference Include="Roslynator.Analyzers" Version="2.3.0">
3236
<PrivateAssets>all</PrivateAssets>
@@ -35,5 +39,26 @@
3539
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
3640

3741
</ItemGroup>
42+
43+
<ItemGroup>
44+
<TypeScriptCompile Include="wwwroot\js\ClipboardCopy.ts" />
45+
<TypeScriptCompile Include="wwwroot\js\NoodleDragHandler.ts" />
46+
</ItemGroup>
47+
48+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
49+
<TypeScriptTarget>ES2015</TypeScriptTarget>
50+
<TypeScriptJSXEmit>React</TypeScriptJSXEmit>
51+
<TypeScriptModuleKind>ES6</TypeScriptModuleKind>
52+
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
53+
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
54+
<TypeScriptRemoveComments>False</TypeScriptRemoveComments>
55+
<TypeScriptOutFile />
56+
<TypeScriptOutDir />
57+
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
58+
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
59+
<TypeScriptSourceMap>True</TypeScriptSourceMap>
60+
<TypeScriptMapRoot />
61+
<TypeScriptSourceRoot />
62+
</PropertyGroup>
3863

3964
</Project>

Nodexr/Shared/Components/NodeGraph.razor

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,50 @@
22
@using Nodexr.Shared.NodeTypes;
33
@using Nodexr.Shared.Components;
44
@inject INodeDragService NodeDragService
5-
@inject INoodleDragService NoodleDragService
5+
@inject INoodleDragService NoodleDragService
66
@inject INodeHandler NodeHandler
7+
@inject IJSRuntime JSRuntime
78

89
@{
910
//Console.WriteLine("Updating Node Graph");
1011
}
11-
<div class="viewport nodegraph" onwheel="panzoom.zoom(event)" onmousedown="panzoom.startPan(event)"
12-
ondragover="event.preventDefault()" @ondrop="@OnDrop" @onkeydown="@OnKeyDown" tabindex="-1">
13-
<div style="width:100%; height:100%; position:absolute;" @onclick="@DeselectNode"></div>
12+
<div class="viewport nodegraph" onwheel="panzoom.zoom(event)"
13+
@onmousedown="StartPan" @onmousedown:preventDefault
14+
ondragover="event.preventDefault()" @ondrop="@OnDrop" @onkeydown="@OnKeyDown" tabindex="-1">
15+
<div style="width:100%; height:100%; position:absolute;" @onclick="@OnClick"></div>
1416
<div id="nodegraph" style="position:relative; transform-origin:0% 0%; width:0px; height:0px;">
15-
@foreach(var node in NodeHandler.Tree.Nodes)
17+
@foreach (var node in NodeHandler.Tree.Nodes)
1618
{
1719
<NodeView @key="node" Data="node" />
1820
}
1921
<svg style="overflow:visible; position:absolute;">
2022
<NoodleSvg Noodle="NoodleDragService.TempNoodle" DomId="tempNoodle" />
2123
</svg>
2224
<svg style="overflow:visible; position:absolute;">
23-
<NoodleCollection Nodes="@NodeHandler.Tree.Nodes"/>
25+
<NoodleCollection Nodes="@NodeHandler.Tree.Nodes" />
2426
</svg>
2527
</div>
2628
</div>
2729

2830
@functions{
2931

30-
protected int XOffset { get; set; } = 0;
31-
//OutputDisplay outputDisplay;
32-
33-
bool shouldRender = false;
34-
32+
private bool shouldRender = false;
3533
protected override bool ShouldRender() => shouldRender;
3634

35+
private Vector2 clickStartPos; //Used to check whether an onclick event was actually a drag
36+
3737
protected override void OnInitialized()
3838
{
3939
//NodeHandler.OnNodeCountChanged += StateHasChanged;
4040
NodeHandler.OnRequireNodeGraphRefresh += (sender, e) => Refresh();
4141
}
4242

43+
async Task StartPan(MouseEventArgs e)
44+
{
45+
clickStartPos = e.GetClientPos();
46+
await JSRuntime.InvokeVoidAsync("panzoom.startPan");
47+
}
48+
4349
void Refresh()
4450
{
4551
shouldRender = true;
@@ -59,7 +65,18 @@
5965
{
6066
NodeHandler.DeleteSelectedNode();
6167
}
62-
else if(e.Key == "Escape")
68+
else if (e.Key == "Escape")
69+
{
70+
DeselectNode();
71+
}
72+
}
73+
74+
void OnClick(MouseEventArgs e)
75+
{
76+
const int dragThreshold = 4; //Length in px to consider a drag (instead of a click)
77+
var mouseOffset = e.GetClientPos() - clickStartPos;
78+
79+
if (mouseOffset.GetLength() <= dragThreshold)
6380
{
6481
DeselectNode();
6582
}

Nodexr/Shared/Components/NodeInputDot.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{
2424
if (Input.ConnectedNode != null)
2525
{
26-
NoodleDragService.OnStartNoodleDrag(Input.ConnectedNode, e, Input.Pos);
26+
NoodleDragService.OnStartNoodleDrag(Input.ConnectedNode, Input.Pos);
2727
Input.ConnectedNode = null;
2828
}
2929
}

Nodexr/Shared/Components/NodeOutputDot.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
@inject IJSRuntime JSRuntime;
44

55

6-
<div draggable="true" onmousedown="event.stopPropagation()" class="node-output-dot-parent"
7-
@ondragstart="OnDragStart"
6+
<div draggable="true" class="node-output-dot-parent"
7+
ondragstart="tempNoodle.clearDragImage(event)"
8+
@onmousedown="OnDragStart" @onmousedown:stopPropagation
89
@ondragend="OnDragEnd">
910
<div class="node-output-dot">
1011
<span class="outputtooltip">
@@ -19,10 +20,9 @@
1920
{
2021
[Parameter] public INode Data { get; set; }
2122

22-
void OnDragStart(DragEventArgs e)
23+
void OnDragStart()
2324
{
24-
//TODO: Set drag image
25-
NoodleDragService.OnStartNoodleDrag(Data, e);
25+
NoodleDragService.OnStartNoodleDrag(Data);
2626
}
2727

2828
void OnDragEnd(DragEventArgs e)

Nodexr/Shared/Components/NoodleCollection.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
var inputsWithNoodles = node.GetAllInputs()
1111
.OfType<InputProcedural>()
12-
.Where(input => input.ConnectedNode != null);
12+
.Where(input => input.Enabled);
1313

1414
@foreach (var input in inputsWithNoodles)
1515
{

Nodexr/Shared/Components/NoodleSvg.razor

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
@inject INodeHandler NodeHandler;
22
@implements IDisposable
33

4-
5-
<path id="@DomId" class="noodle" d="@PathInstructions"
6-
style="display:@(Noodle.Enabled ? "default" : "none"); @CssStrokeStyle"/>
7-
4+
<path id="@DomId" class="noodle" d="@PathInstructions"
5+
style="@(Noodle.Enabled ? "" : "display:none;") @CssStrokeStyle"/>
86

97

108
@functions{
11-
//public const string normalClass = "noodle";
12-
//public const string invalidClass = "noodle noodle-invalid";
139

1410
[Parameter] public INoodleData Noodle { get; set; }
15-
[Parameter] public string DomId { get; set; } = "";
11+
[Parameter] public string DomId { get; set; } = null;
1612
[Parameter] public string Gradient { get; set; }
1713

1814
public bool Valid { get; set; } = true;
1915
//public string CssClass => Valid ? normalClass : invalidClass;
2016
protected string PathInstructions {
2117
get
2218
{
23-
long startX = Noodle.StartPos.x;
24-
double startY = Noodle.StartPos.y + 0.01d;
25-
long endX = Noodle.EndPos.x, endY = Noodle.EndPos.y;
26-
long ctrlLength = (long)(5 + 0.4*Math.Abs(endX-startX) + 0.2*Math.Abs(endY-startY));
19+
var startX = (long)Noodle.StartPos.x;
20+
var startY = (long)Noodle.StartPos.y + 0.01d;
21+
var endX = (long)Noodle.EndPos.x;
22+
var endY = (long)Noodle.EndPos.y;
23+
double ctrlLength = 5 + 0.4*Math.Abs(endX-startX) + Math.Min(0.2*Math.Abs(endY-startY), 40);
2724
return FormattableString.Invariant(
2825
$"M {startX} {startY} C {startX + ctrlLength} {startY} {endX - ctrlLength} {endY} {endX} {endY}");
2926
}

Nodexr/Shared/ExtensionMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace Nodexr.Shared
55
{
66
public static class ExtensionMethods
77
{
8-
public static Vector2L GetClientPos(this Microsoft.AspNetCore.Components.Web.DragEventArgs e)
8+
public static Vector2 GetClientPos(this Microsoft.AspNetCore.Components.Web.MouseEventArgs e)
99
{
10-
return new Vector2L((long)e.ClientX, (long)e.ClientY);
10+
return new Vector2(e.ClientX, e.ClientY);
1111
}
1212

1313
public static string InNonCapturingGroup(this string input) => $"(?:{input})";

Nodexr/Shared/IPositionable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
public interface IPositionable
44
{
5-
Vector2L Pos { get; set; }
5+
Vector2 Pos { get; set; }
66
}
77
}

Nodexr/Shared/NodeInputs/InputCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void AddItem(INodeOutput node = null)
4242
public void RemoveItem(InputProcedural item)
4343
{
4444
item.ValueChanged -= OnValueChanged;
45+
item.ConnectedNode = null;
4546
inputs.Remove(item);
4647
OnInputPositionsChanged();
4748
OnValueChanged();

Nodexr/Shared/NodeInputs/InputCollectionView.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
void MoveUp(InputProcedural input)
2323
{
2424
Data.MoveUp(input);
25-
NodeHandler.ForceRefreshNoodles();
2625
}
2726

2827
void MoveDown(InputProcedural input)
2928
{
3029
Data.MoveDown(input);
31-
NodeHandler.ForceRefreshNoodles();
3230
}
3331

3432
void RemoveItem(InputProcedural input)

Nodexr/Shared/NodeInputs/InputProcedural.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public INodeOutput ConnectedNode
2626
}
2727
}
2828

29-
public Vector2L StartPos => connectedNode.OutputPos;
29+
public Vector2 StartPos => connectedNode.OutputPos;
3030

31-
public Vector2L EndPos => Pos;
31+
public Vector2 EndPos => Pos;
3232

3333
public bool Enabled => connectedNode != null;
3434

@@ -56,8 +56,8 @@ public void Refresh()
5656

5757
public interface INoodleData
5858
{
59-
Vector2L StartPos { get; }
60-
Vector2L EndPos { get; }
59+
Vector2 StartPos { get; }
60+
Vector2 EndPos { get; }
6161
bool Enabled { get; }
6262
void Refresh();
6363

Nodexr/Shared/NodeInputs/NodeInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public abstract class NodeInput : INodeInput
2121

2222
public event EventHandler ValueChanged;
2323

24-
public Vector2L Pos { get; set; }
24+
public Vector2 Pos { get; set; }
2525

2626
public Func<bool> IsEnabled { get; set; } = (() => true);
2727

Nodexr/Shared/Nodes/Node.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nodexr.Shared.Nodes
88
{
99
public interface INodeOutput
1010
{
11-
Vector2L OutputPos { get; }
11+
Vector2 OutputPos { get; }
1212
string CssName { get; }
1313
string CssColor { get; }
1414
NodeResult CachedOutput { get; }
@@ -47,9 +47,9 @@ public interface INode : IPositionable, INodeOutput
4747

4848
public abstract class Node : INode
4949
{
50-
private Vector2L pos;
50+
private Vector2 pos;
5151

52-
public Vector2L Pos
52+
public Vector2 Pos
5353
{
5454
get => pos;
5555
set
@@ -73,7 +73,7 @@ public INodeOutput PreviousNode
7373

7474
public NodeResult CachedOutput { get; private set; }
7575

76-
public Vector2L OutputPos => Pos + new Vector2L(150, 14);
76+
public Vector2 OutputPos => Pos + new Vector2(154, 13);
7777

7878
public bool IsCollapsed { get; set; }
7979

@@ -133,7 +133,7 @@ protected Node()
133133
public void CalculateInputsPos()
134134
{
135135
//TODO: refactor using GetHeight() on each input
136-
Previous.Pos = new Vector2L(Pos.x + 2, Pos.y + 13);
136+
Previous.Pos = new Vector2(Pos.x + 2, Pos.y + 13);
137137
if (IsCollapsed)
138138
{
139139
const int startHeight = 13;
@@ -142,13 +142,13 @@ public void CalculateInputsPos()
142142
switch (input)
143143
{
144144
case InputProcedural input1:
145-
input1.Pos = new Vector2L(Pos.x + 2, Pos.y + startHeight);
145+
input1.Pos = new Vector2(Pos.x + 2, Pos.y + startHeight);
146146
break;
147147
case InputCollection input1:
148-
input1.Pos = new Vector2L(Pos.x + 2, Pos.y + startHeight);
148+
input1.Pos = new Vector2(Pos.x + 2, Pos.y + startHeight);
149149
foreach (var input2 in input1.Inputs)
150150
{
151-
input2.Pos = new Vector2L(Pos.x + 2, Pos.y + startHeight);
151+
input2.Pos = new Vector2(Pos.x + 2, Pos.y + startHeight);
152152
}
153153
break;
154154
}
@@ -163,16 +163,16 @@ public void CalculateInputsPos()
163163
if (input is InputCollection inputColl)
164164
{
165165
startHeight += 28;
166-
inputColl.Pos = new Vector2L(Pos.x, Pos.y + startHeight);
166+
inputColl.Pos = new Vector2(Pos.x, Pos.y + startHeight);
167167
foreach (var input2 in inputColl.Inputs)
168168
{
169-
input2.Pos = new Vector2L(Pos.x, Pos.y + startHeight);
169+
input2.Pos = new Vector2(Pos.x, Pos.y + startHeight);
170170
startHeight += input2.Height;
171171
}
172172
}
173173
else
174174
{
175-
input.Pos = new Vector2L(Pos.x, Pos.y + startHeight);
175+
input.Pos = new Vector2(Pos.x, Pos.y + startHeight);
176176
startHeight += input.Height;
177177
}
178178
}

0 commit comments

Comments
 (0)