fix: Import diagram

This commit is contained in:
Sidharth Vinod 2022-10-06 13:44:28 +08:00
parent 0f2e0c2ab4
commit c919bef70e
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
4 changed files with 10 additions and 17 deletions

View File

@ -100,7 +100,7 @@ mindmap
logLevel: 0, logLevel: 0,
// basePath: './packages/', // basePath: './packages/',
// themeVariables: { darkMode: true }, // themeVariables: { darkMode: true },
extraDiagrams: ['./mermaid-mindmap-detector.js'], extraDiagrams: ['./mermaid-mindmap-detector.core.mjs'],
// extraDiagrams: ['../../mermaid-mindmap/registry.ts'], // extraDiagrams: ['../../mermaid-mindmap/registry.ts'],
}); });
function callback() { function callback() {

View File

@ -1,6 +1,6 @@
export const id = 'mindmap'; export const id = 'mindmap';
const detector = (txt: string) => { export const detector = (txt: string) => {
return txt.match(/^\s*mindmap/) !== null; return txt.match(/^\s*mindmap/) !== null;
}; };
@ -8,9 +8,3 @@ export const loadDiagram = async () => {
const { mindmap } = await import('./add-diagram'); const { mindmap } = await import('./add-diagram');
return { id, diagram: mindmap }; return { id, diagram: mindmap };
}; };
export default {
id,
detector,
loadDiagram,
};

View File

@ -54,6 +54,9 @@ export const addDetector = (
loader: DiagramLoader | null loader: DiagramLoader | null
) => { ) => {
detectors[key] = { detector, loader }; detectors[key] = { detector, loader };
// TODO: Remove
// eslint-disable-next-line no-console
console.log(detectors);
}; };
export const getDiagramLoader = (key: string) => detectors[key].loader; export const getDiagramLoader = (key: string) => detectors[key].loader;

View File

@ -57,15 +57,11 @@ const init = async function (
const conf = mermaidAPI.getConfig(); const conf = mermaidAPI.getConfig();
if (typeof conf.extraDiagrams !== 'undefined' && conf.extraDiagrams.length > 0) { if (typeof conf.extraDiagrams !== 'undefined' && conf.extraDiagrams.length > 0) {
// config.extraDiagrams.forEach(async (diagram: string) => { // config.extraDiagrams.forEach(async (diagram: string) => {
const apa = await import(conf.extraDiagrams[0]); const { id, detector, loadDiagram } = await import(conf.extraDiagrams[0]);
// Todo figure out how to get the diagram properly // TODO: Remove
//@ts-ignore temporary code // eslint-disable-next-line no-console
const did = window['mermaid-mindmap-detector'].default.id; //eslint-disable-line console.log(id, detector, loadDiagram);
//@ts-ignore temporary code addDetector(id, detector, loadDiagram);
const detector = window['mermaid-mindmap-detector'].default.detector; //eslint-disable-line
//@ts-ignore temporary code
const loader = window['mermaid-mindmap-detector'].default.loadDiagram; //eslint-disable-line
addDetector(did, detector, loader);
// }); // });
} }
mermaid.detectors.forEach(({ id, detector, path }) => { mermaid.detectors.forEach(({ id, detector, path }) => {