From e5e2a31845e4b1ed13363f4dc944b125e56f76ee Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 6 Jun 2025 10:20:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20OnLoaded=20?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PdfViewer.razor.cs | 44 ++++++++++++++++++- .../PdfViewer.razor.js | 15 +++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs index d80548eb..febcb9f1 100644 --- a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs +++ b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs @@ -23,6 +23,18 @@ public partial class PdfViewer [Parameter] public string? Height { get; set; } + /// + /// Gets or sets the document loaded event callback. + /// + [Parameter] + public Func? OnLoaded { get; set; } + + /// + /// Gets or sets the document loaded event callback. + /// + [Parameter] + public Func? NotSupportCallback { get; set; } + private string? ClassString => CssBuilder.Default("bb-pdf-viewer-container") .AddClassFromAttributes(AdditionalAttributes) .Build(); @@ -58,5 +70,35 @@ protected override async Task OnAfterRenderAsync(bool firstRender) /// /// /// - protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id); + protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new + { + LoadedCallaback = nameof(TriggerOnLoaded), + NotSupportCallback = nameof(TriggerNotSupportCallback) + }); + + /// + /// Trigger OnLoaded callback when the PDF document is loaded. + /// + /// + [JSInvokable] + public async Task TriggerOnLoaded() + { + if (OnLoaded != null) + { + await OnLoaded(); + } + } + + /// + /// Trigger NotSupportCallback when the PDF viewer does not support the document. + /// + /// + [JSInvokable] + public async Task TriggerNotSupportCallback() + { + if (NotSupportCallback != null) + { + await NotSupportCallback(); + } + } } diff --git a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js index d043fd1c..51f22381 100644 --- a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js +++ b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js @@ -1,11 +1,15 @@ import { addLink } from "../BootstrapBlazor/modules/utility.js" import Data from "../BootstrapBlazor/modules/data.js" -export async function init(id) { +export async function init(id, invoke, options) { await addLink("./_content/BootstrapBlazor.PdfViewer/pdf-viewer.css"); + if (!navigator.pdfViewerEnabled) { + await invoke.invokeMethodAsync(options.notSupportCallback); + } + const el = document.getElementById(id); - const pdfViewer = { el }; + const pdfViewer = { el, invoke, options }; Data.set(id, pdfViewer); const url = el.getAttribute('data-bb-url'); @@ -16,8 +20,13 @@ export function loadPdf(id, url) { const pdfViewer = Data.get(id); const { el } = pdfViewer; if (url) { - const { frame } = pdfViewer; + const { frame, invoke, options } = pdfViewer; const viewer = frame || createFrame(el); + if (options.loadedCallaback) { + viewer.onload = () => { + invoke.invokeMethodAsync(options.loadedCallaback); + }; + } viewer.src = url; } else { From bd0e46ce8d8eb16aeac0028faa143bf059d2785e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 6 Jun 2025 10:21:04 +0800 Subject: [PATCH 2/5] chore: bump version 9.0.0 --- .../BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj b/src/components/BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj index 6c69df1e..7e568d3d 100644 --- a/src/components/BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj +++ b/src/components/BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj @@ -1,7 +1,7 @@ - 9.0.0-beta01 + 9.0.0 From ff25b5ee44786bb0b7c2e2627e0c5fc1cea42ec2 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 6 Jun 2025 10:22:29 +0800 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=94=AF=E6=8C=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js index 51f22381..5828017b 100644 --- a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js +++ b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js @@ -6,6 +6,7 @@ export async function init(id, invoke, options) { if (!navigator.pdfViewerEnabled) { await invoke.invokeMethodAsync(options.notSupportCallback); + return; } const el = document.getElementById(id); From 406a9dbcd88a89a997f90875acecca5a16948958 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 6 Jun 2025 10:23:28 +0800 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.PdfViewer/PdfViewer.razor.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js index 5828017b..820e6d80 100644 --- a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js +++ b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js @@ -4,11 +4,6 @@ import Data from "../BootstrapBlazor/modules/data.js" export async function init(id, invoke, options) { await addLink("./_content/BootstrapBlazor.PdfViewer/pdf-viewer.css"); - if (!navigator.pdfViewerEnabled) { - await invoke.invokeMethodAsync(options.notSupportCallback); - return; - } - const el = document.getElementById(id); const pdfViewer = { el, invoke, options }; Data.set(id, pdfViewer); @@ -19,9 +14,15 @@ export async function init(id, invoke, options) { export function loadPdf(id, url) { const pdfViewer = Data.get(id); - const { el } = pdfViewer; + const { el, invoke, options } = pdfViewer; + + if (!navigator.pdfViewerEnabled) { + await invoke.invokeMethodAsync(options.notSupportCallback); + return; + } + if (url) { - const { frame, invoke, options } = pdfViewer; + const { frame } = pdfViewer; const viewer = frame || createFrame(el); if (options.loadedCallaback) { viewer.onload = () => { From 4cd3d9c6a1700b7845c157aa7b120a2e2c1d8af4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 6 Jun 2025 10:25:43 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js index 820e6d80..f29350f7 100644 --- a/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js +++ b/src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js @@ -9,10 +9,10 @@ export async function init(id, invoke, options) { Data.set(id, pdfViewer); const url = el.getAttribute('data-bb-url'); - loadPdf(id, url); + await loadPdf(id, url); } -export function loadPdf(id, url) { +export async function loadPdf(id, url) { const pdfViewer = Data.get(id); const { el, invoke, options } = pdfViewer;