@* * dbMango * * Copyright 2025 Deutsche Bank AG * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *@ 
@code { [Parameter] public string Class { get; set; } = ""; [Parameter] public string Text { get => _text; set { if (_text == value) return; _text = value; Task.Run( async () => await JsRuntime!.InvokeVoidAsync("DashboardUtils.CodeEditor_SetValue", _scriptEditorReference, _text) ); } } [Parameter] public EventCallback TextChanged { get; set; } [Parameter] public int Rows { get; set; } = 50; [Parameter] public string MimeType { get; set; } = "text/plain"; [Parameter] public bool Readonly { get; set { field = value; SetReadonlyMode(); } } = false; [Inject] public IJSRuntime? JsRuntime { get; set; } private bool _initialized = false; private DotNetObjectReference? _objRef = null; private ElementReference _scriptEditorReference; private string _text = ""; protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { _objRef = DotNetObjectReference.Create(this); await JsRuntime!.InvokeVoidAsync("DashboardUtils.LoadCodeEditor", "TECCodeMirrorArea", MimeType, _scriptEditorReference, _objRef, "UpdateTextField", Readonly); _initialized = true; await InvokeAsync(StateHasChanged); } } private void SetReadonlyMode() { if (_objRef == null) { return; } JsRuntime!.InvokeVoidAsync("DashboardUtils.CodeEditor_SetParam", _scriptEditorReference, "readOnly", Readonly); } [JSInvokable("UpdateTextField")] public async Task UpdateTextField(string codeValue) { if (_text == codeValue) return; _text = codeValue; await TextChanged.InvokeAsync(codeValue); await InvokeAsync(StateHasChanged); } }