@@ -6,7 +6,7 @@ import { keymap, Command } from '@codemirror/view';
6
6
import { defaultKeymap } from '@codemirror/commands' ;
7
7
import { oneDarkTheme } from '@codemirror/theme-one-dark' ;
8
8
9
- import { getAttribute , ensureUniqueId , htmlDecode } from '../utils' ;
9
+ import { ensureUniqueId , htmlDecode } from '../utils' ;
10
10
import { pyExec } from '../pyexec' ;
11
11
import { getLogger } from '../logger' ;
12
12
import { InterpreterClient } from '../interpreter_client' ;
@@ -20,31 +20,20 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
20
20
/* High level structure of py-repl DOM, and the corresponding JS names.
21
21
22
22
this <py-repl>
23
- shadow #shadow-root
24
- <slot></slot>
25
23
boxDiv <div class='py-repl-box'>
26
- editorLabel <label>...</label>
27
24
editorDiv <div class="py-repl-editor"></div>
28
25
outDiv <div class="py-repl-output"></div>
29
26
</div>
30
27
</py-repl>
31
28
*/
32
29
class PyRepl extends HTMLElement {
33
- shadow : ShadowRoot ;
34
30
outDiv : HTMLElement ;
35
31
editor : EditorView ;
36
32
stdout_manager : Stdio | null ;
37
33
stderr_manager : Stdio | null ;
38
34
39
- constructor ( ) {
40
- super ( ) ;
41
- }
42
-
43
35
connectedCallback ( ) {
44
36
ensureUniqueId ( this ) ;
45
- this . shadow = this . attachShadow ( { mode : 'open' } ) ;
46
- const slot = document . createElement ( 'slot' ) ;
47
- this . shadow . appendChild ( slot ) ;
48
37
49
38
if ( ! this . hasAttribute ( 'exec-id' ) ) {
50
39
this . setAttribute ( 'exec-id' , '0' ) ;
@@ -77,7 +66,7 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
77
66
] ) ,
78
67
] ;
79
68
80
- if ( getAttribute ( this , 'theme' ) === 'dark' ) {
69
+ if ( this . getAttribute ( 'theme' ) === 'dark' ) {
81
70
extensions . push ( oneDarkTheme ) ;
82
71
}
83
72
@@ -97,10 +86,8 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
97
86
boxDiv . className = 'py-repl-box' ;
98
87
99
88
const editorDiv = this . makeEditorDiv ( ) ;
100
- const editorLabel = this . makeLabel ( 'Python Script Area' , editorDiv ) ;
101
89
this . outDiv = this . makeOutDiv ( ) ;
102
90
103
- boxDiv . append ( editorLabel ) ;
104
91
boxDiv . appendChild ( editorDiv ) ;
105
92
boxDiv . appendChild ( this . outDiv ) ;
106
93
@@ -109,35 +96,21 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
109
96
110
97
makeEditorDiv ( ) : HTMLElement {
111
98
const editorDiv = document . createElement ( 'div' ) ;
112
- editorDiv . id = 'code-editor' ;
113
99
editorDiv . className = 'py-repl-editor' ;
100
+ editorDiv . setAttribute ( 'aria-label' , 'Python Script Area' ) ;
114
101
editorDiv . appendChild ( this . editor . dom ) ;
115
102
116
103
const runButton = this . makeRunButton ( ) ;
117
- const runLabel = this . makeLabel ( 'Python Script Run Button' , runButton ) ;
118
- editorDiv . appendChild ( runLabel ) ;
119
104
editorDiv . appendChild ( runButton ) ;
120
105
121
106
return editorDiv ;
122
107
}
123
108
124
- makeLabel ( text : string , elementFor : HTMLElement ) : HTMLElement {
125
- ensureUniqueId ( elementFor ) ;
126
- const lbl = document . createElement ( 'label' ) ;
127
- lbl . innerHTML = text ;
128
- lbl . htmlFor = elementFor . id ;
129
- // XXX this should be a CSS class
130
- // Styles that we use to hide the labels whilst also keeping it accessible for screen readers
131
- const labelStyle = 'overflow:hidden; display:block; width:1px; height:1px' ;
132
- lbl . setAttribute ( 'style' , labelStyle ) ;
133
- return lbl ;
134
- }
135
-
136
109
makeRunButton ( ) : HTMLElement {
137
110
const runButton = document . createElement ( 'button' ) ;
138
- runButton . id = 'runButton' ;
139
111
runButton . className = 'absolute py-repl-run-button' ;
140
112
runButton . innerHTML = RUNBUTTON ;
113
+ runButton . setAttribute ( 'aria-label' , 'Python Script Run Button' ) ;
141
114
runButton . addEventListener ( 'click' , this . execute . bind ( this ) as ( e : MouseEvent ) => void ) ;
142
115
return runButton ;
143
116
}
@@ -161,13 +134,13 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
161
134
// execute the python code
162
135
app . plugins . beforePyReplExec ( { interpreter : interpreter , src : pySrc , outEl : outEl , pyReplTag : this } ) ;
163
136
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
164
- const pyResult = ( await pyExec ( interpreter , pySrc , outEl ) ) . result ;
137
+ const { result } = await pyExec ( interpreter , pySrc , outEl ) ;
165
138
app . plugins . afterPyReplExec ( {
166
139
interpreter : interpreter ,
167
140
src : pySrc ,
168
141
outEl : outEl ,
169
142
pyReplTag : this ,
170
- result : pyResult , // eslint-disable-line @typescript-eslint/no-unsafe-assignment
143
+ result, // eslint-disable-line @typescript-eslint/no-unsafe-assignment
171
144
} ) ;
172
145
173
146
this . autogenerateMaybe ( ) ;
@@ -190,7 +163,7 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
190
163
191
164
//Attributes to be copied from old REPL to auto-generated REPL
192
165
for ( const attribute of [ 'root' , 'output-mode' , 'output' , 'stderr' ] ) {
193
- const attr = getAttribute ( this , attribute ) ;
166
+ const attr = this . getAttribute ( attribute ) ;
194
167
if ( attr ) {
195
168
newPyRepl . setAttribute ( attribute , attr ) ;
196
169
}
0 commit comments