Allow css override for custom board styles
This commit is contained in:
parent
c67e126f5d
commit
5fd611c2ff
@ -8,11 +8,13 @@ export default class KanbnBoardPanel {
|
|||||||
|
|
||||||
private readonly _panel: vscode.WebviewPanel;
|
private readonly _panel: vscode.WebviewPanel;
|
||||||
private readonly _extensionPath: string;
|
private readonly _extensionPath: string;
|
||||||
|
private readonly _workspacePath: string;
|
||||||
private readonly _kanbn: typeof import('@basementuniverse/kanbn/src/main');
|
private readonly _kanbn: typeof import('@basementuniverse/kanbn/src/main');
|
||||||
private _disposables: vscode.Disposable[] = [];
|
private _disposables: vscode.Disposable[] = [];
|
||||||
|
|
||||||
public static createOrShow(
|
public static createOrShow(
|
||||||
extensionPath: string,
|
extensionPath: string,
|
||||||
|
workspacePath: string,
|
||||||
kanbn: typeof import('@basementuniverse/kanbn/src/main')
|
kanbn: typeof import('@basementuniverse/kanbn/src/main')
|
||||||
) {
|
) {
|
||||||
const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
|
const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
|
||||||
@ -23,6 +25,7 @@ export default class KanbnBoardPanel {
|
|||||||
} else {
|
} else {
|
||||||
KanbnBoardPanel.currentPanel = new KanbnBoardPanel(
|
KanbnBoardPanel.currentPanel = new KanbnBoardPanel(
|
||||||
extensionPath,
|
extensionPath,
|
||||||
|
workspacePath,
|
||||||
column || vscode.ViewColumn.One,
|
column || vscode.ViewColumn.One,
|
||||||
kanbn
|
kanbn
|
||||||
);
|
);
|
||||||
@ -42,33 +45,43 @@ export default class KanbnBoardPanel {
|
|||||||
index,
|
index,
|
||||||
tasks: (await KanbnBoardPanel.currentPanel._kanbn.loadAllTrackedTasks(index)).map(
|
tasks: (await KanbnBoardPanel.currentPanel._kanbn.loadAllTrackedTasks(index)).map(
|
||||||
task => KanbnBoardPanel.currentPanel!._kanbn.hydrateTask(index, task)
|
task => KanbnBoardPanel.currentPanel!._kanbn.hydrateTask(index, task)
|
||||||
)
|
),
|
||||||
|
startedColumns: index.options.startedColumns ?? [],
|
||||||
|
completedColumns: index.options.completedColumns ?? []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor(
|
private constructor(
|
||||||
extensionPath: string,
|
extensionPath: string,
|
||||||
|
workspacePath: string,
|
||||||
column: vscode.ViewColumn,
|
column: vscode.ViewColumn,
|
||||||
kanbn: typeof import('@basementuniverse/kanbn/src/main')
|
kanbn: typeof import('@basementuniverse/kanbn/src/main')
|
||||||
) {
|
) {
|
||||||
this._extensionPath = extensionPath;
|
this._extensionPath = extensionPath;
|
||||||
|
this._workspacePath = workspacePath;
|
||||||
this._kanbn = kanbn;
|
this._kanbn = kanbn;
|
||||||
|
|
||||||
// Create and show a new webview panel
|
// Create and show a new webview panel
|
||||||
this._panel = vscode.window.createWebviewPanel(KanbnBoardPanel.viewType, "Kanbn Board", column, {
|
this._panel = vscode.window.createWebviewPanel(KanbnBoardPanel.viewType, 'Kanbn Board', column, {
|
||||||
// Enable javascript in the webview
|
// Enable javascript in the webview
|
||||||
enableScripts: true,
|
enableScripts: true,
|
||||||
|
|
||||||
// Retain state even when hidden
|
// Retain state even when hidden
|
||||||
retainContextWhenHidden: true,
|
retainContextWhenHidden: true,
|
||||||
|
|
||||||
// Restrict the webview to only loading content from our extension's `media` directory.
|
// Restrict the webview to only loading content from allowed paths
|
||||||
localResourceRoots: [
|
localResourceRoots: [
|
||||||
vscode.Uri.file(path.join(this._extensionPath, 'build'))
|
vscode.Uri.file(path.join(this._extensionPath, 'build')),
|
||||||
|
vscode.Uri.file(path.join(this._workspacePath, '.kanbn'))
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Set the webview's title to the kanbn project name
|
||||||
|
this._kanbn.getIndex().then(index => {
|
||||||
|
this._panel.title = index.name;
|
||||||
|
});
|
||||||
|
|
||||||
// Set the webview's initial html content
|
// Set the webview's initial html content
|
||||||
this._panel.webview.html = this._getHtmlForWebview();
|
this._panel.webview.html = this._getHtmlForWebview();
|
||||||
|
|
||||||
@ -104,11 +117,6 @@ export default class KanbnBoardPanel {
|
|||||||
//
|
//
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Rename a task
|
|
||||||
case 'kanbn.rename':
|
|
||||||
//
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Delete a task
|
// Delete a task
|
||||||
case 'kanbn.delete':
|
case 'kanbn.delete':
|
||||||
//
|
//
|
||||||
@ -140,6 +148,9 @@ export default class KanbnBoardPanel {
|
|||||||
const styleUri = vscode.Uri
|
const styleUri = vscode.Uri
|
||||||
.file(path.join(this._extensionPath, 'build', mainStyle))
|
.file(path.join(this._extensionPath, 'build', mainStyle))
|
||||||
.with({ scheme: 'vscode-resource' });
|
.with({ scheme: 'vscode-resource' });
|
||||||
|
const customStyleUri = vscode.Uri
|
||||||
|
.file(path.join(this._workspacePath, '.kanbn', 'board.css'))
|
||||||
|
.with({ scheme: 'vscode-resource' });
|
||||||
|
|
||||||
// Use a nonce to whitelist which scripts can be run
|
// Use a nonce to whitelist which scripts can be run
|
||||||
const nonce = getNonce();
|
const nonce = getNonce();
|
||||||
@ -152,6 +163,7 @@ export default class KanbnBoardPanel {
|
|||||||
<meta name="theme-color" content="#000000">
|
<meta name="theme-color" content="#000000">
|
||||||
<title>Kanbn Board</title>
|
<title>Kanbn Board</title>
|
||||||
<link rel="stylesheet" type="text/css" href="${styleUri}">
|
<link rel="stylesheet" type="text/css" href="${styleUri}">
|
||||||
|
<link rel="stylesheet" type="text/css" href="${customStyleUri}">
|
||||||
<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:;">
|
<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' })}/">
|
<base href="${vscode.Uri.file(path.join(this._extensionPath, 'build')).with({ scheme: 'vscode-resource' })}/">
|
||||||
</head>
|
</head>
|
||||||
|
@ -62,7 +62,11 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
// If kanbn is initialised, view the kanbn board
|
// If kanbn is initialised, view the kanbn board
|
||||||
if (await kanbn.initialised()) {
|
if (await kanbn.initialised()) {
|
||||||
KanbnBoardPanel.createOrShow(context.extensionPath, kanbn);
|
KanbnBoardPanel.createOrShow(
|
||||||
|
context.extensionPath,
|
||||||
|
vscode.workspace.workspaceFolders[0].uri.fsPath,
|
||||||
|
kanbn
|
||||||
|
);
|
||||||
KanbnBoardPanel.update();
|
KanbnBoardPanel.update();
|
||||||
} else {
|
} else {
|
||||||
vscode.window.showErrorMessage('You need to initialise kanbn before viewing the kanbn board.');
|
vscode.window.showErrorMessage('You need to initialise kanbn before viewing the kanbn board.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user