Skip to content

Commit

Permalink
feat: setup js initializers (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderJames committed Jan 1, 2024
1 parent 88b3b1f commit 6897f94
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/AntDesign.Charts.Docs.Server/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ant Design Charts of Blazor</title>
<base href="~/" />
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet">
<script src="_content/AntDesign/js/ant-design-blazor.js"></script>
@* <link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet">
<script src="_content/AntDesign/js/ant-design-blazor.js"></script> *@
<link href="css/site.css" rel="stylesheet" />
<script type="text/javascript" src="https://unpkg.com/@@antv/g2plot@latest/dist/g2plot.min.js"></script>
<script src="_content/AntDesign.Charts/ant-design-charts-blazor.js"></script>
@* <script type="text/javascript" src="https://unpkg.com/@@antv/g2plot@latest/dist/g2plot.min.js"></script>
<script src="_content/AntDesign.Charts/ant-design-charts-blazor.js"></script> *@
</head>
<body>
<app>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/AntDesign.Charts.Docs/AntDesign.Charts.Docs.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AntDesign" Version="0.13.2" />
<PackageReference Include="AntDesign" Version="0.17.1" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
</ItemGroup>

Expand Down
35 changes: 35 additions & 0 deletions src/AntDesign.Charts/wwwroot/AntDesign.Charts.lib.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var beforeStartCalled = false;
var afterStartedCalled = false;

export function beforeWebStart() {
loadScriptAndStyle();
}

export function beforeStart(options, extensions) {
loadScriptAndStyle();
}

function loadScriptAndStyle() {
if (beforeStartCalled) {
return;
}

beforeStartCalled = true;

const interopJS = "_content/AntDesign.Charts/ant-design-charts-blazor.js";
const cdnJS = "https://unpkg.com/@antv/[email protected]/dist/g2plot.min.js";
const localJS = "_content/AntDesign.Charts/g2plot.min.js";
const cdnFlag = document.querySelector('[use-ant-design-charts-cdn]');

if (!document.querySelector(`[src="${interopJS}"]`)) {
var chartJS = cdnFlag ? cdnJS : localJS;
var chartScript = document.createElement('script');
chartScript.setAttribute('src', chartJS);

document.body.insertBefore(chartScript, document.body.querySelector("script"));

var interopScript = document.createElement('script');
interopScript.setAttribute('src', interopJS);
chartScript.after(interopScript);
}
}
17 changes: 17 additions & 0 deletions src/AntDesign.Charts/wwwroot/g2plot.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/AntDesign.Charts/wwwroot/g2plot.min.js.map

Large diffs are not rendered by default.

0 comments on commit 6897f94

Please sign in to comment.