@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 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
- var react_1 = __importDefault(require("react"));
19
- var react_2 = require("react");
20
- var mermaid_1 = __importDefault(require("mermaid"));
21
- var i = 0;
22
- var Diagram = function (_a) {
23
- var chart = _a.chart, isError = _a.isError;
24
- var inputEl = react_2.useRef(null);
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(function () {
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: e });
31
+ console.log({ e });
44
32
  }
45
33
  }, [chart]);
46
- return react_1.default.createElement("div", { className: "mermaid" + (isError ? ' error' : ''), ref: inputEl });
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: function (writer) { return function (node) {
39
+ toAst: (writer) => (node) => {
50
40
  if (typeof node !== "string" && 'type' in node && 'content' in node && node.type === 'block') {
51
- var content = node.content[0];
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
- var data = content.value;
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
- var convert_line_to_absolute = function (line, location) {
61
- var lineoffset = line + location.start.line + 1;
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 = __assign(__assign({}, err), { location: convert_line_to_absolute(err['hash']['line'], node.location) });
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.5",
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 --passWithNoTests"
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
- "@types/node": "^14.11.2",
18
- "jest-watch-typeahead": "^0.6.1",
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
- "@types/react-dom": "^17.0.3",
25
- "react": "16.12.0",
26
- "react-dom": "^17.0.2",
27
- "typescript": "4.2.3"
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
- "react": "*"
31
- },
32
- "gitHead": "8c6f712b1b46052f6da0ede14c3271b92a7b6dc9"
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={ `mermaid${ isError ? ' error' : ''}` } ref={inputEl}/>
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="mermaid">
128
+ <div class="diagram">
129
+ <div class="mermaid">
130
+ </div>
95
131
  </div>
96
132
  </div>
97
133
  `);
package/tsconfig.json CHANGED
@@ -2,9 +2,10 @@
2
2
  "extends": "../core/tsconfig.json",
3
3
  "include": ["src/**/*"],
4
4
  "compilerOptions": {
5
+ "jsx": "react",
5
6
  "outDir": "./lib",
6
7
  "rootDir": "./src",
7
- "jsx": "react",
8
+ "baseUrl": "."
8
9
  },
9
10
  "references": [
10
11
  {