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

Commit9cb8ba5

Browse files
committed
run prettier on all files, setup on save
1 parent830c01a commit9cb8ba5

File tree

27 files changed

+865
-862
lines changed

27 files changed

+865
-862
lines changed

‎.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"search.exclude": {
3131
"out":true// set this to false to include "out" folder in search results
3232
},
33+
"prettier.eslintIntegration":true,
34+
"editor.formatOnSave":true,
3335
}

‎src/editor/ReactWebView.ts

Lines changed: 124 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -6,134 +6,135 @@ import * as path from 'path'
66
* Manages React webview panels
77
*/
88
classReactWebView{
9-
//@ts-ignore
10-
privatepanel:vscode.WebviewPanel
11-
privateextensionPath:string
12-
privatedisposables:vscode.Disposable[]=[]
13-
privateonReceive:any// TODO: properly type
14-
15-
publicconstructor(extensionPath:string){
16-
this.extensionPath=extensionPath
17-
18-
// Create and show a new webview panel
19-
this.panel=this.createWebviewPanel(vscode.ViewColumn.Two)
20-
21-
// Set the webview's initial html content
22-
this.panel.webview.html=this.getHtmlForWebview()
23-
24-
// Listen for when the panel is disposed
25-
// This happens when the user closes the panel or when the panel is closed programatically
26-
// this.panel.onDidDispose(() => this.dispose(), null, this.disposables)
27-
28-
// Handle messages from the webview
29-
constonReceive=(action:string|CR.Action)=>vscode.commands.executeCommand('coderoad.receive_action',action)
30-
this.panel.webview.onDidReceiveMessage(onReceive,null,this.disposables)
31-
32-
// update panel on changes
33-
constupdateWindows=()=>{
34-
35-
vscode.commands.executeCommand('vscode.setEditorLayout',{orientation:0,groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}]})
36-
this.panel.reveal(vscode.ViewColumn.Two)
37-
}
38-
39-
this.panel.onDidDispose(()=>{
40-
updateWindows()
41-
})
42-
43-
// this.panel.onDidChangeViewState(() => {
44-
// console.log('onDidChangeViewState')
45-
// updateWindows()
46-
// })
47-
48-
// prevents new panels from going ontop of coderoad panel
49-
vscode.window.onDidChangeActiveTextEditor((param)=>{
50-
if(!param||param.viewColumn!==vscode.ViewColumn.Two){
51-
updateWindows()
52-
}
53-
})
54-
// // prevents moving coderoad panel on top of left panel
55-
vscode.window.onDidChangeVisibleTextEditors((param)=>{
56-
updateWindows()
57-
})
58-
59-
// TODO: prevent window from moving to the left when no windows remain on rights
9+
//@ts-ignore
10+
privatepanel:vscode.WebviewPanel
11+
privateextensionPath:string
12+
privatedisposables:vscode.Disposable[]=[]
13+
privateonReceive:any// TODO: properly type
14+
15+
publicconstructor(extensionPath:string){
16+
this.extensionPath=extensionPath
17+
18+
// Create and show a new webview panel
19+
this.panel=this.createWebviewPanel(vscode.ViewColumn.Two)
20+
21+
// Set the webview's initial html content
22+
this.panel.webview.html=this.getHtmlForWebview()
23+
24+
// Listen for when the panel is disposed
25+
// This happens when the user closes the panel or when the panel is closed programatically
26+
// this.panel.onDidDispose(() => this.dispose(), null, this.disposables)
27+
28+
// Handle messages from the webview
29+
constonReceive=(action:string|CR.Action)=>vscode.commands.executeCommand('coderoad.receive_action',action)
30+
this.panel.webview.onDidReceiveMessage(onReceive,null,this.disposables)
31+
32+
// update panel on changes
33+
constupdateWindows=()=>{
34+
vscode.commands.executeCommand('vscode.setEditorLayout',{
35+
orientation:0,
36+
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
37+
})
38+
this.panel.reveal(vscode.ViewColumn.Two)
6039
}
6140

62-
publiccreateOrShow(column:number):void{
63-
// If we already have a panel, show it.
64-
// Otherwise, create a new panel.
65-
if(this.panel&&this.panel.webview){
66-
this.panel.reveal(column)
67-
}else{
68-
this.panel=this.createWebviewPanel(column)
69-
}
41+
this.panel.onDidDispose(()=>{
42+
updateWindows()
43+
})
44+
45+
// this.panel.onDidChangeViewState(() => {
46+
// console.log('onDidChangeViewState')
47+
// updateWindows()
48+
// })
49+
50+
// prevents new panels from going ontop of coderoad panel
51+
vscode.window.onDidChangeActiveTextEditor(param=>{
52+
if(!param||param.viewColumn!==vscode.ViewColumn.Two){
53+
updateWindows()
54+
}
55+
})
56+
// // prevents moving coderoad panel on top of left panel
57+
vscode.window.onDidChangeVisibleTextEditors(param=>{
58+
updateWindows()
59+
})
60+
61+
// TODO: prevent window from moving to the left when no windows remain on rights
62+
}
63+
64+
publiccreateOrShow(column:number):void{
65+
// If we already have a panel, show it.
66+
// Otherwise, create a new panel.
67+
if(this.panel&&this.panel.webview){
68+
this.panel.reveal(column)
69+
}else{
70+
this.panel=this.createWebviewPanel(column)
7071
}
71-
72-
privatecreateWebviewPanel(column:number):vscode.WebviewPanel{
73-
constviewType='CodeRoad'
74-
consttitle='CodeRoad'
75-
constconfig={
76-
// Enable javascript in the webview
77-
enableScripts:true,
78-
// And restric the webview to only loading content from our extension's `media` directory.
79-
localResourceRoots:[vscode.Uri.file(path.join(this.extensionPath,'build'))],
80-
// prevents destroying the window when it is in the background
81-
retainContextWhenHidden:true,
82-
}
83-
returnvscode.window.createWebviewPanel(viewType,title,column,config)
72+
}
73+
74+
privatecreateWebviewPanel(column:number):vscode.WebviewPanel{
75+
constviewType='CodeRoad'
76+
consttitle='CodeRoad'
77+
constconfig={
78+
// Enable javascript in the webview
79+
enableScripts:true,
80+
// And restric the webview to only loading content from our extension's `media` directory.
81+
localResourceRoots:[vscode.Uri.file(path.join(this.extensionPath,'build'))],
82+
// prevents destroying the window when it is in the background
83+
retainContextWhenHidden:true,
8484
}
85-
86-
privategetNonce():string{
87-
lettext=''
88-
constpossible='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
89-
for(leti=0;i<32;i++){
90-
text+=possible.charAt(Math.floor(Math.random()*possible.length))
91-
}
92-
returntext
85+
returnvscode.window.createWebviewPanel(viewType,title,column,config)
86+
}
87+
88+
privategetNonce():string{
89+
lettext=''
90+
constpossible='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
91+
for(leti=0;i<32;i++){
92+
text+=possible.charAt(Math.floor(Math.random()*possible.length))
9393
}
94-
95-
publicasyncpostMessage(action:CR.Action):Promise<void>{
96-
// Send a message to the webview webview.
97-
// You can send any JSON serializable data.
98-
constsuccess=awaitthis.panel.webview.postMessage(action)
99-
if(!success){
100-
thrownewError(`Message post failure:${JSON.stringify(action)}`)
101-
}
94+
returntext
95+
}
96+
97+
publicasyncpostMessage(action:CR.Action):Promise<void>{
98+
// Send a message to the webview webview.
99+
// You can send any JSON serializable data.
100+
constsuccess=awaitthis.panel.webview.postMessage(action)
101+
if(!success){
102+
thrownewError(`Message post failure:${JSON.stringify(action)}`)
102103
}
104+
}
103105

104-
publicdispose():void{
105-
// Clean up our resources
106-
this.panel.dispose()
106+
publicdispose():void{
107+
// Clean up our resources
108+
this.panel.dispose()
107109

108-
while(this.disposables.length){
109-
constx=this.disposables.pop()
110-
if(x){
111-
x.dispose()
112-
}
113-
}
110+
while(this.disposables.length){
111+
constx=this.disposables.pop()
112+
if(x){
113+
x.dispose()
114+
}
114115
}
115-
116-
privategetHtmlForWebview():string{
117-
118-
// eslint-disable-next-line
119-
constmanifest=require(path.join(this.extensionPath,'build','asset-manifest.json'))
120-
constmainScript=manifest.files['main.js']
121-
// grab first chunk
122-
constchunk=Object.keys(manifest.files).filter(f=>f.match(/^static\/js\/.+\.js$/))[0]
123-
constchunkScript=manifest.files[chunk]
124-
constmainStyle=manifest.files['main.css']
125-
126-
constscriptPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainScript))
127-
constscriptUri=scriptPathOnDisk.with({scheme:'vscode-resource'})
128-
constchunkPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',chunkScript))
129-
constchunkUri=chunkPathOnDisk.with({scheme:'vscode-resource'})
130-
conststylePathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainStyle))
131-
conststyleUri=stylePathOnDisk.with({scheme:'vscode-resource'})
132-
133-
// Use a nonce to whitelist which scripts can be run
134-
const[n1,n2,n3]=[1,2,3].map(this.getNonce)
135-
136-
return`<!DOCTYPE html>
116+
}
117+
118+
privategetHtmlForWebview():string{
119+
// eslint-disable-next-line
120+
constmanifest=require(path.join(this.extensionPath,'build','asset-manifest.json'))
121+
constmainScript=manifest.files['main.js']
122+
// grab first chunk
123+
constchunk=Object.keys(manifest.files).filter(f=>f.match(/^static\/js\/.+\.js$/))[0]
124+
constchunkScript=manifest.files[chunk]
125+
constmainStyle=manifest.files['main.css']
126+
127+
constscriptPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainScript))
128+
constscriptUri=scriptPathOnDisk.with({scheme:'vscode-resource'})
129+
constchunkPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',chunkScript))
130+
constchunkUri=chunkPathOnDisk.with({scheme:'vscode-resource'})
131+
conststylePathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainStyle))
132+
conststyleUri=stylePathOnDisk.with({scheme:'vscode-resource'})
133+
134+
// Use a nonce to whitelist which scripts can be run
135+
const[n1,n2,n3]=[1,2,3].map(this.getNonce)
136+
137+
return`<!DOCTYPE html>
137138
<html lang="en">
138139
<head>
139140
<meta charset="utf-8">
@@ -143,7 +144,9 @@ class ReactWebView {
143144
<link rel="manifest" href="./manifest.json" />
144145
<link rel="stylesheet" type="text/css" href="${styleUri}">
145146
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${n1}' 'nonce-${n2}' 'nonce-${n3}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
146-
<base href="${vscode.Uri.file(path.join(this.extensionPath,'build')).with({scheme:'vscode-resource'})}/">
147+
<base href="${vscode.Uri.file(path.join(this.extensionPath,'build')).with({
148+
scheme:'vscode-resource',
149+
})}/">
147150
<style></style>
148151
</head>
149152
@@ -155,7 +158,7 @@ class ReactWebView {
155158
<script nonce="${n3}" src="${scriptUri}"></script>
156159
</body>
157160
</html>`
158-
}
161+
}
159162
}
160163

161164
exportdefaultReactWebView

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp