forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
export const mindmapDetector = (txt: string) => { | ||
return txt.match(/^\s*mindmap/) !== null; | ||
}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,26 @@ | ||
// @ts-ignore: TODO Fix ts errors | ||
import { mindmapDetector } from './mindmapDetector'; | ||
export const id = 'mindmap'; | ||
|
||
const scriptElement = document.currentScript as HTMLScriptElement; | ||
const path = scriptElement.src; | ||
const lastSlash = path.lastIndexOf('/'); | ||
const baseFolder = lastSlash < 0 ? path : path.substring(0, lastSlash + 1); | ||
const detectorFunction = (txt: string) => { | ||
return txt.match(/^\s*mindmap/) !== null; | ||
}; | ||
|
||
if (typeof document !== 'undefined') { | ||
if (window.mermaid && typeof window.mermaid.detectors === 'object') { | ||
window.mermaid.detectors.push({ id: 'mindmap', detector: mindmapDetector }); | ||
export const loadDiagram = async () => { | ||
const diagram = await import('./add-diagram'); | ||
return { id, detector, diagram }; | ||
}; | ||
export const detector = async (txt: string) => { | ||
if (detectorFunction(txt)) { | ||
const diagram = await import('./add-diagram'); | ||
return { id, diagram }; | ||
} else { | ||
window.mermaid = {}; | ||
window.mermaid.detectors = [{ id: 'mindmap', detector: mindmapDetector }]; | ||
return false; | ||
} | ||
}; | ||
|
||
/*! | ||
* Wait for document loaded before starting the execution. | ||
*/ | ||
window.addEventListener( | ||
'load', | ||
() => { | ||
if (window.mermaid && typeof window.mermaid.detectors === 'object') { | ||
window.mermaid.detectors.push({ | ||
id: 'mindmap', | ||
detector: mindmapDetector, | ||
path: baseFolder, | ||
}); | ||
console.error(window.mermaid.detectors); // eslint-disable-line no-console | ||
} | ||
}, | ||
false | ||
); | ||
} | ||
export const id = 'mindmap'; | ||
|
||
export default { | ||
id, | ||
detector, | ||
loadDiagram, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters