Skip to content

Commit cd7431c

Browse files
committed
Added support for customizing where to find the javascript required to run
1 parent 3ee713b commit cd7431c

15 files changed

Lines changed: 70 additions & 17 deletions

File tree

Demo/BlazorFluentUI.Demo.Server/Pages/_Layout.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<link href="css/site.css" rel="stylesheet" />
1515

1616
<script src="https://cdn.quilljs.com/1.3.7/quill.js"></script>
17-
<script src="_content/BlazorFluentUI.CoreComponents/richTextEditor.js"></script> <title>Blazor Fluent UI Server Demo</title>
17+
<script src="_content/BlazorFluentUI.CoreComponents/richTextEditor.js"></script>
18+
<title>Blazor Fluent UI Server Demo</title>
1819
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
1920
</head>
2021
<body>

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<IsPackable>true</IsPackable>
1414
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
1515
<PackageOutputPath>../../packages</PackageOutputPath>
16-
<Version>8.0.0.4</Version>
16+
<Version>8.0.0.5</Version>
1717
<!--<GeneratePackageOnBuild>false</GeneratePackageOnBuild>-->
1818
</PropertyGroup>
1919

src/BlazorFluentUI.CoreComponents/BaseComponent/FluentUIComponentBase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,18 @@ public class FluentUIComponentBase : ComponentBase, IAsyncDisposable
6464

6565
[Inject] ScopedStatics? ScopedStatics { get; set; }
6666

67-
protected const string BasePath = "./_content/BlazorFluentUI.CoreComponents/baseComponent.js";
67+
internal const string BaseComponentJs = "baseComponent.js";
68+
internal const string BaseComponentPath = "_content/BlazorFluentUI.CoreComponents/";
69+
internal const string DefaultBasePath = "./";
70+
71+
private static string? _appBasePath = null;
72+
private static string? _baseComponentPath = null;
73+
74+
protected string AppBasePath => _appBasePath ??= (Settings.AssetsPath ?? ((Settings.BasePath ?? DefaultBasePath) + BaseComponentPath));
75+
76+
protected string BuildScriptPath(ref string? scriptPath, string scriptName) => scriptPath ??= AppBasePath + scriptName;
77+
78+
protected string BasePath => _baseComponentPath ??= BuildScriptPath(ref _baseComponentPath, BaseComponentJs);
6879
protected IJSObjectReference? baseModule;
6980

7081
protected CancellationTokenSource cancellationTokenSource = new();

src/BlazorFluentUI.CoreComponents/Callout/CalloutContent.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ namespace BlazorFluentUI
1111
{
1212
public partial class CalloutContent : FluentUIComponentBase, IAsyncDisposable
1313
{
14-
private const string CalloutPath = "./_content/BlazorFluentUI.CoreComponents/callout.js";
14+
private string? _calloutPath;
15+
16+
private string CalloutPath => _calloutPath ??= BuildScriptPath(ref _calloutPath, "callout.js");
17+
1518
private IJSObjectReference? calloutModule;
1619

1720

src/BlazorFluentUI.CoreComponents/DocumentCard/DocumentCard.razor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public partial class DocumentCard : FluentUIComponentBase, IAsyncDisposable
4646
/// </summary>
4747
[Parameter] public string? OnClickTarget { get; set; }
4848

49+
private string? _scriptPath;
4950

50-
private const string ScriptPath = "./_content/BlazorFluentUI.CoreComponents/documentCard.js";
51+
private string ScriptPath => _scriptPath ??= BuildScriptPath(ref _scriptPath, "documentCard.js");
5152
private IJSObjectReference? scriptModule;
5253

5354
[Inject]

src/BlazorFluentUI.CoreComponents/DocumentCard/DocumentCardTitle.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public partial class DocumentCardTitle : FluentUIComponentBase, IAsyncDisposable
3535
/// </value>
3636
[Parameter] public bool ShowAsSecondaryTitle { get; set; }
3737

38-
private const string ScriptPath = "./_content/BlazorFluentUI.CoreComponents/documentCard.js";
38+
private string? _scriptPath;
39+
40+
private string ScriptPath => _scriptPath ??= BuildScriptPath(ref _scriptPath, "documentCard.js");
41+
3942
private IJSObjectReference? scriptModule;
4043
private DotNetObjectReference<DocumentCardTitle>? selfReference;
4144

src/BlazorFluentUI.CoreComponents/FluentUISettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ public sealed record FluentUISettings
1111
public static FluentUISettings Default { get; } = new FluentUISettings();
1212

1313
public bool UseFluentUISystemIcons { get; set; } = true;
14+
15+
public string? BasePath { get; set; }
16+
17+
public string? AssetsPath { get; set; }
1418
}
1519
}

src/BlazorFluentUI.CoreComponents/FocusTrapZone/FocusTrapZone.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ namespace BlazorFluentUI
88
{
99
public partial class FocusTrapZone : FluentUIComponentBase, IAsyncDisposable
1010
{
11-
private const string ScriptPath = "./_content/BlazorFluentUI.CoreComponents/focusTrapZone.js";
11+
private string? _scriptPath;
12+
13+
private string ScriptPath => _scriptPath ??= BuildScriptPath(ref _scriptPath, "focusTrapZone.js");
14+
1215
private IJSObjectReference? scriptModule;
1316

1417
[Parameter]

src/BlazorFluentUI.CoreComponents/FocusZone/FocusZone.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ namespace BlazorFluentUI
1212
public partial class FocusZone : FluentUIComponentBase, IAsyncDisposable
1313
{
1414
//[Inject] private IJSRuntime? JSRuntime { get; set; }
15-
private const string ScriptPath = "./_content/BlazorFluentUI.CoreComponents/focusZone.js";
15+
private string? _scriptPath;
16+
17+
private string ScriptPath => _scriptPath ??= BuildScriptPath(ref _scriptPath, "focusZone.js");
18+
1619
private IJSObjectReference? scriptModule;
1720
//private const string BasePath = "./_content/BlazorFluentUI.CoreComponents/baseComponent.js";
1821
//private IJSObjectReference? baseModule;

src/BlazorFluentUI.CoreComponents/List/List.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ public class List<TItem> : FluentUIComponentBase, IAsyncDisposable
4848
public bool IsVirtualizing { get; set; } = true;
4949
//[Parameter]
5050
//public EventCallback<Viewport> OnViewportChanged { get; set; }
51+
private string? _scriptPath;
52+
53+
private string ScriptPath => _scriptPath ??= BuildScriptPath(ref _scriptPath, "list.js");
5154

52-
private const string scriptPath = "./_content/BlazorFluentUI.CoreComponents/list.js";
5355
private IJSObjectReference? scriptModule;
5456

5557

@@ -183,7 +185,7 @@ protected override void OnParametersSet()
183185
protected override async Task OnAfterRenderAsync(bool firstRender)
184186
{
185187
if (scriptModule == null)
186-
scriptModule = await JSRuntime!.InvokeAsync<IJSObjectReference>("import", scriptPath);
188+
scriptModule = await JSRuntime!.InvokeAsync<IJSObjectReference>("import", ScriptPath);
187189
if (firstRender)
188190
{
189191
_selfReference = DotNetObjectReference.Create(this);

0 commit comments

Comments
 (0)