migrate CSS references and remove JS Interop methods

This commit is contained in:
sbwalker
2023-05-16 09:09:18 -04:00
parent 5e652364c9
commit 89ada83012
7 changed files with 25 additions and 104 deletions

View File

@ -72,6 +72,7 @@
{
if (firstRender)
{
// prevents flash on initial page load
_display = "";
StateHasChanged();
}

View File

@ -90,21 +90,6 @@ namespace Oqtane.UI
}
}
public Task IncludeLinks(object[] links)
{
try
{
_jsRuntime.InvokeVoidAsync(
"Oqtane.Interop.includeLinks",
(object) links);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
// external scripts need to specify src, inline scripts need to specify id and content
public Task IncludeScript(string id, string src, string integrity, string crossorigin, string content, string location)
{
@ -135,21 +120,6 @@ namespace Oqtane.UI
}
}
public Task RemoveElementsById(string prefix, string first, string last)
{
try
{
_jsRuntime.InvokeVoidAsync(
"Oqtane.Interop.removeElementsById",
prefix, first, last);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
public ValueTask<string> GetElementByName(string name)
{
try

View File

@ -41,10 +41,19 @@
// PWA manifest
if (PageState.Site.PwaIsEnabled && PageState.Site.PwaAppIconFileId != null && PageState.Site.PwaSplashIconFileId != null)
{
headcontent += "<link id=\"app-manifest\" rel=\"manifest\" />";
headcontent += "<link id=\"app-manifest\" rel=\"manifest\" />\n";
}
// meta
headcontent += PageState.Page.Meta ?? "";
if (!string.IsNullOrEmpty(PageState.Page.Meta))
{
headcontent += PageState.Page.Meta + "\n";
}
// stylesheets
foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet))
{
var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url;
headcontent += CreateLink(url, resource.Integrity, resource.CrossOrigin) + "\n";
}
SiteState.Properties.HeadContent = headcontent;
// set page body content
@ -58,34 +67,18 @@
SiteState.Properties.BodyContent = bodycontent;
}
DynamicComponent = builder =>
{
var themeType = Type.GetType(PageState.Page.ThemeType);
builder.OpenComponent(0, themeType);
builder.CloseComponent();
};
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var interop = new Interop(JsRuntime);
// manage stylesheets for this page
string batch = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
var links = new List<object>();
foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet))
{
var prefix = "app-stylesheet-" + resource.Level.ToString().ToLower();
var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url;
links.Add(new { id = prefix + "-" + batch + "-" + (links.Count + 1).ToString("00"), rel = "stylesheet", href = url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", insertbefore = prefix });
}
if (links.Any())
DynamicComponent = builder =>
{
await interop.IncludeLinks(links.ToArray());
}
await interop.RemoveElementsById("app-stylesheet-page-", "", "app-stylesheet-page-" + batch + "-00");
await interop.RemoveElementsById("app-stylesheet-module-", "", "app-stylesheet-module-" + batch + "-00");
}
var themeType = Type.GetType(PageState.Page.ThemeType);
builder.OpenComponent(0, themeType);
builder.CloseComponent();
};
}
private string CreateLink(string url, string integrity, string crossorigin)
{
return "<link rel=\"stylesheet\" href=\"" + url + "\"" + (!string.IsNullOrEmpty(integrity) ? " integrity=\"" + integrity + "\"" : "") + (!string.IsNullOrEmpty(crossorigin) ? " crossorigin=\"" + crossorigin + "\"" : "") + " type=\"text/css\"/>";
}
private string CreatePWAScript(Alias alias, Site site, Route route)
{