This repository was archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
60 lines (48 loc) · 1.81 KB
/
index.ts
File metadata and controls
60 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const PLUGIN_NAME = "@wallneradam/custom_css";
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { JSONObject } from '@lumino/coreutils';
interface ICSSRule extends JSONObject {
selector: string;
styles: string[];
}
const extension: JupyterFrontEndPlugin<void> = {
id: PLUGIN_NAME,
requires: [ISettingRegistry],
autoStart: true,
activate: (app: JupyterFrontEnd, settingRegistry: ISettingRegistry) => {
console.log('JupyterLab extension custom_css is activated!');
let styleElement = document.createElement("style");
styleElement.type = "text/css";
styleElement.id = PLUGIN_NAME;
document.body.appendChild(styleElement);
/**
* Update settings on change
* @param settings The loaded settings
*/
function updateOptions(settings: ISettingRegistry.ISettings): void {
let styles = "";
let rules = settings.composite.rules as ICSSRule[];
for (let rule of rules) {
styles += `${rule.selector} \{`;
styles += "\n " + rule.styles.join(";\n ")
styles += "\n}\n";
}
document.body.removeChild(styleElement);
styleElement.innerHTML = styles;
document.body.appendChild(styleElement);
}
// Load settings
settingRegistry
.load(extension.id + ':plugin')
.then(settings => {
// Update options
updateOptions(settings);
// Update options on settings changed
settings.changed.connect(() => {
updateOptions(settings);
});
});
}
};
export default extension;