@jupyterlab/mermaid-extension 4.1.0-alpha.1

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 ADDED
@@ -0,0 +1,3 @@
1
+ # @jupyterlab/mermaid-extension
2
+
3
+ A mime-renderer extension for JupyterLab that provides support for rendering Mermaid text-based diagrams and mime bundles.
package/lib/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module mermaid-extension
4
+ */
5
+ import { JupyterFrontEndPlugin } from '@jupyterlab/application';
6
+ import { IMermaidManager, IMermaidMarkdown } from '@jupyterlab/mermaid';
7
+ /**
8
+ * A namespace for mermaid text-based diagram commands.
9
+ */
10
+ export declare namespace CommandIDs {
11
+ const copySource = "mermaid:copy-source";
12
+ }
13
+ declare const _default: (JupyterFrontEndPlugin<void> | JupyterFrontEndPlugin<IMermaidManager> | JupyterFrontEndPlugin<IMermaidMarkdown>)[];
14
+ export default _default;
package/lib/index.js ADDED
@@ -0,0 +1,70 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { IThemeManager } from '@jupyterlab/apputils';
4
+ import { IMermaidManager, IMermaidMarkdown, MERMAID_CLASS, MERMAID_CODE_CLASS, MermaidManager, MermaidMarkdown, RenderedMermaid } from '@jupyterlab/mermaid';
5
+ /**
6
+ * A namespace for mermaid text-based diagram commands.
7
+ */
8
+ export var CommandIDs;
9
+ (function (CommandIDs) {
10
+ CommandIDs.copySource = 'mermaid:copy-source';
11
+ })(CommandIDs || (CommandIDs = {}));
12
+ /**
13
+ * A plugin for the core rendering/cachine of mermaid text-based diagrams
14
+ */
15
+ const core = {
16
+ id: '@jupyterlab/mermaid-extension:core',
17
+ description: 'Provides the Mermaid manager.',
18
+ autoStart: true,
19
+ optional: [IThemeManager],
20
+ provides: IMermaidManager,
21
+ activate: (app, themes) => {
22
+ const manager = new MermaidManager({ themes });
23
+ RenderedMermaid.manager = manager;
24
+ return manager;
25
+ }
26
+ };
27
+ /**
28
+ * A plugin for rendering mermaid text-based diagrams in markdown fenced code blocks
29
+ */
30
+ const markdown = {
31
+ id: '@jupyterlab/mermaid-extension:markdown',
32
+ description: 'Provides the Mermaid markdown renderer.',
33
+ autoStart: true,
34
+ requires: [IMermaidManager],
35
+ provides: IMermaidMarkdown,
36
+ activate: (app, mermaid) => {
37
+ return new MermaidMarkdown({ mermaid });
38
+ }
39
+ };
40
+ /**
41
+ * Contextual commands for mermaid text-based diagrams.
42
+ */
43
+ const contextCommands = {
44
+ id: '@jupyterlab/mermaid-extension:context-commands',
45
+ description: 'Provides context menu commands for mermaid diagrams.',
46
+ autoStart: true,
47
+ requires: [IMermaidManager],
48
+ activate: (app, mermaid) => {
49
+ const isMermaid = (node) => node.classList.contains(MERMAID_CLASS);
50
+ app.commands.addCommand(CommandIDs.copySource, {
51
+ label: 'Mermaid Copy Diagram Source',
52
+ execute: async (args) => {
53
+ const node = app.contextMenuHitTest(isMermaid);
54
+ if (!node) {
55
+ return;
56
+ }
57
+ const code = node.querySelector(`.${MERMAID_CODE_CLASS}`);
58
+ if (!code || !code.textContent) {
59
+ return;
60
+ }
61
+ await navigator.clipboard.writeText(code.textContent);
62
+ }
63
+ });
64
+ const options = { selector: `.${MERMAID_CLASS}`, rank: 13 };
65
+ app.contextMenu.addItem({ command: CommandIDs.copySource, ...options });
66
+ app.contextMenu.addItem({ type: 'separator', ...options });
67
+ }
68
+ };
69
+ export default [core, markdown, contextCommands];
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAW3D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,eAAe,EAChB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,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,EAAE;YAC7C,KAAK,EAAE,6BAA6B;YACpC,OAAO,EAAE,KAAK,EAAE,IAAU,EAAE,EAAE;gBAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;gBAC/C,IAAI,CAAC,IAAI,EAAE;oBACT,OAAO;iBACR;gBACD,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC;gBAC1D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBAC9B,OAAO;iBACR;gBACD,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACxD,CAAC;SACF,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,aAAa,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAC5D,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;QACxE,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF,CAAC;AAEF,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC"}
package/lib/mime.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module mermaid-extension
4
+ */
5
+ import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
6
+ declare const extension: IRenderMime.IExtension;
7
+ export default extension;
package/lib/mime.js ADDED
@@ -0,0 +1,35 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+ /**
6
+ * @packageDocumentation
7
+ * @module mermaid-extension
8
+ */
9
+ import { MERMAID_FILE_EXTENSIONS, MERMAID_MIME_TYPE, rendererFactory } from '@jupyterlab/mermaid';
10
+ const extension = {
11
+ id: '@jupyterlab/mermaid-extension:factory',
12
+ description: 'Provides a renderer for mermaid text-based diagrams.',
13
+ rendererFactory,
14
+ // one more than markdown
15
+ rank: 61,
16
+ dataType: 'string',
17
+ documentWidgetFactoryOptions: [
18
+ {
19
+ name: 'Mermaid',
20
+ primaryFileType: 'mermaid',
21
+ fileTypes: ['mermaid'],
22
+ defaultFor: ['mermaid']
23
+ }
24
+ ],
25
+ fileTypes: [
26
+ {
27
+ mimeTypes: [MERMAID_MIME_TYPE],
28
+ name: 'mermaid',
29
+ extensions: MERMAID_FILE_EXTENSIONS,
30
+ icon: 'ui-components:mermaid'
31
+ }
32
+ ]
33
+ };
34
+ export default extension;
35
+ //# sourceMappingURL=mime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mime.js","sourceRoot":"","sources":["../src/mime.ts"],"names":[],"mappings":"AAAA;;;+EAG+E;AAC/E;;;GAGG;AAEH,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,SAAS,GAA2B;IACxC,EAAE,EAAE,uCAAuC;IAC3C,WAAW,EAAE,sDAAsD;IACnE,eAAe;IACf,yBAAyB;IACzB,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,QAAQ;IAClB,4BAA4B,EAAE;QAC5B;YACE,IAAI,EAAE,SAAS;YACf,eAAe,EAAE,SAAS;YAC1B,SAAS,EAAE,CAAC,SAAS,CAAC;YACtB,UAAU,EAAE,CAAC,SAAS,CAAC;SACxB;KACF;IACD,SAAS,EAAE;QACT;YACE,SAAS,EAAE,CAAC,iBAAiB,CAAC;YAC9B,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,uBAAuB;YACnC,IAAI,EAAE,uBAAuB;SAC9B;KACF;CACF,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@jupyterlab/mermaid-extension",
3
+ "version": "4.1.0-alpha.1",
4
+ "description": "JupyterLab - Mermaid Viewer",
5
+ "homepage": "https://github.com/jupyterlab/jupyterlab",
6
+ "bugs": {
7
+ "url": "https://github.com/jupyterlab/jupyterlab/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/jupyterlab/jupyterlab.git"
12
+ },
13
+ "license": "BSD-3-Clause",
14
+ "author": "Project Jupyter",
15
+ "sideEffects": [
16
+ "style/*.css",
17
+ "style/index.js"
18
+ ],
19
+ "main": "lib/index.js",
20
+ "types": "lib/index.d.ts",
21
+ "style": "style/index.css",
22
+ "directories": {
23
+ "lib": "lib/"
24
+ },
25
+ "files": [
26
+ "lib/*.d.ts",
27
+ "lib/*.js.map",
28
+ "lib/*.js",
29
+ "style/*.css",
30
+ "style/index.js",
31
+ "src/**/*.{ts,tsx}"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc -b",
35
+ "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
36
+ "docs": "typedoc src",
37
+ "watch": "tsc -b --watch"
38
+ },
39
+ "dependencies": {
40
+ "@jupyterlab/application": "^4.1.0-alpha.1",
41
+ "@jupyterlab/apputils": "^4.2.0-alpha.1",
42
+ "@jupyterlab/mermaid": "^4.1.0-alpha.1",
43
+ "@jupyterlab/rendermime-interfaces": "^3.8.3-alpha.0"
44
+ },
45
+ "devDependencies": {
46
+ "rimraf": "~3.0.0",
47
+ "typedoc": "~0.24.7",
48
+ "typescript": "~5.0.4"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "jupyterlab": {
54
+ "extension": true,
55
+ "mimeExtension": "lib/mime.js"
56
+ },
57
+ "styleModule": "style/index.js"
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1,94 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ /**
5
+ * @packageDocumentation
6
+ * @module mermaid-extension
7
+ */
8
+
9
+ import {
10
+ JupyterFrontEnd,
11
+ JupyterFrontEndPlugin
12
+ } from '@jupyterlab/application';
13
+ import { IThemeManager } from '@jupyterlab/apputils';
14
+ import {
15
+ IMermaidManager,
16
+ IMermaidMarkdown,
17
+ MERMAID_CLASS,
18
+ MERMAID_CODE_CLASS,
19
+ MermaidManager,
20
+ MermaidMarkdown,
21
+ RenderedMermaid
22
+ } from '@jupyterlab/mermaid';
23
+
24
+ /**
25
+ * A namespace for mermaid text-based diagram commands.
26
+ */
27
+ export namespace CommandIDs {
28
+ export const copySource = 'mermaid:copy-source';
29
+ }
30
+
31
+ /**
32
+ * A plugin for the core rendering/cachine of mermaid text-based diagrams
33
+ */
34
+ const core: JupyterFrontEndPlugin<IMermaidManager> = {
35
+ id: '@jupyterlab/mermaid-extension:core',
36
+ description: 'Provides the Mermaid manager.',
37
+ autoStart: true,
38
+ optional: [IThemeManager],
39
+ provides: IMermaidManager,
40
+ activate: (app: JupyterFrontEnd, themes: IThemeManager) => {
41
+ const manager = new MermaidManager({ themes });
42
+ RenderedMermaid.manager = manager;
43
+ return manager;
44
+ }
45
+ };
46
+
47
+ /**
48
+ * A plugin for rendering mermaid text-based diagrams in markdown fenced code blocks
49
+ */
50
+ const markdown: JupyterFrontEndPlugin<IMermaidMarkdown> = {
51
+ id: '@jupyterlab/mermaid-extension:markdown',
52
+ description: 'Provides the Mermaid markdown renderer.',
53
+ autoStart: true,
54
+ requires: [IMermaidManager],
55
+ provides: IMermaidMarkdown,
56
+ activate: (app: JupyterFrontEnd, mermaid: IMermaidManager) => {
57
+ return new MermaidMarkdown({ mermaid });
58
+ }
59
+ };
60
+
61
+ /**
62
+ * Contextual commands for mermaid text-based diagrams.
63
+ */
64
+ const contextCommands: JupyterFrontEndPlugin<void> = {
65
+ id: '@jupyterlab/mermaid-extension:context-commands',
66
+ description: 'Provides context menu commands for mermaid diagrams.',
67
+ autoStart: true,
68
+ requires: [IMermaidManager],
69
+ activate: (app: JupyterFrontEnd, mermaid: IMermaidManager) => {
70
+ const isMermaid = (node: HTMLElement) =>
71
+ node.classList.contains(MERMAID_CLASS);
72
+
73
+ app.commands.addCommand(CommandIDs.copySource, {
74
+ label: 'Mermaid Copy Diagram Source',
75
+ execute: async (args?: any) => {
76
+ const node = app.contextMenuHitTest(isMermaid);
77
+ if (!node) {
78
+ return;
79
+ }
80
+ const code = node.querySelector(`.${MERMAID_CODE_CLASS}`);
81
+ if (!code || !code.textContent) {
82
+ return;
83
+ }
84
+ await navigator.clipboard.writeText(code.textContent);
85
+ }
86
+ });
87
+
88
+ const options = { selector: `.${MERMAID_CLASS}`, rank: 13 };
89
+ app.contextMenu.addItem({ command: CommandIDs.copySource, ...options });
90
+ app.contextMenu.addItem({ type: 'separator', ...options });
91
+ }
92
+ };
93
+
94
+ export default [core, markdown, contextCommands];
package/src/mime.ts ADDED
@@ -0,0 +1,42 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+ /**
6
+ * @packageDocumentation
7
+ * @module mermaid-extension
8
+ */
9
+
10
+ import {
11
+ MERMAID_FILE_EXTENSIONS,
12
+ MERMAID_MIME_TYPE,
13
+ rendererFactory
14
+ } from '@jupyterlab/mermaid';
15
+ import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
16
+
17
+ const extension: IRenderMime.IExtension = {
18
+ id: '@jupyterlab/mermaid-extension:factory',
19
+ description: 'Provides a renderer for mermaid text-based diagrams.',
20
+ rendererFactory,
21
+ // one more than markdown
22
+ rank: 61,
23
+ dataType: 'string',
24
+ documentWidgetFactoryOptions: [
25
+ {
26
+ name: 'Mermaid',
27
+ primaryFileType: 'mermaid',
28
+ fileTypes: ['mermaid'],
29
+ defaultFor: ['mermaid']
30
+ }
31
+ ],
32
+ fileTypes: [
33
+ {
34
+ mimeTypes: [MERMAID_MIME_TYPE],
35
+ name: 'mermaid',
36
+ extensions: MERMAID_FILE_EXTENSIONS,
37
+ icon: 'ui-components:mermaid'
38
+ }
39
+ ]
40
+ };
41
+
42
+ export default extension;
package/style/base.css ADDED
@@ -0,0 +1,4 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
@@ -0,0 +1,10 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+ @import url('~@jupyterlab/apputils/style/index.css');
8
+ @import url('~@jupyterlab/application/style/index.css');
9
+ @import url('~@jupyterlab/mermaid/style/index.css');
10
+ @import url('./base.css');
package/style/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+ import '@jupyterlab/apputils/style/index.js';
8
+ import '@jupyterlab/application/style/index.js';
9
+ import '@jupyterlab/mermaid/style/index.js';
10
+
11
+ import './base.css';