@podlite/diagram 0.0.5 → 0.0.9
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/CHANGELOG.md +9 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +19 -29
- package/package.json +19 -16
- package/src/index.tsx +5 -2
- package/t/plugin.test.tsx +50 -14
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1890
- package/yarn-error.log +8890 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# @podlite/diagram
|
|
2
2
|
|
|
3
3
|
## Upcoming
|
|
4
|
-
|
|
4
|
+
## 0.0.9
|
|
5
|
+
- fix npm
|
|
6
|
+
## 0.0.8
|
|
7
|
+
- add :caption, :id support
|
|
8
|
+
- upgrade mermaid to 8.12.1
|
|
9
|
+
## 0.0.7
|
|
10
|
+
- update deps
|
|
11
|
+
## 0.0.6
|
|
12
|
+
- update deps
|
|
5
13
|
## 0.0.5
|
|
6
14
|
- update mermaid to latest version
|
|
7
15
|
- fix error while diagrams renders
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Plugin } from '@podlite/schema';
|
|
3
|
-
declare const Diagram: ({ chart, isError }: {
|
|
3
|
+
declare const Diagram: ({ chart, isError, caption, id }: {
|
|
4
4
|
chart: string;
|
|
5
5
|
isError: any;
|
|
6
|
+
caption?: string;
|
|
7
|
+
id?: string;
|
|
6
8
|
}) => JSX.Element;
|
|
7
9
|
export declare const plugin: Plugin;
|
|
8
10
|
export default Diagram;
|
package/lib/index.js
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.plugin = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var config = {
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_2 = require("react");
|
|
9
|
+
const mermaid_1 = __importDefault(require("mermaid"));
|
|
10
|
+
let i = 0;
|
|
11
|
+
const Diagram = ({ chart, isError, caption, id }) => {
|
|
12
|
+
const inputEl = (0, react_2.useRef)(null);
|
|
13
|
+
const config = {
|
|
26
14
|
securityLevel: "loose",
|
|
27
15
|
startOnLoad: false
|
|
28
16
|
};
|
|
29
|
-
react_2.useEffect(
|
|
17
|
+
(0, react_2.useEffect)(() => {
|
|
30
18
|
var insertSvg = function (svgCode) {
|
|
31
19
|
inputEl.current.innerHTML = svgCode;
|
|
32
20
|
};
|
|
@@ -40,25 +28,27 @@ var Diagram = function (_a) {
|
|
|
40
28
|
mermaid_1.default.render('graph-div' + i++, chart, insertSvg);
|
|
41
29
|
}
|
|
42
30
|
catch (e) {
|
|
43
|
-
console.log({ e
|
|
31
|
+
console.log({ e });
|
|
44
32
|
}
|
|
45
33
|
}, [chart]);
|
|
46
|
-
return react_1.default.createElement("div", { className: "
|
|
34
|
+
return react_1.default.createElement("div", { className: "diagram", id: id },
|
|
35
|
+
react_1.default.createElement("div", { className: `mermaid${isError ? ' error' : ''}`, ref: inputEl }),
|
|
36
|
+
caption ? react_1.default.createElement("div", { className: "caption" }, caption) : null);
|
|
47
37
|
};
|
|
48
38
|
exports.plugin = {
|
|
49
|
-
toAst:
|
|
39
|
+
toAst: (writer) => (node) => {
|
|
50
40
|
if (typeof node !== "string" && 'type' in node && 'content' in node && node.type === 'block') {
|
|
51
|
-
|
|
41
|
+
const content = node.content[0];
|
|
52
42
|
if (typeof content !== "string" && 'location' in node && 'value' in content) {
|
|
53
43
|
// get link and alt text
|
|
54
|
-
|
|
44
|
+
const data = content.value;
|
|
55
45
|
try {
|
|
56
46
|
mermaid_1.default.parse(data);
|
|
57
47
|
}
|
|
58
48
|
catch (err) {
|
|
59
49
|
// calculate line in relation to node
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
const convert_line_to_absolute = (line, location) => {
|
|
51
|
+
const lineoffset = line + location.start.line + 1;
|
|
62
52
|
return { "start": {
|
|
63
53
|
"offset": 0,
|
|
64
54
|
"line": lineoffset,
|
|
@@ -71,12 +61,12 @@ exports.plugin = {
|
|
|
71
61
|
}
|
|
72
62
|
};
|
|
73
63
|
};
|
|
74
|
-
node.custom =
|
|
64
|
+
node.custom = { ...err, location: convert_line_to_absolute(err['hash']['line'], node.location) };
|
|
75
65
|
writer.emit("errors", node.location);
|
|
76
66
|
}
|
|
77
67
|
return node;
|
|
78
68
|
}
|
|
79
69
|
}
|
|
80
|
-
}
|
|
70
|
+
},
|
|
81
71
|
};
|
|
82
72
|
exports.default = Diagram;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podlite/diagram",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Diagram",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -8,26 +8,29 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"clean": "rm -rf dist lib tsconfig.tsbuildinfo",
|
|
10
10
|
"build": "tsc",
|
|
11
|
-
"test": "jest
|
|
11
|
+
"test": "yarn g:jest --passWithNoTests"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
14
|
-
"access": "public"
|
|
14
|
+
"access": "public",
|
|
15
|
+
"main": "index.js"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"
|
|
19
|
-
"mermaid": "8.10.1",
|
|
20
|
-
"react-is": "^16.12.0",
|
|
21
|
-
"ts-jest": "^26.4.1"
|
|
18
|
+
"@podlite/schema": "0.0.7",
|
|
19
|
+
"react-is": "^17.0.2"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"
|
|
26
|
-
"react
|
|
27
|
-
"
|
|
22
|
+
"@podlite/to-jsx": "0.0.8",
|
|
23
|
+
"@types/node": "^16.11.9",
|
|
24
|
+
"@types/react": "^16.x",
|
|
25
|
+
"@types/react-dom": "^16.x",
|
|
26
|
+
"mermaid": "8.12.1",
|
|
27
|
+
"podlite": "0.0.13",
|
|
28
|
+
"react": "^16.12.0",
|
|
29
|
+
"react-dom": "^16.12.0"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
32
|
+
"mermaid": "*",
|
|
33
|
+
"react": "*",
|
|
34
|
+
"react-is": "*"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import {useEffect, useRef} from 'react'
|
|
|
3
3
|
import {Plugin, Location} from '@podlite/schema'
|
|
4
4
|
import mermaid from 'mermaid';
|
|
5
5
|
let i = 0;
|
|
6
|
-
const Diagram = ({ chart , isError }: {chart:string, isError:any})=>{
|
|
6
|
+
const Diagram = ({ chart , isError, caption, id }: {chart:string, isError:any, caption?:string, id?:string})=>{
|
|
7
7
|
const inputEl = useRef(null);
|
|
8
8
|
const config = {
|
|
9
9
|
securityLevel: "loose",
|
|
@@ -27,7 +27,10 @@ const Diagram = ({ chart , isError }: {chart:string, isError:any})=>{
|
|
|
27
27
|
}
|
|
28
28
|
}, [chart])
|
|
29
29
|
|
|
30
|
-
return <div className=
|
|
30
|
+
return <div className="diagram" id={id}>
|
|
31
|
+
<div className={ `mermaid${ isError ? ' error' : ''}` } ref={inputEl}/>
|
|
32
|
+
{ caption ? <div className="caption">{caption}</div> : null }
|
|
33
|
+
</div>
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export const plugin:Plugin = {
|
package/t/plugin.test.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import Diagram, { plugin as DiagramPlugin } from "../src/index";
|
|
|
8
8
|
import Podlite from "@podlite/to-jsx";
|
|
9
9
|
import React from "react";
|
|
10
10
|
import ReactDOM from "react-dom";
|
|
11
|
+
import makeAttrs from "pod6/built/helpers/config";
|
|
11
12
|
|
|
12
13
|
const parse = (str: string): PodliteDocument => {
|
|
13
14
|
let podlite = podlite_core({ importPlugins: false }).use({
|
|
@@ -31,6 +32,31 @@ const cleanHTML = (html: string) => {
|
|
|
31
32
|
return html.replace(/\n+/g, "");
|
|
32
33
|
};
|
|
33
34
|
|
|
35
|
+
const plugins = (makeComponent) => {
|
|
36
|
+
return {
|
|
37
|
+
Diagram: () => (node, ctx, interator) => {
|
|
38
|
+
const conf = makeAttrs(node, ctx);
|
|
39
|
+
const caption = conf.exists("caption")
|
|
40
|
+
? conf.getFirstValue("caption")
|
|
41
|
+
: null;
|
|
42
|
+
return makeComponent(
|
|
43
|
+
({ children, key }) => {
|
|
44
|
+
return (
|
|
45
|
+
<Diagram
|
|
46
|
+
isError={node.custom}
|
|
47
|
+
key={key}
|
|
48
|
+
caption={caption}
|
|
49
|
+
chart={node.content[0].value}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
node,
|
|
54
|
+
interator(node.content, { ...ctx })
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
34
60
|
const root = document.body.appendChild(document.createElement("div"));
|
|
35
61
|
|
|
36
62
|
function render(jsx) {
|
|
@@ -73,25 +99,35 @@ B-->D(fa:fa-spinner aaaaa);
|
|
|
73
99
|
it("=Diagrams: parse to html", () => {
|
|
74
100
|
expect(parseToHtml(pod)).toMatchInlineSnapshot(`""`);
|
|
75
101
|
});
|
|
102
|
+
it("=Diagrams: caption", () => {
|
|
103
|
+
const pod = `
|
|
104
|
+
=begin Diagram :caption('Caption test')
|
|
105
|
+
graph LR
|
|
106
|
+
A-->B
|
|
107
|
+
B-->C
|
|
108
|
+
C-->A
|
|
109
|
+
D-->C
|
|
110
|
+
=end Diagram
|
|
111
|
+
`;
|
|
112
|
+
render(<Podlite plugins={plugins}>{pod}</Podlite>);
|
|
113
|
+
expect(root.innerHTML).toMatchInlineSnapshot(`
|
|
114
|
+
<div class="diagram">
|
|
115
|
+
<div class="mermaid">
|
|
116
|
+
</div>
|
|
117
|
+
<div class="caption">
|
|
118
|
+
Caption test
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
76
123
|
|
|
77
124
|
it("accepts =Diagram", () => {
|
|
78
|
-
const plugins = (makeComponent) => {
|
|
79
|
-
return {
|
|
80
|
-
Diagram: () => (node, ctx, interator) => {
|
|
81
|
-
return makeComponent(
|
|
82
|
-
({ children, key }) => {
|
|
83
|
-
return <Diagram isError= {node.custom} key={key} chart={node.content[0].value} />;
|
|
84
|
-
},
|
|
85
|
-
node,
|
|
86
|
-
interator(node.content, { ...ctx })
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
125
|
render(<Podlite plugins={plugins}>{pod}</Podlite>);
|
|
92
126
|
expect(root.innerHTML).toMatchInlineSnapshot(`
|
|
93
127
|
<div>
|
|
94
|
-
<div class="
|
|
128
|
+
<div class="diagram">
|
|
129
|
+
<div class="mermaid">
|
|
130
|
+
</div>
|
|
95
131
|
</div>
|
|
96
132
|
</div>
|
|
97
133
|
`);
|