@kispace-io/extension-notebook 0.8.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/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@kispace-io/extension-notebook",
3
+ "version": "0.8.0",
4
+ "type": "module",
5
+ "main": "./src/index.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./src/index.ts",
9
+ "types": "./src/index.ts"
10
+ }
11
+ },
12
+ "dependencies": {
13
+ "@kispace-io/core": "*",
14
+ "@kispace-io/extension-python-runtime": "*",
15
+ "marked": "^12.0.0 || ^16.4.1",
16
+ "monaco-editor": "0.55.1"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.9.3"
20
+ }
21
+ }
package/src/i18n.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "namespace": "extensions",
3
+ "en": {
4
+ "EXT_NOTEBOOK_NAME": "Jupyter-like Notebook Editor",
5
+ "EXT_NOTEBOOK_DESC": "View and execute Jupyter-like notebooks (.ipynb) with Python code execution and markdown rendering"
6
+ },
7
+ "de": {
8
+ "EXT_NOTEBOOK_NAME": "Jupyter-ähnlicher Notebook-Editor",
9
+ "EXT_NOTEBOOK_DESC": "Anzeigen und Ausführen von Jupyter-ähnlichen Notebooks (.ipynb) mit Python-Codeausführung und Markdown-Rendering"
10
+ }
11
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { extensionRegistry, i18nLazy, contributionRegistry, SYSTEM_LANGUAGE_BUNDLES } from '@kispace-io/core';
2
+ import bundle from './i18n.json';
3
+
4
+ contributionRegistry.registerContribution(SYSTEM_LANGUAGE_BUNDLES, bundle as any);
5
+
6
+ const t = i18nLazy('extensions');
7
+
8
+ extensionRegistry.registerExtension({
9
+ id: "system.notebook",
10
+ name: t('EXT_NOTEBOOK_NAME'),
11
+ description: t('EXT_NOTEBOOK_DESC'),
12
+ loader: () => import("./notebook-extension"),
13
+ icon: "k jupyter",
14
+
15
+ dependencies: ["system.pythonruntime"],
16
+ });
@@ -0,0 +1,84 @@
1
+ import {html} from "lit";
2
+ import type {EditorInput} from "@kispace-io/core";
3
+ import {File} from "@kispace-io/core";
4
+ import {activeEditorSignal} from "@kispace-io/core";
5
+ import type {ExecutionContext} from "@kispace-io/core";
6
+ import {NotebookData, isNotebookEditorLike} from "./notebook-types";
7
+
8
+ export default ({editorRegistry, commandRegistry, contributionRegistry}: any) => {
9
+ const INITIAL_NOTEBOOK_CONTENT: NotebookData = {
10
+ cells: [
11
+ {
12
+ cell_type: 'markdown',
13
+ source: ['Press the **Run** button in the code cell below to execute it.'],
14
+ metadata: {}
15
+ },
16
+ {
17
+ cell_type: 'code',
18
+ source: ['print("Hello, World!")'],
19
+ execution_count: null,
20
+ outputs: [],
21
+ metadata: {}
22
+ }
23
+ ],
24
+ metadata: {},
25
+ nbformat: 4,
26
+ nbformat_minor: 4
27
+ };
28
+ commandRegistry.registerHandler('python', {
29
+ canExecute: (context: ExecutionContext) => {
30
+ const activeEditor = activeEditorSignal.get();
31
+ if (isNotebookEditorLike(activeEditor)) {
32
+ const cellIndex = context.params?.cellIndex;
33
+ if (cellIndex !== undefined) {
34
+ return cellIndex >= 0 && cellIndex < (activeEditor.notebook?.cells.length ?? 0);
35
+ }
36
+ return activeEditor.focusedCellIndex >= 0;
37
+ }
38
+ return false;
39
+ },
40
+ execute: async (context: ExecutionContext) => {
41
+ const activeEditor = activeEditorSignal.get();
42
+ if (isNotebookEditorLike(activeEditor)) {
43
+ const cellIndex = context.params?.cellIndex ?? activeEditor.focusedCellIndex;
44
+ if (cellIndex >= 0) {
45
+ await activeEditor.executeCell(cellIndex);
46
+ }
47
+ }
48
+ }
49
+ });
50
+
51
+ editorRegistry.registerEditorInputHandler({
52
+ lazyInit: () => import('./notebook-runtime'),
53
+ canHandle: (input: any) => input instanceof File && input.getName().toLowerCase().endsWith(".ipynb"),
54
+ handle: async (input: File) => {
55
+ const editorInput = {
56
+ title: input.getName(),
57
+ data: input,
58
+ key: input.getName(),
59
+ editorId: "notebook-editor",
60
+ icon: "k jupyter",
61
+ noOverflow: true,
62
+ state: {},
63
+ } as EditorInput;
64
+ editorInput.widgetFactory = () => html`
65
+ <k-notebook-editor .input=${editorInput}></k-notebook-editor>`;
66
+ return editorInput;
67
+ },
68
+ ranking: 100,
69
+ });
70
+
71
+ contributionRegistry.registerContribution('filebrowser.create', {
72
+ label: 'Jupyter Notebook',
73
+ icon: 'k jupyter',
74
+ command: 'create_file',
75
+ params: {
76
+ path: "notebook.ipynb",
77
+ extension: '.ipynb',
78
+ ask: true,
79
+ contents: JSON.stringify(INITIAL_NOTEBOOK_CONTENT, null, 2)
80
+ }
81
+ });
82
+ };
83
+
84
+