Skip to content

Commit

Permalink
fixes webview resource. close #624
Browse files Browse the repository at this point in the history
  • Loading branch information
mtxr committed Jun 26, 2020
1 parent 12a5924 commit 284f44e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions docs/src/pages/changelog.mdx
Expand Up @@ -7,6 +7,11 @@ route: /changelog

## v0.22

### Upcoming Release

- **Extension**
- Fixes webview resource. [#624](https://github.com/mtxr/vscode-sqltools/issues/624)

### v0.22.9 - (Jun 22, 2020)

- **Extension**
Expand Down
Expand Up @@ -179,7 +179,7 @@ const Screen: React.SFC<Props> = () => {
const columns = cols.map(title => ({ name: title, title }));

return (
<ViewContainer className={results.length > 0 ? 'has-tabs' : ''}>
<ViewContainer className={results.length > 1 ? 'has-tabs' : ''}>
<Tabs active={activeTab} items={results.map(r => r.label || r.query)} onChange={toggleTab}/>
{activeResult && <Table
columns={columns}
Expand Down
18 changes: 10 additions & 8 deletions packages/vscode/webview-provider/index.ts
Expand Up @@ -27,14 +27,14 @@ export default abstract class WebviewProvider<State = any> implements Disposable
<style>
:root {${cssVariables}}
</style>
<link rel="stylesheet" type="text/css" href="${this.panel.webview.asWebviewUri(Uri.file(Context.asAbsolutePath(`./ui/commons.css`)))}">
<link rel="stylesheet" type="text/css" href="${this.prepareUrl(Context.asAbsolutePath(`./ui/commons.css`))}">
</head>
<body>
<link rel="stylesheet" type="text/css" href="${this.panel.webview.asWebviewUri(Uri.file(Context.asAbsolutePath(`./ui/theme.css`)))}">
<link rel="stylesheet" type="text/css" href="${this.prepareUrl(Context.asAbsolutePath(`./ui/theme.css`))}">
<div id="app-root"></div>
<script src="${this.panel.webview.asWebviewUri(Uri.file(Context.asAbsolutePath(`./ui/vendor.js`)))}" type="text/javascript" charset="UTF-8"></script>
<script src="${this.panel.webview.asWebviewUri(Uri.file(Context.asAbsolutePath(`./ui/commons.js`)))}" type="text/javascript" charset="UTF-8"></script>
<script src="${this.panel.webview.asWebviewUri(Uri.file(Context.asAbsolutePath(`./ui/${this.id}.js`)))}" type="text/javascript" charset="UTF-8"></script>
<script src="${this.prepareUrl(Context.asAbsolutePath(`./ui/vendor.js`))}" type="text/javascript" charset="UTF-8"></script>
<script src="${this.prepareUrl(Context.asAbsolutePath(`./ui/commons.js`))}" type="text/javascript" charset="UTF-8"></script>
<script src="${this.prepareUrl(Context.asAbsolutePath(`./ui/${this.id}.js`))}" type="text/javascript" charset="UTF-8"></script>
</body>
</html>`;
}
Expand All @@ -61,7 +61,7 @@ export default abstract class WebviewProvider<State = any> implements Disposable
enableScripts: true,
retainContextWhenHidden: true, // @OPTIMIZE remove and migrate to state restore
enableCommandUris: true,
localResourceRoots: [Uri.file(path.resolve(Context.extensionPath, '..')).with({ scheme: 'vscode-resource' })],
localResourceRoots: [Uri.file(Context.extensionPath), Uri.file(path.resolve(Context.extensionPath, '..'))],
// enableFindWidget: true,
},
);
Expand Down Expand Up @@ -103,8 +103,10 @@ export default abstract class WebviewProvider<State = any> implements Disposable
return this.panel && this.panel.active;
}

public get asWebviewUri() {
return this.panel ? this.panel.webview.asWebviewUri : (() => '');
public prepareUrl(localResource: Uri | string) {
return this.panel && this.panel.webview
? this.panel.webview.asWebviewUri(Uri.parse(localResource.toString()))
: null;
}
public hide = () => {
if (this.panel === undefined) return;
Expand Down

0 comments on commit 284f44e

Please sign in to comment.