-
Notifications
You must be signed in to change notification settings - Fork 20
/
PanelGroupDisplay.razor.cs
208 lines (164 loc) · 7.29 KB
/
PanelGroupDisplay.razor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using Fluxor;
using Fluxor.Blazor.Web.Components;
using Luthetus.Common.RazorLib.Dimensions.Models;
using Luthetus.Common.RazorLib.Drags.Displays;
using Luthetus.Common.RazorLib.Keys.Models;
using Luthetus.Common.RazorLib.Panels.States;
using Luthetus.Common.RazorLib.Panels.Models;
using Luthetus.Common.RazorLib.Dialogs.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.JSInterop;
using System.Collections.Immutable;
namespace Luthetus.Common.RazorLib.Panels.Displays;
public partial class PanelGroupDisplay : FluxorComponent
{
[Inject]
private IState<PanelState> PanelStateWrap { get; set; } = null!;
[Inject]
private IDispatcher Dispatcher { get; set; } = null!;
[Inject]
private IDialogService DialogService { get; set; } = null!;
[Inject]
private IJSRuntime JsRuntime { get; set; } = null!;
[Parameter, EditorRequired]
public Key<PanelGroup> PanelGroupKey { get; set; } = Key<PanelGroup>.Empty;
[Parameter, EditorRequired]
public ElementDimensions AdjacentElementDimensions { get; set; } = null!;
[Parameter, EditorRequired]
public DimensionAttributeKind DimensionAttributeKind { get; set; }
[Parameter, EditorRequired]
public Func<Task> ReRenderSelfAndAdjacentElementDimensionsFunc { get; set; } = null!;
[Parameter]
public string CssClassString { get; set; } = null!;
[Parameter]
public RenderFragment? JustifyEndRenderFragment { get; set; } = null;
public string DimensionAttributeModificationPurpose => $"take_size_of_adjacent_hidden_panel_{PanelGroupKey}";
private string PanelPositionCssClass => GetPanelPositionCssClass();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
// TODO: Why is 'PassAlongSizeIfNoActiveTab()' only invoked if its the firstRender?
await PassAlongSizeIfNoActiveTab()
.ConfigureAwait(false);
}
await base.OnAfterRenderAsync(firstRender);
}
private ImmutableArray<IPanelTab> GetTabList(PanelGroup panelGroup)
{
var tabList = new List<IPanelTab>();
foreach (var panelTab in panelGroup.TabList)
{
panelTab.TabGroup = panelGroup;
tabList.Add(panelTab);
}
return tabList.ToImmutableArray();
}
private string GetHtmlId()
{
return GetPanelPositionCssClass();
}
private string GetPanelPositionCssClass()
{
var position = string.Empty;
if (PanelFacts.LeftPanelGroupKey == PanelGroupKey)
position = "left";
else if (PanelFacts.RightPanelGroupKey == PanelGroupKey)
position = "right";
else if (PanelFacts.BottomPanelGroupKey == PanelGroupKey)
position = "bottom";
return $"luth_ide_panel_{position}";
}
private async Task PassAlongSizeIfNoActiveTab()
{
var panelState = PanelStateWrap.Value;
var panelGroup = panelState.PanelGroupList.FirstOrDefault(x => x.Key == PanelGroupKey);
if (panelGroup is not null)
{
var activePanelTab = panelGroup.TabList.FirstOrDefault(
x => x.Key == panelGroup.ActiveTabKey);
var adjacentElementSizeDimensionAttribute = AdjacentElementDimensions.DimensionAttributeList.First(
x => x.DimensionAttributeKind == DimensionAttributeKind);
var indexOfPreviousPassAlong = adjacentElementSizeDimensionAttribute.DimensionUnitList.FindIndex(
x => x.Purpose == DimensionAttributeModificationPurpose);
if (activePanelTab is null && indexOfPreviousPassAlong == -1)
{
var panelGroupSizeDimensionsAttribute = panelGroup.ElementDimensions.DimensionAttributeList.First(
x => x.DimensionAttributeKind == DimensionAttributeKind);
var panelGroupPercentageSize = panelGroupSizeDimensionsAttribute.DimensionUnitList.First(
x => x.DimensionUnitKind == DimensionUnitKind.Percentage);
adjacentElementSizeDimensionAttribute.DimensionUnitList.Add(new DimensionUnit
{
Value = panelGroupPercentageSize.Value,
DimensionUnitKind = panelGroupPercentageSize.DimensionUnitKind,
DimensionOperatorKind = DimensionOperatorKind.Add,
Purpose = DimensionAttributeModificationPurpose
});
await ReRenderSelfAndAdjacentElementDimensionsFunc
.Invoke()
.ConfigureAwait(false);
}
else if (activePanelTab is not null && indexOfPreviousPassAlong != -1)
{
adjacentElementSizeDimensionAttribute.DimensionUnitList.RemoveAt(indexOfPreviousPassAlong);
await ReRenderSelfAndAdjacentElementDimensionsFunc
.Invoke()
.ConfigureAwait(false);
}
}
}
private string GetElementDimensionsStyleString(PanelGroup? panelGroup, IPanelTab? activePanelTab)
{
if (activePanelTab is null)
{
return "calc(" +
"var(--luth_ide_panel-tabs-font-size)" +
" + var(--luth_ide_panel-tabs-margin)" +
" + var(--luth_ide_panel-tabs-bug-are-not-aligning-need-to-fix-todo))";
}
return panelGroup?.ElementDimensions.StyleString ?? string.Empty;
}
private Task TopDropzoneOnMouseUp(MouseEventArgs mouseEventArgs)
{
var panelState = PanelStateWrap.Value;
var panelGroup = panelState.PanelGroupList.FirstOrDefault(x => x.Key == PanelGroupKey);
if (panelGroup is null)
return Task.CompletedTask;
var panelDragEventArgs = panelState.DragEventArgs;
if (panelDragEventArgs is not null)
{
Dispatcher.Dispatch(new PanelState.DisposePanelTabAction(
panelDragEventArgs.Value.PanelGroup.Key,
panelDragEventArgs.Value.PanelTab.Key));
Dispatcher.Dispatch(new PanelState.RegisterPanelTabAction(
panelGroup.Key,
panelDragEventArgs.Value.PanelTab,
true));
Dispatcher.Dispatch(new PanelState.SetDragEventArgsAction(null));
Dispatcher.Dispatch(new DragState.ShouldDisplayAndMouseEventArgsSetAction(false, null));
}
return Task.CompletedTask;
}
private Task BottomDropzoneOnMouseUp(MouseEventArgs mouseEventArgs)
{
var panelState = PanelStateWrap.Value;
var panelGroup = panelState.PanelGroupList.FirstOrDefault(x => x.Key == PanelGroupKey);
if (panelGroup is null)
return Task.CompletedTask;
var panelDragEventArgs = panelState.DragEventArgs;
if (panelDragEventArgs is not null)
{
Dispatcher.Dispatch(new PanelState.DisposePanelTabAction(
panelDragEventArgs.Value.PanelGroup.Key,
panelDragEventArgs.Value.PanelTab.Key));
Dispatcher.Dispatch(new PanelState.RegisterPanelTabAction(
panelGroup.Key,
panelDragEventArgs.Value.PanelTab,
false));
Dispatcher.Dispatch(new PanelState.SetDragEventArgsAction(null));
Dispatcher.Dispatch(new DragState.ShouldDisplayAndMouseEventArgsSetAction(false, null));
}
return Task.CompletedTask;
}
}