Skip to content

Continue progress #32

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Sep 23, 2019
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
17a71b7
setup storage on server
ShMcK Sep 9, 2019
1b99222
continue tutorial progress
ShMcK Sep 9, 2019
90e5e97
store tutorial id/version on server
ShMcK Sep 9, 2019
e49165c
manage storage in editor Channel
ShMcK Sep 14, 2019
0f992bf
setup storage in editor channel
ShMcK Sep 15, 2019
f174afa
load progress on server and send to client
ShMcK Sep 15, 2019
ecac58b
add continue option to start new
ShMcK Sep 15, 2019
33d854c
load stage (not 100%)
ShMcK Sep 15, 2019
a54f1d5
save commit on successful test
ShMcK Sep 15, 2019
8bea508
setup editor position & progress state
ShMcK Sep 15, 2019
83820ab
cleanup deps
ShMcK Sep 18, 2019
04d3eca
update deps
ShMcK Sep 21, 2019
b1eb6b1
refactor context
ShMcK Sep 21, 2019
d1d5384
setup position/progress/tutorial context
ShMcK Sep 21, 2019
1a9ccf9
refactor setupActions
ShMcK Sep 21, 2019
6217ea6
align channel with context
ShMcK Sep 21, 2019
e7b084d
fix build process
ShMcK Sep 21, 2019
229c6b8
parse webview from jsdom
ShMcK Sep 21, 2019
bab2e54
refactor webview render
ShMcK Sep 21, 2019
7bada36
fix webview after webpack build breakage
ShMcK Sep 22, 2019
22451c7
fix react web view for latest webpack
ShMcK Sep 22, 2019
6f8bee2
add extensive comments to react webview
ShMcK Sep 22, 2019
13a4499
clear up CSP issue with GQL
ShMcK Sep 22, 2019
ccd088b
fix loading tutorial position
ShMcK Sep 22, 2019
30dd21c
fix issues with tutorial init
ShMcK Sep 23, 2019
14d4f56
setup editor sync progress (uninitiated)
ShMcK Sep 23, 2019
4bb125d
clear tutorial on new
ShMcK Sep 23, 2019
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add extensive comments to react webview
  • Loading branch information
ShMcK committed Sep 22, 2019
commit 6f8bee27085c35b0c17de06008a53f03cb40dffa
22 changes: 16 additions & 6 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,28 @@ class ReactWebView {
}

private render = async (): Promise<void> => {

// path to build directory
const rootPath = path.join(this.extensionPath, 'build')

// load copied index.html from web app build
const dom = await JSDOM.fromFile(path.join(rootPath, 'index.html'))
const {document} = dom.window

// set base href
const base: HTMLBaseElement = document.createElement('base')
base.href = vscode.Uri.file(rootPath).with({scheme: 'vscode-resource'}).toString() + '/'
document.head.appendChild(base)

const manifest = require(path.join(rootPath, 'asset-manifest.json'))

// used for CSP
const nonces: string[] = []

const createUri = (filePath: string): string => vscode.Uri.file(filePath).with({scheme: 'vscode-resource'}).toString().replace(/^\/+/g, '').replace('/vscode-resource%3A', rootPath)
// generate vscode-resource build path uri
const createUri = (filePath: string): string =>
vscode.Uri.file(filePath).with({scheme: 'vscode-resource'}).toString()
.replace(/^\/+/g, '') // remove leading '/'
.replace('/vscode-resource%3A', rootPath) // replace mangled resource path with root

// fix paths for scripts
const scripts: HTMLScriptElement[] = Array.from(document.getElementsByTagName('script'))
for (const script of scripts) {
if (script.src) {
Expand All @@ -144,10 +151,11 @@ class ReactWebView {
const runTimeScript = document.createElement('script')
runTimeScript.nonce = getNonce()
nonces.push(runTimeScript.nonce)
const manifest = require(path.join(rootPath, 'asset-manifest.json'))
runTimeScript.src = createUri(path.join(rootPath, manifest.files['runtime-main.js']))

document.body.appendChild(runTimeScript)

// fix paths for links
const styles: HTMLLinkElement[] = Array.from(document.getElementsByTagName('link'))
for (const style of styles) {
if (style.href) {
Expand All @@ -156,7 +164,7 @@ class ReactWebView {
}


// content security policy
// set CSP (content security policy) to grant permission to local files
const cspMeta: HTMLMetaElement = document.createElement('meta')
cspMeta.httpEquiv = 'Content-Security-Policy'
cspMeta.content = [
Expand All @@ -168,8 +176,10 @@ class ReactWebView {
].join(' ')
document.head.appendChild(cspMeta)

// stringify dom
const html = dom.serialize()

// set view
this.panel.webview.html = html
}

Expand Down