Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f8bee2

Browse files
committed
add extensive comments to react webview
1 parent22451c7 commit6f8bee2

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,28 @@ class ReactWebView {
115115
}
116116

117117
privaterender=async():Promise<void>=>{
118-
118+
// path to build directory
119119
constrootPath=path.join(this.extensionPath,'build')
120+
121+
// load copied index.html from web app build
120122
constdom=awaitJSDOM.fromFile(path.join(rootPath,'index.html'))
121123
const{document}=dom.window
122124

125+
// set base href
123126
constbase:HTMLBaseElement=document.createElement('base')
124127
base.href=vscode.Uri.file(rootPath).with({scheme:'vscode-resource'}).toString()+'/'
125128
document.head.appendChild(base)
126129

127-
constmanifest=require(path.join(rootPath,'asset-manifest.json'))
128-
130+
// used for CSP
129131
constnonces:string[]=[]
130132

131-
constcreateUri=(filePath:string):string=>vscode.Uri.file(filePath).with({scheme:'vscode-resource'}).toString().replace(/^\/+/g,'').replace('/vscode-resource%3A',rootPath)
133+
// generate vscode-resource build path uri
134+
constcreateUri=(filePath:string):string=>
135+
vscode.Uri.file(filePath).with({scheme:'vscode-resource'}).toString()
136+
.replace(/^\/+/g,'')// remove leading '/'
137+
.replace('/vscode-resource%3A',rootPath)// replace mangled resource path with root
132138

139+
// fix paths for scripts
133140
constscripts:HTMLScriptElement[]=Array.from(document.getElementsByTagName('script'))
134141
for(constscriptofscripts){
135142
if(script.src){
@@ -144,10 +151,11 @@ class ReactWebView {
144151
construnTimeScript=document.createElement('script')
145152
runTimeScript.nonce=getNonce()
146153
nonces.push(runTimeScript.nonce)
154+
constmanifest=require(path.join(rootPath,'asset-manifest.json'))
147155
runTimeScript.src=createUri(path.join(rootPath,manifest.files['runtime-main.js']))
148-
149156
document.body.appendChild(runTimeScript)
150157

158+
// fix paths for links
151159
conststyles:HTMLLinkElement[]=Array.from(document.getElementsByTagName('link'))
152160
for(conststyleofstyles){
153161
if(style.href){
@@ -156,7 +164,7 @@ class ReactWebView {
156164
}
157165

158166

159-
// content security policy
167+
//set CSP (content security policy) to grant permission to local files
160168
constcspMeta:HTMLMetaElement=document.createElement('meta')
161169
cspMeta.httpEquiv='Content-Security-Policy'
162170
cspMeta.content=[
@@ -168,8 +176,10 @@ class ReactWebView {
168176
].join(' ')
169177
document.head.appendChild(cspMeta)
170178

179+
// stringify dom
171180
consthtml=dom.serialize()
172181

182+
// set view
173183
this.panel.webview.html=html
174184
}
175185

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp