backstage-plugin-techdocs-addon-mermaid 0.1.1 → 0.2.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/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createRouteRef, createPlugin } from '@backstage/core-plugin-api';
1
+ import { createPlugin } from '@backstage/core-plugin-api';
2
2
  import { useShadowRootElements, createTechDocsAddonExtension, TechDocsAddonLocations } from '@backstage/plugin-techdocs-react';
3
3
  import { useEffect } from 'react';
4
4
  import mermaid from 'mermaid';
@@ -11,6 +11,7 @@ const isMermaidCode = (code) => {
11
11
  let diagramId = 0;
12
12
  const MermaidAddon = ({}) => {
13
13
  const highlightTables = useShadowRootElements([".highlighttable"]);
14
+ console.log("MermaidAddon");
14
15
  useEffect(() => {
15
16
  highlightTables.forEach((highlightTable) => {
16
17
  var _a;
@@ -21,6 +22,7 @@ const MermaidAddon = ({}) => {
21
22
  if (!codeBlock) {
22
23
  return;
23
24
  }
25
+ console.log("useEffect", codeBlock.innerText);
24
26
  const diagramText = codeBlock.innerText;
25
27
  if (!isMermaidCode(diagramText)) {
26
28
  return;
@@ -38,15 +40,8 @@ const MermaidAddon = ({}) => {
38
40
  return null;
39
41
  };
40
42
 
41
- const rootRouteRef = createRouteRef({
42
- id: "techdocs-addon-mermaid"
43
- });
44
-
45
43
  const techdocsAddonMermaidPlugin = createPlugin({
46
- id: "techdocs-addon-mermaid",
47
- routes: {
48
- root: rootRouteRef
49
- }
44
+ id: "techdocs-addon-mermaid"
50
45
  });
51
46
  const Mermaid = techdocsAddonMermaidPlugin.provide(createTechDocsAddonExtension({
52
47
  name: "MermaidDiagram",
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/Mermaid/hooks.ts","../src/Mermaid/Mermaid.tsx","../src/routes.ts","../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst mermaidStart = /^(\\s*)(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|requirementDiagram|gitGraph)/;\n\nexport const isMermaidCode = (code: string): boolean => {\n return code.match(mermaidStart) !== null\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect } from 'react';\nimport { useShadowRootElements } from '@backstage/plugin-techdocs-react';\nimport mermaid from 'mermaid'\nimport { isMermaidCode } from './hooks';\n\n/**\n * @public\n */\nexport type MermaidProps = {};\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0\n\nexport const MermaidAddon = ({}: MermaidProps) => {\n const highlightTables = useShadowRootElements<HTMLDivElement>(['.highlighttable']);\n\n useEffect(() => {\n highlightTables.forEach(highlightTable => {\n // Skip already processed\n if (highlightTable.style.display === 'none') {\n return\n }\n\n const codeBlock = highlightTable.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.innerText\n\n // Ideally we could detect mermaid based on some annotation, but use a regex for now\n if (!isMermaidCode(diagramText)) {\n return\n }\n\n highlightTable.style.display = 'none'\n\n const diagramElement = document.createElement('div')\n diagramElement.className = \"mermaid\"\n\n highlightTable.parentNode?.insertBefore(diagramElement, highlightTable.nextSibling);\n\n const id = `mermaid-${diagramId++}`\n\n mermaid.render(id, diagramText, (svgGraph: string) => {\n diagramElement.innerHTML = svgGraph\n });\n });\n }, [highlightTables]);\n\n return null;\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createRouteRef } from '@backstage/core-plugin-api';\n\nexport const rootRouteRef = createRouteRef({\n id: 'techdocs-addon-mermaid',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createPlugin } from '@backstage/core-plugin-api';\nimport {\n createTechDocsAddonExtension,\n TechDocsAddonLocations,\n} from '@backstage/plugin-techdocs-react';\n\nimport { MermaidAddon, MermaidProps } from './Mermaid';\nimport { rootRouteRef } from './routes';\n\nexport const techdocsAddonMermaidPlugin = createPlugin({\n id: 'techdocs-addon-mermaid',\n routes: {\n root: rootRouteRef,\n },\n});\n\n/**\n * TechDocs addon that lets you render Mermaid diagrams\n *\n * @public\n */\n\n export const Mermaid = techdocsAddonMermaidPlugin.provide(\n createTechDocsAddonExtension<MermaidProps>({\n name: 'MermaidDiagram',\n location: TechDocsAddonLocations.Content,\n component: MermaidAddon,\n }),\n);\n"],"names":[],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C;AAC1C,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,QAAQ,KAAK;AACpD,QAAQ,cAAc,CAAC,SAAS,GAAG,QAAQ,CAAC;AAC5C,OAAO,CAAC,CAAC;AACT,KAAK,CAAC,CAAC;AACP,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AACxB,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;;AC/BM,MAAM,YAAY,GAAG,cAAc,CAAC;AAC3C,EAAE,EAAE,EAAE,wBAAwB;AAC9B,CAAC,CAAC;;ACIU,MAAC,0BAA0B,GAAG,YAAY,CAAC;AACvD,EAAE,EAAE,EAAE,wBAAwB;AAC9B,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,YAAY;AACtB,GAAG;AACH,CAAC,EAAE;AACS,MAAC,OAAO,GAAG,0BAA0B,CAAC,OAAO,CAAC,4BAA4B,CAAC;AACvF,EAAE,IAAI,EAAE,gBAAgB;AACxB,EAAE,QAAQ,EAAE,sBAAsB,CAAC,OAAO;AAC1C,EAAE,SAAS,EAAE,YAAY;AACzB,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/Mermaid/hooks.ts","../src/Mermaid/Mermaid.tsx","../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst mermaidStart = /^(\\s*)(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|requirementDiagram|gitGraph)/;\n\nexport const isMermaidCode = (code: string): boolean => {\n return code.match(mermaidStart) !== null\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect } from 'react';\nimport { useShadowRootElements } from '@backstage/plugin-techdocs-react';\nimport mermaid from 'mermaid'\nimport { isMermaidCode } from './hooks';\n\n/**\n * @public\n */\nexport type MermaidProps = {};\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0\n\nexport const MermaidAddon = ({}: MermaidProps) => {\n const highlightTables = useShadowRootElements<HTMLDivElement>(['.highlighttable']);\n\n console.log('MermaidAddon')\n\n useEffect(() => {\n highlightTables.forEach(highlightTable => {\n // Skip already processed\n if (highlightTable.style.display === 'none') {\n return\n }\n\n const codeBlock = highlightTable.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n console.log('useEffect', codeBlock.innerText)\n\n const diagramText = codeBlock.innerText\n\n // Ideally we could detect mermaid based on some annotation, but use a regex for now\n if (!isMermaidCode(diagramText)) {\n return\n }\n\n highlightTable.style.display = 'none'\n\n const diagramElement = document.createElement('div')\n diagramElement.className = \"mermaid\"\n\n highlightTable.parentNode?.insertBefore(diagramElement, highlightTable.nextSibling);\n\n const id = `mermaid-${diagramId++}`\n\n mermaid.render(id, diagramText, (svgGraph: string) => {\n diagramElement.innerHTML = svgGraph\n });\n });\n }, [highlightTables]);\n\n return null;\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createPlugin } from '@backstage/core-plugin-api';\nimport {\n createTechDocsAddonExtension,\n TechDocsAddonLocations,\n} from '@backstage/plugin-techdocs-react';\n\nimport { MermaidAddon, MermaidProps } from './Mermaid';\n\n/**\n * The TechDocs addons mermaid plugin\n *\n * @public\n */\n\n\nexport const techdocsAddonMermaidPlugin = createPlugin({\n id: 'techdocs-addon-mermaid',\n});\n\n/**\n * TechDocs addon that lets you render Mermaid diagrams\n *\n * @public\n */\n\n export const Mermaid = techdocsAddonMermaidPlugin.provide(\n createTechDocsAddonExtension<MermaidProps>({\n name: 'MermaidDiagram',\n location: TechDocsAddonLocations.Content,\n component: MermaidAddon,\n }),\n);\n"],"names":[],"mappings":";;;;;AAAA,MAAM,YAAY,GAAG,2HAA2H,CAAC;AAC1I,MAAM,aAAa,GAAG,CAAC,IAAI,KAAK;AACvC,EAAE,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AAC3C,CAAC;;ACCD,IAAI,SAAS,GAAG,CAAC,CAAC;AACX,MAAM,YAAY,GAAG,CAAC,EAAE,KAAK;AACpC,EAAE,MAAM,eAAe,GAAG,qBAAqB,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACrE,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAC9B,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,cAAc,KAAK;AAChD,MAAM,IAAI,EAAE,CAAC;AACb,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,EAAE;AACnD,QAAQ,OAAO;AACf,OAAO;AACP,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,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AC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backstage-plugin-techdocs-addon-mermaid",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "main": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
@@ -27,32 +27,33 @@
27
27
  "postpack": "backstage-cli package postpack"
28
28
  },
29
29
  "dependencies": {
30
- "@backstage/core-components": "^0.9.3",
31
- "@backstage/core-plugin-api": "^1.0.1",
32
- "@backstage/plugin-techdocs-react": "^0.1.1-next.0",
30
+ "@backstage/core-components": "^0.9.4",
31
+ "@backstage/core-plugin-api": "^1.0.2",
32
+ "@backstage/plugin-techdocs-react": "^1.0.0",
33
33
  "@backstage/theme": "^0.2.15",
34
34
  "@material-ui/core": "^4.9.13",
35
35
  "@material-ui/icons": "^4.9.1",
36
36
  "@material-ui/lab": "4.0.0-alpha.57",
37
- "mermaid": "^9.0.1",
37
+ "mermaid": "^9.1.1",
38
38
  "react-use": "^17.2.4"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": "^16.13.1 || ^17.0.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@backstage/cli": "^0.17.1-next.0",
45
- "@backstage/core-app-api": "^1.0.1",
46
- "@backstage/dev-utils": "^1.0.2-next.0",
47
- "@backstage/test-utils": "^1.0.2-next.0",
44
+ "@backstage/cli": "^0.17.1",
45
+ "@backstage/core-app-api": "^1.0.2",
46
+ "@backstage/dev-utils": "^1.0.2",
47
+ "@backstage/plugin-techdocs-addons-test-utils": "^1.0.0",
48
+ "@backstage/test-utils": "^1.1.0",
48
49
  "@testing-library/jest-dom": "^5.10.1",
49
50
  "@testing-library/react": "^12.1.3",
50
51
  "@testing-library/user-event": "^14.0.0",
51
52
  "@types/jest": "*",
52
53
  "@types/mermaid": "^8.2.9",
53
54
  "@types/node": "*",
54
- "msw": "^0.35.0",
55
- "cross-fetch": "^3.1.5"
55
+ "cross-fetch": "^3.1.5",
56
+ "msw": "^0.35.0"
56
57
  },
57
58
  "files": [
58
59
  "dist"