| | | 1 | | using System.Reflection; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows.UIHints.CodeEditor; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides options for the code editor component. |
| | | 7 | | /// </summary> |
| | | 8 | | public abstract class CodeEditorOptionsProviderBase : PropertyUIHandlerBase |
| | | 9 | | { |
| | | 10 | | /// <inheritdoc /> |
| | | 11 | | public override ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? conte |
| | | 12 | | { |
| | 582 | 13 | | var codeEditorOptions = GetCodeEditorOptions(propertyInfo, context); |
| | | 14 | | |
| | 582 | 15 | | var options = new Dictionary<string, object> |
| | 582 | 16 | | { |
| | 582 | 17 | | [InputUIHints.CodeEditor] = codeEditorOptions |
| | 582 | 18 | | }; |
| | | 19 | | |
| | 582 | 20 | | return new(options); |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Returns an object containing properties that will be used to render the UI for the property. |
| | | 25 | | /// </summary> |
| | | 26 | | protected virtual CodeEditorOptions GetCodeEditorOptions(PropertyInfo propertyInfo, object? context) |
| | | 27 | | { |
| | 582 | 28 | | var language = GetLanguage(propertyInfo, context); |
| | 582 | 29 | | var options = new CodeEditorOptions(); |
| | | 30 | | |
| | 582 | 31 | | if (!string.IsNullOrWhiteSpace(language)) |
| | 582 | 32 | | options.Language = language; |
| | | 33 | | |
| | 582 | 34 | | return options; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Returns the language to use for syntax highlighting. |
| | | 39 | | /// </summary> |
| | 0 | 40 | | protected virtual string GetLanguage(PropertyInfo propertyInfo, object? context) => ""; |
| | | 41 | | } |