8000 Feature/integrate by ShMcK · Pull Request #16 · coderoad/coderoad-vscode · GitHub
[go: up one dir, main page]

Skip to content

Feature/integrate #16

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 2 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 26 additions & 24 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode'
import * as CR from 'typings'
import * as path from 'path'
import * as CR from 'typings'
import * as vscode from 'vscode'

/**
* Manages React webview panels
Expand Down Expand Up @@ -71,7 +71,7 @@ class ReactWebView {
if (callback) {
// listen for when webview is loaded
// unfortunately there is no easy way of doing this
let webPanelListener = setInterval(() => {
const webPanelListener = setInterval(() => {
if (this.loaded) {
setTimeout(callback)
clearInterval(webPanelListener)
Expand All @@ -80,6 +80,27 @@ class ReactWebView {
}
}

public async postMessage(action: CR.Action): Promise<void> {
// Send a message to the webview webview.
// You can send any JSON serializable data.
const success = await this.panel.webview.postMessage(action)
if (!success) {
throw new Error(`Message post failure: ${JSON.stringify(action)}`)
}
}

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

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

private createWebviewPanel(column: number): vscode.WebviewPanel {
const viewType = 'CodeRoad'
const title = 'CodeRoad'
Expand All @@ -103,27 +124,6 @@ class ReactWebView {
return text
}

public async postMessage(action: CR.Action): Promise<void> {
// Send a message to the webview webview.
// You can send any JSON serializable data.
const success = await this.panel.webview.postMessage(action)
if (!success) {
throw new Error(`Message post failure: ${JSON.stringify(action)}`)
}
}

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

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

private getHtmlForWebview(): string {
// eslint-disable-next-line
const manifest = require(path.join(this.extensionPath, 'build', 'asset-manifest.json'))
Expand Down Expand Up @@ -151,6 +151,8 @@ class ReactWebView {
<meta name="theme-color" content="#000000">
<title>React App</title>
<link rel="manifest" href="./manifest.json" />
<!-- TODO: load styles through package -->
<link rel="stylesheet" href="https://unpkg.com/@alifd/next/dist/next.css" />
<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({
Expand Down
7 changes: 3 additions & 4 deletions src/editor/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as vscode from 'vscode'
import { join } from 'path'
import { setStorage } from '../storage'
import * as CR from 'typings'
import * as vscode from 'vscode'
import ReactWebView from '../ReactWebView'
import { setStorage } from '../storage'
import { isEmptyWorkspace } from '../workspace'
import * as CR from 'typings'
import runTest from './runTest'

const COMMANDS = {
Expand Down Expand Up @@ -44,7 +44,6 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre

// activate machine
webview = new ReactWebView(context.extensionPath)
console.log('webview', webview.panel.webview.postMessage)
machine.activate()
},
// open React webview
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"class-name": true,
"semicolon": [true, "never"],
"triple-equals": true,
"interface-name": [true, "never-prefix"]
"interface-name": [true, "never-prefix"],
"object-literal-sort-keys": false
},
"defaultSeverity": "warning",
"no-submodule-imports": false
Expand Down
11 changes: 10 additions & 1 deletion web-app/.storybook/config.ts