Loading...
Loading...
Implements Syncfusion SfSmartRichTextEditor, an AI-enhanced WYSIWYG editor extending SfRichTextEditor in Blazor. Use this when configuring AI backends (OpenAI, Azure OpenAI, Ollama, custom IChatClient), Smart Action toolbar, AI query dialog, AssistViewSettings, AI popup events and methods, or any inherited Rich Text Editor features in Blazor Server and Web App.
npx skill4agent add syncfusion/blazor-ui-components-skills syncfusion-blazor-smart-rich-text-editorSfSmartRichTextEditorSfRichTextEditorAlt+EnterAssistViewSettingsSfSmartRichTextEditorIChatClientIChatInferenceServiceSyncfusionAIServiceProgram.csName = "AI Commands"Name = "AI Query"ToolbarItemModelAlt+EnterAssistViewSettingsCommandsSuggestionsPromptsPlaceholderMaxPromptHistoryBannerTemplateHeaderToolbarSettingsPromptToolbarSettingsResponseToolbarSettingsAIPromptRequestedAIResponseStoppedAIToolbarItemClickedAIPopupOpeningAIPopupClosingShowAIPopupAsyncHideAIPopupAsyncExecuteAIPromptAsyncUpdateAIResponseAsyncGetAIPromptHistoryAsyncClearAIPromptHistoryAsync.e-rte-aiquery-dialogSfRichTextEditordotnet add package Syncfusion.Blazor.SmartRichTextEditor
dotnet add package Syncfusion.Blazor.Themes
dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.Extensions.AI.OpenAIProgram.csusing Syncfusion.Blazor;
using Syncfusion.Blazor.AI;
using Microsoft.Extensions.AI;
using OpenAI;
builder.Services.AddSyncfusionBlazor();
string openAIApiKey = "YOUR_API_KEY";
string openAIModel = "gpt-4";
OpenAIClient openAIClient = new OpenAIClient(openAIApiKey);
IChatClient chatClient = openAIClient.GetChatClient(openAIModel).AsIChatClient();
builder.Services.AddChatClient(chatClient);
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();_Imports.razor@using Syncfusion.Blazor
@using Syncfusion.Blazor.SmartRichTextEditorApp.razorindex.html<link href="_content/Syncfusion.Blazor.Themes/tailwind.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js"></script>@rendermode InteractiveServer
<SfSmartRichTextEditor>
<h2>Welcome to Smart Rich Text Editor</h2>
<p>Select text and use the Smart Action toolbar, or press Alt+Enter to open the AI Query dialog.</p>
<AssistViewSettings Placeholder="Ask AI to rewrite or generate content." />
</SfSmartRichTextEditor>Syncfusion.Blazor.SmartRichTextEditorSyncfusion.Blazor.ThemesIChatClientProgram.csAddInteractiveServerComponents()AssistViewSettingsGetTextAsyncGetCharCountAsyncgpt-4-turbogpt-4gpt-3.5-turboOpenAIClientAzureOpenAIClientApiKeyCredentialappsettings.jsonmistralllama2OllamaApiClientOllamaSharpIChatClientIChatClientProgram.csCommandsList<AICommands>PopupMaxHeightPopupWidthPlaceholderPromptsList<AssistViewPrompt>SuggestionsList<string>MaxPromptHistoryBannerTemplateRenderFragmentHeaderToolbarSettingsPromptToolbarSettingsResponseToolbarSettingsAssistViewToolbarItemAIPromptRequestedAssistViewPromptRequestedEventArgsCancel=trueResponsePromptSuggestionsResponseToolbarItemsAIResponseStoppedResponseStoppedEventArgsDataIndexPromptAIToolbarItemClickedAssistViewToolbarItemClickedEventArgsItemDataIndexEventCancel=trueAIPopupOpeningBeforeOpenEventArgsargs.Cancel = trueElementAIPopupClosingBeforeCloseEventArgsClosedByIsInteractedPreventFocusShowAIPopupAsync()HideAIPopupAsync()ExecuteAIPromptAsync(string prompt)UpdateAIResponseAsync(string response, bool isFinalUpdate)isFinalUpdate=trueGetAIPromptHistoryAsync()AssistViewPrompt[]MaxPromptHistoryClearAIPromptHistoryAsync()@ref.e-rte-aiquery-dialog.e-aiassistview.e-view-header.e-view-content .e-toolbar.e-footerRichTextEditorToolbarSettings.EnableToolbarItemModelSfSmartRichTextEditorName = "AI Commands"Name = "AI Query"NameToolbarCommandToolbarCommandSfSmartRichTextEditorRichTextEditorImageSettingsCreateTableRichTextEditorTableSettingsEditorMode.MarkdownInlineModeToolbarItemModelExecuteCommandAsync/RichTextEditorFormatPainterSettingsRichTextEditorEventsCreatedDestroyedFocusBlurOnToolbarClickSelectionChangedValueChangeBeforePasteCleanupAfterPasteCleanupOnActionBeginOnActionCompleteOnDialogOpenDialogOpenedOnDialogCloseDialogClosedOnQuickToolbarOpenQuickToolbarOpenedQuickToolbarClosedOnImageSelectedBeforeUploadImageOnImageUploadSuccessOnImageUploadFailedImageUploadChangeOnImageDropImageDeleteFileSelectedFileUploadingFileUploadSuccessFileUploadFailedFileUploadChangeOnMediaDropMediaDeletedOnResizeStartOnResizeStopUpdatedToolbarStatusOnExportOnExportFailureSlashMenuItemSelectingFocusAsyncFocusOutAsyncSaveSelectionAsyncRestoreSelectionAsyncSelectAllAsyncGetSelectionAsyncGetTextAsyncGetSelectedHtmlAsyncGetCharCountAsyncGetXhtmlAsyncExecuteCommandAsyncEnableToolbarItemDisableToolbarItemRemoveToolbarItemShowDialogAsyncCloseDialogAsyncShowFullScreenAsyncPrintAsyncRefreshUIAsyncShowSourceCodeAsyncClearUndoRedoAsyncCommandNameToolbarCommandDialogTypeValuePlaceholderReadonlyEnabledMaxLengthShowCharCountEditorModeEnterKeyShiftEnterKeyEnableTabKeyEnableAutoUrlEnableMarkdownAutoFormatEnableClipboardCleanupEnableXhtmlEnableHtmlEncodeEnableResizeHeightWidthCssClassShowTooltipFloatingToolbarOffsetRichTextEditorIFrameSettingsEnableAttributesResourcesEnableHtmlSanitizerAdditionalSanitizeAttributesAdditionalSanitizeTagsDeniedSanitizeSelectorsKeyConfigureShortcutKeysEnablePersistenceSaveIntervalAutoSaveOnIdleUndoRedoStepsUndoRedoTimerHttpClientInstance@bind-ValueValueChangeReadonlyRichTextEditorPasteCleanupSettingsEnterKeyShiftEnterKeyEnableRtl@rendermode InteractiveServer
@using Syncfusion.Blazor.SmartRichTextEditor
<SfSmartRichTextEditor @bind-Value="@Content">
<AssistViewSettings Placeholder="Ask AI to rewrite or generate content." />
</SfSmartRichTextEditor>
@code {
private string Content { get; set; } = "<p>Start editing...</p>";
}<SfSmartRichTextEditor>
<AssistViewSettings Commands="@MyCommands" Suggestions="@QuickSuggestions" />
</SfSmartRichTextEditor>
@code {
private List<AICommands> MyCommands = new()
{
new AICommands { Text = "Summarize", Prompt = "Summarize this content concisely" },
new AICommands { Text = "Expand", Prompt = "Add more details and examples" },
new AICommands
{
Text = "Translate",
Items = new List<AICommands>
{
new AICommands { Text = "To French", Prompt = "Translate to French" },
new AICommands { Text = "To Spanish", Prompt = "Translate to Spanish" }
}
}
};
private List<string> QuickSuggestions = new()
{
"Fix grammar", "Make shorter", "More formal", "Simplify"
};
}<SfSmartRichTextEditor>
<AssistViewSettings @ref="AssistViewRef" MaxPromptHistory="10" />
</SfSmartRichTextEditor>
<button @onclick="OpenAI">Open AI</button>
<button @onclick="RunPrompt">Run Prompt</button>
@code {
private AssistViewSettings AssistViewRef;
private async Task OpenAI() =>
await AssistViewRef.ShowAIPopupAsync();
private async Task RunPrompt() =>
await AssistViewRef.ExecuteAIPromptAsync("Improve the clarity of this text");
}<SfSmartRichTextEditor @bind-Value="@HtmlContent" ShowCharCount="true" MaxLength="2000">
<AssistViewSettings Placeholder="Ask AI for writing help." />
</SfSmartRichTextEditor>
@code {
private string HtmlContent { get; set; } = string.Empty;
}<SfSmartRichTextEditor Value="@HtmlContent" Readonly="true">
<RichTextEditorToolbarSettings Enable="false" />
</SfSmartRichTextEditor><SfSmartRichTextEditor EditorMode="EditorMode.Markdown" @bind-Value="@MarkdownContent">
<AssistViewSettings Placeholder="Ask AI to help with your Markdown content." />
</SfSmartRichTextEditor>
@code {
private string MarkdownContent { get; set; } = "**Hello** world!";
}<SfSmartRichTextEditor>
<AssistViewSettings AIPromptRequested="OnAIPrompt" />
</SfSmartRichTextEditor>
@code {
private async Task OnAIPrompt(AssistViewPromptRequestedEventArgs args)
{
// Log, validate, or modify args.Prompt before it is sent to AI
Console.WriteLine($"Prompt: {args.Prompt}");
// To cancel: args.Cancel = true;
}
}