@myst-theme/diagrams 0.1.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 ADDED
@@ -0,0 +1,6 @@
1
+ # @myst-theme/diagrams
2
+
3
+ [![myst-demo on npm](https://img.shields.io/npm/v/myst-demo.svg)](https://www.npmjs.com/package/myst-demo)
4
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/curvenote/curvenote/blob/main/LICENSE)
5
+
6
+ A demo component for MyST
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare function MermaidRenderer({ id, value }: {
3
+ value: string;
4
+ id: string;
5
+ }): JSX.Element;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";AAWA,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,eA0B3E"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.MermaidRenderer = void 0;
36
+ const jsx_runtime_1 = require("react/jsx-runtime");
37
+ const react_1 = require("react");
38
+ function parse(id, text) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const { default: mermaid } = yield Promise.resolve().then(() => __importStar(require('mermaid')));
41
+ return yield new Promise((resolve) => {
42
+ mermaid.render(id, text, (code) => {
43
+ resolve(code);
44
+ });
45
+ });
46
+ });
47
+ }
48
+ function MermaidRenderer({ id, value }) {
49
+ const [graph, setGraph] = (0, react_1.useState)();
50
+ const [error, setError] = (0, react_1.useState)();
51
+ (0, react_1.useEffect)(() => {
52
+ parse(id, value)
53
+ .then((svg) => {
54
+ setGraph(svg);
55
+ setError(undefined);
56
+ })
57
+ .catch((err) => {
58
+ setGraph(undefined);
59
+ setError(err);
60
+ });
61
+ }, []);
62
+ return ((0, jsx_runtime_1.jsxs)("figure", Object.assign({ className: "" }, { children: [graph && (0, jsx_runtime_1.jsx)("div", { dangerouslySetInnerHTML: { __html: graph } }), error && ((0, jsx_runtime_1.jsxs)("pre", { children: ["Error parsing mermaid graph.", '\n\n', value] }))] })));
63
+ }
64
+ exports.MermaidRenderer = MermaidRenderer;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare function MermaidRenderer({ id, value }: {
3
+ value: string;
4
+ id: string;
5
+ }): JSX.Element;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";AAWA,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,eA0B3E"}
@@ -0,0 +1,37 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { useEffect, useState } from 'react';
12
+ function parse(id, text) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ const { default: mermaid } = yield import('mermaid');
15
+ return yield new Promise((resolve) => {
16
+ mermaid.render(id, text, (code) => {
17
+ resolve(code);
18
+ });
19
+ });
20
+ });
21
+ }
22
+ export function MermaidRenderer({ id, value }) {
23
+ const [graph, setGraph] = useState();
24
+ const [error, setError] = useState();
25
+ useEffect(() => {
26
+ parse(id, value)
27
+ .then((svg) => {
28
+ setGraph(svg);
29
+ setError(undefined);
30
+ })
31
+ .catch((err) => {
32
+ setGraph(undefined);
33
+ setError(err);
34
+ });
35
+ }, []);
36
+ return (_jsxs("figure", Object.assign({ className: "" }, { children: [graph && _jsx("div", { dangerouslySetInnerHTML: { __html: graph } }), error && (_jsxs("pre", { children: ["Error parsing mermaid graph.", '\n\n', value] }))] })));
37
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare function MermaidRenderer({ id, value }: {
3
+ value: string;
4
+ id: string;
5
+ }): JSX.Element;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";AAWA,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,eA0B3E"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@myst-theme/diagrams",
3
+ "version": "0.1.0",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "clean": "rimraf dist",
13
+ "compile": "tsc",
14
+ "lint": "eslint \"src/**/*.ts*\" \"src/**/*.tsx\" -c ./.eslintrc.js",
15
+ "lint:format": "prettier --check \"src/**/*.{ts,tsx,md}\"",
16
+ "dev": "npm-run-all --parallel \"build:* -- --watch\"",
17
+ "build:cjs": "tsc --module commonjs --outDir dist/cjs",
18
+ "build:esm": "tsc --module es2020 --outDir dist/esm",
19
+ "build:types": "tsc --declaration --emitDeclarationOnly --declarationMap --outDir dist/types",
20
+ "build": "npm-run-all -l clean -p build:cjs build:esm build:types"
21
+ },
22
+ "dependencies": {
23
+ "mermaid": "^9.1.7"
24
+ },
25
+ "peerDependencies": {
26
+ "@types/react": "^16.8 || ^17.0 || ^18.0",
27
+ "@types/react-dom": "^16.8 || ^17.0 || ^18.0",
28
+ "react": "^16.8 || ^17.0 || ^18.0",
29
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/js-yaml": "^4.0.5",
33
+ "@types/mermaid": "^8.2.9",
34
+ "eslint": "^8.21.0",
35
+ "eslint-config-curvenote": "latest",
36
+ "npm-run-all": "^4.1.5",
37
+ "tsconfig": "latest",
38
+ "typescript": "latest"
39
+ }
40
+ }