@jupyterlite/terminal 0.2.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,6 +46,17 @@ Then build a new JupyterLite site:
46
46
  jupyter lite build
47
47
  ```
48
48
 
49
+ ## Version compatibility
50
+
51
+ Each `jupyterlite-terminal` release is built against a specific version of `cockle`. If you need to
52
+ include imports from both `jupyterlite-terminal` and `cockle`, such as if you are implementing
53
+ `cockle` external commands, you should ensure that you are using the correct version combination.
54
+
55
+ | `jupyterlite-terminal` | `cockle` | `jupyterlite-core` |
56
+ | ---------------------- | -------- | ------------------ |
57
+ | 1.0.0 | 1.0.0 | >= 0.6, < 0.7 |
58
+ | 0.2.2 | 0.1.3 | >= 0.6, < 0.7 |
59
+
49
60
  ## Contributing
50
61
 
51
62
  ### Development install
package/lib/client.d.ts CHANGED
@@ -21,6 +21,7 @@ export declare class LiteTerminalAPIClient implements ILiteTerminalAPIClient {
21
21
  registerEnvironmentVariable(key: string, value: string | undefined): void;
22
22
  registerExternalCommand(options: IExternalCommand.IOptions): void;
23
23
  shutdown(name: string): Promise<void>;
24
+ themeChange(isDarkMode?: boolean): void;
24
25
  private get _models();
25
26
  private _nextAvailableName;
26
27
  private _aliases?;
package/lib/client.js CHANGED
@@ -114,6 +114,13 @@ export class LiteTerminalAPIClient {
114
114
  shell.dispose();
115
115
  }
116
116
  }
117
+ themeChange(isDarkMode) {
118
+ for (const shell of this._shells.values()) {
119
+ // Can pass isDarkMode when cockle is released with PR #232.
120
+ //shell.themeChange(isDarkMode);
121
+ shell.themeChange();
122
+ }
123
+ }
117
124
  get _models() {
118
125
  return Array.from(this._shells.keys(), name => {
119
126
  return { name };
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
- import { ITerminalManager, ServerConnection, IServerSettings, TerminalManager } from '@jupyterlab/services';
3
+ import { IThemeManager } from '@jupyterlab/apputils';
4
+ import { IServerSettings, ITerminalManager, ServerConnection, TerminalManager } from '@jupyterlab/services';
4
5
  import { IServiceWorkerManager } from '@jupyterlite/server';
6
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
5
7
  import { WebSocket } from 'mock-socket';
6
8
  import { LiteTerminalAPIClient } from './client';
7
9
  import { ILiteTerminalAPIClient } from './tokens';
@@ -60,10 +62,43 @@ const terminalServiceWorkerPlugin = {
60
62
  }
61
63
  }
62
64
  };
65
+ const terminalThemeChangePlugin = {
66
+ id: '@jupyterlite/terminal:theme-change',
67
+ autoStart: true,
68
+ requires: [ILiteTerminalAPIClient, ISettingRegistry],
69
+ optional: [IThemeManager],
70
+ activate: (_, liteTerminalAPIClient, settingRegistry, themeManager) => {
71
+ // Cache latest terminal theme so can identify if it has changed.
72
+ let terminalTheme;
73
+ themeManager === null || themeManager === void 0 ? void 0 : themeManager.themeChanged.connect(async (_, changedArgs) => {
74
+ // An overall Lab theme change only affects terminals if the terminaTheme is 'inherit'.
75
+ if (terminalTheme === 'inherit') {
76
+ const isDarkMode = !themeManager.isLight(changedArgs.newValue);
77
+ liteTerminalAPIClient.themeChange(isDarkMode);
78
+ }
79
+ });
80
+ // There is no signal for a terminal theme change, so use settings change.
81
+ settingRegistry
82
+ .load('@jupyterlab/terminal-extension:plugin')
83
+ .then(setting => {
84
+ terminalTheme = setting.composite.theme;
85
+ setting.changed.connect(() => {
86
+ // This signal is fired for any change to the terminal settings, not just the theme.
87
+ // Hence compare with the cached terminalTheme to identify if it has changed.
88
+ const newTerminalTheme = setting.composite.theme;
89
+ if (newTerminalTheme !== terminalTheme) {
90
+ liteTerminalAPIClient.themeChange();
91
+ terminalTheme = newTerminalTheme;
92
+ }
93
+ });
94
+ });
95
+ }
96
+ };
63
97
  export default [
64
98
  terminalClientPlugin,
65
99
  terminalManagerPlugin,
66
- terminalServiceWorkerPlugin
100
+ terminalServiceWorkerPlugin,
101
+ terminalThemeChangePlugin
67
102
  ];
68
103
  // Export ILiteTerminalAPIClient so that other extensions can register external commands.
69
104
  export { ILiteTerminalAPIClient };
package/lib/tokens.d.ts CHANGED
@@ -26,4 +26,8 @@ export interface ILiteTerminalAPIClient extends Terminal.ITerminalAPIClient {
26
26
  * Register an external command that will be available in all terminals.
27
27
  */
28
28
  registerExternalCommand(options: IExternalCommand.IOptions): void;
29
+ /**
30
+ * Inform all terminals that the theme has changed so that they can react to it if they wish.
31
+ */
32
+ themeChange(isDarkMode?: boolean): void;
29
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/terminal",
3
- "version": "0.2.2",
3
+ "version": "1.0.0",
4
4
  "description": "A terminal for JupyterLite",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -59,9 +59,11 @@
59
59
  "watch:labextension": "jupyter labextension watch ."
60
60
  },
61
61
  "dependencies": {
62
+ "@jupyterlab/apputils": "^4.5.3",
62
63
  "@jupyterlab/coreutils": "^6.4.3",
63
64
  "@jupyterlab/services": "^7.4.3",
64
- "@jupyterlite/cockle": "^0.1.2",
65
+ "@jupyterlab/settingregistry": "^4.4.3",
66
+ "@jupyterlite/cockle": "^1.0.0",
65
67
  "@jupyterlite/contents": "^0.6.0",
66
68
  "@jupyterlite/server": "^0.6.0",
67
69
  "@lumino/coreutils": "^2.2.0",
@@ -74,8 +76,8 @@
74
76
  "@types/json-schema": "^7.0.11",
75
77
  "@types/react": "^18.0.26",
76
78
  "@types/react-addons-linked-state-mixin": "^0.14.22",
77
- "@typescript-eslint/eslint-plugin": "^6.1.0",
78
- "@typescript-eslint/parser": "^6.1.0",
79
+ "@typescript-eslint/eslint-plugin": "^7.16.1",
80
+ "@typescript-eslint/parser": "^7.16.1",
79
81
  "css-loader": "^6.7.1",
80
82
  "eslint": "^8.36.0",
81
83
  "eslint-config-prettier": "^8.8.0",
@@ -92,7 +94,7 @@
92
94
  "stylelint-csstree-validator": "^3.0.0",
93
95
  "stylelint-prettier": "^4.0.0",
94
96
  "ts-loader": "^9.5.2",
95
- "typescript": "~5.0.2",
97
+ "typescript": "~5.7.0",
96
98
  "webpack": "^5.87.0",
97
99
  "webpack-cli": "^5.1.4",
98
100
  "yjs": "^13.5.0"
@@ -112,6 +114,14 @@
112
114
  "extension": true,
113
115
  "outputDir": "jupyterlite_terminal/labextension",
114
116
  "sharedPackages": {
117
+ "@jupyterlab/apputils": {
118
+ "bundled": false,
119
+ "singleton": true
120
+ },
121
+ "@jupyterlab/settingregistry": {
122
+ "bundled": false,
123
+ "singleton": true
124
+ },
115
125
  "@jupyterlite/contents": {
116
126
  "bundled": false,
117
127
  "singleton": true
package/src/client.ts CHANGED
@@ -148,6 +148,15 @@ export class LiteTerminalAPIClient implements ILiteTerminalAPIClient {
148
148
  }
149
149
  }
150
150
 
151
+ themeChange(isDarkMode?: boolean): void {
152
+ for (const shell of this._shells.values()) {
153
+ // Can pass isDarkMode when cockle is released with PR #232.
154
+ //shell.themeChange(isDarkMode);
155
+
156
+ shell.themeChange();
157
+ }
158
+ }
159
+
151
160
  private get _models(): Terminal.IModel[] {
152
161
  return Array.from(this._shells.keys(), name => {
153
162
  return { name };
package/src/index.ts CHANGED
@@ -5,15 +5,17 @@ import {
5
5
  JupyterFrontEnd,
6
6
  JupyterFrontEndPlugin
7
7
  } from '@jupyterlab/application';
8
+ import { IThemeManager } from '@jupyterlab/apputils';
8
9
  import {
10
+ IServerSettings,
9
11
  ITerminalManager,
12
+ ServerConnection,
10
13
  ServiceManagerPlugin,
11
14
  Terminal,
12
- ServerConnection,
13
- IServerSettings,
14
15
  TerminalManager
15
16
  } from '@jupyterlab/services';
16
17
  import { IServiceWorkerManager } from '@jupyterlite/server';
18
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
17
19
 
18
20
  import { WebSocket } from 'mock-socket';
19
21
 
@@ -94,10 +96,52 @@ const terminalServiceWorkerPlugin: JupyterFrontEndPlugin<void> = {
94
96
  }
95
97
  };
96
98
 
99
+ const terminalThemeChangePlugin: JupyterFrontEndPlugin<void> = {
100
+ id: '@jupyterlite/terminal:theme-change',
101
+ autoStart: true,
102
+ requires: [ILiteTerminalAPIClient, ISettingRegistry],
103
+ optional: [IThemeManager],
104
+ activate: (
105
+ _: JupyterFrontEnd,
106
+ liteTerminalAPIClient: ILiteTerminalAPIClient,
107
+ settingRegistry: ISettingRegistry,
108
+ themeManager?: IThemeManager
109
+ ): void => {
110
+ // Cache latest terminal theme so can identify if it has changed.
111
+ let terminalTheme: string | undefined;
112
+
113
+ themeManager?.themeChanged.connect(async (_, changedArgs) => {
114
+ // An overall Lab theme change only affects terminals if the terminaTheme is 'inherit'.
115
+ if (terminalTheme === 'inherit') {
116
+ const isDarkMode = !themeManager.isLight(changedArgs.newValue);
117
+ liteTerminalAPIClient.themeChange(isDarkMode);
118
+ }
119
+ });
120
+
121
+ // There is no signal for a terminal theme change, so use settings change.
122
+ settingRegistry
123
+ .load('@jupyterlab/terminal-extension:plugin')
124
+ .then(setting => {
125
+ terminalTheme = setting.composite.theme as string;
126
+
127
+ setting.changed.connect(() => {
128
+ // This signal is fired for any change to the terminal settings, not just the theme.
129
+ // Hence compare with the cached terminalTheme to identify if it has changed.
130
+ const newTerminalTheme = setting.composite.theme as string;
131
+ if (newTerminalTheme !== terminalTheme) {
132
+ liteTerminalAPIClient.themeChange();
133
+ terminalTheme = newTerminalTheme;
134
+ }
135
+ });
136
+ });
137
+ }
138
+ };
139
+
97
140
  export default [
98
141
  terminalClientPlugin,
99
142
  terminalManagerPlugin,
100
- terminalServiceWorkerPlugin
143
+ terminalServiceWorkerPlugin,
144
+ terminalThemeChangePlugin
101
145
  ];
102
146
 
103
147
  // Export ILiteTerminalAPIClient so that other extensions can register external commands.
package/src/tokens.ts CHANGED
@@ -38,4 +38,9 @@ export interface ILiteTerminalAPIClient extends Terminal.ITerminalAPIClient {
38
38
  * Register an external command that will be available in all terminals.
39
39
  */
40
40
  registerExternalCommand(options: IExternalCommand.IOptions): void;
41
+
42
+ /**
43
+ * Inform all terminals that the theme has changed so that they can react to it if they wish.
44
+ */
45
+ themeChange(isDarkMode?: boolean): void;
41
46
  }