@dxos/plugin-mermaid 0.8.4-main.c4373fc → 0.8.4-main.d9fc60f731

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.
Files changed (40) hide show
  1. package/LICENSE +102 -5
  2. package/PLUGIN.mdl +260 -0
  3. package/README.md +1 -1
  4. package/dist/lib/neutral/MermaidPlugin.mjs +190 -0
  5. package/dist/lib/neutral/MermaidPlugin.mjs.map +7 -0
  6. package/dist/lib/neutral/chunk-WD2YFG2L.mjs +36 -0
  7. package/dist/lib/neutral/chunk-WD2YFG2L.mjs.map +7 -0
  8. package/dist/lib/neutral/index.mjs +7 -0
  9. package/dist/lib/neutral/index.mjs.map +7 -0
  10. package/dist/lib/neutral/meta.json +1 -0
  11. package/dist/lib/neutral/meta.mjs +7 -0
  12. package/dist/lib/neutral/meta.mjs.map +7 -0
  13. package/dist/lib/neutral/plugin.mjs +11 -0
  14. package/dist/lib/neutral/plugin.mjs.map +7 -0
  15. package/dist/types/src/MermaidPlugin.d.ts +3 -1
  16. package/dist/types/src/MermaidPlugin.d.ts.map +1 -1
  17. package/dist/types/src/MermaidPlugin.test.d.ts +2 -0
  18. package/dist/types/src/MermaidPlugin.test.d.ts.map +1 -0
  19. package/dist/types/src/extensions/mermaid-extension.d.ts.map +1 -1
  20. package/dist/types/src/extensions/mermaid.stories.d.ts +2 -5
  21. package/dist/types/src/extensions/mermaid.stories.d.ts.map +1 -1
  22. package/dist/types/src/index.d.ts +0 -1
  23. package/dist/types/src/index.d.ts.map +1 -1
  24. package/dist/types/src/meta.d.ts +2 -2
  25. package/dist/types/src/meta.d.ts.map +1 -1
  26. package/dist/types/src/plugin.d.ts +3 -0
  27. package/dist/types/src/plugin.d.ts.map +1 -0
  28. package/dist/types/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +53 -30
  30. package/src/MermaidPlugin.test.ts +30 -0
  31. package/src/MermaidPlugin.tsx +19 -7
  32. package/src/extensions/mermaid-extension.ts +9 -9
  33. package/src/extensions/mermaid.stories.tsx +7 -10
  34. package/src/index.ts +0 -1
  35. package/src/meta.ts +27 -5
  36. package/src/plugin.ts +9 -0
  37. package/src/vite-env.d.ts +10 -0
  38. package/dist/lib/browser/index.mjs +0 -195
  39. package/dist/lib/browser/index.mjs.map +0 -7
  40. package/dist/lib/browser/meta.json +0 -1
package/package.json CHANGED
@@ -1,57 +1,80 @@
1
1
  {
2
2
  "name": "@dxos/plugin-mermaid",
3
- "version": "0.8.4-main.c4373fc",
3
+ "version": "0.8.4-main.d9fc60f731",
4
4
  "description": "Mermaid markdown plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
- "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
11
+ "license": "FSL-1.1-Apache-2.0",
8
12
  "author": "DXOS.org",
9
13
  "sideEffects": true,
10
14
  "type": "module",
15
+ "imports": {
16
+ "#meta": {
17
+ "source": "./src/meta.ts",
18
+ "types": "./dist/types/src/meta.d.ts",
19
+ "default": "./dist/lib/neutral/meta.mjs"
20
+ },
21
+ "#plugin": {
22
+ "source": "./src/MermaidPlugin.tsx",
23
+ "types": "./dist/types/src/MermaidPlugin.d.ts",
24
+ "default": "./dist/lib/neutral/MermaidPlugin.mjs"
25
+ }
26
+ },
11
27
  "exports": {
12
28
  ".": {
13
29
  "source": "./src/index.ts",
14
30
  "types": "./dist/types/src/index.d.ts",
15
- "browser": "./dist/lib/browser/index.mjs"
31
+ "default": "./dist/lib/neutral/index.mjs"
32
+ },
33
+ "./assets/PLUGIN.mdl": "./PLUGIN.mdl",
34
+ "./plugin": {
35
+ "source": "./src/plugin.ts",
36
+ "types": "./dist/types/src/plugin.d.ts",
37
+ "default": "./dist/lib/neutral/plugin.mjs"
16
38
  }
17
39
  },
18
40
  "types": "dist/types/src/index.d.ts",
19
- "typesVersions": {
20
- "*": {}
21
- },
22
41
  "files": [
23
42
  "dist",
24
- "src"
43
+ "src",
44
+ "PLUGIN.mdl"
25
45
  ],
26
46
  "dependencies": {
27
- "@codemirror/language": "^6.11.3",
28
- "@codemirror/state": "^6.5.2",
29
- "@codemirror/view": "^6.38.4",
30
- "@preact-signals/safe-react": "^0.9.0",
47
+ "@codemirror/language": "^6.12.3",
48
+ "@codemirror/state": "^6.6.0",
49
+ "@codemirror/view": "^6.43.0",
31
50
  "mermaid": "^10.9.4",
32
- "@dxos/app-framework": "0.8.4-main.c4373fc",
33
- "@dxos/plugin-space": "0.8.4-main.c4373fc",
34
- "@dxos/plugin-markdown": "0.8.4-main.c4373fc",
35
- "@dxos/react-ui-editor": "0.8.4-main.c4373fc"
51
+ "@dxos/app-framework": "0.8.4-main.d9fc60f731",
52
+ "@dxos/operation": "0.8.4-main.d9fc60f731",
53
+ "@dxos/plugin-markdown": "0.8.4-main.d9fc60f731",
54
+ "@dxos/app-toolkit": "0.8.4-main.d9fc60f731",
55
+ "@dxos/ui-editor": "0.8.4-main.d9fc60f731",
56
+ "@dxos/react-ui-editor": "0.8.4-main.d9fc60f731",
57
+ "@dxos/util": "0.8.4-main.d9fc60f731",
58
+ "@dxos/keys": "0.8.4-main.d9fc60f731"
36
59
  },
37
60
  "devDependencies": {
38
- "@types/react": "~19.2.2",
39
- "@types/react-dom": "~19.2.1",
40
- "effect": "3.18.3",
41
- "react": "~19.2.0",
42
- "react-dom": "~19.2.0",
43
- "vite": "7.1.9",
44
- "@dxos/echo": "0.8.4-main.c4373fc",
45
- "@dxos/react-ui": "0.8.4-main.c4373fc",
46
- "@dxos/react-ui-theme": "0.8.4-main.c4373fc",
47
- "@dxos/storybook-utils": "0.8.4-main.c4373fc"
61
+ "@types/react": "~19.2.7",
62
+ "@types/react-dom": "~19.2.3",
63
+ "effect": "3.21.2",
64
+ "react": "~19.2.3",
65
+ "react-dom": "~19.2.3",
66
+ "vite": "^8.0.14",
67
+ "@dxos/echo": "0.8.4-main.d9fc60f731",
68
+ "@dxos/react-ui": "0.8.4-main.d9fc60f731",
69
+ "@dxos/storybook-utils": "0.8.4-main.d9fc60f731",
70
+ "@dxos/ui-theme": "0.8.4-main.d9fc60f731"
48
71
  },
49
72
  "peerDependencies": {
50
- "effect": "^3.13.3",
51
- "react": "^19.0.0",
52
- "react-dom": "^19.0.0",
53
- "@dxos/react-ui": "0.8.4-main.c4373fc",
54
- "@dxos/react-ui-theme": "0.8.4-main.c4373fc"
73
+ "effect": "3.21.2",
74
+ "react": "~19.2.3",
75
+ "react-dom": "~19.2.3",
76
+ "@dxos/react-ui": "0.8.4-main.d9fc60f731",
77
+ "@dxos/ui-theme": "0.8.4-main.d9fc60f731"
55
78
  },
56
79
  "publishConfig": {
57
80
  "access": "public"
@@ -0,0 +1,30 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { describe, test } from 'vitest';
6
+
7
+ import { ProcessManagerPlugin } from '@dxos/app-framework';
8
+ import { createTestApp } from '@dxos/app-framework/testing';
9
+ import { MarkdownEvents } from '@dxos/plugin-markdown';
10
+
11
+ import { MermaidPlugin } from '#plugin';
12
+
13
+ import { meta } from './meta';
14
+
15
+ const moduleId = (name: string) => `${meta.id}.module.${name}`;
16
+
17
+ describe('MermaidPlugin', () => {
18
+ test('modules activate on the expected events', async ({ expect }) => {
19
+ // Use createTestApp directly — only ProcessManagerPlugin and ProcessManagerPlugin are needed.
20
+ // MermaidPlugin has no surface module so SetupReactSurface firing harmlessly is fine.
21
+ await using harness = await createTestApp({
22
+ plugins: [ProcessManagerPlugin(), MermaidPlugin()],
23
+ });
24
+
25
+ // The markdown module activates on MarkdownEvents.SetupExtensions,
26
+ // which is fired by MarkdownPlugin before its ReactSurface activates.
27
+ await harness.fire(MarkdownEvents.SetupExtensions);
28
+ expect(harness.manager.getActive()).toContain(moduleId('markdown'));
29
+ });
30
+ });
@@ -2,16 +2,28 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { contributes, defineModule, definePlugin } from '@dxos/app-framework';
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Capability, Plugin } from '@dxos/app-framework';
8
+ import { AppPlugin } from '@dxos/app-toolkit';
6
9
  import { MarkdownCapabilities, MarkdownEvents } from '@dxos/plugin-markdown';
7
10
 
11
+ import { meta } from '#meta';
12
+
13
+ // eslint-disable-next-line import/no-relative-packages
14
+ import pluginSpec from '../PLUGIN.mdl?raw';
8
15
  import { mermaid } from './extensions';
9
- import { meta } from './meta';
10
16
 
11
- export const MermaidPlugin = definePlugin(meta, () => [
12
- defineModule({
13
- id: `${meta.id}/module/markdown`,
17
+ export const MermaidPlugin = Plugin.define(meta).pipe(
18
+ Plugin.addModule({
19
+ id: 'markdown',
14
20
  activatesOn: MarkdownEvents.SetupExtensions,
15
- activate: () => contributes(MarkdownCapabilities.Extensions, [mermaid]),
21
+ activate: () => Effect.succeed(Capability.contributes(MarkdownCapabilities.Extensions, [mermaid])),
16
22
  }),
17
- ]);
23
+ AppPlugin.addPluginAssetModule({
24
+ asset: { pluginId: meta.id, path: 'PLUGIN.mdl', content: pluginSpec, mimeType: 'application/x-mdl' },
25
+ }),
26
+ Plugin.make,
27
+ );
28
+
29
+ export default MermaidPlugin;
@@ -112,18 +112,18 @@ export const mermaid = (_options: MermaidOptions = {}): Extension => {
112
112
  maring: '4px 0',
113
113
  padding: '16px',
114
114
  justifyContent: 'center',
115
- backgroundColor: 'var(--dx-groupSurface)',
115
+ backgroundColor: 'var(--color-group-surface)',
116
116
  borderRadius: '8px',
117
117
  },
118
118
  '& .cm-mermaid-label': {
119
119
  position: 'absolute',
120
120
  right: '16px',
121
121
  fontFamily: 'unset',
122
- color: 'var(--dx-subdued)',
122
+ color: 'var(--color-subdued)',
123
123
  },
124
124
  '& .cm-mermaid-error': {
125
125
  display: 'inline-block',
126
- color: 'var(--dx-errorText)',
126
+ color: 'var(--color-error)',
127
127
  },
128
128
  '& .cm-mermaid-hidden': {
129
129
  display: 'none !important',
@@ -145,11 +145,15 @@ class MermaidWidget extends WidgetType {
145
145
  super();
146
146
  }
147
147
 
148
- override eq(other: this): boolean {
148
+ override eq(other: this) {
149
149
  return this._source === other._source;
150
150
  }
151
151
 
152
- override toDOM(view: EditorView): HTMLDivElement {
152
+ override ignoreEvent(ev: Event) {
153
+ return !/^mouse/.test(ev.type);
154
+ }
155
+
156
+ override toDOM(view: EditorView) {
153
157
  const div = document.createElement('div');
154
158
  div.className = 'cm-mermaid';
155
159
 
@@ -208,8 +212,4 @@ class MermaidWidget extends WidgetType {
208
212
  this._svg = undefined;
209
213
  }
210
214
  }
211
-
212
- override ignoreEvent(e: Event): boolean {
213
- return !/^mouse/.test(e.type);
214
- }
215
215
  }
@@ -6,24 +6,24 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import React from 'react';
7
7
 
8
8
  import { useThemeContext } from '@dxos/react-ui';
9
- import { withTheme } from '@dxos/react-ui/testing';
9
+ import { useTextEditor } from '@dxos/react-ui-editor';
10
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
11
  import {
11
12
  createBasicExtensions,
12
13
  createMarkdownExtensions,
13
14
  createThemeExtensions,
14
15
  decorateMarkdown,
15
- useTextEditor,
16
- } from '@dxos/react-ui-editor';
16
+ } from '@dxos/ui-editor';
17
17
 
18
18
  import { mermaid } from './mermaid-extension';
19
19
 
20
20
  const str = (...lines: string[]) => lines.join('\n');
21
21
 
22
- type StoryProps = {
22
+ type DefaultStoryProps = {
23
23
  text?: string;
24
24
  };
25
25
 
26
- const DefaultStory = ({ text }: StoryProps) => {
26
+ const DefaultStory = ({ text }: DefaultStoryProps) => {
27
27
  const { themeMode } = useThemeContext();
28
28
  const { parentRef, focusAttributes } = useTextEditor(
29
29
  () => ({
@@ -43,12 +43,9 @@ const DefaultStory = ({ text }: StoryProps) => {
43
43
  };
44
44
 
45
45
  const meta = {
46
- title: 'plugins/plugin-mermaid/extensions',
46
+ title: 'plugins/plugin-mermaid/extensions/mermaid',
47
47
  render: DefaultStory,
48
- decorators: [withTheme],
49
- parameters: {
50
- layout: 'column',
51
- },
48
+ decorators: [withTheme(), withLayout({ layout: 'column' })],
52
49
  } satisfies Meta<typeof DefaultStory>;
53
50
 
54
51
  export default meta;
package/src/index.ts CHANGED
@@ -2,5 +2,4 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './MermaidPlugin';
6
5
  export * from './meta';
package/src/meta.ts CHANGED
@@ -2,12 +2,34 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { Plugin } from '@dxos/app-framework';
6
+ import { DXN } from '@dxos/keys';
7
+ import { trim } from '@dxos/util';
6
8
 
7
- export const meta: PluginMeta = {
8
- id: 'dxos.org/plugin/mermaid',
9
+ export const meta = Plugin.makeMeta({
10
+ key: DXN.make('org.dxos.plugin.mermaid'),
9
11
  name: 'Mermaid',
10
- description: 'Tool that renders text definitions to create diagrams.',
12
+ author: 'DXOS',
13
+ description: trim`
14
+ Generate diagrams from simple text-based definitions using Mermaid syntax.
15
+ Create flowcharts, sequence diagrams, class diagrams, state diagrams, entity-relationship
16
+ diagrams, Gantt charts, pie charts, Git graphs, mindmaps, and timelines — all from
17
+ plain-text source embedded directly in your documents.
18
+
19
+ The plugin integrates with the markdown editor as a CodeMirror extension.
20
+ Any fenced code block tagged with the \`mermaid\` language identifier is automatically
21
+ detected and replaced with a live SVG preview rendered by the Mermaid JS library.
22
+ The raw source is revealed for editing whenever the cursor moves inside the block,
23
+ then the rendered diagram is restored when the cursor moves away, providing a seamless
24
+ live-preview experience without leaving the editor.
25
+
26
+ Diagram rendering adapts to the editor's current color scheme: dark-mode documents
27
+ use Mermaid's dark theme while light-mode documents use the neutral theme.
28
+ Parse and render errors are shown inline in place of the diagram so that
29
+ invalid syntax is immediately visible without disrupting the rest of the document.
30
+ `,
11
31
  icon: 'ph--anchor-simple--regular',
32
+ iconHue: 'cyan',
12
33
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-mermaid',
13
- };
34
+ spec: 'PLUGIN.mdl',
35
+ });
package/src/plugin.ts ADDED
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+
7
+ import { meta } from './meta';
8
+
9
+ export const MermaidPlugin = Plugin.lazy(meta, () => import('#plugin'));
@@ -0,0 +1,10 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ //
4
+ // Copyright 2026 DXOS.org
5
+ //
6
+
7
+ declare module '*.mdl?raw' {
8
+ const content: string;
9
+ export default content;
10
+ }
@@ -1,195 +0,0 @@
1
- // src/MermaidPlugin.tsx
2
- import { contributes, defineModule, definePlugin } from "@dxos/app-framework";
3
- import { MarkdownCapabilities, MarkdownEvents } from "@dxos/plugin-markdown";
4
-
5
- // src/extensions/mermaid-extension.ts
6
- import { syntaxTree } from "@codemirror/language";
7
- import { Decoration, EditorView, ViewPlugin, WidgetType } from "@codemirror/view";
8
- import _mermaid from "mermaid";
9
- function _define_property(obj, key, value) {
10
- if (key in obj) {
11
- Object.defineProperty(obj, key, {
12
- value,
13
- enumerable: true,
14
- configurable: true,
15
- writable: true
16
- });
17
- } else {
18
- obj[key] = value;
19
- }
20
- return obj;
21
- }
22
- var mermaid = (_options = {}) => {
23
- return [
24
- ViewPlugin.fromClass(class {
25
- update(update) {
26
- if (update.docChanged || update.viewportChanged || update.selectionSet || update.focusChanged) {
27
- this.decorations = this.buildDecorations(update.view);
28
- }
29
- }
30
- buildDecorations(view) {
31
- const decorations = [];
32
- syntaxTree(view.state).iterate({
33
- enter: (node) => {
34
- if (node.name === "FencedCode") {
35
- const cursor = view.state.selection.main.head;
36
- const showWidget = view.state.readOnly || cursor < node.from - 1 || cursor > node.to + 1;
37
- if (showWidget) {
38
- const info = node.node.getChild("CodeInfo");
39
- if (info) {
40
- const type = view.state.sliceDoc(info.from, info.to);
41
- const text = node.node.getChild("CodeText");
42
- if (type === "mermaid" && text) {
43
- const content = view.state.sliceDoc(text.from, text.to).trim();
44
- const label = content.split(" ")[0];
45
- const widget = new MermaidWidget(`mermaid-${node.from}`, content, label);
46
- const endLine = view.state.doc.lineAt(node.to);
47
- const nextLinePos = endLine.to + 1;
48
- if (nextLinePos <= view.state.doc.length) {
49
- decorations.push({
50
- from: nextLinePos,
51
- to: nextLinePos,
52
- decoration: Decoration.widget({
53
- widget
54
- })
55
- });
56
- } else {
57
- decorations.push({
58
- from: endLine.to,
59
- to: endLine.to,
60
- decoration: Decoration.widget({
61
- widget,
62
- side: 1
63
- })
64
- });
65
- }
66
- const startLine = view.state.doc.lineAt(node.from);
67
- for (let lineNum = startLine.number; lineNum <= endLine.number; lineNum++) {
68
- const line = view.state.doc.line(lineNum);
69
- decorations.push({
70
- from: line.from,
71
- to: line.from,
72
- decoration: Decoration.line({
73
- class: "cm-mermaid-hidden"
74
- })
75
- });
76
- }
77
- }
78
- }
79
- }
80
- }
81
- }
82
- });
83
- return Decoration.set(decorations.sort((a, b) => a.from - b.from || a.to - b.to).map((d) => d.decoration.range(d.from, d.to)));
84
- }
85
- constructor(view) {
86
- _define_property(this, "decorations", void 0);
87
- this.decorations = this.buildDecorations(view);
88
- }
89
- }, {
90
- decorations: (v) => v.decorations
91
- }),
92
- EditorView.theme({
93
- "& .cm-mermaid": {
94
- position: "relative",
95
- display: "inline-flex",
96
- width: "100%",
97
- maring: "4px 0",
98
- padding: "16px",
99
- justifyContent: "center",
100
- backgroundColor: "var(--dx-groupSurface)",
101
- borderRadius: "8px"
102
- },
103
- "& .cm-mermaid-label": {
104
- position: "absolute",
105
- right: "16px",
106
- fontFamily: "unset",
107
- color: "var(--dx-subdued)"
108
- },
109
- "& .cm-mermaid-error": {
110
- display: "inline-block",
111
- color: "var(--dx-errorText)"
112
- },
113
- "& .cm-mermaid-hidden": {
114
- display: "none !important"
115
- }
116
- })
117
- ];
118
- };
119
- var MermaidWidget = class extends WidgetType {
120
- eq(other) {
121
- return this._source === other._source;
122
- }
123
- toDOM(view) {
124
- const div = document.createElement("div");
125
- div.className = "cm-mermaid";
126
- setTimeout(async () => {
127
- _mermaid.initialize({
128
- darkMode: view.state.facet(EditorView.darkTheme),
129
- theme: "neutral"
130
- });
131
- const svg = await this.render(div);
132
- if (this._error) {
133
- div.className = "cm-mermaid-error";
134
- div.innerText = this._error;
135
- } else {
136
- div.className = "cm-mermaid";
137
- div.innerHTML = svg;
138
- if (this._label) {
139
- const label = document.createElement("span");
140
- label.innerText = this._label;
141
- label.className = "cm-mermaid-label";
142
- div.appendChild(label);
143
- view.requestMeasure();
144
- }
145
- }
146
- });
147
- return div;
148
- }
149
- async render(_container) {
150
- try {
151
- const valid = await _mermaid.parse(this._source);
152
- if (valid) {
153
- const result = await _mermaid.render(this._id, this._source);
154
- this._error = void 0;
155
- this._svg = result.svg;
156
- return result.svg;
157
- }
158
- } catch (err) {
159
- this._error = String(err);
160
- this._svg = void 0;
161
- }
162
- }
163
- ignoreEvent(e) {
164
- return !/^mouse/.test(e.type);
165
- }
166
- // TODO(burdon): Mermaid API requires unique id.
167
- constructor(_id, _source, _label) {
168
- super(), _define_property(this, "_id", void 0), _define_property(this, "_source", void 0), _define_property(this, "_label", void 0), _define_property(this, "_svg", void 0), _define_property(this, "_error", void 0), this._id = _id, this._source = _source, this._label = _label;
169
- }
170
- };
171
-
172
- // src/meta.ts
173
- var meta = {
174
- id: "dxos.org/plugin/mermaid",
175
- name: "Mermaid",
176
- description: "Tool that renders text definitions to create diagrams.",
177
- icon: "ph--anchor-simple--regular",
178
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-mermaid"
179
- };
180
-
181
- // src/MermaidPlugin.tsx
182
- var MermaidPlugin = definePlugin(meta, () => [
183
- defineModule({
184
- id: `${meta.id}/module/markdown`,
185
- activatesOn: MarkdownEvents.SetupExtensions,
186
- activate: () => contributes(MarkdownCapabilities.Extensions, [
187
- mermaid
188
- ])
189
- })
190
- ]);
191
- export {
192
- MermaidPlugin,
193
- meta
194
- };
195
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/MermaidPlugin.tsx", "../../../src/extensions/mermaid-extension.ts", "../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { contributes, defineModule, definePlugin } from '@dxos/app-framework';\nimport { MarkdownCapabilities, MarkdownEvents } from '@dxos/plugin-markdown';\n\nimport { mermaid } from './extensions';\nimport { meta } from './meta';\n\nexport const MermaidPlugin = definePlugin(meta, () => [\n defineModule({\n id: `${meta.id}/module/markdown`,\n activatesOn: MarkdownEvents.SetupExtensions,\n activate: () => contributes(MarkdownCapabilities.Extensions, [mermaid]),\n }),\n]);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { syntaxTree } from '@codemirror/language';\nimport { type Extension } from '@codemirror/state';\nimport { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate, WidgetType } from '@codemirror/view';\nimport _mermaid from 'mermaid';\n\nexport type MermaidOptions = {};\n\n/**\n * Extension to create mermaid diagrams.\n */\nexport const mermaid = (_options: MermaidOptions = {}): Extension => {\n return [\n ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = this.buildDecorations(view);\n }\n\n update(update: ViewUpdate) {\n // Always rebuild decorations when selection changes to handle arrow key navigation.\n if (update.docChanged || update.viewportChanged || update.selectionSet || update.focusChanged) {\n this.decorations = this.buildDecorations(update.view);\n }\n }\n\n buildDecorations(view: EditorView): DecorationSet {\n const decorations: Array<{ from: number; to: number; decoration: Decoration }> = [];\n\n syntaxTree(view.state).iterate({\n enter: (node) => {\n if (node.name === 'FencedCode') {\n const cursor = view.state.selection.main.head;\n // Show widget when cursor is outside the code block.\n // Add a buffer of 1 position before and after to handle edge cases.\n const showWidget = view.state.readOnly || cursor < node.from - 1 || cursor > node.to + 1;\n if (showWidget) {\n const info = node.node.getChild('CodeInfo');\n if (info) {\n const type = view.state.sliceDoc(info.from, info.to);\n const text = node.node.getChild('CodeText');\n if (type === 'mermaid' && text) {\n const content = view.state.sliceDoc(text.from, text.to).trim();\n const label = content.split(' ')[0];\n\n // Create widget.\n const widget = new MermaidWidget(`mermaid-${node.from}`, content, label);\n\n // Find the line after the code block to place the widget.\n const endLine = view.state.doc.lineAt(node.to);\n const nextLinePos = endLine.to + 1;\n\n // Add widget after the code block.\n if (nextLinePos <= view.state.doc.length) {\n decorations.push({\n from: nextLinePos,\n to: nextLinePos,\n decoration: Decoration.widget({\n widget,\n }),\n });\n } else {\n // Check if at the end of the document.\n decorations.push({\n from: endLine.to,\n to: endLine.to,\n decoration: Decoration.widget({\n widget,\n side: 1,\n }),\n });\n }\n\n // Hide each line of the code block.\n const startLine = view.state.doc.lineAt(node.from);\n for (let lineNum = startLine.number; lineNum <= endLine.number; lineNum++) {\n const line = view.state.doc.line(lineNum);\n decorations.push({\n from: line.from,\n to: line.from,\n decoration: Decoration.line({\n class: 'cm-mermaid-hidden',\n }),\n });\n }\n }\n }\n }\n }\n },\n });\n\n return Decoration.set(\n decorations.sort((a, b) => a.from - b.from || a.to - b.to).map((d) => d.decoration.range(d.from, d.to)),\n );\n }\n },\n {\n decorations: (v) => v.decorations,\n },\n ),\n EditorView.theme({\n '& .cm-mermaid': {\n position: 'relative',\n display: 'inline-flex',\n width: '100%',\n maring: '4px 0',\n padding: '16px',\n justifyContent: 'center',\n backgroundColor: 'var(--dx-groupSurface)',\n borderRadius: '8px',\n },\n '& .cm-mermaid-label': {\n position: 'absolute',\n right: '16px',\n fontFamily: 'unset',\n color: 'var(--dx-subdued)',\n },\n '& .cm-mermaid-error': {\n display: 'inline-block',\n color: 'var(--dx-errorText)',\n },\n '& .cm-mermaid-hidden': {\n display: 'none !important',\n },\n }),\n ];\n};\n\nclass MermaidWidget extends WidgetType {\n _svg: string | undefined;\n _error: string | undefined;\n\n // TODO(burdon): Mermaid API requires unique id.\n constructor(\n private readonly _id: string,\n private readonly _source: string,\n private readonly _label?: string,\n ) {\n super();\n }\n\n override eq(other: this): boolean {\n return this._source === other._source;\n }\n\n override toDOM(view: EditorView): HTMLDivElement {\n const div = document.createElement('div');\n div.className = 'cm-mermaid';\n\n setTimeout(async () => {\n // https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts\n _mermaid.initialize({\n darkMode: view.state.facet(EditorView.darkTheme),\n theme: 'neutral',\n // TODO(burdon): Styles.\n // NOTE: Must specify 'base' in order to override.\n // theme: 'base',\n // themeVariables: {\n // primaryColor: getToken('extend.colors.red.100'),\n // primaryBorderColor: getToken('extend.colors.neutral.200'),\n // },\n // https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/diagrams/flowchart/styles.ts\n // https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/diagrams/sequence/styles.js\n // https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/diagrams/state/styles.js\n // themeCSS: '.node rect { fill: red; }',\n });\n\n // TODO(burdon): Cache?\n const svg = await this.render(div);\n if (this._error) {\n div.className = 'cm-mermaid-error';\n div.innerText = this._error;\n } else {\n div.className = 'cm-mermaid';\n div.innerHTML = svg!;\n\n if (this._label) {\n const label = document.createElement('span');\n label.innerText = this._label;\n label.className = 'cm-mermaid-label';\n div.appendChild(label);\n view.requestMeasure();\n }\n }\n });\n\n return div;\n }\n\n async render(_container: Element): Promise<string | undefined> {\n try {\n // https://github.com/mermaid-js/mermaid\n const valid = await _mermaid.parse(this._source);\n if (valid) {\n const result = await _mermaid.render(this._id, this._source);\n this._error = undefined;\n this._svg = result.svg;\n return result.svg;\n }\n } catch (err: any) {\n this._error = String(err);\n this._svg = undefined;\n }\n }\n\n override ignoreEvent(e: Event): boolean {\n return !/^mouse/.test(e.type);\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const meta: PluginMeta = {\n id: 'dxos.org/plugin/mermaid',\n name: 'Mermaid',\n description: 'Tool that renders text definitions to create diagrams.',\n icon: 'ph--anchor-simple--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-mermaid',\n};\n"],
5
- "mappings": ";AAIA,SAASA,aAAaC,cAAcC,oBAAoB;AACxD,SAASC,sBAAsBC,sBAAsB;;;ACDrD,SAASC,kBAAkB;AAE3B,SAASC,YAAgCC,YAAYC,YAA6BC,kBAAkB;AACpG,OAAOC,cAAc;;;;;;;;;;;;;;AAOd,IAAMC,UAAU,CAACC,WAA2B,CAAC,MAAC;AACnD,SAAO;IACLC,WAAWC,UACT,MAAA;MAOEC,OAAOA,QAAoB;AAEzB,YAAIA,OAAOC,cAAcD,OAAOE,mBAAmBF,OAAOG,gBAAgBH,OAAOI,cAAc;AAC7F,eAAKC,cAAc,KAAKC,iBAAiBN,OAAOO,IAAI;QACtD;MACF;MAEAD,iBAAiBC,MAAiC;AAChD,cAAMF,cAA2E,CAAA;AAEjFG,mBAAWD,KAAKE,KAAK,EAAEC,QAAQ;UAC7BC,OAAO,CAACC,SAAAA;AACN,gBAAIA,KAAKC,SAAS,cAAc;AAC9B,oBAAMC,SAASP,KAAKE,MAAMM,UAAUC,KAAKC;AAGzC,oBAAMC,aAAaX,KAAKE,MAAMU,YAAYL,SAASF,KAAKQ,OAAO,KAAKN,SAASF,KAAKS,KAAK;AACvF,kBAAIH,YAAY;AACd,sBAAMI,OAAOV,KAAKA,KAAKW,SAAS,UAAA;AAChC,oBAAID,MAAM;AACR,wBAAME,OAAOjB,KAAKE,MAAMgB,SAASH,KAAKF,MAAME,KAAKD,EAAE;AACnD,wBAAMK,OAAOd,KAAKA,KAAKW,SAAS,UAAA;AAChC,sBAAIC,SAAS,aAAaE,MAAM;AAC9B,0BAAMC,UAAUpB,KAAKE,MAAMgB,SAASC,KAAKN,MAAMM,KAAKL,EAAE,EAAEO,KAAI;AAC5D,0BAAMC,QAAQF,QAAQG,MAAM,GAAA,EAAK,CAAA;AAGjC,0BAAMC,SAAS,IAAIC,cA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,SAASW;AACd,aAAKC,OAAOH,OAAOX;AACnB,eAAOW,OAAOX;MAChB;IACF,SAASe,KAAU;AACjB,WAAKb,SAASc,OAAOD,GAAAA;AACrB,WAAKD,OAAOD;IACd;EACF;EAESI,YAAYC,GAAmB;AACtC,WAAO,CAAC,SAASC,KAAKD,EAAE7E,IAAI;EAC9B;;EA1EA,YACmBuE,KACAxB,SACAiB,QACjB;AACA,UAAK,GAAA,iBAAA,MAAA,OAAA,MAAA,GAAA,iBAAA,MAAA,WAAA,MAAA,GAAA,iBAAA,MAAA,UAAA,MAAA,GATPS,iBAAAA,MAAAA,QAAAA,MAAAA,GACAZ,iBAAAA,MAAAA,UAAAA,MAAAA,GAAAA,KAImBU,MAAAA,KAAAA,KACAxB,UAAAA,SAAAA,KACAiB,SAAAA;EAGnB;AAqEF;;;AChNO,IAAMe,OAAmB;EAC9BC,IAAI;EACJC,MAAM;EACNC,aAAa;EACbC,MAAM;EACNC,QAAQ;AACV;;;AFFO,IAAMC,gBAAgBC,aAAaC,MAAM,MAAM;EACpDC,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,eAAeC;IAC5BC,UAAU,MAAMC,YAAYC,qBAAqBC,YAAY;MAACC;KAAQ;EACxE,CAAA;CACD;",
6
- "names": ["contributes", "defineModule", "definePlugin", "MarkdownCapabilities", "MarkdownEvents", "syntaxTree", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "_mermaid", "mermaid", "_options", "ViewPlugin", "fromClass", "update", "docChanged", "viewportChanged", "selectionSet", "focusChanged", "decorations", "buildDecorations", "view", "syntaxTree", "state", "iterate", "enter", "node", "name", "cursor", "selection", "main", "head", "showWidget", "readOnly", "from", "to", "info", "getChild", "type", "sliceDoc", "text", "content", "trim", "label", "split", "widget", "MermaidWidget", "endLine", "doc", "lineAt", "nextLinePos", "length", "push", "decoration", "Decoration", "side", "startLine", "lineNum", "number", "line", "class", "set", "sort", "a", "b", "map", "d", "range", "v", "EditorView", "theme", "position", "display", "width", "maring", "padding", "justifyContent", "backgroundColor", "borderRadius", "right", "fontFamily", "color", "WidgetType", "eq", "other", "_source", "toDOM", "div", "document", "createElement", "className", "setTimeout", "_mermaid", "initialize", "darkMode", "facet", "darkTheme", "svg", "render", "_error", "innerText", "innerHTML", "_label", "appendChild", "requestMeasure", "_container", "valid", "parse", "result", "_id", "undefined", "_svg", "err", "String", "ignoreEvent", "e", "test", "meta", "id", "name", "description", "icon", "source", "MermaidPlugin", "definePlugin", "meta", "defineModule", "id", "activatesOn", "MarkdownEvents", "SetupExtensions", "activate", "contributes", "MarkdownCapabilities", "Extensions", "mermaid"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/extensions/mermaid-extension.ts":{"bytes":25706,"imports":[{"path":"@codemirror/language","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"mermaid","kind":"import-statement","external":true}],"format":"esm"},"src/extensions/index.ts":{"bytes":494,"imports":[{"path":"src/extensions/mermaid-extension.ts","kind":"import-statement","original":"./mermaid-extension"}],"format":"esm"},"src/meta.ts":{"bytes":1298,"imports":[],"format":"esm"},"src/MermaidPlugin.tsx":{"bytes":2282,"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-markdown","kind":"import-statement","external":true},{"path":"src/extensions/index.ts","kind":"import-statement","original":"./extensions"},{"path":"src/meta.ts","kind":"import-statement","original":"./meta"}],"format":"esm"},"src/index.ts":{"bytes":551,"imports":[{"path":"src/MermaidPlugin.tsx","kind":"import-statement","original":"./MermaidPlugin"},{"path":"src/meta.ts","kind":"import-statement","original":"./meta"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":14097},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-markdown","kind":"import-statement","external":true},{"path":"@codemirror/language","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"mermaid","kind":"import-statement","external":true}],"exports":["MermaidPlugin","meta"],"entryPoint":"src/index.ts","inputs":{"src/MermaidPlugin.tsx":{"bytesInOutput":405},"src/extensions/mermaid-extension.ts":{"bytesInOutput":5709},"src/extensions/index.ts":{"bytesInOutput":0},"src/meta.ts":{"bytesInOutput":262},"src/index.ts":{"bytesInOutput":0}},"bytes":6554}}}