@@ -12,6 +12,9 @@ import toast from 'react-hot-toast'
12
12
import { wrapJSCode } from './wrapJSCode'
13
13
import { validateHtml5 } from '../../common/validateHtml5/validateHtml5'
14
14
import { normalizeHtmlText } from '../../common/validateHtml5/normalizeHtmlText'
15
+ import { submitCode } from '../../JikiscriptExercisePage/hooks/useConstructRunCode/submitCode'
16
+ import { getCodeMirrorFieldValue } from '../../JikiscriptExercisePage/CodeMirror/getCodeMirrorFieldValue'
17
+ import { readOnlyRangesStateField } from '../../JikiscriptExercisePage/CodeMirror/extensions/read-only-ranges/readOnlyRanges'
15
18
16
19
export type TabIndex = 'html' | 'css' | 'javascript'
17
20
@@ -32,6 +35,7 @@ export function LHS() {
32
35
expectedReferenceIFrameRef,
33
36
exercise,
34
37
code,
38
+ links,
35
39
} = useContext ( FrontendExercisePageContext )
36
40
37
41
const {
@@ -57,10 +61,10 @@ export function LHS() {
57
61
const handleRunCode = useCallback ( ( ) => {
58
62
if ( ! jsEditorRef . current || ! htmlEditorRef . current ) return
59
63
60
- const htmlText = htmlEditorRef . current . state . doc . toString ( )
64
+ const htmlCode = htmlEditorRef . current . state . doc . toString ( )
61
65
62
- if ( htmlText . length > 0 ) {
63
- const normalizedHtml = normalizeHtmlText ( htmlText )
66
+ if ( htmlCode . length > 0 ) {
67
+ const normalizedHtml = normalizeHtmlText ( htmlCode )
64
68
const isHTMLValid = validateHtml5 ( normalizedHtml )
65
69
66
70
if ( ! isHTMLValid . isValid ) {
@@ -72,9 +76,44 @@ export function LHS() {
72
76
}
73
77
}
74
78
79
+ const cssCode = cssEditorRef . current ?. state . doc . toString ( )
80
+
75
81
const jsView = jsEditorRef . current
76
82
const jsCode = jsEditorRef . current . state . doc . toString ( )
77
83
84
+ const cssReadonlyRanges = getCodeMirrorFieldValue (
85
+ cssEditorRef . current ,
86
+ readOnlyRangesStateField
87
+ )
88
+ const htmlReadonlyRanges = getCodeMirrorFieldValue (
89
+ htmlEditorRef . current ,
90
+ readOnlyRangesStateField
91
+ )
92
+ const jsReadonlyRanges = getCodeMirrorFieldValue (
93
+ jsEditorRef . current ,
94
+ readOnlyRangesStateField
95
+ )
96
+
97
+ const submittedCode = JSON . stringify ( {
98
+ html : htmlCode ,
99
+ css : cssCode ,
100
+ js : jsCode ,
101
+ } )
102
+ submitCode ( {
103
+ postUrl : links . postSubmission ,
104
+ code : submittedCode ,
105
+ testResults : {
106
+ status : 'unknown' ,
107
+ tests : [ ] ,
108
+ } ,
109
+ customFunctions : [ ] ,
110
+ readonlyRanges : {
111
+ html : cssReadonlyRanges ,
112
+ css : cssReadonlyRanges ,
113
+ js : jsReadonlyRanges ,
114
+ } ,
115
+ } )
116
+
78
117
const result = parseJS ( jsView . state . doc . toString ( ) )
79
118
switch ( result . status ) {
80
119
case 'success' :
@@ -87,8 +126,8 @@ export function LHS() {
87
126
actualIFrameRef ,
88
127
{
89
128
script : fullScript ,
90
- html : htmlEditorRef . current ?. state . doc . toString ( ) ,
91
- css : cssEditorRef . current ?. state . doc . toString ( ) ,
129
+ html : htmlCode ,
130
+ css : cssCode ,
92
131
} ,
93
132
code
94
133
)
0 commit comments