mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-27 00:53:37 +00:00
Unify the drop zones into one component
This commit is contained in:
parent
e024209214
commit
a9a7aef86e
@ -4,7 +4,7 @@
|
||||
|
||||
@* Every assistant is a drop area: a file dropped anywhere inside it lands on the assistant's
|
||||
default zone, while a file dropped on one of its specific zones lands there. *@
|
||||
<DropZoneScope Class="inner-scrolling-context">
|
||||
<PathDropZone IsArea="@true" Class="inner-scrolling-context">
|
||||
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2 mr-3" StretchItems="StretchItems.Start">
|
||||
<MudText Typo="Typo.h3">
|
||||
@ -188,4 +188,4 @@
|
||||
</MudStack>
|
||||
</FooterContent>
|
||||
</InnerScrolling>
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
@ -3,8 +3,13 @@
|
||||
@if (this.UseSmallForm)
|
||||
{
|
||||
<MudStack Spacing="0">
|
||||
<div data-drop-zone-id="@this.dropZoneId">
|
||||
@if (this.isDraggingOver)
|
||||
<PathDropZone IdPrefix="attach-documents"
|
||||
Frameless="@true"
|
||||
CatchAllDocuments="@this.CatchAllDocuments"
|
||||
Disabled="@(() => this.IsUnavailable)"
|
||||
OnPathsDropped="@this.PathsDropped"
|
||||
Context="isDropTarget">
|
||||
@if (isDropTarget)
|
||||
{
|
||||
<MudBadge
|
||||
Content="@this.DocumentPaths.Count"
|
||||
@ -52,7 +57,7 @@
|
||||
OnClick="@this.AddFilesManually"/>
|
||||
</MudTooltip>
|
||||
}
|
||||
</div>
|
||||
</PathDropZone>
|
||||
@if (this.ShowMediaStatus)
|
||||
{
|
||||
<MediaTranscriptionStatus Owner="@this.EffectiveImportOwner" TargetId="@this.EffectiveMediaImportTarget.TargetId" Compact="true"/>
|
||||
@ -82,21 +87,25 @@ else
|
||||
{
|
||||
<MediaTranscriptionStatus Owner="@this.EffectiveImportOwner" TargetId="@this.EffectiveMediaImportTarget.TargetId"/>
|
||||
}
|
||||
<div data-drop-zone-id="@this.dropZoneId">
|
||||
<MudPaper Height="20em" Outlined="true" Class="@this.dragClass" Style="overflow-y: auto;">
|
||||
@foreach (var fileAttachment in this.DocumentPaths)
|
||||
<PathDropZone IdPrefix="attach-documents"
|
||||
Class="pa-4 mt-4 mud-height-full"
|
||||
HighlightClass="mud-border-primary border-4"
|
||||
Style="height: 20em; overflow-y: auto;"
|
||||
CatchAllDocuments="@this.CatchAllDocuments"
|
||||
Disabled="@(() => this.IsUnavailable)"
|
||||
OnPathsDropped="@this.PathsDropped">
|
||||
@foreach (var fileAttachment in this.DocumentPaths)
|
||||
{
|
||||
@if (this.IsUnavailable)
|
||||
{
|
||||
@if (this.IsUnavailable)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Dark" Text="@fileAttachment.FileName" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(fileAttachment))"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip T="string" Color="Color.Dark" Text="@fileAttachment.FileName" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(fileAttachment))" OnClose="@(() => this.RemoveDocument(fileAttachment))"/>
|
||||
}
|
||||
<MudChip T="string" Color="Color.Dark" Text="@fileAttachment.FileName" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(fileAttachment))"/>
|
||||
}
|
||||
</MudPaper>
|
||||
</div>
|
||||
else
|
||||
{
|
||||
<MudChip T="string" Color="Color.Dark" Text="@fileAttachment.FileName" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(fileAttachment))" OnClose="@(() => this.RemoveDocument(fileAttachment))"/>
|
||||
}
|
||||
}
|
||||
</PathDropZone>
|
||||
@if (!this.IsUnavailable)
|
||||
{
|
||||
<MudButton OnClick="@(async () => await this.ClearAllFiles())" Variant="Variant.Filled" Color="Color.Info" Class="mt-2" StartIcon="@Icons.Material.Filled.Delete">
|
||||
|
||||
@ -45,12 +45,6 @@ public partial class AttachDocuments : MSGComponentBase
|
||||
[Parameter]
|
||||
public bool CatchAllDocuments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The area this component lives in, if it lives in one at all.
|
||||
/// </summary>
|
||||
[CascadingParameter]
|
||||
private DropZoneScopeState? Scope { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool UseSmallForm { get; set; }
|
||||
|
||||
@ -105,11 +99,6 @@ public partial class AttachDocuments : MSGComponentBase
|
||||
private const Placement TOOLBAR_TOOLTIP_PLACEMENT = Placement.Top;
|
||||
private static readonly string DROP_FILES_HERE_TEXT = TB("Drop files here to attach them.");
|
||||
|
||||
private readonly string dropZoneId = $"attach-documents-{Guid.NewGuid():N}";
|
||||
|
||||
private bool isDefaultZone;
|
||||
private bool hasReportedDefaultZoneProblem;
|
||||
private bool isDraggingOver;
|
||||
private bool isFileDialogOpen;
|
||||
private MediaImportOwner EffectiveImportOwner => this.OwnerChat is not null
|
||||
? MediaImportOwner.ForChat(this.OwnerChat.ChatId)
|
||||
@ -124,7 +113,7 @@ public partial class AttachDocuments : MSGComponentBase
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
this.MediaTranscriptionService.StateChanged += this.OnMediaImportStateChanged;
|
||||
this.ApplyFilters([], [ Event.HIGHLIGHT_DROP_ZONE, Event.PATHS_DROPPED ]);
|
||||
this.ApplyFilters([], []);
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
@ -132,7 +121,6 @@ public partial class AttachDocuments : MSGComponentBase
|
||||
/// <summary>Rehydrates results after the component is assigned another chat or target.</summary>
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
this.UpdateDefaultZoneRole();
|
||||
await base.OnParametersSetAsync();
|
||||
await this.SyncCompletedMediaAttachmentsAsync();
|
||||
}
|
||||
@ -223,139 +211,22 @@ public partial class AttachDocuments : MSGComponentBase
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
this.MediaTranscriptionService.StateChanged -= this.OnMediaImportStateChanged;
|
||||
|
||||
// Hand the role of the default target back to the area:
|
||||
if (this.isDefaultZone)
|
||||
this.Scope?.ReleaseDefaultZone(this);
|
||||
|
||||
base.DisposeResources();
|
||||
}
|
||||
|
||||
protected override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
||||
{
|
||||
switch (triggeredEvent)
|
||||
{
|
||||
case Event.HIGHLIGHT_DROP_ZONE when data is DropZoneHighlight highlight:
|
||||
this.ApplyHighlight(this.IsThisZone(highlight.ZoneId));
|
||||
break;
|
||||
|
||||
case Event.PATHS_DROPPED when data is DroppedPaths dropped:
|
||||
// Whoever the drop was meant for, the drag is over and no zone stays highlighted:
|
||||
this.ApplyHighlight(false);
|
||||
|
||||
if (!this.IsThisZone(dropped.ZoneId))
|
||||
return;
|
||||
|
||||
if (this.IsUnavailable)
|
||||
{
|
||||
this.Logger.LogDebug("The attachment zone '{Name}' is unavailable and swallowed {Count} dropped path(s).", this.Name, dropped.Paths.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.AddFileBatchAsync(dropped.Paths);
|
||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||
await this.OnChange(this.DocumentPaths);
|
||||
this.StateHasChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Keeps the role of the default target in step with the CatchAllDocuments parameter.
|
||||
/// Attaches what the user dropped on the zone of this component.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The flag is a parameter, so it can change while this component lives. A zone inside a
|
||||
/// collapsed panel is the case this exists for: MudBlazor leaves the content of a collapsed
|
||||
/// panel in the DOM with a height of zero, so the zone stays alive and cannot be aimed at --
|
||||
/// yet it would keep the role and swallow every drop meant for the visible part of the page.
|
||||
/// </remarks>
|
||||
private void UpdateDefaultZoneRole()
|
||||
/// <param name="paths">The dropped paths, in the order the runtime delivered them.</param>
|
||||
private async Task PathsDropped(List<string> paths)
|
||||
{
|
||||
if (this.CatchAllDocuments)
|
||||
{
|
||||
this.ClaimDefaultZoneRole();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isDefaultZone)
|
||||
return;
|
||||
|
||||
this.Scope?.ReleaseDefaultZone(this);
|
||||
this.isDefaultZone = false;
|
||||
await this.AddFileBatchAsync(paths);
|
||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||
await this.OnChange(this.DocumentPaths);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks the area for the role of its default target.
|
||||
/// </summary>
|
||||
private void ClaimDefaultZoneRole()
|
||||
{
|
||||
if (this.isDefaultZone)
|
||||
return;
|
||||
|
||||
if (this.Scope is null)
|
||||
{
|
||||
//
|
||||
// There is nothing to claim: the surrounding page, assistant, or dialog is not a drop
|
||||
// area at all. The flag would then do nothing, and silently -- which is how a zone ends
|
||||
// up promising a behaviour it cannot deliver. So say it out loud: either the area needs
|
||||
// a DropZoneScope, or the flag does not belong here. Reported once only, because the
|
||||
// claim is retried on every parameter change.
|
||||
//
|
||||
if (!this.hasReportedDefaultZoneProblem)
|
||||
{
|
||||
this.hasReportedDefaultZoneProblem = true;
|
||||
this.Logger.LogWarning("The attachment zone '{Name}' wants to be the default target of its area, but it does not live in a drop zone scope. Dropping next to this zone will do nothing.", this.Name);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.isDefaultZone = this.Scope.TryBecomeDefaultZone(this);
|
||||
|
||||
// Losing the role to a neighbour is a decision, not a defect -- and it can be undone later,
|
||||
// when that neighbour goes away. So this one only goes to the debug log, and only once:
|
||||
if (this.isDefaultZone || this.hasReportedDefaultZoneProblem)
|
||||
return;
|
||||
|
||||
this.hasReportedDefaultZoneProblem = true;
|
||||
this.Logger.LogDebug("The attachment zone '{Name}' asked to be the default target of its area, which another zone already is. It now takes only the drops aimed at itself.", this.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decides whether the named zone is this one.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The area counts as this zone as long as this zone is its default target. That is the whole
|
||||
/// mechanism behind dropping anywhere in the chat and still landing on the composer.
|
||||
/// </remarks>
|
||||
/// <param name="zoneId">The ID the hit test reported, or null when it hit nothing.</param>
|
||||
private bool IsThisZone(string? zoneId) => zoneId is not null && (zoneId == this.dropZoneId || (this.isDefaultZone && zoneId == this.Scope?.ScopeId));
|
||||
|
||||
/// <summary>
|
||||
/// Highlights the zone, or takes the highlight away.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The comparison is not for tidiness: a throttled drag-over event arrives about ten times per
|
||||
/// second, and without it every one of them would render every zone on the page anew. In the
|
||||
/// small form the highlight also swaps the markup, so this keeps the composer from flickering.
|
||||
/// </remarks>
|
||||
private void ApplyHighlight(bool shouldBeHighlighted)
|
||||
{
|
||||
var highlighted = shouldBeHighlighted && !this.IsUnavailable;
|
||||
if (highlighted == this.isDraggingOver)
|
||||
return;
|
||||
|
||||
this.isDraggingOver = highlighted;
|
||||
this.dragClass = highlighted ? $"{DEFAULT_DRAG_CLASS} mud-border-primary border-4" : DEFAULT_DRAG_CLASS;
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
private const string DEFAULT_DRAG_CLASS = "relative rounded-lg border-2 border-dashed pa-4 mt-4 mud-width-full mud-height-full";
|
||||
|
||||
private string dragClass = DEFAULT_DRAG_CLASS;
|
||||
|
||||
private async Task AddFilesManually()
|
||||
{
|
||||
if (this.IsUnavailable)
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
@* One element, and the content immediately inside it. Layouts hang child selectors on this
|
||||
element, for instance app.css does on .inner-scrolling-context, so an extra level here would
|
||||
break them. The cascading value renders no element of its own. *@
|
||||
<div class="@this.Class" style="@this.Style" data-drop-zone-id="@this.EffectiveState.ScopeId">
|
||||
<CascadingValue Value="@this.EffectiveState" IsFixed="@true">
|
||||
@this.ChildContent
|
||||
</CascadingValue>
|
||||
</div>
|
||||
@ -1,57 +0,0 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Marks an area whose drops end up at its default target when they hit no specific zone.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This is how the habitual behaviour survives the move to hit testing: a file dropped anywhere in
|
||||
/// the chat, in an assistant, or in a dialog still arrives where it used to, while a file dropped
|
||||
/// on a specific zone now arrives exactly there. No code decides between the two -- the browser
|
||||
/// does, because the specific zone lies deeper in the DOM than the area around it, and the hit test
|
||||
/// resolves from the inside out.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The component replaces an existing element rather than adding one: it takes the class and the
|
||||
/// style of the element it stands in for. Where the areas already had a wrapper, which is the case
|
||||
/// for every page and every assistant, nothing about the layout changes.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public partial class DropZoneScope : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The content of the area.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The CSS classes of the element this scope renders.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Class { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The inline style of the element this scope renders.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Style { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The state to cascade, for hosts which want to be the default target of their own area.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A host cannot read what it cascades itself, so a page which is its own drop target has to own
|
||||
/// the state instead. The plugins page is such a case: it accepts an archive anywhere on it and
|
||||
/// has no inner zone to hand the role to. Everybody else leaves this alone and lets the scope
|
||||
/// keep its own state.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public DropZoneScopeState? State { get; set; }
|
||||
|
||||
private readonly DropZoneScopeState ownState = new($"drop-zone-scope-{Guid.NewGuid():N}");
|
||||
|
||||
private DropZoneScopeState EffectiveState => this.State ?? this.ownState;
|
||||
}
|
||||
@ -1,7 +1,28 @@
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<div data-drop-zone-id="@this.dropZoneId">
|
||||
<MudPaper Outlined="@true" Class="@this.dragClass">
|
||||
@this.ChildContent
|
||||
</MudPaper>
|
||||
</div>
|
||||
@if (this.IsFramed)
|
||||
{
|
||||
<div data-drop-zone-id="@this.zoneId">
|
||||
<MudPaper Outlined="@true" Class="@this.FrameClass" Style="@this.Style">
|
||||
@this.ChildContent?.Invoke(this.isHighlighted)
|
||||
</MudPaper>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@* An area renders one element, with the content immediately inside it. Layouts hang child
|
||||
selectors on that element, for instance app.css does on .inner-scrolling-context, so an extra
|
||||
level here would break them. The cascading value renders no element of its own. *@
|
||||
<div class="@this.Class" style="@this.Style" data-drop-zone-id="@this.zoneId">
|
||||
@if (this.areaState is null)
|
||||
{
|
||||
@this.ChildContent?.Invoke(this.isHighlighted)
|
||||
}
|
||||
else
|
||||
{
|
||||
<CascadingValue Value="@this.areaState" IsFixed="@true">
|
||||
@this.ChildContent?.Invoke(this.isHighlighted)
|
||||
</CascadingValue>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@ -6,22 +6,40 @@ namespace AIStudio.Components;
|
||||
/// A drop zone which reports the paths of whatever was dropped on it, and nothing else.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Dropping is a native matter in AI Studio: the Tauri runtime reports real paths, which is why
|
||||
/// this zone can hand out folders just as well as files. What those paths mean is the consumer's
|
||||
/// business — this component reads no content and does not care whether a path leads to a file or
|
||||
/// to a folder.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// One component serves both kinds of drop target, because both are the same thing to the hit test:
|
||||
/// an element with an ID. A zone is a place one aims at, and it draws a frame around whatever it is
|
||||
/// given. An area is a page, an assistant, or a dialog: it draws nothing, it marks the space in
|
||||
/// which a drop counts at all, and the drops which hit none of its zones go to its default target.
|
||||
/// Set IsArea for the second kind.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public partial class PathDropZone : MSGComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The content shown inside the zone.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Its argument tells the content whether this zone is the one under the cursor right now, so it
|
||||
/// can show where the drop would land. Everybody who does not care about that ignores it.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
public RenderFragment<bool>? ChildContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reports the dropped paths, in the order the runtime delivered them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An area without this callback is a marker and nothing more: it takes no drops itself, it only
|
||||
/// gives the drops aimed between its zones a place to be counted, from where the default target
|
||||
/// of the area picks them up.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public EventCallback<List<string>> OnPathsDropped { get; set; }
|
||||
|
||||
@ -32,21 +50,87 @@ public partial class PathDropZone : MSGComponentBase
|
||||
/// A drop aimed at this zone arrives here in any case. What this flag decides is the fate of the
|
||||
/// drops aimed anywhere else in the surrounding area which hit no zone of their own: with the
|
||||
/// flag, they arrive here as well. Only one zone per area can hold that role, and if several ask
|
||||
/// for it, the first one in the markup gets it.
|
||||
/// for it, the first one in the markup gets it. An area ignores the flag: an area which takes
|
||||
/// drops at all is its own default target, see IsArea.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public bool CatchAllDocuments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When true, the zone ignores drops and is not highlighted.
|
||||
/// Decides, at the moment a drop arrives, whether this zone may take it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It keeps its ID in the DOM nevertheless and therefore swallows the drops aimed at it. That is
|
||||
/// A disabled zone keeps its ID in the DOM and therefore swallows the drops aimed at it. That is
|
||||
/// what the pointer says: it rests on a switched-off field, so nothing happens. Letting the drop
|
||||
/// fall through to the area behind it would deliver the files somewhere else entirely.
|
||||
/// fall through to the area behind it would deliver the files somewhere else entirely. This is
|
||||
/// asked rather than passed as a value because the answer often depends on work in flight, and a
|
||||
/// value would be as old as the last render of the consumer.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
public Func<bool> Disabled { get; set; } = () => false;
|
||||
|
||||
/// <summary>
|
||||
/// Makes this element an area instead of a zone: it marks a page, an assistant, or a dialog, and
|
||||
/// it draws no frame of its own.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is how the habitual behaviour survives the move to hit testing: a file dropped anywhere
|
||||
/// in the chat, in an assistant, or in a dialog still arrives where it used to, while a file
|
||||
/// dropped on a specific zone now arrives exactly there. No code decides between the two — the
|
||||
/// browser does, because a zone lies deeper in the DOM than the area around it, and the hit test
|
||||
/// resolves from the inside out. An area replaces the element it stands in for rather than
|
||||
/// adding one, so it takes over its class and its style.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public bool IsArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Leaves out the frame this zone would otherwise draw around its content.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For zones whose content is the marker itself, such as a toolbar which shows a drop field
|
||||
/// while a file hovers over it. An area never has a frame, so it does not need this flag.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public bool Frameless { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The first part of the ID this element reports to the hit test, followed by a unique suffix.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It names the kind of zone in the log, next to the IDs the arbiter lists when a drop reached
|
||||
/// nobody. Which is the whole reason it is a parameter: an ID of its own tells one from another,
|
||||
/// but only a name tells what one is looking at.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public string IdPrefix { get; set; } = "path-drop-zone";
|
||||
|
||||
/// <summary>
|
||||
/// The CSS classes of the element this component renders: of the frame for a zone which has one,
|
||||
/// and of the element itself for an area and for a frameless zone.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A frame keeps its border and its width in any case; the classes given here replace the
|
||||
/// padding and the margin it would use otherwise.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public string Class { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The classes a frame takes on in addition while it is the zone under the cursor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only a frame is highlighted this way. Without one there is nothing to draw on, and the
|
||||
/// content says for itself what it looks like when it is the target, see ChildContent.
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public string HighlightClass { get; set; } = "mud-border-primary border-2";
|
||||
|
||||
/// <summary>
|
||||
/// The inline style of the element this component renders.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Style { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The area this zone lives in, if it lives in one at all.
|
||||
@ -57,20 +141,65 @@ public partial class PathDropZone : MSGComponentBase
|
||||
[Inject]
|
||||
private ILogger<PathDropZone> Logger { get; init; } = null!;
|
||||
|
||||
private const string DEFAULT_DRAG_CLASS = "relative rounded-lg border-2 border-dashed pa-3 mb-3 mud-width-full";
|
||||
private const string FRAME_CLASSES = "relative rounded-lg border-2 border-dashed mud-width-full";
|
||||
private const string DEFAULT_SPACING_CLASSES = "pa-3 mb-3";
|
||||
|
||||
private readonly string dropZoneId = $"path-drop-zone-{Guid.NewGuid():N}";
|
||||
|
||||
private string dragClass = DEFAULT_DRAG_CLASS;
|
||||
private DropZoneScopeState? areaState;
|
||||
private string zoneId = string.Empty;
|
||||
private bool isDefaultZone;
|
||||
private bool isHighlighted;
|
||||
private bool hasReportedDefaultZoneProblem;
|
||||
|
||||
private bool IsFramed => !this.IsArea && !this.Frameless;
|
||||
|
||||
private string FrameClass => this.isHighlighted
|
||||
? $"{FRAME_CLASSES} {this.SpacingClasses} {this.HighlightClass}"
|
||||
: $"{FRAME_CLASSES} {this.SpacingClasses}";
|
||||
|
||||
private string SpacingClasses => string.IsNullOrWhiteSpace(this.Class) ? DEFAULT_SPACING_CLASSES : this.Class;
|
||||
|
||||
/// <summary>
|
||||
/// The area this zone reports to, which for an area is itself.
|
||||
/// </summary>
|
||||
private DropZoneScopeState? EffectiveScope => this.areaState ?? this.Scope;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this element wants to be the default target of its area.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An area which takes drops is that target by definition, because its own element is the area
|
||||
/// and a drop next to its zones has nothing else to hit. It claims the role nevertheless, which
|
||||
/// is what keeps a zone inside it from taking it and delivering the same drop a second time.
|
||||
/// </remarks>
|
||||
private bool WantsDefaultZoneRole => this.IsArea ? this.OnPathsDropped.HasDelegate : this.CatchAllDocuments;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a drop can arrive here at all.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An area which delivers to nobody is only a mark on the page, and it must not listen: the
|
||||
/// highlight would render a whole page or assistant anew several times per drag, for a highlight
|
||||
/// nobody asked to see.
|
||||
/// </remarks>
|
||||
private bool CanBeTarget => !this.IsArea || this.OnPathsDropped.HasDelegate;
|
||||
|
||||
#region Overrides of MSGComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
this.ApplyFilters([], [ Event.HIGHLIGHT_DROP_ZONE, Event.PATHS_DROPPED ]);
|
||||
//
|
||||
// The ID is built once and never again: the hit test names this element by it, so it has to
|
||||
// outlive every render. The prefix is a parameter, and parameters are set before this point.
|
||||
//
|
||||
this.zoneId = $"{this.IdPrefix}-{Guid.NewGuid():N}";
|
||||
if (this.IsArea)
|
||||
this.areaState = new DropZoneScopeState(this.zoneId);
|
||||
|
||||
if (this.CanBeTarget)
|
||||
this.ApplyFilters([], [ Event.HIGHLIGHT_DROP_ZONE, Event.PATHS_DROPPED ]);
|
||||
else
|
||||
this.ApplyFilters([], []);
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
@ -86,7 +215,7 @@ public partial class PathDropZone : MSGComponentBase
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
if (this.isDefaultZone)
|
||||
this.Scope?.ReleaseDefaultZone(this);
|
||||
this.EffectiveScope?.ReleaseDefaultZone(this);
|
||||
|
||||
base.DisposeResources();
|
||||
}
|
||||
@ -106,13 +235,13 @@ public partial class PathDropZone : MSGComponentBase
|
||||
if (!this.IsThisZone(dropped.ZoneId))
|
||||
return;
|
||||
|
||||
if (this.Disabled)
|
||||
if (this.Disabled())
|
||||
{
|
||||
this.Logger.LogDebug("The path drop zone '{ZoneId}' is disabled and swallowed {Count} dropped path(s).", this.dropZoneId, dropped.Paths.Count);
|
||||
this.Logger.LogDebug("The drop zone '{ZoneId}' cannot take drops right now and swallowed {Count} dropped path(s).", this.zoneId, dropped.Paths.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
this.Logger.LogDebug("The path drop zone '{ZoneId}' caught {Count} path(s).", this.dropZoneId, dropped.Paths.Count);
|
||||
this.Logger.LogDebug("The drop zone '{ZoneId}' caught {Count} path(s).", this.zoneId, dropped.Paths.Count);
|
||||
await this.OnPathsDropped.InvokeAsync(dropped.Paths);
|
||||
break;
|
||||
}
|
||||
@ -131,7 +260,7 @@ public partial class PathDropZone : MSGComponentBase
|
||||
/// </remarks>
|
||||
private void UpdateDefaultZoneRole()
|
||||
{
|
||||
if (this.CatchAllDocuments)
|
||||
if (this.WantsDefaultZoneRole)
|
||||
{
|
||||
this.ClaimDefaultZoneRole();
|
||||
return;
|
||||
@ -140,7 +269,7 @@ public partial class PathDropZone : MSGComponentBase
|
||||
if (!this.isDefaultZone)
|
||||
return;
|
||||
|
||||
this.Scope?.ReleaseDefaultZone(this);
|
||||
this.EffectiveScope?.ReleaseDefaultZone(this);
|
||||
this.isDefaultZone = false;
|
||||
}
|
||||
|
||||
@ -152,13 +281,13 @@ public partial class PathDropZone : MSGComponentBase
|
||||
if (this.isDefaultZone)
|
||||
return;
|
||||
|
||||
if (this.Scope is null)
|
||||
if (this.EffectiveScope is null)
|
||||
{
|
||||
//
|
||||
// There is nothing to claim: the surrounding page, assistant, or dialog is not a drop
|
||||
// area at all. The flag would then do nothing, and silently -- which is how a zone ends
|
||||
// up promising a behaviour it cannot deliver. So say it out loud: either the area needs
|
||||
// a DropZoneScope, or the flag does not belong here.
|
||||
// a drop area of its own, or the flag does not belong here.
|
||||
//
|
||||
//
|
||||
// Reported once only: the claim is retried on every parameter change, and repeating
|
||||
@ -167,13 +296,13 @@ public partial class PathDropZone : MSGComponentBase
|
||||
if (!this.hasReportedDefaultZoneProblem)
|
||||
{
|
||||
this.hasReportedDefaultZoneProblem = true;
|
||||
this.Logger.LogWarning("The path drop zone '{ZoneId}' wants to be the default target of its area, but it does not live in a drop zone scope. Dropping next to this zone will do nothing.", this.dropZoneId);
|
||||
this.Logger.LogWarning("The drop zone '{ZoneId}' wants to be the default target of its area, but it does not live in a drop area. Dropping next to this zone will do nothing.", this.zoneId);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.isDefaultZone = this.Scope.TryBecomeDefaultZone(this);
|
||||
this.isDefaultZone = this.EffectiveScope.TryBecomeDefaultZone(this);
|
||||
|
||||
// Losing the role to a neighbour is a decision, not a defect -- and it can be undone later,
|
||||
// when that neighbour goes away. So this one only goes to the debug log, and only once:
|
||||
@ -181,7 +310,7 @@ public partial class PathDropZone : MSGComponentBase
|
||||
return;
|
||||
|
||||
this.hasReportedDefaultZoneProblem = true;
|
||||
this.Logger.LogDebug("The path drop zone '{ZoneId}' asked to be the default target of its area, which another zone already is. It now takes only the drops aimed at itself.", this.dropZoneId);
|
||||
this.Logger.LogDebug("The drop zone '{ZoneId}' asked to be the default target of its area, which another zone already is. It now takes only the drops aimed at itself.", this.zoneId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -191,8 +320,8 @@ public partial class PathDropZone : MSGComponentBase
|
||||
/// The area counts as this zone as long as this zone is its default target. That is the whole
|
||||
/// mechanism behind dropping anywhere in a page and still landing here.
|
||||
/// </remarks>
|
||||
/// <param name="zoneId">The ID the hit test reported, or null when it hit nothing.</param>
|
||||
private bool IsThisZone(string? zoneId) => zoneId is not null && (zoneId == this.dropZoneId || (this.isDefaultZone && zoneId == this.Scope?.ScopeId));
|
||||
/// <param name="targetZoneId">The ID the hit test reported, or null when it hit nothing.</param>
|
||||
private bool IsThisZone(string? targetZoneId) => targetZoneId is not null && (targetZoneId == this.zoneId || (this.isDefaultZone && targetZoneId == this.EffectiveScope?.ScopeId));
|
||||
|
||||
/// <summary>
|
||||
/// Highlights the zone, or takes the highlight away.
|
||||
@ -203,12 +332,11 @@ public partial class PathDropZone : MSGComponentBase
|
||||
/// </remarks>
|
||||
private void ApplyHighlight(bool shouldBeHighlighted)
|
||||
{
|
||||
var highlighted = shouldBeHighlighted && !this.Disabled;
|
||||
var highlighted = shouldBeHighlighted && !this.Disabled();
|
||||
if (highlighted == this.isHighlighted)
|
||||
return;
|
||||
|
||||
this.isHighlighted = highlighted;
|
||||
this.dragClass = highlighted ? $"{DEFAULT_DRAG_CLASS} mud-border-primary border-2" : DEFAULT_DRAG_CLASS;
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
@ -2,39 +2,40 @@
|
||||
|
||||
@if (this.EnableDragDrop)
|
||||
{
|
||||
<div data-drop-zone-id="@this.dropZoneId">
|
||||
<MudPaper Outlined="true" Class="@this.dragClass">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.None" Wrap="Wrap.Wrap">
|
||||
@if (this.ShowAttachedDocumentState && this.hasLoadedFileContent)
|
||||
{
|
||||
<MudTooltip Text="@this.FileLoadedTooltip()">
|
||||
<MudBadge Icon="@Icons.Material.Filled.Check" Color="Color.Success" Overlap="true">
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Description" OnClick="@(async () => await this.SelectFile())" Variant="Variant.Filled" Disabled="@this.IsUnavailable">
|
||||
@this.ButtonText
|
||||
</MudButton>
|
||||
</MudBadge>
|
||||
</MudTooltip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Description" OnClick="@(async () => await this.SelectFile())" Variant="Variant.Filled" Disabled="@this.IsUnavailable">
|
||||
@this.ButtonText
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
@if (this.IsCurrentTargetBusy)
|
||||
{
|
||||
<MediaTranscriptionStatus Owner="@this.EffectiveImportOwner" TargetId="@this.EffectiveMediaImportTarget.TargetId" Compact="true"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.body2">
|
||||
@T("Drop one file here to load its content.")
|
||||
</MudText>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</div>
|
||||
<PathDropZone IdPrefix="read-file-content"
|
||||
CatchAllDocuments="@this.CatchAllDocuments"
|
||||
Disabled="@(() => this.IsUnavailable)"
|
||||
OnPathsDropped="@this.LoadFirstValidFile">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.None" Wrap="Wrap.Wrap">
|
||||
@if (this.ShowAttachedDocumentState && this.hasLoadedFileContent)
|
||||
{
|
||||
<MudTooltip Text="@this.FileLoadedTooltip()">
|
||||
<MudBadge Icon="@Icons.Material.Filled.Check" Color="Color.Success" Overlap="true">
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Description" OnClick="@(async () => await this.SelectFile())" Variant="Variant.Filled" Disabled="@this.IsUnavailable">
|
||||
@this.ButtonText
|
||||
</MudButton>
|
||||
</MudBadge>
|
||||
</MudTooltip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Description" OnClick="@(async () => await this.SelectFile())" Variant="Variant.Filled" Disabled="@this.IsUnavailable">
|
||||
@this.ButtonText
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
@if (this.IsCurrentTargetBusy)
|
||||
{
|
||||
<MediaTranscriptionStatus Owner="@this.EffectiveImportOwner" TargetId="@this.EffectiveMediaImportTarget.TargetId" Compact="true"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.body2">
|
||||
@T("Drop one file here to load its content.")
|
||||
</MudText>
|
||||
}
|
||||
</MudStack>
|
||||
</PathDropZone>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -57,12 +57,6 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
[Parameter]
|
||||
public bool CatchAllDocuments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The area this component lives in, if it lives in one at all.
|
||||
/// </summary>
|
||||
[CascadingParameter]
|
||||
private DropZoneScopeState? Scope { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optionally restricts the file types offered by the native file picker
|
||||
/// and accepted by this component.
|
||||
@ -85,15 +79,7 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
[Inject]
|
||||
private MediaTranscriptionService MediaTranscriptionService { get; init; } = null!;
|
||||
|
||||
private const string DEFAULT_DRAG_CLASS = "relative rounded-lg border-2 border-dashed pa-3 mb-3 mud-width-full";
|
||||
|
||||
private readonly string dropZoneId = $"read-file-content-{Guid.NewGuid():N}";
|
||||
|
||||
private string ButtonText => string.IsNullOrWhiteSpace(this.Text) ? T("Use file content as input") : this.Text;
|
||||
private string dragClass = DEFAULT_DRAG_CLASS;
|
||||
private bool isDefaultZone;
|
||||
private bool isHighlighted;
|
||||
private bool hasReportedDefaultZoneProblem;
|
||||
private bool isFileDialogOpen;
|
||||
private bool hasLoadedFileContent;
|
||||
private string loadedFileName = string.Empty;
|
||||
@ -121,15 +107,13 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
this.loadedFileName = string.Empty;
|
||||
}
|
||||
|
||||
this.UpdateDefaultZoneRole();
|
||||
base.OnParametersSet();
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
this.MediaTranscriptionService.StateChanged += this.OnMediaImportStateChanged;
|
||||
if (this.EnableDragDrop)
|
||||
this.ApplyFilters([], [ Event.HIGHLIGHT_DROP_ZONE, Event.PATHS_DROPPED ]);
|
||||
this.ApplyFilters([], []);
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
await this.SyncCompletedMediaTextAsync();
|
||||
@ -194,139 +178,15 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
this.MediaTranscriptionService.AcknowledgeDelivery(delivery);
|
||||
}
|
||||
|
||||
/// <summary>Unsubscribes from the singleton media service and releases the drop area.</summary>
|
||||
/// <summary>Unsubscribes from the singleton media service.</summary>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
this.MediaTranscriptionService.StateChanged -= this.OnMediaImportStateChanged;
|
||||
|
||||
// Hand the role of the default target back to the area:
|
||||
if (this.isDefaultZone)
|
||||
this.Scope?.ReleaseDefaultZone(this);
|
||||
|
||||
base.DisposeResources();
|
||||
}
|
||||
|
||||
protected override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
||||
{
|
||||
if (!this.EnableDragDrop)
|
||||
return;
|
||||
|
||||
switch (triggeredEvent)
|
||||
{
|
||||
case Event.HIGHLIGHT_DROP_ZONE when data is DropZoneHighlight highlight:
|
||||
this.ApplyHighlight(this.IsThisZone(highlight.ZoneId));
|
||||
break;
|
||||
|
||||
case Event.PATHS_DROPPED when data is DroppedPaths dropped:
|
||||
// Whoever the drop was meant for, the drag is over and no zone stays highlighted:
|
||||
this.ApplyHighlight(false);
|
||||
|
||||
if (!this.IsThisZone(dropped.ZoneId))
|
||||
return;
|
||||
|
||||
if (this.IsUnavailable)
|
||||
{
|
||||
this.Logger.LogDebug("The file zone '{ZoneId}' is unavailable and swallowed {Count} dropped path(s).", this.dropZoneId, dropped.Paths.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.LoadFirstValidFile(dropped.Paths);
|
||||
this.StateHasChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Keeps the role of the default target in step with the CatchAllDocuments parameter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The flag is a parameter, so it can change while this component lives. A zone inside a
|
||||
/// collapsed panel is the case this exists for: MudBlazor leaves the content of a collapsed
|
||||
/// panel in the DOM with a height of zero, so the zone stays alive and cannot be aimed at --
|
||||
/// yet it would keep the role and swallow every drop meant for the visible part of the page.
|
||||
/// </remarks>
|
||||
private void UpdateDefaultZoneRole()
|
||||
{
|
||||
if (this.EnableDragDrop && this.CatchAllDocuments)
|
||||
{
|
||||
this.ClaimDefaultZoneRole();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isDefaultZone)
|
||||
return;
|
||||
|
||||
this.Scope?.ReleaseDefaultZone(this);
|
||||
this.isDefaultZone = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks the area for the role of its default target.
|
||||
/// </summary>
|
||||
private void ClaimDefaultZoneRole()
|
||||
{
|
||||
if (this.isDefaultZone)
|
||||
return;
|
||||
|
||||
if (this.Scope is null)
|
||||
{
|
||||
//
|
||||
// There is nothing to claim: the surrounding page, assistant, or dialog is not a drop
|
||||
// area at all. The flag would then do nothing, and silently -- which is how a zone ends
|
||||
// up promising a behaviour it cannot deliver. So say it out loud: either the area needs
|
||||
// a DropZoneScope, or the flag does not belong here. Reported once only, because the
|
||||
// claim is retried on every parameter change.
|
||||
//
|
||||
if (!this.hasReportedDefaultZoneProblem)
|
||||
{
|
||||
this.hasReportedDefaultZoneProblem = true;
|
||||
this.Logger.LogWarning("The file zone '{ZoneId}' wants to be the default target of its area, but it does not live in a drop zone scope. Dropping next to this zone will do nothing.", this.dropZoneId);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.isDefaultZone = this.Scope.TryBecomeDefaultZone(this);
|
||||
|
||||
// Losing the role to a neighbour is a decision, not a defect -- and it can be undone later,
|
||||
// when that neighbour goes away. So this one only goes to the debug log, and only once:
|
||||
if (this.isDefaultZone || this.hasReportedDefaultZoneProblem)
|
||||
return;
|
||||
|
||||
this.hasReportedDefaultZoneProblem = true;
|
||||
this.Logger.LogDebug("The file zone '{ZoneId}' asked to be the default target of its area, which another zone already is. It now takes only the drops aimed at itself.", this.dropZoneId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decides whether the named zone is this one.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The area counts as this zone as long as this zone is its default target. That is the whole
|
||||
/// mechanism behind dropping anywhere in an assistant and still landing here.
|
||||
/// </remarks>
|
||||
/// <param name="zoneId">The ID the hit test reported, or null when it hit nothing.</param>
|
||||
private bool IsThisZone(string? zoneId) => zoneId is not null && (zoneId == this.dropZoneId || (this.isDefaultZone && zoneId == this.Scope?.ScopeId));
|
||||
|
||||
/// <summary>
|
||||
/// Highlights the zone, or takes the highlight away.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The comparison is not for tidiness: a throttled drag-over event arrives about ten times per
|
||||
/// second, and without it every one of them would render every zone on the page anew.
|
||||
/// </remarks>
|
||||
private void ApplyHighlight(bool shouldBeHighlighted)
|
||||
{
|
||||
var highlighted = shouldBeHighlighted && !this.IsUnavailable;
|
||||
if (highlighted == this.isHighlighted)
|
||||
return;
|
||||
|
||||
this.isHighlighted = highlighted;
|
||||
this.dragClass = highlighted ? $"{DEFAULT_DRAG_CLASS} mud-border-primary border-2" : DEFAULT_DRAG_CLASS;
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task SelectFile()
|
||||
{
|
||||
if (this.IsUnavailable)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
@if (this.EnableDragDrop)
|
||||
{
|
||||
<PathDropZone CatchAllDocuments="@this.CatchAllDocuments" Disabled="@this.Disabled" OnPathsDropped="@this.PathsDropped">
|
||||
<PathDropZone CatchAllDocuments="@this.CatchAllDocuments" Disabled="@(() => this.Disabled)" OnPathsDropped="@this.PathsDropped">
|
||||
@this.Picker
|
||||
<MudText Typo="Typo.body2">
|
||||
@T("You can also drag & drop the folder here.")
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
@if (this.EnableDragDrop)
|
||||
{
|
||||
<PathDropZone CatchAllDocuments="@this.CatchAllDocuments" Disabled="@this.Disabled" OnPathsDropped="@this.PathsDropped">
|
||||
<PathDropZone CatchAllDocuments="@this.CatchAllDocuments" Disabled="@(() => this.Disabled)" OnPathsDropped="@this.PathsDropped">
|
||||
@this.Picker
|
||||
<MudText Typo="Typo.body2">
|
||||
@T("You can also drag & drop the file here.")
|
||||
|
||||
@ -4,7 +4,9 @@
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<DropZoneScope>
|
||||
@* The name for the drop state is given although nobody uses it: the messages of this dialog
|
||||
are listed in a table, whose rows would otherwise ask for the same name. *@
|
||||
<PathDropZone IsArea="@true" Context="isDropTarget">
|
||||
<MudJustifiedText Class="mb-3" Typo="Typo.body1">
|
||||
@T("Create your custom chat template to tailor the LLM's behavior for specific tasks or domains. Define a custom system prompt and provide an example conversation to design an AI experience perfectly suited to your requirements.")
|
||||
</MudJustifiedText>
|
||||
@ -203,7 +205,7 @@
|
||||
}
|
||||
|
||||
<Issues IssuesData="@this.dataIssues"/>
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
@if (this.IsReadOnly)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<DropZoneScope>
|
||||
<PathDropZone IsArea="@true">
|
||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
@ -193,7 +193,7 @@
|
||||
</MudStack>
|
||||
</MudForm>
|
||||
<Issues IssuesData="@this.dataIssues"/>
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<DropZoneScope>
|
||||
<PathDropZone IsArea="@true">
|
||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
@ -193,7 +193,7 @@
|
||||
</MudStack>
|
||||
</MudForm>
|
||||
<Issues IssuesData="@this.dataIssues"/>
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<DropZoneScope>
|
||||
<PathDropZone IsArea="@true">
|
||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||
@T("See how we load your file. Review the content before we process it further.")
|
||||
</MudJustifiedText>
|
||||
@ -102,7 +102,7 @@
|
||||
}
|
||||
</MudTabs>
|
||||
}
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Close" Variant="Variant.Filled" Color="Color.Primary">
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<DropZoneScope>
|
||||
<PathDropZone IsArea="@true">
|
||||
<MudPaper Class="pa-3 mb-8 border-dashed border rounded-lg">
|
||||
<ConfigurationOption OptionDescription="@T("Preselect batch processing options?")" LabelOn="@T("Batch processing options are preselected")" LabelOff="@T("No batch processing options are preselected")" State="@(() => this.SettingsManager.ConfigurationData.BatchProcessing.PreselectOptions)" StateUpdate="@(value => this.SettingsManager.ConfigurationData.BatchProcessing.PreselectOptions = value)" OptionHelp="@T("When enabled, new batch runs start with the defaults configured below.")" IsLocked="() => ManagedConfiguration.TryGet(x => x.BatchProcessing, x => x.PreselectOptions, out var meta) && meta.IsLocked"/>
|
||||
|
||||
@ -88,7 +88,7 @@
|
||||
<ConfigurationMinConfidenceSelection Disabled="@this.DefaultsDisabled" RestrictToGlobalMinimumConfidence="true" SelectedValue="@(() => this.SettingsManager.ConfigurationData.BatchProcessing.MinimumProviderConfidence)" SelectionUpdate="@(value => this.SettingsManager.ConfigurationData.BatchProcessing.MinimumProviderConfidence = value)" IsLocked="() => ManagedConfiguration.TryGet(x => x.BatchProcessing, x => x.MinimumProviderConfidence, out var meta) && meta.IsLocked"/>
|
||||
<ConfigurationProviderSelection Component="Components.BATCH_PROCESSING_ASSISTANT" Data="@this.AvailableLLMProviders" Disabled="@this.DefaultsDisabled" SelectedValue="@(() => this.SettingsManager.ConfigurationData.BatchProcessing.PreselectedProvider)" SelectionUpdate="@(value => this.SettingsManager.ConfigurationData.BatchProcessing.PreselectedProvider = value)" IsLocked="() => ManagedConfiguration.TryGet(x => x.BatchProcessing, x => x.PreselectedProvider, out var meta) && meta.IsLocked"/>
|
||||
</MudPaper>
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Close" Variant="Variant.Filled">@T("Close")</MudButton>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
@* The chat is a drop area: a file dropped anywhere in it hangs itself on the composer, which is
|
||||
what users are used to. *@
|
||||
<DropZoneScope Class="inner-scrolling-context">
|
||||
<PathDropZone IsArea="@true" Class="inner-scrolling-context">
|
||||
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2" StretchItems="StretchItems.Start">
|
||||
<MudText Typo="Typo.h3">
|
||||
@ -168,4 +168,4 @@
|
||||
</MudDrawerContainer>
|
||||
</MudDrawer>
|
||||
}
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
|
||||
@ -5,8 +5,13 @@
|
||||
@attribute [Route(Routes.PLUGINS)]
|
||||
|
||||
@* The page is its own drop target: a plugin archive may be dropped anywhere on it, and there is no
|
||||
inner zone to hand that role to. Hence the page owns the scope state instead of reading it. *@
|
||||
<DropZoneScope State="@this.dropZoneScope" Class="inner-scrolling-context">
|
||||
inner zone to hand that role to. An area which takes drops itself is that target by definition. *@
|
||||
<PathDropZone IsArea="@true"
|
||||
IdPrefix="plugins-page"
|
||||
Class="inner-scrolling-context"
|
||||
Disabled="@(() => !this.CanCatchDroppedFile())"
|
||||
OnPathsDropped="@this.ImportDroppedPluginArchiveAsync"
|
||||
Context="isDropTarget">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2">
|
||||
<MudText Typo="Typo.h3">
|
||||
@T("Plugins")
|
||||
@ -26,7 +31,7 @@
|
||||
|
||||
<InnerScrolling>
|
||||
|
||||
<MudTable Items="@PluginFactory.AvailablePlugins" Hover="@true" GroupBy="@this.groupConfig" Class="@this.PluginTableClass">
|
||||
<MudTable Items="@PluginFactory.AvailablePlugins" Hover="@true" GroupBy="@this.groupConfig" Class="@PluginTableClass(isDropTarget)">
|
||||
<ColGroup>
|
||||
<col style="width: 2em;" />
|
||||
<col style="width: 2.1em; "/>
|
||||
@ -155,4 +160,4 @@
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</InnerScrolling>
|
||||
</DropZoneScope>
|
||||
</PathDropZone>
|
||||
|
||||
@ -42,14 +42,6 @@ public partial class Plugins : MSGComponentBase
|
||||
|
||||
private bool isSharingPlugin;
|
||||
|
||||
/// <summary>
|
||||
/// The drop area of this page. The page owns it rather than reading it from a cascading value,
|
||||
/// because a component cannot read what it cascades itself.
|
||||
/// </summary>
|
||||
private readonly DropZoneScopeState dropZoneScope = new($"plugins-page-{Guid.NewGuid():N}");
|
||||
|
||||
private bool isDraggingOverPage;
|
||||
|
||||
private const string IMPORT_ICON =
|
||||
@"<svg class=""mud-icon-root mud-svg-icon mud-dark-text mud-icon-size-medium"" focusable=""false"" viewBox=""0 0 24 24"" aria-hidden=""true"" role=""img"">
|
||||
<path d=""M0 0h24v24H0V0z"" fill=""none""></path>
|
||||
@ -61,10 +53,7 @@ public partial class Plugins : MSGComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
this.ApplyFilters([], [ Event.PLUGINS_RELOADED, Event.CONFIGURATION_CHANGED, Event.HIGHLIGHT_DROP_ZONE, Event.PATHS_DROPPED ]);
|
||||
|
||||
// The whole page is the drop target, so users can drop a plugin archive anywhere on it:
|
||||
this.dropZoneScope.TryBecomeDefaultZone(this);
|
||||
this.ApplyFilters([], [ Event.PLUGINS_RELOADED, Event.CONFIGURATION_CHANGED ]);
|
||||
|
||||
this.groupConfig = new TableGroupDefinition<IPluginMetadata>
|
||||
{
|
||||
@ -90,12 +79,6 @@ public partial class Plugins : MSGComponentBase
|
||||
await this.TryAutoAuditAssistantsAsync();
|
||||
}
|
||||
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
this.dropZoneScope.ReleaseDefaultZone(this);
|
||||
base.DisposeResources();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private async Task PluginActivationStateChanged(IPluginMetadata pluginMeta)
|
||||
@ -275,7 +258,8 @@ public partial class Plugins : MSGComponentBase
|
||||
/// Highlights the plugin table while the user drags a file over the page, so it is visible
|
||||
/// where the file would land.
|
||||
/// </summary>
|
||||
private string PluginTableClass => this.isDraggingOverPage
|
||||
/// <param name="isDropTarget">Whether the page is the target of the drop being aimed right now.</param>
|
||||
private static string PluginTableClass(bool isDropTarget) => isDropTarget
|
||||
? "border-dashed border rounded-lg mud-border-primary border-4"
|
||||
: "border-dashed border rounded-lg";
|
||||
|
||||
@ -570,54 +554,11 @@ public partial class Plugins : MSGComponentBase
|
||||
case Event.CONFIGURATION_CHANGED:
|
||||
await this.InvokeAsync(this.StateHasChanged);
|
||||
break;
|
||||
|
||||
case Event.HIGHLIGHT_DROP_ZONE when data is DropZoneHighlight highlight:
|
||||
this.ApplyHighlight(this.IsThisZone(highlight.ZoneId));
|
||||
break;
|
||||
|
||||
case Event.PATHS_DROPPED when data is DroppedPaths dropped:
|
||||
// Whoever the drop was meant for, the drag is over and nothing stays highlighted:
|
||||
this.ApplyHighlight(false);
|
||||
|
||||
if (!this.IsThisZone(dropped.ZoneId))
|
||||
return;
|
||||
|
||||
if (!this.CanCatchDroppedFile())
|
||||
{
|
||||
LOG.LogDebug("The plugins page cannot import right now and swallowed {Count} dropped path(s).", dropped.Paths.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.ImportDroppedPluginArchiveAsync(dropped.Paths);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Decides whether the named zone is this page.
|
||||
/// </summary>
|
||||
/// <param name="zoneId">The ID the hit test reported, or null when it hit nothing.</param>
|
||||
private bool IsThisZone(string? zoneId) => zoneId is not null && zoneId == this.dropZoneScope.ScopeId;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the page as the drop target, or takes that mark away.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The comparison is not for tidiness: a throttled drag-over event arrives about ten times per
|
||||
/// second, and without it every one of them would render the whole plugin table anew.
|
||||
/// </remarks>
|
||||
private void ApplyHighlight(bool shouldBeHighlighted)
|
||||
{
|
||||
var highlighted = shouldBeHighlighted && this.CanCatchDroppedFile();
|
||||
if (highlighted == this.isDraggingOverPage)
|
||||
return;
|
||||
|
||||
this.isDraggingOverPage = highlighted;
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decides whether this page may process dropped files: only when the organization allows
|
||||
/// importing plugins at all and no import is running.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user