- Notifications
You must be signed in to change notification settings - Fork42
Setup#3
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Setup#3
Changes from1 commit
Commits
Show all changes
23 commits Select commitHold shift + click to select a range
820097a
setup level/stage tree
ShMcK32edbcf
setup xstate machine as core
ShMcK4be011f
setup start w/ continue or new
ShMcK6993147
add machine loadTutorial
ShMcK04653e2
setup tutorial initialization
ShMcKb51dd2f
refactor files
ShMcK89045a3
refactor files
ShMcK9bcf64c
refactor storage into editor
ShMcKcc176e6
update deps
ShMcKe88651e
setup xstate with interpreter
ShMcKf8c527e
cleanup start
ShMcK634a6d4
Merge pull request #2 from ShMcK/feature/treeview
9241fef
add createWebview logic
ShMcK563874f
initialize webview
ShMcK54e06de
setup web-app
ShMcK81a1041
setup react liniting & tsconfig
ShMcKaa1a8b8
refactor out path to build
ShMcK69b7e81
working react in vscode
ShMcKc4a05ca
cleanup inline script
ShMcK826f2e7
update deps
ShMcK97cf2a1
setup storybook & components
ShMcK567c6a6
setup concurrent build script
ShMcK01d2669
resolve alifd/next style issues
ShMcKFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
add createWebview logic
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit9241feffdfeffe32e9da21d38e4a896a13d7ce28
There are no files selected for viewing
128 changes: 128 additions & 0 deletionssrc/editor/views/createWebview.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import*asvscodefrom'vscode' | ||
import*asCRfrom'typings' | ||
import*aspathfrom'path' | ||
importgetNoncefrom'./utils/nonce' | ||
importonReceivefrom'./onReceive' | ||
/** | ||
* Manages React webview panels | ||
*/ | ||
classReactPanel{ | ||
/** | ||
* Track the currently panel. Only allow a single panel to exist at a time. | ||
*/ | ||
publicstaticcurrentPanel:ReactPanel|undefined=undefined | ||
privatereadonly_panel:vscode.WebviewPanel | ||
privatereadonly_extensionPath:string | ||
private_disposables:vscode.Disposable[]=[] | ||
publicstaticasynccreateOrShow(extensionPath:string):Promise<void>{ | ||
consthasActiveEditor=vscode.window.activeTextEditor | ||
if(!hasActiveEditor){ | ||
thrownewError('Should have an open file on launch') | ||
} | ||
constcolumn=vscode.ViewColumn.Two | ||
// If we already have a panel, show it. | ||
// Otherwise, create a new panel. | ||
if(ReactPanel.currentPanel){ | ||
ReactPanel.currentPanel._panel.reveal(column) | ||
}else{ | ||
ReactPanel.currentPanel=newReactPanel(extensionPath,column) | ||
} | ||
} | ||
privateconstructor(extensionPath:string,column:vscode.ViewColumn){ | ||
this._extensionPath=extensionPath | ||
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, | ||
} | ||
// Create and show a new webview panel | ||
this._panel=vscode.window.createWebviewPanel(viewType,title,column,config) | ||
// 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 | ||
this._panel.webview.onDidReceiveMessage(onReceive,null,this._disposables) | ||
} | ||
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{ | ||
ReactPanel.currentPanel=undefined | ||
// Clean up our resources | ||
this._panel.dispose() | ||
while(this._disposables.length){ | ||
constx=this._disposables.pop() | ||
if(x){ | ||
x.dispose() | ||
} | ||
} | ||
} | ||
private_getHtmlForWebview():string{ | ||
// eslint-disable-next-line | ||
constmanifest=require(path.join(this._extensionPath,'build','asset-manifest.json')) | ||
constmainScript=manifest['main.js'] | ||
constmainStyle=manifest['main.css'] | ||
constscriptPathOnDisk=vscode.Uri.file(path.join(this._extensionPath,'build',mainScript)) | ||
constscriptUri=scriptPathOnDisk.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=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="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}';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"></div> | ||
<script nonce="${nonce}" src="${scriptUri}"></script> | ||
</body> | ||
</html>` | ||
} | ||
} | ||
exportdefaultReactPanel |
6 changes: 6 additions & 0 deletionssrc/editor/views/onReceive.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import*asCRfrom'typings' | ||
exportdefaultasync(action:CR.Action):Promise<void>=>{ | ||
console.log('action',action) | ||
// TODO: call state machine | ||
} |
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.