@@ -5,7 +5,10 @@ import type {
55 ComponentProps ,
66 ComponentState ,
77 ComponentTypeSpecification ,
8- ComponentConfiguration
8+ ComponentConfiguration ,
9+ ValidationStrategy ,
10+ ValidationConfigurationMap ,
11+ ValidationConfiguration
912} from "@/components/BaseComponent/BaseComponent" ;
1013import { BaseComponent } from "@/components/BaseComponent/BaseComponent" ;
1114import type { JSONPathExpression } from "@/stores/Store" ;
@@ -25,33 +28,89 @@ export type CodeEditorComponentType = "CodeEditor";
2528 * The CodeEditor-component requires the following dependencies. The paths to the dependencies are defined here via JSONPathExpression.
2629 */
2730export interface SerializedCodeEditorDependencies extends SerialisedDependencies {
31+ /**
32+ * The globalDarkMode-property is a JSONPathExpression that may point to the user's dark mode preference.
33+ */
2834 globalDarkMode ?: JSONPathExpression ;
35+ /**
36+ * The code-property is a JSONPathExpression that may point to the user's code.
37+ */
2938 code ?: JSONPathExpression ;
39+ /**
40+ * The referenceCode-property is a JSONPathExpression that points to the reference code that the user's code will be compared against.
41+ */
42+ referenceCode ?: JSONPathExpression ;
3043}
3144
3245/**
3346 * The CodeEditor-component requires the following dependencies. The types of the dependencies are defined here.
3447 */
3548export interface CodeEditorDependencies extends ComponentDependencies {
49+ /**
50+ * The globalDarkMode-property is a boolean that may be used to determine the dark mode of the CodeEditor.
51+ */
3652 globalDarkMode ?: boolean | undefined ;
53+ /**
54+ * The code-property is a string that may contains the user's code.
55+ */
3756 code ?: string ;
57+ /**
58+ * The referenceCode-property is a string that mcontains the reference code that the user's code may be compared against.
59+ */
60+ referenceCode ?: string ;
3861}
3962
4063/**
4164 * The CodeEditor-component may require state handling. This state is defined here.
4265 */
4366export interface CodeEditorComponentState extends ComponentState {
67+ /**
68+ * The code-property is a string that contains the user's code.
69+ */
4470 code : string ;
4571}
4672
4773/**
4874 * The CodeEditor-component may have configuration options. These options are defined here.
4975 */
5076export interface CodeEditorConfiguration extends ComponentConfiguration {
77+ /**
78+ * The darkMode-property is a boolean that may be used to determine the dark mode of the CodeEditor.
79+ */
5180 darkMode ?: boolean ;
81+ /**
82+ * The language-property is a string that may be used to determine the syntax highlighting of the CodeEditor.
83+ */
5284 language ?: SupportedLanguages ;
5385}
5486
87+ /**
88+ * The CodeEditor allows for optional validation strategies.
89+ * The first strategy is a basic string compare.
90+ * The second strategy is a request-based strategy, which may depend on a user-defined strategy (e.g. test-suite, output comparisons, more complex string comparisons, etc.).
91+ * As the second strategy may depend on more than just the code, the entire state is accessible.
92+ */
93+ export type CodeEditorValidationConfiguration <
94+ K extends keyof CodeEditorValidationConfigurationMap
95+ > = { [ P in K ] : { type : P } & CodeEditorValidationConfigurationMap [ P ] } [ K ] &
96+ ValidationConfiguration ;
97+
98+ export interface StringComparison extends ValidationStrategy {
99+ type : "compareToString" ;
100+ }
101+
102+ export interface ExternalValidation extends ValidationStrategy {
103+ type : "validateExternally" ;
104+ }
105+
106+ /**
107+ * Map of all available validation strategies for the CodeEditor component.
108+ */
109+ interface CodeEditorValidationConfigurationMap extends ValidationConfigurationMap {
110+ validateExternally : ExternalValidation ;
111+ compareToString : StringComparison ;
112+ }
113+
55114/**
56115 * The SerializedCodeEditorComponent interface is used to define the serialised properties of the CodeEditor component.
57116 */
@@ -60,6 +119,9 @@ export interface SerializedCodeEditorComponent
60119 dependencies : SerializedCodeEditorDependencies ;
61120 state : CodeEditorComponentState ;
62121 componentConfiguration ?: CodeEditorConfiguration ;
122+ validationConfiguration ?: CodeEditorValidationConfiguration <
123+ keyof CodeEditorValidationConfigurationMap
124+ > ;
63125}
64126
65127export interface CodeEditorSpecification extends ComponentTypeSpecification {
@@ -71,13 +133,29 @@ export interface CodeEditorSpecification extends ComponentTypeSpecification {
71133 * The CodeEditorComponent class is a derived taskComponent, that displays a Graph specified in the Graphviz-DOT language.
72134 */
73135export class CodeEditorComponent extends BaseComponent < CodeEditorSpecification > {
136+ private validationStrategies : {
137+ [ K in keyof CodeEditorValidationConfigurationMap ] : (
138+ taskState : string ,
139+ functionConfig : CodeEditorValidationConfiguration < K >
140+ ) => boolean ;
141+ } = {
142+ validateExternally : this . externalValidation . bind ( this ) ,
143+ compareToString : this . stringComparison . bind ( this )
144+ } ;
74145 /**
75146 * This function determines when a CodeEditorComponent is valid and when it is correct.
76147 * @returns
77148 */
78- public validate ( ) {
149+ public validate ( userCode : string ) {
79150 const validity = { isValid : false , isCorrect : false } ;
80151
81152 return validity ;
82153 }
154+
155+ private externalValidation ( userCode : string , validationConfiguration : ExternalValidation ) {
156+ return true ;
157+ }
158+ private stringComparison ( userCode : string , validationConfiguration : StringComparison ) {
159+ return true ;
160+ }
83161}
0 commit comments