From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.Client.Blazor/Util/ElementReferenceEx.cs |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/HotelPms.Client.Blazor/Util/ElementReferenceEx.cs b/HotelPms.Client.Blazor/Util/ElementReferenceEx.cs
new file mode 100644
index 0000000..1980f52
--- /dev/null
+++ b/HotelPms.Client.Blazor/Util/ElementReferenceEx.cs
@@ -0,0 +1,49 @@
+using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
+using System.Reflection;
+
+namespace HotelPms.Client.Blazor.Util
+{
+    public static class ElementReferenceEx
+    {
+        private static readonly PropertyInfo jsRuntimeProperty = typeof(WebElementReferenceContext).GetProperty("JSRuntime", BindingFlags.Instance | BindingFlags.NonPublic);
+
+        internal static IJSRuntime GetJSRuntime(this ElementReference elementReference)
+        {
+            if (elementReference.Context is not WebElementReferenceContext context)
+            {
+                return null;
+            }
+
+            return (IJSRuntime)jsRuntimeProperty.GetValue(context);
+        }
+
+        /// <summary>
+        /// input[text] or textarea
+        /// </summary>
+        /// <param name="elementReference"></param>
+        /// <returns></returns>
+        public static ValueTask<string> GetInputValue(this ElementReference elementReference)
+        {
+            return elementReference.GetJSRuntime()?.InvokeAsync<string>("NetCallJs.getInputValue", elementReference) ?? ValueTask.FromResult(string.Empty);
+        }
+
+        /// <summary>
+        /// input[text] or textarea
+        /// </summary>
+        /// <param name="elementReference"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        public static ValueTask SetInputValue(this ElementReference elementReference, string value) => elementReference.GetJSRuntime()?.InvokeVoidAsync("NetCallJs.setInputValue", elementReference, value) ?? ValueTask.CompletedTask;
+
+        public static ValueTask<BoundingClientRect> GetClientRect(this ElementReference elementReference)
+        {
+            return elementReference.GetJSRuntime()?.InvokeAsync<BoundingClientRect>("NetCallJs.getClientRect", elementReference) ?? ValueTask.FromResult(new BoundingClientRect());
+        }
+
+        public static ValueTask<ScrollPosition> GetScroll(this ElementReference elementReference)
+        {
+            return elementReference.GetJSRuntime()?.InvokeAsync<ScrollPosition>("NetCallJs.getScroll", elementReference) ?? ValueTask.FromResult(new ScrollPosition());
+        }
+    }
+}

--
Gitblit v1.10.0