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

Feature/progress#11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 4 commits intomasterfromfeature/progress
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions.vscode/settings.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,4 +30,6 @@
"search.exclude": {
"out":true// set this to false to include "out" folder in search results
},
"prettier.eslintIntegration":true,
"editor.formatOnSave":true,
}
18 changes: 9 additions & 9 deletionspackage-lock.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

6 changes: 3 additions & 3 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,16 +58,16 @@
},
"devDependencies": {
"@types/mocha":"^5.2.7",
"@types/node":"^12.0.12",
"@types/node":"^12.6.2",
"concurrently":"^4.1.1",
"prettier":"^1.18.2",
"tslint":"^5.18.0",
"tslint-config-prettier":"^1.18.0",
"typescript":"^3.5.2"
"typescript":"^3.5.3"
},
"dependencies": {
"vscode":"^1.1.35",
"xstate":"^4.6.4"
"xstate":"^4.6.7"
},
"license":"SEE LICENSE IN LICENSE.md"
}
277 changes: 142 additions & 135 deletionssrc/editor/ReactWebView.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,152 +6,159 @@ import * as path from 'path'
* Manages React webview panels
*/
classReactWebView{
//@ts-ignore
privatepanel:vscode.WebviewPanel
privateextensionPath:string
privatedisposables:vscode.Disposable[]=[]
privateonReceive:any// TODO: properly type

publicconstructor(extensionPath:string){
this.extensionPath=extensionPath

// Create and show a new webview panel
this.panel=this.createWebviewPanel(vscode.ViewColumn.Two)

// Set the webview's initial html content
this.panel.webview.html=this.getHtmlForWebview()

// Listen for when the panel is disposed
// This happens when the user closes the panel or when the panel is closed programatically
this.panel.onDidDispose(()=>this.dispose(),null,this.disposables)

// Handle messages from the webview
constonReceive=(action:string|CR.Action)=>vscode.commands.executeCommand('coderoad.receive_action',action)
this.panel.webview.onDidReceiveMessage(onReceive,null,this.disposables)

// update panel on changes
constupdateWindows=()=>{
vscode.commands.executeCommand('vscode.setEditorLayout',{orientation:0,groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}]})
this.panel.reveal(vscode.ViewColumn.Two)
}
// prevents new panels from going ontop of coderoad panel
vscode.window.onDidChangeActiveTextEditor((param)=>{
if(!param||param.viewColumn!==vscode.ViewColumn.Two){
updateWindows()
}
})
// prevents moving coderoad panel on top of left panel
vscode.window.onDidChangeVisibleTextEditors((param)=>{
updateWindows()
})

// TODO: prevent window from moving to the left when no windows remain on rights
//@ts-ignore
privatepanel:vscode.WebviewPanel
privateextensionPath:string
privatedisposables:vscode.Disposable[]=[]
privateonReceive:any// TODO: properly type

publicconstructor(extensionPath:string){
this.extensionPath=extensionPath

// Create and show a new webview panel
this.panel=this.createWebviewPanel(vscode.ViewColumn.Two)

// Set the webview's initial html content
this.panel.webview.html=this.getHtmlForWebview()

// Listen for when the panel is disposed
// This happens when the user closes the panel or when the panel is closed programatically
// this.panel.onDidDispose(() => this.dispose(), null, this.disposables)

// Handle messages from the webview
constonReceive=(action:string|CR.Action)=>vscode.commands.executeCommand('coderoad.receive_action',action)
this.panel.webview.onDidReceiveMessage(onReceive,null,this.disposables)

// update panel on changes
constupdateWindows=()=>{
vscode.commands.executeCommand('vscode.setEditorLayout',{
orientation:0,
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
})
this.panel.reveal(vscode.ViewColumn.Two)
}

publiccreateOrShow(column:number):void{
// If we already have a panel, show it.
// Otherwise, create a new panel.
if(this.panel&&this.panel.webview){
console.log('reveal')
this.panel.reveal(column)
}else{
console.log('make new panel')
this.panel=this.createWebviewPanel(column)
}
this.panel.onDidDispose(()=>{
updateWindows()
})

// this.panel.onDidChangeViewState(() => {
// console.log('onDidChangeViewState')
// updateWindows()
// })

// prevents new panels from going ontop of coderoad panel
vscode.window.onDidChangeActiveTextEditor(param=>{
if(!param||param.viewColumn!==vscode.ViewColumn.Two){
updateWindows()
}
})
// // prevents moving coderoad panel on top of left panel
vscode.window.onDidChangeVisibleTextEditors(param=>{
updateWindows()
})

// TODO: prevent window from moving to the left when no windows remain on rights
}

publiccreateOrShow(column:number):void{
// If we already have a panel, show it.
// Otherwise, create a new panel.
if(this.panel&&this.panel.webview){
this.panel.reveal(column)
}else{
this.panel=this.createWebviewPanel(column)
}

privatecreateWebviewPanel(column:number):vscode.WebviewPanel{
constviewType='CodeRoad'
consttitle='CodeRoad'
constconfig={
// Enable javascript in the webview
enableScripts:true,
// And restric the webview to only loading content from our extension's `media` directory.
localResourceRoots:[vscode.Uri.file(path.join(this.extensionPath,'build'))],
// prevents destroying the window when it is in the background
retainContextWhenHidden:true,
}
returnvscode.window.createWebviewPanel(viewType,title,column,config)
}

privatecreateWebviewPanel(column:number):vscode.WebviewPanel{
constviewType='CodeRoad'
consttitle='CodeRoad'
constconfig={
// Enable javascript in the webview
enableScripts:true,
// And restric the webview to only loading content from our extension's `media` directory.
localResourceRoots:[vscode.Uri.file(path.join(this.extensionPath,'build'))],
// prevents destroying the window when it is in the background
retainContextWhenHidden:true,
}

privategetNonce():string{
lettext=''
constpossible='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
for(leti=0;i<32;i++){
text+=possible.charAt(Math.floor(Math.random()*possible.length))
}
returntext
returnvscode.window.createWebviewPanel(viewType,title,column,config)
}

privategetNonce():string{
lettext=''
constpossible='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
for(leti=0;i<32;i++){
text+=possible.charAt(Math.floor(Math.random()*possible.length))
}

publicasyncpostMessage(action:CR.Action):Promise<void>{
console.log('webview postMessage')
console.log(action)
// Send a message to the webview webview.
// You can send any JSON serializable data.
constsuccess=awaitthis.panel.webview.postMessage(action)
if(!success){
thrownewError(`Message post failure:${JSON.stringify(action)}`)
}
console.log('postMessage sent')
returntext
}

publicasyncpostMessage(action:CR.Action):Promise<void>{
// Send a message to the webview webview.
// You can send any JSON serializable data.
constsuccess=awaitthis.panel.webview.postMessage(action)
if(!success){
thrownewError(`Message post failure:${JSON.stringify(action)}`)
}
}

publicdispose():void{
// Clean up our resources
this.panel.dispose()
publicdispose():void{
// Clean up our resources
this.panel.dispose()

while(this.disposables.length){
constx=this.disposables.pop()
if(x){
x.dispose()
}
}
while(this.disposables.length){
constx=this.disposables.pop()
if(x){
x.dispose()
}
}

privategetHtmlForWebview():string{

// eslint-disable-next-line
constmanifest=require(path.join(this.extensionPath,'build','asset-manifest.json'))
constmainScript=manifest.files['main.js']
// grab first chunk
constchunk=Object.keys(manifest.files).filter(f=>f.match(/^static\/js\/.+\.js$/))[0]
constchunkScript=manifest.files[chunk]
constmainStyle=manifest.files['main.css']

constscriptPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainScript))
constscriptUri=scriptPathOnDisk.with({scheme:'vscode-resource'})
constchunkPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',chunkScript))
constchunkUri=chunkPathOnDisk.with({scheme:'vscode-resource'})
conststylePathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainStyle))
conststyleUri=stylePathOnDisk.with({scheme:'vscode-resource'})

// Use a nonce to whitelist which scripts can be run
constnonce=this.getNonce()
constnonce2=this.getNonce()
constnonce3=this.getNonce()

return`<!DOCTYPE html>
}

privategetHtmlForWebview():string{
// eslint-disable-next-line
constmanifest=require(path.join(this.extensionPath,'build','asset-manifest.json'))
constmainScript=manifest.files['main.js']
// grab first chunk
constchunk=Object.keys(manifest.files).filter(f=>f.match(/^static\/js\/.+\.js$/))[0]
constchunkScript=manifest.files[chunk]
constmainStyle=manifest.files['main.css']

constscriptPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainScript))
constscriptUri=scriptPathOnDisk.with({scheme:'vscode-resource'})
constchunkPathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',chunkScript))
constchunkUri=chunkPathOnDisk.with({scheme:'vscode-resource'})
conststylePathOnDisk=vscode.Uri.file(path.join(this.extensionPath,'build',mainStyle))
conststyleUri=stylePathOnDisk.with({scheme:'vscode-resource'})

// Use a nonce to whitelist which scripts can be run
const[n1,n2,n3]=[1,2,3].map(this.getNonce)

return`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<link rel="manifest" href="./manifest.json" />
<link rel="stylesheet" type="text/css" href="${styleUri}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'nonce-${nonce2}' 'nonce-${nonce3}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
<base href="${vscode.Uri.file(path.join(this.extensionPath,'build')).with({scheme:'vscode-resource'})}/">
<style></style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">Loading...</div>
<script nonce=${nonce} src="./webpackBuild.js"></script>
<script nonce=${nonce2} src="${chunkUri}"></script>
<script nonce="${nonce3}" src="${scriptUri}"></script>
</body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<link rel="manifest" href="./manifest.json" />
<link rel="stylesheet" type="text/css" href="${styleUri}">
<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:;">
<base href="${vscode.Uri.file(path.join(this.extensionPath,'build')).with({
scheme:'vscode-resource',
})}/">
<style></style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">Loading...</div>
<script nonce=${n1} src="./webpackBuild.js"></script>
<script nonce=${n2} src="${chunkUri}"></script>
<script nonce="${n3}" src="${scriptUri}"></script>
</body>
</html>`
}
}
}

exportdefaultReactWebView
Loading

[8]ページ先頭

©2009-2025 Movatter.jp